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"
49 /* Prototypes for local functions */
51 static void signals_info (char *, int);
53 static void handle_command (char *, int);
55 static void sig_print_info (enum target_signal
);
57 static void sig_print_header (void);
59 static void resume_cleanups (void *);
61 static int hook_stop_stub (void *);
63 static void delete_breakpoint_current_contents (void *);
65 static void set_follow_fork_mode_command (char *arg
, int from_tty
,
66 struct cmd_list_element
*c
);
68 static int restore_selected_frame (void *);
70 static void build_infrun (void);
72 static int follow_fork (void);
74 static void set_schedlock_func (char *args
, int from_tty
,
75 struct cmd_list_element
*c
);
77 struct execution_control_state
;
79 static int currently_stepping (struct execution_control_state
*ecs
);
81 static void xdb_handle_command (char *args
, int from_tty
);
83 static int prepare_to_proceed (void);
85 void _initialize_infrun (void);
87 int inferior_ignoring_startup_exec_events
= 0;
88 int inferior_ignoring_leading_exec_events
= 0;
90 /* When set, stop the 'step' command if we enter a function which has
91 no line number information. The normal behavior is that we step
92 over such function. */
93 int step_stop_if_no_debug
= 0;
95 /* In asynchronous mode, but simulating synchronous execution. */
97 int sync_execution
= 0;
99 /* wait_for_inferior and normal_stop use this to notify the user
100 when the inferior stopped in a different thread than it had been
103 static ptid_t previous_inferior_ptid
;
105 /* This is true for configurations that may follow through execl() and
106 similar functions. At present this is only true for HP-UX native. */
108 #ifndef MAY_FOLLOW_EXEC
109 #define MAY_FOLLOW_EXEC (0)
112 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
114 /* If the program uses ELF-style shared libraries, then calls to
115 functions in shared libraries go through stubs, which live in a
116 table called the PLT (Procedure Linkage Table). The first time the
117 function is called, the stub sends control to the dynamic linker,
118 which looks up the function's real address, patches the stub so
119 that future calls will go directly to the function, and then passes
120 control to the function.
122 If we are stepping at the source level, we don't want to see any of
123 this --- we just want to skip over the stub and the dynamic linker.
124 The simple approach is to single-step until control leaves the
127 However, on some systems (e.g., Red Hat's 5.2 distribution) the
128 dynamic linker calls functions in the shared C library, so you
129 can't tell from the PC alone whether the dynamic linker is still
130 running. In this case, we use a step-resume breakpoint to get us
131 past the dynamic linker, as if we were using "next" to step over a
134 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
135 linker code or not. Normally, this means we single-step. However,
136 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
137 address where we can place a step-resume breakpoint to get past the
138 linker's symbol resolution function.
140 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
141 pretty portable way, by comparing the PC against the address ranges
142 of the dynamic linker's sections.
144 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
145 it depends on internal details of the dynamic linker. It's usually
146 not too hard to figure out where to put a breakpoint, but it
147 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
148 sanity checking. If it can't figure things out, returning zero and
149 getting the (possibly confusing) stepping behavior is better than
150 signalling an error, which will obscure the change in the
153 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
154 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
157 /* This function returns TRUE if pc is the address of an instruction
158 that lies within the dynamic linker (such as the event hook, or the
161 This function must be used only when a dynamic linker event has
162 been caught, and the inferior is being stepped out of the hook, or
163 undefined results are guaranteed. */
165 #ifndef SOLIB_IN_DYNAMIC_LINKER
166 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
169 /* On MIPS16, a function that returns a floating point value may call
170 a library helper function to copy the return value to a floating point
171 register. The IGNORE_HELPER_CALL macro returns non-zero if we
172 should ignore (i.e. step over) this function call. */
173 #ifndef IGNORE_HELPER_CALL
174 #define IGNORE_HELPER_CALL(pc) 0
177 /* On some systems, the PC may be left pointing at an instruction that won't
178 actually be executed. This is usually indicated by a bit in the PSW. If
179 we find ourselves in such a state, then we step the target beyond the
180 nullified instruction before returning control to the user so as to avoid
183 #ifndef INSTRUCTION_NULLIFIED
184 #define INSTRUCTION_NULLIFIED 0
187 /* We can't step off a permanent breakpoint in the ordinary way, because we
188 can't remove it. Instead, we have to advance the PC to the next
189 instruction. This macro should expand to a pointer to a function that
190 does that, or zero if we have no such function. If we don't have a
191 definition for it, we have to report an error. */
192 #ifndef SKIP_PERMANENT_BREAKPOINT
193 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
195 default_skip_permanent_breakpoint (void)
198 The program is stopped at a permanent breakpoint, but GDB does not know\n\
199 how to step past a permanent breakpoint on this architecture. Try using\n\
200 a command like `return' or `jump' to continue execution.");
205 /* Convert the #defines into values. This is temporary until wfi control
206 flow is completely sorted out. */
208 #ifndef HAVE_STEPPABLE_WATCHPOINT
209 #define HAVE_STEPPABLE_WATCHPOINT 0
211 #undef HAVE_STEPPABLE_WATCHPOINT
212 #define HAVE_STEPPABLE_WATCHPOINT 1
215 #ifndef CANNOT_STEP_HW_WATCHPOINTS
216 #define CANNOT_STEP_HW_WATCHPOINTS 0
218 #undef CANNOT_STEP_HW_WATCHPOINTS
219 #define CANNOT_STEP_HW_WATCHPOINTS 1
222 /* Tables of how to react to signals; the user sets them. */
224 static unsigned char *signal_stop
;
225 static unsigned char *signal_print
;
226 static unsigned char *signal_program
;
228 #define SET_SIGS(nsigs,sigs,flags) \
230 int signum = (nsigs); \
231 while (signum-- > 0) \
232 if ((sigs)[signum]) \
233 (flags)[signum] = 1; \
236 #define UNSET_SIGS(nsigs,sigs,flags) \
238 int signum = (nsigs); \
239 while (signum-- > 0) \
240 if ((sigs)[signum]) \
241 (flags)[signum] = 0; \
244 /* Value to pass to target_resume() to cause all threads to resume */
246 #define RESUME_ALL (pid_to_ptid (-1))
248 /* Command list pointer for the "stop" placeholder. */
250 static struct cmd_list_element
*stop_command
;
252 /* Nonzero if breakpoints are now inserted in the inferior. */
254 static int breakpoints_inserted
;
256 /* Function inferior was in as of last step command. */
258 static struct symbol
*step_start_function
;
260 /* Nonzero if we are expecting a trace trap and should proceed from it. */
262 static int trap_expected
;
265 /* Nonzero if we want to give control to the user when we're notified
266 of shared library events by the dynamic linker. */
267 static int stop_on_solib_events
;
271 /* Nonzero if the next time we try to continue the inferior, it will
272 step one instruction and generate a spurious trace trap.
273 This is used to compensate for a bug in HP-UX. */
275 static int trap_expected_after_continue
;
278 /* Nonzero means expecting a trace trap
279 and should stop the inferior and return silently when it happens. */
283 /* Nonzero means expecting a trap and caller will handle it themselves.
284 It is used after attach, due to attaching to a process;
285 when running in the shell before the child program has been exec'd;
286 and when running some kinds of remote stuff (FIXME?). */
288 enum stop_kind stop_soon
;
290 /* Nonzero if proceed is being used for a "finish" command or a similar
291 situation when stop_registers should be saved. */
293 int proceed_to_finish
;
295 /* Save register contents here when about to pop a stack dummy frame,
296 if-and-only-if proceed_to_finish is set.
297 Thus this contains the return value from the called function (assuming
298 values are returned in a register). */
300 struct regcache
*stop_registers
;
302 /* Nonzero if program stopped due to error trying to insert breakpoints. */
304 static int breakpoints_failed
;
306 /* Nonzero after stop if current stack frame should be printed. */
308 static int stop_print_frame
;
310 static struct breakpoint
*step_resume_breakpoint
= NULL
;
311 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
313 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
314 interactions with an inferior that is running a kernel function
315 (aka, a system call or "syscall"). wait_for_inferior therefore
316 may have a need to know when the inferior is in a syscall. This
317 is a count of the number of inferior threads which are known to
318 currently be running in a syscall. */
319 static int number_of_threads_in_syscalls
;
321 /* This is a cached copy of the pid/waitstatus of the last event
322 returned by target_wait()/target_wait_hook(). This information is
323 returned by get_last_target_status(). */
324 static ptid_t target_last_wait_ptid
;
325 static struct target_waitstatus target_last_waitstatus
;
327 /* This is used to remember when a fork, vfork or exec event
328 was caught by a catchpoint, and thus the event is to be
329 followed at the next resume of the inferior, and not
333 enum target_waitkind kind
;
340 char *execd_pathname
;
344 static const char follow_fork_mode_ask
[] = "ask";
345 static const char follow_fork_mode_child
[] = "child";
346 static const char follow_fork_mode_parent
[] = "parent";
348 static const char *follow_fork_mode_kind_names
[] = {
349 follow_fork_mode_ask
,
350 follow_fork_mode_child
,
351 follow_fork_mode_parent
,
355 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
361 const char *follow_mode
= follow_fork_mode_string
;
362 int follow_child
= (follow_mode
== follow_fork_mode_child
);
364 /* Or, did the user not know, and want us to ask? */
365 if (follow_fork_mode_string
== follow_fork_mode_ask
)
367 internal_error (__FILE__
, __LINE__
,
368 "follow_inferior_fork: \"ask\" mode not implemented");
369 /* follow_mode = follow_fork_mode_...; */
372 return target_follow_fork (follow_child
);
376 follow_inferior_reset_breakpoints (void)
378 /* Was there a step_resume breakpoint? (There was if the user
379 did a "next" at the fork() call.) If so, explicitly reset its
382 step_resumes are a form of bp that are made to be per-thread.
383 Since we created the step_resume bp when the parent process
384 was being debugged, and now are switching to the child process,
385 from the breakpoint package's viewpoint, that's a switch of
386 "threads". We must update the bp's notion of which thread
387 it is for, or it'll be ignored when it triggers. */
389 if (step_resume_breakpoint
)
390 breakpoint_re_set_thread (step_resume_breakpoint
);
392 /* Reinsert all breakpoints in the child. The user may have set
393 breakpoints after catching the fork, in which case those
394 were never set in the child, but only in the parent. This makes
395 sure the inserted breakpoints match the breakpoint list. */
397 breakpoint_re_set ();
398 insert_breakpoints ();
401 /* EXECD_PATHNAME is assumed to be non-NULL. */
404 follow_exec (int pid
, char *execd_pathname
)
407 struct target_ops
*tgt
;
409 if (!may_follow_exec
)
412 /* This is an exec event that we actually wish to pay attention to.
413 Refresh our symbol table to the newly exec'd program, remove any
416 If there are breakpoints, they aren't really inserted now,
417 since the exec() transformed our inferior into a fresh set
420 We want to preserve symbolic breakpoints on the list, since
421 we have hopes that they can be reset after the new a.out's
422 symbol table is read.
424 However, any "raw" breakpoints must be removed from the list
425 (e.g., the solib bp's), since their address is probably invalid
428 And, we DON'T want to call delete_breakpoints() here, since
429 that may write the bp's "shadow contents" (the instruction
430 value that was overwritten witha TRAP instruction). Since
431 we now have a new a.out, those shadow contents aren't valid. */
432 update_breakpoints_after_exec ();
434 /* If there was one, it's gone now. We cannot truly step-to-next
435 statement through an exec(). */
436 step_resume_breakpoint
= NULL
;
437 step_range_start
= 0;
440 /* If there was one, it's gone now. */
441 through_sigtramp_breakpoint
= NULL
;
443 /* What is this a.out's name? */
444 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
446 /* We've followed the inferior through an exec. Therefore, the
447 inferior has essentially been killed & reborn. */
449 /* First collect the run target in effect. */
450 tgt
= find_run_target ();
451 /* If we can't find one, things are in a very strange state... */
453 error ("Could find run target to save before following exec");
455 gdb_flush (gdb_stdout
);
456 target_mourn_inferior ();
457 inferior_ptid
= pid_to_ptid (saved_pid
);
458 /* Because mourn_inferior resets inferior_ptid. */
461 /* That a.out is now the one to use. */
462 exec_file_attach (execd_pathname
, 0);
464 /* And also is where symbols can be found. */
465 symbol_file_add_main (execd_pathname
, 0);
467 /* Reset the shared library package. This ensures that we get
468 a shlib event when the child reaches "_start", at which point
469 the dld will have had a chance to initialize the child. */
470 #if defined(SOLIB_RESTART)
473 #ifdef SOLIB_CREATE_INFERIOR_HOOK
474 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
477 /* Reinsert all breakpoints. (Those which were symbolic have
478 been reset to the proper address in the new a.out, thanks
479 to symbol_file_command...) */
480 insert_breakpoints ();
482 /* The next resume of this inferior should bring it to the shlib
483 startup breakpoints. (If the user had also set bp's on
484 "main" from the old (parent) process, then they'll auto-
485 matically get reset there in the new process.) */
488 /* Non-zero if we just simulating a single-step. This is needed
489 because we cannot remove the breakpoints in the inferior process
490 until after the `wait' in `wait_for_inferior'. */
491 static int singlestep_breakpoints_inserted_p
= 0;
494 /* Things to clean up if we QUIT out of resume (). */
496 resume_cleanups (void *ignore
)
501 static const char schedlock_off
[] = "off";
502 static const char schedlock_on
[] = "on";
503 static const char schedlock_step
[] = "step";
504 static const char *scheduler_mode
= schedlock_off
;
505 static const char *scheduler_enums
[] = {
513 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
515 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
516 the set command passed as a parameter. The clone operation will
517 include (BUG?) any ``set'' command callback, if present.
518 Commands like ``info set'' call all the ``show'' command
519 callbacks. Unfortunately, for ``show'' commands cloned from
520 ``set'', this includes callbacks belonging to ``set'' commands.
521 Making this worse, this only occures if add_show_from_set() is
522 called after add_cmd_sfunc() (BUG?). */
523 if (cmd_type (c
) == set_cmd
)
524 if (!target_can_lock_scheduler
)
526 scheduler_mode
= schedlock_off
;
527 error ("Target '%s' cannot support this command.", target_shortname
);
532 /* Resume the inferior, but allow a QUIT. This is useful if the user
533 wants to interrupt some lengthy single-stepping operation
534 (for child processes, the SIGINT goes to the inferior, and so
535 we get a SIGINT random_signal, but for remote debugging and perhaps
536 other targets, that's not true).
538 STEP nonzero if we should step (zero to continue instead).
539 SIG is the signal to give the inferior (zero for none). */
541 resume (int step
, enum target_signal sig
)
543 int should_resume
= 1;
544 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
547 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
550 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
551 over an instruction that causes a page fault without triggering
552 a hardware watchpoint. The kernel properly notices that it shouldn't
553 stop, because the hardware watchpoint is not triggered, but it forgets
554 the step request and continues the program normally.
555 Work around the problem by removing hardware watchpoints if a step is
556 requested, GDB will check for a hardware watchpoint trigger after the
558 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
559 remove_hw_watchpoints ();
562 /* Normally, by the time we reach `resume', the breakpoints are either
563 removed or inserted, as appropriate. The exception is if we're sitting
564 at a permanent breakpoint; we need to step over it, but permanent
565 breakpoints can't be removed. So we have to test for it here. */
566 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
567 SKIP_PERMANENT_BREAKPOINT ();
569 if (SOFTWARE_SINGLE_STEP_P () && step
)
571 /* Do it the hard way, w/temp breakpoints */
572 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
573 /* ...and don't ask hardware to do it. */
575 /* and do not pull these breakpoints until after a `wait' in
576 `wait_for_inferior' */
577 singlestep_breakpoints_inserted_p
= 1;
580 /* Handle any optimized stores to the inferior NOW... */
581 #ifdef DO_DEFERRED_STORES
585 /* If there were any forks/vforks/execs that were caught and are
586 now to be followed, then do so. */
587 switch (pending_follow
.kind
)
589 case TARGET_WAITKIND_FORKED
:
590 case TARGET_WAITKIND_VFORKED
:
591 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
596 case TARGET_WAITKIND_EXECD
:
597 /* follow_exec is called as soon as the exec event is seen. */
598 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
605 /* Install inferior's terminal modes. */
606 target_terminal_inferior ();
612 resume_ptid
= RESUME_ALL
; /* Default */
614 if ((step
|| singlestep_breakpoints_inserted_p
) &&
615 !breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
617 /* Stepping past a breakpoint without inserting breakpoints.
618 Make sure only the current thread gets to step, so that
619 other threads don't sneak past breakpoints while they are
622 resume_ptid
= inferior_ptid
;
625 if ((scheduler_mode
== schedlock_on
) ||
626 (scheduler_mode
== schedlock_step
&&
627 (step
|| singlestep_breakpoints_inserted_p
)))
629 /* User-settable 'scheduler' mode requires solo thread resume. */
630 resume_ptid
= inferior_ptid
;
633 if (CANNOT_STEP_BREAKPOINT
)
635 /* Most targets can step a breakpoint instruction, thus
636 executing it normally. But if this one cannot, just
637 continue and we will hit it anyway. */
638 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
641 target_resume (resume_ptid
, step
, sig
);
644 discard_cleanups (old_cleanups
);
648 /* Clear out all variables saying what to do when inferior is continued.
649 First do this, then set the ones you want, then call `proceed'. */
652 clear_proceed_status (void)
655 step_range_start
= 0;
657 step_frame_id
= null_frame_id
;
658 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
660 stop_soon
= NO_STOP_QUIETLY
;
661 proceed_to_finish
= 0;
662 breakpoint_proceeded
= 1; /* We're about to proceed... */
664 /* Discard any remaining commands or status from previous stop. */
665 bpstat_clear (&stop_bpstat
);
668 /* This should be suitable for any targets that support threads. */
671 prepare_to_proceed (void)
674 struct target_waitstatus wait_status
;
676 /* Get the last target status returned by target_wait(). */
677 get_last_target_status (&wait_ptid
, &wait_status
);
679 /* Make sure we were stopped either at a breakpoint, or because
681 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
682 || (wait_status
.value
.sig
!= TARGET_SIGNAL_TRAP
&&
683 wait_status
.value
.sig
!= TARGET_SIGNAL_INT
))
688 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
689 && !ptid_equal (inferior_ptid
, wait_ptid
))
691 /* Switched over from WAIT_PID. */
692 CORE_ADDR wait_pc
= read_pc_pid (wait_ptid
);
694 if (wait_pc
!= read_pc ())
696 /* Switch back to WAIT_PID thread. */
697 inferior_ptid
= wait_ptid
;
699 /* FIXME: This stuff came from switch_to_thread() in
700 thread.c (which should probably be a public function). */
701 flush_cached_frames ();
702 registers_changed ();
704 select_frame (get_current_frame ());
707 /* We return 1 to indicate that there is a breakpoint here,
708 so we need to step over it before continuing to avoid
709 hitting it straight away. */
710 if (breakpoint_here_p (wait_pc
))
718 /* Record the pc of the program the last time it stopped. This is
719 just used internally by wait_for_inferior, but need to be preserved
720 over calls to it and cleared when the inferior is started. */
721 static CORE_ADDR prev_pc
;
723 /* Basic routine for continuing the program in various fashions.
725 ADDR is the address to resume at, or -1 for resume where stopped.
726 SIGGNAL is the signal to give it, or 0 for none,
727 or -1 for act according to how it stopped.
728 STEP is nonzero if should trap after one instruction.
729 -1 means return after that and print nothing.
730 You should probably set various step_... variables
731 before calling here, if you are stepping.
733 You should call clear_proceed_status before calling proceed. */
736 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
741 step_start_function
= find_pc_function (read_pc ());
745 if (addr
== (CORE_ADDR
) -1)
747 /* If there is a breakpoint at the address we will resume at,
748 step one instruction before inserting breakpoints
749 so that we do not stop right away (and report a second
750 hit at this breakpoint). */
752 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
755 #ifndef STEP_SKIPS_DELAY
756 #define STEP_SKIPS_DELAY(pc) (0)
757 #define STEP_SKIPS_DELAY_P (0)
759 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
760 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
761 is slow (it needs to read memory from the target). */
762 if (STEP_SKIPS_DELAY_P
763 && breakpoint_here_p (read_pc () + 4)
764 && STEP_SKIPS_DELAY (read_pc ()))
772 /* In a multi-threaded task we may select another thread
773 and then continue or step.
775 But if the old thread was stopped at a breakpoint, it
776 will immediately cause another breakpoint stop without
777 any execution (i.e. it will report a breakpoint hit
778 incorrectly). So we must step over it first.
780 prepare_to_proceed checks the current thread against the thread
781 that reported the most recent event. If a step-over is required
782 it returns TRUE and sets the current thread to the old thread. */
783 if (prepare_to_proceed () && breakpoint_here_p (read_pc ()))
787 if (trap_expected_after_continue
)
789 /* If (step == 0), a trap will be automatically generated after
790 the first instruction is executed. Force step one
791 instruction to clear this condition. This should not occur
792 if step is nonzero, but it is harmless in that case. */
794 trap_expected_after_continue
= 0;
796 #endif /* HP_OS_BUG */
799 /* We will get a trace trap after one instruction.
800 Continue it automatically and insert breakpoints then. */
804 insert_breakpoints ();
805 /* If we get here there was no call to error() in
806 insert breakpoints -- so they were inserted. */
807 breakpoints_inserted
= 1;
810 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
811 stop_signal
= siggnal
;
812 /* If this signal should not be seen by program,
813 give it zero. Used for debugging signals. */
814 else if (!signal_program
[stop_signal
])
815 stop_signal
= TARGET_SIGNAL_0
;
817 annotate_starting ();
819 /* Make sure that output from GDB appears before output from the
821 gdb_flush (gdb_stdout
);
823 /* Refresh prev_pc value just prior to resuming. This used to be
824 done in stop_stepping, however, setting prev_pc there did not handle
825 scenarios such as inferior function calls or returning from
826 a function via the return command. In those cases, the prev_pc
827 value was not set properly for subsequent commands. The prev_pc value
828 is used to initialize the starting line number in the ecs. With an
829 invalid value, the gdb next command ends up stopping at the position
830 represented by the next line table entry past our start position.
831 On platforms that generate one line table entry per line, this
832 is not a problem. However, on the ia64, the compiler generates
833 extraneous line table entries that do not increase the line number.
834 When we issue the gdb next command on the ia64 after an inferior call
835 or a return command, we often end up a few instructions forward, still
836 within the original line we started.
838 An attempt was made to have init_execution_control_state () refresh
839 the prev_pc value before calculating the line number. This approach
840 did not work because on platforms that use ptrace, the pc register
841 cannot be read unless the inferior is stopped. At that point, we
842 are not guaranteed the inferior is stopped and so the read_pc ()
843 call can fail. Setting the prev_pc value here ensures the value is
844 updated correctly when the inferior is stopped. */
845 prev_pc
= read_pc ();
847 /* Resume inferior. */
848 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
850 /* Wait for it to stop (if not standalone)
851 and in any case decode why it stopped, and act accordingly. */
852 /* Do this only if we are not using the event loop, or if the target
853 does not support asynchronous execution. */
854 if (!event_loop_p
|| !target_can_async_p ())
856 wait_for_inferior ();
862 /* Start remote-debugging of a machine over a serial link. */
868 init_wait_for_inferior ();
869 stop_soon
= STOP_QUIETLY
;
872 /* Always go on waiting for the target, regardless of the mode. */
873 /* FIXME: cagney/1999-09-23: At present it isn't possible to
874 indicate to wait_for_inferior that a target should timeout if
875 nothing is returned (instead of just blocking). Because of this,
876 targets expecting an immediate response need to, internally, set
877 things up so that the target_wait() is forced to eventually
879 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
880 differentiate to its caller what the state of the target is after
881 the initial open has been performed. Here we're assuming that
882 the target has stopped. It should be possible to eventually have
883 target_open() return to the caller an indication that the target
884 is currently running and GDB state should be set to the same as
886 wait_for_inferior ();
890 /* Initialize static vars when a new inferior begins. */
893 init_wait_for_inferior (void)
895 /* These are meaningless until the first time through wait_for_inferior. */
899 trap_expected_after_continue
= 0;
901 breakpoints_inserted
= 0;
902 breakpoint_init_inferior (inf_starting
);
904 /* Don't confuse first call to proceed(). */
905 stop_signal
= TARGET_SIGNAL_0
;
907 /* The first resume is not following a fork/vfork/exec. */
908 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
910 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
911 number_of_threads_in_syscalls
= 0;
913 clear_proceed_status ();
917 delete_breakpoint_current_contents (void *arg
)
919 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
920 if (*breakpointp
!= NULL
)
922 delete_breakpoint (*breakpointp
);
927 /* This enum encodes possible reasons for doing a target_wait, so that
928 wfi can call target_wait in one place. (Ultimately the call will be
929 moved out of the infinite loop entirely.) */
933 infwait_normal_state
,
934 infwait_thread_hop_state
,
935 infwait_nullified_state
,
936 infwait_nonstep_watch_state
939 /* Why did the inferior stop? Used to print the appropriate messages
940 to the interface from within handle_inferior_event(). */
941 enum inferior_stop_reason
943 /* We don't know why. */
945 /* Step, next, nexti, stepi finished. */
947 /* Found breakpoint. */
949 /* Inferior terminated by signal. */
951 /* Inferior exited. */
953 /* Inferior received signal, and user asked to be notified. */
957 /* This structure contains what used to be local variables in
958 wait_for_inferior. Probably many of them can return to being
959 locals in handle_inferior_event. */
961 struct execution_control_state
963 struct target_waitstatus ws
;
964 struct target_waitstatus
*wp
;
967 CORE_ADDR stop_func_start
;
968 CORE_ADDR stop_func_end
;
969 char *stop_func_name
;
970 struct symtab_and_line sal
;
971 int remove_breakpoints_on_following_step
;
973 struct symtab
*current_symtab
;
974 int handling_longjmp
; /* FIXME */
976 ptid_t saved_inferior_ptid
;
978 int stepping_through_solib_after_catch
;
979 bpstat stepping_through_solib_catchpoints
;
980 int enable_hw_watchpoints_after_wait
;
981 int stepping_through_sigtramp
;
982 int new_thread_event
;
983 struct target_waitstatus tmpstatus
;
984 enum infwait_states infwait_state
;
989 void init_execution_control_state (struct execution_control_state
*ecs
);
991 void handle_inferior_event (struct execution_control_state
*ecs
);
993 static void check_sigtramp2 (struct execution_control_state
*ecs
);
994 static void step_into_function (struct execution_control_state
*ecs
);
995 static void step_over_function (struct execution_control_state
*ecs
);
996 static void stop_stepping (struct execution_control_state
*ecs
);
997 static void prepare_to_wait (struct execution_control_state
*ecs
);
998 static void keep_going (struct execution_control_state
*ecs
);
999 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
1002 /* Wait for control to return from inferior to debugger.
1003 If inferior gets a signal, we may decide to start it up again
1004 instead of returning. That is why there is a loop in this function.
1005 When this function actually returns it means the inferior
1006 should be left stopped and GDB should read more commands. */
1009 wait_for_inferior (void)
1011 struct cleanup
*old_cleanups
;
1012 struct execution_control_state ecss
;
1013 struct execution_control_state
*ecs
;
1015 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1016 &step_resume_breakpoint
);
1017 make_cleanup (delete_breakpoint_current_contents
,
1018 &through_sigtramp_breakpoint
);
1020 /* wfi still stays in a loop, so it's OK just to take the address of
1021 a local to get the ecs pointer. */
1024 /* Fill in with reasonable starting values. */
1025 init_execution_control_state (ecs
);
1027 /* We'll update this if & when we switch to a new thread. */
1028 previous_inferior_ptid
= inferior_ptid
;
1030 overlay_cache_invalid
= 1;
1032 /* We have to invalidate the registers BEFORE calling target_wait
1033 because they can be loaded from the target while in target_wait.
1034 This makes remote debugging a bit more efficient for those
1035 targets that provide critical registers as part of their normal
1036 status mechanism. */
1038 registers_changed ();
1042 if (target_wait_hook
)
1043 ecs
->ptid
= target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
1045 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
1047 /* Now figure out what to do with the result of the result. */
1048 handle_inferior_event (ecs
);
1050 if (!ecs
->wait_some_more
)
1053 do_cleanups (old_cleanups
);
1056 /* Asynchronous version of wait_for_inferior. It is called by the
1057 event loop whenever a change of state is detected on the file
1058 descriptor corresponding to the target. It can be called more than
1059 once to complete a single execution command. In such cases we need
1060 to keep the state in a global variable ASYNC_ECSS. If it is the
1061 last time that this function is called for a single execution
1062 command, then report to the user that the inferior has stopped, and
1063 do the necessary cleanups. */
1065 struct execution_control_state async_ecss
;
1066 struct execution_control_state
*async_ecs
;
1069 fetch_inferior_event (void *client_data
)
1071 static struct cleanup
*old_cleanups
;
1073 async_ecs
= &async_ecss
;
1075 if (!async_ecs
->wait_some_more
)
1077 old_cleanups
= make_exec_cleanup (delete_step_resume_breakpoint
,
1078 &step_resume_breakpoint
);
1079 make_exec_cleanup (delete_breakpoint_current_contents
,
1080 &through_sigtramp_breakpoint
);
1082 /* Fill in with reasonable starting values. */
1083 init_execution_control_state (async_ecs
);
1085 /* We'll update this if & when we switch to a new thread. */
1086 previous_inferior_ptid
= inferior_ptid
;
1088 overlay_cache_invalid
= 1;
1090 /* We have to invalidate the registers BEFORE calling target_wait
1091 because they can be loaded from the target while in target_wait.
1092 This makes remote debugging a bit more efficient for those
1093 targets that provide critical registers as part of their normal
1094 status mechanism. */
1096 registers_changed ();
1099 if (target_wait_hook
)
1101 target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1103 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1105 /* Now figure out what to do with the result of the result. */
1106 handle_inferior_event (async_ecs
);
1108 if (!async_ecs
->wait_some_more
)
1110 /* Do only the cleanups that have been added by this
1111 function. Let the continuations for the commands do the rest,
1112 if there are any. */
1113 do_exec_cleanups (old_cleanups
);
1115 if (step_multi
&& stop_step
)
1116 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1118 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1122 /* Prepare an execution control state for looping through a
1123 wait_for_inferior-type loop. */
1126 init_execution_control_state (struct execution_control_state
*ecs
)
1128 /* ecs->another_trap? */
1129 ecs
->random_signal
= 0;
1130 ecs
->remove_breakpoints_on_following_step
= 0;
1131 ecs
->handling_longjmp
= 0; /* FIXME */
1132 ecs
->update_step_sp
= 0;
1133 ecs
->stepping_through_solib_after_catch
= 0;
1134 ecs
->stepping_through_solib_catchpoints
= NULL
;
1135 ecs
->enable_hw_watchpoints_after_wait
= 0;
1136 ecs
->stepping_through_sigtramp
= 0;
1137 ecs
->sal
= find_pc_line (prev_pc
, 0);
1138 ecs
->current_line
= ecs
->sal
.line
;
1139 ecs
->current_symtab
= ecs
->sal
.symtab
;
1140 ecs
->infwait_state
= infwait_normal_state
;
1141 ecs
->waiton_ptid
= pid_to_ptid (-1);
1142 ecs
->wp
= &(ecs
->ws
);
1145 /* Call this function before setting step_resume_breakpoint, as a
1146 sanity check. There should never be more than one step-resume
1147 breakpoint per thread, so we should never be setting a new
1148 step_resume_breakpoint when one is already active. */
1150 check_for_old_step_resume_breakpoint (void)
1152 if (step_resume_breakpoint
)
1154 ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1157 /* Return the cached copy of the last pid/waitstatus returned by
1158 target_wait()/target_wait_hook(). The data is actually cached by
1159 handle_inferior_event(), which gets called immediately after
1160 target_wait()/target_wait_hook(). */
1163 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
1165 *ptidp
= target_last_wait_ptid
;
1166 *status
= target_last_waitstatus
;
1169 /* Switch thread contexts, maintaining "infrun state". */
1172 context_switch (struct execution_control_state
*ecs
)
1174 /* Caution: it may happen that the new thread (or the old one!)
1175 is not in the thread list. In this case we must not attempt
1176 to "switch context", or we run the risk that our context may
1177 be lost. This may happen as a result of the target module
1178 mishandling thread creation. */
1180 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1181 { /* Perform infrun state context switch: */
1182 /* Save infrun state for the old thread. */
1183 save_infrun_state (inferior_ptid
, prev_pc
,
1184 trap_expected
, step_resume_breakpoint
,
1185 through_sigtramp_breakpoint
, step_range_start
,
1186 step_range_end
, &step_frame_id
,
1187 ecs
->handling_longjmp
, ecs
->another_trap
,
1188 ecs
->stepping_through_solib_after_catch
,
1189 ecs
->stepping_through_solib_catchpoints
,
1190 ecs
->stepping_through_sigtramp
,
1191 ecs
->current_line
, ecs
->current_symtab
, step_sp
);
1193 /* Load infrun state for the new thread. */
1194 load_infrun_state (ecs
->ptid
, &prev_pc
,
1195 &trap_expected
, &step_resume_breakpoint
,
1196 &through_sigtramp_breakpoint
, &step_range_start
,
1197 &step_range_end
, &step_frame_id
,
1198 &ecs
->handling_longjmp
, &ecs
->another_trap
,
1199 &ecs
->stepping_through_solib_after_catch
,
1200 &ecs
->stepping_through_solib_catchpoints
,
1201 &ecs
->stepping_through_sigtramp
,
1202 &ecs
->current_line
, &ecs
->current_symtab
, &step_sp
);
1204 inferior_ptid
= ecs
->ptid
;
1207 /* Wrapper for PC_IN_SIGTRAMP that takes care of the need to find the
1210 In a classic example of "left hand VS right hand", "infrun.c" was
1211 trying to improve GDB's performance by caching the result of calls
1212 to calls to find_pc_partial_funtion, while at the same time
1213 find_pc_partial_function was also trying to ramp up performance by
1214 caching its most recent return value. The below makes the the
1215 function find_pc_partial_function solely responsibile for
1216 performance issues (the local cache that relied on a global
1217 variable - arrrggg - deleted).
1219 Using the testsuite and gcov, it was found that dropping the local
1220 "infrun.c" cache and instead relying on find_pc_partial_function
1221 increased the number of calls to 12000 (from 10000), but the number
1222 of times find_pc_partial_function's cache missed (this is what
1223 matters) was only increased by only 4 (to 3569). (A quick back of
1224 envelope caculation suggests that the extra 2000 function calls
1225 @1000 extra instructions per call make the 1 MIP VAX testsuite run
1226 take two extra seconds, oops :-)
1228 Long term, this function can be eliminated, replaced by the code:
1229 get_frame_type(current_frame()) == SIGTRAMP_FRAME (for new
1230 architectures this is very cheap). */
1233 pc_in_sigtramp (CORE_ADDR pc
)
1236 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
1237 return PC_IN_SIGTRAMP (pc
, name
);
1241 /* Given an execution control state that has been freshly filled in
1242 by an event from the inferior, figure out what it means and take
1243 appropriate action. */
1246 handle_inferior_event (struct execution_control_state
*ecs
)
1248 CORE_ADDR real_stop_pc
;
1249 /* NOTE: cagney/2003-03-28: If you're looking at this code and
1250 thinking that the variable stepped_after_stopped_by_watchpoint
1251 isn't used, then you're wrong! The macro STOPPED_BY_WATCHPOINT,
1252 defined in the file "config/pa/nm-hppah.h", accesses the variable
1253 indirectly. Mutter something rude about the HP merge. */
1254 int stepped_after_stopped_by_watchpoint
;
1255 int sw_single_step_trap_p
= 0;
1257 /* Cache the last pid/waitstatus. */
1258 target_last_wait_ptid
= ecs
->ptid
;
1259 target_last_waitstatus
= *ecs
->wp
;
1261 switch (ecs
->infwait_state
)
1263 case infwait_thread_hop_state
:
1264 /* Cancel the waiton_ptid. */
1265 ecs
->waiton_ptid
= pid_to_ptid (-1);
1266 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1267 is serviced in this loop, below. */
1268 if (ecs
->enable_hw_watchpoints_after_wait
)
1270 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1271 ecs
->enable_hw_watchpoints_after_wait
= 0;
1273 stepped_after_stopped_by_watchpoint
= 0;
1276 case infwait_normal_state
:
1277 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1278 is serviced in this loop, below. */
1279 if (ecs
->enable_hw_watchpoints_after_wait
)
1281 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1282 ecs
->enable_hw_watchpoints_after_wait
= 0;
1284 stepped_after_stopped_by_watchpoint
= 0;
1287 case infwait_nullified_state
:
1288 stepped_after_stopped_by_watchpoint
= 0;
1291 case infwait_nonstep_watch_state
:
1292 insert_breakpoints ();
1294 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1295 handle things like signals arriving and other things happening
1296 in combination correctly? */
1297 stepped_after_stopped_by_watchpoint
= 1;
1301 internal_error (__FILE__
, __LINE__
, "bad switch");
1303 ecs
->infwait_state
= infwait_normal_state
;
1305 flush_cached_frames ();
1307 /* If it's a new process, add it to the thread database */
1309 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
1310 && !in_thread_list (ecs
->ptid
));
1312 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1313 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
1315 add_thread (ecs
->ptid
);
1317 ui_out_text (uiout
, "[New ");
1318 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->ptid
));
1319 ui_out_text (uiout
, "]\n");
1322 /* NOTE: This block is ONLY meant to be invoked in case of a
1323 "thread creation event"! If it is invoked for any other
1324 sort of event (such as a new thread landing on a breakpoint),
1325 the event will be discarded, which is almost certainly
1328 To avoid this, the low-level module (eg. target_wait)
1329 should call in_thread_list and add_thread, so that the
1330 new thread is known by the time we get here. */
1332 /* We may want to consider not doing a resume here in order
1333 to give the user a chance to play with the new thread.
1334 It might be good to make that a user-settable option. */
1336 /* At this point, all threads are stopped (happens
1337 automatically in either the OS or the native code).
1338 Therefore we need to continue all threads in order to
1341 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1342 prepare_to_wait (ecs
);
1347 switch (ecs
->ws
.kind
)
1349 case TARGET_WAITKIND_LOADED
:
1350 /* Ignore gracefully during startup of the inferior, as it
1351 might be the shell which has just loaded some objects,
1352 otherwise add the symbols for the newly loaded objects. */
1354 if (stop_soon
== NO_STOP_QUIETLY
)
1356 /* Remove breakpoints, SOLIB_ADD might adjust
1357 breakpoint addresses via breakpoint_re_set. */
1358 if (breakpoints_inserted
)
1359 remove_breakpoints ();
1361 /* Check for any newly added shared libraries if we're
1362 supposed to be adding them automatically. Switch
1363 terminal for any messages produced by
1364 breakpoint_re_set. */
1365 target_terminal_ours_for_output ();
1366 SOLIB_ADD (NULL
, 0, &exec_ops
, auto_solib_add
);
1367 target_terminal_inferior ();
1369 /* Reinsert breakpoints and continue. */
1370 if (breakpoints_inserted
)
1371 insert_breakpoints ();
1374 resume (0, TARGET_SIGNAL_0
);
1375 prepare_to_wait (ecs
);
1378 case TARGET_WAITKIND_SPURIOUS
:
1379 resume (0, TARGET_SIGNAL_0
);
1380 prepare_to_wait (ecs
);
1383 case TARGET_WAITKIND_EXITED
:
1384 target_terminal_ours (); /* Must do this before mourn anyway */
1385 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1387 /* Record the exit code in the convenience variable $_exitcode, so
1388 that the user can inspect this again later. */
1389 set_internalvar (lookup_internalvar ("_exitcode"),
1390 value_from_longest (builtin_type_int
,
1391 (LONGEST
) ecs
->ws
.value
.integer
));
1392 gdb_flush (gdb_stdout
);
1393 target_mourn_inferior ();
1394 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1395 stop_print_frame
= 0;
1396 stop_stepping (ecs
);
1399 case TARGET_WAITKIND_SIGNALLED
:
1400 stop_print_frame
= 0;
1401 stop_signal
= ecs
->ws
.value
.sig
;
1402 target_terminal_ours (); /* Must do this before mourn anyway */
1404 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1405 reach here unless the inferior is dead. However, for years
1406 target_kill() was called here, which hints that fatal signals aren't
1407 really fatal on some systems. If that's true, then some changes
1409 target_mourn_inferior ();
1411 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1412 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1413 stop_stepping (ecs
);
1416 /* The following are the only cases in which we keep going;
1417 the above cases end in a continue or goto. */
1418 case TARGET_WAITKIND_FORKED
:
1419 case TARGET_WAITKIND_VFORKED
:
1420 stop_signal
= TARGET_SIGNAL_TRAP
;
1421 pending_follow
.kind
= ecs
->ws
.kind
;
1423 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1424 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1426 stop_pc
= read_pc ();
1428 /* Assume that catchpoints are not really software breakpoints. If
1429 some future target implements them using software breakpoints then
1430 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1431 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1432 bpstat_stop_status will not decrement the PC. */
1434 stop_bpstat
= bpstat_stop_status (&stop_pc
, 1);
1436 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1438 /* If no catchpoint triggered for this, then keep going. */
1439 if (ecs
->random_signal
)
1441 stop_signal
= TARGET_SIGNAL_0
;
1445 goto process_event_stop_test
;
1447 case TARGET_WAITKIND_EXECD
:
1448 stop_signal
= TARGET_SIGNAL_TRAP
;
1450 /* NOTE drow/2002-12-05: This code should be pushed down into the
1451 target_wait function. Until then following vfork on HP/UX 10.20
1452 is probably broken by this. Of course, it's broken anyway. */
1453 /* Is this a target which reports multiple exec events per actual
1454 call to exec()? (HP-UX using ptrace does, for example.) If so,
1455 ignore all but the last one. Just resume the exec'r, and wait
1456 for the next exec event. */
1457 if (inferior_ignoring_leading_exec_events
)
1459 inferior_ignoring_leading_exec_events
--;
1460 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1461 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.
1463 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1464 prepare_to_wait (ecs
);
1467 inferior_ignoring_leading_exec_events
=
1468 target_reported_exec_events_per_exec_call () - 1;
1470 pending_follow
.execd_pathname
=
1471 savestring (ecs
->ws
.value
.execd_pathname
,
1472 strlen (ecs
->ws
.value
.execd_pathname
));
1474 /* This causes the eventpoints and symbol table to be reset. Must
1475 do this now, before trying to determine whether to stop. */
1476 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1477 xfree (pending_follow
.execd_pathname
);
1479 stop_pc
= read_pc_pid (ecs
->ptid
);
1480 ecs
->saved_inferior_ptid
= inferior_ptid
;
1481 inferior_ptid
= ecs
->ptid
;
1483 /* Assume that catchpoints are not really software breakpoints. If
1484 some future target implements them using software breakpoints then
1485 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1486 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1487 bpstat_stop_status will not decrement the PC. */
1489 stop_bpstat
= bpstat_stop_status (&stop_pc
, 1);
1491 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1492 inferior_ptid
= ecs
->saved_inferior_ptid
;
1494 /* If no catchpoint triggered for this, then keep going. */
1495 if (ecs
->random_signal
)
1497 stop_signal
= TARGET_SIGNAL_0
;
1501 goto process_event_stop_test
;
1503 /* These syscall events are returned on HP-UX, as part of its
1504 implementation of page-protection-based "hardware" watchpoints.
1505 HP-UX has unfortunate interactions between page-protections and
1506 some system calls. Our solution is to disable hardware watches
1507 when a system call is entered, and reenable them when the syscall
1508 completes. The downside of this is that we may miss the precise
1509 point at which a watched piece of memory is modified. "Oh well."
1511 Note that we may have multiple threads running, which may each
1512 enter syscalls at roughly the same time. Since we don't have a
1513 good notion currently of whether a watched piece of memory is
1514 thread-private, we'd best not have any page-protections active
1515 when any thread is in a syscall. Thus, we only want to reenable
1516 hardware watches when no threads are in a syscall.
1518 Also, be careful not to try to gather much state about a thread
1519 that's in a syscall. It's frequently a losing proposition. */
1520 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1521 number_of_threads_in_syscalls
++;
1522 if (number_of_threads_in_syscalls
== 1)
1524 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1526 resume (0, TARGET_SIGNAL_0
);
1527 prepare_to_wait (ecs
);
1530 /* Before examining the threads further, step this thread to
1531 get it entirely out of the syscall. (We get notice of the
1532 event when the thread is just on the verge of exiting a
1533 syscall. Stepping one instruction seems to get it back
1536 Note that although the logical place to reenable h/w watches
1537 is here, we cannot. We cannot reenable them before stepping
1538 the thread (this causes the next wait on the thread to hang).
1540 Nor can we enable them after stepping until we've done a wait.
1541 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1542 here, which will be serviced immediately after the target
1544 case TARGET_WAITKIND_SYSCALL_RETURN
:
1545 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1547 if (number_of_threads_in_syscalls
> 0)
1549 number_of_threads_in_syscalls
--;
1550 ecs
->enable_hw_watchpoints_after_wait
=
1551 (number_of_threads_in_syscalls
== 0);
1553 prepare_to_wait (ecs
);
1556 case TARGET_WAITKIND_STOPPED
:
1557 stop_signal
= ecs
->ws
.value
.sig
;
1560 /* We had an event in the inferior, but we are not interested
1561 in handling it at this level. The lower layers have already
1562 done what needs to be done, if anything.
1564 One of the possible circumstances for this is when the
1565 inferior produces output for the console. The inferior has
1566 not stopped, and we are ignoring the event. Another possible
1567 circumstance is any event which the lower level knows will be
1568 reported multiple times without an intervening resume. */
1569 case TARGET_WAITKIND_IGNORE
:
1570 prepare_to_wait (ecs
);
1574 /* We may want to consider not doing a resume here in order to give
1575 the user a chance to play with the new thread. It might be good
1576 to make that a user-settable option. */
1578 /* At this point, all threads are stopped (happens automatically in
1579 either the OS or the native code). Therefore we need to continue
1580 all threads in order to make progress. */
1581 if (ecs
->new_thread_event
)
1583 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1584 prepare_to_wait (ecs
);
1588 stop_pc
= read_pc_pid (ecs
->ptid
);
1590 /* See if a thread hit a thread-specific breakpoint that was meant for
1591 another thread. If so, then step that thread past the breakpoint,
1594 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1596 /* Check if a regular breakpoint has been hit before checking
1597 for a potential single step breakpoint. Otherwise, GDB will
1598 not see this breakpoint hit when stepping onto breakpoints. */
1599 if (breakpoints_inserted
1600 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1602 ecs
->random_signal
= 0;
1603 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1608 /* Saw a breakpoint, but it was hit by the wrong thread.
1610 if (DECR_PC_AFTER_BREAK
)
1611 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->ptid
);
1613 remove_status
= remove_breakpoints ();
1614 /* Did we fail to remove breakpoints? If so, try
1615 to set the PC past the bp. (There's at least
1616 one situation in which we can fail to remove
1617 the bp's: On HP-UX's that use ttrace, we can't
1618 change the address space of a vforking child
1619 process until the child exits (well, okay, not
1620 then either :-) or execs. */
1621 if (remove_status
!= 0)
1623 /* FIXME! This is obviously non-portable! */
1624 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->ptid
);
1625 /* We need to restart all the threads now,
1626 * unles we're running in scheduler-locked mode.
1627 * Use currently_stepping to determine whether to
1630 /* FIXME MVS: is there any reason not to call resume()? */
1631 if (scheduler_mode
== schedlock_on
)
1632 target_resume (ecs
->ptid
,
1633 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1635 target_resume (RESUME_ALL
,
1636 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1637 prepare_to_wait (ecs
);
1642 breakpoints_inserted
= 0;
1643 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
1644 context_switch (ecs
);
1645 ecs
->waiton_ptid
= ecs
->ptid
;
1646 ecs
->wp
= &(ecs
->ws
);
1647 ecs
->another_trap
= 1;
1649 ecs
->infwait_state
= infwait_thread_hop_state
;
1651 registers_changed ();
1656 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1658 /* Readjust the stop_pc as it is off by DECR_PC_AFTER_BREAK
1659 compared to the value it would have if the system stepping
1660 capability was used. This allows the rest of the code in
1661 this function to use this address without having to worry
1662 whether software single step is in use or not. */
1663 if (DECR_PC_AFTER_BREAK
)
1665 stop_pc
-= DECR_PC_AFTER_BREAK
;
1666 write_pc_pid (stop_pc
, ecs
->ptid
);
1669 sw_single_step_trap_p
= 1;
1670 ecs
->random_signal
= 0;
1674 ecs
->random_signal
= 1;
1676 /* See if something interesting happened to the non-current thread. If
1677 so, then switch to that thread, and eventually give control back to
1680 Note that if there's any kind of pending follow (i.e., of a fork,
1681 vfork or exec), we don't want to do this now. Rather, we'll let
1682 the next resume handle it. */
1683 if (!ptid_equal (ecs
->ptid
, inferior_ptid
) &&
1684 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1688 /* If it's a random signal for a non-current thread, notify user
1689 if he's expressed an interest. */
1690 if (ecs
->random_signal
&& signal_print
[stop_signal
])
1692 /* ??rehrauer: I don't understand the rationale for this code. If the
1693 inferior will stop as a result of this signal, then the act of handling
1694 the stop ought to print a message that's couches the stoppage in user
1695 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1696 won't stop as a result of the signal -- i.e., if the signal is merely
1697 a side-effect of something GDB's doing "under the covers" for the
1698 user, such as stepping threads over a breakpoint they shouldn't stop
1699 for -- then the message seems to be a serious annoyance at best.
1701 For now, remove the message altogether. */
1704 target_terminal_ours_for_output ();
1705 printf_filtered ("\nProgram received signal %s, %s.\n",
1706 target_signal_to_name (stop_signal
),
1707 target_signal_to_string (stop_signal
));
1708 gdb_flush (gdb_stdout
);
1712 /* If it's not SIGTRAP and not a signal we want to stop for, then
1713 continue the thread. */
1715 if (stop_signal
!= TARGET_SIGNAL_TRAP
&& !signal_stop
[stop_signal
])
1718 target_terminal_inferior ();
1720 /* Clear the signal if it should not be passed. */
1721 if (signal_program
[stop_signal
] == 0)
1722 stop_signal
= TARGET_SIGNAL_0
;
1724 target_resume (ecs
->ptid
, 0, stop_signal
);
1725 prepare_to_wait (ecs
);
1729 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1730 and fall into the rest of wait_for_inferior(). */
1732 context_switch (ecs
);
1735 context_hook (pid_to_thread_id (ecs
->ptid
));
1737 flush_cached_frames ();
1740 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1742 /* Pull the single step breakpoints out of the target. */
1743 SOFTWARE_SINGLE_STEP (0, 0);
1744 singlestep_breakpoints_inserted_p
= 0;
1747 /* If PC is pointing at a nullified instruction, then step beyond
1748 it so that the user won't be confused when GDB appears to be ready
1751 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1752 if (INSTRUCTION_NULLIFIED
)
1754 registers_changed ();
1755 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1757 /* We may have received a signal that we want to pass to
1758 the inferior; therefore, we must not clobber the waitstatus
1761 ecs
->infwait_state
= infwait_nullified_state
;
1762 ecs
->waiton_ptid
= ecs
->ptid
;
1763 ecs
->wp
= &(ecs
->tmpstatus
);
1764 prepare_to_wait (ecs
);
1768 /* It may not be necessary to disable the watchpoint to stop over
1769 it. For example, the PA can (with some kernel cooperation)
1770 single step over a watchpoint without disabling the watchpoint. */
1771 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1774 prepare_to_wait (ecs
);
1778 /* It is far more common to need to disable a watchpoint to step
1779 the inferior over it. FIXME. What else might a debug
1780 register or page protection watchpoint scheme need here? */
1781 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1783 /* At this point, we are stopped at an instruction which has
1784 attempted to write to a piece of memory under control of
1785 a watchpoint. The instruction hasn't actually executed
1786 yet. If we were to evaluate the watchpoint expression
1787 now, we would get the old value, and therefore no change
1788 would seem to have occurred.
1790 In order to make watchpoints work `right', we really need
1791 to complete the memory write, and then evaluate the
1792 watchpoint expression. The following code does that by
1793 removing the watchpoint (actually, all watchpoints and
1794 breakpoints), single-stepping the target, re-inserting
1795 watchpoints, and then falling through to let normal
1796 single-step processing handle proceed. Since this
1797 includes evaluating watchpoints, things will come to a
1798 stop in the correct manner. */
1800 if (DECR_PC_AFTER_BREAK
)
1801 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
1803 remove_breakpoints ();
1804 registers_changed ();
1805 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
1807 ecs
->waiton_ptid
= ecs
->ptid
;
1808 ecs
->wp
= &(ecs
->ws
);
1809 ecs
->infwait_state
= infwait_nonstep_watch_state
;
1810 prepare_to_wait (ecs
);
1814 /* It may be possible to simply continue after a watchpoint. */
1815 if (HAVE_CONTINUABLE_WATCHPOINT
)
1816 STOPPED_BY_WATCHPOINT (ecs
->ws
);
1818 ecs
->stop_func_start
= 0;
1819 ecs
->stop_func_end
= 0;
1820 ecs
->stop_func_name
= 0;
1821 /* Don't care about return value; stop_func_start and stop_func_name
1822 will both be 0 if it doesn't work. */
1823 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
1824 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
1825 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
1826 ecs
->another_trap
= 0;
1827 bpstat_clear (&stop_bpstat
);
1829 stop_stack_dummy
= 0;
1830 stop_print_frame
= 1;
1831 ecs
->random_signal
= 0;
1832 stopped_by_random_signal
= 0;
1833 breakpoints_failed
= 0;
1835 /* Look at the cause of the stop, and decide what to do.
1836 The alternatives are:
1837 1) break; to really stop and return to the debugger,
1838 2) drop through to start up again
1839 (set ecs->another_trap to 1 to single step once)
1840 3) set ecs->random_signal to 1, and the decision between 1 and 2
1841 will be made according to the signal handling tables. */
1843 /* First, distinguish signals caused by the debugger from signals
1844 that have to do with the program's own actions.
1845 Note that breakpoint insns may cause SIGTRAP or SIGILL
1846 or SIGEMT, depending on the operating system version.
1847 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1848 and change it to SIGTRAP. */
1850 if (stop_signal
== TARGET_SIGNAL_TRAP
1851 || (breakpoints_inserted
&&
1852 (stop_signal
== TARGET_SIGNAL_ILL
1853 || stop_signal
== TARGET_SIGNAL_EMT
))
1854 || stop_soon
== STOP_QUIETLY
1855 || stop_soon
== STOP_QUIETLY_NO_SIGSTOP
)
1857 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
1859 stop_print_frame
= 0;
1860 stop_stepping (ecs
);
1864 /* This is originated from start_remote(), start_inferior() and
1865 shared libraries hook functions. */
1866 if (stop_soon
== STOP_QUIETLY
)
1868 stop_stepping (ecs
);
1872 /* This originates from attach_command(). We need to overwrite
1873 the stop_signal here, because some kernels don't ignore a
1874 SIGSTOP in a subsequent ptrace(PTRACE_SONT,SOGSTOP) call.
1875 See more comments in inferior.h. */
1876 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
)
1878 stop_stepping (ecs
);
1879 if (stop_signal
== TARGET_SIGNAL_STOP
)
1880 stop_signal
= TARGET_SIGNAL_0
;
1884 /* Don't even think about breakpoints
1885 if just proceeded over a breakpoint.
1887 However, if we are trying to proceed over a breakpoint
1888 and end up in sigtramp, then through_sigtramp_breakpoint
1889 will be set and we should check whether we've hit the
1891 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
1892 && through_sigtramp_breakpoint
== NULL
)
1893 bpstat_clear (&stop_bpstat
);
1896 /* See if there is a breakpoint at the current PC. */
1898 /* The second argument of bpstat_stop_status is meant to help
1899 distinguish between a breakpoint trap and a singlestep trap.
1900 This is only important on targets where DECR_PC_AFTER_BREAK
1901 is non-zero. The prev_pc test is meant to distinguish between
1902 singlestepping a trap instruction, and singlestepping thru a
1903 jump to the instruction following a trap instruction.
1905 Therefore, pass TRUE if our reason for stopping is
1906 something other than hitting a breakpoint. We do this by
1907 checking that either: we detected earlier a software single
1908 step trap or, 1) stepping is going on and 2) we didn't hit
1909 a breakpoint in a signal handler without an intervening stop
1910 in sigtramp, which is detected by a new stack pointer value
1911 below any usual function calling stack adjustments. */
1915 sw_single_step_trap_p
1916 || (currently_stepping (ecs
)
1917 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1919 && INNER_THAN (read_sp (), (step_sp
- 16)))));
1920 /* Following in case break condition called a
1922 stop_print_frame
= 1;
1925 /* NOTE: cagney/2003-03-29: These two checks for a random signal
1926 at one stage in the past included checks for an inferior
1927 function call's call dummy's return breakpoint. The original
1928 comment, that went with the test, read:
1930 ``End of a stack dummy. Some systems (e.g. Sony news) give
1931 another signal besides SIGTRAP, so check here as well as
1934 If someone ever tries to get get call dummys on a
1935 non-executable stack to work (where the target would stop
1936 with something like a SIGSEG), then those tests might need to
1937 be re-instated. Given, however, that the tests were only
1938 enabled when momentary breakpoints were not being used, I
1939 suspect that it won't be the case. */
1941 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1943 = !(bpstat_explains_signal (stop_bpstat
)
1945 || (step_range_end
&& step_resume_breakpoint
== NULL
));
1948 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1949 if (!ecs
->random_signal
)
1950 stop_signal
= TARGET_SIGNAL_TRAP
;
1954 /* When we reach this point, we've pretty much decided
1955 that the reason for stopping must've been a random
1956 (unexpected) signal. */
1959 ecs
->random_signal
= 1;
1961 process_event_stop_test
:
1962 /* For the program's own signals, act according to
1963 the signal handling tables. */
1965 if (ecs
->random_signal
)
1967 /* Signal not for debugging purposes. */
1970 stopped_by_random_signal
= 1;
1972 if (signal_print
[stop_signal
])
1975 target_terminal_ours_for_output ();
1976 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
1978 if (signal_stop
[stop_signal
])
1980 stop_stepping (ecs
);
1983 /* If not going to stop, give terminal back
1984 if we took it away. */
1986 target_terminal_inferior ();
1988 /* Clear the signal if it should not be passed. */
1989 if (signal_program
[stop_signal
] == 0)
1990 stop_signal
= TARGET_SIGNAL_0
;
1992 /* I'm not sure whether this needs to be check_sigtramp2 or
1993 whether it could/should be keep_going.
1995 This used to jump to step_over_function if we are stepping,
1998 Suppose the user does a `next' over a function call, and while
1999 that call is in progress, the inferior receives a signal for
2000 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2001 that case, when we reach this point, there is already a
2002 step-resume breakpoint established, right where it should be:
2003 immediately after the function call the user is "next"-ing
2004 over. If we call step_over_function now, two bad things
2007 - we'll create a new breakpoint, at wherever the current
2008 frame's return address happens to be. That could be
2009 anywhere, depending on what function call happens to be on
2010 the top of the stack at that point. Point is, it's probably
2011 not where we need it.
2013 - the existing step-resume breakpoint (which is at the correct
2014 address) will get orphaned: step_resume_breakpoint will point
2015 to the new breakpoint, and the old step-resume breakpoint
2016 will never be cleaned up.
2018 The old behavior was meant to help HP-UX single-step out of
2019 sigtramps. It would place the new breakpoint at prev_pc, which
2020 was certainly wrong. I don't know the details there, so fixing
2021 this probably breaks that. As with anything else, it's up to
2022 the HP-UX maintainer to furnish a fix that doesn't break other
2023 platforms. --JimB, 20 May 1999 */
2024 check_sigtramp2 (ecs
);
2029 /* Handle cases caused by hitting a breakpoint. */
2031 CORE_ADDR jmp_buf_pc
;
2032 struct bpstat_what what
;
2034 what
= bpstat_what (stop_bpstat
);
2036 if (what
.call_dummy
)
2038 stop_stack_dummy
= 1;
2040 trap_expected_after_continue
= 1;
2044 switch (what
.main_action
)
2046 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2047 /* If we hit the breakpoint at longjmp, disable it for the
2048 duration of this command. Then, install a temporary
2049 breakpoint at the target of the jmp_buf. */
2050 disable_longjmp_breakpoint ();
2051 remove_breakpoints ();
2052 breakpoints_inserted
= 0;
2053 if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc
))
2059 /* Need to blow away step-resume breakpoint, as it
2060 interferes with us */
2061 if (step_resume_breakpoint
!= NULL
)
2063 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2065 /* Not sure whether we need to blow this away too, but probably
2066 it is like the step-resume breakpoint. */
2067 if (through_sigtramp_breakpoint
!= NULL
)
2069 delete_breakpoint (through_sigtramp_breakpoint
);
2070 through_sigtramp_breakpoint
= NULL
;
2074 /* FIXME - Need to implement nested temporary breakpoints */
2075 if (step_over_calls
> 0)
2076 set_longjmp_resume_breakpoint (jmp_buf_pc
, get_current_frame ());
2079 set_longjmp_resume_breakpoint (jmp_buf_pc
, null_frame_id
);
2080 ecs
->handling_longjmp
= 1; /* FIXME */
2084 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2085 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2086 remove_breakpoints ();
2087 breakpoints_inserted
= 0;
2089 /* FIXME - Need to implement nested temporary breakpoints */
2091 && (frame_id_inner (get_frame_id (get_current_frame ()),
2094 ecs
->another_trap
= 1;
2099 disable_longjmp_breakpoint ();
2100 ecs
->handling_longjmp
= 0; /* FIXME */
2101 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2103 /* else fallthrough */
2105 case BPSTAT_WHAT_SINGLE
:
2106 if (breakpoints_inserted
)
2108 remove_breakpoints ();
2110 breakpoints_inserted
= 0;
2111 ecs
->another_trap
= 1;
2112 /* Still need to check other stuff, at least the case
2113 where we are stepping and step out of the right range. */
2116 case BPSTAT_WHAT_STOP_NOISY
:
2117 stop_print_frame
= 1;
2119 /* We are about to nuke the step_resume_breakpoint and
2120 through_sigtramp_breakpoint via the cleanup chain, so
2121 no need to worry about it here. */
2123 stop_stepping (ecs
);
2126 case BPSTAT_WHAT_STOP_SILENT
:
2127 stop_print_frame
= 0;
2129 /* We are about to nuke the step_resume_breakpoint and
2130 through_sigtramp_breakpoint via the cleanup chain, so
2131 no need to worry about it here. */
2133 stop_stepping (ecs
);
2136 case BPSTAT_WHAT_STEP_RESUME
:
2137 /* This proably demands a more elegant solution, but, yeah
2140 This function's use of the simple variable
2141 step_resume_breakpoint doesn't seem to accomodate
2142 simultaneously active step-resume bp's, although the
2143 breakpoint list certainly can.
2145 If we reach here and step_resume_breakpoint is already
2146 NULL, then apparently we have multiple active
2147 step-resume bp's. We'll just delete the breakpoint we
2148 stopped at, and carry on.
2150 Correction: what the code currently does is delete a
2151 step-resume bp, but it makes no effort to ensure that
2152 the one deleted is the one currently stopped at. MVS */
2154 if (step_resume_breakpoint
== NULL
)
2156 step_resume_breakpoint
=
2157 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2159 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2162 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2163 if (through_sigtramp_breakpoint
)
2164 delete_breakpoint (through_sigtramp_breakpoint
);
2165 through_sigtramp_breakpoint
= NULL
;
2167 /* If were waiting for a trap, hitting the step_resume_break
2168 doesn't count as getting it. */
2170 ecs
->another_trap
= 1;
2173 case BPSTAT_WHAT_CHECK_SHLIBS
:
2174 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2177 /* Remove breakpoints, we eventually want to step over the
2178 shlib event breakpoint, and SOLIB_ADD might adjust
2179 breakpoint addresses via breakpoint_re_set. */
2180 if (breakpoints_inserted
)
2181 remove_breakpoints ();
2182 breakpoints_inserted
= 0;
2184 /* Check for any newly added shared libraries if we're
2185 supposed to be adding them automatically. Switch
2186 terminal for any messages produced by
2187 breakpoint_re_set. */
2188 target_terminal_ours_for_output ();
2189 SOLIB_ADD (NULL
, 0, &exec_ops
, auto_solib_add
);
2190 target_terminal_inferior ();
2192 /* Try to reenable shared library breakpoints, additional
2193 code segments in shared libraries might be mapped in now. */
2194 re_enable_breakpoints_in_shlibs ();
2196 /* If requested, stop when the dynamic linker notifies
2197 gdb of events. This allows the user to get control
2198 and place breakpoints in initializer routines for
2199 dynamically loaded objects (among other things). */
2200 if (stop_on_solib_events
)
2202 stop_stepping (ecs
);
2206 /* If we stopped due to an explicit catchpoint, then the
2207 (see above) call to SOLIB_ADD pulled in any symbols
2208 from a newly-loaded library, if appropriate.
2210 We do want the inferior to stop, but not where it is
2211 now, which is in the dynamic linker callback. Rather,
2212 we would like it stop in the user's program, just after
2213 the call that caused this catchpoint to trigger. That
2214 gives the user a more useful vantage from which to
2215 examine their program's state. */
2216 else if (what
.main_action
==
2217 BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2219 /* ??rehrauer: If I could figure out how to get the
2220 right return PC from here, we could just set a temp
2221 breakpoint and resume. I'm not sure we can without
2222 cracking open the dld's shared libraries and sniffing
2223 their unwind tables and text/data ranges, and that's
2224 not a terribly portable notion.
2226 Until that time, we must step the inferior out of the
2227 dld callback, and also out of the dld itself (and any
2228 code or stubs in libdld.sl, such as "shl_load" and
2229 friends) until we reach non-dld code. At that point,
2230 we can stop stepping. */
2231 bpstat_get_triggered_catchpoints (stop_bpstat
,
2233 stepping_through_solib_catchpoints
);
2234 ecs
->stepping_through_solib_after_catch
= 1;
2236 /* Be sure to lift all breakpoints, so the inferior does
2237 actually step past this point... */
2238 ecs
->another_trap
= 1;
2243 /* We want to step over this breakpoint, then keep going. */
2244 ecs
->another_trap
= 1;
2251 case BPSTAT_WHAT_LAST
:
2252 /* Not a real code, but listed here to shut up gcc -Wall. */
2254 case BPSTAT_WHAT_KEEP_CHECKING
:
2259 /* We come here if we hit a breakpoint but should not
2260 stop for it. Possibly we also were stepping
2261 and should stop for that. So fall through and
2262 test for stepping. But, if not stepping,
2265 /* Are we stepping to get the inferior out of the dynamic
2266 linker's hook (and possibly the dld itself) after catching
2268 if (ecs
->stepping_through_solib_after_catch
)
2270 #if defined(SOLIB_ADD)
2271 /* Have we reached our destination? If not, keep going. */
2272 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2274 ecs
->another_trap
= 1;
2279 /* Else, stop and report the catchpoint(s) whose triggering
2280 caused us to begin stepping. */
2281 ecs
->stepping_through_solib_after_catch
= 0;
2282 bpstat_clear (&stop_bpstat
);
2283 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2284 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2285 stop_print_frame
= 1;
2286 stop_stepping (ecs
);
2290 if (step_resume_breakpoint
)
2292 /* Having a step-resume breakpoint overrides anything
2293 else having to do with stepping commands until
2294 that breakpoint is reached. */
2295 /* I'm not sure whether this needs to be check_sigtramp2 or
2296 whether it could/should be keep_going. */
2297 check_sigtramp2 (ecs
);
2302 if (step_range_end
== 0)
2304 /* Likewise if we aren't even stepping. */
2305 /* I'm not sure whether this needs to be check_sigtramp2 or
2306 whether it could/should be keep_going. */
2307 check_sigtramp2 (ecs
);
2312 /* If stepping through a line, keep going if still within it.
2314 Note that step_range_end is the address of the first instruction
2315 beyond the step range, and NOT the address of the last instruction
2317 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
2319 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2320 So definately need to check for sigtramp here. */
2321 check_sigtramp2 (ecs
);
2326 /* We stepped out of the stepping range. */
2328 /* If we are stepping at the source level and entered the runtime
2329 loader dynamic symbol resolution code, we keep on single stepping
2330 until we exit the run time loader code and reach the callee's
2332 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2333 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2335 CORE_ADDR pc_after_resolver
=
2336 gdbarch_skip_solib_resolver (current_gdbarch
, stop_pc
);
2338 if (pc_after_resolver
)
2340 /* Set up a step-resume breakpoint at the address
2341 indicated by SKIP_SOLIB_RESOLVER. */
2342 struct symtab_and_line sr_sal
;
2344 sr_sal
.pc
= pc_after_resolver
;
2346 check_for_old_step_resume_breakpoint ();
2347 step_resume_breakpoint
=
2348 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2349 if (breakpoints_inserted
)
2350 insert_breakpoints ();
2357 /* We can't update step_sp every time through the loop, because
2358 reading the stack pointer would slow down stepping too much.
2359 But we can update it every time we leave the step range. */
2360 ecs
->update_step_sp
= 1;
2362 /* Did we just take a signal? */
2363 if (pc_in_sigtramp (stop_pc
)
2364 && !pc_in_sigtramp (prev_pc
)
2365 && INNER_THAN (read_sp (), step_sp
))
2367 /* We've just taken a signal; go until we are back to
2368 the point where we took it and one more. */
2370 /* Note: The test above succeeds not only when we stepped
2371 into a signal handler, but also when we step past the last
2372 statement of a signal handler and end up in the return stub
2373 of the signal handler trampoline. To distinguish between
2374 these two cases, check that the frame is INNER_THAN the
2375 previous one below. pai/1997-09-11 */
2379 struct frame_id current_frame
= get_frame_id (get_current_frame ());
2381 if (frame_id_inner (current_frame
, step_frame_id
))
2383 /* We have just taken a signal; go until we are back to
2384 the point where we took it and one more. */
2386 /* This code is needed at least in the following case:
2387 The user types "next" and then a signal arrives (before
2388 the "next" is done). */
2390 /* Note that if we are stopped at a breakpoint, then we need
2391 the step_resume breakpoint to override any breakpoints at
2392 the same location, so that we will still step over the
2393 breakpoint even though the signal happened. */
2394 struct symtab_and_line sr_sal
;
2397 sr_sal
.symtab
= NULL
;
2399 sr_sal
.pc
= prev_pc
;
2400 /* We could probably be setting the frame to
2401 step_frame_id; I don't think anyone thought to try it. */
2402 check_for_old_step_resume_breakpoint ();
2403 step_resume_breakpoint
=
2404 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2405 if (breakpoints_inserted
)
2406 insert_breakpoints ();
2410 /* We just stepped out of a signal handler and into
2411 its calling trampoline.
2413 Normally, we'd call step_over_function from
2414 here, but for some reason GDB can't unwind the
2415 stack correctly to find the real PC for the point
2416 user code where the signal trampoline will return
2417 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2418 But signal trampolines are pretty small stubs of
2419 code, anyway, so it's OK instead to just
2420 single-step out. Note: assuming such trampolines
2421 don't exhibit recursion on any platform... */
2422 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2423 &ecs
->stop_func_start
,
2424 &ecs
->stop_func_end
);
2425 /* Readjust stepping range */
2426 step_range_start
= ecs
->stop_func_start
;
2427 step_range_end
= ecs
->stop_func_end
;
2428 ecs
->stepping_through_sigtramp
= 1;
2433 /* If this is stepi or nexti, make sure that the stepping range
2434 gets us past that instruction. */
2435 if (step_range_end
== 1)
2436 /* FIXME: Does this run afoul of the code below which, if
2437 we step into the middle of a line, resets the stepping
2439 step_range_end
= (step_range_start
= prev_pc
) + 1;
2441 ecs
->remove_breakpoints_on_following_step
= 1;
2446 if (((stop_pc
== ecs
->stop_func_start
/* Quick test */
2447 || in_prologue (stop_pc
, ecs
->stop_func_start
))
2448 && !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2449 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2450 || ecs
->stop_func_name
== 0)
2452 /* It's a subroutine call. */
2454 if ((step_over_calls
== STEP_OVER_NONE
)
2455 || ((step_range_end
== 1)
2456 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2458 /* I presume that step_over_calls is only 0 when we're
2459 supposed to be stepping at the assembly language level
2460 ("stepi"). Just stop. */
2461 /* Also, maybe we just did a "nexti" inside a prolog,
2462 so we thought it was a subroutine call but it was not.
2463 Stop as well. FENN */
2465 print_stop_reason (END_STEPPING_RANGE
, 0);
2466 stop_stepping (ecs
);
2470 if (step_over_calls
== STEP_OVER_ALL
|| IGNORE_HELPER_CALL (stop_pc
))
2472 /* We're doing a "next". */
2474 if (pc_in_sigtramp (stop_pc
)
2475 && frame_id_inner (step_frame_id
,
2476 frame_id_build (read_sp (), 0)))
2477 /* We stepped out of a signal handler, and into its
2478 calling trampoline. This is misdetected as a
2479 subroutine call, but stepping over the signal
2480 trampoline isn't such a bad idea. In order to do that,
2481 we have to ignore the value in step_frame_id, since
2482 that doesn't represent the frame that'll reach when we
2483 return from the signal trampoline. Otherwise we'll
2484 probably continue to the end of the program. */
2485 step_frame_id
= null_frame_id
;
2487 step_over_function (ecs
);
2492 /* If we are in a function call trampoline (a stub between
2493 the calling routine and the real function), locate the real
2494 function. That's what tells us (a) whether we want to step
2495 into it at all, and (b) what prologue we want to run to
2496 the end of, if we do step into it. */
2497 real_stop_pc
= skip_language_trampoline (stop_pc
);
2498 if (real_stop_pc
== 0)
2499 real_stop_pc
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2500 if (real_stop_pc
!= 0)
2501 ecs
->stop_func_start
= real_stop_pc
;
2503 /* If we have line number information for the function we
2504 are thinking of stepping into, step into it.
2506 If there are several symtabs at that PC (e.g. with include
2507 files), just want to know whether *any* of them have line
2508 numbers. find_pc_line handles this. */
2510 struct symtab_and_line tmp_sal
;
2512 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2513 if (tmp_sal
.line
!= 0)
2515 step_into_function (ecs
);
2520 /* If we have no line number and the step-stop-if-no-debug
2521 is set, we stop the step so that the user has a chance to
2522 switch in assembly mode. */
2523 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2526 print_stop_reason (END_STEPPING_RANGE
, 0);
2527 stop_stepping (ecs
);
2531 step_over_function (ecs
);
2537 /* We've wandered out of the step range. */
2539 ecs
->sal
= find_pc_line (stop_pc
, 0);
2541 if (step_range_end
== 1)
2543 /* It is stepi or nexti. We always want to stop stepping after
2546 print_stop_reason (END_STEPPING_RANGE
, 0);
2547 stop_stepping (ecs
);
2551 /* If we're in the return path from a shared library trampoline,
2552 we want to proceed through the trampoline when stepping. */
2553 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2555 /* Determine where this trampoline returns. */
2556 real_stop_pc
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2558 /* Only proceed through if we know where it's going. */
2561 /* And put the step-breakpoint there and go until there. */
2562 struct symtab_and_line sr_sal
;
2564 init_sal (&sr_sal
); /* initialize to zeroes */
2565 sr_sal
.pc
= real_stop_pc
;
2566 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2567 /* Do not specify what the fp should be when we stop
2568 since on some machines the prologue
2569 is where the new fp value is established. */
2570 check_for_old_step_resume_breakpoint ();
2571 step_resume_breakpoint
=
2572 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2573 if (breakpoints_inserted
)
2574 insert_breakpoints ();
2576 /* Restart without fiddling with the step ranges or
2583 if (ecs
->sal
.line
== 0)
2585 /* We have no line number information. That means to stop
2586 stepping (does this always happen right after one instruction,
2587 when we do "s" in a function with no line numbers,
2588 or can this happen as a result of a return or longjmp?). */
2590 print_stop_reason (END_STEPPING_RANGE
, 0);
2591 stop_stepping (ecs
);
2595 if ((stop_pc
== ecs
->sal
.pc
)
2596 && (ecs
->current_line
!= ecs
->sal
.line
2597 || ecs
->current_symtab
!= ecs
->sal
.symtab
))
2599 /* We are at the start of a different line. So stop. Note that
2600 we don't stop if we step into the middle of a different line.
2601 That is said to make things like for (;;) statements work
2604 print_stop_reason (END_STEPPING_RANGE
, 0);
2605 stop_stepping (ecs
);
2609 /* We aren't done stepping.
2611 Optimize by setting the stepping range to the line.
2612 (We might not be in the original line, but if we entered a
2613 new line in mid-statement, we continue stepping. This makes
2614 things like for(;;) statements work better.) */
2616 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2618 /* If this is the last line of the function, don't keep stepping
2619 (it would probably step us out of the function).
2620 This is particularly necessary for a one-line function,
2621 in which after skipping the prologue we better stop even though
2622 we will be in mid-line. */
2624 print_stop_reason (END_STEPPING_RANGE
, 0);
2625 stop_stepping (ecs
);
2628 step_range_start
= ecs
->sal
.pc
;
2629 step_range_end
= ecs
->sal
.end
;
2630 step_frame_id
= get_frame_id (get_current_frame ());
2631 ecs
->current_line
= ecs
->sal
.line
;
2632 ecs
->current_symtab
= ecs
->sal
.symtab
;
2634 /* In the case where we just stepped out of a function into the
2635 middle of a line of the caller, continue stepping, but
2636 step_frame_id must be modified to current frame */
2638 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too
2639 generous. It will trigger on things like a step into a frameless
2640 stackless leaf function. I think the logic should instead look
2641 at the unwound frame ID has that should give a more robust
2642 indication of what happened. */
2643 if (step
-ID
== current
-ID
)
2644 still stepping in same function
;
2645 else if (step
-ID
== unwind (current
-ID
))
2646 stepped into a function
;
2648 stepped out of a function
;
2649 /* Of course this assumes that the frame ID unwind code is robust
2650 and we're willing to introduce frame unwind logic into this
2651 function. Fortunately, those days are nearly upon us. */
2654 struct frame_id current_frame
= get_frame_id (get_current_frame ());
2655 if (!(frame_id_inner (current_frame
, step_frame_id
)))
2656 step_frame_id
= current_frame
;
2662 /* Are we in the middle of stepping? */
2665 currently_stepping (struct execution_control_state
*ecs
)
2667 return ((through_sigtramp_breakpoint
== NULL
2668 && !ecs
->handling_longjmp
2669 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2671 || ecs
->stepping_through_solib_after_catch
2672 || bpstat_should_step ());
2676 check_sigtramp2 (struct execution_control_state
*ecs
)
2679 && pc_in_sigtramp (stop_pc
)
2680 && !pc_in_sigtramp (prev_pc
)
2681 && INNER_THAN (read_sp (), step_sp
))
2683 /* What has happened here is that we have just stepped the
2684 inferior with a signal (because it is a signal which
2685 shouldn't make us stop), thus stepping into sigtramp.
2687 So we need to set a step_resume_break_address breakpoint and
2688 continue until we hit it, and then step. FIXME: This should
2689 be more enduring than a step_resume breakpoint; we should
2690 know that we will later need to keep going rather than
2691 re-hitting the breakpoint here (see the testsuite,
2692 gdb.base/signals.exp where it says "exceedingly difficult"). */
2694 struct symtab_and_line sr_sal
;
2696 init_sal (&sr_sal
); /* initialize to zeroes */
2697 sr_sal
.pc
= prev_pc
;
2698 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2699 /* We perhaps could set the frame if we kept track of what the
2700 frame corresponding to prev_pc was. But we don't, so don't. */
2701 through_sigtramp_breakpoint
=
2702 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_through_sigtramp
);
2703 if (breakpoints_inserted
)
2704 insert_breakpoints ();
2706 ecs
->remove_breakpoints_on_following_step
= 1;
2707 ecs
->another_trap
= 1;
2711 /* Subroutine call with source code we should not step over. Do step
2712 to the first line of code in it. */
2715 step_into_function (struct execution_control_state
*ecs
)
2718 struct symtab_and_line sr_sal
;
2720 s
= find_pc_symtab (stop_pc
);
2721 if (s
&& s
->language
!= language_asm
)
2722 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2724 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2725 /* Use the step_resume_break to step until the end of the prologue,
2726 even if that involves jumps (as it seems to on the vax under
2728 /* If the prologue ends in the middle of a source line, continue to
2729 the end of that source line (if it is still within the function).
2730 Otherwise, just go to end of prologue. */
2732 && ecs
->sal
.pc
!= ecs
->stop_func_start
2733 && ecs
->sal
.end
< ecs
->stop_func_end
)
2734 ecs
->stop_func_start
= ecs
->sal
.end
;
2736 if (ecs
->stop_func_start
== stop_pc
)
2738 /* We are already there: stop now. */
2740 print_stop_reason (END_STEPPING_RANGE
, 0);
2741 stop_stepping (ecs
);
2746 /* Put the step-breakpoint there and go until there. */
2747 init_sal (&sr_sal
); /* initialize to zeroes */
2748 sr_sal
.pc
= ecs
->stop_func_start
;
2749 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
2750 /* Do not specify what the fp should be when we stop since on
2751 some machines the prologue is where the new fp value is
2753 check_for_old_step_resume_breakpoint ();
2754 step_resume_breakpoint
=
2755 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2756 if (breakpoints_inserted
)
2757 insert_breakpoints ();
2759 /* And make sure stepping stops right away then. */
2760 step_range_end
= step_range_start
;
2765 /* We've just entered a callee, and we wish to resume until it returns
2766 to the caller. Setting a step_resume breakpoint on the return
2767 address will catch a return from the callee.
2769 However, if the callee is recursing, we want to be careful not to
2770 catch returns of those recursive calls, but only of THIS instance
2773 To do this, we set the step_resume bp's frame to our current
2774 caller's frame (step_frame_id, which is set by the "next" or
2775 "until" command, before execution begins). */
2778 step_over_function (struct execution_control_state
*ecs
)
2780 struct symtab_and_line sr_sal
;
2782 init_sal (&sr_sal
); /* initialize to zeros */
2784 /* NOTE: cagney/2003-04-06:
2786 At this point the equality get_frame_pc() == get_frame_func()
2787 should hold. This may make it possible for this code to tell the
2788 frame where it's function is, instead of the reverse. This would
2789 avoid the need to search for the frame's function, which can get
2790 very messy when there is no debug info available (look at the
2791 heuristic find pc start code found in targets like the MIPS). */
2793 /* NOTE: cagney/2003-04-06:
2795 The intent of DEPRECATED_SAVED_PC_AFTER_CALL was to:
2797 - provide a very light weight equivalent to frame_unwind_pc()
2798 (nee FRAME_SAVED_PC) that avoids the prologue analyzer
2800 - avoid handling the case where the PC hasn't been saved in the
2803 Unfortunately, not five lines further down, is a call to
2804 get_frame_id() and that is guarenteed to trigger the prologue
2807 The `correct fix' is for the prologe analyzer to handle the case
2808 where the prologue is incomplete (PC in prologue) and,
2809 consequently, the return pc has not yet been saved. It should be
2810 noted that the prologue analyzer needs to handle this case
2811 anyway: frameless leaf functions that don't save the return PC;
2812 single stepping through a prologue.
2814 The d10v handles all this by bailing out of the prologue analsis
2815 when it reaches the current instruction. */
2817 if (DEPRECATED_SAVED_PC_AFTER_CALL_P ())
2818 sr_sal
.pc
= ADDR_BITS_REMOVE (DEPRECATED_SAVED_PC_AFTER_CALL (get_current_frame ()));
2820 sr_sal
.pc
= ADDR_BITS_REMOVE (frame_pc_unwind (get_current_frame ()));
2821 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2823 check_for_old_step_resume_breakpoint ();
2824 step_resume_breakpoint
=
2825 set_momentary_breakpoint (sr_sal
, get_frame_id (get_current_frame ()),
2828 if (frame_id_p (step_frame_id
)
2829 && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
2830 step_resume_breakpoint
->frame_id
= step_frame_id
;
2832 if (breakpoints_inserted
)
2833 insert_breakpoints ();
2837 stop_stepping (struct execution_control_state
*ecs
)
2839 /* Let callers know we don't want to wait for the inferior anymore. */
2840 ecs
->wait_some_more
= 0;
2843 /* This function handles various cases where we need to continue
2844 waiting for the inferior. */
2845 /* (Used to be the keep_going: label in the old wait_for_inferior) */
2848 keep_going (struct execution_control_state
*ecs
)
2850 /* Save the pc before execution, to compare with pc after stop. */
2851 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
2853 if (ecs
->update_step_sp
)
2854 step_sp
= read_sp ();
2855 ecs
->update_step_sp
= 0;
2857 /* If we did not do break;, it means we should keep running the
2858 inferior and not return to debugger. */
2860 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
2862 /* We took a signal (which we are supposed to pass through to
2863 the inferior, else we'd have done a break above) and we
2864 haven't yet gotten our trap. Simply continue. */
2865 resume (currently_stepping (ecs
), stop_signal
);
2869 /* Either the trap was not expected, but we are continuing
2870 anyway (the user asked that this signal be passed to the
2873 The signal was SIGTRAP, e.g. it was our signal, but we
2874 decided we should resume from it.
2876 We're going to run this baby now!
2878 Insert breakpoints now, unless we are trying to one-proceed
2879 past a breakpoint. */
2880 /* If we've just finished a special step resume and we don't
2881 want to hit a breakpoint, pull em out. */
2882 if (step_resume_breakpoint
== NULL
2883 && through_sigtramp_breakpoint
== NULL
2884 && ecs
->remove_breakpoints_on_following_step
)
2886 ecs
->remove_breakpoints_on_following_step
= 0;
2887 remove_breakpoints ();
2888 breakpoints_inserted
= 0;
2890 else if (!breakpoints_inserted
&&
2891 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
2893 breakpoints_failed
= insert_breakpoints ();
2894 if (breakpoints_failed
)
2896 stop_stepping (ecs
);
2899 breakpoints_inserted
= 1;
2902 trap_expected
= ecs
->another_trap
;
2904 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
2905 specifies that such a signal should be delivered to the
2908 Typically, this would occure when a user is debugging a
2909 target monitor on a simulator: the target monitor sets a
2910 breakpoint; the simulator encounters this break-point and
2911 halts the simulation handing control to GDB; GDB, noteing
2912 that the break-point isn't valid, returns control back to the
2913 simulator; the simulator then delivers the hardware
2914 equivalent of a SIGNAL_TRAP to the program being debugged. */
2916 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !signal_program
[stop_signal
])
2917 stop_signal
= TARGET_SIGNAL_0
;
2919 #ifdef SHIFT_INST_REGS
2920 /* I'm not sure when this following segment applies. I do know,
2921 now, that we shouldn't rewrite the regs when we were stopped
2922 by a random signal from the inferior process. */
2923 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2924 (this is only used on the 88k). */
2926 if (!bpstat_explains_signal (stop_bpstat
)
2927 && (stop_signal
!= TARGET_SIGNAL_CHLD
) && !stopped_by_random_signal
)
2929 #endif /* SHIFT_INST_REGS */
2931 resume (currently_stepping (ecs
), stop_signal
);
2934 prepare_to_wait (ecs
);
2937 /* This function normally comes after a resume, before
2938 handle_inferior_event exits. It takes care of any last bits of
2939 housekeeping, and sets the all-important wait_some_more flag. */
2942 prepare_to_wait (struct execution_control_state
*ecs
)
2944 if (ecs
->infwait_state
== infwait_normal_state
)
2946 overlay_cache_invalid
= 1;
2948 /* We have to invalidate the registers BEFORE calling
2949 target_wait because they can be loaded from the target while
2950 in target_wait. This makes remote debugging a bit more
2951 efficient for those targets that provide critical registers
2952 as part of their normal status mechanism. */
2954 registers_changed ();
2955 ecs
->waiton_ptid
= pid_to_ptid (-1);
2956 ecs
->wp
= &(ecs
->ws
);
2958 /* This is the old end of the while loop. Let everybody know we
2959 want to wait for the inferior some more and get called again
2961 ecs
->wait_some_more
= 1;
2964 /* Print why the inferior has stopped. We always print something when
2965 the inferior exits, or receives a signal. The rest of the cases are
2966 dealt with later on in normal_stop() and print_it_typical(). Ideally
2967 there should be a call to this function from handle_inferior_event()
2968 each time stop_stepping() is called.*/
2970 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
2972 switch (stop_reason
)
2975 /* We don't deal with these cases from handle_inferior_event()
2978 case END_STEPPING_RANGE
:
2979 /* We are done with a step/next/si/ni command. */
2980 /* For now print nothing. */
2981 /* Print a message only if not in the middle of doing a "step n"
2982 operation for n > 1 */
2983 if (!step_multi
|| !stop_step
)
2984 if (ui_out_is_mi_like_p (uiout
))
2985 ui_out_field_string (uiout
, "reason", "end-stepping-range");
2987 case BREAKPOINT_HIT
:
2988 /* We found a breakpoint. */
2989 /* For now print nothing. */
2992 /* The inferior was terminated by a signal. */
2993 annotate_signalled ();
2994 if (ui_out_is_mi_like_p (uiout
))
2995 ui_out_field_string (uiout
, "reason", "exited-signalled");
2996 ui_out_text (uiout
, "\nProgram terminated with signal ");
2997 annotate_signal_name ();
2998 ui_out_field_string (uiout
, "signal-name",
2999 target_signal_to_name (stop_info
));
3000 annotate_signal_name_end ();
3001 ui_out_text (uiout
, ", ");
3002 annotate_signal_string ();
3003 ui_out_field_string (uiout
, "signal-meaning",
3004 target_signal_to_string (stop_info
));
3005 annotate_signal_string_end ();
3006 ui_out_text (uiout
, ".\n");
3007 ui_out_text (uiout
, "The program no longer exists.\n");
3010 /* The inferior program is finished. */
3011 annotate_exited (stop_info
);
3014 if (ui_out_is_mi_like_p (uiout
))
3015 ui_out_field_string (uiout
, "reason", "exited");
3016 ui_out_text (uiout
, "\nProgram exited with code ");
3017 ui_out_field_fmt (uiout
, "exit-code", "0%o",
3018 (unsigned int) stop_info
);
3019 ui_out_text (uiout
, ".\n");
3023 if (ui_out_is_mi_like_p (uiout
))
3024 ui_out_field_string (uiout
, "reason", "exited-normally");
3025 ui_out_text (uiout
, "\nProgram exited normally.\n");
3028 case SIGNAL_RECEIVED
:
3029 /* Signal received. The signal table tells us to print about
3032 ui_out_text (uiout
, "\nProgram received signal ");
3033 annotate_signal_name ();
3034 if (ui_out_is_mi_like_p (uiout
))
3035 ui_out_field_string (uiout
, "reason", "signal-received");
3036 ui_out_field_string (uiout
, "signal-name",
3037 target_signal_to_name (stop_info
));
3038 annotate_signal_name_end ();
3039 ui_out_text (uiout
, ", ");
3040 annotate_signal_string ();
3041 ui_out_field_string (uiout
, "signal-meaning",
3042 target_signal_to_string (stop_info
));
3043 annotate_signal_string_end ();
3044 ui_out_text (uiout
, ".\n");
3047 internal_error (__FILE__
, __LINE__
,
3048 "print_stop_reason: unrecognized enum value");
3054 /* Here to return control to GDB when the inferior stops for real.
3055 Print appropriate messages, remove breakpoints, give terminal our modes.
3057 STOP_PRINT_FRAME nonzero means print the executing frame
3058 (pc, function, args, file, line number and line text).
3059 BREAKPOINTS_FAILED nonzero means stop was due to error
3060 attempting to insert breakpoints. */
3065 struct target_waitstatus last
;
3068 get_last_target_status (&last_ptid
, &last
);
3070 /* As with the notification of thread events, we want to delay
3071 notifying the user that we've switched thread context until
3072 the inferior actually stops.
3074 There's no point in saying anything if the inferior has exited.
3075 Note that SIGNALLED here means "exited with a signal", not
3076 "received a signal". */
3077 if (!ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3078 && target_has_execution
3079 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
3080 && last
.kind
!= TARGET_WAITKIND_EXITED
)
3082 target_terminal_ours_for_output ();
3083 printf_filtered ("[Switching to %s]\n",
3084 target_pid_or_tid_to_str (inferior_ptid
));
3085 previous_inferior_ptid
= inferior_ptid
;
3088 /* Make sure that the current_frame's pc is correct. This
3089 is a correction for setting up the frame info before doing
3090 DECR_PC_AFTER_BREAK */
3091 if (target_has_execution
)
3092 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3093 DECR_PC_AFTER_BREAK, the program counter can change. Ask the
3094 frame code to check for this and sort out any resultant mess.
3095 DECR_PC_AFTER_BREAK needs to just go away. */
3096 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3098 if (target_has_execution
&& breakpoints_inserted
)
3100 if (remove_breakpoints ())
3102 target_terminal_ours_for_output ();
3103 printf_filtered ("Cannot remove breakpoints because ");
3104 printf_filtered ("program is no longer writable.\n");
3105 printf_filtered ("It might be running in another process.\n");
3106 printf_filtered ("Further execution is probably impossible.\n");
3109 breakpoints_inserted
= 0;
3111 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3112 Delete any breakpoint that is to be deleted at the next stop. */
3114 breakpoint_auto_delete (stop_bpstat
);
3116 /* If an auto-display called a function and that got a signal,
3117 delete that auto-display to avoid an infinite recursion. */
3119 if (stopped_by_random_signal
)
3120 disable_current_display ();
3122 /* Don't print a message if in the middle of doing a "step n"
3123 operation for n > 1 */
3124 if (step_multi
&& stop_step
)
3127 target_terminal_ours ();
3129 /* Look up the hook_stop and run it (CLI internally handles problem
3130 of stop_command's pre-hook not existing). */
3132 catch_errors (hook_stop_stub
, stop_command
,
3133 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3135 if (!target_has_stack
)
3141 /* Select innermost stack frame - i.e., current frame is frame 0,
3142 and current location is based on that.
3143 Don't do this on return from a stack dummy routine,
3144 or if the program has exited. */
3146 if (!stop_stack_dummy
)
3148 select_frame (get_current_frame ());
3150 /* Print current location without a level number, if
3151 we have changed functions or hit a breakpoint.
3152 Print source line if we have one.
3153 bpstat_print() contains the logic deciding in detail
3154 what to print, based on the event(s) that just occurred. */
3156 if (stop_print_frame
&& deprecated_selected_frame
)
3160 int do_frame_printing
= 1;
3162 bpstat_ret
= bpstat_print (stop_bpstat
);
3166 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3167 (or should) carry around the function and does (or
3168 should) use that when doing a frame comparison. */
3170 && frame_id_eq (step_frame_id
,
3171 get_frame_id (get_current_frame ()))
3172 && step_start_function
== find_pc_function (stop_pc
))
3173 source_flag
= SRC_LINE
; /* finished step, just print source line */
3175 source_flag
= SRC_AND_LOC
; /* print location and source line */
3177 case PRINT_SRC_AND_LOC
:
3178 source_flag
= SRC_AND_LOC
; /* print location and source line */
3180 case PRINT_SRC_ONLY
:
3181 source_flag
= SRC_LINE
;
3184 source_flag
= SRC_LINE
; /* something bogus */
3185 do_frame_printing
= 0;
3188 internal_error (__FILE__
, __LINE__
, "Unknown value.");
3190 /* For mi, have the same behavior every time we stop:
3191 print everything but the source line. */
3192 if (ui_out_is_mi_like_p (uiout
))
3193 source_flag
= LOC_AND_ADDRESS
;
3195 if (ui_out_is_mi_like_p (uiout
))
3196 ui_out_field_int (uiout
, "thread-id",
3197 pid_to_thread_id (inferior_ptid
));
3198 /* The behavior of this routine with respect to the source
3200 SRC_LINE: Print only source line
3201 LOCATION: Print only location
3202 SRC_AND_LOC: Print location and source line */
3203 if (do_frame_printing
)
3204 print_stack_frame (deprecated_selected_frame
, -1, source_flag
);
3206 /* Display the auto-display expressions. */
3211 /* Save the function value return registers, if we care.
3212 We might be about to restore their previous contents. */
3213 if (proceed_to_finish
)
3214 /* NB: The copy goes through to the target picking up the value of
3215 all the registers. */
3216 regcache_cpy (stop_registers
, current_regcache
);
3218 if (stop_stack_dummy
)
3220 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3221 ends with a setting of the current frame, so we can use that
3223 frame_pop (get_current_frame ());
3224 /* Set stop_pc to what it was before we called the function.
3225 Can't rely on restore_inferior_status because that only gets
3226 called if we don't stop in the called function. */
3227 stop_pc
= read_pc ();
3228 select_frame (get_current_frame ());
3232 annotate_stopped ();
3233 observer_notify_normal_stop ();
3237 hook_stop_stub (void *cmd
)
3239 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3244 signal_stop_state (int signo
)
3246 return signal_stop
[signo
];
3250 signal_print_state (int signo
)
3252 return signal_print
[signo
];
3256 signal_pass_state (int signo
)
3258 return signal_program
[signo
];
3262 signal_stop_update (int signo
, int state
)
3264 int ret
= signal_stop
[signo
];
3265 signal_stop
[signo
] = state
;
3270 signal_print_update (int signo
, int state
)
3272 int ret
= signal_print
[signo
];
3273 signal_print
[signo
] = state
;
3278 signal_pass_update (int signo
, int state
)
3280 int ret
= signal_program
[signo
];
3281 signal_program
[signo
] = state
;
3286 sig_print_header (void)
3289 Signal Stop\tPrint\tPass to program\tDescription\n");
3293 sig_print_info (enum target_signal oursig
)
3295 char *name
= target_signal_to_name (oursig
);
3296 int name_padding
= 13 - strlen (name
);
3298 if (name_padding
<= 0)
3301 printf_filtered ("%s", name
);
3302 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
3303 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3304 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3305 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3306 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3309 /* Specify how various signals in the inferior should be handled. */
3312 handle_command (char *args
, int from_tty
)
3315 int digits
, wordlen
;
3316 int sigfirst
, signum
, siglast
;
3317 enum target_signal oursig
;
3320 unsigned char *sigs
;
3321 struct cleanup
*old_chain
;
3325 error_no_arg ("signal to handle");
3328 /* Allocate and zero an array of flags for which signals to handle. */
3330 nsigs
= (int) TARGET_SIGNAL_LAST
;
3331 sigs
= (unsigned char *) alloca (nsigs
);
3332 memset (sigs
, 0, nsigs
);
3334 /* Break the command line up into args. */
3336 argv
= buildargv (args
);
3341 old_chain
= make_cleanup_freeargv (argv
);
3343 /* Walk through the args, looking for signal oursigs, signal names, and
3344 actions. Signal numbers and signal names may be interspersed with
3345 actions, with the actions being performed for all signals cumulatively
3346 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3348 while (*argv
!= NULL
)
3350 wordlen
= strlen (*argv
);
3351 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3355 sigfirst
= siglast
= -1;
3357 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3359 /* Apply action to all signals except those used by the
3360 debugger. Silently skip those. */
3363 siglast
= nsigs
- 1;
3365 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3367 SET_SIGS (nsigs
, sigs
, signal_stop
);
3368 SET_SIGS (nsigs
, sigs
, signal_print
);
3370 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3372 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3374 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3376 SET_SIGS (nsigs
, sigs
, signal_print
);
3378 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3380 SET_SIGS (nsigs
, sigs
, signal_program
);
3382 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3384 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3386 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3388 SET_SIGS (nsigs
, sigs
, signal_program
);
3390 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3392 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3393 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3395 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3397 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3399 else if (digits
> 0)
3401 /* It is numeric. The numeric signal refers to our own
3402 internal signal numbering from target.h, not to host/target
3403 signal number. This is a feature; users really should be
3404 using symbolic names anyway, and the common ones like
3405 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3407 sigfirst
= siglast
= (int)
3408 target_signal_from_command (atoi (*argv
));
3409 if ((*argv
)[digits
] == '-')
3412 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3414 if (sigfirst
> siglast
)
3416 /* Bet he didn't figure we'd think of this case... */
3424 oursig
= target_signal_from_name (*argv
);
3425 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3427 sigfirst
= siglast
= (int) oursig
;
3431 /* Not a number and not a recognized flag word => complain. */
3432 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3436 /* If any signal numbers or symbol names were found, set flags for
3437 which signals to apply actions to. */
3439 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3441 switch ((enum target_signal
) signum
)
3443 case TARGET_SIGNAL_TRAP
:
3444 case TARGET_SIGNAL_INT
:
3445 if (!allsigs
&& !sigs
[signum
])
3447 if (query ("%s is used by the debugger.\n\
3448 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
3454 printf_unfiltered ("Not confirmed, unchanged.\n");
3455 gdb_flush (gdb_stdout
);
3459 case TARGET_SIGNAL_0
:
3460 case TARGET_SIGNAL_DEFAULT
:
3461 case TARGET_SIGNAL_UNKNOWN
:
3462 /* Make sure that "all" doesn't print these. */
3473 target_notice_signals (inferior_ptid
);
3477 /* Show the results. */
3478 sig_print_header ();
3479 for (signum
= 0; signum
< nsigs
; signum
++)
3483 sig_print_info (signum
);
3488 do_cleanups (old_chain
);
3492 xdb_handle_command (char *args
, int from_tty
)
3495 struct cleanup
*old_chain
;
3497 /* Break the command line up into args. */
3499 argv
= buildargv (args
);
3504 old_chain
= make_cleanup_freeargv (argv
);
3505 if (argv
[1] != (char *) NULL
)
3510 bufLen
= strlen (argv
[0]) + 20;
3511 argBuf
= (char *) xmalloc (bufLen
);
3515 enum target_signal oursig
;
3517 oursig
= target_signal_from_name (argv
[0]);
3518 memset (argBuf
, 0, bufLen
);
3519 if (strcmp (argv
[1], "Q") == 0)
3520 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3523 if (strcmp (argv
[1], "s") == 0)
3525 if (!signal_stop
[oursig
])
3526 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3528 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3530 else if (strcmp (argv
[1], "i") == 0)
3532 if (!signal_program
[oursig
])
3533 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3535 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3537 else if (strcmp (argv
[1], "r") == 0)
3539 if (!signal_print
[oursig
])
3540 sprintf (argBuf
, "%s %s", argv
[0], "print");
3542 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3548 handle_command (argBuf
, from_tty
);
3550 printf_filtered ("Invalid signal handling flag.\n");
3555 do_cleanups (old_chain
);
3558 /* Print current contents of the tables set by the handle command.
3559 It is possible we should just be printing signals actually used
3560 by the current target (but for things to work right when switching
3561 targets, all signals should be in the signal tables). */
3564 signals_info (char *signum_exp
, int from_tty
)
3566 enum target_signal oursig
;
3567 sig_print_header ();
3571 /* First see if this is a symbol name. */
3572 oursig
= target_signal_from_name (signum_exp
);
3573 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3575 /* No, try numeric. */
3577 target_signal_from_command (parse_and_eval_long (signum_exp
));
3579 sig_print_info (oursig
);
3583 printf_filtered ("\n");
3584 /* These ugly casts brought to you by the native VAX compiler. */
3585 for (oursig
= TARGET_SIGNAL_FIRST
;
3586 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3587 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3591 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3592 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
3593 sig_print_info (oursig
);
3596 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3599 struct inferior_status
3601 enum target_signal stop_signal
;
3605 int stop_stack_dummy
;
3606 int stopped_by_random_signal
;
3608 CORE_ADDR step_range_start
;
3609 CORE_ADDR step_range_end
;
3610 struct frame_id step_frame_id
;
3611 enum step_over_calls_kind step_over_calls
;
3612 CORE_ADDR step_resume_break_address
;
3613 int stop_after_trap
;
3615 struct regcache
*stop_registers
;
3617 /* These are here because if call_function_by_hand has written some
3618 registers and then decides to call error(), we better not have changed
3620 struct regcache
*registers
;
3622 /* A frame unique identifier. */
3623 struct frame_id selected_frame_id
;
3625 int breakpoint_proceeded
;
3626 int restore_stack_info
;
3627 int proceed_to_finish
;
3631 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3634 int size
= DEPRECATED_REGISTER_RAW_SIZE (regno
);
3635 void *buf
= alloca (size
);
3636 store_signed_integer (buf
, size
, val
);
3637 regcache_raw_write (inf_status
->registers
, regno
, buf
);
3640 /* Save all of the information associated with the inferior<==>gdb
3641 connection. INF_STATUS is a pointer to a "struct inferior_status"
3642 (defined in inferior.h). */
3644 struct inferior_status
*
3645 save_inferior_status (int restore_stack_info
)
3647 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
3649 inf_status
->stop_signal
= stop_signal
;
3650 inf_status
->stop_pc
= stop_pc
;
3651 inf_status
->stop_step
= stop_step
;
3652 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3653 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3654 inf_status
->trap_expected
= trap_expected
;
3655 inf_status
->step_range_start
= step_range_start
;
3656 inf_status
->step_range_end
= step_range_end
;
3657 inf_status
->step_frame_id
= step_frame_id
;
3658 inf_status
->step_over_calls
= step_over_calls
;
3659 inf_status
->stop_after_trap
= stop_after_trap
;
3660 inf_status
->stop_soon
= stop_soon
;
3661 /* Save original bpstat chain here; replace it with copy of chain.
3662 If caller's caller is walking the chain, they'll be happier if we
3663 hand them back the original chain when restore_inferior_status is
3665 inf_status
->stop_bpstat
= stop_bpstat
;
3666 stop_bpstat
= bpstat_copy (stop_bpstat
);
3667 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3668 inf_status
->restore_stack_info
= restore_stack_info
;
3669 inf_status
->proceed_to_finish
= proceed_to_finish
;
3671 inf_status
->stop_registers
= regcache_dup_no_passthrough (stop_registers
);
3673 inf_status
->registers
= regcache_dup (current_regcache
);
3675 inf_status
->selected_frame_id
= get_frame_id (deprecated_selected_frame
);
3680 restore_selected_frame (void *args
)
3682 struct frame_id
*fid
= (struct frame_id
*) args
;
3683 struct frame_info
*frame
;
3685 frame
= frame_find_by_id (*fid
);
3687 /* If inf_status->selected_frame_id is NULL, there was no previously
3691 warning ("Unable to restore previously selected frame.\n");
3695 select_frame (frame
);
3701 restore_inferior_status (struct inferior_status
*inf_status
)
3703 stop_signal
= inf_status
->stop_signal
;
3704 stop_pc
= inf_status
->stop_pc
;
3705 stop_step
= inf_status
->stop_step
;
3706 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3707 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3708 trap_expected
= inf_status
->trap_expected
;
3709 step_range_start
= inf_status
->step_range_start
;
3710 step_range_end
= inf_status
->step_range_end
;
3711 step_frame_id
= inf_status
->step_frame_id
;
3712 step_over_calls
= inf_status
->step_over_calls
;
3713 stop_after_trap
= inf_status
->stop_after_trap
;
3714 stop_soon
= inf_status
->stop_soon
;
3715 bpstat_clear (&stop_bpstat
);
3716 stop_bpstat
= inf_status
->stop_bpstat
;
3717 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3718 proceed_to_finish
= inf_status
->proceed_to_finish
;
3720 /* FIXME: Is the restore of stop_registers always needed. */
3721 regcache_xfree (stop_registers
);
3722 stop_registers
= inf_status
->stop_registers
;
3724 /* The inferior can be gone if the user types "print exit(0)"
3725 (and perhaps other times). */
3726 if (target_has_execution
)
3727 /* NB: The register write goes through to the target. */
3728 regcache_cpy (current_regcache
, inf_status
->registers
);
3729 regcache_xfree (inf_status
->registers
);
3731 /* FIXME: If we are being called after stopping in a function which
3732 is called from gdb, we should not be trying to restore the
3733 selected frame; it just prints a spurious error message (The
3734 message is useful, however, in detecting bugs in gdb (like if gdb
3735 clobbers the stack)). In fact, should we be restoring the
3736 inferior status at all in that case? . */
3738 if (target_has_stack
&& inf_status
->restore_stack_info
)
3740 /* The point of catch_errors is that if the stack is clobbered,
3741 walking the stack might encounter a garbage pointer and
3742 error() trying to dereference it. */
3744 (restore_selected_frame
, &inf_status
->selected_frame_id
,
3745 "Unable to restore previously selected frame:\n",
3746 RETURN_MASK_ERROR
) == 0)
3747 /* Error in restoring the selected frame. Select the innermost
3749 select_frame (get_current_frame ());
3757 do_restore_inferior_status_cleanup (void *sts
)
3759 restore_inferior_status (sts
);
3763 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
3765 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
3769 discard_inferior_status (struct inferior_status
*inf_status
)
3771 /* See save_inferior_status for info on stop_bpstat. */
3772 bpstat_clear (&inf_status
->stop_bpstat
);
3773 regcache_xfree (inf_status
->registers
);
3774 regcache_xfree (inf_status
->stop_registers
);
3779 inferior_has_forked (int pid
, int *child_pid
)
3781 struct target_waitstatus last
;
3784 get_last_target_status (&last_ptid
, &last
);
3786 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
3789 if (ptid_get_pid (last_ptid
) != pid
)
3792 *child_pid
= last
.value
.related_pid
;
3797 inferior_has_vforked (int pid
, int *child_pid
)
3799 struct target_waitstatus last
;
3802 get_last_target_status (&last_ptid
, &last
);
3804 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
3807 if (ptid_get_pid (last_ptid
) != pid
)
3810 *child_pid
= last
.value
.related_pid
;
3815 inferior_has_execd (int pid
, char **execd_pathname
)
3817 struct target_waitstatus last
;
3820 get_last_target_status (&last_ptid
, &last
);
3822 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
3825 if (ptid_get_pid (last_ptid
) != pid
)
3828 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
3832 /* Oft used ptids */
3834 ptid_t minus_one_ptid
;
3836 /* Create a ptid given the necessary PID, LWP, and TID components. */
3839 ptid_build (int pid
, long lwp
, long tid
)
3849 /* Create a ptid from just a pid. */
3852 pid_to_ptid (int pid
)
3854 return ptid_build (pid
, 0, 0);
3857 /* Fetch the pid (process id) component from a ptid. */
3860 ptid_get_pid (ptid_t ptid
)
3865 /* Fetch the lwp (lightweight process) component from a ptid. */
3868 ptid_get_lwp (ptid_t ptid
)
3873 /* Fetch the tid (thread id) component from a ptid. */
3876 ptid_get_tid (ptid_t ptid
)
3881 /* ptid_equal() is used to test equality of two ptids. */
3884 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
3886 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
3887 && ptid1
.tid
== ptid2
.tid
);
3890 /* restore_inferior_ptid() will be used by the cleanup machinery
3891 to restore the inferior_ptid value saved in a call to
3892 save_inferior_ptid(). */
3895 restore_inferior_ptid (void *arg
)
3897 ptid_t
*saved_ptid_ptr
= arg
;
3898 inferior_ptid
= *saved_ptid_ptr
;
3902 /* Save the value of inferior_ptid so that it may be restored by a
3903 later call to do_cleanups(). Returns the struct cleanup pointer
3904 needed for later doing the cleanup. */
3907 save_inferior_ptid (void)
3909 ptid_t
*saved_ptid_ptr
;
3911 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
3912 *saved_ptid_ptr
= inferior_ptid
;
3913 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
3920 stop_registers
= regcache_xmalloc (current_gdbarch
);
3924 _initialize_infrun (void)
3928 struct cmd_list_element
*c
;
3930 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
3931 register_gdbarch_swap (NULL
, 0, build_infrun
);
3933 add_info ("signals", signals_info
,
3934 "What debugger does when program gets various signals.\n\
3935 Specify a signal as argument to print info on that signal only.");
3936 add_info_alias ("handle", "signals", 0);
3938 add_com ("handle", class_run
, handle_command
,
3939 concat ("Specify how to handle a signal.\n\
3940 Args are signals and actions to apply to those signals.\n\
3941 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3942 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3943 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3944 The special arg \"all\" is recognized to mean all signals except those\n\
3945 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3946 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3947 Stop means reenter debugger if this signal happens (implies print).\n\
3948 Print means print a message if this signal happens.\n\
3949 Pass means let program see this signal; otherwise program doesn't know.\n\
3950 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3951 Pass and Stop may be combined.", NULL
));
3954 add_com ("lz", class_info
, signals_info
,
3955 "What debugger does when program gets various signals.\n\
3956 Specify a signal as argument to print info on that signal only.");
3957 add_com ("z", class_run
, xdb_handle_command
,
3958 concat ("Specify how to handle a signal.\n\
3959 Args are signals and actions to apply to those signals.\n\
3960 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3961 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3962 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3963 The special arg \"all\" is recognized to mean all signals except those\n\
3964 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3965 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3966 nopass), \"Q\" (noprint)\n\
3967 Stop means reenter debugger if this signal happens (implies print).\n\
3968 Print means print a message if this signal happens.\n\
3969 Pass means let program see this signal; otherwise program doesn't know.\n\
3970 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3971 Pass and Stop may be combined.", NULL
));
3976 add_cmd ("stop", class_obscure
, not_just_help_class_command
, "There is no `stop' command, but you can set a hook on `stop'.\n\
3977 This allows you to set a list of commands to be run each time execution\n\
3978 of the program stops.", &cmdlist
);
3980 numsigs
= (int) TARGET_SIGNAL_LAST
;
3981 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
3982 signal_print
= (unsigned char *)
3983 xmalloc (sizeof (signal_print
[0]) * numsigs
);
3984 signal_program
= (unsigned char *)
3985 xmalloc (sizeof (signal_program
[0]) * numsigs
);
3986 for (i
= 0; i
< numsigs
; i
++)
3989 signal_print
[i
] = 1;
3990 signal_program
[i
] = 1;
3993 /* Signals caused by debugger's own actions
3994 should not be given to the program afterwards. */
3995 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
3996 signal_program
[TARGET_SIGNAL_INT
] = 0;
3998 /* Signals that are not errors should not normally enter the debugger. */
3999 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4000 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4001 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4002 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4003 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4004 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4005 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4006 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4007 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4008 signal_print
[TARGET_SIGNAL_IO
] = 0;
4009 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4010 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4011 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4012 signal_print
[TARGET_SIGNAL_URG
] = 0;
4013 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4014 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4016 /* These signals are used internally by user-level thread
4017 implementations. (See signal(5) on Solaris.) Like the above
4018 signals, a healthy program receives and handles them as part of
4019 its normal operation. */
4020 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4021 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4022 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4023 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4024 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4025 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4029 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4030 (char *) &stop_on_solib_events
,
4031 "Set stopping for shared library events.\n\
4032 If nonzero, gdb will give control to the user when the dynamic linker\n\
4033 notifies gdb of shared library events. The most common event of interest\n\
4034 to the user would be loading/unloading of a new library.\n", &setlist
), &showlist
);
4037 c
= add_set_enum_cmd ("follow-fork-mode",
4039 follow_fork_mode_kind_names
, &follow_fork_mode_string
,
4040 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4041 kernel problem. It's also not terribly useful without a GUI to
4042 help the user drive two debuggers. So for now, I'm disabling
4043 the "both" option. */
4044 /* "Set debugger response to a program call of fork \
4046 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4047 parent - the original process is debugged after a fork\n\
4048 child - the new process is debugged after a fork\n\
4049 both - both the parent and child are debugged after a fork\n\
4050 ask - the debugger will ask for one of the above choices\n\
4051 For \"both\", another copy of the debugger will be started to follow\n\
4052 the new child process. The original debugger will continue to follow\n\
4053 the original parent process. To distinguish their prompts, the\n\
4054 debugger copy's prompt will be changed.\n\
4055 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4056 By default, the debugger will follow the parent process.",
4058 "Set debugger response to a program call of fork \
4060 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4061 parent - the original process is debugged after a fork\n\
4062 child - the new process is debugged after a fork\n\
4063 ask - the debugger will ask for one of the above choices\n\
4064 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4065 By default, the debugger will follow the parent process.", &setlist
);
4066 add_show_from_set (c
, &showlist
);
4068 c
= add_set_enum_cmd ("scheduler-locking", class_run
, scheduler_enums
, /* array of string names */
4069 &scheduler_mode
, /* current mode */
4070 "Set mode for locking scheduler during execution.\n\
4071 off == no locking (threads may preempt at any time)\n\
4072 on == full locking (no thread except the current thread may run)\n\
4073 step == scheduler locked during every single-step operation.\n\
4074 In this mode, no other thread may run during a step command.\n\
4075 Other threads may run while stepping over a function call ('next').", &setlist
);
4077 set_cmd_sfunc (c
, set_schedlock_func
); /* traps on target vector */
4078 add_show_from_set (c
, &showlist
);
4080 c
= add_set_cmd ("step-mode", class_run
,
4081 var_boolean
, (char *) &step_stop_if_no_debug
,
4082 "Set mode of the step operation. When set, doing a step over a\n\
4083 function without debug line information will stop at the first\n\
4084 instruction of that function. Otherwise, the function is skipped and\n\
4085 the step command stops at a different source line.", &setlist
);
4086 add_show_from_set (c
, &showlist
);
4088 /* ptid initializations */
4089 null_ptid
= ptid_build (0, 0, 0);
4090 minus_one_ptid
= ptid_build (-1, 0, 0);
4091 inferior_ptid
= null_ptid
;
4092 target_last_wait_ptid
= minus_one_ptid
;