1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986-1989, 1991-2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
27 #include "breakpoint.h"
32 #include "gdbthread.h"
34 #include "symfile.h" /* for overlay functions */
39 /* Prototypes for local functions */
41 static void signals_info (char *, int);
43 static void handle_command (char *, int);
45 static void sig_print_info (enum target_signal
);
47 static void sig_print_header (void);
49 static void resume_cleanups (void *);
51 static int hook_stop_stub (void *);
53 static void delete_breakpoint_current_contents (void *);
55 static void set_follow_fork_mode_command (char *arg
, int from_tty
,
56 struct cmd_list_element
* c
);
58 static struct inferior_status
*xmalloc_inferior_status (void);
60 static void free_inferior_status (struct inferior_status
*);
62 static int restore_selected_frame (void *);
64 static void build_infrun (void);
66 static void follow_inferior_fork (int parent_pid
, int child_pid
,
67 int has_forked
, int has_vforked
);
69 static void follow_fork (int parent_pid
, int child_pid
);
71 static void follow_vfork (int parent_pid
, int child_pid
);
73 static void set_schedlock_func (char *args
, int from_tty
,
74 struct cmd_list_element
* c
);
76 struct execution_control_state
;
78 static int currently_stepping (struct execution_control_state
*ecs
);
80 static void xdb_handle_command (char *args
, int from_tty
);
82 void _initialize_infrun (void);
84 int inferior_ignoring_startup_exec_events
= 0;
85 int inferior_ignoring_leading_exec_events
= 0;
87 /* In asynchronous mode, but simulating synchronous execution. */
89 int sync_execution
= 0;
91 /* wait_for_inferior and normal_stop use this to notify the user
92 when the inferior stopped in a different thread than it had been
95 static int previous_inferior_pid
;
97 /* This is true for configurations that may follow through execl() and
98 similar functions. At present this is only true for HP-UX native. */
100 #ifndef MAY_FOLLOW_EXEC
101 #define MAY_FOLLOW_EXEC (0)
104 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
106 /* resume and wait_for_inferior use this to ensure that when
107 stepping over a hit breakpoint in a threaded application
108 only the thread that hit the breakpoint is stepped and the
109 other threads don't continue. This prevents having another
110 thread run past the breakpoint while it is temporarily
113 This is not thread-specific, so it isn't saved as part of
116 Versions of gdb which don't use the "step == this thread steps
117 and others continue" model but instead use the "step == this
118 thread steps and others wait" shouldn't do this. */
120 static int thread_step_needed
= 0;
122 /* This is true if thread_step_needed should actually be used. At
123 present this is only true for HP-UX native. */
125 #ifndef USE_THREAD_STEP_NEEDED
126 #define USE_THREAD_STEP_NEEDED (0)
129 static int use_thread_step_needed
= USE_THREAD_STEP_NEEDED
;
131 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
132 program. It needs to examine the jmp_buf argument and extract the PC
133 from it. The return value is non-zero on success, zero otherwise. */
135 #ifndef GET_LONGJMP_TARGET
136 #define GET_LONGJMP_TARGET(PC_ADDR) 0
140 /* Some machines have trampoline code that sits between function callers
141 and the actual functions themselves. If this machine doesn't have
142 such things, disable their processing. */
144 #ifndef SKIP_TRAMPOLINE_CODE
145 #define SKIP_TRAMPOLINE_CODE(pc) 0
148 /* Dynamic function trampolines are similar to solib trampolines in that they
149 are between the caller and the callee. The difference is that when you
150 enter a dynamic trampoline, you can't determine the callee's address. Some
151 (usually complex) code needs to run in the dynamic trampoline to figure out
152 the callee's address. This macro is usually called twice. First, when we
153 enter the trampoline (looks like a normal function call at that point). It
154 should return the PC of a point within the trampoline where the callee's
155 address is known. Second, when we hit the breakpoint, this routine returns
156 the callee's address. At that point, things proceed as per a step resume
159 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
160 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
163 /* If the program uses ELF-style shared libraries, then calls to
164 functions in shared libraries go through stubs, which live in a
165 table called the PLT (Procedure Linkage Table). The first time the
166 function is called, the stub sends control to the dynamic linker,
167 which looks up the function's real address, patches the stub so
168 that future calls will go directly to the function, and then passes
169 control to the function.
171 If we are stepping at the source level, we don't want to see any of
172 this --- we just want to skip over the stub and the dynamic linker.
173 The simple approach is to single-step until control leaves the
176 However, on some systems (e.g., Red Hat Linux 5.2) the dynamic
177 linker calls functions in the shared C library, so you can't tell
178 from the PC alone whether the dynamic linker is still running. In
179 this case, we use a step-resume breakpoint to get us past the
180 dynamic linker, as if we were using "next" to step over a function
183 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
184 linker code or not. Normally, this means we single-step. However,
185 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
186 address where we can place a step-resume breakpoint to get past the
187 linker's symbol resolution function.
189 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
190 pretty portable way, by comparing the PC against the address ranges
191 of the dynamic linker's sections.
193 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
194 it depends on internal details of the dynamic linker. It's usually
195 not too hard to figure out where to put a breakpoint, but it
196 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
197 sanity checking. If it can't figure things out, returning zero and
198 getting the (possibly confusing) stepping behavior is better than
199 signalling an error, which will obscure the change in the
202 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
203 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
206 #ifndef SKIP_SOLIB_RESOLVER
207 #define SKIP_SOLIB_RESOLVER(pc) 0
210 /* For SVR4 shared libraries, each call goes through a small piece of
211 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
212 to nonzero if we are current stopped in one of these. */
214 #ifndef IN_SOLIB_CALL_TRAMPOLINE
215 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
218 /* In some shared library schemes, the return path from a shared library
219 call may need to go through a trampoline too. */
221 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
222 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
225 /* This function returns TRUE if pc is the address of an instruction
226 that lies within the dynamic linker (such as the event hook, or the
229 This function must be used only when a dynamic linker event has
230 been caught, and the inferior is being stepped out of the hook, or
231 undefined results are guaranteed. */
233 #ifndef SOLIB_IN_DYNAMIC_LINKER
234 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
237 /* On MIPS16, a function that returns a floating point value may call
238 a library helper function to copy the return value to a floating point
239 register. The IGNORE_HELPER_CALL macro returns non-zero if we
240 should ignore (i.e. step over) this function call. */
241 #ifndef IGNORE_HELPER_CALL
242 #define IGNORE_HELPER_CALL(pc) 0
245 /* On some systems, the PC may be left pointing at an instruction that won't
246 actually be executed. This is usually indicated by a bit in the PSW. If
247 we find ourselves in such a state, then we step the target beyond the
248 nullified instruction before returning control to the user so as to avoid
251 #ifndef INSTRUCTION_NULLIFIED
252 #define INSTRUCTION_NULLIFIED 0
255 /* We can't step off a permanent breakpoint in the ordinary way, because we
256 can't remove it. Instead, we have to advance the PC to the next
257 instruction. This macro should expand to a pointer to a function that
258 does that, or zero if we have no such function. If we don't have a
259 definition for it, we have to report an error. */
260 #ifndef SKIP_PERMANENT_BREAKPOINT
261 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
263 default_skip_permanent_breakpoint (void)
266 fprintf_filtered (gdb_stderr
, "\
267 The program is stopped at a permanent breakpoint, but GDB does not know\n\
268 how to step past a permanent breakpoint on this architecture. Try using\n\
269 a command like `return' or `jump' to continue execution.\n");
270 return_to_top_level (RETURN_ERROR
);
275 /* Convert the #defines into values. This is temporary until wfi control
276 flow is completely sorted out. */
278 #ifndef HAVE_STEPPABLE_WATCHPOINT
279 #define HAVE_STEPPABLE_WATCHPOINT 0
281 #undef HAVE_STEPPABLE_WATCHPOINT
282 #define HAVE_STEPPABLE_WATCHPOINT 1
285 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
286 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
288 #undef HAVE_NONSTEPPABLE_WATCHPOINT
289 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
292 #ifndef HAVE_CONTINUABLE_WATCHPOINT
293 #define HAVE_CONTINUABLE_WATCHPOINT 0
295 #undef HAVE_CONTINUABLE_WATCHPOINT
296 #define HAVE_CONTINUABLE_WATCHPOINT 1
299 #ifndef CANNOT_STEP_HW_WATCHPOINTS
300 #define CANNOT_STEP_HW_WATCHPOINTS 0
302 #undef CANNOT_STEP_HW_WATCHPOINTS
303 #define CANNOT_STEP_HW_WATCHPOINTS 1
306 /* Tables of how to react to signals; the user sets them. */
308 static unsigned char *signal_stop
;
309 static unsigned char *signal_print
;
310 static unsigned char *signal_program
;
312 #define SET_SIGS(nsigs,sigs,flags) \
314 int signum = (nsigs); \
315 while (signum-- > 0) \
316 if ((sigs)[signum]) \
317 (flags)[signum] = 1; \
320 #define UNSET_SIGS(nsigs,sigs,flags) \
322 int signum = (nsigs); \
323 while (signum-- > 0) \
324 if ((sigs)[signum]) \
325 (flags)[signum] = 0; \
329 /* Command list pointer for the "stop" placeholder. */
331 static struct cmd_list_element
*stop_command
;
333 /* Nonzero if breakpoints are now inserted in the inferior. */
335 static int breakpoints_inserted
;
337 /* Function inferior was in as of last step command. */
339 static struct symbol
*step_start_function
;
341 /* Nonzero if we are expecting a trace trap and should proceed from it. */
343 static int trap_expected
;
346 /* Nonzero if we want to give control to the user when we're notified
347 of shared library events by the dynamic linker. */
348 static int stop_on_solib_events
;
352 /* Nonzero if the next time we try to continue the inferior, it will
353 step one instruction and generate a spurious trace trap.
354 This is used to compensate for a bug in HP-UX. */
356 static int trap_expected_after_continue
;
359 /* Nonzero means expecting a trace trap
360 and should stop the inferior and return silently when it happens. */
364 /* Nonzero means expecting a trap and caller will handle it themselves.
365 It is used after attach, due to attaching to a process;
366 when running in the shell before the child program has been exec'd;
367 and when running some kinds of remote stuff (FIXME?). */
369 int stop_soon_quietly
;
371 /* Nonzero if proceed is being used for a "finish" command or a similar
372 situation when stop_registers should be saved. */
374 int proceed_to_finish
;
376 /* Save register contents here when about to pop a stack dummy frame,
377 if-and-only-if proceed_to_finish is set.
378 Thus this contains the return value from the called function (assuming
379 values are returned in a register). */
381 char *stop_registers
;
383 /* Nonzero if program stopped due to error trying to insert breakpoints. */
385 static int breakpoints_failed
;
387 /* Nonzero after stop if current stack frame should be printed. */
389 static int stop_print_frame
;
391 static struct breakpoint
*step_resume_breakpoint
= NULL
;
392 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
394 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
395 interactions with an inferior that is running a kernel function
396 (aka, a system call or "syscall"). wait_for_inferior therefore
397 may have a need to know when the inferior is in a syscall. This
398 is a count of the number of inferior threads which are known to
399 currently be running in a syscall. */
400 static int number_of_threads_in_syscalls
;
402 /* This is used to remember when a fork, vfork or exec event
403 was caught by a catchpoint, and thus the event is to be
404 followed at the next resume of the inferior, and not
408 enum target_waitkind kind
;
418 char *execd_pathname
;
422 /* Some platforms don't allow us to do anything meaningful with a
423 vforked child until it has exec'd. Vforked processes on such
424 platforms can only be followed after they've exec'd.
426 When this is set to 0, a vfork can be immediately followed,
427 and an exec can be followed merely as an exec. When this is
428 set to 1, a vfork event has been seen, but cannot be followed
429 until the exec is seen.
431 (In the latter case, inferior_pid is still the parent of the
432 vfork, and pending_follow.fork_event.child_pid is the child. The
433 appropriate process is followed, according to the setting of
434 follow-fork-mode.) */
435 static int follow_vfork_when_exec
;
437 static char *follow_fork_mode_kind_names
[] =
439 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
440 kernel problem. It's also not terribly useful without a GUI to
441 help the user drive two debuggers. So for now, I'm disabling the
443 /* "parent", "child", "both", "ask" */
444 "parent", "child", "ask", NULL
447 static char *follow_fork_mode_string
= NULL
;
451 follow_inferior_fork (int parent_pid
, int child_pid
, int has_forked
,
454 int followed_parent
= 0;
455 int followed_child
= 0;
457 /* Which process did the user want us to follow? */
459 savestring (follow_fork_mode_string
, strlen (follow_fork_mode_string
));
461 /* Or, did the user not know, and want us to ask? */
462 if (STREQ (follow_fork_mode_string
, "ask"))
464 char requested_mode
[100];
467 error ("\"ask\" mode NYI");
468 follow_mode
= savestring (requested_mode
, strlen (requested_mode
));
471 /* If we're to be following the parent, then detach from child_pid.
472 We're already following the parent, so need do nothing explicit
474 if (STREQ (follow_mode
, "parent"))
478 /* We're already attached to the parent, by default. */
480 /* Before detaching from the child, remove all breakpoints from
481 it. (This won't actually modify the breakpoint list, but will
482 physically remove the breakpoints from the child.) */
483 if (!has_vforked
|| !follow_vfork_when_exec
)
485 detach_breakpoints (child_pid
);
486 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
487 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
491 /* Detach from the child. */
494 target_require_detach (child_pid
, "", 1);
497 /* If we're to be following the child, then attach to it, detach
498 from inferior_pid, and set inferior_pid to child_pid. */
499 else if (STREQ (follow_mode
, "child"))
501 char child_pid_spelling
[100]; /* Arbitrary length. */
505 /* Before detaching from the parent, detach all breakpoints from
506 the child. But only if we're forking, or if we follow vforks
507 as soon as they happen. (If we're following vforks only when
508 the child has exec'd, then it's very wrong to try to write
509 back the "shadow contents" of inserted breakpoints now -- they
510 belong to the child's pre-exec'd a.out.) */
511 if (!has_vforked
|| !follow_vfork_when_exec
)
513 detach_breakpoints (child_pid
);
516 /* Before detaching from the parent, remove all breakpoints from it. */
517 remove_breakpoints ();
519 /* Also reset the solib inferior hook from the parent. */
520 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
521 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid
);
524 /* Detach from the parent. */
526 target_detach (NULL
, 1);
528 /* Attach to the child. */
529 inferior_pid
= child_pid
;
530 sprintf (child_pid_spelling
, "%d", child_pid
);
533 target_require_attach (child_pid_spelling
, 1);
535 /* Was there a step_resume breakpoint? (There was if the user
536 did a "next" at the fork() call.) If so, explicitly reset its
539 step_resumes are a form of bp that are made to be per-thread.
540 Since we created the step_resume bp when the parent process
541 was being debugged, and now are switching to the child process,
542 from the breakpoint package's viewpoint, that's a switch of
543 "threads". We must update the bp's notion of which thread
544 it is for, or it'll be ignored when it triggers... */
545 if (step_resume_breakpoint
&&
546 (!has_vforked
|| !follow_vfork_when_exec
))
547 breakpoint_re_set_thread (step_resume_breakpoint
);
549 /* Reinsert all breakpoints in the child. (The user may've set
550 breakpoints after catching the fork, in which case those
551 actually didn't get set in the child, but only in the parent.) */
552 if (!has_vforked
|| !follow_vfork_when_exec
)
554 breakpoint_re_set ();
555 insert_breakpoints ();
559 /* If we're to be following both parent and child, then fork ourselves,
560 and attach the debugger clone to the child. */
561 else if (STREQ (follow_mode
, "both"))
563 char pid_suffix
[100]; /* Arbitrary length. */
565 /* Clone ourselves to follow the child. This is the end of our
566 involvement with child_pid; our clone will take it from here... */
568 target_clone_and_follow_inferior (child_pid
, &followed_child
);
569 followed_parent
= !followed_child
;
571 /* We continue to follow the parent. To help distinguish the two
572 debuggers, though, both we and our clone will reset our prompts. */
573 sprintf (pid_suffix
, "[%d] ", inferior_pid
);
574 set_prompt (strcat (get_prompt (), pid_suffix
));
577 /* The parent and child of a vfork share the same address space.
578 Also, on some targets the order in which vfork and exec events
579 are received for parent in child requires some delicate handling
582 For instance, on ptrace-based HPUX we receive the child's vfork
583 event first, at which time the parent has been suspended by the
584 OS and is essentially untouchable until the child's exit or second
585 exec event arrives. At that time, the parent's vfork event is
586 delivered to us, and that's when we see and decide how to follow
587 the vfork. But to get to that point, we must continue the child
588 until it execs or exits. To do that smoothly, all breakpoints
589 must be removed from the child, in case there are any set between
590 the vfork() and exec() calls. But removing them from the child
591 also removes them from the parent, due to the shared-address-space
592 nature of a vfork'd parent and child. On HPUX, therefore, we must
593 take care to restore the bp's to the parent before we continue it.
594 Else, it's likely that we may not stop in the expected place. (The
595 worst scenario is when the user tries to step over a vfork() call;
596 the step-resume bp must be restored for the step to properly stop
597 in the parent after the call completes!)
599 Sequence of events, as reported to gdb from HPUX:
601 Parent Child Action for gdb to take
602 -------------------------------------------------------
603 1 VFORK Continue child
609 target_post_follow_vfork (parent_pid
,
615 pending_follow
.fork_event
.saw_parent_fork
= 0;
616 pending_follow
.fork_event
.saw_child_fork
= 0;
622 follow_fork (int parent_pid
, int child_pid
)
624 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
628 /* Forward declaration. */
629 static void follow_exec (int, char *);
632 follow_vfork (int parent_pid
, int child_pid
)
634 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
636 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
637 if (pending_follow
.fork_event
.saw_child_exec
&& (inferior_pid
== child_pid
))
639 pending_follow
.fork_event
.saw_child_exec
= 0;
640 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
641 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
642 free (pending_follow
.execd_pathname
);
647 follow_exec (int pid
, char *execd_pathname
)
650 struct target_ops
*tgt
;
652 if (!may_follow_exec
)
655 /* Did this exec() follow a vfork()? If so, we must follow the
656 vfork now too. Do it before following the exec. */
657 if (follow_vfork_when_exec
&&
658 (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
))
660 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
661 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
662 follow_vfork_when_exec
= 0;
663 saved_pid
= inferior_pid
;
665 /* Did we follow the parent? If so, we're done. If we followed
666 the child then we must also follow its exec(). */
667 if (inferior_pid
== pending_follow
.fork_event
.parent_pid
)
671 /* This is an exec event that we actually wish to pay attention to.
672 Refresh our symbol table to the newly exec'd program, remove any
675 If there are breakpoints, they aren't really inserted now,
676 since the exec() transformed our inferior into a fresh set
679 We want to preserve symbolic breakpoints on the list, since
680 we have hopes that they can be reset after the new a.out's
681 symbol table is read.
683 However, any "raw" breakpoints must be removed from the list
684 (e.g., the solib bp's), since their address is probably invalid
687 And, we DON'T want to call delete_breakpoints() here, since
688 that may write the bp's "shadow contents" (the instruction
689 value that was overwritten witha TRAP instruction). Since
690 we now have a new a.out, those shadow contents aren't valid. */
691 update_breakpoints_after_exec ();
693 /* If there was one, it's gone now. We cannot truly step-to-next
694 statement through an exec(). */
695 step_resume_breakpoint
= NULL
;
696 step_range_start
= 0;
699 /* If there was one, it's gone now. */
700 through_sigtramp_breakpoint
= NULL
;
702 /* What is this a.out's name? */
703 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
705 /* We've followed the inferior through an exec. Therefore, the
706 inferior has essentially been killed & reborn. */
708 /* First collect the run target in effect. */
709 tgt
= find_run_target ();
710 /* If we can't find one, things are in a very strange state... */
712 error ("Could find run target to save before following exec");
714 gdb_flush (gdb_stdout
);
715 target_mourn_inferior ();
716 inferior_pid
= saved_pid
; /* Because mourn_inferior resets inferior_pid. */
719 /* That a.out is now the one to use. */
720 exec_file_attach (execd_pathname
, 0);
722 /* And also is where symbols can be found. */
723 symbol_file_command (execd_pathname
, 0);
725 /* Reset the shared library package. This ensures that we get
726 a shlib event when the child reaches "_start", at which point
727 the dld will have had a chance to initialize the child. */
728 #if defined(SOLIB_RESTART)
731 #ifdef SOLIB_CREATE_INFERIOR_HOOK
732 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid
);
735 /* Reinsert all breakpoints. (Those which were symbolic have
736 been reset to the proper address in the new a.out, thanks
737 to symbol_file_command...) */
738 insert_breakpoints ();
740 /* The next resume of this inferior should bring it to the shlib
741 startup breakpoints. (If the user had also set bp's on
742 "main" from the old (parent) process, then they'll auto-
743 matically get reset there in the new process.) */
746 /* Non-zero if we just simulating a single-step. This is needed
747 because we cannot remove the breakpoints in the inferior process
748 until after the `wait' in `wait_for_inferior'. */
749 static int singlestep_breakpoints_inserted_p
= 0;
752 /* Things to clean up if we QUIT out of resume (). */
755 resume_cleanups (void *ignore
)
760 static char schedlock_off
[] = "off";
761 static char schedlock_on
[] = "on";
762 static char schedlock_step
[] = "step";
763 static char *scheduler_mode
= schedlock_off
;
764 static char *scheduler_enums
[] =
773 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
775 if (c
->type
== set_cmd
)
776 if (!target_can_lock_scheduler
)
778 scheduler_mode
= schedlock_off
;
779 error ("Target '%s' cannot support this command.",
787 /* Resume the inferior, but allow a QUIT. This is useful if the user
788 wants to interrupt some lengthy single-stepping operation
789 (for child processes, the SIGINT goes to the inferior, and so
790 we get a SIGINT random_signal, but for remote debugging and perhaps
791 other targets, that's not true).
793 STEP nonzero if we should step (zero to continue instead).
794 SIG is the signal to give the inferior (zero for none). */
796 resume (int step
, enum target_signal sig
)
798 int should_resume
= 1;
799 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
802 #ifdef CANNOT_STEP_BREAKPOINT
803 /* Most targets can step a breakpoint instruction, thus executing it
804 normally. But if this one cannot, just continue and we will hit
806 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
810 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
811 over an instruction that causes a page fault without triggering
812 a hardware watchpoint. The kernel properly notices that it shouldn't
813 stop, because the hardware watchpoint is not triggered, but it forgets
814 the step request and continues the program normally.
815 Work around the problem by removing hardware watchpoints if a step is
816 requested, GDB will check for a hardware watchpoint trigger after the
818 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
819 remove_hw_watchpoints ();
822 /* Normally, by the time we reach `resume', the breakpoints are either
823 removed or inserted, as appropriate. The exception is if we're sitting
824 at a permanent breakpoint; we need to step over it, but permanent
825 breakpoints can't be removed. So we have to test for it here. */
826 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
827 SKIP_PERMANENT_BREAKPOINT ();
829 if (SOFTWARE_SINGLE_STEP_P
&& step
)
831 /* Do it the hard way, w/temp breakpoints */
832 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
833 /* ...and don't ask hardware to do it. */
835 /* and do not pull these breakpoints until after a `wait' in
836 `wait_for_inferior' */
837 singlestep_breakpoints_inserted_p
= 1;
840 /* Handle any optimized stores to the inferior NOW... */
841 #ifdef DO_DEFERRED_STORES
845 /* If there were any forks/vforks/execs that were caught and are
846 now to be followed, then do so. */
847 switch (pending_follow
.kind
)
849 case (TARGET_WAITKIND_FORKED
):
850 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
851 follow_fork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
854 case (TARGET_WAITKIND_VFORKED
):
856 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
858 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
859 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
861 /* Did we follow the child, but not yet see the child's exec event?
862 If so, then it actually ought to be waiting for us; we respond to
863 parent vfork events. We don't actually want to resume the child
864 in this situation; we want to just get its exec event. */
865 if (!saw_child_exec
&&
866 (inferior_pid
== pending_follow
.fork_event
.child_pid
))
871 case (TARGET_WAITKIND_EXECD
):
872 /* If we saw a vfork event but couldn't follow it until we saw
873 an exec, then now might be the time! */
874 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
875 /* follow_exec is called as soon as the exec event is seen. */
882 /* Install inferior's terminal modes. */
883 target_terminal_inferior ();
889 if (use_thread_step_needed
&& thread_step_needed
)
891 /* We stopped on a BPT instruction;
892 don't continue other threads and
893 just step this thread. */
894 thread_step_needed
= 0;
896 if (!breakpoint_here_p (read_pc ()))
898 /* Breakpoint deleted: ok to do regular resume
899 where all the threads either step or continue. */
906 warning ("Internal error, changing continue to step.");
907 remove_breakpoints ();
908 breakpoints_inserted
= 0;
912 resume_pid
= inferior_pid
;
917 /* Vanilla resume. */
918 if ((scheduler_mode
== schedlock_on
) ||
919 (scheduler_mode
== schedlock_step
&& step
!= 0))
920 resume_pid
= inferior_pid
;
924 target_resume (resume_pid
, step
, sig
);
927 discard_cleanups (old_cleanups
);
931 /* Clear out all variables saying what to do when inferior is continued.
932 First do this, then set the ones you want, then call `proceed'. */
935 clear_proceed_status (void)
938 step_range_start
= 0;
940 step_frame_address
= 0;
941 step_over_calls
= -1;
943 stop_soon_quietly
= 0;
944 proceed_to_finish
= 0;
945 breakpoint_proceeded
= 1; /* We're about to proceed... */
947 /* Discard any remaining commands or status from previous stop. */
948 bpstat_clear (&stop_bpstat
);
951 /* Basic routine for continuing the program in various fashions.
953 ADDR is the address to resume at, or -1 for resume where stopped.
954 SIGGNAL is the signal to give it, or 0 for none,
955 or -1 for act according to how it stopped.
956 STEP is nonzero if should trap after one instruction.
957 -1 means return after that and print nothing.
958 You should probably set various step_... variables
959 before calling here, if you are stepping.
961 You should call clear_proceed_status before calling proceed. */
964 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
969 step_start_function
= find_pc_function (read_pc ());
973 if (addr
== (CORE_ADDR
) -1)
975 /* If there is a breakpoint at the address we will resume at,
976 step one instruction before inserting breakpoints
977 so that we do not stop right away (and report a second
978 hit at this breakpoint). */
980 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
983 #ifndef STEP_SKIPS_DELAY
984 #define STEP_SKIPS_DELAY(pc) (0)
985 #define STEP_SKIPS_DELAY_P (0)
987 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
988 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
989 is slow (it needs to read memory from the target). */
990 if (STEP_SKIPS_DELAY_P
991 && breakpoint_here_p (read_pc () + 4)
992 && STEP_SKIPS_DELAY (read_pc ()))
999 /* New address; we don't need to single-step a thread
1000 over a breakpoint we just hit, 'cause we aren't
1001 continuing from there.
1003 It's not worth worrying about the case where a user
1004 asks for a "jump" at the current PC--if they get the
1005 hiccup of re-hiting a hit breakpoint, what else do
1007 thread_step_needed
= 0;
1010 #ifdef PREPARE_TO_PROCEED
1011 /* In a multi-threaded task we may select another thread
1012 and then continue or step.
1014 But if the old thread was stopped at a breakpoint, it
1015 will immediately cause another breakpoint stop without
1016 any execution (i.e. it will report a breakpoint hit
1017 incorrectly). So we must step over it first.
1019 PREPARE_TO_PROCEED checks the current thread against the thread
1020 that reported the most recent event. If a step-over is required
1021 it returns TRUE and sets the current thread to the old thread. */
1022 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
1025 thread_step_needed
= 1;
1028 #endif /* PREPARE_TO_PROCEED */
1031 if (trap_expected_after_continue
)
1033 /* If (step == 0), a trap will be automatically generated after
1034 the first instruction is executed. Force step one
1035 instruction to clear this condition. This should not occur
1036 if step is nonzero, but it is harmless in that case. */
1038 trap_expected_after_continue
= 0;
1040 #endif /* HP_OS_BUG */
1043 /* We will get a trace trap after one instruction.
1044 Continue it automatically and insert breakpoints then. */
1048 int temp
= insert_breakpoints ();
1051 print_sys_errmsg ("insert_breakpoints", temp
);
1052 error ("Cannot insert breakpoints.\n\
1053 The same program may be running in another process,\n\
1054 or you may have requested too many hardware\n\
1055 breakpoints and/or watchpoints.\n");
1058 breakpoints_inserted
= 1;
1061 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1062 stop_signal
= siggnal
;
1063 /* If this signal should not be seen by program,
1064 give it zero. Used for debugging signals. */
1065 else if (!signal_program
[stop_signal
])
1066 stop_signal
= TARGET_SIGNAL_0
;
1068 annotate_starting ();
1070 /* Make sure that output from GDB appears before output from the
1072 gdb_flush (gdb_stdout
);
1074 /* Resume inferior. */
1075 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1077 /* Wait for it to stop (if not standalone)
1078 and in any case decode why it stopped, and act accordingly. */
1079 /* Do this only if we are not using the event loop, or if the target
1080 does not support asynchronous execution. */
1081 if (!event_loop_p
|| !target_can_async_p ())
1083 wait_for_inferior ();
1088 /* Record the pc and sp of the program the last time it stopped.
1089 These are just used internally by wait_for_inferior, but need
1090 to be preserved over calls to it and cleared when the inferior
1092 static CORE_ADDR prev_pc
;
1093 static CORE_ADDR prev_func_start
;
1094 static char *prev_func_name
;
1097 /* Start remote-debugging of a machine over a serial link. */
1102 init_thread_list ();
1103 init_wait_for_inferior ();
1104 stop_soon_quietly
= 1;
1107 /* Always go on waiting for the target, regardless of the mode. */
1108 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1109 indicate th wait_for_inferior that a target should timeout if
1110 nothing is returned (instead of just blocking). Because of this,
1111 targets expecting an immediate response need to, internally, set
1112 things up so that the target_wait() is forced to eventually
1114 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1115 differentiate to its caller what the state of the target is after
1116 the initial open has been performed. Here we're assuming that
1117 the target has stopped. It should be possible to eventually have
1118 target_open() return to the caller an indication that the target
1119 is currently running and GDB state should be set to the same as
1120 for an async run. */
1121 wait_for_inferior ();
1125 /* Initialize static vars when a new inferior begins. */
1128 init_wait_for_inferior (void)
1130 /* These are meaningless until the first time through wait_for_inferior. */
1132 prev_func_start
= 0;
1133 prev_func_name
= NULL
;
1136 trap_expected_after_continue
= 0;
1138 breakpoints_inserted
= 0;
1139 breakpoint_init_inferior (inf_starting
);
1141 /* Don't confuse first call to proceed(). */
1142 stop_signal
= TARGET_SIGNAL_0
;
1144 /* The first resume is not following a fork/vfork/exec. */
1145 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1146 pending_follow
.fork_event
.saw_parent_fork
= 0;
1147 pending_follow
.fork_event
.saw_child_fork
= 0;
1148 pending_follow
.fork_event
.saw_child_exec
= 0;
1150 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1151 number_of_threads_in_syscalls
= 0;
1153 clear_proceed_status ();
1157 delete_breakpoint_current_contents (void *arg
)
1159 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1160 if (*breakpointp
!= NULL
)
1162 delete_breakpoint (*breakpointp
);
1163 *breakpointp
= NULL
;
1167 /* This enum encodes possible reasons for doing a target_wait, so that
1168 wfi can call target_wait in one place. (Ultimately the call will be
1169 moved out of the infinite loop entirely.) */
1173 infwait_normal_state
,
1174 infwait_thread_hop_state
,
1175 infwait_nullified_state
,
1176 infwait_nonstep_watch_state
1179 /* Why did the inferior stop? Used to print the appropriate messages
1180 to the interface from within handle_inferior_event(). */
1181 enum inferior_stop_reason
1183 /* We don't know why. */
1185 /* Step, next, nexti, stepi finished. */
1187 /* Found breakpoint. */
1189 /* Inferior terminated by signal. */
1191 /* Inferior exited. */
1193 /* Inferior received signal, and user asked to be notified. */
1197 /* This structure contains what used to be local variables in
1198 wait_for_inferior. Probably many of them can return to being
1199 locals in handle_inferior_event. */
1201 struct execution_control_state
1203 struct target_waitstatus ws
;
1204 struct target_waitstatus
*wp
;
1207 CORE_ADDR stop_func_start
;
1208 CORE_ADDR stop_func_end
;
1209 char *stop_func_name
;
1210 struct symtab_and_line sal
;
1211 int remove_breakpoints_on_following_step
;
1213 struct symtab
*current_symtab
;
1214 int handling_longjmp
; /* FIXME */
1216 int saved_inferior_pid
;
1218 int stepping_through_solib_after_catch
;
1219 bpstat stepping_through_solib_catchpoints
;
1220 int enable_hw_watchpoints_after_wait
;
1221 int stepping_through_sigtramp
;
1222 int new_thread_event
;
1223 struct target_waitstatus tmpstatus
;
1224 enum infwait_states infwait_state
;
1229 void init_execution_control_state (struct execution_control_state
* ecs
);
1231 void handle_inferior_event (struct execution_control_state
* ecs
);
1233 static void check_sigtramp2 (struct execution_control_state
*ecs
);
1234 static void step_into_function (struct execution_control_state
*ecs
);
1235 static void step_over_function (struct execution_control_state
*ecs
);
1236 static void stop_stepping (struct execution_control_state
*ecs
);
1237 static void prepare_to_wait (struct execution_control_state
*ecs
);
1238 static void keep_going (struct execution_control_state
*ecs
);
1239 static void print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
);
1241 /* Wait for control to return from inferior to debugger.
1242 If inferior gets a signal, we may decide to start it up again
1243 instead of returning. That is why there is a loop in this function.
1244 When this function actually returns it means the inferior
1245 should be left stopped and GDB should read more commands. */
1248 wait_for_inferior (void)
1250 struct cleanup
*old_cleanups
;
1251 struct execution_control_state ecss
;
1252 struct execution_control_state
*ecs
;
1254 old_cleanups
= make_cleanup (delete_breakpoint_current_contents
,
1255 &step_resume_breakpoint
);
1256 make_cleanup (delete_breakpoint_current_contents
,
1257 &through_sigtramp_breakpoint
);
1259 /* wfi still stays in a loop, so it's OK just to take the address of
1260 a local to get the ecs pointer. */
1263 /* Fill in with reasonable starting values. */
1264 init_execution_control_state (ecs
);
1266 thread_step_needed
= 0;
1268 /* We'll update this if & when we switch to a new thread. */
1269 previous_inferior_pid
= inferior_pid
;
1271 overlay_cache_invalid
= 1;
1273 /* We have to invalidate the registers BEFORE calling target_wait
1274 because they can be loaded from the target while in target_wait.
1275 This makes remote debugging a bit more efficient for those
1276 targets that provide critical registers as part of their normal
1277 status mechanism. */
1279 registers_changed ();
1283 if (target_wait_hook
)
1284 ecs
->pid
= target_wait_hook (ecs
->waiton_pid
, ecs
->wp
);
1286 ecs
->pid
= target_wait (ecs
->waiton_pid
, ecs
->wp
);
1288 /* Now figure out what to do with the result of the result. */
1289 handle_inferior_event (ecs
);
1291 if (!ecs
->wait_some_more
)
1294 do_cleanups (old_cleanups
);
1297 /* Asynchronous version of wait_for_inferior. It is called by the
1298 event loop whenever a change of state is detected on the file
1299 descriptor corresponding to the target. It can be called more than
1300 once to complete a single execution command. In such cases we need
1301 to keep the state in a global variable ASYNC_ECSS. If it is the
1302 last time that this function is called for a single execution
1303 command, then report to the user that the inferior has stopped, and
1304 do the necessary cleanups. */
1306 struct execution_control_state async_ecss
;
1307 struct execution_control_state
*async_ecs
;
1310 fetch_inferior_event (client_data
)
1313 static struct cleanup
*old_cleanups
;
1315 async_ecs
= &async_ecss
;
1317 if (!async_ecs
->wait_some_more
)
1319 old_cleanups
= make_exec_cleanup (delete_breakpoint_current_contents
,
1320 &step_resume_breakpoint
);
1321 make_exec_cleanup (delete_breakpoint_current_contents
,
1322 &through_sigtramp_breakpoint
);
1324 /* Fill in with reasonable starting values. */
1325 init_execution_control_state (async_ecs
);
1327 thread_step_needed
= 0;
1329 /* We'll update this if & when we switch to a new thread. */
1330 previous_inferior_pid
= inferior_pid
;
1332 overlay_cache_invalid
= 1;
1334 /* We have to invalidate the registers BEFORE calling target_wait
1335 because they can be loaded from the target while in target_wait.
1336 This makes remote debugging a bit more efficient for those
1337 targets that provide critical registers as part of their normal
1338 status mechanism. */
1340 registers_changed ();
1343 if (target_wait_hook
)
1344 async_ecs
->pid
= target_wait_hook (async_ecs
->waiton_pid
, async_ecs
->wp
);
1346 async_ecs
->pid
= target_wait (async_ecs
->waiton_pid
, async_ecs
->wp
);
1348 /* Now figure out what to do with the result of the result. */
1349 handle_inferior_event (async_ecs
);
1351 if (!async_ecs
->wait_some_more
)
1353 /* Do only the cleanups that have been added by this
1354 function. Let the continuations for the commands do the rest,
1355 if there are any. */
1356 do_exec_cleanups (old_cleanups
);
1358 if (step_multi
&& stop_step
)
1359 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1361 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1365 /* Prepare an execution control state for looping through a
1366 wait_for_inferior-type loop. */
1369 init_execution_control_state (struct execution_control_state
*ecs
)
1371 /* ecs->another_trap? */
1372 ecs
->random_signal
= 0;
1373 ecs
->remove_breakpoints_on_following_step
= 0;
1374 ecs
->handling_longjmp
= 0; /* FIXME */
1375 ecs
->update_step_sp
= 0;
1376 ecs
->stepping_through_solib_after_catch
= 0;
1377 ecs
->stepping_through_solib_catchpoints
= NULL
;
1378 ecs
->enable_hw_watchpoints_after_wait
= 0;
1379 ecs
->stepping_through_sigtramp
= 0;
1380 ecs
->sal
= find_pc_line (prev_pc
, 0);
1381 ecs
->current_line
= ecs
->sal
.line
;
1382 ecs
->current_symtab
= ecs
->sal
.symtab
;
1383 ecs
->infwait_state
= infwait_normal_state
;
1384 ecs
->waiton_pid
= -1;
1385 ecs
->wp
= &(ecs
->ws
);
1388 /* Call this function before setting step_resume_breakpoint, as a
1389 sanity check. There should never be more than one step-resume
1390 breakpoint per thread, so we should never be setting a new
1391 step_resume_breakpoint when one is already active. */
1393 check_for_old_step_resume_breakpoint (void)
1395 if (step_resume_breakpoint
)
1396 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1399 /* Given an execution control state that has been freshly filled in
1400 by an event from the inferior, figure out what it means and take
1401 appropriate action. */
1404 handle_inferior_event (struct execution_control_state
*ecs
)
1407 int stepped_after_stopped_by_watchpoint
;
1409 /* Keep this extra brace for now, minimizes diffs. */
1411 switch (ecs
->infwait_state
)
1413 case infwait_normal_state
:
1414 /* Since we've done a wait, we have a new event. Don't
1415 carry over any expectations about needing to step over a
1417 thread_step_needed
= 0;
1419 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1420 is serviced in this loop, below. */
1421 if (ecs
->enable_hw_watchpoints_after_wait
)
1423 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid
);
1424 ecs
->enable_hw_watchpoints_after_wait
= 0;
1426 stepped_after_stopped_by_watchpoint
= 0;
1429 case infwait_thread_hop_state
:
1430 insert_breakpoints ();
1432 /* We need to restart all the threads now,
1433 * unles we're running in scheduler-locked mode.
1434 * FIXME: shouldn't we look at currently_stepping ()?
1436 if (scheduler_mode
== schedlock_on
)
1437 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1439 target_resume (-1, 0, TARGET_SIGNAL_0
);
1440 ecs
->infwait_state
= infwait_normal_state
;
1441 prepare_to_wait (ecs
);
1444 case infwait_nullified_state
:
1447 case infwait_nonstep_watch_state
:
1448 insert_breakpoints ();
1450 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1451 handle things like signals arriving and other things happening
1452 in combination correctly? */
1453 stepped_after_stopped_by_watchpoint
= 1;
1456 ecs
->infwait_state
= infwait_normal_state
;
1458 flush_cached_frames ();
1460 /* If it's a new process, add it to the thread database */
1462 ecs
->new_thread_event
= ((ecs
->pid
!= inferior_pid
) && !in_thread_list (ecs
->pid
));
1464 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1465 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1466 && ecs
->new_thread_event
)
1468 add_thread (ecs
->pid
);
1471 ui_out_text (uiout
, "[New ");
1472 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->pid
));
1473 ui_out_text (uiout
, "]\n");
1475 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs
->pid
));
1479 /* NOTE: This block is ONLY meant to be invoked in case of a
1480 "thread creation event"! If it is invoked for any other
1481 sort of event (such as a new thread landing on a breakpoint),
1482 the event will be discarded, which is almost certainly
1485 To avoid this, the low-level module (eg. target_wait)
1486 should call in_thread_list and add_thread, so that the
1487 new thread is known by the time we get here. */
1489 /* We may want to consider not doing a resume here in order
1490 to give the user a chance to play with the new thread.
1491 It might be good to make that a user-settable option. */
1493 /* At this point, all threads are stopped (happens
1494 automatically in either the OS or the native code).
1495 Therefore we need to continue all threads in order to
1498 target_resume (-1, 0, TARGET_SIGNAL_0
);
1499 prepare_to_wait (ecs
);
1504 switch (ecs
->ws
.kind
)
1506 case TARGET_WAITKIND_LOADED
:
1507 /* Ignore gracefully during startup of the inferior, as it
1508 might be the shell which has just loaded some objects,
1509 otherwise add the symbols for the newly loaded objects. */
1511 if (!stop_soon_quietly
)
1513 /* Remove breakpoints, SOLIB_ADD might adjust
1514 breakpoint addresses via breakpoint_re_set. */
1515 if (breakpoints_inserted
)
1516 remove_breakpoints ();
1518 /* Check for any newly added shared libraries if we're
1519 supposed to be adding them automatically. */
1522 /* Switch terminal for any messages produced by
1523 breakpoint_re_set. */
1524 target_terminal_ours_for_output ();
1525 SOLIB_ADD (NULL
, 0, NULL
);
1526 target_terminal_inferior ();
1529 /* Reinsert breakpoints and continue. */
1530 if (breakpoints_inserted
)
1531 insert_breakpoints ();
1534 resume (0, TARGET_SIGNAL_0
);
1535 prepare_to_wait (ecs
);
1538 case TARGET_WAITKIND_SPURIOUS
:
1539 resume (0, TARGET_SIGNAL_0
);
1540 prepare_to_wait (ecs
);
1543 case TARGET_WAITKIND_EXITED
:
1544 target_terminal_ours (); /* Must do this before mourn anyway */
1545 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1547 /* Record the exit code in the convenience variable $_exitcode, so
1548 that the user can inspect this again later. */
1549 set_internalvar (lookup_internalvar ("_exitcode"),
1550 value_from_longest (builtin_type_int
,
1551 (LONGEST
) ecs
->ws
.value
.integer
));
1552 gdb_flush (gdb_stdout
);
1553 target_mourn_inferior ();
1554 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P */
1555 stop_print_frame
= 0;
1556 stop_stepping (ecs
);
1559 case TARGET_WAITKIND_SIGNALLED
:
1560 stop_print_frame
= 0;
1561 stop_signal
= ecs
->ws
.value
.sig
;
1562 target_terminal_ours (); /* Must do this before mourn anyway */
1564 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1565 reach here unless the inferior is dead. However, for years
1566 target_kill() was called here, which hints that fatal signals aren't
1567 really fatal on some systems. If that's true, then some changes
1569 target_mourn_inferior ();
1571 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1572 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P */
1573 stop_stepping (ecs
);
1576 /* The following are the only cases in which we keep going;
1577 the above cases end in a continue or goto. */
1578 case TARGET_WAITKIND_FORKED
:
1579 stop_signal
= TARGET_SIGNAL_TRAP
;
1580 pending_follow
.kind
= ecs
->ws
.kind
;
1582 /* Ignore fork events reported for the parent; we're only
1583 interested in reacting to forks of the child. Note that
1584 we expect the child's fork event to be available if we
1585 waited for it now. */
1586 if (inferior_pid
== ecs
->pid
)
1588 pending_follow
.fork_event
.saw_parent_fork
= 1;
1589 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1590 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1591 prepare_to_wait (ecs
);
1596 pending_follow
.fork_event
.saw_child_fork
= 1;
1597 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1598 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1601 stop_pc
= read_pc_pid (ecs
->pid
);
1602 ecs
->saved_inferior_pid
= inferior_pid
;
1603 inferior_pid
= ecs
->pid
;
1604 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1605 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1606 inferior_pid
= ecs
->saved_inferior_pid
;
1607 goto process_event_stop_test
;
1609 /* If this a platform which doesn't allow a debugger to touch a
1610 vfork'd inferior until after it exec's, then we'd best keep
1611 our fingers entirely off the inferior, other than continuing
1612 it. This has the unfortunate side-effect that catchpoints
1613 of vforks will be ignored. But since the platform doesn't
1614 allow the inferior be touched at vfork time, there's really
1616 case TARGET_WAITKIND_VFORKED
:
1617 stop_signal
= TARGET_SIGNAL_TRAP
;
1618 pending_follow
.kind
= ecs
->ws
.kind
;
1620 /* Is this a vfork of the parent? If so, then give any
1621 vfork catchpoints a chance to trigger now. (It's
1622 dangerous to do so if the child canot be touched until
1623 it execs, and the child has not yet exec'd. We probably
1624 should warn the user to that effect when the catchpoint
1626 if (ecs
->pid
== inferior_pid
)
1628 pending_follow
.fork_event
.saw_parent_fork
= 1;
1629 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1630 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1633 /* If we've seen the child's vfork event but cannot really touch
1634 the child until it execs, then we must continue the child now.
1635 Else, give any vfork catchpoints a chance to trigger now. */
1638 pending_follow
.fork_event
.saw_child_fork
= 1;
1639 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1640 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1641 target_post_startup_inferior (pending_follow
.fork_event
.child_pid
);
1642 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1643 if (follow_vfork_when_exec
)
1645 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1646 prepare_to_wait (ecs
);
1651 stop_pc
= read_pc ();
1652 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1653 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1654 goto process_event_stop_test
;
1656 case TARGET_WAITKIND_EXECD
:
1657 stop_signal
= TARGET_SIGNAL_TRAP
;
1659 /* Is this a target which reports multiple exec events per actual
1660 call to exec()? (HP-UX using ptrace does, for example.) If so,
1661 ignore all but the last one. Just resume the exec'r, and wait
1662 for the next exec event. */
1663 if (inferior_ignoring_leading_exec_events
)
1665 inferior_ignoring_leading_exec_events
--;
1666 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1667 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.parent_pid
);
1668 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1669 prepare_to_wait (ecs
);
1672 inferior_ignoring_leading_exec_events
=
1673 target_reported_exec_events_per_exec_call () - 1;
1675 pending_follow
.execd_pathname
=
1676 savestring (ecs
->ws
.value
.execd_pathname
,
1677 strlen (ecs
->ws
.value
.execd_pathname
));
1679 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1680 child of a vfork exec?
1682 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1683 HP-UX, events associated with a vforking inferior come in
1684 threes: a vfork event for the child (always first), followed
1685 a vfork event for the parent and an exec event for the child.
1686 The latter two can come in either order.
1688 If we get the parent vfork event first, life's good: We follow
1689 either the parent or child, and then the child's exec event is
1692 But if we get the child's exec event first, then we delay
1693 responding to it until we handle the parent's vfork. Because,
1694 otherwise we can't satisfy a "catch vfork". */
1695 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1697 pending_follow
.fork_event
.saw_child_exec
= 1;
1699 /* On some targets, the child must be resumed before
1700 the parent vfork event is delivered. A single-step
1702 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1703 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1704 /* We expect the parent vfork event to be available now. */
1705 prepare_to_wait (ecs
);
1709 /* This causes the eventpoints and symbol table to be reset. Must
1710 do this now, before trying to determine whether to stop. */
1711 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
1712 free (pending_follow
.execd_pathname
);
1714 stop_pc
= read_pc_pid (ecs
->pid
);
1715 ecs
->saved_inferior_pid
= inferior_pid
;
1716 inferior_pid
= ecs
->pid
;
1717 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1718 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1719 inferior_pid
= ecs
->saved_inferior_pid
;
1720 goto process_event_stop_test
;
1722 /* These syscall events are returned on HP-UX, as part of its
1723 implementation of page-protection-based "hardware" watchpoints.
1724 HP-UX has unfortunate interactions between page-protections and
1725 some system calls. Our solution is to disable hardware watches
1726 when a system call is entered, and reenable them when the syscall
1727 completes. The downside of this is that we may miss the precise
1728 point at which a watched piece of memory is modified. "Oh well."
1730 Note that we may have multiple threads running, which may each
1731 enter syscalls at roughly the same time. Since we don't have a
1732 good notion currently of whether a watched piece of memory is
1733 thread-private, we'd best not have any page-protections active
1734 when any thread is in a syscall. Thus, we only want to reenable
1735 hardware watches when no threads are in a syscall.
1737 Also, be careful not to try to gather much state about a thread
1738 that's in a syscall. It's frequently a losing proposition. */
1739 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1740 number_of_threads_in_syscalls
++;
1741 if (number_of_threads_in_syscalls
== 1)
1743 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid
);
1745 resume (0, TARGET_SIGNAL_0
);
1746 prepare_to_wait (ecs
);
1749 /* Before examining the threads further, step this thread to
1750 get it entirely out of the syscall. (We get notice of the
1751 event when the thread is just on the verge of exiting a
1752 syscall. Stepping one instruction seems to get it back
1755 Note that although the logical place to reenable h/w watches
1756 is here, we cannot. We cannot reenable them before stepping
1757 the thread (this causes the next wait on the thread to hang).
1759 Nor can we enable them after stepping until we've done a wait.
1760 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1761 here, which will be serviced immediately after the target
1763 case TARGET_WAITKIND_SYSCALL_RETURN
:
1764 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1766 if (number_of_threads_in_syscalls
> 0)
1768 number_of_threads_in_syscalls
--;
1769 ecs
->enable_hw_watchpoints_after_wait
=
1770 (number_of_threads_in_syscalls
== 0);
1772 prepare_to_wait (ecs
);
1775 case TARGET_WAITKIND_STOPPED
:
1776 stop_signal
= ecs
->ws
.value
.sig
;
1779 /* We had an event in the inferior, but we are not interested
1780 in handling it at this level. The lower layers have already
1781 done what needs to be done, if anything. This case can
1782 occur only when the target is async or extended-async. One
1783 of the circumstamces for this to happen is when the
1784 inferior produces output for the console. The inferior has
1785 not stopped, and we are ignoring the event. */
1786 case TARGET_WAITKIND_IGNORE
:
1787 ecs
->wait_some_more
= 1;
1791 /* We may want to consider not doing a resume here in order to give
1792 the user a chance to play with the new thread. It might be good
1793 to make that a user-settable option. */
1795 /* At this point, all threads are stopped (happens automatically in
1796 either the OS or the native code). Therefore we need to continue
1797 all threads in order to make progress. */
1798 if (ecs
->new_thread_event
)
1800 target_resume (-1, 0, TARGET_SIGNAL_0
);
1801 prepare_to_wait (ecs
);
1805 stop_pc
= read_pc_pid (ecs
->pid
);
1807 /* See if a thread hit a thread-specific breakpoint that was meant for
1808 another thread. If so, then step that thread past the breakpoint,
1811 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1813 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1814 ecs
->random_signal
= 0;
1815 else if (breakpoints_inserted
1816 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1818 ecs
->random_signal
= 0;
1819 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1824 /* Saw a breakpoint, but it was hit by the wrong thread.
1826 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->pid
);
1828 remove_status
= remove_breakpoints ();
1829 /* Did we fail to remove breakpoints? If so, try
1830 to set the PC past the bp. (There's at least
1831 one situation in which we can fail to remove
1832 the bp's: On HP-UX's that use ttrace, we can't
1833 change the address space of a vforking child
1834 process until the child exits (well, okay, not
1835 then either :-) or execs. */
1836 if (remove_status
!= 0)
1838 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->pid
);
1842 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1843 /* FIXME: What if a signal arrives instead of the
1844 single-step happening? */
1846 ecs
->waiton_pid
= ecs
->pid
;
1847 ecs
->wp
= &(ecs
->ws
);
1848 ecs
->infwait_state
= infwait_thread_hop_state
;
1849 prepare_to_wait (ecs
);
1853 /* We need to restart all the threads now,
1854 * unles we're running in scheduler-locked mode.
1855 * FIXME: shouldn't we look at currently_stepping ()?
1857 if (scheduler_mode
== schedlock_on
)
1858 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1860 target_resume (-1, 0, TARGET_SIGNAL_0
);
1861 prepare_to_wait (ecs
);
1866 /* This breakpoint matches--either it is the right
1867 thread or it's a generic breakpoint for all threads.
1868 Remember that we'll need to step just _this_ thread
1869 on any following user continuation! */
1870 thread_step_needed
= 1;
1875 ecs
->random_signal
= 1;
1877 /* See if something interesting happened to the non-current thread. If
1878 so, then switch to that thread, and eventually give control back to
1881 Note that if there's any kind of pending follow (i.e., of a fork,
1882 vfork or exec), we don't want to do this now. Rather, we'll let
1883 the next resume handle it. */
1884 if ((ecs
->pid
!= inferior_pid
) &&
1885 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1889 /* If it's a random signal for a non-current thread, notify user
1890 if he's expressed an interest. */
1891 if (ecs
->random_signal
1892 && signal_print
[stop_signal
])
1894 /* ??rehrauer: I don't understand the rationale for this code. If the
1895 inferior will stop as a result of this signal, then the act of handling
1896 the stop ought to print a message that's couches the stoppage in user
1897 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1898 won't stop as a result of the signal -- i.e., if the signal is merely
1899 a side-effect of something GDB's doing "under the covers" for the
1900 user, such as stepping threads over a breakpoint they shouldn't stop
1901 for -- then the message seems to be a serious annoyance at best.
1903 For now, remove the message altogether. */
1906 target_terminal_ours_for_output ();
1907 printf_filtered ("\nProgram received signal %s, %s.\n",
1908 target_signal_to_name (stop_signal
),
1909 target_signal_to_string (stop_signal
));
1910 gdb_flush (gdb_stdout
);
1914 /* If it's not SIGTRAP and not a signal we want to stop for, then
1915 continue the thread. */
1917 if (stop_signal
!= TARGET_SIGNAL_TRAP
1918 && !signal_stop
[stop_signal
])
1921 target_terminal_inferior ();
1923 /* Clear the signal if it should not be passed. */
1924 if (signal_program
[stop_signal
] == 0)
1925 stop_signal
= TARGET_SIGNAL_0
;
1927 target_resume (ecs
->pid
, 0, stop_signal
);
1928 prepare_to_wait (ecs
);
1932 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1933 and fall into the rest of wait_for_inferior(). */
1935 /* Caution: it may happen that the new thread (or the old one!)
1936 is not in the thread list. In this case we must not attempt
1937 to "switch context", or we run the risk that our context may
1938 be lost. This may happen as a result of the target module
1939 mishandling thread creation. */
1941 if (in_thread_list (inferior_pid
) && in_thread_list (ecs
->pid
))
1942 { /* Perform infrun state context switch: */
1943 /* Save infrun state for the old thread. */
1944 save_infrun_state (inferior_pid
, prev_pc
,
1945 prev_func_start
, prev_func_name
,
1946 trap_expected
, step_resume_breakpoint
,
1947 through_sigtramp_breakpoint
,
1948 step_range_start
, step_range_end
,
1949 step_frame_address
, ecs
->handling_longjmp
,
1951 ecs
->stepping_through_solib_after_catch
,
1952 ecs
->stepping_through_solib_catchpoints
,
1953 ecs
->stepping_through_sigtramp
);
1955 /* Load infrun state for the new thread. */
1956 load_infrun_state (ecs
->pid
, &prev_pc
,
1957 &prev_func_start
, &prev_func_name
,
1958 &trap_expected
, &step_resume_breakpoint
,
1959 &through_sigtramp_breakpoint
,
1960 &step_range_start
, &step_range_end
,
1961 &step_frame_address
, &ecs
->handling_longjmp
,
1963 &ecs
->stepping_through_solib_after_catch
,
1964 &ecs
->stepping_through_solib_catchpoints
,
1965 &ecs
->stepping_through_sigtramp
);
1968 inferior_pid
= ecs
->pid
;
1971 context_hook (pid_to_thread_id (ecs
->pid
));
1973 flush_cached_frames ();
1976 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1978 /* Pull the single step breakpoints out of the target. */
1979 SOFTWARE_SINGLE_STEP (0, 0);
1980 singlestep_breakpoints_inserted_p
= 0;
1983 /* If PC is pointing at a nullified instruction, then step beyond
1984 it so that the user won't be confused when GDB appears to be ready
1987 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1988 if (INSTRUCTION_NULLIFIED
)
1990 registers_changed ();
1991 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1993 /* We may have received a signal that we want to pass to
1994 the inferior; therefore, we must not clobber the waitstatus
1997 ecs
->infwait_state
= infwait_nullified_state
;
1998 ecs
->waiton_pid
= ecs
->pid
;
1999 ecs
->wp
= &(ecs
->tmpstatus
);
2000 prepare_to_wait (ecs
);
2004 /* It may not be necessary to disable the watchpoint to stop over
2005 it. For example, the PA can (with some kernel cooperation)
2006 single step over a watchpoint without disabling the watchpoint. */
2007 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2010 prepare_to_wait (ecs
);
2014 /* It is far more common to need to disable a watchpoint to step
2015 the inferior over it. FIXME. What else might a debug
2016 register or page protection watchpoint scheme need here? */
2017 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2019 /* At this point, we are stopped at an instruction which has
2020 attempted to write to a piece of memory under control of
2021 a watchpoint. The instruction hasn't actually executed
2022 yet. If we were to evaluate the watchpoint expression
2023 now, we would get the old value, and therefore no change
2024 would seem to have occurred.
2026 In order to make watchpoints work `right', we really need
2027 to complete the memory write, and then evaluate the
2028 watchpoint expression. The following code does that by
2029 removing the watchpoint (actually, all watchpoints and
2030 breakpoints), single-stepping the target, re-inserting
2031 watchpoints, and then falling through to let normal
2032 single-step processing handle proceed. Since this
2033 includes evaluating watchpoints, things will come to a
2034 stop in the correct manner. */
2036 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
2038 remove_breakpoints ();
2039 registers_changed ();
2040 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
); /* Single step */
2042 ecs
->waiton_pid
= ecs
->pid
;
2043 ecs
->wp
= &(ecs
->ws
);
2044 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2045 prepare_to_wait (ecs
);
2049 /* It may be possible to simply continue after a watchpoint. */
2050 if (HAVE_CONTINUABLE_WATCHPOINT
)
2051 STOPPED_BY_WATCHPOINT (ecs
->ws
);
2053 ecs
->stop_func_start
= 0;
2054 ecs
->stop_func_end
= 0;
2055 ecs
->stop_func_name
= 0;
2056 /* Don't care about return value; stop_func_start and stop_func_name
2057 will both be 0 if it doesn't work. */
2058 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2059 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2060 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
2061 ecs
->another_trap
= 0;
2062 bpstat_clear (&stop_bpstat
);
2064 stop_stack_dummy
= 0;
2065 stop_print_frame
= 1;
2066 ecs
->random_signal
= 0;
2067 stopped_by_random_signal
= 0;
2068 breakpoints_failed
= 0;
2070 /* Look at the cause of the stop, and decide what to do.
2071 The alternatives are:
2072 1) break; to really stop and return to the debugger,
2073 2) drop through to start up again
2074 (set ecs->another_trap to 1 to single step once)
2075 3) set ecs->random_signal to 1, and the decision between 1 and 2
2076 will be made according to the signal handling tables. */
2078 /* First, distinguish signals caused by the debugger from signals
2079 that have to do with the program's own actions.
2080 Note that breakpoint insns may cause SIGTRAP or SIGILL
2081 or SIGEMT, depending on the operating system version.
2082 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2083 and change it to SIGTRAP. */
2085 if (stop_signal
== TARGET_SIGNAL_TRAP
2086 || (breakpoints_inserted
&&
2087 (stop_signal
== TARGET_SIGNAL_ILL
2088 || stop_signal
== TARGET_SIGNAL_EMT
2090 || stop_soon_quietly
)
2092 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2094 stop_print_frame
= 0;
2095 stop_stepping (ecs
);
2098 if (stop_soon_quietly
)
2100 stop_stepping (ecs
);
2104 /* Don't even think about breakpoints
2105 if just proceeded over a breakpoint.
2107 However, if we are trying to proceed over a breakpoint
2108 and end up in sigtramp, then through_sigtramp_breakpoint
2109 will be set and we should check whether we've hit the
2111 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2112 && through_sigtramp_breakpoint
== NULL
)
2113 bpstat_clear (&stop_bpstat
);
2116 /* See if there is a breakpoint at the current PC. */
2117 stop_bpstat
= bpstat_stop_status
2119 /* Pass TRUE if our reason for stopping is something other
2120 than hitting a breakpoint. We do this by checking that
2121 1) stepping is going on and 2) we didn't hit a breakpoint
2122 in a signal handler without an intervening stop in
2123 sigtramp, which is detected by a new stack pointer value
2124 below any usual function calling stack adjustments. */
2125 (currently_stepping (ecs
)
2127 && INNER_THAN (read_sp (), (step_sp
- 16))))
2129 /* Following in case break condition called a
2131 stop_print_frame
= 1;
2134 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2136 = !(bpstat_explains_signal (stop_bpstat
)
2138 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2139 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2140 FRAME_FP (get_current_frame ())))
2141 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2146 = !(bpstat_explains_signal (stop_bpstat
)
2147 /* End of a stack dummy. Some systems (e.g. Sony
2148 news) give another signal besides SIGTRAP, so
2149 check here as well as above. */
2150 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2151 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2152 FRAME_FP (get_current_frame ())))
2154 if (!ecs
->random_signal
)
2155 stop_signal
= TARGET_SIGNAL_TRAP
;
2159 /* When we reach this point, we've pretty much decided
2160 that the reason for stopping must've been a random
2161 (unexpected) signal. */
2164 ecs
->random_signal
= 1;
2165 /* If a fork, vfork or exec event was seen, then there are two
2166 possible responses we can make:
2168 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2169 then we must stop now and issue a prompt. We will resume
2170 the inferior when the user tells us to.
2171 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2172 then we must resume the inferior now and keep checking.
2174 In either case, we must take appropriate steps to "follow" the
2175 the fork/vfork/exec when the inferior is resumed. For example,
2176 if follow-fork-mode is "child", then we must detach from the
2177 parent inferior and follow the new child inferior.
2179 In either case, setting pending_follow causes the next resume()
2180 to take the appropriate following action. */
2181 process_event_stop_test
:
2182 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2184 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2187 stop_signal
= TARGET_SIGNAL_0
;
2192 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2194 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2196 stop_signal
= TARGET_SIGNAL_0
;
2201 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2203 pending_follow
.kind
= ecs
->ws
.kind
;
2204 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2207 stop_signal
= TARGET_SIGNAL_0
;
2213 /* For the program's own signals, act according to
2214 the signal handling tables. */
2216 if (ecs
->random_signal
)
2218 /* Signal not for debugging purposes. */
2221 stopped_by_random_signal
= 1;
2223 if (signal_print
[stop_signal
])
2226 target_terminal_ours_for_output ();
2227 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2229 if (signal_stop
[stop_signal
])
2231 stop_stepping (ecs
);
2234 /* If not going to stop, give terminal back
2235 if we took it away. */
2237 target_terminal_inferior ();
2239 /* Clear the signal if it should not be passed. */
2240 if (signal_program
[stop_signal
] == 0)
2241 stop_signal
= TARGET_SIGNAL_0
;
2243 /* I'm not sure whether this needs to be check_sigtramp2 or
2244 whether it could/should be keep_going.
2246 This used to jump to step_over_function if we are stepping,
2249 Suppose the user does a `next' over a function call, and while
2250 that call is in progress, the inferior receives a signal for
2251 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2252 that case, when we reach this point, there is already a
2253 step-resume breakpoint established, right where it should be:
2254 immediately after the function call the user is "next"-ing
2255 over. If we call step_over_function now, two bad things
2258 - we'll create a new breakpoint, at wherever the current
2259 frame's return address happens to be. That could be
2260 anywhere, depending on what function call happens to be on
2261 the top of the stack at that point. Point is, it's probably
2262 not where we need it.
2264 - the existing step-resume breakpoint (which is at the correct
2265 address) will get orphaned: step_resume_breakpoint will point
2266 to the new breakpoint, and the old step-resume breakpoint
2267 will never be cleaned up.
2269 The old behavior was meant to help HP-UX single-step out of
2270 sigtramps. It would place the new breakpoint at prev_pc, which
2271 was certainly wrong. I don't know the details there, so fixing
2272 this probably breaks that. As with anything else, it's up to
2273 the HP-UX maintainer to furnish a fix that doesn't break other
2274 platforms. --JimB, 20 May 1999 */
2275 check_sigtramp2 (ecs
);
2280 /* Handle cases caused by hitting a breakpoint. */
2282 CORE_ADDR jmp_buf_pc
;
2283 struct bpstat_what what
;
2285 what
= bpstat_what (stop_bpstat
);
2287 if (what
.call_dummy
)
2289 stop_stack_dummy
= 1;
2291 trap_expected_after_continue
= 1;
2295 switch (what
.main_action
)
2297 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2298 /* If we hit the breakpoint at longjmp, disable it for the
2299 duration of this command. Then, install a temporary
2300 breakpoint at the target of the jmp_buf. */
2301 disable_longjmp_breakpoint ();
2302 remove_breakpoints ();
2303 breakpoints_inserted
= 0;
2304 if (!GET_LONGJMP_TARGET (&jmp_buf_pc
))
2310 /* Need to blow away step-resume breakpoint, as it
2311 interferes with us */
2312 if (step_resume_breakpoint
!= NULL
)
2314 delete_breakpoint (step_resume_breakpoint
);
2315 step_resume_breakpoint
= NULL
;
2317 /* Not sure whether we need to blow this away too, but probably
2318 it is like the step-resume breakpoint. */
2319 if (through_sigtramp_breakpoint
!= NULL
)
2321 delete_breakpoint (through_sigtramp_breakpoint
);
2322 through_sigtramp_breakpoint
= NULL
;
2326 /* FIXME - Need to implement nested temporary breakpoints */
2327 if (step_over_calls
> 0)
2328 set_longjmp_resume_breakpoint (jmp_buf_pc
,
2329 get_current_frame ());
2332 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2333 ecs
->handling_longjmp
= 1; /* FIXME */
2337 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2338 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2339 remove_breakpoints ();
2340 breakpoints_inserted
= 0;
2342 /* FIXME - Need to implement nested temporary breakpoints */
2344 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2345 step_frame_address
)))
2347 ecs
->another_trap
= 1;
2352 disable_longjmp_breakpoint ();
2353 ecs
->handling_longjmp
= 0; /* FIXME */
2354 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2356 /* else fallthrough */
2358 case BPSTAT_WHAT_SINGLE
:
2359 if (breakpoints_inserted
)
2361 thread_step_needed
= 1;
2362 remove_breakpoints ();
2364 breakpoints_inserted
= 0;
2365 ecs
->another_trap
= 1;
2366 /* Still need to check other stuff, at least the case
2367 where we are stepping and step out of the right range. */
2370 case BPSTAT_WHAT_STOP_NOISY
:
2371 stop_print_frame
= 1;
2373 /* We are about to nuke the step_resume_breakpoint and
2374 through_sigtramp_breakpoint via the cleanup chain, so
2375 no need to worry about it here. */
2377 stop_stepping (ecs
);
2380 case BPSTAT_WHAT_STOP_SILENT
:
2381 stop_print_frame
= 0;
2383 /* We are about to nuke the step_resume_breakpoint and
2384 through_sigtramp_breakpoint via the cleanup chain, so
2385 no need to worry about it here. */
2387 stop_stepping (ecs
);
2390 case BPSTAT_WHAT_STEP_RESUME
:
2391 /* This proably demands a more elegant solution, but, yeah
2394 This function's use of the simple variable
2395 step_resume_breakpoint doesn't seem to accomodate
2396 simultaneously active step-resume bp's, although the
2397 breakpoint list certainly can.
2399 If we reach here and step_resume_breakpoint is already
2400 NULL, then apparently we have multiple active
2401 step-resume bp's. We'll just delete the breakpoint we
2402 stopped at, and carry on.
2404 Correction: what the code currently does is delete a
2405 step-resume bp, but it makes no effort to ensure that
2406 the one deleted is the one currently stopped at. MVS */
2408 if (step_resume_breakpoint
== NULL
)
2410 step_resume_breakpoint
=
2411 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2413 delete_breakpoint (step_resume_breakpoint
);
2414 step_resume_breakpoint
= NULL
;
2417 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2418 if (through_sigtramp_breakpoint
)
2419 delete_breakpoint (through_sigtramp_breakpoint
);
2420 through_sigtramp_breakpoint
= NULL
;
2422 /* If were waiting for a trap, hitting the step_resume_break
2423 doesn't count as getting it. */
2425 ecs
->another_trap
= 1;
2428 case BPSTAT_WHAT_CHECK_SHLIBS
:
2429 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2432 /* Remove breakpoints, we eventually want to step over the
2433 shlib event breakpoint, and SOLIB_ADD might adjust
2434 breakpoint addresses via breakpoint_re_set. */
2435 if (breakpoints_inserted
)
2436 remove_breakpoints ();
2437 breakpoints_inserted
= 0;
2439 /* Check for any newly added shared libraries if we're
2440 supposed to be adding them automatically. */
2443 /* Switch terminal for any messages produced by
2444 breakpoint_re_set. */
2445 target_terminal_ours_for_output ();
2446 SOLIB_ADD (NULL
, 0, NULL
);
2447 target_terminal_inferior ();
2450 /* Try to reenable shared library breakpoints, additional
2451 code segments in shared libraries might be mapped in now. */
2452 re_enable_breakpoints_in_shlibs ();
2454 /* If requested, stop when the dynamic linker notifies
2455 gdb of events. This allows the user to get control
2456 and place breakpoints in initializer routines for
2457 dynamically loaded objects (among other things). */
2458 if (stop_on_solib_events
)
2460 stop_stepping (ecs
);
2464 /* If we stopped due to an explicit catchpoint, then the
2465 (see above) call to SOLIB_ADD pulled in any symbols
2466 from a newly-loaded library, if appropriate.
2468 We do want the inferior to stop, but not where it is
2469 now, which is in the dynamic linker callback. Rather,
2470 we would like it stop in the user's program, just after
2471 the call that caused this catchpoint to trigger. That
2472 gives the user a more useful vantage from which to
2473 examine their program's state. */
2474 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2476 /* ??rehrauer: If I could figure out how to get the
2477 right return PC from here, we could just set a temp
2478 breakpoint and resume. I'm not sure we can without
2479 cracking open the dld's shared libraries and sniffing
2480 their unwind tables and text/data ranges, and that's
2481 not a terribly portable notion.
2483 Until that time, we must step the inferior out of the
2484 dld callback, and also out of the dld itself (and any
2485 code or stubs in libdld.sl, such as "shl_load" and
2486 friends) until we reach non-dld code. At that point,
2487 we can stop stepping. */
2488 bpstat_get_triggered_catchpoints (stop_bpstat
,
2489 &ecs
->stepping_through_solib_catchpoints
);
2490 ecs
->stepping_through_solib_after_catch
= 1;
2492 /* Be sure to lift all breakpoints, so the inferior does
2493 actually step past this point... */
2494 ecs
->another_trap
= 1;
2499 /* We want to step over this breakpoint, then keep going. */
2500 ecs
->another_trap
= 1;
2507 case BPSTAT_WHAT_LAST
:
2508 /* Not a real code, but listed here to shut up gcc -Wall. */
2510 case BPSTAT_WHAT_KEEP_CHECKING
:
2515 /* We come here if we hit a breakpoint but should not
2516 stop for it. Possibly we also were stepping
2517 and should stop for that. So fall through and
2518 test for stepping. But, if not stepping,
2521 /* Are we stepping to get the inferior out of the dynamic
2522 linker's hook (and possibly the dld itself) after catching
2524 if (ecs
->stepping_through_solib_after_catch
)
2526 #if defined(SOLIB_ADD)
2527 /* Have we reached our destination? If not, keep going. */
2528 if (SOLIB_IN_DYNAMIC_LINKER (ecs
->pid
, stop_pc
))
2530 ecs
->another_trap
= 1;
2535 /* Else, stop and report the catchpoint(s) whose triggering
2536 caused us to begin stepping. */
2537 ecs
->stepping_through_solib_after_catch
= 0;
2538 bpstat_clear (&stop_bpstat
);
2539 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2540 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2541 stop_print_frame
= 1;
2542 stop_stepping (ecs
);
2546 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2548 /* This is the old way of detecting the end of the stack dummy.
2549 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2550 handled above. As soon as we can test it on all of them, all
2551 architectures should define it. */
2553 /* If this is the breakpoint at the end of a stack dummy,
2554 just stop silently, unless the user was doing an si/ni, in which
2555 case she'd better know what she's doing. */
2557 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2558 FRAME_FP (get_current_frame ()))
2561 stop_print_frame
= 0;
2562 stop_stack_dummy
= 1;
2564 trap_expected_after_continue
= 1;
2566 stop_stepping (ecs
);
2571 if (step_resume_breakpoint
)
2573 /* Having a step-resume breakpoint overrides anything
2574 else having to do with stepping commands until
2575 that breakpoint is reached. */
2576 /* I'm not sure whether this needs to be check_sigtramp2 or
2577 whether it could/should be keep_going. */
2578 check_sigtramp2 (ecs
);
2583 if (step_range_end
== 0)
2585 /* Likewise if we aren't even stepping. */
2586 /* I'm not sure whether this needs to be check_sigtramp2 or
2587 whether it could/should be keep_going. */
2588 check_sigtramp2 (ecs
);
2593 /* If stepping through a line, keep going if still within it.
2595 Note that step_range_end is the address of the first instruction
2596 beyond the step range, and NOT the address of the last instruction
2598 if (stop_pc
>= step_range_start
2599 && stop_pc
< step_range_end
)
2601 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2602 So definately need to check for sigtramp here. */
2603 check_sigtramp2 (ecs
);
2608 /* We stepped out of the stepping range. */
2610 /* If we are stepping at the source level and entered the runtime
2611 loader dynamic symbol resolution code, we keep on single stepping
2612 until we exit the run time loader code and reach the callee's
2614 if (step_over_calls
< 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2616 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2618 if (pc_after_resolver
)
2620 /* Set up a step-resume breakpoint at the address
2621 indicated by SKIP_SOLIB_RESOLVER. */
2622 struct symtab_and_line sr_sal
;
2624 sr_sal
.pc
= pc_after_resolver
;
2626 check_for_old_step_resume_breakpoint ();
2627 step_resume_breakpoint
=
2628 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2629 if (breakpoints_inserted
)
2630 insert_breakpoints ();
2637 /* We can't update step_sp every time through the loop, because
2638 reading the stack pointer would slow down stepping too much.
2639 But we can update it every time we leave the step range. */
2640 ecs
->update_step_sp
= 1;
2642 /* Did we just take a signal? */
2643 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2644 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2645 && INNER_THAN (read_sp (), step_sp
))
2647 /* We've just taken a signal; go until we are back to
2648 the point where we took it and one more. */
2650 /* Note: The test above succeeds not only when we stepped
2651 into a signal handler, but also when we step past the last
2652 statement of a signal handler and end up in the return stub
2653 of the signal handler trampoline. To distinguish between
2654 these two cases, check that the frame is INNER_THAN the
2655 previous one below. pai/1997-09-11 */
2659 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2661 if (INNER_THAN (current_frame
, step_frame_address
))
2663 /* We have just taken a signal; go until we are back to
2664 the point where we took it and one more. */
2666 /* This code is needed at least in the following case:
2667 The user types "next" and then a signal arrives (before
2668 the "next" is done). */
2670 /* Note that if we are stopped at a breakpoint, then we need
2671 the step_resume breakpoint to override any breakpoints at
2672 the same location, so that we will still step over the
2673 breakpoint even though the signal happened. */
2674 struct symtab_and_line sr_sal
;
2677 sr_sal
.symtab
= NULL
;
2679 sr_sal
.pc
= prev_pc
;
2680 /* We could probably be setting the frame to
2681 step_frame_address; I don't think anyone thought to
2683 check_for_old_step_resume_breakpoint ();
2684 step_resume_breakpoint
=
2685 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2686 if (breakpoints_inserted
)
2687 insert_breakpoints ();
2691 /* We just stepped out of a signal handler and into
2692 its calling trampoline.
2694 Normally, we'd call step_over_function from
2695 here, but for some reason GDB can't unwind the
2696 stack correctly to find the real PC for the point
2697 user code where the signal trampoline will return
2698 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2699 But signal trampolines are pretty small stubs of
2700 code, anyway, so it's OK instead to just
2701 single-step out. Note: assuming such trampolines
2702 don't exhibit recursion on any platform... */
2703 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2704 &ecs
->stop_func_start
,
2705 &ecs
->stop_func_end
);
2706 /* Readjust stepping range */
2707 step_range_start
= ecs
->stop_func_start
;
2708 step_range_end
= ecs
->stop_func_end
;
2709 ecs
->stepping_through_sigtramp
= 1;
2714 /* If this is stepi or nexti, make sure that the stepping range
2715 gets us past that instruction. */
2716 if (step_range_end
== 1)
2717 /* FIXME: Does this run afoul of the code below which, if
2718 we step into the middle of a line, resets the stepping
2720 step_range_end
= (step_range_start
= prev_pc
) + 1;
2722 ecs
->remove_breakpoints_on_following_step
= 1;
2727 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2728 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2729 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2730 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2731 || ecs
->stop_func_name
== 0)
2733 /* It's a subroutine call. */
2735 if (step_over_calls
== 0)
2737 /* I presume that step_over_calls is only 0 when we're
2738 supposed to be stepping at the assembly language level
2739 ("stepi"). Just stop. */
2741 print_stop_reason (END_STEPPING_RANGE
, 0);
2742 stop_stepping (ecs
);
2746 if (step_over_calls
> 0 || IGNORE_HELPER_CALL (stop_pc
))
2748 /* We're doing a "next". */
2750 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2751 && INNER_THAN (step_frame_address
, read_sp()))
2752 /* We stepped out of a signal handler, and into its
2753 calling trampoline. This is misdetected as a
2754 subroutine call, but stepping over the signal
2755 trampoline isn't such a bad idea. In order to do
2756 that, we have to ignore the value in
2757 step_frame_address, since that doesn't represent the
2758 frame that'll reach when we return from the signal
2759 trampoline. Otherwise we'll probably continue to the
2760 end of the program. */
2761 step_frame_address
= 0;
2763 step_over_function (ecs
);
2768 /* If we are in a function call trampoline (a stub between
2769 the calling routine and the real function), locate the real
2770 function. That's what tells us (a) whether we want to step
2771 into it at all, and (b) what prologue we want to run to
2772 the end of, if we do step into it. */
2773 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2775 ecs
->stop_func_start
= tmp
;
2778 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2781 struct symtab_and_line xxx
;
2782 /* Why isn't this s_a_l called "sr_sal", like all of the
2783 other s_a_l's where this code is duplicated? */
2784 INIT_SAL (&xxx
); /* initialize to zeroes */
2786 xxx
.section
= find_pc_overlay (xxx
.pc
);
2787 check_for_old_step_resume_breakpoint ();
2788 step_resume_breakpoint
=
2789 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2790 insert_breakpoints ();
2796 /* If we have line number information for the function we
2797 are thinking of stepping into, step into it.
2799 If there are several symtabs at that PC (e.g. with include
2800 files), just want to know whether *any* of them have line
2801 numbers. find_pc_line handles this. */
2803 struct symtab_and_line tmp_sal
;
2805 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2806 if (tmp_sal
.line
!= 0)
2808 step_into_function (ecs
);
2812 step_over_function (ecs
);
2818 /* We've wandered out of the step range. */
2820 ecs
->sal
= find_pc_line (stop_pc
, 0);
2822 if (step_range_end
== 1)
2824 /* It is stepi or nexti. We always want to stop stepping after
2827 print_stop_reason (END_STEPPING_RANGE
, 0);
2828 stop_stepping (ecs
);
2832 /* If we're in the return path from a shared library trampoline,
2833 we want to proceed through the trampoline when stepping. */
2834 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2838 /* Determine where this trampoline returns. */
2839 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2841 /* Only proceed through if we know where it's going. */
2844 /* And put the step-breakpoint there and go until there. */
2845 struct symtab_and_line sr_sal
;
2847 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2849 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2850 /* Do not specify what the fp should be when we stop
2851 since on some machines the prologue
2852 is where the new fp value is established. */
2853 check_for_old_step_resume_breakpoint ();
2854 step_resume_breakpoint
=
2855 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2856 if (breakpoints_inserted
)
2857 insert_breakpoints ();
2859 /* Restart without fiddling with the step ranges or
2866 if (ecs
->sal
.line
== 0)
2868 /* We have no line number information. That means to stop
2869 stepping (does this always happen right after one instruction,
2870 when we do "s" in a function with no line numbers,
2871 or can this happen as a result of a return or longjmp?). */
2873 print_stop_reason (END_STEPPING_RANGE
, 0);
2874 stop_stepping (ecs
);
2878 if ((stop_pc
== ecs
->sal
.pc
)
2879 && (ecs
->current_line
!= ecs
->sal
.line
|| ecs
->current_symtab
!= ecs
->sal
.symtab
))
2881 /* We are at the start of a different line. So stop. Note that
2882 we don't stop if we step into the middle of a different line.
2883 That is said to make things like for (;;) statements work
2886 print_stop_reason (END_STEPPING_RANGE
, 0);
2887 stop_stepping (ecs
);
2891 /* We aren't done stepping.
2893 Optimize by setting the stepping range to the line.
2894 (We might not be in the original line, but if we entered a
2895 new line in mid-statement, we continue stepping. This makes
2896 things like for(;;) statements work better.) */
2898 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2900 /* If this is the last line of the function, don't keep stepping
2901 (it would probably step us out of the function).
2902 This is particularly necessary for a one-line function,
2903 in which after skipping the prologue we better stop even though
2904 we will be in mid-line. */
2906 print_stop_reason (END_STEPPING_RANGE
, 0);
2907 stop_stepping (ecs
);
2910 step_range_start
= ecs
->sal
.pc
;
2911 step_range_end
= ecs
->sal
.end
;
2912 step_frame_address
= FRAME_FP (get_current_frame ());
2913 ecs
->current_line
= ecs
->sal
.line
;
2914 ecs
->current_symtab
= ecs
->sal
.symtab
;
2916 /* In the case where we just stepped out of a function into the middle
2917 of a line of the caller, continue stepping, but step_frame_address
2918 must be modified to current frame */
2920 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2921 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2922 step_frame_address
= current_frame
;
2927 } /* extra brace, to preserve old indentation */
2930 /* Are we in the middle of stepping? */
2933 currently_stepping (struct execution_control_state
*ecs
)
2935 return ((through_sigtramp_breakpoint
== NULL
2936 && !ecs
->handling_longjmp
2937 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2939 || ecs
->stepping_through_solib_after_catch
2940 || bpstat_should_step ());
2944 check_sigtramp2 (struct execution_control_state
*ecs
)
2947 && IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2948 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2949 && INNER_THAN (read_sp (), step_sp
))
2951 /* What has happened here is that we have just stepped the
2952 inferior with a signal (because it is a signal which
2953 shouldn't make us stop), thus stepping into sigtramp.
2955 So we need to set a step_resume_break_address breakpoint and
2956 continue until we hit it, and then step. FIXME: This should
2957 be more enduring than a step_resume breakpoint; we should
2958 know that we will later need to keep going rather than
2959 re-hitting the breakpoint here (see the testsuite,
2960 gdb.base/signals.exp where it says "exceedingly difficult"). */
2962 struct symtab_and_line sr_sal
;
2964 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2965 sr_sal
.pc
= prev_pc
;
2966 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2967 /* We perhaps could set the frame if we kept track of what the
2968 frame corresponding to prev_pc was. But we don't, so don't. */
2969 through_sigtramp_breakpoint
=
2970 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2971 if (breakpoints_inserted
)
2972 insert_breakpoints ();
2974 ecs
->remove_breakpoints_on_following_step
= 1;
2975 ecs
->another_trap
= 1;
2979 /* Subroutine call with source code we should not step over. Do step
2980 to the first line of code in it. */
2983 step_into_function (struct execution_control_state
*ecs
)
2986 struct symtab_and_line sr_sal
;
2988 s
= find_pc_symtab (stop_pc
);
2989 if (s
&& s
->language
!= language_asm
)
2990 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2992 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2993 /* Use the step_resume_break to step until the end of the prologue,
2994 even if that involves jumps (as it seems to on the vax under
2996 /* If the prologue ends in the middle of a source line, continue to
2997 the end of that source line (if it is still within the function).
2998 Otherwise, just go to end of prologue. */
2999 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
3000 /* no, don't either. It skips any code that's legitimately on the
3004 && ecs
->sal
.pc
!= ecs
->stop_func_start
3005 && ecs
->sal
.end
< ecs
->stop_func_end
)
3006 ecs
->stop_func_start
= ecs
->sal
.end
;
3009 if (ecs
->stop_func_start
== stop_pc
)
3011 /* We are already there: stop now. */
3013 print_stop_reason (END_STEPPING_RANGE
, 0);
3014 stop_stepping (ecs
);
3019 /* Put the step-breakpoint there and go until there. */
3020 INIT_SAL (&sr_sal
); /* initialize to zeroes */
3021 sr_sal
.pc
= ecs
->stop_func_start
;
3022 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3023 /* Do not specify what the fp should be when we stop since on
3024 some machines the prologue is where the new fp value is
3026 check_for_old_step_resume_breakpoint ();
3027 step_resume_breakpoint
=
3028 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
3029 if (breakpoints_inserted
)
3030 insert_breakpoints ();
3032 /* And make sure stepping stops right away then. */
3033 step_range_end
= step_range_start
;
3038 /* We've just entered a callee, and we wish to resume until it returns
3039 to the caller. Setting a step_resume breakpoint on the return
3040 address will catch a return from the callee.
3042 However, if the callee is recursing, we want to be careful not to
3043 catch returns of those recursive calls, but only of THIS instance
3046 To do this, we set the step_resume bp's frame to our current
3047 caller's frame (step_frame_address, which is set by the "next" or
3048 "until" command, before execution begins). */
3051 step_over_function (struct execution_control_state
*ecs
)
3053 struct symtab_and_line sr_sal
;
3055 INIT_SAL (&sr_sal
); /* initialize to zeros */
3056 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3057 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3059 check_for_old_step_resume_breakpoint ();
3060 step_resume_breakpoint
=
3061 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
3063 if (step_frame_address
&& !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
3064 step_resume_breakpoint
->frame
= step_frame_address
;
3066 if (breakpoints_inserted
)
3067 insert_breakpoints ();
3071 stop_stepping (struct execution_control_state
*ecs
)
3073 if (target_has_execution
)
3075 /* Are we stopping for a vfork event? We only stop when we see
3076 the child's event. However, we may not yet have seen the
3077 parent's event. And, inferior_pid is still set to the
3078 parent's pid, until we resume again and follow either the
3081 To ensure that we can really touch inferior_pid (aka, the
3082 parent process) -- which calls to functions like read_pc
3083 implicitly do -- wait on the parent if necessary. */
3084 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3085 && !pending_follow
.fork_event
.saw_parent_fork
)
3091 if (target_wait_hook
)
3092 parent_pid
= target_wait_hook (-1, &(ecs
->ws
));
3094 parent_pid
= target_wait (-1, &(ecs
->ws
));
3096 while (parent_pid
!= inferior_pid
);
3099 /* Assuming the inferior still exists, set these up for next
3100 time, just like we did above if we didn't break out of the
3102 prev_pc
= read_pc ();
3103 prev_func_start
= ecs
->stop_func_start
;
3104 prev_func_name
= ecs
->stop_func_name
;
3107 /* Let callers know we don't want to wait for the inferior anymore. */
3108 ecs
->wait_some_more
= 0;
3111 /* This function handles various cases where we need to continue
3112 waiting for the inferior. */
3113 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3116 keep_going (struct execution_control_state
*ecs
)
3118 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3119 vforked child between its creation and subsequent exit or call to
3120 exec(). However, I had big problems in this rather creaky exec
3121 engine, getting that to work. The fundamental problem is that
3122 I'm trying to debug two processes via an engine that only
3123 understands a single process with possibly multiple threads.
3125 Hence, this spot is known to have problems when
3126 target_can_follow_vfork_prior_to_exec returns 1. */
3128 /* Save the pc before execution, to compare with pc after stop. */
3129 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3130 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3131 BREAK is defined, the
3132 original pc would not have
3133 been at the start of a
3135 prev_func_name
= ecs
->stop_func_name
;
3137 if (ecs
->update_step_sp
)
3138 step_sp
= read_sp ();
3139 ecs
->update_step_sp
= 0;
3141 /* If we did not do break;, it means we should keep running the
3142 inferior and not return to debugger. */
3144 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3146 /* We took a signal (which we are supposed to pass through to
3147 the inferior, else we'd have done a break above) and we
3148 haven't yet gotten our trap. Simply continue. */
3149 resume (currently_stepping (ecs
), stop_signal
);
3153 /* Either the trap was not expected, but we are continuing
3154 anyway (the user asked that this signal be passed to the
3157 The signal was SIGTRAP, e.g. it was our signal, but we
3158 decided we should resume from it.
3160 We're going to run this baby now!
3162 Insert breakpoints now, unless we are trying to one-proceed
3163 past a breakpoint. */
3164 /* If we've just finished a special step resume and we don't
3165 want to hit a breakpoint, pull em out. */
3166 if (step_resume_breakpoint
== NULL
3167 && through_sigtramp_breakpoint
== NULL
3168 && ecs
->remove_breakpoints_on_following_step
)
3170 ecs
->remove_breakpoints_on_following_step
= 0;
3171 remove_breakpoints ();
3172 breakpoints_inserted
= 0;
3174 else if (!breakpoints_inserted
&&
3175 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3177 breakpoints_failed
= insert_breakpoints ();
3178 if (breakpoints_failed
)
3180 stop_stepping (ecs
);
3183 breakpoints_inserted
= 1;
3186 trap_expected
= ecs
->another_trap
;
3188 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3189 specifies that such a signal should be delivered to the
3192 Typically, this would occure when a user is debugging a
3193 target monitor on a simulator: the target monitor sets a
3194 breakpoint; the simulator encounters this break-point and
3195 halts the simulation handing control to GDB; GDB, noteing
3196 that the break-point isn't valid, returns control back to the
3197 simulator; the simulator then delivers the hardware
3198 equivalent of a SIGNAL_TRAP to the program being debugged. */
3200 if (stop_signal
== TARGET_SIGNAL_TRAP
3201 && !signal_program
[stop_signal
])
3202 stop_signal
= TARGET_SIGNAL_0
;
3204 #ifdef SHIFT_INST_REGS
3205 /* I'm not sure when this following segment applies. I do know,
3206 now, that we shouldn't rewrite the regs when we were stopped
3207 by a random signal from the inferior process. */
3208 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3209 (this is only used on the 88k). */
3211 if (!bpstat_explains_signal (stop_bpstat
)
3212 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
3213 && !stopped_by_random_signal
)
3215 #endif /* SHIFT_INST_REGS */
3217 resume (currently_stepping (ecs
), stop_signal
);
3220 prepare_to_wait (ecs
);
3223 /* This function normally comes after a resume, before
3224 handle_inferior_event exits. It takes care of any last bits of
3225 housekeeping, and sets the all-important wait_some_more flag. */
3228 prepare_to_wait (struct execution_control_state
*ecs
)
3230 if (ecs
->infwait_state
== infwait_normal_state
)
3232 overlay_cache_invalid
= 1;
3234 /* We have to invalidate the registers BEFORE calling
3235 target_wait because they can be loaded from the target while
3236 in target_wait. This makes remote debugging a bit more
3237 efficient for those targets that provide critical registers
3238 as part of their normal status mechanism. */
3240 registers_changed ();
3241 ecs
->waiton_pid
= -1;
3242 ecs
->wp
= &(ecs
->ws
);
3244 /* This is the old end of the while loop. Let everybody know we
3245 want to wait for the inferior some more and get called again
3247 ecs
->wait_some_more
= 1;
3250 /* Print why the inferior has stopped. We always print something when
3251 the inferior exits, or receives a signal. The rest of the cases are
3252 dealt with later on in normal_stop() and print_it_typical(). Ideally
3253 there should be a call to this function from handle_inferior_event()
3254 each time stop_stepping() is called.*/
3256 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3258 switch (stop_reason
)
3261 /* We don't deal with these cases from handle_inferior_event()
3264 case END_STEPPING_RANGE
:
3265 /* We are done with a step/next/si/ni command. */
3266 /* For now print nothing. */
3268 /* Print a message only if not in the middle of doing a "step n"
3269 operation for n > 1 */
3270 if (!step_multi
|| !stop_step
)
3271 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3272 ui_out_field_string (uiout
, "reason", "end-stepping-range");
3275 case BREAKPOINT_HIT
:
3276 /* We found a breakpoint. */
3277 /* For now print nothing. */
3280 /* The inferior was terminated by a signal. */
3282 annotate_signalled ();
3283 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3284 ui_out_field_string (uiout
, "reason", "exited-signalled");
3285 ui_out_text (uiout
, "\nProgram terminated with signal ");
3286 annotate_signal_name ();
3287 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3288 annotate_signal_name_end ();
3289 ui_out_text (uiout
, ", ");
3290 annotate_signal_string ();
3291 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3292 annotate_signal_string_end ();
3293 ui_out_text (uiout
, ".\n");
3294 ui_out_text (uiout
, "The program no longer exists.\n");
3296 annotate_signalled ();
3297 printf_filtered ("\nProgram terminated with signal ");
3298 annotate_signal_name ();
3299 printf_filtered ("%s", target_signal_to_name (stop_info
));
3300 annotate_signal_name_end ();
3301 printf_filtered (", ");
3302 annotate_signal_string ();
3303 printf_filtered ("%s", target_signal_to_string (stop_info
));
3304 annotate_signal_string_end ();
3305 printf_filtered (".\n");
3307 printf_filtered ("The program no longer exists.\n");
3308 gdb_flush (gdb_stdout
);
3312 /* The inferior program is finished. */
3314 annotate_exited (stop_info
);
3317 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3318 ui_out_field_string (uiout
, "reason", "exited");
3319 ui_out_text (uiout
, "\nProgram exited with code ");
3320 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) stop_info
);
3321 ui_out_text (uiout
, ".\n");
3325 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3326 ui_out_field_string (uiout
, "reason", "exited-normally");
3327 ui_out_text (uiout
, "\nProgram exited normally.\n");
3330 annotate_exited (stop_info
);
3332 printf_filtered ("\nProgram exited with code 0%o.\n",
3333 (unsigned int) stop_info
);
3335 printf_filtered ("\nProgram exited normally.\n");
3338 case SIGNAL_RECEIVED
:
3339 /* Signal received. The signal table tells us to print about
3343 ui_out_text (uiout
, "\nProgram received signal ");
3344 annotate_signal_name ();
3345 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3346 annotate_signal_name_end ();
3347 ui_out_text (uiout
, ", ");
3348 annotate_signal_string ();
3349 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3350 annotate_signal_string_end ();
3351 ui_out_text (uiout
, ".\n");
3354 printf_filtered ("\nProgram received signal ");
3355 annotate_signal_name ();
3356 printf_filtered ("%s", target_signal_to_name (stop_info
));
3357 annotate_signal_name_end ();
3358 printf_filtered (", ");
3359 annotate_signal_string ();
3360 printf_filtered ("%s", target_signal_to_string (stop_info
));
3361 annotate_signal_string_end ();
3362 printf_filtered (".\n");
3363 gdb_flush (gdb_stdout
);
3367 internal_error ("print_stop_reason: unrecognized enum value");
3373 /* Here to return control to GDB when the inferior stops for real.
3374 Print appropriate messages, remove breakpoints, give terminal our modes.
3376 STOP_PRINT_FRAME nonzero means print the executing frame
3377 (pc, function, args, file, line number and line text).
3378 BREAKPOINTS_FAILED nonzero means stop was due to error
3379 attempting to insert breakpoints. */
3384 /* As with the notification of thread events, we want to delay
3385 notifying the user that we've switched thread context until
3386 the inferior actually stops.
3388 (Note that there's no point in saying anything if the inferior
3390 if ((previous_inferior_pid
!= inferior_pid
)
3391 && target_has_execution
)
3393 target_terminal_ours_for_output ();
3394 printf_filtered ("[Switching to %s]\n",
3395 target_pid_or_tid_to_str (inferior_pid
));
3396 previous_inferior_pid
= inferior_pid
;
3399 /* Make sure that the current_frame's pc is correct. This
3400 is a correction for setting up the frame info before doing
3401 DECR_PC_AFTER_BREAK */
3402 if (target_has_execution
&& get_current_frame ())
3403 (get_current_frame ())->pc
= read_pc ();
3405 if (breakpoints_failed
)
3407 target_terminal_ours_for_output ();
3408 print_sys_errmsg ("While inserting breakpoints", breakpoints_failed
);
3409 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3410 The same program may be running in another process,\n\
3411 or you may have requested too many hardware breakpoints\n\
3412 and/or watchpoints.\n");
3415 if (target_has_execution
&& breakpoints_inserted
)
3417 if (remove_breakpoints ())
3419 target_terminal_ours_for_output ();
3420 printf_filtered ("Cannot remove breakpoints because ");
3421 printf_filtered ("program is no longer writable.\n");
3422 printf_filtered ("It might be running in another process.\n");
3423 printf_filtered ("Further execution is probably impossible.\n");
3426 breakpoints_inserted
= 0;
3428 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3429 Delete any breakpoint that is to be deleted at the next stop. */
3431 breakpoint_auto_delete (stop_bpstat
);
3433 /* If an auto-display called a function and that got a signal,
3434 delete that auto-display to avoid an infinite recursion. */
3436 if (stopped_by_random_signal
)
3437 disable_current_display ();
3439 /* Don't print a message if in the middle of doing a "step n"
3440 operation for n > 1 */
3441 if (step_multi
&& stop_step
)
3444 target_terminal_ours ();
3446 /* Look up the hook_stop and run it if it exists. */
3448 if (stop_command
&& stop_command
->hook
)
3450 catch_errors (hook_stop_stub
, stop_command
->hook
,
3451 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3454 if (!target_has_stack
)
3460 /* Select innermost stack frame - i.e., current frame is frame 0,
3461 and current location is based on that.
3462 Don't do this on return from a stack dummy routine,
3463 or if the program has exited. */
3465 if (!stop_stack_dummy
)
3467 select_frame (get_current_frame (), 0);
3469 /* Print current location without a level number, if
3470 we have changed functions or hit a breakpoint.
3471 Print source line if we have one.
3472 bpstat_print() contains the logic deciding in detail
3473 what to print, based on the event(s) that just occurred. */
3475 if (stop_print_frame
3480 int do_frame_printing
= 1;
3482 bpstat_ret
= bpstat_print (stop_bpstat
);
3487 && step_frame_address
== FRAME_FP (get_current_frame ())
3488 && step_start_function
== find_pc_function (stop_pc
))
3489 source_flag
= SRC_LINE
; /* finished step, just print source line */
3491 source_flag
= SRC_AND_LOC
; /* print location and source line */
3493 case PRINT_SRC_AND_LOC
:
3494 source_flag
= SRC_AND_LOC
; /* print location and source line */
3496 case PRINT_SRC_ONLY
:
3497 source_flag
= SRC_LINE
;
3500 do_frame_printing
= 0;
3503 internal_error ("Unknown value.");
3506 /* For mi, have the same behavior every time we stop:
3507 print everything but the source line. */
3508 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3509 source_flag
= LOC_AND_ADDRESS
;
3513 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3514 ui_out_field_int (uiout
, "thread-id", pid_to_thread_id (inferior_pid
));
3516 /* The behavior of this routine with respect to the source
3518 SRC_LINE: Print only source line
3519 LOCATION: Print only location
3520 SRC_AND_LOC: Print location and source line */
3521 if (do_frame_printing
)
3522 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
3524 /* Display the auto-display expressions. */
3529 /* Save the function value return registers, if we care.
3530 We might be about to restore their previous contents. */
3531 if (proceed_to_finish
)
3532 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
3534 if (stop_stack_dummy
)
3536 /* Pop the empty frame that contains the stack dummy.
3537 POP_FRAME ends with a setting of the current frame, so we
3538 can use that next. */
3540 /* Set stop_pc to what it was before we called the function.
3541 Can't rely on restore_inferior_status because that only gets
3542 called if we don't stop in the called function. */
3543 stop_pc
= read_pc ();
3544 select_frame (get_current_frame (), 0);
3548 TUIDO (((TuiOpaqueFuncPtr
) tui_vCheckDataValues
, selected_frame
));
3551 annotate_stopped ();
3555 hook_stop_stub (void *cmd
)
3557 execute_user_command ((struct cmd_list_element
*) cmd
, 0);
3562 signal_stop_state (int signo
)
3564 return signal_stop
[signo
];
3568 signal_print_state (int signo
)
3570 return signal_print
[signo
];
3574 signal_pass_state (int signo
)
3576 return signal_program
[signo
];
3579 int signal_stop_update (signo
, state
)
3583 int ret
= signal_stop
[signo
];
3584 signal_stop
[signo
] = state
;
3588 int signal_print_update (signo
, state
)
3592 int ret
= signal_print
[signo
];
3593 signal_print
[signo
] = state
;
3597 int signal_pass_update (signo
, state
)
3601 int ret
= signal_program
[signo
];
3602 signal_program
[signo
] = state
;
3607 sig_print_header (void)
3610 Signal Stop\tPrint\tPass to program\tDescription\n");
3614 sig_print_info (enum target_signal oursig
)
3616 char *name
= target_signal_to_name (oursig
);
3617 int name_padding
= 13 - strlen (name
);
3619 if (name_padding
<= 0)
3622 printf_filtered ("%s", name
);
3623 printf_filtered ("%*.*s ", name_padding
, name_padding
,
3625 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3626 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3627 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3628 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3631 /* Specify how various signals in the inferior should be handled. */
3634 handle_command (char *args
, int from_tty
)
3637 int digits
, wordlen
;
3638 int sigfirst
, signum
, siglast
;
3639 enum target_signal oursig
;
3642 unsigned char *sigs
;
3643 struct cleanup
*old_chain
;
3647 error_no_arg ("signal to handle");
3650 /* Allocate and zero an array of flags for which signals to handle. */
3652 nsigs
= (int) TARGET_SIGNAL_LAST
;
3653 sigs
= (unsigned char *) alloca (nsigs
);
3654 memset (sigs
, 0, nsigs
);
3656 /* Break the command line up into args. */
3658 argv
= buildargv (args
);
3663 old_chain
= make_cleanup_freeargv (argv
);
3665 /* Walk through the args, looking for signal oursigs, signal names, and
3666 actions. Signal numbers and signal names may be interspersed with
3667 actions, with the actions being performed for all signals cumulatively
3668 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3670 while (*argv
!= NULL
)
3672 wordlen
= strlen (*argv
);
3673 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3677 sigfirst
= siglast
= -1;
3679 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3681 /* Apply action to all signals except those used by the
3682 debugger. Silently skip those. */
3685 siglast
= nsigs
- 1;
3687 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3689 SET_SIGS (nsigs
, sigs
, signal_stop
);
3690 SET_SIGS (nsigs
, sigs
, signal_print
);
3692 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3694 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3696 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3698 SET_SIGS (nsigs
, sigs
, signal_print
);
3700 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3702 SET_SIGS (nsigs
, sigs
, signal_program
);
3704 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3706 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3708 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3710 SET_SIGS (nsigs
, sigs
, signal_program
);
3712 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3714 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3715 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3717 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3719 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3721 else if (digits
> 0)
3723 /* It is numeric. The numeric signal refers to our own
3724 internal signal numbering from target.h, not to host/target
3725 signal number. This is a feature; users really should be
3726 using symbolic names anyway, and the common ones like
3727 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3729 sigfirst
= siglast
= (int)
3730 target_signal_from_command (atoi (*argv
));
3731 if ((*argv
)[digits
] == '-')
3734 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3736 if (sigfirst
> siglast
)
3738 /* Bet he didn't figure we'd think of this case... */
3746 oursig
= target_signal_from_name (*argv
);
3747 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3749 sigfirst
= siglast
= (int) oursig
;
3753 /* Not a number and not a recognized flag word => complain. */
3754 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3758 /* If any signal numbers or symbol names were found, set flags for
3759 which signals to apply actions to. */
3761 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3763 switch ((enum target_signal
) signum
)
3765 case TARGET_SIGNAL_TRAP
:
3766 case TARGET_SIGNAL_INT
:
3767 if (!allsigs
&& !sigs
[signum
])
3769 if (query ("%s is used by the debugger.\n\
3770 Are you sure you want to change it? ",
3771 target_signal_to_name
3772 ((enum target_signal
) signum
)))
3778 printf_unfiltered ("Not confirmed, unchanged.\n");
3779 gdb_flush (gdb_stdout
);
3783 case TARGET_SIGNAL_0
:
3784 case TARGET_SIGNAL_DEFAULT
:
3785 case TARGET_SIGNAL_UNKNOWN
:
3786 /* Make sure that "all" doesn't print these. */
3797 target_notice_signals (inferior_pid
);
3801 /* Show the results. */
3802 sig_print_header ();
3803 for (signum
= 0; signum
< nsigs
; signum
++)
3807 sig_print_info (signum
);
3812 do_cleanups (old_chain
);
3816 xdb_handle_command (char *args
, int from_tty
)
3819 struct cleanup
*old_chain
;
3821 /* Break the command line up into args. */
3823 argv
= buildargv (args
);
3828 old_chain
= make_cleanup_freeargv (argv
);
3829 if (argv
[1] != (char *) NULL
)
3834 bufLen
= strlen (argv
[0]) + 20;
3835 argBuf
= (char *) xmalloc (bufLen
);
3839 enum target_signal oursig
;
3841 oursig
= target_signal_from_name (argv
[0]);
3842 memset (argBuf
, 0, bufLen
);
3843 if (strcmp (argv
[1], "Q") == 0)
3844 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3847 if (strcmp (argv
[1], "s") == 0)
3849 if (!signal_stop
[oursig
])
3850 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3852 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3854 else if (strcmp (argv
[1], "i") == 0)
3856 if (!signal_program
[oursig
])
3857 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3859 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3861 else if (strcmp (argv
[1], "r") == 0)
3863 if (!signal_print
[oursig
])
3864 sprintf (argBuf
, "%s %s", argv
[0], "print");
3866 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3872 handle_command (argBuf
, from_tty
);
3874 printf_filtered ("Invalid signal handling flag.\n");
3879 do_cleanups (old_chain
);
3882 /* Print current contents of the tables set by the handle command.
3883 It is possible we should just be printing signals actually used
3884 by the current target (but for things to work right when switching
3885 targets, all signals should be in the signal tables). */
3888 signals_info (char *signum_exp
, int from_tty
)
3890 enum target_signal oursig
;
3891 sig_print_header ();
3895 /* First see if this is a symbol name. */
3896 oursig
= target_signal_from_name (signum_exp
);
3897 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3899 /* No, try numeric. */
3901 target_signal_from_command (parse_and_eval_address (signum_exp
));
3903 sig_print_info (oursig
);
3907 printf_filtered ("\n");
3908 /* These ugly casts brought to you by the native VAX compiler. */
3909 for (oursig
= TARGET_SIGNAL_FIRST
;
3910 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3911 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3915 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3916 && oursig
!= TARGET_SIGNAL_DEFAULT
3917 && oursig
!= TARGET_SIGNAL_0
)
3918 sig_print_info (oursig
);
3921 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3924 struct inferior_status
3926 enum target_signal stop_signal
;
3930 int stop_stack_dummy
;
3931 int stopped_by_random_signal
;
3933 CORE_ADDR step_range_start
;
3934 CORE_ADDR step_range_end
;
3935 CORE_ADDR step_frame_address
;
3936 int step_over_calls
;
3937 CORE_ADDR step_resume_break_address
;
3938 int stop_after_trap
;
3939 int stop_soon_quietly
;
3940 CORE_ADDR selected_frame_address
;
3941 char *stop_registers
;
3943 /* These are here because if call_function_by_hand has written some
3944 registers and then decides to call error(), we better not have changed
3949 int breakpoint_proceeded
;
3950 int restore_stack_info
;
3951 int proceed_to_finish
;
3954 static struct inferior_status
*
3955 xmalloc_inferior_status (void)
3957 struct inferior_status
*inf_status
;
3958 inf_status
= xmalloc (sizeof (struct inferior_status
));
3959 inf_status
->stop_registers
= xmalloc (REGISTER_BYTES
);
3960 inf_status
->registers
= xmalloc (REGISTER_BYTES
);
3965 free_inferior_status (struct inferior_status
*inf_status
)
3967 free (inf_status
->registers
);
3968 free (inf_status
->stop_registers
);
3973 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3976 int size
= REGISTER_RAW_SIZE (regno
);
3977 void *buf
= alloca (size
);
3978 store_signed_integer (buf
, size
, val
);
3979 memcpy (&inf_status
->registers
[REGISTER_BYTE (regno
)], buf
, size
);
3982 /* Save all of the information associated with the inferior<==>gdb
3983 connection. INF_STATUS is a pointer to a "struct inferior_status"
3984 (defined in inferior.h). */
3986 struct inferior_status
*
3987 save_inferior_status (int restore_stack_info
)
3989 struct inferior_status
*inf_status
= xmalloc_inferior_status ();
3991 inf_status
->stop_signal
= stop_signal
;
3992 inf_status
->stop_pc
= stop_pc
;
3993 inf_status
->stop_step
= stop_step
;
3994 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3995 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3996 inf_status
->trap_expected
= trap_expected
;
3997 inf_status
->step_range_start
= step_range_start
;
3998 inf_status
->step_range_end
= step_range_end
;
3999 inf_status
->step_frame_address
= step_frame_address
;
4000 inf_status
->step_over_calls
= step_over_calls
;
4001 inf_status
->stop_after_trap
= stop_after_trap
;
4002 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
4003 /* Save original bpstat chain here; replace it with copy of chain.
4004 If caller's caller is walking the chain, they'll be happier if we
4005 hand them back the original chain when restore_inferior_status is
4007 inf_status
->stop_bpstat
= stop_bpstat
;
4008 stop_bpstat
= bpstat_copy (stop_bpstat
);
4009 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
4010 inf_status
->restore_stack_info
= restore_stack_info
;
4011 inf_status
->proceed_to_finish
= proceed_to_finish
;
4013 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
4015 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
4017 record_selected_frame (&(inf_status
->selected_frame_address
),
4018 &(inf_status
->selected_level
));
4022 struct restore_selected_frame_args
4024 CORE_ADDR frame_address
;
4029 restore_selected_frame (void *args
)
4031 struct restore_selected_frame_args
*fr
=
4032 (struct restore_selected_frame_args
*) args
;
4033 struct frame_info
*frame
;
4034 int level
= fr
->level
;
4036 frame
= find_relative_frame (get_current_frame (), &level
);
4038 /* If inf_status->selected_frame_address is NULL, there was no
4039 previously selected frame. */
4040 if (frame
== NULL
||
4041 /* FRAME_FP (frame) != fr->frame_address || */
4042 /* elz: deleted this check as a quick fix to the problem that
4043 for function called by hand gdb creates no internal frame
4044 structure and the real stack and gdb's idea of stack are
4045 different if nested calls by hands are made.
4047 mvs: this worries me. */
4050 warning ("Unable to restore previously selected frame.\n");
4054 select_frame (frame
, fr
->level
);
4060 restore_inferior_status (struct inferior_status
*inf_status
)
4062 stop_signal
= inf_status
->stop_signal
;
4063 stop_pc
= inf_status
->stop_pc
;
4064 stop_step
= inf_status
->stop_step
;
4065 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4066 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4067 trap_expected
= inf_status
->trap_expected
;
4068 step_range_start
= inf_status
->step_range_start
;
4069 step_range_end
= inf_status
->step_range_end
;
4070 step_frame_address
= inf_status
->step_frame_address
;
4071 step_over_calls
= inf_status
->step_over_calls
;
4072 stop_after_trap
= inf_status
->stop_after_trap
;
4073 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
4074 bpstat_clear (&stop_bpstat
);
4075 stop_bpstat
= inf_status
->stop_bpstat
;
4076 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4077 proceed_to_finish
= inf_status
->proceed_to_finish
;
4079 /* FIXME: Is the restore of stop_registers always needed */
4080 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
4082 /* The inferior can be gone if the user types "print exit(0)"
4083 (and perhaps other times). */
4084 if (target_has_execution
)
4085 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
4087 /* FIXME: If we are being called after stopping in a function which
4088 is called from gdb, we should not be trying to restore the
4089 selected frame; it just prints a spurious error message (The
4090 message is useful, however, in detecting bugs in gdb (like if gdb
4091 clobbers the stack)). In fact, should we be restoring the
4092 inferior status at all in that case? . */
4094 if (target_has_stack
&& inf_status
->restore_stack_info
)
4096 struct restore_selected_frame_args fr
;
4097 fr
.level
= inf_status
->selected_level
;
4098 fr
.frame_address
= inf_status
->selected_frame_address
;
4099 /* The point of catch_errors is that if the stack is clobbered,
4100 walking the stack might encounter a garbage pointer and error()
4101 trying to dereference it. */
4102 if (catch_errors (restore_selected_frame
, &fr
,
4103 "Unable to restore previously selected frame:\n",
4104 RETURN_MASK_ERROR
) == 0)
4105 /* Error in restoring the selected frame. Select the innermost
4109 select_frame (get_current_frame (), 0);
4113 free_inferior_status (inf_status
);
4117 do_restore_inferior_status_cleanup (void *sts
)
4119 restore_inferior_status (sts
);
4123 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4125 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4129 discard_inferior_status (struct inferior_status
*inf_status
)
4131 /* See save_inferior_status for info on stop_bpstat. */
4132 bpstat_clear (&inf_status
->stop_bpstat
);
4133 free_inferior_status (inf_status
);
4137 set_follow_fork_mode_command (char *arg
, int from_tty
,
4138 struct cmd_list_element
*c
)
4140 if (!STREQ (arg
, "parent") &&
4141 !STREQ (arg
, "child") &&
4142 !STREQ (arg
, "both") &&
4143 !STREQ (arg
, "ask"))
4144 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
4146 if (follow_fork_mode_string
!= NULL
)
4147 free (follow_fork_mode_string
);
4148 follow_fork_mode_string
= savestring (arg
, strlen (arg
));
4154 stop_registers
= xmalloc (REGISTER_BYTES
);
4158 _initialize_infrun (void)
4161 register int numsigs
;
4162 struct cmd_list_element
*c
;
4166 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4167 register_gdbarch_swap (NULL
, 0, build_infrun
);
4169 add_info ("signals", signals_info
,
4170 "What debugger does when program gets various signals.\n\
4171 Specify a signal as argument to print info on that signal only.");
4172 add_info_alias ("handle", "signals", 0);
4174 add_com ("handle", class_run
, handle_command
,
4175 concat ("Specify how to handle a signal.\n\
4176 Args are signals and actions to apply to those signals.\n\
4177 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4178 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4179 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4180 The special arg \"all\" is recognized to mean all signals except those\n\
4181 used by the debugger, typically SIGTRAP and SIGINT.\n",
4182 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4183 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4184 Stop means reenter debugger if this signal happens (implies print).\n\
4185 Print means print a message if this signal happens.\n\
4186 Pass means let program see this signal; otherwise program doesn't know.\n\
4187 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4188 Pass and Stop may be combined.", NULL
));
4191 add_com ("lz", class_info
, signals_info
,
4192 "What debugger does when program gets various signals.\n\
4193 Specify a signal as argument to print info on that signal only.");
4194 add_com ("z", class_run
, xdb_handle_command
,
4195 concat ("Specify how to handle a signal.\n\
4196 Args are signals and actions to apply to those signals.\n\
4197 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4198 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4199 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4200 The special arg \"all\" is recognized to mean all signals except those\n\
4201 used by the debugger, typically SIGTRAP and SIGINT.\n",
4202 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4203 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4204 nopass), \"Q\" (noprint)\n\
4205 Stop means reenter debugger if this signal happens (implies print).\n\
4206 Print means print a message if this signal happens.\n\
4207 Pass means let program see this signal; otherwise program doesn't know.\n\
4208 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4209 Pass and Stop may be combined.", NULL
));
4213 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
4214 "There is no `stop' command, but you can set a hook on `stop'.\n\
4215 This allows you to set a list of commands to be run each time execution\n\
4216 of the program stops.", &cmdlist
);
4218 numsigs
= (int) TARGET_SIGNAL_LAST
;
4219 signal_stop
= (unsigned char *)
4220 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4221 signal_print
= (unsigned char *)
4222 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4223 signal_program
= (unsigned char *)
4224 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4225 for (i
= 0; i
< numsigs
; i
++)
4228 signal_print
[i
] = 1;
4229 signal_program
[i
] = 1;
4232 /* Signals caused by debugger's own actions
4233 should not be given to the program afterwards. */
4234 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4235 signal_program
[TARGET_SIGNAL_INT
] = 0;
4237 /* Signals that are not errors should not normally enter the debugger. */
4238 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4239 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4240 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4241 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4242 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4243 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4244 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4245 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4246 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4247 signal_print
[TARGET_SIGNAL_IO
] = 0;
4248 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4249 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4250 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4251 signal_print
[TARGET_SIGNAL_URG
] = 0;
4252 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4253 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4255 /* These signals are used internally by user-level thread
4256 implementations. (See signal(5) on Solaris.) Like the above
4257 signals, a healthy program receives and handles them as part of
4258 its normal operation. */
4259 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4260 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4261 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4262 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4263 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4264 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4268 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4269 (char *) &stop_on_solib_events
,
4270 "Set stopping for shared library events.\n\
4271 If nonzero, gdb will give control to the user when the dynamic linker\n\
4272 notifies gdb of shared library events. The most common event of interest\n\
4273 to the user would be loading/unloading of a new library.\n",
4278 c
= add_set_enum_cmd ("follow-fork-mode",
4280 follow_fork_mode_kind_names
,
4281 &follow_fork_mode_string
,
4282 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4283 kernel problem. It's also not terribly useful without a GUI to
4284 help the user drive two debuggers. So for now, I'm disabling
4285 the "both" option. */
4286 /* "Set debugger response to a program call of fork \
4288 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4289 parent - the original process is debugged after a fork\n\
4290 child - the new process is debugged after a fork\n\
4291 both - both the parent and child are debugged after a fork\n\
4292 ask - the debugger will ask for one of the above choices\n\
4293 For \"both\", another copy of the debugger will be started to follow\n\
4294 the new child process. The original debugger will continue to follow\n\
4295 the original parent process. To distinguish their prompts, the\n\
4296 debugger copy's prompt will be changed.\n\
4297 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4298 By default, the debugger will follow the parent process.",
4300 "Set debugger response to a program call of fork \
4302 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4303 parent - the original process is debugged after a fork\n\
4304 child - the new process is debugged after a fork\n\
4305 ask - the debugger will ask for one of the above choices\n\
4306 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4307 By default, the debugger will follow the parent process.",
4309 /* c->function.sfunc = ; */
4310 add_show_from_set (c
, &showlist
);
4312 set_follow_fork_mode_command ("parent", 0, NULL
);
4314 c
= add_set_enum_cmd ("scheduler-locking", class_run
,
4315 scheduler_enums
, /* array of string names */
4316 &scheduler_mode
, /* current mode */
4317 "Set mode for locking scheduler during execution.\n\
4318 off == no locking (threads may preempt at any time)\n\
4319 on == full locking (no thread except the current thread may run)\n\
4320 step == scheduler locked during every single-step operation.\n\
4321 In this mode, no other thread may run during a step command.\n\
4322 Other threads may run while stepping over a function call ('next').",
4325 c
->function
.sfunc
= set_schedlock_func
; /* traps on target vector */
4326 add_show_from_set (c
, &showlist
);