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"
46 /* Prototypes for local functions */
48 static void signals_info (char *, int);
50 static void handle_command (char *, int);
52 static void sig_print_info (enum target_signal
);
54 static void sig_print_header (void);
56 static void resume_cleanups (void *);
58 static int hook_stop_stub (void *);
60 static void delete_breakpoint_current_contents (void *);
62 static void set_follow_fork_mode_command (char *arg
, int from_tty
,
63 struct cmd_list_element
*c
);
65 static int restore_selected_frame (void *);
67 static void build_infrun (void);
69 static int follow_fork (void);
71 static void set_schedlock_func (char *args
, int from_tty
,
72 struct cmd_list_element
*c
);
74 struct execution_control_state
;
76 static int currently_stepping (struct execution_control_state
*ecs
);
78 static void xdb_handle_command (char *args
, int from_tty
);
80 void _initialize_infrun (void);
82 int inferior_ignoring_startup_exec_events
= 0;
83 int inferior_ignoring_leading_exec_events
= 0;
85 /* When set, stop the 'step' command if we enter a function which has
86 no line number information. The normal behavior is that we step
87 over such function. */
88 int step_stop_if_no_debug
= 0;
90 /* In asynchronous mode, but simulating synchronous execution. */
92 int sync_execution
= 0;
94 /* wait_for_inferior and normal_stop use this to notify the user
95 when the inferior stopped in a different thread than it had been
98 static ptid_t previous_inferior_ptid
;
100 /* This is true for configurations that may follow through execl() and
101 similar functions. At present this is only true for HP-UX native. */
103 #ifndef MAY_FOLLOW_EXEC
104 #define MAY_FOLLOW_EXEC (0)
107 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
109 /* Dynamic function trampolines are similar to solib trampolines in that they
110 are between the caller and the callee. The difference is that when you
111 enter a dynamic trampoline, you can't determine the callee's address. Some
112 (usually complex) code needs to run in the dynamic trampoline to figure out
113 the callee's address. This macro is usually called twice. First, when we
114 enter the trampoline (looks like a normal function call at that point). It
115 should return the PC of a point within the trampoline where the callee's
116 address is known. Second, when we hit the breakpoint, this routine returns
117 the callee's address. At that point, things proceed as per a step resume
120 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
121 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
124 /* If the program uses ELF-style shared libraries, then calls to
125 functions in shared libraries go through stubs, which live in a
126 table called the PLT (Procedure Linkage Table). The first time the
127 function is called, the stub sends control to the dynamic linker,
128 which looks up the function's real address, patches the stub so
129 that future calls will go directly to the function, and then passes
130 control to the function.
132 If we are stepping at the source level, we don't want to see any of
133 this --- we just want to skip over the stub and the dynamic linker.
134 The simple approach is to single-step until control leaves the
137 However, on some systems (e.g., Red Hat's 5.2 distribution) the
138 dynamic linker calls functions in the shared C library, so you
139 can't tell from the PC alone whether the dynamic linker is still
140 running. In this case, we use a step-resume breakpoint to get us
141 past the dynamic linker, as if we were using "next" to step over a
144 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
145 linker code or not. Normally, this means we single-step. However,
146 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
147 address where we can place a step-resume breakpoint to get past the
148 linker's symbol resolution function.
150 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
151 pretty portable way, by comparing the PC against the address ranges
152 of the dynamic linker's sections.
154 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
155 it depends on internal details of the dynamic linker. It's usually
156 not too hard to figure out where to put a breakpoint, but it
157 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
158 sanity checking. If it can't figure things out, returning zero and
159 getting the (possibly confusing) stepping behavior is better than
160 signalling an error, which will obscure the change in the
163 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
164 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
167 #ifndef SKIP_SOLIB_RESOLVER
168 #define SKIP_SOLIB_RESOLVER(pc) 0
171 /* This function returns TRUE if pc is the address of an instruction
172 that lies within the dynamic linker (such as the event hook, or the
175 This function must be used only when a dynamic linker event has
176 been caught, and the inferior is being stepped out of the hook, or
177 undefined results are guaranteed. */
179 #ifndef SOLIB_IN_DYNAMIC_LINKER
180 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
183 /* On MIPS16, a function that returns a floating point value may call
184 a library helper function to copy the return value to a floating point
185 register. The IGNORE_HELPER_CALL macro returns non-zero if we
186 should ignore (i.e. step over) this function call. */
187 #ifndef IGNORE_HELPER_CALL
188 #define IGNORE_HELPER_CALL(pc) 0
191 /* On some systems, the PC may be left pointing at an instruction that won't
192 actually be executed. This is usually indicated by a bit in the PSW. If
193 we find ourselves in such a state, then we step the target beyond the
194 nullified instruction before returning control to the user so as to avoid
197 #ifndef INSTRUCTION_NULLIFIED
198 #define INSTRUCTION_NULLIFIED 0
201 /* We can't step off a permanent breakpoint in the ordinary way, because we
202 can't remove it. Instead, we have to advance the PC to the next
203 instruction. This macro should expand to a pointer to a function that
204 does that, or zero if we have no such function. If we don't have a
205 definition for it, we have to report an error. */
206 #ifndef SKIP_PERMANENT_BREAKPOINT
207 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
209 default_skip_permanent_breakpoint (void)
212 The program is stopped at a permanent breakpoint, but GDB does not know\n\
213 how to step past a permanent breakpoint on this architecture. Try using\n\
214 a command like `return' or `jump' to continue execution.");
219 /* Convert the #defines into values. This is temporary until wfi control
220 flow is completely sorted out. */
222 #ifndef HAVE_STEPPABLE_WATCHPOINT
223 #define HAVE_STEPPABLE_WATCHPOINT 0
225 #undef HAVE_STEPPABLE_WATCHPOINT
226 #define HAVE_STEPPABLE_WATCHPOINT 1
229 #ifndef CANNOT_STEP_HW_WATCHPOINTS
230 #define CANNOT_STEP_HW_WATCHPOINTS 0
232 #undef CANNOT_STEP_HW_WATCHPOINTS
233 #define CANNOT_STEP_HW_WATCHPOINTS 1
236 /* Tables of how to react to signals; the user sets them. */
238 static unsigned char *signal_stop
;
239 static unsigned char *signal_print
;
240 static unsigned char *signal_program
;
242 #define SET_SIGS(nsigs,sigs,flags) \
244 int signum = (nsigs); \
245 while (signum-- > 0) \
246 if ((sigs)[signum]) \
247 (flags)[signum] = 1; \
250 #define UNSET_SIGS(nsigs,sigs,flags) \
252 int signum = (nsigs); \
253 while (signum-- > 0) \
254 if ((sigs)[signum]) \
255 (flags)[signum] = 0; \
258 /* Value to pass to target_resume() to cause all threads to resume */
260 #define RESUME_ALL (pid_to_ptid (-1))
262 /* Command list pointer for the "stop" placeholder. */
264 static struct cmd_list_element
*stop_command
;
266 /* Nonzero if breakpoints are now inserted in the inferior. */
268 static int breakpoints_inserted
;
270 /* Function inferior was in as of last step command. */
272 static struct symbol
*step_start_function
;
274 /* Nonzero if we are expecting a trace trap and should proceed from it. */
276 static int trap_expected
;
279 /* Nonzero if we want to give control to the user when we're notified
280 of shared library events by the dynamic linker. */
281 static int stop_on_solib_events
;
285 /* Nonzero if the next time we try to continue the inferior, it will
286 step one instruction and generate a spurious trace trap.
287 This is used to compensate for a bug in HP-UX. */
289 static int trap_expected_after_continue
;
292 /* Nonzero means expecting a trace trap
293 and should stop the inferior and return silently when it happens. */
297 /* Nonzero means expecting a trap and caller will handle it themselves.
298 It is used after attach, due to attaching to a process;
299 when running in the shell before the child program has been exec'd;
300 and when running some kinds of remote stuff (FIXME?). */
302 int stop_soon_quietly
;
304 /* Nonzero if proceed is being used for a "finish" command or a similar
305 situation when stop_registers should be saved. */
307 int proceed_to_finish
;
309 /* Save register contents here when about to pop a stack dummy frame,
310 if-and-only-if proceed_to_finish is set.
311 Thus this contains the return value from the called function (assuming
312 values are returned in a register). */
314 struct regcache
*stop_registers
;
316 /* Nonzero if program stopped due to error trying to insert breakpoints. */
318 static int breakpoints_failed
;
320 /* Nonzero after stop if current stack frame should be printed. */
322 static int stop_print_frame
;
324 static struct breakpoint
*step_resume_breakpoint
= NULL
;
325 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
327 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
328 interactions with an inferior that is running a kernel function
329 (aka, a system call or "syscall"). wait_for_inferior therefore
330 may have a need to know when the inferior is in a syscall. This
331 is a count of the number of inferior threads which are known to
332 currently be running in a syscall. */
333 static int number_of_threads_in_syscalls
;
335 /* This is a cached copy of the pid/waitstatus of the last event
336 returned by target_wait()/target_wait_hook(). This information is
337 returned by get_last_target_status(). */
338 static ptid_t target_last_wait_ptid
;
339 static struct target_waitstatus target_last_waitstatus
;
341 /* This is used to remember when a fork, vfork or exec event
342 was caught by a catchpoint, and thus the event is to be
343 followed at the next resume of the inferior, and not
347 enum target_waitkind kind
;
354 char *execd_pathname
;
358 static const char follow_fork_mode_ask
[] = "ask";
359 static const char follow_fork_mode_child
[] = "child";
360 static const char follow_fork_mode_parent
[] = "parent";
362 static const char *follow_fork_mode_kind_names
[] = {
363 follow_fork_mode_ask
,
364 follow_fork_mode_child
,
365 follow_fork_mode_parent
,
369 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
375 const char *follow_mode
= follow_fork_mode_string
;
376 int follow_child
= (follow_mode
== follow_fork_mode_child
);
378 /* Or, did the user not know, and want us to ask? */
379 if (follow_fork_mode_string
== follow_fork_mode_ask
)
381 internal_error (__FILE__
, __LINE__
,
382 "follow_inferior_fork: \"ask\" mode not implemented");
383 /* follow_mode = follow_fork_mode_...; */
386 return target_follow_fork (follow_child
);
390 follow_inferior_reset_breakpoints (void)
392 /* Was there a step_resume breakpoint? (There was if the user
393 did a "next" at the fork() call.) If so, explicitly reset its
396 step_resumes are a form of bp that are made to be per-thread.
397 Since we created the step_resume bp when the parent process
398 was being debugged, and now are switching to the child process,
399 from the breakpoint package's viewpoint, that's a switch of
400 "threads". We must update the bp's notion of which thread
401 it is for, or it'll be ignored when it triggers. */
403 if (step_resume_breakpoint
)
404 breakpoint_re_set_thread (step_resume_breakpoint
);
406 /* Reinsert all breakpoints in the child. The user may have set
407 breakpoints after catching the fork, in which case those
408 were never set in the child, but only in the parent. This makes
409 sure the inserted breakpoints match the breakpoint list. */
411 breakpoint_re_set ();
412 insert_breakpoints ();
415 /* EXECD_PATHNAME is assumed to be non-NULL. */
418 follow_exec (int pid
, char *execd_pathname
)
421 struct target_ops
*tgt
;
423 if (!may_follow_exec
)
426 /* This is an exec event that we actually wish to pay attention to.
427 Refresh our symbol table to the newly exec'd program, remove any
430 If there are breakpoints, they aren't really inserted now,
431 since the exec() transformed our inferior into a fresh set
434 We want to preserve symbolic breakpoints on the list, since
435 we have hopes that they can be reset after the new a.out's
436 symbol table is read.
438 However, any "raw" breakpoints must be removed from the list
439 (e.g., the solib bp's), since their address is probably invalid
442 And, we DON'T want to call delete_breakpoints() here, since
443 that may write the bp's "shadow contents" (the instruction
444 value that was overwritten witha TRAP instruction). Since
445 we now have a new a.out, those shadow contents aren't valid. */
446 update_breakpoints_after_exec ();
448 /* If there was one, it's gone now. We cannot truly step-to-next
449 statement through an exec(). */
450 step_resume_breakpoint
= NULL
;
451 step_range_start
= 0;
454 /* If there was one, it's gone now. */
455 through_sigtramp_breakpoint
= NULL
;
457 /* What is this a.out's name? */
458 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
460 /* We've followed the inferior through an exec. Therefore, the
461 inferior has essentially been killed & reborn. */
463 /* First collect the run target in effect. */
464 tgt
= find_run_target ();
465 /* If we can't find one, things are in a very strange state... */
467 error ("Could find run target to save before following exec");
469 gdb_flush (gdb_stdout
);
470 target_mourn_inferior ();
471 inferior_ptid
= pid_to_ptid (saved_pid
);
472 /* Because mourn_inferior resets inferior_ptid. */
475 /* That a.out is now the one to use. */
476 exec_file_attach (execd_pathname
, 0);
478 /* And also is where symbols can be found. */
479 symbol_file_add_main (execd_pathname
, 0);
481 /* Reset the shared library package. This ensures that we get
482 a shlib event when the child reaches "_start", at which point
483 the dld will have had a chance to initialize the child. */
484 #if defined(SOLIB_RESTART)
487 #ifdef SOLIB_CREATE_INFERIOR_HOOK
488 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
491 /* Reinsert all breakpoints. (Those which were symbolic have
492 been reset to the proper address in the new a.out, thanks
493 to symbol_file_command...) */
494 insert_breakpoints ();
496 /* The next resume of this inferior should bring it to the shlib
497 startup breakpoints. (If the user had also set bp's on
498 "main" from the old (parent) process, then they'll auto-
499 matically get reset there in the new process.) */
502 /* Non-zero if we just simulating a single-step. This is needed
503 because we cannot remove the breakpoints in the inferior process
504 until after the `wait' in `wait_for_inferior'. */
505 static int singlestep_breakpoints_inserted_p
= 0;
508 /* Things to clean up if we QUIT out of resume (). */
511 resume_cleanups (void *ignore
)
516 static const char schedlock_off
[] = "off";
517 static const char schedlock_on
[] = "on";
518 static const char schedlock_step
[] = "step";
519 static const char *scheduler_mode
= schedlock_off
;
520 static const char *scheduler_enums
[] = {
528 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
530 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
531 the set command passed as a parameter. The clone operation will
532 include (BUG?) any ``set'' command callback, if present.
533 Commands like ``info set'' call all the ``show'' command
534 callbacks. Unfortunatly, for ``show'' commands cloned from
535 ``set'', this includes callbacks belonging to ``set'' commands.
536 Making this worse, this only occures if add_show_from_set() is
537 called after add_cmd_sfunc() (BUG?). */
538 if (cmd_type (c
) == set_cmd
)
539 if (!target_can_lock_scheduler
)
541 scheduler_mode
= schedlock_off
;
542 error ("Target '%s' cannot support this command.", target_shortname
);
547 /* Resume the inferior, but allow a QUIT. This is useful if the user
548 wants to interrupt some lengthy single-stepping operation
549 (for child processes, the SIGINT goes to the inferior, and so
550 we get a SIGINT random_signal, but for remote debugging and perhaps
551 other targets, that's not true).
553 STEP nonzero if we should step (zero to continue instead).
554 SIG is the signal to give the inferior (zero for none). */
556 resume (int step
, enum target_signal sig
)
558 int should_resume
= 1;
559 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
562 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
565 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
566 over an instruction that causes a page fault without triggering
567 a hardware watchpoint. The kernel properly notices that it shouldn't
568 stop, because the hardware watchpoint is not triggered, but it forgets
569 the step request and continues the program normally.
570 Work around the problem by removing hardware watchpoints if a step is
571 requested, GDB will check for a hardware watchpoint trigger after the
573 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
574 remove_hw_watchpoints ();
577 /* Normally, by the time we reach `resume', the breakpoints are either
578 removed or inserted, as appropriate. The exception is if we're sitting
579 at a permanent breakpoint; we need to step over it, but permanent
580 breakpoints can't be removed. So we have to test for it here. */
581 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
582 SKIP_PERMANENT_BREAKPOINT ();
584 if (SOFTWARE_SINGLE_STEP_P () && step
)
586 /* Do it the hard way, w/temp breakpoints */
587 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
588 /* ...and don't ask hardware to do it. */
590 /* and do not pull these breakpoints until after a `wait' in
591 `wait_for_inferior' */
592 singlestep_breakpoints_inserted_p
= 1;
595 /* Handle any optimized stores to the inferior NOW... */
596 #ifdef DO_DEFERRED_STORES
600 /* If there were any forks/vforks/execs that were caught and are
601 now to be followed, then do so. */
602 switch (pending_follow
.kind
)
604 case TARGET_WAITKIND_FORKED
:
605 case TARGET_WAITKIND_VFORKED
:
606 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
611 case TARGET_WAITKIND_EXECD
:
612 /* follow_exec is called as soon as the exec event is seen. */
613 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
620 /* Install inferior's terminal modes. */
621 target_terminal_inferior ();
627 resume_ptid
= RESUME_ALL
; /* Default */
629 if ((step
|| singlestep_breakpoints_inserted_p
) &&
630 !breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
632 /* Stepping past a breakpoint without inserting breakpoints.
633 Make sure only the current thread gets to step, so that
634 other threads don't sneak past breakpoints while they are
637 resume_ptid
= inferior_ptid
;
640 if ((scheduler_mode
== schedlock_on
) ||
641 (scheduler_mode
== schedlock_step
&&
642 (step
|| singlestep_breakpoints_inserted_p
)))
644 /* User-settable 'scheduler' mode requires solo thread resume. */
645 resume_ptid
= inferior_ptid
;
648 if (CANNOT_STEP_BREAKPOINT
)
650 /* Most targets can step a breakpoint instruction, thus
651 executing it normally. But if this one cannot, just
652 continue and we will hit it anyway. */
653 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
656 target_resume (resume_ptid
, step
, sig
);
659 discard_cleanups (old_cleanups
);
663 /* Clear out all variables saying what to do when inferior is continued.
664 First do this, then set the ones you want, then call `proceed'. */
667 clear_proceed_status (void)
670 step_range_start
= 0;
672 step_frame_id
= null_frame_id
;
673 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
675 stop_soon_quietly
= 0;
676 proceed_to_finish
= 0;
677 breakpoint_proceeded
= 1; /* We're about to proceed... */
679 /* Discard any remaining commands or status from previous stop. */
680 bpstat_clear (&stop_bpstat
);
683 /* Basic routine for continuing the program in various fashions.
685 ADDR is the address to resume at, or -1 for resume where stopped.
686 SIGGNAL is the signal to give it, or 0 for none,
687 or -1 for act according to how it stopped.
688 STEP is nonzero if should trap after one instruction.
689 -1 means return after that and print nothing.
690 You should probably set various step_... variables
691 before calling here, if you are stepping.
693 You should call clear_proceed_status before calling proceed. */
696 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
701 step_start_function
= find_pc_function (read_pc ());
705 if (addr
== (CORE_ADDR
) -1)
707 /* If there is a breakpoint at the address we will resume at,
708 step one instruction before inserting breakpoints
709 so that we do not stop right away (and report a second
710 hit at this breakpoint). */
712 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
715 #ifndef STEP_SKIPS_DELAY
716 #define STEP_SKIPS_DELAY(pc) (0)
717 #define STEP_SKIPS_DELAY_P (0)
719 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
720 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
721 is slow (it needs to read memory from the target). */
722 if (STEP_SKIPS_DELAY_P
723 && breakpoint_here_p (read_pc () + 4)
724 && STEP_SKIPS_DELAY (read_pc ()))
732 #ifdef PREPARE_TO_PROCEED
733 /* In a multi-threaded task we may select another thread
734 and then continue or step.
736 But if the old thread was stopped at a breakpoint, it
737 will immediately cause another breakpoint stop without
738 any execution (i.e. it will report a breakpoint hit
739 incorrectly). So we must step over it first.
741 PREPARE_TO_PROCEED checks the current thread against the thread
742 that reported the most recent event. If a step-over is required
743 it returns TRUE and sets the current thread to the old thread. */
744 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
749 #endif /* PREPARE_TO_PROCEED */
752 if (trap_expected_after_continue
)
754 /* If (step == 0), a trap will be automatically generated after
755 the first instruction is executed. Force step one
756 instruction to clear this condition. This should not occur
757 if step is nonzero, but it is harmless in that case. */
759 trap_expected_after_continue
= 0;
761 #endif /* HP_OS_BUG */
764 /* We will get a trace trap after one instruction.
765 Continue it automatically and insert breakpoints then. */
769 insert_breakpoints ();
770 /* If we get here there was no call to error() in
771 insert breakpoints -- so they were inserted. */
772 breakpoints_inserted
= 1;
775 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
776 stop_signal
= siggnal
;
777 /* If this signal should not be seen by program,
778 give it zero. Used for debugging signals. */
779 else if (!signal_program
[stop_signal
])
780 stop_signal
= TARGET_SIGNAL_0
;
782 annotate_starting ();
784 /* Make sure that output from GDB appears before output from the
786 gdb_flush (gdb_stdout
);
788 /* Resume inferior. */
789 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
791 /* Wait for it to stop (if not standalone)
792 and in any case decode why it stopped, and act accordingly. */
793 /* Do this only if we are not using the event loop, or if the target
794 does not support asynchronous execution. */
795 if (!event_loop_p
|| !target_can_async_p ())
797 wait_for_inferior ();
802 /* Record the pc and sp of the program the last time it stopped.
803 These are just used internally by wait_for_inferior, but need
804 to be preserved over calls to it and cleared when the inferior
806 static CORE_ADDR prev_pc
;
807 static CORE_ADDR prev_func_start
;
808 static char *prev_func_name
;
811 /* Start remote-debugging of a machine over a serial link. */
817 init_wait_for_inferior ();
818 stop_soon_quietly
= 1;
821 /* Always go on waiting for the target, regardless of the mode. */
822 /* FIXME: cagney/1999-09-23: At present it isn't possible to
823 indicate to wait_for_inferior that a target should timeout if
824 nothing is returned (instead of just blocking). Because of this,
825 targets expecting an immediate response need to, internally, set
826 things up so that the target_wait() is forced to eventually
828 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
829 differentiate to its caller what the state of the target is after
830 the initial open has been performed. Here we're assuming that
831 the target has stopped. It should be possible to eventually have
832 target_open() return to the caller an indication that the target
833 is currently running and GDB state should be set to the same as
835 wait_for_inferior ();
839 /* Initialize static vars when a new inferior begins. */
842 init_wait_for_inferior (void)
844 /* These are meaningless until the first time through wait_for_inferior. */
847 prev_func_name
= NULL
;
850 trap_expected_after_continue
= 0;
852 breakpoints_inserted
= 0;
853 breakpoint_init_inferior (inf_starting
);
855 /* Don't confuse first call to proceed(). */
856 stop_signal
= TARGET_SIGNAL_0
;
858 /* The first resume is not following a fork/vfork/exec. */
859 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
861 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
862 number_of_threads_in_syscalls
= 0;
864 clear_proceed_status ();
868 delete_breakpoint_current_contents (void *arg
)
870 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
871 if (*breakpointp
!= NULL
)
873 delete_breakpoint (*breakpointp
);
878 /* This enum encodes possible reasons for doing a target_wait, so that
879 wfi can call target_wait in one place. (Ultimately the call will be
880 moved out of the infinite loop entirely.) */
884 infwait_normal_state
,
885 infwait_thread_hop_state
,
886 infwait_nullified_state
,
887 infwait_nonstep_watch_state
890 /* Why did the inferior stop? Used to print the appropriate messages
891 to the interface from within handle_inferior_event(). */
892 enum inferior_stop_reason
894 /* We don't know why. */
896 /* Step, next, nexti, stepi finished. */
898 /* Found breakpoint. */
900 /* Inferior terminated by signal. */
902 /* Inferior exited. */
904 /* Inferior received signal, and user asked to be notified. */
908 /* This structure contains what used to be local variables in
909 wait_for_inferior. Probably many of them can return to being
910 locals in handle_inferior_event. */
912 struct execution_control_state
914 struct target_waitstatus ws
;
915 struct target_waitstatus
*wp
;
918 CORE_ADDR stop_func_start
;
919 CORE_ADDR stop_func_end
;
920 char *stop_func_name
;
921 struct symtab_and_line sal
;
922 int remove_breakpoints_on_following_step
;
924 struct symtab
*current_symtab
;
925 int handling_longjmp
; /* FIXME */
927 ptid_t saved_inferior_ptid
;
929 int stepping_through_solib_after_catch
;
930 bpstat stepping_through_solib_catchpoints
;
931 int enable_hw_watchpoints_after_wait
;
932 int stepping_through_sigtramp
;
933 int new_thread_event
;
934 struct target_waitstatus tmpstatus
;
935 enum infwait_states infwait_state
;
940 void init_execution_control_state (struct execution_control_state
*ecs
);
942 void handle_inferior_event (struct execution_control_state
*ecs
);
944 static void check_sigtramp2 (struct execution_control_state
*ecs
);
945 static void step_into_function (struct execution_control_state
*ecs
);
946 static void step_over_function (struct execution_control_state
*ecs
);
947 static void stop_stepping (struct execution_control_state
*ecs
);
948 static void prepare_to_wait (struct execution_control_state
*ecs
);
949 static void keep_going (struct execution_control_state
*ecs
);
950 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
953 /* Wait for control to return from inferior to debugger.
954 If inferior gets a signal, we may decide to start it up again
955 instead of returning. That is why there is a loop in this function.
956 When this function actually returns it means the inferior
957 should be left stopped and GDB should read more commands. */
960 wait_for_inferior (void)
962 struct cleanup
*old_cleanups
;
963 struct execution_control_state ecss
;
964 struct execution_control_state
*ecs
;
966 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
967 &step_resume_breakpoint
);
968 make_cleanup (delete_breakpoint_current_contents
,
969 &through_sigtramp_breakpoint
);
971 /* wfi still stays in a loop, so it's OK just to take the address of
972 a local to get the ecs pointer. */
975 /* Fill in with reasonable starting values. */
976 init_execution_control_state (ecs
);
978 /* We'll update this if & when we switch to a new thread. */
979 previous_inferior_ptid
= inferior_ptid
;
981 overlay_cache_invalid
= 1;
983 /* We have to invalidate the registers BEFORE calling target_wait
984 because they can be loaded from the target while in target_wait.
985 This makes remote debugging a bit more efficient for those
986 targets that provide critical registers as part of their normal
989 registers_changed ();
993 if (target_wait_hook
)
994 ecs
->ptid
= target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
996 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
998 /* Now figure out what to do with the result of the result. */
999 handle_inferior_event (ecs
);
1001 if (!ecs
->wait_some_more
)
1004 do_cleanups (old_cleanups
);
1007 /* Asynchronous version of wait_for_inferior. It is called by the
1008 event loop whenever a change of state is detected on the file
1009 descriptor corresponding to the target. It can be called more than
1010 once to complete a single execution command. In such cases we need
1011 to keep the state in a global variable ASYNC_ECSS. If it is the
1012 last time that this function is called for a single execution
1013 command, then report to the user that the inferior has stopped, and
1014 do the necessary cleanups. */
1016 struct execution_control_state async_ecss
;
1017 struct execution_control_state
*async_ecs
;
1020 fetch_inferior_event (void *client_data
)
1022 static struct cleanup
*old_cleanups
;
1024 async_ecs
= &async_ecss
;
1026 if (!async_ecs
->wait_some_more
)
1028 old_cleanups
= make_exec_cleanup (delete_step_resume_breakpoint
,
1029 &step_resume_breakpoint
);
1030 make_exec_cleanup (delete_breakpoint_current_contents
,
1031 &through_sigtramp_breakpoint
);
1033 /* Fill in with reasonable starting values. */
1034 init_execution_control_state (async_ecs
);
1036 /* We'll update this if & when we switch to a new thread. */
1037 previous_inferior_ptid
= inferior_ptid
;
1039 overlay_cache_invalid
= 1;
1041 /* We have to invalidate the registers BEFORE calling target_wait
1042 because they can be loaded from the target while in target_wait.
1043 This makes remote debugging a bit more efficient for those
1044 targets that provide critical registers as part of their normal
1045 status mechanism. */
1047 registers_changed ();
1050 if (target_wait_hook
)
1052 target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1054 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1056 /* Now figure out what to do with the result of the result. */
1057 handle_inferior_event (async_ecs
);
1059 if (!async_ecs
->wait_some_more
)
1061 /* Do only the cleanups that have been added by this
1062 function. Let the continuations for the commands do the rest,
1063 if there are any. */
1064 do_exec_cleanups (old_cleanups
);
1066 if (step_multi
&& stop_step
)
1067 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1069 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1073 /* Prepare an execution control state for looping through a
1074 wait_for_inferior-type loop. */
1077 init_execution_control_state (struct execution_control_state
*ecs
)
1079 /* ecs->another_trap? */
1080 ecs
->random_signal
= 0;
1081 ecs
->remove_breakpoints_on_following_step
= 0;
1082 ecs
->handling_longjmp
= 0; /* FIXME */
1083 ecs
->update_step_sp
= 0;
1084 ecs
->stepping_through_solib_after_catch
= 0;
1085 ecs
->stepping_through_solib_catchpoints
= NULL
;
1086 ecs
->enable_hw_watchpoints_after_wait
= 0;
1087 ecs
->stepping_through_sigtramp
= 0;
1088 ecs
->sal
= find_pc_line (prev_pc
, 0);
1089 ecs
->current_line
= ecs
->sal
.line
;
1090 ecs
->current_symtab
= ecs
->sal
.symtab
;
1091 ecs
->infwait_state
= infwait_normal_state
;
1092 ecs
->waiton_ptid
= pid_to_ptid (-1);
1093 ecs
->wp
= &(ecs
->ws
);
1096 /* Call this function before setting step_resume_breakpoint, as a
1097 sanity check. There should never be more than one step-resume
1098 breakpoint per thread, so we should never be setting a new
1099 step_resume_breakpoint when one is already active. */
1101 check_for_old_step_resume_breakpoint (void)
1103 if (step_resume_breakpoint
)
1105 ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1108 /* Return the cached copy of the last pid/waitstatus returned by
1109 target_wait()/target_wait_hook(). The data is actually cached by
1110 handle_inferior_event(), which gets called immediately after
1111 target_wait()/target_wait_hook(). */
1114 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
1116 *ptidp
= target_last_wait_ptid
;
1117 *status
= target_last_waitstatus
;
1120 /* Switch thread contexts, maintaining "infrun state". */
1123 context_switch (struct execution_control_state
*ecs
)
1125 /* Caution: it may happen that the new thread (or the old one!)
1126 is not in the thread list. In this case we must not attempt
1127 to "switch context", or we run the risk that our context may
1128 be lost. This may happen as a result of the target module
1129 mishandling thread creation. */
1131 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1132 { /* Perform infrun state context switch: */
1133 /* Save infrun state for the old thread. */
1134 save_infrun_state (inferior_ptid
, prev_pc
,
1135 prev_func_start
, prev_func_name
,
1136 trap_expected
, step_resume_breakpoint
,
1137 through_sigtramp_breakpoint
, step_range_start
,
1138 step_range_end
, &step_frame_id
,
1139 ecs
->handling_longjmp
, ecs
->another_trap
,
1140 ecs
->stepping_through_solib_after_catch
,
1141 ecs
->stepping_through_solib_catchpoints
,
1142 ecs
->stepping_through_sigtramp
,
1143 ecs
->current_line
, ecs
->current_symtab
, step_sp
);
1145 /* Load infrun state for the new thread. */
1146 load_infrun_state (ecs
->ptid
, &prev_pc
,
1147 &prev_func_start
, &prev_func_name
,
1148 &trap_expected
, &step_resume_breakpoint
,
1149 &through_sigtramp_breakpoint
, &step_range_start
,
1150 &step_range_end
, &step_frame_id
,
1151 &ecs
->handling_longjmp
, &ecs
->another_trap
,
1152 &ecs
->stepping_through_solib_after_catch
,
1153 &ecs
->stepping_through_solib_catchpoints
,
1154 &ecs
->stepping_through_sigtramp
,
1155 &ecs
->current_line
, &ecs
->current_symtab
, &step_sp
);
1157 inferior_ptid
= ecs
->ptid
;
1161 /* Given an execution control state that has been freshly filled in
1162 by an event from the inferior, figure out what it means and take
1163 appropriate action. */
1166 handle_inferior_event (struct execution_control_state
*ecs
)
1168 CORE_ADDR real_stop_pc
;
1169 int stepped_after_stopped_by_watchpoint
;
1170 int sw_single_step_trap_p
= 0;
1172 /* Cache the last pid/waitstatus. */
1173 target_last_wait_ptid
= ecs
->ptid
;
1174 target_last_waitstatus
= *ecs
->wp
;
1176 switch (ecs
->infwait_state
)
1178 case infwait_thread_hop_state
:
1179 /* Cancel the waiton_ptid. */
1180 ecs
->waiton_ptid
= pid_to_ptid (-1);
1181 /* Fall thru to the normal_state case. */
1183 case infwait_normal_state
:
1184 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1185 is serviced in this loop, below. */
1186 if (ecs
->enable_hw_watchpoints_after_wait
)
1188 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1189 ecs
->enable_hw_watchpoints_after_wait
= 0;
1191 stepped_after_stopped_by_watchpoint
= 0;
1194 case infwait_nullified_state
:
1197 case infwait_nonstep_watch_state
:
1198 insert_breakpoints ();
1200 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1201 handle things like signals arriving and other things happening
1202 in combination correctly? */
1203 stepped_after_stopped_by_watchpoint
= 1;
1206 ecs
->infwait_state
= infwait_normal_state
;
1208 flush_cached_frames ();
1210 /* If it's a new process, add it to the thread database */
1212 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
1213 && !in_thread_list (ecs
->ptid
));
1215 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1216 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
1218 add_thread (ecs
->ptid
);
1220 ui_out_text (uiout
, "[New ");
1221 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->ptid
));
1222 ui_out_text (uiout
, "]\n");
1225 /* NOTE: This block is ONLY meant to be invoked in case of a
1226 "thread creation event"! If it is invoked for any other
1227 sort of event (such as a new thread landing on a breakpoint),
1228 the event will be discarded, which is almost certainly
1231 To avoid this, the low-level module (eg. target_wait)
1232 should call in_thread_list and add_thread, so that the
1233 new thread is known by the time we get here. */
1235 /* We may want to consider not doing a resume here in order
1236 to give the user a chance to play with the new thread.
1237 It might be good to make that a user-settable option. */
1239 /* At this point, all threads are stopped (happens
1240 automatically in either the OS or the native code).
1241 Therefore we need to continue all threads in order to
1244 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1245 prepare_to_wait (ecs
);
1250 switch (ecs
->ws
.kind
)
1252 case TARGET_WAITKIND_LOADED
:
1253 /* Ignore gracefully during startup of the inferior, as it
1254 might be the shell which has just loaded some objects,
1255 otherwise add the symbols for the newly loaded objects. */
1257 if (!stop_soon_quietly
)
1259 /* Remove breakpoints, SOLIB_ADD might adjust
1260 breakpoint addresses via breakpoint_re_set. */
1261 if (breakpoints_inserted
)
1262 remove_breakpoints ();
1264 /* Check for any newly added shared libraries if we're
1265 supposed to be adding them automatically. Switch
1266 terminal for any messages produced by
1267 breakpoint_re_set. */
1268 target_terminal_ours_for_output ();
1269 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
1270 target_terminal_inferior ();
1272 /* Reinsert breakpoints and continue. */
1273 if (breakpoints_inserted
)
1274 insert_breakpoints ();
1277 resume (0, TARGET_SIGNAL_0
);
1278 prepare_to_wait (ecs
);
1281 case TARGET_WAITKIND_SPURIOUS
:
1282 resume (0, TARGET_SIGNAL_0
);
1283 prepare_to_wait (ecs
);
1286 case TARGET_WAITKIND_EXITED
:
1287 target_terminal_ours (); /* Must do this before mourn anyway */
1288 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1290 /* Record the exit code in the convenience variable $_exitcode, so
1291 that the user can inspect this again later. */
1292 set_internalvar (lookup_internalvar ("_exitcode"),
1293 value_from_longest (builtin_type_int
,
1294 (LONGEST
) ecs
->ws
.value
.integer
));
1295 gdb_flush (gdb_stdout
);
1296 target_mourn_inferior ();
1297 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1298 stop_print_frame
= 0;
1299 stop_stepping (ecs
);
1302 case TARGET_WAITKIND_SIGNALLED
:
1303 stop_print_frame
= 0;
1304 stop_signal
= ecs
->ws
.value
.sig
;
1305 target_terminal_ours (); /* Must do this before mourn anyway */
1307 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1308 reach here unless the inferior is dead. However, for years
1309 target_kill() was called here, which hints that fatal signals aren't
1310 really fatal on some systems. If that's true, then some changes
1312 target_mourn_inferior ();
1314 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1315 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1316 stop_stepping (ecs
);
1319 /* The following are the only cases in which we keep going;
1320 the above cases end in a continue or goto. */
1321 case TARGET_WAITKIND_FORKED
:
1322 case TARGET_WAITKIND_VFORKED
:
1323 stop_signal
= TARGET_SIGNAL_TRAP
;
1324 pending_follow
.kind
= ecs
->ws
.kind
;
1326 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1327 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1329 stop_pc
= read_pc ();
1331 /* Assume that catchpoints are not really software breakpoints. If
1332 some future target implements them using software breakpoints then
1333 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1334 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1335 bpstat_stop_status will not decrement the PC. */
1337 stop_bpstat
= bpstat_stop_status (&stop_pc
, 1);
1339 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1341 /* If no catchpoint triggered for this, then keep going. */
1342 if (ecs
->random_signal
)
1344 stop_signal
= TARGET_SIGNAL_0
;
1348 goto process_event_stop_test
;
1350 case TARGET_WAITKIND_EXECD
:
1351 stop_signal
= TARGET_SIGNAL_TRAP
;
1353 /* NOTE drow/2002-12-05: This code should be pushed down into the
1354 target_wait function. Until then following vfork on HP/UX 10.20
1355 is probably broken by this. Of course, it's broken anyway. */
1356 /* Is this a target which reports multiple exec events per actual
1357 call to exec()? (HP-UX using ptrace does, for example.) If so,
1358 ignore all but the last one. Just resume the exec'r, and wait
1359 for the next exec event. */
1360 if (inferior_ignoring_leading_exec_events
)
1362 inferior_ignoring_leading_exec_events
--;
1363 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1364 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.
1366 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1367 prepare_to_wait (ecs
);
1370 inferior_ignoring_leading_exec_events
=
1371 target_reported_exec_events_per_exec_call () - 1;
1373 pending_follow
.execd_pathname
=
1374 savestring (ecs
->ws
.value
.execd_pathname
,
1375 strlen (ecs
->ws
.value
.execd_pathname
));
1377 /* This causes the eventpoints and symbol table to be reset. Must
1378 do this now, before trying to determine whether to stop. */
1379 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1380 xfree (pending_follow
.execd_pathname
);
1382 stop_pc
= read_pc_pid (ecs
->ptid
);
1383 ecs
->saved_inferior_ptid
= inferior_ptid
;
1384 inferior_ptid
= ecs
->ptid
;
1386 /* Assume that catchpoints are not really software breakpoints. If
1387 some future target implements them using software breakpoints then
1388 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1389 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1390 bpstat_stop_status will not decrement the PC. */
1392 stop_bpstat
= bpstat_stop_status (&stop_pc
, 1);
1394 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1395 inferior_ptid
= ecs
->saved_inferior_ptid
;
1397 /* If no catchpoint triggered for this, then keep going. */
1398 if (ecs
->random_signal
)
1400 stop_signal
= TARGET_SIGNAL_0
;
1404 goto process_event_stop_test
;
1406 /* These syscall events are returned on HP-UX, as part of its
1407 implementation of page-protection-based "hardware" watchpoints.
1408 HP-UX has unfortunate interactions between page-protections and
1409 some system calls. Our solution is to disable hardware watches
1410 when a system call is entered, and reenable them when the syscall
1411 completes. The downside of this is that we may miss the precise
1412 point at which a watched piece of memory is modified. "Oh well."
1414 Note that we may have multiple threads running, which may each
1415 enter syscalls at roughly the same time. Since we don't have a
1416 good notion currently of whether a watched piece of memory is
1417 thread-private, we'd best not have any page-protections active
1418 when any thread is in a syscall. Thus, we only want to reenable
1419 hardware watches when no threads are in a syscall.
1421 Also, be careful not to try to gather much state about a thread
1422 that's in a syscall. It's frequently a losing proposition. */
1423 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1424 number_of_threads_in_syscalls
++;
1425 if (number_of_threads_in_syscalls
== 1)
1427 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1429 resume (0, TARGET_SIGNAL_0
);
1430 prepare_to_wait (ecs
);
1433 /* Before examining the threads further, step this thread to
1434 get it entirely out of the syscall. (We get notice of the
1435 event when the thread is just on the verge of exiting a
1436 syscall. Stepping one instruction seems to get it back
1439 Note that although the logical place to reenable h/w watches
1440 is here, we cannot. We cannot reenable them before stepping
1441 the thread (this causes the next wait on the thread to hang).
1443 Nor can we enable them after stepping until we've done a wait.
1444 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1445 here, which will be serviced immediately after the target
1447 case TARGET_WAITKIND_SYSCALL_RETURN
:
1448 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1450 if (number_of_threads_in_syscalls
> 0)
1452 number_of_threads_in_syscalls
--;
1453 ecs
->enable_hw_watchpoints_after_wait
=
1454 (number_of_threads_in_syscalls
== 0);
1456 prepare_to_wait (ecs
);
1459 case TARGET_WAITKIND_STOPPED
:
1460 stop_signal
= ecs
->ws
.value
.sig
;
1463 /* We had an event in the inferior, but we are not interested
1464 in handling it at this level. The lower layers have already
1465 done what needs to be done, if anything.
1467 One of the possible circumstances for this is when the
1468 inferior produces output for the console. The inferior has
1469 not stopped, and we are ignoring the event. Another possible
1470 circumstance is any event which the lower level knows will be
1471 reported multiple times without an intervening resume. */
1472 case TARGET_WAITKIND_IGNORE
:
1473 prepare_to_wait (ecs
);
1477 /* We may want to consider not doing a resume here in order to give
1478 the user a chance to play with the new thread. It might be good
1479 to make that a user-settable option. */
1481 /* At this point, all threads are stopped (happens automatically in
1482 either the OS or the native code). Therefore we need to continue
1483 all threads in order to make progress. */
1484 if (ecs
->new_thread_event
)
1486 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1487 prepare_to_wait (ecs
);
1491 stop_pc
= read_pc_pid (ecs
->ptid
);
1493 /* See if a thread hit a thread-specific breakpoint that was meant for
1494 another thread. If so, then step that thread past the breakpoint,
1497 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1499 /* Check if a regular breakpoint has been hit before checking
1500 for a potential single step breakpoint. Otherwise, GDB will
1501 not see this breakpoint hit when stepping onto breakpoints. */
1502 if (breakpoints_inserted
1503 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1505 ecs
->random_signal
= 0;
1506 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1511 /* Saw a breakpoint, but it was hit by the wrong thread.
1513 if (DECR_PC_AFTER_BREAK
)
1514 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->ptid
);
1516 remove_status
= remove_breakpoints ();
1517 /* Did we fail to remove breakpoints? If so, try
1518 to set the PC past the bp. (There's at least
1519 one situation in which we can fail to remove
1520 the bp's: On HP-UX's that use ttrace, we can't
1521 change the address space of a vforking child
1522 process until the child exits (well, okay, not
1523 then either :-) or execs. */
1524 if (remove_status
!= 0)
1526 /* FIXME! This is obviously non-portable! */
1527 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->ptid
);
1528 /* We need to restart all the threads now,
1529 * unles we're running in scheduler-locked mode.
1530 * Use currently_stepping to determine whether to
1533 /* FIXME MVS: is there any reason not to call resume()? */
1534 if (scheduler_mode
== schedlock_on
)
1535 target_resume (ecs
->ptid
,
1536 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1538 target_resume (RESUME_ALL
,
1539 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1540 prepare_to_wait (ecs
);
1545 breakpoints_inserted
= 0;
1546 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
1547 context_switch (ecs
);
1548 ecs
->waiton_ptid
= ecs
->ptid
;
1549 ecs
->wp
= &(ecs
->ws
);
1550 ecs
->another_trap
= 1;
1552 ecs
->infwait_state
= infwait_thread_hop_state
;
1554 registers_changed ();
1559 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1561 /* Readjust the stop_pc as it is off by DECR_PC_AFTER_BREAK
1562 compared to the value it would have if the system stepping
1563 capability was used. This allows the rest of the code in
1564 this function to use this address without having to worry
1565 whether software single step is in use or not. */
1566 if (DECR_PC_AFTER_BREAK
)
1568 stop_pc
-= DECR_PC_AFTER_BREAK
;
1569 write_pc_pid (stop_pc
, ecs
->ptid
);
1572 sw_single_step_trap_p
= 1;
1573 ecs
->random_signal
= 0;
1577 ecs
->random_signal
= 1;
1579 /* See if something interesting happened to the non-current thread. If
1580 so, then switch to that thread, and eventually give control back to
1583 Note that if there's any kind of pending follow (i.e., of a fork,
1584 vfork or exec), we don't want to do this now. Rather, we'll let
1585 the next resume handle it. */
1586 if (!ptid_equal (ecs
->ptid
, inferior_ptid
) &&
1587 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1591 /* If it's a random signal for a non-current thread, notify user
1592 if he's expressed an interest. */
1593 if (ecs
->random_signal
&& signal_print
[stop_signal
])
1595 /* ??rehrauer: I don't understand the rationale for this code. If the
1596 inferior will stop as a result of this signal, then the act of handling
1597 the stop ought to print a message that's couches the stoppage in user
1598 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1599 won't stop as a result of the signal -- i.e., if the signal is merely
1600 a side-effect of something GDB's doing "under the covers" for the
1601 user, such as stepping threads over a breakpoint they shouldn't stop
1602 for -- then the message seems to be a serious annoyance at best.
1604 For now, remove the message altogether. */
1607 target_terminal_ours_for_output ();
1608 printf_filtered ("\nProgram received signal %s, %s.\n",
1609 target_signal_to_name (stop_signal
),
1610 target_signal_to_string (stop_signal
));
1611 gdb_flush (gdb_stdout
);
1615 /* If it's not SIGTRAP and not a signal we want to stop for, then
1616 continue the thread. */
1618 if (stop_signal
!= TARGET_SIGNAL_TRAP
&& !signal_stop
[stop_signal
])
1621 target_terminal_inferior ();
1623 /* Clear the signal if it should not be passed. */
1624 if (signal_program
[stop_signal
] == 0)
1625 stop_signal
= TARGET_SIGNAL_0
;
1627 target_resume (ecs
->ptid
, 0, stop_signal
);
1628 prepare_to_wait (ecs
);
1632 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1633 and fall into the rest of wait_for_inferior(). */
1635 context_switch (ecs
);
1638 context_hook (pid_to_thread_id (ecs
->ptid
));
1640 flush_cached_frames ();
1643 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1645 /* Pull the single step breakpoints out of the target. */
1646 SOFTWARE_SINGLE_STEP (0, 0);
1647 singlestep_breakpoints_inserted_p
= 0;
1650 /* If PC is pointing at a nullified instruction, then step beyond
1651 it so that the user won't be confused when GDB appears to be ready
1654 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1655 if (INSTRUCTION_NULLIFIED
)
1657 registers_changed ();
1658 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1660 /* We may have received a signal that we want to pass to
1661 the inferior; therefore, we must not clobber the waitstatus
1664 ecs
->infwait_state
= infwait_nullified_state
;
1665 ecs
->waiton_ptid
= ecs
->ptid
;
1666 ecs
->wp
= &(ecs
->tmpstatus
);
1667 prepare_to_wait (ecs
);
1671 /* It may not be necessary to disable the watchpoint to stop over
1672 it. For example, the PA can (with some kernel cooperation)
1673 single step over a watchpoint without disabling the watchpoint. */
1674 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1677 prepare_to_wait (ecs
);
1681 /* It is far more common to need to disable a watchpoint to step
1682 the inferior over it. FIXME. What else might a debug
1683 register or page protection watchpoint scheme need here? */
1684 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1686 /* At this point, we are stopped at an instruction which has
1687 attempted to write to a piece of memory under control of
1688 a watchpoint. The instruction hasn't actually executed
1689 yet. If we were to evaluate the watchpoint expression
1690 now, we would get the old value, and therefore no change
1691 would seem to have occurred.
1693 In order to make watchpoints work `right', we really need
1694 to complete the memory write, and then evaluate the
1695 watchpoint expression. The following code does that by
1696 removing the watchpoint (actually, all watchpoints and
1697 breakpoints), single-stepping the target, re-inserting
1698 watchpoints, and then falling through to let normal
1699 single-step processing handle proceed. Since this
1700 includes evaluating watchpoints, things will come to a
1701 stop in the correct manner. */
1703 if (DECR_PC_AFTER_BREAK
)
1704 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
1706 remove_breakpoints ();
1707 registers_changed ();
1708 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
1710 ecs
->waiton_ptid
= ecs
->ptid
;
1711 ecs
->wp
= &(ecs
->ws
);
1712 ecs
->infwait_state
= infwait_nonstep_watch_state
;
1713 prepare_to_wait (ecs
);
1717 /* It may be possible to simply continue after a watchpoint. */
1718 if (HAVE_CONTINUABLE_WATCHPOINT
)
1719 STOPPED_BY_WATCHPOINT (ecs
->ws
);
1721 ecs
->stop_func_start
= 0;
1722 ecs
->stop_func_end
= 0;
1723 ecs
->stop_func_name
= 0;
1724 /* Don't care about return value; stop_func_start and stop_func_name
1725 will both be 0 if it doesn't work. */
1726 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
1727 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
1728 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
1729 ecs
->another_trap
= 0;
1730 bpstat_clear (&stop_bpstat
);
1732 stop_stack_dummy
= 0;
1733 stop_print_frame
= 1;
1734 ecs
->random_signal
= 0;
1735 stopped_by_random_signal
= 0;
1736 breakpoints_failed
= 0;
1738 /* Look at the cause of the stop, and decide what to do.
1739 The alternatives are:
1740 1) break; to really stop and return to the debugger,
1741 2) drop through to start up again
1742 (set ecs->another_trap to 1 to single step once)
1743 3) set ecs->random_signal to 1, and the decision between 1 and 2
1744 will be made according to the signal handling tables. */
1746 /* First, distinguish signals caused by the debugger from signals
1747 that have to do with the program's own actions.
1748 Note that breakpoint insns may cause SIGTRAP or SIGILL
1749 or SIGEMT, depending on the operating system version.
1750 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1751 and change it to SIGTRAP. */
1753 if (stop_signal
== TARGET_SIGNAL_TRAP
1754 || (breakpoints_inserted
&&
1755 (stop_signal
== TARGET_SIGNAL_ILL
1756 || stop_signal
== TARGET_SIGNAL_EMT
)) || stop_soon_quietly
)
1758 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
1760 stop_print_frame
= 0;
1761 stop_stepping (ecs
);
1764 if (stop_soon_quietly
)
1766 stop_stepping (ecs
);
1770 /* Don't even think about breakpoints
1771 if just proceeded over a breakpoint.
1773 However, if we are trying to proceed over a breakpoint
1774 and end up in sigtramp, then through_sigtramp_breakpoint
1775 will be set and we should check whether we've hit the
1777 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
1778 && through_sigtramp_breakpoint
== NULL
)
1779 bpstat_clear (&stop_bpstat
);
1782 /* See if there is a breakpoint at the current PC. */
1784 /* The second argument of bpstat_stop_status is meant to help
1785 distinguish between a breakpoint trap and a singlestep trap.
1786 This is only important on targets where DECR_PC_AFTER_BREAK
1787 is non-zero. The prev_pc test is meant to distinguish between
1788 singlestepping a trap instruction, and singlestepping thru a
1789 jump to the instruction following a trap instruction.
1791 Therefore, pass TRUE if our reason for stopping is
1792 something other than hitting a breakpoint. We do this by
1793 checking that either: we detected earlier a software single
1794 step trap or, 1) stepping is going on and 2) we didn't hit
1795 a breakpoint in a signal handler without an intervening stop
1796 in sigtramp, which is detected by a new stack pointer value
1797 below any usual function calling stack adjustments. */
1801 sw_single_step_trap_p
1802 || (currently_stepping (ecs
)
1803 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1805 && INNER_THAN (read_sp (), (step_sp
- 16)))));
1806 /* Following in case break condition called a
1808 stop_print_frame
= 1;
1811 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1813 = !(bpstat_explains_signal (stop_bpstat
)
1815 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
1816 && DEPRECATED_PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
1817 get_frame_base (get_current_frame ())))
1818 || (step_range_end
&& step_resume_breakpoint
== NULL
));
1822 ecs
->random_signal
= !(bpstat_explains_signal (stop_bpstat
)
1823 /* End of a stack dummy. Some systems (e.g. Sony
1824 news) give another signal besides SIGTRAP, so
1825 check here as well as above. */
1826 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
1827 && DEPRECATED_PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
1831 if (!ecs
->random_signal
)
1832 stop_signal
= TARGET_SIGNAL_TRAP
;
1836 /* When we reach this point, we've pretty much decided
1837 that the reason for stopping must've been a random
1838 (unexpected) signal. */
1841 ecs
->random_signal
= 1;
1843 process_event_stop_test
:
1844 /* For the program's own signals, act according to
1845 the signal handling tables. */
1847 if (ecs
->random_signal
)
1849 /* Signal not for debugging purposes. */
1852 stopped_by_random_signal
= 1;
1854 if (signal_print
[stop_signal
])
1857 target_terminal_ours_for_output ();
1858 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
1860 if (signal_stop
[stop_signal
])
1862 stop_stepping (ecs
);
1865 /* If not going to stop, give terminal back
1866 if we took it away. */
1868 target_terminal_inferior ();
1870 /* Clear the signal if it should not be passed. */
1871 if (signal_program
[stop_signal
] == 0)
1872 stop_signal
= TARGET_SIGNAL_0
;
1874 /* I'm not sure whether this needs to be check_sigtramp2 or
1875 whether it could/should be keep_going.
1877 This used to jump to step_over_function if we are stepping,
1880 Suppose the user does a `next' over a function call, and while
1881 that call is in progress, the inferior receives a signal for
1882 which GDB does not stop (i.e., signal_stop[SIG] is false). In
1883 that case, when we reach this point, there is already a
1884 step-resume breakpoint established, right where it should be:
1885 immediately after the function call the user is "next"-ing
1886 over. If we call step_over_function now, two bad things
1889 - we'll create a new breakpoint, at wherever the current
1890 frame's return address happens to be. That could be
1891 anywhere, depending on what function call happens to be on
1892 the top of the stack at that point. Point is, it's probably
1893 not where we need it.
1895 - the existing step-resume breakpoint (which is at the correct
1896 address) will get orphaned: step_resume_breakpoint will point
1897 to the new breakpoint, and the old step-resume breakpoint
1898 will never be cleaned up.
1900 The old behavior was meant to help HP-UX single-step out of
1901 sigtramps. It would place the new breakpoint at prev_pc, which
1902 was certainly wrong. I don't know the details there, so fixing
1903 this probably breaks that. As with anything else, it's up to
1904 the HP-UX maintainer to furnish a fix that doesn't break other
1905 platforms. --JimB, 20 May 1999 */
1906 check_sigtramp2 (ecs
);
1911 /* Handle cases caused by hitting a breakpoint. */
1913 CORE_ADDR jmp_buf_pc
;
1914 struct bpstat_what what
;
1916 what
= bpstat_what (stop_bpstat
);
1918 if (what
.call_dummy
)
1920 stop_stack_dummy
= 1;
1922 trap_expected_after_continue
= 1;
1926 switch (what
.main_action
)
1928 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
1929 /* If we hit the breakpoint at longjmp, disable it for the
1930 duration of this command. Then, install a temporary
1931 breakpoint at the target of the jmp_buf. */
1932 disable_longjmp_breakpoint ();
1933 remove_breakpoints ();
1934 breakpoints_inserted
= 0;
1935 if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc
))
1941 /* Need to blow away step-resume breakpoint, as it
1942 interferes with us */
1943 if (step_resume_breakpoint
!= NULL
)
1945 delete_step_resume_breakpoint (&step_resume_breakpoint
);
1947 /* Not sure whether we need to blow this away too, but probably
1948 it is like the step-resume breakpoint. */
1949 if (through_sigtramp_breakpoint
!= NULL
)
1951 delete_breakpoint (through_sigtramp_breakpoint
);
1952 through_sigtramp_breakpoint
= NULL
;
1956 /* FIXME - Need to implement nested temporary breakpoints */
1957 if (step_over_calls
> 0)
1958 set_longjmp_resume_breakpoint (jmp_buf_pc
, get_current_frame ());
1961 set_longjmp_resume_breakpoint (jmp_buf_pc
, null_frame_id
);
1962 ecs
->handling_longjmp
= 1; /* FIXME */
1966 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
1967 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
1968 remove_breakpoints ();
1969 breakpoints_inserted
= 0;
1971 /* FIXME - Need to implement nested temporary breakpoints */
1973 && (frame_id_inner (get_frame_id (get_current_frame ()),
1976 ecs
->another_trap
= 1;
1981 disable_longjmp_breakpoint ();
1982 ecs
->handling_longjmp
= 0; /* FIXME */
1983 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
1985 /* else fallthrough */
1987 case BPSTAT_WHAT_SINGLE
:
1988 if (breakpoints_inserted
)
1990 remove_breakpoints ();
1992 breakpoints_inserted
= 0;
1993 ecs
->another_trap
= 1;
1994 /* Still need to check other stuff, at least the case
1995 where we are stepping and step out of the right range. */
1998 case BPSTAT_WHAT_STOP_NOISY
:
1999 stop_print_frame
= 1;
2001 /* We are about to nuke the step_resume_breakpoint and
2002 through_sigtramp_breakpoint via the cleanup chain, so
2003 no need to worry about it here. */
2005 stop_stepping (ecs
);
2008 case BPSTAT_WHAT_STOP_SILENT
:
2009 stop_print_frame
= 0;
2011 /* We are about to nuke the step_resume_breakpoint and
2012 through_sigtramp_breakpoint via the cleanup chain, so
2013 no need to worry about it here. */
2015 stop_stepping (ecs
);
2018 case BPSTAT_WHAT_STEP_RESUME
:
2019 /* This proably demands a more elegant solution, but, yeah
2022 This function's use of the simple variable
2023 step_resume_breakpoint doesn't seem to accomodate
2024 simultaneously active step-resume bp's, although the
2025 breakpoint list certainly can.
2027 If we reach here and step_resume_breakpoint is already
2028 NULL, then apparently we have multiple active
2029 step-resume bp's. We'll just delete the breakpoint we
2030 stopped at, and carry on.
2032 Correction: what the code currently does is delete a
2033 step-resume bp, but it makes no effort to ensure that
2034 the one deleted is the one currently stopped at. MVS */
2036 if (step_resume_breakpoint
== NULL
)
2038 step_resume_breakpoint
=
2039 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2041 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2044 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2045 if (through_sigtramp_breakpoint
)
2046 delete_breakpoint (through_sigtramp_breakpoint
);
2047 through_sigtramp_breakpoint
= NULL
;
2049 /* If were waiting for a trap, hitting the step_resume_break
2050 doesn't count as getting it. */
2052 ecs
->another_trap
= 1;
2055 case BPSTAT_WHAT_CHECK_SHLIBS
:
2056 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2059 /* Remove breakpoints, we eventually want to step over the
2060 shlib event breakpoint, and SOLIB_ADD might adjust
2061 breakpoint addresses via breakpoint_re_set. */
2062 if (breakpoints_inserted
)
2063 remove_breakpoints ();
2064 breakpoints_inserted
= 0;
2066 /* Check for any newly added shared libraries if we're
2067 supposed to be adding them automatically. Switch
2068 terminal for any messages produced by
2069 breakpoint_re_set. */
2070 target_terminal_ours_for_output ();
2071 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
2072 target_terminal_inferior ();
2074 /* Try to reenable shared library breakpoints, additional
2075 code segments in shared libraries might be mapped in now. */
2076 re_enable_breakpoints_in_shlibs ();
2078 /* If requested, stop when the dynamic linker notifies
2079 gdb of events. This allows the user to get control
2080 and place breakpoints in initializer routines for
2081 dynamically loaded objects (among other things). */
2082 if (stop_on_solib_events
)
2084 stop_stepping (ecs
);
2088 /* If we stopped due to an explicit catchpoint, then the
2089 (see above) call to SOLIB_ADD pulled in any symbols
2090 from a newly-loaded library, if appropriate.
2092 We do want the inferior to stop, but not where it is
2093 now, which is in the dynamic linker callback. Rather,
2094 we would like it stop in the user's program, just after
2095 the call that caused this catchpoint to trigger. That
2096 gives the user a more useful vantage from which to
2097 examine their program's state. */
2098 else if (what
.main_action
==
2099 BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2101 /* ??rehrauer: If I could figure out how to get the
2102 right return PC from here, we could just set a temp
2103 breakpoint and resume. I'm not sure we can without
2104 cracking open the dld's shared libraries and sniffing
2105 their unwind tables and text/data ranges, and that's
2106 not a terribly portable notion.
2108 Until that time, we must step the inferior out of the
2109 dld callback, and also out of the dld itself (and any
2110 code or stubs in libdld.sl, such as "shl_load" and
2111 friends) until we reach non-dld code. At that point,
2112 we can stop stepping. */
2113 bpstat_get_triggered_catchpoints (stop_bpstat
,
2115 stepping_through_solib_catchpoints
);
2116 ecs
->stepping_through_solib_after_catch
= 1;
2118 /* Be sure to lift all breakpoints, so the inferior does
2119 actually step past this point... */
2120 ecs
->another_trap
= 1;
2125 /* We want to step over this breakpoint, then keep going. */
2126 ecs
->another_trap
= 1;
2133 case BPSTAT_WHAT_LAST
:
2134 /* Not a real code, but listed here to shut up gcc -Wall. */
2136 case BPSTAT_WHAT_KEEP_CHECKING
:
2141 /* We come here if we hit a breakpoint but should not
2142 stop for it. Possibly we also were stepping
2143 and should stop for that. So fall through and
2144 test for stepping. But, if not stepping,
2147 /* Are we stepping to get the inferior out of the dynamic
2148 linker's hook (and possibly the dld itself) after catching
2150 if (ecs
->stepping_through_solib_after_catch
)
2152 #if defined(SOLIB_ADD)
2153 /* Have we reached our destination? If not, keep going. */
2154 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2156 ecs
->another_trap
= 1;
2161 /* Else, stop and report the catchpoint(s) whose triggering
2162 caused us to begin stepping. */
2163 ecs
->stepping_through_solib_after_catch
= 0;
2164 bpstat_clear (&stop_bpstat
);
2165 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2166 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2167 stop_print_frame
= 1;
2168 stop_stepping (ecs
);
2172 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2174 /* This is the old way of detecting the end of the stack dummy.
2175 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2176 handled above. As soon as we can test it on all of them, all
2177 architectures should define it. */
2179 /* If this is the breakpoint at the end of a stack dummy,
2180 just stop silently, unless the user was doing an si/ni, in which
2181 case she'd better know what she's doing. */
2183 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2184 get_frame_base (get_current_frame ()))
2187 stop_print_frame
= 0;
2188 stop_stack_dummy
= 1;
2190 trap_expected_after_continue
= 1;
2192 stop_stepping (ecs
);
2197 if (step_resume_breakpoint
)
2199 /* Having a step-resume breakpoint overrides anything
2200 else having to do with stepping commands until
2201 that breakpoint is reached. */
2202 /* I'm not sure whether this needs to be check_sigtramp2 or
2203 whether it could/should be keep_going. */
2204 check_sigtramp2 (ecs
);
2209 if (step_range_end
== 0)
2211 /* Likewise if we aren't even stepping. */
2212 /* I'm not sure whether this needs to be check_sigtramp2 or
2213 whether it could/should be keep_going. */
2214 check_sigtramp2 (ecs
);
2219 /* If stepping through a line, keep going if still within it.
2221 Note that step_range_end is the address of the first instruction
2222 beyond the step range, and NOT the address of the last instruction
2224 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
2226 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2227 So definately need to check for sigtramp here. */
2228 check_sigtramp2 (ecs
);
2233 /* We stepped out of the stepping range. */
2235 /* If we are stepping at the source level and entered the runtime
2236 loader dynamic symbol resolution code, we keep on single stepping
2237 until we exit the run time loader code and reach the callee's
2239 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2240 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2242 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2244 if (pc_after_resolver
)
2246 /* Set up a step-resume breakpoint at the address
2247 indicated by SKIP_SOLIB_RESOLVER. */
2248 struct symtab_and_line sr_sal
;
2250 sr_sal
.pc
= pc_after_resolver
;
2252 check_for_old_step_resume_breakpoint ();
2253 step_resume_breakpoint
=
2254 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2255 if (breakpoints_inserted
)
2256 insert_breakpoints ();
2263 /* We can't update step_sp every time through the loop, because
2264 reading the stack pointer would slow down stepping too much.
2265 But we can update it every time we leave the step range. */
2266 ecs
->update_step_sp
= 1;
2268 /* Did we just take a signal? */
2269 if (PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2270 && !PC_IN_SIGTRAMP (prev_pc
, prev_func_name
)
2271 && INNER_THAN (read_sp (), step_sp
))
2273 /* We've just taken a signal; go until we are back to
2274 the point where we took it and one more. */
2276 /* Note: The test above succeeds not only when we stepped
2277 into a signal handler, but also when we step past the last
2278 statement of a signal handler and end up in the return stub
2279 of the signal handler trampoline. To distinguish between
2280 these two cases, check that the frame is INNER_THAN the
2281 previous one below. pai/1997-09-11 */
2285 struct frame_id current_frame
= get_frame_id (get_current_frame ());
2287 if (frame_id_inner (current_frame
, step_frame_id
))
2289 /* We have just taken a signal; go until we are back to
2290 the point where we took it and one more. */
2292 /* This code is needed at least in the following case:
2293 The user types "next" and then a signal arrives (before
2294 the "next" is done). */
2296 /* Note that if we are stopped at a breakpoint, then we need
2297 the step_resume breakpoint to override any breakpoints at
2298 the same location, so that we will still step over the
2299 breakpoint even though the signal happened. */
2300 struct symtab_and_line sr_sal
;
2303 sr_sal
.symtab
= NULL
;
2305 sr_sal
.pc
= prev_pc
;
2306 /* We could probably be setting the frame to
2307 step_frame_id; I don't think anyone thought to try it. */
2308 check_for_old_step_resume_breakpoint ();
2309 step_resume_breakpoint
=
2310 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2311 if (breakpoints_inserted
)
2312 insert_breakpoints ();
2316 /* We just stepped out of a signal handler and into
2317 its calling trampoline.
2319 Normally, we'd call step_over_function from
2320 here, but for some reason GDB can't unwind the
2321 stack correctly to find the real PC for the point
2322 user code where the signal trampoline will return
2323 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2324 But signal trampolines are pretty small stubs of
2325 code, anyway, so it's OK instead to just
2326 single-step out. Note: assuming such trampolines
2327 don't exhibit recursion on any platform... */
2328 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2329 &ecs
->stop_func_start
,
2330 &ecs
->stop_func_end
);
2331 /* Readjust stepping range */
2332 step_range_start
= ecs
->stop_func_start
;
2333 step_range_end
= ecs
->stop_func_end
;
2334 ecs
->stepping_through_sigtramp
= 1;
2339 /* If this is stepi or nexti, make sure that the stepping range
2340 gets us past that instruction. */
2341 if (step_range_end
== 1)
2342 /* FIXME: Does this run afoul of the code below which, if
2343 we step into the middle of a line, resets the stepping
2345 step_range_end
= (step_range_start
= prev_pc
) + 1;
2347 ecs
->remove_breakpoints_on_following_step
= 1;
2352 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2353 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2354 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2355 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2356 || ecs
->stop_func_name
== 0)
2358 /* It's a subroutine call. */
2360 if ((step_over_calls
== STEP_OVER_NONE
)
2361 || ((step_range_end
== 1)
2362 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2364 /* I presume that step_over_calls is only 0 when we're
2365 supposed to be stepping at the assembly language level
2366 ("stepi"). Just stop. */
2367 /* Also, maybe we just did a "nexti" inside a prolog,
2368 so we thought it was a subroutine call but it was not.
2369 Stop as well. FENN */
2371 print_stop_reason (END_STEPPING_RANGE
, 0);
2372 stop_stepping (ecs
);
2376 if (step_over_calls
== STEP_OVER_ALL
|| IGNORE_HELPER_CALL (stop_pc
))
2378 /* We're doing a "next". */
2380 if (PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2381 && frame_id_inner (step_frame_id
,
2382 frame_id_build (read_sp (), 0)))
2383 /* We stepped out of a signal handler, and into its
2384 calling trampoline. This is misdetected as a
2385 subroutine call, but stepping over the signal
2386 trampoline isn't such a bad idea. In order to do that,
2387 we have to ignore the value in step_frame_id, since
2388 that doesn't represent the frame that'll reach when we
2389 return from the signal trampoline. Otherwise we'll
2390 probably continue to the end of the program. */
2391 step_frame_id
= null_frame_id
;
2393 step_over_function (ecs
);
2398 /* If we are in a function call trampoline (a stub between
2399 the calling routine and the real function), locate the real
2400 function. That's what tells us (a) whether we want to step
2401 into it at all, and (b) what prologue we want to run to
2402 the end of, if we do step into it. */
2403 real_stop_pc
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2404 if (real_stop_pc
!= 0)
2405 ecs
->stop_func_start
= real_stop_pc
;
2408 real_stop_pc
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2411 struct symtab_and_line xxx
;
2412 /* Why isn't this s_a_l called "sr_sal", like all of the
2413 other s_a_l's where this code is duplicated? */
2414 init_sal (&xxx
); /* initialize to zeroes */
2415 xxx
.pc
= real_stop_pc
;
2416 xxx
.section
= find_pc_overlay (xxx
.pc
);
2417 check_for_old_step_resume_breakpoint ();
2418 step_resume_breakpoint
=
2419 set_momentary_breakpoint (xxx
, null_frame_id
, bp_step_resume
);
2420 insert_breakpoints ();
2426 /* If we have line number information for the function we
2427 are thinking of stepping into, step into it.
2429 If there are several symtabs at that PC (e.g. with include
2430 files), just want to know whether *any* of them have line
2431 numbers. find_pc_line handles this. */
2433 struct symtab_and_line tmp_sal
;
2435 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2436 if (tmp_sal
.line
!= 0)
2438 step_into_function (ecs
);
2443 /* If we have no line number and the step-stop-if-no-debug
2444 is set, we stop the step so that the user has a chance to
2445 switch in assembly mode. */
2446 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2449 print_stop_reason (END_STEPPING_RANGE
, 0);
2450 stop_stepping (ecs
);
2454 step_over_function (ecs
);
2460 /* We've wandered out of the step range. */
2462 ecs
->sal
= find_pc_line (stop_pc
, 0);
2464 if (step_range_end
== 1)
2466 /* It is stepi or nexti. We always want to stop stepping after
2469 print_stop_reason (END_STEPPING_RANGE
, 0);
2470 stop_stepping (ecs
);
2474 /* If we're in the return path from a shared library trampoline,
2475 we want to proceed through the trampoline when stepping. */
2476 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2478 /* Determine where this trampoline returns. */
2479 real_stop_pc
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2481 /* Only proceed through if we know where it's going. */
2484 /* And put the step-breakpoint there and go until there. */
2485 struct symtab_and_line sr_sal
;
2487 init_sal (&sr_sal
); /* initialize to zeroes */
2488 sr_sal
.pc
= real_stop_pc
;
2489 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2490 /* Do not specify what the fp should be when we stop
2491 since on some machines the prologue
2492 is where the new fp value is established. */
2493 check_for_old_step_resume_breakpoint ();
2494 step_resume_breakpoint
=
2495 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2496 if (breakpoints_inserted
)
2497 insert_breakpoints ();
2499 /* Restart without fiddling with the step ranges or
2506 if (ecs
->sal
.line
== 0)
2508 /* We have no line number information. That means to stop
2509 stepping (does this always happen right after one instruction,
2510 when we do "s" in a function with no line numbers,
2511 or can this happen as a result of a return or longjmp?). */
2513 print_stop_reason (END_STEPPING_RANGE
, 0);
2514 stop_stepping (ecs
);
2518 if ((stop_pc
== ecs
->sal
.pc
)
2519 && (ecs
->current_line
!= ecs
->sal
.line
2520 || ecs
->current_symtab
!= ecs
->sal
.symtab
))
2522 /* We are at the start of a different line. So stop. Note that
2523 we don't stop if we step into the middle of a different line.
2524 That is said to make things like for (;;) statements work
2527 print_stop_reason (END_STEPPING_RANGE
, 0);
2528 stop_stepping (ecs
);
2532 /* We aren't done stepping.
2534 Optimize by setting the stepping range to the line.
2535 (We might not be in the original line, but if we entered a
2536 new line in mid-statement, we continue stepping. This makes
2537 things like for(;;) statements work better.) */
2539 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2541 /* If this is the last line of the function, don't keep stepping
2542 (it would probably step us out of the function).
2543 This is particularly necessary for a one-line function,
2544 in which after skipping the prologue we better stop even though
2545 we will be in mid-line. */
2547 print_stop_reason (END_STEPPING_RANGE
, 0);
2548 stop_stepping (ecs
);
2551 step_range_start
= ecs
->sal
.pc
;
2552 step_range_end
= ecs
->sal
.end
;
2553 step_frame_id
= get_frame_id (get_current_frame ());
2554 ecs
->current_line
= ecs
->sal
.line
;
2555 ecs
->current_symtab
= ecs
->sal
.symtab
;
2557 /* In the case where we just stepped out of a function into the
2558 middle of a line of the caller, continue stepping, but
2559 step_frame_id must be modified to current frame */
2561 struct frame_id current_frame
= get_frame_id (get_current_frame ());
2562 if (!(frame_id_inner (current_frame
, step_frame_id
)))
2563 step_frame_id
= current_frame
;
2569 /* Are we in the middle of stepping? */
2572 currently_stepping (struct execution_control_state
*ecs
)
2574 return ((through_sigtramp_breakpoint
== NULL
2575 && !ecs
->handling_longjmp
2576 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2578 || ecs
->stepping_through_solib_after_catch
2579 || bpstat_should_step ());
2583 check_sigtramp2 (struct execution_control_state
*ecs
)
2586 && PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2587 && !PC_IN_SIGTRAMP (prev_pc
, prev_func_name
)
2588 && INNER_THAN (read_sp (), step_sp
))
2590 /* What has happened here is that we have just stepped the
2591 inferior with a signal (because it is a signal which
2592 shouldn't make us stop), thus stepping into sigtramp.
2594 So we need to set a step_resume_break_address breakpoint and
2595 continue until we hit it, and then step. FIXME: This should
2596 be more enduring than a step_resume breakpoint; we should
2597 know that we will later need to keep going rather than
2598 re-hitting the breakpoint here (see the testsuite,
2599 gdb.base/signals.exp where it says "exceedingly difficult"). */
2601 struct symtab_and_line sr_sal
;
2603 init_sal (&sr_sal
); /* initialize to zeroes */
2604 sr_sal
.pc
= prev_pc
;
2605 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2606 /* We perhaps could set the frame if we kept track of what the
2607 frame corresponding to prev_pc was. But we don't, so don't. */
2608 through_sigtramp_breakpoint
=
2609 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_through_sigtramp
);
2610 if (breakpoints_inserted
)
2611 insert_breakpoints ();
2613 ecs
->remove_breakpoints_on_following_step
= 1;
2614 ecs
->another_trap
= 1;
2618 /* Subroutine call with source code we should not step over. Do step
2619 to the first line of code in it. */
2622 step_into_function (struct execution_control_state
*ecs
)
2625 struct symtab_and_line sr_sal
;
2627 s
= find_pc_symtab (stop_pc
);
2628 if (s
&& s
->language
!= language_asm
)
2629 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2631 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2632 /* Use the step_resume_break to step until the end of the prologue,
2633 even if that involves jumps (as it seems to on the vax under
2635 /* If the prologue ends in the middle of a source line, continue to
2636 the end of that source line (if it is still within the function).
2637 Otherwise, just go to end of prologue. */
2638 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2639 /* no, don't either. It skips any code that's legitimately on the
2643 && ecs
->sal
.pc
!= ecs
->stop_func_start
2644 && ecs
->sal
.end
< ecs
->stop_func_end
)
2645 ecs
->stop_func_start
= ecs
->sal
.end
;
2648 if (ecs
->stop_func_start
== stop_pc
)
2650 /* We are already there: stop now. */
2652 print_stop_reason (END_STEPPING_RANGE
, 0);
2653 stop_stepping (ecs
);
2658 /* Put the step-breakpoint there and go until there. */
2659 init_sal (&sr_sal
); /* initialize to zeroes */
2660 sr_sal
.pc
= ecs
->stop_func_start
;
2661 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
2662 /* Do not specify what the fp should be when we stop since on
2663 some machines the prologue is where the new fp value is
2665 check_for_old_step_resume_breakpoint ();
2666 step_resume_breakpoint
=
2667 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2668 if (breakpoints_inserted
)
2669 insert_breakpoints ();
2671 /* And make sure stepping stops right away then. */
2672 step_range_end
= step_range_start
;
2677 /* We've just entered a callee, and we wish to resume until it returns
2678 to the caller. Setting a step_resume breakpoint on the return
2679 address will catch a return from the callee.
2681 However, if the callee is recursing, we want to be careful not to
2682 catch returns of those recursive calls, but only of THIS instance
2685 To do this, we set the step_resume bp's frame to our current
2686 caller's frame (step_frame_id, which is set by the "next" or
2687 "until" command, before execution begins). */
2690 step_over_function (struct execution_control_state
*ecs
)
2692 struct symtab_and_line sr_sal
;
2694 init_sal (&sr_sal
); /* initialize to zeros */
2695 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2696 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2698 check_for_old_step_resume_breakpoint ();
2699 step_resume_breakpoint
=
2700 set_momentary_breakpoint (sr_sal
, get_frame_id (get_current_frame ()),
2703 if (frame_id_p (step_frame_id
)
2704 && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
2705 step_resume_breakpoint
->frame_id
= step_frame_id
;
2707 if (breakpoints_inserted
)
2708 insert_breakpoints ();
2712 stop_stepping (struct execution_control_state
*ecs
)
2714 if (target_has_execution
)
2716 /* Assuming the inferior still exists, set these up for next
2717 time, just like we did above if we didn't break out of the
2719 prev_pc
= read_pc ();
2720 prev_func_start
= ecs
->stop_func_start
;
2721 prev_func_name
= ecs
->stop_func_name
;
2724 /* Let callers know we don't want to wait for the inferior anymore. */
2725 ecs
->wait_some_more
= 0;
2728 /* This function handles various cases where we need to continue
2729 waiting for the inferior. */
2730 /* (Used to be the keep_going: label in the old wait_for_inferior) */
2733 keep_going (struct execution_control_state
*ecs
)
2735 /* Save the pc before execution, to compare with pc after stop. */
2736 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
2737 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
2738 BREAK is defined, the
2739 original pc would not have
2740 been at the start of a
2742 prev_func_name
= ecs
->stop_func_name
;
2744 if (ecs
->update_step_sp
)
2745 step_sp
= read_sp ();
2746 ecs
->update_step_sp
= 0;
2748 /* If we did not do break;, it means we should keep running the
2749 inferior and not return to debugger. */
2751 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
2753 /* We took a signal (which we are supposed to pass through to
2754 the inferior, else we'd have done a break above) and we
2755 haven't yet gotten our trap. Simply continue. */
2756 resume (currently_stepping (ecs
), stop_signal
);
2760 /* Either the trap was not expected, but we are continuing
2761 anyway (the user asked that this signal be passed to the
2764 The signal was SIGTRAP, e.g. it was our signal, but we
2765 decided we should resume from it.
2767 We're going to run this baby now!
2769 Insert breakpoints now, unless we are trying to one-proceed
2770 past a breakpoint. */
2771 /* If we've just finished a special step resume and we don't
2772 want to hit a breakpoint, pull em out. */
2773 if (step_resume_breakpoint
== NULL
2774 && through_sigtramp_breakpoint
== NULL
2775 && ecs
->remove_breakpoints_on_following_step
)
2777 ecs
->remove_breakpoints_on_following_step
= 0;
2778 remove_breakpoints ();
2779 breakpoints_inserted
= 0;
2781 else if (!breakpoints_inserted
&&
2782 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
2784 breakpoints_failed
= insert_breakpoints ();
2785 if (breakpoints_failed
)
2787 stop_stepping (ecs
);
2790 breakpoints_inserted
= 1;
2793 trap_expected
= ecs
->another_trap
;
2795 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
2796 specifies that such a signal should be delivered to the
2799 Typically, this would occure when a user is debugging a
2800 target monitor on a simulator: the target monitor sets a
2801 breakpoint; the simulator encounters this break-point and
2802 halts the simulation handing control to GDB; GDB, noteing
2803 that the break-point isn't valid, returns control back to the
2804 simulator; the simulator then delivers the hardware
2805 equivalent of a SIGNAL_TRAP to the program being debugged. */
2807 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !signal_program
[stop_signal
])
2808 stop_signal
= TARGET_SIGNAL_0
;
2810 #ifdef SHIFT_INST_REGS
2811 /* I'm not sure when this following segment applies. I do know,
2812 now, that we shouldn't rewrite the regs when we were stopped
2813 by a random signal from the inferior process. */
2814 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2815 (this is only used on the 88k). */
2817 if (!bpstat_explains_signal (stop_bpstat
)
2818 && (stop_signal
!= TARGET_SIGNAL_CHLD
) && !stopped_by_random_signal
)
2820 #endif /* SHIFT_INST_REGS */
2822 resume (currently_stepping (ecs
), stop_signal
);
2825 prepare_to_wait (ecs
);
2828 /* This function normally comes after a resume, before
2829 handle_inferior_event exits. It takes care of any last bits of
2830 housekeeping, and sets the all-important wait_some_more flag. */
2833 prepare_to_wait (struct execution_control_state
*ecs
)
2835 if (ecs
->infwait_state
== infwait_normal_state
)
2837 overlay_cache_invalid
= 1;
2839 /* We have to invalidate the registers BEFORE calling
2840 target_wait because they can be loaded from the target while
2841 in target_wait. This makes remote debugging a bit more
2842 efficient for those targets that provide critical registers
2843 as part of their normal status mechanism. */
2845 registers_changed ();
2846 ecs
->waiton_ptid
= pid_to_ptid (-1);
2847 ecs
->wp
= &(ecs
->ws
);
2849 /* This is the old end of the while loop. Let everybody know we
2850 want to wait for the inferior some more and get called again
2852 ecs
->wait_some_more
= 1;
2855 /* Print why the inferior has stopped. We always print something when
2856 the inferior exits, or receives a signal. The rest of the cases are
2857 dealt with later on in normal_stop() and print_it_typical(). Ideally
2858 there should be a call to this function from handle_inferior_event()
2859 each time stop_stepping() is called.*/
2861 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
2863 switch (stop_reason
)
2866 /* We don't deal with these cases from handle_inferior_event()
2869 case END_STEPPING_RANGE
:
2870 /* We are done with a step/next/si/ni command. */
2871 /* For now print nothing. */
2872 /* Print a message only if not in the middle of doing a "step n"
2873 operation for n > 1 */
2874 if (!step_multi
|| !stop_step
)
2875 if (ui_out_is_mi_like_p (uiout
))
2876 ui_out_field_string (uiout
, "reason", "end-stepping-range");
2878 case BREAKPOINT_HIT
:
2879 /* We found a breakpoint. */
2880 /* For now print nothing. */
2883 /* The inferior was terminated by a signal. */
2884 annotate_signalled ();
2885 if (ui_out_is_mi_like_p (uiout
))
2886 ui_out_field_string (uiout
, "reason", "exited-signalled");
2887 ui_out_text (uiout
, "\nProgram terminated with signal ");
2888 annotate_signal_name ();
2889 ui_out_field_string (uiout
, "signal-name",
2890 target_signal_to_name (stop_info
));
2891 annotate_signal_name_end ();
2892 ui_out_text (uiout
, ", ");
2893 annotate_signal_string ();
2894 ui_out_field_string (uiout
, "signal-meaning",
2895 target_signal_to_string (stop_info
));
2896 annotate_signal_string_end ();
2897 ui_out_text (uiout
, ".\n");
2898 ui_out_text (uiout
, "The program no longer exists.\n");
2901 /* The inferior program is finished. */
2902 annotate_exited (stop_info
);
2905 if (ui_out_is_mi_like_p (uiout
))
2906 ui_out_field_string (uiout
, "reason", "exited");
2907 ui_out_text (uiout
, "\nProgram exited with code ");
2908 ui_out_field_fmt (uiout
, "exit-code", "0%o",
2909 (unsigned int) stop_info
);
2910 ui_out_text (uiout
, ".\n");
2914 if (ui_out_is_mi_like_p (uiout
))
2915 ui_out_field_string (uiout
, "reason", "exited-normally");
2916 ui_out_text (uiout
, "\nProgram exited normally.\n");
2919 case SIGNAL_RECEIVED
:
2920 /* Signal received. The signal table tells us to print about
2923 ui_out_text (uiout
, "\nProgram received signal ");
2924 annotate_signal_name ();
2925 if (ui_out_is_mi_like_p (uiout
))
2926 ui_out_field_string (uiout
, "reason", "signal-received");
2927 ui_out_field_string (uiout
, "signal-name",
2928 target_signal_to_name (stop_info
));
2929 annotate_signal_name_end ();
2930 ui_out_text (uiout
, ", ");
2931 annotate_signal_string ();
2932 ui_out_field_string (uiout
, "signal-meaning",
2933 target_signal_to_string (stop_info
));
2934 annotate_signal_string_end ();
2935 ui_out_text (uiout
, ".\n");
2938 internal_error (__FILE__
, __LINE__
,
2939 "print_stop_reason: unrecognized enum value");
2945 /* Here to return control to GDB when the inferior stops for real.
2946 Print appropriate messages, remove breakpoints, give terminal our modes.
2948 STOP_PRINT_FRAME nonzero means print the executing frame
2949 (pc, function, args, file, line number and line text).
2950 BREAKPOINTS_FAILED nonzero means stop was due to error
2951 attempting to insert breakpoints. */
2956 /* As with the notification of thread events, we want to delay
2957 notifying the user that we've switched thread context until
2958 the inferior actually stops.
2960 (Note that there's no point in saying anything if the inferior
2962 if (!ptid_equal (previous_inferior_ptid
, inferior_ptid
)
2963 && target_has_execution
)
2965 target_terminal_ours_for_output ();
2966 printf_filtered ("[Switching to %s]\n",
2967 target_pid_or_tid_to_str (inferior_ptid
));
2968 previous_inferior_ptid
= inferior_ptid
;
2971 /* Make sure that the current_frame's pc is correct. This
2972 is a correction for setting up the frame info before doing
2973 DECR_PC_AFTER_BREAK */
2974 if (target_has_execution
)
2975 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
2976 DECR_PC_AFTER_BREAK, the program counter can change. Ask the
2977 frame code to check for this and sort out any resultant mess.
2978 DECR_PC_AFTER_BREAK needs to just go away. */
2979 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
2981 if (target_has_execution
&& breakpoints_inserted
)
2983 if (remove_breakpoints ())
2985 target_terminal_ours_for_output ();
2986 printf_filtered ("Cannot remove breakpoints because ");
2987 printf_filtered ("program is no longer writable.\n");
2988 printf_filtered ("It might be running in another process.\n");
2989 printf_filtered ("Further execution is probably impossible.\n");
2992 breakpoints_inserted
= 0;
2994 /* Delete the breakpoint we stopped at, if it wants to be deleted.
2995 Delete any breakpoint that is to be deleted at the next stop. */
2997 breakpoint_auto_delete (stop_bpstat
);
2999 /* If an auto-display called a function and that got a signal,
3000 delete that auto-display to avoid an infinite recursion. */
3002 if (stopped_by_random_signal
)
3003 disable_current_display ();
3005 /* Don't print a message if in the middle of doing a "step n"
3006 operation for n > 1 */
3007 if (step_multi
&& stop_step
)
3010 target_terminal_ours ();
3012 /* Look up the hook_stop and run it (CLI internally handles problem
3013 of stop_command's pre-hook not existing). */
3015 catch_errors (hook_stop_stub
, stop_command
,
3016 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3018 if (!target_has_stack
)
3024 /* Select innermost stack frame - i.e., current frame is frame 0,
3025 and current location is based on that.
3026 Don't do this on return from a stack dummy routine,
3027 or if the program has exited. */
3029 if (!stop_stack_dummy
)
3031 select_frame (get_current_frame ());
3033 /* Print current location without a level number, if
3034 we have changed functions or hit a breakpoint.
3035 Print source line if we have one.
3036 bpstat_print() contains the logic deciding in detail
3037 what to print, based on the event(s) that just occurred. */
3039 if (stop_print_frame
&& deprecated_selected_frame
)
3043 int do_frame_printing
= 1;
3045 bpstat_ret
= bpstat_print (stop_bpstat
);
3049 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3050 (or should) carry around the function and does (or
3051 should) use that when doing a frame comparison. */
3053 && frame_id_eq (step_frame_id
,
3054 get_frame_id (get_current_frame ()))
3055 && step_start_function
== find_pc_function (stop_pc
))
3056 source_flag
= SRC_LINE
; /* finished step, just print source line */
3058 source_flag
= SRC_AND_LOC
; /* print location and source line */
3060 case PRINT_SRC_AND_LOC
:
3061 source_flag
= SRC_AND_LOC
; /* print location and source line */
3063 case PRINT_SRC_ONLY
:
3064 source_flag
= SRC_LINE
;
3067 source_flag
= SRC_LINE
; /* something bogus */
3068 do_frame_printing
= 0;
3071 internal_error (__FILE__
, __LINE__
, "Unknown value.");
3073 /* For mi, have the same behavior every time we stop:
3074 print everything but the source line. */
3075 if (ui_out_is_mi_like_p (uiout
))
3076 source_flag
= LOC_AND_ADDRESS
;
3078 if (ui_out_is_mi_like_p (uiout
))
3079 ui_out_field_int (uiout
, "thread-id",
3080 pid_to_thread_id (inferior_ptid
));
3081 /* The behavior of this routine with respect to the source
3083 SRC_LINE: Print only source line
3084 LOCATION: Print only location
3085 SRC_AND_LOC: Print location and source line */
3086 if (do_frame_printing
)
3087 print_stack_frame (deprecated_selected_frame
, -1, source_flag
);
3089 /* Display the auto-display expressions. */
3094 /* Save the function value return registers, if we care.
3095 We might be about to restore their previous contents. */
3096 if (proceed_to_finish
)
3097 /* NB: The copy goes through to the target picking up the value of
3098 all the registers. */
3099 regcache_cpy (stop_registers
, current_regcache
);
3101 if (stop_stack_dummy
)
3103 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3104 ends with a setting of the current frame, so we can use that
3106 frame_pop (get_current_frame ());
3107 /* Set stop_pc to what it was before we called the function.
3108 Can't rely on restore_inferior_status because that only gets
3109 called if we don't stop in the called function. */
3110 stop_pc
= read_pc ();
3111 select_frame (get_current_frame ());
3115 annotate_stopped ();
3119 hook_stop_stub (void *cmd
)
3121 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3126 signal_stop_state (int signo
)
3128 return signal_stop
[signo
];
3132 signal_print_state (int signo
)
3134 return signal_print
[signo
];
3138 signal_pass_state (int signo
)
3140 return signal_program
[signo
];
3144 signal_stop_update (int signo
, int state
)
3146 int ret
= signal_stop
[signo
];
3147 signal_stop
[signo
] = state
;
3152 signal_print_update (int signo
, int state
)
3154 int ret
= signal_print
[signo
];
3155 signal_print
[signo
] = state
;
3160 signal_pass_update (int signo
, int state
)
3162 int ret
= signal_program
[signo
];
3163 signal_program
[signo
] = state
;
3168 sig_print_header (void)
3171 Signal Stop\tPrint\tPass to program\tDescription\n");
3175 sig_print_info (enum target_signal oursig
)
3177 char *name
= target_signal_to_name (oursig
);
3178 int name_padding
= 13 - strlen (name
);
3180 if (name_padding
<= 0)
3183 printf_filtered ("%s", name
);
3184 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
3185 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3186 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3187 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3188 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3191 /* Specify how various signals in the inferior should be handled. */
3194 handle_command (char *args
, int from_tty
)
3197 int digits
, wordlen
;
3198 int sigfirst
, signum
, siglast
;
3199 enum target_signal oursig
;
3202 unsigned char *sigs
;
3203 struct cleanup
*old_chain
;
3207 error_no_arg ("signal to handle");
3210 /* Allocate and zero an array of flags for which signals to handle. */
3212 nsigs
= (int) TARGET_SIGNAL_LAST
;
3213 sigs
= (unsigned char *) alloca (nsigs
);
3214 memset (sigs
, 0, nsigs
);
3216 /* Break the command line up into args. */
3218 argv
= buildargv (args
);
3223 old_chain
= make_cleanup_freeargv (argv
);
3225 /* Walk through the args, looking for signal oursigs, signal names, and
3226 actions. Signal numbers and signal names may be interspersed with
3227 actions, with the actions being performed for all signals cumulatively
3228 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3230 while (*argv
!= NULL
)
3232 wordlen
= strlen (*argv
);
3233 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3237 sigfirst
= siglast
= -1;
3239 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3241 /* Apply action to all signals except those used by the
3242 debugger. Silently skip those. */
3245 siglast
= nsigs
- 1;
3247 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3249 SET_SIGS (nsigs
, sigs
, signal_stop
);
3250 SET_SIGS (nsigs
, sigs
, signal_print
);
3252 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3254 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3256 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3258 SET_SIGS (nsigs
, sigs
, signal_print
);
3260 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3262 SET_SIGS (nsigs
, sigs
, signal_program
);
3264 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3266 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3268 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3270 SET_SIGS (nsigs
, sigs
, signal_program
);
3272 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3274 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3275 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3277 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3279 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3281 else if (digits
> 0)
3283 /* It is numeric. The numeric signal refers to our own
3284 internal signal numbering from target.h, not to host/target
3285 signal number. This is a feature; users really should be
3286 using symbolic names anyway, and the common ones like
3287 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3289 sigfirst
= siglast
= (int)
3290 target_signal_from_command (atoi (*argv
));
3291 if ((*argv
)[digits
] == '-')
3294 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3296 if (sigfirst
> siglast
)
3298 /* Bet he didn't figure we'd think of this case... */
3306 oursig
= target_signal_from_name (*argv
);
3307 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3309 sigfirst
= siglast
= (int) oursig
;
3313 /* Not a number and not a recognized flag word => complain. */
3314 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3318 /* If any signal numbers or symbol names were found, set flags for
3319 which signals to apply actions to. */
3321 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3323 switch ((enum target_signal
) signum
)
3325 case TARGET_SIGNAL_TRAP
:
3326 case TARGET_SIGNAL_INT
:
3327 if (!allsigs
&& !sigs
[signum
])
3329 if (query ("%s is used by the debugger.\n\
3330 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
3336 printf_unfiltered ("Not confirmed, unchanged.\n");
3337 gdb_flush (gdb_stdout
);
3341 case TARGET_SIGNAL_0
:
3342 case TARGET_SIGNAL_DEFAULT
:
3343 case TARGET_SIGNAL_UNKNOWN
:
3344 /* Make sure that "all" doesn't print these. */
3355 target_notice_signals (inferior_ptid
);
3359 /* Show the results. */
3360 sig_print_header ();
3361 for (signum
= 0; signum
< nsigs
; signum
++)
3365 sig_print_info (signum
);
3370 do_cleanups (old_chain
);
3374 xdb_handle_command (char *args
, int from_tty
)
3377 struct cleanup
*old_chain
;
3379 /* Break the command line up into args. */
3381 argv
= buildargv (args
);
3386 old_chain
= make_cleanup_freeargv (argv
);
3387 if (argv
[1] != (char *) NULL
)
3392 bufLen
= strlen (argv
[0]) + 20;
3393 argBuf
= (char *) xmalloc (bufLen
);
3397 enum target_signal oursig
;
3399 oursig
= target_signal_from_name (argv
[0]);
3400 memset (argBuf
, 0, bufLen
);
3401 if (strcmp (argv
[1], "Q") == 0)
3402 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3405 if (strcmp (argv
[1], "s") == 0)
3407 if (!signal_stop
[oursig
])
3408 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3410 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3412 else if (strcmp (argv
[1], "i") == 0)
3414 if (!signal_program
[oursig
])
3415 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3417 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3419 else if (strcmp (argv
[1], "r") == 0)
3421 if (!signal_print
[oursig
])
3422 sprintf (argBuf
, "%s %s", argv
[0], "print");
3424 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3430 handle_command (argBuf
, from_tty
);
3432 printf_filtered ("Invalid signal handling flag.\n");
3437 do_cleanups (old_chain
);
3440 /* Print current contents of the tables set by the handle command.
3441 It is possible we should just be printing signals actually used
3442 by the current target (but for things to work right when switching
3443 targets, all signals should be in the signal tables). */
3446 signals_info (char *signum_exp
, int from_tty
)
3448 enum target_signal oursig
;
3449 sig_print_header ();
3453 /* First see if this is a symbol name. */
3454 oursig
= target_signal_from_name (signum_exp
);
3455 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3457 /* No, try numeric. */
3459 target_signal_from_command (parse_and_eval_long (signum_exp
));
3461 sig_print_info (oursig
);
3465 printf_filtered ("\n");
3466 /* These ugly casts brought to you by the native VAX compiler. */
3467 for (oursig
= TARGET_SIGNAL_FIRST
;
3468 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3469 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3473 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3474 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
3475 sig_print_info (oursig
);
3478 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3481 struct inferior_status
3483 enum target_signal stop_signal
;
3487 int stop_stack_dummy
;
3488 int stopped_by_random_signal
;
3490 CORE_ADDR step_range_start
;
3491 CORE_ADDR step_range_end
;
3492 struct frame_id step_frame_id
;
3493 enum step_over_calls_kind step_over_calls
;
3494 CORE_ADDR step_resume_break_address
;
3495 int stop_after_trap
;
3496 int stop_soon_quietly
;
3497 struct regcache
*stop_registers
;
3499 /* These are here because if call_function_by_hand has written some
3500 registers and then decides to call error(), we better not have changed
3502 struct regcache
*registers
;
3504 /* A frame unique identifier. */
3505 struct frame_id selected_frame_id
;
3507 int breakpoint_proceeded
;
3508 int restore_stack_info
;
3509 int proceed_to_finish
;
3513 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3516 int size
= REGISTER_RAW_SIZE (regno
);
3517 void *buf
= alloca (size
);
3518 store_signed_integer (buf
, size
, val
);
3519 regcache_raw_write (inf_status
->registers
, regno
, buf
);
3522 /* Save all of the information associated with the inferior<==>gdb
3523 connection. INF_STATUS is a pointer to a "struct inferior_status"
3524 (defined in inferior.h). */
3526 struct inferior_status
*
3527 save_inferior_status (int restore_stack_info
)
3529 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
3531 inf_status
->stop_signal
= stop_signal
;
3532 inf_status
->stop_pc
= stop_pc
;
3533 inf_status
->stop_step
= stop_step
;
3534 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3535 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3536 inf_status
->trap_expected
= trap_expected
;
3537 inf_status
->step_range_start
= step_range_start
;
3538 inf_status
->step_range_end
= step_range_end
;
3539 inf_status
->step_frame_id
= step_frame_id
;
3540 inf_status
->step_over_calls
= step_over_calls
;
3541 inf_status
->stop_after_trap
= stop_after_trap
;
3542 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3543 /* Save original bpstat chain here; replace it with copy of chain.
3544 If caller's caller is walking the chain, they'll be happier if we
3545 hand them back the original chain when restore_inferior_status is
3547 inf_status
->stop_bpstat
= stop_bpstat
;
3548 stop_bpstat
= bpstat_copy (stop_bpstat
);
3549 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3550 inf_status
->restore_stack_info
= restore_stack_info
;
3551 inf_status
->proceed_to_finish
= proceed_to_finish
;
3553 inf_status
->stop_registers
= regcache_dup_no_passthrough (stop_registers
);
3555 inf_status
->registers
= regcache_dup (current_regcache
);
3557 inf_status
->selected_frame_id
= get_frame_id (deprecated_selected_frame
);
3562 restore_selected_frame (void *args
)
3564 struct frame_id
*fid
= (struct frame_id
*) args
;
3565 struct frame_info
*frame
;
3567 frame
= frame_find_by_id (*fid
);
3569 /* If inf_status->selected_frame_id is NULL, there was no previously
3573 warning ("Unable to restore previously selected frame.\n");
3577 select_frame (frame
);
3583 restore_inferior_status (struct inferior_status
*inf_status
)
3585 stop_signal
= inf_status
->stop_signal
;
3586 stop_pc
= inf_status
->stop_pc
;
3587 stop_step
= inf_status
->stop_step
;
3588 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3589 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3590 trap_expected
= inf_status
->trap_expected
;
3591 step_range_start
= inf_status
->step_range_start
;
3592 step_range_end
= inf_status
->step_range_end
;
3593 step_frame_id
= inf_status
->step_frame_id
;
3594 step_over_calls
= inf_status
->step_over_calls
;
3595 stop_after_trap
= inf_status
->stop_after_trap
;
3596 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
3597 bpstat_clear (&stop_bpstat
);
3598 stop_bpstat
= inf_status
->stop_bpstat
;
3599 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3600 proceed_to_finish
= inf_status
->proceed_to_finish
;
3602 /* FIXME: Is the restore of stop_registers always needed. */
3603 regcache_xfree (stop_registers
);
3604 stop_registers
= inf_status
->stop_registers
;
3606 /* The inferior can be gone if the user types "print exit(0)"
3607 (and perhaps other times). */
3608 if (target_has_execution
)
3609 /* NB: The register write goes through to the target. */
3610 regcache_cpy (current_regcache
, inf_status
->registers
);
3611 regcache_xfree (inf_status
->registers
);
3613 /* FIXME: If we are being called after stopping in a function which
3614 is called from gdb, we should not be trying to restore the
3615 selected frame; it just prints a spurious error message (The
3616 message is useful, however, in detecting bugs in gdb (like if gdb
3617 clobbers the stack)). In fact, should we be restoring the
3618 inferior status at all in that case? . */
3620 if (target_has_stack
&& inf_status
->restore_stack_info
)
3622 /* The point of catch_errors is that if the stack is clobbered,
3623 walking the stack might encounter a garbage pointer and
3624 error() trying to dereference it. */
3626 (restore_selected_frame
, &inf_status
->selected_frame_id
,
3627 "Unable to restore previously selected frame:\n",
3628 RETURN_MASK_ERROR
) == 0)
3629 /* Error in restoring the selected frame. Select the innermost
3631 select_frame (get_current_frame ());
3639 do_restore_inferior_status_cleanup (void *sts
)
3641 restore_inferior_status (sts
);
3645 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
3647 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
3651 discard_inferior_status (struct inferior_status
*inf_status
)
3653 /* See save_inferior_status for info on stop_bpstat. */
3654 bpstat_clear (&inf_status
->stop_bpstat
);
3655 regcache_xfree (inf_status
->registers
);
3656 regcache_xfree (inf_status
->stop_registers
);
3661 inferior_has_forked (int pid
, int *child_pid
)
3663 struct target_waitstatus last
;
3666 get_last_target_status (&last_ptid
, &last
);
3668 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
3671 if (ptid_get_pid (last_ptid
) != pid
)
3674 *child_pid
= last
.value
.related_pid
;
3679 inferior_has_vforked (int pid
, int *child_pid
)
3681 struct target_waitstatus last
;
3684 get_last_target_status (&last_ptid
, &last
);
3686 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
3689 if (ptid_get_pid (last_ptid
) != pid
)
3692 *child_pid
= last
.value
.related_pid
;
3697 inferior_has_execd (int pid
, char **execd_pathname
)
3699 struct target_waitstatus last
;
3702 get_last_target_status (&last_ptid
, &last
);
3704 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
3707 if (ptid_get_pid (last_ptid
) != pid
)
3710 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
3714 /* Oft used ptids */
3716 ptid_t minus_one_ptid
;
3718 /* Create a ptid given the necessary PID, LWP, and TID components. */
3721 ptid_build (int pid
, long lwp
, long tid
)
3731 /* Create a ptid from just a pid. */
3734 pid_to_ptid (int pid
)
3736 return ptid_build (pid
, 0, 0);
3739 /* Fetch the pid (process id) component from a ptid. */
3742 ptid_get_pid (ptid_t ptid
)
3747 /* Fetch the lwp (lightweight process) component from a ptid. */
3750 ptid_get_lwp (ptid_t ptid
)
3755 /* Fetch the tid (thread id) component from a ptid. */
3758 ptid_get_tid (ptid_t ptid
)
3763 /* ptid_equal() is used to test equality of two ptids. */
3766 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
3768 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
3769 && ptid1
.tid
== ptid2
.tid
);
3772 /* restore_inferior_ptid() will be used by the cleanup machinery
3773 to restore the inferior_ptid value saved in a call to
3774 save_inferior_ptid(). */
3777 restore_inferior_ptid (void *arg
)
3779 ptid_t
*saved_ptid_ptr
= arg
;
3780 inferior_ptid
= *saved_ptid_ptr
;
3784 /* Save the value of inferior_ptid so that it may be restored by a
3785 later call to do_cleanups(). Returns the struct cleanup pointer
3786 needed for later doing the cleanup. */
3789 save_inferior_ptid (void)
3791 ptid_t
*saved_ptid_ptr
;
3793 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
3794 *saved_ptid_ptr
= inferior_ptid
;
3795 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
3802 stop_registers
= regcache_xmalloc (current_gdbarch
);
3806 _initialize_infrun (void)
3809 register int numsigs
;
3810 struct cmd_list_element
*c
;
3812 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
3813 register_gdbarch_swap (NULL
, 0, build_infrun
);
3815 add_info ("signals", signals_info
,
3816 "What debugger does when program gets various signals.\n\
3817 Specify a signal as argument to print info on that signal only.");
3818 add_info_alias ("handle", "signals", 0);
3820 add_com ("handle", class_run
, handle_command
,
3821 concat ("Specify how to handle a signal.\n\
3822 Args are signals and actions to apply to those signals.\n\
3823 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3824 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3825 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3826 The special arg \"all\" is recognized to mean all signals except those\n\
3827 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3828 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3829 Stop means reenter debugger if this signal happens (implies print).\n\
3830 Print means print a message if this signal happens.\n\
3831 Pass means let program see this signal; otherwise program doesn't know.\n\
3832 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3833 Pass and Stop may be combined.", NULL
));
3836 add_com ("lz", class_info
, signals_info
,
3837 "What debugger does when program gets various signals.\n\
3838 Specify a signal as argument to print info on that signal only.");
3839 add_com ("z", class_run
, xdb_handle_command
,
3840 concat ("Specify how to handle a signal.\n\
3841 Args are signals and actions to apply to those signals.\n\
3842 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3843 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3844 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3845 The special arg \"all\" is recognized to mean all signals except those\n\
3846 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3847 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3848 nopass), \"Q\" (noprint)\n\
3849 Stop means reenter debugger if this signal happens (implies print).\n\
3850 Print means print a message if this signal happens.\n\
3851 Pass means let program see this signal; otherwise program doesn't know.\n\
3852 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3853 Pass and Stop may be combined.", NULL
));
3858 add_cmd ("stop", class_obscure
, not_just_help_class_command
, "There is no `stop' command, but you can set a hook on `stop'.\n\
3859 This allows you to set a list of commands to be run each time execution\n\
3860 of the program stops.", &cmdlist
);
3862 numsigs
= (int) TARGET_SIGNAL_LAST
;
3863 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
3864 signal_print
= (unsigned char *)
3865 xmalloc (sizeof (signal_print
[0]) * numsigs
);
3866 signal_program
= (unsigned char *)
3867 xmalloc (sizeof (signal_program
[0]) * numsigs
);
3868 for (i
= 0; i
< numsigs
; i
++)
3871 signal_print
[i
] = 1;
3872 signal_program
[i
] = 1;
3875 /* Signals caused by debugger's own actions
3876 should not be given to the program afterwards. */
3877 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
3878 signal_program
[TARGET_SIGNAL_INT
] = 0;
3880 /* Signals that are not errors should not normally enter the debugger. */
3881 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
3882 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
3883 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
3884 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
3885 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
3886 signal_print
[TARGET_SIGNAL_PROF
] = 0;
3887 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
3888 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
3889 signal_stop
[TARGET_SIGNAL_IO
] = 0;
3890 signal_print
[TARGET_SIGNAL_IO
] = 0;
3891 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
3892 signal_print
[TARGET_SIGNAL_POLL
] = 0;
3893 signal_stop
[TARGET_SIGNAL_URG
] = 0;
3894 signal_print
[TARGET_SIGNAL_URG
] = 0;
3895 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
3896 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
3898 /* These signals are used internally by user-level thread
3899 implementations. (See signal(5) on Solaris.) Like the above
3900 signals, a healthy program receives and handles them as part of
3901 its normal operation. */
3902 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
3903 signal_print
[TARGET_SIGNAL_LWP
] = 0;
3904 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
3905 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
3906 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
3907 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
3911 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
3912 (char *) &stop_on_solib_events
,
3913 "Set stopping for shared library events.\n\
3914 If nonzero, gdb will give control to the user when the dynamic linker\n\
3915 notifies gdb of shared library events. The most common event of interest\n\
3916 to the user would be loading/unloading of a new library.\n", &setlist
), &showlist
);
3919 c
= add_set_enum_cmd ("follow-fork-mode",
3921 follow_fork_mode_kind_names
, &follow_fork_mode_string
,
3922 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
3923 kernel problem. It's also not terribly useful without a GUI to
3924 help the user drive two debuggers. So for now, I'm disabling
3925 the "both" option. */
3926 /* "Set debugger response to a program call of fork \
3928 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3929 parent - the original process is debugged after a fork\n\
3930 child - the new process is debugged after a fork\n\
3931 both - both the parent and child are debugged after a fork\n\
3932 ask - the debugger will ask for one of the above choices\n\
3933 For \"both\", another copy of the debugger will be started to follow\n\
3934 the new child process. The original debugger will continue to follow\n\
3935 the original parent process. To distinguish their prompts, the\n\
3936 debugger copy's prompt will be changed.\n\
3937 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3938 By default, the debugger will follow the parent process.",
3940 "Set debugger response to a program call of fork \
3942 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3943 parent - the original process is debugged after a fork\n\
3944 child - the new process is debugged after a fork\n\
3945 ask - the debugger will ask for one of the above choices\n\
3946 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3947 By default, the debugger will follow the parent process.", &setlist
);
3948 add_show_from_set (c
, &showlist
);
3950 c
= add_set_enum_cmd ("scheduler-locking", class_run
, scheduler_enums
, /* array of string names */
3951 &scheduler_mode
, /* current mode */
3952 "Set mode for locking scheduler during execution.\n\
3953 off == no locking (threads may preempt at any time)\n\
3954 on == full locking (no thread except the current thread may run)\n\
3955 step == scheduler locked during every single-step operation.\n\
3956 In this mode, no other thread may run during a step command.\n\
3957 Other threads may run while stepping over a function call ('next').", &setlist
);
3959 set_cmd_sfunc (c
, set_schedlock_func
); /* traps on target vector */
3960 add_show_from_set (c
, &showlist
);
3962 c
= add_set_cmd ("step-mode", class_run
,
3963 var_boolean
, (char *) &step_stop_if_no_debug
,
3964 "Set mode of the step operation. When set, doing a step over a\n\
3965 function without debug line information will stop at the first\n\
3966 instruction of that function. Otherwise, the function is skipped and\n\
3967 the step command stops at a different source line.", &setlist
);
3968 add_show_from_set (c
, &showlist
);
3970 /* ptid initializations */
3971 null_ptid
= ptid_build (0, 0, 0);
3972 minus_one_ptid
= ptid_build (-1, 0, 0);
3973 inferior_ptid
= null_ptid
;
3974 target_last_wait_ptid
= minus_one_ptid
;