1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
5 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
26 #include "gdb_string.h"
31 #include "breakpoint.h"
35 #include "cli/cli-script.h"
37 #include "gdbthread.h"
46 /* Prototypes for local functions */
48 static void signals_info (char *, int);
50 static void handle_command (char *, int);
52 static void sig_print_info (enum target_signal
);
54 static void sig_print_header (void);
56 static void resume_cleanups (void *);
58 static int hook_stop_stub (void *);
60 static void delete_breakpoint_current_contents (void *);
62 static void set_follow_fork_mode_command (char *arg
, int from_tty
,
63 struct cmd_list_element
*c
);
65 static int restore_selected_frame (void *);
67 static void build_infrun (void);
69 static void follow_inferior_fork (int parent_pid
, int child_pid
,
70 int has_forked
, int has_vforked
);
72 static void follow_fork (int parent_pid
, int child_pid
);
74 static void follow_vfork (int parent_pid
, int child_pid
);
76 static void set_schedlock_func (char *args
, int from_tty
,
77 struct cmd_list_element
*c
);
79 struct execution_control_state
;
81 static int currently_stepping (struct execution_control_state
*ecs
);
83 static void xdb_handle_command (char *args
, int from_tty
);
85 void _initialize_infrun (void);
87 int inferior_ignoring_startup_exec_events
= 0;
88 int inferior_ignoring_leading_exec_events
= 0;
90 /* When set, stop the 'step' command if we enter a function which has
91 no line number information. The normal behavior is that we step
92 over such function. */
93 int step_stop_if_no_debug
= 0;
95 /* In asynchronous mode, but simulating synchronous execution. */
97 int sync_execution
= 0;
99 /* wait_for_inferior and normal_stop use this to notify the user
100 when the inferior stopped in a different thread than it had been
103 static ptid_t previous_inferior_ptid
;
105 /* This is true for configurations that may follow through execl() and
106 similar functions. At present this is only true for HP-UX native. */
108 #ifndef MAY_FOLLOW_EXEC
109 #define MAY_FOLLOW_EXEC (0)
112 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
114 /* Dynamic function trampolines are similar to solib trampolines in that they
115 are between the caller and the callee. The difference is that when you
116 enter a dynamic trampoline, you can't determine the callee's address. Some
117 (usually complex) code needs to run in the dynamic trampoline to figure out
118 the callee's address. This macro is usually called twice. First, when we
119 enter the trampoline (looks like a normal function call at that point). It
120 should return the PC of a point within the trampoline where the callee's
121 address is known. Second, when we hit the breakpoint, this routine returns
122 the callee's address. At that point, things proceed as per a step resume
125 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
126 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
129 /* If the program uses ELF-style shared libraries, then calls to
130 functions in shared libraries go through stubs, which live in a
131 table called the PLT (Procedure Linkage Table). The first time the
132 function is called, the stub sends control to the dynamic linker,
133 which looks up the function's real address, patches the stub so
134 that future calls will go directly to the function, and then passes
135 control to the function.
137 If we are stepping at the source level, we don't want to see any of
138 this --- we just want to skip over the stub and the dynamic linker.
139 The simple approach is to single-step until control leaves the
142 However, on some systems (e.g., Red Hat's 5.2 distribution) the
143 dynamic linker calls functions in the shared C library, so you
144 can't tell from the PC alone whether the dynamic linker is still
145 running. In this case, we use a step-resume breakpoint to get us
146 past the dynamic linker, as if we were using "next" to step over a
149 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
150 linker code or not. Normally, this means we single-step. However,
151 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
152 address where we can place a step-resume breakpoint to get past the
153 linker's symbol resolution function.
155 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
156 pretty portable way, by comparing the PC against the address ranges
157 of the dynamic linker's sections.
159 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
160 it depends on internal details of the dynamic linker. It's usually
161 not too hard to figure out where to put a breakpoint, but it
162 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
163 sanity checking. If it can't figure things out, returning zero and
164 getting the (possibly confusing) stepping behavior is better than
165 signalling an error, which will obscure the change in the
168 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
169 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
172 #ifndef SKIP_SOLIB_RESOLVER
173 #define SKIP_SOLIB_RESOLVER(pc) 0
176 /* This function returns TRUE if pc is the address of an instruction
177 that lies within the dynamic linker (such as the event hook, or the
180 This function must be used only when a dynamic linker event has
181 been caught, and the inferior is being stepped out of the hook, or
182 undefined results are guaranteed. */
184 #ifndef SOLIB_IN_DYNAMIC_LINKER
185 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
188 /* On MIPS16, a function that returns a floating point value may call
189 a library helper function to copy the return value to a floating point
190 register. The IGNORE_HELPER_CALL macro returns non-zero if we
191 should ignore (i.e. step over) this function call. */
192 #ifndef IGNORE_HELPER_CALL
193 #define IGNORE_HELPER_CALL(pc) 0
196 /* On some systems, the PC may be left pointing at an instruction that won't
197 actually be executed. This is usually indicated by a bit in the PSW. If
198 we find ourselves in such a state, then we step the target beyond the
199 nullified instruction before returning control to the user so as to avoid
202 #ifndef INSTRUCTION_NULLIFIED
203 #define INSTRUCTION_NULLIFIED 0
206 /* We can't step off a permanent breakpoint in the ordinary way, because we
207 can't remove it. Instead, we have to advance the PC to the next
208 instruction. This macro should expand to a pointer to a function that
209 does that, or zero if we have no such function. If we don't have a
210 definition for it, we have to report an error. */
211 #ifndef SKIP_PERMANENT_BREAKPOINT
212 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
214 default_skip_permanent_breakpoint (void)
217 The program is stopped at a permanent breakpoint, but GDB does not know\n\
218 how to step past a permanent breakpoint on this architecture. Try using\n\
219 a command like `return' or `jump' to continue execution.");
224 /* Convert the #defines into values. This is temporary until wfi control
225 flow is completely sorted out. */
227 #ifndef HAVE_STEPPABLE_WATCHPOINT
228 #define HAVE_STEPPABLE_WATCHPOINT 0
230 #undef HAVE_STEPPABLE_WATCHPOINT
231 #define HAVE_STEPPABLE_WATCHPOINT 1
234 #ifndef HAVE_CONTINUABLE_WATCHPOINT
235 #define HAVE_CONTINUABLE_WATCHPOINT 0
237 #undef HAVE_CONTINUABLE_WATCHPOINT
238 #define HAVE_CONTINUABLE_WATCHPOINT 1
241 #ifndef CANNOT_STEP_HW_WATCHPOINTS
242 #define CANNOT_STEP_HW_WATCHPOINTS 0
244 #undef CANNOT_STEP_HW_WATCHPOINTS
245 #define CANNOT_STEP_HW_WATCHPOINTS 1
248 /* Tables of how to react to signals; the user sets them. */
250 static unsigned char *signal_stop
;
251 static unsigned char *signal_print
;
252 static unsigned char *signal_program
;
254 #define SET_SIGS(nsigs,sigs,flags) \
256 int signum = (nsigs); \
257 while (signum-- > 0) \
258 if ((sigs)[signum]) \
259 (flags)[signum] = 1; \
262 #define UNSET_SIGS(nsigs,sigs,flags) \
264 int signum = (nsigs); \
265 while (signum-- > 0) \
266 if ((sigs)[signum]) \
267 (flags)[signum] = 0; \
270 /* Value to pass to target_resume() to cause all threads to resume */
272 #define RESUME_ALL (pid_to_ptid (-1))
274 /* Command list pointer for the "stop" placeholder. */
276 static struct cmd_list_element
*stop_command
;
278 /* Nonzero if breakpoints are now inserted in the inferior. */
280 static int breakpoints_inserted
;
282 /* Function inferior was in as of last step command. */
284 static struct symbol
*step_start_function
;
286 /* Nonzero if we are expecting a trace trap and should proceed from it. */
288 static int trap_expected
;
291 /* Nonzero if we want to give control to the user when we're notified
292 of shared library events by the dynamic linker. */
293 static int stop_on_solib_events
;
297 /* Nonzero if the next time we try to continue the inferior, it will
298 step one instruction and generate a spurious trace trap.
299 This is used to compensate for a bug in HP-UX. */
301 static int trap_expected_after_continue
;
304 /* Nonzero means expecting a trace trap
305 and should stop the inferior and return silently when it happens. */
309 /* Nonzero means expecting a trap and caller will handle it themselves.
310 It is used after attach, due to attaching to a process;
311 when running in the shell before the child program has been exec'd;
312 and when running some kinds of remote stuff (FIXME?). */
314 int stop_soon_quietly
;
316 /* Nonzero if proceed is being used for a "finish" command or a similar
317 situation when stop_registers should be saved. */
319 int proceed_to_finish
;
321 /* Save register contents here when about to pop a stack dummy frame,
322 if-and-only-if proceed_to_finish is set.
323 Thus this contains the return value from the called function (assuming
324 values are returned in a register). */
326 struct regcache
*stop_registers
;
328 /* Nonzero if program stopped due to error trying to insert breakpoints. */
330 static int breakpoints_failed
;
332 /* Nonzero after stop if current stack frame should be printed. */
334 static int stop_print_frame
;
336 static struct breakpoint
*step_resume_breakpoint
= NULL
;
337 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
339 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
340 interactions with an inferior that is running a kernel function
341 (aka, a system call or "syscall"). wait_for_inferior therefore
342 may have a need to know when the inferior is in a syscall. This
343 is a count of the number of inferior threads which are known to
344 currently be running in a syscall. */
345 static int number_of_threads_in_syscalls
;
347 /* This is a cached copy of the pid/waitstatus of the last event
348 returned by target_wait()/target_wait_hook(). This information is
349 returned by get_last_target_status(). */
350 static ptid_t target_last_wait_ptid
;
351 static struct target_waitstatus target_last_waitstatus
;
353 /* This is used to remember when a fork, vfork or exec event
354 was caught by a catchpoint, and thus the event is to be
355 followed at the next resume of the inferior, and not
359 enum target_waitkind kind
;
369 char *execd_pathname
;
373 static const char follow_fork_mode_ask
[] = "ask";
374 static const char follow_fork_mode_child
[] = "child";
375 static const char follow_fork_mode_parent
[] = "parent";
377 static const char *follow_fork_mode_kind_names
[] = {
378 follow_fork_mode_ask
,
379 follow_fork_mode_child
,
380 follow_fork_mode_parent
,
384 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
388 follow_inferior_fork (int parent_pid
, int child_pid
, int has_forked
,
391 int followed_parent
= 0;
392 int followed_child
= 0;
394 /* Which process did the user want us to follow? */
395 const char *follow_mode
= follow_fork_mode_string
;
397 /* Or, did the user not know, and want us to ask? */
398 if (follow_fork_mode_string
== follow_fork_mode_ask
)
400 internal_error (__FILE__
, __LINE__
,
401 "follow_inferior_fork: \"ask\" mode not implemented");
402 /* follow_mode = follow_fork_mode_...; */
405 /* If we're to be following the parent, then detach from child_pid.
406 We're already following the parent, so need do nothing explicit
408 if (follow_mode
== follow_fork_mode_parent
)
412 /* We're already attached to the parent, by default. */
414 /* Before detaching from the child, remove all breakpoints from
415 it. (This won't actually modify the breakpoint list, but will
416 physically remove the breakpoints from the child.) */
417 detach_breakpoints (child_pid
);
418 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
419 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
422 /* Detach from the child. */
425 target_require_detach (child_pid
, "", 1);
428 /* If we're to be following the child, then attach to it, detach
429 from inferior_ptid, and set inferior_ptid to child_pid. */
430 else if (follow_mode
== follow_fork_mode_child
)
432 char child_pid_spelling
[100]; /* Arbitrary length. */
436 /* Before detaching from the parent, detach all breakpoints from
437 the child. Note that this only works if we're following vforks
438 right away; if we've exec'd then the breakpoints are already detached
439 and the shadow contents are out of date. */
440 detach_breakpoints (child_pid
);
442 /* Before detaching from the parent, remove all breakpoints from it. */
443 remove_breakpoints ();
445 /* Also reset the solib inferior hook from the parent. */
446 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
447 SOLIB_REMOVE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
450 /* Detach from the parent. */
452 target_detach (NULL
, 1);
454 /* Attach to the child. */
455 inferior_ptid
= pid_to_ptid (child_pid
);
456 sprintf (child_pid_spelling
, "%d", child_pid
);
459 target_require_attach (child_pid_spelling
, 1);
461 /* Was there a step_resume breakpoint? (There was if the user
462 did a "next" at the fork() call.) If so, explicitly reset its
465 step_resumes are a form of bp that are made to be per-thread.
466 Since we created the step_resume bp when the parent process
467 was being debugged, and now are switching to the child process,
468 from the breakpoint package's viewpoint, that's a switch of
469 "threads". We must update the bp's notion of which thread
470 it is for, or it'll be ignored when it triggers... */
471 /* As above, if we're following vforks at exec time then resetting the
472 step resume breakpoint is probably wrong. */
473 if (step_resume_breakpoint
)
474 breakpoint_re_set_thread (step_resume_breakpoint
);
476 /* Reinsert all breakpoints in the child. (The user may've set
477 breakpoints after catching the fork, in which case those
478 actually didn't get set in the child, but only in the parent.) */
479 breakpoint_re_set ();
480 insert_breakpoints ();
483 /* The parent and child of a vfork share the same address space.
484 Also, on some targets the order in which vfork and exec events
485 are received for parent in child requires some delicate handling
488 For instance, on ptrace-based HPUX we receive the child's vfork
489 event first, at which time the parent has been suspended by the
490 OS and is essentially untouchable until the child's exit or second
491 exec event arrives. At that time, the parent's vfork event is
492 delivered to us, and that's when we see and decide how to follow
493 the vfork. But to get to that point, we must continue the child
494 until it execs or exits. To do that smoothly, all breakpoints
495 must be removed from the child, in case there are any set between
496 the vfork() and exec() calls. But removing them from the child
497 also removes them from the parent, due to the shared-address-space
498 nature of a vfork'd parent and child. On HPUX, therefore, we must
499 take care to restore the bp's to the parent before we continue it.
500 Else, it's likely that we may not stop in the expected place. (The
501 worst scenario is when the user tries to step over a vfork() call;
502 the step-resume bp must be restored for the step to properly stop
503 in the parent after the call completes!)
505 Sequence of events, as reported to gdb from HPUX:
507 Parent Child Action for gdb to take
508 -------------------------------------------------------
509 1 VFORK Continue child
515 target_post_follow_vfork (parent_pid
,
516 followed_parent
, child_pid
, followed_child
);
519 pending_follow
.fork_event
.saw_parent_fork
= 0;
520 pending_follow
.fork_event
.saw_child_fork
= 0;
524 follow_fork (int parent_pid
, int child_pid
)
526 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
530 /* Forward declaration. */
531 static void follow_exec (int, char *);
534 follow_vfork (int parent_pid
, int child_pid
)
536 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
538 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
539 if (pending_follow
.fork_event
.saw_child_exec
540 && (PIDGET (inferior_ptid
) == child_pid
))
542 pending_follow
.fork_event
.saw_child_exec
= 0;
543 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
544 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
545 xfree (pending_follow
.execd_pathname
);
549 /* EXECD_PATHNAME is assumed to be non-NULL. */
552 follow_exec (int pid
, char *execd_pathname
)
555 struct target_ops
*tgt
;
557 if (!may_follow_exec
)
560 /* This is an exec event that we actually wish to pay attention to.
561 Refresh our symbol table to the newly exec'd program, remove any
564 If there are breakpoints, they aren't really inserted now,
565 since the exec() transformed our inferior into a fresh set
568 We want to preserve symbolic breakpoints on the list, since
569 we have hopes that they can be reset after the new a.out's
570 symbol table is read.
572 However, any "raw" breakpoints must be removed from the list
573 (e.g., the solib bp's), since their address is probably invalid
576 And, we DON'T want to call delete_breakpoints() here, since
577 that may write the bp's "shadow contents" (the instruction
578 value that was overwritten witha TRAP instruction). Since
579 we now have a new a.out, those shadow contents aren't valid. */
580 update_breakpoints_after_exec ();
582 /* If there was one, it's gone now. We cannot truly step-to-next
583 statement through an exec(). */
584 step_resume_breakpoint
= NULL
;
585 step_range_start
= 0;
588 /* If there was one, it's gone now. */
589 through_sigtramp_breakpoint
= NULL
;
591 /* What is this a.out's name? */
592 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
594 /* We've followed the inferior through an exec. Therefore, the
595 inferior has essentially been killed & reborn. */
597 /* First collect the run target in effect. */
598 tgt
= find_run_target ();
599 /* If we can't find one, things are in a very strange state... */
601 error ("Could find run target to save before following exec");
603 gdb_flush (gdb_stdout
);
604 target_mourn_inferior ();
605 inferior_ptid
= pid_to_ptid (saved_pid
);
606 /* Because mourn_inferior resets inferior_ptid. */
609 /* That a.out is now the one to use. */
610 exec_file_attach (execd_pathname
, 0);
612 /* And also is where symbols can be found. */
613 symbol_file_add_main (execd_pathname
, 0);
615 /* Reset the shared library package. This ensures that we get
616 a shlib event when the child reaches "_start", at which point
617 the dld will have had a chance to initialize the child. */
618 #if defined(SOLIB_RESTART)
621 #ifdef SOLIB_CREATE_INFERIOR_HOOK
622 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
625 /* Reinsert all breakpoints. (Those which were symbolic have
626 been reset to the proper address in the new a.out, thanks
627 to symbol_file_command...) */
628 insert_breakpoints ();
630 /* The next resume of this inferior should bring it to the shlib
631 startup breakpoints. (If the user had also set bp's on
632 "main" from the old (parent) process, then they'll auto-
633 matically get reset there in the new process.) */
636 /* Non-zero if we just simulating a single-step. This is needed
637 because we cannot remove the breakpoints in the inferior process
638 until after the `wait' in `wait_for_inferior'. */
639 static int singlestep_breakpoints_inserted_p
= 0;
642 /* Things to clean up if we QUIT out of resume (). */
645 resume_cleanups (void *ignore
)
650 static const char schedlock_off
[] = "off";
651 static const char schedlock_on
[] = "on";
652 static const char schedlock_step
[] = "step";
653 static const char *scheduler_mode
= schedlock_off
;
654 static const char *scheduler_enums
[] = {
662 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
664 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
665 the set command passed as a parameter. The clone operation will
666 include (BUG?) any ``set'' command callback, if present.
667 Commands like ``info set'' call all the ``show'' command
668 callbacks. Unfortunatly, for ``show'' commands cloned from
669 ``set'', this includes callbacks belonging to ``set'' commands.
670 Making this worse, this only occures if add_show_from_set() is
671 called after add_cmd_sfunc() (BUG?). */
672 if (cmd_type (c
) == set_cmd
)
673 if (!target_can_lock_scheduler
)
675 scheduler_mode
= schedlock_off
;
676 error ("Target '%s' cannot support this command.", target_shortname
);
681 /* Resume the inferior, but allow a QUIT. This is useful if the user
682 wants to interrupt some lengthy single-stepping operation
683 (for child processes, the SIGINT goes to the inferior, and so
684 we get a SIGINT random_signal, but for remote debugging and perhaps
685 other targets, that's not true).
687 STEP nonzero if we should step (zero to continue instead).
688 SIG is the signal to give the inferior (zero for none). */
690 resume (int step
, enum target_signal sig
)
692 int should_resume
= 1;
693 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
696 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
699 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
700 over an instruction that causes a page fault without triggering
701 a hardware watchpoint. The kernel properly notices that it shouldn't
702 stop, because the hardware watchpoint is not triggered, but it forgets
703 the step request and continues the program normally.
704 Work around the problem by removing hardware watchpoints if a step is
705 requested, GDB will check for a hardware watchpoint trigger after the
707 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
708 remove_hw_watchpoints ();
711 /* Normally, by the time we reach `resume', the breakpoints are either
712 removed or inserted, as appropriate. The exception is if we're sitting
713 at a permanent breakpoint; we need to step over it, but permanent
714 breakpoints can't be removed. So we have to test for it here. */
715 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
716 SKIP_PERMANENT_BREAKPOINT ();
718 if (SOFTWARE_SINGLE_STEP_P () && step
)
720 /* Do it the hard way, w/temp breakpoints */
721 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
722 /* ...and don't ask hardware to do it. */
724 /* and do not pull these breakpoints until after a `wait' in
725 `wait_for_inferior' */
726 singlestep_breakpoints_inserted_p
= 1;
729 /* Handle any optimized stores to the inferior NOW... */
730 #ifdef DO_DEFERRED_STORES
734 /* If there were any forks/vforks/execs that were caught and are
735 now to be followed, then do so. */
736 switch (pending_follow
.kind
)
738 case (TARGET_WAITKIND_FORKED
):
739 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
740 follow_fork (PIDGET (inferior_ptid
),
741 pending_follow
.fork_event
.child_pid
);
744 case (TARGET_WAITKIND_VFORKED
):
746 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
748 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
749 follow_vfork (PIDGET (inferior_ptid
),
750 pending_follow
.fork_event
.child_pid
);
752 /* Did we follow the child, but not yet see the child's exec event?
753 If so, then it actually ought to be waiting for us; we respond to
754 parent vfork events. We don't actually want to resume the child
755 in this situation; we want to just get its exec event. */
756 if (!saw_child_exec
&&
757 (PIDGET (inferior_ptid
) == pending_follow
.fork_event
.child_pid
))
762 case (TARGET_WAITKIND_EXECD
):
763 /* If we saw a vfork event but couldn't follow it until we saw
764 an exec, then now might be the time! */
765 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
766 /* follow_exec is called as soon as the exec event is seen. */
773 /* Install inferior's terminal modes. */
774 target_terminal_inferior ();
780 resume_ptid
= RESUME_ALL
; /* Default */
782 if ((step
|| singlestep_breakpoints_inserted_p
) &&
783 !breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
785 /* Stepping past a breakpoint without inserting breakpoints.
786 Make sure only the current thread gets to step, so that
787 other threads don't sneak past breakpoints while they are
790 resume_ptid
= inferior_ptid
;
793 if ((scheduler_mode
== schedlock_on
) ||
794 (scheduler_mode
== schedlock_step
&&
795 (step
|| singlestep_breakpoints_inserted_p
)))
797 /* User-settable 'scheduler' mode requires solo thread resume. */
798 resume_ptid
= inferior_ptid
;
801 if (CANNOT_STEP_BREAKPOINT
)
803 /* Most targets can step a breakpoint instruction, thus
804 executing it normally. But if this one cannot, just
805 continue and we will hit it anyway. */
806 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
809 target_resume (resume_ptid
, step
, sig
);
812 discard_cleanups (old_cleanups
);
816 /* Clear out all variables saying what to do when inferior is continued.
817 First do this, then set the ones you want, then call `proceed'. */
820 clear_proceed_status (void)
823 step_range_start
= 0;
825 step_frame_id
= null_frame_id
;
826 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
828 stop_soon_quietly
= 0;
829 proceed_to_finish
= 0;
830 breakpoint_proceeded
= 1; /* We're about to proceed... */
832 /* Discard any remaining commands or status from previous stop. */
833 bpstat_clear (&stop_bpstat
);
836 /* Basic routine for continuing the program in various fashions.
838 ADDR is the address to resume at, or -1 for resume where stopped.
839 SIGGNAL is the signal to give it, or 0 for none,
840 or -1 for act according to how it stopped.
841 STEP is nonzero if should trap after one instruction.
842 -1 means return after that and print nothing.
843 You should probably set various step_... variables
844 before calling here, if you are stepping.
846 You should call clear_proceed_status before calling proceed. */
849 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
854 step_start_function
= find_pc_function (read_pc ());
858 if (addr
== (CORE_ADDR
) -1)
860 /* If there is a breakpoint at the address we will resume at,
861 step one instruction before inserting breakpoints
862 so that we do not stop right away (and report a second
863 hit at this breakpoint). */
865 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
868 #ifndef STEP_SKIPS_DELAY
869 #define STEP_SKIPS_DELAY(pc) (0)
870 #define STEP_SKIPS_DELAY_P (0)
872 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
873 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
874 is slow (it needs to read memory from the target). */
875 if (STEP_SKIPS_DELAY_P
876 && breakpoint_here_p (read_pc () + 4)
877 && STEP_SKIPS_DELAY (read_pc ()))
885 #ifdef PREPARE_TO_PROCEED
886 /* In a multi-threaded task we may select another thread
887 and then continue or step.
889 But if the old thread was stopped at a breakpoint, it
890 will immediately cause another breakpoint stop without
891 any execution (i.e. it will report a breakpoint hit
892 incorrectly). So we must step over it first.
894 PREPARE_TO_PROCEED checks the current thread against the thread
895 that reported the most recent event. If a step-over is required
896 it returns TRUE and sets the current thread to the old thread. */
897 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
902 #endif /* PREPARE_TO_PROCEED */
905 if (trap_expected_after_continue
)
907 /* If (step == 0), a trap will be automatically generated after
908 the first instruction is executed. Force step one
909 instruction to clear this condition. This should not occur
910 if step is nonzero, but it is harmless in that case. */
912 trap_expected_after_continue
= 0;
914 #endif /* HP_OS_BUG */
917 /* We will get a trace trap after one instruction.
918 Continue it automatically and insert breakpoints then. */
922 insert_breakpoints ();
923 /* If we get here there was no call to error() in
924 insert breakpoints -- so they were inserted. */
925 breakpoints_inserted
= 1;
928 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
929 stop_signal
= siggnal
;
930 /* If this signal should not be seen by program,
931 give it zero. Used for debugging signals. */
932 else if (!signal_program
[stop_signal
])
933 stop_signal
= TARGET_SIGNAL_0
;
935 annotate_starting ();
937 /* Make sure that output from GDB appears before output from the
939 gdb_flush (gdb_stdout
);
941 /* Resume inferior. */
942 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
944 /* Wait for it to stop (if not standalone)
945 and in any case decode why it stopped, and act accordingly. */
946 /* Do this only if we are not using the event loop, or if the target
947 does not support asynchronous execution. */
948 if (!event_loop_p
|| !target_can_async_p ())
950 wait_for_inferior ();
955 /* Record the pc and sp of the program the last time it stopped.
956 These are just used internally by wait_for_inferior, but need
957 to be preserved over calls to it and cleared when the inferior
959 static CORE_ADDR prev_pc
;
960 static CORE_ADDR prev_func_start
;
961 static char *prev_func_name
;
964 /* Start remote-debugging of a machine over a serial link. */
970 init_wait_for_inferior ();
971 stop_soon_quietly
= 1;
974 /* Always go on waiting for the target, regardless of the mode. */
975 /* FIXME: cagney/1999-09-23: At present it isn't possible to
976 indicate to wait_for_inferior that a target should timeout if
977 nothing is returned (instead of just blocking). Because of this,
978 targets expecting an immediate response need to, internally, set
979 things up so that the target_wait() is forced to eventually
981 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
982 differentiate to its caller what the state of the target is after
983 the initial open has been performed. Here we're assuming that
984 the target has stopped. It should be possible to eventually have
985 target_open() return to the caller an indication that the target
986 is currently running and GDB state should be set to the same as
988 wait_for_inferior ();
992 /* Initialize static vars when a new inferior begins. */
995 init_wait_for_inferior (void)
997 /* These are meaningless until the first time through wait_for_inferior. */
1000 prev_func_name
= NULL
;
1003 trap_expected_after_continue
= 0;
1005 breakpoints_inserted
= 0;
1006 breakpoint_init_inferior (inf_starting
);
1008 /* Don't confuse first call to proceed(). */
1009 stop_signal
= TARGET_SIGNAL_0
;
1011 /* The first resume is not following a fork/vfork/exec. */
1012 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1013 pending_follow
.fork_event
.saw_parent_fork
= 0;
1014 pending_follow
.fork_event
.saw_child_fork
= 0;
1015 pending_follow
.fork_event
.saw_child_exec
= 0;
1017 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1018 number_of_threads_in_syscalls
= 0;
1020 clear_proceed_status ();
1024 delete_breakpoint_current_contents (void *arg
)
1026 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1027 if (*breakpointp
!= NULL
)
1029 delete_breakpoint (*breakpointp
);
1030 *breakpointp
= NULL
;
1034 /* This enum encodes possible reasons for doing a target_wait, so that
1035 wfi can call target_wait in one place. (Ultimately the call will be
1036 moved out of the infinite loop entirely.) */
1040 infwait_normal_state
,
1041 infwait_thread_hop_state
,
1042 infwait_nullified_state
,
1043 infwait_nonstep_watch_state
1046 /* Why did the inferior stop? Used to print the appropriate messages
1047 to the interface from within handle_inferior_event(). */
1048 enum inferior_stop_reason
1050 /* We don't know why. */
1052 /* Step, next, nexti, stepi finished. */
1054 /* Found breakpoint. */
1056 /* Inferior terminated by signal. */
1058 /* Inferior exited. */
1060 /* Inferior received signal, and user asked to be notified. */
1064 /* This structure contains what used to be local variables in
1065 wait_for_inferior. Probably many of them can return to being
1066 locals in handle_inferior_event. */
1068 struct execution_control_state
1070 struct target_waitstatus ws
;
1071 struct target_waitstatus
*wp
;
1074 CORE_ADDR stop_func_start
;
1075 CORE_ADDR stop_func_end
;
1076 char *stop_func_name
;
1077 struct symtab_and_line sal
;
1078 int remove_breakpoints_on_following_step
;
1080 struct symtab
*current_symtab
;
1081 int handling_longjmp
; /* FIXME */
1083 ptid_t saved_inferior_ptid
;
1085 int stepping_through_solib_after_catch
;
1086 bpstat stepping_through_solib_catchpoints
;
1087 int enable_hw_watchpoints_after_wait
;
1088 int stepping_through_sigtramp
;
1089 int new_thread_event
;
1090 struct target_waitstatus tmpstatus
;
1091 enum infwait_states infwait_state
;
1096 void init_execution_control_state (struct execution_control_state
*ecs
);
1098 void handle_inferior_event (struct execution_control_state
*ecs
);
1100 static void check_sigtramp2 (struct execution_control_state
*ecs
);
1101 static void step_into_function (struct execution_control_state
*ecs
);
1102 static void step_over_function (struct execution_control_state
*ecs
);
1103 static void stop_stepping (struct execution_control_state
*ecs
);
1104 static void prepare_to_wait (struct execution_control_state
*ecs
);
1105 static void keep_going (struct execution_control_state
*ecs
);
1106 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
1109 /* Wait for control to return from inferior to debugger.
1110 If inferior gets a signal, we may decide to start it up again
1111 instead of returning. That is why there is a loop in this function.
1112 When this function actually returns it means the inferior
1113 should be left stopped and GDB should read more commands. */
1116 wait_for_inferior (void)
1118 struct cleanup
*old_cleanups
;
1119 struct execution_control_state ecss
;
1120 struct execution_control_state
*ecs
;
1122 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1123 &step_resume_breakpoint
);
1124 make_cleanup (delete_breakpoint_current_contents
,
1125 &through_sigtramp_breakpoint
);
1127 /* wfi still stays in a loop, so it's OK just to take the address of
1128 a local to get the ecs pointer. */
1131 /* Fill in with reasonable starting values. */
1132 init_execution_control_state (ecs
);
1134 /* We'll update this if & when we switch to a new thread. */
1135 previous_inferior_ptid
= inferior_ptid
;
1137 overlay_cache_invalid
= 1;
1139 /* We have to invalidate the registers BEFORE calling target_wait
1140 because they can be loaded from the target while in target_wait.
1141 This makes remote debugging a bit more efficient for those
1142 targets that provide critical registers as part of their normal
1143 status mechanism. */
1145 registers_changed ();
1149 if (target_wait_hook
)
1150 ecs
->ptid
= target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
1152 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
1154 /* Now figure out what to do with the result of the result. */
1155 handle_inferior_event (ecs
);
1157 if (!ecs
->wait_some_more
)
1160 do_cleanups (old_cleanups
);
1163 /* Asynchronous version of wait_for_inferior. It is called by the
1164 event loop whenever a change of state is detected on the file
1165 descriptor corresponding to the target. It can be called more than
1166 once to complete a single execution command. In such cases we need
1167 to keep the state in a global variable ASYNC_ECSS. If it is the
1168 last time that this function is called for a single execution
1169 command, then report to the user that the inferior has stopped, and
1170 do the necessary cleanups. */
1172 struct execution_control_state async_ecss
;
1173 struct execution_control_state
*async_ecs
;
1176 fetch_inferior_event (void *client_data
)
1178 static struct cleanup
*old_cleanups
;
1180 async_ecs
= &async_ecss
;
1182 if (!async_ecs
->wait_some_more
)
1184 old_cleanups
= make_exec_cleanup (delete_step_resume_breakpoint
,
1185 &step_resume_breakpoint
);
1186 make_exec_cleanup (delete_breakpoint_current_contents
,
1187 &through_sigtramp_breakpoint
);
1189 /* Fill in with reasonable starting values. */
1190 init_execution_control_state (async_ecs
);
1192 /* We'll update this if & when we switch to a new thread. */
1193 previous_inferior_ptid
= inferior_ptid
;
1195 overlay_cache_invalid
= 1;
1197 /* We have to invalidate the registers BEFORE calling target_wait
1198 because they can be loaded from the target while in target_wait.
1199 This makes remote debugging a bit more efficient for those
1200 targets that provide critical registers as part of their normal
1201 status mechanism. */
1203 registers_changed ();
1206 if (target_wait_hook
)
1208 target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1210 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1212 /* Now figure out what to do with the result of the result. */
1213 handle_inferior_event (async_ecs
);
1215 if (!async_ecs
->wait_some_more
)
1217 /* Do only the cleanups that have been added by this
1218 function. Let the continuations for the commands do the rest,
1219 if there are any. */
1220 do_exec_cleanups (old_cleanups
);
1222 if (step_multi
&& stop_step
)
1223 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1225 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1229 /* Prepare an execution control state for looping through a
1230 wait_for_inferior-type loop. */
1233 init_execution_control_state (struct execution_control_state
*ecs
)
1235 /* ecs->another_trap? */
1236 ecs
->random_signal
= 0;
1237 ecs
->remove_breakpoints_on_following_step
= 0;
1238 ecs
->handling_longjmp
= 0; /* FIXME */
1239 ecs
->update_step_sp
= 0;
1240 ecs
->stepping_through_solib_after_catch
= 0;
1241 ecs
->stepping_through_solib_catchpoints
= NULL
;
1242 ecs
->enable_hw_watchpoints_after_wait
= 0;
1243 ecs
->stepping_through_sigtramp
= 0;
1244 ecs
->sal
= find_pc_line (prev_pc
, 0);
1245 ecs
->current_line
= ecs
->sal
.line
;
1246 ecs
->current_symtab
= ecs
->sal
.symtab
;
1247 ecs
->infwait_state
= infwait_normal_state
;
1248 ecs
->waiton_ptid
= pid_to_ptid (-1);
1249 ecs
->wp
= &(ecs
->ws
);
1252 /* Call this function before setting step_resume_breakpoint, as a
1253 sanity check. There should never be more than one step-resume
1254 breakpoint per thread, so we should never be setting a new
1255 step_resume_breakpoint when one is already active. */
1257 check_for_old_step_resume_breakpoint (void)
1259 if (step_resume_breakpoint
)
1261 ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1264 /* Return the cached copy of the last pid/waitstatus returned by
1265 target_wait()/target_wait_hook(). The data is actually cached by
1266 handle_inferior_event(), which gets called immediately after
1267 target_wait()/target_wait_hook(). */
1270 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
1272 *ptidp
= target_last_wait_ptid
;
1273 *status
= target_last_waitstatus
;
1276 /* Switch thread contexts, maintaining "infrun state". */
1279 context_switch (struct execution_control_state
*ecs
)
1281 /* Caution: it may happen that the new thread (or the old one!)
1282 is not in the thread list. In this case we must not attempt
1283 to "switch context", or we run the risk that our context may
1284 be lost. This may happen as a result of the target module
1285 mishandling thread creation. */
1287 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1288 { /* Perform infrun state context switch: */
1289 /* Save infrun state for the old thread. */
1290 save_infrun_state (inferior_ptid
, prev_pc
,
1291 prev_func_start
, prev_func_name
,
1292 trap_expected
, step_resume_breakpoint
,
1293 through_sigtramp_breakpoint
, step_range_start
,
1294 step_range_end
, &step_frame_id
,
1295 ecs
->handling_longjmp
, ecs
->another_trap
,
1296 ecs
->stepping_through_solib_after_catch
,
1297 ecs
->stepping_through_solib_catchpoints
,
1298 ecs
->stepping_through_sigtramp
,
1299 ecs
->current_line
, ecs
->current_symtab
, step_sp
);
1301 /* Load infrun state for the new thread. */
1302 load_infrun_state (ecs
->ptid
, &prev_pc
,
1303 &prev_func_start
, &prev_func_name
,
1304 &trap_expected
, &step_resume_breakpoint
,
1305 &through_sigtramp_breakpoint
, &step_range_start
,
1306 &step_range_end
, &step_frame_id
,
1307 &ecs
->handling_longjmp
, &ecs
->another_trap
,
1308 &ecs
->stepping_through_solib_after_catch
,
1309 &ecs
->stepping_through_solib_catchpoints
,
1310 &ecs
->stepping_through_sigtramp
,
1311 &ecs
->current_line
, &ecs
->current_symtab
, &step_sp
);
1313 inferior_ptid
= ecs
->ptid
;
1317 /* Given an execution control state that has been freshly filled in
1318 by an event from the inferior, figure out what it means and take
1319 appropriate action. */
1322 handle_inferior_event (struct execution_control_state
*ecs
)
1325 int stepped_after_stopped_by_watchpoint
;
1326 int sw_single_step_trap_p
= 0;
1328 /* Cache the last pid/waitstatus. */
1329 target_last_wait_ptid
= ecs
->ptid
;
1330 target_last_waitstatus
= *ecs
->wp
;
1332 switch (ecs
->infwait_state
)
1334 case infwait_thread_hop_state
:
1335 /* Cancel the waiton_ptid. */
1336 ecs
->waiton_ptid
= pid_to_ptid (-1);
1337 /* Fall thru to the normal_state case. */
1339 case infwait_normal_state
:
1340 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1341 is serviced in this loop, below. */
1342 if (ecs
->enable_hw_watchpoints_after_wait
)
1344 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1345 ecs
->enable_hw_watchpoints_after_wait
= 0;
1347 stepped_after_stopped_by_watchpoint
= 0;
1350 case infwait_nullified_state
:
1353 case infwait_nonstep_watch_state
:
1354 insert_breakpoints ();
1356 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1357 handle things like signals arriving and other things happening
1358 in combination correctly? */
1359 stepped_after_stopped_by_watchpoint
= 1;
1362 ecs
->infwait_state
= infwait_normal_state
;
1364 flush_cached_frames ();
1366 /* If it's a new process, add it to the thread database */
1368 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
1369 && !in_thread_list (ecs
->ptid
));
1371 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1372 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
1374 add_thread (ecs
->ptid
);
1376 ui_out_text (uiout
, "[New ");
1377 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->ptid
));
1378 ui_out_text (uiout
, "]\n");
1381 /* NOTE: This block is ONLY meant to be invoked in case of a
1382 "thread creation event"! If it is invoked for any other
1383 sort of event (such as a new thread landing on a breakpoint),
1384 the event will be discarded, which is almost certainly
1387 To avoid this, the low-level module (eg. target_wait)
1388 should call in_thread_list and add_thread, so that the
1389 new thread is known by the time we get here. */
1391 /* We may want to consider not doing a resume here in order
1392 to give the user a chance to play with the new thread.
1393 It might be good to make that a user-settable option. */
1395 /* At this point, all threads are stopped (happens
1396 automatically in either the OS or the native code).
1397 Therefore we need to continue all threads in order to
1400 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1401 prepare_to_wait (ecs
);
1406 switch (ecs
->ws
.kind
)
1408 case TARGET_WAITKIND_LOADED
:
1409 /* Ignore gracefully during startup of the inferior, as it
1410 might be the shell which has just loaded some objects,
1411 otherwise add the symbols for the newly loaded objects. */
1413 if (!stop_soon_quietly
)
1415 /* Remove breakpoints, SOLIB_ADD might adjust
1416 breakpoint addresses via breakpoint_re_set. */
1417 if (breakpoints_inserted
)
1418 remove_breakpoints ();
1420 /* Check for any newly added shared libraries if we're
1421 supposed to be adding them automatically. Switch
1422 terminal for any messages produced by
1423 breakpoint_re_set. */
1424 target_terminal_ours_for_output ();
1425 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
1426 target_terminal_inferior ();
1428 /* Reinsert breakpoints and continue. */
1429 if (breakpoints_inserted
)
1430 insert_breakpoints ();
1433 resume (0, TARGET_SIGNAL_0
);
1434 prepare_to_wait (ecs
);
1437 case TARGET_WAITKIND_SPURIOUS
:
1438 resume (0, TARGET_SIGNAL_0
);
1439 prepare_to_wait (ecs
);
1442 case TARGET_WAITKIND_EXITED
:
1443 target_terminal_ours (); /* Must do this before mourn anyway */
1444 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1446 /* Record the exit code in the convenience variable $_exitcode, so
1447 that the user can inspect this again later. */
1448 set_internalvar (lookup_internalvar ("_exitcode"),
1449 value_from_longest (builtin_type_int
,
1450 (LONGEST
) ecs
->ws
.value
.integer
));
1451 gdb_flush (gdb_stdout
);
1452 target_mourn_inferior ();
1453 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1454 stop_print_frame
= 0;
1455 stop_stepping (ecs
);
1458 case TARGET_WAITKIND_SIGNALLED
:
1459 stop_print_frame
= 0;
1460 stop_signal
= ecs
->ws
.value
.sig
;
1461 target_terminal_ours (); /* Must do this before mourn anyway */
1463 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1464 reach here unless the inferior is dead. However, for years
1465 target_kill() was called here, which hints that fatal signals aren't
1466 really fatal on some systems. If that's true, then some changes
1468 target_mourn_inferior ();
1470 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1471 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1472 stop_stepping (ecs
);
1475 /* The following are the only cases in which we keep going;
1476 the above cases end in a continue or goto. */
1477 case TARGET_WAITKIND_FORKED
:
1478 stop_signal
= TARGET_SIGNAL_TRAP
;
1479 pending_follow
.kind
= ecs
->ws
.kind
;
1481 /* Ignore fork events reported for the parent; we're only
1482 interested in reacting to forks of the child. Note that
1483 we expect the child's fork event to be available if we
1484 waited for it now. */
1485 if (ptid_equal (inferior_ptid
, ecs
->ptid
))
1487 pending_follow
.fork_event
.saw_parent_fork
= 1;
1488 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1489 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1490 prepare_to_wait (ecs
);
1495 pending_follow
.fork_event
.saw_child_fork
= 1;
1496 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1497 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1500 stop_pc
= read_pc_pid (ecs
->ptid
);
1501 ecs
->saved_inferior_ptid
= inferior_ptid
;
1502 inferior_ptid
= ecs
->ptid
;
1503 /* The second argument of bpstat_stop_status is meant to help
1504 distinguish between a breakpoint trap and a singlestep trap.
1505 This is only important on targets where DECR_PC_AFTER_BREAK
1506 is non-zero. The prev_pc test is meant to distinguish between
1507 singlestepping a trap instruction, and singlestepping thru a
1508 jump to the instruction following a trap instruction. */
1510 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1511 currently_stepping (ecs
) &&
1513 stop_pc
- DECR_PC_AFTER_BREAK
);
1514 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1515 inferior_ptid
= ecs
->saved_inferior_ptid
;
1516 goto process_event_stop_test
;
1518 /* If this a platform which doesn't allow a debugger to touch a
1519 vfork'd inferior until after it exec's, then we'd best keep
1520 our fingers entirely off the inferior, other than continuing
1521 it. This has the unfortunate side-effect that catchpoints
1522 of vforks will be ignored. But since the platform doesn't
1523 allow the inferior be touched at vfork time, there's really
1525 case TARGET_WAITKIND_VFORKED
:
1526 stop_signal
= TARGET_SIGNAL_TRAP
;
1527 pending_follow
.kind
= ecs
->ws
.kind
;
1529 /* Is this a vfork of the parent? If so, then give any
1530 vfork catchpoints a chance to trigger now. (It's
1531 dangerous to do so if the child canot be touched until
1532 it execs, and the child has not yet exec'd. We probably
1533 should warn the user to that effect when the catchpoint
1535 if (ptid_equal (ecs
->ptid
, inferior_ptid
))
1537 pending_follow
.fork_event
.saw_parent_fork
= 1;
1538 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1539 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1542 /* If we've seen the child's vfork event but cannot really touch
1543 the child until it execs, then we must continue the child now.
1544 Else, give any vfork catchpoints a chance to trigger now. */
1547 pending_follow
.fork_event
.saw_child_fork
= 1;
1548 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1549 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1550 target_post_startup_inferior (pid_to_ptid
1551 (pending_follow
.fork_event
.
1555 stop_pc
= read_pc ();
1556 /* The second argument of bpstat_stop_status is meant to help
1557 distinguish between a breakpoint trap and a singlestep trap.
1558 This is only important on targets where DECR_PC_AFTER_BREAK
1559 is non-zero. The prev_pc test is meant to distinguish between
1560 singlestepping a trap instruction, and singlestepping thru a
1561 jump to the instruction following a trap instruction. */
1563 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1564 currently_stepping (ecs
) &&
1566 stop_pc
- DECR_PC_AFTER_BREAK
);
1567 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1568 goto process_event_stop_test
;
1570 case TARGET_WAITKIND_EXECD
:
1571 stop_signal
= TARGET_SIGNAL_TRAP
;
1573 /* Is this a target which reports multiple exec events per actual
1574 call to exec()? (HP-UX using ptrace does, for example.) If so,
1575 ignore all but the last one. Just resume the exec'r, and wait
1576 for the next exec event. */
1577 if (inferior_ignoring_leading_exec_events
)
1579 inferior_ignoring_leading_exec_events
--;
1580 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1581 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.
1583 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1584 prepare_to_wait (ecs
);
1587 inferior_ignoring_leading_exec_events
=
1588 target_reported_exec_events_per_exec_call () - 1;
1590 pending_follow
.execd_pathname
=
1591 savestring (ecs
->ws
.value
.execd_pathname
,
1592 strlen (ecs
->ws
.value
.execd_pathname
));
1594 /* Did inferior_ptid exec, or did a (possibly not-yet-followed)
1595 child of a vfork exec?
1597 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1598 HP-UX, events associated with a vforking inferior come in
1599 threes: a vfork event for the child (always first), followed
1600 a vfork event for the parent and an exec event for the child.
1601 The latter two can come in either order.
1603 If we get the parent vfork event first, life's good: We follow
1604 either the parent or child, and then the child's exec event is
1607 But if we get the child's exec event first, then we delay
1608 responding to it until we handle the parent's vfork. Because,
1609 otherwise we can't satisfy a "catch vfork". */
1610 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1612 pending_follow
.fork_event
.saw_child_exec
= 1;
1614 /* On some targets, the child must be resumed before
1615 the parent vfork event is delivered. A single-step
1617 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1618 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1619 /* We expect the parent vfork event to be available now. */
1620 prepare_to_wait (ecs
);
1624 /* This causes the eventpoints and symbol table to be reset. Must
1625 do this now, before trying to determine whether to stop. */
1626 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1627 xfree (pending_follow
.execd_pathname
);
1629 stop_pc
= read_pc_pid (ecs
->ptid
);
1630 ecs
->saved_inferior_ptid
= inferior_ptid
;
1631 inferior_ptid
= ecs
->ptid
;
1632 /* The second argument of bpstat_stop_status is meant to help
1633 distinguish between a breakpoint trap and a singlestep trap.
1634 This is only important on targets where DECR_PC_AFTER_BREAK
1635 is non-zero. The prev_pc test is meant to distinguish between
1636 singlestepping a trap instruction, and singlestepping thru a
1637 jump to the instruction following a trap instruction. */
1639 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1640 currently_stepping (ecs
) &&
1642 stop_pc
- DECR_PC_AFTER_BREAK
);
1643 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1644 inferior_ptid
= ecs
->saved_inferior_ptid
;
1645 goto process_event_stop_test
;
1647 /* These syscall events are returned on HP-UX, as part of its
1648 implementation of page-protection-based "hardware" watchpoints.
1649 HP-UX has unfortunate interactions between page-protections and
1650 some system calls. Our solution is to disable hardware watches
1651 when a system call is entered, and reenable them when the syscall
1652 completes. The downside of this is that we may miss the precise
1653 point at which a watched piece of memory is modified. "Oh well."
1655 Note that we may have multiple threads running, which may each
1656 enter syscalls at roughly the same time. Since we don't have a
1657 good notion currently of whether a watched piece of memory is
1658 thread-private, we'd best not have any page-protections active
1659 when any thread is in a syscall. Thus, we only want to reenable
1660 hardware watches when no threads are in a syscall.
1662 Also, be careful not to try to gather much state about a thread
1663 that's in a syscall. It's frequently a losing proposition. */
1664 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1665 number_of_threads_in_syscalls
++;
1666 if (number_of_threads_in_syscalls
== 1)
1668 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1670 resume (0, TARGET_SIGNAL_0
);
1671 prepare_to_wait (ecs
);
1674 /* Before examining the threads further, step this thread to
1675 get it entirely out of the syscall. (We get notice of the
1676 event when the thread is just on the verge of exiting a
1677 syscall. Stepping one instruction seems to get it back
1680 Note that although the logical place to reenable h/w watches
1681 is here, we cannot. We cannot reenable them before stepping
1682 the thread (this causes the next wait on the thread to hang).
1684 Nor can we enable them after stepping until we've done a wait.
1685 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1686 here, which will be serviced immediately after the target
1688 case TARGET_WAITKIND_SYSCALL_RETURN
:
1689 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1691 if (number_of_threads_in_syscalls
> 0)
1693 number_of_threads_in_syscalls
--;
1694 ecs
->enable_hw_watchpoints_after_wait
=
1695 (number_of_threads_in_syscalls
== 0);
1697 prepare_to_wait (ecs
);
1700 case TARGET_WAITKIND_STOPPED
:
1701 stop_signal
= ecs
->ws
.value
.sig
;
1704 /* We had an event in the inferior, but we are not interested
1705 in handling it at this level. The lower layers have already
1706 done what needs to be done, if anything. This case can
1707 occur only when the target is async or extended-async. One
1708 of the circumstamces for this to happen is when the
1709 inferior produces output for the console. The inferior has
1710 not stopped, and we are ignoring the event. */
1711 case TARGET_WAITKIND_IGNORE
:
1712 ecs
->wait_some_more
= 1;
1716 /* We may want to consider not doing a resume here in order to give
1717 the user a chance to play with the new thread. It might be good
1718 to make that a user-settable option. */
1720 /* At this point, all threads are stopped (happens automatically in
1721 either the OS or the native code). Therefore we need to continue
1722 all threads in order to make progress. */
1723 if (ecs
->new_thread_event
)
1725 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1726 prepare_to_wait (ecs
);
1730 stop_pc
= read_pc_pid (ecs
->ptid
);
1732 /* See if a thread hit a thread-specific breakpoint that was meant for
1733 another thread. If so, then step that thread past the breakpoint,
1736 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1738 /* Check if a regular breakpoint has been hit before checking
1739 for a potential single step breakpoint. Otherwise, GDB will
1740 not see this breakpoint hit when stepping onto breakpoints. */
1741 if (breakpoints_inserted
1742 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1744 ecs
->random_signal
= 0;
1745 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1750 /* Saw a breakpoint, but it was hit by the wrong thread.
1752 if (DECR_PC_AFTER_BREAK
)
1753 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->ptid
);
1755 remove_status
= remove_breakpoints ();
1756 /* Did we fail to remove breakpoints? If so, try
1757 to set the PC past the bp. (There's at least
1758 one situation in which we can fail to remove
1759 the bp's: On HP-UX's that use ttrace, we can't
1760 change the address space of a vforking child
1761 process until the child exits (well, okay, not
1762 then either :-) or execs. */
1763 if (remove_status
!= 0)
1765 /* FIXME! This is obviously non-portable! */
1766 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->ptid
);
1767 /* We need to restart all the threads now,
1768 * unles we're running in scheduler-locked mode.
1769 * Use currently_stepping to determine whether to
1772 /* FIXME MVS: is there any reason not to call resume()? */
1773 if (scheduler_mode
== schedlock_on
)
1774 target_resume (ecs
->ptid
,
1775 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1777 target_resume (RESUME_ALL
,
1778 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1779 prepare_to_wait (ecs
);
1784 breakpoints_inserted
= 0;
1785 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
1786 context_switch (ecs
);
1787 ecs
->waiton_ptid
= ecs
->ptid
;
1788 ecs
->wp
= &(ecs
->ws
);
1789 ecs
->another_trap
= 1;
1791 ecs
->infwait_state
= infwait_thread_hop_state
;
1793 registers_changed ();
1798 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1800 /* Readjust the stop_pc as it is off by DECR_PC_AFTER_BREAK
1801 compared to the value it would have if the system stepping
1802 capability was used. This allows the rest of the code in
1803 this function to use this address without having to worry
1804 whether software single step is in use or not. */
1805 if (DECR_PC_AFTER_BREAK
)
1807 stop_pc
-= DECR_PC_AFTER_BREAK
;
1808 write_pc_pid (stop_pc
, ecs
->ptid
);
1811 sw_single_step_trap_p
= 1;
1812 ecs
->random_signal
= 0;
1816 ecs
->random_signal
= 1;
1818 /* See if something interesting happened to the non-current thread. If
1819 so, then switch to that thread, and eventually give control back to
1822 Note that if there's any kind of pending follow (i.e., of a fork,
1823 vfork or exec), we don't want to do this now. Rather, we'll let
1824 the next resume handle it. */
1825 if (!ptid_equal (ecs
->ptid
, inferior_ptid
) &&
1826 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1830 /* If it's a random signal for a non-current thread, notify user
1831 if he's expressed an interest. */
1832 if (ecs
->random_signal
&& signal_print
[stop_signal
])
1834 /* ??rehrauer: I don't understand the rationale for this code. If the
1835 inferior will stop as a result of this signal, then the act of handling
1836 the stop ought to print a message that's couches the stoppage in user
1837 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1838 won't stop as a result of the signal -- i.e., if the signal is merely
1839 a side-effect of something GDB's doing "under the covers" for the
1840 user, such as stepping threads over a breakpoint they shouldn't stop
1841 for -- then the message seems to be a serious annoyance at best.
1843 For now, remove the message altogether. */
1846 target_terminal_ours_for_output ();
1847 printf_filtered ("\nProgram received signal %s, %s.\n",
1848 target_signal_to_name (stop_signal
),
1849 target_signal_to_string (stop_signal
));
1850 gdb_flush (gdb_stdout
);
1854 /* If it's not SIGTRAP and not a signal we want to stop for, then
1855 continue the thread. */
1857 if (stop_signal
!= TARGET_SIGNAL_TRAP
&& !signal_stop
[stop_signal
])
1860 target_terminal_inferior ();
1862 /* Clear the signal if it should not be passed. */
1863 if (signal_program
[stop_signal
] == 0)
1864 stop_signal
= TARGET_SIGNAL_0
;
1866 target_resume (ecs
->ptid
, 0, stop_signal
);
1867 prepare_to_wait (ecs
);
1871 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1872 and fall into the rest of wait_for_inferior(). */
1874 context_switch (ecs
);
1877 context_hook (pid_to_thread_id (ecs
->ptid
));
1879 flush_cached_frames ();
1882 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1884 /* Pull the single step breakpoints out of the target. */
1885 SOFTWARE_SINGLE_STEP (0, 0);
1886 singlestep_breakpoints_inserted_p
= 0;
1889 /* If PC is pointing at a nullified instruction, then step beyond
1890 it so that the user won't be confused when GDB appears to be ready
1893 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1894 if (INSTRUCTION_NULLIFIED
)
1896 registers_changed ();
1897 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1899 /* We may have received a signal that we want to pass to
1900 the inferior; therefore, we must not clobber the waitstatus
1903 ecs
->infwait_state
= infwait_nullified_state
;
1904 ecs
->waiton_ptid
= ecs
->ptid
;
1905 ecs
->wp
= &(ecs
->tmpstatus
);
1906 prepare_to_wait (ecs
);
1910 /* It may not be necessary to disable the watchpoint to stop over
1911 it. For example, the PA can (with some kernel cooperation)
1912 single step over a watchpoint without disabling the watchpoint. */
1913 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1916 prepare_to_wait (ecs
);
1920 /* It is far more common to need to disable a watchpoint to step
1921 the inferior over it. FIXME. What else might a debug
1922 register or page protection watchpoint scheme need here? */
1923 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1925 /* At this point, we are stopped at an instruction which has
1926 attempted to write to a piece of memory under control of
1927 a watchpoint. The instruction hasn't actually executed
1928 yet. If we were to evaluate the watchpoint expression
1929 now, we would get the old value, and therefore no change
1930 would seem to have occurred.
1932 In order to make watchpoints work `right', we really need
1933 to complete the memory write, and then evaluate the
1934 watchpoint expression. The following code does that by
1935 removing the watchpoint (actually, all watchpoints and
1936 breakpoints), single-stepping the target, re-inserting
1937 watchpoints, and then falling through to let normal
1938 single-step processing handle proceed. Since this
1939 includes evaluating watchpoints, things will come to a
1940 stop in the correct manner. */
1942 if (DECR_PC_AFTER_BREAK
)
1943 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
1945 remove_breakpoints ();
1946 registers_changed ();
1947 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
1949 ecs
->waiton_ptid
= ecs
->ptid
;
1950 ecs
->wp
= &(ecs
->ws
);
1951 ecs
->infwait_state
= infwait_nonstep_watch_state
;
1952 prepare_to_wait (ecs
);
1956 /* It may be possible to simply continue after a watchpoint. */
1957 if (HAVE_CONTINUABLE_WATCHPOINT
)
1958 STOPPED_BY_WATCHPOINT (ecs
->ws
);
1960 ecs
->stop_func_start
= 0;
1961 ecs
->stop_func_end
= 0;
1962 ecs
->stop_func_name
= 0;
1963 /* Don't care about return value; stop_func_start and stop_func_name
1964 will both be 0 if it doesn't work. */
1965 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
1966 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
1967 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
1968 ecs
->another_trap
= 0;
1969 bpstat_clear (&stop_bpstat
);
1971 stop_stack_dummy
= 0;
1972 stop_print_frame
= 1;
1973 ecs
->random_signal
= 0;
1974 stopped_by_random_signal
= 0;
1975 breakpoints_failed
= 0;
1977 /* Look at the cause of the stop, and decide what to do.
1978 The alternatives are:
1979 1) break; to really stop and return to the debugger,
1980 2) drop through to start up again
1981 (set ecs->another_trap to 1 to single step once)
1982 3) set ecs->random_signal to 1, and the decision between 1 and 2
1983 will be made according to the signal handling tables. */
1985 /* First, distinguish signals caused by the debugger from signals
1986 that have to do with the program's own actions.
1987 Note that breakpoint insns may cause SIGTRAP or SIGILL
1988 or SIGEMT, depending on the operating system version.
1989 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1990 and change it to SIGTRAP. */
1992 if (stop_signal
== TARGET_SIGNAL_TRAP
1993 || (breakpoints_inserted
&&
1994 (stop_signal
== TARGET_SIGNAL_ILL
1995 || stop_signal
== TARGET_SIGNAL_EMT
)) || stop_soon_quietly
)
1997 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
1999 stop_print_frame
= 0;
2000 stop_stepping (ecs
);
2003 if (stop_soon_quietly
)
2005 stop_stepping (ecs
);
2009 /* Don't even think about breakpoints
2010 if just proceeded over a breakpoint.
2012 However, if we are trying to proceed over a breakpoint
2013 and end up in sigtramp, then through_sigtramp_breakpoint
2014 will be set and we should check whether we've hit the
2016 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2017 && through_sigtramp_breakpoint
== NULL
)
2018 bpstat_clear (&stop_bpstat
);
2021 /* See if there is a breakpoint at the current PC. */
2023 /* The second argument of bpstat_stop_status is meant to help
2024 distinguish between a breakpoint trap and a singlestep trap.
2025 This is only important on targets where DECR_PC_AFTER_BREAK
2026 is non-zero. The prev_pc test is meant to distinguish between
2027 singlestepping a trap instruction, and singlestepping thru a
2028 jump to the instruction following a trap instruction.
2030 Therefore, pass TRUE if our reason for stopping is
2031 something other than hitting a breakpoint. We do this by
2032 checking that either: we detected earlier a software single
2033 step trap or, 1) stepping is going on and 2) we didn't hit
2034 a breakpoint in a signal handler without an intervening stop
2035 in sigtramp, which is detected by a new stack pointer value
2036 below any usual function calling stack adjustments. */
2040 sw_single_step_trap_p
2041 || (currently_stepping (ecs
)
2042 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
2044 && INNER_THAN (read_sp (), (step_sp
- 16)))));
2045 /* Following in case break condition called a
2047 stop_print_frame
= 1;
2050 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2052 = !(bpstat_explains_signal (stop_bpstat
)
2054 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2055 && DEPRECATED_PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2056 get_frame_base (get_current_frame ())))
2057 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2061 ecs
->random_signal
= !(bpstat_explains_signal (stop_bpstat
)
2062 /* End of a stack dummy. Some systems (e.g. Sony
2063 news) give another signal besides SIGTRAP, so
2064 check here as well as above. */
2065 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2066 && DEPRECATED_PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2070 if (!ecs
->random_signal
)
2071 stop_signal
= TARGET_SIGNAL_TRAP
;
2075 /* When we reach this point, we've pretty much decided
2076 that the reason for stopping must've been a random
2077 (unexpected) signal. */
2080 ecs
->random_signal
= 1;
2081 /* If a fork, vfork or exec event was seen, then there are two
2082 possible responses we can make:
2084 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2085 then we must stop now and issue a prompt. We will resume
2086 the inferior when the user tells us to.
2087 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2088 then we must resume the inferior now and keep checking.
2090 In either case, we must take appropriate steps to "follow" the
2091 the fork/vfork/exec when the inferior is resumed. For example,
2092 if follow-fork-mode is "child", then we must detach from the
2093 parent inferior and follow the new child inferior.
2095 In either case, setting pending_follow causes the next resume()
2096 to take the appropriate following action. */
2097 process_event_stop_test
:
2098 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2100 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2103 stop_signal
= TARGET_SIGNAL_0
;
2108 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2110 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2112 stop_signal
= TARGET_SIGNAL_0
;
2117 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2119 pending_follow
.kind
= ecs
->ws
.kind
;
2120 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2123 stop_signal
= TARGET_SIGNAL_0
;
2129 /* For the program's own signals, act according to
2130 the signal handling tables. */
2132 if (ecs
->random_signal
)
2134 /* Signal not for debugging purposes. */
2137 stopped_by_random_signal
= 1;
2139 if (signal_print
[stop_signal
])
2142 target_terminal_ours_for_output ();
2143 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2145 if (signal_stop
[stop_signal
])
2147 stop_stepping (ecs
);
2150 /* If not going to stop, give terminal back
2151 if we took it away. */
2153 target_terminal_inferior ();
2155 /* Clear the signal if it should not be passed. */
2156 if (signal_program
[stop_signal
] == 0)
2157 stop_signal
= TARGET_SIGNAL_0
;
2159 /* I'm not sure whether this needs to be check_sigtramp2 or
2160 whether it could/should be keep_going.
2162 This used to jump to step_over_function if we are stepping,
2165 Suppose the user does a `next' over a function call, and while
2166 that call is in progress, the inferior receives a signal for
2167 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2168 that case, when we reach this point, there is already a
2169 step-resume breakpoint established, right where it should be:
2170 immediately after the function call the user is "next"-ing
2171 over. If we call step_over_function now, two bad things
2174 - we'll create a new breakpoint, at wherever the current
2175 frame's return address happens to be. That could be
2176 anywhere, depending on what function call happens to be on
2177 the top of the stack at that point. Point is, it's probably
2178 not where we need it.
2180 - the existing step-resume breakpoint (which is at the correct
2181 address) will get orphaned: step_resume_breakpoint will point
2182 to the new breakpoint, and the old step-resume breakpoint
2183 will never be cleaned up.
2185 The old behavior was meant to help HP-UX single-step out of
2186 sigtramps. It would place the new breakpoint at prev_pc, which
2187 was certainly wrong. I don't know the details there, so fixing
2188 this probably breaks that. As with anything else, it's up to
2189 the HP-UX maintainer to furnish a fix that doesn't break other
2190 platforms. --JimB, 20 May 1999 */
2191 check_sigtramp2 (ecs
);
2196 /* Handle cases caused by hitting a breakpoint. */
2198 CORE_ADDR jmp_buf_pc
;
2199 struct bpstat_what what
;
2201 what
= bpstat_what (stop_bpstat
);
2203 if (what
.call_dummy
)
2205 stop_stack_dummy
= 1;
2207 trap_expected_after_continue
= 1;
2211 switch (what
.main_action
)
2213 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2214 /* If we hit the breakpoint at longjmp, disable it for the
2215 duration of this command. Then, install a temporary
2216 breakpoint at the target of the jmp_buf. */
2217 disable_longjmp_breakpoint ();
2218 remove_breakpoints ();
2219 breakpoints_inserted
= 0;
2220 if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc
))
2226 /* Need to blow away step-resume breakpoint, as it
2227 interferes with us */
2228 if (step_resume_breakpoint
!= NULL
)
2230 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2232 /* Not sure whether we need to blow this away too, but probably
2233 it is like the step-resume breakpoint. */
2234 if (through_sigtramp_breakpoint
!= NULL
)
2236 delete_breakpoint (through_sigtramp_breakpoint
);
2237 through_sigtramp_breakpoint
= NULL
;
2241 /* FIXME - Need to implement nested temporary breakpoints */
2242 if (step_over_calls
> 0)
2243 set_longjmp_resume_breakpoint (jmp_buf_pc
, get_current_frame ());
2246 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2247 ecs
->handling_longjmp
= 1; /* FIXME */
2251 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2252 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2253 remove_breakpoints ();
2254 breakpoints_inserted
= 0;
2256 /* FIXME - Need to implement nested temporary breakpoints */
2258 && (frame_id_inner (get_frame_id (get_current_frame ()),
2261 ecs
->another_trap
= 1;
2266 disable_longjmp_breakpoint ();
2267 ecs
->handling_longjmp
= 0; /* FIXME */
2268 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2270 /* else fallthrough */
2272 case BPSTAT_WHAT_SINGLE
:
2273 if (breakpoints_inserted
)
2275 remove_breakpoints ();
2277 breakpoints_inserted
= 0;
2278 ecs
->another_trap
= 1;
2279 /* Still need to check other stuff, at least the case
2280 where we are stepping and step out of the right range. */
2283 case BPSTAT_WHAT_STOP_NOISY
:
2284 stop_print_frame
= 1;
2286 /* We are about to nuke the step_resume_breakpoint and
2287 through_sigtramp_breakpoint via the cleanup chain, so
2288 no need to worry about it here. */
2290 stop_stepping (ecs
);
2293 case BPSTAT_WHAT_STOP_SILENT
:
2294 stop_print_frame
= 0;
2296 /* We are about to nuke the step_resume_breakpoint and
2297 through_sigtramp_breakpoint via the cleanup chain, so
2298 no need to worry about it here. */
2300 stop_stepping (ecs
);
2303 case BPSTAT_WHAT_STEP_RESUME
:
2304 /* This proably demands a more elegant solution, but, yeah
2307 This function's use of the simple variable
2308 step_resume_breakpoint doesn't seem to accomodate
2309 simultaneously active step-resume bp's, although the
2310 breakpoint list certainly can.
2312 If we reach here and step_resume_breakpoint is already
2313 NULL, then apparently we have multiple active
2314 step-resume bp's. We'll just delete the breakpoint we
2315 stopped at, and carry on.
2317 Correction: what the code currently does is delete a
2318 step-resume bp, but it makes no effort to ensure that
2319 the one deleted is the one currently stopped at. MVS */
2321 if (step_resume_breakpoint
== NULL
)
2323 step_resume_breakpoint
=
2324 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2326 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2329 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2330 if (through_sigtramp_breakpoint
)
2331 delete_breakpoint (through_sigtramp_breakpoint
);
2332 through_sigtramp_breakpoint
= NULL
;
2334 /* If were waiting for a trap, hitting the step_resume_break
2335 doesn't count as getting it. */
2337 ecs
->another_trap
= 1;
2340 case BPSTAT_WHAT_CHECK_SHLIBS
:
2341 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2344 /* Remove breakpoints, we eventually want to step over the
2345 shlib event breakpoint, and SOLIB_ADD might adjust
2346 breakpoint addresses via breakpoint_re_set. */
2347 if (breakpoints_inserted
)
2348 remove_breakpoints ();
2349 breakpoints_inserted
= 0;
2351 /* Check for any newly added shared libraries if we're
2352 supposed to be adding them automatically. Switch
2353 terminal for any messages produced by
2354 breakpoint_re_set. */
2355 target_terminal_ours_for_output ();
2356 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
2357 target_terminal_inferior ();
2359 /* Try to reenable shared library breakpoints, additional
2360 code segments in shared libraries might be mapped in now. */
2361 re_enable_breakpoints_in_shlibs ();
2363 /* If requested, stop when the dynamic linker notifies
2364 gdb of events. This allows the user to get control
2365 and place breakpoints in initializer routines for
2366 dynamically loaded objects (among other things). */
2367 if (stop_on_solib_events
)
2369 stop_stepping (ecs
);
2373 /* If we stopped due to an explicit catchpoint, then the
2374 (see above) call to SOLIB_ADD pulled in any symbols
2375 from a newly-loaded library, if appropriate.
2377 We do want the inferior to stop, but not where it is
2378 now, which is in the dynamic linker callback. Rather,
2379 we would like it stop in the user's program, just after
2380 the call that caused this catchpoint to trigger. That
2381 gives the user a more useful vantage from which to
2382 examine their program's state. */
2383 else if (what
.main_action
==
2384 BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2386 /* ??rehrauer: If I could figure out how to get the
2387 right return PC from here, we could just set a temp
2388 breakpoint and resume. I'm not sure we can without
2389 cracking open the dld's shared libraries and sniffing
2390 their unwind tables and text/data ranges, and that's
2391 not a terribly portable notion.
2393 Until that time, we must step the inferior out of the
2394 dld callback, and also out of the dld itself (and any
2395 code or stubs in libdld.sl, such as "shl_load" and
2396 friends) until we reach non-dld code. At that point,
2397 we can stop stepping. */
2398 bpstat_get_triggered_catchpoints (stop_bpstat
,
2400 stepping_through_solib_catchpoints
);
2401 ecs
->stepping_through_solib_after_catch
= 1;
2403 /* Be sure to lift all breakpoints, so the inferior does
2404 actually step past this point... */
2405 ecs
->another_trap
= 1;
2410 /* We want to step over this breakpoint, then keep going. */
2411 ecs
->another_trap
= 1;
2418 case BPSTAT_WHAT_LAST
:
2419 /* Not a real code, but listed here to shut up gcc -Wall. */
2421 case BPSTAT_WHAT_KEEP_CHECKING
:
2426 /* We come here if we hit a breakpoint but should not
2427 stop for it. Possibly we also were stepping
2428 and should stop for that. So fall through and
2429 test for stepping. But, if not stepping,
2432 /* Are we stepping to get the inferior out of the dynamic
2433 linker's hook (and possibly the dld itself) after catching
2435 if (ecs
->stepping_through_solib_after_catch
)
2437 #if defined(SOLIB_ADD)
2438 /* Have we reached our destination? If not, keep going. */
2439 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2441 ecs
->another_trap
= 1;
2446 /* Else, stop and report the catchpoint(s) whose triggering
2447 caused us to begin stepping. */
2448 ecs
->stepping_through_solib_after_catch
= 0;
2449 bpstat_clear (&stop_bpstat
);
2450 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2451 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2452 stop_print_frame
= 1;
2453 stop_stepping (ecs
);
2457 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2459 /* This is the old way of detecting the end of the stack dummy.
2460 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2461 handled above. As soon as we can test it on all of them, all
2462 architectures should define it. */
2464 /* If this is the breakpoint at the end of a stack dummy,
2465 just stop silently, unless the user was doing an si/ni, in which
2466 case she'd better know what she's doing. */
2468 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2469 get_frame_base (get_current_frame ()))
2472 stop_print_frame
= 0;
2473 stop_stack_dummy
= 1;
2475 trap_expected_after_continue
= 1;
2477 stop_stepping (ecs
);
2482 if (step_resume_breakpoint
)
2484 /* Having a step-resume breakpoint overrides anything
2485 else having to do with stepping commands until
2486 that breakpoint is reached. */
2487 /* I'm not sure whether this needs to be check_sigtramp2 or
2488 whether it could/should be keep_going. */
2489 check_sigtramp2 (ecs
);
2494 if (step_range_end
== 0)
2496 /* Likewise if we aren't even stepping. */
2497 /* I'm not sure whether this needs to be check_sigtramp2 or
2498 whether it could/should be keep_going. */
2499 check_sigtramp2 (ecs
);
2504 /* If stepping through a line, keep going if still within it.
2506 Note that step_range_end is the address of the first instruction
2507 beyond the step range, and NOT the address of the last instruction
2509 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
2511 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2512 So definately need to check for sigtramp here. */
2513 check_sigtramp2 (ecs
);
2518 /* We stepped out of the stepping range. */
2520 /* If we are stepping at the source level and entered the runtime
2521 loader dynamic symbol resolution code, we keep on single stepping
2522 until we exit the run time loader code and reach the callee's
2524 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2525 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2527 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2529 if (pc_after_resolver
)
2531 /* Set up a step-resume breakpoint at the address
2532 indicated by SKIP_SOLIB_RESOLVER. */
2533 struct symtab_and_line sr_sal
;
2535 sr_sal
.pc
= pc_after_resolver
;
2537 check_for_old_step_resume_breakpoint ();
2538 step_resume_breakpoint
=
2539 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2540 if (breakpoints_inserted
)
2541 insert_breakpoints ();
2548 /* We can't update step_sp every time through the loop, because
2549 reading the stack pointer would slow down stepping too much.
2550 But we can update it every time we leave the step range. */
2551 ecs
->update_step_sp
= 1;
2553 /* Did we just take a signal? */
2554 if (PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2555 && !PC_IN_SIGTRAMP (prev_pc
, prev_func_name
)
2556 && INNER_THAN (read_sp (), step_sp
))
2558 /* We've just taken a signal; go until we are back to
2559 the point where we took it and one more. */
2561 /* Note: The test above succeeds not only when we stepped
2562 into a signal handler, but also when we step past the last
2563 statement of a signal handler and end up in the return stub
2564 of the signal handler trampoline. To distinguish between
2565 these two cases, check that the frame is INNER_THAN the
2566 previous one below. pai/1997-09-11 */
2570 struct frame_id current_frame
= get_frame_id (get_current_frame ());
2572 if (frame_id_inner (current_frame
, step_frame_id
))
2574 /* We have just taken a signal; go until we are back to
2575 the point where we took it and one more. */
2577 /* This code is needed at least in the following case:
2578 The user types "next" and then a signal arrives (before
2579 the "next" is done). */
2581 /* Note that if we are stopped at a breakpoint, then we need
2582 the step_resume breakpoint to override any breakpoints at
2583 the same location, so that we will still step over the
2584 breakpoint even though the signal happened. */
2585 struct symtab_and_line sr_sal
;
2588 sr_sal
.symtab
= NULL
;
2590 sr_sal
.pc
= prev_pc
;
2591 /* We could probably be setting the frame to
2592 step_frame_id; I don't think anyone thought to try it. */
2593 check_for_old_step_resume_breakpoint ();
2594 step_resume_breakpoint
=
2595 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2596 if (breakpoints_inserted
)
2597 insert_breakpoints ();
2601 /* We just stepped out of a signal handler and into
2602 its calling trampoline.
2604 Normally, we'd call step_over_function from
2605 here, but for some reason GDB can't unwind the
2606 stack correctly to find the real PC for the point
2607 user code where the signal trampoline will return
2608 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2609 But signal trampolines are pretty small stubs of
2610 code, anyway, so it's OK instead to just
2611 single-step out. Note: assuming such trampolines
2612 don't exhibit recursion on any platform... */
2613 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2614 &ecs
->stop_func_start
,
2615 &ecs
->stop_func_end
);
2616 /* Readjust stepping range */
2617 step_range_start
= ecs
->stop_func_start
;
2618 step_range_end
= ecs
->stop_func_end
;
2619 ecs
->stepping_through_sigtramp
= 1;
2624 /* If this is stepi or nexti, make sure that the stepping range
2625 gets us past that instruction. */
2626 if (step_range_end
== 1)
2627 /* FIXME: Does this run afoul of the code below which, if
2628 we step into the middle of a line, resets the stepping
2630 step_range_end
= (step_range_start
= prev_pc
) + 1;
2632 ecs
->remove_breakpoints_on_following_step
= 1;
2637 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2638 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2639 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2640 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2641 || ecs
->stop_func_name
== 0)
2643 /* It's a subroutine call. */
2645 if ((step_over_calls
== STEP_OVER_NONE
)
2646 || ((step_range_end
== 1)
2647 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2649 /* I presume that step_over_calls is only 0 when we're
2650 supposed to be stepping at the assembly language level
2651 ("stepi"). Just stop. */
2652 /* Also, maybe we just did a "nexti" inside a prolog,
2653 so we thought it was a subroutine call but it was not.
2654 Stop as well. FENN */
2656 print_stop_reason (END_STEPPING_RANGE
, 0);
2657 stop_stepping (ecs
);
2661 if (step_over_calls
== STEP_OVER_ALL
|| IGNORE_HELPER_CALL (stop_pc
))
2663 /* We're doing a "next". */
2665 if (PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2666 && frame_id_inner (step_frame_id
,
2667 frame_id_build (read_sp (), 0)))
2668 /* We stepped out of a signal handler, and into its
2669 calling trampoline. This is misdetected as a
2670 subroutine call, but stepping over the signal
2671 trampoline isn't such a bad idea. In order to do that,
2672 we have to ignore the value in step_frame_id, since
2673 that doesn't represent the frame that'll reach when we
2674 return from the signal trampoline. Otherwise we'll
2675 probably continue to the end of the program. */
2676 step_frame_id
= null_frame_id
;
2678 step_over_function (ecs
);
2683 /* If we are in a function call trampoline (a stub between
2684 the calling routine and the real function), locate the real
2685 function. That's what tells us (a) whether we want to step
2686 into it at all, and (b) what prologue we want to run to
2687 the end of, if we do step into it. */
2688 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2690 ecs
->stop_func_start
= tmp
;
2693 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2696 struct symtab_and_line xxx
;
2697 /* Why isn't this s_a_l called "sr_sal", like all of the
2698 other s_a_l's where this code is duplicated? */
2699 init_sal (&xxx
); /* initialize to zeroes */
2701 xxx
.section
= find_pc_overlay (xxx
.pc
);
2702 check_for_old_step_resume_breakpoint ();
2703 step_resume_breakpoint
=
2704 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2705 insert_breakpoints ();
2711 /* If we have line number information for the function we
2712 are thinking of stepping into, step into it.
2714 If there are several symtabs at that PC (e.g. with include
2715 files), just want to know whether *any* of them have line
2716 numbers. find_pc_line handles this. */
2718 struct symtab_and_line tmp_sal
;
2720 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2721 if (tmp_sal
.line
!= 0)
2723 step_into_function (ecs
);
2728 /* If we have no line number and the step-stop-if-no-debug
2729 is set, we stop the step so that the user has a chance to
2730 switch in assembly mode. */
2731 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2734 print_stop_reason (END_STEPPING_RANGE
, 0);
2735 stop_stepping (ecs
);
2739 step_over_function (ecs
);
2745 /* We've wandered out of the step range. */
2747 ecs
->sal
= find_pc_line (stop_pc
, 0);
2749 if (step_range_end
== 1)
2751 /* It is stepi or nexti. We always want to stop stepping after
2754 print_stop_reason (END_STEPPING_RANGE
, 0);
2755 stop_stepping (ecs
);
2759 /* If we're in the return path from a shared library trampoline,
2760 we want to proceed through the trampoline when stepping. */
2761 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2765 /* Determine where this trampoline returns. */
2766 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2768 /* Only proceed through if we know where it's going. */
2771 /* And put the step-breakpoint there and go until there. */
2772 struct symtab_and_line sr_sal
;
2774 init_sal (&sr_sal
); /* initialize to zeroes */
2776 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2777 /* Do not specify what the fp should be when we stop
2778 since on some machines the prologue
2779 is where the new fp value is established. */
2780 check_for_old_step_resume_breakpoint ();
2781 step_resume_breakpoint
=
2782 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2783 if (breakpoints_inserted
)
2784 insert_breakpoints ();
2786 /* Restart without fiddling with the step ranges or
2793 if (ecs
->sal
.line
== 0)
2795 /* We have no line number information. That means to stop
2796 stepping (does this always happen right after one instruction,
2797 when we do "s" in a function with no line numbers,
2798 or can this happen as a result of a return or longjmp?). */
2800 print_stop_reason (END_STEPPING_RANGE
, 0);
2801 stop_stepping (ecs
);
2805 if ((stop_pc
== ecs
->sal
.pc
)
2806 && (ecs
->current_line
!= ecs
->sal
.line
2807 || ecs
->current_symtab
!= ecs
->sal
.symtab
))
2809 /* We are at the start of a different line. So stop. Note that
2810 we don't stop if we step into the middle of a different line.
2811 That is said to make things like for (;;) statements work
2814 print_stop_reason (END_STEPPING_RANGE
, 0);
2815 stop_stepping (ecs
);
2819 /* We aren't done stepping.
2821 Optimize by setting the stepping range to the line.
2822 (We might not be in the original line, but if we entered a
2823 new line in mid-statement, we continue stepping. This makes
2824 things like for(;;) statements work better.) */
2826 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2828 /* If this is the last line of the function, don't keep stepping
2829 (it would probably step us out of the function).
2830 This is particularly necessary for a one-line function,
2831 in which after skipping the prologue we better stop even though
2832 we will be in mid-line. */
2834 print_stop_reason (END_STEPPING_RANGE
, 0);
2835 stop_stepping (ecs
);
2838 step_range_start
= ecs
->sal
.pc
;
2839 step_range_end
= ecs
->sal
.end
;
2840 step_frame_id
= get_frame_id (get_current_frame ());
2841 ecs
->current_line
= ecs
->sal
.line
;
2842 ecs
->current_symtab
= ecs
->sal
.symtab
;
2844 /* In the case where we just stepped out of a function into the
2845 middle of a line of the caller, continue stepping, but
2846 step_frame_id must be modified to current frame */
2848 struct frame_id current_frame
= get_frame_id (get_current_frame ());
2849 if (!(frame_id_inner (current_frame
, step_frame_id
)))
2850 step_frame_id
= current_frame
;
2856 /* Are we in the middle of stepping? */
2859 currently_stepping (struct execution_control_state
*ecs
)
2861 return ((through_sigtramp_breakpoint
== NULL
2862 && !ecs
->handling_longjmp
2863 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2865 || ecs
->stepping_through_solib_after_catch
2866 || bpstat_should_step ());
2870 check_sigtramp2 (struct execution_control_state
*ecs
)
2873 && PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2874 && !PC_IN_SIGTRAMP (prev_pc
, prev_func_name
)
2875 && INNER_THAN (read_sp (), step_sp
))
2877 /* What has happened here is that we have just stepped the
2878 inferior with a signal (because it is a signal which
2879 shouldn't make us stop), thus stepping into sigtramp.
2881 So we need to set a step_resume_break_address breakpoint and
2882 continue until we hit it, and then step. FIXME: This should
2883 be more enduring than a step_resume breakpoint; we should
2884 know that we will later need to keep going rather than
2885 re-hitting the breakpoint here (see the testsuite,
2886 gdb.base/signals.exp where it says "exceedingly difficult"). */
2888 struct symtab_and_line sr_sal
;
2890 init_sal (&sr_sal
); /* initialize to zeroes */
2891 sr_sal
.pc
= prev_pc
;
2892 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2893 /* We perhaps could set the frame if we kept track of what the
2894 frame corresponding to prev_pc was. But we don't, so don't. */
2895 through_sigtramp_breakpoint
=
2896 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2897 if (breakpoints_inserted
)
2898 insert_breakpoints ();
2900 ecs
->remove_breakpoints_on_following_step
= 1;
2901 ecs
->another_trap
= 1;
2905 /* Subroutine call with source code we should not step over. Do step
2906 to the first line of code in it. */
2909 step_into_function (struct execution_control_state
*ecs
)
2912 struct symtab_and_line sr_sal
;
2914 s
= find_pc_symtab (stop_pc
);
2915 if (s
&& s
->language
!= language_asm
)
2916 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2918 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2919 /* Use the step_resume_break to step until the end of the prologue,
2920 even if that involves jumps (as it seems to on the vax under
2922 /* If the prologue ends in the middle of a source line, continue to
2923 the end of that source line (if it is still within the function).
2924 Otherwise, just go to end of prologue. */
2925 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2926 /* no, don't either. It skips any code that's legitimately on the
2930 && ecs
->sal
.pc
!= ecs
->stop_func_start
2931 && ecs
->sal
.end
< ecs
->stop_func_end
)
2932 ecs
->stop_func_start
= ecs
->sal
.end
;
2935 if (ecs
->stop_func_start
== stop_pc
)
2937 /* We are already there: stop now. */
2939 print_stop_reason (END_STEPPING_RANGE
, 0);
2940 stop_stepping (ecs
);
2945 /* Put the step-breakpoint there and go until there. */
2946 init_sal (&sr_sal
); /* initialize to zeroes */
2947 sr_sal
.pc
= ecs
->stop_func_start
;
2948 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
2949 /* Do not specify what the fp should be when we stop since on
2950 some machines the prologue is where the new fp value is
2952 check_for_old_step_resume_breakpoint ();
2953 step_resume_breakpoint
=
2954 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2955 if (breakpoints_inserted
)
2956 insert_breakpoints ();
2958 /* And make sure stepping stops right away then. */
2959 step_range_end
= step_range_start
;
2964 /* We've just entered a callee, and we wish to resume until it returns
2965 to the caller. Setting a step_resume breakpoint on the return
2966 address will catch a return from the callee.
2968 However, if the callee is recursing, we want to be careful not to
2969 catch returns of those recursive calls, but only of THIS instance
2972 To do this, we set the step_resume bp's frame to our current
2973 caller's frame (step_frame_id, which is set by the "next" or
2974 "until" command, before execution begins). */
2977 step_over_function (struct execution_control_state
*ecs
)
2979 struct symtab_and_line sr_sal
;
2981 init_sal (&sr_sal
); /* initialize to zeros */
2982 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2983 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2985 check_for_old_step_resume_breakpoint ();
2986 step_resume_breakpoint
=
2987 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
2989 if (frame_id_p (step_frame_id
)
2990 && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
2991 /* FIXME: cagney/2002-12-01: Someone should modify the breakpoint
2992 code so that it uses a frame ID, instead of a frame address. */
2993 step_resume_breakpoint
->frame
= step_frame_id
.base
;
2995 if (breakpoints_inserted
)
2996 insert_breakpoints ();
3000 stop_stepping (struct execution_control_state
*ecs
)
3002 if (target_has_execution
)
3004 /* Are we stopping for a vfork event? We only stop when we see
3005 the child's event. However, we may not yet have seen the
3006 parent's event. And, inferior_ptid is still set to the
3007 parent's pid, until we resume again and follow either the
3010 To ensure that we can really touch inferior_ptid (aka, the
3011 parent process) -- which calls to functions like read_pc
3012 implicitly do -- wait on the parent if necessary. */
3013 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3014 && !pending_follow
.fork_event
.saw_parent_fork
)
3020 if (target_wait_hook
)
3021 parent_ptid
= target_wait_hook (pid_to_ptid (-1), &(ecs
->ws
));
3023 parent_ptid
= target_wait (pid_to_ptid (-1), &(ecs
->ws
));
3025 while (!ptid_equal (parent_ptid
, inferior_ptid
));
3028 /* Assuming the inferior still exists, set these up for next
3029 time, just like we did above if we didn't break out of the
3031 prev_pc
= read_pc ();
3032 prev_func_start
= ecs
->stop_func_start
;
3033 prev_func_name
= ecs
->stop_func_name
;
3036 /* Let callers know we don't want to wait for the inferior anymore. */
3037 ecs
->wait_some_more
= 0;
3040 /* This function handles various cases where we need to continue
3041 waiting for the inferior. */
3042 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3045 keep_going (struct execution_control_state
*ecs
)
3047 /* Save the pc before execution, to compare with pc after stop. */
3048 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3049 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3050 BREAK is defined, the
3051 original pc would not have
3052 been at the start of a
3054 prev_func_name
= ecs
->stop_func_name
;
3056 if (ecs
->update_step_sp
)
3057 step_sp
= read_sp ();
3058 ecs
->update_step_sp
= 0;
3060 /* If we did not do break;, it means we should keep running the
3061 inferior and not return to debugger. */
3063 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3065 /* We took a signal (which we are supposed to pass through to
3066 the inferior, else we'd have done a break above) and we
3067 haven't yet gotten our trap. Simply continue. */
3068 resume (currently_stepping (ecs
), stop_signal
);
3072 /* Either the trap was not expected, but we are continuing
3073 anyway (the user asked that this signal be passed to the
3076 The signal was SIGTRAP, e.g. it was our signal, but we
3077 decided we should resume from it.
3079 We're going to run this baby now!
3081 Insert breakpoints now, unless we are trying to one-proceed
3082 past a breakpoint. */
3083 /* If we've just finished a special step resume and we don't
3084 want to hit a breakpoint, pull em out. */
3085 if (step_resume_breakpoint
== NULL
3086 && through_sigtramp_breakpoint
== NULL
3087 && ecs
->remove_breakpoints_on_following_step
)
3089 ecs
->remove_breakpoints_on_following_step
= 0;
3090 remove_breakpoints ();
3091 breakpoints_inserted
= 0;
3093 else if (!breakpoints_inserted
&&
3094 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3096 breakpoints_failed
= insert_breakpoints ();
3097 if (breakpoints_failed
)
3099 stop_stepping (ecs
);
3102 breakpoints_inserted
= 1;
3105 trap_expected
= ecs
->another_trap
;
3107 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3108 specifies that such a signal should be delivered to the
3111 Typically, this would occure when a user is debugging a
3112 target monitor on a simulator: the target monitor sets a
3113 breakpoint; the simulator encounters this break-point and
3114 halts the simulation handing control to GDB; GDB, noteing
3115 that the break-point isn't valid, returns control back to the
3116 simulator; the simulator then delivers the hardware
3117 equivalent of a SIGNAL_TRAP to the program being debugged. */
3119 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !signal_program
[stop_signal
])
3120 stop_signal
= TARGET_SIGNAL_0
;
3122 #ifdef SHIFT_INST_REGS
3123 /* I'm not sure when this following segment applies. I do know,
3124 now, that we shouldn't rewrite the regs when we were stopped
3125 by a random signal from the inferior process. */
3126 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3127 (this is only used on the 88k). */
3129 if (!bpstat_explains_signal (stop_bpstat
)
3130 && (stop_signal
!= TARGET_SIGNAL_CHLD
) && !stopped_by_random_signal
)
3132 #endif /* SHIFT_INST_REGS */
3134 resume (currently_stepping (ecs
), stop_signal
);
3137 prepare_to_wait (ecs
);
3140 /* This function normally comes after a resume, before
3141 handle_inferior_event exits. It takes care of any last bits of
3142 housekeeping, and sets the all-important wait_some_more flag. */
3145 prepare_to_wait (struct execution_control_state
*ecs
)
3147 if (ecs
->infwait_state
== infwait_normal_state
)
3149 overlay_cache_invalid
= 1;
3151 /* We have to invalidate the registers BEFORE calling
3152 target_wait because they can be loaded from the target while
3153 in target_wait. This makes remote debugging a bit more
3154 efficient for those targets that provide critical registers
3155 as part of their normal status mechanism. */
3157 registers_changed ();
3158 ecs
->waiton_ptid
= pid_to_ptid (-1);
3159 ecs
->wp
= &(ecs
->ws
);
3161 /* This is the old end of the while loop. Let everybody know we
3162 want to wait for the inferior some more and get called again
3164 ecs
->wait_some_more
= 1;
3167 /* Print why the inferior has stopped. We always print something when
3168 the inferior exits, or receives a signal. The rest of the cases are
3169 dealt with later on in normal_stop() and print_it_typical(). Ideally
3170 there should be a call to this function from handle_inferior_event()
3171 each time stop_stepping() is called.*/
3173 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3175 switch (stop_reason
)
3178 /* We don't deal with these cases from handle_inferior_event()
3181 case END_STEPPING_RANGE
:
3182 /* We are done with a step/next/si/ni command. */
3183 /* For now print nothing. */
3184 /* Print a message only if not in the middle of doing a "step n"
3185 operation for n > 1 */
3186 if (!step_multi
|| !stop_step
)
3187 if (ui_out_is_mi_like_p (uiout
))
3188 ui_out_field_string (uiout
, "reason", "end-stepping-range");
3190 case BREAKPOINT_HIT
:
3191 /* We found a breakpoint. */
3192 /* For now print nothing. */
3195 /* The inferior was terminated by a signal. */
3196 annotate_signalled ();
3197 if (ui_out_is_mi_like_p (uiout
))
3198 ui_out_field_string (uiout
, "reason", "exited-signalled");
3199 ui_out_text (uiout
, "\nProgram terminated with signal ");
3200 annotate_signal_name ();
3201 ui_out_field_string (uiout
, "signal-name",
3202 target_signal_to_name (stop_info
));
3203 annotate_signal_name_end ();
3204 ui_out_text (uiout
, ", ");
3205 annotate_signal_string ();
3206 ui_out_field_string (uiout
, "signal-meaning",
3207 target_signal_to_string (stop_info
));
3208 annotate_signal_string_end ();
3209 ui_out_text (uiout
, ".\n");
3210 ui_out_text (uiout
, "The program no longer exists.\n");
3213 /* The inferior program is finished. */
3214 annotate_exited (stop_info
);
3217 if (ui_out_is_mi_like_p (uiout
))
3218 ui_out_field_string (uiout
, "reason", "exited");
3219 ui_out_text (uiout
, "\nProgram exited with code ");
3220 ui_out_field_fmt (uiout
, "exit-code", "0%o",
3221 (unsigned int) stop_info
);
3222 ui_out_text (uiout
, ".\n");
3226 if (ui_out_is_mi_like_p (uiout
))
3227 ui_out_field_string (uiout
, "reason", "exited-normally");
3228 ui_out_text (uiout
, "\nProgram exited normally.\n");
3231 case SIGNAL_RECEIVED
:
3232 /* Signal received. The signal table tells us to print about
3235 ui_out_text (uiout
, "\nProgram received signal ");
3236 annotate_signal_name ();
3237 if (ui_out_is_mi_like_p (uiout
))
3238 ui_out_field_string (uiout
, "reason", "signal-received");
3239 ui_out_field_string (uiout
, "signal-name",
3240 target_signal_to_name (stop_info
));
3241 annotate_signal_name_end ();
3242 ui_out_text (uiout
, ", ");
3243 annotate_signal_string ();
3244 ui_out_field_string (uiout
, "signal-meaning",
3245 target_signal_to_string (stop_info
));
3246 annotate_signal_string_end ();
3247 ui_out_text (uiout
, ".\n");
3250 internal_error (__FILE__
, __LINE__
,
3251 "print_stop_reason: unrecognized enum value");
3257 /* Here to return control to GDB when the inferior stops for real.
3258 Print appropriate messages, remove breakpoints, give terminal our modes.
3260 STOP_PRINT_FRAME nonzero means print the executing frame
3261 (pc, function, args, file, line number and line text).
3262 BREAKPOINTS_FAILED nonzero means stop was due to error
3263 attempting to insert breakpoints. */
3268 /* As with the notification of thread events, we want to delay
3269 notifying the user that we've switched thread context until
3270 the inferior actually stops.
3272 (Note that there's no point in saying anything if the inferior
3274 if (!ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3275 && target_has_execution
)
3277 target_terminal_ours_for_output ();
3278 printf_filtered ("[Switching to %s]\n",
3279 target_pid_or_tid_to_str (inferior_ptid
));
3280 previous_inferior_ptid
= inferior_ptid
;
3283 /* Make sure that the current_frame's pc is correct. This
3284 is a correction for setting up the frame info before doing
3285 DECR_PC_AFTER_BREAK */
3286 if (target_has_execution
&& get_current_frame ())
3287 (get_current_frame ())->pc
= read_pc ();
3289 if (target_has_execution
&& breakpoints_inserted
)
3291 if (remove_breakpoints ())
3293 target_terminal_ours_for_output ();
3294 printf_filtered ("Cannot remove breakpoints because ");
3295 printf_filtered ("program is no longer writable.\n");
3296 printf_filtered ("It might be running in another process.\n");
3297 printf_filtered ("Further execution is probably impossible.\n");
3300 breakpoints_inserted
= 0;
3302 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3303 Delete any breakpoint that is to be deleted at the next stop. */
3305 breakpoint_auto_delete (stop_bpstat
);
3307 /* If an auto-display called a function and that got a signal,
3308 delete that auto-display to avoid an infinite recursion. */
3310 if (stopped_by_random_signal
)
3311 disable_current_display ();
3313 /* Don't print a message if in the middle of doing a "step n"
3314 operation for n > 1 */
3315 if (step_multi
&& stop_step
)
3318 target_terminal_ours ();
3320 /* Look up the hook_stop and run it (CLI internally handles problem
3321 of stop_command's pre-hook not existing). */
3323 catch_errors (hook_stop_stub
, stop_command
,
3324 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3326 if (!target_has_stack
)
3332 /* Select innermost stack frame - i.e., current frame is frame 0,
3333 and current location is based on that.
3334 Don't do this on return from a stack dummy routine,
3335 or if the program has exited. */
3337 if (!stop_stack_dummy
)
3339 select_frame (get_current_frame ());
3341 /* Print current location without a level number, if
3342 we have changed functions or hit a breakpoint.
3343 Print source line if we have one.
3344 bpstat_print() contains the logic deciding in detail
3345 what to print, based on the event(s) that just occurred. */
3347 if (stop_print_frame
&& deprecated_selected_frame
)
3351 int do_frame_printing
= 1;
3353 bpstat_ret
= bpstat_print (stop_bpstat
);
3357 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3358 (or should) carry around the function and does (or
3359 should) use that when doing a frame comparison. */
3361 && frame_id_eq (step_frame_id
,
3362 get_frame_id (get_current_frame ()))
3363 && step_start_function
== find_pc_function (stop_pc
))
3364 source_flag
= SRC_LINE
; /* finished step, just print source line */
3366 source_flag
= SRC_AND_LOC
; /* print location and source line */
3368 case PRINT_SRC_AND_LOC
:
3369 source_flag
= SRC_AND_LOC
; /* print location and source line */
3371 case PRINT_SRC_ONLY
:
3372 source_flag
= SRC_LINE
;
3375 source_flag
= SRC_LINE
; /* something bogus */
3376 do_frame_printing
= 0;
3379 internal_error (__FILE__
, __LINE__
, "Unknown value.");
3381 /* For mi, have the same behavior every time we stop:
3382 print everything but the source line. */
3383 if (ui_out_is_mi_like_p (uiout
))
3384 source_flag
= LOC_AND_ADDRESS
;
3386 if (ui_out_is_mi_like_p (uiout
))
3387 ui_out_field_int (uiout
, "thread-id",
3388 pid_to_thread_id (inferior_ptid
));
3389 /* The behavior of this routine with respect to the source
3391 SRC_LINE: Print only source line
3392 LOCATION: Print only location
3393 SRC_AND_LOC: Print location and source line */
3394 if (do_frame_printing
)
3395 show_and_print_stack_frame (deprecated_selected_frame
, -1, source_flag
);
3397 /* Display the auto-display expressions. */
3402 /* Save the function value return registers, if we care.
3403 We might be about to restore their previous contents. */
3404 if (proceed_to_finish
)
3405 /* NB: The copy goes through to the target picking up the value of
3406 all the registers. */
3407 regcache_cpy (stop_registers
, current_regcache
);
3409 if (stop_stack_dummy
)
3411 /* Pop the empty frame that contains the stack dummy.
3412 POP_FRAME ends with a setting of the current frame, so we
3413 can use that next. */
3415 /* Set stop_pc to what it was before we called the function.
3416 Can't rely on restore_inferior_status because that only gets
3417 called if we don't stop in the called function. */
3418 stop_pc
= read_pc ();
3419 select_frame (get_current_frame ());
3423 annotate_stopped ();
3427 hook_stop_stub (void *cmd
)
3429 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3434 signal_stop_state (int signo
)
3436 return signal_stop
[signo
];
3440 signal_print_state (int signo
)
3442 return signal_print
[signo
];
3446 signal_pass_state (int signo
)
3448 return signal_program
[signo
];
3452 signal_stop_update (int signo
, int state
)
3454 int ret
= signal_stop
[signo
];
3455 signal_stop
[signo
] = state
;
3460 signal_print_update (int signo
, int state
)
3462 int ret
= signal_print
[signo
];
3463 signal_print
[signo
] = state
;
3468 signal_pass_update (int signo
, int state
)
3470 int ret
= signal_program
[signo
];
3471 signal_program
[signo
] = state
;
3476 sig_print_header (void)
3479 Signal Stop\tPrint\tPass to program\tDescription\n");
3483 sig_print_info (enum target_signal oursig
)
3485 char *name
= target_signal_to_name (oursig
);
3486 int name_padding
= 13 - strlen (name
);
3488 if (name_padding
<= 0)
3491 printf_filtered ("%s", name
);
3492 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
3493 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3494 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3495 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3496 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3499 /* Specify how various signals in the inferior should be handled. */
3502 handle_command (char *args
, int from_tty
)
3505 int digits
, wordlen
;
3506 int sigfirst
, signum
, siglast
;
3507 enum target_signal oursig
;
3510 unsigned char *sigs
;
3511 struct cleanup
*old_chain
;
3515 error_no_arg ("signal to handle");
3518 /* Allocate and zero an array of flags for which signals to handle. */
3520 nsigs
= (int) TARGET_SIGNAL_LAST
;
3521 sigs
= (unsigned char *) alloca (nsigs
);
3522 memset (sigs
, 0, nsigs
);
3524 /* Break the command line up into args. */
3526 argv
= buildargv (args
);
3531 old_chain
= make_cleanup_freeargv (argv
);
3533 /* Walk through the args, looking for signal oursigs, signal names, and
3534 actions. Signal numbers and signal names may be interspersed with
3535 actions, with the actions being performed for all signals cumulatively
3536 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3538 while (*argv
!= NULL
)
3540 wordlen
= strlen (*argv
);
3541 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3545 sigfirst
= siglast
= -1;
3547 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3549 /* Apply action to all signals except those used by the
3550 debugger. Silently skip those. */
3553 siglast
= nsigs
- 1;
3555 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3557 SET_SIGS (nsigs
, sigs
, signal_stop
);
3558 SET_SIGS (nsigs
, sigs
, signal_print
);
3560 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3562 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3564 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3566 SET_SIGS (nsigs
, sigs
, signal_print
);
3568 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3570 SET_SIGS (nsigs
, sigs
, signal_program
);
3572 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3574 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3576 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3578 SET_SIGS (nsigs
, sigs
, signal_program
);
3580 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3582 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3583 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3585 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3587 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3589 else if (digits
> 0)
3591 /* It is numeric. The numeric signal refers to our own
3592 internal signal numbering from target.h, not to host/target
3593 signal number. This is a feature; users really should be
3594 using symbolic names anyway, and the common ones like
3595 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3597 sigfirst
= siglast
= (int)
3598 target_signal_from_command (atoi (*argv
));
3599 if ((*argv
)[digits
] == '-')
3602 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3604 if (sigfirst
> siglast
)
3606 /* Bet he didn't figure we'd think of this case... */
3614 oursig
= target_signal_from_name (*argv
);
3615 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3617 sigfirst
= siglast
= (int) oursig
;
3621 /* Not a number and not a recognized flag word => complain. */
3622 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3626 /* If any signal numbers or symbol names were found, set flags for
3627 which signals to apply actions to. */
3629 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3631 switch ((enum target_signal
) signum
)
3633 case TARGET_SIGNAL_TRAP
:
3634 case TARGET_SIGNAL_INT
:
3635 if (!allsigs
&& !sigs
[signum
])
3637 if (query ("%s is used by the debugger.\n\
3638 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
3644 printf_unfiltered ("Not confirmed, unchanged.\n");
3645 gdb_flush (gdb_stdout
);
3649 case TARGET_SIGNAL_0
:
3650 case TARGET_SIGNAL_DEFAULT
:
3651 case TARGET_SIGNAL_UNKNOWN
:
3652 /* Make sure that "all" doesn't print these. */
3663 target_notice_signals (inferior_ptid
);
3667 /* Show the results. */
3668 sig_print_header ();
3669 for (signum
= 0; signum
< nsigs
; signum
++)
3673 sig_print_info (signum
);
3678 do_cleanups (old_chain
);
3682 xdb_handle_command (char *args
, int from_tty
)
3685 struct cleanup
*old_chain
;
3687 /* Break the command line up into args. */
3689 argv
= buildargv (args
);
3694 old_chain
= make_cleanup_freeargv (argv
);
3695 if (argv
[1] != (char *) NULL
)
3700 bufLen
= strlen (argv
[0]) + 20;
3701 argBuf
= (char *) xmalloc (bufLen
);
3705 enum target_signal oursig
;
3707 oursig
= target_signal_from_name (argv
[0]);
3708 memset (argBuf
, 0, bufLen
);
3709 if (strcmp (argv
[1], "Q") == 0)
3710 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3713 if (strcmp (argv
[1], "s") == 0)
3715 if (!signal_stop
[oursig
])
3716 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3718 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3720 else if (strcmp (argv
[1], "i") == 0)
3722 if (!signal_program
[oursig
])
3723 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3725 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3727 else if (strcmp (argv
[1], "r") == 0)
3729 if (!signal_print
[oursig
])
3730 sprintf (argBuf
, "%s %s", argv
[0], "print");
3732 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3738 handle_command (argBuf
, from_tty
);
3740 printf_filtered ("Invalid signal handling flag.\n");
3745 do_cleanups (old_chain
);
3748 /* Print current contents of the tables set by the handle command.
3749 It is possible we should just be printing signals actually used
3750 by the current target (but for things to work right when switching
3751 targets, all signals should be in the signal tables). */
3754 signals_info (char *signum_exp
, int from_tty
)
3756 enum target_signal oursig
;
3757 sig_print_header ();
3761 /* First see if this is a symbol name. */
3762 oursig
= target_signal_from_name (signum_exp
);
3763 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3765 /* No, try numeric. */
3767 target_signal_from_command (parse_and_eval_long (signum_exp
));
3769 sig_print_info (oursig
);
3773 printf_filtered ("\n");
3774 /* These ugly casts brought to you by the native VAX compiler. */
3775 for (oursig
= TARGET_SIGNAL_FIRST
;
3776 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3777 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3781 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3782 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
3783 sig_print_info (oursig
);
3786 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3789 struct inferior_status
3791 enum target_signal stop_signal
;
3795 int stop_stack_dummy
;
3796 int stopped_by_random_signal
;
3798 CORE_ADDR step_range_start
;
3799 CORE_ADDR step_range_end
;
3800 struct frame_id step_frame_id
;
3801 enum step_over_calls_kind step_over_calls
;
3802 CORE_ADDR step_resume_break_address
;
3803 int stop_after_trap
;
3804 int stop_soon_quietly
;
3805 struct regcache
*stop_registers
;
3807 /* These are here because if call_function_by_hand has written some
3808 registers and then decides to call error(), we better not have changed
3810 struct regcache
*registers
;
3812 /* A frame unique identifier. */
3813 struct frame_id selected_frame_id
;
3815 int breakpoint_proceeded
;
3816 int restore_stack_info
;
3817 int proceed_to_finish
;
3821 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3824 int size
= REGISTER_RAW_SIZE (regno
);
3825 void *buf
= alloca (size
);
3826 store_signed_integer (buf
, size
, val
);
3827 regcache_raw_write (inf_status
->registers
, regno
, buf
);
3830 /* Save all of the information associated with the inferior<==>gdb
3831 connection. INF_STATUS is a pointer to a "struct inferior_status"
3832 (defined in inferior.h). */
3834 struct inferior_status
*
3835 save_inferior_status (int restore_stack_info
)
3837 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
3839 inf_status
->stop_signal
= stop_signal
;
3840 inf_status
->stop_pc
= stop_pc
;
3841 inf_status
->stop_step
= stop_step
;
3842 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3843 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3844 inf_status
->trap_expected
= trap_expected
;
3845 inf_status
->step_range_start
= step_range_start
;
3846 inf_status
->step_range_end
= step_range_end
;
3847 inf_status
->step_frame_id
= step_frame_id
;
3848 inf_status
->step_over_calls
= step_over_calls
;
3849 inf_status
->stop_after_trap
= stop_after_trap
;
3850 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3851 /* Save original bpstat chain here; replace it with copy of chain.
3852 If caller's caller is walking the chain, they'll be happier if we
3853 hand them back the original chain when restore_inferior_status is
3855 inf_status
->stop_bpstat
= stop_bpstat
;
3856 stop_bpstat
= bpstat_copy (stop_bpstat
);
3857 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3858 inf_status
->restore_stack_info
= restore_stack_info
;
3859 inf_status
->proceed_to_finish
= proceed_to_finish
;
3861 inf_status
->stop_registers
= regcache_dup_no_passthrough (stop_registers
);
3863 inf_status
->registers
= regcache_dup (current_regcache
);
3865 inf_status
->selected_frame_id
= get_frame_id (deprecated_selected_frame
);
3870 restore_selected_frame (void *args
)
3872 struct frame_id
*fid
= (struct frame_id
*) args
;
3873 struct frame_info
*frame
;
3875 frame
= frame_find_by_id (*fid
);
3877 /* If inf_status->selected_frame_id is NULL, there was no previously
3881 warning ("Unable to restore previously selected frame.\n");
3885 select_frame (frame
);
3891 restore_inferior_status (struct inferior_status
*inf_status
)
3893 stop_signal
= inf_status
->stop_signal
;
3894 stop_pc
= inf_status
->stop_pc
;
3895 stop_step
= inf_status
->stop_step
;
3896 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3897 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3898 trap_expected
= inf_status
->trap_expected
;
3899 step_range_start
= inf_status
->step_range_start
;
3900 step_range_end
= inf_status
->step_range_end
;
3901 step_frame_id
= inf_status
->step_frame_id
;
3902 step_over_calls
= inf_status
->step_over_calls
;
3903 stop_after_trap
= inf_status
->stop_after_trap
;
3904 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
3905 bpstat_clear (&stop_bpstat
);
3906 stop_bpstat
= inf_status
->stop_bpstat
;
3907 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3908 proceed_to_finish
= inf_status
->proceed_to_finish
;
3910 /* FIXME: Is the restore of stop_registers always needed. */
3911 regcache_xfree (stop_registers
);
3912 stop_registers
= inf_status
->stop_registers
;
3914 /* The inferior can be gone if the user types "print exit(0)"
3915 (and perhaps other times). */
3916 if (target_has_execution
)
3917 /* NB: The register write goes through to the target. */
3918 regcache_cpy (current_regcache
, inf_status
->registers
);
3919 regcache_xfree (inf_status
->registers
);
3921 /* FIXME: If we are being called after stopping in a function which
3922 is called from gdb, we should not be trying to restore the
3923 selected frame; it just prints a spurious error message (The
3924 message is useful, however, in detecting bugs in gdb (like if gdb
3925 clobbers the stack)). In fact, should we be restoring the
3926 inferior status at all in that case? . */
3928 if (target_has_stack
&& inf_status
->restore_stack_info
)
3930 /* The point of catch_errors is that if the stack is clobbered,
3931 walking the stack might encounter a garbage pointer and
3932 error() trying to dereference it. */
3934 (restore_selected_frame
, &inf_status
->selected_frame_id
,
3935 "Unable to restore previously selected frame:\n",
3936 RETURN_MASK_ERROR
) == 0)
3937 /* Error in restoring the selected frame. Select the innermost
3939 select_frame (get_current_frame ());
3947 do_restore_inferior_status_cleanup (void *sts
)
3949 restore_inferior_status (sts
);
3953 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
3955 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
3959 discard_inferior_status (struct inferior_status
*inf_status
)
3961 /* See save_inferior_status for info on stop_bpstat. */
3962 bpstat_clear (&inf_status
->stop_bpstat
);
3963 regcache_xfree (inf_status
->registers
);
3964 regcache_xfree (inf_status
->stop_registers
);
3969 inferior_has_forked (int pid
, int *child_pid
)
3971 struct target_waitstatus last
;
3974 get_last_target_status (&last_ptid
, &last
);
3976 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
3979 if (ptid_get_pid (last_ptid
) != pid
)
3982 *child_pid
= last
.value
.related_pid
;
3987 inferior_has_vforked (int pid
, int *child_pid
)
3989 struct target_waitstatus last
;
3992 get_last_target_status (&last_ptid
, &last
);
3994 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
3997 if (ptid_get_pid (last_ptid
) != pid
)
4000 *child_pid
= last
.value
.related_pid
;
4005 inferior_has_execd (int pid
, char **execd_pathname
)
4007 struct target_waitstatus last
;
4010 get_last_target_status (&last_ptid
, &last
);
4012 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
4015 if (ptid_get_pid (last_ptid
) != pid
)
4018 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
4022 /* Oft used ptids */
4024 ptid_t minus_one_ptid
;
4026 /* Create a ptid given the necessary PID, LWP, and TID components. */
4029 ptid_build (int pid
, long lwp
, long tid
)
4039 /* Create a ptid from just a pid. */
4042 pid_to_ptid (int pid
)
4044 return ptid_build (pid
, 0, 0);
4047 /* Fetch the pid (process id) component from a ptid. */
4050 ptid_get_pid (ptid_t ptid
)
4055 /* Fetch the lwp (lightweight process) component from a ptid. */
4058 ptid_get_lwp (ptid_t ptid
)
4063 /* Fetch the tid (thread id) component from a ptid. */
4066 ptid_get_tid (ptid_t ptid
)
4071 /* ptid_equal() is used to test equality of two ptids. */
4074 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4076 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4077 && ptid1
.tid
== ptid2
.tid
);
4080 /* restore_inferior_ptid() will be used by the cleanup machinery
4081 to restore the inferior_ptid value saved in a call to
4082 save_inferior_ptid(). */
4085 restore_inferior_ptid (void *arg
)
4087 ptid_t
*saved_ptid_ptr
= arg
;
4088 inferior_ptid
= *saved_ptid_ptr
;
4092 /* Save the value of inferior_ptid so that it may be restored by a
4093 later call to do_cleanups(). Returns the struct cleanup pointer
4094 needed for later doing the cleanup. */
4097 save_inferior_ptid (void)
4099 ptid_t
*saved_ptid_ptr
;
4101 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4102 *saved_ptid_ptr
= inferior_ptid
;
4103 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4110 stop_registers
= regcache_xmalloc (current_gdbarch
);
4114 _initialize_infrun (void)
4117 register int numsigs
;
4118 struct cmd_list_element
*c
;
4120 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4121 register_gdbarch_swap (NULL
, 0, build_infrun
);
4123 add_info ("signals", signals_info
,
4124 "What debugger does when program gets various signals.\n\
4125 Specify a signal as argument to print info on that signal only.");
4126 add_info_alias ("handle", "signals", 0);
4128 add_com ("handle", class_run
, handle_command
,
4129 concat ("Specify how to handle a signal.\n\
4130 Args are signals and actions to apply to those signals.\n\
4131 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4132 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4133 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4134 The special arg \"all\" is recognized to mean all signals except those\n\
4135 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4136 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4137 Stop means reenter debugger if this signal happens (implies print).\n\
4138 Print means print a message if this signal happens.\n\
4139 Pass means let program see this signal; otherwise program doesn't know.\n\
4140 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4141 Pass and Stop may be combined.", NULL
));
4144 add_com ("lz", class_info
, signals_info
,
4145 "What debugger does when program gets various signals.\n\
4146 Specify a signal as argument to print info on that signal only.");
4147 add_com ("z", class_run
, xdb_handle_command
,
4148 concat ("Specify how to handle a signal.\n\
4149 Args are signals and actions to apply to those signals.\n\
4150 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4151 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4152 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4153 The special arg \"all\" is recognized to mean all signals except those\n\
4154 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4155 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4156 nopass), \"Q\" (noprint)\n\
4157 Stop means reenter debugger if this signal happens (implies print).\n\
4158 Print means print a message if this signal happens.\n\
4159 Pass means let program see this signal; otherwise program doesn't know.\n\
4160 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4161 Pass and Stop may be combined.", NULL
));
4166 add_cmd ("stop", class_obscure
, not_just_help_class_command
, "There is no `stop' command, but you can set a hook on `stop'.\n\
4167 This allows you to set a list of commands to be run each time execution\n\
4168 of the program stops.", &cmdlist
);
4170 numsigs
= (int) TARGET_SIGNAL_LAST
;
4171 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4172 signal_print
= (unsigned char *)
4173 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4174 signal_program
= (unsigned char *)
4175 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4176 for (i
= 0; i
< numsigs
; i
++)
4179 signal_print
[i
] = 1;
4180 signal_program
[i
] = 1;
4183 /* Signals caused by debugger's own actions
4184 should not be given to the program afterwards. */
4185 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4186 signal_program
[TARGET_SIGNAL_INT
] = 0;
4188 /* Signals that are not errors should not normally enter the debugger. */
4189 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4190 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4191 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4192 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4193 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4194 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4195 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4196 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4197 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4198 signal_print
[TARGET_SIGNAL_IO
] = 0;
4199 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4200 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4201 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4202 signal_print
[TARGET_SIGNAL_URG
] = 0;
4203 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4204 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4206 /* These signals are used internally by user-level thread
4207 implementations. (See signal(5) on Solaris.) Like the above
4208 signals, a healthy program receives and handles them as part of
4209 its normal operation. */
4210 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4211 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4212 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4213 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4214 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4215 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4219 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4220 (char *) &stop_on_solib_events
,
4221 "Set stopping for shared library events.\n\
4222 If nonzero, gdb will give control to the user when the dynamic linker\n\
4223 notifies gdb of shared library events. The most common event of interest\n\
4224 to the user would be loading/unloading of a new library.\n", &setlist
), &showlist
);
4227 c
= add_set_enum_cmd ("follow-fork-mode",
4229 follow_fork_mode_kind_names
, &follow_fork_mode_string
,
4230 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4231 kernel problem. It's also not terribly useful without a GUI to
4232 help the user drive two debuggers. So for now, I'm disabling
4233 the "both" option. */
4234 /* "Set debugger response to a program call of fork \
4236 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4237 parent - the original process is debugged after a fork\n\
4238 child - the new process is debugged after a fork\n\
4239 both - both the parent and child are debugged after a fork\n\
4240 ask - the debugger will ask for one of the above choices\n\
4241 For \"both\", another copy of the debugger will be started to follow\n\
4242 the new child process. The original debugger will continue to follow\n\
4243 the original parent process. To distinguish their prompts, the\n\
4244 debugger copy's prompt will be changed.\n\
4245 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4246 By default, the debugger will follow the parent process.",
4248 "Set debugger response to a program call of fork \
4250 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4251 parent - the original process is debugged after a fork\n\
4252 child - the new process is debugged after a fork\n\
4253 ask - the debugger will ask for one of the above choices\n\
4254 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4255 By default, the debugger will follow the parent process.", &setlist
);
4256 add_show_from_set (c
, &showlist
);
4258 c
= add_set_enum_cmd ("scheduler-locking", class_run
, scheduler_enums
, /* array of string names */
4259 &scheduler_mode
, /* current mode */
4260 "Set mode for locking scheduler during execution.\n\
4261 off == no locking (threads may preempt at any time)\n\
4262 on == full locking (no thread except the current thread may run)\n\
4263 step == scheduler locked during every single-step operation.\n\
4264 In this mode, no other thread may run during a step command.\n\
4265 Other threads may run while stepping over a function call ('next').", &setlist
);
4267 set_cmd_sfunc (c
, set_schedlock_func
); /* traps on target vector */
4268 add_show_from_set (c
, &showlist
);
4270 c
= add_set_cmd ("step-mode", class_run
,
4271 var_boolean
, (char *) &step_stop_if_no_debug
,
4272 "Set mode of the step operation. When set, doing a step over a\n\
4273 function without debug line information will stop at the first\n\
4274 instruction of that function. Otherwise, the function is skipped and\n\
4275 the step command stops at a different source line.", &setlist
);
4276 add_show_from_set (c
, &showlist
);
4278 /* ptid initializations */
4279 null_ptid
= ptid_build (0, 0, 0);
4280 minus_one_ptid
= ptid_build (-1, 0, 0);
4281 inferior_ptid
= null_ptid
;
4282 target_last_wait_ptid
= minus_one_ptid
;