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, 2003 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"
47 /* Prototypes for local functions */
49 static void signals_info (char *, int);
51 static void handle_command (char *, int);
53 static void sig_print_info (enum target_signal);
55 static void sig_print_header (void);
57 static void resume_cleanups (void *);
59 static int hook_stop_stub (void *);
61 static void delete_breakpoint_current_contents (void *);
63 static void set_follow_fork_mode_command (char *arg, int from_tty,
64 struct cmd_list_element *c);
66 static int restore_selected_frame (void *);
68 static void build_infrun (void);
70 static int follow_fork (void);
72 static void set_schedlock_func (char *args, int from_tty,
73 struct cmd_list_element *c);
75 struct execution_control_state;
77 static int currently_stepping (struct execution_control_state *ecs);
79 static void xdb_handle_command (char *args, int from_tty);
81 void _initialize_infrun (void);
83 int inferior_ignoring_startup_exec_events = 0;
84 int inferior_ignoring_leading_exec_events = 0;
86 /* When set, stop the 'step' command if we enter a function which has
87 no line number information. The normal behavior is that we step
88 over such function. */
89 int step_stop_if_no_debug = 0;
91 /* In asynchronous mode, but simulating synchronous execution. */
93 int sync_execution = 0;
95 /* wait_for_inferior and normal_stop use this to notify the user
96 when the inferior stopped in a different thread than it had been
99 static ptid_t previous_inferior_ptid;
101 /* This is true for configurations that may follow through execl() and
102 similar functions. At present this is only true for HP-UX native. */
104 #ifndef MAY_FOLLOW_EXEC
105 #define MAY_FOLLOW_EXEC (0)
108 static int may_follow_exec = MAY_FOLLOW_EXEC;
110 /* Dynamic function trampolines are similar to solib trampolines in that they
111 are between the caller and the callee. The difference is that when you
112 enter a dynamic trampoline, you can't determine the callee's address. Some
113 (usually complex) code needs to run in the dynamic trampoline to figure out
114 the callee's address. This macro is usually called twice. First, when we
115 enter the trampoline (looks like a normal function call at that point). It
116 should return the PC of a point within the trampoline where the callee's
117 address is known. Second, when we hit the breakpoint, this routine returns
118 the callee's address. At that point, things proceed as per a step resume
121 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
122 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
125 /* If the program uses ELF-style shared libraries, then calls to
126 functions in shared libraries go through stubs, which live in a
127 table called the PLT (Procedure Linkage Table). The first time the
128 function is called, the stub sends control to the dynamic linker,
129 which looks up the function's real address, patches the stub so
130 that future calls will go directly to the function, and then passes
131 control to the function.
133 If we are stepping at the source level, we don't want to see any of
134 this --- we just want to skip over the stub and the dynamic linker.
135 The simple approach is to single-step until control leaves the
138 However, on some systems (e.g., Red Hat's 5.2 distribution) the
139 dynamic linker calls functions in the shared C library, so you
140 can't tell from the PC alone whether the dynamic linker is still
141 running. In this case, we use a step-resume breakpoint to get us
142 past the dynamic linker, as if we were using "next" to step over a
145 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
146 linker code or not. Normally, this means we single-step. However,
147 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
148 address where we can place a step-resume breakpoint to get past the
149 linker's symbol resolution function.
151 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
152 pretty portable way, by comparing the PC against the address ranges
153 of the dynamic linker's sections.
155 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
156 it depends on internal details of the dynamic linker. It's usually
157 not too hard to figure out where to put a breakpoint, but it
158 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
159 sanity checking. If it can't figure things out, returning zero and
160 getting the (possibly confusing) stepping behavior is better than
161 signalling an error, which will obscure the change in the
164 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
165 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
168 #ifndef SKIP_SOLIB_RESOLVER
169 #define SKIP_SOLIB_RESOLVER(pc) 0
172 /* This function returns TRUE if pc is the address of an instruction
173 that lies within the dynamic linker (such as the event hook, or the
176 This function must be used only when a dynamic linker event has
177 been caught, and the inferior is being stepped out of the hook, or
178 undefined results are guaranteed. */
180 #ifndef SOLIB_IN_DYNAMIC_LINKER
181 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
184 /* On MIPS16, a function that returns a floating point value may call
185 a library helper function to copy the return value to a floating point
186 register. The IGNORE_HELPER_CALL macro returns non-zero if we
187 should ignore (i.e. step over) this function call. */
188 #ifndef IGNORE_HELPER_CALL
189 #define IGNORE_HELPER_CALL(pc) 0
192 /* On some systems, the PC may be left pointing at an instruction that won't
193 actually be executed. This is usually indicated by a bit in the PSW. If
194 we find ourselves in such a state, then we step the target beyond the
195 nullified instruction before returning control to the user so as to avoid
198 #ifndef INSTRUCTION_NULLIFIED
199 #define INSTRUCTION_NULLIFIED 0
202 /* We can't step off a permanent breakpoint in the ordinary way, because we
203 can't remove it. Instead, we have to advance the PC to the next
204 instruction. This macro should expand to a pointer to a function that
205 does that, or zero if we have no such function. If we don't have a
206 definition for it, we have to report an error. */
207 #ifndef SKIP_PERMANENT_BREAKPOINT
208 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
210 default_skip_permanent_breakpoint (void)
213 The program is stopped at a permanent breakpoint, but GDB does not know\n\
214 how to step past a permanent breakpoint on this architecture. Try using\n\
215 a command like `return' or `jump' to continue execution.");
220 /* Convert the #defines into values. This is temporary until wfi control
221 flow is completely sorted out. */
223 #ifndef HAVE_STEPPABLE_WATCHPOINT
224 #define HAVE_STEPPABLE_WATCHPOINT 0
226 #undef HAVE_STEPPABLE_WATCHPOINT
227 #define HAVE_STEPPABLE_WATCHPOINT 1
230 #ifndef CANNOT_STEP_HW_WATCHPOINTS
231 #define CANNOT_STEP_HW_WATCHPOINTS 0
233 #undef CANNOT_STEP_HW_WATCHPOINTS
234 #define CANNOT_STEP_HW_WATCHPOINTS 1
237 /* Tables of how to react to signals; the user sets them. */
239 static unsigned char *signal_stop;
240 static unsigned char *signal_print;
241 static unsigned char *signal_program;
243 #define SET_SIGS(nsigs,sigs,flags) \
245 int signum = (nsigs); \
246 while (signum-- > 0) \
247 if ((sigs)[signum]) \
248 (flags)[signum] = 1; \
251 #define UNSET_SIGS(nsigs,sigs,flags) \
253 int signum = (nsigs); \
254 while (signum-- > 0) \
255 if ((sigs)[signum]) \
256 (flags)[signum] = 0; \
259 /* Value to pass to target_resume() to cause all threads to resume */
261 #define RESUME_ALL (pid_to_ptid (-1))
263 /* Command list pointer for the "stop" placeholder. */
265 static struct cmd_list_element *stop_command;
267 /* Nonzero if breakpoints are now inserted in the inferior. */
269 static int breakpoints_inserted;
271 /* Function inferior was in as of last step command. */
273 static struct symbol *step_start_function;
275 /* Nonzero if we are expecting a trace trap and should proceed from it. */
277 static int trap_expected;
280 /* Nonzero if we want to give control to the user when we're notified
281 of shared library events by the dynamic linker. */
282 static int stop_on_solib_events;
286 /* Nonzero if the next time we try to continue the inferior, it will
287 step one instruction and generate a spurious trace trap.
288 This is used to compensate for a bug in HP-UX. */
290 static int trap_expected_after_continue;
293 /* Nonzero means expecting a trace trap
294 and should stop the inferior and return silently when it happens. */
298 /* Nonzero means expecting a trap and caller will handle it themselves.
299 It is used after attach, due to attaching to a process;
300 when running in the shell before the child program has been exec'd;
301 and when running some kinds of remote stuff (FIXME?). */
303 int stop_soon_quietly;
305 /* Nonzero if proceed is being used for a "finish" command or a similar
306 situation when stop_registers should be saved. */
308 int proceed_to_finish;
310 /* Save register contents here when about to pop a stack dummy frame,
311 if-and-only-if proceed_to_finish is set.
312 Thus this contains the return value from the called function (assuming
313 values are returned in a register). */
315 struct regcache *stop_registers;
317 /* Nonzero if program stopped due to error trying to insert breakpoints. */
319 static int breakpoints_failed;
321 /* Nonzero after stop if current stack frame should be printed. */
323 static int stop_print_frame;
325 static struct breakpoint *step_resume_breakpoint = NULL;
326 static struct breakpoint *through_sigtramp_breakpoint = NULL;
328 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
329 interactions with an inferior that is running a kernel function
330 (aka, a system call or "syscall"). wait_for_inferior therefore
331 may have a need to know when the inferior is in a syscall. This
332 is a count of the number of inferior threads which are known to
333 currently be running in a syscall. */
334 static int number_of_threads_in_syscalls;
336 /* This is a cached copy of the pid/waitstatus of the last event
337 returned by target_wait()/target_wait_hook(). This information is
338 returned by get_last_target_status(). */
339 static ptid_t target_last_wait_ptid;
340 static struct target_waitstatus target_last_waitstatus;
342 /* This is used to remember when a fork, vfork or exec event
343 was caught by a catchpoint, and thus the event is to be
344 followed at the next resume of the inferior, and not
348 enum target_waitkind kind;
355 char *execd_pathname;
359 static const char follow_fork_mode_ask[] = "ask";
360 static const char follow_fork_mode_child[] = "child";
361 static const char follow_fork_mode_parent[] = "parent";
363 static const char *follow_fork_mode_kind_names[] = {
364 follow_fork_mode_ask,
365 follow_fork_mode_child,
366 follow_fork_mode_parent,
370 static const char *follow_fork_mode_string = follow_fork_mode_parent;
376 const char *follow_mode = follow_fork_mode_string;
377 int follow_child = (follow_mode == follow_fork_mode_child);
379 /* Or, did the user not know, and want us to ask? */
380 if (follow_fork_mode_string == follow_fork_mode_ask)
382 internal_error (__FILE__, __LINE__,
383 "follow_inferior_fork: \"ask\" mode not implemented");
384 /* follow_mode = follow_fork_mode_...; */
387 return target_follow_fork (follow_child);
391 follow_inferior_reset_breakpoints (void)
393 /* Was there a step_resume breakpoint? (There was if the user
394 did a "next" at the fork() call.) If so, explicitly reset its
397 step_resumes are a form of bp that are made to be per-thread.
398 Since we created the step_resume bp when the parent process
399 was being debugged, and now are switching to the child process,
400 from the breakpoint package's viewpoint, that's a switch of
401 "threads". We must update the bp's notion of which thread
402 it is for, or it'll be ignored when it triggers. */
404 if (step_resume_breakpoint)
405 breakpoint_re_set_thread (step_resume_breakpoint);
407 /* Reinsert all breakpoints in the child. The user may have set
408 breakpoints after catching the fork, in which case those
409 were never set in the child, but only in the parent. This makes
410 sure the inserted breakpoints match the breakpoint list. */
412 breakpoint_re_set ();
413 insert_breakpoints ();
416 /* EXECD_PATHNAME is assumed to be non-NULL. */
419 follow_exec (int pid, char *execd_pathname)
422 struct target_ops *tgt;
424 if (!may_follow_exec)
427 /* This is an exec event that we actually wish to pay attention to.
428 Refresh our symbol table to the newly exec'd program, remove any
431 If there are breakpoints, they aren't really inserted now,
432 since the exec() transformed our inferior into a fresh set
435 We want to preserve symbolic breakpoints on the list, since
436 we have hopes that they can be reset after the new a.out's
437 symbol table is read.
439 However, any "raw" breakpoints must be removed from the list
440 (e.g., the solib bp's), since their address is probably invalid
443 And, we DON'T want to call delete_breakpoints() here, since
444 that may write the bp's "shadow contents" (the instruction
445 value that was overwritten witha TRAP instruction). Since
446 we now have a new a.out, those shadow contents aren't valid. */
447 update_breakpoints_after_exec ();
449 /* If there was one, it's gone now. We cannot truly step-to-next
450 statement through an exec(). */
451 step_resume_breakpoint = NULL;
452 step_range_start = 0;
455 /* If there was one, it's gone now. */
456 through_sigtramp_breakpoint = NULL;
458 /* What is this a.out's name? */
459 printf_unfiltered ("Executing new program: %s\n", execd_pathname);
461 /* We've followed the inferior through an exec. Therefore, the
462 inferior has essentially been killed & reborn. */
464 /* First collect the run target in effect. */
465 tgt = find_run_target ();
466 /* If we can't find one, things are in a very strange state... */
468 error ("Could find run target to save before following exec");
470 gdb_flush (gdb_stdout);
471 target_mourn_inferior ();
472 inferior_ptid = pid_to_ptid (saved_pid);
473 /* Because mourn_inferior resets inferior_ptid. */
476 /* That a.out is now the one to use. */
477 exec_file_attach (execd_pathname, 0);
479 /* And also is where symbols can be found. */
480 symbol_file_add_main (execd_pathname, 0);
482 /* Reset the shared library package. This ensures that we get
483 a shlib event when the child reaches "_start", at which point
484 the dld will have had a chance to initialize the child. */
485 #if defined(SOLIB_RESTART)
488 #ifdef SOLIB_CREATE_INFERIOR_HOOK
489 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
492 /* Reinsert all breakpoints. (Those which were symbolic have
493 been reset to the proper address in the new a.out, thanks
494 to symbol_file_command...) */
495 insert_breakpoints ();
497 /* The next resume of this inferior should bring it to the shlib
498 startup breakpoints. (If the user had also set bp's on
499 "main" from the old (parent) process, then they'll auto-
500 matically get reset there in the new process.) */
503 /* Non-zero if we just simulating a single-step. This is needed
504 because we cannot remove the breakpoints in the inferior process
505 until after the `wait' in `wait_for_inferior'. */
506 static int singlestep_breakpoints_inserted_p = 0;
509 /* Things to clean up if we QUIT out of resume (). */
512 resume_cleanups (void *ignore)
517 static const char schedlock_off[] = "off";
518 static const char schedlock_on[] = "on";
519 static const char schedlock_step[] = "step";
520 static const char *scheduler_mode = schedlock_off;
521 static const char *scheduler_enums[] = {
529 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
531 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
532 the set command passed as a parameter. The clone operation will
533 include (BUG?) any ``set'' command callback, if present.
534 Commands like ``info set'' call all the ``show'' command
535 callbacks. Unfortunatly, for ``show'' commands cloned from
536 ``set'', this includes callbacks belonging to ``set'' commands.
537 Making this worse, this only occures if add_show_from_set() is
538 called after add_cmd_sfunc() (BUG?). */
539 if (cmd_type (c) == set_cmd)
540 if (!target_can_lock_scheduler)
542 scheduler_mode = schedlock_off;
543 error ("Target '%s' cannot support this command.", target_shortname);
548 /* Resume the inferior, but allow a QUIT. This is useful if the user
549 wants to interrupt some lengthy single-stepping operation
550 (for child processes, the SIGINT goes to the inferior, and so
551 we get a SIGINT random_signal, but for remote debugging and perhaps
552 other targets, that's not true).
554 STEP nonzero if we should step (zero to continue instead).
555 SIG is the signal to give the inferior (zero for none). */
557 resume (int step, enum target_signal sig)
559 int should_resume = 1;
560 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
563 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
566 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
567 over an instruction that causes a page fault without triggering
568 a hardware watchpoint. The kernel properly notices that it shouldn't
569 stop, because the hardware watchpoint is not triggered, but it forgets
570 the step request and continues the program normally.
571 Work around the problem by removing hardware watchpoints if a step is
572 requested, GDB will check for a hardware watchpoint trigger after the
574 if (CANNOT_STEP_HW_WATCHPOINTS && step && breakpoints_inserted)
575 remove_hw_watchpoints ();
578 /* Normally, by the time we reach `resume', the breakpoints are either
579 removed or inserted, as appropriate. The exception is if we're sitting
580 at a permanent breakpoint; we need to step over it, but permanent
581 breakpoints can't be removed. So we have to test for it here. */
582 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here)
583 SKIP_PERMANENT_BREAKPOINT ();
585 if (SOFTWARE_SINGLE_STEP_P () && step)
587 /* Do it the hard way, w/temp breakpoints */
588 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ );
589 /* ...and don't ask hardware to do it. */
591 /* and do not pull these breakpoints until after a `wait' in
592 `wait_for_inferior' */
593 singlestep_breakpoints_inserted_p = 1;
596 /* Handle any optimized stores to the inferior NOW... */
597 #ifdef DO_DEFERRED_STORES
601 /* If there were any forks/vforks/execs that were caught and are
602 now to be followed, then do so. */
603 switch (pending_follow.kind)
605 case TARGET_WAITKIND_FORKED:
606 case TARGET_WAITKIND_VFORKED:
607 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
612 case TARGET_WAITKIND_EXECD:
613 /* follow_exec is called as soon as the exec event is seen. */
614 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
621 /* Install inferior's terminal modes. */
622 target_terminal_inferior ();
628 resume_ptid = RESUME_ALL; /* Default */
630 if ((step || singlestep_breakpoints_inserted_p) &&
631 !breakpoints_inserted && breakpoint_here_p (read_pc ()))
633 /* Stepping past a breakpoint without inserting breakpoints.
634 Make sure only the current thread gets to step, so that
635 other threads don't sneak past breakpoints while they are
638 resume_ptid = inferior_ptid;
641 if ((scheduler_mode == schedlock_on) ||
642 (scheduler_mode == schedlock_step &&
643 (step || singlestep_breakpoints_inserted_p)))
645 /* User-settable 'scheduler' mode requires solo thread resume. */
646 resume_ptid = inferior_ptid;
649 if (CANNOT_STEP_BREAKPOINT)
651 /* Most targets can step a breakpoint instruction, thus
652 executing it normally. But if this one cannot, just
653 continue and we will hit it anyway. */
654 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
657 target_resume (resume_ptid, step, sig);
660 discard_cleanups (old_cleanups);
664 /* Clear out all variables saying what to do when inferior is continued.
665 First do this, then set the ones you want, then call `proceed'. */
668 clear_proceed_status (void)
671 step_range_start = 0;
673 step_frame_id = null_frame_id;
674 step_over_calls = STEP_OVER_UNDEBUGGABLE;
676 stop_soon_quietly = 0;
677 proceed_to_finish = 0;
678 breakpoint_proceeded = 1; /* We're about to proceed... */
680 /* Discard any remaining commands or status from previous stop. */
681 bpstat_clear (&stop_bpstat);
684 /* Basic routine for continuing the program in various fashions.
686 ADDR is the address to resume at, or -1 for resume where stopped.
687 SIGGNAL is the signal to give it, or 0 for none,
688 or -1 for act according to how it stopped.
689 STEP is nonzero if should trap after one instruction.
690 -1 means return after that and print nothing.
691 You should probably set various step_... variables
692 before calling here, if you are stepping.
694 You should call clear_proceed_status before calling proceed. */
697 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
702 step_start_function = find_pc_function (read_pc ());
706 if (addr == (CORE_ADDR) -1)
708 /* If there is a breakpoint at the address we will resume at,
709 step one instruction before inserting breakpoints
710 so that we do not stop right away (and report a second
711 hit at this breakpoint). */
713 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
716 #ifndef STEP_SKIPS_DELAY
717 #define STEP_SKIPS_DELAY(pc) (0)
718 #define STEP_SKIPS_DELAY_P (0)
720 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
721 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
722 is slow (it needs to read memory from the target). */
723 if (STEP_SKIPS_DELAY_P
724 && breakpoint_here_p (read_pc () + 4)
725 && STEP_SKIPS_DELAY (read_pc ()))
733 #ifdef PREPARE_TO_PROCEED
734 /* In a multi-threaded task we may select another thread
735 and then continue or step.
737 But if the old thread was stopped at a breakpoint, it
738 will immediately cause another breakpoint stop without
739 any execution (i.e. it will report a breakpoint hit
740 incorrectly). So we must step over it first.
742 PREPARE_TO_PROCEED checks the current thread against the thread
743 that reported the most recent event. If a step-over is required
744 it returns TRUE and sets the current thread to the old thread. */
745 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
750 #endif /* PREPARE_TO_PROCEED */
753 if (trap_expected_after_continue)
755 /* If (step == 0), a trap will be automatically generated after
756 the first instruction is executed. Force step one
757 instruction to clear this condition. This should not occur
758 if step is nonzero, but it is harmless in that case. */
760 trap_expected_after_continue = 0;
762 #endif /* HP_OS_BUG */
765 /* We will get a trace trap after one instruction.
766 Continue it automatically and insert breakpoints then. */
770 insert_breakpoints ();
771 /* If we get here there was no call to error() in
772 insert breakpoints -- so they were inserted. */
773 breakpoints_inserted = 1;
776 if (siggnal != TARGET_SIGNAL_DEFAULT)
777 stop_signal = siggnal;
778 /* If this signal should not be seen by program,
779 give it zero. Used for debugging signals. */
780 else if (!signal_program[stop_signal])
781 stop_signal = TARGET_SIGNAL_0;
783 annotate_starting ();
785 /* Make sure that output from GDB appears before output from the
787 gdb_flush (gdb_stdout);
789 /* Resume inferior. */
790 resume (oneproc || step || bpstat_should_step (), stop_signal);
792 /* Wait for it to stop (if not standalone)
793 and in any case decode why it stopped, and act accordingly. */
794 /* Do this only if we are not using the event loop, or if the target
795 does not support asynchronous execution. */
796 if (!event_loop_p || !target_can_async_p ())
798 wait_for_inferior ();
803 /* Record the pc and sp of the program the last time it stopped.
804 These are just used internally by wait_for_inferior, but need
805 to be preserved over calls to it and cleared when the inferior
807 static CORE_ADDR prev_pc;
808 static CORE_ADDR prev_func_start;
809 static char *prev_func_name;
812 /* Start remote-debugging of a machine over a serial link. */
818 init_wait_for_inferior ();
819 stop_soon_quietly = 1;
822 /* Always go on waiting for the target, regardless of the mode. */
823 /* FIXME: cagney/1999-09-23: At present it isn't possible to
824 indicate to wait_for_inferior that a target should timeout if
825 nothing is returned (instead of just blocking). Because of this,
826 targets expecting an immediate response need to, internally, set
827 things up so that the target_wait() is forced to eventually
829 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
830 differentiate to its caller what the state of the target is after
831 the initial open has been performed. Here we're assuming that
832 the target has stopped. It should be possible to eventually have
833 target_open() return to the caller an indication that the target
834 is currently running and GDB state should be set to the same as
836 wait_for_inferior ();
840 /* Initialize static vars when a new inferior begins. */
843 init_wait_for_inferior (void)
845 /* These are meaningless until the first time through wait_for_inferior. */
848 prev_func_name = NULL;
851 trap_expected_after_continue = 0;
853 breakpoints_inserted = 0;
854 breakpoint_init_inferior (inf_starting);
856 /* Don't confuse first call to proceed(). */
857 stop_signal = TARGET_SIGNAL_0;
859 /* The first resume is not following a fork/vfork/exec. */
860 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
862 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
863 number_of_threads_in_syscalls = 0;
865 clear_proceed_status ();
869 delete_breakpoint_current_contents (void *arg)
871 struct breakpoint **breakpointp = (struct breakpoint **) arg;
872 if (*breakpointp != NULL)
874 delete_breakpoint (*breakpointp);
879 /* This enum encodes possible reasons for doing a target_wait, so that
880 wfi can call target_wait in one place. (Ultimately the call will be
881 moved out of the infinite loop entirely.) */
885 infwait_normal_state,
886 infwait_thread_hop_state,
887 infwait_nullified_state,
888 infwait_nonstep_watch_state
891 /* Why did the inferior stop? Used to print the appropriate messages
892 to the interface from within handle_inferior_event(). */
893 enum inferior_stop_reason
895 /* We don't know why. */
897 /* Step, next, nexti, stepi finished. */
899 /* Found breakpoint. */
901 /* Inferior terminated by signal. */
903 /* Inferior exited. */
905 /* Inferior received signal, and user asked to be notified. */
909 /* This structure contains what used to be local variables in
910 wait_for_inferior. Probably many of them can return to being
911 locals in handle_inferior_event. */
913 struct execution_control_state
915 struct target_waitstatus ws;
916 struct target_waitstatus *wp;
919 CORE_ADDR stop_func_start;
920 CORE_ADDR stop_func_end;
921 char *stop_func_name;
922 struct symtab_and_line sal;
923 int remove_breakpoints_on_following_step;
925 struct symtab *current_symtab;
926 int handling_longjmp; /* FIXME */
928 ptid_t saved_inferior_ptid;
930 int stepping_through_solib_after_catch;
931 bpstat stepping_through_solib_catchpoints;
932 int enable_hw_watchpoints_after_wait;
933 int stepping_through_sigtramp;
934 int new_thread_event;
935 struct target_waitstatus tmpstatus;
936 enum infwait_states infwait_state;
941 void init_execution_control_state (struct execution_control_state *ecs);
943 void handle_inferior_event (struct execution_control_state *ecs);
945 static void check_sigtramp2 (struct execution_control_state *ecs);
946 static void step_into_function (struct execution_control_state *ecs);
947 static void step_over_function (struct execution_control_state *ecs);
948 static void stop_stepping (struct execution_control_state *ecs);
949 static void prepare_to_wait (struct execution_control_state *ecs);
950 static void keep_going (struct execution_control_state *ecs);
951 static void print_stop_reason (enum inferior_stop_reason stop_reason,
954 /* Wait for control to return from inferior to debugger.
955 If inferior gets a signal, we may decide to start it up again
956 instead of returning. That is why there is a loop in this function.
957 When this function actually returns it means the inferior
958 should be left stopped and GDB should read more commands. */
961 wait_for_inferior (void)
963 struct cleanup *old_cleanups;
964 struct execution_control_state ecss;
965 struct execution_control_state *ecs;
967 old_cleanups = make_cleanup (delete_step_resume_breakpoint,
968 &step_resume_breakpoint);
969 make_cleanup (delete_breakpoint_current_contents,
970 &through_sigtramp_breakpoint);
972 /* wfi still stays in a loop, so it's OK just to take the address of
973 a local to get the ecs pointer. */
976 /* Fill in with reasonable starting values. */
977 init_execution_control_state (ecs);
979 /* We'll update this if & when we switch to a new thread. */
980 previous_inferior_ptid = inferior_ptid;
982 overlay_cache_invalid = 1;
984 /* We have to invalidate the registers BEFORE calling target_wait
985 because they can be loaded from the target while in target_wait.
986 This makes remote debugging a bit more efficient for those
987 targets that provide critical registers as part of their normal
990 registers_changed ();
994 if (target_wait_hook)
995 ecs->ptid = target_wait_hook (ecs->waiton_ptid, ecs->wp);
997 ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp);
999 /* Now figure out what to do with the result of the result. */
1000 handle_inferior_event (ecs);
1002 if (!ecs->wait_some_more)
1005 do_cleanups (old_cleanups);
1008 /* Asynchronous version of wait_for_inferior. It is called by the
1009 event loop whenever a change of state is detected on the file
1010 descriptor corresponding to the target. It can be called more than
1011 once to complete a single execution command. In such cases we need
1012 to keep the state in a global variable ASYNC_ECSS. If it is the
1013 last time that this function is called for a single execution
1014 command, then report to the user that the inferior has stopped, and
1015 do the necessary cleanups. */
1017 struct execution_control_state async_ecss;
1018 struct execution_control_state *async_ecs;
1021 fetch_inferior_event (void *client_data)
1023 static struct cleanup *old_cleanups;
1025 async_ecs = &async_ecss;
1027 if (!async_ecs->wait_some_more)
1029 old_cleanups = make_exec_cleanup (delete_step_resume_breakpoint,
1030 &step_resume_breakpoint);
1031 make_exec_cleanup (delete_breakpoint_current_contents,
1032 &through_sigtramp_breakpoint);
1034 /* Fill in with reasonable starting values. */
1035 init_execution_control_state (async_ecs);
1037 /* We'll update this if & when we switch to a new thread. */
1038 previous_inferior_ptid = inferior_ptid;
1040 overlay_cache_invalid = 1;
1042 /* We have to invalidate the registers BEFORE calling target_wait
1043 because they can be loaded from the target while in target_wait.
1044 This makes remote debugging a bit more efficient for those
1045 targets that provide critical registers as part of their normal
1046 status mechanism. */
1048 registers_changed ();
1051 if (target_wait_hook)
1053 target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp);
1055 async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp);
1057 /* Now figure out what to do with the result of the result. */
1058 handle_inferior_event (async_ecs);
1060 if (!async_ecs->wait_some_more)
1062 /* Do only the cleanups that have been added by this
1063 function. Let the continuations for the commands do the rest,
1064 if there are any. */
1065 do_exec_cleanups (old_cleanups);
1067 if (step_multi && stop_step)
1068 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
1070 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1074 /* Prepare an execution control state for looping through a
1075 wait_for_inferior-type loop. */
1078 init_execution_control_state (struct execution_control_state *ecs)
1080 /* ecs->another_trap? */
1081 ecs->random_signal = 0;
1082 ecs->remove_breakpoints_on_following_step = 0;
1083 ecs->handling_longjmp = 0; /* FIXME */
1084 ecs->update_step_sp = 0;
1085 ecs->stepping_through_solib_after_catch = 0;
1086 ecs->stepping_through_solib_catchpoints = NULL;
1087 ecs->enable_hw_watchpoints_after_wait = 0;
1088 ecs->stepping_through_sigtramp = 0;
1089 ecs->sal = find_pc_line (prev_pc, 0);
1090 ecs->current_line = ecs->sal.line;
1091 ecs->current_symtab = ecs->sal.symtab;
1092 ecs->infwait_state = infwait_normal_state;
1093 ecs->waiton_ptid = pid_to_ptid (-1);
1094 ecs->wp = &(ecs->ws);
1097 /* Call this function before setting step_resume_breakpoint, as a
1098 sanity check. There should never be more than one step-resume
1099 breakpoint per thread, so we should never be setting a new
1100 step_resume_breakpoint when one is already active. */
1102 check_for_old_step_resume_breakpoint (void)
1104 if (step_resume_breakpoint)
1106 ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1109 /* Return the cached copy of the last pid/waitstatus returned by
1110 target_wait()/target_wait_hook(). The data is actually cached by
1111 handle_inferior_event(), which gets called immediately after
1112 target_wait()/target_wait_hook(). */
1115 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
1117 *ptidp = target_last_wait_ptid;
1118 *status = target_last_waitstatus;
1121 /* Switch thread contexts, maintaining "infrun state". */
1124 context_switch (struct execution_control_state *ecs)
1126 /* Caution: it may happen that the new thread (or the old one!)
1127 is not in the thread list. In this case we must not attempt
1128 to "switch context", or we run the risk that our context may
1129 be lost. This may happen as a result of the target module
1130 mishandling thread creation. */
1132 if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid))
1133 { /* Perform infrun state context switch: */
1134 /* Save infrun state for the old thread. */
1135 save_infrun_state (inferior_ptid, prev_pc,
1136 prev_func_start, prev_func_name,
1137 trap_expected, step_resume_breakpoint,
1138 through_sigtramp_breakpoint, step_range_start,
1139 step_range_end, &step_frame_id,
1140 ecs->handling_longjmp, ecs->another_trap,
1141 ecs->stepping_through_solib_after_catch,
1142 ecs->stepping_through_solib_catchpoints,
1143 ecs->stepping_through_sigtramp,
1144 ecs->current_line, ecs->current_symtab, step_sp);
1146 /* Load infrun state for the new thread. */
1147 load_infrun_state (ecs->ptid, &prev_pc,
1148 &prev_func_start, &prev_func_name,
1149 &trap_expected, &step_resume_breakpoint,
1150 &through_sigtramp_breakpoint, &step_range_start,
1151 &step_range_end, &step_frame_id,
1152 &ecs->handling_longjmp, &ecs->another_trap,
1153 &ecs->stepping_through_solib_after_catch,
1154 &ecs->stepping_through_solib_catchpoints,
1155 &ecs->stepping_through_sigtramp,
1156 &ecs->current_line, &ecs->current_symtab, &step_sp);
1158 inferior_ptid = ecs->ptid;
1162 /* Given an execution control state that has been freshly filled in
1163 by an event from the inferior, figure out what it means and take
1164 appropriate action. */
1167 handle_inferior_event (struct execution_control_state *ecs)
1169 CORE_ADDR real_stop_pc;
1170 int stepped_after_stopped_by_watchpoint;
1171 int sw_single_step_trap_p = 0;
1173 /* Cache the last pid/waitstatus. */
1174 target_last_wait_ptid = ecs->ptid;
1175 target_last_waitstatus = *ecs->wp;
1177 switch (ecs->infwait_state)
1179 case infwait_thread_hop_state:
1180 /* Cancel the waiton_ptid. */
1181 ecs->waiton_ptid = pid_to_ptid (-1);
1182 /* Fall thru to the normal_state case. */
1184 case infwait_normal_state:
1185 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1186 is serviced in this loop, below. */
1187 if (ecs->enable_hw_watchpoints_after_wait)
1189 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1190 ecs->enable_hw_watchpoints_after_wait = 0;
1192 stepped_after_stopped_by_watchpoint = 0;
1195 case infwait_nullified_state:
1198 case infwait_nonstep_watch_state:
1199 insert_breakpoints ();
1201 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1202 handle things like signals arriving and other things happening
1203 in combination correctly? */
1204 stepped_after_stopped_by_watchpoint = 1;
1207 ecs->infwait_state = infwait_normal_state;
1209 flush_cached_frames ();
1211 /* If it's a new process, add it to the thread database */
1213 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
1214 && !in_thread_list (ecs->ptid));
1216 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1217 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
1219 add_thread (ecs->ptid);
1221 ui_out_text (uiout, "[New ");
1222 ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid));
1223 ui_out_text (uiout, "]\n");
1226 /* NOTE: This block is ONLY meant to be invoked in case of a
1227 "thread creation event"! If it is invoked for any other
1228 sort of event (such as a new thread landing on a breakpoint),
1229 the event will be discarded, which is almost certainly
1232 To avoid this, the low-level module (eg. target_wait)
1233 should call in_thread_list and add_thread, so that the
1234 new thread is known by the time we get here. */
1236 /* We may want to consider not doing a resume here in order
1237 to give the user a chance to play with the new thread.
1238 It might be good to make that a user-settable option. */
1240 /* At this point, all threads are stopped (happens
1241 automatically in either the OS or the native code).
1242 Therefore we need to continue all threads in order to
1245 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
1246 prepare_to_wait (ecs);
1251 switch (ecs->ws.kind)
1253 case TARGET_WAITKIND_LOADED:
1254 /* Ignore gracefully during startup of the inferior, as it
1255 might be the shell which has just loaded some objects,
1256 otherwise add the symbols for the newly loaded objects. */
1258 if (!stop_soon_quietly)
1260 /* Remove breakpoints, SOLIB_ADD might adjust
1261 breakpoint addresses via breakpoint_re_set. */
1262 if (breakpoints_inserted)
1263 remove_breakpoints ();
1265 /* Check for any newly added shared libraries if we're
1266 supposed to be adding them automatically. Switch
1267 terminal for any messages produced by
1268 breakpoint_re_set. */
1269 target_terminal_ours_for_output ();
1270 SOLIB_ADD (NULL, 0, NULL, auto_solib_add);
1271 target_terminal_inferior ();
1273 /* Reinsert breakpoints and continue. */
1274 if (breakpoints_inserted)
1275 insert_breakpoints ();
1278 resume (0, TARGET_SIGNAL_0);
1279 prepare_to_wait (ecs);
1282 case TARGET_WAITKIND_SPURIOUS:
1283 resume (0, TARGET_SIGNAL_0);
1284 prepare_to_wait (ecs);
1287 case TARGET_WAITKIND_EXITED:
1288 target_terminal_ours (); /* Must do this before mourn anyway */
1289 print_stop_reason (EXITED, ecs->ws.value.integer);
1291 /* Record the exit code in the convenience variable $_exitcode, so
1292 that the user can inspect this again later. */
1293 set_internalvar (lookup_internalvar ("_exitcode"),
1294 value_from_longest (builtin_type_int,
1295 (LONGEST) ecs->ws.value.integer));
1296 gdb_flush (gdb_stdout);
1297 target_mourn_inferior ();
1298 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */
1299 stop_print_frame = 0;
1300 stop_stepping (ecs);
1303 case TARGET_WAITKIND_SIGNALLED:
1304 stop_print_frame = 0;
1305 stop_signal = ecs->ws.value.sig;
1306 target_terminal_ours (); /* Must do this before mourn anyway */
1308 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1309 reach here unless the inferior is dead. However, for years
1310 target_kill() was called here, which hints that fatal signals aren't
1311 really fatal on some systems. If that's true, then some changes
1313 target_mourn_inferior ();
1315 print_stop_reason (SIGNAL_EXITED, stop_signal);
1316 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */
1317 stop_stepping (ecs);
1320 /* The following are the only cases in which we keep going;
1321 the above cases end in a continue or goto. */
1322 case TARGET_WAITKIND_FORKED:
1323 case TARGET_WAITKIND_VFORKED:
1324 stop_signal = TARGET_SIGNAL_TRAP;
1325 pending_follow.kind = ecs->ws.kind;
1327 pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid);
1328 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1330 stop_pc = read_pc ();
1332 /* Assume that catchpoints are not really software breakpoints. If
1333 some future target implements them using software breakpoints then
1334 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1335 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1336 bpstat_stop_status will not decrement the PC. */
1338 stop_bpstat = bpstat_stop_status (&stop_pc, 1);
1340 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1342 /* If no catchpoint triggered for this, then keep going. */
1343 if (ecs->random_signal)
1345 stop_signal = TARGET_SIGNAL_0;
1349 goto process_event_stop_test;
1351 case TARGET_WAITKIND_EXECD:
1352 stop_signal = TARGET_SIGNAL_TRAP;
1354 /* NOTE drow/2002-12-05: This code should be pushed down into the
1355 target_wait function. Until then following vfork on HP/UX 10.20
1356 is probably broken by this. Of course, it's broken anyway. */
1357 /* Is this a target which reports multiple exec events per actual
1358 call to exec()? (HP-UX using ptrace does, for example.) If so,
1359 ignore all but the last one. Just resume the exec'r, and wait
1360 for the next exec event. */
1361 if (inferior_ignoring_leading_exec_events)
1363 inferior_ignoring_leading_exec_events--;
1364 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1365 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.
1367 target_resume (ecs->ptid, 0, TARGET_SIGNAL_0);
1368 prepare_to_wait (ecs);
1371 inferior_ignoring_leading_exec_events =
1372 target_reported_exec_events_per_exec_call () - 1;
1374 pending_follow.execd_pathname =
1375 savestring (ecs->ws.value.execd_pathname,
1376 strlen (ecs->ws.value.execd_pathname));
1378 /* This causes the eventpoints and symbol table to be reset. Must
1379 do this now, before trying to determine whether to stop. */
1380 follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname);
1381 xfree (pending_follow.execd_pathname);
1383 stop_pc = read_pc_pid (ecs->ptid);
1384 ecs->saved_inferior_ptid = inferior_ptid;
1385 inferior_ptid = ecs->ptid;
1387 /* Assume that catchpoints are not really software breakpoints. If
1388 some future target implements them using software breakpoints then
1389 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1390 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1391 bpstat_stop_status will not decrement the PC. */
1393 stop_bpstat = bpstat_stop_status (&stop_pc, 1);
1395 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1396 inferior_ptid = ecs->saved_inferior_ptid;
1398 /* If no catchpoint triggered for this, then keep going. */
1399 if (ecs->random_signal)
1401 stop_signal = TARGET_SIGNAL_0;
1405 goto process_event_stop_test;
1407 /* These syscall events are returned on HP-UX, as part of its
1408 implementation of page-protection-based "hardware" watchpoints.
1409 HP-UX has unfortunate interactions between page-protections and
1410 some system calls. Our solution is to disable hardware watches
1411 when a system call is entered, and reenable them when the syscall
1412 completes. The downside of this is that we may miss the precise
1413 point at which a watched piece of memory is modified. "Oh well."
1415 Note that we may have multiple threads running, which may each
1416 enter syscalls at roughly the same time. Since we don't have a
1417 good notion currently of whether a watched piece of memory is
1418 thread-private, we'd best not have any page-protections active
1419 when any thread is in a syscall. Thus, we only want to reenable
1420 hardware watches when no threads are in a syscall.
1422 Also, be careful not to try to gather much state about a thread
1423 that's in a syscall. It's frequently a losing proposition. */
1424 case TARGET_WAITKIND_SYSCALL_ENTRY:
1425 number_of_threads_in_syscalls++;
1426 if (number_of_threads_in_syscalls == 1)
1428 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1430 resume (0, TARGET_SIGNAL_0);
1431 prepare_to_wait (ecs);
1434 /* Before examining the threads further, step this thread to
1435 get it entirely out of the syscall. (We get notice of the
1436 event when the thread is just on the verge of exiting a
1437 syscall. Stepping one instruction seems to get it back
1440 Note that although the logical place to reenable h/w watches
1441 is here, we cannot. We cannot reenable them before stepping
1442 the thread (this causes the next wait on the thread to hang).
1444 Nor can we enable them after stepping until we've done a wait.
1445 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1446 here, which will be serviced immediately after the target
1448 case TARGET_WAITKIND_SYSCALL_RETURN:
1449 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
1451 if (number_of_threads_in_syscalls > 0)
1453 number_of_threads_in_syscalls--;
1454 ecs->enable_hw_watchpoints_after_wait =
1455 (number_of_threads_in_syscalls == 0);
1457 prepare_to_wait (ecs);
1460 case TARGET_WAITKIND_STOPPED:
1461 stop_signal = ecs->ws.value.sig;
1464 /* We had an event in the inferior, but we are not interested
1465 in handling it at this level. The lower layers have already
1466 done what needs to be done, if anything.
1468 One of the possible circumstances for this is when the
1469 inferior produces output for the console. The inferior has
1470 not stopped, and we are ignoring the event. Another possible
1471 circumstance is any event which the lower level knows will be
1472 reported multiple times without an intervening resume. */
1473 case TARGET_WAITKIND_IGNORE:
1474 prepare_to_wait (ecs);
1478 /* We may want to consider not doing a resume here in order to give
1479 the user a chance to play with the new thread. It might be good
1480 to make that a user-settable option. */
1482 /* At this point, all threads are stopped (happens automatically in
1483 either the OS or the native code). Therefore we need to continue
1484 all threads in order to make progress. */
1485 if (ecs->new_thread_event)
1487 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
1488 prepare_to_wait (ecs);
1492 stop_pc = read_pc_pid (ecs->ptid);
1494 /* See if a thread hit a thread-specific breakpoint that was meant for
1495 another thread. If so, then step that thread past the breakpoint,
1498 if (stop_signal == TARGET_SIGNAL_TRAP)
1500 /* Check if a regular breakpoint has been hit before checking
1501 for a potential single step breakpoint. Otherwise, GDB will
1502 not see this breakpoint hit when stepping onto breakpoints. */
1503 if (breakpoints_inserted
1504 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
1506 ecs->random_signal = 0;
1507 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK,
1512 /* Saw a breakpoint, but it was hit by the wrong thread.
1514 if (DECR_PC_AFTER_BREAK)
1515 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, ecs->ptid);
1517 remove_status = remove_breakpoints ();
1518 /* Did we fail to remove breakpoints? If so, try
1519 to set the PC past the bp. (There's at least
1520 one situation in which we can fail to remove
1521 the bp's: On HP-UX's that use ttrace, we can't
1522 change the address space of a vforking child
1523 process until the child exits (well, okay, not
1524 then either :-) or execs. */
1525 if (remove_status != 0)
1527 /* FIXME! This is obviously non-portable! */
1528 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, ecs->ptid);
1529 /* We need to restart all the threads now,
1530 * unles we're running in scheduler-locked mode.
1531 * Use currently_stepping to determine whether to
1534 /* FIXME MVS: is there any reason not to call resume()? */
1535 if (scheduler_mode == schedlock_on)
1536 target_resume (ecs->ptid,
1537 currently_stepping (ecs), TARGET_SIGNAL_0);
1539 target_resume (RESUME_ALL,
1540 currently_stepping (ecs), TARGET_SIGNAL_0);
1541 prepare_to_wait (ecs);
1546 breakpoints_inserted = 0;
1547 if (!ptid_equal (inferior_ptid, ecs->ptid))
1548 context_switch (ecs);
1549 ecs->waiton_ptid = ecs->ptid;
1550 ecs->wp = &(ecs->ws);
1551 ecs->another_trap = 1;
1553 ecs->infwait_state = infwait_thread_hop_state;
1555 registers_changed ();
1560 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1562 /* Readjust the stop_pc as it is off by DECR_PC_AFTER_BREAK
1563 compared to the value it would have if the system stepping
1564 capability was used. This allows the rest of the code in
1565 this function to use this address without having to worry
1566 whether software single step is in use or not. */
1567 if (DECR_PC_AFTER_BREAK)
1569 stop_pc -= DECR_PC_AFTER_BREAK;
1570 write_pc_pid (stop_pc, ecs->ptid);
1573 sw_single_step_trap_p = 1;
1574 ecs->random_signal = 0;
1578 ecs->random_signal = 1;
1580 /* See if something interesting happened to the non-current thread. If
1581 so, then switch to that thread, and eventually give control back to
1584 Note that if there's any kind of pending follow (i.e., of a fork,
1585 vfork or exec), we don't want to do this now. Rather, we'll let
1586 the next resume handle it. */
1587 if (!ptid_equal (ecs->ptid, inferior_ptid) &&
1588 (pending_follow.kind == TARGET_WAITKIND_SPURIOUS))
1592 /* If it's a random signal for a non-current thread, notify user
1593 if he's expressed an interest. */
1594 if (ecs->random_signal && signal_print[stop_signal])
1596 /* ??rehrauer: I don't understand the rationale for this code. If the
1597 inferior will stop as a result of this signal, then the act of handling
1598 the stop ought to print a message that's couches the stoppage in user
1599 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1600 won't stop as a result of the signal -- i.e., if the signal is merely
1601 a side-effect of something GDB's doing "under the covers" for the
1602 user, such as stepping threads over a breakpoint they shouldn't stop
1603 for -- then the message seems to be a serious annoyance at best.
1605 For now, remove the message altogether. */
1608 target_terminal_ours_for_output ();
1609 printf_filtered ("\nProgram received signal %s, %s.\n",
1610 target_signal_to_name (stop_signal),
1611 target_signal_to_string (stop_signal));
1612 gdb_flush (gdb_stdout);
1616 /* If it's not SIGTRAP and not a signal we want to stop for, then
1617 continue the thread. */
1619 if (stop_signal != TARGET_SIGNAL_TRAP && !signal_stop[stop_signal])
1622 target_terminal_inferior ();
1624 /* Clear the signal if it should not be passed. */
1625 if (signal_program[stop_signal] == 0)
1626 stop_signal = TARGET_SIGNAL_0;
1628 target_resume (ecs->ptid, 0, stop_signal);
1629 prepare_to_wait (ecs);
1633 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1634 and fall into the rest of wait_for_inferior(). */
1636 context_switch (ecs);
1639 context_hook (pid_to_thread_id (ecs->ptid));
1641 flush_cached_frames ();
1644 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1646 /* Pull the single step breakpoints out of the target. */
1647 SOFTWARE_SINGLE_STEP (0, 0);
1648 singlestep_breakpoints_inserted_p = 0;
1651 /* If PC is pointing at a nullified instruction, then step beyond
1652 it so that the user won't be confused when GDB appears to be ready
1655 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1656 if (INSTRUCTION_NULLIFIED)
1658 registers_changed ();
1659 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
1661 /* We may have received a signal that we want to pass to
1662 the inferior; therefore, we must not clobber the waitstatus
1665 ecs->infwait_state = infwait_nullified_state;
1666 ecs->waiton_ptid = ecs->ptid;
1667 ecs->wp = &(ecs->tmpstatus);
1668 prepare_to_wait (ecs);
1672 /* It may not be necessary to disable the watchpoint to stop over
1673 it. For example, the PA can (with some kernel cooperation)
1674 single step over a watchpoint without disabling the watchpoint. */
1675 if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1678 prepare_to_wait (ecs);
1682 /* It is far more common to need to disable a watchpoint to step
1683 the inferior over it. FIXME. What else might a debug
1684 register or page protection watchpoint scheme need here? */
1685 if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1687 /* At this point, we are stopped at an instruction which has
1688 attempted to write to a piece of memory under control of
1689 a watchpoint. The instruction hasn't actually executed
1690 yet. If we were to evaluate the watchpoint expression
1691 now, we would get the old value, and therefore no change
1692 would seem to have occurred.
1694 In order to make watchpoints work `right', we really need
1695 to complete the memory write, and then evaluate the
1696 watchpoint expression. The following code does that by
1697 removing the watchpoint (actually, all watchpoints and
1698 breakpoints), single-stepping the target, re-inserting
1699 watchpoints, and then falling through to let normal
1700 single-step processing handle proceed. Since this
1701 includes evaluating watchpoints, things will come to a
1702 stop in the correct manner. */
1704 if (DECR_PC_AFTER_BREAK)
1705 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
1707 remove_breakpoints ();
1708 registers_changed ();
1709 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */
1711 ecs->waiton_ptid = ecs->ptid;
1712 ecs->wp = &(ecs->ws);
1713 ecs->infwait_state = infwait_nonstep_watch_state;
1714 prepare_to_wait (ecs);
1718 /* It may be possible to simply continue after a watchpoint. */
1719 if (HAVE_CONTINUABLE_WATCHPOINT)
1720 STOPPED_BY_WATCHPOINT (ecs->ws);
1722 ecs->stop_func_start = 0;
1723 ecs->stop_func_end = 0;
1724 ecs->stop_func_name = 0;
1725 /* Don't care about return value; stop_func_start and stop_func_name
1726 will both be 0 if it doesn't work. */
1727 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
1728 &ecs->stop_func_start, &ecs->stop_func_end);
1729 ecs->stop_func_start += FUNCTION_START_OFFSET;
1730 ecs->another_trap = 0;
1731 bpstat_clear (&stop_bpstat);
1733 stop_stack_dummy = 0;
1734 stop_print_frame = 1;
1735 ecs->random_signal = 0;
1736 stopped_by_random_signal = 0;
1737 breakpoints_failed = 0;
1739 /* Look at the cause of the stop, and decide what to do.
1740 The alternatives are:
1741 1) break; to really stop and return to the debugger,
1742 2) drop through to start up again
1743 (set ecs->another_trap to 1 to single step once)
1744 3) set ecs->random_signal to 1, and the decision between 1 and 2
1745 will be made according to the signal handling tables. */
1747 /* First, distinguish signals caused by the debugger from signals
1748 that have to do with the program's own actions.
1749 Note that breakpoint insns may cause SIGTRAP or SIGILL
1750 or SIGEMT, depending on the operating system version.
1751 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1752 and change it to SIGTRAP. */
1754 if (stop_signal == TARGET_SIGNAL_TRAP
1755 || (breakpoints_inserted &&
1756 (stop_signal == TARGET_SIGNAL_ILL
1757 || stop_signal == TARGET_SIGNAL_EMT)) || stop_soon_quietly)
1759 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
1761 stop_print_frame = 0;
1762 stop_stepping (ecs);
1765 if (stop_soon_quietly)
1767 stop_stepping (ecs);
1771 /* Don't even think about breakpoints
1772 if just proceeded over a breakpoint.
1774 However, if we are trying to proceed over a breakpoint
1775 and end up in sigtramp, then through_sigtramp_breakpoint
1776 will be set and we should check whether we've hit the
1778 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
1779 && through_sigtramp_breakpoint == NULL)
1780 bpstat_clear (&stop_bpstat);
1783 /* See if there is a breakpoint at the current PC. */
1785 /* The second argument of bpstat_stop_status is meant to help
1786 distinguish between a breakpoint trap and a singlestep trap.
1787 This is only important on targets where DECR_PC_AFTER_BREAK
1788 is non-zero. The prev_pc test is meant to distinguish between
1789 singlestepping a trap instruction, and singlestepping thru a
1790 jump to the instruction following a trap instruction.
1792 Therefore, pass TRUE if our reason for stopping is
1793 something other than hitting a breakpoint. We do this by
1794 checking that either: we detected earlier a software single
1795 step trap or, 1) stepping is going on and 2) we didn't hit
1796 a breakpoint in a signal handler without an intervening stop
1797 in sigtramp, which is detected by a new stack pointer value
1798 below any usual function calling stack adjustments. */
1802 sw_single_step_trap_p
1803 || (currently_stepping (ecs)
1804 && prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1806 && INNER_THAN (read_sp (), (step_sp - 16)))));
1807 /* Following in case break condition called a
1809 stop_print_frame = 1;
1812 if (stop_signal == TARGET_SIGNAL_TRAP)
1814 = !(bpstat_explains_signal (stop_bpstat)
1816 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
1817 && DEPRECATED_PC_IN_CALL_DUMMY (stop_pc, read_sp (),
1818 get_frame_base (get_current_frame ())))
1819 || (step_range_end && step_resume_breakpoint == NULL));
1823 ecs->random_signal = !(bpstat_explains_signal (stop_bpstat)
1824 /* End of a stack dummy. Some systems (e.g. Sony
1825 news) give another signal besides SIGTRAP, so
1826 check here as well as above. */
1827 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
1828 && DEPRECATED_PC_IN_CALL_DUMMY (stop_pc, read_sp (),
1832 if (!ecs->random_signal)
1833 stop_signal = TARGET_SIGNAL_TRAP;
1837 /* When we reach this point, we've pretty much decided
1838 that the reason for stopping must've been a random
1839 (unexpected) signal. */
1842 ecs->random_signal = 1;
1844 process_event_stop_test:
1845 /* For the program's own signals, act according to
1846 the signal handling tables. */
1848 if (ecs->random_signal)
1850 /* Signal not for debugging purposes. */
1853 stopped_by_random_signal = 1;
1855 if (signal_print[stop_signal])
1858 target_terminal_ours_for_output ();
1859 print_stop_reason (SIGNAL_RECEIVED, stop_signal);
1861 if (signal_stop[stop_signal])
1863 stop_stepping (ecs);
1866 /* If not going to stop, give terminal back
1867 if we took it away. */
1869 target_terminal_inferior ();
1871 /* Clear the signal if it should not be passed. */
1872 if (signal_program[stop_signal] == 0)
1873 stop_signal = TARGET_SIGNAL_0;
1875 /* I'm not sure whether this needs to be check_sigtramp2 or
1876 whether it could/should be keep_going.
1878 This used to jump to step_over_function if we are stepping,
1881 Suppose the user does a `next' over a function call, and while
1882 that call is in progress, the inferior receives a signal for
1883 which GDB does not stop (i.e., signal_stop[SIG] is false). In
1884 that case, when we reach this point, there is already a
1885 step-resume breakpoint established, right where it should be:
1886 immediately after the function call the user is "next"-ing
1887 over. If we call step_over_function now, two bad things
1890 - we'll create a new breakpoint, at wherever the current
1891 frame's return address happens to be. That could be
1892 anywhere, depending on what function call happens to be on
1893 the top of the stack at that point. Point is, it's probably
1894 not where we need it.
1896 - the existing step-resume breakpoint (which is at the correct
1897 address) will get orphaned: step_resume_breakpoint will point
1898 to the new breakpoint, and the old step-resume breakpoint
1899 will never be cleaned up.
1901 The old behavior was meant to help HP-UX single-step out of
1902 sigtramps. It would place the new breakpoint at prev_pc, which
1903 was certainly wrong. I don't know the details there, so fixing
1904 this probably breaks that. As with anything else, it's up to
1905 the HP-UX maintainer to furnish a fix that doesn't break other
1906 platforms. --JimB, 20 May 1999 */
1907 check_sigtramp2 (ecs);
1912 /* Handle cases caused by hitting a breakpoint. */
1914 CORE_ADDR jmp_buf_pc;
1915 struct bpstat_what what;
1917 what = bpstat_what (stop_bpstat);
1919 if (what.call_dummy)
1921 stop_stack_dummy = 1;
1923 trap_expected_after_continue = 1;
1927 switch (what.main_action)
1929 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
1930 /* If we hit the breakpoint at longjmp, disable it for the
1931 duration of this command. Then, install a temporary
1932 breakpoint at the target of the jmp_buf. */
1933 disable_longjmp_breakpoint ();
1934 remove_breakpoints ();
1935 breakpoints_inserted = 0;
1936 if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc))
1942 /* Need to blow away step-resume breakpoint, as it
1943 interferes with us */
1944 if (step_resume_breakpoint != NULL)
1946 delete_step_resume_breakpoint (&step_resume_breakpoint);
1948 /* Not sure whether we need to blow this away too, but probably
1949 it is like the step-resume breakpoint. */
1950 if (through_sigtramp_breakpoint != NULL)
1952 delete_breakpoint (through_sigtramp_breakpoint);
1953 through_sigtramp_breakpoint = NULL;
1957 /* FIXME - Need to implement nested temporary breakpoints */
1958 if (step_over_calls > 0)
1959 set_longjmp_resume_breakpoint (jmp_buf_pc, get_current_frame ());
1962 set_longjmp_resume_breakpoint (jmp_buf_pc, null_frame_id);
1963 ecs->handling_longjmp = 1; /* FIXME */
1967 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
1968 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
1969 remove_breakpoints ();
1970 breakpoints_inserted = 0;
1972 /* FIXME - Need to implement nested temporary breakpoints */
1974 && (frame_id_inner (get_frame_id (get_current_frame ()),
1977 ecs->another_trap = 1;
1982 disable_longjmp_breakpoint ();
1983 ecs->handling_longjmp = 0; /* FIXME */
1984 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
1986 /* else fallthrough */
1988 case BPSTAT_WHAT_SINGLE:
1989 if (breakpoints_inserted)
1991 remove_breakpoints ();
1993 breakpoints_inserted = 0;
1994 ecs->another_trap = 1;
1995 /* Still need to check other stuff, at least the case
1996 where we are stepping and step out of the right range. */
1999 case BPSTAT_WHAT_STOP_NOISY:
2000 stop_print_frame = 1;
2002 /* We are about to nuke the step_resume_breakpoint and
2003 through_sigtramp_breakpoint via the cleanup chain, so
2004 no need to worry about it here. */
2006 stop_stepping (ecs);
2009 case BPSTAT_WHAT_STOP_SILENT:
2010 stop_print_frame = 0;
2012 /* We are about to nuke the step_resume_breakpoint and
2013 through_sigtramp_breakpoint via the cleanup chain, so
2014 no need to worry about it here. */
2016 stop_stepping (ecs);
2019 case BPSTAT_WHAT_STEP_RESUME:
2020 /* This proably demands a more elegant solution, but, yeah
2023 This function's use of the simple variable
2024 step_resume_breakpoint doesn't seem to accomodate
2025 simultaneously active step-resume bp's, although the
2026 breakpoint list certainly can.
2028 If we reach here and step_resume_breakpoint is already
2029 NULL, then apparently we have multiple active
2030 step-resume bp's. We'll just delete the breakpoint we
2031 stopped at, and carry on.
2033 Correction: what the code currently does is delete a
2034 step-resume bp, but it makes no effort to ensure that
2035 the one deleted is the one currently stopped at. MVS */
2037 if (step_resume_breakpoint == NULL)
2039 step_resume_breakpoint =
2040 bpstat_find_step_resume_breakpoint (stop_bpstat);
2042 delete_step_resume_breakpoint (&step_resume_breakpoint);
2045 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2046 if (through_sigtramp_breakpoint)
2047 delete_breakpoint (through_sigtramp_breakpoint);
2048 through_sigtramp_breakpoint = NULL;
2050 /* If were waiting for a trap, hitting the step_resume_break
2051 doesn't count as getting it. */
2053 ecs->another_trap = 1;
2056 case BPSTAT_WHAT_CHECK_SHLIBS:
2057 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2060 /* Remove breakpoints, we eventually want to step over the
2061 shlib event breakpoint, and SOLIB_ADD might adjust
2062 breakpoint addresses via breakpoint_re_set. */
2063 if (breakpoints_inserted)
2064 remove_breakpoints ();
2065 breakpoints_inserted = 0;
2067 /* Check for any newly added shared libraries if we're
2068 supposed to be adding them automatically. Switch
2069 terminal for any messages produced by
2070 breakpoint_re_set. */
2071 target_terminal_ours_for_output ();
2072 SOLIB_ADD (NULL, 0, NULL, auto_solib_add);
2073 target_terminal_inferior ();
2075 /* Try to reenable shared library breakpoints, additional
2076 code segments in shared libraries might be mapped in now. */
2077 re_enable_breakpoints_in_shlibs ();
2079 /* If requested, stop when the dynamic linker notifies
2080 gdb of events. This allows the user to get control
2081 and place breakpoints in initializer routines for
2082 dynamically loaded objects (among other things). */
2083 if (stop_on_solib_events)
2085 stop_stepping (ecs);
2089 /* If we stopped due to an explicit catchpoint, then the
2090 (see above) call to SOLIB_ADD pulled in any symbols
2091 from a newly-loaded library, if appropriate.
2093 We do want the inferior to stop, but not where it is
2094 now, which is in the dynamic linker callback. Rather,
2095 we would like it stop in the user's program, just after
2096 the call that caused this catchpoint to trigger. That
2097 gives the user a more useful vantage from which to
2098 examine their program's state. */
2099 else if (what.main_action ==
2100 BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2102 /* ??rehrauer: If I could figure out how to get the
2103 right return PC from here, we could just set a temp
2104 breakpoint and resume. I'm not sure we can without
2105 cracking open the dld's shared libraries and sniffing
2106 their unwind tables and text/data ranges, and that's
2107 not a terribly portable notion.
2109 Until that time, we must step the inferior out of the
2110 dld callback, and also out of the dld itself (and any
2111 code or stubs in libdld.sl, such as "shl_load" and
2112 friends) until we reach non-dld code. At that point,
2113 we can stop stepping. */
2114 bpstat_get_triggered_catchpoints (stop_bpstat,
2116 stepping_through_solib_catchpoints);
2117 ecs->stepping_through_solib_after_catch = 1;
2119 /* Be sure to lift all breakpoints, so the inferior does
2120 actually step past this point... */
2121 ecs->another_trap = 1;
2126 /* We want to step over this breakpoint, then keep going. */
2127 ecs->another_trap = 1;
2134 case BPSTAT_WHAT_LAST:
2135 /* Not a real code, but listed here to shut up gcc -Wall. */
2137 case BPSTAT_WHAT_KEEP_CHECKING:
2142 /* We come here if we hit a breakpoint but should not
2143 stop for it. Possibly we also were stepping
2144 and should stop for that. So fall through and
2145 test for stepping. But, if not stepping,
2148 /* Are we stepping to get the inferior out of the dynamic
2149 linker's hook (and possibly the dld itself) after catching
2151 if (ecs->stepping_through_solib_after_catch)
2153 #if defined(SOLIB_ADD)
2154 /* Have we reached our destination? If not, keep going. */
2155 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
2157 ecs->another_trap = 1;
2162 /* Else, stop and report the catchpoint(s) whose triggering
2163 caused us to begin stepping. */
2164 ecs->stepping_through_solib_after_catch = 0;
2165 bpstat_clear (&stop_bpstat);
2166 stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints);
2167 bpstat_clear (&ecs->stepping_through_solib_catchpoints);
2168 stop_print_frame = 1;
2169 stop_stepping (ecs);
2173 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P)
2175 /* This is the old way of detecting the end of the stack dummy.
2176 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2177 handled above. As soon as we can test it on all of them, all
2178 architectures should define it. */
2180 /* If this is the breakpoint at the end of a stack dummy,
2181 just stop silently, unless the user was doing an si/ni, in which
2182 case she'd better know what she's doing. */
2184 if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (),
2185 get_frame_base (get_current_frame ()))
2188 stop_print_frame = 0;
2189 stop_stack_dummy = 1;
2191 trap_expected_after_continue = 1;
2193 stop_stepping (ecs);
2198 if (step_resume_breakpoint)
2200 /* Having a step-resume breakpoint overrides anything
2201 else having to do with stepping commands until
2202 that breakpoint is reached. */
2203 /* I'm not sure whether this needs to be check_sigtramp2 or
2204 whether it could/should be keep_going. */
2205 check_sigtramp2 (ecs);
2210 if (step_range_end == 0)
2212 /* Likewise if we aren't even stepping. */
2213 /* I'm not sure whether this needs to be check_sigtramp2 or
2214 whether it could/should be keep_going. */
2215 check_sigtramp2 (ecs);
2220 /* If stepping through a line, keep going if still within it.
2222 Note that step_range_end is the address of the first instruction
2223 beyond the step range, and NOT the address of the last instruction
2225 if (stop_pc >= step_range_start && stop_pc < step_range_end)
2227 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2228 So definately need to check for sigtramp here. */
2229 check_sigtramp2 (ecs);
2234 /* We stepped out of the stepping range. */
2236 /* If we are stepping at the source level and entered the runtime
2237 loader dynamic symbol resolution code, we keep on single stepping
2238 until we exit the run time loader code and reach the callee's
2240 if (step_over_calls == STEP_OVER_UNDEBUGGABLE
2241 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2243 CORE_ADDR pc_after_resolver = SKIP_SOLIB_RESOLVER (stop_pc);
2245 if (pc_after_resolver)
2247 /* Set up a step-resume breakpoint at the address
2248 indicated by SKIP_SOLIB_RESOLVER. */
2249 struct symtab_and_line sr_sal;
2251 sr_sal.pc = pc_after_resolver;
2253 check_for_old_step_resume_breakpoint ();
2254 step_resume_breakpoint =
2255 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2256 if (breakpoints_inserted)
2257 insert_breakpoints ();
2264 /* We can't update step_sp every time through the loop, because
2265 reading the stack pointer would slow down stepping too much.
2266 But we can update it every time we leave the step range. */
2267 ecs->update_step_sp = 1;
2269 /* Did we just take a signal? */
2270 if (PC_IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2271 && !PC_IN_SIGTRAMP (prev_pc, prev_func_name)
2272 && INNER_THAN (read_sp (), step_sp))
2274 /* We've just taken a signal; go until we are back to
2275 the point where we took it and one more. */
2277 /* Note: The test above succeeds not only when we stepped
2278 into a signal handler, but also when we step past the last
2279 statement of a signal handler and end up in the return stub
2280 of the signal handler trampoline. To distinguish between
2281 these two cases, check that the frame is INNER_THAN the
2282 previous one below. pai/1997-09-11 */
2286 struct frame_id current_frame = get_frame_id (get_current_frame ());
2288 if (frame_id_inner (current_frame, step_frame_id))
2290 /* We have just taken a signal; go until we are back to
2291 the point where we took it and one more. */
2293 /* This code is needed at least in the following case:
2294 The user types "next" and then a signal arrives (before
2295 the "next" is done). */
2297 /* Note that if we are stopped at a breakpoint, then we need
2298 the step_resume breakpoint to override any breakpoints at
2299 the same location, so that we will still step over the
2300 breakpoint even though the signal happened. */
2301 struct symtab_and_line sr_sal;
2304 sr_sal.symtab = NULL;
2306 sr_sal.pc = prev_pc;
2307 /* We could probably be setting the frame to
2308 step_frame_id; I don't think anyone thought to try it. */
2309 check_for_old_step_resume_breakpoint ();
2310 step_resume_breakpoint =
2311 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2312 if (breakpoints_inserted)
2313 insert_breakpoints ();
2317 /* We just stepped out of a signal handler and into
2318 its calling trampoline.
2320 Normally, we'd call step_over_function from
2321 here, but for some reason GDB can't unwind the
2322 stack correctly to find the real PC for the point
2323 user code where the signal trampoline will return
2324 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2325 But signal trampolines are pretty small stubs of
2326 code, anyway, so it's OK instead to just
2327 single-step out. Note: assuming such trampolines
2328 don't exhibit recursion on any platform... */
2329 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2330 &ecs->stop_func_start,
2331 &ecs->stop_func_end);
2332 /* Readjust stepping range */
2333 step_range_start = ecs->stop_func_start;
2334 step_range_end = ecs->stop_func_end;
2335 ecs->stepping_through_sigtramp = 1;
2340 /* If this is stepi or nexti, make sure that the stepping range
2341 gets us past that instruction. */
2342 if (step_range_end == 1)
2343 /* FIXME: Does this run afoul of the code below which, if
2344 we step into the middle of a line, resets the stepping
2346 step_range_end = (step_range_start = prev_pc) + 1;
2348 ecs->remove_breakpoints_on_following_step = 1;
2353 if (stop_pc == ecs->stop_func_start /* Quick test */
2354 || (in_prologue (stop_pc, ecs->stop_func_start) &&
2355 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2356 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name)
2357 || ecs->stop_func_name == 0)
2359 /* It's a subroutine call. */
2361 if ((step_over_calls == STEP_OVER_NONE)
2362 || ((step_range_end == 1)
2363 && in_prologue (prev_pc, ecs->stop_func_start)))
2365 /* I presume that step_over_calls is only 0 when we're
2366 supposed to be stepping at the assembly language level
2367 ("stepi"). Just stop. */
2368 /* Also, maybe we just did a "nexti" inside a prolog,
2369 so we thought it was a subroutine call but it was not.
2370 Stop as well. FENN */
2372 print_stop_reason (END_STEPPING_RANGE, 0);
2373 stop_stepping (ecs);
2377 if (step_over_calls == STEP_OVER_ALL || IGNORE_HELPER_CALL (stop_pc))
2379 /* We're doing a "next". */
2381 if (PC_IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2382 && frame_id_inner (step_frame_id,
2383 frame_id_build (read_sp (), 0)))
2384 /* We stepped out of a signal handler, and into its
2385 calling trampoline. This is misdetected as a
2386 subroutine call, but stepping over the signal
2387 trampoline isn't such a bad idea. In order to do that,
2388 we have to ignore the value in step_frame_id, since
2389 that doesn't represent the frame that'll reach when we
2390 return from the signal trampoline. Otherwise we'll
2391 probably continue to the end of the program. */
2392 step_frame_id = null_frame_id;
2394 step_over_function (ecs);
2399 /* If we are in a function call trampoline (a stub between
2400 the calling routine and the real function), locate the real
2401 function. That's what tells us (a) whether we want to step
2402 into it at all, and (b) what prologue we want to run to
2403 the end of, if we do step into it. */
2404 real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc);
2405 if (real_stop_pc != 0)
2406 ecs->stop_func_start = real_stop_pc;
2409 real_stop_pc = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
2412 struct symtab_and_line xxx;
2413 /* Why isn't this s_a_l called "sr_sal", like all of the
2414 other s_a_l's where this code is duplicated? */
2415 init_sal (&xxx); /* initialize to zeroes */
2416 xxx.pc = real_stop_pc;
2417 xxx.section = find_pc_overlay (xxx.pc);
2418 check_for_old_step_resume_breakpoint ();
2419 step_resume_breakpoint =
2420 set_momentary_breakpoint (xxx, null_frame_id, bp_step_resume);
2421 insert_breakpoints ();
2427 /* If we have line number information for the function we
2428 are thinking of stepping into, step into it.
2430 If there are several symtabs at that PC (e.g. with include
2431 files), just want to know whether *any* of them have line
2432 numbers. find_pc_line handles this. */
2434 struct symtab_and_line tmp_sal;
2436 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
2437 if (tmp_sal.line != 0)
2439 step_into_function (ecs);
2444 /* If we have no line number and the step-stop-if-no-debug
2445 is set, we stop the step so that the user has a chance to
2446 switch in assembly mode. */
2447 if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug)
2450 print_stop_reason (END_STEPPING_RANGE, 0);
2451 stop_stepping (ecs);
2455 step_over_function (ecs);
2461 /* We've wandered out of the step range. */
2463 ecs->sal = find_pc_line (stop_pc, 0);
2465 if (step_range_end == 1)
2467 /* It is stepi or nexti. We always want to stop stepping after
2470 print_stop_reason (END_STEPPING_RANGE, 0);
2471 stop_stepping (ecs);
2475 /* If we're in the return path from a shared library trampoline,
2476 we want to proceed through the trampoline when stepping. */
2477 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2479 /* Determine where this trampoline returns. */
2480 real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc);
2482 /* Only proceed through if we know where it's going. */
2485 /* And put the step-breakpoint there and go until there. */
2486 struct symtab_and_line sr_sal;
2488 init_sal (&sr_sal); /* initialize to zeroes */
2489 sr_sal.pc = real_stop_pc;
2490 sr_sal.section = find_pc_overlay (sr_sal.pc);
2491 /* Do not specify what the fp should be when we stop
2492 since on some machines the prologue
2493 is where the new fp value is established. */
2494 check_for_old_step_resume_breakpoint ();
2495 step_resume_breakpoint =
2496 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2497 if (breakpoints_inserted)
2498 insert_breakpoints ();
2500 /* Restart without fiddling with the step ranges or
2507 if (ecs->sal.line == 0)
2509 /* We have no line number information. That means to stop
2510 stepping (does this always happen right after one instruction,
2511 when we do "s" in a function with no line numbers,
2512 or can this happen as a result of a return or longjmp?). */
2514 print_stop_reason (END_STEPPING_RANGE, 0);
2515 stop_stepping (ecs);
2519 if ((stop_pc == ecs->sal.pc)
2520 && (ecs->current_line != ecs->sal.line
2521 || ecs->current_symtab != ecs->sal.symtab))
2523 /* We are at the start of a different line. So stop. Note that
2524 we don't stop if we step into the middle of a different line.
2525 That is said to make things like for (;;) statements work
2528 print_stop_reason (END_STEPPING_RANGE, 0);
2529 stop_stepping (ecs);
2533 /* We aren't done stepping.
2535 Optimize by setting the stepping range to the line.
2536 (We might not be in the original line, but if we entered a
2537 new line in mid-statement, we continue stepping. This makes
2538 things like for(;;) statements work better.) */
2540 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
2542 /* If this is the last line of the function, don't keep stepping
2543 (it would probably step us out of the function).
2544 This is particularly necessary for a one-line function,
2545 in which after skipping the prologue we better stop even though
2546 we will be in mid-line. */
2548 print_stop_reason (END_STEPPING_RANGE, 0);
2549 stop_stepping (ecs);
2552 step_range_start = ecs->sal.pc;
2553 step_range_end = ecs->sal.end;
2554 step_frame_id = get_frame_id (get_current_frame ());
2555 ecs->current_line = ecs->sal.line;
2556 ecs->current_symtab = ecs->sal.symtab;
2558 /* In the case where we just stepped out of a function into the
2559 middle of a line of the caller, continue stepping, but
2560 step_frame_id must be modified to current frame */
2562 struct frame_id current_frame = get_frame_id (get_current_frame ());
2563 if (!(frame_id_inner (current_frame, step_frame_id)))
2564 step_frame_id = current_frame;
2570 /* Are we in the middle of stepping? */
2573 currently_stepping (struct execution_control_state *ecs)
2575 return ((through_sigtramp_breakpoint == NULL
2576 && !ecs->handling_longjmp
2577 && ((step_range_end && step_resume_breakpoint == NULL)
2579 || ecs->stepping_through_solib_after_catch
2580 || bpstat_should_step ());
2584 check_sigtramp2 (struct execution_control_state *ecs)
2587 && PC_IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2588 && !PC_IN_SIGTRAMP (prev_pc, prev_func_name)
2589 && INNER_THAN (read_sp (), step_sp))
2591 /* What has happened here is that we have just stepped the
2592 inferior with a signal (because it is a signal which
2593 shouldn't make us stop), thus stepping into sigtramp.
2595 So we need to set a step_resume_break_address breakpoint and
2596 continue until we hit it, and then step. FIXME: This should
2597 be more enduring than a step_resume breakpoint; we should
2598 know that we will later need to keep going rather than
2599 re-hitting the breakpoint here (see the testsuite,
2600 gdb.base/signals.exp where it says "exceedingly difficult"). */
2602 struct symtab_and_line sr_sal;
2604 init_sal (&sr_sal); /* initialize to zeroes */
2605 sr_sal.pc = prev_pc;
2606 sr_sal.section = find_pc_overlay (sr_sal.pc);
2607 /* We perhaps could set the frame if we kept track of what the
2608 frame corresponding to prev_pc was. But we don't, so don't. */
2609 through_sigtramp_breakpoint =
2610 set_momentary_breakpoint (sr_sal, null_frame_id, bp_through_sigtramp);
2611 if (breakpoints_inserted)
2612 insert_breakpoints ();
2614 ecs->remove_breakpoints_on_following_step = 1;
2615 ecs->another_trap = 1;
2619 /* Subroutine call with source code we should not step over. Do step
2620 to the first line of code in it. */
2623 step_into_function (struct execution_control_state *ecs)
2626 struct symtab_and_line sr_sal;
2628 s = find_pc_symtab (stop_pc);
2629 if (s && s->language != language_asm)
2630 ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start);
2632 ecs->sal = find_pc_line (ecs->stop_func_start, 0);
2633 /* Use the step_resume_break to step until the end of the prologue,
2634 even if that involves jumps (as it seems to on the vax under
2636 /* If the prologue ends in the middle of a source line, continue to
2637 the end of that source line (if it is still within the function).
2638 Otherwise, just go to end of prologue. */
2639 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2640 /* no, don't either. It skips any code that's legitimately on the
2644 && ecs->sal.pc != ecs->stop_func_start
2645 && ecs->sal.end < ecs->stop_func_end)
2646 ecs->stop_func_start = ecs->sal.end;
2649 if (ecs->stop_func_start == stop_pc)
2651 /* We are already there: stop now. */
2653 print_stop_reason (END_STEPPING_RANGE, 0);
2654 stop_stepping (ecs);
2659 /* Put the step-breakpoint there and go until there. */
2660 init_sal (&sr_sal); /* initialize to zeroes */
2661 sr_sal.pc = ecs->stop_func_start;
2662 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
2663 /* Do not specify what the fp should be when we stop since on
2664 some machines the prologue is where the new fp value is
2666 check_for_old_step_resume_breakpoint ();
2667 step_resume_breakpoint =
2668 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2669 if (breakpoints_inserted)
2670 insert_breakpoints ();
2672 /* And make sure stepping stops right away then. */
2673 step_range_end = step_range_start;
2678 /* We've just entered a callee, and we wish to resume until it returns
2679 to the caller. Setting a step_resume breakpoint on the return
2680 address will catch a return from the callee.
2682 However, if the callee is recursing, we want to be careful not to
2683 catch returns of those recursive calls, but only of THIS instance
2686 To do this, we set the step_resume bp's frame to our current
2687 caller's frame (step_frame_id, which is set by the "next" or
2688 "until" command, before execution begins). */
2691 step_over_function (struct execution_control_state *ecs)
2693 struct symtab_and_line sr_sal;
2695 init_sal (&sr_sal); /* initialize to zeros */
2696 sr_sal.pc = ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2697 sr_sal.section = find_pc_overlay (sr_sal.pc);
2699 check_for_old_step_resume_breakpoint ();
2700 step_resume_breakpoint =
2701 set_momentary_breakpoint (sr_sal, get_frame_id (get_current_frame ()),
2704 if (frame_id_p (step_frame_id)
2705 && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
2706 step_resume_breakpoint->frame_id = step_frame_id;
2708 if (breakpoints_inserted)
2709 insert_breakpoints ();
2713 stop_stepping (struct execution_control_state *ecs)
2715 if (target_has_execution)
2717 /* Assuming the inferior still exists, set these up for next
2718 time, just like we did above if we didn't break out of the
2720 prev_pc = read_pc ();
2721 prev_func_start = ecs->stop_func_start;
2722 prev_func_name = ecs->stop_func_name;
2725 /* Let callers know we don't want to wait for the inferior anymore. */
2726 ecs->wait_some_more = 0;
2729 /* This function handles various cases where we need to continue
2730 waiting for the inferior. */
2731 /* (Used to be the keep_going: label in the old wait_for_inferior) */
2734 keep_going (struct execution_control_state *ecs)
2736 /* Save the pc before execution, to compare with pc after stop. */
2737 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
2738 prev_func_start = ecs->stop_func_start; /* Ok, since if DECR_PC_AFTER
2739 BREAK is defined, the
2740 original pc would not have
2741 been at the start of a
2743 prev_func_name = ecs->stop_func_name;
2745 if (ecs->update_step_sp)
2746 step_sp = read_sp ();
2747 ecs->update_step_sp = 0;
2749 /* If we did not do break;, it means we should keep running the
2750 inferior and not return to debugger. */
2752 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
2754 /* We took a signal (which we are supposed to pass through to
2755 the inferior, else we'd have done a break above) and we
2756 haven't yet gotten our trap. Simply continue. */
2757 resume (currently_stepping (ecs), stop_signal);
2761 /* Either the trap was not expected, but we are continuing
2762 anyway (the user asked that this signal be passed to the
2765 The signal was SIGTRAP, e.g. it was our signal, but we
2766 decided we should resume from it.
2768 We're going to run this baby now!
2770 Insert breakpoints now, unless we are trying to one-proceed
2771 past a breakpoint. */
2772 /* If we've just finished a special step resume and we don't
2773 want to hit a breakpoint, pull em out. */
2774 if (step_resume_breakpoint == NULL
2775 && through_sigtramp_breakpoint == NULL
2776 && ecs->remove_breakpoints_on_following_step)
2778 ecs->remove_breakpoints_on_following_step = 0;
2779 remove_breakpoints ();
2780 breakpoints_inserted = 0;
2782 else if (!breakpoints_inserted &&
2783 (through_sigtramp_breakpoint != NULL || !ecs->another_trap))
2785 breakpoints_failed = insert_breakpoints ();
2786 if (breakpoints_failed)
2788 stop_stepping (ecs);
2791 breakpoints_inserted = 1;
2794 trap_expected = ecs->another_trap;
2796 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
2797 specifies that such a signal should be delivered to the
2800 Typically, this would occure when a user is debugging a
2801 target monitor on a simulator: the target monitor sets a
2802 breakpoint; the simulator encounters this break-point and
2803 halts the simulation handing control to GDB; GDB, noteing
2804 that the break-point isn't valid, returns control back to the
2805 simulator; the simulator then delivers the hardware
2806 equivalent of a SIGNAL_TRAP to the program being debugged. */
2808 if (stop_signal == TARGET_SIGNAL_TRAP && !signal_program[stop_signal])
2809 stop_signal = TARGET_SIGNAL_0;
2811 #ifdef SHIFT_INST_REGS
2812 /* I'm not sure when this following segment applies. I do know,
2813 now, that we shouldn't rewrite the regs when we were stopped
2814 by a random signal from the inferior process. */
2815 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2816 (this is only used on the 88k). */
2818 if (!bpstat_explains_signal (stop_bpstat)
2819 && (stop_signal != TARGET_SIGNAL_CHLD) && !stopped_by_random_signal)
2821 #endif /* SHIFT_INST_REGS */
2823 resume (currently_stepping (ecs), stop_signal);
2826 prepare_to_wait (ecs);
2829 /* This function normally comes after a resume, before
2830 handle_inferior_event exits. It takes care of any last bits of
2831 housekeeping, and sets the all-important wait_some_more flag. */
2834 prepare_to_wait (struct execution_control_state *ecs)
2836 if (ecs->infwait_state == infwait_normal_state)
2838 overlay_cache_invalid = 1;
2840 /* We have to invalidate the registers BEFORE calling
2841 target_wait because they can be loaded from the target while
2842 in target_wait. This makes remote debugging a bit more
2843 efficient for those targets that provide critical registers
2844 as part of their normal status mechanism. */
2846 registers_changed ();
2847 ecs->waiton_ptid = pid_to_ptid (-1);
2848 ecs->wp = &(ecs->ws);
2850 /* This is the old end of the while loop. Let everybody know we
2851 want to wait for the inferior some more and get called again
2853 ecs->wait_some_more = 1;
2856 /* Print why the inferior has stopped. We always print something when
2857 the inferior exits, or receives a signal. The rest of the cases are
2858 dealt with later on in normal_stop() and print_it_typical(). Ideally
2859 there should be a call to this function from handle_inferior_event()
2860 each time stop_stepping() is called.*/
2862 print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
2864 switch (stop_reason)
2867 /* We don't deal with these cases from handle_inferior_event()
2870 case END_STEPPING_RANGE:
2871 /* We are done with a step/next/si/ni command. */
2872 /* For now print nothing. */
2873 /* Print a message only if not in the middle of doing a "step n"
2874 operation for n > 1 */
2875 if (!step_multi || !stop_step)
2876 if (ui_out_is_mi_like_p (uiout))
2877 ui_out_field_string (uiout, "reason", "end-stepping-range");
2879 case BREAKPOINT_HIT:
2880 /* We found a breakpoint. */
2881 /* For now print nothing. */
2884 /* The inferior was terminated by a signal. */
2885 annotate_signalled ();
2886 if (ui_out_is_mi_like_p (uiout))
2887 ui_out_field_string (uiout, "reason", "exited-signalled");
2888 ui_out_text (uiout, "\nProgram terminated with signal ");
2889 annotate_signal_name ();
2890 ui_out_field_string (uiout, "signal-name",
2891 target_signal_to_name (stop_info));
2892 annotate_signal_name_end ();
2893 ui_out_text (uiout, ", ");
2894 annotate_signal_string ();
2895 ui_out_field_string (uiout, "signal-meaning",
2896 target_signal_to_string (stop_info));
2897 annotate_signal_string_end ();
2898 ui_out_text (uiout, ".\n");
2899 ui_out_text (uiout, "The program no longer exists.\n");
2902 /* The inferior program is finished. */
2903 annotate_exited (stop_info);
2906 if (ui_out_is_mi_like_p (uiout))
2907 ui_out_field_string (uiout, "reason", "exited");
2908 ui_out_text (uiout, "\nProgram exited with code ");
2909 ui_out_field_fmt (uiout, "exit-code", "0%o",
2910 (unsigned int) stop_info);
2911 ui_out_text (uiout, ".\n");
2915 if (ui_out_is_mi_like_p (uiout))
2916 ui_out_field_string (uiout, "reason", "exited-normally");
2917 ui_out_text (uiout, "\nProgram exited normally.\n");
2920 case SIGNAL_RECEIVED:
2921 /* Signal received. The signal table tells us to print about
2924 ui_out_text (uiout, "\nProgram received signal ");
2925 annotate_signal_name ();
2926 if (ui_out_is_mi_like_p (uiout))
2927 ui_out_field_string (uiout, "reason", "signal-received");
2928 ui_out_field_string (uiout, "signal-name",
2929 target_signal_to_name (stop_info));
2930 annotate_signal_name_end ();
2931 ui_out_text (uiout, ", ");
2932 annotate_signal_string ();
2933 ui_out_field_string (uiout, "signal-meaning",
2934 target_signal_to_string (stop_info));
2935 annotate_signal_string_end ();
2936 ui_out_text (uiout, ".\n");
2939 internal_error (__FILE__, __LINE__,
2940 "print_stop_reason: unrecognized enum value");
2946 /* Here to return control to GDB when the inferior stops for real.
2947 Print appropriate messages, remove breakpoints, give terminal our modes.
2949 STOP_PRINT_FRAME nonzero means print the executing frame
2950 (pc, function, args, file, line number and line text).
2951 BREAKPOINTS_FAILED nonzero means stop was due to error
2952 attempting to insert breakpoints. */
2957 /* As with the notification of thread events, we want to delay
2958 notifying the user that we've switched thread context until
2959 the inferior actually stops.
2961 (Note that there's no point in saying anything if the inferior
2963 if (!ptid_equal (previous_inferior_ptid, inferior_ptid)
2964 && target_has_execution)
2966 target_terminal_ours_for_output ();
2967 printf_filtered ("[Switching to %s]\n",
2968 target_pid_or_tid_to_str (inferior_ptid));
2969 previous_inferior_ptid = inferior_ptid;
2972 /* Make sure that the current_frame's pc is correct. This
2973 is a correction for setting up the frame info before doing
2974 DECR_PC_AFTER_BREAK */
2975 if (target_has_execution)
2976 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
2977 DECR_PC_AFTER_BREAK, the program counter can change. Ask the
2978 frame code to check for this and sort out any resultant mess.
2979 DECR_PC_AFTER_BREAK needs to just go away. */
2980 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
2982 if (target_has_execution && breakpoints_inserted)
2984 if (remove_breakpoints ())
2986 target_terminal_ours_for_output ();
2987 printf_filtered ("Cannot remove breakpoints because ");
2988 printf_filtered ("program is no longer writable.\n");
2989 printf_filtered ("It might be running in another process.\n");
2990 printf_filtered ("Further execution is probably impossible.\n");
2993 breakpoints_inserted = 0;
2995 /* Delete the breakpoint we stopped at, if it wants to be deleted.
2996 Delete any breakpoint that is to be deleted at the next stop. */
2998 breakpoint_auto_delete (stop_bpstat);
3000 /* If an auto-display called a function and that got a signal,
3001 delete that auto-display to avoid an infinite recursion. */
3003 if (stopped_by_random_signal)
3004 disable_current_display ();
3006 /* Don't print a message if in the middle of doing a "step n"
3007 operation for n > 1 */
3008 if (step_multi && stop_step)
3011 target_terminal_ours ();
3013 /* Look up the hook_stop and run it (CLI internally handles problem
3014 of stop_command's pre-hook not existing). */
3016 catch_errors (hook_stop_stub, stop_command,
3017 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3019 if (!target_has_stack)
3025 /* Select innermost stack frame - i.e., current frame is frame 0,
3026 and current location is based on that.
3027 Don't do this on return from a stack dummy routine,
3028 or if the program has exited. */
3030 if (!stop_stack_dummy)
3032 select_frame (get_current_frame ());
3034 /* Print current location without a level number, if
3035 we have changed functions or hit a breakpoint.
3036 Print source line if we have one.
3037 bpstat_print() contains the logic deciding in detail
3038 what to print, based on the event(s) that just occurred. */
3040 if (stop_print_frame && deprecated_selected_frame)
3044 int do_frame_printing = 1;
3046 bpstat_ret = bpstat_print (stop_bpstat);
3050 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3051 (or should) carry around the function and does (or
3052 should) use that when doing a frame comparison. */
3054 && frame_id_eq (step_frame_id,
3055 get_frame_id (get_current_frame ()))
3056 && step_start_function == find_pc_function (stop_pc))
3057 source_flag = SRC_LINE; /* finished step, just print source line */
3059 source_flag = SRC_AND_LOC; /* print location and source line */
3061 case PRINT_SRC_AND_LOC:
3062 source_flag = SRC_AND_LOC; /* print location and source line */
3064 case PRINT_SRC_ONLY:
3065 source_flag = SRC_LINE;
3068 source_flag = SRC_LINE; /* something bogus */
3069 do_frame_printing = 0;
3072 internal_error (__FILE__, __LINE__, "Unknown value.");
3074 /* For mi, have the same behavior every time we stop:
3075 print everything but the source line. */
3076 if (ui_out_is_mi_like_p (uiout))
3077 source_flag = LOC_AND_ADDRESS;
3079 if (ui_out_is_mi_like_p (uiout))
3080 ui_out_field_int (uiout, "thread-id",
3081 pid_to_thread_id (inferior_ptid));
3082 /* The behavior of this routine with respect to the source
3084 SRC_LINE: Print only source line
3085 LOCATION: Print only location
3086 SRC_AND_LOC: Print location and source line */
3087 if (do_frame_printing)
3088 print_stack_frame (deprecated_selected_frame, -1, source_flag);
3090 /* Display the auto-display expressions. */
3095 /* Save the function value return registers, if we care.
3096 We might be about to restore their previous contents. */
3097 if (proceed_to_finish)
3098 /* NB: The copy goes through to the target picking up the value of
3099 all the registers. */
3100 regcache_cpy (stop_registers, current_regcache);
3102 if (stop_stack_dummy)
3104 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3105 ends with a setting of the current frame, so we can use that
3107 frame_pop (get_current_frame ());
3108 /* Set stop_pc to what it was before we called the function.
3109 Can't rely on restore_inferior_status because that only gets
3110 called if we don't stop in the called function. */
3111 stop_pc = read_pc ();
3112 select_frame (get_current_frame ());
3116 annotate_stopped ();
3117 observer_notify_normal_stop ();
3121 hook_stop_stub (void *cmd)
3123 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
3128 signal_stop_state (int signo)
3130 return signal_stop[signo];
3134 signal_print_state (int signo)
3136 return signal_print[signo];
3140 signal_pass_state (int signo)
3142 return signal_program[signo];
3146 signal_stop_update (int signo, int state)
3148 int ret = signal_stop[signo];
3149 signal_stop[signo] = state;
3154 signal_print_update (int signo, int state)
3156 int ret = signal_print[signo];
3157 signal_print[signo] = state;
3162 signal_pass_update (int signo, int state)
3164 int ret = signal_program[signo];
3165 signal_program[signo] = state;
3170 sig_print_header (void)
3173 Signal Stop\tPrint\tPass to program\tDescription\n");
3177 sig_print_info (enum target_signal oursig)
3179 char *name = target_signal_to_name (oursig);
3180 int name_padding = 13 - strlen (name);
3182 if (name_padding <= 0)
3185 printf_filtered ("%s", name);
3186 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
3187 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3188 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3189 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3190 printf_filtered ("%s\n", target_signal_to_string (oursig));
3193 /* Specify how various signals in the inferior should be handled. */
3196 handle_command (char *args, int from_tty)
3199 int digits, wordlen;
3200 int sigfirst, signum, siglast;
3201 enum target_signal oursig;
3204 unsigned char *sigs;
3205 struct cleanup *old_chain;
3209 error_no_arg ("signal to handle");
3212 /* Allocate and zero an array of flags for which signals to handle. */
3214 nsigs = (int) TARGET_SIGNAL_LAST;
3215 sigs = (unsigned char *) alloca (nsigs);
3216 memset (sigs, 0, nsigs);
3218 /* Break the command line up into args. */
3220 argv = buildargv (args);
3225 old_chain = make_cleanup_freeargv (argv);
3227 /* Walk through the args, looking for signal oursigs, signal names, and
3228 actions. Signal numbers and signal names may be interspersed with
3229 actions, with the actions being performed for all signals cumulatively
3230 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3232 while (*argv != NULL)
3234 wordlen = strlen (*argv);
3235 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3239 sigfirst = siglast = -1;
3241 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3243 /* Apply action to all signals except those used by the
3244 debugger. Silently skip those. */
3247 siglast = nsigs - 1;
3249 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3251 SET_SIGS (nsigs, sigs, signal_stop);
3252 SET_SIGS (nsigs, sigs, signal_print);
3254 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3256 UNSET_SIGS (nsigs, sigs, signal_program);
3258 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3260 SET_SIGS (nsigs, sigs, signal_print);
3262 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3264 SET_SIGS (nsigs, sigs, signal_program);
3266 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3268 UNSET_SIGS (nsigs, sigs, signal_stop);
3270 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3272 SET_SIGS (nsigs, sigs, signal_program);
3274 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3276 UNSET_SIGS (nsigs, sigs, signal_print);
3277 UNSET_SIGS (nsigs, sigs, signal_stop);
3279 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3281 UNSET_SIGS (nsigs, sigs, signal_program);
3283 else if (digits > 0)
3285 /* It is numeric. The numeric signal refers to our own
3286 internal signal numbering from target.h, not to host/target
3287 signal number. This is a feature; users really should be
3288 using symbolic names anyway, and the common ones like
3289 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3291 sigfirst = siglast = (int)
3292 target_signal_from_command (atoi (*argv));
3293 if ((*argv)[digits] == '-')
3296 target_signal_from_command (atoi ((*argv) + digits + 1));
3298 if (sigfirst > siglast)
3300 /* Bet he didn't figure we'd think of this case... */
3308 oursig = target_signal_from_name (*argv);
3309 if (oursig != TARGET_SIGNAL_UNKNOWN)
3311 sigfirst = siglast = (int) oursig;
3315 /* Not a number and not a recognized flag word => complain. */
3316 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3320 /* If any signal numbers or symbol names were found, set flags for
3321 which signals to apply actions to. */
3323 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3325 switch ((enum target_signal) signum)
3327 case TARGET_SIGNAL_TRAP:
3328 case TARGET_SIGNAL_INT:
3329 if (!allsigs && !sigs[signum])
3331 if (query ("%s is used by the debugger.\n\
3332 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum)))
3338 printf_unfiltered ("Not confirmed, unchanged.\n");
3339 gdb_flush (gdb_stdout);
3343 case TARGET_SIGNAL_0:
3344 case TARGET_SIGNAL_DEFAULT:
3345 case TARGET_SIGNAL_UNKNOWN:
3346 /* Make sure that "all" doesn't print these. */
3357 target_notice_signals (inferior_ptid);
3361 /* Show the results. */
3362 sig_print_header ();
3363 for (signum = 0; signum < nsigs; signum++)
3367 sig_print_info (signum);
3372 do_cleanups (old_chain);
3376 xdb_handle_command (char *args, int from_tty)
3379 struct cleanup *old_chain;
3381 /* Break the command line up into args. */
3383 argv = buildargv (args);
3388 old_chain = make_cleanup_freeargv (argv);
3389 if (argv[1] != (char *) NULL)
3394 bufLen = strlen (argv[0]) + 20;
3395 argBuf = (char *) xmalloc (bufLen);
3399 enum target_signal oursig;
3401 oursig = target_signal_from_name (argv[0]);
3402 memset (argBuf, 0, bufLen);
3403 if (strcmp (argv[1], "Q") == 0)
3404 sprintf (argBuf, "%s %s", argv[0], "noprint");
3407 if (strcmp (argv[1], "s") == 0)
3409 if (!signal_stop[oursig])
3410 sprintf (argBuf, "%s %s", argv[0], "stop");
3412 sprintf (argBuf, "%s %s", argv[0], "nostop");
3414 else if (strcmp (argv[1], "i") == 0)
3416 if (!signal_program[oursig])
3417 sprintf (argBuf, "%s %s", argv[0], "pass");
3419 sprintf (argBuf, "%s %s", argv[0], "nopass");
3421 else if (strcmp (argv[1], "r") == 0)
3423 if (!signal_print[oursig])
3424 sprintf (argBuf, "%s %s", argv[0], "print");
3426 sprintf (argBuf, "%s %s", argv[0], "noprint");
3432 handle_command (argBuf, from_tty);
3434 printf_filtered ("Invalid signal handling flag.\n");
3439 do_cleanups (old_chain);
3442 /* Print current contents of the tables set by the handle command.
3443 It is possible we should just be printing signals actually used
3444 by the current target (but for things to work right when switching
3445 targets, all signals should be in the signal tables). */
3448 signals_info (char *signum_exp, int from_tty)
3450 enum target_signal oursig;
3451 sig_print_header ();
3455 /* First see if this is a symbol name. */
3456 oursig = target_signal_from_name (signum_exp);
3457 if (oursig == TARGET_SIGNAL_UNKNOWN)
3459 /* No, try numeric. */
3461 target_signal_from_command (parse_and_eval_long (signum_exp));
3463 sig_print_info (oursig);
3467 printf_filtered ("\n");
3468 /* These ugly casts brought to you by the native VAX compiler. */
3469 for (oursig = TARGET_SIGNAL_FIRST;
3470 (int) oursig < (int) TARGET_SIGNAL_LAST;
3471 oursig = (enum target_signal) ((int) oursig + 1))
3475 if (oursig != TARGET_SIGNAL_UNKNOWN
3476 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
3477 sig_print_info (oursig);
3480 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3483 struct inferior_status
3485 enum target_signal stop_signal;
3489 int stop_stack_dummy;
3490 int stopped_by_random_signal;
3492 CORE_ADDR step_range_start;
3493 CORE_ADDR step_range_end;
3494 struct frame_id step_frame_id;
3495 enum step_over_calls_kind step_over_calls;
3496 CORE_ADDR step_resume_break_address;
3497 int stop_after_trap;
3498 int stop_soon_quietly;
3499 struct regcache *stop_registers;
3501 /* These are here because if call_function_by_hand has written some
3502 registers and then decides to call error(), we better not have changed
3504 struct regcache *registers;
3506 /* A frame unique identifier. */
3507 struct frame_id selected_frame_id;
3509 int breakpoint_proceeded;
3510 int restore_stack_info;
3511 int proceed_to_finish;
3515 write_inferior_status_register (struct inferior_status *inf_status, int regno,
3518 int size = REGISTER_RAW_SIZE (regno);
3519 void *buf = alloca (size);
3520 store_signed_integer (buf, size, val);
3521 regcache_raw_write (inf_status->registers, regno, buf);
3524 /* Save all of the information associated with the inferior<==>gdb
3525 connection. INF_STATUS is a pointer to a "struct inferior_status"
3526 (defined in inferior.h). */
3528 struct inferior_status *
3529 save_inferior_status (int restore_stack_info)
3531 struct inferior_status *inf_status = XMALLOC (struct inferior_status);
3533 inf_status->stop_signal = stop_signal;
3534 inf_status->stop_pc = stop_pc;
3535 inf_status->stop_step = stop_step;
3536 inf_status->stop_stack_dummy = stop_stack_dummy;
3537 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3538 inf_status->trap_expected = trap_expected;
3539 inf_status->step_range_start = step_range_start;
3540 inf_status->step_range_end = step_range_end;
3541 inf_status->step_frame_id = step_frame_id;
3542 inf_status->step_over_calls = step_over_calls;
3543 inf_status->stop_after_trap = stop_after_trap;
3544 inf_status->stop_soon_quietly = stop_soon_quietly;
3545 /* Save original bpstat chain here; replace it with copy of chain.
3546 If caller's caller is walking the chain, they'll be happier if we
3547 hand them back the original chain when restore_inferior_status is
3549 inf_status->stop_bpstat = stop_bpstat;
3550 stop_bpstat = bpstat_copy (stop_bpstat);
3551 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3552 inf_status->restore_stack_info = restore_stack_info;
3553 inf_status->proceed_to_finish = proceed_to_finish;
3555 inf_status->stop_registers = regcache_dup_no_passthrough (stop_registers);
3557 inf_status->registers = regcache_dup (current_regcache);
3559 inf_status->selected_frame_id = get_frame_id (deprecated_selected_frame);
3564 restore_selected_frame (void *args)
3566 struct frame_id *fid = (struct frame_id *) args;
3567 struct frame_info *frame;
3569 frame = frame_find_by_id (*fid);
3571 /* If inf_status->selected_frame_id is NULL, there was no previously
3575 warning ("Unable to restore previously selected frame.\n");
3579 select_frame (frame);
3585 restore_inferior_status (struct inferior_status *inf_status)
3587 stop_signal = inf_status->stop_signal;
3588 stop_pc = inf_status->stop_pc;
3589 stop_step = inf_status->stop_step;
3590 stop_stack_dummy = inf_status->stop_stack_dummy;
3591 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3592 trap_expected = inf_status->trap_expected;
3593 step_range_start = inf_status->step_range_start;
3594 step_range_end = inf_status->step_range_end;
3595 step_frame_id = inf_status->step_frame_id;
3596 step_over_calls = inf_status->step_over_calls;
3597 stop_after_trap = inf_status->stop_after_trap;
3598 stop_soon_quietly = inf_status->stop_soon_quietly;
3599 bpstat_clear (&stop_bpstat);
3600 stop_bpstat = inf_status->stop_bpstat;
3601 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3602 proceed_to_finish = inf_status->proceed_to_finish;
3604 /* FIXME: Is the restore of stop_registers always needed. */
3605 regcache_xfree (stop_registers);
3606 stop_registers = inf_status->stop_registers;
3608 /* The inferior can be gone if the user types "print exit(0)"
3609 (and perhaps other times). */
3610 if (target_has_execution)
3611 /* NB: The register write goes through to the target. */
3612 regcache_cpy (current_regcache, inf_status->registers);
3613 regcache_xfree (inf_status->registers);
3615 /* FIXME: If we are being called after stopping in a function which
3616 is called from gdb, we should not be trying to restore the
3617 selected frame; it just prints a spurious error message (The
3618 message is useful, however, in detecting bugs in gdb (like if gdb
3619 clobbers the stack)). In fact, should we be restoring the
3620 inferior status at all in that case? . */
3622 if (target_has_stack && inf_status->restore_stack_info)
3624 /* The point of catch_errors is that if the stack is clobbered,
3625 walking the stack might encounter a garbage pointer and
3626 error() trying to dereference it. */
3628 (restore_selected_frame, &inf_status->selected_frame_id,
3629 "Unable to restore previously selected frame:\n",
3630 RETURN_MASK_ERROR) == 0)
3631 /* Error in restoring the selected frame. Select the innermost
3633 select_frame (get_current_frame ());
3641 do_restore_inferior_status_cleanup (void *sts)
3643 restore_inferior_status (sts);
3647 make_cleanup_restore_inferior_status (struct inferior_status *inf_status)
3649 return make_cleanup (do_restore_inferior_status_cleanup, inf_status);
3653 discard_inferior_status (struct inferior_status *inf_status)
3655 /* See save_inferior_status for info on stop_bpstat. */
3656 bpstat_clear (&inf_status->stop_bpstat);
3657 regcache_xfree (inf_status->registers);
3658 regcache_xfree (inf_status->stop_registers);
3663 inferior_has_forked (int pid, int *child_pid)
3665 struct target_waitstatus last;
3668 get_last_target_status (&last_ptid, &last);
3670 if (last.kind != TARGET_WAITKIND_FORKED)
3673 if (ptid_get_pid (last_ptid) != pid)
3676 *child_pid = last.value.related_pid;
3681 inferior_has_vforked (int pid, int *child_pid)
3683 struct target_waitstatus last;
3686 get_last_target_status (&last_ptid, &last);
3688 if (last.kind != TARGET_WAITKIND_VFORKED)
3691 if (ptid_get_pid (last_ptid) != pid)
3694 *child_pid = last.value.related_pid;
3699 inferior_has_execd (int pid, char **execd_pathname)
3701 struct target_waitstatus last;
3704 get_last_target_status (&last_ptid, &last);
3706 if (last.kind != TARGET_WAITKIND_EXECD)
3709 if (ptid_get_pid (last_ptid) != pid)
3712 *execd_pathname = xstrdup (last.value.execd_pathname);
3716 /* Oft used ptids */
3718 ptid_t minus_one_ptid;
3720 /* Create a ptid given the necessary PID, LWP, and TID components. */
3723 ptid_build (int pid, long lwp, long tid)
3733 /* Create a ptid from just a pid. */
3736 pid_to_ptid (int pid)
3738 return ptid_build (pid, 0, 0);
3741 /* Fetch the pid (process id) component from a ptid. */
3744 ptid_get_pid (ptid_t ptid)
3749 /* Fetch the lwp (lightweight process) component from a ptid. */
3752 ptid_get_lwp (ptid_t ptid)
3757 /* Fetch the tid (thread id) component from a ptid. */
3760 ptid_get_tid (ptid_t ptid)
3765 /* ptid_equal() is used to test equality of two ptids. */
3768 ptid_equal (ptid_t ptid1, ptid_t ptid2)
3770 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
3771 && ptid1.tid == ptid2.tid);
3774 /* restore_inferior_ptid() will be used by the cleanup machinery
3775 to restore the inferior_ptid value saved in a call to
3776 save_inferior_ptid(). */
3779 restore_inferior_ptid (void *arg)
3781 ptid_t *saved_ptid_ptr = arg;
3782 inferior_ptid = *saved_ptid_ptr;
3786 /* Save the value of inferior_ptid so that it may be restored by a
3787 later call to do_cleanups(). Returns the struct cleanup pointer
3788 needed for later doing the cleanup. */
3791 save_inferior_ptid (void)
3793 ptid_t *saved_ptid_ptr;
3795 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
3796 *saved_ptid_ptr = inferior_ptid;
3797 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
3804 stop_registers = regcache_xmalloc (current_gdbarch);
3808 _initialize_infrun (void)
3811 register int numsigs;
3812 struct cmd_list_element *c;
3814 register_gdbarch_swap (&stop_registers, sizeof (stop_registers), NULL);
3815 register_gdbarch_swap (NULL, 0, build_infrun);
3817 add_info ("signals", signals_info,
3818 "What debugger does when program gets various signals.\n\
3819 Specify a signal as argument to print info on that signal only.");
3820 add_info_alias ("handle", "signals", 0);
3822 add_com ("handle", class_run, handle_command,
3823 concat ("Specify how to handle a signal.\n\
3824 Args are signals and actions to apply to those signals.\n\
3825 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3826 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3827 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3828 The special arg \"all\" is recognized to mean all signals except those\n\
3829 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3830 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3831 Stop means reenter debugger if this signal happens (implies print).\n\
3832 Print means print a message if this signal happens.\n\
3833 Pass means let program see this signal; otherwise program doesn't know.\n\
3834 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3835 Pass and Stop may be combined.", NULL));
3838 add_com ("lz", class_info, signals_info,
3839 "What debugger does when program gets various signals.\n\
3840 Specify a signal as argument to print info on that signal only.");
3841 add_com ("z", class_run, xdb_handle_command,
3842 concat ("Specify how to handle a signal.\n\
3843 Args are signals and actions to apply to those signals.\n\
3844 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3845 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3846 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3847 The special arg \"all\" is recognized to mean all signals except those\n\
3848 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3849 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3850 nopass), \"Q\" (noprint)\n\
3851 Stop means reenter debugger if this signal happens (implies print).\n\
3852 Print means print a message if this signal happens.\n\
3853 Pass means let program see this signal; otherwise program doesn't know.\n\
3854 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3855 Pass and Stop may be combined.", NULL));
3860 add_cmd ("stop", class_obscure, not_just_help_class_command, "There is no `stop' command, but you can set a hook on `stop'.\n\
3861 This allows you to set a list of commands to be run each time execution\n\
3862 of the program stops.", &cmdlist);
3864 numsigs = (int) TARGET_SIGNAL_LAST;
3865 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
3866 signal_print = (unsigned char *)
3867 xmalloc (sizeof (signal_print[0]) * numsigs);
3868 signal_program = (unsigned char *)
3869 xmalloc (sizeof (signal_program[0]) * numsigs);
3870 for (i = 0; i < numsigs; i++)
3873 signal_print[i] = 1;
3874 signal_program[i] = 1;
3877 /* Signals caused by debugger's own actions
3878 should not be given to the program afterwards. */
3879 signal_program[TARGET_SIGNAL_TRAP] = 0;
3880 signal_program[TARGET_SIGNAL_INT] = 0;
3882 /* Signals that are not errors should not normally enter the debugger. */
3883 signal_stop[TARGET_SIGNAL_ALRM] = 0;
3884 signal_print[TARGET_SIGNAL_ALRM] = 0;
3885 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
3886 signal_print[TARGET_SIGNAL_VTALRM] = 0;
3887 signal_stop[TARGET_SIGNAL_PROF] = 0;
3888 signal_print[TARGET_SIGNAL_PROF] = 0;
3889 signal_stop[TARGET_SIGNAL_CHLD] = 0;
3890 signal_print[TARGET_SIGNAL_CHLD] = 0;
3891 signal_stop[TARGET_SIGNAL_IO] = 0;
3892 signal_print[TARGET_SIGNAL_IO] = 0;
3893 signal_stop[TARGET_SIGNAL_POLL] = 0;
3894 signal_print[TARGET_SIGNAL_POLL] = 0;
3895 signal_stop[TARGET_SIGNAL_URG] = 0;
3896 signal_print[TARGET_SIGNAL_URG] = 0;
3897 signal_stop[TARGET_SIGNAL_WINCH] = 0;
3898 signal_print[TARGET_SIGNAL_WINCH] = 0;
3900 /* These signals are used internally by user-level thread
3901 implementations. (See signal(5) on Solaris.) Like the above
3902 signals, a healthy program receives and handles them as part of
3903 its normal operation. */
3904 signal_stop[TARGET_SIGNAL_LWP] = 0;
3905 signal_print[TARGET_SIGNAL_LWP] = 0;
3906 signal_stop[TARGET_SIGNAL_WAITING] = 0;
3907 signal_print[TARGET_SIGNAL_WAITING] = 0;
3908 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
3909 signal_print[TARGET_SIGNAL_CANCEL] = 0;
3913 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
3914 (char *) &stop_on_solib_events,
3915 "Set stopping for shared library events.\n\
3916 If nonzero, gdb will give control to the user when the dynamic linker\n\
3917 notifies gdb of shared library events. The most common event of interest\n\
3918 to the user would be loading/unloading of a new library.\n", &setlist), &showlist);
3921 c = add_set_enum_cmd ("follow-fork-mode",
3923 follow_fork_mode_kind_names, &follow_fork_mode_string,
3924 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
3925 kernel problem. It's also not terribly useful without a GUI to
3926 help the user drive two debuggers. So for now, I'm disabling
3927 the "both" option. */
3928 /* "Set debugger response to a program call of fork \
3930 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3931 parent - the original process is debugged after a fork\n\
3932 child - the new process is debugged after a fork\n\
3933 both - both the parent and child are debugged after a fork\n\
3934 ask - the debugger will ask for one of the above choices\n\
3935 For \"both\", another copy of the debugger will be started to follow\n\
3936 the new child process. The original debugger will continue to follow\n\
3937 the original parent process. To distinguish their prompts, the\n\
3938 debugger copy's prompt will be changed.\n\
3939 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3940 By default, the debugger will follow the parent process.",
3942 "Set debugger response to a program call of fork \
3944 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3945 parent - the original process is debugged after a fork\n\
3946 child - the new process is debugged after a fork\n\
3947 ask - the debugger will ask for one of the above choices\n\
3948 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3949 By default, the debugger will follow the parent process.", &setlist);
3950 add_show_from_set (c, &showlist);
3952 c = add_set_enum_cmd ("scheduler-locking", class_run, scheduler_enums, /* array of string names */
3953 &scheduler_mode, /* current mode */
3954 "Set mode for locking scheduler during execution.\n\
3955 off == no locking (threads may preempt at any time)\n\
3956 on == full locking (no thread except the current thread may run)\n\
3957 step == scheduler locked during every single-step operation.\n\
3958 In this mode, no other thread may run during a step command.\n\
3959 Other threads may run while stepping over a function call ('next').", &setlist);
3961 set_cmd_sfunc (c, set_schedlock_func); /* traps on target vector */
3962 add_show_from_set (c, &showlist);
3964 c = add_set_cmd ("step-mode", class_run,
3965 var_boolean, (char *) &step_stop_if_no_debug,
3966 "Set mode of the step operation. When set, doing a step over a\n\
3967 function without debug line information will stop at the first\n\
3968 instruction of that function. Otherwise, the function is skipped and\n\
3969 the step command stops at a different source line.", &setlist);
3970 add_show_from_set (c, &showlist);
3972 /* ptid initializations */
3973 null_ptid = ptid_build (0, 0, 0);
3974 minus_one_ptid = ptid_build (-1, 0, 0);
3975 inferior_ptid = null_ptid;
3976 target_last_wait_ptid = minus_one_ptid;