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"
48 /* Prototypes for local functions */
50 static void signals_info (char *, int);
52 static void handle_command (char *, int);
54 static void sig_print_info (enum target_signal);
56 static void sig_print_header (void);
58 static void resume_cleanups (void *);
60 static int hook_stop_stub (void *);
62 static void delete_breakpoint_current_contents (void *);
64 static void set_follow_fork_mode_command (char *arg, int from_tty,
65 struct cmd_list_element *c);
67 static int restore_selected_frame (void *);
69 static void build_infrun (void);
71 static int follow_fork (void);
73 static void set_schedlock_func (char *args, int from_tty,
74 struct cmd_list_element *c);
76 struct execution_control_state;
78 static int currently_stepping (struct execution_control_state *ecs);
80 static void xdb_handle_command (char *args, int from_tty);
82 static int prepare_to_proceed (void);
84 void _initialize_infrun (void);
86 int inferior_ignoring_startup_exec_events = 0;
87 int inferior_ignoring_leading_exec_events = 0;
89 /* When set, stop the 'step' command if we enter a function which has
90 no line number information. The normal behavior is that we step
91 over such function. */
92 int step_stop_if_no_debug = 0;
94 /* In asynchronous mode, but simulating synchronous execution. */
96 int sync_execution = 0;
98 /* wait_for_inferior and normal_stop use this to notify the user
99 when the inferior stopped in a different thread than it had been
102 static ptid_t previous_inferior_ptid;
104 /* This is true for configurations that may follow through execl() and
105 similar functions. At present this is only true for HP-UX native. */
107 #ifndef MAY_FOLLOW_EXEC
108 #define MAY_FOLLOW_EXEC (0)
111 static int may_follow_exec = MAY_FOLLOW_EXEC;
113 /* If the program uses ELF-style shared libraries, then calls to
114 functions in shared libraries go through stubs, which live in a
115 table called the PLT (Procedure Linkage Table). The first time the
116 function is called, the stub sends control to the dynamic linker,
117 which looks up the function's real address, patches the stub so
118 that future calls will go directly to the function, and then passes
119 control to the function.
121 If we are stepping at the source level, we don't want to see any of
122 this --- we just want to skip over the stub and the dynamic linker.
123 The simple approach is to single-step until control leaves the
126 However, on some systems (e.g., Red Hat's 5.2 distribution) the
127 dynamic linker calls functions in the shared C library, so you
128 can't tell from the PC alone whether the dynamic linker is still
129 running. In this case, we use a step-resume breakpoint to get us
130 past the dynamic linker, as if we were using "next" to step over a
133 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
134 linker code or not. Normally, this means we single-step. However,
135 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
136 address where we can place a step-resume breakpoint to get past the
137 linker's symbol resolution function.
139 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
140 pretty portable way, by comparing the PC against the address ranges
141 of the dynamic linker's sections.
143 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
144 it depends on internal details of the dynamic linker. It's usually
145 not too hard to figure out where to put a breakpoint, but it
146 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
147 sanity checking. If it can't figure things out, returning zero and
148 getting the (possibly confusing) stepping behavior is better than
149 signalling an error, which will obscure the change in the
152 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
153 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
156 #ifndef SKIP_SOLIB_RESOLVER
157 #define SKIP_SOLIB_RESOLVER(pc) 0
160 /* This function returns TRUE if pc is the address of an instruction
161 that lies within the dynamic linker (such as the event hook, or the
164 This function must be used only when a dynamic linker event has
165 been caught, and the inferior is being stepped out of the hook, or
166 undefined results are guaranteed. */
168 #ifndef SOLIB_IN_DYNAMIC_LINKER
169 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
172 /* On MIPS16, a function that returns a floating point value may call
173 a library helper function to copy the return value to a floating point
174 register. The IGNORE_HELPER_CALL macro returns non-zero if we
175 should ignore (i.e. step over) this function call. */
176 #ifndef IGNORE_HELPER_CALL
177 #define IGNORE_HELPER_CALL(pc) 0
180 /* On some systems, the PC may be left pointing at an instruction that won't
181 actually be executed. This is usually indicated by a bit in the PSW. If
182 we find ourselves in such a state, then we step the target beyond the
183 nullified instruction before returning control to the user so as to avoid
186 #ifndef INSTRUCTION_NULLIFIED
187 #define INSTRUCTION_NULLIFIED 0
190 /* We can't step off a permanent breakpoint in the ordinary way, because we
191 can't remove it. Instead, we have to advance the PC to the next
192 instruction. This macro should expand to a pointer to a function that
193 does that, or zero if we have no such function. If we don't have a
194 definition for it, we have to report an error. */
195 #ifndef SKIP_PERMANENT_BREAKPOINT
196 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
198 default_skip_permanent_breakpoint (void)
201 The program is stopped at a permanent breakpoint, but GDB does not know\n\
202 how to step past a permanent breakpoint on this architecture. Try using\n\
203 a command like `return' or `jump' to continue execution.");
208 /* Convert the #defines into values. This is temporary until wfi control
209 flow is completely sorted out. */
211 #ifndef HAVE_STEPPABLE_WATCHPOINT
212 #define HAVE_STEPPABLE_WATCHPOINT 0
214 #undef HAVE_STEPPABLE_WATCHPOINT
215 #define HAVE_STEPPABLE_WATCHPOINT 1
218 #ifndef CANNOT_STEP_HW_WATCHPOINTS
219 #define CANNOT_STEP_HW_WATCHPOINTS 0
221 #undef CANNOT_STEP_HW_WATCHPOINTS
222 #define CANNOT_STEP_HW_WATCHPOINTS 1
225 /* Tables of how to react to signals; the user sets them. */
227 static unsigned char *signal_stop;
228 static unsigned char *signal_print;
229 static unsigned char *signal_program;
231 #define SET_SIGS(nsigs,sigs,flags) \
233 int signum = (nsigs); \
234 while (signum-- > 0) \
235 if ((sigs)[signum]) \
236 (flags)[signum] = 1; \
239 #define UNSET_SIGS(nsigs,sigs,flags) \
241 int signum = (nsigs); \
242 while (signum-- > 0) \
243 if ((sigs)[signum]) \
244 (flags)[signum] = 0; \
247 /* Value to pass to target_resume() to cause all threads to resume */
249 #define RESUME_ALL (pid_to_ptid (-1))
251 /* Command list pointer for the "stop" placeholder. */
253 static struct cmd_list_element *stop_command;
255 /* Nonzero if breakpoints are now inserted in the inferior. */
257 static int breakpoints_inserted;
259 /* Function inferior was in as of last step command. */
261 static struct symbol *step_start_function;
263 /* Nonzero if we are expecting a trace trap and should proceed from it. */
265 static int trap_expected;
268 /* Nonzero if we want to give control to the user when we're notified
269 of shared library events by the dynamic linker. */
270 static int stop_on_solib_events;
274 /* Nonzero if the next time we try to continue the inferior, it will
275 step one instruction and generate a spurious trace trap.
276 This is used to compensate for a bug in HP-UX. */
278 static int trap_expected_after_continue;
281 /* Nonzero means expecting a trace trap
282 and should stop the inferior and return silently when it happens. */
286 /* Nonzero means expecting a trap and caller will handle it themselves.
287 It is used after attach, due to attaching to a process;
288 when running in the shell before the child program has been exec'd;
289 and when running some kinds of remote stuff (FIXME?). */
291 enum stop_kind stop_soon;
293 /* Nonzero if proceed is being used for a "finish" command or a similar
294 situation when stop_registers should be saved. */
296 int proceed_to_finish;
298 /* Save register contents here when about to pop a stack dummy frame,
299 if-and-only-if proceed_to_finish is set.
300 Thus this contains the return value from the called function (assuming
301 values are returned in a register). */
303 struct regcache *stop_registers;
305 /* Nonzero if program stopped due to error trying to insert breakpoints. */
307 static int breakpoints_failed;
309 /* Nonzero after stop if current stack frame should be printed. */
311 static int stop_print_frame;
313 static struct breakpoint *step_resume_breakpoint = NULL;
314 static struct breakpoint *through_sigtramp_breakpoint = NULL;
316 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
317 interactions with an inferior that is running a kernel function
318 (aka, a system call or "syscall"). wait_for_inferior therefore
319 may have a need to know when the inferior is in a syscall. This
320 is a count of the number of inferior threads which are known to
321 currently be running in a syscall. */
322 static int number_of_threads_in_syscalls;
324 /* This is a cached copy of the pid/waitstatus of the last event
325 returned by target_wait()/target_wait_hook(). This information is
326 returned by get_last_target_status(). */
327 static ptid_t target_last_wait_ptid;
328 static struct target_waitstatus target_last_waitstatus;
330 /* This is used to remember when a fork, vfork or exec event
331 was caught by a catchpoint, and thus the event is to be
332 followed at the next resume of the inferior, and not
336 enum target_waitkind kind;
343 char *execd_pathname;
347 static const char follow_fork_mode_ask[] = "ask";
348 static const char follow_fork_mode_child[] = "child";
349 static const char follow_fork_mode_parent[] = "parent";
351 static const char *follow_fork_mode_kind_names[] = {
352 follow_fork_mode_ask,
353 follow_fork_mode_child,
354 follow_fork_mode_parent,
358 static const char *follow_fork_mode_string = follow_fork_mode_parent;
364 const char *follow_mode = follow_fork_mode_string;
365 int follow_child = (follow_mode == follow_fork_mode_child);
367 /* Or, did the user not know, and want us to ask? */
368 if (follow_fork_mode_string == follow_fork_mode_ask)
370 internal_error (__FILE__, __LINE__,
371 "follow_inferior_fork: \"ask\" mode not implemented");
372 /* follow_mode = follow_fork_mode_...; */
375 return target_follow_fork (follow_child);
379 follow_inferior_reset_breakpoints (void)
381 /* Was there a step_resume breakpoint? (There was if the user
382 did a "next" at the fork() call.) If so, explicitly reset its
385 step_resumes are a form of bp that are made to be per-thread.
386 Since we created the step_resume bp when the parent process
387 was being debugged, and now are switching to the child process,
388 from the breakpoint package's viewpoint, that's a switch of
389 "threads". We must update the bp's notion of which thread
390 it is for, or it'll be ignored when it triggers. */
392 if (step_resume_breakpoint)
393 breakpoint_re_set_thread (step_resume_breakpoint);
395 /* Reinsert all breakpoints in the child. The user may have set
396 breakpoints after catching the fork, in which case those
397 were never set in the child, but only in the parent. This makes
398 sure the inserted breakpoints match the breakpoint list. */
400 breakpoint_re_set ();
401 insert_breakpoints ();
404 /* EXECD_PATHNAME is assumed to be non-NULL. */
407 follow_exec (int pid, char *execd_pathname)
410 struct target_ops *tgt;
412 if (!may_follow_exec)
415 /* This is an exec event that we actually wish to pay attention to.
416 Refresh our symbol table to the newly exec'd program, remove any
419 If there are breakpoints, they aren't really inserted now,
420 since the exec() transformed our inferior into a fresh set
423 We want to preserve symbolic breakpoints on the list, since
424 we have hopes that they can be reset after the new a.out's
425 symbol table is read.
427 However, any "raw" breakpoints must be removed from the list
428 (e.g., the solib bp's), since their address is probably invalid
431 And, we DON'T want to call delete_breakpoints() here, since
432 that may write the bp's "shadow contents" (the instruction
433 value that was overwritten witha TRAP instruction). Since
434 we now have a new a.out, those shadow contents aren't valid. */
435 update_breakpoints_after_exec ();
437 /* If there was one, it's gone now. We cannot truly step-to-next
438 statement through an exec(). */
439 step_resume_breakpoint = NULL;
440 step_range_start = 0;
443 /* If there was one, it's gone now. */
444 through_sigtramp_breakpoint = NULL;
446 /* What is this a.out's name? */
447 printf_unfiltered ("Executing new program: %s\n", execd_pathname);
449 /* We've followed the inferior through an exec. Therefore, the
450 inferior has essentially been killed & reborn. */
452 /* First collect the run target in effect. */
453 tgt = find_run_target ();
454 /* If we can't find one, things are in a very strange state... */
456 error ("Could find run target to save before following exec");
458 gdb_flush (gdb_stdout);
459 target_mourn_inferior ();
460 inferior_ptid = pid_to_ptid (saved_pid);
461 /* Because mourn_inferior resets inferior_ptid. */
464 /* That a.out is now the one to use. */
465 exec_file_attach (execd_pathname, 0);
467 /* And also is where symbols can be found. */
468 symbol_file_add_main (execd_pathname, 0);
470 /* Reset the shared library package. This ensures that we get
471 a shlib event when the child reaches "_start", at which point
472 the dld will have had a chance to initialize the child. */
473 #if defined(SOLIB_RESTART)
476 #ifdef SOLIB_CREATE_INFERIOR_HOOK
477 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
480 /* Reinsert all breakpoints. (Those which were symbolic have
481 been reset to the proper address in the new a.out, thanks
482 to symbol_file_command...) */
483 insert_breakpoints ();
485 /* The next resume of this inferior should bring it to the shlib
486 startup breakpoints. (If the user had also set bp's on
487 "main" from the old (parent) process, then they'll auto-
488 matically get reset there in the new process.) */
491 /* Non-zero if we just simulating a single-step. This is needed
492 because we cannot remove the breakpoints in the inferior process
493 until after the `wait' in `wait_for_inferior'. */
494 static int singlestep_breakpoints_inserted_p = 0;
497 /* Things to clean up if we QUIT out of resume (). */
499 resume_cleanups (void *ignore)
504 static const char schedlock_off[] = "off";
505 static const char schedlock_on[] = "on";
506 static const char schedlock_step[] = "step";
507 static const char *scheduler_mode = schedlock_off;
508 static const char *scheduler_enums[] = {
516 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
518 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
519 the set command passed as a parameter. The clone operation will
520 include (BUG?) any ``set'' command callback, if present.
521 Commands like ``info set'' call all the ``show'' command
522 callbacks. Unfortunatly, for ``show'' commands cloned from
523 ``set'', this includes callbacks belonging to ``set'' commands.
524 Making this worse, this only occures if add_show_from_set() is
525 called after add_cmd_sfunc() (BUG?). */
526 if (cmd_type (c) == set_cmd)
527 if (!target_can_lock_scheduler)
529 scheduler_mode = schedlock_off;
530 error ("Target '%s' cannot support this command.", target_shortname);
535 /* Resume the inferior, but allow a QUIT. This is useful if the user
536 wants to interrupt some lengthy single-stepping operation
537 (for child processes, the SIGINT goes to the inferior, and so
538 we get a SIGINT random_signal, but for remote debugging and perhaps
539 other targets, that's not true).
541 STEP nonzero if we should step (zero to continue instead).
542 SIG is the signal to give the inferior (zero for none). */
544 resume (int step, enum target_signal sig)
546 int should_resume = 1;
547 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
550 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
553 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
554 over an instruction that causes a page fault without triggering
555 a hardware watchpoint. The kernel properly notices that it shouldn't
556 stop, because the hardware watchpoint is not triggered, but it forgets
557 the step request and continues the program normally.
558 Work around the problem by removing hardware watchpoints if a step is
559 requested, GDB will check for a hardware watchpoint trigger after the
561 if (CANNOT_STEP_HW_WATCHPOINTS && step && breakpoints_inserted)
562 remove_hw_watchpoints ();
565 /* Normally, by the time we reach `resume', the breakpoints are either
566 removed or inserted, as appropriate. The exception is if we're sitting
567 at a permanent breakpoint; we need to step over it, but permanent
568 breakpoints can't be removed. So we have to test for it here. */
569 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here)
570 SKIP_PERMANENT_BREAKPOINT ();
572 if (SOFTWARE_SINGLE_STEP_P () && step)
574 /* Do it the hard way, w/temp breakpoints */
575 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ );
576 /* ...and don't ask hardware to do it. */
578 /* and do not pull these breakpoints until after a `wait' in
579 `wait_for_inferior' */
580 singlestep_breakpoints_inserted_p = 1;
583 /* Handle any optimized stores to the inferior NOW... */
584 #ifdef DO_DEFERRED_STORES
588 /* If there were any forks/vforks/execs that were caught and are
589 now to be followed, then do so. */
590 switch (pending_follow.kind)
592 case TARGET_WAITKIND_FORKED:
593 case TARGET_WAITKIND_VFORKED:
594 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
599 case TARGET_WAITKIND_EXECD:
600 /* follow_exec is called as soon as the exec event is seen. */
601 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
608 /* Install inferior's terminal modes. */
609 target_terminal_inferior ();
615 resume_ptid = RESUME_ALL; /* Default */
617 if ((step || singlestep_breakpoints_inserted_p) &&
618 !breakpoints_inserted && breakpoint_here_p (read_pc ()))
620 /* Stepping past a breakpoint without inserting breakpoints.
621 Make sure only the current thread gets to step, so that
622 other threads don't sneak past breakpoints while they are
625 resume_ptid = inferior_ptid;
628 if ((scheduler_mode == schedlock_on) ||
629 (scheduler_mode == schedlock_step &&
630 (step || singlestep_breakpoints_inserted_p)))
632 /* User-settable 'scheduler' mode requires solo thread resume. */
633 resume_ptid = inferior_ptid;
636 if (CANNOT_STEP_BREAKPOINT)
638 /* Most targets can step a breakpoint instruction, thus
639 executing it normally. But if this one cannot, just
640 continue and we will hit it anyway. */
641 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
644 target_resume (resume_ptid, step, sig);
647 discard_cleanups (old_cleanups);
651 /* Clear out all variables saying what to do when inferior is continued.
652 First do this, then set the ones you want, then call `proceed'. */
655 clear_proceed_status (void)
658 step_range_start = 0;
660 step_frame_id = null_frame_id;
661 step_over_calls = STEP_OVER_UNDEBUGGABLE;
663 stop_soon = NO_STOP_QUIETLY;
664 proceed_to_finish = 0;
665 breakpoint_proceeded = 1; /* We're about to proceed... */
667 /* Discard any remaining commands or status from previous stop. */
668 bpstat_clear (&stop_bpstat);
671 /* This should be suitable for any targets that support threads. */
674 prepare_to_proceed (void)
677 struct target_waitstatus wait_status;
679 /* Get the last target status returned by target_wait(). */
680 get_last_target_status (&wait_ptid, &wait_status);
682 /* Make sure we were stopped either at a breakpoint, or because
684 if (wait_status.kind != TARGET_WAITKIND_STOPPED
685 || (wait_status.value.sig != TARGET_SIGNAL_TRAP &&
686 wait_status.value.sig != TARGET_SIGNAL_INT))
691 if (!ptid_equal (wait_ptid, minus_one_ptid)
692 && !ptid_equal (inferior_ptid, wait_ptid))
694 /* Switched over from WAIT_PID. */
695 CORE_ADDR wait_pc = read_pc_pid (wait_ptid);
697 if (wait_pc != read_pc ())
699 /* Switch back to WAIT_PID thread. */
700 inferior_ptid = wait_ptid;
702 /* FIXME: This stuff came from switch_to_thread() in
703 thread.c (which should probably be a public function). */
704 flush_cached_frames ();
705 registers_changed ();
707 select_frame (get_current_frame ());
710 /* We return 1 to indicate that there is a breakpoint here,
711 so we need to step over it before continuing to avoid
712 hitting it straight away. */
713 if (breakpoint_here_p (wait_pc))
721 /* Record the pc of the program the last time it stopped. This is
722 just used internally by wait_for_inferior, but need to be preserved
723 over calls to it and cleared when the inferior is started. */
724 static CORE_ADDR prev_pc;
726 /* Basic routine for continuing the program in various fashions.
728 ADDR is the address to resume at, or -1 for resume where stopped.
729 SIGGNAL is the signal to give it, or 0 for none,
730 or -1 for act according to how it stopped.
731 STEP is nonzero if should trap after one instruction.
732 -1 means return after that and print nothing.
733 You should probably set various step_... variables
734 before calling here, if you are stepping.
736 You should call clear_proceed_status before calling proceed. */
739 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
744 step_start_function = find_pc_function (read_pc ());
748 if (addr == (CORE_ADDR) -1)
750 /* If there is a breakpoint at the address we will resume at,
751 step one instruction before inserting breakpoints
752 so that we do not stop right away (and report a second
753 hit at this breakpoint). */
755 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
758 #ifndef STEP_SKIPS_DELAY
759 #define STEP_SKIPS_DELAY(pc) (0)
760 #define STEP_SKIPS_DELAY_P (0)
762 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
763 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
764 is slow (it needs to read memory from the target). */
765 if (STEP_SKIPS_DELAY_P
766 && breakpoint_here_p (read_pc () + 4)
767 && STEP_SKIPS_DELAY (read_pc ()))
775 /* In a multi-threaded task we may select another thread
776 and then continue or step.
778 But if the old thread was stopped at a breakpoint, it
779 will immediately cause another breakpoint stop without
780 any execution (i.e. it will report a breakpoint hit
781 incorrectly). So we must step over it first.
783 prepare_to_proceed checks the current thread against the thread
784 that reported the most recent event. If a step-over is required
785 it returns TRUE and sets the current thread to the old thread. */
786 if (prepare_to_proceed () && breakpoint_here_p (read_pc ()))
790 if (trap_expected_after_continue)
792 /* If (step == 0), a trap will be automatically generated after
793 the first instruction is executed. Force step one
794 instruction to clear this condition. This should not occur
795 if step is nonzero, but it is harmless in that case. */
797 trap_expected_after_continue = 0;
799 #endif /* HP_OS_BUG */
802 /* We will get a trace trap after one instruction.
803 Continue it automatically and insert breakpoints then. */
807 insert_breakpoints ();
808 /* If we get here there was no call to error() in
809 insert breakpoints -- so they were inserted. */
810 breakpoints_inserted = 1;
813 if (siggnal != TARGET_SIGNAL_DEFAULT)
814 stop_signal = siggnal;
815 /* If this signal should not be seen by program,
816 give it zero. Used for debugging signals. */
817 else if (!signal_program[stop_signal])
818 stop_signal = TARGET_SIGNAL_0;
820 annotate_starting ();
822 /* Make sure that output from GDB appears before output from the
824 gdb_flush (gdb_stdout);
826 /* Refresh prev_pc value just prior to resuming. This used to be
827 done in stop_stepping, however, setting prev_pc there did not handle
828 scenarios such as inferior function calls or returning from
829 a function via the return command. In those cases, the prev_pc
830 value was not set properly for subsequent commands. The prev_pc value
831 is used to initialize the starting line number in the ecs. With an
832 invalid value, the gdb next command ends up stopping at the position
833 represented by the next line table entry past our start position.
834 On platforms that generate one line table entry per line, this
835 is not a problem. However, on the ia64, the compiler generates
836 extraneous line table entries that do not increase the line number.
837 When we issue the gdb next command on the ia64 after an inferior call
838 or a return command, we often end up a few instructions forward, still
839 within the original line we started.
841 An attempt was made to have init_execution_control_state () refresh
842 the prev_pc value before calculating the line number. This approach
843 did not work because on platforms that use ptrace, the pc register
844 cannot be read unless the inferior is stopped. At that point, we
845 are not guaranteed the inferior is stopped and so the read_pc ()
846 call can fail. Setting the prev_pc value here ensures the value is
847 updated correctly when the inferior is stopped. */
848 prev_pc = read_pc ();
850 /* Resume inferior. */
851 resume (oneproc || step || bpstat_should_step (), stop_signal);
853 /* Wait for it to stop (if not standalone)
854 and in any case decode why it stopped, and act accordingly. */
855 /* Do this only if we are not using the event loop, or if the target
856 does not support asynchronous execution. */
857 if (!event_loop_p || !target_can_async_p ())
859 wait_for_inferior ();
865 /* Start remote-debugging of a machine over a serial link. */
871 init_wait_for_inferior ();
872 stop_soon = STOP_QUIETLY;
875 /* Always go on waiting for the target, regardless of the mode. */
876 /* FIXME: cagney/1999-09-23: At present it isn't possible to
877 indicate to wait_for_inferior that a target should timeout if
878 nothing is returned (instead of just blocking). Because of this,
879 targets expecting an immediate response need to, internally, set
880 things up so that the target_wait() is forced to eventually
882 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
883 differentiate to its caller what the state of the target is after
884 the initial open has been performed. Here we're assuming that
885 the target has stopped. It should be possible to eventually have
886 target_open() return to the caller an indication that the target
887 is currently running and GDB state should be set to the same as
889 wait_for_inferior ();
893 /* Initialize static vars when a new inferior begins. */
896 init_wait_for_inferior (void)
898 /* These are meaningless until the first time through wait_for_inferior. */
902 trap_expected_after_continue = 0;
904 breakpoints_inserted = 0;
905 breakpoint_init_inferior (inf_starting);
907 /* Don't confuse first call to proceed(). */
908 stop_signal = TARGET_SIGNAL_0;
910 /* The first resume is not following a fork/vfork/exec. */
911 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
913 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
914 number_of_threads_in_syscalls = 0;
916 clear_proceed_status ();
920 delete_breakpoint_current_contents (void *arg)
922 struct breakpoint **breakpointp = (struct breakpoint **) arg;
923 if (*breakpointp != NULL)
925 delete_breakpoint (*breakpointp);
930 /* This enum encodes possible reasons for doing a target_wait, so that
931 wfi can call target_wait in one place. (Ultimately the call will be
932 moved out of the infinite loop entirely.) */
936 infwait_normal_state,
937 infwait_thread_hop_state,
938 infwait_nullified_state,
939 infwait_nonstep_watch_state
942 /* Why did the inferior stop? Used to print the appropriate messages
943 to the interface from within handle_inferior_event(). */
944 enum inferior_stop_reason
946 /* We don't know why. */
948 /* Step, next, nexti, stepi finished. */
950 /* Found breakpoint. */
952 /* Inferior terminated by signal. */
954 /* Inferior exited. */
956 /* Inferior received signal, and user asked to be notified. */
960 /* This structure contains what used to be local variables in
961 wait_for_inferior. Probably many of them can return to being
962 locals in handle_inferior_event. */
964 struct execution_control_state
966 struct target_waitstatus ws;
967 struct target_waitstatus *wp;
970 CORE_ADDR stop_func_start;
971 CORE_ADDR stop_func_end;
972 char *stop_func_name;
973 struct symtab_and_line sal;
974 int remove_breakpoints_on_following_step;
976 struct symtab *current_symtab;
977 int handling_longjmp; /* FIXME */
979 ptid_t saved_inferior_ptid;
981 int stepping_through_solib_after_catch;
982 bpstat stepping_through_solib_catchpoints;
983 int enable_hw_watchpoints_after_wait;
984 int stepping_through_sigtramp;
985 int new_thread_event;
986 struct target_waitstatus tmpstatus;
987 enum infwait_states infwait_state;
992 void init_execution_control_state (struct execution_control_state *ecs);
994 void handle_inferior_event (struct execution_control_state *ecs);
996 static void check_sigtramp2 (struct execution_control_state *ecs);
997 static void step_into_function (struct execution_control_state *ecs);
998 static void step_over_function (struct execution_control_state *ecs);
999 static void stop_stepping (struct execution_control_state *ecs);
1000 static void prepare_to_wait (struct execution_control_state *ecs);
1001 static void keep_going (struct execution_control_state *ecs);
1002 static void print_stop_reason (enum inferior_stop_reason stop_reason,
1005 /* Wait for control to return from inferior to debugger.
1006 If inferior gets a signal, we may decide to start it up again
1007 instead of returning. That is why there is a loop in this function.
1008 When this function actually returns it means the inferior
1009 should be left stopped and GDB should read more commands. */
1012 wait_for_inferior (void)
1014 struct cleanup *old_cleanups;
1015 struct execution_control_state ecss;
1016 struct execution_control_state *ecs;
1018 old_cleanups = make_cleanup (delete_step_resume_breakpoint,
1019 &step_resume_breakpoint);
1020 make_cleanup (delete_breakpoint_current_contents,
1021 &through_sigtramp_breakpoint);
1023 /* wfi still stays in a loop, so it's OK just to take the address of
1024 a local to get the ecs pointer. */
1027 /* Fill in with reasonable starting values. */
1028 init_execution_control_state (ecs);
1030 /* We'll update this if & when we switch to a new thread. */
1031 previous_inferior_ptid = inferior_ptid;
1033 overlay_cache_invalid = 1;
1035 /* We have to invalidate the registers BEFORE calling target_wait
1036 because they can be loaded from the target while in target_wait.
1037 This makes remote debugging a bit more efficient for those
1038 targets that provide critical registers as part of their normal
1039 status mechanism. */
1041 registers_changed ();
1045 if (target_wait_hook)
1046 ecs->ptid = target_wait_hook (ecs->waiton_ptid, ecs->wp);
1048 ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp);
1050 /* Now figure out what to do with the result of the result. */
1051 handle_inferior_event (ecs);
1053 if (!ecs->wait_some_more)
1056 do_cleanups (old_cleanups);
1059 /* Asynchronous version of wait_for_inferior. It is called by the
1060 event loop whenever a change of state is detected on the file
1061 descriptor corresponding to the target. It can be called more than
1062 once to complete a single execution command. In such cases we need
1063 to keep the state in a global variable ASYNC_ECSS. If it is the
1064 last time that this function is called for a single execution
1065 command, then report to the user that the inferior has stopped, and
1066 do the necessary cleanups. */
1068 struct execution_control_state async_ecss;
1069 struct execution_control_state *async_ecs;
1072 fetch_inferior_event (void *client_data)
1074 static struct cleanup *old_cleanups;
1076 async_ecs = &async_ecss;
1078 if (!async_ecs->wait_some_more)
1080 old_cleanups = make_exec_cleanup (delete_step_resume_breakpoint,
1081 &step_resume_breakpoint);
1082 make_exec_cleanup (delete_breakpoint_current_contents,
1083 &through_sigtramp_breakpoint);
1085 /* Fill in with reasonable starting values. */
1086 init_execution_control_state (async_ecs);
1088 /* We'll update this if & when we switch to a new thread. */
1089 previous_inferior_ptid = inferior_ptid;
1091 overlay_cache_invalid = 1;
1093 /* We have to invalidate the registers BEFORE calling target_wait
1094 because they can be loaded from the target while in target_wait.
1095 This makes remote debugging a bit more efficient for those
1096 targets that provide critical registers as part of their normal
1097 status mechanism. */
1099 registers_changed ();
1102 if (target_wait_hook)
1104 target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp);
1106 async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp);
1108 /* Now figure out what to do with the result of the result. */
1109 handle_inferior_event (async_ecs);
1111 if (!async_ecs->wait_some_more)
1113 /* Do only the cleanups that have been added by this
1114 function. Let the continuations for the commands do the rest,
1115 if there are any. */
1116 do_exec_cleanups (old_cleanups);
1118 if (step_multi && stop_step)
1119 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
1121 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1125 /* Prepare an execution control state for looping through a
1126 wait_for_inferior-type loop. */
1129 init_execution_control_state (struct execution_control_state *ecs)
1131 /* ecs->another_trap? */
1132 ecs->random_signal = 0;
1133 ecs->remove_breakpoints_on_following_step = 0;
1134 ecs->handling_longjmp = 0; /* FIXME */
1135 ecs->update_step_sp = 0;
1136 ecs->stepping_through_solib_after_catch = 0;
1137 ecs->stepping_through_solib_catchpoints = NULL;
1138 ecs->enable_hw_watchpoints_after_wait = 0;
1139 ecs->stepping_through_sigtramp = 0;
1140 ecs->sal = find_pc_line (prev_pc, 0);
1141 ecs->current_line = ecs->sal.line;
1142 ecs->current_symtab = ecs->sal.symtab;
1143 ecs->infwait_state = infwait_normal_state;
1144 ecs->waiton_ptid = pid_to_ptid (-1);
1145 ecs->wp = &(ecs->ws);
1148 /* Call this function before setting step_resume_breakpoint, as a
1149 sanity check. There should never be more than one step-resume
1150 breakpoint per thread, so we should never be setting a new
1151 step_resume_breakpoint when one is already active. */
1153 check_for_old_step_resume_breakpoint (void)
1155 if (step_resume_breakpoint)
1157 ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1160 /* Return the cached copy of the last pid/waitstatus returned by
1161 target_wait()/target_wait_hook(). The data is actually cached by
1162 handle_inferior_event(), which gets called immediately after
1163 target_wait()/target_wait_hook(). */
1166 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
1168 *ptidp = target_last_wait_ptid;
1169 *status = target_last_waitstatus;
1172 /* Switch thread contexts, maintaining "infrun state". */
1175 context_switch (struct execution_control_state *ecs)
1177 /* Caution: it may happen that the new thread (or the old one!)
1178 is not in the thread list. In this case we must not attempt
1179 to "switch context", or we run the risk that our context may
1180 be lost. This may happen as a result of the target module
1181 mishandling thread creation. */
1183 if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid))
1184 { /* Perform infrun state context switch: */
1185 /* Save infrun state for the old thread. */
1186 save_infrun_state (inferior_ptid, prev_pc,
1187 trap_expected, step_resume_breakpoint,
1188 through_sigtramp_breakpoint, step_range_start,
1189 step_range_end, &step_frame_id,
1190 ecs->handling_longjmp, ecs->another_trap,
1191 ecs->stepping_through_solib_after_catch,
1192 ecs->stepping_through_solib_catchpoints,
1193 ecs->stepping_through_sigtramp,
1194 ecs->current_line, ecs->current_symtab, step_sp);
1196 /* Load infrun state for the new thread. */
1197 load_infrun_state (ecs->ptid, &prev_pc,
1198 &trap_expected, &step_resume_breakpoint,
1199 &through_sigtramp_breakpoint, &step_range_start,
1200 &step_range_end, &step_frame_id,
1201 &ecs->handling_longjmp, &ecs->another_trap,
1202 &ecs->stepping_through_solib_after_catch,
1203 &ecs->stepping_through_solib_catchpoints,
1204 &ecs->stepping_through_sigtramp,
1205 &ecs->current_line, &ecs->current_symtab, &step_sp);
1207 inferior_ptid = ecs->ptid;
1210 /* Wrapper for PC_IN_SIGTRAMP that takes care of the need to find the
1213 In a classic example of "left hand VS right hand", "infrun.c" was
1214 trying to improve GDB's performance by caching the result of calls
1215 to calls to find_pc_partial_funtion, while at the same time
1216 find_pc_partial_function was also trying to ramp up performance by
1217 caching its most recent return value. The below makes the the
1218 function find_pc_partial_function solely responsibile for
1219 performance issues (the local cache that relied on a global
1220 variable - arrrggg - deleted).
1222 Using the testsuite and gcov, it was found that dropping the local
1223 "infrun.c" cache and instead relying on find_pc_partial_function
1224 increased the number of calls to 12000 (from 10000), but the number
1225 of times find_pc_partial_function's cache missed (this is what
1226 matters) was only increased by only 4 (to 3569). (A quick back of
1227 envelope caculation suggests that the extra 2000 function calls
1228 @1000 extra instructions per call make the 1 MIP VAX testsuite run
1229 take two extra seconds, oops :-)
1231 Long term, this function can be eliminated, replaced by the code:
1232 get_frame_type(current_frame()) == SIGTRAMP_FRAME (for new
1233 architectures this is very cheap). */
1236 pc_in_sigtramp (CORE_ADDR pc)
1239 find_pc_partial_function (pc, &name, NULL, NULL);
1240 return PC_IN_SIGTRAMP (pc, name);
1244 /* Given an execution control state that has been freshly filled in
1245 by an event from the inferior, figure out what it means and take
1246 appropriate action. */
1249 handle_inferior_event (struct execution_control_state *ecs)
1251 CORE_ADDR real_stop_pc;
1252 /* NOTE: cagney/2003-03-28: If you're looking at this code and
1253 thinking that the variable stepped_after_stopped_by_watchpoint
1254 isn't used, then you're wrong! The macro STOPPED_BY_WATCHPOINT,
1255 defined in the file "config/pa/nm-hppah.h", accesses the variable
1256 indirectly. Mutter something rude about the HP merge. */
1257 int stepped_after_stopped_by_watchpoint;
1258 int sw_single_step_trap_p = 0;
1260 /* Cache the last pid/waitstatus. */
1261 target_last_wait_ptid = ecs->ptid;
1262 target_last_waitstatus = *ecs->wp;
1264 switch (ecs->infwait_state)
1266 case infwait_thread_hop_state:
1267 /* Cancel the waiton_ptid. */
1268 ecs->waiton_ptid = pid_to_ptid (-1);
1269 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1270 is serviced in this loop, below. */
1271 if (ecs->enable_hw_watchpoints_after_wait)
1273 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1274 ecs->enable_hw_watchpoints_after_wait = 0;
1276 stepped_after_stopped_by_watchpoint = 0;
1279 case infwait_normal_state:
1280 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1281 is serviced in this loop, below. */
1282 if (ecs->enable_hw_watchpoints_after_wait)
1284 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1285 ecs->enable_hw_watchpoints_after_wait = 0;
1287 stepped_after_stopped_by_watchpoint = 0;
1290 case infwait_nullified_state:
1291 stepped_after_stopped_by_watchpoint = 0;
1294 case infwait_nonstep_watch_state:
1295 insert_breakpoints ();
1297 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1298 handle things like signals arriving and other things happening
1299 in combination correctly? */
1300 stepped_after_stopped_by_watchpoint = 1;
1304 internal_error (__FILE__, __LINE__, "bad switch");
1306 ecs->infwait_state = infwait_normal_state;
1308 flush_cached_frames ();
1310 /* If it's a new process, add it to the thread database */
1312 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
1313 && !in_thread_list (ecs->ptid));
1315 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1316 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
1318 add_thread (ecs->ptid);
1320 ui_out_text (uiout, "[New ");
1321 ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid));
1322 ui_out_text (uiout, "]\n");
1325 /* NOTE: This block is ONLY meant to be invoked in case of a
1326 "thread creation event"! If it is invoked for any other
1327 sort of event (such as a new thread landing on a breakpoint),
1328 the event will be discarded, which is almost certainly
1331 To avoid this, the low-level module (eg. target_wait)
1332 should call in_thread_list and add_thread, so that the
1333 new thread is known by the time we get here. */
1335 /* We may want to consider not doing a resume here in order
1336 to give the user a chance to play with the new thread.
1337 It might be good to make that a user-settable option. */
1339 /* At this point, all threads are stopped (happens
1340 automatically in either the OS or the native code).
1341 Therefore we need to continue all threads in order to
1344 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
1345 prepare_to_wait (ecs);
1350 switch (ecs->ws.kind)
1352 case TARGET_WAITKIND_LOADED:
1353 /* Ignore gracefully during startup of the inferior, as it
1354 might be the shell which has just loaded some objects,
1355 otherwise add the symbols for the newly loaded objects. */
1357 if (stop_soon == NO_STOP_QUIETLY)
1359 /* Remove breakpoints, SOLIB_ADD might adjust
1360 breakpoint addresses via breakpoint_re_set. */
1361 if (breakpoints_inserted)
1362 remove_breakpoints ();
1364 /* Check for any newly added shared libraries if we're
1365 supposed to be adding them automatically. Switch
1366 terminal for any messages produced by
1367 breakpoint_re_set. */
1368 target_terminal_ours_for_output ();
1369 SOLIB_ADD (NULL, 0, NULL, auto_solib_add);
1370 target_terminal_inferior ();
1372 /* Reinsert breakpoints and continue. */
1373 if (breakpoints_inserted)
1374 insert_breakpoints ();
1377 resume (0, TARGET_SIGNAL_0);
1378 prepare_to_wait (ecs);
1381 case TARGET_WAITKIND_SPURIOUS:
1382 resume (0, TARGET_SIGNAL_0);
1383 prepare_to_wait (ecs);
1386 case TARGET_WAITKIND_EXITED:
1387 target_terminal_ours (); /* Must do this before mourn anyway */
1388 print_stop_reason (EXITED, ecs->ws.value.integer);
1390 /* Record the exit code in the convenience variable $_exitcode, so
1391 that the user can inspect this again later. */
1392 set_internalvar (lookup_internalvar ("_exitcode"),
1393 value_from_longest (builtin_type_int,
1394 (LONGEST) ecs->ws.value.integer));
1395 gdb_flush (gdb_stdout);
1396 target_mourn_inferior ();
1397 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */
1398 stop_print_frame = 0;
1399 stop_stepping (ecs);
1402 case TARGET_WAITKIND_SIGNALLED:
1403 stop_print_frame = 0;
1404 stop_signal = ecs->ws.value.sig;
1405 target_terminal_ours (); /* Must do this before mourn anyway */
1407 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1408 reach here unless the inferior is dead. However, for years
1409 target_kill() was called here, which hints that fatal signals aren't
1410 really fatal on some systems. If that's true, then some changes
1412 target_mourn_inferior ();
1414 print_stop_reason (SIGNAL_EXITED, stop_signal);
1415 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */
1416 stop_stepping (ecs);
1419 /* The following are the only cases in which we keep going;
1420 the above cases end in a continue or goto. */
1421 case TARGET_WAITKIND_FORKED:
1422 case TARGET_WAITKIND_VFORKED:
1423 stop_signal = TARGET_SIGNAL_TRAP;
1424 pending_follow.kind = ecs->ws.kind;
1426 pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid);
1427 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1429 stop_pc = read_pc ();
1431 /* Assume that catchpoints are not really software breakpoints. If
1432 some future target implements them using software breakpoints then
1433 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1434 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1435 bpstat_stop_status will not decrement the PC. */
1437 stop_bpstat = bpstat_stop_status (&stop_pc, 1);
1439 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1441 /* If no catchpoint triggered for this, then keep going. */
1442 if (ecs->random_signal)
1444 stop_signal = TARGET_SIGNAL_0;
1448 goto process_event_stop_test;
1450 case TARGET_WAITKIND_EXECD:
1451 stop_signal = TARGET_SIGNAL_TRAP;
1453 /* NOTE drow/2002-12-05: This code should be pushed down into the
1454 target_wait function. Until then following vfork on HP/UX 10.20
1455 is probably broken by this. Of course, it's broken anyway. */
1456 /* Is this a target which reports multiple exec events per actual
1457 call to exec()? (HP-UX using ptrace does, for example.) If so,
1458 ignore all but the last one. Just resume the exec'r, and wait
1459 for the next exec event. */
1460 if (inferior_ignoring_leading_exec_events)
1462 inferior_ignoring_leading_exec_events--;
1463 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1464 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.
1466 target_resume (ecs->ptid, 0, TARGET_SIGNAL_0);
1467 prepare_to_wait (ecs);
1470 inferior_ignoring_leading_exec_events =
1471 target_reported_exec_events_per_exec_call () - 1;
1473 pending_follow.execd_pathname =
1474 savestring (ecs->ws.value.execd_pathname,
1475 strlen (ecs->ws.value.execd_pathname));
1477 /* This causes the eventpoints and symbol table to be reset. Must
1478 do this now, before trying to determine whether to stop. */
1479 follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname);
1480 xfree (pending_follow.execd_pathname);
1482 stop_pc = read_pc_pid (ecs->ptid);
1483 ecs->saved_inferior_ptid = inferior_ptid;
1484 inferior_ptid = ecs->ptid;
1486 /* Assume that catchpoints are not really software breakpoints. If
1487 some future target implements them using software breakpoints then
1488 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1489 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1490 bpstat_stop_status will not decrement the PC. */
1492 stop_bpstat = bpstat_stop_status (&stop_pc, 1);
1494 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1495 inferior_ptid = ecs->saved_inferior_ptid;
1497 /* If no catchpoint triggered for this, then keep going. */
1498 if (ecs->random_signal)
1500 stop_signal = TARGET_SIGNAL_0;
1504 goto process_event_stop_test;
1506 /* These syscall events are returned on HP-UX, as part of its
1507 implementation of page-protection-based "hardware" watchpoints.
1508 HP-UX has unfortunate interactions between page-protections and
1509 some system calls. Our solution is to disable hardware watches
1510 when a system call is entered, and reenable them when the syscall
1511 completes. The downside of this is that we may miss the precise
1512 point at which a watched piece of memory is modified. "Oh well."
1514 Note that we may have multiple threads running, which may each
1515 enter syscalls at roughly the same time. Since we don't have a
1516 good notion currently of whether a watched piece of memory is
1517 thread-private, we'd best not have any page-protections active
1518 when any thread is in a syscall. Thus, we only want to reenable
1519 hardware watches when no threads are in a syscall.
1521 Also, be careful not to try to gather much state about a thread
1522 that's in a syscall. It's frequently a losing proposition. */
1523 case TARGET_WAITKIND_SYSCALL_ENTRY:
1524 number_of_threads_in_syscalls++;
1525 if (number_of_threads_in_syscalls == 1)
1527 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1529 resume (0, TARGET_SIGNAL_0);
1530 prepare_to_wait (ecs);
1533 /* Before examining the threads further, step this thread to
1534 get it entirely out of the syscall. (We get notice of the
1535 event when the thread is just on the verge of exiting a
1536 syscall. Stepping one instruction seems to get it back
1539 Note that although the logical place to reenable h/w watches
1540 is here, we cannot. We cannot reenable them before stepping
1541 the thread (this causes the next wait on the thread to hang).
1543 Nor can we enable them after stepping until we've done a wait.
1544 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1545 here, which will be serviced immediately after the target
1547 case TARGET_WAITKIND_SYSCALL_RETURN:
1548 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
1550 if (number_of_threads_in_syscalls > 0)
1552 number_of_threads_in_syscalls--;
1553 ecs->enable_hw_watchpoints_after_wait =
1554 (number_of_threads_in_syscalls == 0);
1556 prepare_to_wait (ecs);
1559 case TARGET_WAITKIND_STOPPED:
1560 stop_signal = ecs->ws.value.sig;
1563 /* We had an event in the inferior, but we are not interested
1564 in handling it at this level. The lower layers have already
1565 done what needs to be done, if anything.
1567 One of the possible circumstances for this is when the
1568 inferior produces output for the console. The inferior has
1569 not stopped, and we are ignoring the event. Another possible
1570 circumstance is any event which the lower level knows will be
1571 reported multiple times without an intervening resume. */
1572 case TARGET_WAITKIND_IGNORE:
1573 prepare_to_wait (ecs);
1577 /* We may want to consider not doing a resume here in order to give
1578 the user a chance to play with the new thread. It might be good
1579 to make that a user-settable option. */
1581 /* At this point, all threads are stopped (happens automatically in
1582 either the OS or the native code). Therefore we need to continue
1583 all threads in order to make progress. */
1584 if (ecs->new_thread_event)
1586 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
1587 prepare_to_wait (ecs);
1591 stop_pc = read_pc_pid (ecs->ptid);
1593 /* See if a thread hit a thread-specific breakpoint that was meant for
1594 another thread. If so, then step that thread past the breakpoint,
1597 if (stop_signal == TARGET_SIGNAL_TRAP)
1599 /* Check if a regular breakpoint has been hit before checking
1600 for a potential single step breakpoint. Otherwise, GDB will
1601 not see this breakpoint hit when stepping onto breakpoints. */
1602 if (breakpoints_inserted
1603 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
1605 ecs->random_signal = 0;
1606 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK,
1611 /* Saw a breakpoint, but it was hit by the wrong thread.
1613 if (DECR_PC_AFTER_BREAK)
1614 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, ecs->ptid);
1616 remove_status = remove_breakpoints ();
1617 /* Did we fail to remove breakpoints? If so, try
1618 to set the PC past the bp. (There's at least
1619 one situation in which we can fail to remove
1620 the bp's: On HP-UX's that use ttrace, we can't
1621 change the address space of a vforking child
1622 process until the child exits (well, okay, not
1623 then either :-) or execs. */
1624 if (remove_status != 0)
1626 /* FIXME! This is obviously non-portable! */
1627 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, ecs->ptid);
1628 /* We need to restart all the threads now,
1629 * unles we're running in scheduler-locked mode.
1630 * Use currently_stepping to determine whether to
1633 /* FIXME MVS: is there any reason not to call resume()? */
1634 if (scheduler_mode == schedlock_on)
1635 target_resume (ecs->ptid,
1636 currently_stepping (ecs), TARGET_SIGNAL_0);
1638 target_resume (RESUME_ALL,
1639 currently_stepping (ecs), TARGET_SIGNAL_0);
1640 prepare_to_wait (ecs);
1645 breakpoints_inserted = 0;
1646 if (!ptid_equal (inferior_ptid, ecs->ptid))
1647 context_switch (ecs);
1648 ecs->waiton_ptid = ecs->ptid;
1649 ecs->wp = &(ecs->ws);
1650 ecs->another_trap = 1;
1652 ecs->infwait_state = infwait_thread_hop_state;
1654 registers_changed ();
1659 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1661 /* Readjust the stop_pc as it is off by DECR_PC_AFTER_BREAK
1662 compared to the value it would have if the system stepping
1663 capability was used. This allows the rest of the code in
1664 this function to use this address without having to worry
1665 whether software single step is in use or not. */
1666 if (DECR_PC_AFTER_BREAK)
1668 stop_pc -= DECR_PC_AFTER_BREAK;
1669 write_pc_pid (stop_pc, ecs->ptid);
1672 sw_single_step_trap_p = 1;
1673 ecs->random_signal = 0;
1677 ecs->random_signal = 1;
1679 /* See if something interesting happened to the non-current thread. If
1680 so, then switch to that thread, and eventually give control back to
1683 Note that if there's any kind of pending follow (i.e., of a fork,
1684 vfork or exec), we don't want to do this now. Rather, we'll let
1685 the next resume handle it. */
1686 if (!ptid_equal (ecs->ptid, inferior_ptid) &&
1687 (pending_follow.kind == TARGET_WAITKIND_SPURIOUS))
1691 /* If it's a random signal for a non-current thread, notify user
1692 if he's expressed an interest. */
1693 if (ecs->random_signal && signal_print[stop_signal])
1695 /* ??rehrauer: I don't understand the rationale for this code. If the
1696 inferior will stop as a result of this signal, then the act of handling
1697 the stop ought to print a message that's couches the stoppage in user
1698 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1699 won't stop as a result of the signal -- i.e., if the signal is merely
1700 a side-effect of something GDB's doing "under the covers" for the
1701 user, such as stepping threads over a breakpoint they shouldn't stop
1702 for -- then the message seems to be a serious annoyance at best.
1704 For now, remove the message altogether. */
1707 target_terminal_ours_for_output ();
1708 printf_filtered ("\nProgram received signal %s, %s.\n",
1709 target_signal_to_name (stop_signal),
1710 target_signal_to_string (stop_signal));
1711 gdb_flush (gdb_stdout);
1715 /* If it's not SIGTRAP and not a signal we want to stop for, then
1716 continue the thread. */
1718 if (stop_signal != TARGET_SIGNAL_TRAP && !signal_stop[stop_signal])
1721 target_terminal_inferior ();
1723 /* Clear the signal if it should not be passed. */
1724 if (signal_program[stop_signal] == 0)
1725 stop_signal = TARGET_SIGNAL_0;
1727 target_resume (ecs->ptid, 0, stop_signal);
1728 prepare_to_wait (ecs);
1732 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1733 and fall into the rest of wait_for_inferior(). */
1735 context_switch (ecs);
1738 context_hook (pid_to_thread_id (ecs->ptid));
1740 flush_cached_frames ();
1743 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1745 /* Pull the single step breakpoints out of the target. */
1746 SOFTWARE_SINGLE_STEP (0, 0);
1747 singlestep_breakpoints_inserted_p = 0;
1750 /* If PC is pointing at a nullified instruction, then step beyond
1751 it so that the user won't be confused when GDB appears to be ready
1754 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1755 if (INSTRUCTION_NULLIFIED)
1757 registers_changed ();
1758 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
1760 /* We may have received a signal that we want to pass to
1761 the inferior; therefore, we must not clobber the waitstatus
1764 ecs->infwait_state = infwait_nullified_state;
1765 ecs->waiton_ptid = ecs->ptid;
1766 ecs->wp = &(ecs->tmpstatus);
1767 prepare_to_wait (ecs);
1771 /* It may not be necessary to disable the watchpoint to stop over
1772 it. For example, the PA can (with some kernel cooperation)
1773 single step over a watchpoint without disabling the watchpoint. */
1774 if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1777 prepare_to_wait (ecs);
1781 /* It is far more common to need to disable a watchpoint to step
1782 the inferior over it. FIXME. What else might a debug
1783 register or page protection watchpoint scheme need here? */
1784 if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1786 /* At this point, we are stopped at an instruction which has
1787 attempted to write to a piece of memory under control of
1788 a watchpoint. The instruction hasn't actually executed
1789 yet. If we were to evaluate the watchpoint expression
1790 now, we would get the old value, and therefore no change
1791 would seem to have occurred.
1793 In order to make watchpoints work `right', we really need
1794 to complete the memory write, and then evaluate the
1795 watchpoint expression. The following code does that by
1796 removing the watchpoint (actually, all watchpoints and
1797 breakpoints), single-stepping the target, re-inserting
1798 watchpoints, and then falling through to let normal
1799 single-step processing handle proceed. Since this
1800 includes evaluating watchpoints, things will come to a
1801 stop in the correct manner. */
1803 if (DECR_PC_AFTER_BREAK)
1804 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
1806 remove_breakpoints ();
1807 registers_changed ();
1808 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */
1810 ecs->waiton_ptid = ecs->ptid;
1811 ecs->wp = &(ecs->ws);
1812 ecs->infwait_state = infwait_nonstep_watch_state;
1813 prepare_to_wait (ecs);
1817 /* It may be possible to simply continue after a watchpoint. */
1818 if (HAVE_CONTINUABLE_WATCHPOINT)
1819 STOPPED_BY_WATCHPOINT (ecs->ws);
1821 ecs->stop_func_start = 0;
1822 ecs->stop_func_end = 0;
1823 ecs->stop_func_name = 0;
1824 /* Don't care about return value; stop_func_start and stop_func_name
1825 will both be 0 if it doesn't work. */
1826 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
1827 &ecs->stop_func_start, &ecs->stop_func_end);
1828 ecs->stop_func_start += FUNCTION_START_OFFSET;
1829 ecs->another_trap = 0;
1830 bpstat_clear (&stop_bpstat);
1832 stop_stack_dummy = 0;
1833 stop_print_frame = 1;
1834 ecs->random_signal = 0;
1835 stopped_by_random_signal = 0;
1836 breakpoints_failed = 0;
1838 /* Look at the cause of the stop, and decide what to do.
1839 The alternatives are:
1840 1) break; to really stop and return to the debugger,
1841 2) drop through to start up again
1842 (set ecs->another_trap to 1 to single step once)
1843 3) set ecs->random_signal to 1, and the decision between 1 and 2
1844 will be made according to the signal handling tables. */
1846 /* First, distinguish signals caused by the debugger from signals
1847 that have to do with the program's own actions.
1848 Note that breakpoint insns may cause SIGTRAP or SIGILL
1849 or SIGEMT, depending on the operating system version.
1850 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1851 and change it to SIGTRAP. */
1853 if (stop_signal == TARGET_SIGNAL_TRAP
1854 || (breakpoints_inserted &&
1855 (stop_signal == TARGET_SIGNAL_ILL
1856 || stop_signal == TARGET_SIGNAL_EMT))
1857 || stop_soon == STOP_QUIETLY
1858 || stop_soon == STOP_QUIETLY_NO_SIGSTOP)
1860 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
1862 stop_print_frame = 0;
1863 stop_stepping (ecs);
1867 /* This is originated from start_remote(), start_inferior() and
1868 shared libraries hook functions. */
1869 if (stop_soon == STOP_QUIETLY)
1871 stop_stepping (ecs);
1875 /* This originates from attach_command(). We need to overwrite
1876 the stop_signal here, because some kernels don't ignore a
1877 SIGSTOP in a subsequent ptrace(PTRACE_SONT,SOGSTOP) call.
1878 See more comments in inferior.h. */
1879 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP)
1881 stop_stepping (ecs);
1882 if (stop_signal == TARGET_SIGNAL_STOP)
1883 stop_signal = TARGET_SIGNAL_0;
1887 /* Don't even think about breakpoints
1888 if just proceeded over a breakpoint.
1890 However, if we are trying to proceed over a breakpoint
1891 and end up in sigtramp, then through_sigtramp_breakpoint
1892 will be set and we should check whether we've hit the
1894 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
1895 && through_sigtramp_breakpoint == NULL)
1896 bpstat_clear (&stop_bpstat);
1899 /* See if there is a breakpoint at the current PC. */
1901 /* The second argument of bpstat_stop_status is meant to help
1902 distinguish between a breakpoint trap and a singlestep trap.
1903 This is only important on targets where DECR_PC_AFTER_BREAK
1904 is non-zero. The prev_pc test is meant to distinguish between
1905 singlestepping a trap instruction, and singlestepping thru a
1906 jump to the instruction following a trap instruction.
1908 Therefore, pass TRUE if our reason for stopping is
1909 something other than hitting a breakpoint. We do this by
1910 checking that either: we detected earlier a software single
1911 step trap or, 1) stepping is going on and 2) we didn't hit
1912 a breakpoint in a signal handler without an intervening stop
1913 in sigtramp, which is detected by a new stack pointer value
1914 below any usual function calling stack adjustments. */
1918 sw_single_step_trap_p
1919 || (currently_stepping (ecs)
1920 && prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1922 && INNER_THAN (read_sp (), (step_sp - 16)))));
1923 /* Following in case break condition called a
1925 stop_print_frame = 1;
1928 /* NOTE: cagney/2003-03-29: These two checks for a random signal
1929 at one stage in the past included checks for an inferior
1930 function call's call dummy's return breakpoint. The original
1931 comment, that went with the test, read:
1933 ``End of a stack dummy. Some systems (e.g. Sony news) give
1934 another signal besides SIGTRAP, so check here as well as
1937 If someone ever tries to get get call dummys on a
1938 non-executable stack to work (where the target would stop
1939 with something like a SIGSEG), then those tests might need to
1940 be re-instated. Given, however, that the tests were only
1941 enabled when momentary breakpoints were not being used, I
1942 suspect that it won't be the case. */
1944 if (stop_signal == TARGET_SIGNAL_TRAP)
1946 = !(bpstat_explains_signal (stop_bpstat)
1948 || (step_range_end && step_resume_breakpoint == NULL));
1951 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1952 if (!ecs->random_signal)
1953 stop_signal = TARGET_SIGNAL_TRAP;
1957 /* When we reach this point, we've pretty much decided
1958 that the reason for stopping must've been a random
1959 (unexpected) signal. */
1962 ecs->random_signal = 1;
1964 process_event_stop_test:
1965 /* For the program's own signals, act according to
1966 the signal handling tables. */
1968 if (ecs->random_signal)
1970 /* Signal not for debugging purposes. */
1973 stopped_by_random_signal = 1;
1975 if (signal_print[stop_signal])
1978 target_terminal_ours_for_output ();
1979 print_stop_reason (SIGNAL_RECEIVED, stop_signal);
1981 if (signal_stop[stop_signal])
1983 stop_stepping (ecs);
1986 /* If not going to stop, give terminal back
1987 if we took it away. */
1989 target_terminal_inferior ();
1991 /* Clear the signal if it should not be passed. */
1992 if (signal_program[stop_signal] == 0)
1993 stop_signal = TARGET_SIGNAL_0;
1995 /* I'm not sure whether this needs to be check_sigtramp2 or
1996 whether it could/should be keep_going.
1998 This used to jump to step_over_function if we are stepping,
2001 Suppose the user does a `next' over a function call, and while
2002 that call is in progress, the inferior receives a signal for
2003 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2004 that case, when we reach this point, there is already a
2005 step-resume breakpoint established, right where it should be:
2006 immediately after the function call the user is "next"-ing
2007 over. If we call step_over_function now, two bad things
2010 - we'll create a new breakpoint, at wherever the current
2011 frame's return address happens to be. That could be
2012 anywhere, depending on what function call happens to be on
2013 the top of the stack at that point. Point is, it's probably
2014 not where we need it.
2016 - the existing step-resume breakpoint (which is at the correct
2017 address) will get orphaned: step_resume_breakpoint will point
2018 to the new breakpoint, and the old step-resume breakpoint
2019 will never be cleaned up.
2021 The old behavior was meant to help HP-UX single-step out of
2022 sigtramps. It would place the new breakpoint at prev_pc, which
2023 was certainly wrong. I don't know the details there, so fixing
2024 this probably breaks that. As with anything else, it's up to
2025 the HP-UX maintainer to furnish a fix that doesn't break other
2026 platforms. --JimB, 20 May 1999 */
2027 check_sigtramp2 (ecs);
2032 /* Handle cases caused by hitting a breakpoint. */
2034 CORE_ADDR jmp_buf_pc;
2035 struct bpstat_what what;
2037 what = bpstat_what (stop_bpstat);
2039 if (what.call_dummy)
2041 stop_stack_dummy = 1;
2043 trap_expected_after_continue = 1;
2047 switch (what.main_action)
2049 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
2050 /* If we hit the breakpoint at longjmp, disable it for the
2051 duration of this command. Then, install a temporary
2052 breakpoint at the target of the jmp_buf. */
2053 disable_longjmp_breakpoint ();
2054 remove_breakpoints ();
2055 breakpoints_inserted = 0;
2056 if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc))
2062 /* Need to blow away step-resume breakpoint, as it
2063 interferes with us */
2064 if (step_resume_breakpoint != NULL)
2066 delete_step_resume_breakpoint (&step_resume_breakpoint);
2068 /* Not sure whether we need to blow this away too, but probably
2069 it is like the step-resume breakpoint. */
2070 if (through_sigtramp_breakpoint != NULL)
2072 delete_breakpoint (through_sigtramp_breakpoint);
2073 through_sigtramp_breakpoint = NULL;
2077 /* FIXME - Need to implement nested temporary breakpoints */
2078 if (step_over_calls > 0)
2079 set_longjmp_resume_breakpoint (jmp_buf_pc, get_current_frame ());
2082 set_longjmp_resume_breakpoint (jmp_buf_pc, null_frame_id);
2083 ecs->handling_longjmp = 1; /* FIXME */
2087 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
2088 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
2089 remove_breakpoints ();
2090 breakpoints_inserted = 0;
2092 /* FIXME - Need to implement nested temporary breakpoints */
2094 && (frame_id_inner (get_frame_id (get_current_frame ()),
2097 ecs->another_trap = 1;
2102 disable_longjmp_breakpoint ();
2103 ecs->handling_longjmp = 0; /* FIXME */
2104 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
2106 /* else fallthrough */
2108 case BPSTAT_WHAT_SINGLE:
2109 if (breakpoints_inserted)
2111 remove_breakpoints ();
2113 breakpoints_inserted = 0;
2114 ecs->another_trap = 1;
2115 /* Still need to check other stuff, at least the case
2116 where we are stepping and step out of the right range. */
2119 case BPSTAT_WHAT_STOP_NOISY:
2120 stop_print_frame = 1;
2122 /* We are about to nuke the step_resume_breakpoint and
2123 through_sigtramp_breakpoint via the cleanup chain, so
2124 no need to worry about it here. */
2126 stop_stepping (ecs);
2129 case BPSTAT_WHAT_STOP_SILENT:
2130 stop_print_frame = 0;
2132 /* We are about to nuke the step_resume_breakpoint and
2133 through_sigtramp_breakpoint via the cleanup chain, so
2134 no need to worry about it here. */
2136 stop_stepping (ecs);
2139 case BPSTAT_WHAT_STEP_RESUME:
2140 /* This proably demands a more elegant solution, but, yeah
2143 This function's use of the simple variable
2144 step_resume_breakpoint doesn't seem to accomodate
2145 simultaneously active step-resume bp's, although the
2146 breakpoint list certainly can.
2148 If we reach here and step_resume_breakpoint is already
2149 NULL, then apparently we have multiple active
2150 step-resume bp's. We'll just delete the breakpoint we
2151 stopped at, and carry on.
2153 Correction: what the code currently does is delete a
2154 step-resume bp, but it makes no effort to ensure that
2155 the one deleted is the one currently stopped at. MVS */
2157 if (step_resume_breakpoint == NULL)
2159 step_resume_breakpoint =
2160 bpstat_find_step_resume_breakpoint (stop_bpstat);
2162 delete_step_resume_breakpoint (&step_resume_breakpoint);
2165 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2166 if (through_sigtramp_breakpoint)
2167 delete_breakpoint (through_sigtramp_breakpoint);
2168 through_sigtramp_breakpoint = NULL;
2170 /* If were waiting for a trap, hitting the step_resume_break
2171 doesn't count as getting it. */
2173 ecs->another_trap = 1;
2176 case BPSTAT_WHAT_CHECK_SHLIBS:
2177 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2180 /* Remove breakpoints, we eventually want to step over the
2181 shlib event breakpoint, and SOLIB_ADD might adjust
2182 breakpoint addresses via breakpoint_re_set. */
2183 if (breakpoints_inserted)
2184 remove_breakpoints ();
2185 breakpoints_inserted = 0;
2187 /* Check for any newly added shared libraries if we're
2188 supposed to be adding them automatically. Switch
2189 terminal for any messages produced by
2190 breakpoint_re_set. */
2191 target_terminal_ours_for_output ();
2192 SOLIB_ADD (NULL, 0, NULL, auto_solib_add);
2193 target_terminal_inferior ();
2195 /* Try to reenable shared library breakpoints, additional
2196 code segments in shared libraries might be mapped in now. */
2197 re_enable_breakpoints_in_shlibs ();
2199 /* If requested, stop when the dynamic linker notifies
2200 gdb of events. This allows the user to get control
2201 and place breakpoints in initializer routines for
2202 dynamically loaded objects (among other things). */
2203 if (stop_on_solib_events)
2205 stop_stepping (ecs);
2209 /* If we stopped due to an explicit catchpoint, then the
2210 (see above) call to SOLIB_ADD pulled in any symbols
2211 from a newly-loaded library, if appropriate.
2213 We do want the inferior to stop, but not where it is
2214 now, which is in the dynamic linker callback. Rather,
2215 we would like it stop in the user's program, just after
2216 the call that caused this catchpoint to trigger. That
2217 gives the user a more useful vantage from which to
2218 examine their program's state. */
2219 else if (what.main_action ==
2220 BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2222 /* ??rehrauer: If I could figure out how to get the
2223 right return PC from here, we could just set a temp
2224 breakpoint and resume. I'm not sure we can without
2225 cracking open the dld's shared libraries and sniffing
2226 their unwind tables and text/data ranges, and that's
2227 not a terribly portable notion.
2229 Until that time, we must step the inferior out of the
2230 dld callback, and also out of the dld itself (and any
2231 code or stubs in libdld.sl, such as "shl_load" and
2232 friends) until we reach non-dld code. At that point,
2233 we can stop stepping. */
2234 bpstat_get_triggered_catchpoints (stop_bpstat,
2236 stepping_through_solib_catchpoints);
2237 ecs->stepping_through_solib_after_catch = 1;
2239 /* Be sure to lift all breakpoints, so the inferior does
2240 actually step past this point... */
2241 ecs->another_trap = 1;
2246 /* We want to step over this breakpoint, then keep going. */
2247 ecs->another_trap = 1;
2254 case BPSTAT_WHAT_LAST:
2255 /* Not a real code, but listed here to shut up gcc -Wall. */
2257 case BPSTAT_WHAT_KEEP_CHECKING:
2262 /* We come here if we hit a breakpoint but should not
2263 stop for it. Possibly we also were stepping
2264 and should stop for that. So fall through and
2265 test for stepping. But, if not stepping,
2268 /* Are we stepping to get the inferior out of the dynamic
2269 linker's hook (and possibly the dld itself) after catching
2271 if (ecs->stepping_through_solib_after_catch)
2273 #if defined(SOLIB_ADD)
2274 /* Have we reached our destination? If not, keep going. */
2275 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
2277 ecs->another_trap = 1;
2282 /* Else, stop and report the catchpoint(s) whose triggering
2283 caused us to begin stepping. */
2284 ecs->stepping_through_solib_after_catch = 0;
2285 bpstat_clear (&stop_bpstat);
2286 stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints);
2287 bpstat_clear (&ecs->stepping_through_solib_catchpoints);
2288 stop_print_frame = 1;
2289 stop_stepping (ecs);
2293 if (step_resume_breakpoint)
2295 /* Having a step-resume breakpoint overrides anything
2296 else having to do with stepping commands until
2297 that breakpoint is reached. */
2298 /* I'm not sure whether this needs to be check_sigtramp2 or
2299 whether it could/should be keep_going. */
2300 check_sigtramp2 (ecs);
2305 if (step_range_end == 0)
2307 /* Likewise if we aren't even stepping. */
2308 /* I'm not sure whether this needs to be check_sigtramp2 or
2309 whether it could/should be keep_going. */
2310 check_sigtramp2 (ecs);
2315 /* If stepping through a line, keep going if still within it.
2317 Note that step_range_end is the address of the first instruction
2318 beyond the step range, and NOT the address of the last instruction
2320 if (stop_pc >= step_range_start && stop_pc < step_range_end)
2322 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2323 So definately need to check for sigtramp here. */
2324 check_sigtramp2 (ecs);
2329 /* We stepped out of the stepping range. */
2331 /* If we are stepping at the source level and entered the runtime
2332 loader dynamic symbol resolution code, we keep on single stepping
2333 until we exit the run time loader code and reach the callee's
2335 if (step_over_calls == STEP_OVER_UNDEBUGGABLE
2336 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2338 CORE_ADDR pc_after_resolver = SKIP_SOLIB_RESOLVER (stop_pc);
2340 if (pc_after_resolver)
2342 /* Set up a step-resume breakpoint at the address
2343 indicated by SKIP_SOLIB_RESOLVER. */
2344 struct symtab_and_line sr_sal;
2346 sr_sal.pc = pc_after_resolver;
2348 check_for_old_step_resume_breakpoint ();
2349 step_resume_breakpoint =
2350 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2351 if (breakpoints_inserted)
2352 insert_breakpoints ();
2359 /* We can't update step_sp every time through the loop, because
2360 reading the stack pointer would slow down stepping too much.
2361 But we can update it every time we leave the step range. */
2362 ecs->update_step_sp = 1;
2364 /* Did we just take a signal? */
2365 if (pc_in_sigtramp (stop_pc)
2366 && !pc_in_sigtramp (prev_pc)
2367 && INNER_THAN (read_sp (), step_sp))
2369 /* We've just taken a signal; go until we are back to
2370 the point where we took it and one more. */
2372 /* Note: The test above succeeds not only when we stepped
2373 into a signal handler, but also when we step past the last
2374 statement of a signal handler and end up in the return stub
2375 of the signal handler trampoline. To distinguish between
2376 these two cases, check that the frame is INNER_THAN the
2377 previous one below. pai/1997-09-11 */
2381 struct frame_id current_frame = get_frame_id (get_current_frame ());
2383 if (frame_id_inner (current_frame, step_frame_id))
2385 /* We have just taken a signal; go until we are back to
2386 the point where we took it and one more. */
2388 /* This code is needed at least in the following case:
2389 The user types "next" and then a signal arrives (before
2390 the "next" is done). */
2392 /* Note that if we are stopped at a breakpoint, then we need
2393 the step_resume breakpoint to override any breakpoints at
2394 the same location, so that we will still step over the
2395 breakpoint even though the signal happened. */
2396 struct symtab_and_line sr_sal;
2399 sr_sal.symtab = NULL;
2401 sr_sal.pc = prev_pc;
2402 /* We could probably be setting the frame to
2403 step_frame_id; I don't think anyone thought to try it. */
2404 check_for_old_step_resume_breakpoint ();
2405 step_resume_breakpoint =
2406 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2407 if (breakpoints_inserted)
2408 insert_breakpoints ();
2412 /* We just stepped out of a signal handler and into
2413 its calling trampoline.
2415 Normally, we'd call step_over_function from
2416 here, but for some reason GDB can't unwind the
2417 stack correctly to find the real PC for the point
2418 user code where the signal trampoline will return
2419 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2420 But signal trampolines are pretty small stubs of
2421 code, anyway, so it's OK instead to just
2422 single-step out. Note: assuming such trampolines
2423 don't exhibit recursion on any platform... */
2424 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2425 &ecs->stop_func_start,
2426 &ecs->stop_func_end);
2427 /* Readjust stepping range */
2428 step_range_start = ecs->stop_func_start;
2429 step_range_end = ecs->stop_func_end;
2430 ecs->stepping_through_sigtramp = 1;
2435 /* If this is stepi or nexti, make sure that the stepping range
2436 gets us past that instruction. */
2437 if (step_range_end == 1)
2438 /* FIXME: Does this run afoul of the code below which, if
2439 we step into the middle of a line, resets the stepping
2441 step_range_end = (step_range_start = prev_pc) + 1;
2443 ecs->remove_breakpoints_on_following_step = 1;
2448 if (((stop_pc == ecs->stop_func_start /* Quick test */
2449 || in_prologue (stop_pc, ecs->stop_func_start))
2450 && !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2451 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name)
2452 || ecs->stop_func_name == 0)
2454 /* It's a subroutine call. */
2456 if ((step_over_calls == STEP_OVER_NONE)
2457 || ((step_range_end == 1)
2458 && in_prologue (prev_pc, ecs->stop_func_start)))
2460 /* I presume that step_over_calls is only 0 when we're
2461 supposed to be stepping at the assembly language level
2462 ("stepi"). Just stop. */
2463 /* Also, maybe we just did a "nexti" inside a prolog,
2464 so we thought it was a subroutine call but it was not.
2465 Stop as well. FENN */
2467 print_stop_reason (END_STEPPING_RANGE, 0);
2468 stop_stepping (ecs);
2472 if (step_over_calls == STEP_OVER_ALL || IGNORE_HELPER_CALL (stop_pc))
2474 /* We're doing a "next". */
2476 if (pc_in_sigtramp (stop_pc)
2477 && frame_id_inner (step_frame_id,
2478 frame_id_build (read_sp (), 0)))
2479 /* We stepped out of a signal handler, and into its
2480 calling trampoline. This is misdetected as a
2481 subroutine call, but stepping over the signal
2482 trampoline isn't such a bad idea. In order to do that,
2483 we have to ignore the value in step_frame_id, since
2484 that doesn't represent the frame that'll reach when we
2485 return from the signal trampoline. Otherwise we'll
2486 probably continue to the end of the program. */
2487 step_frame_id = null_frame_id;
2489 step_over_function (ecs);
2494 /* If we are in a function call trampoline (a stub between
2495 the calling routine and the real function), locate the real
2496 function. That's what tells us (a) whether we want to step
2497 into it at all, and (b) what prologue we want to run to
2498 the end of, if we do step into it. */
2499 real_stop_pc = skip_language_trampoline (stop_pc);
2500 if (real_stop_pc == 0)
2501 real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc);
2502 if (real_stop_pc != 0)
2503 ecs->stop_func_start = real_stop_pc;
2505 /* If we have line number information for the function we
2506 are thinking of stepping into, step into it.
2508 If there are several symtabs at that PC (e.g. with include
2509 files), just want to know whether *any* of them have line
2510 numbers. find_pc_line handles this. */
2512 struct symtab_and_line tmp_sal;
2514 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
2515 if (tmp_sal.line != 0)
2517 step_into_function (ecs);
2522 /* If we have no line number and the step-stop-if-no-debug
2523 is set, we stop the step so that the user has a chance to
2524 switch in assembly mode. */
2525 if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug)
2528 print_stop_reason (END_STEPPING_RANGE, 0);
2529 stop_stepping (ecs);
2533 step_over_function (ecs);
2539 /* We've wandered out of the step range. */
2541 ecs->sal = find_pc_line (stop_pc, 0);
2543 if (step_range_end == 1)
2545 /* It is stepi or nexti. We always want to stop stepping after
2548 print_stop_reason (END_STEPPING_RANGE, 0);
2549 stop_stepping (ecs);
2553 /* If we're in the return path from a shared library trampoline,
2554 we want to proceed through the trampoline when stepping. */
2555 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2557 /* Determine where this trampoline returns. */
2558 real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc);
2560 /* Only proceed through if we know where it's going. */
2563 /* And put the step-breakpoint there and go until there. */
2564 struct symtab_and_line sr_sal;
2566 init_sal (&sr_sal); /* initialize to zeroes */
2567 sr_sal.pc = real_stop_pc;
2568 sr_sal.section = find_pc_overlay (sr_sal.pc);
2569 /* Do not specify what the fp should be when we stop
2570 since on some machines the prologue
2571 is where the new fp value is established. */
2572 check_for_old_step_resume_breakpoint ();
2573 step_resume_breakpoint =
2574 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2575 if (breakpoints_inserted)
2576 insert_breakpoints ();
2578 /* Restart without fiddling with the step ranges or
2585 if (ecs->sal.line == 0)
2587 /* We have no line number information. That means to stop
2588 stepping (does this always happen right after one instruction,
2589 when we do "s" in a function with no line numbers,
2590 or can this happen as a result of a return or longjmp?). */
2592 print_stop_reason (END_STEPPING_RANGE, 0);
2593 stop_stepping (ecs);
2597 if ((stop_pc == ecs->sal.pc)
2598 && (ecs->current_line != ecs->sal.line
2599 || ecs->current_symtab != ecs->sal.symtab))
2601 /* We are at the start of a different line. So stop. Note that
2602 we don't stop if we step into the middle of a different line.
2603 That is said to make things like for (;;) statements work
2606 print_stop_reason (END_STEPPING_RANGE, 0);
2607 stop_stepping (ecs);
2611 /* We aren't done stepping.
2613 Optimize by setting the stepping range to the line.
2614 (We might not be in the original line, but if we entered a
2615 new line in mid-statement, we continue stepping. This makes
2616 things like for(;;) statements work better.) */
2618 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
2620 /* If this is the last line of the function, don't keep stepping
2621 (it would probably step us out of the function).
2622 This is particularly necessary for a one-line function,
2623 in which after skipping the prologue we better stop even though
2624 we will be in mid-line. */
2626 print_stop_reason (END_STEPPING_RANGE, 0);
2627 stop_stepping (ecs);
2630 step_range_start = ecs->sal.pc;
2631 step_range_end = ecs->sal.end;
2632 step_frame_id = get_frame_id (get_current_frame ());
2633 ecs->current_line = ecs->sal.line;
2634 ecs->current_symtab = ecs->sal.symtab;
2636 /* In the case where we just stepped out of a function into the
2637 middle of a line of the caller, continue stepping, but
2638 step_frame_id must be modified to current frame */
2640 struct frame_id current_frame = get_frame_id (get_current_frame ());
2641 if (!(frame_id_inner (current_frame, step_frame_id)))
2642 step_frame_id = current_frame;
2648 /* Are we in the middle of stepping? */
2651 currently_stepping (struct execution_control_state *ecs)
2653 return ((through_sigtramp_breakpoint == NULL
2654 && !ecs->handling_longjmp
2655 && ((step_range_end && step_resume_breakpoint == NULL)
2657 || ecs->stepping_through_solib_after_catch
2658 || bpstat_should_step ());
2662 check_sigtramp2 (struct execution_control_state *ecs)
2665 && pc_in_sigtramp (stop_pc)
2666 && !pc_in_sigtramp (prev_pc)
2667 && INNER_THAN (read_sp (), step_sp))
2669 /* What has happened here is that we have just stepped the
2670 inferior with a signal (because it is a signal which
2671 shouldn't make us stop), thus stepping into sigtramp.
2673 So we need to set a step_resume_break_address breakpoint and
2674 continue until we hit it, and then step. FIXME: This should
2675 be more enduring than a step_resume breakpoint; we should
2676 know that we will later need to keep going rather than
2677 re-hitting the breakpoint here (see the testsuite,
2678 gdb.base/signals.exp where it says "exceedingly difficult"). */
2680 struct symtab_and_line sr_sal;
2682 init_sal (&sr_sal); /* initialize to zeroes */
2683 sr_sal.pc = prev_pc;
2684 sr_sal.section = find_pc_overlay (sr_sal.pc);
2685 /* We perhaps could set the frame if we kept track of what the
2686 frame corresponding to prev_pc was. But we don't, so don't. */
2687 through_sigtramp_breakpoint =
2688 set_momentary_breakpoint (sr_sal, null_frame_id, bp_through_sigtramp);
2689 if (breakpoints_inserted)
2690 insert_breakpoints ();
2692 ecs->remove_breakpoints_on_following_step = 1;
2693 ecs->another_trap = 1;
2697 /* Subroutine call with source code we should not step over. Do step
2698 to the first line of code in it. */
2701 step_into_function (struct execution_control_state *ecs)
2704 struct symtab_and_line sr_sal;
2706 s = find_pc_symtab (stop_pc);
2707 if (s && s->language != language_asm)
2708 ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start);
2710 ecs->sal = find_pc_line (ecs->stop_func_start, 0);
2711 /* Use the step_resume_break to step until the end of the prologue,
2712 even if that involves jumps (as it seems to on the vax under
2714 /* If the prologue ends in the middle of a source line, continue to
2715 the end of that source line (if it is still within the function).
2716 Otherwise, just go to end of prologue. */
2717 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2718 /* no, don't either. It skips any code that's legitimately on the
2722 && ecs->sal.pc != ecs->stop_func_start
2723 && ecs->sal.end < ecs->stop_func_end)
2724 ecs->stop_func_start = ecs->sal.end;
2727 if (ecs->stop_func_start == stop_pc)
2729 /* We are already there: stop now. */
2731 print_stop_reason (END_STEPPING_RANGE, 0);
2732 stop_stepping (ecs);
2737 /* Put the step-breakpoint there and go until there. */
2738 init_sal (&sr_sal); /* initialize to zeroes */
2739 sr_sal.pc = ecs->stop_func_start;
2740 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
2741 /* Do not specify what the fp should be when we stop since on
2742 some machines the prologue is where the new fp value is
2744 check_for_old_step_resume_breakpoint ();
2745 step_resume_breakpoint =
2746 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2747 if (breakpoints_inserted)
2748 insert_breakpoints ();
2750 /* And make sure stepping stops right away then. */
2751 step_range_end = step_range_start;
2756 /* We've just entered a callee, and we wish to resume until it returns
2757 to the caller. Setting a step_resume breakpoint on the return
2758 address will catch a return from the callee.
2760 However, if the callee is recursing, we want to be careful not to
2761 catch returns of those recursive calls, but only of THIS instance
2764 To do this, we set the step_resume bp's frame to our current
2765 caller's frame (step_frame_id, which is set by the "next" or
2766 "until" command, before execution begins). */
2769 step_over_function (struct execution_control_state *ecs)
2771 struct symtab_and_line sr_sal;
2773 init_sal (&sr_sal); /* initialize to zeros */
2775 /* NOTE: cagney/2003-04-06:
2777 At this point the equality get_frame_pc() == get_frame_func()
2778 should hold. This may make it possible for this code to tell the
2779 frame where it's function is, instead of the reverse. This would
2780 avoid the need to search for the frame's function, which can get
2781 very messy when there is no debug info available (look at the
2782 heuristic find pc start code found in targets like the MIPS). */
2784 /* NOTE: cagney/2003-04-06:
2786 The intent of DEPRECATED_SAVED_PC_AFTER_CALL was to:
2788 - provide a very light weight equivalent to frame_unwind_pc()
2789 (nee FRAME_SAVED_PC) that avoids the prologue analyzer
2791 - avoid handling the case where the PC hasn't been saved in the
2794 Unfortunatly, not five lines further down, is a call to
2795 get_frame_id() and that is guarenteed to trigger the prologue
2798 The `correct fix' is for the prologe analyzer to handle the case
2799 where the prologue is incomplete (PC in prologue) and,
2800 consequently, the return pc has not yet been saved. It should be
2801 noted that the prologue analyzer needs to handle this case
2802 anyway: frameless leaf functions that don't save the return PC;
2803 single stepping through a prologue.
2805 The d10v handles all this by bailing out of the prologue analsis
2806 when it reaches the current instruction. */
2808 if (DEPRECATED_SAVED_PC_AFTER_CALL_P ())
2809 sr_sal.pc = ADDR_BITS_REMOVE (DEPRECATED_SAVED_PC_AFTER_CALL (get_current_frame ()));
2811 sr_sal.pc = ADDR_BITS_REMOVE (frame_pc_unwind (get_current_frame ()));
2812 sr_sal.section = find_pc_overlay (sr_sal.pc);
2814 check_for_old_step_resume_breakpoint ();
2815 step_resume_breakpoint =
2816 set_momentary_breakpoint (sr_sal, get_frame_id (get_current_frame ()),
2819 if (frame_id_p (step_frame_id)
2820 && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
2821 step_resume_breakpoint->frame_id = step_frame_id;
2823 if (breakpoints_inserted)
2824 insert_breakpoints ();
2828 stop_stepping (struct execution_control_state *ecs)
2830 /* Let callers know we don't want to wait for the inferior anymore. */
2831 ecs->wait_some_more = 0;
2834 /* This function handles various cases where we need to continue
2835 waiting for the inferior. */
2836 /* (Used to be the keep_going: label in the old wait_for_inferior) */
2839 keep_going (struct execution_control_state *ecs)
2841 /* Save the pc before execution, to compare with pc after stop. */
2842 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
2844 if (ecs->update_step_sp)
2845 step_sp = read_sp ();
2846 ecs->update_step_sp = 0;
2848 /* If we did not do break;, it means we should keep running the
2849 inferior and not return to debugger. */
2851 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
2853 /* We took a signal (which we are supposed to pass through to
2854 the inferior, else we'd have done a break above) and we
2855 haven't yet gotten our trap. Simply continue. */
2856 resume (currently_stepping (ecs), stop_signal);
2860 /* Either the trap was not expected, but we are continuing
2861 anyway (the user asked that this signal be passed to the
2864 The signal was SIGTRAP, e.g. it was our signal, but we
2865 decided we should resume from it.
2867 We're going to run this baby now!
2869 Insert breakpoints now, unless we are trying to one-proceed
2870 past a breakpoint. */
2871 /* If we've just finished a special step resume and we don't
2872 want to hit a breakpoint, pull em out. */
2873 if (step_resume_breakpoint == NULL
2874 && through_sigtramp_breakpoint == NULL
2875 && ecs->remove_breakpoints_on_following_step)
2877 ecs->remove_breakpoints_on_following_step = 0;
2878 remove_breakpoints ();
2879 breakpoints_inserted = 0;
2881 else if (!breakpoints_inserted &&
2882 (through_sigtramp_breakpoint != NULL || !ecs->another_trap))
2884 breakpoints_failed = insert_breakpoints ();
2885 if (breakpoints_failed)
2887 stop_stepping (ecs);
2890 breakpoints_inserted = 1;
2893 trap_expected = ecs->another_trap;
2895 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
2896 specifies that such a signal should be delivered to the
2899 Typically, this would occure when a user is debugging a
2900 target monitor on a simulator: the target monitor sets a
2901 breakpoint; the simulator encounters this break-point and
2902 halts the simulation handing control to GDB; GDB, noteing
2903 that the break-point isn't valid, returns control back to the
2904 simulator; the simulator then delivers the hardware
2905 equivalent of a SIGNAL_TRAP to the program being debugged. */
2907 if (stop_signal == TARGET_SIGNAL_TRAP && !signal_program[stop_signal])
2908 stop_signal = TARGET_SIGNAL_0;
2910 #ifdef SHIFT_INST_REGS
2911 /* I'm not sure when this following segment applies. I do know,
2912 now, that we shouldn't rewrite the regs when we were stopped
2913 by a random signal from the inferior process. */
2914 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2915 (this is only used on the 88k). */
2917 if (!bpstat_explains_signal (stop_bpstat)
2918 && (stop_signal != TARGET_SIGNAL_CHLD) && !stopped_by_random_signal)
2920 #endif /* SHIFT_INST_REGS */
2922 resume (currently_stepping (ecs), stop_signal);
2925 prepare_to_wait (ecs);
2928 /* This function normally comes after a resume, before
2929 handle_inferior_event exits. It takes care of any last bits of
2930 housekeeping, and sets the all-important wait_some_more flag. */
2933 prepare_to_wait (struct execution_control_state *ecs)
2935 if (ecs->infwait_state == infwait_normal_state)
2937 overlay_cache_invalid = 1;
2939 /* We have to invalidate the registers BEFORE calling
2940 target_wait because they can be loaded from the target while
2941 in target_wait. This makes remote debugging a bit more
2942 efficient for those targets that provide critical registers
2943 as part of their normal status mechanism. */
2945 registers_changed ();
2946 ecs->waiton_ptid = pid_to_ptid (-1);
2947 ecs->wp = &(ecs->ws);
2949 /* This is the old end of the while loop. Let everybody know we
2950 want to wait for the inferior some more and get called again
2952 ecs->wait_some_more = 1;
2955 /* Print why the inferior has stopped. We always print something when
2956 the inferior exits, or receives a signal. The rest of the cases are
2957 dealt with later on in normal_stop() and print_it_typical(). Ideally
2958 there should be a call to this function from handle_inferior_event()
2959 each time stop_stepping() is called.*/
2961 print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
2963 switch (stop_reason)
2966 /* We don't deal with these cases from handle_inferior_event()
2969 case END_STEPPING_RANGE:
2970 /* We are done with a step/next/si/ni command. */
2971 /* For now print nothing. */
2972 /* Print a message only if not in the middle of doing a "step n"
2973 operation for n > 1 */
2974 if (!step_multi || !stop_step)
2975 if (ui_out_is_mi_like_p (uiout))
2976 ui_out_field_string (uiout, "reason", "end-stepping-range");
2978 case BREAKPOINT_HIT:
2979 /* We found a breakpoint. */
2980 /* For now print nothing. */
2983 /* The inferior was terminated by a signal. */
2984 annotate_signalled ();
2985 if (ui_out_is_mi_like_p (uiout))
2986 ui_out_field_string (uiout, "reason", "exited-signalled");
2987 ui_out_text (uiout, "\nProgram terminated with signal ");
2988 annotate_signal_name ();
2989 ui_out_field_string (uiout, "signal-name",
2990 target_signal_to_name (stop_info));
2991 annotate_signal_name_end ();
2992 ui_out_text (uiout, ", ");
2993 annotate_signal_string ();
2994 ui_out_field_string (uiout, "signal-meaning",
2995 target_signal_to_string (stop_info));
2996 annotate_signal_string_end ();
2997 ui_out_text (uiout, ".\n");
2998 ui_out_text (uiout, "The program no longer exists.\n");
3001 /* The inferior program is finished. */
3002 annotate_exited (stop_info);
3005 if (ui_out_is_mi_like_p (uiout))
3006 ui_out_field_string (uiout, "reason", "exited");
3007 ui_out_text (uiout, "\nProgram exited with code ");
3008 ui_out_field_fmt (uiout, "exit-code", "0%o",
3009 (unsigned int) stop_info);
3010 ui_out_text (uiout, ".\n");
3014 if (ui_out_is_mi_like_p (uiout))
3015 ui_out_field_string (uiout, "reason", "exited-normally");
3016 ui_out_text (uiout, "\nProgram exited normally.\n");
3019 case SIGNAL_RECEIVED:
3020 /* Signal received. The signal table tells us to print about
3023 ui_out_text (uiout, "\nProgram received signal ");
3024 annotate_signal_name ();
3025 if (ui_out_is_mi_like_p (uiout))
3026 ui_out_field_string (uiout, "reason", "signal-received");
3027 ui_out_field_string (uiout, "signal-name",
3028 target_signal_to_name (stop_info));
3029 annotate_signal_name_end ();
3030 ui_out_text (uiout, ", ");
3031 annotate_signal_string ();
3032 ui_out_field_string (uiout, "signal-meaning",
3033 target_signal_to_string (stop_info));
3034 annotate_signal_string_end ();
3035 ui_out_text (uiout, ".\n");
3038 internal_error (__FILE__, __LINE__,
3039 "print_stop_reason: unrecognized enum value");
3045 /* Here to return control to GDB when the inferior stops for real.
3046 Print appropriate messages, remove breakpoints, give terminal our modes.
3048 STOP_PRINT_FRAME nonzero means print the executing frame
3049 (pc, function, args, file, line number and line text).
3050 BREAKPOINTS_FAILED nonzero means stop was due to error
3051 attempting to insert breakpoints. */
3056 struct target_waitstatus last;
3059 get_last_target_status (&last_ptid, &last);
3061 /* As with the notification of thread events, we want to delay
3062 notifying the user that we've switched thread context until
3063 the inferior actually stops.
3065 There's no point in saying anything if the inferior has exited.
3066 Note that SIGNALLED here means "exited with a signal", not
3067 "received a signal". */
3068 if (!ptid_equal (previous_inferior_ptid, inferior_ptid)
3069 && target_has_execution
3070 && last.kind != TARGET_WAITKIND_SIGNALLED
3071 && last.kind != TARGET_WAITKIND_EXITED)
3073 target_terminal_ours_for_output ();
3074 printf_filtered ("[Switching to %s]\n",
3075 target_pid_or_tid_to_str (inferior_ptid));
3076 previous_inferior_ptid = inferior_ptid;
3079 /* Make sure that the current_frame's pc is correct. This
3080 is a correction for setting up the frame info before doing
3081 DECR_PC_AFTER_BREAK */
3082 if (target_has_execution)
3083 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3084 DECR_PC_AFTER_BREAK, the program counter can change. Ask the
3085 frame code to check for this and sort out any resultant mess.
3086 DECR_PC_AFTER_BREAK needs to just go away. */
3087 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3089 if (target_has_execution && breakpoints_inserted)
3091 if (remove_breakpoints ())
3093 target_terminal_ours_for_output ();
3094 printf_filtered ("Cannot remove breakpoints because ");
3095 printf_filtered ("program is no longer writable.\n");
3096 printf_filtered ("It might be running in another process.\n");
3097 printf_filtered ("Further execution is probably impossible.\n");
3100 breakpoints_inserted = 0;
3102 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3103 Delete any breakpoint that is to be deleted at the next stop. */
3105 breakpoint_auto_delete (stop_bpstat);
3107 /* If an auto-display called a function and that got a signal,
3108 delete that auto-display to avoid an infinite recursion. */
3110 if (stopped_by_random_signal)
3111 disable_current_display ();
3113 /* Don't print a message if in the middle of doing a "step n"
3114 operation for n > 1 */
3115 if (step_multi && stop_step)
3118 target_terminal_ours ();
3120 /* Look up the hook_stop and run it (CLI internally handles problem
3121 of stop_command's pre-hook not existing). */
3123 catch_errors (hook_stop_stub, stop_command,
3124 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3126 if (!target_has_stack)
3132 /* Select innermost stack frame - i.e., current frame is frame 0,
3133 and current location is based on that.
3134 Don't do this on return from a stack dummy routine,
3135 or if the program has exited. */
3137 if (!stop_stack_dummy)
3139 select_frame (get_current_frame ());
3141 /* Print current location without a level number, if
3142 we have changed functions or hit a breakpoint.
3143 Print source line if we have one.
3144 bpstat_print() contains the logic deciding in detail
3145 what to print, based on the event(s) that just occurred. */
3147 if (stop_print_frame && deprecated_selected_frame)
3151 int do_frame_printing = 1;
3153 bpstat_ret = bpstat_print (stop_bpstat);
3157 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3158 (or should) carry around the function and does (or
3159 should) use that when doing a frame comparison. */
3161 && frame_id_eq (step_frame_id,
3162 get_frame_id (get_current_frame ()))
3163 && step_start_function == find_pc_function (stop_pc))
3164 source_flag = SRC_LINE; /* finished step, just print source line */
3166 source_flag = SRC_AND_LOC; /* print location and source line */
3168 case PRINT_SRC_AND_LOC:
3169 source_flag = SRC_AND_LOC; /* print location and source line */
3171 case PRINT_SRC_ONLY:
3172 source_flag = SRC_LINE;
3175 source_flag = SRC_LINE; /* something bogus */
3176 do_frame_printing = 0;
3179 internal_error (__FILE__, __LINE__, "Unknown value.");
3181 /* For mi, have the same behavior every time we stop:
3182 print everything but the source line. */
3183 if (ui_out_is_mi_like_p (uiout))
3184 source_flag = LOC_AND_ADDRESS;
3186 if (ui_out_is_mi_like_p (uiout))
3187 ui_out_field_int (uiout, "thread-id",
3188 pid_to_thread_id (inferior_ptid));
3189 /* The behavior of this routine with respect to the source
3191 SRC_LINE: Print only source line
3192 LOCATION: Print only location
3193 SRC_AND_LOC: Print location and source line */
3194 if (do_frame_printing)
3195 print_stack_frame (deprecated_selected_frame, -1, source_flag);
3197 /* Display the auto-display expressions. */
3202 /* Save the function value return registers, if we care.
3203 We might be about to restore their previous contents. */
3204 if (proceed_to_finish)
3205 /* NB: The copy goes through to the target picking up the value of
3206 all the registers. */
3207 regcache_cpy (stop_registers, current_regcache);
3209 if (stop_stack_dummy)
3211 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3212 ends with a setting of the current frame, so we can use that
3214 frame_pop (get_current_frame ());
3215 /* Set stop_pc to what it was before we called the function.
3216 Can't rely on restore_inferior_status because that only gets
3217 called if we don't stop in the called function. */
3218 stop_pc = read_pc ();
3219 select_frame (get_current_frame ());
3223 annotate_stopped ();
3224 observer_notify_normal_stop ();
3228 hook_stop_stub (void *cmd)
3230 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
3235 signal_stop_state (int signo)
3237 return signal_stop[signo];
3241 signal_print_state (int signo)
3243 return signal_print[signo];
3247 signal_pass_state (int signo)
3249 return signal_program[signo];
3253 signal_stop_update (int signo, int state)
3255 int ret = signal_stop[signo];
3256 signal_stop[signo] = state;
3261 signal_print_update (int signo, int state)
3263 int ret = signal_print[signo];
3264 signal_print[signo] = state;
3269 signal_pass_update (int signo, int state)
3271 int ret = signal_program[signo];
3272 signal_program[signo] = state;
3277 sig_print_header (void)
3280 Signal Stop\tPrint\tPass to program\tDescription\n");
3284 sig_print_info (enum target_signal oursig)
3286 char *name = target_signal_to_name (oursig);
3287 int name_padding = 13 - strlen (name);
3289 if (name_padding <= 0)
3292 printf_filtered ("%s", name);
3293 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
3294 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3295 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3296 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3297 printf_filtered ("%s\n", target_signal_to_string (oursig));
3300 /* Specify how various signals in the inferior should be handled. */
3303 handle_command (char *args, int from_tty)
3306 int digits, wordlen;
3307 int sigfirst, signum, siglast;
3308 enum target_signal oursig;
3311 unsigned char *sigs;
3312 struct cleanup *old_chain;
3316 error_no_arg ("signal to handle");
3319 /* Allocate and zero an array of flags for which signals to handle. */
3321 nsigs = (int) TARGET_SIGNAL_LAST;
3322 sigs = (unsigned char *) alloca (nsigs);
3323 memset (sigs, 0, nsigs);
3325 /* Break the command line up into args. */
3327 argv = buildargv (args);
3332 old_chain = make_cleanup_freeargv (argv);
3334 /* Walk through the args, looking for signal oursigs, signal names, and
3335 actions. Signal numbers and signal names may be interspersed with
3336 actions, with the actions being performed for all signals cumulatively
3337 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3339 while (*argv != NULL)
3341 wordlen = strlen (*argv);
3342 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3346 sigfirst = siglast = -1;
3348 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3350 /* Apply action to all signals except those used by the
3351 debugger. Silently skip those. */
3354 siglast = nsigs - 1;
3356 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3358 SET_SIGS (nsigs, sigs, signal_stop);
3359 SET_SIGS (nsigs, sigs, signal_print);
3361 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3363 UNSET_SIGS (nsigs, sigs, signal_program);
3365 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3367 SET_SIGS (nsigs, sigs, signal_print);
3369 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3371 SET_SIGS (nsigs, sigs, signal_program);
3373 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3375 UNSET_SIGS (nsigs, sigs, signal_stop);
3377 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3379 SET_SIGS (nsigs, sigs, signal_program);
3381 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3383 UNSET_SIGS (nsigs, sigs, signal_print);
3384 UNSET_SIGS (nsigs, sigs, signal_stop);
3386 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3388 UNSET_SIGS (nsigs, sigs, signal_program);
3390 else if (digits > 0)
3392 /* It is numeric. The numeric signal refers to our own
3393 internal signal numbering from target.h, not to host/target
3394 signal number. This is a feature; users really should be
3395 using symbolic names anyway, and the common ones like
3396 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3398 sigfirst = siglast = (int)
3399 target_signal_from_command (atoi (*argv));
3400 if ((*argv)[digits] == '-')
3403 target_signal_from_command (atoi ((*argv) + digits + 1));
3405 if (sigfirst > siglast)
3407 /* Bet he didn't figure we'd think of this case... */
3415 oursig = target_signal_from_name (*argv);
3416 if (oursig != TARGET_SIGNAL_UNKNOWN)
3418 sigfirst = siglast = (int) oursig;
3422 /* Not a number and not a recognized flag word => complain. */
3423 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3427 /* If any signal numbers or symbol names were found, set flags for
3428 which signals to apply actions to. */
3430 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3432 switch ((enum target_signal) signum)
3434 case TARGET_SIGNAL_TRAP:
3435 case TARGET_SIGNAL_INT:
3436 if (!allsigs && !sigs[signum])
3438 if (query ("%s is used by the debugger.\n\
3439 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum)))
3445 printf_unfiltered ("Not confirmed, unchanged.\n");
3446 gdb_flush (gdb_stdout);
3450 case TARGET_SIGNAL_0:
3451 case TARGET_SIGNAL_DEFAULT:
3452 case TARGET_SIGNAL_UNKNOWN:
3453 /* Make sure that "all" doesn't print these. */
3464 target_notice_signals (inferior_ptid);
3468 /* Show the results. */
3469 sig_print_header ();
3470 for (signum = 0; signum < nsigs; signum++)
3474 sig_print_info (signum);
3479 do_cleanups (old_chain);
3483 xdb_handle_command (char *args, int from_tty)
3486 struct cleanup *old_chain;
3488 /* Break the command line up into args. */
3490 argv = buildargv (args);
3495 old_chain = make_cleanup_freeargv (argv);
3496 if (argv[1] != (char *) NULL)
3501 bufLen = strlen (argv[0]) + 20;
3502 argBuf = (char *) xmalloc (bufLen);
3506 enum target_signal oursig;
3508 oursig = target_signal_from_name (argv[0]);
3509 memset (argBuf, 0, bufLen);
3510 if (strcmp (argv[1], "Q") == 0)
3511 sprintf (argBuf, "%s %s", argv[0], "noprint");
3514 if (strcmp (argv[1], "s") == 0)
3516 if (!signal_stop[oursig])
3517 sprintf (argBuf, "%s %s", argv[0], "stop");
3519 sprintf (argBuf, "%s %s", argv[0], "nostop");
3521 else if (strcmp (argv[1], "i") == 0)
3523 if (!signal_program[oursig])
3524 sprintf (argBuf, "%s %s", argv[0], "pass");
3526 sprintf (argBuf, "%s %s", argv[0], "nopass");
3528 else if (strcmp (argv[1], "r") == 0)
3530 if (!signal_print[oursig])
3531 sprintf (argBuf, "%s %s", argv[0], "print");
3533 sprintf (argBuf, "%s %s", argv[0], "noprint");
3539 handle_command (argBuf, from_tty);
3541 printf_filtered ("Invalid signal handling flag.\n");
3546 do_cleanups (old_chain);
3549 /* Print current contents of the tables set by the handle command.
3550 It is possible we should just be printing signals actually used
3551 by the current target (but for things to work right when switching
3552 targets, all signals should be in the signal tables). */
3555 signals_info (char *signum_exp, int from_tty)
3557 enum target_signal oursig;
3558 sig_print_header ();
3562 /* First see if this is a symbol name. */
3563 oursig = target_signal_from_name (signum_exp);
3564 if (oursig == TARGET_SIGNAL_UNKNOWN)
3566 /* No, try numeric. */
3568 target_signal_from_command (parse_and_eval_long (signum_exp));
3570 sig_print_info (oursig);
3574 printf_filtered ("\n");
3575 /* These ugly casts brought to you by the native VAX compiler. */
3576 for (oursig = TARGET_SIGNAL_FIRST;
3577 (int) oursig < (int) TARGET_SIGNAL_LAST;
3578 oursig = (enum target_signal) ((int) oursig + 1))
3582 if (oursig != TARGET_SIGNAL_UNKNOWN
3583 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
3584 sig_print_info (oursig);
3587 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3590 struct inferior_status
3592 enum target_signal stop_signal;
3596 int stop_stack_dummy;
3597 int stopped_by_random_signal;
3599 CORE_ADDR step_range_start;
3600 CORE_ADDR step_range_end;
3601 struct frame_id step_frame_id;
3602 enum step_over_calls_kind step_over_calls;
3603 CORE_ADDR step_resume_break_address;
3604 int stop_after_trap;
3606 struct regcache *stop_registers;
3608 /* These are here because if call_function_by_hand has written some
3609 registers and then decides to call error(), we better not have changed
3611 struct regcache *registers;
3613 /* A frame unique identifier. */
3614 struct frame_id selected_frame_id;
3616 int breakpoint_proceeded;
3617 int restore_stack_info;
3618 int proceed_to_finish;
3622 write_inferior_status_register (struct inferior_status *inf_status, int regno,
3625 int size = REGISTER_RAW_SIZE (regno);
3626 void *buf = alloca (size);
3627 store_signed_integer (buf, size, val);
3628 regcache_raw_write (inf_status->registers, regno, buf);
3631 /* Save all of the information associated with the inferior<==>gdb
3632 connection. INF_STATUS is a pointer to a "struct inferior_status"
3633 (defined in inferior.h). */
3635 struct inferior_status *
3636 save_inferior_status (int restore_stack_info)
3638 struct inferior_status *inf_status = XMALLOC (struct inferior_status);
3640 inf_status->stop_signal = stop_signal;
3641 inf_status->stop_pc = stop_pc;
3642 inf_status->stop_step = stop_step;
3643 inf_status->stop_stack_dummy = stop_stack_dummy;
3644 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3645 inf_status->trap_expected = trap_expected;
3646 inf_status->step_range_start = step_range_start;
3647 inf_status->step_range_end = step_range_end;
3648 inf_status->step_frame_id = step_frame_id;
3649 inf_status->step_over_calls = step_over_calls;
3650 inf_status->stop_after_trap = stop_after_trap;
3651 inf_status->stop_soon = stop_soon;
3652 /* Save original bpstat chain here; replace it with copy of chain.
3653 If caller's caller is walking the chain, they'll be happier if we
3654 hand them back the original chain when restore_inferior_status is
3656 inf_status->stop_bpstat = stop_bpstat;
3657 stop_bpstat = bpstat_copy (stop_bpstat);
3658 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3659 inf_status->restore_stack_info = restore_stack_info;
3660 inf_status->proceed_to_finish = proceed_to_finish;
3662 inf_status->stop_registers = regcache_dup_no_passthrough (stop_registers);
3664 inf_status->registers = regcache_dup (current_regcache);
3666 inf_status->selected_frame_id = get_frame_id (deprecated_selected_frame);
3671 restore_selected_frame (void *args)
3673 struct frame_id *fid = (struct frame_id *) args;
3674 struct frame_info *frame;
3676 frame = frame_find_by_id (*fid);
3678 /* If inf_status->selected_frame_id is NULL, there was no previously
3682 warning ("Unable to restore previously selected frame.\n");
3686 select_frame (frame);
3692 restore_inferior_status (struct inferior_status *inf_status)
3694 stop_signal = inf_status->stop_signal;
3695 stop_pc = inf_status->stop_pc;
3696 stop_step = inf_status->stop_step;
3697 stop_stack_dummy = inf_status->stop_stack_dummy;
3698 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3699 trap_expected = inf_status->trap_expected;
3700 step_range_start = inf_status->step_range_start;
3701 step_range_end = inf_status->step_range_end;
3702 step_frame_id = inf_status->step_frame_id;
3703 step_over_calls = inf_status->step_over_calls;
3704 stop_after_trap = inf_status->stop_after_trap;
3705 stop_soon = inf_status->stop_soon;
3706 bpstat_clear (&stop_bpstat);
3707 stop_bpstat = inf_status->stop_bpstat;
3708 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3709 proceed_to_finish = inf_status->proceed_to_finish;
3711 /* FIXME: Is the restore of stop_registers always needed. */
3712 regcache_xfree (stop_registers);
3713 stop_registers = inf_status->stop_registers;
3715 /* The inferior can be gone if the user types "print exit(0)"
3716 (and perhaps other times). */
3717 if (target_has_execution)
3718 /* NB: The register write goes through to the target. */
3719 regcache_cpy (current_regcache, inf_status->registers);
3720 regcache_xfree (inf_status->registers);
3722 /* FIXME: If we are being called after stopping in a function which
3723 is called from gdb, we should not be trying to restore the
3724 selected frame; it just prints a spurious error message (The
3725 message is useful, however, in detecting bugs in gdb (like if gdb
3726 clobbers the stack)). In fact, should we be restoring the
3727 inferior status at all in that case? . */
3729 if (target_has_stack && inf_status->restore_stack_info)
3731 /* The point of catch_errors is that if the stack is clobbered,
3732 walking the stack might encounter a garbage pointer and
3733 error() trying to dereference it. */
3735 (restore_selected_frame, &inf_status->selected_frame_id,
3736 "Unable to restore previously selected frame:\n",
3737 RETURN_MASK_ERROR) == 0)
3738 /* Error in restoring the selected frame. Select the innermost
3740 select_frame (get_current_frame ());
3748 do_restore_inferior_status_cleanup (void *sts)
3750 restore_inferior_status (sts);
3754 make_cleanup_restore_inferior_status (struct inferior_status *inf_status)
3756 return make_cleanup (do_restore_inferior_status_cleanup, inf_status);
3760 discard_inferior_status (struct inferior_status *inf_status)
3762 /* See save_inferior_status for info on stop_bpstat. */
3763 bpstat_clear (&inf_status->stop_bpstat);
3764 regcache_xfree (inf_status->registers);
3765 regcache_xfree (inf_status->stop_registers);
3770 inferior_has_forked (int pid, int *child_pid)
3772 struct target_waitstatus last;
3775 get_last_target_status (&last_ptid, &last);
3777 if (last.kind != TARGET_WAITKIND_FORKED)
3780 if (ptid_get_pid (last_ptid) != pid)
3783 *child_pid = last.value.related_pid;
3788 inferior_has_vforked (int pid, int *child_pid)
3790 struct target_waitstatus last;
3793 get_last_target_status (&last_ptid, &last);
3795 if (last.kind != TARGET_WAITKIND_VFORKED)
3798 if (ptid_get_pid (last_ptid) != pid)
3801 *child_pid = last.value.related_pid;
3806 inferior_has_execd (int pid, char **execd_pathname)
3808 struct target_waitstatus last;
3811 get_last_target_status (&last_ptid, &last);
3813 if (last.kind != TARGET_WAITKIND_EXECD)
3816 if (ptid_get_pid (last_ptid) != pid)
3819 *execd_pathname = xstrdup (last.value.execd_pathname);
3823 /* Oft used ptids */
3825 ptid_t minus_one_ptid;
3827 /* Create a ptid given the necessary PID, LWP, and TID components. */
3830 ptid_build (int pid, long lwp, long tid)
3840 /* Create a ptid from just a pid. */
3843 pid_to_ptid (int pid)
3845 return ptid_build (pid, 0, 0);
3848 /* Fetch the pid (process id) component from a ptid. */
3851 ptid_get_pid (ptid_t ptid)
3856 /* Fetch the lwp (lightweight process) component from a ptid. */
3859 ptid_get_lwp (ptid_t ptid)
3864 /* Fetch the tid (thread id) component from a ptid. */
3867 ptid_get_tid (ptid_t ptid)
3872 /* ptid_equal() is used to test equality of two ptids. */
3875 ptid_equal (ptid_t ptid1, ptid_t ptid2)
3877 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
3878 && ptid1.tid == ptid2.tid);
3881 /* restore_inferior_ptid() will be used by the cleanup machinery
3882 to restore the inferior_ptid value saved in a call to
3883 save_inferior_ptid(). */
3886 restore_inferior_ptid (void *arg)
3888 ptid_t *saved_ptid_ptr = arg;
3889 inferior_ptid = *saved_ptid_ptr;
3893 /* Save the value of inferior_ptid so that it may be restored by a
3894 later call to do_cleanups(). Returns the struct cleanup pointer
3895 needed for later doing the cleanup. */
3898 save_inferior_ptid (void)
3900 ptid_t *saved_ptid_ptr;
3902 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
3903 *saved_ptid_ptr = inferior_ptid;
3904 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
3911 stop_registers = regcache_xmalloc (current_gdbarch);
3915 _initialize_infrun (void)
3919 struct cmd_list_element *c;
3921 register_gdbarch_swap (&stop_registers, sizeof (stop_registers), NULL);
3922 register_gdbarch_swap (NULL, 0, build_infrun);
3924 add_info ("signals", signals_info,
3925 "What debugger does when program gets various signals.\n\
3926 Specify a signal as argument to print info on that signal only.");
3927 add_info_alias ("handle", "signals", 0);
3929 add_com ("handle", class_run, handle_command,
3930 concat ("Specify how to handle a signal.\n\
3931 Args are signals and actions to apply to those signals.\n\
3932 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3933 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3934 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3935 The special arg \"all\" is recognized to mean all signals except those\n\
3936 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3937 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3938 Stop means reenter debugger if this signal happens (implies print).\n\
3939 Print means print a message if this signal happens.\n\
3940 Pass means let program see this signal; otherwise program doesn't know.\n\
3941 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3942 Pass and Stop may be combined.", NULL));
3945 add_com ("lz", class_info, signals_info,
3946 "What debugger does when program gets various signals.\n\
3947 Specify a signal as argument to print info on that signal only.");
3948 add_com ("z", class_run, xdb_handle_command,
3949 concat ("Specify how to handle a signal.\n\
3950 Args are signals and actions to apply to those signals.\n\
3951 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3952 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3953 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3954 The special arg \"all\" is recognized to mean all signals except those\n\
3955 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3956 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3957 nopass), \"Q\" (noprint)\n\
3958 Stop means reenter debugger if this signal happens (implies print).\n\
3959 Print means print a message if this signal happens.\n\
3960 Pass means let program see this signal; otherwise program doesn't know.\n\
3961 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3962 Pass and Stop may be combined.", NULL));
3967 add_cmd ("stop", class_obscure, not_just_help_class_command, "There is no `stop' command, but you can set a hook on `stop'.\n\
3968 This allows you to set a list of commands to be run each time execution\n\
3969 of the program stops.", &cmdlist);
3971 numsigs = (int) TARGET_SIGNAL_LAST;
3972 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
3973 signal_print = (unsigned char *)
3974 xmalloc (sizeof (signal_print[0]) * numsigs);
3975 signal_program = (unsigned char *)
3976 xmalloc (sizeof (signal_program[0]) * numsigs);
3977 for (i = 0; i < numsigs; i++)
3980 signal_print[i] = 1;
3981 signal_program[i] = 1;
3984 /* Signals caused by debugger's own actions
3985 should not be given to the program afterwards. */
3986 signal_program[TARGET_SIGNAL_TRAP] = 0;
3987 signal_program[TARGET_SIGNAL_INT] = 0;
3989 /* Signals that are not errors should not normally enter the debugger. */
3990 signal_stop[TARGET_SIGNAL_ALRM] = 0;
3991 signal_print[TARGET_SIGNAL_ALRM] = 0;
3992 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
3993 signal_print[TARGET_SIGNAL_VTALRM] = 0;
3994 signal_stop[TARGET_SIGNAL_PROF] = 0;
3995 signal_print[TARGET_SIGNAL_PROF] = 0;
3996 signal_stop[TARGET_SIGNAL_CHLD] = 0;
3997 signal_print[TARGET_SIGNAL_CHLD] = 0;
3998 signal_stop[TARGET_SIGNAL_IO] = 0;
3999 signal_print[TARGET_SIGNAL_IO] = 0;
4000 signal_stop[TARGET_SIGNAL_POLL] = 0;
4001 signal_print[TARGET_SIGNAL_POLL] = 0;
4002 signal_stop[TARGET_SIGNAL_URG] = 0;
4003 signal_print[TARGET_SIGNAL_URG] = 0;
4004 signal_stop[TARGET_SIGNAL_WINCH] = 0;
4005 signal_print[TARGET_SIGNAL_WINCH] = 0;
4007 /* These signals are used internally by user-level thread
4008 implementations. (See signal(5) on Solaris.) Like the above
4009 signals, a healthy program receives and handles them as part of
4010 its normal operation. */
4011 signal_stop[TARGET_SIGNAL_LWP] = 0;
4012 signal_print[TARGET_SIGNAL_LWP] = 0;
4013 signal_stop[TARGET_SIGNAL_WAITING] = 0;
4014 signal_print[TARGET_SIGNAL_WAITING] = 0;
4015 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
4016 signal_print[TARGET_SIGNAL_CANCEL] = 0;
4020 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
4021 (char *) &stop_on_solib_events,
4022 "Set stopping for shared library events.\n\
4023 If nonzero, gdb will give control to the user when the dynamic linker\n\
4024 notifies gdb of shared library events. The most common event of interest\n\
4025 to the user would be loading/unloading of a new library.\n", &setlist), &showlist);
4028 c = add_set_enum_cmd ("follow-fork-mode",
4030 follow_fork_mode_kind_names, &follow_fork_mode_string,
4031 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4032 kernel problem. It's also not terribly useful without a GUI to
4033 help the user drive two debuggers. So for now, I'm disabling
4034 the "both" option. */
4035 /* "Set debugger response to a program call of fork \
4037 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4038 parent - the original process is debugged after a fork\n\
4039 child - the new process is debugged after a fork\n\
4040 both - both the parent and child are debugged after a fork\n\
4041 ask - the debugger will ask for one of the above choices\n\
4042 For \"both\", another copy of the debugger will be started to follow\n\
4043 the new child process. The original debugger will continue to follow\n\
4044 the original parent process. To distinguish their prompts, the\n\
4045 debugger copy's prompt will be changed.\n\
4046 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4047 By default, the debugger will follow the parent process.",
4049 "Set debugger response to a program call of fork \
4051 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4052 parent - the original process is debugged after a fork\n\
4053 child - the new process is debugged after a fork\n\
4054 ask - the debugger will ask for one of the above choices\n\
4055 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4056 By default, the debugger will follow the parent process.", &setlist);
4057 add_show_from_set (c, &showlist);
4059 c = add_set_enum_cmd ("scheduler-locking", class_run, scheduler_enums, /* array of string names */
4060 &scheduler_mode, /* current mode */
4061 "Set mode for locking scheduler during execution.\n\
4062 off == no locking (threads may preempt at any time)\n\
4063 on == full locking (no thread except the current thread may run)\n\
4064 step == scheduler locked during every single-step operation.\n\
4065 In this mode, no other thread may run during a step command.\n\
4066 Other threads may run while stepping over a function call ('next').", &setlist);
4068 set_cmd_sfunc (c, set_schedlock_func); /* traps on target vector */
4069 add_show_from_set (c, &showlist);
4071 c = add_set_cmd ("step-mode", class_run,
4072 var_boolean, (char *) &step_stop_if_no_debug,
4073 "Set mode of the step operation. When set, doing a step over a\n\
4074 function without debug line information will stop at the first\n\
4075 instruction of that function. Otherwise, the function is skipped and\n\
4076 the step command stops at a different source line.", &setlist);
4077 add_show_from_set (c, &showlist);
4079 /* ptid initializations */
4080 null_ptid = ptid_build (0, 0, 0);
4081 minus_one_ptid = ptid_build (-1, 0, 0);
4082 inferior_ptid = null_ptid;
4083 target_last_wait_ptid = minus_one_ptid;