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 pending_follow
.fork_event
.saw_child_fork
= 1;
1482 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1483 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1485 stop_pc
= read_pc_pid (ecs
->ptid
);
1486 ecs
->saved_inferior_ptid
= inferior_ptid
;
1487 inferior_ptid
= ecs
->ptid
;
1488 /* The second argument of bpstat_stop_status is meant to help
1489 distinguish between a breakpoint trap and a singlestep trap.
1490 This is only important on targets where DECR_PC_AFTER_BREAK
1491 is non-zero. The prev_pc test is meant to distinguish between
1492 singlestepping a trap instruction, and singlestepping thru a
1493 jump to the instruction following a trap instruction. */
1495 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1496 currently_stepping (ecs
) &&
1498 stop_pc
- DECR_PC_AFTER_BREAK
);
1499 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1500 inferior_ptid
= ecs
->saved_inferior_ptid
;
1501 goto process_event_stop_test
;
1503 /* If this a platform which doesn't allow a debugger to touch a
1504 vfork'd inferior until after it exec's, then we'd best keep
1505 our fingers entirely off the inferior, other than continuing
1506 it. This has the unfortunate side-effect that catchpoints
1507 of vforks will be ignored. But since the platform doesn't
1508 allow the inferior be touched at vfork time, there's really
1510 case TARGET_WAITKIND_VFORKED
:
1511 stop_signal
= TARGET_SIGNAL_TRAP
;
1512 pending_follow
.kind
= ecs
->ws
.kind
;
1514 /* Is this a vfork of the parent? If so, then give any
1515 vfork catchpoints a chance to trigger now. (It's
1516 dangerous to do so if the child canot be touched until
1517 it execs, and the child has not yet exec'd. We probably
1518 should warn the user to that effect when the catchpoint
1520 if (ptid_equal (ecs
->ptid
, inferior_ptid
))
1522 pending_follow
.fork_event
.saw_parent_fork
= 1;
1523 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1524 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1527 /* If we've seen the child's vfork event but cannot really touch
1528 the child until it execs, then we must continue the child now.
1529 Else, give any vfork catchpoints a chance to trigger now. */
1532 pending_follow
.fork_event
.saw_child_fork
= 1;
1533 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1534 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1535 target_post_startup_inferior (pid_to_ptid
1536 (pending_follow
.fork_event
.
1540 stop_pc
= read_pc ();
1541 /* The second argument of bpstat_stop_status is meant to help
1542 distinguish between a breakpoint trap and a singlestep trap.
1543 This is only important on targets where DECR_PC_AFTER_BREAK
1544 is non-zero. The prev_pc test is meant to distinguish between
1545 singlestepping a trap instruction, and singlestepping thru a
1546 jump to the instruction following a trap instruction. */
1548 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1549 currently_stepping (ecs
) &&
1551 stop_pc
- DECR_PC_AFTER_BREAK
);
1552 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1553 goto process_event_stop_test
;
1555 case TARGET_WAITKIND_EXECD
:
1556 stop_signal
= TARGET_SIGNAL_TRAP
;
1558 /* Is this a target which reports multiple exec events per actual
1559 call to exec()? (HP-UX using ptrace does, for example.) If so,
1560 ignore all but the last one. Just resume the exec'r, and wait
1561 for the next exec event. */
1562 if (inferior_ignoring_leading_exec_events
)
1564 inferior_ignoring_leading_exec_events
--;
1565 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1566 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.
1568 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1569 prepare_to_wait (ecs
);
1572 inferior_ignoring_leading_exec_events
=
1573 target_reported_exec_events_per_exec_call () - 1;
1575 pending_follow
.execd_pathname
=
1576 savestring (ecs
->ws
.value
.execd_pathname
,
1577 strlen (ecs
->ws
.value
.execd_pathname
));
1579 /* Did inferior_ptid exec, or did a (possibly not-yet-followed)
1580 child of a vfork exec?
1582 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1583 HP-UX, events associated with a vforking inferior come in
1584 threes: a vfork event for the child (always first), followed
1585 a vfork event for the parent and an exec event for the child.
1586 The latter two can come in either order.
1588 If we get the parent vfork event first, life's good: We follow
1589 either the parent or child, and then the child's exec event is
1592 But if we get the child's exec event first, then we delay
1593 responding to it until we handle the parent's vfork. Because,
1594 otherwise we can't satisfy a "catch vfork". */
1595 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1597 pending_follow
.fork_event
.saw_child_exec
= 1;
1599 /* On some targets, the child must be resumed before
1600 the parent vfork event is delivered. A single-step
1602 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1603 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1604 /* We expect the parent vfork event to be available now. */
1605 prepare_to_wait (ecs
);
1609 /* This causes the eventpoints and symbol table to be reset. Must
1610 do this now, before trying to determine whether to stop. */
1611 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1612 xfree (pending_follow
.execd_pathname
);
1614 stop_pc
= read_pc_pid (ecs
->ptid
);
1615 ecs
->saved_inferior_ptid
= inferior_ptid
;
1616 inferior_ptid
= ecs
->ptid
;
1617 /* The second argument of bpstat_stop_status is meant to help
1618 distinguish between a breakpoint trap and a singlestep trap.
1619 This is only important on targets where DECR_PC_AFTER_BREAK
1620 is non-zero. The prev_pc test is meant to distinguish between
1621 singlestepping a trap instruction, and singlestepping thru a
1622 jump to the instruction following a trap instruction. */
1624 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1625 currently_stepping (ecs
) &&
1627 stop_pc
- DECR_PC_AFTER_BREAK
);
1628 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1629 inferior_ptid
= ecs
->saved_inferior_ptid
;
1630 goto process_event_stop_test
;
1632 /* These syscall events are returned on HP-UX, as part of its
1633 implementation of page-protection-based "hardware" watchpoints.
1634 HP-UX has unfortunate interactions between page-protections and
1635 some system calls. Our solution is to disable hardware watches
1636 when a system call is entered, and reenable them when the syscall
1637 completes. The downside of this is that we may miss the precise
1638 point at which a watched piece of memory is modified. "Oh well."
1640 Note that we may have multiple threads running, which may each
1641 enter syscalls at roughly the same time. Since we don't have a
1642 good notion currently of whether a watched piece of memory is
1643 thread-private, we'd best not have any page-protections active
1644 when any thread is in a syscall. Thus, we only want to reenable
1645 hardware watches when no threads are in a syscall.
1647 Also, be careful not to try to gather much state about a thread
1648 that's in a syscall. It's frequently a losing proposition. */
1649 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1650 number_of_threads_in_syscalls
++;
1651 if (number_of_threads_in_syscalls
== 1)
1653 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1655 resume (0, TARGET_SIGNAL_0
);
1656 prepare_to_wait (ecs
);
1659 /* Before examining the threads further, step this thread to
1660 get it entirely out of the syscall. (We get notice of the
1661 event when the thread is just on the verge of exiting a
1662 syscall. Stepping one instruction seems to get it back
1665 Note that although the logical place to reenable h/w watches
1666 is here, we cannot. We cannot reenable them before stepping
1667 the thread (this causes the next wait on the thread to hang).
1669 Nor can we enable them after stepping until we've done a wait.
1670 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1671 here, which will be serviced immediately after the target
1673 case TARGET_WAITKIND_SYSCALL_RETURN
:
1674 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1676 if (number_of_threads_in_syscalls
> 0)
1678 number_of_threads_in_syscalls
--;
1679 ecs
->enable_hw_watchpoints_after_wait
=
1680 (number_of_threads_in_syscalls
== 0);
1682 prepare_to_wait (ecs
);
1685 case TARGET_WAITKIND_STOPPED
:
1686 stop_signal
= ecs
->ws
.value
.sig
;
1689 /* We had an event in the inferior, but we are not interested
1690 in handling it at this level. The lower layers have already
1691 done what needs to be done, if anything.
1693 One of the possible circumstances for this is when the
1694 inferior produces output for the console. The inferior has
1695 not stopped, and we are ignoring the event. Another possible
1696 circumstance is any event which the lower level knows will be
1697 reported multiple times without an intervening resume. */
1698 case TARGET_WAITKIND_IGNORE
:
1699 prepare_to_wait (ecs
);
1703 /* We may want to consider not doing a resume here in order to give
1704 the user a chance to play with the new thread. It might be good
1705 to make that a user-settable option. */
1707 /* At this point, all threads are stopped (happens automatically in
1708 either the OS or the native code). Therefore we need to continue
1709 all threads in order to make progress. */
1710 if (ecs
->new_thread_event
)
1712 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1713 prepare_to_wait (ecs
);
1717 stop_pc
= read_pc_pid (ecs
->ptid
);
1719 /* See if a thread hit a thread-specific breakpoint that was meant for
1720 another thread. If so, then step that thread past the breakpoint,
1723 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1725 /* Check if a regular breakpoint has been hit before checking
1726 for a potential single step breakpoint. Otherwise, GDB will
1727 not see this breakpoint hit when stepping onto breakpoints. */
1728 if (breakpoints_inserted
1729 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1731 ecs
->random_signal
= 0;
1732 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1737 /* Saw a breakpoint, but it was hit by the wrong thread.
1739 if (DECR_PC_AFTER_BREAK
)
1740 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->ptid
);
1742 remove_status
= remove_breakpoints ();
1743 /* Did we fail to remove breakpoints? If so, try
1744 to set the PC past the bp. (There's at least
1745 one situation in which we can fail to remove
1746 the bp's: On HP-UX's that use ttrace, we can't
1747 change the address space of a vforking child
1748 process until the child exits (well, okay, not
1749 then either :-) or execs. */
1750 if (remove_status
!= 0)
1752 /* FIXME! This is obviously non-portable! */
1753 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->ptid
);
1754 /* We need to restart all the threads now,
1755 * unles we're running in scheduler-locked mode.
1756 * Use currently_stepping to determine whether to
1759 /* FIXME MVS: is there any reason not to call resume()? */
1760 if (scheduler_mode
== schedlock_on
)
1761 target_resume (ecs
->ptid
,
1762 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1764 target_resume (RESUME_ALL
,
1765 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1766 prepare_to_wait (ecs
);
1771 breakpoints_inserted
= 0;
1772 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
1773 context_switch (ecs
);
1774 ecs
->waiton_ptid
= ecs
->ptid
;
1775 ecs
->wp
= &(ecs
->ws
);
1776 ecs
->another_trap
= 1;
1778 ecs
->infwait_state
= infwait_thread_hop_state
;
1780 registers_changed ();
1785 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1787 /* Readjust the stop_pc as it is off by DECR_PC_AFTER_BREAK
1788 compared to the value it would have if the system stepping
1789 capability was used. This allows the rest of the code in
1790 this function to use this address without having to worry
1791 whether software single step is in use or not. */
1792 if (DECR_PC_AFTER_BREAK
)
1794 stop_pc
-= DECR_PC_AFTER_BREAK
;
1795 write_pc_pid (stop_pc
, ecs
->ptid
);
1798 sw_single_step_trap_p
= 1;
1799 ecs
->random_signal
= 0;
1803 ecs
->random_signal
= 1;
1805 /* See if something interesting happened to the non-current thread. If
1806 so, then switch to that thread, and eventually give control back to
1809 Note that if there's any kind of pending follow (i.e., of a fork,
1810 vfork or exec), we don't want to do this now. Rather, we'll let
1811 the next resume handle it. */
1812 if (!ptid_equal (ecs
->ptid
, inferior_ptid
) &&
1813 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1817 /* If it's a random signal for a non-current thread, notify user
1818 if he's expressed an interest. */
1819 if (ecs
->random_signal
&& signal_print
[stop_signal
])
1821 /* ??rehrauer: I don't understand the rationale for this code. If the
1822 inferior will stop as a result of this signal, then the act of handling
1823 the stop ought to print a message that's couches the stoppage in user
1824 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1825 won't stop as a result of the signal -- i.e., if the signal is merely
1826 a side-effect of something GDB's doing "under the covers" for the
1827 user, such as stepping threads over a breakpoint they shouldn't stop
1828 for -- then the message seems to be a serious annoyance at best.
1830 For now, remove the message altogether. */
1833 target_terminal_ours_for_output ();
1834 printf_filtered ("\nProgram received signal %s, %s.\n",
1835 target_signal_to_name (stop_signal
),
1836 target_signal_to_string (stop_signal
));
1837 gdb_flush (gdb_stdout
);
1841 /* If it's not SIGTRAP and not a signal we want to stop for, then
1842 continue the thread. */
1844 if (stop_signal
!= TARGET_SIGNAL_TRAP
&& !signal_stop
[stop_signal
])
1847 target_terminal_inferior ();
1849 /* Clear the signal if it should not be passed. */
1850 if (signal_program
[stop_signal
] == 0)
1851 stop_signal
= TARGET_SIGNAL_0
;
1853 target_resume (ecs
->ptid
, 0, stop_signal
);
1854 prepare_to_wait (ecs
);
1858 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1859 and fall into the rest of wait_for_inferior(). */
1861 context_switch (ecs
);
1864 context_hook (pid_to_thread_id (ecs
->ptid
));
1866 flush_cached_frames ();
1869 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1871 /* Pull the single step breakpoints out of the target. */
1872 SOFTWARE_SINGLE_STEP (0, 0);
1873 singlestep_breakpoints_inserted_p
= 0;
1876 /* If PC is pointing at a nullified instruction, then step beyond
1877 it so that the user won't be confused when GDB appears to be ready
1880 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1881 if (INSTRUCTION_NULLIFIED
)
1883 registers_changed ();
1884 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1886 /* We may have received a signal that we want to pass to
1887 the inferior; therefore, we must not clobber the waitstatus
1890 ecs
->infwait_state
= infwait_nullified_state
;
1891 ecs
->waiton_ptid
= ecs
->ptid
;
1892 ecs
->wp
= &(ecs
->tmpstatus
);
1893 prepare_to_wait (ecs
);
1897 /* It may not be necessary to disable the watchpoint to stop over
1898 it. For example, the PA can (with some kernel cooperation)
1899 single step over a watchpoint without disabling the watchpoint. */
1900 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1903 prepare_to_wait (ecs
);
1907 /* It is far more common to need to disable a watchpoint to step
1908 the inferior over it. FIXME. What else might a debug
1909 register or page protection watchpoint scheme need here? */
1910 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1912 /* At this point, we are stopped at an instruction which has
1913 attempted to write to a piece of memory under control of
1914 a watchpoint. The instruction hasn't actually executed
1915 yet. If we were to evaluate the watchpoint expression
1916 now, we would get the old value, and therefore no change
1917 would seem to have occurred.
1919 In order to make watchpoints work `right', we really need
1920 to complete the memory write, and then evaluate the
1921 watchpoint expression. The following code does that by
1922 removing the watchpoint (actually, all watchpoints and
1923 breakpoints), single-stepping the target, re-inserting
1924 watchpoints, and then falling through to let normal
1925 single-step processing handle proceed. Since this
1926 includes evaluating watchpoints, things will come to a
1927 stop in the correct manner. */
1929 if (DECR_PC_AFTER_BREAK
)
1930 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
1932 remove_breakpoints ();
1933 registers_changed ();
1934 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
1936 ecs
->waiton_ptid
= ecs
->ptid
;
1937 ecs
->wp
= &(ecs
->ws
);
1938 ecs
->infwait_state
= infwait_nonstep_watch_state
;
1939 prepare_to_wait (ecs
);
1943 /* It may be possible to simply continue after a watchpoint. */
1944 if (HAVE_CONTINUABLE_WATCHPOINT
)
1945 STOPPED_BY_WATCHPOINT (ecs
->ws
);
1947 ecs
->stop_func_start
= 0;
1948 ecs
->stop_func_end
= 0;
1949 ecs
->stop_func_name
= 0;
1950 /* Don't care about return value; stop_func_start and stop_func_name
1951 will both be 0 if it doesn't work. */
1952 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
1953 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
1954 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
1955 ecs
->another_trap
= 0;
1956 bpstat_clear (&stop_bpstat
);
1958 stop_stack_dummy
= 0;
1959 stop_print_frame
= 1;
1960 ecs
->random_signal
= 0;
1961 stopped_by_random_signal
= 0;
1962 breakpoints_failed
= 0;
1964 /* Look at the cause of the stop, and decide what to do.
1965 The alternatives are:
1966 1) break; to really stop and return to the debugger,
1967 2) drop through to start up again
1968 (set ecs->another_trap to 1 to single step once)
1969 3) set ecs->random_signal to 1, and the decision between 1 and 2
1970 will be made according to the signal handling tables. */
1972 /* First, distinguish signals caused by the debugger from signals
1973 that have to do with the program's own actions.
1974 Note that breakpoint insns may cause SIGTRAP or SIGILL
1975 or SIGEMT, depending on the operating system version.
1976 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1977 and change it to SIGTRAP. */
1979 if (stop_signal
== TARGET_SIGNAL_TRAP
1980 || (breakpoints_inserted
&&
1981 (stop_signal
== TARGET_SIGNAL_ILL
1982 || stop_signal
== TARGET_SIGNAL_EMT
)) || stop_soon_quietly
)
1984 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
1986 stop_print_frame
= 0;
1987 stop_stepping (ecs
);
1990 if (stop_soon_quietly
)
1992 stop_stepping (ecs
);
1996 /* Don't even think about breakpoints
1997 if just proceeded over a breakpoint.
1999 However, if we are trying to proceed over a breakpoint
2000 and end up in sigtramp, then through_sigtramp_breakpoint
2001 will be set and we should check whether we've hit the
2003 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2004 && through_sigtramp_breakpoint
== NULL
)
2005 bpstat_clear (&stop_bpstat
);
2008 /* See if there is a breakpoint at the current PC. */
2010 /* The second argument of bpstat_stop_status is meant to help
2011 distinguish between a breakpoint trap and a singlestep trap.
2012 This is only important on targets where DECR_PC_AFTER_BREAK
2013 is non-zero. The prev_pc test is meant to distinguish between
2014 singlestepping a trap instruction, and singlestepping thru a
2015 jump to the instruction following a trap instruction.
2017 Therefore, pass TRUE if our reason for stopping is
2018 something other than hitting a breakpoint. We do this by
2019 checking that either: we detected earlier a software single
2020 step trap or, 1) stepping is going on and 2) we didn't hit
2021 a breakpoint in a signal handler without an intervening stop
2022 in sigtramp, which is detected by a new stack pointer value
2023 below any usual function calling stack adjustments. */
2027 sw_single_step_trap_p
2028 || (currently_stepping (ecs
)
2029 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
2031 && INNER_THAN (read_sp (), (step_sp
- 16)))));
2032 /* Following in case break condition called a
2034 stop_print_frame
= 1;
2037 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2039 = !(bpstat_explains_signal (stop_bpstat
)
2041 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2042 && DEPRECATED_PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2043 get_frame_base (get_current_frame ())))
2044 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2048 ecs
->random_signal
= !(bpstat_explains_signal (stop_bpstat
)
2049 /* End of a stack dummy. Some systems (e.g. Sony
2050 news) give another signal besides SIGTRAP, so
2051 check here as well as above. */
2052 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2053 && DEPRECATED_PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2057 if (!ecs
->random_signal
)
2058 stop_signal
= TARGET_SIGNAL_TRAP
;
2062 /* When we reach this point, we've pretty much decided
2063 that the reason for stopping must've been a random
2064 (unexpected) signal. */
2067 ecs
->random_signal
= 1;
2068 /* If a fork, vfork or exec event was seen, then there are two
2069 possible responses we can make:
2071 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2072 then we must stop now and issue a prompt. We will resume
2073 the inferior when the user tells us to.
2074 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2075 then we must resume the inferior now and keep checking.
2077 In either case, we must take appropriate steps to "follow" the
2078 the fork/vfork/exec when the inferior is resumed. For example,
2079 if follow-fork-mode is "child", then we must detach from the
2080 parent inferior and follow the new child inferior.
2082 In either case, setting pending_follow causes the next resume()
2083 to take the appropriate following action. */
2084 process_event_stop_test
:
2085 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2087 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2090 stop_signal
= TARGET_SIGNAL_0
;
2095 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2097 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2099 stop_signal
= TARGET_SIGNAL_0
;
2104 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2106 pending_follow
.kind
= ecs
->ws
.kind
;
2107 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2110 stop_signal
= TARGET_SIGNAL_0
;
2116 /* For the program's own signals, act according to
2117 the signal handling tables. */
2119 if (ecs
->random_signal
)
2121 /* Signal not for debugging purposes. */
2124 stopped_by_random_signal
= 1;
2126 if (signal_print
[stop_signal
])
2129 target_terminal_ours_for_output ();
2130 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2132 if (signal_stop
[stop_signal
])
2134 stop_stepping (ecs
);
2137 /* If not going to stop, give terminal back
2138 if we took it away. */
2140 target_terminal_inferior ();
2142 /* Clear the signal if it should not be passed. */
2143 if (signal_program
[stop_signal
] == 0)
2144 stop_signal
= TARGET_SIGNAL_0
;
2146 /* I'm not sure whether this needs to be check_sigtramp2 or
2147 whether it could/should be keep_going.
2149 This used to jump to step_over_function if we are stepping,
2152 Suppose the user does a `next' over a function call, and while
2153 that call is in progress, the inferior receives a signal for
2154 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2155 that case, when we reach this point, there is already a
2156 step-resume breakpoint established, right where it should be:
2157 immediately after the function call the user is "next"-ing
2158 over. If we call step_over_function now, two bad things
2161 - we'll create a new breakpoint, at wherever the current
2162 frame's return address happens to be. That could be
2163 anywhere, depending on what function call happens to be on
2164 the top of the stack at that point. Point is, it's probably
2165 not where we need it.
2167 - the existing step-resume breakpoint (which is at the correct
2168 address) will get orphaned: step_resume_breakpoint will point
2169 to the new breakpoint, and the old step-resume breakpoint
2170 will never be cleaned up.
2172 The old behavior was meant to help HP-UX single-step out of
2173 sigtramps. It would place the new breakpoint at prev_pc, which
2174 was certainly wrong. I don't know the details there, so fixing
2175 this probably breaks that. As with anything else, it's up to
2176 the HP-UX maintainer to furnish a fix that doesn't break other
2177 platforms. --JimB, 20 May 1999 */
2178 check_sigtramp2 (ecs
);
2183 /* Handle cases caused by hitting a breakpoint. */
2185 CORE_ADDR jmp_buf_pc
;
2186 struct bpstat_what what
;
2188 what
= bpstat_what (stop_bpstat
);
2190 if (what
.call_dummy
)
2192 stop_stack_dummy
= 1;
2194 trap_expected_after_continue
= 1;
2198 switch (what
.main_action
)
2200 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2201 /* If we hit the breakpoint at longjmp, disable it for the
2202 duration of this command. Then, install a temporary
2203 breakpoint at the target of the jmp_buf. */
2204 disable_longjmp_breakpoint ();
2205 remove_breakpoints ();
2206 breakpoints_inserted
= 0;
2207 if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc
))
2213 /* Need to blow away step-resume breakpoint, as it
2214 interferes with us */
2215 if (step_resume_breakpoint
!= NULL
)
2217 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2219 /* Not sure whether we need to blow this away too, but probably
2220 it is like the step-resume breakpoint. */
2221 if (through_sigtramp_breakpoint
!= NULL
)
2223 delete_breakpoint (through_sigtramp_breakpoint
);
2224 through_sigtramp_breakpoint
= NULL
;
2228 /* FIXME - Need to implement nested temporary breakpoints */
2229 if (step_over_calls
> 0)
2230 set_longjmp_resume_breakpoint (jmp_buf_pc
, get_current_frame ());
2233 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2234 ecs
->handling_longjmp
= 1; /* FIXME */
2238 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2239 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2240 remove_breakpoints ();
2241 breakpoints_inserted
= 0;
2243 /* FIXME - Need to implement nested temporary breakpoints */
2245 && (frame_id_inner (get_frame_id (get_current_frame ()),
2248 ecs
->another_trap
= 1;
2253 disable_longjmp_breakpoint ();
2254 ecs
->handling_longjmp
= 0; /* FIXME */
2255 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2257 /* else fallthrough */
2259 case BPSTAT_WHAT_SINGLE
:
2260 if (breakpoints_inserted
)
2262 remove_breakpoints ();
2264 breakpoints_inserted
= 0;
2265 ecs
->another_trap
= 1;
2266 /* Still need to check other stuff, at least the case
2267 where we are stepping and step out of the right range. */
2270 case BPSTAT_WHAT_STOP_NOISY
:
2271 stop_print_frame
= 1;
2273 /* We are about to nuke the step_resume_breakpoint and
2274 through_sigtramp_breakpoint via the cleanup chain, so
2275 no need to worry about it here. */
2277 stop_stepping (ecs
);
2280 case BPSTAT_WHAT_STOP_SILENT
:
2281 stop_print_frame
= 0;
2283 /* We are about to nuke the step_resume_breakpoint and
2284 through_sigtramp_breakpoint via the cleanup chain, so
2285 no need to worry about it here. */
2287 stop_stepping (ecs
);
2290 case BPSTAT_WHAT_STEP_RESUME
:
2291 /* This proably demands a more elegant solution, but, yeah
2294 This function's use of the simple variable
2295 step_resume_breakpoint doesn't seem to accomodate
2296 simultaneously active step-resume bp's, although the
2297 breakpoint list certainly can.
2299 If we reach here and step_resume_breakpoint is already
2300 NULL, then apparently we have multiple active
2301 step-resume bp's. We'll just delete the breakpoint we
2302 stopped at, and carry on.
2304 Correction: what the code currently does is delete a
2305 step-resume bp, but it makes no effort to ensure that
2306 the one deleted is the one currently stopped at. MVS */
2308 if (step_resume_breakpoint
== NULL
)
2310 step_resume_breakpoint
=
2311 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2313 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2316 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2317 if (through_sigtramp_breakpoint
)
2318 delete_breakpoint (through_sigtramp_breakpoint
);
2319 through_sigtramp_breakpoint
= NULL
;
2321 /* If were waiting for a trap, hitting the step_resume_break
2322 doesn't count as getting it. */
2324 ecs
->another_trap
= 1;
2327 case BPSTAT_WHAT_CHECK_SHLIBS
:
2328 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2331 /* Remove breakpoints, we eventually want to step over the
2332 shlib event breakpoint, and SOLIB_ADD might adjust
2333 breakpoint addresses via breakpoint_re_set. */
2334 if (breakpoints_inserted
)
2335 remove_breakpoints ();
2336 breakpoints_inserted
= 0;
2338 /* Check for any newly added shared libraries if we're
2339 supposed to be adding them automatically. Switch
2340 terminal for any messages produced by
2341 breakpoint_re_set. */
2342 target_terminal_ours_for_output ();
2343 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
2344 target_terminal_inferior ();
2346 /* Try to reenable shared library breakpoints, additional
2347 code segments in shared libraries might be mapped in now. */
2348 re_enable_breakpoints_in_shlibs ();
2350 /* If requested, stop when the dynamic linker notifies
2351 gdb of events. This allows the user to get control
2352 and place breakpoints in initializer routines for
2353 dynamically loaded objects (among other things). */
2354 if (stop_on_solib_events
)
2356 stop_stepping (ecs
);
2360 /* If we stopped due to an explicit catchpoint, then the
2361 (see above) call to SOLIB_ADD pulled in any symbols
2362 from a newly-loaded library, if appropriate.
2364 We do want the inferior to stop, but not where it is
2365 now, which is in the dynamic linker callback. Rather,
2366 we would like it stop in the user's program, just after
2367 the call that caused this catchpoint to trigger. That
2368 gives the user a more useful vantage from which to
2369 examine their program's state. */
2370 else if (what
.main_action
==
2371 BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2373 /* ??rehrauer: If I could figure out how to get the
2374 right return PC from here, we could just set a temp
2375 breakpoint and resume. I'm not sure we can without
2376 cracking open the dld's shared libraries and sniffing
2377 their unwind tables and text/data ranges, and that's
2378 not a terribly portable notion.
2380 Until that time, we must step the inferior out of the
2381 dld callback, and also out of the dld itself (and any
2382 code or stubs in libdld.sl, such as "shl_load" and
2383 friends) until we reach non-dld code. At that point,
2384 we can stop stepping. */
2385 bpstat_get_triggered_catchpoints (stop_bpstat
,
2387 stepping_through_solib_catchpoints
);
2388 ecs
->stepping_through_solib_after_catch
= 1;
2390 /* Be sure to lift all breakpoints, so the inferior does
2391 actually step past this point... */
2392 ecs
->another_trap
= 1;
2397 /* We want to step over this breakpoint, then keep going. */
2398 ecs
->another_trap
= 1;
2405 case BPSTAT_WHAT_LAST
:
2406 /* Not a real code, but listed here to shut up gcc -Wall. */
2408 case BPSTAT_WHAT_KEEP_CHECKING
:
2413 /* We come here if we hit a breakpoint but should not
2414 stop for it. Possibly we also were stepping
2415 and should stop for that. So fall through and
2416 test for stepping. But, if not stepping,
2419 /* Are we stepping to get the inferior out of the dynamic
2420 linker's hook (and possibly the dld itself) after catching
2422 if (ecs
->stepping_through_solib_after_catch
)
2424 #if defined(SOLIB_ADD)
2425 /* Have we reached our destination? If not, keep going. */
2426 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2428 ecs
->another_trap
= 1;
2433 /* Else, stop and report the catchpoint(s) whose triggering
2434 caused us to begin stepping. */
2435 ecs
->stepping_through_solib_after_catch
= 0;
2436 bpstat_clear (&stop_bpstat
);
2437 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2438 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2439 stop_print_frame
= 1;
2440 stop_stepping (ecs
);
2444 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2446 /* This is the old way of detecting the end of the stack dummy.
2447 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2448 handled above. As soon as we can test it on all of them, all
2449 architectures should define it. */
2451 /* If this is the breakpoint at the end of a stack dummy,
2452 just stop silently, unless the user was doing an si/ni, in which
2453 case she'd better know what she's doing. */
2455 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2456 get_frame_base (get_current_frame ()))
2459 stop_print_frame
= 0;
2460 stop_stack_dummy
= 1;
2462 trap_expected_after_continue
= 1;
2464 stop_stepping (ecs
);
2469 if (step_resume_breakpoint
)
2471 /* Having a step-resume breakpoint overrides anything
2472 else having to do with stepping commands until
2473 that breakpoint is reached. */
2474 /* I'm not sure whether this needs to be check_sigtramp2 or
2475 whether it could/should be keep_going. */
2476 check_sigtramp2 (ecs
);
2481 if (step_range_end
== 0)
2483 /* Likewise if we aren't even stepping. */
2484 /* I'm not sure whether this needs to be check_sigtramp2 or
2485 whether it could/should be keep_going. */
2486 check_sigtramp2 (ecs
);
2491 /* If stepping through a line, keep going if still within it.
2493 Note that step_range_end is the address of the first instruction
2494 beyond the step range, and NOT the address of the last instruction
2496 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
2498 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2499 So definately need to check for sigtramp here. */
2500 check_sigtramp2 (ecs
);
2505 /* We stepped out of the stepping range. */
2507 /* If we are stepping at the source level and entered the runtime
2508 loader dynamic symbol resolution code, we keep on single stepping
2509 until we exit the run time loader code and reach the callee's
2511 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2512 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2514 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2516 if (pc_after_resolver
)
2518 /* Set up a step-resume breakpoint at the address
2519 indicated by SKIP_SOLIB_RESOLVER. */
2520 struct symtab_and_line sr_sal
;
2522 sr_sal
.pc
= pc_after_resolver
;
2524 check_for_old_step_resume_breakpoint ();
2525 step_resume_breakpoint
=
2526 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2527 if (breakpoints_inserted
)
2528 insert_breakpoints ();
2535 /* We can't update step_sp every time through the loop, because
2536 reading the stack pointer would slow down stepping too much.
2537 But we can update it every time we leave the step range. */
2538 ecs
->update_step_sp
= 1;
2540 /* Did we just take a signal? */
2541 if (PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2542 && !PC_IN_SIGTRAMP (prev_pc
, prev_func_name
)
2543 && INNER_THAN (read_sp (), step_sp
))
2545 /* We've just taken a signal; go until we are back to
2546 the point where we took it and one more. */
2548 /* Note: The test above succeeds not only when we stepped
2549 into a signal handler, but also when we step past the last
2550 statement of a signal handler and end up in the return stub
2551 of the signal handler trampoline. To distinguish between
2552 these two cases, check that the frame is INNER_THAN the
2553 previous one below. pai/1997-09-11 */
2557 struct frame_id current_frame
= get_frame_id (get_current_frame ());
2559 if (frame_id_inner (current_frame
, step_frame_id
))
2561 /* We have just taken a signal; go until we are back to
2562 the point where we took it and one more. */
2564 /* This code is needed at least in the following case:
2565 The user types "next" and then a signal arrives (before
2566 the "next" is done). */
2568 /* Note that if we are stopped at a breakpoint, then we need
2569 the step_resume breakpoint to override any breakpoints at
2570 the same location, so that we will still step over the
2571 breakpoint even though the signal happened. */
2572 struct symtab_and_line sr_sal
;
2575 sr_sal
.symtab
= NULL
;
2577 sr_sal
.pc
= prev_pc
;
2578 /* We could probably be setting the frame to
2579 step_frame_id; I don't think anyone thought to try it. */
2580 check_for_old_step_resume_breakpoint ();
2581 step_resume_breakpoint
=
2582 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2583 if (breakpoints_inserted
)
2584 insert_breakpoints ();
2588 /* We just stepped out of a signal handler and into
2589 its calling trampoline.
2591 Normally, we'd call step_over_function from
2592 here, but for some reason GDB can't unwind the
2593 stack correctly to find the real PC for the point
2594 user code where the signal trampoline will return
2595 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2596 But signal trampolines are pretty small stubs of
2597 code, anyway, so it's OK instead to just
2598 single-step out. Note: assuming such trampolines
2599 don't exhibit recursion on any platform... */
2600 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2601 &ecs
->stop_func_start
,
2602 &ecs
->stop_func_end
);
2603 /* Readjust stepping range */
2604 step_range_start
= ecs
->stop_func_start
;
2605 step_range_end
= ecs
->stop_func_end
;
2606 ecs
->stepping_through_sigtramp
= 1;
2611 /* If this is stepi or nexti, make sure that the stepping range
2612 gets us past that instruction. */
2613 if (step_range_end
== 1)
2614 /* FIXME: Does this run afoul of the code below which, if
2615 we step into the middle of a line, resets the stepping
2617 step_range_end
= (step_range_start
= prev_pc
) + 1;
2619 ecs
->remove_breakpoints_on_following_step
= 1;
2624 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2625 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2626 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2627 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2628 || ecs
->stop_func_name
== 0)
2630 /* It's a subroutine call. */
2632 if ((step_over_calls
== STEP_OVER_NONE
)
2633 || ((step_range_end
== 1)
2634 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2636 /* I presume that step_over_calls is only 0 when we're
2637 supposed to be stepping at the assembly language level
2638 ("stepi"). Just stop. */
2639 /* Also, maybe we just did a "nexti" inside a prolog,
2640 so we thought it was a subroutine call but it was not.
2641 Stop as well. FENN */
2643 print_stop_reason (END_STEPPING_RANGE
, 0);
2644 stop_stepping (ecs
);
2648 if (step_over_calls
== STEP_OVER_ALL
|| IGNORE_HELPER_CALL (stop_pc
))
2650 /* We're doing a "next". */
2652 if (PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2653 && frame_id_inner (step_frame_id
,
2654 frame_id_build (read_sp (), 0)))
2655 /* We stepped out of a signal handler, and into its
2656 calling trampoline. This is misdetected as a
2657 subroutine call, but stepping over the signal
2658 trampoline isn't such a bad idea. In order to do that,
2659 we have to ignore the value in step_frame_id, since
2660 that doesn't represent the frame that'll reach when we
2661 return from the signal trampoline. Otherwise we'll
2662 probably continue to the end of the program. */
2663 step_frame_id
= null_frame_id
;
2665 step_over_function (ecs
);
2670 /* If we are in a function call trampoline (a stub between
2671 the calling routine and the real function), locate the real
2672 function. That's what tells us (a) whether we want to step
2673 into it at all, and (b) what prologue we want to run to
2674 the end of, if we do step into it. */
2675 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2677 ecs
->stop_func_start
= tmp
;
2680 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2683 struct symtab_and_line xxx
;
2684 /* Why isn't this s_a_l called "sr_sal", like all of the
2685 other s_a_l's where this code is duplicated? */
2686 init_sal (&xxx
); /* initialize to zeroes */
2688 xxx
.section
= find_pc_overlay (xxx
.pc
);
2689 check_for_old_step_resume_breakpoint ();
2690 step_resume_breakpoint
=
2691 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2692 insert_breakpoints ();
2698 /* If we have line number information for the function we
2699 are thinking of stepping into, step into it.
2701 If there are several symtabs at that PC (e.g. with include
2702 files), just want to know whether *any* of them have line
2703 numbers. find_pc_line handles this. */
2705 struct symtab_and_line tmp_sal
;
2707 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2708 if (tmp_sal
.line
!= 0)
2710 step_into_function (ecs
);
2715 /* If we have no line number and the step-stop-if-no-debug
2716 is set, we stop the step so that the user has a chance to
2717 switch in assembly mode. */
2718 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2721 print_stop_reason (END_STEPPING_RANGE
, 0);
2722 stop_stepping (ecs
);
2726 step_over_function (ecs
);
2732 /* We've wandered out of the step range. */
2734 ecs
->sal
= find_pc_line (stop_pc
, 0);
2736 if (step_range_end
== 1)
2738 /* It is stepi or nexti. We always want to stop stepping after
2741 print_stop_reason (END_STEPPING_RANGE
, 0);
2742 stop_stepping (ecs
);
2746 /* If we're in the return path from a shared library trampoline,
2747 we want to proceed through the trampoline when stepping. */
2748 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2752 /* Determine where this trampoline returns. */
2753 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2755 /* Only proceed through if we know where it's going. */
2758 /* And put the step-breakpoint there and go until there. */
2759 struct symtab_and_line sr_sal
;
2761 init_sal (&sr_sal
); /* initialize to zeroes */
2763 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2764 /* Do not specify what the fp should be when we stop
2765 since on some machines the prologue
2766 is where the new fp value is established. */
2767 check_for_old_step_resume_breakpoint ();
2768 step_resume_breakpoint
=
2769 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2770 if (breakpoints_inserted
)
2771 insert_breakpoints ();
2773 /* Restart without fiddling with the step ranges or
2780 if (ecs
->sal
.line
== 0)
2782 /* We have no line number information. That means to stop
2783 stepping (does this always happen right after one instruction,
2784 when we do "s" in a function with no line numbers,
2785 or can this happen as a result of a return or longjmp?). */
2787 print_stop_reason (END_STEPPING_RANGE
, 0);
2788 stop_stepping (ecs
);
2792 if ((stop_pc
== ecs
->sal
.pc
)
2793 && (ecs
->current_line
!= ecs
->sal
.line
2794 || ecs
->current_symtab
!= ecs
->sal
.symtab
))
2796 /* We are at the start of a different line. So stop. Note that
2797 we don't stop if we step into the middle of a different line.
2798 That is said to make things like for (;;) statements work
2801 print_stop_reason (END_STEPPING_RANGE
, 0);
2802 stop_stepping (ecs
);
2806 /* We aren't done stepping.
2808 Optimize by setting the stepping range to the line.
2809 (We might not be in the original line, but if we entered a
2810 new line in mid-statement, we continue stepping. This makes
2811 things like for(;;) statements work better.) */
2813 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2815 /* If this is the last line of the function, don't keep stepping
2816 (it would probably step us out of the function).
2817 This is particularly necessary for a one-line function,
2818 in which after skipping the prologue we better stop even though
2819 we will be in mid-line. */
2821 print_stop_reason (END_STEPPING_RANGE
, 0);
2822 stop_stepping (ecs
);
2825 step_range_start
= ecs
->sal
.pc
;
2826 step_range_end
= ecs
->sal
.end
;
2827 step_frame_id
= get_frame_id (get_current_frame ());
2828 ecs
->current_line
= ecs
->sal
.line
;
2829 ecs
->current_symtab
= ecs
->sal
.symtab
;
2831 /* In the case where we just stepped out of a function into the
2832 middle of a line of the caller, continue stepping, but
2833 step_frame_id must be modified to current frame */
2835 struct frame_id current_frame
= get_frame_id (get_current_frame ());
2836 if (!(frame_id_inner (current_frame
, step_frame_id
)))
2837 step_frame_id
= current_frame
;
2843 /* Are we in the middle of stepping? */
2846 currently_stepping (struct execution_control_state
*ecs
)
2848 return ((through_sigtramp_breakpoint
== NULL
2849 && !ecs
->handling_longjmp
2850 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2852 || ecs
->stepping_through_solib_after_catch
2853 || bpstat_should_step ());
2857 check_sigtramp2 (struct execution_control_state
*ecs
)
2860 && PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2861 && !PC_IN_SIGTRAMP (prev_pc
, prev_func_name
)
2862 && INNER_THAN (read_sp (), step_sp
))
2864 /* What has happened here is that we have just stepped the
2865 inferior with a signal (because it is a signal which
2866 shouldn't make us stop), thus stepping into sigtramp.
2868 So we need to set a step_resume_break_address breakpoint and
2869 continue until we hit it, and then step. FIXME: This should
2870 be more enduring than a step_resume breakpoint; we should
2871 know that we will later need to keep going rather than
2872 re-hitting the breakpoint here (see the testsuite,
2873 gdb.base/signals.exp where it says "exceedingly difficult"). */
2875 struct symtab_and_line sr_sal
;
2877 init_sal (&sr_sal
); /* initialize to zeroes */
2878 sr_sal
.pc
= prev_pc
;
2879 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2880 /* We perhaps could set the frame if we kept track of what the
2881 frame corresponding to prev_pc was. But we don't, so don't. */
2882 through_sigtramp_breakpoint
=
2883 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2884 if (breakpoints_inserted
)
2885 insert_breakpoints ();
2887 ecs
->remove_breakpoints_on_following_step
= 1;
2888 ecs
->another_trap
= 1;
2892 /* Subroutine call with source code we should not step over. Do step
2893 to the first line of code in it. */
2896 step_into_function (struct execution_control_state
*ecs
)
2899 struct symtab_and_line sr_sal
;
2901 s
= find_pc_symtab (stop_pc
);
2902 if (s
&& s
->language
!= language_asm
)
2903 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2905 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2906 /* Use the step_resume_break to step until the end of the prologue,
2907 even if that involves jumps (as it seems to on the vax under
2909 /* If the prologue ends in the middle of a source line, continue to
2910 the end of that source line (if it is still within the function).
2911 Otherwise, just go to end of prologue. */
2912 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2913 /* no, don't either. It skips any code that's legitimately on the
2917 && ecs
->sal
.pc
!= ecs
->stop_func_start
2918 && ecs
->sal
.end
< ecs
->stop_func_end
)
2919 ecs
->stop_func_start
= ecs
->sal
.end
;
2922 if (ecs
->stop_func_start
== stop_pc
)
2924 /* We are already there: stop now. */
2926 print_stop_reason (END_STEPPING_RANGE
, 0);
2927 stop_stepping (ecs
);
2932 /* Put the step-breakpoint there and go until there. */
2933 init_sal (&sr_sal
); /* initialize to zeroes */
2934 sr_sal
.pc
= ecs
->stop_func_start
;
2935 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
2936 /* Do not specify what the fp should be when we stop since on
2937 some machines the prologue is where the new fp value is
2939 check_for_old_step_resume_breakpoint ();
2940 step_resume_breakpoint
=
2941 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2942 if (breakpoints_inserted
)
2943 insert_breakpoints ();
2945 /* And make sure stepping stops right away then. */
2946 step_range_end
= step_range_start
;
2951 /* We've just entered a callee, and we wish to resume until it returns
2952 to the caller. Setting a step_resume breakpoint on the return
2953 address will catch a return from the callee.
2955 However, if the callee is recursing, we want to be careful not to
2956 catch returns of those recursive calls, but only of THIS instance
2959 To do this, we set the step_resume bp's frame to our current
2960 caller's frame (step_frame_id, which is set by the "next" or
2961 "until" command, before execution begins). */
2964 step_over_function (struct execution_control_state
*ecs
)
2966 struct symtab_and_line sr_sal
;
2968 init_sal (&sr_sal
); /* initialize to zeros */
2969 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2970 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2972 check_for_old_step_resume_breakpoint ();
2973 step_resume_breakpoint
=
2974 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
2976 if (frame_id_p (step_frame_id
)
2977 && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
2978 /* FIXME: cagney/2002-12-01: Someone should modify the breakpoint
2979 code so that it uses a frame ID, instead of a frame address. */
2980 step_resume_breakpoint
->frame
= step_frame_id
.base
;
2982 if (breakpoints_inserted
)
2983 insert_breakpoints ();
2987 stop_stepping (struct execution_control_state
*ecs
)
2989 if (target_has_execution
)
2991 /* Are we stopping for a vfork event? We only stop when we see
2992 the child's event. However, we may not yet have seen the
2993 parent's event. And, inferior_ptid is still set to the
2994 parent's pid, until we resume again and follow either the
2997 To ensure that we can really touch inferior_ptid (aka, the
2998 parent process) -- which calls to functions like read_pc
2999 implicitly do -- wait on the parent if necessary. */
3000 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3001 && !pending_follow
.fork_event
.saw_parent_fork
)
3007 if (target_wait_hook
)
3008 parent_ptid
= target_wait_hook (pid_to_ptid (-1), &(ecs
->ws
));
3010 parent_ptid
= target_wait (pid_to_ptid (-1), &(ecs
->ws
));
3012 while (!ptid_equal (parent_ptid
, inferior_ptid
));
3015 /* Assuming the inferior still exists, set these up for next
3016 time, just like we did above if we didn't break out of the
3018 prev_pc
= read_pc ();
3019 prev_func_start
= ecs
->stop_func_start
;
3020 prev_func_name
= ecs
->stop_func_name
;
3023 /* Let callers know we don't want to wait for the inferior anymore. */
3024 ecs
->wait_some_more
= 0;
3027 /* This function handles various cases where we need to continue
3028 waiting for the inferior. */
3029 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3032 keep_going (struct execution_control_state
*ecs
)
3034 /* Save the pc before execution, to compare with pc after stop. */
3035 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3036 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3037 BREAK is defined, the
3038 original pc would not have
3039 been at the start of a
3041 prev_func_name
= ecs
->stop_func_name
;
3043 if (ecs
->update_step_sp
)
3044 step_sp
= read_sp ();
3045 ecs
->update_step_sp
= 0;
3047 /* If we did not do break;, it means we should keep running the
3048 inferior and not return to debugger. */
3050 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3052 /* We took a signal (which we are supposed to pass through to
3053 the inferior, else we'd have done a break above) and we
3054 haven't yet gotten our trap. Simply continue. */
3055 resume (currently_stepping (ecs
), stop_signal
);
3059 /* Either the trap was not expected, but we are continuing
3060 anyway (the user asked that this signal be passed to the
3063 The signal was SIGTRAP, e.g. it was our signal, but we
3064 decided we should resume from it.
3066 We're going to run this baby now!
3068 Insert breakpoints now, unless we are trying to one-proceed
3069 past a breakpoint. */
3070 /* If we've just finished a special step resume and we don't
3071 want to hit a breakpoint, pull em out. */
3072 if (step_resume_breakpoint
== NULL
3073 && through_sigtramp_breakpoint
== NULL
3074 && ecs
->remove_breakpoints_on_following_step
)
3076 ecs
->remove_breakpoints_on_following_step
= 0;
3077 remove_breakpoints ();
3078 breakpoints_inserted
= 0;
3080 else if (!breakpoints_inserted
&&
3081 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3083 breakpoints_failed
= insert_breakpoints ();
3084 if (breakpoints_failed
)
3086 stop_stepping (ecs
);
3089 breakpoints_inserted
= 1;
3092 trap_expected
= ecs
->another_trap
;
3094 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3095 specifies that such a signal should be delivered to the
3098 Typically, this would occure when a user is debugging a
3099 target monitor on a simulator: the target monitor sets a
3100 breakpoint; the simulator encounters this break-point and
3101 halts the simulation handing control to GDB; GDB, noteing
3102 that the break-point isn't valid, returns control back to the
3103 simulator; the simulator then delivers the hardware
3104 equivalent of a SIGNAL_TRAP to the program being debugged. */
3106 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !signal_program
[stop_signal
])
3107 stop_signal
= TARGET_SIGNAL_0
;
3109 #ifdef SHIFT_INST_REGS
3110 /* I'm not sure when this following segment applies. I do know,
3111 now, that we shouldn't rewrite the regs when we were stopped
3112 by a random signal from the inferior process. */
3113 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3114 (this is only used on the 88k). */
3116 if (!bpstat_explains_signal (stop_bpstat
)
3117 && (stop_signal
!= TARGET_SIGNAL_CHLD
) && !stopped_by_random_signal
)
3119 #endif /* SHIFT_INST_REGS */
3121 resume (currently_stepping (ecs
), stop_signal
);
3124 prepare_to_wait (ecs
);
3127 /* This function normally comes after a resume, before
3128 handle_inferior_event exits. It takes care of any last bits of
3129 housekeeping, and sets the all-important wait_some_more flag. */
3132 prepare_to_wait (struct execution_control_state
*ecs
)
3134 if (ecs
->infwait_state
== infwait_normal_state
)
3136 overlay_cache_invalid
= 1;
3138 /* We have to invalidate the registers BEFORE calling
3139 target_wait because they can be loaded from the target while
3140 in target_wait. This makes remote debugging a bit more
3141 efficient for those targets that provide critical registers
3142 as part of their normal status mechanism. */
3144 registers_changed ();
3145 ecs
->waiton_ptid
= pid_to_ptid (-1);
3146 ecs
->wp
= &(ecs
->ws
);
3148 /* This is the old end of the while loop. Let everybody know we
3149 want to wait for the inferior some more and get called again
3151 ecs
->wait_some_more
= 1;
3154 /* Print why the inferior has stopped. We always print something when
3155 the inferior exits, or receives a signal. The rest of the cases are
3156 dealt with later on in normal_stop() and print_it_typical(). Ideally
3157 there should be a call to this function from handle_inferior_event()
3158 each time stop_stepping() is called.*/
3160 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3162 switch (stop_reason
)
3165 /* We don't deal with these cases from handle_inferior_event()
3168 case END_STEPPING_RANGE
:
3169 /* We are done with a step/next/si/ni command. */
3170 /* For now print nothing. */
3171 /* Print a message only if not in the middle of doing a "step n"
3172 operation for n > 1 */
3173 if (!step_multi
|| !stop_step
)
3174 if (ui_out_is_mi_like_p (uiout
))
3175 ui_out_field_string (uiout
, "reason", "end-stepping-range");
3177 case BREAKPOINT_HIT
:
3178 /* We found a breakpoint. */
3179 /* For now print nothing. */
3182 /* The inferior was terminated by a signal. */
3183 annotate_signalled ();
3184 if (ui_out_is_mi_like_p (uiout
))
3185 ui_out_field_string (uiout
, "reason", "exited-signalled");
3186 ui_out_text (uiout
, "\nProgram terminated with signal ");
3187 annotate_signal_name ();
3188 ui_out_field_string (uiout
, "signal-name",
3189 target_signal_to_name (stop_info
));
3190 annotate_signal_name_end ();
3191 ui_out_text (uiout
, ", ");
3192 annotate_signal_string ();
3193 ui_out_field_string (uiout
, "signal-meaning",
3194 target_signal_to_string (stop_info
));
3195 annotate_signal_string_end ();
3196 ui_out_text (uiout
, ".\n");
3197 ui_out_text (uiout
, "The program no longer exists.\n");
3200 /* The inferior program is finished. */
3201 annotate_exited (stop_info
);
3204 if (ui_out_is_mi_like_p (uiout
))
3205 ui_out_field_string (uiout
, "reason", "exited");
3206 ui_out_text (uiout
, "\nProgram exited with code ");
3207 ui_out_field_fmt (uiout
, "exit-code", "0%o",
3208 (unsigned int) stop_info
);
3209 ui_out_text (uiout
, ".\n");
3213 if (ui_out_is_mi_like_p (uiout
))
3214 ui_out_field_string (uiout
, "reason", "exited-normally");
3215 ui_out_text (uiout
, "\nProgram exited normally.\n");
3218 case SIGNAL_RECEIVED
:
3219 /* Signal received. The signal table tells us to print about
3222 ui_out_text (uiout
, "\nProgram received signal ");
3223 annotate_signal_name ();
3224 if (ui_out_is_mi_like_p (uiout
))
3225 ui_out_field_string (uiout
, "reason", "signal-received");
3226 ui_out_field_string (uiout
, "signal-name",
3227 target_signal_to_name (stop_info
));
3228 annotate_signal_name_end ();
3229 ui_out_text (uiout
, ", ");
3230 annotate_signal_string ();
3231 ui_out_field_string (uiout
, "signal-meaning",
3232 target_signal_to_string (stop_info
));
3233 annotate_signal_string_end ();
3234 ui_out_text (uiout
, ".\n");
3237 internal_error (__FILE__
, __LINE__
,
3238 "print_stop_reason: unrecognized enum value");
3244 /* Here to return control to GDB when the inferior stops for real.
3245 Print appropriate messages, remove breakpoints, give terminal our modes.
3247 STOP_PRINT_FRAME nonzero means print the executing frame
3248 (pc, function, args, file, line number and line text).
3249 BREAKPOINTS_FAILED nonzero means stop was due to error
3250 attempting to insert breakpoints. */
3255 /* As with the notification of thread events, we want to delay
3256 notifying the user that we've switched thread context until
3257 the inferior actually stops.
3259 (Note that there's no point in saying anything if the inferior
3261 if (!ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3262 && target_has_execution
)
3264 target_terminal_ours_for_output ();
3265 printf_filtered ("[Switching to %s]\n",
3266 target_pid_or_tid_to_str (inferior_ptid
));
3267 previous_inferior_ptid
= inferior_ptid
;
3270 /* Make sure that the current_frame's pc is correct. This
3271 is a correction for setting up the frame info before doing
3272 DECR_PC_AFTER_BREAK */
3273 if (target_has_execution
&& get_current_frame ())
3274 (get_current_frame ())->pc
= read_pc ();
3276 if (target_has_execution
&& breakpoints_inserted
)
3278 if (remove_breakpoints ())
3280 target_terminal_ours_for_output ();
3281 printf_filtered ("Cannot remove breakpoints because ");
3282 printf_filtered ("program is no longer writable.\n");
3283 printf_filtered ("It might be running in another process.\n");
3284 printf_filtered ("Further execution is probably impossible.\n");
3287 breakpoints_inserted
= 0;
3289 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3290 Delete any breakpoint that is to be deleted at the next stop. */
3292 breakpoint_auto_delete (stop_bpstat
);
3294 /* If an auto-display called a function and that got a signal,
3295 delete that auto-display to avoid an infinite recursion. */
3297 if (stopped_by_random_signal
)
3298 disable_current_display ();
3300 /* Don't print a message if in the middle of doing a "step n"
3301 operation for n > 1 */
3302 if (step_multi
&& stop_step
)
3305 target_terminal_ours ();
3307 /* Look up the hook_stop and run it (CLI internally handles problem
3308 of stop_command's pre-hook not existing). */
3310 catch_errors (hook_stop_stub
, stop_command
,
3311 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3313 if (!target_has_stack
)
3319 /* Select innermost stack frame - i.e., current frame is frame 0,
3320 and current location is based on that.
3321 Don't do this on return from a stack dummy routine,
3322 or if the program has exited. */
3324 if (!stop_stack_dummy
)
3326 select_frame (get_current_frame ());
3328 /* Print current location without a level number, if
3329 we have changed functions or hit a breakpoint.
3330 Print source line if we have one.
3331 bpstat_print() contains the logic deciding in detail
3332 what to print, based on the event(s) that just occurred. */
3334 if (stop_print_frame
&& deprecated_selected_frame
)
3338 int do_frame_printing
= 1;
3340 bpstat_ret
= bpstat_print (stop_bpstat
);
3344 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3345 (or should) carry around the function and does (or
3346 should) use that when doing a frame comparison. */
3348 && frame_id_eq (step_frame_id
,
3349 get_frame_id (get_current_frame ()))
3350 && step_start_function
== find_pc_function (stop_pc
))
3351 source_flag
= SRC_LINE
; /* finished step, just print source line */
3353 source_flag
= SRC_AND_LOC
; /* print location and source line */
3355 case PRINT_SRC_AND_LOC
:
3356 source_flag
= SRC_AND_LOC
; /* print location and source line */
3358 case PRINT_SRC_ONLY
:
3359 source_flag
= SRC_LINE
;
3362 source_flag
= SRC_LINE
; /* something bogus */
3363 do_frame_printing
= 0;
3366 internal_error (__FILE__
, __LINE__
, "Unknown value.");
3368 /* For mi, have the same behavior every time we stop:
3369 print everything but the source line. */
3370 if (ui_out_is_mi_like_p (uiout
))
3371 source_flag
= LOC_AND_ADDRESS
;
3373 if (ui_out_is_mi_like_p (uiout
))
3374 ui_out_field_int (uiout
, "thread-id",
3375 pid_to_thread_id (inferior_ptid
));
3376 /* The behavior of this routine with respect to the source
3378 SRC_LINE: Print only source line
3379 LOCATION: Print only location
3380 SRC_AND_LOC: Print location and source line */
3381 if (do_frame_printing
)
3382 show_and_print_stack_frame (deprecated_selected_frame
, -1, source_flag
);
3384 /* Display the auto-display expressions. */
3389 /* Save the function value return registers, if we care.
3390 We might be about to restore their previous contents. */
3391 if (proceed_to_finish
)
3392 /* NB: The copy goes through to the target picking up the value of
3393 all the registers. */
3394 regcache_cpy (stop_registers
, current_regcache
);
3396 if (stop_stack_dummy
)
3398 /* Pop the empty frame that contains the stack dummy.
3399 POP_FRAME ends with a setting of the current frame, so we
3400 can use that next. */
3402 /* Set stop_pc to what it was before we called the function.
3403 Can't rely on restore_inferior_status because that only gets
3404 called if we don't stop in the called function. */
3405 stop_pc
= read_pc ();
3406 select_frame (get_current_frame ());
3410 annotate_stopped ();
3414 hook_stop_stub (void *cmd
)
3416 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3421 signal_stop_state (int signo
)
3423 return signal_stop
[signo
];
3427 signal_print_state (int signo
)
3429 return signal_print
[signo
];
3433 signal_pass_state (int signo
)
3435 return signal_program
[signo
];
3439 signal_stop_update (int signo
, int state
)
3441 int ret
= signal_stop
[signo
];
3442 signal_stop
[signo
] = state
;
3447 signal_print_update (int signo
, int state
)
3449 int ret
= signal_print
[signo
];
3450 signal_print
[signo
] = state
;
3455 signal_pass_update (int signo
, int state
)
3457 int ret
= signal_program
[signo
];
3458 signal_program
[signo
] = state
;
3463 sig_print_header (void)
3466 Signal Stop\tPrint\tPass to program\tDescription\n");
3470 sig_print_info (enum target_signal oursig
)
3472 char *name
= target_signal_to_name (oursig
);
3473 int name_padding
= 13 - strlen (name
);
3475 if (name_padding
<= 0)
3478 printf_filtered ("%s", name
);
3479 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
3480 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3481 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3482 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3483 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3486 /* Specify how various signals in the inferior should be handled. */
3489 handle_command (char *args
, int from_tty
)
3492 int digits
, wordlen
;
3493 int sigfirst
, signum
, siglast
;
3494 enum target_signal oursig
;
3497 unsigned char *sigs
;
3498 struct cleanup
*old_chain
;
3502 error_no_arg ("signal to handle");
3505 /* Allocate and zero an array of flags for which signals to handle. */
3507 nsigs
= (int) TARGET_SIGNAL_LAST
;
3508 sigs
= (unsigned char *) alloca (nsigs
);
3509 memset (sigs
, 0, nsigs
);
3511 /* Break the command line up into args. */
3513 argv
= buildargv (args
);
3518 old_chain
= make_cleanup_freeargv (argv
);
3520 /* Walk through the args, looking for signal oursigs, signal names, and
3521 actions. Signal numbers and signal names may be interspersed with
3522 actions, with the actions being performed for all signals cumulatively
3523 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3525 while (*argv
!= NULL
)
3527 wordlen
= strlen (*argv
);
3528 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3532 sigfirst
= siglast
= -1;
3534 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3536 /* Apply action to all signals except those used by the
3537 debugger. Silently skip those. */
3540 siglast
= nsigs
- 1;
3542 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3544 SET_SIGS (nsigs
, sigs
, signal_stop
);
3545 SET_SIGS (nsigs
, sigs
, signal_print
);
3547 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3549 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3551 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3553 SET_SIGS (nsigs
, sigs
, signal_print
);
3555 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3557 SET_SIGS (nsigs
, sigs
, signal_program
);
3559 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3561 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3563 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3565 SET_SIGS (nsigs
, sigs
, signal_program
);
3567 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3569 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3570 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3572 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3574 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3576 else if (digits
> 0)
3578 /* It is numeric. The numeric signal refers to our own
3579 internal signal numbering from target.h, not to host/target
3580 signal number. This is a feature; users really should be
3581 using symbolic names anyway, and the common ones like
3582 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3584 sigfirst
= siglast
= (int)
3585 target_signal_from_command (atoi (*argv
));
3586 if ((*argv
)[digits
] == '-')
3589 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3591 if (sigfirst
> siglast
)
3593 /* Bet he didn't figure we'd think of this case... */
3601 oursig
= target_signal_from_name (*argv
);
3602 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3604 sigfirst
= siglast
= (int) oursig
;
3608 /* Not a number and not a recognized flag word => complain. */
3609 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3613 /* If any signal numbers or symbol names were found, set flags for
3614 which signals to apply actions to. */
3616 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3618 switch ((enum target_signal
) signum
)
3620 case TARGET_SIGNAL_TRAP
:
3621 case TARGET_SIGNAL_INT
:
3622 if (!allsigs
&& !sigs
[signum
])
3624 if (query ("%s is used by the debugger.\n\
3625 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
3631 printf_unfiltered ("Not confirmed, unchanged.\n");
3632 gdb_flush (gdb_stdout
);
3636 case TARGET_SIGNAL_0
:
3637 case TARGET_SIGNAL_DEFAULT
:
3638 case TARGET_SIGNAL_UNKNOWN
:
3639 /* Make sure that "all" doesn't print these. */
3650 target_notice_signals (inferior_ptid
);
3654 /* Show the results. */
3655 sig_print_header ();
3656 for (signum
= 0; signum
< nsigs
; signum
++)
3660 sig_print_info (signum
);
3665 do_cleanups (old_chain
);
3669 xdb_handle_command (char *args
, int from_tty
)
3672 struct cleanup
*old_chain
;
3674 /* Break the command line up into args. */
3676 argv
= buildargv (args
);
3681 old_chain
= make_cleanup_freeargv (argv
);
3682 if (argv
[1] != (char *) NULL
)
3687 bufLen
= strlen (argv
[0]) + 20;
3688 argBuf
= (char *) xmalloc (bufLen
);
3692 enum target_signal oursig
;
3694 oursig
= target_signal_from_name (argv
[0]);
3695 memset (argBuf
, 0, bufLen
);
3696 if (strcmp (argv
[1], "Q") == 0)
3697 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3700 if (strcmp (argv
[1], "s") == 0)
3702 if (!signal_stop
[oursig
])
3703 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3705 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3707 else if (strcmp (argv
[1], "i") == 0)
3709 if (!signal_program
[oursig
])
3710 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3712 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3714 else if (strcmp (argv
[1], "r") == 0)
3716 if (!signal_print
[oursig
])
3717 sprintf (argBuf
, "%s %s", argv
[0], "print");
3719 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3725 handle_command (argBuf
, from_tty
);
3727 printf_filtered ("Invalid signal handling flag.\n");
3732 do_cleanups (old_chain
);
3735 /* Print current contents of the tables set by the handle command.
3736 It is possible we should just be printing signals actually used
3737 by the current target (but for things to work right when switching
3738 targets, all signals should be in the signal tables). */
3741 signals_info (char *signum_exp
, int from_tty
)
3743 enum target_signal oursig
;
3744 sig_print_header ();
3748 /* First see if this is a symbol name. */
3749 oursig
= target_signal_from_name (signum_exp
);
3750 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3752 /* No, try numeric. */
3754 target_signal_from_command (parse_and_eval_long (signum_exp
));
3756 sig_print_info (oursig
);
3760 printf_filtered ("\n");
3761 /* These ugly casts brought to you by the native VAX compiler. */
3762 for (oursig
= TARGET_SIGNAL_FIRST
;
3763 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3764 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3768 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3769 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
3770 sig_print_info (oursig
);
3773 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3776 struct inferior_status
3778 enum target_signal stop_signal
;
3782 int stop_stack_dummy
;
3783 int stopped_by_random_signal
;
3785 CORE_ADDR step_range_start
;
3786 CORE_ADDR step_range_end
;
3787 struct frame_id step_frame_id
;
3788 enum step_over_calls_kind step_over_calls
;
3789 CORE_ADDR step_resume_break_address
;
3790 int stop_after_trap
;
3791 int stop_soon_quietly
;
3792 struct regcache
*stop_registers
;
3794 /* These are here because if call_function_by_hand has written some
3795 registers and then decides to call error(), we better not have changed
3797 struct regcache
*registers
;
3799 /* A frame unique identifier. */
3800 struct frame_id selected_frame_id
;
3802 int breakpoint_proceeded
;
3803 int restore_stack_info
;
3804 int proceed_to_finish
;
3808 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3811 int size
= REGISTER_RAW_SIZE (regno
);
3812 void *buf
= alloca (size
);
3813 store_signed_integer (buf
, size
, val
);
3814 regcache_raw_write (inf_status
->registers
, regno
, buf
);
3817 /* Save all of the information associated with the inferior<==>gdb
3818 connection. INF_STATUS is a pointer to a "struct inferior_status"
3819 (defined in inferior.h). */
3821 struct inferior_status
*
3822 save_inferior_status (int restore_stack_info
)
3824 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
3826 inf_status
->stop_signal
= stop_signal
;
3827 inf_status
->stop_pc
= stop_pc
;
3828 inf_status
->stop_step
= stop_step
;
3829 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3830 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3831 inf_status
->trap_expected
= trap_expected
;
3832 inf_status
->step_range_start
= step_range_start
;
3833 inf_status
->step_range_end
= step_range_end
;
3834 inf_status
->step_frame_id
= step_frame_id
;
3835 inf_status
->step_over_calls
= step_over_calls
;
3836 inf_status
->stop_after_trap
= stop_after_trap
;
3837 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3838 /* Save original bpstat chain here; replace it with copy of chain.
3839 If caller's caller is walking the chain, they'll be happier if we
3840 hand them back the original chain when restore_inferior_status is
3842 inf_status
->stop_bpstat
= stop_bpstat
;
3843 stop_bpstat
= bpstat_copy (stop_bpstat
);
3844 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3845 inf_status
->restore_stack_info
= restore_stack_info
;
3846 inf_status
->proceed_to_finish
= proceed_to_finish
;
3848 inf_status
->stop_registers
= regcache_dup_no_passthrough (stop_registers
);
3850 inf_status
->registers
= regcache_dup (current_regcache
);
3852 inf_status
->selected_frame_id
= get_frame_id (deprecated_selected_frame
);
3857 restore_selected_frame (void *args
)
3859 struct frame_id
*fid
= (struct frame_id
*) args
;
3860 struct frame_info
*frame
;
3862 frame
= frame_find_by_id (*fid
);
3864 /* If inf_status->selected_frame_id is NULL, there was no previously
3868 warning ("Unable to restore previously selected frame.\n");
3872 select_frame (frame
);
3878 restore_inferior_status (struct inferior_status
*inf_status
)
3880 stop_signal
= inf_status
->stop_signal
;
3881 stop_pc
= inf_status
->stop_pc
;
3882 stop_step
= inf_status
->stop_step
;
3883 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3884 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3885 trap_expected
= inf_status
->trap_expected
;
3886 step_range_start
= inf_status
->step_range_start
;
3887 step_range_end
= inf_status
->step_range_end
;
3888 step_frame_id
= inf_status
->step_frame_id
;
3889 step_over_calls
= inf_status
->step_over_calls
;
3890 stop_after_trap
= inf_status
->stop_after_trap
;
3891 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
3892 bpstat_clear (&stop_bpstat
);
3893 stop_bpstat
= inf_status
->stop_bpstat
;
3894 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3895 proceed_to_finish
= inf_status
->proceed_to_finish
;
3897 /* FIXME: Is the restore of stop_registers always needed. */
3898 regcache_xfree (stop_registers
);
3899 stop_registers
= inf_status
->stop_registers
;
3901 /* The inferior can be gone if the user types "print exit(0)"
3902 (and perhaps other times). */
3903 if (target_has_execution
)
3904 /* NB: The register write goes through to the target. */
3905 regcache_cpy (current_regcache
, inf_status
->registers
);
3906 regcache_xfree (inf_status
->registers
);
3908 /* FIXME: If we are being called after stopping in a function which
3909 is called from gdb, we should not be trying to restore the
3910 selected frame; it just prints a spurious error message (The
3911 message is useful, however, in detecting bugs in gdb (like if gdb
3912 clobbers the stack)). In fact, should we be restoring the
3913 inferior status at all in that case? . */
3915 if (target_has_stack
&& inf_status
->restore_stack_info
)
3917 /* The point of catch_errors is that if the stack is clobbered,
3918 walking the stack might encounter a garbage pointer and
3919 error() trying to dereference it. */
3921 (restore_selected_frame
, &inf_status
->selected_frame_id
,
3922 "Unable to restore previously selected frame:\n",
3923 RETURN_MASK_ERROR
) == 0)
3924 /* Error in restoring the selected frame. Select the innermost
3926 select_frame (get_current_frame ());
3934 do_restore_inferior_status_cleanup (void *sts
)
3936 restore_inferior_status (sts
);
3940 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
3942 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
3946 discard_inferior_status (struct inferior_status
*inf_status
)
3948 /* See save_inferior_status for info on stop_bpstat. */
3949 bpstat_clear (&inf_status
->stop_bpstat
);
3950 regcache_xfree (inf_status
->registers
);
3951 regcache_xfree (inf_status
->stop_registers
);
3956 inferior_has_forked (int pid
, int *child_pid
)
3958 struct target_waitstatus last
;
3961 get_last_target_status (&last_ptid
, &last
);
3963 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
3966 if (ptid_get_pid (last_ptid
) != pid
)
3969 *child_pid
= last
.value
.related_pid
;
3974 inferior_has_vforked (int pid
, int *child_pid
)
3976 struct target_waitstatus last
;
3979 get_last_target_status (&last_ptid
, &last
);
3981 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
3984 if (ptid_get_pid (last_ptid
) != pid
)
3987 *child_pid
= last
.value
.related_pid
;
3992 inferior_has_execd (int pid
, char **execd_pathname
)
3994 struct target_waitstatus last
;
3997 get_last_target_status (&last_ptid
, &last
);
3999 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
4002 if (ptid_get_pid (last_ptid
) != pid
)
4005 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
4009 /* Oft used ptids */
4011 ptid_t minus_one_ptid
;
4013 /* Create a ptid given the necessary PID, LWP, and TID components. */
4016 ptid_build (int pid
, long lwp
, long tid
)
4026 /* Create a ptid from just a pid. */
4029 pid_to_ptid (int pid
)
4031 return ptid_build (pid
, 0, 0);
4034 /* Fetch the pid (process id) component from a ptid. */
4037 ptid_get_pid (ptid_t ptid
)
4042 /* Fetch the lwp (lightweight process) component from a ptid. */
4045 ptid_get_lwp (ptid_t ptid
)
4050 /* Fetch the tid (thread id) component from a ptid. */
4053 ptid_get_tid (ptid_t ptid
)
4058 /* ptid_equal() is used to test equality of two ptids. */
4061 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4063 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4064 && ptid1
.tid
== ptid2
.tid
);
4067 /* restore_inferior_ptid() will be used by the cleanup machinery
4068 to restore the inferior_ptid value saved in a call to
4069 save_inferior_ptid(). */
4072 restore_inferior_ptid (void *arg
)
4074 ptid_t
*saved_ptid_ptr
= arg
;
4075 inferior_ptid
= *saved_ptid_ptr
;
4079 /* Save the value of inferior_ptid so that it may be restored by a
4080 later call to do_cleanups(). Returns the struct cleanup pointer
4081 needed for later doing the cleanup. */
4084 save_inferior_ptid (void)
4086 ptid_t
*saved_ptid_ptr
;
4088 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4089 *saved_ptid_ptr
= inferior_ptid
;
4090 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4097 stop_registers
= regcache_xmalloc (current_gdbarch
);
4101 _initialize_infrun (void)
4104 register int numsigs
;
4105 struct cmd_list_element
*c
;
4107 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4108 register_gdbarch_swap (NULL
, 0, build_infrun
);
4110 add_info ("signals", signals_info
,
4111 "What debugger does when program gets various signals.\n\
4112 Specify a signal as argument to print info on that signal only.");
4113 add_info_alias ("handle", "signals", 0);
4115 add_com ("handle", class_run
, handle_command
,
4116 concat ("Specify how to handle a signal.\n\
4117 Args are signals and actions to apply to those signals.\n\
4118 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4119 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4120 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4121 The special arg \"all\" is recognized to mean all signals except those\n\
4122 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4123 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4124 Stop means reenter debugger if this signal happens (implies print).\n\
4125 Print means print a message if this signal happens.\n\
4126 Pass means let program see this signal; otherwise program doesn't know.\n\
4127 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4128 Pass and Stop may be combined.", NULL
));
4131 add_com ("lz", class_info
, signals_info
,
4132 "What debugger does when program gets various signals.\n\
4133 Specify a signal as argument to print info on that signal only.");
4134 add_com ("z", class_run
, xdb_handle_command
,
4135 concat ("Specify how to handle a signal.\n\
4136 Args are signals and actions to apply to those signals.\n\
4137 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4138 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4139 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4140 The special arg \"all\" is recognized to mean all signals except those\n\
4141 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4142 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4143 nopass), \"Q\" (noprint)\n\
4144 Stop means reenter debugger if this signal happens (implies print).\n\
4145 Print means print a message if this signal happens.\n\
4146 Pass means let program see this signal; otherwise program doesn't know.\n\
4147 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4148 Pass and Stop may be combined.", NULL
));
4153 add_cmd ("stop", class_obscure
, not_just_help_class_command
, "There is no `stop' command, but you can set a hook on `stop'.\n\
4154 This allows you to set a list of commands to be run each time execution\n\
4155 of the program stops.", &cmdlist
);
4157 numsigs
= (int) TARGET_SIGNAL_LAST
;
4158 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4159 signal_print
= (unsigned char *)
4160 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4161 signal_program
= (unsigned char *)
4162 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4163 for (i
= 0; i
< numsigs
; i
++)
4166 signal_print
[i
] = 1;
4167 signal_program
[i
] = 1;
4170 /* Signals caused by debugger's own actions
4171 should not be given to the program afterwards. */
4172 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4173 signal_program
[TARGET_SIGNAL_INT
] = 0;
4175 /* Signals that are not errors should not normally enter the debugger. */
4176 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4177 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4178 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4179 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4180 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4181 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4182 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4183 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4184 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4185 signal_print
[TARGET_SIGNAL_IO
] = 0;
4186 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4187 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4188 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4189 signal_print
[TARGET_SIGNAL_URG
] = 0;
4190 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4191 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4193 /* These signals are used internally by user-level thread
4194 implementations. (See signal(5) on Solaris.) Like the above
4195 signals, a healthy program receives and handles them as part of
4196 its normal operation. */
4197 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4198 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4199 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4200 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4201 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4202 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4206 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4207 (char *) &stop_on_solib_events
,
4208 "Set stopping for shared library events.\n\
4209 If nonzero, gdb will give control to the user when the dynamic linker\n\
4210 notifies gdb of shared library events. The most common event of interest\n\
4211 to the user would be loading/unloading of a new library.\n", &setlist
), &showlist
);
4214 c
= add_set_enum_cmd ("follow-fork-mode",
4216 follow_fork_mode_kind_names
, &follow_fork_mode_string
,
4217 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4218 kernel problem. It's also not terribly useful without a GUI to
4219 help the user drive two debuggers. So for now, I'm disabling
4220 the "both" option. */
4221 /* "Set debugger response to a program call of fork \
4223 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4224 parent - the original process is debugged after a fork\n\
4225 child - the new process is debugged after a fork\n\
4226 both - both the parent and child are debugged after a fork\n\
4227 ask - the debugger will ask for one of the above choices\n\
4228 For \"both\", another copy of the debugger will be started to follow\n\
4229 the new child process. The original debugger will continue to follow\n\
4230 the original parent process. To distinguish their prompts, the\n\
4231 debugger copy's prompt will be changed.\n\
4232 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4233 By default, the debugger will follow the parent process.",
4235 "Set debugger response to a program call of fork \
4237 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4238 parent - the original process is debugged after a fork\n\
4239 child - the new process is debugged after a fork\n\
4240 ask - the debugger will ask for one of the above choices\n\
4241 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4242 By default, the debugger will follow the parent process.", &setlist
);
4243 add_show_from_set (c
, &showlist
);
4245 c
= add_set_enum_cmd ("scheduler-locking", class_run
, scheduler_enums
, /* array of string names */
4246 &scheduler_mode
, /* current mode */
4247 "Set mode for locking scheduler during execution.\n\
4248 off == no locking (threads may preempt at any time)\n\
4249 on == full locking (no thread except the current thread may run)\n\
4250 step == scheduler locked during every single-step operation.\n\
4251 In this mode, no other thread may run during a step command.\n\
4252 Other threads may run while stepping over a function call ('next').", &setlist
);
4254 set_cmd_sfunc (c
, set_schedlock_func
); /* traps on target vector */
4255 add_show_from_set (c
, &showlist
);
4257 c
= add_set_cmd ("step-mode", class_run
,
4258 var_boolean
, (char *) &step_stop_if_no_debug
,
4259 "Set mode of the step operation. When set, doing a step over a\n\
4260 function without debug line information will stop at the first\n\
4261 instruction of that function. Otherwise, the function is skipped and\n\
4262 the step command stops at a different source line.", &setlist
);
4263 add_show_from_set (c
, &showlist
);
4265 /* ptid initializations */
4266 null_ptid
= ptid_build (0, 0, 0);
4267 minus_one_ptid
= ptid_build (-1, 0, 0);
4268 inferior_ptid
= null_ptid
;
4269 target_last_wait_ptid
= minus_one_ptid
;