1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
5 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
26 #include "gdb_string.h"
31 #include "breakpoint.h"
35 #include "cli/cli-script.h"
37 #include "gdbthread.h"
47 /* Prototypes for local functions */
49 static void signals_info (char *, int);
51 static void handle_command (char *, int);
53 static void sig_print_info (enum target_signal
);
55 static void sig_print_header (void);
57 static void resume_cleanups (void *);
59 static int hook_stop_stub (void *);
61 static void delete_breakpoint_current_contents (void *);
63 static void set_follow_fork_mode_command (char *arg
, int from_tty
,
64 struct cmd_list_element
*c
);
66 static int restore_selected_frame (void *);
68 static void build_infrun (void);
70 static int follow_fork (void);
72 static void set_schedlock_func (char *args
, int from_tty
,
73 struct cmd_list_element
*c
);
75 struct execution_control_state
;
77 static int currently_stepping (struct execution_control_state
*ecs
);
79 static void xdb_handle_command (char *args
, int from_tty
);
81 void _initialize_infrun (void);
83 int inferior_ignoring_startup_exec_events
= 0;
84 int inferior_ignoring_leading_exec_events
= 0;
86 /* When set, stop the 'step' command if we enter a function which has
87 no line number information. The normal behavior is that we step
88 over such function. */
89 int step_stop_if_no_debug
= 0;
91 /* In asynchronous mode, but simulating synchronous execution. */
93 int sync_execution
= 0;
95 /* wait_for_inferior and normal_stop use this to notify the user
96 when the inferior stopped in a different thread than it had been
99 static ptid_t previous_inferior_ptid
;
101 /* This is true for configurations that may follow through execl() and
102 similar functions. At present this is only true for HP-UX native. */
104 #ifndef MAY_FOLLOW_EXEC
105 #define MAY_FOLLOW_EXEC (0)
108 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
110 /* If the program uses ELF-style shared libraries, then calls to
111 functions in shared libraries go through stubs, which live in a
112 table called the PLT (Procedure Linkage Table). The first time the
113 function is called, the stub sends control to the dynamic linker,
114 which looks up the function's real address, patches the stub so
115 that future calls will go directly to the function, and then passes
116 control to the function.
118 If we are stepping at the source level, we don't want to see any of
119 this --- we just want to skip over the stub and the dynamic linker.
120 The simple approach is to single-step until control leaves the
123 However, on some systems (e.g., Red Hat's 5.2 distribution) the
124 dynamic linker calls functions in the shared C library, so you
125 can't tell from the PC alone whether the dynamic linker is still
126 running. In this case, we use a step-resume breakpoint to get us
127 past the dynamic linker, as if we were using "next" to step over a
130 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
131 linker code or not. Normally, this means we single-step. However,
132 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
133 address where we can place a step-resume breakpoint to get past the
134 linker's symbol resolution function.
136 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
137 pretty portable way, by comparing the PC against the address ranges
138 of the dynamic linker's sections.
140 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
141 it depends on internal details of the dynamic linker. It's usually
142 not too hard to figure out where to put a breakpoint, but it
143 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
144 sanity checking. If it can't figure things out, returning zero and
145 getting the (possibly confusing) stepping behavior is better than
146 signalling an error, which will obscure the change in the
149 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
150 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
153 #ifndef SKIP_SOLIB_RESOLVER
154 #define SKIP_SOLIB_RESOLVER(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 int stop_soon_quietly
;
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 (). */
497 resume_cleanups (void *ignore
)
502 static const char schedlock_off
[] = "off";
503 static const char schedlock_on
[] = "on";
504 static const char schedlock_step
[] = "step";
505 static const char *scheduler_mode
= schedlock_off
;
506 static const char *scheduler_enums
[] = {
514 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
516 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
517 the set command passed as a parameter. The clone operation will
518 include (BUG?) any ``set'' command callback, if present.
519 Commands like ``info set'' call all the ``show'' command
520 callbacks. Unfortunatly, for ``show'' commands cloned from
521 ``set'', this includes callbacks belonging to ``set'' commands.
522 Making this worse, this only occures if add_show_from_set() is
523 called after add_cmd_sfunc() (BUG?). */
524 if (cmd_type (c
) == set_cmd
)
525 if (!target_can_lock_scheduler
)
527 scheduler_mode
= schedlock_off
;
528 error ("Target '%s' cannot support this command.", target_shortname
);
533 /* Resume the inferior, but allow a QUIT. This is useful if the user
534 wants to interrupt some lengthy single-stepping operation
535 (for child processes, the SIGINT goes to the inferior, and so
536 we get a SIGINT random_signal, but for remote debugging and perhaps
537 other targets, that's not true).
539 STEP nonzero if we should step (zero to continue instead).
540 SIG is the signal to give the inferior (zero for none). */
542 resume (int step
, enum target_signal sig
)
544 int should_resume
= 1;
545 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
548 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
551 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
552 over an instruction that causes a page fault without triggering
553 a hardware watchpoint. The kernel properly notices that it shouldn't
554 stop, because the hardware watchpoint is not triggered, but it forgets
555 the step request and continues the program normally.
556 Work around the problem by removing hardware watchpoints if a step is
557 requested, GDB will check for a hardware watchpoint trigger after the
559 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
560 remove_hw_watchpoints ();
563 /* Normally, by the time we reach `resume', the breakpoints are either
564 removed or inserted, as appropriate. The exception is if we're sitting
565 at a permanent breakpoint; we need to step over it, but permanent
566 breakpoints can't be removed. So we have to test for it here. */
567 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
568 SKIP_PERMANENT_BREAKPOINT ();
570 if (SOFTWARE_SINGLE_STEP_P () && step
)
572 /* Do it the hard way, w/temp breakpoints */
573 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
574 /* ...and don't ask hardware to do it. */
576 /* and do not pull these breakpoints until after a `wait' in
577 `wait_for_inferior' */
578 singlestep_breakpoints_inserted_p
= 1;
581 /* Handle any optimized stores to the inferior NOW... */
582 #ifdef DO_DEFERRED_STORES
586 /* If there were any forks/vforks/execs that were caught and are
587 now to be followed, then do so. */
588 switch (pending_follow
.kind
)
590 case TARGET_WAITKIND_FORKED
:
591 case TARGET_WAITKIND_VFORKED
:
592 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
597 case TARGET_WAITKIND_EXECD
:
598 /* follow_exec is called as soon as the exec event is seen. */
599 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
606 /* Install inferior's terminal modes. */
607 target_terminal_inferior ();
613 resume_ptid
= RESUME_ALL
; /* Default */
615 if ((step
|| singlestep_breakpoints_inserted_p
) &&
616 !breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
618 /* Stepping past a breakpoint without inserting breakpoints.
619 Make sure only the current thread gets to step, so that
620 other threads don't sneak past breakpoints while they are
623 resume_ptid
= inferior_ptid
;
626 if ((scheduler_mode
== schedlock_on
) ||
627 (scheduler_mode
== schedlock_step
&&
628 (step
|| singlestep_breakpoints_inserted_p
)))
630 /* User-settable 'scheduler' mode requires solo thread resume. */
631 resume_ptid
= inferior_ptid
;
634 if (CANNOT_STEP_BREAKPOINT
)
636 /* Most targets can step a breakpoint instruction, thus
637 executing it normally. But if this one cannot, just
638 continue and we will hit it anyway. */
639 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
642 target_resume (resume_ptid
, step
, sig
);
645 discard_cleanups (old_cleanups
);
649 /* Clear out all variables saying what to do when inferior is continued.
650 First do this, then set the ones you want, then call `proceed'. */
653 clear_proceed_status (void)
656 step_range_start
= 0;
658 step_frame_id
= null_frame_id
;
659 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
661 stop_soon_quietly
= 0;
662 proceed_to_finish
= 0;
663 breakpoint_proceeded
= 1; /* We're about to proceed... */
665 /* Discard any remaining commands or status from previous stop. */
666 bpstat_clear (&stop_bpstat
);
669 /* Basic routine for continuing the program in various fashions.
671 ADDR is the address to resume at, or -1 for resume where stopped.
672 SIGGNAL is the signal to give it, or 0 for none,
673 or -1 for act according to how it stopped.
674 STEP is nonzero if should trap after one instruction.
675 -1 means return after that and print nothing.
676 You should probably set various step_... variables
677 before calling here, if you are stepping.
679 You should call clear_proceed_status before calling proceed. */
682 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
687 step_start_function
= find_pc_function (read_pc ());
691 if (addr
== (CORE_ADDR
) -1)
693 /* If there is a breakpoint at the address we will resume at,
694 step one instruction before inserting breakpoints
695 so that we do not stop right away (and report a second
696 hit at this breakpoint). */
698 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
701 #ifndef STEP_SKIPS_DELAY
702 #define STEP_SKIPS_DELAY(pc) (0)
703 #define STEP_SKIPS_DELAY_P (0)
705 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
706 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
707 is slow (it needs to read memory from the target). */
708 if (STEP_SKIPS_DELAY_P
709 && breakpoint_here_p (read_pc () + 4)
710 && STEP_SKIPS_DELAY (read_pc ()))
718 #ifdef PREPARE_TO_PROCEED
719 /* In a multi-threaded task we may select another thread
720 and then continue or step.
722 But if the old thread was stopped at a breakpoint, it
723 will immediately cause another breakpoint stop without
724 any execution (i.e. it will report a breakpoint hit
725 incorrectly). So we must step over it first.
727 PREPARE_TO_PROCEED checks the current thread against the thread
728 that reported the most recent event. If a step-over is required
729 it returns TRUE and sets the current thread to the old thread. */
730 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
735 #endif /* PREPARE_TO_PROCEED */
738 if (trap_expected_after_continue
)
740 /* If (step == 0), a trap will be automatically generated after
741 the first instruction is executed. Force step one
742 instruction to clear this condition. This should not occur
743 if step is nonzero, but it is harmless in that case. */
745 trap_expected_after_continue
= 0;
747 #endif /* HP_OS_BUG */
750 /* We will get a trace trap after one instruction.
751 Continue it automatically and insert breakpoints then. */
755 insert_breakpoints ();
756 /* If we get here there was no call to error() in
757 insert breakpoints -- so they were inserted. */
758 breakpoints_inserted
= 1;
761 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
762 stop_signal
= siggnal
;
763 /* If this signal should not be seen by program,
764 give it zero. Used for debugging signals. */
765 else if (!signal_program
[stop_signal
])
766 stop_signal
= TARGET_SIGNAL_0
;
768 annotate_starting ();
770 /* Make sure that output from GDB appears before output from the
772 gdb_flush (gdb_stdout
);
774 /* Resume inferior. */
775 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
777 /* Wait for it to stop (if not standalone)
778 and in any case decode why it stopped, and act accordingly. */
779 /* Do this only if we are not using the event loop, or if the target
780 does not support asynchronous execution. */
781 if (!event_loop_p
|| !target_can_async_p ())
783 wait_for_inferior ();
788 /* Record the pc and sp of the program the last time it stopped.
789 These are just used internally by wait_for_inferior, but need
790 to be preserved over calls to it and cleared when the inferior
792 static CORE_ADDR prev_pc
;
793 static CORE_ADDR prev_func_start
;
794 static char *prev_func_name
;
797 /* Start remote-debugging of a machine over a serial link. */
803 init_wait_for_inferior ();
804 stop_soon_quietly
= 1;
807 /* Always go on waiting for the target, regardless of the mode. */
808 /* FIXME: cagney/1999-09-23: At present it isn't possible to
809 indicate to wait_for_inferior that a target should timeout if
810 nothing is returned (instead of just blocking). Because of this,
811 targets expecting an immediate response need to, internally, set
812 things up so that the target_wait() is forced to eventually
814 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
815 differentiate to its caller what the state of the target is after
816 the initial open has been performed. Here we're assuming that
817 the target has stopped. It should be possible to eventually have
818 target_open() return to the caller an indication that the target
819 is currently running and GDB state should be set to the same as
821 wait_for_inferior ();
825 /* Initialize static vars when a new inferior begins. */
828 init_wait_for_inferior (void)
830 /* These are meaningless until the first time through wait_for_inferior. */
833 prev_func_name
= NULL
;
836 trap_expected_after_continue
= 0;
838 breakpoints_inserted
= 0;
839 breakpoint_init_inferior (inf_starting
);
841 /* Don't confuse first call to proceed(). */
842 stop_signal
= TARGET_SIGNAL_0
;
844 /* The first resume is not following a fork/vfork/exec. */
845 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
847 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
848 number_of_threads_in_syscalls
= 0;
850 clear_proceed_status ();
854 delete_breakpoint_current_contents (void *arg
)
856 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
857 if (*breakpointp
!= NULL
)
859 delete_breakpoint (*breakpointp
);
864 /* This enum encodes possible reasons for doing a target_wait, so that
865 wfi can call target_wait in one place. (Ultimately the call will be
866 moved out of the infinite loop entirely.) */
870 infwait_normal_state
,
871 infwait_thread_hop_state
,
872 infwait_nullified_state
,
873 infwait_nonstep_watch_state
876 /* Why did the inferior stop? Used to print the appropriate messages
877 to the interface from within handle_inferior_event(). */
878 enum inferior_stop_reason
880 /* We don't know why. */
882 /* Step, next, nexti, stepi finished. */
884 /* Found breakpoint. */
886 /* Inferior terminated by signal. */
888 /* Inferior exited. */
890 /* Inferior received signal, and user asked to be notified. */
894 /* This structure contains what used to be local variables in
895 wait_for_inferior. Probably many of them can return to being
896 locals in handle_inferior_event. */
898 struct execution_control_state
900 struct target_waitstatus ws
;
901 struct target_waitstatus
*wp
;
904 CORE_ADDR stop_func_start
;
905 CORE_ADDR stop_func_end
;
906 char *stop_func_name
;
907 struct symtab_and_line sal
;
908 int remove_breakpoints_on_following_step
;
910 struct symtab
*current_symtab
;
911 int handling_longjmp
; /* FIXME */
913 ptid_t saved_inferior_ptid
;
915 int stepping_through_solib_after_catch
;
916 bpstat stepping_through_solib_catchpoints
;
917 int enable_hw_watchpoints_after_wait
;
918 int stepping_through_sigtramp
;
919 int new_thread_event
;
920 struct target_waitstatus tmpstatus
;
921 enum infwait_states infwait_state
;
926 void init_execution_control_state (struct execution_control_state
*ecs
);
928 void handle_inferior_event (struct execution_control_state
*ecs
);
930 static void check_sigtramp2 (struct execution_control_state
*ecs
);
931 static void step_into_function (struct execution_control_state
*ecs
);
932 static void step_over_function (struct execution_control_state
*ecs
);
933 static void stop_stepping (struct execution_control_state
*ecs
);
934 static void prepare_to_wait (struct execution_control_state
*ecs
);
935 static void keep_going (struct execution_control_state
*ecs
);
936 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
939 /* Wait for control to return from inferior to debugger.
940 If inferior gets a signal, we may decide to start it up again
941 instead of returning. That is why there is a loop in this function.
942 When this function actually returns it means the inferior
943 should be left stopped and GDB should read more commands. */
946 wait_for_inferior (void)
948 struct cleanup
*old_cleanups
;
949 struct execution_control_state ecss
;
950 struct execution_control_state
*ecs
;
952 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
953 &step_resume_breakpoint
);
954 make_cleanup (delete_breakpoint_current_contents
,
955 &through_sigtramp_breakpoint
);
957 /* wfi still stays in a loop, so it's OK just to take the address of
958 a local to get the ecs pointer. */
961 /* Fill in with reasonable starting values. */
962 init_execution_control_state (ecs
);
964 /* We'll update this if & when we switch to a new thread. */
965 previous_inferior_ptid
= inferior_ptid
;
967 overlay_cache_invalid
= 1;
969 /* We have to invalidate the registers BEFORE calling target_wait
970 because they can be loaded from the target while in target_wait.
971 This makes remote debugging a bit more efficient for those
972 targets that provide critical registers as part of their normal
975 registers_changed ();
979 if (target_wait_hook
)
980 ecs
->ptid
= target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
982 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
984 /* Now figure out what to do with the result of the result. */
985 handle_inferior_event (ecs
);
987 if (!ecs
->wait_some_more
)
990 do_cleanups (old_cleanups
);
993 /* Asynchronous version of wait_for_inferior. It is called by the
994 event loop whenever a change of state is detected on the file
995 descriptor corresponding to the target. It can be called more than
996 once to complete a single execution command. In such cases we need
997 to keep the state in a global variable ASYNC_ECSS. If it is the
998 last time that this function is called for a single execution
999 command, then report to the user that the inferior has stopped, and
1000 do the necessary cleanups. */
1002 struct execution_control_state async_ecss
;
1003 struct execution_control_state
*async_ecs
;
1006 fetch_inferior_event (void *client_data
)
1008 static struct cleanup
*old_cleanups
;
1010 async_ecs
= &async_ecss
;
1012 if (!async_ecs
->wait_some_more
)
1014 old_cleanups
= make_exec_cleanup (delete_step_resume_breakpoint
,
1015 &step_resume_breakpoint
);
1016 make_exec_cleanup (delete_breakpoint_current_contents
,
1017 &through_sigtramp_breakpoint
);
1019 /* Fill in with reasonable starting values. */
1020 init_execution_control_state (async_ecs
);
1022 /* We'll update this if & when we switch to a new thread. */
1023 previous_inferior_ptid
= inferior_ptid
;
1025 overlay_cache_invalid
= 1;
1027 /* We have to invalidate the registers BEFORE calling target_wait
1028 because they can be loaded from the target while in target_wait.
1029 This makes remote debugging a bit more efficient for those
1030 targets that provide critical registers as part of their normal
1031 status mechanism. */
1033 registers_changed ();
1036 if (target_wait_hook
)
1038 target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1040 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1042 /* Now figure out what to do with the result of the result. */
1043 handle_inferior_event (async_ecs
);
1045 if (!async_ecs
->wait_some_more
)
1047 /* Do only the cleanups that have been added by this
1048 function. Let the continuations for the commands do the rest,
1049 if there are any. */
1050 do_exec_cleanups (old_cleanups
);
1052 if (step_multi
&& stop_step
)
1053 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1055 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1059 /* Prepare an execution control state for looping through a
1060 wait_for_inferior-type loop. */
1063 init_execution_control_state (struct execution_control_state
*ecs
)
1065 /* ecs->another_trap? */
1066 ecs
->random_signal
= 0;
1067 ecs
->remove_breakpoints_on_following_step
= 0;
1068 ecs
->handling_longjmp
= 0; /* FIXME */
1069 ecs
->update_step_sp
= 0;
1070 ecs
->stepping_through_solib_after_catch
= 0;
1071 ecs
->stepping_through_solib_catchpoints
= NULL
;
1072 ecs
->enable_hw_watchpoints_after_wait
= 0;
1073 ecs
->stepping_through_sigtramp
= 0;
1074 ecs
->sal
= find_pc_line (prev_pc
, 0);
1075 ecs
->current_line
= ecs
->sal
.line
;
1076 ecs
->current_symtab
= ecs
->sal
.symtab
;
1077 ecs
->infwait_state
= infwait_normal_state
;
1078 ecs
->waiton_ptid
= pid_to_ptid (-1);
1079 ecs
->wp
= &(ecs
->ws
);
1082 /* Call this function before setting step_resume_breakpoint, as a
1083 sanity check. There should never be more than one step-resume
1084 breakpoint per thread, so we should never be setting a new
1085 step_resume_breakpoint when one is already active. */
1087 check_for_old_step_resume_breakpoint (void)
1089 if (step_resume_breakpoint
)
1091 ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1094 /* Return the cached copy of the last pid/waitstatus returned by
1095 target_wait()/target_wait_hook(). The data is actually cached by
1096 handle_inferior_event(), which gets called immediately after
1097 target_wait()/target_wait_hook(). */
1100 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
1102 *ptidp
= target_last_wait_ptid
;
1103 *status
= target_last_waitstatus
;
1106 /* Switch thread contexts, maintaining "infrun state". */
1109 context_switch (struct execution_control_state
*ecs
)
1111 /* Caution: it may happen that the new thread (or the old one!)
1112 is not in the thread list. In this case we must not attempt
1113 to "switch context", or we run the risk that our context may
1114 be lost. This may happen as a result of the target module
1115 mishandling thread creation. */
1117 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1118 { /* Perform infrun state context switch: */
1119 /* Save infrun state for the old thread. */
1120 save_infrun_state (inferior_ptid
, prev_pc
,
1121 prev_func_start
, prev_func_name
,
1122 trap_expected
, step_resume_breakpoint
,
1123 through_sigtramp_breakpoint
, step_range_start
,
1124 step_range_end
, &step_frame_id
,
1125 ecs
->handling_longjmp
, ecs
->another_trap
,
1126 ecs
->stepping_through_solib_after_catch
,
1127 ecs
->stepping_through_solib_catchpoints
,
1128 ecs
->stepping_through_sigtramp
,
1129 ecs
->current_line
, ecs
->current_symtab
, step_sp
);
1131 /* Load infrun state for the new thread. */
1132 load_infrun_state (ecs
->ptid
, &prev_pc
,
1133 &prev_func_start
, &prev_func_name
,
1134 &trap_expected
, &step_resume_breakpoint
,
1135 &through_sigtramp_breakpoint
, &step_range_start
,
1136 &step_range_end
, &step_frame_id
,
1137 &ecs
->handling_longjmp
, &ecs
->another_trap
,
1138 &ecs
->stepping_through_solib_after_catch
,
1139 &ecs
->stepping_through_solib_catchpoints
,
1140 &ecs
->stepping_through_sigtramp
,
1141 &ecs
->current_line
, &ecs
->current_symtab
, &step_sp
);
1143 inferior_ptid
= ecs
->ptid
;
1147 /* Given an execution control state that has been freshly filled in
1148 by an event from the inferior, figure out what it means and take
1149 appropriate action. */
1152 handle_inferior_event (struct execution_control_state
*ecs
)
1154 CORE_ADDR real_stop_pc
;
1155 int stepped_after_stopped_by_watchpoint
;
1156 int sw_single_step_trap_p
= 0;
1158 /* Cache the last pid/waitstatus. */
1159 target_last_wait_ptid
= ecs
->ptid
;
1160 target_last_waitstatus
= *ecs
->wp
;
1162 switch (ecs
->infwait_state
)
1164 case infwait_thread_hop_state
:
1165 /* Cancel the waiton_ptid. */
1166 ecs
->waiton_ptid
= pid_to_ptid (-1);
1167 /* Fall thru to the normal_state case. */
1169 case infwait_normal_state
:
1170 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1171 is serviced in this loop, below. */
1172 if (ecs
->enable_hw_watchpoints_after_wait
)
1174 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1175 ecs
->enable_hw_watchpoints_after_wait
= 0;
1177 stepped_after_stopped_by_watchpoint
= 0;
1180 case infwait_nullified_state
:
1183 case infwait_nonstep_watch_state
:
1184 insert_breakpoints ();
1186 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1187 handle things like signals arriving and other things happening
1188 in combination correctly? */
1189 stepped_after_stopped_by_watchpoint
= 1;
1192 ecs
->infwait_state
= infwait_normal_state
;
1194 flush_cached_frames ();
1196 /* If it's a new process, add it to the thread database */
1198 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
1199 && !in_thread_list (ecs
->ptid
));
1201 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1202 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
1204 add_thread (ecs
->ptid
);
1206 ui_out_text (uiout
, "[New ");
1207 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->ptid
));
1208 ui_out_text (uiout
, "]\n");
1211 /* NOTE: This block is ONLY meant to be invoked in case of a
1212 "thread creation event"! If it is invoked for any other
1213 sort of event (such as a new thread landing on a breakpoint),
1214 the event will be discarded, which is almost certainly
1217 To avoid this, the low-level module (eg. target_wait)
1218 should call in_thread_list and add_thread, so that the
1219 new thread is known by the time we get here. */
1221 /* We may want to consider not doing a resume here in order
1222 to give the user a chance to play with the new thread.
1223 It might be good to make that a user-settable option. */
1225 /* At this point, all threads are stopped (happens
1226 automatically in either the OS or the native code).
1227 Therefore we need to continue all threads in order to
1230 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1231 prepare_to_wait (ecs
);
1236 switch (ecs
->ws
.kind
)
1238 case TARGET_WAITKIND_LOADED
:
1239 /* Ignore gracefully during startup of the inferior, as it
1240 might be the shell which has just loaded some objects,
1241 otherwise add the symbols for the newly loaded objects. */
1243 if (!stop_soon_quietly
)
1245 /* Remove breakpoints, SOLIB_ADD might adjust
1246 breakpoint addresses via breakpoint_re_set. */
1247 if (breakpoints_inserted
)
1248 remove_breakpoints ();
1250 /* Check for any newly added shared libraries if we're
1251 supposed to be adding them automatically. Switch
1252 terminal for any messages produced by
1253 breakpoint_re_set. */
1254 target_terminal_ours_for_output ();
1255 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
1256 target_terminal_inferior ();
1258 /* Reinsert breakpoints and continue. */
1259 if (breakpoints_inserted
)
1260 insert_breakpoints ();
1263 resume (0, TARGET_SIGNAL_0
);
1264 prepare_to_wait (ecs
);
1267 case TARGET_WAITKIND_SPURIOUS
:
1268 resume (0, TARGET_SIGNAL_0
);
1269 prepare_to_wait (ecs
);
1272 case TARGET_WAITKIND_EXITED
:
1273 target_terminal_ours (); /* Must do this before mourn anyway */
1274 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1276 /* Record the exit code in the convenience variable $_exitcode, so
1277 that the user can inspect this again later. */
1278 set_internalvar (lookup_internalvar ("_exitcode"),
1279 value_from_longest (builtin_type_int
,
1280 (LONGEST
) ecs
->ws
.value
.integer
));
1281 gdb_flush (gdb_stdout
);
1282 target_mourn_inferior ();
1283 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1284 stop_print_frame
= 0;
1285 stop_stepping (ecs
);
1288 case TARGET_WAITKIND_SIGNALLED
:
1289 stop_print_frame
= 0;
1290 stop_signal
= ecs
->ws
.value
.sig
;
1291 target_terminal_ours (); /* Must do this before mourn anyway */
1293 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1294 reach here unless the inferior is dead. However, for years
1295 target_kill() was called here, which hints that fatal signals aren't
1296 really fatal on some systems. If that's true, then some changes
1298 target_mourn_inferior ();
1300 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1301 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1302 stop_stepping (ecs
);
1305 /* The following are the only cases in which we keep going;
1306 the above cases end in a continue or goto. */
1307 case TARGET_WAITKIND_FORKED
:
1308 case TARGET_WAITKIND_VFORKED
:
1309 stop_signal
= TARGET_SIGNAL_TRAP
;
1310 pending_follow
.kind
= ecs
->ws
.kind
;
1312 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1313 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1315 stop_pc
= read_pc ();
1317 /* Assume that catchpoints are not really software breakpoints. If
1318 some future target implements them using software breakpoints then
1319 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1320 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1321 bpstat_stop_status will not decrement the PC. */
1323 stop_bpstat
= bpstat_stop_status (&stop_pc
, 1);
1325 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1327 /* If no catchpoint triggered for this, then keep going. */
1328 if (ecs
->random_signal
)
1330 stop_signal
= TARGET_SIGNAL_0
;
1334 goto process_event_stop_test
;
1336 case TARGET_WAITKIND_EXECD
:
1337 stop_signal
= TARGET_SIGNAL_TRAP
;
1339 /* NOTE drow/2002-12-05: This code should be pushed down into the
1340 target_wait function. Until then following vfork on HP/UX 10.20
1341 is probably broken by this. Of course, it's broken anyway. */
1342 /* Is this a target which reports multiple exec events per actual
1343 call to exec()? (HP-UX using ptrace does, for example.) If so,
1344 ignore all but the last one. Just resume the exec'r, and wait
1345 for the next exec event. */
1346 if (inferior_ignoring_leading_exec_events
)
1348 inferior_ignoring_leading_exec_events
--;
1349 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1350 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.
1352 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1353 prepare_to_wait (ecs
);
1356 inferior_ignoring_leading_exec_events
=
1357 target_reported_exec_events_per_exec_call () - 1;
1359 pending_follow
.execd_pathname
=
1360 savestring (ecs
->ws
.value
.execd_pathname
,
1361 strlen (ecs
->ws
.value
.execd_pathname
));
1363 /* This causes the eventpoints and symbol table to be reset. Must
1364 do this now, before trying to determine whether to stop. */
1365 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1366 xfree (pending_follow
.execd_pathname
);
1368 stop_pc
= read_pc_pid (ecs
->ptid
);
1369 ecs
->saved_inferior_ptid
= inferior_ptid
;
1370 inferior_ptid
= ecs
->ptid
;
1372 /* Assume that catchpoints are not really software breakpoints. If
1373 some future target implements them using software breakpoints then
1374 that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus
1375 we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that
1376 bpstat_stop_status will not decrement the PC. */
1378 stop_bpstat
= bpstat_stop_status (&stop_pc
, 1);
1380 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1381 inferior_ptid
= ecs
->saved_inferior_ptid
;
1383 /* If no catchpoint triggered for this, then keep going. */
1384 if (ecs
->random_signal
)
1386 stop_signal
= TARGET_SIGNAL_0
;
1390 goto process_event_stop_test
;
1392 /* These syscall events are returned on HP-UX, as part of its
1393 implementation of page-protection-based "hardware" watchpoints.
1394 HP-UX has unfortunate interactions between page-protections and
1395 some system calls. Our solution is to disable hardware watches
1396 when a system call is entered, and reenable them when the syscall
1397 completes. The downside of this is that we may miss the precise
1398 point at which a watched piece of memory is modified. "Oh well."
1400 Note that we may have multiple threads running, which may each
1401 enter syscalls at roughly the same time. Since we don't have a
1402 good notion currently of whether a watched piece of memory is
1403 thread-private, we'd best not have any page-protections active
1404 when any thread is in a syscall. Thus, we only want to reenable
1405 hardware watches when no threads are in a syscall.
1407 Also, be careful not to try to gather much state about a thread
1408 that's in a syscall. It's frequently a losing proposition. */
1409 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1410 number_of_threads_in_syscalls
++;
1411 if (number_of_threads_in_syscalls
== 1)
1413 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1415 resume (0, TARGET_SIGNAL_0
);
1416 prepare_to_wait (ecs
);
1419 /* Before examining the threads further, step this thread to
1420 get it entirely out of the syscall. (We get notice of the
1421 event when the thread is just on the verge of exiting a
1422 syscall. Stepping one instruction seems to get it back
1425 Note that although the logical place to reenable h/w watches
1426 is here, we cannot. We cannot reenable them before stepping
1427 the thread (this causes the next wait on the thread to hang).
1429 Nor can we enable them after stepping until we've done a wait.
1430 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1431 here, which will be serviced immediately after the target
1433 case TARGET_WAITKIND_SYSCALL_RETURN
:
1434 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1436 if (number_of_threads_in_syscalls
> 0)
1438 number_of_threads_in_syscalls
--;
1439 ecs
->enable_hw_watchpoints_after_wait
=
1440 (number_of_threads_in_syscalls
== 0);
1442 prepare_to_wait (ecs
);
1445 case TARGET_WAITKIND_STOPPED
:
1446 stop_signal
= ecs
->ws
.value
.sig
;
1449 /* We had an event in the inferior, but we are not interested
1450 in handling it at this level. The lower layers have already
1451 done what needs to be done, if anything.
1453 One of the possible circumstances for this is when the
1454 inferior produces output for the console. The inferior has
1455 not stopped, and we are ignoring the event. Another possible
1456 circumstance is any event which the lower level knows will be
1457 reported multiple times without an intervening resume. */
1458 case TARGET_WAITKIND_IGNORE
:
1459 prepare_to_wait (ecs
);
1463 /* We may want to consider not doing a resume here in order to give
1464 the user a chance to play with the new thread. It might be good
1465 to make that a user-settable option. */
1467 /* At this point, all threads are stopped (happens automatically in
1468 either the OS or the native code). Therefore we need to continue
1469 all threads in order to make progress. */
1470 if (ecs
->new_thread_event
)
1472 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1473 prepare_to_wait (ecs
);
1477 stop_pc
= read_pc_pid (ecs
->ptid
);
1479 /* See if a thread hit a thread-specific breakpoint that was meant for
1480 another thread. If so, then step that thread past the breakpoint,
1483 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1485 /* Check if a regular breakpoint has been hit before checking
1486 for a potential single step breakpoint. Otherwise, GDB will
1487 not see this breakpoint hit when stepping onto breakpoints. */
1488 if (breakpoints_inserted
1489 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1491 ecs
->random_signal
= 0;
1492 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1497 /* Saw a breakpoint, but it was hit by the wrong thread.
1499 if (DECR_PC_AFTER_BREAK
)
1500 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->ptid
);
1502 remove_status
= remove_breakpoints ();
1503 /* Did we fail to remove breakpoints? If so, try
1504 to set the PC past the bp. (There's at least
1505 one situation in which we can fail to remove
1506 the bp's: On HP-UX's that use ttrace, we can't
1507 change the address space of a vforking child
1508 process until the child exits (well, okay, not
1509 then either :-) or execs. */
1510 if (remove_status
!= 0)
1512 /* FIXME! This is obviously non-portable! */
1513 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->ptid
);
1514 /* We need to restart all the threads now,
1515 * unles we're running in scheduler-locked mode.
1516 * Use currently_stepping to determine whether to
1519 /* FIXME MVS: is there any reason not to call resume()? */
1520 if (scheduler_mode
== schedlock_on
)
1521 target_resume (ecs
->ptid
,
1522 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1524 target_resume (RESUME_ALL
,
1525 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1526 prepare_to_wait (ecs
);
1531 breakpoints_inserted
= 0;
1532 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
1533 context_switch (ecs
);
1534 ecs
->waiton_ptid
= ecs
->ptid
;
1535 ecs
->wp
= &(ecs
->ws
);
1536 ecs
->another_trap
= 1;
1538 ecs
->infwait_state
= infwait_thread_hop_state
;
1540 registers_changed ();
1545 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1547 /* Readjust the stop_pc as it is off by DECR_PC_AFTER_BREAK
1548 compared to the value it would have if the system stepping
1549 capability was used. This allows the rest of the code in
1550 this function to use this address without having to worry
1551 whether software single step is in use or not. */
1552 if (DECR_PC_AFTER_BREAK
)
1554 stop_pc
-= DECR_PC_AFTER_BREAK
;
1555 write_pc_pid (stop_pc
, ecs
->ptid
);
1558 sw_single_step_trap_p
= 1;
1559 ecs
->random_signal
= 0;
1563 ecs
->random_signal
= 1;
1565 /* See if something interesting happened to the non-current thread. If
1566 so, then switch to that thread, and eventually give control back to
1569 Note that if there's any kind of pending follow (i.e., of a fork,
1570 vfork or exec), we don't want to do this now. Rather, we'll let
1571 the next resume handle it. */
1572 if (!ptid_equal (ecs
->ptid
, inferior_ptid
) &&
1573 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1577 /* If it's a random signal for a non-current thread, notify user
1578 if he's expressed an interest. */
1579 if (ecs
->random_signal
&& signal_print
[stop_signal
])
1581 /* ??rehrauer: I don't understand the rationale for this code. If the
1582 inferior will stop as a result of this signal, then the act of handling
1583 the stop ought to print a message that's couches the stoppage in user
1584 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1585 won't stop as a result of the signal -- i.e., if the signal is merely
1586 a side-effect of something GDB's doing "under the covers" for the
1587 user, such as stepping threads over a breakpoint they shouldn't stop
1588 for -- then the message seems to be a serious annoyance at best.
1590 For now, remove the message altogether. */
1593 target_terminal_ours_for_output ();
1594 printf_filtered ("\nProgram received signal %s, %s.\n",
1595 target_signal_to_name (stop_signal
),
1596 target_signal_to_string (stop_signal
));
1597 gdb_flush (gdb_stdout
);
1601 /* If it's not SIGTRAP and not a signal we want to stop for, then
1602 continue the thread. */
1604 if (stop_signal
!= TARGET_SIGNAL_TRAP
&& !signal_stop
[stop_signal
])
1607 target_terminal_inferior ();
1609 /* Clear the signal if it should not be passed. */
1610 if (signal_program
[stop_signal
] == 0)
1611 stop_signal
= TARGET_SIGNAL_0
;
1613 target_resume (ecs
->ptid
, 0, stop_signal
);
1614 prepare_to_wait (ecs
);
1618 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1619 and fall into the rest of wait_for_inferior(). */
1621 context_switch (ecs
);
1624 context_hook (pid_to_thread_id (ecs
->ptid
));
1626 flush_cached_frames ();
1629 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1631 /* Pull the single step breakpoints out of the target. */
1632 SOFTWARE_SINGLE_STEP (0, 0);
1633 singlestep_breakpoints_inserted_p
= 0;
1636 /* If PC is pointing at a nullified instruction, then step beyond
1637 it so that the user won't be confused when GDB appears to be ready
1640 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1641 if (INSTRUCTION_NULLIFIED
)
1643 registers_changed ();
1644 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1646 /* We may have received a signal that we want to pass to
1647 the inferior; therefore, we must not clobber the waitstatus
1650 ecs
->infwait_state
= infwait_nullified_state
;
1651 ecs
->waiton_ptid
= ecs
->ptid
;
1652 ecs
->wp
= &(ecs
->tmpstatus
);
1653 prepare_to_wait (ecs
);
1657 /* It may not be necessary to disable the watchpoint to stop over
1658 it. For example, the PA can (with some kernel cooperation)
1659 single step over a watchpoint without disabling the watchpoint. */
1660 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1663 prepare_to_wait (ecs
);
1667 /* It is far more common to need to disable a watchpoint to step
1668 the inferior over it. FIXME. What else might a debug
1669 register or page protection watchpoint scheme need here? */
1670 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1672 /* At this point, we are stopped at an instruction which has
1673 attempted to write to a piece of memory under control of
1674 a watchpoint. The instruction hasn't actually executed
1675 yet. If we were to evaluate the watchpoint expression
1676 now, we would get the old value, and therefore no change
1677 would seem to have occurred.
1679 In order to make watchpoints work `right', we really need
1680 to complete the memory write, and then evaluate the
1681 watchpoint expression. The following code does that by
1682 removing the watchpoint (actually, all watchpoints and
1683 breakpoints), single-stepping the target, re-inserting
1684 watchpoints, and then falling through to let normal
1685 single-step processing handle proceed. Since this
1686 includes evaluating watchpoints, things will come to a
1687 stop in the correct manner. */
1689 if (DECR_PC_AFTER_BREAK
)
1690 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
1692 remove_breakpoints ();
1693 registers_changed ();
1694 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
1696 ecs
->waiton_ptid
= ecs
->ptid
;
1697 ecs
->wp
= &(ecs
->ws
);
1698 ecs
->infwait_state
= infwait_nonstep_watch_state
;
1699 prepare_to_wait (ecs
);
1703 /* It may be possible to simply continue after a watchpoint. */
1704 if (HAVE_CONTINUABLE_WATCHPOINT
)
1705 STOPPED_BY_WATCHPOINT (ecs
->ws
);
1707 ecs
->stop_func_start
= 0;
1708 ecs
->stop_func_end
= 0;
1709 ecs
->stop_func_name
= 0;
1710 /* Don't care about return value; stop_func_start and stop_func_name
1711 will both be 0 if it doesn't work. */
1712 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
1713 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
1714 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
1715 ecs
->another_trap
= 0;
1716 bpstat_clear (&stop_bpstat
);
1718 stop_stack_dummy
= 0;
1719 stop_print_frame
= 1;
1720 ecs
->random_signal
= 0;
1721 stopped_by_random_signal
= 0;
1722 breakpoints_failed
= 0;
1724 /* Look at the cause of the stop, and decide what to do.
1725 The alternatives are:
1726 1) break; to really stop and return to the debugger,
1727 2) drop through to start up again
1728 (set ecs->another_trap to 1 to single step once)
1729 3) set ecs->random_signal to 1, and the decision between 1 and 2
1730 will be made according to the signal handling tables. */
1732 /* First, distinguish signals caused by the debugger from signals
1733 that have to do with the program's own actions.
1734 Note that breakpoint insns may cause SIGTRAP or SIGILL
1735 or SIGEMT, depending on the operating system version.
1736 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1737 and change it to SIGTRAP. */
1739 if (stop_signal
== TARGET_SIGNAL_TRAP
1740 || (breakpoints_inserted
&&
1741 (stop_signal
== TARGET_SIGNAL_ILL
1742 || stop_signal
== TARGET_SIGNAL_EMT
)) || stop_soon_quietly
)
1744 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
1746 stop_print_frame
= 0;
1747 stop_stepping (ecs
);
1750 if (stop_soon_quietly
)
1752 stop_stepping (ecs
);
1756 /* Don't even think about breakpoints
1757 if just proceeded over a breakpoint.
1759 However, if we are trying to proceed over a breakpoint
1760 and end up in sigtramp, then through_sigtramp_breakpoint
1761 will be set and we should check whether we've hit the
1763 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
1764 && through_sigtramp_breakpoint
== NULL
)
1765 bpstat_clear (&stop_bpstat
);
1768 /* See if there is a breakpoint at the current PC. */
1770 /* The second argument of bpstat_stop_status is meant to help
1771 distinguish between a breakpoint trap and a singlestep trap.
1772 This is only important on targets where DECR_PC_AFTER_BREAK
1773 is non-zero. The prev_pc test is meant to distinguish between
1774 singlestepping a trap instruction, and singlestepping thru a
1775 jump to the instruction following a trap instruction.
1777 Therefore, pass TRUE if our reason for stopping is
1778 something other than hitting a breakpoint. We do this by
1779 checking that either: we detected earlier a software single
1780 step trap or, 1) stepping is going on and 2) we didn't hit
1781 a breakpoint in a signal handler without an intervening stop
1782 in sigtramp, which is detected by a new stack pointer value
1783 below any usual function calling stack adjustments. */
1787 sw_single_step_trap_p
1788 || (currently_stepping (ecs
)
1789 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1791 && INNER_THAN (read_sp (), (step_sp
- 16)))));
1792 /* Following in case break condition called a
1794 stop_print_frame
= 1;
1797 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1799 = !(bpstat_explains_signal (stop_bpstat
)
1801 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
1802 && DEPRECATED_PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
1803 get_frame_base (get_current_frame ())))
1804 || (step_range_end
&& step_resume_breakpoint
== NULL
));
1808 ecs
->random_signal
= !(bpstat_explains_signal (stop_bpstat
)
1809 /* End of a stack dummy. Some systems (e.g. Sony
1810 news) give another signal besides SIGTRAP, so
1811 check here as well as above. */
1812 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
1813 && DEPRECATED_PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
1817 if (!ecs
->random_signal
)
1818 stop_signal
= TARGET_SIGNAL_TRAP
;
1822 /* When we reach this point, we've pretty much decided
1823 that the reason for stopping must've been a random
1824 (unexpected) signal. */
1827 ecs
->random_signal
= 1;
1829 process_event_stop_test
:
1830 /* For the program's own signals, act according to
1831 the signal handling tables. */
1833 if (ecs
->random_signal
)
1835 /* Signal not for debugging purposes. */
1838 stopped_by_random_signal
= 1;
1840 if (signal_print
[stop_signal
])
1843 target_terminal_ours_for_output ();
1844 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
1846 if (signal_stop
[stop_signal
])
1848 stop_stepping (ecs
);
1851 /* If not going to stop, give terminal back
1852 if we took it away. */
1854 target_terminal_inferior ();
1856 /* Clear the signal if it should not be passed. */
1857 if (signal_program
[stop_signal
] == 0)
1858 stop_signal
= TARGET_SIGNAL_0
;
1860 /* I'm not sure whether this needs to be check_sigtramp2 or
1861 whether it could/should be keep_going.
1863 This used to jump to step_over_function if we are stepping,
1866 Suppose the user does a `next' over a function call, and while
1867 that call is in progress, the inferior receives a signal for
1868 which GDB does not stop (i.e., signal_stop[SIG] is false). In
1869 that case, when we reach this point, there is already a
1870 step-resume breakpoint established, right where it should be:
1871 immediately after the function call the user is "next"-ing
1872 over. If we call step_over_function now, two bad things
1875 - we'll create a new breakpoint, at wherever the current
1876 frame's return address happens to be. That could be
1877 anywhere, depending on what function call happens to be on
1878 the top of the stack at that point. Point is, it's probably
1879 not where we need it.
1881 - the existing step-resume breakpoint (which is at the correct
1882 address) will get orphaned: step_resume_breakpoint will point
1883 to the new breakpoint, and the old step-resume breakpoint
1884 will never be cleaned up.
1886 The old behavior was meant to help HP-UX single-step out of
1887 sigtramps. It would place the new breakpoint at prev_pc, which
1888 was certainly wrong. I don't know the details there, so fixing
1889 this probably breaks that. As with anything else, it's up to
1890 the HP-UX maintainer to furnish a fix that doesn't break other
1891 platforms. --JimB, 20 May 1999 */
1892 check_sigtramp2 (ecs
);
1897 /* Handle cases caused by hitting a breakpoint. */
1899 CORE_ADDR jmp_buf_pc
;
1900 struct bpstat_what what
;
1902 what
= bpstat_what (stop_bpstat
);
1904 if (what
.call_dummy
)
1906 stop_stack_dummy
= 1;
1908 trap_expected_after_continue
= 1;
1912 switch (what
.main_action
)
1914 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
1915 /* If we hit the breakpoint at longjmp, disable it for the
1916 duration of this command. Then, install a temporary
1917 breakpoint at the target of the jmp_buf. */
1918 disable_longjmp_breakpoint ();
1919 remove_breakpoints ();
1920 breakpoints_inserted
= 0;
1921 if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc
))
1927 /* Need to blow away step-resume breakpoint, as it
1928 interferes with us */
1929 if (step_resume_breakpoint
!= NULL
)
1931 delete_step_resume_breakpoint (&step_resume_breakpoint
);
1933 /* Not sure whether we need to blow this away too, but probably
1934 it is like the step-resume breakpoint. */
1935 if (through_sigtramp_breakpoint
!= NULL
)
1937 delete_breakpoint (through_sigtramp_breakpoint
);
1938 through_sigtramp_breakpoint
= NULL
;
1942 /* FIXME - Need to implement nested temporary breakpoints */
1943 if (step_over_calls
> 0)
1944 set_longjmp_resume_breakpoint (jmp_buf_pc
, get_current_frame ());
1947 set_longjmp_resume_breakpoint (jmp_buf_pc
, null_frame_id
);
1948 ecs
->handling_longjmp
= 1; /* FIXME */
1952 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
1953 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
1954 remove_breakpoints ();
1955 breakpoints_inserted
= 0;
1957 /* FIXME - Need to implement nested temporary breakpoints */
1959 && (frame_id_inner (get_frame_id (get_current_frame ()),
1962 ecs
->another_trap
= 1;
1967 disable_longjmp_breakpoint ();
1968 ecs
->handling_longjmp
= 0; /* FIXME */
1969 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
1971 /* else fallthrough */
1973 case BPSTAT_WHAT_SINGLE
:
1974 if (breakpoints_inserted
)
1976 remove_breakpoints ();
1978 breakpoints_inserted
= 0;
1979 ecs
->another_trap
= 1;
1980 /* Still need to check other stuff, at least the case
1981 where we are stepping and step out of the right range. */
1984 case BPSTAT_WHAT_STOP_NOISY
:
1985 stop_print_frame
= 1;
1987 /* We are about to nuke the step_resume_breakpoint and
1988 through_sigtramp_breakpoint via the cleanup chain, so
1989 no need to worry about it here. */
1991 stop_stepping (ecs
);
1994 case BPSTAT_WHAT_STOP_SILENT
:
1995 stop_print_frame
= 0;
1997 /* We are about to nuke the step_resume_breakpoint and
1998 through_sigtramp_breakpoint via the cleanup chain, so
1999 no need to worry about it here. */
2001 stop_stepping (ecs
);
2004 case BPSTAT_WHAT_STEP_RESUME
:
2005 /* This proably demands a more elegant solution, but, yeah
2008 This function's use of the simple variable
2009 step_resume_breakpoint doesn't seem to accomodate
2010 simultaneously active step-resume bp's, although the
2011 breakpoint list certainly can.
2013 If we reach here and step_resume_breakpoint is already
2014 NULL, then apparently we have multiple active
2015 step-resume bp's. We'll just delete the breakpoint we
2016 stopped at, and carry on.
2018 Correction: what the code currently does is delete a
2019 step-resume bp, but it makes no effort to ensure that
2020 the one deleted is the one currently stopped at. MVS */
2022 if (step_resume_breakpoint
== NULL
)
2024 step_resume_breakpoint
=
2025 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2027 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2030 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2031 if (through_sigtramp_breakpoint
)
2032 delete_breakpoint (through_sigtramp_breakpoint
);
2033 through_sigtramp_breakpoint
= NULL
;
2035 /* If were waiting for a trap, hitting the step_resume_break
2036 doesn't count as getting it. */
2038 ecs
->another_trap
= 1;
2041 case BPSTAT_WHAT_CHECK_SHLIBS
:
2042 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2045 /* Remove breakpoints, we eventually want to step over the
2046 shlib event breakpoint, and SOLIB_ADD might adjust
2047 breakpoint addresses via breakpoint_re_set. */
2048 if (breakpoints_inserted
)
2049 remove_breakpoints ();
2050 breakpoints_inserted
= 0;
2052 /* Check for any newly added shared libraries if we're
2053 supposed to be adding them automatically. Switch
2054 terminal for any messages produced by
2055 breakpoint_re_set. */
2056 target_terminal_ours_for_output ();
2057 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
2058 target_terminal_inferior ();
2060 /* Try to reenable shared library breakpoints, additional
2061 code segments in shared libraries might be mapped in now. */
2062 re_enable_breakpoints_in_shlibs ();
2064 /* If requested, stop when the dynamic linker notifies
2065 gdb of events. This allows the user to get control
2066 and place breakpoints in initializer routines for
2067 dynamically loaded objects (among other things). */
2068 if (stop_on_solib_events
)
2070 stop_stepping (ecs
);
2074 /* If we stopped due to an explicit catchpoint, then the
2075 (see above) call to SOLIB_ADD pulled in any symbols
2076 from a newly-loaded library, if appropriate.
2078 We do want the inferior to stop, but not where it is
2079 now, which is in the dynamic linker callback. Rather,
2080 we would like it stop in the user's program, just after
2081 the call that caused this catchpoint to trigger. That
2082 gives the user a more useful vantage from which to
2083 examine their program's state. */
2084 else if (what
.main_action
==
2085 BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2087 /* ??rehrauer: If I could figure out how to get the
2088 right return PC from here, we could just set a temp
2089 breakpoint and resume. I'm not sure we can without
2090 cracking open the dld's shared libraries and sniffing
2091 their unwind tables and text/data ranges, and that's
2092 not a terribly portable notion.
2094 Until that time, we must step the inferior out of the
2095 dld callback, and also out of the dld itself (and any
2096 code or stubs in libdld.sl, such as "shl_load" and
2097 friends) until we reach non-dld code. At that point,
2098 we can stop stepping. */
2099 bpstat_get_triggered_catchpoints (stop_bpstat
,
2101 stepping_through_solib_catchpoints
);
2102 ecs
->stepping_through_solib_after_catch
= 1;
2104 /* Be sure to lift all breakpoints, so the inferior does
2105 actually step past this point... */
2106 ecs
->another_trap
= 1;
2111 /* We want to step over this breakpoint, then keep going. */
2112 ecs
->another_trap
= 1;
2119 case BPSTAT_WHAT_LAST
:
2120 /* Not a real code, but listed here to shut up gcc -Wall. */
2122 case BPSTAT_WHAT_KEEP_CHECKING
:
2127 /* We come here if we hit a breakpoint but should not
2128 stop for it. Possibly we also were stepping
2129 and should stop for that. So fall through and
2130 test for stepping. But, if not stepping,
2133 /* Are we stepping to get the inferior out of the dynamic
2134 linker's hook (and possibly the dld itself) after catching
2136 if (ecs
->stepping_through_solib_after_catch
)
2138 #if defined(SOLIB_ADD)
2139 /* Have we reached our destination? If not, keep going. */
2140 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2142 ecs
->another_trap
= 1;
2147 /* Else, stop and report the catchpoint(s) whose triggering
2148 caused us to begin stepping. */
2149 ecs
->stepping_through_solib_after_catch
= 0;
2150 bpstat_clear (&stop_bpstat
);
2151 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2152 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2153 stop_print_frame
= 1;
2154 stop_stepping (ecs
);
2158 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2160 /* This is the old way of detecting the end of the stack dummy.
2161 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2162 handled above. As soon as we can test it on all of them, all
2163 architectures should define it. */
2165 /* If this is the breakpoint at the end of a stack dummy,
2166 just stop silently, unless the user was doing an si/ni, in which
2167 case she'd better know what she's doing. */
2169 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2170 get_frame_base (get_current_frame ()))
2173 stop_print_frame
= 0;
2174 stop_stack_dummy
= 1;
2176 trap_expected_after_continue
= 1;
2178 stop_stepping (ecs
);
2183 if (step_resume_breakpoint
)
2185 /* Having a step-resume breakpoint overrides anything
2186 else having to do with stepping commands until
2187 that breakpoint is reached. */
2188 /* I'm not sure whether this needs to be check_sigtramp2 or
2189 whether it could/should be keep_going. */
2190 check_sigtramp2 (ecs
);
2195 if (step_range_end
== 0)
2197 /* Likewise if we aren't even stepping. */
2198 /* I'm not sure whether this needs to be check_sigtramp2 or
2199 whether it could/should be keep_going. */
2200 check_sigtramp2 (ecs
);
2205 /* If stepping through a line, keep going if still within it.
2207 Note that step_range_end is the address of the first instruction
2208 beyond the step range, and NOT the address of the last instruction
2210 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
2212 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2213 So definately need to check for sigtramp here. */
2214 check_sigtramp2 (ecs
);
2219 /* We stepped out of the stepping range. */
2221 /* If we are stepping at the source level and entered the runtime
2222 loader dynamic symbol resolution code, we keep on single stepping
2223 until we exit the run time loader code and reach the callee's
2225 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2226 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2228 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2230 if (pc_after_resolver
)
2232 /* Set up a step-resume breakpoint at the address
2233 indicated by SKIP_SOLIB_RESOLVER. */
2234 struct symtab_and_line sr_sal
;
2236 sr_sal
.pc
= pc_after_resolver
;
2238 check_for_old_step_resume_breakpoint ();
2239 step_resume_breakpoint
=
2240 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2241 if (breakpoints_inserted
)
2242 insert_breakpoints ();
2249 /* We can't update step_sp every time through the loop, because
2250 reading the stack pointer would slow down stepping too much.
2251 But we can update it every time we leave the step range. */
2252 ecs
->update_step_sp
= 1;
2254 /* Did we just take a signal? */
2255 if (PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2256 && !PC_IN_SIGTRAMP (prev_pc
, prev_func_name
)
2257 && INNER_THAN (read_sp (), step_sp
))
2259 /* We've just taken a signal; go until we are back to
2260 the point where we took it and one more. */
2262 /* Note: The test above succeeds not only when we stepped
2263 into a signal handler, but also when we step past the last
2264 statement of a signal handler and end up in the return stub
2265 of the signal handler trampoline. To distinguish between
2266 these two cases, check that the frame is INNER_THAN the
2267 previous one below. pai/1997-09-11 */
2271 struct frame_id current_frame
= get_frame_id (get_current_frame ());
2273 if (frame_id_inner (current_frame
, step_frame_id
))
2275 /* We have just taken a signal; go until we are back to
2276 the point where we took it and one more. */
2278 /* This code is needed at least in the following case:
2279 The user types "next" and then a signal arrives (before
2280 the "next" is done). */
2282 /* Note that if we are stopped at a breakpoint, then we need
2283 the step_resume breakpoint to override any breakpoints at
2284 the same location, so that we will still step over the
2285 breakpoint even though the signal happened. */
2286 struct symtab_and_line sr_sal
;
2289 sr_sal
.symtab
= NULL
;
2291 sr_sal
.pc
= prev_pc
;
2292 /* We could probably be setting the frame to
2293 step_frame_id; I don't think anyone thought to try it. */
2294 check_for_old_step_resume_breakpoint ();
2295 step_resume_breakpoint
=
2296 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2297 if (breakpoints_inserted
)
2298 insert_breakpoints ();
2302 /* We just stepped out of a signal handler and into
2303 its calling trampoline.
2305 Normally, we'd call step_over_function from
2306 here, but for some reason GDB can't unwind the
2307 stack correctly to find the real PC for the point
2308 user code where the signal trampoline will return
2309 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2310 But signal trampolines are pretty small stubs of
2311 code, anyway, so it's OK instead to just
2312 single-step out. Note: assuming such trampolines
2313 don't exhibit recursion on any platform... */
2314 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2315 &ecs
->stop_func_start
,
2316 &ecs
->stop_func_end
);
2317 /* Readjust stepping range */
2318 step_range_start
= ecs
->stop_func_start
;
2319 step_range_end
= ecs
->stop_func_end
;
2320 ecs
->stepping_through_sigtramp
= 1;
2325 /* If this is stepi or nexti, make sure that the stepping range
2326 gets us past that instruction. */
2327 if (step_range_end
== 1)
2328 /* FIXME: Does this run afoul of the code below which, if
2329 we step into the middle of a line, resets the stepping
2331 step_range_end
= (step_range_start
= prev_pc
) + 1;
2333 ecs
->remove_breakpoints_on_following_step
= 1;
2338 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2339 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2340 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2341 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2342 || ecs
->stop_func_name
== 0)
2344 /* It's a subroutine call. */
2346 if ((step_over_calls
== STEP_OVER_NONE
)
2347 || ((step_range_end
== 1)
2348 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2350 /* I presume that step_over_calls is only 0 when we're
2351 supposed to be stepping at the assembly language level
2352 ("stepi"). Just stop. */
2353 /* Also, maybe we just did a "nexti" inside a prolog,
2354 so we thought it was a subroutine call but it was not.
2355 Stop as well. FENN */
2357 print_stop_reason (END_STEPPING_RANGE
, 0);
2358 stop_stepping (ecs
);
2362 if (step_over_calls
== STEP_OVER_ALL
|| IGNORE_HELPER_CALL (stop_pc
))
2364 /* We're doing a "next". */
2366 if (PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2367 && frame_id_inner (step_frame_id
,
2368 frame_id_build (read_sp (), 0)))
2369 /* We stepped out of a signal handler, and into its
2370 calling trampoline. This is misdetected as a
2371 subroutine call, but stepping over the signal
2372 trampoline isn't such a bad idea. In order to do that,
2373 we have to ignore the value in step_frame_id, since
2374 that doesn't represent the frame that'll reach when we
2375 return from the signal trampoline. Otherwise we'll
2376 probably continue to the end of the program. */
2377 step_frame_id
= null_frame_id
;
2379 step_over_function (ecs
);
2384 /* If we are in a function call trampoline (a stub between
2385 the calling routine and the real function), locate the real
2386 function. That's what tells us (a) whether we want to step
2387 into it at all, and (b) what prologue we want to run to
2388 the end of, if we do step into it. */
2389 real_stop_pc
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2390 if (real_stop_pc
!= 0)
2391 ecs
->stop_func_start
= real_stop_pc
;
2393 /* If we have line number information for the function we
2394 are thinking of stepping into, step into it.
2396 If there are several symtabs at that PC (e.g. with include
2397 files), just want to know whether *any* of them have line
2398 numbers. find_pc_line handles this. */
2400 struct symtab_and_line tmp_sal
;
2402 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2403 if (tmp_sal
.line
!= 0)
2405 step_into_function (ecs
);
2410 /* If we have no line number and the step-stop-if-no-debug
2411 is set, we stop the step so that the user has a chance to
2412 switch in assembly mode. */
2413 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2416 print_stop_reason (END_STEPPING_RANGE
, 0);
2417 stop_stepping (ecs
);
2421 step_over_function (ecs
);
2427 /* We've wandered out of the step range. */
2429 ecs
->sal
= find_pc_line (stop_pc
, 0);
2431 if (step_range_end
== 1)
2433 /* It is stepi or nexti. We always want to stop stepping after
2436 print_stop_reason (END_STEPPING_RANGE
, 0);
2437 stop_stepping (ecs
);
2441 /* If we're in the return path from a shared library trampoline,
2442 we want to proceed through the trampoline when stepping. */
2443 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2445 /* Determine where this trampoline returns. */
2446 real_stop_pc
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2448 /* Only proceed through if we know where it's going. */
2451 /* And put the step-breakpoint there and go until there. */
2452 struct symtab_and_line sr_sal
;
2454 init_sal (&sr_sal
); /* initialize to zeroes */
2455 sr_sal
.pc
= real_stop_pc
;
2456 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2457 /* Do not specify what the fp should be when we stop
2458 since on some machines the prologue
2459 is where the new fp value is established. */
2460 check_for_old_step_resume_breakpoint ();
2461 step_resume_breakpoint
=
2462 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2463 if (breakpoints_inserted
)
2464 insert_breakpoints ();
2466 /* Restart without fiddling with the step ranges or
2473 if (ecs
->sal
.line
== 0)
2475 /* We have no line number information. That means to stop
2476 stepping (does this always happen right after one instruction,
2477 when we do "s" in a function with no line numbers,
2478 or can this happen as a result of a return or longjmp?). */
2480 print_stop_reason (END_STEPPING_RANGE
, 0);
2481 stop_stepping (ecs
);
2485 if ((stop_pc
== ecs
->sal
.pc
)
2486 && (ecs
->current_line
!= ecs
->sal
.line
2487 || ecs
->current_symtab
!= ecs
->sal
.symtab
))
2489 /* We are at the start of a different line. So stop. Note that
2490 we don't stop if we step into the middle of a different line.
2491 That is said to make things like for (;;) statements work
2494 print_stop_reason (END_STEPPING_RANGE
, 0);
2495 stop_stepping (ecs
);
2499 /* We aren't done stepping.
2501 Optimize by setting the stepping range to the line.
2502 (We might not be in the original line, but if we entered a
2503 new line in mid-statement, we continue stepping. This makes
2504 things like for(;;) statements work better.) */
2506 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2508 /* If this is the last line of the function, don't keep stepping
2509 (it would probably step us out of the function).
2510 This is particularly necessary for a one-line function,
2511 in which after skipping the prologue we better stop even though
2512 we will be in mid-line. */
2514 print_stop_reason (END_STEPPING_RANGE
, 0);
2515 stop_stepping (ecs
);
2518 step_range_start
= ecs
->sal
.pc
;
2519 step_range_end
= ecs
->sal
.end
;
2520 step_frame_id
= get_frame_id (get_current_frame ());
2521 ecs
->current_line
= ecs
->sal
.line
;
2522 ecs
->current_symtab
= ecs
->sal
.symtab
;
2524 /* In the case where we just stepped out of a function into the
2525 middle of a line of the caller, continue stepping, but
2526 step_frame_id must be modified to current frame */
2528 struct frame_id current_frame
= get_frame_id (get_current_frame ());
2529 if (!(frame_id_inner (current_frame
, step_frame_id
)))
2530 step_frame_id
= current_frame
;
2536 /* Are we in the middle of stepping? */
2539 currently_stepping (struct execution_control_state
*ecs
)
2541 return ((through_sigtramp_breakpoint
== NULL
2542 && !ecs
->handling_longjmp
2543 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2545 || ecs
->stepping_through_solib_after_catch
2546 || bpstat_should_step ());
2550 check_sigtramp2 (struct execution_control_state
*ecs
)
2553 && PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2554 && !PC_IN_SIGTRAMP (prev_pc
, prev_func_name
)
2555 && INNER_THAN (read_sp (), step_sp
))
2557 /* What has happened here is that we have just stepped the
2558 inferior with a signal (because it is a signal which
2559 shouldn't make us stop), thus stepping into sigtramp.
2561 So we need to set a step_resume_break_address breakpoint and
2562 continue until we hit it, and then step. FIXME: This should
2563 be more enduring than a step_resume breakpoint; we should
2564 know that we will later need to keep going rather than
2565 re-hitting the breakpoint here (see the testsuite,
2566 gdb.base/signals.exp where it says "exceedingly difficult"). */
2568 struct symtab_and_line sr_sal
;
2570 init_sal (&sr_sal
); /* initialize to zeroes */
2571 sr_sal
.pc
= prev_pc
;
2572 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2573 /* We perhaps could set the frame if we kept track of what the
2574 frame corresponding to prev_pc was. But we don't, so don't. */
2575 through_sigtramp_breakpoint
=
2576 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_through_sigtramp
);
2577 if (breakpoints_inserted
)
2578 insert_breakpoints ();
2580 ecs
->remove_breakpoints_on_following_step
= 1;
2581 ecs
->another_trap
= 1;
2585 /* Subroutine call with source code we should not step over. Do step
2586 to the first line of code in it. */
2589 step_into_function (struct execution_control_state
*ecs
)
2592 struct symtab_and_line sr_sal
;
2594 s
= find_pc_symtab (stop_pc
);
2595 if (s
&& s
->language
!= language_asm
)
2596 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2598 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2599 /* Use the step_resume_break to step until the end of the prologue,
2600 even if that involves jumps (as it seems to on the vax under
2602 /* If the prologue ends in the middle of a source line, continue to
2603 the end of that source line (if it is still within the function).
2604 Otherwise, just go to end of prologue. */
2605 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2606 /* no, don't either. It skips any code that's legitimately on the
2610 && ecs
->sal
.pc
!= ecs
->stop_func_start
2611 && ecs
->sal
.end
< ecs
->stop_func_end
)
2612 ecs
->stop_func_start
= ecs
->sal
.end
;
2615 if (ecs
->stop_func_start
== stop_pc
)
2617 /* We are already there: stop now. */
2619 print_stop_reason (END_STEPPING_RANGE
, 0);
2620 stop_stepping (ecs
);
2625 /* Put the step-breakpoint there and go until there. */
2626 init_sal (&sr_sal
); /* initialize to zeroes */
2627 sr_sal
.pc
= ecs
->stop_func_start
;
2628 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
2629 /* Do not specify what the fp should be when we stop since on
2630 some machines the prologue is where the new fp value is
2632 check_for_old_step_resume_breakpoint ();
2633 step_resume_breakpoint
=
2634 set_momentary_breakpoint (sr_sal
, null_frame_id
, bp_step_resume
);
2635 if (breakpoints_inserted
)
2636 insert_breakpoints ();
2638 /* And make sure stepping stops right away then. */
2639 step_range_end
= step_range_start
;
2644 /* We've just entered a callee, and we wish to resume until it returns
2645 to the caller. Setting a step_resume breakpoint on the return
2646 address will catch a return from the callee.
2648 However, if the callee is recursing, we want to be careful not to
2649 catch returns of those recursive calls, but only of THIS instance
2652 To do this, we set the step_resume bp's frame to our current
2653 caller's frame (step_frame_id, which is set by the "next" or
2654 "until" command, before execution begins). */
2657 step_over_function (struct execution_control_state
*ecs
)
2659 struct symtab_and_line sr_sal
;
2661 init_sal (&sr_sal
); /* initialize to zeros */
2662 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2663 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2665 check_for_old_step_resume_breakpoint ();
2666 step_resume_breakpoint
=
2667 set_momentary_breakpoint (sr_sal
, get_frame_id (get_current_frame ()),
2670 if (frame_id_p (step_frame_id
)
2671 && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
2672 step_resume_breakpoint
->frame_id
= step_frame_id
;
2674 if (breakpoints_inserted
)
2675 insert_breakpoints ();
2679 stop_stepping (struct execution_control_state
*ecs
)
2681 if (target_has_execution
)
2683 /* Assuming the inferior still exists, set these up for next
2684 time, just like we did above if we didn't break out of the
2686 prev_pc
= read_pc ();
2687 prev_func_start
= ecs
->stop_func_start
;
2688 prev_func_name
= ecs
->stop_func_name
;
2691 /* Let callers know we don't want to wait for the inferior anymore. */
2692 ecs
->wait_some_more
= 0;
2695 /* This function handles various cases where we need to continue
2696 waiting for the inferior. */
2697 /* (Used to be the keep_going: label in the old wait_for_inferior) */
2700 keep_going (struct execution_control_state
*ecs
)
2702 /* Save the pc before execution, to compare with pc after stop. */
2703 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
2704 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
2705 BREAK is defined, the
2706 original pc would not have
2707 been at the start of a
2709 prev_func_name
= ecs
->stop_func_name
;
2711 if (ecs
->update_step_sp
)
2712 step_sp
= read_sp ();
2713 ecs
->update_step_sp
= 0;
2715 /* If we did not do break;, it means we should keep running the
2716 inferior and not return to debugger. */
2718 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
2720 /* We took a signal (which we are supposed to pass through to
2721 the inferior, else we'd have done a break above) and we
2722 haven't yet gotten our trap. Simply continue. */
2723 resume (currently_stepping (ecs
), stop_signal
);
2727 /* Either the trap was not expected, but we are continuing
2728 anyway (the user asked that this signal be passed to the
2731 The signal was SIGTRAP, e.g. it was our signal, but we
2732 decided we should resume from it.
2734 We're going to run this baby now!
2736 Insert breakpoints now, unless we are trying to one-proceed
2737 past a breakpoint. */
2738 /* If we've just finished a special step resume and we don't
2739 want to hit a breakpoint, pull em out. */
2740 if (step_resume_breakpoint
== NULL
2741 && through_sigtramp_breakpoint
== NULL
2742 && ecs
->remove_breakpoints_on_following_step
)
2744 ecs
->remove_breakpoints_on_following_step
= 0;
2745 remove_breakpoints ();
2746 breakpoints_inserted
= 0;
2748 else if (!breakpoints_inserted
&&
2749 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
2751 breakpoints_failed
= insert_breakpoints ();
2752 if (breakpoints_failed
)
2754 stop_stepping (ecs
);
2757 breakpoints_inserted
= 1;
2760 trap_expected
= ecs
->another_trap
;
2762 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
2763 specifies that such a signal should be delivered to the
2766 Typically, this would occure when a user is debugging a
2767 target monitor on a simulator: the target monitor sets a
2768 breakpoint; the simulator encounters this break-point and
2769 halts the simulation handing control to GDB; GDB, noteing
2770 that the break-point isn't valid, returns control back to the
2771 simulator; the simulator then delivers the hardware
2772 equivalent of a SIGNAL_TRAP to the program being debugged. */
2774 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !signal_program
[stop_signal
])
2775 stop_signal
= TARGET_SIGNAL_0
;
2777 #ifdef SHIFT_INST_REGS
2778 /* I'm not sure when this following segment applies. I do know,
2779 now, that we shouldn't rewrite the regs when we were stopped
2780 by a random signal from the inferior process. */
2781 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2782 (this is only used on the 88k). */
2784 if (!bpstat_explains_signal (stop_bpstat
)
2785 && (stop_signal
!= TARGET_SIGNAL_CHLD
) && !stopped_by_random_signal
)
2787 #endif /* SHIFT_INST_REGS */
2789 resume (currently_stepping (ecs
), stop_signal
);
2792 prepare_to_wait (ecs
);
2795 /* This function normally comes after a resume, before
2796 handle_inferior_event exits. It takes care of any last bits of
2797 housekeeping, and sets the all-important wait_some_more flag. */
2800 prepare_to_wait (struct execution_control_state
*ecs
)
2802 if (ecs
->infwait_state
== infwait_normal_state
)
2804 overlay_cache_invalid
= 1;
2806 /* We have to invalidate the registers BEFORE calling
2807 target_wait because they can be loaded from the target while
2808 in target_wait. This makes remote debugging a bit more
2809 efficient for those targets that provide critical registers
2810 as part of their normal status mechanism. */
2812 registers_changed ();
2813 ecs
->waiton_ptid
= pid_to_ptid (-1);
2814 ecs
->wp
= &(ecs
->ws
);
2816 /* This is the old end of the while loop. Let everybody know we
2817 want to wait for the inferior some more and get called again
2819 ecs
->wait_some_more
= 1;
2822 /* Print why the inferior has stopped. We always print something when
2823 the inferior exits, or receives a signal. The rest of the cases are
2824 dealt with later on in normal_stop() and print_it_typical(). Ideally
2825 there should be a call to this function from handle_inferior_event()
2826 each time stop_stepping() is called.*/
2828 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
2830 switch (stop_reason
)
2833 /* We don't deal with these cases from handle_inferior_event()
2836 case END_STEPPING_RANGE
:
2837 /* We are done with a step/next/si/ni command. */
2838 /* For now print nothing. */
2839 /* Print a message only if not in the middle of doing a "step n"
2840 operation for n > 1 */
2841 if (!step_multi
|| !stop_step
)
2842 if (ui_out_is_mi_like_p (uiout
))
2843 ui_out_field_string (uiout
, "reason", "end-stepping-range");
2845 case BREAKPOINT_HIT
:
2846 /* We found a breakpoint. */
2847 /* For now print nothing. */
2850 /* The inferior was terminated by a signal. */
2851 annotate_signalled ();
2852 if (ui_out_is_mi_like_p (uiout
))
2853 ui_out_field_string (uiout
, "reason", "exited-signalled");
2854 ui_out_text (uiout
, "\nProgram terminated with signal ");
2855 annotate_signal_name ();
2856 ui_out_field_string (uiout
, "signal-name",
2857 target_signal_to_name (stop_info
));
2858 annotate_signal_name_end ();
2859 ui_out_text (uiout
, ", ");
2860 annotate_signal_string ();
2861 ui_out_field_string (uiout
, "signal-meaning",
2862 target_signal_to_string (stop_info
));
2863 annotate_signal_string_end ();
2864 ui_out_text (uiout
, ".\n");
2865 ui_out_text (uiout
, "The program no longer exists.\n");
2868 /* The inferior program is finished. */
2869 annotate_exited (stop_info
);
2872 if (ui_out_is_mi_like_p (uiout
))
2873 ui_out_field_string (uiout
, "reason", "exited");
2874 ui_out_text (uiout
, "\nProgram exited with code ");
2875 ui_out_field_fmt (uiout
, "exit-code", "0%o",
2876 (unsigned int) stop_info
);
2877 ui_out_text (uiout
, ".\n");
2881 if (ui_out_is_mi_like_p (uiout
))
2882 ui_out_field_string (uiout
, "reason", "exited-normally");
2883 ui_out_text (uiout
, "\nProgram exited normally.\n");
2886 case SIGNAL_RECEIVED
:
2887 /* Signal received. The signal table tells us to print about
2890 ui_out_text (uiout
, "\nProgram received signal ");
2891 annotate_signal_name ();
2892 if (ui_out_is_mi_like_p (uiout
))
2893 ui_out_field_string (uiout
, "reason", "signal-received");
2894 ui_out_field_string (uiout
, "signal-name",
2895 target_signal_to_name (stop_info
));
2896 annotate_signal_name_end ();
2897 ui_out_text (uiout
, ", ");
2898 annotate_signal_string ();
2899 ui_out_field_string (uiout
, "signal-meaning",
2900 target_signal_to_string (stop_info
));
2901 annotate_signal_string_end ();
2902 ui_out_text (uiout
, ".\n");
2905 internal_error (__FILE__
, __LINE__
,
2906 "print_stop_reason: unrecognized enum value");
2912 /* Here to return control to GDB when the inferior stops for real.
2913 Print appropriate messages, remove breakpoints, give terminal our modes.
2915 STOP_PRINT_FRAME nonzero means print the executing frame
2916 (pc, function, args, file, line number and line text).
2917 BREAKPOINTS_FAILED nonzero means stop was due to error
2918 attempting to insert breakpoints. */
2923 /* As with the notification of thread events, we want to delay
2924 notifying the user that we've switched thread context until
2925 the inferior actually stops.
2927 (Note that there's no point in saying anything if the inferior
2929 if (!ptid_equal (previous_inferior_ptid
, inferior_ptid
)
2930 && target_has_execution
)
2932 target_terminal_ours_for_output ();
2933 printf_filtered ("[Switching to %s]\n",
2934 target_pid_or_tid_to_str (inferior_ptid
));
2935 previous_inferior_ptid
= inferior_ptid
;
2938 /* Make sure that the current_frame's pc is correct. This
2939 is a correction for setting up the frame info before doing
2940 DECR_PC_AFTER_BREAK */
2941 if (target_has_execution
)
2942 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
2943 DECR_PC_AFTER_BREAK, the program counter can change. Ask the
2944 frame code to check for this and sort out any resultant mess.
2945 DECR_PC_AFTER_BREAK needs to just go away. */
2946 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
2948 if (target_has_execution
&& breakpoints_inserted
)
2950 if (remove_breakpoints ())
2952 target_terminal_ours_for_output ();
2953 printf_filtered ("Cannot remove breakpoints because ");
2954 printf_filtered ("program is no longer writable.\n");
2955 printf_filtered ("It might be running in another process.\n");
2956 printf_filtered ("Further execution is probably impossible.\n");
2959 breakpoints_inserted
= 0;
2961 /* Delete the breakpoint we stopped at, if it wants to be deleted.
2962 Delete any breakpoint that is to be deleted at the next stop. */
2964 breakpoint_auto_delete (stop_bpstat
);
2966 /* If an auto-display called a function and that got a signal,
2967 delete that auto-display to avoid an infinite recursion. */
2969 if (stopped_by_random_signal
)
2970 disable_current_display ();
2972 /* Don't print a message if in the middle of doing a "step n"
2973 operation for n > 1 */
2974 if (step_multi
&& stop_step
)
2977 target_terminal_ours ();
2979 /* Look up the hook_stop and run it (CLI internally handles problem
2980 of stop_command's pre-hook not existing). */
2982 catch_errors (hook_stop_stub
, stop_command
,
2983 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
2985 if (!target_has_stack
)
2991 /* Select innermost stack frame - i.e., current frame is frame 0,
2992 and current location is based on that.
2993 Don't do this on return from a stack dummy routine,
2994 or if the program has exited. */
2996 if (!stop_stack_dummy
)
2998 select_frame (get_current_frame ());
3000 /* Print current location without a level number, if
3001 we have changed functions or hit a breakpoint.
3002 Print source line if we have one.
3003 bpstat_print() contains the logic deciding in detail
3004 what to print, based on the event(s) that just occurred. */
3006 if (stop_print_frame
&& deprecated_selected_frame
)
3010 int do_frame_printing
= 1;
3012 bpstat_ret
= bpstat_print (stop_bpstat
);
3016 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3017 (or should) carry around the function and does (or
3018 should) use that when doing a frame comparison. */
3020 && frame_id_eq (step_frame_id
,
3021 get_frame_id (get_current_frame ()))
3022 && step_start_function
== find_pc_function (stop_pc
))
3023 source_flag
= SRC_LINE
; /* finished step, just print source line */
3025 source_flag
= SRC_AND_LOC
; /* print location and source line */
3027 case PRINT_SRC_AND_LOC
:
3028 source_flag
= SRC_AND_LOC
; /* print location and source line */
3030 case PRINT_SRC_ONLY
:
3031 source_flag
= SRC_LINE
;
3034 source_flag
= SRC_LINE
; /* something bogus */
3035 do_frame_printing
= 0;
3038 internal_error (__FILE__
, __LINE__
, "Unknown value.");
3040 /* For mi, have the same behavior every time we stop:
3041 print everything but the source line. */
3042 if (ui_out_is_mi_like_p (uiout
))
3043 source_flag
= LOC_AND_ADDRESS
;
3045 if (ui_out_is_mi_like_p (uiout
))
3046 ui_out_field_int (uiout
, "thread-id",
3047 pid_to_thread_id (inferior_ptid
));
3048 /* The behavior of this routine with respect to the source
3050 SRC_LINE: Print only source line
3051 LOCATION: Print only location
3052 SRC_AND_LOC: Print location and source line */
3053 if (do_frame_printing
)
3054 print_stack_frame (deprecated_selected_frame
, -1, source_flag
);
3056 /* Display the auto-display expressions. */
3061 /* Save the function value return registers, if we care.
3062 We might be about to restore their previous contents. */
3063 if (proceed_to_finish
)
3064 /* NB: The copy goes through to the target picking up the value of
3065 all the registers. */
3066 regcache_cpy (stop_registers
, current_regcache
);
3068 if (stop_stack_dummy
)
3070 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3071 ends with a setting of the current frame, so we can use that
3073 frame_pop (get_current_frame ());
3074 /* Set stop_pc to what it was before we called the function.
3075 Can't rely on restore_inferior_status because that only gets
3076 called if we don't stop in the called function. */
3077 stop_pc
= read_pc ();
3078 select_frame (get_current_frame ());
3082 annotate_stopped ();
3083 observer_notify_normal_stop ();
3087 hook_stop_stub (void *cmd
)
3089 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3094 signal_stop_state (int signo
)
3096 return signal_stop
[signo
];
3100 signal_print_state (int signo
)
3102 return signal_print
[signo
];
3106 signal_pass_state (int signo
)
3108 return signal_program
[signo
];
3112 signal_stop_update (int signo
, int state
)
3114 int ret
= signal_stop
[signo
];
3115 signal_stop
[signo
] = state
;
3120 signal_print_update (int signo
, int state
)
3122 int ret
= signal_print
[signo
];
3123 signal_print
[signo
] = state
;
3128 signal_pass_update (int signo
, int state
)
3130 int ret
= signal_program
[signo
];
3131 signal_program
[signo
] = state
;
3136 sig_print_header (void)
3139 Signal Stop\tPrint\tPass to program\tDescription\n");
3143 sig_print_info (enum target_signal oursig
)
3145 char *name
= target_signal_to_name (oursig
);
3146 int name_padding
= 13 - strlen (name
);
3148 if (name_padding
<= 0)
3151 printf_filtered ("%s", name
);
3152 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
3153 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3154 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3155 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3156 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3159 /* Specify how various signals in the inferior should be handled. */
3162 handle_command (char *args
, int from_tty
)
3165 int digits
, wordlen
;
3166 int sigfirst
, signum
, siglast
;
3167 enum target_signal oursig
;
3170 unsigned char *sigs
;
3171 struct cleanup
*old_chain
;
3175 error_no_arg ("signal to handle");
3178 /* Allocate and zero an array of flags for which signals to handle. */
3180 nsigs
= (int) TARGET_SIGNAL_LAST
;
3181 sigs
= (unsigned char *) alloca (nsigs
);
3182 memset (sigs
, 0, nsigs
);
3184 /* Break the command line up into args. */
3186 argv
= buildargv (args
);
3191 old_chain
= make_cleanup_freeargv (argv
);
3193 /* Walk through the args, looking for signal oursigs, signal names, and
3194 actions. Signal numbers and signal names may be interspersed with
3195 actions, with the actions being performed for all signals cumulatively
3196 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3198 while (*argv
!= NULL
)
3200 wordlen
= strlen (*argv
);
3201 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3205 sigfirst
= siglast
= -1;
3207 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3209 /* Apply action to all signals except those used by the
3210 debugger. Silently skip those. */
3213 siglast
= nsigs
- 1;
3215 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3217 SET_SIGS (nsigs
, sigs
, signal_stop
);
3218 SET_SIGS (nsigs
, sigs
, signal_print
);
3220 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3222 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3224 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3226 SET_SIGS (nsigs
, sigs
, signal_print
);
3228 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3230 SET_SIGS (nsigs
, sigs
, signal_program
);
3232 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3234 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3236 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3238 SET_SIGS (nsigs
, sigs
, signal_program
);
3240 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3242 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3243 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3245 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3247 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3249 else if (digits
> 0)
3251 /* It is numeric. The numeric signal refers to our own
3252 internal signal numbering from target.h, not to host/target
3253 signal number. This is a feature; users really should be
3254 using symbolic names anyway, and the common ones like
3255 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3257 sigfirst
= siglast
= (int)
3258 target_signal_from_command (atoi (*argv
));
3259 if ((*argv
)[digits
] == '-')
3262 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3264 if (sigfirst
> siglast
)
3266 /* Bet he didn't figure we'd think of this case... */
3274 oursig
= target_signal_from_name (*argv
);
3275 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3277 sigfirst
= siglast
= (int) oursig
;
3281 /* Not a number and not a recognized flag word => complain. */
3282 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3286 /* If any signal numbers or symbol names were found, set flags for
3287 which signals to apply actions to. */
3289 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3291 switch ((enum target_signal
) signum
)
3293 case TARGET_SIGNAL_TRAP
:
3294 case TARGET_SIGNAL_INT
:
3295 if (!allsigs
&& !sigs
[signum
])
3297 if (query ("%s is used by the debugger.\n\
3298 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
3304 printf_unfiltered ("Not confirmed, unchanged.\n");
3305 gdb_flush (gdb_stdout
);
3309 case TARGET_SIGNAL_0
:
3310 case TARGET_SIGNAL_DEFAULT
:
3311 case TARGET_SIGNAL_UNKNOWN
:
3312 /* Make sure that "all" doesn't print these. */
3323 target_notice_signals (inferior_ptid
);
3327 /* Show the results. */
3328 sig_print_header ();
3329 for (signum
= 0; signum
< nsigs
; signum
++)
3333 sig_print_info (signum
);
3338 do_cleanups (old_chain
);
3342 xdb_handle_command (char *args
, int from_tty
)
3345 struct cleanup
*old_chain
;
3347 /* Break the command line up into args. */
3349 argv
= buildargv (args
);
3354 old_chain
= make_cleanup_freeargv (argv
);
3355 if (argv
[1] != (char *) NULL
)
3360 bufLen
= strlen (argv
[0]) + 20;
3361 argBuf
= (char *) xmalloc (bufLen
);
3365 enum target_signal oursig
;
3367 oursig
= target_signal_from_name (argv
[0]);
3368 memset (argBuf
, 0, bufLen
);
3369 if (strcmp (argv
[1], "Q") == 0)
3370 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3373 if (strcmp (argv
[1], "s") == 0)
3375 if (!signal_stop
[oursig
])
3376 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3378 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3380 else if (strcmp (argv
[1], "i") == 0)
3382 if (!signal_program
[oursig
])
3383 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3385 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3387 else if (strcmp (argv
[1], "r") == 0)
3389 if (!signal_print
[oursig
])
3390 sprintf (argBuf
, "%s %s", argv
[0], "print");
3392 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3398 handle_command (argBuf
, from_tty
);
3400 printf_filtered ("Invalid signal handling flag.\n");
3405 do_cleanups (old_chain
);
3408 /* Print current contents of the tables set by the handle command.
3409 It is possible we should just be printing signals actually used
3410 by the current target (but for things to work right when switching
3411 targets, all signals should be in the signal tables). */
3414 signals_info (char *signum_exp
, int from_tty
)
3416 enum target_signal oursig
;
3417 sig_print_header ();
3421 /* First see if this is a symbol name. */
3422 oursig
= target_signal_from_name (signum_exp
);
3423 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3425 /* No, try numeric. */
3427 target_signal_from_command (parse_and_eval_long (signum_exp
));
3429 sig_print_info (oursig
);
3433 printf_filtered ("\n");
3434 /* These ugly casts brought to you by the native VAX compiler. */
3435 for (oursig
= TARGET_SIGNAL_FIRST
;
3436 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3437 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3441 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3442 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
3443 sig_print_info (oursig
);
3446 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3449 struct inferior_status
3451 enum target_signal stop_signal
;
3455 int stop_stack_dummy
;
3456 int stopped_by_random_signal
;
3458 CORE_ADDR step_range_start
;
3459 CORE_ADDR step_range_end
;
3460 struct frame_id step_frame_id
;
3461 enum step_over_calls_kind step_over_calls
;
3462 CORE_ADDR step_resume_break_address
;
3463 int stop_after_trap
;
3464 int stop_soon_quietly
;
3465 struct regcache
*stop_registers
;
3467 /* These are here because if call_function_by_hand has written some
3468 registers and then decides to call error(), we better not have changed
3470 struct regcache
*registers
;
3472 /* A frame unique identifier. */
3473 struct frame_id selected_frame_id
;
3475 int breakpoint_proceeded
;
3476 int restore_stack_info
;
3477 int proceed_to_finish
;
3481 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3484 int size
= REGISTER_RAW_SIZE (regno
);
3485 void *buf
= alloca (size
);
3486 store_signed_integer (buf
, size
, val
);
3487 regcache_raw_write (inf_status
->registers
, regno
, buf
);
3490 /* Save all of the information associated with the inferior<==>gdb
3491 connection. INF_STATUS is a pointer to a "struct inferior_status"
3492 (defined in inferior.h). */
3494 struct inferior_status
*
3495 save_inferior_status (int restore_stack_info
)
3497 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
3499 inf_status
->stop_signal
= stop_signal
;
3500 inf_status
->stop_pc
= stop_pc
;
3501 inf_status
->stop_step
= stop_step
;
3502 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3503 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3504 inf_status
->trap_expected
= trap_expected
;
3505 inf_status
->step_range_start
= step_range_start
;
3506 inf_status
->step_range_end
= step_range_end
;
3507 inf_status
->step_frame_id
= step_frame_id
;
3508 inf_status
->step_over_calls
= step_over_calls
;
3509 inf_status
->stop_after_trap
= stop_after_trap
;
3510 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3511 /* Save original bpstat chain here; replace it with copy of chain.
3512 If caller's caller is walking the chain, they'll be happier if we
3513 hand them back the original chain when restore_inferior_status is
3515 inf_status
->stop_bpstat
= stop_bpstat
;
3516 stop_bpstat
= bpstat_copy (stop_bpstat
);
3517 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3518 inf_status
->restore_stack_info
= restore_stack_info
;
3519 inf_status
->proceed_to_finish
= proceed_to_finish
;
3521 inf_status
->stop_registers
= regcache_dup_no_passthrough (stop_registers
);
3523 inf_status
->registers
= regcache_dup (current_regcache
);
3525 inf_status
->selected_frame_id
= get_frame_id (deprecated_selected_frame
);
3530 restore_selected_frame (void *args
)
3532 struct frame_id
*fid
= (struct frame_id
*) args
;
3533 struct frame_info
*frame
;
3535 frame
= frame_find_by_id (*fid
);
3537 /* If inf_status->selected_frame_id is NULL, there was no previously
3541 warning ("Unable to restore previously selected frame.\n");
3545 select_frame (frame
);
3551 restore_inferior_status (struct inferior_status
*inf_status
)
3553 stop_signal
= inf_status
->stop_signal
;
3554 stop_pc
= inf_status
->stop_pc
;
3555 stop_step
= inf_status
->stop_step
;
3556 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3557 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3558 trap_expected
= inf_status
->trap_expected
;
3559 step_range_start
= inf_status
->step_range_start
;
3560 step_range_end
= inf_status
->step_range_end
;
3561 step_frame_id
= inf_status
->step_frame_id
;
3562 step_over_calls
= inf_status
->step_over_calls
;
3563 stop_after_trap
= inf_status
->stop_after_trap
;
3564 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
3565 bpstat_clear (&stop_bpstat
);
3566 stop_bpstat
= inf_status
->stop_bpstat
;
3567 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3568 proceed_to_finish
= inf_status
->proceed_to_finish
;
3570 /* FIXME: Is the restore of stop_registers always needed. */
3571 regcache_xfree (stop_registers
);
3572 stop_registers
= inf_status
->stop_registers
;
3574 /* The inferior can be gone if the user types "print exit(0)"
3575 (and perhaps other times). */
3576 if (target_has_execution
)
3577 /* NB: The register write goes through to the target. */
3578 regcache_cpy (current_regcache
, inf_status
->registers
);
3579 regcache_xfree (inf_status
->registers
);
3581 /* FIXME: If we are being called after stopping in a function which
3582 is called from gdb, we should not be trying to restore the
3583 selected frame; it just prints a spurious error message (The
3584 message is useful, however, in detecting bugs in gdb (like if gdb
3585 clobbers the stack)). In fact, should we be restoring the
3586 inferior status at all in that case? . */
3588 if (target_has_stack
&& inf_status
->restore_stack_info
)
3590 /* The point of catch_errors is that if the stack is clobbered,
3591 walking the stack might encounter a garbage pointer and
3592 error() trying to dereference it. */
3594 (restore_selected_frame
, &inf_status
->selected_frame_id
,
3595 "Unable to restore previously selected frame:\n",
3596 RETURN_MASK_ERROR
) == 0)
3597 /* Error in restoring the selected frame. Select the innermost
3599 select_frame (get_current_frame ());
3607 do_restore_inferior_status_cleanup (void *sts
)
3609 restore_inferior_status (sts
);
3613 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
3615 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
3619 discard_inferior_status (struct inferior_status
*inf_status
)
3621 /* See save_inferior_status for info on stop_bpstat. */
3622 bpstat_clear (&inf_status
->stop_bpstat
);
3623 regcache_xfree (inf_status
->registers
);
3624 regcache_xfree (inf_status
->stop_registers
);
3629 inferior_has_forked (int pid
, int *child_pid
)
3631 struct target_waitstatus last
;
3634 get_last_target_status (&last_ptid
, &last
);
3636 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
3639 if (ptid_get_pid (last_ptid
) != pid
)
3642 *child_pid
= last
.value
.related_pid
;
3647 inferior_has_vforked (int pid
, int *child_pid
)
3649 struct target_waitstatus last
;
3652 get_last_target_status (&last_ptid
, &last
);
3654 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
3657 if (ptid_get_pid (last_ptid
) != pid
)
3660 *child_pid
= last
.value
.related_pid
;
3665 inferior_has_execd (int pid
, char **execd_pathname
)
3667 struct target_waitstatus last
;
3670 get_last_target_status (&last_ptid
, &last
);
3672 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
3675 if (ptid_get_pid (last_ptid
) != pid
)
3678 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
3682 /* Oft used ptids */
3684 ptid_t minus_one_ptid
;
3686 /* Create a ptid given the necessary PID, LWP, and TID components. */
3689 ptid_build (int pid
, long lwp
, long tid
)
3699 /* Create a ptid from just a pid. */
3702 pid_to_ptid (int pid
)
3704 return ptid_build (pid
, 0, 0);
3707 /* Fetch the pid (process id) component from a ptid. */
3710 ptid_get_pid (ptid_t ptid
)
3715 /* Fetch the lwp (lightweight process) component from a ptid. */
3718 ptid_get_lwp (ptid_t ptid
)
3723 /* Fetch the tid (thread id) component from a ptid. */
3726 ptid_get_tid (ptid_t ptid
)
3731 /* ptid_equal() is used to test equality of two ptids. */
3734 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
3736 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
3737 && ptid1
.tid
== ptid2
.tid
);
3740 /* restore_inferior_ptid() will be used by the cleanup machinery
3741 to restore the inferior_ptid value saved in a call to
3742 save_inferior_ptid(). */
3745 restore_inferior_ptid (void *arg
)
3747 ptid_t
*saved_ptid_ptr
= arg
;
3748 inferior_ptid
= *saved_ptid_ptr
;
3752 /* Save the value of inferior_ptid so that it may be restored by a
3753 later call to do_cleanups(). Returns the struct cleanup pointer
3754 needed for later doing the cleanup. */
3757 save_inferior_ptid (void)
3759 ptid_t
*saved_ptid_ptr
;
3761 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
3762 *saved_ptid_ptr
= inferior_ptid
;
3763 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
3770 stop_registers
= regcache_xmalloc (current_gdbarch
);
3774 _initialize_infrun (void)
3777 register int numsigs
;
3778 struct cmd_list_element
*c
;
3780 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
3781 register_gdbarch_swap (NULL
, 0, build_infrun
);
3783 add_info ("signals", signals_info
,
3784 "What debugger does when program gets various signals.\n\
3785 Specify a signal as argument to print info on that signal only.");
3786 add_info_alias ("handle", "signals", 0);
3788 add_com ("handle", class_run
, handle_command
,
3789 concat ("Specify how to handle a signal.\n\
3790 Args are signals and actions to apply to those signals.\n\
3791 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3792 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3793 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3794 The special arg \"all\" is recognized to mean all signals except those\n\
3795 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3796 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3797 Stop means reenter debugger if this signal happens (implies print).\n\
3798 Print means print a message if this signal happens.\n\
3799 Pass means let program see this signal; otherwise program doesn't know.\n\
3800 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3801 Pass and Stop may be combined.", NULL
));
3804 add_com ("lz", class_info
, signals_info
,
3805 "What debugger does when program gets various signals.\n\
3806 Specify a signal as argument to print info on that signal only.");
3807 add_com ("z", class_run
, xdb_handle_command
,
3808 concat ("Specify how to handle a signal.\n\
3809 Args are signals and actions to apply to those signals.\n\
3810 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3811 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3812 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3813 The special arg \"all\" is recognized to mean all signals except those\n\
3814 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3815 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3816 nopass), \"Q\" (noprint)\n\
3817 Stop means reenter debugger if this signal happens (implies print).\n\
3818 Print means print a message if this signal happens.\n\
3819 Pass means let program see this signal; otherwise program doesn't know.\n\
3820 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3821 Pass and Stop may be combined.", NULL
));
3826 add_cmd ("stop", class_obscure
, not_just_help_class_command
, "There is no `stop' command, but you can set a hook on `stop'.\n\
3827 This allows you to set a list of commands to be run each time execution\n\
3828 of the program stops.", &cmdlist
);
3830 numsigs
= (int) TARGET_SIGNAL_LAST
;
3831 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
3832 signal_print
= (unsigned char *)
3833 xmalloc (sizeof (signal_print
[0]) * numsigs
);
3834 signal_program
= (unsigned char *)
3835 xmalloc (sizeof (signal_program
[0]) * numsigs
);
3836 for (i
= 0; i
< numsigs
; i
++)
3839 signal_print
[i
] = 1;
3840 signal_program
[i
] = 1;
3843 /* Signals caused by debugger's own actions
3844 should not be given to the program afterwards. */
3845 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
3846 signal_program
[TARGET_SIGNAL_INT
] = 0;
3848 /* Signals that are not errors should not normally enter the debugger. */
3849 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
3850 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
3851 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
3852 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
3853 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
3854 signal_print
[TARGET_SIGNAL_PROF
] = 0;
3855 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
3856 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
3857 signal_stop
[TARGET_SIGNAL_IO
] = 0;
3858 signal_print
[TARGET_SIGNAL_IO
] = 0;
3859 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
3860 signal_print
[TARGET_SIGNAL_POLL
] = 0;
3861 signal_stop
[TARGET_SIGNAL_URG
] = 0;
3862 signal_print
[TARGET_SIGNAL_URG
] = 0;
3863 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
3864 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
3866 /* These signals are used internally by user-level thread
3867 implementations. (See signal(5) on Solaris.) Like the above
3868 signals, a healthy program receives and handles them as part of
3869 its normal operation. */
3870 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
3871 signal_print
[TARGET_SIGNAL_LWP
] = 0;
3872 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
3873 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
3874 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
3875 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
3879 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
3880 (char *) &stop_on_solib_events
,
3881 "Set stopping for shared library events.\n\
3882 If nonzero, gdb will give control to the user when the dynamic linker\n\
3883 notifies gdb of shared library events. The most common event of interest\n\
3884 to the user would be loading/unloading of a new library.\n", &setlist
), &showlist
);
3887 c
= add_set_enum_cmd ("follow-fork-mode",
3889 follow_fork_mode_kind_names
, &follow_fork_mode_string
,
3890 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
3891 kernel problem. It's also not terribly useful without a GUI to
3892 help the user drive two debuggers. So for now, I'm disabling
3893 the "both" option. */
3894 /* "Set debugger response to a program call of fork \
3896 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3897 parent - the original process is debugged after a fork\n\
3898 child - the new process is debugged after a fork\n\
3899 both - both the parent and child are debugged after a fork\n\
3900 ask - the debugger will ask for one of the above choices\n\
3901 For \"both\", another copy of the debugger will be started to follow\n\
3902 the new child process. The original debugger will continue to follow\n\
3903 the original parent process. To distinguish their prompts, the\n\
3904 debugger copy's prompt will be changed.\n\
3905 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3906 By default, the debugger will follow the parent process.",
3908 "Set debugger response to a program call of fork \
3910 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3911 parent - the original process is debugged after a fork\n\
3912 child - the new process is debugged after a fork\n\
3913 ask - the debugger will ask for one of the above choices\n\
3914 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3915 By default, the debugger will follow the parent process.", &setlist
);
3916 add_show_from_set (c
, &showlist
);
3918 c
= add_set_enum_cmd ("scheduler-locking", class_run
, scheduler_enums
, /* array of string names */
3919 &scheduler_mode
, /* current mode */
3920 "Set mode for locking scheduler during execution.\n\
3921 off == no locking (threads may preempt at any time)\n\
3922 on == full locking (no thread except the current thread may run)\n\
3923 step == scheduler locked during every single-step operation.\n\
3924 In this mode, no other thread may run during a step command.\n\
3925 Other threads may run while stepping over a function call ('next').", &setlist
);
3927 set_cmd_sfunc (c
, set_schedlock_func
); /* traps on target vector */
3928 add_show_from_set (c
, &showlist
);
3930 c
= add_set_cmd ("step-mode", class_run
,
3931 var_boolean
, (char *) &step_stop_if_no_debug
,
3932 "Set mode of the step operation. When set, doing a step over a\n\
3933 function without debug line information will stop at the first\n\
3934 instruction of that function. Otherwise, the function is skipped and\n\
3935 the step command stops at a different source line.", &setlist
);
3936 add_show_from_set (c
, &showlist
);
3938 /* ptid initializations */
3939 null_ptid
= ptid_build (0, 0, 0);
3940 minus_one_ptid
= ptid_build (-1, 0, 0);
3941 inferior_ptid
= null_ptid
;
3942 target_last_wait_ptid
= minus_one_ptid
;