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 int follow_fork ();
71 static void set_schedlock_func (char *args
, int from_tty
,
72 struct cmd_list_element
*c
);
74 struct execution_control_state
;
76 static int currently_stepping (struct execution_control_state
*ecs
);
78 static void xdb_handle_command (char *args
, int from_tty
);
80 void _initialize_infrun (void);
82 int inferior_ignoring_startup_exec_events
= 0;
83 int inferior_ignoring_leading_exec_events
= 0;
85 /* When set, stop the 'step' command if we enter a function which has
86 no line number information. The normal behavior is that we step
87 over such function. */
88 int step_stop_if_no_debug
= 0;
90 /* In asynchronous mode, but simulating synchronous execution. */
92 int sync_execution
= 0;
94 /* wait_for_inferior and normal_stop use this to notify the user
95 when the inferior stopped in a different thread than it had been
98 static ptid_t previous_inferior_ptid
;
100 /* This is true for configurations that may follow through execl() and
101 similar functions. At present this is only true for HP-UX native. */
103 #ifndef MAY_FOLLOW_EXEC
104 #define MAY_FOLLOW_EXEC (0)
107 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
109 /* Dynamic function trampolines are similar to solib trampolines in that they
110 are between the caller and the callee. The difference is that when you
111 enter a dynamic trampoline, you can't determine the callee's address. Some
112 (usually complex) code needs to run in the dynamic trampoline to figure out
113 the callee's address. This macro is usually called twice. First, when we
114 enter the trampoline (looks like a normal function call at that point). It
115 should return the PC of a point within the trampoline where the callee's
116 address is known. Second, when we hit the breakpoint, this routine returns
117 the callee's address. At that point, things proceed as per a step resume
120 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
121 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
124 /* If the program uses ELF-style shared libraries, then calls to
125 functions in shared libraries go through stubs, which live in a
126 table called the PLT (Procedure Linkage Table). The first time the
127 function is called, the stub sends control to the dynamic linker,
128 which looks up the function's real address, patches the stub so
129 that future calls will go directly to the function, and then passes
130 control to the function.
132 If we are stepping at the source level, we don't want to see any of
133 this --- we just want to skip over the stub and the dynamic linker.
134 The simple approach is to single-step until control leaves the
137 However, on some systems (e.g., Red Hat's 5.2 distribution) the
138 dynamic linker calls functions in the shared C library, so you
139 can't tell from the PC alone whether the dynamic linker is still
140 running. In this case, we use a step-resume breakpoint to get us
141 past the dynamic linker, as if we were using "next" to step over a
144 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
145 linker code or not. Normally, this means we single-step. However,
146 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
147 address where we can place a step-resume breakpoint to get past the
148 linker's symbol resolution function.
150 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
151 pretty portable way, by comparing the PC against the address ranges
152 of the dynamic linker's sections.
154 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
155 it depends on internal details of the dynamic linker. It's usually
156 not too hard to figure out where to put a breakpoint, but it
157 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
158 sanity checking. If it can't figure things out, returning zero and
159 getting the (possibly confusing) stepping behavior is better than
160 signalling an error, which will obscure the change in the
163 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
164 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
167 #ifndef SKIP_SOLIB_RESOLVER
168 #define SKIP_SOLIB_RESOLVER(pc) 0
171 /* This function returns TRUE if pc is the address of an instruction
172 that lies within the dynamic linker (such as the event hook, or the
175 This function must be used only when a dynamic linker event has
176 been caught, and the inferior is being stepped out of the hook, or
177 undefined results are guaranteed. */
179 #ifndef SOLIB_IN_DYNAMIC_LINKER
180 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
183 /* On MIPS16, a function that returns a floating point value may call
184 a library helper function to copy the return value to a floating point
185 register. The IGNORE_HELPER_CALL macro returns non-zero if we
186 should ignore (i.e. step over) this function call. */
187 #ifndef IGNORE_HELPER_CALL
188 #define IGNORE_HELPER_CALL(pc) 0
191 /* On some systems, the PC may be left pointing at an instruction that won't
192 actually be executed. This is usually indicated by a bit in the PSW. If
193 we find ourselves in such a state, then we step the target beyond the
194 nullified instruction before returning control to the user so as to avoid
197 #ifndef INSTRUCTION_NULLIFIED
198 #define INSTRUCTION_NULLIFIED 0
201 /* We can't step off a permanent breakpoint in the ordinary way, because we
202 can't remove it. Instead, we have to advance the PC to the next
203 instruction. This macro should expand to a pointer to a function that
204 does that, or zero if we have no such function. If we don't have a
205 definition for it, we have to report an error. */
206 #ifndef SKIP_PERMANENT_BREAKPOINT
207 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
209 default_skip_permanent_breakpoint (void)
212 The program is stopped at a permanent breakpoint, but GDB does not know\n\
213 how to step past a permanent breakpoint on this architecture. Try using\n\
214 a command like `return' or `jump' to continue execution.");
219 /* Convert the #defines into values. This is temporary until wfi control
220 flow is completely sorted out. */
222 #ifndef HAVE_STEPPABLE_WATCHPOINT
223 #define HAVE_STEPPABLE_WATCHPOINT 0
225 #undef HAVE_STEPPABLE_WATCHPOINT
226 #define HAVE_STEPPABLE_WATCHPOINT 1
229 #ifndef HAVE_CONTINUABLE_WATCHPOINT
230 #define HAVE_CONTINUABLE_WATCHPOINT 0
232 #undef HAVE_CONTINUABLE_WATCHPOINT
233 #define HAVE_CONTINUABLE_WATCHPOINT 1
236 #ifndef CANNOT_STEP_HW_WATCHPOINTS
237 #define CANNOT_STEP_HW_WATCHPOINTS 0
239 #undef CANNOT_STEP_HW_WATCHPOINTS
240 #define CANNOT_STEP_HW_WATCHPOINTS 1
243 /* Tables of how to react to signals; the user sets them. */
245 static unsigned char *signal_stop
;
246 static unsigned char *signal_print
;
247 static unsigned char *signal_program
;
249 #define SET_SIGS(nsigs,sigs,flags) \
251 int signum = (nsigs); \
252 while (signum-- > 0) \
253 if ((sigs)[signum]) \
254 (flags)[signum] = 1; \
257 #define UNSET_SIGS(nsigs,sigs,flags) \
259 int signum = (nsigs); \
260 while (signum-- > 0) \
261 if ((sigs)[signum]) \
262 (flags)[signum] = 0; \
265 /* Value to pass to target_resume() to cause all threads to resume */
267 #define RESUME_ALL (pid_to_ptid (-1))
269 /* Command list pointer for the "stop" placeholder. */
271 static struct cmd_list_element
*stop_command
;
273 /* Nonzero if breakpoints are now inserted in the inferior. */
275 static int breakpoints_inserted
;
277 /* Function inferior was in as of last step command. */
279 static struct symbol
*step_start_function
;
281 /* Nonzero if we are expecting a trace trap and should proceed from it. */
283 static int trap_expected
;
286 /* Nonzero if we want to give control to the user when we're notified
287 of shared library events by the dynamic linker. */
288 static int stop_on_solib_events
;
292 /* Nonzero if the next time we try to continue the inferior, it will
293 step one instruction and generate a spurious trace trap.
294 This is used to compensate for a bug in HP-UX. */
296 static int trap_expected_after_continue
;
299 /* Nonzero means expecting a trace trap
300 and should stop the inferior and return silently when it happens. */
304 /* Nonzero means expecting a trap and caller will handle it themselves.
305 It is used after attach, due to attaching to a process;
306 when running in the shell before the child program has been exec'd;
307 and when running some kinds of remote stuff (FIXME?). */
309 int stop_soon_quietly
;
311 /* Nonzero if proceed is being used for a "finish" command or a similar
312 situation when stop_registers should be saved. */
314 int proceed_to_finish
;
316 /* Save register contents here when about to pop a stack dummy frame,
317 if-and-only-if proceed_to_finish is set.
318 Thus this contains the return value from the called function (assuming
319 values are returned in a register). */
321 struct regcache
*stop_registers
;
323 /* Nonzero if program stopped due to error trying to insert breakpoints. */
325 static int breakpoints_failed
;
327 /* Nonzero after stop if current stack frame should be printed. */
329 static int stop_print_frame
;
331 static struct breakpoint
*step_resume_breakpoint
= NULL
;
332 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
334 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
335 interactions with an inferior that is running a kernel function
336 (aka, a system call or "syscall"). wait_for_inferior therefore
337 may have a need to know when the inferior is in a syscall. This
338 is a count of the number of inferior threads which are known to
339 currently be running in a syscall. */
340 static int number_of_threads_in_syscalls
;
342 /* This is a cached copy of the pid/waitstatus of the last event
343 returned by target_wait()/target_wait_hook(). This information is
344 returned by get_last_target_status(). */
345 static ptid_t target_last_wait_ptid
;
346 static struct target_waitstatus target_last_waitstatus
;
348 /* This is used to remember when a fork, vfork or exec event
349 was caught by a catchpoint, and thus the event is to be
350 followed at the next resume of the inferior, and not
354 enum target_waitkind kind
;
361 char *execd_pathname
;
365 static const char follow_fork_mode_ask
[] = "ask";
366 static const char follow_fork_mode_child
[] = "child";
367 static const char follow_fork_mode_parent
[] = "parent";
369 static const char *follow_fork_mode_kind_names
[] = {
370 follow_fork_mode_ask
,
371 follow_fork_mode_child
,
372 follow_fork_mode_parent
,
376 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
382 const char *follow_mode
= follow_fork_mode_string
;
383 int follow_child
= (follow_mode
== follow_fork_mode_child
);
385 /* Or, did the user not know, and want us to ask? */
386 if (follow_fork_mode_string
== follow_fork_mode_ask
)
388 internal_error (__FILE__
, __LINE__
,
389 "follow_inferior_fork: \"ask\" mode not implemented");
390 /* follow_mode = follow_fork_mode_...; */
393 return target_follow_fork (follow_child
);
397 follow_inferior_reset_breakpoints (void)
399 /* Was there a step_resume breakpoint? (There was if the user
400 did a "next" at the fork() call.) If so, explicitly reset its
403 step_resumes are a form of bp that are made to be per-thread.
404 Since we created the step_resume bp when the parent process
405 was being debugged, and now are switching to the child process,
406 from the breakpoint package's viewpoint, that's a switch of
407 "threads". We must update the bp's notion of which thread
408 it is for, or it'll be ignored when it triggers. */
410 if (step_resume_breakpoint
)
411 breakpoint_re_set_thread (step_resume_breakpoint
);
413 /* Reinsert all breakpoints in the child. The user may have set
414 breakpoints after catching the fork, in which case those
415 were never set in the child, but only in the parent. This makes
416 sure the inserted breakpoints match the breakpoint list. */
418 breakpoint_re_set ();
419 insert_breakpoints ();
422 /* EXECD_PATHNAME is assumed to be non-NULL. */
425 follow_exec (int pid
, char *execd_pathname
)
428 struct target_ops
*tgt
;
430 if (!may_follow_exec
)
433 /* This is an exec event that we actually wish to pay attention to.
434 Refresh our symbol table to the newly exec'd program, remove any
437 If there are breakpoints, they aren't really inserted now,
438 since the exec() transformed our inferior into a fresh set
441 We want to preserve symbolic breakpoints on the list, since
442 we have hopes that they can be reset after the new a.out's
443 symbol table is read.
445 However, any "raw" breakpoints must be removed from the list
446 (e.g., the solib bp's), since their address is probably invalid
449 And, we DON'T want to call delete_breakpoints() here, since
450 that may write the bp's "shadow contents" (the instruction
451 value that was overwritten witha TRAP instruction). Since
452 we now have a new a.out, those shadow contents aren't valid. */
453 update_breakpoints_after_exec ();
455 /* If there was one, it's gone now. We cannot truly step-to-next
456 statement through an exec(). */
457 step_resume_breakpoint
= NULL
;
458 step_range_start
= 0;
461 /* If there was one, it's gone now. */
462 through_sigtramp_breakpoint
= NULL
;
464 /* What is this a.out's name? */
465 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
467 /* We've followed the inferior through an exec. Therefore, the
468 inferior has essentially been killed & reborn. */
470 /* First collect the run target in effect. */
471 tgt
= find_run_target ();
472 /* If we can't find one, things are in a very strange state... */
474 error ("Could find run target to save before following exec");
476 gdb_flush (gdb_stdout
);
477 target_mourn_inferior ();
478 inferior_ptid
= pid_to_ptid (saved_pid
);
479 /* Because mourn_inferior resets inferior_ptid. */
482 /* That a.out is now the one to use. */
483 exec_file_attach (execd_pathname
, 0);
485 /* And also is where symbols can be found. */
486 symbol_file_add_main (execd_pathname
, 0);
488 /* Reset the shared library package. This ensures that we get
489 a shlib event when the child reaches "_start", at which point
490 the dld will have had a chance to initialize the child. */
491 #if defined(SOLIB_RESTART)
494 #ifdef SOLIB_CREATE_INFERIOR_HOOK
495 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
498 /* Reinsert all breakpoints. (Those which were symbolic have
499 been reset to the proper address in the new a.out, thanks
500 to symbol_file_command...) */
501 insert_breakpoints ();
503 /* The next resume of this inferior should bring it to the shlib
504 startup breakpoints. (If the user had also set bp's on
505 "main" from the old (parent) process, then they'll auto-
506 matically get reset there in the new process.) */
509 /* Non-zero if we just simulating a single-step. This is needed
510 because we cannot remove the breakpoints in the inferior process
511 until after the `wait' in `wait_for_inferior'. */
512 static int singlestep_breakpoints_inserted_p
= 0;
515 /* Things to clean up if we QUIT out of resume (). */
518 resume_cleanups (void *ignore
)
523 static const char schedlock_off
[] = "off";
524 static const char schedlock_on
[] = "on";
525 static const char schedlock_step
[] = "step";
526 static const char *scheduler_mode
= schedlock_off
;
527 static const char *scheduler_enums
[] = {
535 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
537 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
538 the set command passed as a parameter. The clone operation will
539 include (BUG?) any ``set'' command callback, if present.
540 Commands like ``info set'' call all the ``show'' command
541 callbacks. Unfortunatly, for ``show'' commands cloned from
542 ``set'', this includes callbacks belonging to ``set'' commands.
543 Making this worse, this only occures if add_show_from_set() is
544 called after add_cmd_sfunc() (BUG?). */
545 if (cmd_type (c
) == set_cmd
)
546 if (!target_can_lock_scheduler
)
548 scheduler_mode
= schedlock_off
;
549 error ("Target '%s' cannot support this command.", target_shortname
);
554 /* Resume the inferior, but allow a QUIT. This is useful if the user
555 wants to interrupt some lengthy single-stepping operation
556 (for child processes, the SIGINT goes to the inferior, and so
557 we get a SIGINT random_signal, but for remote debugging and perhaps
558 other targets, that's not true).
560 STEP nonzero if we should step (zero to continue instead).
561 SIG is the signal to give the inferior (zero for none). */
563 resume (int step
, enum target_signal sig
)
565 int should_resume
= 1;
566 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
569 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
572 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
573 over an instruction that causes a page fault without triggering
574 a hardware watchpoint. The kernel properly notices that it shouldn't
575 stop, because the hardware watchpoint is not triggered, but it forgets
576 the step request and continues the program normally.
577 Work around the problem by removing hardware watchpoints if a step is
578 requested, GDB will check for a hardware watchpoint trigger after the
580 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
581 remove_hw_watchpoints ();
584 /* Normally, by the time we reach `resume', the breakpoints are either
585 removed or inserted, as appropriate. The exception is if we're sitting
586 at a permanent breakpoint; we need to step over it, but permanent
587 breakpoints can't be removed. So we have to test for it here. */
588 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
589 SKIP_PERMANENT_BREAKPOINT ();
591 if (SOFTWARE_SINGLE_STEP_P () && step
)
593 /* Do it the hard way, w/temp breakpoints */
594 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
595 /* ...and don't ask hardware to do it. */
597 /* and do not pull these breakpoints until after a `wait' in
598 `wait_for_inferior' */
599 singlestep_breakpoints_inserted_p
= 1;
602 /* Handle any optimized stores to the inferior NOW... */
603 #ifdef DO_DEFERRED_STORES
607 /* If there were any forks/vforks/execs that were caught and are
608 now to be followed, then do so. */
609 switch (pending_follow
.kind
)
611 case TARGET_WAITKIND_FORKED
:
612 case TARGET_WAITKIND_VFORKED
:
613 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
618 case TARGET_WAITKIND_EXECD
:
619 /* follow_exec is called as soon as the exec event is seen. */
620 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
627 /* Install inferior's terminal modes. */
628 target_terminal_inferior ();
634 resume_ptid
= RESUME_ALL
; /* Default */
636 if ((step
|| singlestep_breakpoints_inserted_p
) &&
637 !breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
639 /* Stepping past a breakpoint without inserting breakpoints.
640 Make sure only the current thread gets to step, so that
641 other threads don't sneak past breakpoints while they are
644 resume_ptid
= inferior_ptid
;
647 if ((scheduler_mode
== schedlock_on
) ||
648 (scheduler_mode
== schedlock_step
&&
649 (step
|| singlestep_breakpoints_inserted_p
)))
651 /* User-settable 'scheduler' mode requires solo thread resume. */
652 resume_ptid
= inferior_ptid
;
655 if (CANNOT_STEP_BREAKPOINT
)
657 /* Most targets can step a breakpoint instruction, thus
658 executing it normally. But if this one cannot, just
659 continue and we will hit it anyway. */
660 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
663 target_resume (resume_ptid
, step
, sig
);
666 discard_cleanups (old_cleanups
);
670 /* Clear out all variables saying what to do when inferior is continued.
671 First do this, then set the ones you want, then call `proceed'. */
674 clear_proceed_status (void)
677 step_range_start
= 0;
679 step_frame_id
= null_frame_id
;
680 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
682 stop_soon_quietly
= 0;
683 proceed_to_finish
= 0;
684 breakpoint_proceeded
= 1; /* We're about to proceed... */
686 /* Discard any remaining commands or status from previous stop. */
687 bpstat_clear (&stop_bpstat
);
690 /* Basic routine for continuing the program in various fashions.
692 ADDR is the address to resume at, or -1 for resume where stopped.
693 SIGGNAL is the signal to give it, or 0 for none,
694 or -1 for act according to how it stopped.
695 STEP is nonzero if should trap after one instruction.
696 -1 means return after that and print nothing.
697 You should probably set various step_... variables
698 before calling here, if you are stepping.
700 You should call clear_proceed_status before calling proceed. */
703 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
708 step_start_function
= find_pc_function (read_pc ());
712 if (addr
== (CORE_ADDR
) -1)
714 /* If there is a breakpoint at the address we will resume at,
715 step one instruction before inserting breakpoints
716 so that we do not stop right away (and report a second
717 hit at this breakpoint). */
719 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
722 #ifndef STEP_SKIPS_DELAY
723 #define STEP_SKIPS_DELAY(pc) (0)
724 #define STEP_SKIPS_DELAY_P (0)
726 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
727 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
728 is slow (it needs to read memory from the target). */
729 if (STEP_SKIPS_DELAY_P
730 && breakpoint_here_p (read_pc () + 4)
731 && STEP_SKIPS_DELAY (read_pc ()))
739 #ifdef PREPARE_TO_PROCEED
740 /* In a multi-threaded task we may select another thread
741 and then continue or step.
743 But if the old thread was stopped at a breakpoint, it
744 will immediately cause another breakpoint stop without
745 any execution (i.e. it will report a breakpoint hit
746 incorrectly). So we must step over it first.
748 PREPARE_TO_PROCEED checks the current thread against the thread
749 that reported the most recent event. If a step-over is required
750 it returns TRUE and sets the current thread to the old thread. */
751 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
756 #endif /* PREPARE_TO_PROCEED */
759 if (trap_expected_after_continue
)
761 /* If (step == 0), a trap will be automatically generated after
762 the first instruction is executed. Force step one
763 instruction to clear this condition. This should not occur
764 if step is nonzero, but it is harmless in that case. */
766 trap_expected_after_continue
= 0;
768 #endif /* HP_OS_BUG */
771 /* We will get a trace trap after one instruction.
772 Continue it automatically and insert breakpoints then. */
776 insert_breakpoints ();
777 /* If we get here there was no call to error() in
778 insert breakpoints -- so they were inserted. */
779 breakpoints_inserted
= 1;
782 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
783 stop_signal
= siggnal
;
784 /* If this signal should not be seen by program,
785 give it zero. Used for debugging signals. */
786 else if (!signal_program
[stop_signal
])
787 stop_signal
= TARGET_SIGNAL_0
;
789 annotate_starting ();
791 /* Make sure that output from GDB appears before output from the
793 gdb_flush (gdb_stdout
);
795 /* Resume inferior. */
796 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
798 /* Wait for it to stop (if not standalone)
799 and in any case decode why it stopped, and act accordingly. */
800 /* Do this only if we are not using the event loop, or if the target
801 does not support asynchronous execution. */
802 if (!event_loop_p
|| !target_can_async_p ())
804 wait_for_inferior ();
809 /* Record the pc and sp of the program the last time it stopped.
810 These are just used internally by wait_for_inferior, but need
811 to be preserved over calls to it and cleared when the inferior
813 static CORE_ADDR prev_pc
;
814 static CORE_ADDR prev_func_start
;
815 static char *prev_func_name
;
818 /* Start remote-debugging of a machine over a serial link. */
824 init_wait_for_inferior ();
825 stop_soon_quietly
= 1;
828 /* Always go on waiting for the target, regardless of the mode. */
829 /* FIXME: cagney/1999-09-23: At present it isn't possible to
830 indicate to wait_for_inferior that a target should timeout if
831 nothing is returned (instead of just blocking). Because of this,
832 targets expecting an immediate response need to, internally, set
833 things up so that the target_wait() is forced to eventually
835 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
836 differentiate to its caller what the state of the target is after
837 the initial open has been performed. Here we're assuming that
838 the target has stopped. It should be possible to eventually have
839 target_open() return to the caller an indication that the target
840 is currently running and GDB state should be set to the same as
842 wait_for_inferior ();
846 /* Initialize static vars when a new inferior begins. */
849 init_wait_for_inferior (void)
851 /* These are meaningless until the first time through wait_for_inferior. */
854 prev_func_name
= NULL
;
857 trap_expected_after_continue
= 0;
859 breakpoints_inserted
= 0;
860 breakpoint_init_inferior (inf_starting
);
862 /* Don't confuse first call to proceed(). */
863 stop_signal
= TARGET_SIGNAL_0
;
865 /* The first resume is not following a fork/vfork/exec. */
866 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
868 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
869 number_of_threads_in_syscalls
= 0;
871 clear_proceed_status ();
875 delete_breakpoint_current_contents (void *arg
)
877 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
878 if (*breakpointp
!= NULL
)
880 delete_breakpoint (*breakpointp
);
885 /* This enum encodes possible reasons for doing a target_wait, so that
886 wfi can call target_wait in one place. (Ultimately the call will be
887 moved out of the infinite loop entirely.) */
891 infwait_normal_state
,
892 infwait_thread_hop_state
,
893 infwait_nullified_state
,
894 infwait_nonstep_watch_state
897 /* Why did the inferior stop? Used to print the appropriate messages
898 to the interface from within handle_inferior_event(). */
899 enum inferior_stop_reason
901 /* We don't know why. */
903 /* Step, next, nexti, stepi finished. */
905 /* Found breakpoint. */
907 /* Inferior terminated by signal. */
909 /* Inferior exited. */
911 /* Inferior received signal, and user asked to be notified. */
915 /* This structure contains what used to be local variables in
916 wait_for_inferior. Probably many of them can return to being
917 locals in handle_inferior_event. */
919 struct execution_control_state
921 struct target_waitstatus ws
;
922 struct target_waitstatus
*wp
;
925 CORE_ADDR stop_func_start
;
926 CORE_ADDR stop_func_end
;
927 char *stop_func_name
;
928 struct symtab_and_line sal
;
929 int remove_breakpoints_on_following_step
;
931 struct symtab
*current_symtab
;
932 int handling_longjmp
; /* FIXME */
934 ptid_t saved_inferior_ptid
;
936 int stepping_through_solib_after_catch
;
937 bpstat stepping_through_solib_catchpoints
;
938 int enable_hw_watchpoints_after_wait
;
939 int stepping_through_sigtramp
;
940 int new_thread_event
;
941 struct target_waitstatus tmpstatus
;
942 enum infwait_states infwait_state
;
947 void init_execution_control_state (struct execution_control_state
*ecs
);
949 void handle_inferior_event (struct execution_control_state
*ecs
);
951 static void check_sigtramp2 (struct execution_control_state
*ecs
);
952 static void step_into_function (struct execution_control_state
*ecs
);
953 static void step_over_function (struct execution_control_state
*ecs
);
954 static void stop_stepping (struct execution_control_state
*ecs
);
955 static void prepare_to_wait (struct execution_control_state
*ecs
);
956 static void keep_going (struct execution_control_state
*ecs
);
957 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
960 /* Wait for control to return from inferior to debugger.
961 If inferior gets a signal, we may decide to start it up again
962 instead of returning. That is why there is a loop in this function.
963 When this function actually returns it means the inferior
964 should be left stopped and GDB should read more commands. */
967 wait_for_inferior (void)
969 struct cleanup
*old_cleanups
;
970 struct execution_control_state ecss
;
971 struct execution_control_state
*ecs
;
973 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
974 &step_resume_breakpoint
);
975 make_cleanup (delete_breakpoint_current_contents
,
976 &through_sigtramp_breakpoint
);
978 /* wfi still stays in a loop, so it's OK just to take the address of
979 a local to get the ecs pointer. */
982 /* Fill in with reasonable starting values. */
983 init_execution_control_state (ecs
);
985 /* We'll update this if & when we switch to a new thread. */
986 previous_inferior_ptid
= inferior_ptid
;
988 overlay_cache_invalid
= 1;
990 /* We have to invalidate the registers BEFORE calling target_wait
991 because they can be loaded from the target while in target_wait.
992 This makes remote debugging a bit more efficient for those
993 targets that provide critical registers as part of their normal
996 registers_changed ();
1000 if (target_wait_hook
)
1001 ecs
->ptid
= target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
1003 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
1005 /* Now figure out what to do with the result of the result. */
1006 handle_inferior_event (ecs
);
1008 if (!ecs
->wait_some_more
)
1011 do_cleanups (old_cleanups
);
1014 /* Asynchronous version of wait_for_inferior. It is called by the
1015 event loop whenever a change of state is detected on the file
1016 descriptor corresponding to the target. It can be called more than
1017 once to complete a single execution command. In such cases we need
1018 to keep the state in a global variable ASYNC_ECSS. If it is the
1019 last time that this function is called for a single execution
1020 command, then report to the user that the inferior has stopped, and
1021 do the necessary cleanups. */
1023 struct execution_control_state async_ecss
;
1024 struct execution_control_state
*async_ecs
;
1027 fetch_inferior_event (void *client_data
)
1029 static struct cleanup
*old_cleanups
;
1031 async_ecs
= &async_ecss
;
1033 if (!async_ecs
->wait_some_more
)
1035 old_cleanups
= make_exec_cleanup (delete_step_resume_breakpoint
,
1036 &step_resume_breakpoint
);
1037 make_exec_cleanup (delete_breakpoint_current_contents
,
1038 &through_sigtramp_breakpoint
);
1040 /* Fill in with reasonable starting values. */
1041 init_execution_control_state (async_ecs
);
1043 /* We'll update this if & when we switch to a new thread. */
1044 previous_inferior_ptid
= inferior_ptid
;
1046 overlay_cache_invalid
= 1;
1048 /* We have to invalidate the registers BEFORE calling target_wait
1049 because they can be loaded from the target while in target_wait.
1050 This makes remote debugging a bit more efficient for those
1051 targets that provide critical registers as part of their normal
1052 status mechanism. */
1054 registers_changed ();
1057 if (target_wait_hook
)
1059 target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1061 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1063 /* Now figure out what to do with the result of the result. */
1064 handle_inferior_event (async_ecs
);
1066 if (!async_ecs
->wait_some_more
)
1068 /* Do only the cleanups that have been added by this
1069 function. Let the continuations for the commands do the rest,
1070 if there are any. */
1071 do_exec_cleanups (old_cleanups
);
1073 if (step_multi
&& stop_step
)
1074 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1076 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1080 /* Prepare an execution control state for looping through a
1081 wait_for_inferior-type loop. */
1084 init_execution_control_state (struct execution_control_state
*ecs
)
1086 /* ecs->another_trap? */
1087 ecs
->random_signal
= 0;
1088 ecs
->remove_breakpoints_on_following_step
= 0;
1089 ecs
->handling_longjmp
= 0; /* FIXME */
1090 ecs
->update_step_sp
= 0;
1091 ecs
->stepping_through_solib_after_catch
= 0;
1092 ecs
->stepping_through_solib_catchpoints
= NULL
;
1093 ecs
->enable_hw_watchpoints_after_wait
= 0;
1094 ecs
->stepping_through_sigtramp
= 0;
1095 ecs
->sal
= find_pc_line (prev_pc
, 0);
1096 ecs
->current_line
= ecs
->sal
.line
;
1097 ecs
->current_symtab
= ecs
->sal
.symtab
;
1098 ecs
->infwait_state
= infwait_normal_state
;
1099 ecs
->waiton_ptid
= pid_to_ptid (-1);
1100 ecs
->wp
= &(ecs
->ws
);
1103 /* Call this function before setting step_resume_breakpoint, as a
1104 sanity check. There should never be more than one step-resume
1105 breakpoint per thread, so we should never be setting a new
1106 step_resume_breakpoint when one is already active. */
1108 check_for_old_step_resume_breakpoint (void)
1110 if (step_resume_breakpoint
)
1112 ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1115 /* Return the cached copy of the last pid/waitstatus returned by
1116 target_wait()/target_wait_hook(). The data is actually cached by
1117 handle_inferior_event(), which gets called immediately after
1118 target_wait()/target_wait_hook(). */
1121 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
1123 *ptidp
= target_last_wait_ptid
;
1124 *status
= target_last_waitstatus
;
1127 /* Switch thread contexts, maintaining "infrun state". */
1130 context_switch (struct execution_control_state
*ecs
)
1132 /* Caution: it may happen that the new thread (or the old one!)
1133 is not in the thread list. In this case we must not attempt
1134 to "switch context", or we run the risk that our context may
1135 be lost. This may happen as a result of the target module
1136 mishandling thread creation. */
1138 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1139 { /* Perform infrun state context switch: */
1140 /* Save infrun state for the old thread. */
1141 save_infrun_state (inferior_ptid
, prev_pc
,
1142 prev_func_start
, prev_func_name
,
1143 trap_expected
, step_resume_breakpoint
,
1144 through_sigtramp_breakpoint
, step_range_start
,
1145 step_range_end
, &step_frame_id
,
1146 ecs
->handling_longjmp
, ecs
->another_trap
,
1147 ecs
->stepping_through_solib_after_catch
,
1148 ecs
->stepping_through_solib_catchpoints
,
1149 ecs
->stepping_through_sigtramp
,
1150 ecs
->current_line
, ecs
->current_symtab
, step_sp
);
1152 /* Load infrun state for the new thread. */
1153 load_infrun_state (ecs
->ptid
, &prev_pc
,
1154 &prev_func_start
, &prev_func_name
,
1155 &trap_expected
, &step_resume_breakpoint
,
1156 &through_sigtramp_breakpoint
, &step_range_start
,
1157 &step_range_end
, &step_frame_id
,
1158 &ecs
->handling_longjmp
, &ecs
->another_trap
,
1159 &ecs
->stepping_through_solib_after_catch
,
1160 &ecs
->stepping_through_solib_catchpoints
,
1161 &ecs
->stepping_through_sigtramp
,
1162 &ecs
->current_line
, &ecs
->current_symtab
, &step_sp
);
1164 inferior_ptid
= ecs
->ptid
;
1168 /* Given an execution control state that has been freshly filled in
1169 by an event from the inferior, figure out what it means and take
1170 appropriate action. */
1173 handle_inferior_event (struct execution_control_state
*ecs
)
1176 int stepped_after_stopped_by_watchpoint
;
1177 int sw_single_step_trap_p
= 0;
1179 /* Cache the last pid/waitstatus. */
1180 target_last_wait_ptid
= ecs
->ptid
;
1181 target_last_waitstatus
= *ecs
->wp
;
1183 switch (ecs
->infwait_state
)
1185 case infwait_thread_hop_state
:
1186 /* Cancel the waiton_ptid. */
1187 ecs
->waiton_ptid
= pid_to_ptid (-1);
1188 /* Fall thru to the normal_state case. */
1190 case infwait_normal_state
:
1191 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1192 is serviced in this loop, below. */
1193 if (ecs
->enable_hw_watchpoints_after_wait
)
1195 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1196 ecs
->enable_hw_watchpoints_after_wait
= 0;
1198 stepped_after_stopped_by_watchpoint
= 0;
1201 case infwait_nullified_state
:
1204 case infwait_nonstep_watch_state
:
1205 insert_breakpoints ();
1207 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1208 handle things like signals arriving and other things happening
1209 in combination correctly? */
1210 stepped_after_stopped_by_watchpoint
= 1;
1213 ecs
->infwait_state
= infwait_normal_state
;
1215 flush_cached_frames ();
1217 /* If it's a new process, add it to the thread database */
1219 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
1220 && !in_thread_list (ecs
->ptid
));
1222 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1223 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
1225 add_thread (ecs
->ptid
);
1227 ui_out_text (uiout
, "[New ");
1228 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->ptid
));
1229 ui_out_text (uiout
, "]\n");
1232 /* NOTE: This block is ONLY meant to be invoked in case of a
1233 "thread creation event"! If it is invoked for any other
1234 sort of event (such as a new thread landing on a breakpoint),
1235 the event will be discarded, which is almost certainly
1238 To avoid this, the low-level module (eg. target_wait)
1239 should call in_thread_list and add_thread, so that the
1240 new thread is known by the time we get here. */
1242 /* We may want to consider not doing a resume here in order
1243 to give the user a chance to play with the new thread.
1244 It might be good to make that a user-settable option. */
1246 /* At this point, all threads are stopped (happens
1247 automatically in either the OS or the native code).
1248 Therefore we need to continue all threads in order to
1251 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1252 prepare_to_wait (ecs
);
1257 switch (ecs
->ws
.kind
)
1259 case TARGET_WAITKIND_LOADED
:
1260 /* Ignore gracefully during startup of the inferior, as it
1261 might be the shell which has just loaded some objects,
1262 otherwise add the symbols for the newly loaded objects. */
1264 if (!stop_soon_quietly
)
1266 /* Remove breakpoints, SOLIB_ADD might adjust
1267 breakpoint addresses via breakpoint_re_set. */
1268 if (breakpoints_inserted
)
1269 remove_breakpoints ();
1271 /* Check for any newly added shared libraries if we're
1272 supposed to be adding them automatically. Switch
1273 terminal for any messages produced by
1274 breakpoint_re_set. */
1275 target_terminal_ours_for_output ();
1276 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
1277 target_terminal_inferior ();
1279 /* Reinsert breakpoints and continue. */
1280 if (breakpoints_inserted
)
1281 insert_breakpoints ();
1284 resume (0, TARGET_SIGNAL_0
);
1285 prepare_to_wait (ecs
);
1288 case TARGET_WAITKIND_SPURIOUS
:
1289 resume (0, TARGET_SIGNAL_0
);
1290 prepare_to_wait (ecs
);
1293 case TARGET_WAITKIND_EXITED
:
1294 target_terminal_ours (); /* Must do this before mourn anyway */
1295 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1297 /* Record the exit code in the convenience variable $_exitcode, so
1298 that the user can inspect this again later. */
1299 set_internalvar (lookup_internalvar ("_exitcode"),
1300 value_from_longest (builtin_type_int
,
1301 (LONGEST
) ecs
->ws
.value
.integer
));
1302 gdb_flush (gdb_stdout
);
1303 target_mourn_inferior ();
1304 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1305 stop_print_frame
= 0;
1306 stop_stepping (ecs
);
1309 case TARGET_WAITKIND_SIGNALLED
:
1310 stop_print_frame
= 0;
1311 stop_signal
= ecs
->ws
.value
.sig
;
1312 target_terminal_ours (); /* Must do this before mourn anyway */
1314 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1315 reach here unless the inferior is dead. However, for years
1316 target_kill() was called here, which hints that fatal signals aren't
1317 really fatal on some systems. If that's true, then some changes
1319 target_mourn_inferior ();
1321 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1322 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1323 stop_stepping (ecs
);
1326 /* The following are the only cases in which we keep going;
1327 the above cases end in a continue or goto. */
1328 case TARGET_WAITKIND_FORKED
:
1329 stop_signal
= TARGET_SIGNAL_TRAP
;
1330 pending_follow
.kind
= ecs
->ws
.kind
;
1332 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1333 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1335 stop_pc
= read_pc_pid (ecs
->ptid
);
1336 ecs
->saved_inferior_ptid
= inferior_ptid
;
1337 inferior_ptid
= ecs
->ptid
;
1339 /* Assume that catchpoints are not really software breakpoints. If
1340 some future target implements them using software breakpoints then
1341 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1342 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1343 bpstat_stop_status will not decrement the PC. */
1345 stop_bpstat
= bpstat_stop_status (&stop_pc
, 1);
1347 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1348 inferior_ptid
= ecs
->saved_inferior_ptid
;
1349 goto process_event_stop_test
;
1351 /* If this a platform which doesn't allow a debugger to touch a
1352 vfork'd inferior until after it exec's, then we'd best keep
1353 our fingers entirely off the inferior, other than continuing
1354 it. This has the unfortunate side-effect that catchpoints
1355 of vforks will be ignored. But since the platform doesn't
1356 allow the inferior be touched at vfork time, there's really
1358 case TARGET_WAITKIND_VFORKED
:
1359 stop_signal
= TARGET_SIGNAL_TRAP
;
1360 pending_follow
.kind
= ecs
->ws
.kind
;
1362 /* Is this a vfork of the parent? If so, then give any
1363 vfork catchpoints a chance to trigger now. (It's
1364 dangerous to do so if the child canot be touched until
1365 it execs, and the child has not yet exec'd. We probably
1366 should warn the user to that effect when the catchpoint
1368 if (ptid_equal (ecs
->ptid
, inferior_ptid
))
1370 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1371 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1374 /* If we've seen the child's vfork event but cannot really touch
1375 the child until it execs, then we must continue the child now.
1376 Else, give any vfork catchpoints a chance to trigger now. */
1379 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1380 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1381 target_post_startup_inferior (pid_to_ptid
1382 (pending_follow
.fork_event
.
1386 stop_pc
= read_pc ();
1388 /* Assume that catchpoints are not really software breakpoints. If
1389 some future target implements them using software breakpoints then
1390 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1391 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1392 bpstat_stop_status will not decrement the PC. */
1394 stop_bpstat
= bpstat_stop_status (&stop_pc
, 1);
1396 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1397 goto process_event_stop_test
;
1399 case TARGET_WAITKIND_EXECD
:
1400 stop_signal
= TARGET_SIGNAL_TRAP
;
1402 /* NOTE drow/2002-12-05: This code should be pushed down into the
1403 target_wait function. Until then following vfork on HP/UX 10.20
1404 is probably broken by this. Of course, it's broken anyway. */
1405 /* Is this a target which reports multiple exec events per actual
1406 call to exec()? (HP-UX using ptrace does, for example.) If so,
1407 ignore all but the last one. Just resume the exec'r, and wait
1408 for the next exec event. */
1409 if (inferior_ignoring_leading_exec_events
)
1411 inferior_ignoring_leading_exec_events
--;
1412 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1413 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.
1415 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1416 prepare_to_wait (ecs
);
1419 inferior_ignoring_leading_exec_events
=
1420 target_reported_exec_events_per_exec_call () - 1;
1422 pending_follow
.execd_pathname
=
1423 savestring (ecs
->ws
.value
.execd_pathname
,
1424 strlen (ecs
->ws
.value
.execd_pathname
));
1426 /* This causes the eventpoints and symbol table to be reset. Must
1427 do this now, before trying to determine whether to stop. */
1428 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1429 xfree (pending_follow
.execd_pathname
);
1431 stop_pc
= read_pc_pid (ecs
->ptid
);
1432 ecs
->saved_inferior_ptid
= inferior_ptid
;
1433 inferior_ptid
= ecs
->ptid
;
1435 /* Assume that catchpoints are not really software breakpoints. If
1436 some future target implements them using software breakpoints then
1437 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1438 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1439 bpstat_stop_status will not decrement the PC. */
1441 stop_bpstat
= bpstat_stop_status (&stop_pc
, 1);
1443 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1444 inferior_ptid
= ecs
->saved_inferior_ptid
;
1445 goto process_event_stop_test
;
1447 /* These syscall events are returned on HP-UX, as part of its
1448 implementation of page-protection-based "hardware" watchpoints.
1449 HP-UX has unfortunate interactions between page-protections and
1450 some system calls. Our solution is to disable hardware watches
1451 when a system call is entered, and reenable them when the syscall
1452 completes. The downside of this is that we may miss the precise
1453 point at which a watched piece of memory is modified. "Oh well."
1455 Note that we may have multiple threads running, which may each
1456 enter syscalls at roughly the same time. Since we don't have a
1457 good notion currently of whether a watched piece of memory is
1458 thread-private, we'd best not have any page-protections active
1459 when any thread is in a syscall. Thus, we only want to reenable
1460 hardware watches when no threads are in a syscall.
1462 Also, be careful not to try to gather much state about a thread
1463 that's in a syscall. It's frequently a losing proposition. */
1464 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1465 number_of_threads_in_syscalls
++;
1466 if (number_of_threads_in_syscalls
== 1)
1468 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1470 resume (0, TARGET_SIGNAL_0
);
1471 prepare_to_wait (ecs
);
1474 /* Before examining the threads further, step this thread to
1475 get it entirely out of the syscall. (We get notice of the
1476 event when the thread is just on the verge of exiting a
1477 syscall. Stepping one instruction seems to get it back
1480 Note that although the logical place to reenable h/w watches
1481 is here, we cannot. We cannot reenable them before stepping
1482 the thread (this causes the next wait on the thread to hang).
1484 Nor can we enable them after stepping until we've done a wait.
1485 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1486 here, which will be serviced immediately after the target
1488 case TARGET_WAITKIND_SYSCALL_RETURN
:
1489 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1491 if (number_of_threads_in_syscalls
> 0)
1493 number_of_threads_in_syscalls
--;
1494 ecs
->enable_hw_watchpoints_after_wait
=
1495 (number_of_threads_in_syscalls
== 0);
1497 prepare_to_wait (ecs
);
1500 case TARGET_WAITKIND_STOPPED
:
1501 stop_signal
= ecs
->ws
.value
.sig
;
1504 /* We had an event in the inferior, but we are not interested
1505 in handling it at this level. The lower layers have already
1506 done what needs to be done, if anything.
1508 One of the possible circumstances for this is when the
1509 inferior produces output for the console. The inferior has
1510 not stopped, and we are ignoring the event. Another possible
1511 circumstance is any event which the lower level knows will be
1512 reported multiple times without an intervening resume. */
1513 case TARGET_WAITKIND_IGNORE
:
1514 prepare_to_wait (ecs
);
1518 /* We may want to consider not doing a resume here in order to give
1519 the user a chance to play with the new thread. It might be good
1520 to make that a user-settable option. */
1522 /* At this point, all threads are stopped (happens automatically in
1523 either the OS or the native code). Therefore we need to continue
1524 all threads in order to make progress. */
1525 if (ecs
->new_thread_event
)
1527 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1528 prepare_to_wait (ecs
);
1532 stop_pc
= read_pc_pid (ecs
->ptid
);
1534 /* See if a thread hit a thread-specific breakpoint that was meant for
1535 another thread. If so, then step that thread past the breakpoint,
1538 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1540 /* Check if a regular breakpoint has been hit before checking
1541 for a potential single step breakpoint. Otherwise, GDB will
1542 not see this breakpoint hit when stepping onto breakpoints. */
1543 if (breakpoints_inserted
1544 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1546 ecs
->random_signal
= 0;
1547 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1552 /* Saw a breakpoint, but it was hit by the wrong thread.
1554 if (DECR_PC_AFTER_BREAK
)
1555 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->ptid
);
1557 remove_status
= remove_breakpoints ();
1558 /* Did we fail to remove breakpoints? If so, try
1559 to set the PC past the bp. (There's at least
1560 one situation in which we can fail to remove
1561 the bp's: On HP-UX's that use ttrace, we can't
1562 change the address space of a vforking child
1563 process until the child exits (well, okay, not
1564 then either :-) or execs. */
1565 if (remove_status
!= 0)
1567 /* FIXME! This is obviously non-portable! */
1568 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->ptid
);
1569 /* We need to restart all the threads now,
1570 * unles we're running in scheduler-locked mode.
1571 * Use currently_stepping to determine whether to
1574 /* FIXME MVS: is there any reason not to call resume()? */
1575 if (scheduler_mode
== schedlock_on
)
1576 target_resume (ecs
->ptid
,
1577 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1579 target_resume (RESUME_ALL
,
1580 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1581 prepare_to_wait (ecs
);
1586 breakpoints_inserted
= 0;
1587 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
1588 context_switch (ecs
);
1589 ecs
->waiton_ptid
= ecs
->ptid
;
1590 ecs
->wp
= &(ecs
->ws
);
1591 ecs
->another_trap
= 1;
1593 ecs
->infwait_state
= infwait_thread_hop_state
;
1595 registers_changed ();
1600 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1602 /* Readjust the stop_pc as it is off by DECR_PC_AFTER_BREAK
1603 compared to the value it would have if the system stepping
1604 capability was used. This allows the rest of the code in
1605 this function to use this address without having to worry
1606 whether software single step is in use or not. */
1607 if (DECR_PC_AFTER_BREAK
)
1609 stop_pc
-= DECR_PC_AFTER_BREAK
;
1610 write_pc_pid (stop_pc
, ecs
->ptid
);
1613 sw_single_step_trap_p
= 1;
1614 ecs
->random_signal
= 0;
1618 ecs
->random_signal
= 1;
1620 /* See if something interesting happened to the non-current thread. If
1621 so, then switch to that thread, and eventually give control back to
1624 Note that if there's any kind of pending follow (i.e., of a fork,
1625 vfork or exec), we don't want to do this now. Rather, we'll let
1626 the next resume handle it. */
1627 if (!ptid_equal (ecs
->ptid
, inferior_ptid
) &&
1628 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1632 /* If it's a random signal for a non-current thread, notify user
1633 if he's expressed an interest. */
1634 if (ecs
->random_signal
&& signal_print
[stop_signal
])
1636 /* ??rehrauer: I don't understand the rationale for this code. If the
1637 inferior will stop as a result of this signal, then the act of handling
1638 the stop ought to print a message that's couches the stoppage in user
1639 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1640 won't stop as a result of the signal -- i.e., if the signal is merely
1641 a side-effect of something GDB's doing "under the covers" for the
1642 user, such as stepping threads over a breakpoint they shouldn't stop
1643 for -- then the message seems to be a serious annoyance at best.
1645 For now, remove the message altogether. */
1648 target_terminal_ours_for_output ();
1649 printf_filtered ("\nProgram received signal %s, %s.\n",
1650 target_signal_to_name (stop_signal
),
1651 target_signal_to_string (stop_signal
));
1652 gdb_flush (gdb_stdout
);
1656 /* If it's not SIGTRAP and not a signal we want to stop for, then
1657 continue the thread. */
1659 if (stop_signal
!= TARGET_SIGNAL_TRAP
&& !signal_stop
[stop_signal
])
1662 target_terminal_inferior ();
1664 /* Clear the signal if it should not be passed. */
1665 if (signal_program
[stop_signal
] == 0)
1666 stop_signal
= TARGET_SIGNAL_0
;
1668 target_resume (ecs
->ptid
, 0, stop_signal
);
1669 prepare_to_wait (ecs
);
1673 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1674 and fall into the rest of wait_for_inferior(). */
1676 context_switch (ecs
);
1679 context_hook (pid_to_thread_id (ecs
->ptid
));
1681 flush_cached_frames ();
1684 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1686 /* Pull the single step breakpoints out of the target. */
1687 SOFTWARE_SINGLE_STEP (0, 0);
1688 singlestep_breakpoints_inserted_p
= 0;
1691 /* If PC is pointing at a nullified instruction, then step beyond
1692 it so that the user won't be confused when GDB appears to be ready
1695 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1696 if (INSTRUCTION_NULLIFIED
)
1698 registers_changed ();
1699 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1701 /* We may have received a signal that we want to pass to
1702 the inferior; therefore, we must not clobber the waitstatus
1705 ecs
->infwait_state
= infwait_nullified_state
;
1706 ecs
->waiton_ptid
= ecs
->ptid
;
1707 ecs
->wp
= &(ecs
->tmpstatus
);
1708 prepare_to_wait (ecs
);
1712 /* It may not be necessary to disable the watchpoint to stop over
1713 it. For example, the PA can (with some kernel cooperation)
1714 single step over a watchpoint without disabling the watchpoint. */
1715 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1718 prepare_to_wait (ecs
);
1722 /* It is far more common to need to disable a watchpoint to step
1723 the inferior over it. FIXME. What else might a debug
1724 register or page protection watchpoint scheme need here? */
1725 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1727 /* At this point, we are stopped at an instruction which has
1728 attempted to write to a piece of memory under control of
1729 a watchpoint. The instruction hasn't actually executed
1730 yet. If we were to evaluate the watchpoint expression
1731 now, we would get the old value, and therefore no change
1732 would seem to have occurred.
1734 In order to make watchpoints work `right', we really need
1735 to complete the memory write, and then evaluate the
1736 watchpoint expression. The following code does that by
1737 removing the watchpoint (actually, all watchpoints and
1738 breakpoints), single-stepping the target, re-inserting
1739 watchpoints, and then falling through to let normal
1740 single-step processing handle proceed. Since this
1741 includes evaluating watchpoints, things will come to a
1742 stop in the correct manner. */
1744 if (DECR_PC_AFTER_BREAK
)
1745 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
1747 remove_breakpoints ();
1748 registers_changed ();
1749 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
1751 ecs
->waiton_ptid
= ecs
->ptid
;
1752 ecs
->wp
= &(ecs
->ws
);
1753 ecs
->infwait_state
= infwait_nonstep_watch_state
;
1754 prepare_to_wait (ecs
);
1758 /* It may be possible to simply continue after a watchpoint. */
1759 if (HAVE_CONTINUABLE_WATCHPOINT
)
1760 STOPPED_BY_WATCHPOINT (ecs
->ws
);
1762 ecs
->stop_func_start
= 0;
1763 ecs
->stop_func_end
= 0;
1764 ecs
->stop_func_name
= 0;
1765 /* Don't care about return value; stop_func_start and stop_func_name
1766 will both be 0 if it doesn't work. */
1767 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
1768 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
1769 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
1770 ecs
->another_trap
= 0;
1771 bpstat_clear (&stop_bpstat
);
1773 stop_stack_dummy
= 0;
1774 stop_print_frame
= 1;
1775 ecs
->random_signal
= 0;
1776 stopped_by_random_signal
= 0;
1777 breakpoints_failed
= 0;
1779 /* Look at the cause of the stop, and decide what to do.
1780 The alternatives are:
1781 1) break; to really stop and return to the debugger,
1782 2) drop through to start up again
1783 (set ecs->another_trap to 1 to single step once)
1784 3) set ecs->random_signal to 1, and the decision between 1 and 2
1785 will be made according to the signal handling tables. */
1787 /* First, distinguish signals caused by the debugger from signals
1788 that have to do with the program's own actions.
1789 Note that breakpoint insns may cause SIGTRAP or SIGILL
1790 or SIGEMT, depending on the operating system version.
1791 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1792 and change it to SIGTRAP. */
1794 if (stop_signal
== TARGET_SIGNAL_TRAP
1795 || (breakpoints_inserted
&&
1796 (stop_signal
== TARGET_SIGNAL_ILL
1797 || stop_signal
== TARGET_SIGNAL_EMT
)) || stop_soon_quietly
)
1799 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
1801 stop_print_frame
= 0;
1802 stop_stepping (ecs
);
1805 if (stop_soon_quietly
)
1807 stop_stepping (ecs
);
1811 /* Don't even think about breakpoints
1812 if just proceeded over a breakpoint.
1814 However, if we are trying to proceed over a breakpoint
1815 and end up in sigtramp, then through_sigtramp_breakpoint
1816 will be set and we should check whether we've hit the
1818 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
1819 && through_sigtramp_breakpoint
== NULL
)
1820 bpstat_clear (&stop_bpstat
);
1823 /* See if there is a breakpoint at the current PC. */
1825 /* The second argument of bpstat_stop_status is meant to help
1826 distinguish between a breakpoint trap and a singlestep trap.
1827 This is only important on targets where DECR_PC_AFTER_BREAK
1828 is non-zero. The prev_pc test is meant to distinguish between
1829 singlestepping a trap instruction, and singlestepping thru a
1830 jump to the instruction following a trap instruction.
1832 Therefore, pass TRUE if our reason for stopping is
1833 something other than hitting a breakpoint. We do this by
1834 checking that either: we detected earlier a software single
1835 step trap or, 1) stepping is going on and 2) we didn't hit
1836 a breakpoint in a signal handler without an intervening stop
1837 in sigtramp, which is detected by a new stack pointer value
1838 below any usual function calling stack adjustments. */
1842 sw_single_step_trap_p
1843 || (currently_stepping (ecs
)
1844 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1846 && INNER_THAN (read_sp (), (step_sp
- 16)))));
1847 /* Following in case break condition called a
1849 stop_print_frame
= 1;
1852 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1854 = !(bpstat_explains_signal (stop_bpstat
)
1856 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
1857 && DEPRECATED_PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
1858 get_frame_base (get_current_frame ())))
1859 || (step_range_end
&& step_resume_breakpoint
== NULL
));
1863 ecs
->random_signal
= !(bpstat_explains_signal (stop_bpstat
)
1864 /* End of a stack dummy. Some systems (e.g. Sony
1865 news) give another signal besides SIGTRAP, so
1866 check here as well as above. */
1867 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
1868 && DEPRECATED_PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
1872 if (!ecs
->random_signal
)
1873 stop_signal
= TARGET_SIGNAL_TRAP
;
1877 /* When we reach this point, we've pretty much decided
1878 that the reason for stopping must've been a random
1879 (unexpected) signal. */
1882 ecs
->random_signal
= 1;
1883 /* If a fork, vfork or exec event was seen, then there are two
1884 possible responses we can make:
1886 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
1887 then we must stop now and issue a prompt. We will resume
1888 the inferior when the user tells us to.
1889 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
1890 then we must resume the inferior now and keep checking.
1892 In either case, we must take appropriate steps to "follow" the
1893 the fork/vfork/exec when the inferior is resumed. For example,
1894 if follow-fork-mode is "child", then we must detach from the
1895 parent inferior and follow the new child inferior.
1897 In either case, setting pending_follow causes the next resume()
1898 to take the appropriate following action. */
1899 process_event_stop_test
:
1900 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
1902 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
1905 stop_signal
= TARGET_SIGNAL_0
;
1910 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
1912 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
1914 stop_signal
= TARGET_SIGNAL_0
;
1919 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
1921 pending_follow
.kind
= ecs
->ws
.kind
;
1922 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
1925 stop_signal
= TARGET_SIGNAL_0
;
1931 /* For the program's own signals, act according to
1932 the signal handling tables. */
1934 if (ecs
->random_signal
)
1936 /* Signal not for debugging purposes. */
1939 stopped_by_random_signal
= 1;
1941 if (signal_print
[stop_signal
])
1944 target_terminal_ours_for_output ();
1945 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
1947 if (signal_stop
[stop_signal
])
1949 stop_stepping (ecs
);
1952 /* If not going to stop, give terminal back
1953 if we took it away. */
1955 target_terminal_inferior ();
1957 /* Clear the signal if it should not be passed. */
1958 if (signal_program
[stop_signal
] == 0)
1959 stop_signal
= TARGET_SIGNAL_0
;
1961 /* I'm not sure whether this needs to be check_sigtramp2 or
1962 whether it could/should be keep_going.
1964 This used to jump to step_over_function if we are stepping,
1967 Suppose the user does a `next' over a function call, and while
1968 that call is in progress, the inferior receives a signal for
1969 which GDB does not stop (i.e., signal_stop[SIG] is false). In
1970 that case, when we reach this point, there is already a
1971 step-resume breakpoint established, right where it should be:
1972 immediately after the function call the user is "next"-ing
1973 over. If we call step_over_function now, two bad things
1976 - we'll create a new breakpoint, at wherever the current
1977 frame's return address happens to be. That could be
1978 anywhere, depending on what function call happens to be on
1979 the top of the stack at that point. Point is, it's probably
1980 not where we need it.
1982 - the existing step-resume breakpoint (which is at the correct
1983 address) will get orphaned: step_resume_breakpoint will point
1984 to the new breakpoint, and the old step-resume breakpoint
1985 will never be cleaned up.
1987 The old behavior was meant to help HP-UX single-step out of
1988 sigtramps. It would place the new breakpoint at prev_pc, which
1989 was certainly wrong. I don't know the details there, so fixing
1990 this probably breaks that. As with anything else, it's up to
1991 the HP-UX maintainer to furnish a fix that doesn't break other
1992 platforms. --JimB, 20 May 1999 */
1993 check_sigtramp2 (ecs
);
1998 /* Handle cases caused by hitting a breakpoint. */
2000 CORE_ADDR jmp_buf_pc
;
2001 struct bpstat_what what
;
2003 what
= bpstat_what (stop_bpstat
);
2005 if (what
.call_dummy
)
2007 stop_stack_dummy
= 1;
2009 trap_expected_after_continue
= 1;
2013 switch (what
.main_action
)
2015 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2016 /* If we hit the breakpoint at longjmp, disable it for the
2017 duration of this command. Then, install a temporary
2018 breakpoint at the target of the jmp_buf. */
2019 disable_longjmp_breakpoint ();
2020 remove_breakpoints ();
2021 breakpoints_inserted
= 0;
2022 if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc
))
2028 /* Need to blow away step-resume breakpoint, as it
2029 interferes with us */
2030 if (step_resume_breakpoint
!= NULL
)
2032 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2034 /* Not sure whether we need to blow this away too, but probably
2035 it is like the step-resume breakpoint. */
2036 if (through_sigtramp_breakpoint
!= NULL
)
2038 delete_breakpoint (through_sigtramp_breakpoint
);
2039 through_sigtramp_breakpoint
= NULL
;
2043 /* FIXME - Need to implement nested temporary breakpoints */
2044 if (step_over_calls
> 0)
2045 set_longjmp_resume_breakpoint (jmp_buf_pc
, get_current_frame ());
2048 set_longjmp_resume_breakpoint (jmp_buf_pc
, null_frame_id
);
2049 ecs
->handling_longjmp
= 1; /* FIXME */
2053 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2054 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2055 remove_breakpoints ();
2056 breakpoints_inserted
= 0;
2058 /* FIXME - Need to implement nested temporary breakpoints */
2060 && (frame_id_inner (get_frame_id (get_current_frame ()),
2063 ecs
->another_trap
= 1;
2068 disable_longjmp_breakpoint ();
2069 ecs
->handling_longjmp
= 0; /* FIXME */
2070 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2072 /* else fallthrough */
2074 case BPSTAT_WHAT_SINGLE
:
2075 if (breakpoints_inserted
)
2077 remove_breakpoints ();
2079 breakpoints_inserted
= 0;
2080 ecs
->another_trap
= 1;
2081 /* Still need to check other stuff, at least the case
2082 where we are stepping and step out of the right range. */
2085 case BPSTAT_WHAT_STOP_NOISY
:
2086 stop_print_frame
= 1;
2088 /* We are about to nuke the step_resume_breakpoint and
2089 through_sigtramp_breakpoint via the cleanup chain, so
2090 no need to worry about it here. */
2092 stop_stepping (ecs
);
2095 case BPSTAT_WHAT_STOP_SILENT
:
2096 stop_print_frame
= 0;
2098 /* We are about to nuke the step_resume_breakpoint and
2099 through_sigtramp_breakpoint via the cleanup chain, so
2100 no need to worry about it here. */
2102 stop_stepping (ecs
);
2105 case BPSTAT_WHAT_STEP_RESUME
:
2106 /* This proably demands a more elegant solution, but, yeah
2109 This function's use of the simple variable
2110 step_resume_breakpoint doesn't seem to accomodate
2111 simultaneously active step-resume bp's, although the
2112 breakpoint list certainly can.
2114 If we reach here and step_resume_breakpoint is already
2115 NULL, then apparently we have multiple active
2116 step-resume bp's. We'll just delete the breakpoint we
2117 stopped at, and carry on.
2119 Correction: what the code currently does is delete a
2120 step-resume bp, but it makes no effort to ensure that
2121 the one deleted is the one currently stopped at. MVS */
2123 if (step_resume_breakpoint
== NULL
)
2125 step_resume_breakpoint
=
2126 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2128 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2131 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2132 if (through_sigtramp_breakpoint
)
2133 delete_breakpoint (through_sigtramp_breakpoint
);
2134 through_sigtramp_breakpoint
= NULL
;
2136 /* If were waiting for a trap, hitting the step_resume_break
2137 doesn't count as getting it. */
2139 ecs
->another_trap
= 1;
2142 case BPSTAT_WHAT_CHECK_SHLIBS
:
2143 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2146 /* Remove breakpoints, we eventually want to step over the
2147 shlib event breakpoint, and SOLIB_ADD might adjust
2148 breakpoint addresses via breakpoint_re_set. */
2149 if (breakpoints_inserted
)
2150 remove_breakpoints ();
2151 breakpoints_inserted
= 0;
2153 /* Check for any newly added shared libraries if we're
2154 supposed to be adding them automatically. Switch
2155 terminal for any messages produced by
2156 breakpoint_re_set. */
2157 target_terminal_ours_for_output ();
2158 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
2159 target_terminal_inferior ();
2161 /* Try to reenable shared library breakpoints, additional
2162 code segments in shared libraries might be mapped in now. */
2163 re_enable_breakpoints_in_shlibs ();
2165 /* If requested, stop when the dynamic linker notifies
2166 gdb of events. This allows the user to get control
2167 and place breakpoints in initializer routines for
2168 dynamically loaded objects (among other things). */
2169 if (stop_on_solib_events
)
2171 stop_stepping (ecs
);
2175 /* If we stopped due to an explicit catchpoint, then the
2176 (see above) call to SOLIB_ADD pulled in any symbols
2177 from a newly-loaded library, if appropriate.
2179 We do want the inferior to stop, but not where it is
2180 now, which is in the dynamic linker callback. Rather,
2181 we would like it stop in the user's program, just after
2182 the call that caused this catchpoint to trigger. That
2183 gives the user a more useful vantage from which to
2184 examine their program's state. */
2185 else if (what
.main_action
==
2186 BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2188 /* ??rehrauer: If I could figure out how to get the
2189 right return PC from here, we could just set a temp
2190 breakpoint and resume. I'm not sure we can without
2191 cracking open the dld's shared libraries and sniffing
2192 their unwind tables and text/data ranges, and that's
2193 not a terribly portable notion.
2195 Until that time, we must step the inferior out of the
2196 dld callback, and also out of the dld itself (and any
2197 code or stubs in libdld.sl, such as "shl_load" and
2198 friends) until we reach non-dld code. At that point,
2199 we can stop stepping. */
2200 bpstat_get_triggered_catchpoints (stop_bpstat
,
2202 stepping_through_solib_catchpoints
);
2203 ecs
->stepping_through_solib_after_catch
= 1;
2205 /* Be sure to lift all breakpoints, so the inferior does
2206 actually step past this point... */
2207 ecs
->another_trap
= 1;
2212 /* We want to step over this breakpoint, then keep going. */
2213 ecs
->another_trap
= 1;
2220 case BPSTAT_WHAT_LAST
:
2221 /* Not a real code, but listed here to shut up gcc -Wall. */
2223 case BPSTAT_WHAT_KEEP_CHECKING
:
2228 /* We come here if we hit a breakpoint but should not
2229 stop for it. Possibly we also were stepping
2230 and should stop for that. So fall through and
2231 test for stepping. But, if not stepping,
2234 /* Are we stepping to get the inferior out of the dynamic
2235 linker's hook (and possibly the dld itself) after catching
2237 if (ecs
->stepping_through_solib_after_catch
)
2239 #if defined(SOLIB_ADD)
2240 /* Have we reached our destination? If not, keep going. */
2241 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2243 ecs
->another_trap
= 1;
2248 /* Else, stop and report the catchpoint(s) whose triggering
2249 caused us to begin stepping. */
2250 ecs
->stepping_through_solib_after_catch
= 0;
2251 bpstat_clear (&stop_bpstat
);
2252 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2253 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2254 stop_print_frame
= 1;
2255 stop_stepping (ecs
);
2259 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2261 /* This is the old way of detecting the end of the stack dummy.
2262 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2263 handled above. As soon as we can test it on all of them, all
2264 architectures should define it. */
2266 /* If this is the breakpoint at the end of a stack dummy,
2267 just stop silently, unless the user was doing an si/ni, in which
2268 case she'd better know what she's doing. */
2270 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2271 get_frame_base (get_current_frame ()))
2274 stop_print_frame
= 0;
2275 stop_stack_dummy
= 1;
2277 trap_expected_after_continue
= 1;
2279 stop_stepping (ecs
);
2284 if (step_resume_breakpoint
)
2286 /* Having a step-resume breakpoint overrides anything
2287 else having to do with stepping commands until
2288 that breakpoint is reached. */
2289 /* I'm not sure whether this needs to be check_sigtramp2 or
2290 whether it could/should be keep_going. */
2291 check_sigtramp2 (ecs
);
2296 if (step_range_end
== 0)
2298 /* Likewise if we aren't even stepping. */
2299 /* I'm not sure whether this needs to be check_sigtramp2 or
2300 whether it could/should be keep_going. */
2301 check_sigtramp2 (ecs
);
2306 /* If stepping through a line, keep going if still within it.
2308 Note that step_range_end is the address of the first instruction
2309 beyond the step range, and NOT the address of the last instruction
2311 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
2313 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2314 So definately need to check for sigtramp here. */
2315 check_sigtramp2 (ecs
);
2320 /* We stepped out of the stepping range. */
2322 /* If we are stepping at the source level and entered the runtime
2323 loader dynamic symbol resolution code, we keep on single stepping
2324 until we exit the run time loader code and reach the callee's
2326 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2327 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2329 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2331 if (pc_after_resolver
)
2333 /* Set up a step-resume breakpoint at the address
2334 indicated by SKIP_SOLIB_RESOLVER. */
2335 struct symtab_and_line sr_sal
;
2337 sr_sal
.pc
= pc_after_resolver
;
2339 check_for_old_step_resume_breakpoint ();
2340 step_resume_breakpoint
=
2341 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2342 if (breakpoints_inserted
)
2343 insert_breakpoints ();
2350 /* We can't update step_sp every time through the loop, because
2351 reading the stack pointer would slow down stepping too much.
2352 But we can update it every time we leave the step range. */
2353 ecs
->update_step_sp
= 1;
2355 /* Did we just take a signal? */
2356 if (PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2357 && !PC_IN_SIGTRAMP (prev_pc
, prev_func_name
)
2358 && INNER_THAN (read_sp (), step_sp
))
2360 /* We've just taken a signal; go until we are back to
2361 the point where we took it and one more. */
2363 /* Note: The test above succeeds not only when we stepped
2364 into a signal handler, but also when we step past the last
2365 statement of a signal handler and end up in the return stub
2366 of the signal handler trampoline. To distinguish between
2367 these two cases, check that the frame is INNER_THAN the
2368 previous one below. pai/1997-09-11 */
2372 struct frame_id current_frame
= get_frame_id (get_current_frame ());
2374 if (frame_id_inner (current_frame
, step_frame_id
))
2376 /* We have just taken a signal; go until we are back to
2377 the point where we took it and one more. */
2379 /* This code is needed at least in the following case:
2380 The user types "next" and then a signal arrives (before
2381 the "next" is done). */
2383 /* Note that if we are stopped at a breakpoint, then we need
2384 the step_resume breakpoint to override any breakpoints at
2385 the same location, so that we will still step over the
2386 breakpoint even though the signal happened. */
2387 struct symtab_and_line sr_sal
;
2390 sr_sal
.symtab
= NULL
;
2392 sr_sal
.pc
= prev_pc
;
2393 /* We could probably be setting the frame to
2394 step_frame_id; I don't think anyone thought to try it. */
2395 check_for_old_step_resume_breakpoint ();
2396 step_resume_breakpoint
=
2397 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2398 if (breakpoints_inserted
)
2399 insert_breakpoints ();
2403 /* We just stepped out of a signal handler and into
2404 its calling trampoline.
2406 Normally, we'd call step_over_function from
2407 here, but for some reason GDB can't unwind the
2408 stack correctly to find the real PC for the point
2409 user code where the signal trampoline will return
2410 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2411 But signal trampolines are pretty small stubs of
2412 code, anyway, so it's OK instead to just
2413 single-step out. Note: assuming such trampolines
2414 don't exhibit recursion on any platform... */
2415 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2416 &ecs
->stop_func_start
,
2417 &ecs
->stop_func_end
);
2418 /* Readjust stepping range */
2419 step_range_start
= ecs
->stop_func_start
;
2420 step_range_end
= ecs
->stop_func_end
;
2421 ecs
->stepping_through_sigtramp
= 1;
2426 /* If this is stepi or nexti, make sure that the stepping range
2427 gets us past that instruction. */
2428 if (step_range_end
== 1)
2429 /* FIXME: Does this run afoul of the code below which, if
2430 we step into the middle of a line, resets the stepping
2432 step_range_end
= (step_range_start
= prev_pc
) + 1;
2434 ecs
->remove_breakpoints_on_following_step
= 1;
2439 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2440 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2441 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2442 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2443 || ecs
->stop_func_name
== 0)
2445 /* It's a subroutine call. */
2447 if ((step_over_calls
== STEP_OVER_NONE
)
2448 || ((step_range_end
== 1)
2449 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2451 /* I presume that step_over_calls is only 0 when we're
2452 supposed to be stepping at the assembly language level
2453 ("stepi"). Just stop. */
2454 /* Also, maybe we just did a "nexti" inside a prolog,
2455 so we thought it was a subroutine call but it was not.
2456 Stop as well. FENN */
2458 print_stop_reason (END_STEPPING_RANGE
, 0);
2459 stop_stepping (ecs
);
2463 if (step_over_calls
== STEP_OVER_ALL
|| IGNORE_HELPER_CALL (stop_pc
))
2465 /* We're doing a "next". */
2467 if (PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2468 && frame_id_inner (step_frame_id
,
2469 frame_id_build (read_sp (), 0)))
2470 /* We stepped out of a signal handler, and into its
2471 calling trampoline. This is misdetected as a
2472 subroutine call, but stepping over the signal
2473 trampoline isn't such a bad idea. In order to do that,
2474 we have to ignore the value in step_frame_id, since
2475 that doesn't represent the frame that'll reach when we
2476 return from the signal trampoline. Otherwise we'll
2477 probably continue to the end of the program. */
2478 step_frame_id
= null_frame_id
;
2480 step_over_function (ecs
);
2485 /* If we are in a function call trampoline (a stub between
2486 the calling routine and the real function), locate the real
2487 function. That's what tells us (a) whether we want to step
2488 into it at all, and (b) what prologue we want to run to
2489 the end of, if we do step into it. */
2490 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2492 ecs
->stop_func_start
= tmp
;
2495 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2498 struct symtab_and_line xxx
;
2499 /* Why isn't this s_a_l called "sr_sal", like all of the
2500 other s_a_l's where this code is duplicated? */
2501 init_sal (&xxx
); /* initialize to zeroes */
2503 xxx
.section
= find_pc_overlay (xxx
.pc
);
2504 check_for_old_step_resume_breakpoint ();
2505 step_resume_breakpoint
=
2506 set_momentary_breakpoint (xxx
, null_frame_id
, bp_step_resume
);
2507 insert_breakpoints ();
2513 /* If we have line number information for the function we
2514 are thinking of stepping into, step into it.
2516 If there are several symtabs at that PC (e.g. with include
2517 files), just want to know whether *any* of them have line
2518 numbers. find_pc_line handles this. */
2520 struct symtab_and_line tmp_sal
;
2522 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2523 if (tmp_sal
.line
!= 0)
2525 step_into_function (ecs
);
2530 /* If we have no line number and the step-stop-if-no-debug
2531 is set, we stop the step so that the user has a chance to
2532 switch in assembly mode. */
2533 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2536 print_stop_reason (END_STEPPING_RANGE
, 0);
2537 stop_stepping (ecs
);
2541 step_over_function (ecs
);
2547 /* We've wandered out of the step range. */
2549 ecs
->sal
= find_pc_line (stop_pc
, 0);
2551 if (step_range_end
== 1)
2553 /* It is stepi or nexti. We always want to stop stepping after
2556 print_stop_reason (END_STEPPING_RANGE
, 0);
2557 stop_stepping (ecs
);
2561 /* If we're in the return path from a shared library trampoline,
2562 we want to proceed through the trampoline when stepping. */
2563 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2567 /* Determine where this trampoline returns. */
2568 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2570 /* Only proceed through if we know where it's going. */
2573 /* And put the step-breakpoint there and go until there. */
2574 struct symtab_and_line sr_sal
;
2576 init_sal (&sr_sal
); /* initialize to zeroes */
2578 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2579 /* Do not specify what the fp should be when we stop
2580 since on some machines the prologue
2581 is where the new fp value is established. */
2582 check_for_old_step_resume_breakpoint ();
2583 step_resume_breakpoint
=
2584 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2585 if (breakpoints_inserted
)
2586 insert_breakpoints ();
2588 /* Restart without fiddling with the step ranges or
2595 if (ecs
->sal
.line
== 0)
2597 /* We have no line number information. That means to stop
2598 stepping (does this always happen right after one instruction,
2599 when we do "s" in a function with no line numbers,
2600 or can this happen as a result of a return or longjmp?). */
2602 print_stop_reason (END_STEPPING_RANGE
, 0);
2603 stop_stepping (ecs
);
2607 if ((stop_pc
== ecs
->sal
.pc
)
2608 && (ecs
->current_line
!= ecs
->sal
.line
2609 || ecs
->current_symtab
!= ecs
->sal
.symtab
))
2611 /* We are at the start of a different line. So stop. Note that
2612 we don't stop if we step into the middle of a different line.
2613 That is said to make things like for (;;) statements work
2616 print_stop_reason (END_STEPPING_RANGE
, 0);
2617 stop_stepping (ecs
);
2621 /* We aren't done stepping.
2623 Optimize by setting the stepping range to the line.
2624 (We might not be in the original line, but if we entered a
2625 new line in mid-statement, we continue stepping. This makes
2626 things like for(;;) statements work better.) */
2628 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2630 /* If this is the last line of the function, don't keep stepping
2631 (it would probably step us out of the function).
2632 This is particularly necessary for a one-line function,
2633 in which after skipping the prologue we better stop even though
2634 we will be in mid-line. */
2636 print_stop_reason (END_STEPPING_RANGE
, 0);
2637 stop_stepping (ecs
);
2640 step_range_start
= ecs
->sal
.pc
;
2641 step_range_end
= ecs
->sal
.end
;
2642 step_frame_id
= get_frame_id (get_current_frame ());
2643 ecs
->current_line
= ecs
->sal
.line
;
2644 ecs
->current_symtab
= ecs
->sal
.symtab
;
2646 /* In the case where we just stepped out of a function into the
2647 middle of a line of the caller, continue stepping, but
2648 step_frame_id must be modified to current frame */
2650 struct frame_id current_frame
= get_frame_id (get_current_frame ());
2651 if (!(frame_id_inner (current_frame
, step_frame_id
)))
2652 step_frame_id
= current_frame
;
2658 /* Are we in the middle of stepping? */
2661 currently_stepping (struct execution_control_state
*ecs
)
2663 return ((through_sigtramp_breakpoint
== NULL
2664 && !ecs
->handling_longjmp
2665 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2667 || ecs
->stepping_through_solib_after_catch
2668 || bpstat_should_step ());
2672 check_sigtramp2 (struct execution_control_state
*ecs
)
2675 && PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2676 && !PC_IN_SIGTRAMP (prev_pc
, prev_func_name
)
2677 && INNER_THAN (read_sp (), step_sp
))
2679 /* What has happened here is that we have just stepped the
2680 inferior with a signal (because it is a signal which
2681 shouldn't make us stop), thus stepping into sigtramp.
2683 So we need to set a step_resume_break_address breakpoint and
2684 continue until we hit it, and then step. FIXME: This should
2685 be more enduring than a step_resume breakpoint; we should
2686 know that we will later need to keep going rather than
2687 re-hitting the breakpoint here (see the testsuite,
2688 gdb.base/signals.exp where it says "exceedingly difficult"). */
2690 struct symtab_and_line sr_sal
;
2692 init_sal (&sr_sal
); /* initialize to zeroes */
2693 sr_sal
.pc
= prev_pc
;
2694 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2695 /* We perhaps could set the frame if we kept track of what the
2696 frame corresponding to prev_pc was. But we don't, so don't. */
2697 through_sigtramp_breakpoint
=
2698 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_through_sigtramp
);
2699 if (breakpoints_inserted
)
2700 insert_breakpoints ();
2702 ecs
->remove_breakpoints_on_following_step
= 1;
2703 ecs
->another_trap
= 1;
2707 /* Subroutine call with source code we should not step over. Do step
2708 to the first line of code in it. */
2711 step_into_function (struct execution_control_state
*ecs
)
2714 struct symtab_and_line sr_sal
;
2716 s
= find_pc_symtab (stop_pc
);
2717 if (s
&& s
->language
!= language_asm
)
2718 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2720 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2721 /* Use the step_resume_break to step until the end of the prologue,
2722 even if that involves jumps (as it seems to on the vax under
2724 /* If the prologue ends in the middle of a source line, continue to
2725 the end of that source line (if it is still within the function).
2726 Otherwise, just go to end of prologue. */
2727 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2728 /* no, don't either. It skips any code that's legitimately on the
2732 && ecs
->sal
.pc
!= ecs
->stop_func_start
2733 && ecs
->sal
.end
< ecs
->stop_func_end
)
2734 ecs
->stop_func_start
= ecs
->sal
.end
;
2737 if (ecs
->stop_func_start
== stop_pc
)
2739 /* We are already there: stop now. */
2741 print_stop_reason (END_STEPPING_RANGE
, 0);
2742 stop_stepping (ecs
);
2747 /* Put the step-breakpoint there and go until there. */
2748 init_sal (&sr_sal
); /* initialize to zeroes */
2749 sr_sal
.pc
= ecs
->stop_func_start
;
2750 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
2751 /* Do not specify what the fp should be when we stop since on
2752 some machines the prologue is where the new fp value is
2754 check_for_old_step_resume_breakpoint ();
2755 step_resume_breakpoint
=
2756 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2757 if (breakpoints_inserted
)
2758 insert_breakpoints ();
2760 /* And make sure stepping stops right away then. */
2761 step_range_end
= step_range_start
;
2766 /* We've just entered a callee, and we wish to resume until it returns
2767 to the caller. Setting a step_resume breakpoint on the return
2768 address will catch a return from the callee.
2770 However, if the callee is recursing, we want to be careful not to
2771 catch returns of those recursive calls, but only of THIS instance
2774 To do this, we set the step_resume bp's frame to our current
2775 caller's frame (step_frame_id, which is set by the "next" or
2776 "until" command, before execution begins). */
2779 step_over_function (struct execution_control_state
*ecs
)
2781 struct symtab_and_line sr_sal
;
2783 init_sal (&sr_sal
); /* initialize to zeros */
2784 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2785 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2787 check_for_old_step_resume_breakpoint ();
2788 step_resume_breakpoint
=
2789 set_momentary_breakpoint (sr_sal
, get_frame_id (get_current_frame ()),
2792 if (frame_id_p (step_frame_id
)
2793 && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
2794 step_resume_breakpoint
->frame_id
= step_frame_id
;
2796 if (breakpoints_inserted
)
2797 insert_breakpoints ();
2801 stop_stepping (struct execution_control_state
*ecs
)
2803 if (target_has_execution
)
2805 /* Assuming the inferior still exists, set these up for next
2806 time, just like we did above if we didn't break out of the
2808 prev_pc
= read_pc ();
2809 prev_func_start
= ecs
->stop_func_start
;
2810 prev_func_name
= ecs
->stop_func_name
;
2813 /* Let callers know we don't want to wait for the inferior anymore. */
2814 ecs
->wait_some_more
= 0;
2817 /* This function handles various cases where we need to continue
2818 waiting for the inferior. */
2819 /* (Used to be the keep_going: label in the old wait_for_inferior) */
2822 keep_going (struct execution_control_state
*ecs
)
2824 /* Save the pc before execution, to compare with pc after stop. */
2825 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
2826 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
2827 BREAK is defined, the
2828 original pc would not have
2829 been at the start of a
2831 prev_func_name
= ecs
->stop_func_name
;
2833 if (ecs
->update_step_sp
)
2834 step_sp
= read_sp ();
2835 ecs
->update_step_sp
= 0;
2837 /* If we did not do break;, it means we should keep running the
2838 inferior and not return to debugger. */
2840 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
2842 /* We took a signal (which we are supposed to pass through to
2843 the inferior, else we'd have done a break above) and we
2844 haven't yet gotten our trap. Simply continue. */
2845 resume (currently_stepping (ecs
), stop_signal
);
2849 /* Either the trap was not expected, but we are continuing
2850 anyway (the user asked that this signal be passed to the
2853 The signal was SIGTRAP, e.g. it was our signal, but we
2854 decided we should resume from it.
2856 We're going to run this baby now!
2858 Insert breakpoints now, unless we are trying to one-proceed
2859 past a breakpoint. */
2860 /* If we've just finished a special step resume and we don't
2861 want to hit a breakpoint, pull em out. */
2862 if (step_resume_breakpoint
== NULL
2863 && through_sigtramp_breakpoint
== NULL
2864 && ecs
->remove_breakpoints_on_following_step
)
2866 ecs
->remove_breakpoints_on_following_step
= 0;
2867 remove_breakpoints ();
2868 breakpoints_inserted
= 0;
2870 else if (!breakpoints_inserted
&&
2871 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
2873 breakpoints_failed
= insert_breakpoints ();
2874 if (breakpoints_failed
)
2876 stop_stepping (ecs
);
2879 breakpoints_inserted
= 1;
2882 trap_expected
= ecs
->another_trap
;
2884 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
2885 specifies that such a signal should be delivered to the
2888 Typically, this would occure when a user is debugging a
2889 target monitor on a simulator: the target monitor sets a
2890 breakpoint; the simulator encounters this break-point and
2891 halts the simulation handing control to GDB; GDB, noteing
2892 that the break-point isn't valid, returns control back to the
2893 simulator; the simulator then delivers the hardware
2894 equivalent of a SIGNAL_TRAP to the program being debugged. */
2896 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !signal_program
[stop_signal
])
2897 stop_signal
= TARGET_SIGNAL_0
;
2899 #ifdef SHIFT_INST_REGS
2900 /* I'm not sure when this following segment applies. I do know,
2901 now, that we shouldn't rewrite the regs when we were stopped
2902 by a random signal from the inferior process. */
2903 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2904 (this is only used on the 88k). */
2906 if (!bpstat_explains_signal (stop_bpstat
)
2907 && (stop_signal
!= TARGET_SIGNAL_CHLD
) && !stopped_by_random_signal
)
2909 #endif /* SHIFT_INST_REGS */
2911 resume (currently_stepping (ecs
), stop_signal
);
2914 prepare_to_wait (ecs
);
2917 /* This function normally comes after a resume, before
2918 handle_inferior_event exits. It takes care of any last bits of
2919 housekeeping, and sets the all-important wait_some_more flag. */
2922 prepare_to_wait (struct execution_control_state
*ecs
)
2924 if (ecs
->infwait_state
== infwait_normal_state
)
2926 overlay_cache_invalid
= 1;
2928 /* We have to invalidate the registers BEFORE calling
2929 target_wait because they can be loaded from the target while
2930 in target_wait. This makes remote debugging a bit more
2931 efficient for those targets that provide critical registers
2932 as part of their normal status mechanism. */
2934 registers_changed ();
2935 ecs
->waiton_ptid
= pid_to_ptid (-1);
2936 ecs
->wp
= &(ecs
->ws
);
2938 /* This is the old end of the while loop. Let everybody know we
2939 want to wait for the inferior some more and get called again
2941 ecs
->wait_some_more
= 1;
2944 /* Print why the inferior has stopped. We always print something when
2945 the inferior exits, or receives a signal. The rest of the cases are
2946 dealt with later on in normal_stop() and print_it_typical(). Ideally
2947 there should be a call to this function from handle_inferior_event()
2948 each time stop_stepping() is called.*/
2950 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
2952 switch (stop_reason
)
2955 /* We don't deal with these cases from handle_inferior_event()
2958 case END_STEPPING_RANGE
:
2959 /* We are done with a step/next/si/ni command. */
2960 /* For now print nothing. */
2961 /* Print a message only if not in the middle of doing a "step n"
2962 operation for n > 1 */
2963 if (!step_multi
|| !stop_step
)
2964 if (ui_out_is_mi_like_p (uiout
))
2965 ui_out_field_string (uiout
, "reason", "end-stepping-range");
2967 case BREAKPOINT_HIT
:
2968 /* We found a breakpoint. */
2969 /* For now print nothing. */
2972 /* The inferior was terminated by a signal. */
2973 annotate_signalled ();
2974 if (ui_out_is_mi_like_p (uiout
))
2975 ui_out_field_string (uiout
, "reason", "exited-signalled");
2976 ui_out_text (uiout
, "\nProgram terminated with signal ");
2977 annotate_signal_name ();
2978 ui_out_field_string (uiout
, "signal-name",
2979 target_signal_to_name (stop_info
));
2980 annotate_signal_name_end ();
2981 ui_out_text (uiout
, ", ");
2982 annotate_signal_string ();
2983 ui_out_field_string (uiout
, "signal-meaning",
2984 target_signal_to_string (stop_info
));
2985 annotate_signal_string_end ();
2986 ui_out_text (uiout
, ".\n");
2987 ui_out_text (uiout
, "The program no longer exists.\n");
2990 /* The inferior program is finished. */
2991 annotate_exited (stop_info
);
2994 if (ui_out_is_mi_like_p (uiout
))
2995 ui_out_field_string (uiout
, "reason", "exited");
2996 ui_out_text (uiout
, "\nProgram exited with code ");
2997 ui_out_field_fmt (uiout
, "exit-code", "0%o",
2998 (unsigned int) stop_info
);
2999 ui_out_text (uiout
, ".\n");
3003 if (ui_out_is_mi_like_p (uiout
))
3004 ui_out_field_string (uiout
, "reason", "exited-normally");
3005 ui_out_text (uiout
, "\nProgram exited normally.\n");
3008 case SIGNAL_RECEIVED
:
3009 /* Signal received. The signal table tells us to print about
3012 ui_out_text (uiout
, "\nProgram received signal ");
3013 annotate_signal_name ();
3014 if (ui_out_is_mi_like_p (uiout
))
3015 ui_out_field_string (uiout
, "reason", "signal-received");
3016 ui_out_field_string (uiout
, "signal-name",
3017 target_signal_to_name (stop_info
));
3018 annotate_signal_name_end ();
3019 ui_out_text (uiout
, ", ");
3020 annotate_signal_string ();
3021 ui_out_field_string (uiout
, "signal-meaning",
3022 target_signal_to_string (stop_info
));
3023 annotate_signal_string_end ();
3024 ui_out_text (uiout
, ".\n");
3027 internal_error (__FILE__
, __LINE__
,
3028 "print_stop_reason: unrecognized enum value");
3034 /* Here to return control to GDB when the inferior stops for real.
3035 Print appropriate messages, remove breakpoints, give terminal our modes.
3037 STOP_PRINT_FRAME nonzero means print the executing frame
3038 (pc, function, args, file, line number and line text).
3039 BREAKPOINTS_FAILED nonzero means stop was due to error
3040 attempting to insert breakpoints. */
3045 /* As with the notification of thread events, we want to delay
3046 notifying the user that we've switched thread context until
3047 the inferior actually stops.
3049 (Note that there's no point in saying anything if the inferior
3051 if (!ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3052 && target_has_execution
)
3054 target_terminal_ours_for_output ();
3055 printf_filtered ("[Switching to %s]\n",
3056 target_pid_or_tid_to_str (inferior_ptid
));
3057 previous_inferior_ptid
= inferior_ptid
;
3060 /* Make sure that the current_frame's pc is correct. This
3061 is a correction for setting up the frame info before doing
3062 DECR_PC_AFTER_BREAK */
3063 if (target_has_execution
)
3064 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3065 DECR_PC_AFTER_BREAK, the program counter can change. Ask the
3066 frame code to check for this and sort out any resultant mess.
3067 DECR_PC_AFTER_BREAK needs to just go away. */
3068 deprecated_update_current_frame_pc_hack (read_pc ());
3070 if (target_has_execution
&& breakpoints_inserted
)
3072 if (remove_breakpoints ())
3074 target_terminal_ours_for_output ();
3075 printf_filtered ("Cannot remove breakpoints because ");
3076 printf_filtered ("program is no longer writable.\n");
3077 printf_filtered ("It might be running in another process.\n");
3078 printf_filtered ("Further execution is probably impossible.\n");
3081 breakpoints_inserted
= 0;
3083 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3084 Delete any breakpoint that is to be deleted at the next stop. */
3086 breakpoint_auto_delete (stop_bpstat
);
3088 /* If an auto-display called a function and that got a signal,
3089 delete that auto-display to avoid an infinite recursion. */
3091 if (stopped_by_random_signal
)
3092 disable_current_display ();
3094 /* Don't print a message if in the middle of doing a "step n"
3095 operation for n > 1 */
3096 if (step_multi
&& stop_step
)
3099 target_terminal_ours ();
3101 /* Look up the hook_stop and run it (CLI internally handles problem
3102 of stop_command's pre-hook not existing). */
3104 catch_errors (hook_stop_stub
, stop_command
,
3105 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3107 if (!target_has_stack
)
3113 /* Select innermost stack frame - i.e., current frame is frame 0,
3114 and current location is based on that.
3115 Don't do this on return from a stack dummy routine,
3116 or if the program has exited. */
3118 if (!stop_stack_dummy
)
3120 select_frame (get_current_frame ());
3122 /* Print current location without a level number, if
3123 we have changed functions or hit a breakpoint.
3124 Print source line if we have one.
3125 bpstat_print() contains the logic deciding in detail
3126 what to print, based on the event(s) that just occurred. */
3128 if (stop_print_frame
&& deprecated_selected_frame
)
3132 int do_frame_printing
= 1;
3134 bpstat_ret
= bpstat_print (stop_bpstat
);
3138 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3139 (or should) carry around the function and does (or
3140 should) use that when doing a frame comparison. */
3142 && frame_id_eq (step_frame_id
,
3143 get_frame_id (get_current_frame ()))
3144 && step_start_function
== find_pc_function (stop_pc
))
3145 source_flag
= SRC_LINE
; /* finished step, just print source line */
3147 source_flag
= SRC_AND_LOC
; /* print location and source line */
3149 case PRINT_SRC_AND_LOC
:
3150 source_flag
= SRC_AND_LOC
; /* print location and source line */
3152 case PRINT_SRC_ONLY
:
3153 source_flag
= SRC_LINE
;
3156 source_flag
= SRC_LINE
; /* something bogus */
3157 do_frame_printing
= 0;
3160 internal_error (__FILE__
, __LINE__
, "Unknown value.");
3162 /* For mi, have the same behavior every time we stop:
3163 print everything but the source line. */
3164 if (ui_out_is_mi_like_p (uiout
))
3165 source_flag
= LOC_AND_ADDRESS
;
3167 if (ui_out_is_mi_like_p (uiout
))
3168 ui_out_field_int (uiout
, "thread-id",
3169 pid_to_thread_id (inferior_ptid
));
3170 /* The behavior of this routine with respect to the source
3172 SRC_LINE: Print only source line
3173 LOCATION: Print only location
3174 SRC_AND_LOC: Print location and source line */
3175 if (do_frame_printing
)
3176 show_and_print_stack_frame (deprecated_selected_frame
, -1, source_flag
);
3178 /* Display the auto-display expressions. */
3183 /* Save the function value return registers, if we care.
3184 We might be about to restore their previous contents. */
3185 if (proceed_to_finish
)
3186 /* NB: The copy goes through to the target picking up the value of
3187 all the registers. */
3188 regcache_cpy (stop_registers
, current_regcache
);
3190 if (stop_stack_dummy
)
3192 /* Pop the empty frame that contains the stack dummy.
3193 POP_FRAME ends with a setting of the current frame, so we
3194 can use that next. */
3196 /* Set stop_pc to what it was before we called the function.
3197 Can't rely on restore_inferior_status because that only gets
3198 called if we don't stop in the called function. */
3199 stop_pc
= read_pc ();
3200 select_frame (get_current_frame ());
3204 annotate_stopped ();
3208 hook_stop_stub (void *cmd
)
3210 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3215 signal_stop_state (int signo
)
3217 return signal_stop
[signo
];
3221 signal_print_state (int signo
)
3223 return signal_print
[signo
];
3227 signal_pass_state (int signo
)
3229 return signal_program
[signo
];
3233 signal_stop_update (int signo
, int state
)
3235 int ret
= signal_stop
[signo
];
3236 signal_stop
[signo
] = state
;
3241 signal_print_update (int signo
, int state
)
3243 int ret
= signal_print
[signo
];
3244 signal_print
[signo
] = state
;
3249 signal_pass_update (int signo
, int state
)
3251 int ret
= signal_program
[signo
];
3252 signal_program
[signo
] = state
;
3257 sig_print_header (void)
3260 Signal Stop\tPrint\tPass to program\tDescription\n");
3264 sig_print_info (enum target_signal oursig
)
3266 char *name
= target_signal_to_name (oursig
);
3267 int name_padding
= 13 - strlen (name
);
3269 if (name_padding
<= 0)
3272 printf_filtered ("%s", name
);
3273 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
3274 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3275 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3276 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3277 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3280 /* Specify how various signals in the inferior should be handled. */
3283 handle_command (char *args
, int from_tty
)
3286 int digits
, wordlen
;
3287 int sigfirst
, signum
, siglast
;
3288 enum target_signal oursig
;
3291 unsigned char *sigs
;
3292 struct cleanup
*old_chain
;
3296 error_no_arg ("signal to handle");
3299 /* Allocate and zero an array of flags for which signals to handle. */
3301 nsigs
= (int) TARGET_SIGNAL_LAST
;
3302 sigs
= (unsigned char *) alloca (nsigs
);
3303 memset (sigs
, 0, nsigs
);
3305 /* Break the command line up into args. */
3307 argv
= buildargv (args
);
3312 old_chain
= make_cleanup_freeargv (argv
);
3314 /* Walk through the args, looking for signal oursigs, signal names, and
3315 actions. Signal numbers and signal names may be interspersed with
3316 actions, with the actions being performed for all signals cumulatively
3317 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3319 while (*argv
!= NULL
)
3321 wordlen
= strlen (*argv
);
3322 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3326 sigfirst
= siglast
= -1;
3328 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3330 /* Apply action to all signals except those used by the
3331 debugger. Silently skip those. */
3334 siglast
= nsigs
- 1;
3336 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3338 SET_SIGS (nsigs
, sigs
, signal_stop
);
3339 SET_SIGS (nsigs
, sigs
, signal_print
);
3341 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3343 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3345 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3347 SET_SIGS (nsigs
, sigs
, signal_print
);
3349 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3351 SET_SIGS (nsigs
, sigs
, signal_program
);
3353 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3355 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3357 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3359 SET_SIGS (nsigs
, sigs
, signal_program
);
3361 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3363 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3364 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3366 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3368 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3370 else if (digits
> 0)
3372 /* It is numeric. The numeric signal refers to our own
3373 internal signal numbering from target.h, not to host/target
3374 signal number. This is a feature; users really should be
3375 using symbolic names anyway, and the common ones like
3376 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3378 sigfirst
= siglast
= (int)
3379 target_signal_from_command (atoi (*argv
));
3380 if ((*argv
)[digits
] == '-')
3383 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3385 if (sigfirst
> siglast
)
3387 /* Bet he didn't figure we'd think of this case... */
3395 oursig
= target_signal_from_name (*argv
);
3396 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3398 sigfirst
= siglast
= (int) oursig
;
3402 /* Not a number and not a recognized flag word => complain. */
3403 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3407 /* If any signal numbers or symbol names were found, set flags for
3408 which signals to apply actions to. */
3410 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3412 switch ((enum target_signal
) signum
)
3414 case TARGET_SIGNAL_TRAP
:
3415 case TARGET_SIGNAL_INT
:
3416 if (!allsigs
&& !sigs
[signum
])
3418 if (query ("%s is used by the debugger.\n\
3419 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
3425 printf_unfiltered ("Not confirmed, unchanged.\n");
3426 gdb_flush (gdb_stdout
);
3430 case TARGET_SIGNAL_0
:
3431 case TARGET_SIGNAL_DEFAULT
:
3432 case TARGET_SIGNAL_UNKNOWN
:
3433 /* Make sure that "all" doesn't print these. */
3444 target_notice_signals (inferior_ptid
);
3448 /* Show the results. */
3449 sig_print_header ();
3450 for (signum
= 0; signum
< nsigs
; signum
++)
3454 sig_print_info (signum
);
3459 do_cleanups (old_chain
);
3463 xdb_handle_command (char *args
, int from_tty
)
3466 struct cleanup
*old_chain
;
3468 /* Break the command line up into args. */
3470 argv
= buildargv (args
);
3475 old_chain
= make_cleanup_freeargv (argv
);
3476 if (argv
[1] != (char *) NULL
)
3481 bufLen
= strlen (argv
[0]) + 20;
3482 argBuf
= (char *) xmalloc (bufLen
);
3486 enum target_signal oursig
;
3488 oursig
= target_signal_from_name (argv
[0]);
3489 memset (argBuf
, 0, bufLen
);
3490 if (strcmp (argv
[1], "Q") == 0)
3491 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3494 if (strcmp (argv
[1], "s") == 0)
3496 if (!signal_stop
[oursig
])
3497 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3499 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3501 else if (strcmp (argv
[1], "i") == 0)
3503 if (!signal_program
[oursig
])
3504 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3506 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3508 else if (strcmp (argv
[1], "r") == 0)
3510 if (!signal_print
[oursig
])
3511 sprintf (argBuf
, "%s %s", argv
[0], "print");
3513 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3519 handle_command (argBuf
, from_tty
);
3521 printf_filtered ("Invalid signal handling flag.\n");
3526 do_cleanups (old_chain
);
3529 /* Print current contents of the tables set by the handle command.
3530 It is possible we should just be printing signals actually used
3531 by the current target (but for things to work right when switching
3532 targets, all signals should be in the signal tables). */
3535 signals_info (char *signum_exp
, int from_tty
)
3537 enum target_signal oursig
;
3538 sig_print_header ();
3542 /* First see if this is a symbol name. */
3543 oursig
= target_signal_from_name (signum_exp
);
3544 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3546 /* No, try numeric. */
3548 target_signal_from_command (parse_and_eval_long (signum_exp
));
3550 sig_print_info (oursig
);
3554 printf_filtered ("\n");
3555 /* These ugly casts brought to you by the native VAX compiler. */
3556 for (oursig
= TARGET_SIGNAL_FIRST
;
3557 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3558 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3562 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3563 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
3564 sig_print_info (oursig
);
3567 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3570 struct inferior_status
3572 enum target_signal stop_signal
;
3576 int stop_stack_dummy
;
3577 int stopped_by_random_signal
;
3579 CORE_ADDR step_range_start
;
3580 CORE_ADDR step_range_end
;
3581 struct frame_id step_frame_id
;
3582 enum step_over_calls_kind step_over_calls
;
3583 CORE_ADDR step_resume_break_address
;
3584 int stop_after_trap
;
3585 int stop_soon_quietly
;
3586 struct regcache
*stop_registers
;
3588 /* These are here because if call_function_by_hand has written some
3589 registers and then decides to call error(), we better not have changed
3591 struct regcache
*registers
;
3593 /* A frame unique identifier. */
3594 struct frame_id selected_frame_id
;
3596 int breakpoint_proceeded
;
3597 int restore_stack_info
;
3598 int proceed_to_finish
;
3602 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3605 int size
= REGISTER_RAW_SIZE (regno
);
3606 void *buf
= alloca (size
);
3607 store_signed_integer (buf
, size
, val
);
3608 regcache_raw_write (inf_status
->registers
, regno
, buf
);
3611 /* Save all of the information associated with the inferior<==>gdb
3612 connection. INF_STATUS is a pointer to a "struct inferior_status"
3613 (defined in inferior.h). */
3615 struct inferior_status
*
3616 save_inferior_status (int restore_stack_info
)
3618 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
3620 inf_status
->stop_signal
= stop_signal
;
3621 inf_status
->stop_pc
= stop_pc
;
3622 inf_status
->stop_step
= stop_step
;
3623 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3624 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3625 inf_status
->trap_expected
= trap_expected
;
3626 inf_status
->step_range_start
= step_range_start
;
3627 inf_status
->step_range_end
= step_range_end
;
3628 inf_status
->step_frame_id
= step_frame_id
;
3629 inf_status
->step_over_calls
= step_over_calls
;
3630 inf_status
->stop_after_trap
= stop_after_trap
;
3631 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3632 /* Save original bpstat chain here; replace it with copy of chain.
3633 If caller's caller is walking the chain, they'll be happier if we
3634 hand them back the original chain when restore_inferior_status is
3636 inf_status
->stop_bpstat
= stop_bpstat
;
3637 stop_bpstat
= bpstat_copy (stop_bpstat
);
3638 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3639 inf_status
->restore_stack_info
= restore_stack_info
;
3640 inf_status
->proceed_to_finish
= proceed_to_finish
;
3642 inf_status
->stop_registers
= regcache_dup_no_passthrough (stop_registers
);
3644 inf_status
->registers
= regcache_dup (current_regcache
);
3646 inf_status
->selected_frame_id
= get_frame_id (deprecated_selected_frame
);
3651 restore_selected_frame (void *args
)
3653 struct frame_id
*fid
= (struct frame_id
*) args
;
3654 struct frame_info
*frame
;
3656 frame
= frame_find_by_id (*fid
);
3658 /* If inf_status->selected_frame_id is NULL, there was no previously
3662 warning ("Unable to restore previously selected frame.\n");
3666 select_frame (frame
);
3672 restore_inferior_status (struct inferior_status
*inf_status
)
3674 stop_signal
= inf_status
->stop_signal
;
3675 stop_pc
= inf_status
->stop_pc
;
3676 stop_step
= inf_status
->stop_step
;
3677 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3678 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3679 trap_expected
= inf_status
->trap_expected
;
3680 step_range_start
= inf_status
->step_range_start
;
3681 step_range_end
= inf_status
->step_range_end
;
3682 step_frame_id
= inf_status
->step_frame_id
;
3683 step_over_calls
= inf_status
->step_over_calls
;
3684 stop_after_trap
= inf_status
->stop_after_trap
;
3685 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
3686 bpstat_clear (&stop_bpstat
);
3687 stop_bpstat
= inf_status
->stop_bpstat
;
3688 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3689 proceed_to_finish
= inf_status
->proceed_to_finish
;
3691 /* FIXME: Is the restore of stop_registers always needed. */
3692 regcache_xfree (stop_registers
);
3693 stop_registers
= inf_status
->stop_registers
;
3695 /* The inferior can be gone if the user types "print exit(0)"
3696 (and perhaps other times). */
3697 if (target_has_execution
)
3698 /* NB: The register write goes through to the target. */
3699 regcache_cpy (current_regcache
, inf_status
->registers
);
3700 regcache_xfree (inf_status
->registers
);
3702 /* FIXME: If we are being called after stopping in a function which
3703 is called from gdb, we should not be trying to restore the
3704 selected frame; it just prints a spurious error message (The
3705 message is useful, however, in detecting bugs in gdb (like if gdb
3706 clobbers the stack)). In fact, should we be restoring the
3707 inferior status at all in that case? . */
3709 if (target_has_stack
&& inf_status
->restore_stack_info
)
3711 /* The point of catch_errors is that if the stack is clobbered,
3712 walking the stack might encounter a garbage pointer and
3713 error() trying to dereference it. */
3715 (restore_selected_frame
, &inf_status
->selected_frame_id
,
3716 "Unable to restore previously selected frame:\n",
3717 RETURN_MASK_ERROR
) == 0)
3718 /* Error in restoring the selected frame. Select the innermost
3720 select_frame (get_current_frame ());
3728 do_restore_inferior_status_cleanup (void *sts
)
3730 restore_inferior_status (sts
);
3734 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
3736 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
3740 discard_inferior_status (struct inferior_status
*inf_status
)
3742 /* See save_inferior_status for info on stop_bpstat. */
3743 bpstat_clear (&inf_status
->stop_bpstat
);
3744 regcache_xfree (inf_status
->registers
);
3745 regcache_xfree (inf_status
->stop_registers
);
3750 inferior_has_forked (int pid
, int *child_pid
)
3752 struct target_waitstatus last
;
3755 get_last_target_status (&last_ptid
, &last
);
3757 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
3760 if (ptid_get_pid (last_ptid
) != pid
)
3763 *child_pid
= last
.value
.related_pid
;
3768 inferior_has_vforked (int pid
, int *child_pid
)
3770 struct target_waitstatus last
;
3773 get_last_target_status (&last_ptid
, &last
);
3775 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
3778 if (ptid_get_pid (last_ptid
) != pid
)
3781 *child_pid
= last
.value
.related_pid
;
3786 inferior_has_execd (int pid
, char **execd_pathname
)
3788 struct target_waitstatus last
;
3791 get_last_target_status (&last_ptid
, &last
);
3793 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
3796 if (ptid_get_pid (last_ptid
) != pid
)
3799 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
3803 /* Oft used ptids */
3805 ptid_t minus_one_ptid
;
3807 /* Create a ptid given the necessary PID, LWP, and TID components. */
3810 ptid_build (int pid
, long lwp
, long tid
)
3820 /* Create a ptid from just a pid. */
3823 pid_to_ptid (int pid
)
3825 return ptid_build (pid
, 0, 0);
3828 /* Fetch the pid (process id) component from a ptid. */
3831 ptid_get_pid (ptid_t ptid
)
3836 /* Fetch the lwp (lightweight process) component from a ptid. */
3839 ptid_get_lwp (ptid_t ptid
)
3844 /* Fetch the tid (thread id) component from a ptid. */
3847 ptid_get_tid (ptid_t ptid
)
3852 /* ptid_equal() is used to test equality of two ptids. */
3855 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
3857 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
3858 && ptid1
.tid
== ptid2
.tid
);
3861 /* restore_inferior_ptid() will be used by the cleanup machinery
3862 to restore the inferior_ptid value saved in a call to
3863 save_inferior_ptid(). */
3866 restore_inferior_ptid (void *arg
)
3868 ptid_t
*saved_ptid_ptr
= arg
;
3869 inferior_ptid
= *saved_ptid_ptr
;
3873 /* Save the value of inferior_ptid so that it may be restored by a
3874 later call to do_cleanups(). Returns the struct cleanup pointer
3875 needed for later doing the cleanup. */
3878 save_inferior_ptid (void)
3880 ptid_t
*saved_ptid_ptr
;
3882 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
3883 *saved_ptid_ptr
= inferior_ptid
;
3884 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
3891 stop_registers
= regcache_xmalloc (current_gdbarch
);
3895 _initialize_infrun (void)
3898 register int numsigs
;
3899 struct cmd_list_element
*c
;
3901 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
3902 register_gdbarch_swap (NULL
, 0, build_infrun
);
3904 add_info ("signals", signals_info
,
3905 "What debugger does when program gets various signals.\n\
3906 Specify a signal as argument to print info on that signal only.");
3907 add_info_alias ("handle", "signals", 0);
3909 add_com ("handle", class_run
, handle_command
,
3910 concat ("Specify how to handle a signal.\n\
3911 Args are signals and actions to apply to those signals.\n\
3912 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3913 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3914 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3915 The special arg \"all\" is recognized to mean all signals except those\n\
3916 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3917 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3918 Stop means reenter debugger if this signal happens (implies print).\n\
3919 Print means print a message if this signal happens.\n\
3920 Pass means let program see this signal; otherwise program doesn't know.\n\
3921 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3922 Pass and Stop may be combined.", NULL
));
3925 add_com ("lz", class_info
, signals_info
,
3926 "What debugger does when program gets various signals.\n\
3927 Specify a signal as argument to print info on that signal only.");
3928 add_com ("z", class_run
, xdb_handle_command
,
3929 concat ("Specify how to handle a signal.\n\
3930 Args are signals and actions to apply to those signals.\n\
3931 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3932 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3933 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3934 The special arg \"all\" is recognized to mean all signals except those\n\
3935 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3936 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3937 nopass), \"Q\" (noprint)\n\
3938 Stop means reenter debugger if this signal happens (implies print).\n\
3939 Print means print a message if this signal happens.\n\
3940 Pass means let program see this signal; otherwise program doesn't know.\n\
3941 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3942 Pass and Stop may be combined.", NULL
));
3947 add_cmd ("stop", class_obscure
, not_just_help_class_command
, "There is no `stop' command, but you can set a hook on `stop'.\n\
3948 This allows you to set a list of commands to be run each time execution\n\
3949 of the program stops.", &cmdlist
);
3951 numsigs
= (int) TARGET_SIGNAL_LAST
;
3952 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
3953 signal_print
= (unsigned char *)
3954 xmalloc (sizeof (signal_print
[0]) * numsigs
);
3955 signal_program
= (unsigned char *)
3956 xmalloc (sizeof (signal_program
[0]) * numsigs
);
3957 for (i
= 0; i
< numsigs
; i
++)
3960 signal_print
[i
] = 1;
3961 signal_program
[i
] = 1;
3964 /* Signals caused by debugger's own actions
3965 should not be given to the program afterwards. */
3966 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
3967 signal_program
[TARGET_SIGNAL_INT
] = 0;
3969 /* Signals that are not errors should not normally enter the debugger. */
3970 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
3971 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
3972 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
3973 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
3974 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
3975 signal_print
[TARGET_SIGNAL_PROF
] = 0;
3976 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
3977 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
3978 signal_stop
[TARGET_SIGNAL_IO
] = 0;
3979 signal_print
[TARGET_SIGNAL_IO
] = 0;
3980 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
3981 signal_print
[TARGET_SIGNAL_POLL
] = 0;
3982 signal_stop
[TARGET_SIGNAL_URG
] = 0;
3983 signal_print
[TARGET_SIGNAL_URG
] = 0;
3984 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
3985 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
3987 /* These signals are used internally by user-level thread
3988 implementations. (See signal(5) on Solaris.) Like the above
3989 signals, a healthy program receives and handles them as part of
3990 its normal operation. */
3991 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
3992 signal_print
[TARGET_SIGNAL_LWP
] = 0;
3993 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
3994 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
3995 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
3996 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4000 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4001 (char *) &stop_on_solib_events
,
4002 "Set stopping for shared library events.\n\
4003 If nonzero, gdb will give control to the user when the dynamic linker\n\
4004 notifies gdb of shared library events. The most common event of interest\n\
4005 to the user would be loading/unloading of a new library.\n", &setlist
), &showlist
);
4008 c
= add_set_enum_cmd ("follow-fork-mode",
4010 follow_fork_mode_kind_names
, &follow_fork_mode_string
,
4011 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4012 kernel problem. It's also not terribly useful without a GUI to
4013 help the user drive two debuggers. So for now, I'm disabling
4014 the "both" option. */
4015 /* "Set debugger response to a program call of fork \
4017 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4018 parent - the original process is debugged after a fork\n\
4019 child - the new process is debugged after a fork\n\
4020 both - both the parent and child are debugged after a fork\n\
4021 ask - the debugger will ask for one of the above choices\n\
4022 For \"both\", another copy of the debugger will be started to follow\n\
4023 the new child process. The original debugger will continue to follow\n\
4024 the original parent process. To distinguish their prompts, the\n\
4025 debugger copy's prompt will be changed.\n\
4026 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4027 By default, the debugger will follow the parent process.",
4029 "Set debugger response to a program call of fork \
4031 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4032 parent - the original process is debugged after a fork\n\
4033 child - the new process is debugged after a fork\n\
4034 ask - the debugger will ask for one of the above choices\n\
4035 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4036 By default, the debugger will follow the parent process.", &setlist
);
4037 add_show_from_set (c
, &showlist
);
4039 c
= add_set_enum_cmd ("scheduler-locking", class_run
, scheduler_enums
, /* array of string names */
4040 &scheduler_mode
, /* current mode */
4041 "Set mode for locking scheduler during execution.\n\
4042 off == no locking (threads may preempt at any time)\n\
4043 on == full locking (no thread except the current thread may run)\n\
4044 step == scheduler locked during every single-step operation.\n\
4045 In this mode, no other thread may run during a step command.\n\
4046 Other threads may run while stepping over a function call ('next').", &setlist
);
4048 set_cmd_sfunc (c
, set_schedlock_func
); /* traps on target vector */
4049 add_show_from_set (c
, &showlist
);
4051 c
= add_set_cmd ("step-mode", class_run
,
4052 var_boolean
, (char *) &step_stop_if_no_debug
,
4053 "Set mode of the step operation. When set, doing a step over a\n\
4054 function without debug line information will stop at the first\n\
4055 instruction of that function. Otherwise, the function is skipped and\n\
4056 the step command stops at a different source line.", &setlist
);
4057 add_show_from_set (c
, &showlist
);
4059 /* ptid initializations */
4060 null_ptid
= ptid_build (0, 0, 0);
4061 minus_one_ptid
= ptid_build (-1, 0, 0);
4062 inferior_ptid
= null_ptid
;
4063 target_last_wait_ptid
= minus_one_ptid
;