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 /* This function returns TRUE if pc is the address of an instruction
157 that lies within the dynamic linker (such as the event hook, or the
160 This function must be used only when a dynamic linker event has
161 been caught, and the inferior is being stepped out of the hook, or
162 undefined results are guaranteed. */
164 #ifndef SOLIB_IN_DYNAMIC_LINKER
165 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
168 /* On MIPS16, a function that returns a floating point value may call
169 a library helper function to copy the return value to a floating point
170 register. The IGNORE_HELPER_CALL macro returns non-zero if we
171 should ignore (i.e. step over) this function call. */
172 #ifndef IGNORE_HELPER_CALL
173 #define IGNORE_HELPER_CALL(pc) 0
176 /* On some systems, the PC may be left pointing at an instruction that won't
177 actually be executed. This is usually indicated by a bit in the PSW. If
178 we find ourselves in such a state, then we step the target beyond the
179 nullified instruction before returning control to the user so as to avoid
182 #ifndef INSTRUCTION_NULLIFIED
183 #define INSTRUCTION_NULLIFIED 0
186 /* We can't step off a permanent breakpoint in the ordinary way, because we
187 can't remove it. Instead, we have to advance the PC to the next
188 instruction. This macro should expand to a pointer to a function that
189 does that, or zero if we have no such function. If we don't have a
190 definition for it, we have to report an error. */
191 #ifndef SKIP_PERMANENT_BREAKPOINT
192 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
194 default_skip_permanent_breakpoint (void)
197 The program is stopped at a permanent breakpoint, but GDB does not know\n\
198 how to step past a permanent breakpoint on this architecture. Try using\n\
199 a command like `return' or `jump' to continue execution.");
204 /* Convert the #defines into values. This is temporary until wfi control
205 flow is completely sorted out. */
207 #ifndef HAVE_STEPPABLE_WATCHPOINT
208 #define HAVE_STEPPABLE_WATCHPOINT 0
210 #undef HAVE_STEPPABLE_WATCHPOINT
211 #define HAVE_STEPPABLE_WATCHPOINT 1
214 #ifndef CANNOT_STEP_HW_WATCHPOINTS
215 #define CANNOT_STEP_HW_WATCHPOINTS 0
217 #undef CANNOT_STEP_HW_WATCHPOINTS
218 #define CANNOT_STEP_HW_WATCHPOINTS 1
221 /* Tables of how to react to signals; the user sets them. */
223 static unsigned char *signal_stop;
224 static unsigned char *signal_print;
225 static unsigned char *signal_program;
227 #define SET_SIGS(nsigs,sigs,flags) \
229 int signum = (nsigs); \
230 while (signum-- > 0) \
231 if ((sigs)[signum]) \
232 (flags)[signum] = 1; \
235 #define UNSET_SIGS(nsigs,sigs,flags) \
237 int signum = (nsigs); \
238 while (signum-- > 0) \
239 if ((sigs)[signum]) \
240 (flags)[signum] = 0; \
243 /* Value to pass to target_resume() to cause all threads to resume */
245 #define RESUME_ALL (pid_to_ptid (-1))
247 /* Command list pointer for the "stop" placeholder. */
249 static struct cmd_list_element *stop_command;
251 /* Nonzero if breakpoints are now inserted in the inferior. */
253 static int breakpoints_inserted;
255 /* Function inferior was in as of last step command. */
257 static struct symbol *step_start_function;
259 /* Nonzero if we are expecting a trace trap and should proceed from it. */
261 static int trap_expected;
264 /* Nonzero if we want to give control to the user when we're notified
265 of shared library events by the dynamic linker. */
266 static int stop_on_solib_events;
270 /* Nonzero if the next time we try to continue the inferior, it will
271 step one instruction and generate a spurious trace trap.
272 This is used to compensate for a bug in HP-UX. */
274 static int trap_expected_after_continue;
277 /* Nonzero means expecting a trace trap
278 and should stop the inferior and return silently when it happens. */
282 /* Nonzero means expecting a trap and caller will handle it themselves.
283 It is used after attach, due to attaching to a process;
284 when running in the shell before the child program has been exec'd;
285 and when running some kinds of remote stuff (FIXME?). */
287 enum stop_kind stop_soon;
289 /* Nonzero if proceed is being used for a "finish" command or a similar
290 situation when stop_registers should be saved. */
292 int proceed_to_finish;
294 /* Save register contents here when about to pop a stack dummy frame,
295 if-and-only-if proceed_to_finish is set.
296 Thus this contains the return value from the called function (assuming
297 values are returned in a register). */
299 struct regcache *stop_registers;
301 /* Nonzero if program stopped due to error trying to insert breakpoints. */
303 static int breakpoints_failed;
305 /* Nonzero after stop if current stack frame should be printed. */
307 static int stop_print_frame;
309 static struct breakpoint *step_resume_breakpoint = NULL;
310 static struct breakpoint *through_sigtramp_breakpoint = NULL;
312 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
313 interactions with an inferior that is running a kernel function
314 (aka, a system call or "syscall"). wait_for_inferior therefore
315 may have a need to know when the inferior is in a syscall. This
316 is a count of the number of inferior threads which are known to
317 currently be running in a syscall. */
318 static int number_of_threads_in_syscalls;
320 /* This is a cached copy of the pid/waitstatus of the last event
321 returned by target_wait()/target_wait_hook(). This information is
322 returned by get_last_target_status(). */
323 static ptid_t target_last_wait_ptid;
324 static struct target_waitstatus target_last_waitstatus;
326 /* This is used to remember when a fork, vfork or exec event
327 was caught by a catchpoint, and thus the event is to be
328 followed at the next resume of the inferior, and not
332 enum target_waitkind kind;
339 char *execd_pathname;
343 static const char follow_fork_mode_ask[] = "ask";
344 static const char follow_fork_mode_child[] = "child";
345 static const char follow_fork_mode_parent[] = "parent";
347 static const char *follow_fork_mode_kind_names[] = {
348 follow_fork_mode_ask,
349 follow_fork_mode_child,
350 follow_fork_mode_parent,
354 static const char *follow_fork_mode_string = follow_fork_mode_parent;
360 const char *follow_mode = follow_fork_mode_string;
361 int follow_child = (follow_mode == follow_fork_mode_child);
363 /* Or, did the user not know, and want us to ask? */
364 if (follow_fork_mode_string == follow_fork_mode_ask)
366 internal_error (__FILE__, __LINE__,
367 "follow_inferior_fork: \"ask\" mode not implemented");
368 /* follow_mode = follow_fork_mode_...; */
371 return target_follow_fork (follow_child);
375 follow_inferior_reset_breakpoints (void)
377 /* Was there a step_resume breakpoint? (There was if the user
378 did a "next" at the fork() call.) If so, explicitly reset its
381 step_resumes are a form of bp that are made to be per-thread.
382 Since we created the step_resume bp when the parent process
383 was being debugged, and now are switching to the child process,
384 from the breakpoint package's viewpoint, that's a switch of
385 "threads". We must update the bp's notion of which thread
386 it is for, or it'll be ignored when it triggers. */
388 if (step_resume_breakpoint)
389 breakpoint_re_set_thread (step_resume_breakpoint);
391 /* Reinsert all breakpoints in the child. The user may have set
392 breakpoints after catching the fork, in which case those
393 were never set in the child, but only in the parent. This makes
394 sure the inserted breakpoints match the breakpoint list. */
396 breakpoint_re_set ();
397 insert_breakpoints ();
400 /* EXECD_PATHNAME is assumed to be non-NULL. */
403 follow_exec (int pid, char *execd_pathname)
406 struct target_ops *tgt;
408 if (!may_follow_exec)
411 /* This is an exec event that we actually wish to pay attention to.
412 Refresh our symbol table to the newly exec'd program, remove any
415 If there are breakpoints, they aren't really inserted now,
416 since the exec() transformed our inferior into a fresh set
419 We want to preserve symbolic breakpoints on the list, since
420 we have hopes that they can be reset after the new a.out's
421 symbol table is read.
423 However, any "raw" breakpoints must be removed from the list
424 (e.g., the solib bp's), since their address is probably invalid
427 And, we DON'T want to call delete_breakpoints() here, since
428 that may write the bp's "shadow contents" (the instruction
429 value that was overwritten witha TRAP instruction). Since
430 we now have a new a.out, those shadow contents aren't valid. */
431 update_breakpoints_after_exec ();
433 /* If there was one, it's gone now. We cannot truly step-to-next
434 statement through an exec(). */
435 step_resume_breakpoint = NULL;
436 step_range_start = 0;
439 /* If there was one, it's gone now. */
440 through_sigtramp_breakpoint = NULL;
442 /* What is this a.out's name? */
443 printf_unfiltered ("Executing new program: %s\n", execd_pathname);
445 /* We've followed the inferior through an exec. Therefore, the
446 inferior has essentially been killed & reborn. */
448 /* First collect the run target in effect. */
449 tgt = find_run_target ();
450 /* If we can't find one, things are in a very strange state... */
452 error ("Could find run target to save before following exec");
454 gdb_flush (gdb_stdout);
455 target_mourn_inferior ();
456 inferior_ptid = pid_to_ptid (saved_pid);
457 /* Because mourn_inferior resets inferior_ptid. */
460 /* That a.out is now the one to use. */
461 exec_file_attach (execd_pathname, 0);
463 /* And also is where symbols can be found. */
464 symbol_file_add_main (execd_pathname, 0);
466 /* Reset the shared library package. This ensures that we get
467 a shlib event when the child reaches "_start", at which point
468 the dld will have had a chance to initialize the child. */
469 #if defined(SOLIB_RESTART)
472 #ifdef SOLIB_CREATE_INFERIOR_HOOK
473 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
476 /* Reinsert all breakpoints. (Those which were symbolic have
477 been reset to the proper address in the new a.out, thanks
478 to symbol_file_command...) */
479 insert_breakpoints ();
481 /* The next resume of this inferior should bring it to the shlib
482 startup breakpoints. (If the user had also set bp's on
483 "main" from the old (parent) process, then they'll auto-
484 matically get reset there in the new process.) */
487 /* Non-zero if we just simulating a single-step. This is needed
488 because we cannot remove the breakpoints in the inferior process
489 until after the `wait' in `wait_for_inferior'. */
490 static int singlestep_breakpoints_inserted_p = 0;
493 /* Things to clean up if we QUIT out of resume (). */
495 resume_cleanups (void *ignore)
500 static const char schedlock_off[] = "off";
501 static const char schedlock_on[] = "on";
502 static const char schedlock_step[] = "step";
503 static const char *scheduler_mode = schedlock_off;
504 static const char *scheduler_enums[] = {
512 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
514 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
515 the set command passed as a parameter. The clone operation will
516 include (BUG?) any ``set'' command callback, if present.
517 Commands like ``info set'' call all the ``show'' command
518 callbacks. Unfortunately, for ``show'' commands cloned from
519 ``set'', this includes callbacks belonging to ``set'' commands.
520 Making this worse, this only occures if add_show_from_set() is
521 called after add_cmd_sfunc() (BUG?). */
522 if (cmd_type (c) == set_cmd)
523 if (!target_can_lock_scheduler)
525 scheduler_mode = schedlock_off;
526 error ("Target '%s' cannot support this command.", target_shortname);
531 /* Resume the inferior, but allow a QUIT. This is useful if the user
532 wants to interrupt some lengthy single-stepping operation
533 (for child processes, the SIGINT goes to the inferior, and so
534 we get a SIGINT random_signal, but for remote debugging and perhaps
535 other targets, that's not true).
537 STEP nonzero if we should step (zero to continue instead).
538 SIG is the signal to give the inferior (zero for none). */
540 resume (int step, enum target_signal sig)
542 int should_resume = 1;
543 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
546 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
549 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
550 over an instruction that causes a page fault without triggering
551 a hardware watchpoint. The kernel properly notices that it shouldn't
552 stop, because the hardware watchpoint is not triggered, but it forgets
553 the step request and continues the program normally.
554 Work around the problem by removing hardware watchpoints if a step is
555 requested, GDB will check for a hardware watchpoint trigger after the
557 if (CANNOT_STEP_HW_WATCHPOINTS && step && breakpoints_inserted)
558 remove_hw_watchpoints ();
561 /* Normally, by the time we reach `resume', the breakpoints are either
562 removed or inserted, as appropriate. The exception is if we're sitting
563 at a permanent breakpoint; we need to step over it, but permanent
564 breakpoints can't be removed. So we have to test for it here. */
565 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here)
566 SKIP_PERMANENT_BREAKPOINT ();
568 if (SOFTWARE_SINGLE_STEP_P () && step)
570 /* Do it the hard way, w/temp breakpoints */
571 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ );
572 /* ...and don't ask hardware to do it. */
574 /* and do not pull these breakpoints until after a `wait' in
575 `wait_for_inferior' */
576 singlestep_breakpoints_inserted_p = 1;
579 /* Handle any optimized stores to the inferior NOW... */
580 #ifdef DO_DEFERRED_STORES
584 /* If there were any forks/vforks/execs that were caught and are
585 now to be followed, then do so. */
586 switch (pending_follow.kind)
588 case TARGET_WAITKIND_FORKED:
589 case TARGET_WAITKIND_VFORKED:
590 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
595 case TARGET_WAITKIND_EXECD:
596 /* follow_exec is called as soon as the exec event is seen. */
597 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
604 /* Install inferior's terminal modes. */
605 target_terminal_inferior ();
611 resume_ptid = RESUME_ALL; /* Default */
613 if ((step || singlestep_breakpoints_inserted_p) &&
614 !breakpoints_inserted && breakpoint_here_p (read_pc ()))
616 /* Stepping past a breakpoint without inserting breakpoints.
617 Make sure only the current thread gets to step, so that
618 other threads don't sneak past breakpoints while they are
621 resume_ptid = inferior_ptid;
624 if ((scheduler_mode == schedlock_on) ||
625 (scheduler_mode == schedlock_step &&
626 (step || singlestep_breakpoints_inserted_p)))
628 /* User-settable 'scheduler' mode requires solo thread resume. */
629 resume_ptid = inferior_ptid;
632 if (CANNOT_STEP_BREAKPOINT)
634 /* Most targets can step a breakpoint instruction, thus
635 executing it normally. But if this one cannot, just
636 continue and we will hit it anyway. */
637 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
640 target_resume (resume_ptid, step, sig);
643 discard_cleanups (old_cleanups);
647 /* Clear out all variables saying what to do when inferior is continued.
648 First do this, then set the ones you want, then call `proceed'. */
651 clear_proceed_status (void)
654 step_range_start = 0;
656 step_frame_id = null_frame_id;
657 step_over_calls = STEP_OVER_UNDEBUGGABLE;
659 stop_soon = NO_STOP_QUIETLY;
660 proceed_to_finish = 0;
661 breakpoint_proceeded = 1; /* We're about to proceed... */
663 /* Discard any remaining commands or status from previous stop. */
664 bpstat_clear (&stop_bpstat);
667 /* This should be suitable for any targets that support threads. */
670 prepare_to_proceed (void)
673 struct target_waitstatus wait_status;
675 /* Get the last target status returned by target_wait(). */
676 get_last_target_status (&wait_ptid, &wait_status);
678 /* Make sure we were stopped either at a breakpoint, or because
680 if (wait_status.kind != TARGET_WAITKIND_STOPPED
681 || (wait_status.value.sig != TARGET_SIGNAL_TRAP &&
682 wait_status.value.sig != TARGET_SIGNAL_INT))
687 if (!ptid_equal (wait_ptid, minus_one_ptid)
688 && !ptid_equal (inferior_ptid, wait_ptid))
690 /* Switched over from WAIT_PID. */
691 CORE_ADDR wait_pc = read_pc_pid (wait_ptid);
693 if (wait_pc != read_pc ())
695 /* Switch back to WAIT_PID thread. */
696 inferior_ptid = wait_ptid;
698 /* FIXME: This stuff came from switch_to_thread() in
699 thread.c (which should probably be a public function). */
700 flush_cached_frames ();
701 registers_changed ();
703 select_frame (get_current_frame ());
706 /* We return 1 to indicate that there is a breakpoint here,
707 so we need to step over it before continuing to avoid
708 hitting it straight away. */
709 if (breakpoint_here_p (wait_pc))
717 /* Record the pc of the program the last time it stopped. This is
718 just used internally by wait_for_inferior, but need to be preserved
719 over calls to it and cleared when the inferior is started. */
720 static CORE_ADDR prev_pc;
722 /* Basic routine for continuing the program in various fashions.
724 ADDR is the address to resume at, or -1 for resume where stopped.
725 SIGGNAL is the signal to give it, or 0 for none,
726 or -1 for act according to how it stopped.
727 STEP is nonzero if should trap after one instruction.
728 -1 means return after that and print nothing.
729 You should probably set various step_... variables
730 before calling here, if you are stepping.
732 You should call clear_proceed_status before calling proceed. */
735 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
740 step_start_function = find_pc_function (read_pc ());
744 if (addr == (CORE_ADDR) -1)
746 /* If there is a breakpoint at the address we will resume at,
747 step one instruction before inserting breakpoints
748 so that we do not stop right away (and report a second
749 hit at this breakpoint). */
751 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
754 #ifndef STEP_SKIPS_DELAY
755 #define STEP_SKIPS_DELAY(pc) (0)
756 #define STEP_SKIPS_DELAY_P (0)
758 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
759 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
760 is slow (it needs to read memory from the target). */
761 if (STEP_SKIPS_DELAY_P
762 && breakpoint_here_p (read_pc () + 4)
763 && STEP_SKIPS_DELAY (read_pc ()))
771 /* In a multi-threaded task we may select another thread
772 and then continue or step.
774 But if the old thread was stopped at a breakpoint, it
775 will immediately cause another breakpoint stop without
776 any execution (i.e. it will report a breakpoint hit
777 incorrectly). So we must step over it first.
779 prepare_to_proceed checks the current thread against the thread
780 that reported the most recent event. If a step-over is required
781 it returns TRUE and sets the current thread to the old thread. */
782 if (prepare_to_proceed () && breakpoint_here_p (read_pc ()))
786 if (trap_expected_after_continue)
788 /* If (step == 0), a trap will be automatically generated after
789 the first instruction is executed. Force step one
790 instruction to clear this condition. This should not occur
791 if step is nonzero, but it is harmless in that case. */
793 trap_expected_after_continue = 0;
795 #endif /* HP_OS_BUG */
798 /* We will get a trace trap after one instruction.
799 Continue it automatically and insert breakpoints then. */
803 insert_breakpoints ();
804 /* If we get here there was no call to error() in
805 insert breakpoints -- so they were inserted. */
806 breakpoints_inserted = 1;
809 if (siggnal != TARGET_SIGNAL_DEFAULT)
810 stop_signal = siggnal;
811 /* If this signal should not be seen by program,
812 give it zero. Used for debugging signals. */
813 else if (!signal_program[stop_signal])
814 stop_signal = TARGET_SIGNAL_0;
816 annotate_starting ();
818 /* Make sure that output from GDB appears before output from the
820 gdb_flush (gdb_stdout);
822 /* Refresh prev_pc value just prior to resuming. This used to be
823 done in stop_stepping, however, setting prev_pc there did not handle
824 scenarios such as inferior function calls or returning from
825 a function via the return command. In those cases, the prev_pc
826 value was not set properly for subsequent commands. The prev_pc value
827 is used to initialize the starting line number in the ecs. With an
828 invalid value, the gdb next command ends up stopping at the position
829 represented by the next line table entry past our start position.
830 On platforms that generate one line table entry per line, this
831 is not a problem. However, on the ia64, the compiler generates
832 extraneous line table entries that do not increase the line number.
833 When we issue the gdb next command on the ia64 after an inferior call
834 or a return command, we often end up a few instructions forward, still
835 within the original line we started.
837 An attempt was made to have init_execution_control_state () refresh
838 the prev_pc value before calculating the line number. This approach
839 did not work because on platforms that use ptrace, the pc register
840 cannot be read unless the inferior is stopped. At that point, we
841 are not guaranteed the inferior is stopped and so the read_pc ()
842 call can fail. Setting the prev_pc value here ensures the value is
843 updated correctly when the inferior is stopped. */
844 prev_pc = read_pc ();
846 /* Resume inferior. */
847 resume (oneproc || step || bpstat_should_step (), stop_signal);
849 /* Wait for it to stop (if not standalone)
850 and in any case decode why it stopped, and act accordingly. */
851 /* Do this only if we are not using the event loop, or if the target
852 does not support asynchronous execution. */
853 if (!event_loop_p || !target_can_async_p ())
855 wait_for_inferior ();
861 /* Start remote-debugging of a machine over a serial link. */
867 init_wait_for_inferior ();
868 stop_soon = STOP_QUIETLY;
871 /* Always go on waiting for the target, regardless of the mode. */
872 /* FIXME: cagney/1999-09-23: At present it isn't possible to
873 indicate to wait_for_inferior that a target should timeout if
874 nothing is returned (instead of just blocking). Because of this,
875 targets expecting an immediate response need to, internally, set
876 things up so that the target_wait() is forced to eventually
878 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
879 differentiate to its caller what the state of the target is after
880 the initial open has been performed. Here we're assuming that
881 the target has stopped. It should be possible to eventually have
882 target_open() return to the caller an indication that the target
883 is currently running and GDB state should be set to the same as
885 wait_for_inferior ();
889 /* Initialize static vars when a new inferior begins. */
892 init_wait_for_inferior (void)
894 /* These are meaningless until the first time through wait_for_inferior. */
898 trap_expected_after_continue = 0;
900 breakpoints_inserted = 0;
901 breakpoint_init_inferior (inf_starting);
903 /* Don't confuse first call to proceed(). */
904 stop_signal = TARGET_SIGNAL_0;
906 /* The first resume is not following a fork/vfork/exec. */
907 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
909 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
910 number_of_threads_in_syscalls = 0;
912 clear_proceed_status ();
916 delete_breakpoint_current_contents (void *arg)
918 struct breakpoint **breakpointp = (struct breakpoint **) arg;
919 if (*breakpointp != NULL)
921 delete_breakpoint (*breakpointp);
926 /* This enum encodes possible reasons for doing a target_wait, so that
927 wfi can call target_wait in one place. (Ultimately the call will be
928 moved out of the infinite loop entirely.) */
932 infwait_normal_state,
933 infwait_thread_hop_state,
934 infwait_nullified_state,
935 infwait_nonstep_watch_state
938 /* Why did the inferior stop? Used to print the appropriate messages
939 to the interface from within handle_inferior_event(). */
940 enum inferior_stop_reason
942 /* We don't know why. */
944 /* Step, next, nexti, stepi finished. */
946 /* Found breakpoint. */
948 /* Inferior terminated by signal. */
950 /* Inferior exited. */
952 /* Inferior received signal, and user asked to be notified. */
956 /* This structure contains what used to be local variables in
957 wait_for_inferior. Probably many of them can return to being
958 locals in handle_inferior_event. */
960 struct execution_control_state
962 struct target_waitstatus ws;
963 struct target_waitstatus *wp;
966 CORE_ADDR stop_func_start;
967 CORE_ADDR stop_func_end;
968 char *stop_func_name;
969 struct symtab_and_line sal;
970 int remove_breakpoints_on_following_step;
972 struct symtab *current_symtab;
973 int handling_longjmp; /* FIXME */
975 ptid_t saved_inferior_ptid;
977 int stepping_through_solib_after_catch;
978 bpstat stepping_through_solib_catchpoints;
979 int enable_hw_watchpoints_after_wait;
980 int stepping_through_sigtramp;
981 int new_thread_event;
982 struct target_waitstatus tmpstatus;
983 enum infwait_states infwait_state;
988 void init_execution_control_state (struct execution_control_state *ecs);
990 void handle_inferior_event (struct execution_control_state *ecs);
992 static void check_sigtramp2 (struct execution_control_state *ecs);
993 static void step_into_function (struct execution_control_state *ecs);
994 static void step_over_function (struct execution_control_state *ecs);
995 static void stop_stepping (struct execution_control_state *ecs);
996 static void prepare_to_wait (struct execution_control_state *ecs);
997 static void keep_going (struct execution_control_state *ecs);
998 static void print_stop_reason (enum inferior_stop_reason stop_reason,
1001 /* Wait for control to return from inferior to debugger.
1002 If inferior gets a signal, we may decide to start it up again
1003 instead of returning. That is why there is a loop in this function.
1004 When this function actually returns it means the inferior
1005 should be left stopped and GDB should read more commands. */
1008 wait_for_inferior (void)
1010 struct cleanup *old_cleanups;
1011 struct execution_control_state ecss;
1012 struct execution_control_state *ecs;
1014 old_cleanups = make_cleanup (delete_step_resume_breakpoint,
1015 &step_resume_breakpoint);
1016 make_cleanup (delete_breakpoint_current_contents,
1017 &through_sigtramp_breakpoint);
1019 /* wfi still stays in a loop, so it's OK just to take the address of
1020 a local to get the ecs pointer. */
1023 /* Fill in with reasonable starting values. */
1024 init_execution_control_state (ecs);
1026 /* We'll update this if & when we switch to a new thread. */
1027 previous_inferior_ptid = inferior_ptid;
1029 overlay_cache_invalid = 1;
1031 /* We have to invalidate the registers BEFORE calling target_wait
1032 because they can be loaded from the target while in target_wait.
1033 This makes remote debugging a bit more efficient for those
1034 targets that provide critical registers as part of their normal
1035 status mechanism. */
1037 registers_changed ();
1041 if (target_wait_hook)
1042 ecs->ptid = target_wait_hook (ecs->waiton_ptid, ecs->wp);
1044 ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp);
1046 /* Now figure out what to do with the result of the result. */
1047 handle_inferior_event (ecs);
1049 if (!ecs->wait_some_more)
1052 do_cleanups (old_cleanups);
1055 /* Asynchronous version of wait_for_inferior. It is called by the
1056 event loop whenever a change of state is detected on the file
1057 descriptor corresponding to the target. It can be called more than
1058 once to complete a single execution command. In such cases we need
1059 to keep the state in a global variable ASYNC_ECSS. If it is the
1060 last time that this function is called for a single execution
1061 command, then report to the user that the inferior has stopped, and
1062 do the necessary cleanups. */
1064 struct execution_control_state async_ecss;
1065 struct execution_control_state *async_ecs;
1068 fetch_inferior_event (void *client_data)
1070 static struct cleanup *old_cleanups;
1072 async_ecs = &async_ecss;
1074 if (!async_ecs->wait_some_more)
1076 old_cleanups = make_exec_cleanup (delete_step_resume_breakpoint,
1077 &step_resume_breakpoint);
1078 make_exec_cleanup (delete_breakpoint_current_contents,
1079 &through_sigtramp_breakpoint);
1081 /* Fill in with reasonable starting values. */
1082 init_execution_control_state (async_ecs);
1084 /* We'll update this if & when we switch to a new thread. */
1085 previous_inferior_ptid = inferior_ptid;
1087 overlay_cache_invalid = 1;
1089 /* We have to invalidate the registers BEFORE calling target_wait
1090 because they can be loaded from the target while in target_wait.
1091 This makes remote debugging a bit more efficient for those
1092 targets that provide critical registers as part of their normal
1093 status mechanism. */
1095 registers_changed ();
1098 if (target_wait_hook)
1100 target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp);
1102 async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp);
1104 /* Now figure out what to do with the result of the result. */
1105 handle_inferior_event (async_ecs);
1107 if (!async_ecs->wait_some_more)
1109 /* Do only the cleanups that have been added by this
1110 function. Let the continuations for the commands do the rest,
1111 if there are any. */
1112 do_exec_cleanups (old_cleanups);
1114 if (step_multi && stop_step)
1115 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
1117 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1121 /* Prepare an execution control state for looping through a
1122 wait_for_inferior-type loop. */
1125 init_execution_control_state (struct execution_control_state *ecs)
1127 /* ecs->another_trap? */
1128 ecs->random_signal = 0;
1129 ecs->remove_breakpoints_on_following_step = 0;
1130 ecs->handling_longjmp = 0; /* FIXME */
1131 ecs->update_step_sp = 0;
1132 ecs->stepping_through_solib_after_catch = 0;
1133 ecs->stepping_through_solib_catchpoints = NULL;
1134 ecs->enable_hw_watchpoints_after_wait = 0;
1135 ecs->stepping_through_sigtramp = 0;
1136 ecs->sal = find_pc_line (prev_pc, 0);
1137 ecs->current_line = ecs->sal.line;
1138 ecs->current_symtab = ecs->sal.symtab;
1139 ecs->infwait_state = infwait_normal_state;
1140 ecs->waiton_ptid = pid_to_ptid (-1);
1141 ecs->wp = &(ecs->ws);
1144 /* Call this function before setting step_resume_breakpoint, as a
1145 sanity check. There should never be more than one step-resume
1146 breakpoint per thread, so we should never be setting a new
1147 step_resume_breakpoint when one is already active. */
1149 check_for_old_step_resume_breakpoint (void)
1151 if (step_resume_breakpoint)
1153 ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1156 /* Return the cached copy of the last pid/waitstatus returned by
1157 target_wait()/target_wait_hook(). The data is actually cached by
1158 handle_inferior_event(), which gets called immediately after
1159 target_wait()/target_wait_hook(). */
1162 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
1164 *ptidp = target_last_wait_ptid;
1165 *status = target_last_waitstatus;
1168 /* Switch thread contexts, maintaining "infrun state". */
1171 context_switch (struct execution_control_state *ecs)
1173 /* Caution: it may happen that the new thread (or the old one!)
1174 is not in the thread list. In this case we must not attempt
1175 to "switch context", or we run the risk that our context may
1176 be lost. This may happen as a result of the target module
1177 mishandling thread creation. */
1179 if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid))
1180 { /* Perform infrun state context switch: */
1181 /* Save infrun state for the old thread. */
1182 save_infrun_state (inferior_ptid, prev_pc,
1183 trap_expected, step_resume_breakpoint,
1184 through_sigtramp_breakpoint, step_range_start,
1185 step_range_end, &step_frame_id,
1186 ecs->handling_longjmp, ecs->another_trap,
1187 ecs->stepping_through_solib_after_catch,
1188 ecs->stepping_through_solib_catchpoints,
1189 ecs->stepping_through_sigtramp,
1190 ecs->current_line, ecs->current_symtab, step_sp);
1192 /* Load infrun state for the new thread. */
1193 load_infrun_state (ecs->ptid, &prev_pc,
1194 &trap_expected, &step_resume_breakpoint,
1195 &through_sigtramp_breakpoint, &step_range_start,
1196 &step_range_end, &step_frame_id,
1197 &ecs->handling_longjmp, &ecs->another_trap,
1198 &ecs->stepping_through_solib_after_catch,
1199 &ecs->stepping_through_solib_catchpoints,
1200 &ecs->stepping_through_sigtramp,
1201 &ecs->current_line, &ecs->current_symtab, &step_sp);
1203 inferior_ptid = ecs->ptid;
1206 /* Wrapper for PC_IN_SIGTRAMP that takes care of the need to find the
1209 In a classic example of "left hand VS right hand", "infrun.c" was
1210 trying to improve GDB's performance by caching the result of calls
1211 to calls to find_pc_partial_funtion, while at the same time
1212 find_pc_partial_function was also trying to ramp up performance by
1213 caching its most recent return value. The below makes the the
1214 function find_pc_partial_function solely responsibile for
1215 performance issues (the local cache that relied on a global
1216 variable - arrrggg - deleted).
1218 Using the testsuite and gcov, it was found that dropping the local
1219 "infrun.c" cache and instead relying on find_pc_partial_function
1220 increased the number of calls to 12000 (from 10000), but the number
1221 of times find_pc_partial_function's cache missed (this is what
1222 matters) was only increased by only 4 (to 3569). (A quick back of
1223 envelope caculation suggests that the extra 2000 function calls
1224 @1000 extra instructions per call make the 1 MIP VAX testsuite run
1225 take two extra seconds, oops :-)
1227 Long term, this function can be eliminated, replaced by the code:
1228 get_frame_type(current_frame()) == SIGTRAMP_FRAME (for new
1229 architectures this is very cheap). */
1232 pc_in_sigtramp (CORE_ADDR pc)
1235 find_pc_partial_function (pc, &name, NULL, NULL);
1236 return PC_IN_SIGTRAMP (pc, name);
1240 /* Given an execution control state that has been freshly filled in
1241 by an event from the inferior, figure out what it means and take
1242 appropriate action. */
1245 handle_inferior_event (struct execution_control_state *ecs)
1247 CORE_ADDR real_stop_pc;
1248 /* NOTE: cagney/2003-03-28: If you're looking at this code and
1249 thinking that the variable stepped_after_stopped_by_watchpoint
1250 isn't used, then you're wrong! The macro STOPPED_BY_WATCHPOINT,
1251 defined in the file "config/pa/nm-hppah.h", accesses the variable
1252 indirectly. Mutter something rude about the HP merge. */
1253 int stepped_after_stopped_by_watchpoint;
1254 int sw_single_step_trap_p = 0;
1256 /* Cache the last pid/waitstatus. */
1257 target_last_wait_ptid = ecs->ptid;
1258 target_last_waitstatus = *ecs->wp;
1260 switch (ecs->infwait_state)
1262 case infwait_thread_hop_state:
1263 /* Cancel the waiton_ptid. */
1264 ecs->waiton_ptid = pid_to_ptid (-1);
1265 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1266 is serviced in this loop, below. */
1267 if (ecs->enable_hw_watchpoints_after_wait)
1269 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1270 ecs->enable_hw_watchpoints_after_wait = 0;
1272 stepped_after_stopped_by_watchpoint = 0;
1275 case infwait_normal_state:
1276 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1277 is serviced in this loop, below. */
1278 if (ecs->enable_hw_watchpoints_after_wait)
1280 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1281 ecs->enable_hw_watchpoints_after_wait = 0;
1283 stepped_after_stopped_by_watchpoint = 0;
1286 case infwait_nullified_state:
1287 stepped_after_stopped_by_watchpoint = 0;
1290 case infwait_nonstep_watch_state:
1291 insert_breakpoints ();
1293 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1294 handle things like signals arriving and other things happening
1295 in combination correctly? */
1296 stepped_after_stopped_by_watchpoint = 1;
1300 internal_error (__FILE__, __LINE__, "bad switch");
1302 ecs->infwait_state = infwait_normal_state;
1304 flush_cached_frames ();
1306 /* If it's a new process, add it to the thread database */
1308 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
1309 && !in_thread_list (ecs->ptid));
1311 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1312 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
1314 add_thread (ecs->ptid);
1316 ui_out_text (uiout, "[New ");
1317 ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid));
1318 ui_out_text (uiout, "]\n");
1321 /* NOTE: This block is ONLY meant to be invoked in case of a
1322 "thread creation event"! If it is invoked for any other
1323 sort of event (such as a new thread landing on a breakpoint),
1324 the event will be discarded, which is almost certainly
1327 To avoid this, the low-level module (eg. target_wait)
1328 should call in_thread_list and add_thread, so that the
1329 new thread is known by the time we get here. */
1331 /* We may want to consider not doing a resume here in order
1332 to give the user a chance to play with the new thread.
1333 It might be good to make that a user-settable option. */
1335 /* At this point, all threads are stopped (happens
1336 automatically in either the OS or the native code).
1337 Therefore we need to continue all threads in order to
1340 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
1341 prepare_to_wait (ecs);
1346 switch (ecs->ws.kind)
1348 case TARGET_WAITKIND_LOADED:
1349 /* Ignore gracefully during startup of the inferior, as it
1350 might be the shell which has just loaded some objects,
1351 otherwise add the symbols for the newly loaded objects. */
1353 if (stop_soon == NO_STOP_QUIETLY)
1355 /* Remove breakpoints, SOLIB_ADD might adjust
1356 breakpoint addresses via breakpoint_re_set. */
1357 if (breakpoints_inserted)
1358 remove_breakpoints ();
1360 /* Check for any newly added shared libraries if we're
1361 supposed to be adding them automatically. Switch
1362 terminal for any messages produced by
1363 breakpoint_re_set. */
1364 target_terminal_ours_for_output ();
1365 SOLIB_ADD (NULL, 0, NULL, auto_solib_add);
1366 target_terminal_inferior ();
1368 /* Reinsert breakpoints and continue. */
1369 if (breakpoints_inserted)
1370 insert_breakpoints ();
1373 resume (0, TARGET_SIGNAL_0);
1374 prepare_to_wait (ecs);
1377 case TARGET_WAITKIND_SPURIOUS:
1378 resume (0, TARGET_SIGNAL_0);
1379 prepare_to_wait (ecs);
1382 case TARGET_WAITKIND_EXITED:
1383 target_terminal_ours (); /* Must do this before mourn anyway */
1384 print_stop_reason (EXITED, ecs->ws.value.integer);
1386 /* Record the exit code in the convenience variable $_exitcode, so
1387 that the user can inspect this again later. */
1388 set_internalvar (lookup_internalvar ("_exitcode"),
1389 value_from_longest (builtin_type_int,
1390 (LONGEST) ecs->ws.value.integer));
1391 gdb_flush (gdb_stdout);
1392 target_mourn_inferior ();
1393 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */
1394 stop_print_frame = 0;
1395 stop_stepping (ecs);
1398 case TARGET_WAITKIND_SIGNALLED:
1399 stop_print_frame = 0;
1400 stop_signal = ecs->ws.value.sig;
1401 target_terminal_ours (); /* Must do this before mourn anyway */
1403 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1404 reach here unless the inferior is dead. However, for years
1405 target_kill() was called here, which hints that fatal signals aren't
1406 really fatal on some systems. If that's true, then some changes
1408 target_mourn_inferior ();
1410 print_stop_reason (SIGNAL_EXITED, stop_signal);
1411 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */
1412 stop_stepping (ecs);
1415 /* The following are the only cases in which we keep going;
1416 the above cases end in a continue or goto. */
1417 case TARGET_WAITKIND_FORKED:
1418 case TARGET_WAITKIND_VFORKED:
1419 stop_signal = TARGET_SIGNAL_TRAP;
1420 pending_follow.kind = ecs->ws.kind;
1422 pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid);
1423 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1425 stop_pc = read_pc ();
1427 /* Assume that catchpoints are not really software breakpoints. If
1428 some future target implements them using software breakpoints then
1429 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1430 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1431 bpstat_stop_status will not decrement the PC. */
1433 stop_bpstat = bpstat_stop_status (&stop_pc, 1);
1435 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1437 /* If no catchpoint triggered for this, then keep going. */
1438 if (ecs->random_signal)
1440 stop_signal = TARGET_SIGNAL_0;
1444 goto process_event_stop_test;
1446 case TARGET_WAITKIND_EXECD:
1447 stop_signal = TARGET_SIGNAL_TRAP;
1449 /* NOTE drow/2002-12-05: This code should be pushed down into the
1450 target_wait function. Until then following vfork on HP/UX 10.20
1451 is probably broken by this. Of course, it's broken anyway. */
1452 /* Is this a target which reports multiple exec events per actual
1453 call to exec()? (HP-UX using ptrace does, for example.) If so,
1454 ignore all but the last one. Just resume the exec'r, and wait
1455 for the next exec event. */
1456 if (inferior_ignoring_leading_exec_events)
1458 inferior_ignoring_leading_exec_events--;
1459 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1460 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.
1462 target_resume (ecs->ptid, 0, TARGET_SIGNAL_0);
1463 prepare_to_wait (ecs);
1466 inferior_ignoring_leading_exec_events =
1467 target_reported_exec_events_per_exec_call () - 1;
1469 pending_follow.execd_pathname =
1470 savestring (ecs->ws.value.execd_pathname,
1471 strlen (ecs->ws.value.execd_pathname));
1473 /* This causes the eventpoints and symbol table to be reset. Must
1474 do this now, before trying to determine whether to stop. */
1475 follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname);
1476 xfree (pending_follow.execd_pathname);
1478 stop_pc = read_pc_pid (ecs->ptid);
1479 ecs->saved_inferior_ptid = inferior_ptid;
1480 inferior_ptid = ecs->ptid;
1482 /* Assume that catchpoints are not really software breakpoints. If
1483 some future target implements them using software breakpoints then
1484 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1485 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1486 bpstat_stop_status will not decrement the PC. */
1488 stop_bpstat = bpstat_stop_status (&stop_pc, 1);
1490 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1491 inferior_ptid = ecs->saved_inferior_ptid;
1493 /* If no catchpoint triggered for this, then keep going. */
1494 if (ecs->random_signal)
1496 stop_signal = TARGET_SIGNAL_0;
1500 goto process_event_stop_test;
1502 /* These syscall events are returned on HP-UX, as part of its
1503 implementation of page-protection-based "hardware" watchpoints.
1504 HP-UX has unfortunate interactions between page-protections and
1505 some system calls. Our solution is to disable hardware watches
1506 when a system call is entered, and reenable them when the syscall
1507 completes. The downside of this is that we may miss the precise
1508 point at which a watched piece of memory is modified. "Oh well."
1510 Note that we may have multiple threads running, which may each
1511 enter syscalls at roughly the same time. Since we don't have a
1512 good notion currently of whether a watched piece of memory is
1513 thread-private, we'd best not have any page-protections active
1514 when any thread is in a syscall. Thus, we only want to reenable
1515 hardware watches when no threads are in a syscall.
1517 Also, be careful not to try to gather much state about a thread
1518 that's in a syscall. It's frequently a losing proposition. */
1519 case TARGET_WAITKIND_SYSCALL_ENTRY:
1520 number_of_threads_in_syscalls++;
1521 if (number_of_threads_in_syscalls == 1)
1523 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1525 resume (0, TARGET_SIGNAL_0);
1526 prepare_to_wait (ecs);
1529 /* Before examining the threads further, step this thread to
1530 get it entirely out of the syscall. (We get notice of the
1531 event when the thread is just on the verge of exiting a
1532 syscall. Stepping one instruction seems to get it back
1535 Note that although the logical place to reenable h/w watches
1536 is here, we cannot. We cannot reenable them before stepping
1537 the thread (this causes the next wait on the thread to hang).
1539 Nor can we enable them after stepping until we've done a wait.
1540 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1541 here, which will be serviced immediately after the target
1543 case TARGET_WAITKIND_SYSCALL_RETURN:
1544 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
1546 if (number_of_threads_in_syscalls > 0)
1548 number_of_threads_in_syscalls--;
1549 ecs->enable_hw_watchpoints_after_wait =
1550 (number_of_threads_in_syscalls == 0);
1552 prepare_to_wait (ecs);
1555 case TARGET_WAITKIND_STOPPED:
1556 stop_signal = ecs->ws.value.sig;
1559 /* We had an event in the inferior, but we are not interested
1560 in handling it at this level. The lower layers have already
1561 done what needs to be done, if anything.
1563 One of the possible circumstances for this is when the
1564 inferior produces output for the console. The inferior has
1565 not stopped, and we are ignoring the event. Another possible
1566 circumstance is any event which the lower level knows will be
1567 reported multiple times without an intervening resume. */
1568 case TARGET_WAITKIND_IGNORE:
1569 prepare_to_wait (ecs);
1573 /* We may want to consider not doing a resume here in order to give
1574 the user a chance to play with the new thread. It might be good
1575 to make that a user-settable option. */
1577 /* At this point, all threads are stopped (happens automatically in
1578 either the OS or the native code). Therefore we need to continue
1579 all threads in order to make progress. */
1580 if (ecs->new_thread_event)
1582 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
1583 prepare_to_wait (ecs);
1587 stop_pc = read_pc_pid (ecs->ptid);
1589 /* See if a thread hit a thread-specific breakpoint that was meant for
1590 another thread. If so, then step that thread past the breakpoint,
1593 if (stop_signal == TARGET_SIGNAL_TRAP)
1595 /* Check if a regular breakpoint has been hit before checking
1596 for a potential single step breakpoint. Otherwise, GDB will
1597 not see this breakpoint hit when stepping onto breakpoints. */
1598 if (breakpoints_inserted
1599 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
1601 ecs->random_signal = 0;
1602 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK,
1607 /* Saw a breakpoint, but it was hit by the wrong thread.
1609 if (DECR_PC_AFTER_BREAK)
1610 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, ecs->ptid);
1612 remove_status = remove_breakpoints ();
1613 /* Did we fail to remove breakpoints? If so, try
1614 to set the PC past the bp. (There's at least
1615 one situation in which we can fail to remove
1616 the bp's: On HP-UX's that use ttrace, we can't
1617 change the address space of a vforking child
1618 process until the child exits (well, okay, not
1619 then either :-) or execs. */
1620 if (remove_status != 0)
1622 /* FIXME! This is obviously non-portable! */
1623 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, ecs->ptid);
1624 /* We need to restart all the threads now,
1625 * unles we're running in scheduler-locked mode.
1626 * Use currently_stepping to determine whether to
1629 /* FIXME MVS: is there any reason not to call resume()? */
1630 if (scheduler_mode == schedlock_on)
1631 target_resume (ecs->ptid,
1632 currently_stepping (ecs), TARGET_SIGNAL_0);
1634 target_resume (RESUME_ALL,
1635 currently_stepping (ecs), TARGET_SIGNAL_0);
1636 prepare_to_wait (ecs);
1641 breakpoints_inserted = 0;
1642 if (!ptid_equal (inferior_ptid, ecs->ptid))
1643 context_switch (ecs);
1644 ecs->waiton_ptid = ecs->ptid;
1645 ecs->wp = &(ecs->ws);
1646 ecs->another_trap = 1;
1648 ecs->infwait_state = infwait_thread_hop_state;
1650 registers_changed ();
1655 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1657 /* Readjust the stop_pc as it is off by DECR_PC_AFTER_BREAK
1658 compared to the value it would have if the system stepping
1659 capability was used. This allows the rest of the code in
1660 this function to use this address without having to worry
1661 whether software single step is in use or not. */
1662 if (DECR_PC_AFTER_BREAK)
1664 stop_pc -= DECR_PC_AFTER_BREAK;
1665 write_pc_pid (stop_pc, ecs->ptid);
1668 sw_single_step_trap_p = 1;
1669 ecs->random_signal = 0;
1673 ecs->random_signal = 1;
1675 /* See if something interesting happened to the non-current thread. If
1676 so, then switch to that thread, and eventually give control back to
1679 Note that if there's any kind of pending follow (i.e., of a fork,
1680 vfork or exec), we don't want to do this now. Rather, we'll let
1681 the next resume handle it. */
1682 if (!ptid_equal (ecs->ptid, inferior_ptid) &&
1683 (pending_follow.kind == TARGET_WAITKIND_SPURIOUS))
1687 /* If it's a random signal for a non-current thread, notify user
1688 if he's expressed an interest. */
1689 if (ecs->random_signal && signal_print[stop_signal])
1691 /* ??rehrauer: I don't understand the rationale for this code. If the
1692 inferior will stop as a result of this signal, then the act of handling
1693 the stop ought to print a message that's couches the stoppage in user
1694 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1695 won't stop as a result of the signal -- i.e., if the signal is merely
1696 a side-effect of something GDB's doing "under the covers" for the
1697 user, such as stepping threads over a breakpoint they shouldn't stop
1698 for -- then the message seems to be a serious annoyance at best.
1700 For now, remove the message altogether. */
1703 target_terminal_ours_for_output ();
1704 printf_filtered ("\nProgram received signal %s, %s.\n",
1705 target_signal_to_name (stop_signal),
1706 target_signal_to_string (stop_signal));
1707 gdb_flush (gdb_stdout);
1711 /* If it's not SIGTRAP and not a signal we want to stop for, then
1712 continue the thread. */
1714 if (stop_signal != TARGET_SIGNAL_TRAP && !signal_stop[stop_signal])
1717 target_terminal_inferior ();
1719 /* Clear the signal if it should not be passed. */
1720 if (signal_program[stop_signal] == 0)
1721 stop_signal = TARGET_SIGNAL_0;
1723 target_resume (ecs->ptid, 0, stop_signal);
1724 prepare_to_wait (ecs);
1728 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1729 and fall into the rest of wait_for_inferior(). */
1731 context_switch (ecs);
1734 context_hook (pid_to_thread_id (ecs->ptid));
1736 flush_cached_frames ();
1739 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1741 /* Pull the single step breakpoints out of the target. */
1742 SOFTWARE_SINGLE_STEP (0, 0);
1743 singlestep_breakpoints_inserted_p = 0;
1746 /* If PC is pointing at a nullified instruction, then step beyond
1747 it so that the user won't be confused when GDB appears to be ready
1750 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1751 if (INSTRUCTION_NULLIFIED)
1753 registers_changed ();
1754 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
1756 /* We may have received a signal that we want to pass to
1757 the inferior; therefore, we must not clobber the waitstatus
1760 ecs->infwait_state = infwait_nullified_state;
1761 ecs->waiton_ptid = ecs->ptid;
1762 ecs->wp = &(ecs->tmpstatus);
1763 prepare_to_wait (ecs);
1767 /* It may not be necessary to disable the watchpoint to stop over
1768 it. For example, the PA can (with some kernel cooperation)
1769 single step over a watchpoint without disabling the watchpoint. */
1770 if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1773 prepare_to_wait (ecs);
1777 /* It is far more common to need to disable a watchpoint to step
1778 the inferior over it. FIXME. What else might a debug
1779 register or page protection watchpoint scheme need here? */
1780 if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1782 /* At this point, we are stopped at an instruction which has
1783 attempted to write to a piece of memory under control of
1784 a watchpoint. The instruction hasn't actually executed
1785 yet. If we were to evaluate the watchpoint expression
1786 now, we would get the old value, and therefore no change
1787 would seem to have occurred.
1789 In order to make watchpoints work `right', we really need
1790 to complete the memory write, and then evaluate the
1791 watchpoint expression. The following code does that by
1792 removing the watchpoint (actually, all watchpoints and
1793 breakpoints), single-stepping the target, re-inserting
1794 watchpoints, and then falling through to let normal
1795 single-step processing handle proceed. Since this
1796 includes evaluating watchpoints, things will come to a
1797 stop in the correct manner. */
1799 if (DECR_PC_AFTER_BREAK)
1800 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
1802 remove_breakpoints ();
1803 registers_changed ();
1804 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */
1806 ecs->waiton_ptid = ecs->ptid;
1807 ecs->wp = &(ecs->ws);
1808 ecs->infwait_state = infwait_nonstep_watch_state;
1809 prepare_to_wait (ecs);
1813 /* It may be possible to simply continue after a watchpoint. */
1814 if (HAVE_CONTINUABLE_WATCHPOINT)
1815 STOPPED_BY_WATCHPOINT (ecs->ws);
1817 ecs->stop_func_start = 0;
1818 ecs->stop_func_end = 0;
1819 ecs->stop_func_name = 0;
1820 /* Don't care about return value; stop_func_start and stop_func_name
1821 will both be 0 if it doesn't work. */
1822 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
1823 &ecs->stop_func_start, &ecs->stop_func_end);
1824 ecs->stop_func_start += FUNCTION_START_OFFSET;
1825 ecs->another_trap = 0;
1826 bpstat_clear (&stop_bpstat);
1828 stop_stack_dummy = 0;
1829 stop_print_frame = 1;
1830 ecs->random_signal = 0;
1831 stopped_by_random_signal = 0;
1832 breakpoints_failed = 0;
1834 /* Look at the cause of the stop, and decide what to do.
1835 The alternatives are:
1836 1) break; to really stop and return to the debugger,
1837 2) drop through to start up again
1838 (set ecs->another_trap to 1 to single step once)
1839 3) set ecs->random_signal to 1, and the decision between 1 and 2
1840 will be made according to the signal handling tables. */
1842 /* First, distinguish signals caused by the debugger from signals
1843 that have to do with the program's own actions.
1844 Note that breakpoint insns may cause SIGTRAP or SIGILL
1845 or SIGEMT, depending on the operating system version.
1846 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1847 and change it to SIGTRAP. */
1849 if (stop_signal == TARGET_SIGNAL_TRAP
1850 || (breakpoints_inserted &&
1851 (stop_signal == TARGET_SIGNAL_ILL
1852 || stop_signal == TARGET_SIGNAL_EMT))
1853 || stop_soon == STOP_QUIETLY
1854 || stop_soon == STOP_QUIETLY_NO_SIGSTOP)
1856 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
1858 stop_print_frame = 0;
1859 stop_stepping (ecs);
1863 /* This is originated from start_remote(), start_inferior() and
1864 shared libraries hook functions. */
1865 if (stop_soon == STOP_QUIETLY)
1867 stop_stepping (ecs);
1871 /* This originates from attach_command(). We need to overwrite
1872 the stop_signal here, because some kernels don't ignore a
1873 SIGSTOP in a subsequent ptrace(PTRACE_SONT,SOGSTOP) call.
1874 See more comments in inferior.h. */
1875 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP)
1877 stop_stepping (ecs);
1878 if (stop_signal == TARGET_SIGNAL_STOP)
1879 stop_signal = TARGET_SIGNAL_0;
1883 /* Don't even think about breakpoints
1884 if just proceeded over a breakpoint.
1886 However, if we are trying to proceed over a breakpoint
1887 and end up in sigtramp, then through_sigtramp_breakpoint
1888 will be set and we should check whether we've hit the
1890 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
1891 && through_sigtramp_breakpoint == NULL)
1892 bpstat_clear (&stop_bpstat);
1895 /* See if there is a breakpoint at the current PC. */
1897 /* The second argument of bpstat_stop_status is meant to help
1898 distinguish between a breakpoint trap and a singlestep trap.
1899 This is only important on targets where DECR_PC_AFTER_BREAK
1900 is non-zero. The prev_pc test is meant to distinguish between
1901 singlestepping a trap instruction, and singlestepping thru a
1902 jump to the instruction following a trap instruction.
1904 Therefore, pass TRUE if our reason for stopping is
1905 something other than hitting a breakpoint. We do this by
1906 checking that either: we detected earlier a software single
1907 step trap or, 1) stepping is going on and 2) we didn't hit
1908 a breakpoint in a signal handler without an intervening stop
1909 in sigtramp, which is detected by a new stack pointer value
1910 below any usual function calling stack adjustments. */
1914 sw_single_step_trap_p
1915 || (currently_stepping (ecs)
1916 && prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1918 && INNER_THAN (read_sp (), (step_sp - 16)))));
1919 /* Following in case break condition called a
1921 stop_print_frame = 1;
1924 /* NOTE: cagney/2003-03-29: These two checks for a random signal
1925 at one stage in the past included checks for an inferior
1926 function call's call dummy's return breakpoint. The original
1927 comment, that went with the test, read:
1929 ``End of a stack dummy. Some systems (e.g. Sony news) give
1930 another signal besides SIGTRAP, so check here as well as
1933 If someone ever tries to get get call dummys on a
1934 non-executable stack to work (where the target would stop
1935 with something like a SIGSEG), then those tests might need to
1936 be re-instated. Given, however, that the tests were only
1937 enabled when momentary breakpoints were not being used, I
1938 suspect that it won't be the case. */
1940 if (stop_signal == TARGET_SIGNAL_TRAP)
1942 = !(bpstat_explains_signal (stop_bpstat)
1944 || (step_range_end && step_resume_breakpoint == NULL));
1947 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1948 if (!ecs->random_signal)
1949 stop_signal = TARGET_SIGNAL_TRAP;
1953 /* When we reach this point, we've pretty much decided
1954 that the reason for stopping must've been a random
1955 (unexpected) signal. */
1958 ecs->random_signal = 1;
1960 process_event_stop_test:
1961 /* For the program's own signals, act according to
1962 the signal handling tables. */
1964 if (ecs->random_signal)
1966 /* Signal not for debugging purposes. */
1969 stopped_by_random_signal = 1;
1971 if (signal_print[stop_signal])
1974 target_terminal_ours_for_output ();
1975 print_stop_reason (SIGNAL_RECEIVED, stop_signal);
1977 if (signal_stop[stop_signal])
1979 stop_stepping (ecs);
1982 /* If not going to stop, give terminal back
1983 if we took it away. */
1985 target_terminal_inferior ();
1987 /* Clear the signal if it should not be passed. */
1988 if (signal_program[stop_signal] == 0)
1989 stop_signal = TARGET_SIGNAL_0;
1991 /* I'm not sure whether this needs to be check_sigtramp2 or
1992 whether it could/should be keep_going.
1994 This used to jump to step_over_function if we are stepping,
1997 Suppose the user does a `next' over a function call, and while
1998 that call is in progress, the inferior receives a signal for
1999 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2000 that case, when we reach this point, there is already a
2001 step-resume breakpoint established, right where it should be:
2002 immediately after the function call the user is "next"-ing
2003 over. If we call step_over_function now, two bad things
2006 - we'll create a new breakpoint, at wherever the current
2007 frame's return address happens to be. That could be
2008 anywhere, depending on what function call happens to be on
2009 the top of the stack at that point. Point is, it's probably
2010 not where we need it.
2012 - the existing step-resume breakpoint (which is at the correct
2013 address) will get orphaned: step_resume_breakpoint will point
2014 to the new breakpoint, and the old step-resume breakpoint
2015 will never be cleaned up.
2017 The old behavior was meant to help HP-UX single-step out of
2018 sigtramps. It would place the new breakpoint at prev_pc, which
2019 was certainly wrong. I don't know the details there, so fixing
2020 this probably breaks that. As with anything else, it's up to
2021 the HP-UX maintainer to furnish a fix that doesn't break other
2022 platforms. --JimB, 20 May 1999 */
2023 check_sigtramp2 (ecs);
2028 /* Handle cases caused by hitting a breakpoint. */
2030 CORE_ADDR jmp_buf_pc;
2031 struct bpstat_what what;
2033 what = bpstat_what (stop_bpstat);
2035 if (what.call_dummy)
2037 stop_stack_dummy = 1;
2039 trap_expected_after_continue = 1;
2043 switch (what.main_action)
2045 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
2046 /* If we hit the breakpoint at longjmp, disable it for the
2047 duration of this command. Then, install a temporary
2048 breakpoint at the target of the jmp_buf. */
2049 disable_longjmp_breakpoint ();
2050 remove_breakpoints ();
2051 breakpoints_inserted = 0;
2052 if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc))
2058 /* Need to blow away step-resume breakpoint, as it
2059 interferes with us */
2060 if (step_resume_breakpoint != NULL)
2062 delete_step_resume_breakpoint (&step_resume_breakpoint);
2064 /* Not sure whether we need to blow this away too, but probably
2065 it is like the step-resume breakpoint. */
2066 if (through_sigtramp_breakpoint != NULL)
2068 delete_breakpoint (through_sigtramp_breakpoint);
2069 through_sigtramp_breakpoint = NULL;
2073 /* FIXME - Need to implement nested temporary breakpoints */
2074 if (step_over_calls > 0)
2075 set_longjmp_resume_breakpoint (jmp_buf_pc, get_current_frame ());
2078 set_longjmp_resume_breakpoint (jmp_buf_pc, null_frame_id);
2079 ecs->handling_longjmp = 1; /* FIXME */
2083 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
2084 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
2085 remove_breakpoints ();
2086 breakpoints_inserted = 0;
2088 /* FIXME - Need to implement nested temporary breakpoints */
2090 && (frame_id_inner (get_frame_id (get_current_frame ()),
2093 ecs->another_trap = 1;
2098 disable_longjmp_breakpoint ();
2099 ecs->handling_longjmp = 0; /* FIXME */
2100 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
2102 /* else fallthrough */
2104 case BPSTAT_WHAT_SINGLE:
2105 if (breakpoints_inserted)
2107 remove_breakpoints ();
2109 breakpoints_inserted = 0;
2110 ecs->another_trap = 1;
2111 /* Still need to check other stuff, at least the case
2112 where we are stepping and step out of the right range. */
2115 case BPSTAT_WHAT_STOP_NOISY:
2116 stop_print_frame = 1;
2118 /* We are about to nuke the step_resume_breakpoint and
2119 through_sigtramp_breakpoint via the cleanup chain, so
2120 no need to worry about it here. */
2122 stop_stepping (ecs);
2125 case BPSTAT_WHAT_STOP_SILENT:
2126 stop_print_frame = 0;
2128 /* We are about to nuke the step_resume_breakpoint and
2129 through_sigtramp_breakpoint via the cleanup chain, so
2130 no need to worry about it here. */
2132 stop_stepping (ecs);
2135 case BPSTAT_WHAT_STEP_RESUME:
2136 /* This proably demands a more elegant solution, but, yeah
2139 This function's use of the simple variable
2140 step_resume_breakpoint doesn't seem to accomodate
2141 simultaneously active step-resume bp's, although the
2142 breakpoint list certainly can.
2144 If we reach here and step_resume_breakpoint is already
2145 NULL, then apparently we have multiple active
2146 step-resume bp's. We'll just delete the breakpoint we
2147 stopped at, and carry on.
2149 Correction: what the code currently does is delete a
2150 step-resume bp, but it makes no effort to ensure that
2151 the one deleted is the one currently stopped at. MVS */
2153 if (step_resume_breakpoint == NULL)
2155 step_resume_breakpoint =
2156 bpstat_find_step_resume_breakpoint (stop_bpstat);
2158 delete_step_resume_breakpoint (&step_resume_breakpoint);
2161 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2162 if (through_sigtramp_breakpoint)
2163 delete_breakpoint (through_sigtramp_breakpoint);
2164 through_sigtramp_breakpoint = NULL;
2166 /* If were waiting for a trap, hitting the step_resume_break
2167 doesn't count as getting it. */
2169 ecs->another_trap = 1;
2172 case BPSTAT_WHAT_CHECK_SHLIBS:
2173 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2176 /* Remove breakpoints, we eventually want to step over the
2177 shlib event breakpoint, and SOLIB_ADD might adjust
2178 breakpoint addresses via breakpoint_re_set. */
2179 if (breakpoints_inserted)
2180 remove_breakpoints ();
2181 breakpoints_inserted = 0;
2183 /* Check for any newly added shared libraries if we're
2184 supposed to be adding them automatically. Switch
2185 terminal for any messages produced by
2186 breakpoint_re_set. */
2187 target_terminal_ours_for_output ();
2188 SOLIB_ADD (NULL, 0, NULL, auto_solib_add);
2189 target_terminal_inferior ();
2191 /* Try to reenable shared library breakpoints, additional
2192 code segments in shared libraries might be mapped in now. */
2193 re_enable_breakpoints_in_shlibs ();
2195 /* If requested, stop when the dynamic linker notifies
2196 gdb of events. This allows the user to get control
2197 and place breakpoints in initializer routines for
2198 dynamically loaded objects (among other things). */
2199 if (stop_on_solib_events)
2201 stop_stepping (ecs);
2205 /* If we stopped due to an explicit catchpoint, then the
2206 (see above) call to SOLIB_ADD pulled in any symbols
2207 from a newly-loaded library, if appropriate.
2209 We do want the inferior to stop, but not where it is
2210 now, which is in the dynamic linker callback. Rather,
2211 we would like it stop in the user's program, just after
2212 the call that caused this catchpoint to trigger. That
2213 gives the user a more useful vantage from which to
2214 examine their program's state. */
2215 else if (what.main_action ==
2216 BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2218 /* ??rehrauer: If I could figure out how to get the
2219 right return PC from here, we could just set a temp
2220 breakpoint and resume. I'm not sure we can without
2221 cracking open the dld's shared libraries and sniffing
2222 their unwind tables and text/data ranges, and that's
2223 not a terribly portable notion.
2225 Until that time, we must step the inferior out of the
2226 dld callback, and also out of the dld itself (and any
2227 code or stubs in libdld.sl, such as "shl_load" and
2228 friends) until we reach non-dld code. At that point,
2229 we can stop stepping. */
2230 bpstat_get_triggered_catchpoints (stop_bpstat,
2232 stepping_through_solib_catchpoints);
2233 ecs->stepping_through_solib_after_catch = 1;
2235 /* Be sure to lift all breakpoints, so the inferior does
2236 actually step past this point... */
2237 ecs->another_trap = 1;
2242 /* We want to step over this breakpoint, then keep going. */
2243 ecs->another_trap = 1;
2250 case BPSTAT_WHAT_LAST:
2251 /* Not a real code, but listed here to shut up gcc -Wall. */
2253 case BPSTAT_WHAT_KEEP_CHECKING:
2258 /* We come here if we hit a breakpoint but should not
2259 stop for it. Possibly we also were stepping
2260 and should stop for that. So fall through and
2261 test for stepping. But, if not stepping,
2264 /* Are we stepping to get the inferior out of the dynamic
2265 linker's hook (and possibly the dld itself) after catching
2267 if (ecs->stepping_through_solib_after_catch)
2269 #if defined(SOLIB_ADD)
2270 /* Have we reached our destination? If not, keep going. */
2271 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
2273 ecs->another_trap = 1;
2278 /* Else, stop and report the catchpoint(s) whose triggering
2279 caused us to begin stepping. */
2280 ecs->stepping_through_solib_after_catch = 0;
2281 bpstat_clear (&stop_bpstat);
2282 stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints);
2283 bpstat_clear (&ecs->stepping_through_solib_catchpoints);
2284 stop_print_frame = 1;
2285 stop_stepping (ecs);
2289 if (step_resume_breakpoint)
2291 /* Having a step-resume breakpoint overrides anything
2292 else having to do with stepping commands until
2293 that breakpoint is reached. */
2294 /* I'm not sure whether this needs to be check_sigtramp2 or
2295 whether it could/should be keep_going. */
2296 check_sigtramp2 (ecs);
2301 if (step_range_end == 0)
2303 /* Likewise if we aren't even stepping. */
2304 /* I'm not sure whether this needs to be check_sigtramp2 or
2305 whether it could/should be keep_going. */
2306 check_sigtramp2 (ecs);
2311 /* If stepping through a line, keep going if still within it.
2313 Note that step_range_end is the address of the first instruction
2314 beyond the step range, and NOT the address of the last instruction
2316 if (stop_pc >= step_range_start && stop_pc < step_range_end)
2318 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2319 So definately need to check for sigtramp here. */
2320 check_sigtramp2 (ecs);
2325 /* We stepped out of the stepping range. */
2327 /* If we are stepping at the source level and entered the runtime
2328 loader dynamic symbol resolution code, we keep on single stepping
2329 until we exit the run time loader code and reach the callee's
2331 if (step_over_calls == STEP_OVER_UNDEBUGGABLE
2332 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2334 CORE_ADDR pc_after_resolver =
2335 gdbarch_skip_solib_resolver (current_gdbarch, stop_pc);
2337 if (pc_after_resolver)
2339 /* Set up a step-resume breakpoint at the address
2340 indicated by SKIP_SOLIB_RESOLVER. */
2341 struct symtab_and_line sr_sal;
2343 sr_sal.pc = pc_after_resolver;
2345 check_for_old_step_resume_breakpoint ();
2346 step_resume_breakpoint =
2347 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2348 if (breakpoints_inserted)
2349 insert_breakpoints ();
2356 /* We can't update step_sp every time through the loop, because
2357 reading the stack pointer would slow down stepping too much.
2358 But we can update it every time we leave the step range. */
2359 ecs->update_step_sp = 1;
2361 /* Did we just take a signal? */
2362 if (pc_in_sigtramp (stop_pc)
2363 && !pc_in_sigtramp (prev_pc)
2364 && INNER_THAN (read_sp (), step_sp))
2366 /* We've just taken a signal; go until we are back to
2367 the point where we took it and one more. */
2369 /* Note: The test above succeeds not only when we stepped
2370 into a signal handler, but also when we step past the last
2371 statement of a signal handler and end up in the return stub
2372 of the signal handler trampoline. To distinguish between
2373 these two cases, check that the frame is INNER_THAN the
2374 previous one below. pai/1997-09-11 */
2378 struct frame_id current_frame = get_frame_id (get_current_frame ());
2380 if (frame_id_inner (current_frame, step_frame_id))
2382 /* We have just taken a signal; go until we are back to
2383 the point where we took it and one more. */
2385 /* This code is needed at least in the following case:
2386 The user types "next" and then a signal arrives (before
2387 the "next" is done). */
2389 /* Note that if we are stopped at a breakpoint, then we need
2390 the step_resume breakpoint to override any breakpoints at
2391 the same location, so that we will still step over the
2392 breakpoint even though the signal happened. */
2393 struct symtab_and_line sr_sal;
2396 sr_sal.symtab = NULL;
2398 sr_sal.pc = prev_pc;
2399 /* We could probably be setting the frame to
2400 step_frame_id; I don't think anyone thought to try it. */
2401 check_for_old_step_resume_breakpoint ();
2402 step_resume_breakpoint =
2403 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2404 if (breakpoints_inserted)
2405 insert_breakpoints ();
2409 /* We just stepped out of a signal handler and into
2410 its calling trampoline.
2412 Normally, we'd call step_over_function from
2413 here, but for some reason GDB can't unwind the
2414 stack correctly to find the real PC for the point
2415 user code where the signal trampoline will return
2416 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2417 But signal trampolines are pretty small stubs of
2418 code, anyway, so it's OK instead to just
2419 single-step out. Note: assuming such trampolines
2420 don't exhibit recursion on any platform... */
2421 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2422 &ecs->stop_func_start,
2423 &ecs->stop_func_end);
2424 /* Readjust stepping range */
2425 step_range_start = ecs->stop_func_start;
2426 step_range_end = ecs->stop_func_end;
2427 ecs->stepping_through_sigtramp = 1;
2432 /* If this is stepi or nexti, make sure that the stepping range
2433 gets us past that instruction. */
2434 if (step_range_end == 1)
2435 /* FIXME: Does this run afoul of the code below which, if
2436 we step into the middle of a line, resets the stepping
2438 step_range_end = (step_range_start = prev_pc) + 1;
2440 ecs->remove_breakpoints_on_following_step = 1;
2445 if (((stop_pc == ecs->stop_func_start /* Quick test */
2446 || in_prologue (stop_pc, ecs->stop_func_start))
2447 && !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2448 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name)
2449 || ecs->stop_func_name == 0)
2451 /* It's a subroutine call. */
2453 if ((step_over_calls == STEP_OVER_NONE)
2454 || ((step_range_end == 1)
2455 && in_prologue (prev_pc, ecs->stop_func_start)))
2457 /* I presume that step_over_calls is only 0 when we're
2458 supposed to be stepping at the assembly language level
2459 ("stepi"). Just stop. */
2460 /* Also, maybe we just did a "nexti" inside a prolog,
2461 so we thought it was a subroutine call but it was not.
2462 Stop as well. FENN */
2464 print_stop_reason (END_STEPPING_RANGE, 0);
2465 stop_stepping (ecs);
2469 if (step_over_calls == STEP_OVER_ALL || IGNORE_HELPER_CALL (stop_pc))
2471 /* We're doing a "next". */
2473 if (pc_in_sigtramp (stop_pc)
2474 && frame_id_inner (step_frame_id,
2475 frame_id_build (read_sp (), 0)))
2476 /* We stepped out of a signal handler, and into its
2477 calling trampoline. This is misdetected as a
2478 subroutine call, but stepping over the signal
2479 trampoline isn't such a bad idea. In order to do that,
2480 we have to ignore the value in step_frame_id, since
2481 that doesn't represent the frame that'll reach when we
2482 return from the signal trampoline. Otherwise we'll
2483 probably continue to the end of the program. */
2484 step_frame_id = null_frame_id;
2486 step_over_function (ecs);
2491 /* If we are in a function call trampoline (a stub between
2492 the calling routine and the real function), locate the real
2493 function. That's what tells us (a) whether we want to step
2494 into it at all, and (b) what prologue we want to run to
2495 the end of, if we do step into it. */
2496 real_stop_pc = skip_language_trampoline (stop_pc);
2497 if (real_stop_pc == 0)
2498 real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc);
2499 if (real_stop_pc != 0)
2500 ecs->stop_func_start = real_stop_pc;
2502 /* If we have line number information for the function we
2503 are thinking of stepping into, step into it.
2505 If there are several symtabs at that PC (e.g. with include
2506 files), just want to know whether *any* of them have line
2507 numbers. find_pc_line handles this. */
2509 struct symtab_and_line tmp_sal;
2511 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
2512 if (tmp_sal.line != 0)
2514 step_into_function (ecs);
2519 /* If we have no line number and the step-stop-if-no-debug
2520 is set, we stop the step so that the user has a chance to
2521 switch in assembly mode. */
2522 if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug)
2525 print_stop_reason (END_STEPPING_RANGE, 0);
2526 stop_stepping (ecs);
2530 step_over_function (ecs);
2536 /* We've wandered out of the step range. */
2538 ecs->sal = find_pc_line (stop_pc, 0);
2540 if (step_range_end == 1)
2542 /* It is stepi or nexti. We always want to stop stepping after
2545 print_stop_reason (END_STEPPING_RANGE, 0);
2546 stop_stepping (ecs);
2550 /* If we're in the return path from a shared library trampoline,
2551 we want to proceed through the trampoline when stepping. */
2552 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2554 /* Determine where this trampoline returns. */
2555 real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc);
2557 /* Only proceed through if we know where it's going. */
2560 /* And put the step-breakpoint there and go until there. */
2561 struct symtab_and_line sr_sal;
2563 init_sal (&sr_sal); /* initialize to zeroes */
2564 sr_sal.pc = real_stop_pc;
2565 sr_sal.section = find_pc_overlay (sr_sal.pc);
2566 /* Do not specify what the fp should be when we stop
2567 since on some machines the prologue
2568 is where the new fp value is established. */
2569 check_for_old_step_resume_breakpoint ();
2570 step_resume_breakpoint =
2571 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2572 if (breakpoints_inserted)
2573 insert_breakpoints ();
2575 /* Restart without fiddling with the step ranges or
2582 if (ecs->sal.line == 0)
2584 /* We have no line number information. That means to stop
2585 stepping (does this always happen right after one instruction,
2586 when we do "s" in a function with no line numbers,
2587 or can this happen as a result of a return or longjmp?). */
2589 print_stop_reason (END_STEPPING_RANGE, 0);
2590 stop_stepping (ecs);
2594 if ((stop_pc == ecs->sal.pc)
2595 && (ecs->current_line != ecs->sal.line
2596 || ecs->current_symtab != ecs->sal.symtab))
2598 /* We are at the start of a different line. So stop. Note that
2599 we don't stop if we step into the middle of a different line.
2600 That is said to make things like for (;;) statements work
2603 print_stop_reason (END_STEPPING_RANGE, 0);
2604 stop_stepping (ecs);
2608 /* We aren't done stepping.
2610 Optimize by setting the stepping range to the line.
2611 (We might not be in the original line, but if we entered a
2612 new line in mid-statement, we continue stepping. This makes
2613 things like for(;;) statements work better.) */
2615 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
2617 /* If this is the last line of the function, don't keep stepping
2618 (it would probably step us out of the function).
2619 This is particularly necessary for a one-line function,
2620 in which after skipping the prologue we better stop even though
2621 we will be in mid-line. */
2623 print_stop_reason (END_STEPPING_RANGE, 0);
2624 stop_stepping (ecs);
2627 step_range_start = ecs->sal.pc;
2628 step_range_end = ecs->sal.end;
2629 step_frame_id = get_frame_id (get_current_frame ());
2630 ecs->current_line = ecs->sal.line;
2631 ecs->current_symtab = ecs->sal.symtab;
2633 /* In the case where we just stepped out of a function into the
2634 middle of a line of the caller, continue stepping, but
2635 step_frame_id must be modified to current frame */
2637 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too
2638 generous. It will trigger on things like a step into a frameless
2639 stackless leaf function. I think the logic should instead look
2640 at the unwound frame ID has that should give a more robust
2641 indication of what happened. */
2642 if (step-ID == current-ID)
2643 still stepping in same function;
2644 else if (step-ID == unwind (current-ID))
2645 stepped into a function;
2647 stepped out of a function;
2648 /* Of course this assumes that the frame ID unwind code is robust
2649 and we're willing to introduce frame unwind logic into this
2650 function. Fortunately, those days are nearly upon us. */
2653 struct frame_id current_frame = get_frame_id (get_current_frame ());
2654 if (!(frame_id_inner (current_frame, step_frame_id)))
2655 step_frame_id = current_frame;
2661 /* Are we in the middle of stepping? */
2664 currently_stepping (struct execution_control_state *ecs)
2666 return ((through_sigtramp_breakpoint == NULL
2667 && !ecs->handling_longjmp
2668 && ((step_range_end && step_resume_breakpoint == NULL)
2670 || ecs->stepping_through_solib_after_catch
2671 || bpstat_should_step ());
2675 check_sigtramp2 (struct execution_control_state *ecs)
2678 && pc_in_sigtramp (stop_pc)
2679 && !pc_in_sigtramp (prev_pc)
2680 && INNER_THAN (read_sp (), step_sp))
2682 /* What has happened here is that we have just stepped the
2683 inferior with a signal (because it is a signal which
2684 shouldn't make us stop), thus stepping into sigtramp.
2686 So we need to set a step_resume_break_address breakpoint and
2687 continue until we hit it, and then step. FIXME: This should
2688 be more enduring than a step_resume breakpoint; we should
2689 know that we will later need to keep going rather than
2690 re-hitting the breakpoint here (see the testsuite,
2691 gdb.base/signals.exp where it says "exceedingly difficult"). */
2693 struct symtab_and_line sr_sal;
2695 init_sal (&sr_sal); /* initialize to zeroes */
2696 sr_sal.pc = prev_pc;
2697 sr_sal.section = find_pc_overlay (sr_sal.pc);
2698 /* We perhaps could set the frame if we kept track of what the
2699 frame corresponding to prev_pc was. But we don't, so don't. */
2700 through_sigtramp_breakpoint =
2701 set_momentary_breakpoint (sr_sal, null_frame_id, bp_through_sigtramp);
2702 if (breakpoints_inserted)
2703 insert_breakpoints ();
2705 ecs->remove_breakpoints_on_following_step = 1;
2706 ecs->another_trap = 1;
2710 /* Subroutine call with source code we should not step over. Do step
2711 to the first line of code in it. */
2714 step_into_function (struct execution_control_state *ecs)
2717 struct symtab_and_line sr_sal;
2719 s = find_pc_symtab (stop_pc);
2720 if (s && s->language != language_asm)
2721 ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start);
2723 ecs->sal = find_pc_line (ecs->stop_func_start, 0);
2724 /* Use the step_resume_break to step until the end of the prologue,
2725 even if that involves jumps (as it seems to on the vax under
2727 /* If the prologue ends in the middle of a source line, continue to
2728 the end of that source line (if it is still within the function).
2729 Otherwise, just go to end of prologue. */
2731 && ecs->sal.pc != ecs->stop_func_start
2732 && ecs->sal.end < ecs->stop_func_end)
2733 ecs->stop_func_start = ecs->sal.end;
2735 if (ecs->stop_func_start == stop_pc)
2737 /* We are already there: stop now. */
2739 print_stop_reason (END_STEPPING_RANGE, 0);
2740 stop_stepping (ecs);
2745 /* Put the step-breakpoint there and go until there. */
2746 init_sal (&sr_sal); /* initialize to zeroes */
2747 sr_sal.pc = ecs->stop_func_start;
2748 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
2749 /* Do not specify what the fp should be when we stop since on
2750 some machines the prologue is where the new fp value is
2752 check_for_old_step_resume_breakpoint ();
2753 step_resume_breakpoint =
2754 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2755 if (breakpoints_inserted)
2756 insert_breakpoints ();
2758 /* And make sure stepping stops right away then. */
2759 step_range_end = step_range_start;
2764 /* We've just entered a callee, and we wish to resume until it returns
2765 to the caller. Setting a step_resume breakpoint on the return
2766 address will catch a return from the callee.
2768 However, if the callee is recursing, we want to be careful not to
2769 catch returns of those recursive calls, but only of THIS instance
2772 To do this, we set the step_resume bp's frame to our current
2773 caller's frame (step_frame_id, which is set by the "next" or
2774 "until" command, before execution begins). */
2777 step_over_function (struct execution_control_state *ecs)
2779 struct symtab_and_line sr_sal;
2781 init_sal (&sr_sal); /* initialize to zeros */
2783 /* NOTE: cagney/2003-04-06:
2785 At this point the equality get_frame_pc() == get_frame_func()
2786 should hold. This may make it possible for this code to tell the
2787 frame where it's function is, instead of the reverse. This would
2788 avoid the need to search for the frame's function, which can get
2789 very messy when there is no debug info available (look at the
2790 heuristic find pc start code found in targets like the MIPS). */
2792 /* NOTE: cagney/2003-04-06:
2794 The intent of DEPRECATED_SAVED_PC_AFTER_CALL was to:
2796 - provide a very light weight equivalent to frame_unwind_pc()
2797 (nee FRAME_SAVED_PC) that avoids the prologue analyzer
2799 - avoid handling the case where the PC hasn't been saved in the
2802 Unfortunately, not five lines further down, is a call to
2803 get_frame_id() and that is guarenteed to trigger the prologue
2806 The `correct fix' is for the prologe analyzer to handle the case
2807 where the prologue is incomplete (PC in prologue) and,
2808 consequently, the return pc has not yet been saved. It should be
2809 noted that the prologue analyzer needs to handle this case
2810 anyway: frameless leaf functions that don't save the return PC;
2811 single stepping through a prologue.
2813 The d10v handles all this by bailing out of the prologue analsis
2814 when it reaches the current instruction. */
2816 if (DEPRECATED_SAVED_PC_AFTER_CALL_P ())
2817 sr_sal.pc = ADDR_BITS_REMOVE (DEPRECATED_SAVED_PC_AFTER_CALL (get_current_frame ()));
2819 sr_sal.pc = ADDR_BITS_REMOVE (frame_pc_unwind (get_current_frame ()));
2820 sr_sal.section = find_pc_overlay (sr_sal.pc);
2822 check_for_old_step_resume_breakpoint ();
2823 step_resume_breakpoint =
2824 set_momentary_breakpoint (sr_sal, get_frame_id (get_current_frame ()),
2827 if (frame_id_p (step_frame_id)
2828 && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
2829 step_resume_breakpoint->frame_id = step_frame_id;
2831 if (breakpoints_inserted)
2832 insert_breakpoints ();
2836 stop_stepping (struct execution_control_state *ecs)
2838 /* Let callers know we don't want to wait for the inferior anymore. */
2839 ecs->wait_some_more = 0;
2842 /* This function handles various cases where we need to continue
2843 waiting for the inferior. */
2844 /* (Used to be the keep_going: label in the old wait_for_inferior) */
2847 keep_going (struct execution_control_state *ecs)
2849 /* Save the pc before execution, to compare with pc after stop. */
2850 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
2852 if (ecs->update_step_sp)
2853 step_sp = read_sp ();
2854 ecs->update_step_sp = 0;
2856 /* If we did not do break;, it means we should keep running the
2857 inferior and not return to debugger. */
2859 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
2861 /* We took a signal (which we are supposed to pass through to
2862 the inferior, else we'd have done a break above) and we
2863 haven't yet gotten our trap. Simply continue. */
2864 resume (currently_stepping (ecs), stop_signal);
2868 /* Either the trap was not expected, but we are continuing
2869 anyway (the user asked that this signal be passed to the
2872 The signal was SIGTRAP, e.g. it was our signal, but we
2873 decided we should resume from it.
2875 We're going to run this baby now!
2877 Insert breakpoints now, unless we are trying to one-proceed
2878 past a breakpoint. */
2879 /* If we've just finished a special step resume and we don't
2880 want to hit a breakpoint, pull em out. */
2881 if (step_resume_breakpoint == NULL
2882 && through_sigtramp_breakpoint == NULL
2883 && ecs->remove_breakpoints_on_following_step)
2885 ecs->remove_breakpoints_on_following_step = 0;
2886 remove_breakpoints ();
2887 breakpoints_inserted = 0;
2889 else if (!breakpoints_inserted &&
2890 (through_sigtramp_breakpoint != NULL || !ecs->another_trap))
2892 breakpoints_failed = insert_breakpoints ();
2893 if (breakpoints_failed)
2895 stop_stepping (ecs);
2898 breakpoints_inserted = 1;
2901 trap_expected = ecs->another_trap;
2903 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
2904 specifies that such a signal should be delivered to the
2907 Typically, this would occure when a user is debugging a
2908 target monitor on a simulator: the target monitor sets a
2909 breakpoint; the simulator encounters this break-point and
2910 halts the simulation handing control to GDB; GDB, noteing
2911 that the break-point isn't valid, returns control back to the
2912 simulator; the simulator then delivers the hardware
2913 equivalent of a SIGNAL_TRAP to the program being debugged. */
2915 if (stop_signal == TARGET_SIGNAL_TRAP && !signal_program[stop_signal])
2916 stop_signal = TARGET_SIGNAL_0;
2918 #ifdef SHIFT_INST_REGS
2919 /* I'm not sure when this following segment applies. I do know,
2920 now, that we shouldn't rewrite the regs when we were stopped
2921 by a random signal from the inferior process. */
2922 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2923 (this is only used on the 88k). */
2925 if (!bpstat_explains_signal (stop_bpstat)
2926 && (stop_signal != TARGET_SIGNAL_CHLD) && !stopped_by_random_signal)
2928 #endif /* SHIFT_INST_REGS */
2930 resume (currently_stepping (ecs), stop_signal);
2933 prepare_to_wait (ecs);
2936 /* This function normally comes after a resume, before
2937 handle_inferior_event exits. It takes care of any last bits of
2938 housekeeping, and sets the all-important wait_some_more flag. */
2941 prepare_to_wait (struct execution_control_state *ecs)
2943 if (ecs->infwait_state == infwait_normal_state)
2945 overlay_cache_invalid = 1;
2947 /* We have to invalidate the registers BEFORE calling
2948 target_wait because they can be loaded from the target while
2949 in target_wait. This makes remote debugging a bit more
2950 efficient for those targets that provide critical registers
2951 as part of their normal status mechanism. */
2953 registers_changed ();
2954 ecs->waiton_ptid = pid_to_ptid (-1);
2955 ecs->wp = &(ecs->ws);
2957 /* This is the old end of the while loop. Let everybody know we
2958 want to wait for the inferior some more and get called again
2960 ecs->wait_some_more = 1;
2963 /* Print why the inferior has stopped. We always print something when
2964 the inferior exits, or receives a signal. The rest of the cases are
2965 dealt with later on in normal_stop() and print_it_typical(). Ideally
2966 there should be a call to this function from handle_inferior_event()
2967 each time stop_stepping() is called.*/
2969 print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
2971 switch (stop_reason)
2974 /* We don't deal with these cases from handle_inferior_event()
2977 case END_STEPPING_RANGE:
2978 /* We are done with a step/next/si/ni command. */
2979 /* For now print nothing. */
2980 /* Print a message only if not in the middle of doing a "step n"
2981 operation for n > 1 */
2982 if (!step_multi || !stop_step)
2983 if (ui_out_is_mi_like_p (uiout))
2984 ui_out_field_string (uiout, "reason", "end-stepping-range");
2986 case BREAKPOINT_HIT:
2987 /* We found a breakpoint. */
2988 /* For now print nothing. */
2991 /* The inferior was terminated by a signal. */
2992 annotate_signalled ();
2993 if (ui_out_is_mi_like_p (uiout))
2994 ui_out_field_string (uiout, "reason", "exited-signalled");
2995 ui_out_text (uiout, "\nProgram terminated with signal ");
2996 annotate_signal_name ();
2997 ui_out_field_string (uiout, "signal-name",
2998 target_signal_to_name (stop_info));
2999 annotate_signal_name_end ();
3000 ui_out_text (uiout, ", ");
3001 annotate_signal_string ();
3002 ui_out_field_string (uiout, "signal-meaning",
3003 target_signal_to_string (stop_info));
3004 annotate_signal_string_end ();
3005 ui_out_text (uiout, ".\n");
3006 ui_out_text (uiout, "The program no longer exists.\n");
3009 /* The inferior program is finished. */
3010 annotate_exited (stop_info);
3013 if (ui_out_is_mi_like_p (uiout))
3014 ui_out_field_string (uiout, "reason", "exited");
3015 ui_out_text (uiout, "\nProgram exited with code ");
3016 ui_out_field_fmt (uiout, "exit-code", "0%o",
3017 (unsigned int) stop_info);
3018 ui_out_text (uiout, ".\n");
3022 if (ui_out_is_mi_like_p (uiout))
3023 ui_out_field_string (uiout, "reason", "exited-normally");
3024 ui_out_text (uiout, "\nProgram exited normally.\n");
3027 case SIGNAL_RECEIVED:
3028 /* Signal received. The signal table tells us to print about
3031 ui_out_text (uiout, "\nProgram received signal ");
3032 annotate_signal_name ();
3033 if (ui_out_is_mi_like_p (uiout))
3034 ui_out_field_string (uiout, "reason", "signal-received");
3035 ui_out_field_string (uiout, "signal-name",
3036 target_signal_to_name (stop_info));
3037 annotate_signal_name_end ();
3038 ui_out_text (uiout, ", ");
3039 annotate_signal_string ();
3040 ui_out_field_string (uiout, "signal-meaning",
3041 target_signal_to_string (stop_info));
3042 annotate_signal_string_end ();
3043 ui_out_text (uiout, ".\n");
3046 internal_error (__FILE__, __LINE__,
3047 "print_stop_reason: unrecognized enum value");
3053 /* Here to return control to GDB when the inferior stops for real.
3054 Print appropriate messages, remove breakpoints, give terminal our modes.
3056 STOP_PRINT_FRAME nonzero means print the executing frame
3057 (pc, function, args, file, line number and line text).
3058 BREAKPOINTS_FAILED nonzero means stop was due to error
3059 attempting to insert breakpoints. */
3064 struct target_waitstatus last;
3067 get_last_target_status (&last_ptid, &last);
3069 /* As with the notification of thread events, we want to delay
3070 notifying the user that we've switched thread context until
3071 the inferior actually stops.
3073 There's no point in saying anything if the inferior has exited.
3074 Note that SIGNALLED here means "exited with a signal", not
3075 "received a signal". */
3076 if (!ptid_equal (previous_inferior_ptid, inferior_ptid)
3077 && target_has_execution
3078 && last.kind != TARGET_WAITKIND_SIGNALLED
3079 && last.kind != TARGET_WAITKIND_EXITED)
3081 target_terminal_ours_for_output ();
3082 printf_filtered ("[Switching to %s]\n",
3083 target_pid_or_tid_to_str (inferior_ptid));
3084 previous_inferior_ptid = inferior_ptid;
3087 /* Make sure that the current_frame's pc is correct. This
3088 is a correction for setting up the frame info before doing
3089 DECR_PC_AFTER_BREAK */
3090 if (target_has_execution)
3091 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3092 DECR_PC_AFTER_BREAK, the program counter can change. Ask the
3093 frame code to check for this and sort out any resultant mess.
3094 DECR_PC_AFTER_BREAK needs to just go away. */
3095 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3097 if (target_has_execution && breakpoints_inserted)
3099 if (remove_breakpoints ())
3101 target_terminal_ours_for_output ();
3102 printf_filtered ("Cannot remove breakpoints because ");
3103 printf_filtered ("program is no longer writable.\n");
3104 printf_filtered ("It might be running in another process.\n");
3105 printf_filtered ("Further execution is probably impossible.\n");
3108 breakpoints_inserted = 0;
3110 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3111 Delete any breakpoint that is to be deleted at the next stop. */
3113 breakpoint_auto_delete (stop_bpstat);
3115 /* If an auto-display called a function and that got a signal,
3116 delete that auto-display to avoid an infinite recursion. */
3118 if (stopped_by_random_signal)
3119 disable_current_display ();
3121 /* Don't print a message if in the middle of doing a "step n"
3122 operation for n > 1 */
3123 if (step_multi && stop_step)
3126 target_terminal_ours ();
3128 /* Look up the hook_stop and run it (CLI internally handles problem
3129 of stop_command's pre-hook not existing). */
3131 catch_errors (hook_stop_stub, stop_command,
3132 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3134 if (!target_has_stack)
3140 /* Select innermost stack frame - i.e., current frame is frame 0,
3141 and current location is based on that.
3142 Don't do this on return from a stack dummy routine,
3143 or if the program has exited. */
3145 if (!stop_stack_dummy)
3147 select_frame (get_current_frame ());
3149 /* Print current location without a level number, if
3150 we have changed functions or hit a breakpoint.
3151 Print source line if we have one.
3152 bpstat_print() contains the logic deciding in detail
3153 what to print, based on the event(s) that just occurred. */
3155 if (stop_print_frame && deprecated_selected_frame)
3159 int do_frame_printing = 1;
3161 bpstat_ret = bpstat_print (stop_bpstat);
3165 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3166 (or should) carry around the function and does (or
3167 should) use that when doing a frame comparison. */
3169 && frame_id_eq (step_frame_id,
3170 get_frame_id (get_current_frame ()))
3171 && step_start_function == find_pc_function (stop_pc))
3172 source_flag = SRC_LINE; /* finished step, just print source line */
3174 source_flag = SRC_AND_LOC; /* print location and source line */
3176 case PRINT_SRC_AND_LOC:
3177 source_flag = SRC_AND_LOC; /* print location and source line */
3179 case PRINT_SRC_ONLY:
3180 source_flag = SRC_LINE;
3183 source_flag = SRC_LINE; /* something bogus */
3184 do_frame_printing = 0;
3187 internal_error (__FILE__, __LINE__, "Unknown value.");
3189 /* For mi, have the same behavior every time we stop:
3190 print everything but the source line. */
3191 if (ui_out_is_mi_like_p (uiout))
3192 source_flag = LOC_AND_ADDRESS;
3194 if (ui_out_is_mi_like_p (uiout))
3195 ui_out_field_int (uiout, "thread-id",
3196 pid_to_thread_id (inferior_ptid));
3197 /* The behavior of this routine with respect to the source
3199 SRC_LINE: Print only source line
3200 LOCATION: Print only location
3201 SRC_AND_LOC: Print location and source line */
3202 if (do_frame_printing)
3203 print_stack_frame (deprecated_selected_frame, -1, source_flag);
3205 /* Display the auto-display expressions. */
3210 /* Save the function value return registers, if we care.
3211 We might be about to restore their previous contents. */
3212 if (proceed_to_finish)
3213 /* NB: The copy goes through to the target picking up the value of
3214 all the registers. */
3215 regcache_cpy (stop_registers, current_regcache);
3217 if (stop_stack_dummy)
3219 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3220 ends with a setting of the current frame, so we can use that
3222 frame_pop (get_current_frame ());
3223 /* Set stop_pc to what it was before we called the function.
3224 Can't rely on restore_inferior_status because that only gets
3225 called if we don't stop in the called function. */
3226 stop_pc = read_pc ();
3227 select_frame (get_current_frame ());
3231 annotate_stopped ();
3232 observer_notify_normal_stop ();
3236 hook_stop_stub (void *cmd)
3238 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
3243 signal_stop_state (int signo)
3245 return signal_stop[signo];
3249 signal_print_state (int signo)
3251 return signal_print[signo];
3255 signal_pass_state (int signo)
3257 return signal_program[signo];
3261 signal_stop_update (int signo, int state)
3263 int ret = signal_stop[signo];
3264 signal_stop[signo] = state;
3269 signal_print_update (int signo, int state)
3271 int ret = signal_print[signo];
3272 signal_print[signo] = state;
3277 signal_pass_update (int signo, int state)
3279 int ret = signal_program[signo];
3280 signal_program[signo] = state;
3285 sig_print_header (void)
3288 Signal Stop\tPrint\tPass to program\tDescription\n");
3292 sig_print_info (enum target_signal oursig)
3294 char *name = target_signal_to_name (oursig);
3295 int name_padding = 13 - strlen (name);
3297 if (name_padding <= 0)
3300 printf_filtered ("%s", name);
3301 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
3302 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3303 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3304 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3305 printf_filtered ("%s\n", target_signal_to_string (oursig));
3308 /* Specify how various signals in the inferior should be handled. */
3311 handle_command (char *args, int from_tty)
3314 int digits, wordlen;
3315 int sigfirst, signum, siglast;
3316 enum target_signal oursig;
3319 unsigned char *sigs;
3320 struct cleanup *old_chain;
3324 error_no_arg ("signal to handle");
3327 /* Allocate and zero an array of flags for which signals to handle. */
3329 nsigs = (int) TARGET_SIGNAL_LAST;
3330 sigs = (unsigned char *) alloca (nsigs);
3331 memset (sigs, 0, nsigs);
3333 /* Break the command line up into args. */
3335 argv = buildargv (args);
3340 old_chain = make_cleanup_freeargv (argv);
3342 /* Walk through the args, looking for signal oursigs, signal names, and
3343 actions. Signal numbers and signal names may be interspersed with
3344 actions, with the actions being performed for all signals cumulatively
3345 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3347 while (*argv != NULL)
3349 wordlen = strlen (*argv);
3350 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3354 sigfirst = siglast = -1;
3356 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3358 /* Apply action to all signals except those used by the
3359 debugger. Silently skip those. */
3362 siglast = nsigs - 1;
3364 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3366 SET_SIGS (nsigs, sigs, signal_stop);
3367 SET_SIGS (nsigs, sigs, signal_print);
3369 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3371 UNSET_SIGS (nsigs, sigs, signal_program);
3373 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3375 SET_SIGS (nsigs, sigs, signal_print);
3377 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3379 SET_SIGS (nsigs, sigs, signal_program);
3381 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3383 UNSET_SIGS (nsigs, sigs, signal_stop);
3385 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3387 SET_SIGS (nsigs, sigs, signal_program);
3389 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3391 UNSET_SIGS (nsigs, sigs, signal_print);
3392 UNSET_SIGS (nsigs, sigs, signal_stop);
3394 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3396 UNSET_SIGS (nsigs, sigs, signal_program);
3398 else if (digits > 0)
3400 /* It is numeric. The numeric signal refers to our own
3401 internal signal numbering from target.h, not to host/target
3402 signal number. This is a feature; users really should be
3403 using symbolic names anyway, and the common ones like
3404 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3406 sigfirst = siglast = (int)
3407 target_signal_from_command (atoi (*argv));
3408 if ((*argv)[digits] == '-')
3411 target_signal_from_command (atoi ((*argv) + digits + 1));
3413 if (sigfirst > siglast)
3415 /* Bet he didn't figure we'd think of this case... */
3423 oursig = target_signal_from_name (*argv);
3424 if (oursig != TARGET_SIGNAL_UNKNOWN)
3426 sigfirst = siglast = (int) oursig;
3430 /* Not a number and not a recognized flag word => complain. */
3431 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3435 /* If any signal numbers or symbol names were found, set flags for
3436 which signals to apply actions to. */
3438 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3440 switch ((enum target_signal) signum)
3442 case TARGET_SIGNAL_TRAP:
3443 case TARGET_SIGNAL_INT:
3444 if (!allsigs && !sigs[signum])
3446 if (query ("%s is used by the debugger.\n\
3447 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum)))
3453 printf_unfiltered ("Not confirmed, unchanged.\n");
3454 gdb_flush (gdb_stdout);
3458 case TARGET_SIGNAL_0:
3459 case TARGET_SIGNAL_DEFAULT:
3460 case TARGET_SIGNAL_UNKNOWN:
3461 /* Make sure that "all" doesn't print these. */
3472 target_notice_signals (inferior_ptid);
3476 /* Show the results. */
3477 sig_print_header ();
3478 for (signum = 0; signum < nsigs; signum++)
3482 sig_print_info (signum);
3487 do_cleanups (old_chain);
3491 xdb_handle_command (char *args, int from_tty)
3494 struct cleanup *old_chain;
3496 /* Break the command line up into args. */
3498 argv = buildargv (args);
3503 old_chain = make_cleanup_freeargv (argv);
3504 if (argv[1] != (char *) NULL)
3509 bufLen = strlen (argv[0]) + 20;
3510 argBuf = (char *) xmalloc (bufLen);
3514 enum target_signal oursig;
3516 oursig = target_signal_from_name (argv[0]);
3517 memset (argBuf, 0, bufLen);
3518 if (strcmp (argv[1], "Q") == 0)
3519 sprintf (argBuf, "%s %s", argv[0], "noprint");
3522 if (strcmp (argv[1], "s") == 0)
3524 if (!signal_stop[oursig])
3525 sprintf (argBuf, "%s %s", argv[0], "stop");
3527 sprintf (argBuf, "%s %s", argv[0], "nostop");
3529 else if (strcmp (argv[1], "i") == 0)
3531 if (!signal_program[oursig])
3532 sprintf (argBuf, "%s %s", argv[0], "pass");
3534 sprintf (argBuf, "%s %s", argv[0], "nopass");
3536 else if (strcmp (argv[1], "r") == 0)
3538 if (!signal_print[oursig])
3539 sprintf (argBuf, "%s %s", argv[0], "print");
3541 sprintf (argBuf, "%s %s", argv[0], "noprint");
3547 handle_command (argBuf, from_tty);
3549 printf_filtered ("Invalid signal handling flag.\n");
3554 do_cleanups (old_chain);
3557 /* Print current contents of the tables set by the handle command.
3558 It is possible we should just be printing signals actually used
3559 by the current target (but for things to work right when switching
3560 targets, all signals should be in the signal tables). */
3563 signals_info (char *signum_exp, int from_tty)
3565 enum target_signal oursig;
3566 sig_print_header ();
3570 /* First see if this is a symbol name. */
3571 oursig = target_signal_from_name (signum_exp);
3572 if (oursig == TARGET_SIGNAL_UNKNOWN)
3574 /* No, try numeric. */
3576 target_signal_from_command (parse_and_eval_long (signum_exp));
3578 sig_print_info (oursig);
3582 printf_filtered ("\n");
3583 /* These ugly casts brought to you by the native VAX compiler. */
3584 for (oursig = TARGET_SIGNAL_FIRST;
3585 (int) oursig < (int) TARGET_SIGNAL_LAST;
3586 oursig = (enum target_signal) ((int) oursig + 1))
3590 if (oursig != TARGET_SIGNAL_UNKNOWN
3591 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
3592 sig_print_info (oursig);
3595 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3598 struct inferior_status
3600 enum target_signal stop_signal;
3604 int stop_stack_dummy;
3605 int stopped_by_random_signal;
3607 CORE_ADDR step_range_start;
3608 CORE_ADDR step_range_end;
3609 struct frame_id step_frame_id;
3610 enum step_over_calls_kind step_over_calls;
3611 CORE_ADDR step_resume_break_address;
3612 int stop_after_trap;
3614 struct regcache *stop_registers;
3616 /* These are here because if call_function_by_hand has written some
3617 registers and then decides to call error(), we better not have changed
3619 struct regcache *registers;
3621 /* A frame unique identifier. */
3622 struct frame_id selected_frame_id;
3624 int breakpoint_proceeded;
3625 int restore_stack_info;
3626 int proceed_to_finish;
3630 write_inferior_status_register (struct inferior_status *inf_status, int regno,
3633 int size = DEPRECATED_REGISTER_RAW_SIZE (regno);
3634 void *buf = alloca (size);
3635 store_signed_integer (buf, size, val);
3636 regcache_raw_write (inf_status->registers, regno, buf);
3639 /* Save all of the information associated with the inferior<==>gdb
3640 connection. INF_STATUS is a pointer to a "struct inferior_status"
3641 (defined in inferior.h). */
3643 struct inferior_status *
3644 save_inferior_status (int restore_stack_info)
3646 struct inferior_status *inf_status = XMALLOC (struct inferior_status);
3648 inf_status->stop_signal = stop_signal;
3649 inf_status->stop_pc = stop_pc;
3650 inf_status->stop_step = stop_step;
3651 inf_status->stop_stack_dummy = stop_stack_dummy;
3652 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3653 inf_status->trap_expected = trap_expected;
3654 inf_status->step_range_start = step_range_start;
3655 inf_status->step_range_end = step_range_end;
3656 inf_status->step_frame_id = step_frame_id;
3657 inf_status->step_over_calls = step_over_calls;
3658 inf_status->stop_after_trap = stop_after_trap;
3659 inf_status->stop_soon = stop_soon;
3660 /* Save original bpstat chain here; replace it with copy of chain.
3661 If caller's caller is walking the chain, they'll be happier if we
3662 hand them back the original chain when restore_inferior_status is
3664 inf_status->stop_bpstat = stop_bpstat;
3665 stop_bpstat = bpstat_copy (stop_bpstat);
3666 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3667 inf_status->restore_stack_info = restore_stack_info;
3668 inf_status->proceed_to_finish = proceed_to_finish;
3670 inf_status->stop_registers = regcache_dup_no_passthrough (stop_registers);
3672 inf_status->registers = regcache_dup (current_regcache);
3674 inf_status->selected_frame_id = get_frame_id (deprecated_selected_frame);
3679 restore_selected_frame (void *args)
3681 struct frame_id *fid = (struct frame_id *) args;
3682 struct frame_info *frame;
3684 frame = frame_find_by_id (*fid);
3686 /* If inf_status->selected_frame_id is NULL, there was no previously
3690 warning ("Unable to restore previously selected frame.\n");
3694 select_frame (frame);
3700 restore_inferior_status (struct inferior_status *inf_status)
3702 stop_signal = inf_status->stop_signal;
3703 stop_pc = inf_status->stop_pc;
3704 stop_step = inf_status->stop_step;
3705 stop_stack_dummy = inf_status->stop_stack_dummy;
3706 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3707 trap_expected = inf_status->trap_expected;
3708 step_range_start = inf_status->step_range_start;
3709 step_range_end = inf_status->step_range_end;
3710 step_frame_id = inf_status->step_frame_id;
3711 step_over_calls = inf_status->step_over_calls;
3712 stop_after_trap = inf_status->stop_after_trap;
3713 stop_soon = inf_status->stop_soon;
3714 bpstat_clear (&stop_bpstat);
3715 stop_bpstat = inf_status->stop_bpstat;
3716 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3717 proceed_to_finish = inf_status->proceed_to_finish;
3719 /* FIXME: Is the restore of stop_registers always needed. */
3720 regcache_xfree (stop_registers);
3721 stop_registers = inf_status->stop_registers;
3723 /* The inferior can be gone if the user types "print exit(0)"
3724 (and perhaps other times). */
3725 if (target_has_execution)
3726 /* NB: The register write goes through to the target. */
3727 regcache_cpy (current_regcache, inf_status->registers);
3728 regcache_xfree (inf_status->registers);
3730 /* FIXME: If we are being called after stopping in a function which
3731 is called from gdb, we should not be trying to restore the
3732 selected frame; it just prints a spurious error message (The
3733 message is useful, however, in detecting bugs in gdb (like if gdb
3734 clobbers the stack)). In fact, should we be restoring the
3735 inferior status at all in that case? . */
3737 if (target_has_stack && inf_status->restore_stack_info)
3739 /* The point of catch_errors is that if the stack is clobbered,
3740 walking the stack might encounter a garbage pointer and
3741 error() trying to dereference it. */
3743 (restore_selected_frame, &inf_status->selected_frame_id,
3744 "Unable to restore previously selected frame:\n",
3745 RETURN_MASK_ERROR) == 0)
3746 /* Error in restoring the selected frame. Select the innermost
3748 select_frame (get_current_frame ());
3756 do_restore_inferior_status_cleanup (void *sts)
3758 restore_inferior_status (sts);
3762 make_cleanup_restore_inferior_status (struct inferior_status *inf_status)
3764 return make_cleanup (do_restore_inferior_status_cleanup, inf_status);
3768 discard_inferior_status (struct inferior_status *inf_status)
3770 /* See save_inferior_status for info on stop_bpstat. */
3771 bpstat_clear (&inf_status->stop_bpstat);
3772 regcache_xfree (inf_status->registers);
3773 regcache_xfree (inf_status->stop_registers);
3778 inferior_has_forked (int pid, int *child_pid)
3780 struct target_waitstatus last;
3783 get_last_target_status (&last_ptid, &last);
3785 if (last.kind != TARGET_WAITKIND_FORKED)
3788 if (ptid_get_pid (last_ptid) != pid)
3791 *child_pid = last.value.related_pid;
3796 inferior_has_vforked (int pid, int *child_pid)
3798 struct target_waitstatus last;
3801 get_last_target_status (&last_ptid, &last);
3803 if (last.kind != TARGET_WAITKIND_VFORKED)
3806 if (ptid_get_pid (last_ptid) != pid)
3809 *child_pid = last.value.related_pid;
3814 inferior_has_execd (int pid, char **execd_pathname)
3816 struct target_waitstatus last;
3819 get_last_target_status (&last_ptid, &last);
3821 if (last.kind != TARGET_WAITKIND_EXECD)
3824 if (ptid_get_pid (last_ptid) != pid)
3827 *execd_pathname = xstrdup (last.value.execd_pathname);
3831 /* Oft used ptids */
3833 ptid_t minus_one_ptid;
3835 /* Create a ptid given the necessary PID, LWP, and TID components. */
3838 ptid_build (int pid, long lwp, long tid)
3848 /* Create a ptid from just a pid. */
3851 pid_to_ptid (int pid)
3853 return ptid_build (pid, 0, 0);
3856 /* Fetch the pid (process id) component from a ptid. */
3859 ptid_get_pid (ptid_t ptid)
3864 /* Fetch the lwp (lightweight process) component from a ptid. */
3867 ptid_get_lwp (ptid_t ptid)
3872 /* Fetch the tid (thread id) component from a ptid. */
3875 ptid_get_tid (ptid_t ptid)
3880 /* ptid_equal() is used to test equality of two ptids. */
3883 ptid_equal (ptid_t ptid1, ptid_t ptid2)
3885 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
3886 && ptid1.tid == ptid2.tid);
3889 /* restore_inferior_ptid() will be used by the cleanup machinery
3890 to restore the inferior_ptid value saved in a call to
3891 save_inferior_ptid(). */
3894 restore_inferior_ptid (void *arg)
3896 ptid_t *saved_ptid_ptr = arg;
3897 inferior_ptid = *saved_ptid_ptr;
3901 /* Save the value of inferior_ptid so that it may be restored by a
3902 later call to do_cleanups(). Returns the struct cleanup pointer
3903 needed for later doing the cleanup. */
3906 save_inferior_ptid (void)
3908 ptid_t *saved_ptid_ptr;
3910 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
3911 *saved_ptid_ptr = inferior_ptid;
3912 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
3919 stop_registers = regcache_xmalloc (current_gdbarch);
3923 _initialize_infrun (void)
3927 struct cmd_list_element *c;
3929 register_gdbarch_swap (&stop_registers, sizeof (stop_registers), NULL);
3930 register_gdbarch_swap (NULL, 0, build_infrun);
3932 add_info ("signals", signals_info,
3933 "What debugger does when program gets various signals.\n\
3934 Specify a signal as argument to print info on that signal only.");
3935 add_info_alias ("handle", "signals", 0);
3937 add_com ("handle", class_run, handle_command,
3938 concat ("Specify how to handle a signal.\n\
3939 Args are signals and actions to apply to those signals.\n\
3940 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3941 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3942 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3943 The special arg \"all\" is recognized to mean all signals except those\n\
3944 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3945 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3946 Stop means reenter debugger if this signal happens (implies print).\n\
3947 Print means print a message if this signal happens.\n\
3948 Pass means let program see this signal; otherwise program doesn't know.\n\
3949 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3950 Pass and Stop may be combined.", NULL));
3953 add_com ("lz", class_info, signals_info,
3954 "What debugger does when program gets various signals.\n\
3955 Specify a signal as argument to print info on that signal only.");
3956 add_com ("z", class_run, xdb_handle_command,
3957 concat ("Specify how to handle a signal.\n\
3958 Args are signals and actions to apply to those signals.\n\
3959 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3960 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3961 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3962 The special arg \"all\" is recognized to mean all signals except those\n\
3963 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3964 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3965 nopass), \"Q\" (noprint)\n\
3966 Stop means reenter debugger if this signal happens (implies print).\n\
3967 Print means print a message if this signal happens.\n\
3968 Pass means let program see this signal; otherwise program doesn't know.\n\
3969 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3970 Pass and Stop may be combined.", NULL));
3975 add_cmd ("stop", class_obscure, not_just_help_class_command, "There is no `stop' command, but you can set a hook on `stop'.\n\
3976 This allows you to set a list of commands to be run each time execution\n\
3977 of the program stops.", &cmdlist);
3979 numsigs = (int) TARGET_SIGNAL_LAST;
3980 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
3981 signal_print = (unsigned char *)
3982 xmalloc (sizeof (signal_print[0]) * numsigs);
3983 signal_program = (unsigned char *)
3984 xmalloc (sizeof (signal_program[0]) * numsigs);
3985 for (i = 0; i < numsigs; i++)
3988 signal_print[i] = 1;
3989 signal_program[i] = 1;
3992 /* Signals caused by debugger's own actions
3993 should not be given to the program afterwards. */
3994 signal_program[TARGET_SIGNAL_TRAP] = 0;
3995 signal_program[TARGET_SIGNAL_INT] = 0;
3997 /* Signals that are not errors should not normally enter the debugger. */
3998 signal_stop[TARGET_SIGNAL_ALRM] = 0;
3999 signal_print[TARGET_SIGNAL_ALRM] = 0;
4000 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
4001 signal_print[TARGET_SIGNAL_VTALRM] = 0;
4002 signal_stop[TARGET_SIGNAL_PROF] = 0;
4003 signal_print[TARGET_SIGNAL_PROF] = 0;
4004 signal_stop[TARGET_SIGNAL_CHLD] = 0;
4005 signal_print[TARGET_SIGNAL_CHLD] = 0;
4006 signal_stop[TARGET_SIGNAL_IO] = 0;
4007 signal_print[TARGET_SIGNAL_IO] = 0;
4008 signal_stop[TARGET_SIGNAL_POLL] = 0;
4009 signal_print[TARGET_SIGNAL_POLL] = 0;
4010 signal_stop[TARGET_SIGNAL_URG] = 0;
4011 signal_print[TARGET_SIGNAL_URG] = 0;
4012 signal_stop[TARGET_SIGNAL_WINCH] = 0;
4013 signal_print[TARGET_SIGNAL_WINCH] = 0;
4015 /* These signals are used internally by user-level thread
4016 implementations. (See signal(5) on Solaris.) Like the above
4017 signals, a healthy program receives and handles them as part of
4018 its normal operation. */
4019 signal_stop[TARGET_SIGNAL_LWP] = 0;
4020 signal_print[TARGET_SIGNAL_LWP] = 0;
4021 signal_stop[TARGET_SIGNAL_WAITING] = 0;
4022 signal_print[TARGET_SIGNAL_WAITING] = 0;
4023 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
4024 signal_print[TARGET_SIGNAL_CANCEL] = 0;
4028 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
4029 (char *) &stop_on_solib_events,
4030 "Set stopping for shared library events.\n\
4031 If nonzero, gdb will give control to the user when the dynamic linker\n\
4032 notifies gdb of shared library events. The most common event of interest\n\
4033 to the user would be loading/unloading of a new library.\n", &setlist), &showlist);
4036 c = add_set_enum_cmd ("follow-fork-mode",
4038 follow_fork_mode_kind_names, &follow_fork_mode_string,
4039 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4040 kernel problem. It's also not terribly useful without a GUI to
4041 help the user drive two debuggers. So for now, I'm disabling
4042 the "both" option. */
4043 /* "Set debugger response to a program call of fork \
4045 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4046 parent - the original process is debugged after a fork\n\
4047 child - the new process is debugged after a fork\n\
4048 both - both the parent and child are debugged after a fork\n\
4049 ask - the debugger will ask for one of the above choices\n\
4050 For \"both\", another copy of the debugger will be started to follow\n\
4051 the new child process. The original debugger will continue to follow\n\
4052 the original parent process. To distinguish their prompts, the\n\
4053 debugger copy's prompt will be changed.\n\
4054 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4055 By default, the debugger will follow the parent process.",
4057 "Set debugger response to a program call of fork \
4059 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4060 parent - the original process is debugged after a fork\n\
4061 child - the new process is debugged after a fork\n\
4062 ask - the debugger will ask for one of the above choices\n\
4063 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4064 By default, the debugger will follow the parent process.", &setlist);
4065 add_show_from_set (c, &showlist);
4067 c = add_set_enum_cmd ("scheduler-locking", class_run, scheduler_enums, /* array of string names */
4068 &scheduler_mode, /* current mode */
4069 "Set mode for locking scheduler during execution.\n\
4070 off == no locking (threads may preempt at any time)\n\
4071 on == full locking (no thread except the current thread may run)\n\
4072 step == scheduler locked during every single-step operation.\n\
4073 In this mode, no other thread may run during a step command.\n\
4074 Other threads may run while stepping over a function call ('next').", &setlist);
4076 set_cmd_sfunc (c, set_schedlock_func); /* traps on target vector */
4077 add_show_from_set (c, &showlist);
4079 c = add_set_cmd ("step-mode", class_run,
4080 var_boolean, (char *) &step_stop_if_no_debug,
4081 "Set mode of the step operation. When set, doing a step over a\n\
4082 function without debug line information will stop at the first\n\
4083 instruction of that function. Otherwise, the function is skipped and\n\
4084 the step command stops at a different source line.", &setlist);
4085 add_show_from_set (c, &showlist);
4087 /* ptid initializations */
4088 null_ptid = ptid_build (0, 0, 0);
4089 minus_one_ptid = ptid_build (-1, 0, 0);
4090 inferior_ptid = null_ptid;
4091 target_last_wait_ptid = minus_one_ptid;