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, 2004 Free
6 Software Foundation, Inc.
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 #include "gdb_assert.h"
49 /* Prototypes for local functions */
51 static void signals_info (char *, int);
53 static void handle_command (char *, int);
55 static void sig_print_info (enum target_signal);
57 static void sig_print_header (void);
59 static void resume_cleanups (void *);
61 static int hook_stop_stub (void *);
63 static void delete_breakpoint_current_contents (void *);
65 static int restore_selected_frame (void *);
67 static void build_infrun (void);
69 static int follow_fork (void);
71 static void set_schedlock_func (char *args, int from_tty,
72 struct cmd_list_element *c);
74 struct execution_control_state;
76 static int currently_stepping (struct execution_control_state *ecs);
78 static void xdb_handle_command (char *args, int from_tty);
80 static int prepare_to_proceed (void);
82 void _initialize_infrun (void);
84 int inferior_ignoring_startup_exec_events = 0;
85 int inferior_ignoring_leading_exec_events = 0;
87 /* When set, stop the 'step' command if we enter a function which has
88 no line number information. The normal behavior is that we step
89 over such function. */
90 int step_stop_if_no_debug = 0;
92 /* In asynchronous mode, but simulating synchronous execution. */
94 int sync_execution = 0;
96 /* wait_for_inferior and normal_stop use this to notify the user
97 when the inferior stopped in a different thread than it had been
100 static ptid_t previous_inferior_ptid;
102 /* This is true for configurations that may follow through execl() and
103 similar functions. At present this is only true for HP-UX native. */
105 #ifndef MAY_FOLLOW_EXEC
106 #define MAY_FOLLOW_EXEC (0)
109 static int may_follow_exec = MAY_FOLLOW_EXEC;
111 /* If the program uses ELF-style shared libraries, then calls to
112 functions in shared libraries go through stubs, which live in a
113 table called the PLT (Procedure Linkage Table). The first time the
114 function is called, the stub sends control to the dynamic linker,
115 which looks up the function's real address, patches the stub so
116 that future calls will go directly to the function, and then passes
117 control to the function.
119 If we are stepping at the source level, we don't want to see any of
120 this --- we just want to skip over the stub and the dynamic linker.
121 The simple approach is to single-step until control leaves the
124 However, on some systems (e.g., Red Hat's 5.2 distribution) the
125 dynamic linker calls functions in the shared C library, so you
126 can't tell from the PC alone whether the dynamic linker is still
127 running. In this case, we use a step-resume breakpoint to get us
128 past the dynamic linker, as if we were using "next" to step over a
131 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
132 linker code or not. Normally, this means we single-step. However,
133 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
134 address where we can place a step-resume breakpoint to get past the
135 linker's symbol resolution function.
137 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
138 pretty portable way, by comparing the PC against the address ranges
139 of the dynamic linker's sections.
141 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
142 it depends on internal details of the dynamic linker. It's usually
143 not too hard to figure out where to put a breakpoint, but it
144 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
145 sanity checking. If it can't figure things out, returning zero and
146 getting the (possibly confusing) stepping behavior is better than
147 signalling an error, which will obscure the change in the
150 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
151 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
154 /* This function returns TRUE if pc is the address of an instruction
155 that lies within the dynamic linker (such as the event hook, or the
158 This function must be used only when a dynamic linker event has
159 been caught, and the inferior is being stepped out of the hook, or
160 undefined results are guaranteed. */
162 #ifndef SOLIB_IN_DYNAMIC_LINKER
163 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
166 /* On MIPS16, a function that returns a floating point value may call
167 a library helper function to copy the return value to a floating point
168 register. The IGNORE_HELPER_CALL macro returns non-zero if we
169 should ignore (i.e. step over) this function call. */
170 #ifndef IGNORE_HELPER_CALL
171 #define IGNORE_HELPER_CALL(pc) 0
174 /* On some systems, the PC may be left pointing at an instruction that won't
175 actually be executed. This is usually indicated by a bit in the PSW. If
176 we find ourselves in such a state, then we step the target beyond the
177 nullified instruction before returning control to the user so as to avoid
180 #ifndef INSTRUCTION_NULLIFIED
181 #define INSTRUCTION_NULLIFIED 0
184 /* We can't step off a permanent breakpoint in the ordinary way, because we
185 can't remove it. Instead, we have to advance the PC to the next
186 instruction. This macro should expand to a pointer to a function that
187 does that, or zero if we have no such function. If we don't have a
188 definition for it, we have to report an error. */
189 #ifndef SKIP_PERMANENT_BREAKPOINT
190 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
192 default_skip_permanent_breakpoint (void)
195 The program is stopped at a permanent breakpoint, but GDB does not know\n\
196 how to step past a permanent breakpoint on this architecture. Try using\n\
197 a command like `return' or `jump' to continue execution.");
202 /* Convert the #defines into values. This is temporary until wfi control
203 flow is completely sorted out. */
205 #ifndef HAVE_STEPPABLE_WATCHPOINT
206 #define HAVE_STEPPABLE_WATCHPOINT 0
208 #undef HAVE_STEPPABLE_WATCHPOINT
209 #define HAVE_STEPPABLE_WATCHPOINT 1
212 #ifndef CANNOT_STEP_HW_WATCHPOINTS
213 #define CANNOT_STEP_HW_WATCHPOINTS 0
215 #undef CANNOT_STEP_HW_WATCHPOINTS
216 #define CANNOT_STEP_HW_WATCHPOINTS 1
219 /* Tables of how to react to signals; the user sets them. */
221 static unsigned char *signal_stop;
222 static unsigned char *signal_print;
223 static unsigned char *signal_program;
225 #define SET_SIGS(nsigs,sigs,flags) \
227 int signum = (nsigs); \
228 while (signum-- > 0) \
229 if ((sigs)[signum]) \
230 (flags)[signum] = 1; \
233 #define UNSET_SIGS(nsigs,sigs,flags) \
235 int signum = (nsigs); \
236 while (signum-- > 0) \
237 if ((sigs)[signum]) \
238 (flags)[signum] = 0; \
241 /* Value to pass to target_resume() to cause all threads to resume */
243 #define RESUME_ALL (pid_to_ptid (-1))
245 /* Command list pointer for the "stop" placeholder. */
247 static struct cmd_list_element *stop_command;
249 /* Nonzero if breakpoints are now inserted in the inferior. */
251 static int breakpoints_inserted;
253 /* Function inferior was in as of last step command. */
255 static struct symbol *step_start_function;
257 /* Nonzero if we are expecting a trace trap and should proceed from it. */
259 static int trap_expected;
262 /* Nonzero if we want to give control to the user when we're notified
263 of shared library events by the dynamic linker. */
264 static int stop_on_solib_events;
268 /* Nonzero if the next time we try to continue the inferior, it will
269 step one instruction and generate a spurious trace trap.
270 This is used to compensate for a bug in HP-UX. */
272 static int trap_expected_after_continue;
275 /* Nonzero means expecting a trace trap
276 and should stop the inferior and return silently when it happens. */
280 /* Nonzero means expecting a trap and caller will handle it themselves.
281 It is used after attach, due to attaching to a process;
282 when running in the shell before the child program has been exec'd;
283 and when running some kinds of remote stuff (FIXME?). */
285 enum stop_kind stop_soon;
287 /* Nonzero if proceed is being used for a "finish" command or a similar
288 situation when stop_registers should be saved. */
290 int proceed_to_finish;
292 /* Save register contents here when about to pop a stack dummy frame,
293 if-and-only-if proceed_to_finish is set.
294 Thus this contains the return value from the called function (assuming
295 values are returned in a register). */
297 struct regcache *stop_registers;
299 /* Nonzero if program stopped due to error trying to insert breakpoints. */
301 static int breakpoints_failed;
303 /* Nonzero after stop if current stack frame should be printed. */
305 static int stop_print_frame;
307 static struct breakpoint *step_resume_breakpoint = NULL;
308 static struct breakpoint *through_sigtramp_breakpoint = NULL;
310 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
311 interactions with an inferior that is running a kernel function
312 (aka, a system call or "syscall"). wait_for_inferior therefore
313 may have a need to know when the inferior is in a syscall. This
314 is a count of the number of inferior threads which are known to
315 currently be running in a syscall. */
316 static int number_of_threads_in_syscalls;
318 /* This is a cached copy of the pid/waitstatus of the last event
319 returned by target_wait()/deprecated_target_wait_hook(). This
320 information is returned by get_last_target_status(). */
321 static ptid_t target_last_wait_ptid;
322 static struct target_waitstatus target_last_waitstatus;
324 /* This is used to remember when a fork, vfork or exec event
325 was caught by a catchpoint, and thus the event is to be
326 followed at the next resume of the inferior, and not
330 enum target_waitkind kind;
337 char *execd_pathname;
341 static const char follow_fork_mode_child[] = "child";
342 static const char follow_fork_mode_parent[] = "parent";
344 static const char *follow_fork_mode_kind_names[] = {
345 follow_fork_mode_child,
346 follow_fork_mode_parent,
350 static const char *follow_fork_mode_string = follow_fork_mode_parent;
356 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
358 return target_follow_fork (follow_child);
362 follow_inferior_reset_breakpoints (void)
364 /* Was there a step_resume breakpoint? (There was if the user
365 did a "next" at the fork() call.) If so, explicitly reset its
368 step_resumes are a form of bp that are made to be per-thread.
369 Since we created the step_resume bp when the parent process
370 was being debugged, and now are switching to the child process,
371 from the breakpoint package's viewpoint, that's a switch of
372 "threads". We must update the bp's notion of which thread
373 it is for, or it'll be ignored when it triggers. */
375 if (step_resume_breakpoint)
376 breakpoint_re_set_thread (step_resume_breakpoint);
378 /* Reinsert all breakpoints in the child. The user may have set
379 breakpoints after catching the fork, in which case those
380 were never set in the child, but only in the parent. This makes
381 sure the inserted breakpoints match the breakpoint list. */
383 breakpoint_re_set ();
384 insert_breakpoints ();
387 /* EXECD_PATHNAME is assumed to be non-NULL. */
390 follow_exec (int pid, char *execd_pathname)
393 struct target_ops *tgt;
395 if (!may_follow_exec)
398 /* This is an exec event that we actually wish to pay attention to.
399 Refresh our symbol table to the newly exec'd program, remove any
402 If there are breakpoints, they aren't really inserted now,
403 since the exec() transformed our inferior into a fresh set
406 We want to preserve symbolic breakpoints on the list, since
407 we have hopes that they can be reset after the new a.out's
408 symbol table is read.
410 However, any "raw" breakpoints must be removed from the list
411 (e.g., the solib bp's), since their address is probably invalid
414 And, we DON'T want to call delete_breakpoints() here, since
415 that may write the bp's "shadow contents" (the instruction
416 value that was overwritten witha TRAP instruction). Since
417 we now have a new a.out, those shadow contents aren't valid. */
418 update_breakpoints_after_exec ();
420 /* If there was one, it's gone now. We cannot truly step-to-next
421 statement through an exec(). */
422 step_resume_breakpoint = NULL;
423 step_range_start = 0;
426 /* If there was one, it's gone now. */
427 through_sigtramp_breakpoint = NULL;
429 /* What is this a.out's name? */
430 printf_unfiltered ("Executing new program: %s\n", execd_pathname);
432 /* We've followed the inferior through an exec. Therefore, the
433 inferior has essentially been killed & reborn. */
435 /* First collect the run target in effect. */
436 tgt = find_run_target ();
437 /* If we can't find one, things are in a very strange state... */
439 error ("Could find run target to save before following exec");
441 gdb_flush (gdb_stdout);
442 target_mourn_inferior ();
443 inferior_ptid = pid_to_ptid (saved_pid);
444 /* Because mourn_inferior resets inferior_ptid. */
447 /* That a.out is now the one to use. */
448 exec_file_attach (execd_pathname, 0);
450 /* And also is where symbols can be found. */
451 symbol_file_add_main (execd_pathname, 0);
453 /* Reset the shared library package. This ensures that we get
454 a shlib event when the child reaches "_start", at which point
455 the dld will have had a chance to initialize the child. */
456 #if defined(SOLIB_RESTART)
459 #ifdef SOLIB_CREATE_INFERIOR_HOOK
460 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
463 /* Reinsert all breakpoints. (Those which were symbolic have
464 been reset to the proper address in the new a.out, thanks
465 to symbol_file_command...) */
466 insert_breakpoints ();
468 /* The next resume of this inferior should bring it to the shlib
469 startup breakpoints. (If the user had also set bp's on
470 "main" from the old (parent) process, then they'll auto-
471 matically get reset there in the new process.) */
474 /* Non-zero if we just simulating a single-step. This is needed
475 because we cannot remove the breakpoints in the inferior process
476 until after the `wait' in `wait_for_inferior'. */
477 static int singlestep_breakpoints_inserted_p = 0;
479 /* The thread we inserted single-step breakpoints for. */
480 static ptid_t singlestep_ptid;
482 /* If another thread hit the singlestep breakpoint, we save the original
483 thread here so that we can resume single-stepping it later. */
484 static ptid_t saved_singlestep_ptid;
485 static int stepping_past_singlestep_breakpoint;
488 /* Things to clean up if we QUIT out of resume (). */
490 resume_cleanups (void *ignore)
495 static const char schedlock_off[] = "off";
496 static const char schedlock_on[] = "on";
497 static const char schedlock_step[] = "step";
498 static const char *scheduler_mode = schedlock_off;
499 static const char *scheduler_enums[] = {
507 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
509 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
510 the set command passed as a parameter. The clone operation will
511 include (BUG?) any ``set'' command callback, if present.
512 Commands like ``info set'' call all the ``show'' command
513 callbacks. Unfortunately, for ``show'' commands cloned from
514 ``set'', this includes callbacks belonging to ``set'' commands.
515 Making this worse, this only occures if add_show_from_set() is
516 called after add_cmd_sfunc() (BUG?). */
517 if (cmd_type (c) == set_cmd)
518 if (!target_can_lock_scheduler)
520 scheduler_mode = schedlock_off;
521 error ("Target '%s' cannot support this command.", target_shortname);
526 /* Resume the inferior, but allow a QUIT. This is useful if the user
527 wants to interrupt some lengthy single-stepping operation
528 (for child processes, the SIGINT goes to the inferior, and so
529 we get a SIGINT random_signal, but for remote debugging and perhaps
530 other targets, that's not true).
532 STEP nonzero if we should step (zero to continue instead).
533 SIG is the signal to give the inferior (zero for none). */
535 resume (int step, enum target_signal sig)
537 int should_resume = 1;
538 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
541 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
544 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
545 over an instruction that causes a page fault without triggering
546 a hardware watchpoint. The kernel properly notices that it shouldn't
547 stop, because the hardware watchpoint is not triggered, but it forgets
548 the step request and continues the program normally.
549 Work around the problem by removing hardware watchpoints if a step is
550 requested, GDB will check for a hardware watchpoint trigger after the
552 if (CANNOT_STEP_HW_WATCHPOINTS && step && breakpoints_inserted)
553 remove_hw_watchpoints ();
556 /* Normally, by the time we reach `resume', the breakpoints are either
557 removed or inserted, as appropriate. The exception is if we're sitting
558 at a permanent breakpoint; we need to step over it, but permanent
559 breakpoints can't be removed. So we have to test for it here. */
560 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here)
561 SKIP_PERMANENT_BREAKPOINT ();
563 if (SOFTWARE_SINGLE_STEP_P () && step)
565 /* Do it the hard way, w/temp breakpoints */
566 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ );
567 /* ...and don't ask hardware to do it. */
569 /* and do not pull these breakpoints until after a `wait' in
570 `wait_for_inferior' */
571 singlestep_breakpoints_inserted_p = 1;
572 singlestep_ptid = inferior_ptid;
575 /* If there were any forks/vforks/execs that were caught and are
576 now to be followed, then do so. */
577 switch (pending_follow.kind)
579 case TARGET_WAITKIND_FORKED:
580 case TARGET_WAITKIND_VFORKED:
581 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
586 case TARGET_WAITKIND_EXECD:
587 /* follow_exec is called as soon as the exec event is seen. */
588 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
595 /* Install inferior's terminal modes. */
596 target_terminal_inferior ();
602 resume_ptid = RESUME_ALL; /* Default */
604 if ((step || singlestep_breakpoints_inserted_p) &&
605 (stepping_past_singlestep_breakpoint
606 || (!breakpoints_inserted && breakpoint_here_p (read_pc ()))))
608 /* Stepping past a breakpoint without inserting breakpoints.
609 Make sure only the current thread gets to step, so that
610 other threads don't sneak past breakpoints while they are
613 resume_ptid = inferior_ptid;
616 if ((scheduler_mode == schedlock_on) ||
617 (scheduler_mode == schedlock_step &&
618 (step || singlestep_breakpoints_inserted_p)))
620 /* User-settable 'scheduler' mode requires solo thread resume. */
621 resume_ptid = inferior_ptid;
624 if (CANNOT_STEP_BREAKPOINT)
626 /* Most targets can step a breakpoint instruction, thus
627 executing it normally. But if this one cannot, just
628 continue and we will hit it anyway. */
629 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
632 target_resume (resume_ptid, step, sig);
635 discard_cleanups (old_cleanups);
639 /* Clear out all variables saying what to do when inferior is continued.
640 First do this, then set the ones you want, then call `proceed'. */
643 clear_proceed_status (void)
646 step_range_start = 0;
648 step_frame_id = null_frame_id;
649 step_over_calls = STEP_OVER_UNDEBUGGABLE;
651 stop_soon = NO_STOP_QUIETLY;
652 proceed_to_finish = 0;
653 breakpoint_proceeded = 1; /* We're about to proceed... */
655 /* Discard any remaining commands or status from previous stop. */
656 bpstat_clear (&stop_bpstat);
659 /* This should be suitable for any targets that support threads. */
662 prepare_to_proceed (void)
665 struct target_waitstatus wait_status;
667 /* Get the last target status returned by target_wait(). */
668 get_last_target_status (&wait_ptid, &wait_status);
670 /* Make sure we were stopped either at a breakpoint, or because
672 if (wait_status.kind != TARGET_WAITKIND_STOPPED
673 || (wait_status.value.sig != TARGET_SIGNAL_TRAP &&
674 wait_status.value.sig != TARGET_SIGNAL_INT))
679 if (!ptid_equal (wait_ptid, minus_one_ptid)
680 && !ptid_equal (inferior_ptid, wait_ptid))
682 /* Switched over from WAIT_PID. */
683 CORE_ADDR wait_pc = read_pc_pid (wait_ptid);
685 if (wait_pc != read_pc ())
687 /* Switch back to WAIT_PID thread. */
688 inferior_ptid = wait_ptid;
690 /* FIXME: This stuff came from switch_to_thread() in
691 thread.c (which should probably be a public function). */
692 flush_cached_frames ();
693 registers_changed ();
695 select_frame (get_current_frame ());
698 /* We return 1 to indicate that there is a breakpoint here,
699 so we need to step over it before continuing to avoid
700 hitting it straight away. */
701 if (breakpoint_here_p (wait_pc))
709 /* Record the pc of the program the last time it stopped. This is
710 just used internally by wait_for_inferior, but need to be preserved
711 over calls to it and cleared when the inferior is started. */
712 static CORE_ADDR prev_pc;
714 /* Basic routine for continuing the program in various fashions.
716 ADDR is the address to resume at, or -1 for resume where stopped.
717 SIGGNAL is the signal to give it, or 0 for none,
718 or -1 for act according to how it stopped.
719 STEP is nonzero if should trap after one instruction.
720 -1 means return after that and print nothing.
721 You should probably set various step_... variables
722 before calling here, if you are stepping.
724 You should call clear_proceed_status before calling proceed. */
727 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
732 step_start_function = find_pc_function (read_pc ());
736 if (addr == (CORE_ADDR) -1)
738 /* If there is a breakpoint at the address we will resume at,
739 step one instruction before inserting breakpoints
740 so that we do not stop right away (and report a second
741 hit at this breakpoint). */
743 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
746 #ifndef STEP_SKIPS_DELAY
747 #define STEP_SKIPS_DELAY(pc) (0)
748 #define STEP_SKIPS_DELAY_P (0)
750 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
751 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
752 is slow (it needs to read memory from the target). */
753 if (STEP_SKIPS_DELAY_P
754 && breakpoint_here_p (read_pc () + 4)
755 && STEP_SKIPS_DELAY (read_pc ()))
763 /* In a multi-threaded task we may select another thread
764 and then continue or step.
766 But if the old thread was stopped at a breakpoint, it
767 will immediately cause another breakpoint stop without
768 any execution (i.e. it will report a breakpoint hit
769 incorrectly). So we must step over it first.
771 prepare_to_proceed checks the current thread against the thread
772 that reported the most recent event. If a step-over is required
773 it returns TRUE and sets the current thread to the old thread. */
774 if (prepare_to_proceed () && breakpoint_here_p (read_pc ()))
778 if (trap_expected_after_continue)
780 /* If (step == 0), a trap will be automatically generated after
781 the first instruction is executed. Force step one
782 instruction to clear this condition. This should not occur
783 if step is nonzero, but it is harmless in that case. */
785 trap_expected_after_continue = 0;
787 #endif /* HP_OS_BUG */
790 /* We will get a trace trap after one instruction.
791 Continue it automatically and insert breakpoints then. */
795 insert_breakpoints ();
796 /* If we get here there was no call to error() in
797 insert breakpoints -- so they were inserted. */
798 breakpoints_inserted = 1;
801 if (siggnal != TARGET_SIGNAL_DEFAULT)
802 stop_signal = siggnal;
803 /* If this signal should not be seen by program,
804 give it zero. Used for debugging signals. */
805 else if (!signal_program[stop_signal])
806 stop_signal = TARGET_SIGNAL_0;
808 annotate_starting ();
810 /* Make sure that output from GDB appears before output from the
812 gdb_flush (gdb_stdout);
814 /* Refresh prev_pc value just prior to resuming. This used to be
815 done in stop_stepping, however, setting prev_pc there did not handle
816 scenarios such as inferior function calls or returning from
817 a function via the return command. In those cases, the prev_pc
818 value was not set properly for subsequent commands. The prev_pc value
819 is used to initialize the starting line number in the ecs. With an
820 invalid value, the gdb next command ends up stopping at the position
821 represented by the next line table entry past our start position.
822 On platforms that generate one line table entry per line, this
823 is not a problem. However, on the ia64, the compiler generates
824 extraneous line table entries that do not increase the line number.
825 When we issue the gdb next command on the ia64 after an inferior call
826 or a return command, we often end up a few instructions forward, still
827 within the original line we started.
829 An attempt was made to have init_execution_control_state () refresh
830 the prev_pc value before calculating the line number. This approach
831 did not work because on platforms that use ptrace, the pc register
832 cannot be read unless the inferior is stopped. At that point, we
833 are not guaranteed the inferior is stopped and so the read_pc ()
834 call can fail. Setting the prev_pc value here ensures the value is
835 updated correctly when the inferior is stopped. */
836 prev_pc = read_pc ();
838 /* Resume inferior. */
839 resume (oneproc || step || bpstat_should_step (), stop_signal);
841 /* Wait for it to stop (if not standalone)
842 and in any case decode why it stopped, and act accordingly. */
843 /* Do this only if we are not using the event loop, or if the target
844 does not support asynchronous execution. */
845 if (!event_loop_p || !target_can_async_p ())
847 wait_for_inferior ();
853 /* Start remote-debugging of a machine over a serial link. */
859 init_wait_for_inferior ();
860 stop_soon = STOP_QUIETLY;
863 /* Always go on waiting for the target, regardless of the mode. */
864 /* FIXME: cagney/1999-09-23: At present it isn't possible to
865 indicate to wait_for_inferior that a target should timeout if
866 nothing is returned (instead of just blocking). Because of this,
867 targets expecting an immediate response need to, internally, set
868 things up so that the target_wait() is forced to eventually
870 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
871 differentiate to its caller what the state of the target is after
872 the initial open has been performed. Here we're assuming that
873 the target has stopped. It should be possible to eventually have
874 target_open() return to the caller an indication that the target
875 is currently running and GDB state should be set to the same as
877 wait_for_inferior ();
881 /* Initialize static vars when a new inferior begins. */
884 init_wait_for_inferior (void)
886 /* These are meaningless until the first time through wait_for_inferior. */
890 trap_expected_after_continue = 0;
892 breakpoints_inserted = 0;
893 breakpoint_init_inferior (inf_starting);
895 /* Don't confuse first call to proceed(). */
896 stop_signal = TARGET_SIGNAL_0;
898 /* The first resume is not following a fork/vfork/exec. */
899 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
901 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
902 number_of_threads_in_syscalls = 0;
904 clear_proceed_status ();
906 stepping_past_singlestep_breakpoint = 0;
910 delete_breakpoint_current_contents (void *arg)
912 struct breakpoint **breakpointp = (struct breakpoint **) arg;
913 if (*breakpointp != NULL)
915 delete_breakpoint (*breakpointp);
920 /* This enum encodes possible reasons for doing a target_wait, so that
921 wfi can call target_wait in one place. (Ultimately the call will be
922 moved out of the infinite loop entirely.) */
926 infwait_normal_state,
927 infwait_thread_hop_state,
928 infwait_nullified_state,
929 infwait_nonstep_watch_state
932 /* Why did the inferior stop? Used to print the appropriate messages
933 to the interface from within handle_inferior_event(). */
934 enum inferior_stop_reason
936 /* We don't know why. */
938 /* Step, next, nexti, stepi finished. */
940 /* Found breakpoint. */
942 /* Inferior terminated by signal. */
944 /* Inferior exited. */
946 /* Inferior received signal, and user asked to be notified. */
950 /* This structure contains what used to be local variables in
951 wait_for_inferior. Probably many of them can return to being
952 locals in handle_inferior_event. */
954 struct execution_control_state
956 struct target_waitstatus ws;
957 struct target_waitstatus *wp;
960 CORE_ADDR stop_func_start;
961 CORE_ADDR stop_func_end;
962 char *stop_func_name;
963 struct symtab_and_line sal;
964 int remove_breakpoints_on_following_step;
966 struct symtab *current_symtab;
967 int handling_longjmp; /* FIXME */
969 ptid_t saved_inferior_ptid;
971 int stepping_through_solib_after_catch;
972 bpstat stepping_through_solib_catchpoints;
973 int enable_hw_watchpoints_after_wait;
974 int stepping_through_sigtramp;
975 int new_thread_event;
976 struct target_waitstatus tmpstatus;
977 enum infwait_states infwait_state;
982 void init_execution_control_state (struct execution_control_state *ecs);
984 static void handle_step_into_function (struct execution_control_state *ecs);
985 void handle_inferior_event (struct execution_control_state *ecs);
987 static void check_sigtramp2 (struct execution_control_state *ecs);
988 static void step_into_function (struct execution_control_state *ecs);
989 static void step_over_function (struct execution_control_state *ecs);
990 static void stop_stepping (struct execution_control_state *ecs);
991 static void prepare_to_wait (struct execution_control_state *ecs);
992 static void keep_going (struct execution_control_state *ecs);
993 static void print_stop_reason (enum inferior_stop_reason stop_reason,
996 /* Wait for control to return from inferior to debugger.
997 If inferior gets a signal, we may decide to start it up again
998 instead of returning. That is why there is a loop in this function.
999 When this function actually returns it means the inferior
1000 should be left stopped and GDB should read more commands. */
1003 wait_for_inferior (void)
1005 struct cleanup *old_cleanups;
1006 struct execution_control_state ecss;
1007 struct execution_control_state *ecs;
1009 old_cleanups = make_cleanup (delete_step_resume_breakpoint,
1010 &step_resume_breakpoint);
1011 make_cleanup (delete_breakpoint_current_contents,
1012 &through_sigtramp_breakpoint);
1014 /* wfi still stays in a loop, so it's OK just to take the address of
1015 a local to get the ecs pointer. */
1018 /* Fill in with reasonable starting values. */
1019 init_execution_control_state (ecs);
1021 /* We'll update this if & when we switch to a new thread. */
1022 previous_inferior_ptid = inferior_ptid;
1024 overlay_cache_invalid = 1;
1026 /* We have to invalidate the registers BEFORE calling target_wait
1027 because they can be loaded from the target while in target_wait.
1028 This makes remote debugging a bit more efficient for those
1029 targets that provide critical registers as part of their normal
1030 status mechanism. */
1032 registers_changed ();
1036 if (deprecated_target_wait_hook)
1037 ecs->ptid = deprecated_target_wait_hook (ecs->waiton_ptid, ecs->wp);
1039 ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp);
1041 /* Now figure out what to do with the result of the result. */
1042 handle_inferior_event (ecs);
1044 if (!ecs->wait_some_more)
1047 do_cleanups (old_cleanups);
1050 /* Asynchronous version of wait_for_inferior. It is called by the
1051 event loop whenever a change of state is detected on the file
1052 descriptor corresponding to the target. It can be called more than
1053 once to complete a single execution command. In such cases we need
1054 to keep the state in a global variable ASYNC_ECSS. If it is the
1055 last time that this function is called for a single execution
1056 command, then report to the user that the inferior has stopped, and
1057 do the necessary cleanups. */
1059 struct execution_control_state async_ecss;
1060 struct execution_control_state *async_ecs;
1063 fetch_inferior_event (void *client_data)
1065 static struct cleanup *old_cleanups;
1067 async_ecs = &async_ecss;
1069 if (!async_ecs->wait_some_more)
1071 old_cleanups = make_exec_cleanup (delete_step_resume_breakpoint,
1072 &step_resume_breakpoint);
1073 make_exec_cleanup (delete_breakpoint_current_contents,
1074 &through_sigtramp_breakpoint);
1076 /* Fill in with reasonable starting values. */
1077 init_execution_control_state (async_ecs);
1079 /* We'll update this if & when we switch to a new thread. */
1080 previous_inferior_ptid = inferior_ptid;
1082 overlay_cache_invalid = 1;
1084 /* We have to invalidate the registers BEFORE calling target_wait
1085 because they can be loaded from the target while in target_wait.
1086 This makes remote debugging a bit more efficient for those
1087 targets that provide critical registers as part of their normal
1088 status mechanism. */
1090 registers_changed ();
1093 if (deprecated_target_wait_hook)
1095 deprecated_target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp);
1097 async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp);
1099 /* Now figure out what to do with the result of the result. */
1100 handle_inferior_event (async_ecs);
1102 if (!async_ecs->wait_some_more)
1104 /* Do only the cleanups that have been added by this
1105 function. Let the continuations for the commands do the rest,
1106 if there are any. */
1107 do_exec_cleanups (old_cleanups);
1109 if (step_multi && stop_step)
1110 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
1112 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1116 /* Prepare an execution control state for looping through a
1117 wait_for_inferior-type loop. */
1120 init_execution_control_state (struct execution_control_state *ecs)
1122 /* ecs->another_trap? */
1123 ecs->random_signal = 0;
1124 ecs->remove_breakpoints_on_following_step = 0;
1125 ecs->handling_longjmp = 0; /* FIXME */
1126 ecs->update_step_sp = 0;
1127 ecs->stepping_through_solib_after_catch = 0;
1128 ecs->stepping_through_solib_catchpoints = NULL;
1129 ecs->enable_hw_watchpoints_after_wait = 0;
1130 ecs->stepping_through_sigtramp = 0;
1131 ecs->sal = find_pc_line (prev_pc, 0);
1132 ecs->current_line = ecs->sal.line;
1133 ecs->current_symtab = ecs->sal.symtab;
1134 ecs->infwait_state = infwait_normal_state;
1135 ecs->waiton_ptid = pid_to_ptid (-1);
1136 ecs->wp = &(ecs->ws);
1139 /* Call this function before setting step_resume_breakpoint, as a
1140 sanity check. There should never be more than one step-resume
1141 breakpoint per thread, so we should never be setting a new
1142 step_resume_breakpoint when one is already active. */
1144 check_for_old_step_resume_breakpoint (void)
1146 if (step_resume_breakpoint)
1148 ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1151 /* Return the cached copy of the last pid/waitstatus returned by
1152 target_wait()/deprecated_target_wait_hook(). The data is actually
1153 cached by handle_inferior_event(), which gets called immediately
1154 after target_wait()/deprecated_target_wait_hook(). */
1157 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
1159 *ptidp = target_last_wait_ptid;
1160 *status = target_last_waitstatus;
1163 /* Switch thread contexts, maintaining "infrun state". */
1166 context_switch (struct execution_control_state *ecs)
1168 /* Caution: it may happen that the new thread (or the old one!)
1169 is not in the thread list. In this case we must not attempt
1170 to "switch context", or we run the risk that our context may
1171 be lost. This may happen as a result of the target module
1172 mishandling thread creation. */
1174 if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid))
1175 { /* Perform infrun state context switch: */
1176 /* Save infrun state for the old thread. */
1177 save_infrun_state (inferior_ptid, prev_pc,
1178 trap_expected, step_resume_breakpoint,
1179 through_sigtramp_breakpoint, step_range_start,
1180 step_range_end, &step_frame_id,
1181 ecs->handling_longjmp, ecs->another_trap,
1182 ecs->stepping_through_solib_after_catch,
1183 ecs->stepping_through_solib_catchpoints,
1184 ecs->stepping_through_sigtramp,
1185 ecs->current_line, ecs->current_symtab, step_sp);
1187 /* Load infrun state for the new thread. */
1188 load_infrun_state (ecs->ptid, &prev_pc,
1189 &trap_expected, &step_resume_breakpoint,
1190 &through_sigtramp_breakpoint, &step_range_start,
1191 &step_range_end, &step_frame_id,
1192 &ecs->handling_longjmp, &ecs->another_trap,
1193 &ecs->stepping_through_solib_after_catch,
1194 &ecs->stepping_through_solib_catchpoints,
1195 &ecs->stepping_through_sigtramp,
1196 &ecs->current_line, &ecs->current_symtab, &step_sp);
1198 inferior_ptid = ecs->ptid;
1201 /* Handle the inferior event in the cases when we just stepped
1205 handle_step_into_function (struct execution_control_state *ecs)
1207 CORE_ADDR real_stop_pc;
1209 if ((step_over_calls == STEP_OVER_NONE)
1210 || ((step_range_end == 1)
1211 && in_prologue (prev_pc, ecs->stop_func_start)))
1213 /* I presume that step_over_calls is only 0 when we're
1214 supposed to be stepping at the assembly language level
1215 ("stepi"). Just stop. */
1216 /* Also, maybe we just did a "nexti" inside a prolog,
1217 so we thought it was a subroutine call but it was not.
1218 Stop as well. FENN */
1220 print_stop_reason (END_STEPPING_RANGE, 0);
1221 stop_stepping (ecs);
1225 if (step_over_calls == STEP_OVER_ALL || IGNORE_HELPER_CALL (stop_pc))
1227 /* We're doing a "next". */
1228 step_over_function (ecs);
1233 /* If we are in a function call trampoline (a stub between
1234 the calling routine and the real function), locate the real
1235 function. That's what tells us (a) whether we want to step
1236 into it at all, and (b) what prologue we want to run to
1237 the end of, if we do step into it. */
1238 real_stop_pc = skip_language_trampoline (stop_pc);
1239 if (real_stop_pc == 0)
1240 real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc);
1241 if (real_stop_pc != 0)
1242 ecs->stop_func_start = real_stop_pc;
1244 /* If we have line number information for the function we
1245 are thinking of stepping into, step into it.
1247 If there are several symtabs at that PC (e.g. with include
1248 files), just want to know whether *any* of them have line
1249 numbers. find_pc_line handles this. */
1251 struct symtab_and_line tmp_sal;
1253 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
1254 if (tmp_sal.line != 0)
1256 step_into_function (ecs);
1261 /* If we have no line number and the step-stop-if-no-debug
1262 is set, we stop the step so that the user has a chance to
1263 switch in assembly mode. */
1264 if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug)
1267 print_stop_reason (END_STEPPING_RANGE, 0);
1268 stop_stepping (ecs);
1272 step_over_function (ecs);
1278 adjust_pc_after_break (struct execution_control_state *ecs)
1282 /* If this target does not decrement the PC after breakpoints, then
1283 we have nothing to do. */
1284 if (DECR_PC_AFTER_BREAK == 0)
1287 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
1288 we aren't, just return.
1290 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
1291 affected by DECR_PC_AFTER_BREAK. Other waitkinds which are implemented
1292 by software breakpoints should be handled through the normal breakpoint
1295 NOTE drow/2004-01-31: On some targets, breakpoints may generate
1296 different signals (SIGILL or SIGEMT for instance), but it is less
1297 clear where the PC is pointing afterwards. It may not match
1298 DECR_PC_AFTER_BREAK. I don't know any specific target that generates
1299 these signals at breakpoints (the code has been in GDB since at least
1300 1992) so I can not guess how to handle them here.
1302 In earlier versions of GDB, a target with HAVE_NONSTEPPABLE_WATCHPOINTS
1303 would have the PC after hitting a watchpoint affected by
1304 DECR_PC_AFTER_BREAK. I haven't found any target with both of these set
1305 in GDB history, and it seems unlikely to be correct, so
1306 HAVE_NONSTEPPABLE_WATCHPOINTS is not checked here. */
1308 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
1311 if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP)
1314 /* Find the location where (if we've hit a breakpoint) the breakpoint would
1316 stop_pc = read_pc_pid (ecs->ptid) - DECR_PC_AFTER_BREAK;
1318 /* If we're software-single-stepping, then assume this is a breakpoint.
1319 NOTE drow/2004-01-17: This doesn't check that the PC matches, or that
1320 we're even in the right thread. The software-single-step code needs
1323 If we're not software-single-stepping, then we first check that there
1324 is an enabled software breakpoint at this address. If there is, and
1325 we weren't using hardware-single-step, then we've hit the breakpoint.
1327 If we were using hardware-single-step, we check prev_pc; if we just
1328 stepped over an inserted software breakpoint, then we should decrement
1329 the PC and eventually report hitting the breakpoint. The prev_pc check
1330 prevents us from decrementing the PC if we just stepped over a jump
1331 instruction and landed on the instruction after a breakpoint.
1333 The last bit checks that we didn't hit a breakpoint in a signal handler
1334 without an intervening stop in sigtramp, which is detected by a new
1335 stack pointer value below any usual function calling stack adjustments.
1337 NOTE drow/2004-01-17: I'm not sure that this is necessary. The check
1338 predates checking for software single step at the same time. Also,
1339 if we've moved into a signal handler we should have seen the
1342 if ((SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1343 || (software_breakpoint_inserted_here_p (stop_pc)
1344 && !(currently_stepping (ecs)
1345 && prev_pc != stop_pc
1346 && !(step_range_end && INNER_THAN (read_sp (), (step_sp - 16))))))
1347 write_pc_pid (stop_pc, ecs->ptid);
1350 /* Given an execution control state that has been freshly filled in
1351 by an event from the inferior, figure out what it means and take
1352 appropriate action. */
1354 int stepped_after_stopped_by_watchpoint;
1357 handle_inferior_event (struct execution_control_state *ecs)
1359 /* NOTE: cagney/2003-03-28: If you're looking at this code and
1360 thinking that the variable stepped_after_stopped_by_watchpoint
1361 isn't used, then you're wrong! The macro STOPPED_BY_WATCHPOINT,
1362 defined in the file "config/pa/nm-hppah.h", accesses the variable
1363 indirectly. Mutter something rude about the HP merge. */
1364 int sw_single_step_trap_p = 0;
1366 /* Cache the last pid/waitstatus. */
1367 target_last_wait_ptid = ecs->ptid;
1368 target_last_waitstatus = *ecs->wp;
1370 adjust_pc_after_break (ecs);
1372 switch (ecs->infwait_state)
1374 case infwait_thread_hop_state:
1375 /* Cancel the waiton_ptid. */
1376 ecs->waiton_ptid = pid_to_ptid (-1);
1377 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1378 is serviced in this loop, below. */
1379 if (ecs->enable_hw_watchpoints_after_wait)
1381 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1382 ecs->enable_hw_watchpoints_after_wait = 0;
1384 stepped_after_stopped_by_watchpoint = 0;
1387 case infwait_normal_state:
1388 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1389 is serviced in this loop, below. */
1390 if (ecs->enable_hw_watchpoints_after_wait)
1392 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1393 ecs->enable_hw_watchpoints_after_wait = 0;
1395 stepped_after_stopped_by_watchpoint = 0;
1398 case infwait_nullified_state:
1399 stepped_after_stopped_by_watchpoint = 0;
1402 case infwait_nonstep_watch_state:
1403 insert_breakpoints ();
1405 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1406 handle things like signals arriving and other things happening
1407 in combination correctly? */
1408 stepped_after_stopped_by_watchpoint = 1;
1412 internal_error (__FILE__, __LINE__, "bad switch");
1414 ecs->infwait_state = infwait_normal_state;
1416 flush_cached_frames ();
1418 /* If it's a new process, add it to the thread database */
1420 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
1421 && !in_thread_list (ecs->ptid));
1423 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1424 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
1426 add_thread (ecs->ptid);
1428 ui_out_text (uiout, "[New ");
1429 ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid));
1430 ui_out_text (uiout, "]\n");
1433 /* NOTE: This block is ONLY meant to be invoked in case of a
1434 "thread creation event"! If it is invoked for any other
1435 sort of event (such as a new thread landing on a breakpoint),
1436 the event will be discarded, which is almost certainly
1439 To avoid this, the low-level module (eg. target_wait)
1440 should call in_thread_list and add_thread, so that the
1441 new thread is known by the time we get here. */
1443 /* We may want to consider not doing a resume here in order
1444 to give the user a chance to play with the new thread.
1445 It might be good to make that a user-settable option. */
1447 /* At this point, all threads are stopped (happens
1448 automatically in either the OS or the native code).
1449 Therefore we need to continue all threads in order to
1452 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
1453 prepare_to_wait (ecs);
1458 switch (ecs->ws.kind)
1460 case TARGET_WAITKIND_LOADED:
1461 /* Ignore gracefully during startup of the inferior, as it
1462 might be the shell which has just loaded some objects,
1463 otherwise add the symbols for the newly loaded objects. */
1465 if (stop_soon == NO_STOP_QUIETLY)
1467 /* Remove breakpoints, SOLIB_ADD might adjust
1468 breakpoint addresses via breakpoint_re_set. */
1469 if (breakpoints_inserted)
1470 remove_breakpoints ();
1472 /* Check for any newly added shared libraries if we're
1473 supposed to be adding them automatically. Switch
1474 terminal for any messages produced by
1475 breakpoint_re_set. */
1476 target_terminal_ours_for_output ();
1477 /* NOTE: cagney/2003-11-25: Make certain that the target
1478 stack's section table is kept up-to-date. Architectures,
1479 (e.g., PPC64), use the section table to perform
1480 operations such as address => section name and hence
1481 require the table to contain all sections (including
1482 those found in shared libraries). */
1483 /* NOTE: cagney/2003-11-25: Pass current_target and not
1484 exec_ops to SOLIB_ADD. This is because current GDB is
1485 only tooled to propagate section_table changes out from
1486 the "current_target" (see target_resize_to_sections), and
1487 not up from the exec stratum. This, of course, isn't
1488 right. "infrun.c" should only interact with the
1489 exec/process stratum, instead relying on the target stack
1490 to propagate relevant changes (stop, section table
1491 changed, ...) up to other layers. */
1492 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
1493 target_terminal_inferior ();
1495 /* Reinsert breakpoints and continue. */
1496 if (breakpoints_inserted)
1497 insert_breakpoints ();
1500 resume (0, TARGET_SIGNAL_0);
1501 prepare_to_wait (ecs);
1504 case TARGET_WAITKIND_SPURIOUS:
1505 resume (0, TARGET_SIGNAL_0);
1506 prepare_to_wait (ecs);
1509 case TARGET_WAITKIND_EXITED:
1510 target_terminal_ours (); /* Must do this before mourn anyway */
1511 print_stop_reason (EXITED, ecs->ws.value.integer);
1513 /* Record the exit code in the convenience variable $_exitcode, so
1514 that the user can inspect this again later. */
1515 set_internalvar (lookup_internalvar ("_exitcode"),
1516 value_from_longest (builtin_type_int,
1517 (LONGEST) ecs->ws.value.integer));
1518 gdb_flush (gdb_stdout);
1519 target_mourn_inferior ();
1520 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */
1521 stop_print_frame = 0;
1522 stop_stepping (ecs);
1525 case TARGET_WAITKIND_SIGNALLED:
1526 stop_print_frame = 0;
1527 stop_signal = ecs->ws.value.sig;
1528 target_terminal_ours (); /* Must do this before mourn anyway */
1530 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1531 reach here unless the inferior is dead. However, for years
1532 target_kill() was called here, which hints that fatal signals aren't
1533 really fatal on some systems. If that's true, then some changes
1535 target_mourn_inferior ();
1537 print_stop_reason (SIGNAL_EXITED, stop_signal);
1538 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */
1539 stop_stepping (ecs);
1542 /* The following are the only cases in which we keep going;
1543 the above cases end in a continue or goto. */
1544 case TARGET_WAITKIND_FORKED:
1545 case TARGET_WAITKIND_VFORKED:
1546 stop_signal = TARGET_SIGNAL_TRAP;
1547 pending_follow.kind = ecs->ws.kind;
1549 pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid);
1550 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1552 stop_pc = read_pc ();
1554 stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
1556 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1558 /* If no catchpoint triggered for this, then keep going. */
1559 if (ecs->random_signal)
1561 stop_signal = TARGET_SIGNAL_0;
1565 goto process_event_stop_test;
1567 case TARGET_WAITKIND_EXECD:
1568 stop_signal = TARGET_SIGNAL_TRAP;
1570 /* NOTE drow/2002-12-05: This code should be pushed down into the
1571 target_wait function. Until then following vfork on HP/UX 10.20
1572 is probably broken by this. Of course, it's broken anyway. */
1573 /* Is this a target which reports multiple exec events per actual
1574 call to exec()? (HP-UX using ptrace does, for example.) If so,
1575 ignore all but the last one. Just resume the exec'r, and wait
1576 for the next exec event. */
1577 if (inferior_ignoring_leading_exec_events)
1579 inferior_ignoring_leading_exec_events--;
1580 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1581 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.
1583 target_resume (ecs->ptid, 0, TARGET_SIGNAL_0);
1584 prepare_to_wait (ecs);
1587 inferior_ignoring_leading_exec_events =
1588 target_reported_exec_events_per_exec_call () - 1;
1590 pending_follow.execd_pathname =
1591 savestring (ecs->ws.value.execd_pathname,
1592 strlen (ecs->ws.value.execd_pathname));
1594 /* This causes the eventpoints and symbol table to be reset. Must
1595 do this now, before trying to determine whether to stop. */
1596 follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname);
1597 xfree (pending_follow.execd_pathname);
1599 stop_pc = read_pc_pid (ecs->ptid);
1600 ecs->saved_inferior_ptid = inferior_ptid;
1601 inferior_ptid = ecs->ptid;
1603 stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
1605 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1606 inferior_ptid = ecs->saved_inferior_ptid;
1608 /* If no catchpoint triggered for this, then keep going. */
1609 if (ecs->random_signal)
1611 stop_signal = TARGET_SIGNAL_0;
1615 goto process_event_stop_test;
1617 /* These syscall events are returned on HP-UX, as part of its
1618 implementation of page-protection-based "hardware" watchpoints.
1619 HP-UX has unfortunate interactions between page-protections and
1620 some system calls. Our solution is to disable hardware watches
1621 when a system call is entered, and reenable them when the syscall
1622 completes. The downside of this is that we may miss the precise
1623 point at which a watched piece of memory is modified. "Oh well."
1625 Note that we may have multiple threads running, which may each
1626 enter syscalls at roughly the same time. Since we don't have a
1627 good notion currently of whether a watched piece of memory is
1628 thread-private, we'd best not have any page-protections active
1629 when any thread is in a syscall. Thus, we only want to reenable
1630 hardware watches when no threads are in a syscall.
1632 Also, be careful not to try to gather much state about a thread
1633 that's in a syscall. It's frequently a losing proposition. */
1634 case TARGET_WAITKIND_SYSCALL_ENTRY:
1635 number_of_threads_in_syscalls++;
1636 if (number_of_threads_in_syscalls == 1)
1638 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1640 resume (0, TARGET_SIGNAL_0);
1641 prepare_to_wait (ecs);
1644 /* Before examining the threads further, step this thread to
1645 get it entirely out of the syscall. (We get notice of the
1646 event when the thread is just on the verge of exiting a
1647 syscall. Stepping one instruction seems to get it back
1650 Note that although the logical place to reenable h/w watches
1651 is here, we cannot. We cannot reenable them before stepping
1652 the thread (this causes the next wait on the thread to hang).
1654 Nor can we enable them after stepping until we've done a wait.
1655 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1656 here, which will be serviced immediately after the target
1658 case TARGET_WAITKIND_SYSCALL_RETURN:
1659 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
1661 if (number_of_threads_in_syscalls > 0)
1663 number_of_threads_in_syscalls--;
1664 ecs->enable_hw_watchpoints_after_wait =
1665 (number_of_threads_in_syscalls == 0);
1667 prepare_to_wait (ecs);
1670 case TARGET_WAITKIND_STOPPED:
1671 stop_signal = ecs->ws.value.sig;
1674 /* We had an event in the inferior, but we are not interested
1675 in handling it at this level. The lower layers have already
1676 done what needs to be done, if anything.
1678 One of the possible circumstances for this is when the
1679 inferior produces output for the console. The inferior has
1680 not stopped, and we are ignoring the event. Another possible
1681 circumstance is any event which the lower level knows will be
1682 reported multiple times without an intervening resume. */
1683 case TARGET_WAITKIND_IGNORE:
1684 prepare_to_wait (ecs);
1688 /* We may want to consider not doing a resume here in order to give
1689 the user a chance to play with the new thread. It might be good
1690 to make that a user-settable option. */
1692 /* At this point, all threads are stopped (happens automatically in
1693 either the OS or the native code). Therefore we need to continue
1694 all threads in order to make progress. */
1695 if (ecs->new_thread_event)
1697 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
1698 prepare_to_wait (ecs);
1702 stop_pc = read_pc_pid (ecs->ptid);
1704 if (stepping_past_singlestep_breakpoint)
1706 gdb_assert (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p);
1707 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
1708 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
1710 stepping_past_singlestep_breakpoint = 0;
1712 /* We've either finished single-stepping past the single-step
1713 breakpoint, or stopped for some other reason. It would be nice if
1714 we could tell, but we can't reliably. */
1715 if (stop_signal == TARGET_SIGNAL_TRAP)
1717 /* Pull the single step breakpoints out of the target. */
1718 SOFTWARE_SINGLE_STEP (0, 0);
1719 singlestep_breakpoints_inserted_p = 0;
1721 ecs->random_signal = 0;
1723 ecs->ptid = saved_singlestep_ptid;
1724 context_switch (ecs);
1725 if (deprecated_context_hook)
1726 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
1728 resume (1, TARGET_SIGNAL_0);
1729 prepare_to_wait (ecs);
1734 stepping_past_singlestep_breakpoint = 0;
1736 /* See if a thread hit a thread-specific breakpoint that was meant for
1737 another thread. If so, then step that thread past the breakpoint,
1740 if (stop_signal == TARGET_SIGNAL_TRAP)
1742 int thread_hop_needed = 0;
1744 /* Check if a regular breakpoint has been hit before checking
1745 for a potential single step breakpoint. Otherwise, GDB will
1746 not see this breakpoint hit when stepping onto breakpoints. */
1747 if (breakpoints_inserted && breakpoint_here_p (stop_pc))
1749 ecs->random_signal = 0;
1750 if (!breakpoint_thread_match (stop_pc, ecs->ptid))
1751 thread_hop_needed = 1;
1753 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1755 ecs->random_signal = 0;
1756 /* The call to in_thread_list is necessary because PTIDs sometimes
1757 change when we go from single-threaded to multi-threaded. If
1758 the singlestep_ptid is still in the list, assume that it is
1759 really different from ecs->ptid. */
1760 if (!ptid_equal (singlestep_ptid, ecs->ptid)
1761 && in_thread_list (singlestep_ptid))
1763 thread_hop_needed = 1;
1764 stepping_past_singlestep_breakpoint = 1;
1765 saved_singlestep_ptid = singlestep_ptid;
1769 if (thread_hop_needed)
1773 /* Saw a breakpoint, but it was hit by the wrong thread.
1776 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1778 /* Pull the single step breakpoints out of the target. */
1779 SOFTWARE_SINGLE_STEP (0, 0);
1780 singlestep_breakpoints_inserted_p = 0;
1783 remove_status = remove_breakpoints ();
1784 /* Did we fail to remove breakpoints? If so, try
1785 to set the PC past the bp. (There's at least
1786 one situation in which we can fail to remove
1787 the bp's: On HP-UX's that use ttrace, we can't
1788 change the address space of a vforking child
1789 process until the child exits (well, okay, not
1790 then either :-) or execs. */
1791 if (remove_status != 0)
1793 /* FIXME! This is obviously non-portable! */
1794 write_pc_pid (stop_pc + 4, ecs->ptid);
1795 /* We need to restart all the threads now,
1796 * unles we're running in scheduler-locked mode.
1797 * Use currently_stepping to determine whether to
1800 /* FIXME MVS: is there any reason not to call resume()? */
1801 if (scheduler_mode == schedlock_on)
1802 target_resume (ecs->ptid,
1803 currently_stepping (ecs), TARGET_SIGNAL_0);
1805 target_resume (RESUME_ALL,
1806 currently_stepping (ecs), TARGET_SIGNAL_0);
1807 prepare_to_wait (ecs);
1812 breakpoints_inserted = 0;
1813 if (!ptid_equal (inferior_ptid, ecs->ptid))
1814 context_switch (ecs);
1815 ecs->waiton_ptid = ecs->ptid;
1816 ecs->wp = &(ecs->ws);
1817 ecs->another_trap = 1;
1819 ecs->infwait_state = infwait_thread_hop_state;
1821 registers_changed ();
1825 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1827 sw_single_step_trap_p = 1;
1828 ecs->random_signal = 0;
1832 ecs->random_signal = 1;
1834 /* See if something interesting happened to the non-current thread. If
1835 so, then switch to that thread. */
1836 if (!ptid_equal (ecs->ptid, inferior_ptid))
1838 context_switch (ecs);
1840 if (deprecated_context_hook)
1841 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
1843 flush_cached_frames ();
1846 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1848 /* Pull the single step breakpoints out of the target. */
1849 SOFTWARE_SINGLE_STEP (0, 0);
1850 singlestep_breakpoints_inserted_p = 0;
1853 /* If PC is pointing at a nullified instruction, then step beyond
1854 it so that the user won't be confused when GDB appears to be ready
1857 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1858 if (INSTRUCTION_NULLIFIED)
1860 registers_changed ();
1861 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
1863 /* We may have received a signal that we want to pass to
1864 the inferior; therefore, we must not clobber the waitstatus
1867 ecs->infwait_state = infwait_nullified_state;
1868 ecs->waiton_ptid = ecs->ptid;
1869 ecs->wp = &(ecs->tmpstatus);
1870 prepare_to_wait (ecs);
1874 /* It may not be necessary to disable the watchpoint to stop over
1875 it. For example, the PA can (with some kernel cooperation)
1876 single step over a watchpoint without disabling the watchpoint. */
1877 if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1880 prepare_to_wait (ecs);
1884 /* It is far more common to need to disable a watchpoint to step
1885 the inferior over it. FIXME. What else might a debug
1886 register or page protection watchpoint scheme need here? */
1887 if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1889 /* At this point, we are stopped at an instruction which has
1890 attempted to write to a piece of memory under control of
1891 a watchpoint. The instruction hasn't actually executed
1892 yet. If we were to evaluate the watchpoint expression
1893 now, we would get the old value, and therefore no change
1894 would seem to have occurred.
1896 In order to make watchpoints work `right', we really need
1897 to complete the memory write, and then evaluate the
1898 watchpoint expression. The following code does that by
1899 removing the watchpoint (actually, all watchpoints and
1900 breakpoints), single-stepping the target, re-inserting
1901 watchpoints, and then falling through to let normal
1902 single-step processing handle proceed. Since this
1903 includes evaluating watchpoints, things will come to a
1904 stop in the correct manner. */
1906 remove_breakpoints ();
1907 registers_changed ();
1908 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */
1910 ecs->waiton_ptid = ecs->ptid;
1911 ecs->wp = &(ecs->ws);
1912 ecs->infwait_state = infwait_nonstep_watch_state;
1913 prepare_to_wait (ecs);
1917 /* It may be possible to simply continue after a watchpoint. */
1918 if (HAVE_CONTINUABLE_WATCHPOINT)
1919 STOPPED_BY_WATCHPOINT (ecs->ws);
1921 ecs->stop_func_start = 0;
1922 ecs->stop_func_end = 0;
1923 ecs->stop_func_name = 0;
1924 /* Don't care about return value; stop_func_start and stop_func_name
1925 will both be 0 if it doesn't work. */
1926 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
1927 &ecs->stop_func_start, &ecs->stop_func_end);
1928 ecs->stop_func_start += FUNCTION_START_OFFSET;
1929 ecs->another_trap = 0;
1930 bpstat_clear (&stop_bpstat);
1932 stop_stack_dummy = 0;
1933 stop_print_frame = 1;
1934 ecs->random_signal = 0;
1935 stopped_by_random_signal = 0;
1936 breakpoints_failed = 0;
1938 /* Look at the cause of the stop, and decide what to do.
1939 The alternatives are:
1940 1) break; to really stop and return to the debugger,
1941 2) drop through to start up again
1942 (set ecs->another_trap to 1 to single step once)
1943 3) set ecs->random_signal to 1, and the decision between 1 and 2
1944 will be made according to the signal handling tables. */
1946 /* First, distinguish signals caused by the debugger from signals
1947 that have to do with the program's own actions. Note that
1948 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
1949 on the operating system version. Here we detect when a SIGILL or
1950 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
1951 something similar for SIGSEGV, since a SIGSEGV will be generated
1952 when we're trying to execute a breakpoint instruction on a
1953 non-executable stack. This happens for call dummy breakpoints
1954 for architectures like SPARC that place call dummies on the
1957 if (stop_signal == TARGET_SIGNAL_TRAP
1958 || (breakpoints_inserted &&
1959 (stop_signal == TARGET_SIGNAL_ILL
1960 || stop_signal == TARGET_SIGNAL_SEGV
1961 || stop_signal == TARGET_SIGNAL_EMT))
1962 || stop_soon == STOP_QUIETLY
1963 || stop_soon == STOP_QUIETLY_NO_SIGSTOP)
1965 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
1967 stop_print_frame = 0;
1968 stop_stepping (ecs);
1972 /* This is originated from start_remote(), start_inferior() and
1973 shared libraries hook functions. */
1974 if (stop_soon == STOP_QUIETLY)
1976 stop_stepping (ecs);
1980 /* This originates from attach_command(). We need to overwrite
1981 the stop_signal here, because some kernels don't ignore a
1982 SIGSTOP in a subsequent ptrace(PTRACE_SONT,SOGSTOP) call.
1983 See more comments in inferior.h. */
1984 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP)
1986 stop_stepping (ecs);
1987 if (stop_signal == TARGET_SIGNAL_STOP)
1988 stop_signal = TARGET_SIGNAL_0;
1992 /* Don't even think about breakpoints
1993 if just proceeded over a breakpoint.
1995 However, if we are trying to proceed over a breakpoint
1996 and end up in sigtramp, then through_sigtramp_breakpoint
1997 will be set and we should check whether we've hit the
1999 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
2000 && through_sigtramp_breakpoint == NULL)
2001 bpstat_clear (&stop_bpstat);
2004 /* See if there is a breakpoint at the current PC. */
2005 stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
2007 /* Following in case break condition called a
2009 stop_print_frame = 1;
2012 /* NOTE: cagney/2003-03-29: These two checks for a random signal
2013 at one stage in the past included checks for an inferior
2014 function call's call dummy's return breakpoint. The original
2015 comment, that went with the test, read:
2017 ``End of a stack dummy. Some systems (e.g. Sony news) give
2018 another signal besides SIGTRAP, so check here as well as
2021 If someone ever tries to get get call dummys on a
2022 non-executable stack to work (where the target would stop
2023 with something like a SIGSEGV), then those tests might need
2024 to be re-instated. Given, however, that the tests were only
2025 enabled when momentary breakpoints were not being used, I
2026 suspect that it won't be the case.
2028 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
2029 be necessary for call dummies on a non-executable stack on
2032 if (stop_signal == TARGET_SIGNAL_TRAP)
2034 = !(bpstat_explains_signal (stop_bpstat)
2036 || (step_range_end && step_resume_breakpoint == NULL));
2039 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
2040 if (!ecs->random_signal)
2041 stop_signal = TARGET_SIGNAL_TRAP;
2045 /* When we reach this point, we've pretty much decided
2046 that the reason for stopping must've been a random
2047 (unexpected) signal. */
2050 ecs->random_signal = 1;
2052 process_event_stop_test:
2053 /* For the program's own signals, act according to
2054 the signal handling tables. */
2056 if (ecs->random_signal)
2058 /* Signal not for debugging purposes. */
2061 stopped_by_random_signal = 1;
2063 if (signal_print[stop_signal])
2066 target_terminal_ours_for_output ();
2067 print_stop_reason (SIGNAL_RECEIVED, stop_signal);
2069 if (signal_stop[stop_signal])
2071 stop_stepping (ecs);
2074 /* If not going to stop, give terminal back
2075 if we took it away. */
2077 target_terminal_inferior ();
2079 /* Clear the signal if it should not be passed. */
2080 if (signal_program[stop_signal] == 0)
2081 stop_signal = TARGET_SIGNAL_0;
2083 /* I'm not sure whether this needs to be check_sigtramp2 or
2084 whether it could/should be keep_going.
2086 This used to jump to step_over_function if we are stepping,
2089 Suppose the user does a `next' over a function call, and while
2090 that call is in progress, the inferior receives a signal for
2091 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2092 that case, when we reach this point, there is already a
2093 step-resume breakpoint established, right where it should be:
2094 immediately after the function call the user is "next"-ing
2095 over. If we call step_over_function now, two bad things
2098 - we'll create a new breakpoint, at wherever the current
2099 frame's return address happens to be. That could be
2100 anywhere, depending on what function call happens to be on
2101 the top of the stack at that point. Point is, it's probably
2102 not where we need it.
2104 - the existing step-resume breakpoint (which is at the correct
2105 address) will get orphaned: step_resume_breakpoint will point
2106 to the new breakpoint, and the old step-resume breakpoint
2107 will never be cleaned up.
2109 The old behavior was meant to help HP-UX single-step out of
2110 sigtramps. It would place the new breakpoint at prev_pc, which
2111 was certainly wrong. I don't know the details there, so fixing
2112 this probably breaks that. As with anything else, it's up to
2113 the HP-UX maintainer to furnish a fix that doesn't break other
2114 platforms. --JimB, 20 May 1999 */
2115 check_sigtramp2 (ecs);
2120 /* Handle cases caused by hitting a breakpoint. */
2122 CORE_ADDR jmp_buf_pc;
2123 struct bpstat_what what;
2125 what = bpstat_what (stop_bpstat);
2127 if (what.call_dummy)
2129 stop_stack_dummy = 1;
2131 trap_expected_after_continue = 1;
2135 switch (what.main_action)
2137 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
2138 /* If we hit the breakpoint at longjmp, disable it for the
2139 duration of this command. Then, install a temporary
2140 breakpoint at the target of the jmp_buf. */
2141 disable_longjmp_breakpoint ();
2142 remove_breakpoints ();
2143 breakpoints_inserted = 0;
2144 if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc))
2150 /* Need to blow away step-resume breakpoint, as it
2151 interferes with us */
2152 if (step_resume_breakpoint != NULL)
2154 delete_step_resume_breakpoint (&step_resume_breakpoint);
2156 /* Not sure whether we need to blow this away too, but probably
2157 it is like the step-resume breakpoint. */
2158 if (through_sigtramp_breakpoint != NULL)
2160 delete_breakpoint (through_sigtramp_breakpoint);
2161 through_sigtramp_breakpoint = NULL;
2165 /* FIXME - Need to implement nested temporary breakpoints */
2166 if (step_over_calls > 0)
2167 set_longjmp_resume_breakpoint (jmp_buf_pc, get_current_frame ());
2170 set_longjmp_resume_breakpoint (jmp_buf_pc, null_frame_id);
2171 ecs->handling_longjmp = 1; /* FIXME */
2175 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
2176 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
2177 remove_breakpoints ();
2178 breakpoints_inserted = 0;
2180 /* FIXME - Need to implement nested temporary breakpoints */
2182 && (frame_id_inner (get_frame_id (get_current_frame ()),
2185 ecs->another_trap = 1;
2190 disable_longjmp_breakpoint ();
2191 ecs->handling_longjmp = 0; /* FIXME */
2192 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
2194 /* else fallthrough */
2196 case BPSTAT_WHAT_SINGLE:
2197 if (breakpoints_inserted)
2199 remove_breakpoints ();
2201 breakpoints_inserted = 0;
2202 ecs->another_trap = 1;
2203 /* Still need to check other stuff, at least the case
2204 where we are stepping and step out of the right range. */
2207 case BPSTAT_WHAT_STOP_NOISY:
2208 stop_print_frame = 1;
2210 /* We are about to nuke the step_resume_breakpoint and
2211 through_sigtramp_breakpoint via the cleanup chain, so
2212 no need to worry about it here. */
2214 stop_stepping (ecs);
2217 case BPSTAT_WHAT_STOP_SILENT:
2218 stop_print_frame = 0;
2220 /* We are about to nuke the step_resume_breakpoint and
2221 through_sigtramp_breakpoint via the cleanup chain, so
2222 no need to worry about it here. */
2224 stop_stepping (ecs);
2227 case BPSTAT_WHAT_STEP_RESUME:
2228 /* This proably demands a more elegant solution, but, yeah
2231 This function's use of the simple variable
2232 step_resume_breakpoint doesn't seem to accomodate
2233 simultaneously active step-resume bp's, although the
2234 breakpoint list certainly can.
2236 If we reach here and step_resume_breakpoint is already
2237 NULL, then apparently we have multiple active
2238 step-resume bp's. We'll just delete the breakpoint we
2239 stopped at, and carry on.
2241 Correction: what the code currently does is delete a
2242 step-resume bp, but it makes no effort to ensure that
2243 the one deleted is the one currently stopped at. MVS */
2245 if (step_resume_breakpoint == NULL)
2247 step_resume_breakpoint =
2248 bpstat_find_step_resume_breakpoint (stop_bpstat);
2250 delete_step_resume_breakpoint (&step_resume_breakpoint);
2253 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2254 if (through_sigtramp_breakpoint)
2255 delete_breakpoint (through_sigtramp_breakpoint);
2256 through_sigtramp_breakpoint = NULL;
2258 /* If were waiting for a trap, hitting the step_resume_break
2259 doesn't count as getting it. */
2261 ecs->another_trap = 1;
2264 case BPSTAT_WHAT_CHECK_SHLIBS:
2265 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2268 /* Remove breakpoints, we eventually want to step over the
2269 shlib event breakpoint, and SOLIB_ADD might adjust
2270 breakpoint addresses via breakpoint_re_set. */
2271 if (breakpoints_inserted)
2272 remove_breakpoints ();
2273 breakpoints_inserted = 0;
2275 /* Check for any newly added shared libraries if we're
2276 supposed to be adding them automatically. Switch
2277 terminal for any messages produced by
2278 breakpoint_re_set. */
2279 target_terminal_ours_for_output ();
2280 /* NOTE: cagney/2003-11-25: Make certain that the target
2281 stack's section table is kept up-to-date. Architectures,
2282 (e.g., PPC64), use the section table to perform
2283 operations such as address => section name and hence
2284 require the table to contain all sections (including
2285 those found in shared libraries). */
2286 /* NOTE: cagney/2003-11-25: Pass current_target and not
2287 exec_ops to SOLIB_ADD. This is because current GDB is
2288 only tooled to propagate section_table changes out from
2289 the "current_target" (see target_resize_to_sections), and
2290 not up from the exec stratum. This, of course, isn't
2291 right. "infrun.c" should only interact with the
2292 exec/process stratum, instead relying on the target stack
2293 to propagate relevant changes (stop, section table
2294 changed, ...) up to other layers. */
2295 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
2296 target_terminal_inferior ();
2298 /* Try to reenable shared library breakpoints, additional
2299 code segments in shared libraries might be mapped in now. */
2300 re_enable_breakpoints_in_shlibs ();
2302 /* If requested, stop when the dynamic linker notifies
2303 gdb of events. This allows the user to get control
2304 and place breakpoints in initializer routines for
2305 dynamically loaded objects (among other things). */
2306 if (stop_on_solib_events || stop_stack_dummy)
2308 stop_stepping (ecs);
2312 /* If we stopped due to an explicit catchpoint, then the
2313 (see above) call to SOLIB_ADD pulled in any symbols
2314 from a newly-loaded library, if appropriate.
2316 We do want the inferior to stop, but not where it is
2317 now, which is in the dynamic linker callback. Rather,
2318 we would like it stop in the user's program, just after
2319 the call that caused this catchpoint to trigger. That
2320 gives the user a more useful vantage from which to
2321 examine their program's state. */
2322 else if (what.main_action ==
2323 BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2325 /* ??rehrauer: If I could figure out how to get the
2326 right return PC from here, we could just set a temp
2327 breakpoint and resume. I'm not sure we can without
2328 cracking open the dld's shared libraries and sniffing
2329 their unwind tables and text/data ranges, and that's
2330 not a terribly portable notion.
2332 Until that time, we must step the inferior out of the
2333 dld callback, and also out of the dld itself (and any
2334 code or stubs in libdld.sl, such as "shl_load" and
2335 friends) until we reach non-dld code. At that point,
2336 we can stop stepping. */
2337 bpstat_get_triggered_catchpoints (stop_bpstat,
2339 stepping_through_solib_catchpoints);
2340 ecs->stepping_through_solib_after_catch = 1;
2342 /* Be sure to lift all breakpoints, so the inferior does
2343 actually step past this point... */
2344 ecs->another_trap = 1;
2349 /* We want to step over this breakpoint, then keep going. */
2350 ecs->another_trap = 1;
2357 case BPSTAT_WHAT_LAST:
2358 /* Not a real code, but listed here to shut up gcc -Wall. */
2360 case BPSTAT_WHAT_KEEP_CHECKING:
2365 /* We come here if we hit a breakpoint but should not
2366 stop for it. Possibly we also were stepping
2367 and should stop for that. So fall through and
2368 test for stepping. But, if not stepping,
2371 /* Are we stepping to get the inferior out of the dynamic
2372 linker's hook (and possibly the dld itself) after catching
2374 if (ecs->stepping_through_solib_after_catch)
2376 #if defined(SOLIB_ADD)
2377 /* Have we reached our destination? If not, keep going. */
2378 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
2380 ecs->another_trap = 1;
2385 /* Else, stop and report the catchpoint(s) whose triggering
2386 caused us to begin stepping. */
2387 ecs->stepping_through_solib_after_catch = 0;
2388 bpstat_clear (&stop_bpstat);
2389 stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints);
2390 bpstat_clear (&ecs->stepping_through_solib_catchpoints);
2391 stop_print_frame = 1;
2392 stop_stepping (ecs);
2396 if (step_resume_breakpoint)
2398 /* Having a step-resume breakpoint overrides anything
2399 else having to do with stepping commands until
2400 that breakpoint is reached. */
2401 /* I'm not sure whether this needs to be check_sigtramp2 or
2402 whether it could/should be keep_going. */
2403 check_sigtramp2 (ecs);
2408 if (step_range_end == 0)
2410 /* Likewise if we aren't even stepping. */
2411 /* I'm not sure whether this needs to be check_sigtramp2 or
2412 whether it could/should be keep_going. */
2413 check_sigtramp2 (ecs);
2418 /* If stepping through a line, keep going if still within it.
2420 Note that step_range_end is the address of the first instruction
2421 beyond the step range, and NOT the address of the last instruction
2423 if (stop_pc >= step_range_start && stop_pc < step_range_end)
2425 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2426 So definately need to check for sigtramp here. */
2427 check_sigtramp2 (ecs);
2432 /* We stepped out of the stepping range. */
2434 /* If we are stepping at the source level and entered the runtime
2435 loader dynamic symbol resolution code, we keep on single stepping
2436 until we exit the run time loader code and reach the callee's
2438 if (step_over_calls == STEP_OVER_UNDEBUGGABLE
2439 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2441 CORE_ADDR pc_after_resolver =
2442 gdbarch_skip_solib_resolver (current_gdbarch, stop_pc);
2444 if (pc_after_resolver)
2446 /* Set up a step-resume breakpoint at the address
2447 indicated by SKIP_SOLIB_RESOLVER. */
2448 struct symtab_and_line sr_sal;
2450 sr_sal.pc = pc_after_resolver;
2452 check_for_old_step_resume_breakpoint ();
2453 step_resume_breakpoint =
2454 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2455 if (breakpoints_inserted)
2456 insert_breakpoints ();
2463 if (step_over_calls == STEP_OVER_UNDEBUGGABLE
2464 && ecs->stop_func_name == NULL)
2466 /* There is no symbol, not even a minimal symbol, corresponding
2467 to the address where we just stopped. So we just stepped
2468 inside undebuggable code. Since we want to step over this
2469 kind of code, we keep going until the inferior returns from
2470 the current function. */
2471 handle_step_into_function (ecs);
2475 /* We can't update step_sp every time through the loop, because
2476 reading the stack pointer would slow down stepping too much.
2477 But we can update it every time we leave the step range. */
2478 ecs->update_step_sp = 1;
2480 /* Did we just step into a singal trampoline (either by stepping out
2481 of a handler, or by taking a signal)? */
2482 if (get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME
2483 && !frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id))
2486 struct frame_id current_frame = get_frame_id (get_current_frame ());
2488 if (frame_id_inner (current_frame, step_frame_id))
2490 /* We have just taken a signal; go until we are back to
2491 the point where we took it and one more. */
2493 /* This code is needed at least in the following case:
2494 The user types "next" and then a signal arrives (before
2495 the "next" is done). */
2497 /* Note that if we are stopped at a breakpoint, then we need
2498 the step_resume breakpoint to override any breakpoints at
2499 the same location, so that we will still step over the
2500 breakpoint even though the signal happened. */
2501 struct symtab_and_line sr_sal;
2504 sr_sal.symtab = NULL;
2506 sr_sal.pc = prev_pc;
2507 /* We could probably be setting the frame to
2508 step_frame_id; I don't think anyone thought to try it. */
2509 check_for_old_step_resume_breakpoint ();
2510 step_resume_breakpoint =
2511 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2512 if (breakpoints_inserted)
2513 insert_breakpoints ();
2517 /* We just stepped out of a signal handler and into
2518 its calling trampoline.
2520 Normally, we'd call step_over_function from
2521 here, but for some reason GDB can't unwind the
2522 stack correctly to find the real PC for the point
2523 user code where the signal trampoline will return
2524 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2525 But signal trampolines are pretty small stubs of
2526 code, anyway, so it's OK instead to just
2527 single-step out. Note: assuming such trampolines
2528 don't exhibit recursion on any platform... */
2529 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2530 &ecs->stop_func_start,
2531 &ecs->stop_func_end);
2532 /* Readjust stepping range */
2533 step_range_start = ecs->stop_func_start;
2534 step_range_end = ecs->stop_func_end;
2535 ecs->stepping_through_sigtramp = 1;
2540 /* If this is stepi or nexti, make sure that the stepping range
2541 gets us past that instruction. */
2542 if (step_range_end == 1)
2543 /* FIXME: Does this run afoul of the code below which, if
2544 we step into the middle of a line, resets the stepping
2546 step_range_end = (step_range_start = prev_pc) + 1;
2548 ecs->remove_breakpoints_on_following_step = 1;
2553 if (frame_id_eq (get_frame_id (get_prev_frame (get_current_frame ())),
2556 /* It's a subroutine call. */
2557 handle_step_into_function (ecs);
2561 /* We've wandered out of the step range. */
2563 ecs->sal = find_pc_line (stop_pc, 0);
2565 if (step_range_end == 1)
2567 /* It is stepi or nexti. We always want to stop stepping after
2570 print_stop_reason (END_STEPPING_RANGE, 0);
2571 stop_stepping (ecs);
2575 /* If we're in the return path from a shared library trampoline,
2576 we want to proceed through the trampoline when stepping. */
2577 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2579 /* Determine where this trampoline returns. */
2580 CORE_ADDR real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc);
2582 /* Only proceed through if we know where it's going. */
2585 /* And put the step-breakpoint there and go until there. */
2586 struct symtab_and_line sr_sal;
2588 init_sal (&sr_sal); /* initialize to zeroes */
2589 sr_sal.pc = real_stop_pc;
2590 sr_sal.section = find_pc_overlay (sr_sal.pc);
2591 /* Do not specify what the fp should be when we stop
2592 since on some machines the prologue
2593 is where the new fp value is established. */
2594 check_for_old_step_resume_breakpoint ();
2595 step_resume_breakpoint =
2596 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2597 if (breakpoints_inserted)
2598 insert_breakpoints ();
2600 /* Restart without fiddling with the step ranges or
2607 if (ecs->sal.line == 0)
2609 /* We have no line number information. That means to stop
2610 stepping (does this always happen right after one instruction,
2611 when we do "s" in a function with no line numbers,
2612 or can this happen as a result of a return or longjmp?). */
2614 print_stop_reason (END_STEPPING_RANGE, 0);
2615 stop_stepping (ecs);
2619 if ((stop_pc == ecs->sal.pc)
2620 && (ecs->current_line != ecs->sal.line
2621 || ecs->current_symtab != ecs->sal.symtab))
2623 /* We are at the start of a different line. So stop. Note that
2624 we don't stop if we step into the middle of a different line.
2625 That is said to make things like for (;;) statements work
2628 print_stop_reason (END_STEPPING_RANGE, 0);
2629 stop_stepping (ecs);
2633 /* We aren't done stepping.
2635 Optimize by setting the stepping range to the line.
2636 (We might not be in the original line, but if we entered a
2637 new line in mid-statement, we continue stepping. This makes
2638 things like for(;;) statements work better.) */
2640 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
2642 /* If this is the last line of the function, don't keep stepping
2643 (it would probably step us out of the function).
2644 This is particularly necessary for a one-line function,
2645 in which after skipping the prologue we better stop even though
2646 we will be in mid-line. */
2648 print_stop_reason (END_STEPPING_RANGE, 0);
2649 stop_stepping (ecs);
2652 step_range_start = ecs->sal.pc;
2653 step_range_end = ecs->sal.end;
2654 step_frame_id = get_frame_id (get_current_frame ());
2655 ecs->current_line = ecs->sal.line;
2656 ecs->current_symtab = ecs->sal.symtab;
2658 /* In the case where we just stepped out of a function into the
2659 middle of a line of the caller, continue stepping, but
2660 step_frame_id must be modified to current frame */
2662 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too
2663 generous. It will trigger on things like a step into a frameless
2664 stackless leaf function. I think the logic should instead look
2665 at the unwound frame ID has that should give a more robust
2666 indication of what happened. */
2667 if (step-ID == current-ID)
2668 still stepping in same function;
2669 else if (step-ID == unwind (current-ID))
2670 stepped into a function;
2672 stepped out of a function;
2673 /* Of course this assumes that the frame ID unwind code is robust
2674 and we're willing to introduce frame unwind logic into this
2675 function. Fortunately, those days are nearly upon us. */
2678 struct frame_id current_frame = get_frame_id (get_current_frame ());
2679 if (!(frame_id_inner (current_frame, step_frame_id)))
2680 step_frame_id = current_frame;
2686 /* Are we in the middle of stepping? */
2689 currently_stepping (struct execution_control_state *ecs)
2691 return ((through_sigtramp_breakpoint == NULL
2692 && !ecs->handling_longjmp
2693 && ((step_range_end && step_resume_breakpoint == NULL)
2695 || ecs->stepping_through_solib_after_catch
2696 || bpstat_should_step ());
2700 check_sigtramp2 (struct execution_control_state *ecs)
2703 struct symtab_and_line sr_sal;
2705 /* Check that what has happened here is that we have just stepped
2706 the inferior with a signal (because it is a signal which
2707 shouldn't make us stop), thus stepping into sigtramp. */
2711 if (get_frame_type (get_current_frame ()) != SIGTRAMP_FRAME)
2714 /* So we need to set a step_resume_break_address breakpoint and
2715 continue until we hit it, and then step. FIXME: This should be
2716 more enduring than a step_resume breakpoint; we should know that
2717 we will later need to keep going rather than re-hitting the
2718 breakpoint here (see the testsuite, gdb.base/signals.exp where it
2719 says "exceedingly difficult"). */
2721 init_sal (&sr_sal); /* initialize to zeroes */
2722 sr_sal.pc = prev_pc;
2723 sr_sal.section = find_pc_overlay (sr_sal.pc);
2724 /* We perhaps could set the frame if we kept track of what the frame
2725 corresponding to prev_pc was. But we don't, so don't. */
2726 through_sigtramp_breakpoint =
2727 set_momentary_breakpoint (sr_sal, null_frame_id, bp_through_sigtramp);
2728 if (breakpoints_inserted)
2729 insert_breakpoints ();
2731 ecs->remove_breakpoints_on_following_step = 1;
2732 ecs->another_trap = 1;
2735 /* Subroutine call with source code we should not step over. Do step
2736 to the first line of code in it. */
2739 step_into_function (struct execution_control_state *ecs)
2742 struct symtab_and_line sr_sal;
2744 s = find_pc_symtab (stop_pc);
2745 if (s && s->language != language_asm)
2746 ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start);
2748 ecs->sal = find_pc_line (ecs->stop_func_start, 0);
2749 /* Use the step_resume_break to step until the end of the prologue,
2750 even if that involves jumps (as it seems to on the vax under
2752 /* If the prologue ends in the middle of a source line, continue to
2753 the end of that source line (if it is still within the function).
2754 Otherwise, just go to end of prologue. */
2756 && ecs->sal.pc != ecs->stop_func_start
2757 && ecs->sal.end < ecs->stop_func_end)
2758 ecs->stop_func_start = ecs->sal.end;
2760 /* Architectures which require breakpoint adjustment might not be able
2761 to place a breakpoint at the computed address. If so, the test
2762 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
2763 ecs->stop_func_start to an address at which a breakpoint may be
2764 legitimately placed.
2766 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
2767 made, GDB will enter an infinite loop when stepping through
2768 optimized code consisting of VLIW instructions which contain
2769 subinstructions corresponding to different source lines. On
2770 FR-V, it's not permitted to place a breakpoint on any but the
2771 first subinstruction of a VLIW instruction. When a breakpoint is
2772 set, GDB will adjust the breakpoint address to the beginning of
2773 the VLIW instruction. Thus, we need to make the corresponding
2774 adjustment here when computing the stop address. */
2776 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch))
2778 ecs->stop_func_start
2779 = gdbarch_adjust_breakpoint_address (current_gdbarch,
2780 ecs->stop_func_start);
2783 if (ecs->stop_func_start == stop_pc)
2785 /* We are already there: stop now. */
2787 print_stop_reason (END_STEPPING_RANGE, 0);
2788 stop_stepping (ecs);
2793 /* Put the step-breakpoint there and go until there. */
2794 init_sal (&sr_sal); /* initialize to zeroes */
2795 sr_sal.pc = ecs->stop_func_start;
2796 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
2797 /* Do not specify what the fp should be when we stop since on
2798 some machines the prologue is where the new fp value is
2800 check_for_old_step_resume_breakpoint ();
2801 step_resume_breakpoint =
2802 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2803 if (breakpoints_inserted)
2804 insert_breakpoints ();
2806 /* And make sure stepping stops right away then. */
2807 step_range_end = step_range_start;
2812 /* We've just entered a callee, and we wish to resume until it returns
2813 to the caller. Setting a step_resume breakpoint on the return
2814 address will catch a return from the callee.
2816 However, if the callee is recursing, we want to be careful not to
2817 catch returns of those recursive calls, but only of THIS instance
2820 To do this, we set the step_resume bp's frame to our current
2821 caller's frame (obtained by doing a frame ID unwind). */
2824 step_over_function (struct execution_control_state *ecs)
2826 struct symtab_and_line sr_sal;
2827 struct frame_id sr_id;
2829 init_sal (&sr_sal); /* initialize to zeros */
2831 /* NOTE: cagney/2003-04-06:
2833 At this point the equality get_frame_pc() == get_frame_func()
2834 should hold. This may make it possible for this code to tell the
2835 frame where it's function is, instead of the reverse. This would
2836 avoid the need to search for the frame's function, which can get
2837 very messy when there is no debug info available (look at the
2838 heuristic find pc start code found in targets like the MIPS). */
2840 /* NOTE: cagney/2003-04-06:
2842 The intent of DEPRECATED_SAVED_PC_AFTER_CALL was to:
2844 - provide a very light weight equivalent to frame_unwind_pc()
2845 (nee FRAME_SAVED_PC) that avoids the prologue analyzer
2847 - avoid handling the case where the PC hasn't been saved in the
2850 Unfortunately, not five lines further down, is a call to
2851 get_frame_id() and that is guarenteed to trigger the prologue
2854 The `correct fix' is for the prologe analyzer to handle the case
2855 where the prologue is incomplete (PC in prologue) and,
2856 consequently, the return pc has not yet been saved. It should be
2857 noted that the prologue analyzer needs to handle this case
2858 anyway: frameless leaf functions that don't save the return PC;
2859 single stepping through a prologue.
2861 The d10v handles all this by bailing out of the prologue analsis
2862 when it reaches the current instruction. */
2864 if (DEPRECATED_SAVED_PC_AFTER_CALL_P ())
2865 sr_sal.pc = ADDR_BITS_REMOVE (DEPRECATED_SAVED_PC_AFTER_CALL (get_current_frame ()));
2867 sr_sal.pc = ADDR_BITS_REMOVE (frame_pc_unwind (get_current_frame ()));
2868 sr_sal.section = find_pc_overlay (sr_sal.pc);
2870 check_for_old_step_resume_breakpoint ();
2872 /* NOTE: cagney/2004-03-31: Code using the current value of
2873 "step_frame_id", instead of unwinding that frame ID, removed. On
2874 s390 GNU/Linux, after taking a signal, the program is directly
2875 resumed at the signal handler and, consequently, the PC would
2876 point at at the first instruction of that signal handler but
2877 STEP_FRAME_ID would [incorrectly] at the interrupted code when it
2878 should point at the signal trampoline. By always and locally
2879 doing a frame ID unwind, it's possible to assert that the code is
2880 always using the correct ID. */
2881 sr_id = frame_unwind_id (get_current_frame ());
2883 step_resume_breakpoint = set_momentary_breakpoint (sr_sal, sr_id, bp_step_resume);
2885 if (breakpoints_inserted)
2886 insert_breakpoints ();
2890 stop_stepping (struct execution_control_state *ecs)
2892 /* Let callers know we don't want to wait for the inferior anymore. */
2893 ecs->wait_some_more = 0;
2896 /* This function handles various cases where we need to continue
2897 waiting for the inferior. */
2898 /* (Used to be the keep_going: label in the old wait_for_inferior) */
2901 keep_going (struct execution_control_state *ecs)
2903 /* Save the pc before execution, to compare with pc after stop. */
2904 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
2906 if (ecs->update_step_sp)
2907 step_sp = read_sp ();
2908 ecs->update_step_sp = 0;
2910 /* If we did not do break;, it means we should keep running the
2911 inferior and not return to debugger. */
2913 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
2915 /* We took a signal (which we are supposed to pass through to
2916 the inferior, else we'd have done a break above) and we
2917 haven't yet gotten our trap. Simply continue. */
2918 resume (currently_stepping (ecs), stop_signal);
2922 /* Either the trap was not expected, but we are continuing
2923 anyway (the user asked that this signal be passed to the
2926 The signal was SIGTRAP, e.g. it was our signal, but we
2927 decided we should resume from it.
2929 We're going to run this baby now!
2931 Insert breakpoints now, unless we are trying to one-proceed
2932 past a breakpoint. */
2933 /* If we've just finished a special step resume and we don't
2934 want to hit a breakpoint, pull em out. */
2935 if (step_resume_breakpoint == NULL
2936 && through_sigtramp_breakpoint == NULL
2937 && ecs->remove_breakpoints_on_following_step)
2939 ecs->remove_breakpoints_on_following_step = 0;
2940 remove_breakpoints ();
2941 breakpoints_inserted = 0;
2943 else if (!breakpoints_inserted &&
2944 (through_sigtramp_breakpoint != NULL || !ecs->another_trap))
2946 breakpoints_failed = insert_breakpoints ();
2947 if (breakpoints_failed)
2949 stop_stepping (ecs);
2952 breakpoints_inserted = 1;
2955 trap_expected = ecs->another_trap;
2957 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
2958 specifies that such a signal should be delivered to the
2961 Typically, this would occure when a user is debugging a
2962 target monitor on a simulator: the target monitor sets a
2963 breakpoint; the simulator encounters this break-point and
2964 halts the simulation handing control to GDB; GDB, noteing
2965 that the break-point isn't valid, returns control back to the
2966 simulator; the simulator then delivers the hardware
2967 equivalent of a SIGNAL_TRAP to the program being debugged. */
2969 if (stop_signal == TARGET_SIGNAL_TRAP && !signal_program[stop_signal])
2970 stop_signal = TARGET_SIGNAL_0;
2973 resume (currently_stepping (ecs), stop_signal);
2976 prepare_to_wait (ecs);
2979 /* This function normally comes after a resume, before
2980 handle_inferior_event exits. It takes care of any last bits of
2981 housekeeping, and sets the all-important wait_some_more flag. */
2984 prepare_to_wait (struct execution_control_state *ecs)
2986 if (ecs->infwait_state == infwait_normal_state)
2988 overlay_cache_invalid = 1;
2990 /* We have to invalidate the registers BEFORE calling
2991 target_wait because they can be loaded from the target while
2992 in target_wait. This makes remote debugging a bit more
2993 efficient for those targets that provide critical registers
2994 as part of their normal status mechanism. */
2996 registers_changed ();
2997 ecs->waiton_ptid = pid_to_ptid (-1);
2998 ecs->wp = &(ecs->ws);
3000 /* This is the old end of the while loop. Let everybody know we
3001 want to wait for the inferior some more and get called again
3003 ecs->wait_some_more = 1;
3006 /* Print why the inferior has stopped. We always print something when
3007 the inferior exits, or receives a signal. The rest of the cases are
3008 dealt with later on in normal_stop() and print_it_typical(). Ideally
3009 there should be a call to this function from handle_inferior_event()
3010 each time stop_stepping() is called.*/
3012 print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
3014 switch (stop_reason)
3017 /* We don't deal with these cases from handle_inferior_event()
3020 case END_STEPPING_RANGE:
3021 /* We are done with a step/next/si/ni command. */
3022 /* For now print nothing. */
3023 /* Print a message only if not in the middle of doing a "step n"
3024 operation for n > 1 */
3025 if (!step_multi || !stop_step)
3026 if (ui_out_is_mi_like_p (uiout))
3027 ui_out_field_string (uiout, "reason", "end-stepping-range");
3029 case BREAKPOINT_HIT:
3030 /* We found a breakpoint. */
3031 /* For now print nothing. */
3034 /* The inferior was terminated by a signal. */
3035 annotate_signalled ();
3036 if (ui_out_is_mi_like_p (uiout))
3037 ui_out_field_string (uiout, "reason", "exited-signalled");
3038 ui_out_text (uiout, "\nProgram terminated with signal ");
3039 annotate_signal_name ();
3040 ui_out_field_string (uiout, "signal-name",
3041 target_signal_to_name (stop_info));
3042 annotate_signal_name_end ();
3043 ui_out_text (uiout, ", ");
3044 annotate_signal_string ();
3045 ui_out_field_string (uiout, "signal-meaning",
3046 target_signal_to_string (stop_info));
3047 annotate_signal_string_end ();
3048 ui_out_text (uiout, ".\n");
3049 ui_out_text (uiout, "The program no longer exists.\n");
3052 /* The inferior program is finished. */
3053 annotate_exited (stop_info);
3056 if (ui_out_is_mi_like_p (uiout))
3057 ui_out_field_string (uiout, "reason", "exited");
3058 ui_out_text (uiout, "\nProgram exited with code ");
3059 ui_out_field_fmt (uiout, "exit-code", "0%o",
3060 (unsigned int) stop_info);
3061 ui_out_text (uiout, ".\n");
3065 if (ui_out_is_mi_like_p (uiout))
3066 ui_out_field_string (uiout, "reason", "exited-normally");
3067 ui_out_text (uiout, "\nProgram exited normally.\n");
3070 case SIGNAL_RECEIVED:
3071 /* Signal received. The signal table tells us to print about
3074 ui_out_text (uiout, "\nProgram received signal ");
3075 annotate_signal_name ();
3076 if (ui_out_is_mi_like_p (uiout))
3077 ui_out_field_string (uiout, "reason", "signal-received");
3078 ui_out_field_string (uiout, "signal-name",
3079 target_signal_to_name (stop_info));
3080 annotate_signal_name_end ();
3081 ui_out_text (uiout, ", ");
3082 annotate_signal_string ();
3083 ui_out_field_string (uiout, "signal-meaning",
3084 target_signal_to_string (stop_info));
3085 annotate_signal_string_end ();
3086 ui_out_text (uiout, ".\n");
3089 internal_error (__FILE__, __LINE__,
3090 "print_stop_reason: unrecognized enum value");
3096 /* Here to return control to GDB when the inferior stops for real.
3097 Print appropriate messages, remove breakpoints, give terminal our modes.
3099 STOP_PRINT_FRAME nonzero means print the executing frame
3100 (pc, function, args, file, line number and line text).
3101 BREAKPOINTS_FAILED nonzero means stop was due to error
3102 attempting to insert breakpoints. */
3107 struct target_waitstatus last;
3110 get_last_target_status (&last_ptid, &last);
3112 /* As with the notification of thread events, we want to delay
3113 notifying the user that we've switched thread context until
3114 the inferior actually stops.
3116 There's no point in saying anything if the inferior has exited.
3117 Note that SIGNALLED here means "exited with a signal", not
3118 "received a signal". */
3119 if (!ptid_equal (previous_inferior_ptid, inferior_ptid)
3120 && target_has_execution
3121 && last.kind != TARGET_WAITKIND_SIGNALLED
3122 && last.kind != TARGET_WAITKIND_EXITED)
3124 target_terminal_ours_for_output ();
3125 printf_filtered ("[Switching to %s]\n",
3126 target_pid_or_tid_to_str (inferior_ptid));
3127 previous_inferior_ptid = inferior_ptid;
3130 /* NOTE drow/2004-01-17: Is this still necessary? */
3131 /* Make sure that the current_frame's pc is correct. This
3132 is a correction for setting up the frame info before doing
3133 DECR_PC_AFTER_BREAK */
3134 if (target_has_execution)
3135 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3136 DECR_PC_AFTER_BREAK, the program counter can change. Ask the
3137 frame code to check for this and sort out any resultant mess.
3138 DECR_PC_AFTER_BREAK needs to just go away. */
3139 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3141 if (target_has_execution && breakpoints_inserted)
3143 if (remove_breakpoints ())
3145 target_terminal_ours_for_output ();
3146 printf_filtered ("Cannot remove breakpoints because ");
3147 printf_filtered ("program is no longer writable.\n");
3148 printf_filtered ("It might be running in another process.\n");
3149 printf_filtered ("Further execution is probably impossible.\n");
3152 breakpoints_inserted = 0;
3154 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3155 Delete any breakpoint that is to be deleted at the next stop. */
3157 breakpoint_auto_delete (stop_bpstat);
3159 /* If an auto-display called a function and that got a signal,
3160 delete that auto-display to avoid an infinite recursion. */
3162 if (stopped_by_random_signal)
3163 disable_current_display ();
3165 /* Don't print a message if in the middle of doing a "step n"
3166 operation for n > 1 */
3167 if (step_multi && stop_step)
3170 target_terminal_ours ();
3172 /* Look up the hook_stop and run it (CLI internally handles problem
3173 of stop_command's pre-hook not existing). */
3175 catch_errors (hook_stop_stub, stop_command,
3176 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3178 if (!target_has_stack)
3184 /* Select innermost stack frame - i.e., current frame is frame 0,
3185 and current location is based on that.
3186 Don't do this on return from a stack dummy routine,
3187 or if the program has exited. */
3189 if (!stop_stack_dummy)
3191 select_frame (get_current_frame ());
3193 /* Print current location without a level number, if
3194 we have changed functions or hit a breakpoint.
3195 Print source line if we have one.
3196 bpstat_print() contains the logic deciding in detail
3197 what to print, based on the event(s) that just occurred. */
3199 if (stop_print_frame && deprecated_selected_frame)
3203 int do_frame_printing = 1;
3205 bpstat_ret = bpstat_print (stop_bpstat);
3209 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3210 (or should) carry around the function and does (or
3211 should) use that when doing a frame comparison. */
3213 && frame_id_eq (step_frame_id,
3214 get_frame_id (get_current_frame ()))
3215 && step_start_function == find_pc_function (stop_pc))
3216 source_flag = SRC_LINE; /* finished step, just print source line */
3218 source_flag = SRC_AND_LOC; /* print location and source line */
3220 case PRINT_SRC_AND_LOC:
3221 source_flag = SRC_AND_LOC; /* print location and source line */
3223 case PRINT_SRC_ONLY:
3224 source_flag = SRC_LINE;
3227 source_flag = SRC_LINE; /* something bogus */
3228 do_frame_printing = 0;
3231 internal_error (__FILE__, __LINE__, "Unknown value.");
3233 /* For mi, have the same behavior every time we stop:
3234 print everything but the source line. */
3235 if (ui_out_is_mi_like_p (uiout))
3236 source_flag = LOC_AND_ADDRESS;
3238 if (ui_out_is_mi_like_p (uiout))
3239 ui_out_field_int (uiout, "thread-id",
3240 pid_to_thread_id (inferior_ptid));
3241 /* The behavior of this routine with respect to the source
3243 SRC_LINE: Print only source line
3244 LOCATION: Print only location
3245 SRC_AND_LOC: Print location and source line */
3246 if (do_frame_printing)
3247 print_stack_frame (get_selected_frame (), 0, source_flag);
3249 /* Display the auto-display expressions. */
3254 /* Save the function value return registers, if we care.
3255 We might be about to restore their previous contents. */
3256 if (proceed_to_finish)
3257 /* NB: The copy goes through to the target picking up the value of
3258 all the registers. */
3259 regcache_cpy (stop_registers, current_regcache);
3261 if (stop_stack_dummy)
3263 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3264 ends with a setting of the current frame, so we can use that
3266 frame_pop (get_current_frame ());
3267 /* Set stop_pc to what it was before we called the function.
3268 Can't rely on restore_inferior_status because that only gets
3269 called if we don't stop in the called function. */
3270 stop_pc = read_pc ();
3271 select_frame (get_current_frame ());
3275 annotate_stopped ();
3276 observer_notify_normal_stop (stop_bpstat);
3280 hook_stop_stub (void *cmd)
3282 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
3287 signal_stop_state (int signo)
3289 return signal_stop[signo];
3293 signal_print_state (int signo)
3295 return signal_print[signo];
3299 signal_pass_state (int signo)
3301 return signal_program[signo];
3305 signal_stop_update (int signo, int state)
3307 int ret = signal_stop[signo];
3308 signal_stop[signo] = state;
3313 signal_print_update (int signo, int state)
3315 int ret = signal_print[signo];
3316 signal_print[signo] = state;
3321 signal_pass_update (int signo, int state)
3323 int ret = signal_program[signo];
3324 signal_program[signo] = state;
3329 sig_print_header (void)
3332 Signal Stop\tPrint\tPass to program\tDescription\n");
3336 sig_print_info (enum target_signal oursig)
3338 char *name = target_signal_to_name (oursig);
3339 int name_padding = 13 - strlen (name);
3341 if (name_padding <= 0)
3344 printf_filtered ("%s", name);
3345 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
3346 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3347 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3348 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3349 printf_filtered ("%s\n", target_signal_to_string (oursig));
3352 /* Specify how various signals in the inferior should be handled. */
3355 handle_command (char *args, int from_tty)
3358 int digits, wordlen;
3359 int sigfirst, signum, siglast;
3360 enum target_signal oursig;
3363 unsigned char *sigs;
3364 struct cleanup *old_chain;
3368 error_no_arg ("signal to handle");
3371 /* Allocate and zero an array of flags for which signals to handle. */
3373 nsigs = (int) TARGET_SIGNAL_LAST;
3374 sigs = (unsigned char *) alloca (nsigs);
3375 memset (sigs, 0, nsigs);
3377 /* Break the command line up into args. */
3379 argv = buildargv (args);
3384 old_chain = make_cleanup_freeargv (argv);
3386 /* Walk through the args, looking for signal oursigs, signal names, and
3387 actions. Signal numbers and signal names may be interspersed with
3388 actions, with the actions being performed for all signals cumulatively
3389 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3391 while (*argv != NULL)
3393 wordlen = strlen (*argv);
3394 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3398 sigfirst = siglast = -1;
3400 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3402 /* Apply action to all signals except those used by the
3403 debugger. Silently skip those. */
3406 siglast = nsigs - 1;
3408 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3410 SET_SIGS (nsigs, sigs, signal_stop);
3411 SET_SIGS (nsigs, sigs, signal_print);
3413 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3415 UNSET_SIGS (nsigs, sigs, signal_program);
3417 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3419 SET_SIGS (nsigs, sigs, signal_print);
3421 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3423 SET_SIGS (nsigs, sigs, signal_program);
3425 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3427 UNSET_SIGS (nsigs, sigs, signal_stop);
3429 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3431 SET_SIGS (nsigs, sigs, signal_program);
3433 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3435 UNSET_SIGS (nsigs, sigs, signal_print);
3436 UNSET_SIGS (nsigs, sigs, signal_stop);
3438 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3440 UNSET_SIGS (nsigs, sigs, signal_program);
3442 else if (digits > 0)
3444 /* It is numeric. The numeric signal refers to our own
3445 internal signal numbering from target.h, not to host/target
3446 signal number. This is a feature; users really should be
3447 using symbolic names anyway, and the common ones like
3448 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3450 sigfirst = siglast = (int)
3451 target_signal_from_command (atoi (*argv));
3452 if ((*argv)[digits] == '-')
3455 target_signal_from_command (atoi ((*argv) + digits + 1));
3457 if (sigfirst > siglast)
3459 /* Bet he didn't figure we'd think of this case... */
3467 oursig = target_signal_from_name (*argv);
3468 if (oursig != TARGET_SIGNAL_UNKNOWN)
3470 sigfirst = siglast = (int) oursig;
3474 /* Not a number and not a recognized flag word => complain. */
3475 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3479 /* If any signal numbers or symbol names were found, set flags for
3480 which signals to apply actions to. */
3482 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3484 switch ((enum target_signal) signum)
3486 case TARGET_SIGNAL_TRAP:
3487 case TARGET_SIGNAL_INT:
3488 if (!allsigs && !sigs[signum])
3490 if (query ("%s is used by the debugger.\n\
3491 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum)))
3497 printf_unfiltered ("Not confirmed, unchanged.\n");
3498 gdb_flush (gdb_stdout);
3502 case TARGET_SIGNAL_0:
3503 case TARGET_SIGNAL_DEFAULT:
3504 case TARGET_SIGNAL_UNKNOWN:
3505 /* Make sure that "all" doesn't print these. */
3516 target_notice_signals (inferior_ptid);
3520 /* Show the results. */
3521 sig_print_header ();
3522 for (signum = 0; signum < nsigs; signum++)
3526 sig_print_info (signum);
3531 do_cleanups (old_chain);
3535 xdb_handle_command (char *args, int from_tty)
3538 struct cleanup *old_chain;
3540 /* Break the command line up into args. */
3542 argv = buildargv (args);
3547 old_chain = make_cleanup_freeargv (argv);
3548 if (argv[1] != (char *) NULL)
3553 bufLen = strlen (argv[0]) + 20;
3554 argBuf = (char *) xmalloc (bufLen);
3558 enum target_signal oursig;
3560 oursig = target_signal_from_name (argv[0]);
3561 memset (argBuf, 0, bufLen);
3562 if (strcmp (argv[1], "Q") == 0)
3563 sprintf (argBuf, "%s %s", argv[0], "noprint");
3566 if (strcmp (argv[1], "s") == 0)
3568 if (!signal_stop[oursig])
3569 sprintf (argBuf, "%s %s", argv[0], "stop");
3571 sprintf (argBuf, "%s %s", argv[0], "nostop");
3573 else if (strcmp (argv[1], "i") == 0)
3575 if (!signal_program[oursig])
3576 sprintf (argBuf, "%s %s", argv[0], "pass");
3578 sprintf (argBuf, "%s %s", argv[0], "nopass");
3580 else if (strcmp (argv[1], "r") == 0)
3582 if (!signal_print[oursig])
3583 sprintf (argBuf, "%s %s", argv[0], "print");
3585 sprintf (argBuf, "%s %s", argv[0], "noprint");
3591 handle_command (argBuf, from_tty);
3593 printf_filtered ("Invalid signal handling flag.\n");
3598 do_cleanups (old_chain);
3601 /* Print current contents of the tables set by the handle command.
3602 It is possible we should just be printing signals actually used
3603 by the current target (but for things to work right when switching
3604 targets, all signals should be in the signal tables). */
3607 signals_info (char *signum_exp, int from_tty)
3609 enum target_signal oursig;
3610 sig_print_header ();
3614 /* First see if this is a symbol name. */
3615 oursig = target_signal_from_name (signum_exp);
3616 if (oursig == TARGET_SIGNAL_UNKNOWN)
3618 /* No, try numeric. */
3620 target_signal_from_command (parse_and_eval_long (signum_exp));
3622 sig_print_info (oursig);
3626 printf_filtered ("\n");
3627 /* These ugly casts brought to you by the native VAX compiler. */
3628 for (oursig = TARGET_SIGNAL_FIRST;
3629 (int) oursig < (int) TARGET_SIGNAL_LAST;
3630 oursig = (enum target_signal) ((int) oursig + 1))
3634 if (oursig != TARGET_SIGNAL_UNKNOWN
3635 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
3636 sig_print_info (oursig);
3639 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3642 struct inferior_status
3644 enum target_signal stop_signal;
3648 int stop_stack_dummy;
3649 int stopped_by_random_signal;
3651 CORE_ADDR step_range_start;
3652 CORE_ADDR step_range_end;
3653 struct frame_id step_frame_id;
3654 enum step_over_calls_kind step_over_calls;
3655 CORE_ADDR step_resume_break_address;
3656 int stop_after_trap;
3658 struct regcache *stop_registers;
3660 /* These are here because if call_function_by_hand has written some
3661 registers and then decides to call error(), we better not have changed
3663 struct regcache *registers;
3665 /* A frame unique identifier. */
3666 struct frame_id selected_frame_id;
3668 int breakpoint_proceeded;
3669 int restore_stack_info;
3670 int proceed_to_finish;
3674 write_inferior_status_register (struct inferior_status *inf_status, int regno,
3677 int size = DEPRECATED_REGISTER_RAW_SIZE (regno);
3678 void *buf = alloca (size);
3679 store_signed_integer (buf, size, val);
3680 regcache_raw_write (inf_status->registers, regno, buf);
3683 /* Save all of the information associated with the inferior<==>gdb
3684 connection. INF_STATUS is a pointer to a "struct inferior_status"
3685 (defined in inferior.h). */
3687 struct inferior_status *
3688 save_inferior_status (int restore_stack_info)
3690 struct inferior_status *inf_status = XMALLOC (struct inferior_status);
3692 inf_status->stop_signal = stop_signal;
3693 inf_status->stop_pc = stop_pc;
3694 inf_status->stop_step = stop_step;
3695 inf_status->stop_stack_dummy = stop_stack_dummy;
3696 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3697 inf_status->trap_expected = trap_expected;
3698 inf_status->step_range_start = step_range_start;
3699 inf_status->step_range_end = step_range_end;
3700 inf_status->step_frame_id = step_frame_id;
3701 inf_status->step_over_calls = step_over_calls;
3702 inf_status->stop_after_trap = stop_after_trap;
3703 inf_status->stop_soon = stop_soon;
3704 /* Save original bpstat chain here; replace it with copy of chain.
3705 If caller's caller is walking the chain, they'll be happier if we
3706 hand them back the original chain when restore_inferior_status is
3708 inf_status->stop_bpstat = stop_bpstat;
3709 stop_bpstat = bpstat_copy (stop_bpstat);
3710 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3711 inf_status->restore_stack_info = restore_stack_info;
3712 inf_status->proceed_to_finish = proceed_to_finish;
3714 inf_status->stop_registers = regcache_dup_no_passthrough (stop_registers);
3716 inf_status->registers = regcache_dup (current_regcache);
3718 inf_status->selected_frame_id = get_frame_id (deprecated_selected_frame);
3723 restore_selected_frame (void *args)
3725 struct frame_id *fid = (struct frame_id *) args;
3726 struct frame_info *frame;
3728 frame = frame_find_by_id (*fid);
3730 /* If inf_status->selected_frame_id is NULL, there was no previously
3734 warning ("Unable to restore previously selected frame.\n");
3738 select_frame (frame);
3744 restore_inferior_status (struct inferior_status *inf_status)
3746 stop_signal = inf_status->stop_signal;
3747 stop_pc = inf_status->stop_pc;
3748 stop_step = inf_status->stop_step;
3749 stop_stack_dummy = inf_status->stop_stack_dummy;
3750 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3751 trap_expected = inf_status->trap_expected;
3752 step_range_start = inf_status->step_range_start;
3753 step_range_end = inf_status->step_range_end;
3754 step_frame_id = inf_status->step_frame_id;
3755 step_over_calls = inf_status->step_over_calls;
3756 stop_after_trap = inf_status->stop_after_trap;
3757 stop_soon = inf_status->stop_soon;
3758 bpstat_clear (&stop_bpstat);
3759 stop_bpstat = inf_status->stop_bpstat;
3760 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3761 proceed_to_finish = inf_status->proceed_to_finish;
3763 /* FIXME: Is the restore of stop_registers always needed. */
3764 regcache_xfree (stop_registers);
3765 stop_registers = inf_status->stop_registers;
3767 /* The inferior can be gone if the user types "print exit(0)"
3768 (and perhaps other times). */
3769 if (target_has_execution)
3770 /* NB: The register write goes through to the target. */
3771 regcache_cpy (current_regcache, inf_status->registers);
3772 regcache_xfree (inf_status->registers);
3774 /* FIXME: If we are being called after stopping in a function which
3775 is called from gdb, we should not be trying to restore the
3776 selected frame; it just prints a spurious error message (The
3777 message is useful, however, in detecting bugs in gdb (like if gdb
3778 clobbers the stack)). In fact, should we be restoring the
3779 inferior status at all in that case? . */
3781 if (target_has_stack && inf_status->restore_stack_info)
3783 /* The point of catch_errors is that if the stack is clobbered,
3784 walking the stack might encounter a garbage pointer and
3785 error() trying to dereference it. */
3787 (restore_selected_frame, &inf_status->selected_frame_id,
3788 "Unable to restore previously selected frame:\n",
3789 RETURN_MASK_ERROR) == 0)
3790 /* Error in restoring the selected frame. Select the innermost
3792 select_frame (get_current_frame ());
3800 do_restore_inferior_status_cleanup (void *sts)
3802 restore_inferior_status (sts);
3806 make_cleanup_restore_inferior_status (struct inferior_status *inf_status)
3808 return make_cleanup (do_restore_inferior_status_cleanup, inf_status);
3812 discard_inferior_status (struct inferior_status *inf_status)
3814 /* See save_inferior_status for info on stop_bpstat. */
3815 bpstat_clear (&inf_status->stop_bpstat);
3816 regcache_xfree (inf_status->registers);
3817 regcache_xfree (inf_status->stop_registers);
3822 inferior_has_forked (int pid, int *child_pid)
3824 struct target_waitstatus last;
3827 get_last_target_status (&last_ptid, &last);
3829 if (last.kind != TARGET_WAITKIND_FORKED)
3832 if (ptid_get_pid (last_ptid) != pid)
3835 *child_pid = last.value.related_pid;
3840 inferior_has_vforked (int pid, int *child_pid)
3842 struct target_waitstatus last;
3845 get_last_target_status (&last_ptid, &last);
3847 if (last.kind != TARGET_WAITKIND_VFORKED)
3850 if (ptid_get_pid (last_ptid) != pid)
3853 *child_pid = last.value.related_pid;
3858 inferior_has_execd (int pid, char **execd_pathname)
3860 struct target_waitstatus last;
3863 get_last_target_status (&last_ptid, &last);
3865 if (last.kind != TARGET_WAITKIND_EXECD)
3868 if (ptid_get_pid (last_ptid) != pid)
3871 *execd_pathname = xstrdup (last.value.execd_pathname);
3875 /* Oft used ptids */
3877 ptid_t minus_one_ptid;
3879 /* Create a ptid given the necessary PID, LWP, and TID components. */
3882 ptid_build (int pid, long lwp, long tid)
3892 /* Create a ptid from just a pid. */
3895 pid_to_ptid (int pid)
3897 return ptid_build (pid, 0, 0);
3900 /* Fetch the pid (process id) component from a ptid. */
3903 ptid_get_pid (ptid_t ptid)
3908 /* Fetch the lwp (lightweight process) component from a ptid. */
3911 ptid_get_lwp (ptid_t ptid)
3916 /* Fetch the tid (thread id) component from a ptid. */
3919 ptid_get_tid (ptid_t ptid)
3924 /* ptid_equal() is used to test equality of two ptids. */
3927 ptid_equal (ptid_t ptid1, ptid_t ptid2)
3929 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
3930 && ptid1.tid == ptid2.tid);
3933 /* restore_inferior_ptid() will be used by the cleanup machinery
3934 to restore the inferior_ptid value saved in a call to
3935 save_inferior_ptid(). */
3938 restore_inferior_ptid (void *arg)
3940 ptid_t *saved_ptid_ptr = arg;
3941 inferior_ptid = *saved_ptid_ptr;
3945 /* Save the value of inferior_ptid so that it may be restored by a
3946 later call to do_cleanups(). Returns the struct cleanup pointer
3947 needed for later doing the cleanup. */
3950 save_inferior_ptid (void)
3952 ptid_t *saved_ptid_ptr;
3954 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
3955 *saved_ptid_ptr = inferior_ptid;
3956 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
3963 stop_registers = regcache_xmalloc (current_gdbarch);
3967 _initialize_infrun (void)
3971 struct cmd_list_element *c;
3973 DEPRECATED_REGISTER_GDBARCH_SWAP (stop_registers);
3974 deprecated_register_gdbarch_swap (NULL, 0, build_infrun);
3976 add_info ("signals", signals_info,
3977 "What debugger does when program gets various signals.\n\
3978 Specify a signal as argument to print info on that signal only.");
3979 add_info_alias ("handle", "signals", 0);
3981 add_com ("handle", class_run, handle_command,
3982 concat ("Specify how to handle a signal.\n\
3983 Args are signals and actions to apply to those signals.\n\
3984 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3985 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3986 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3987 The special arg \"all\" is recognized to mean all signals except those\n\
3988 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3989 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3990 Stop means reenter debugger if this signal happens (implies print).\n\
3991 Print means print a message if this signal happens.\n\
3992 Pass means let program see this signal; otherwise program doesn't know.\n\
3993 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3994 Pass and Stop may be combined.", NULL));
3997 add_com ("lz", class_info, signals_info,
3998 "What debugger does when program gets various signals.\n\
3999 Specify a signal as argument to print info on that signal only.");
4000 add_com ("z", class_run, xdb_handle_command,
4001 concat ("Specify how to handle a signal.\n\
4002 Args are signals and actions to apply to those signals.\n\
4003 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4004 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4005 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4006 The special arg \"all\" is recognized to mean all signals except those\n\
4007 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4008 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4009 nopass), \"Q\" (noprint)\n\
4010 Stop means reenter debugger if this signal happens (implies print).\n\
4011 Print means print a message if this signal happens.\n\
4012 Pass means let program see this signal; otherwise program doesn't know.\n\
4013 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4014 Pass and Stop may be combined.", NULL));
4019 add_cmd ("stop", class_obscure, not_just_help_class_command, "There is no `stop' command, but you can set a hook on `stop'.\n\
4020 This allows you to set a list of commands to be run each time execution\n\
4021 of the program stops.", &cmdlist);
4023 numsigs = (int) TARGET_SIGNAL_LAST;
4024 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
4025 signal_print = (unsigned char *)
4026 xmalloc (sizeof (signal_print[0]) * numsigs);
4027 signal_program = (unsigned char *)
4028 xmalloc (sizeof (signal_program[0]) * numsigs);
4029 for (i = 0; i < numsigs; i++)
4032 signal_print[i] = 1;
4033 signal_program[i] = 1;
4036 /* Signals caused by debugger's own actions
4037 should not be given to the program afterwards. */
4038 signal_program[TARGET_SIGNAL_TRAP] = 0;
4039 signal_program[TARGET_SIGNAL_INT] = 0;
4041 /* Signals that are not errors should not normally enter the debugger. */
4042 signal_stop[TARGET_SIGNAL_ALRM] = 0;
4043 signal_print[TARGET_SIGNAL_ALRM] = 0;
4044 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
4045 signal_print[TARGET_SIGNAL_VTALRM] = 0;
4046 signal_stop[TARGET_SIGNAL_PROF] = 0;
4047 signal_print[TARGET_SIGNAL_PROF] = 0;
4048 signal_stop[TARGET_SIGNAL_CHLD] = 0;
4049 signal_print[TARGET_SIGNAL_CHLD] = 0;
4050 signal_stop[TARGET_SIGNAL_IO] = 0;
4051 signal_print[TARGET_SIGNAL_IO] = 0;
4052 signal_stop[TARGET_SIGNAL_POLL] = 0;
4053 signal_print[TARGET_SIGNAL_POLL] = 0;
4054 signal_stop[TARGET_SIGNAL_URG] = 0;
4055 signal_print[TARGET_SIGNAL_URG] = 0;
4056 signal_stop[TARGET_SIGNAL_WINCH] = 0;
4057 signal_print[TARGET_SIGNAL_WINCH] = 0;
4059 /* These signals are used internally by user-level thread
4060 implementations. (See signal(5) on Solaris.) Like the above
4061 signals, a healthy program receives and handles them as part of
4062 its normal operation. */
4063 signal_stop[TARGET_SIGNAL_LWP] = 0;
4064 signal_print[TARGET_SIGNAL_LWP] = 0;
4065 signal_stop[TARGET_SIGNAL_WAITING] = 0;
4066 signal_print[TARGET_SIGNAL_WAITING] = 0;
4067 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
4068 signal_print[TARGET_SIGNAL_CANCEL] = 0;
4072 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
4073 (char *) &stop_on_solib_events,
4074 "Set stopping for shared library events.\n\
4075 If nonzero, gdb will give control to the user when the dynamic linker\n\
4076 notifies gdb of shared library events. The most common event of interest\n\
4077 to the user would be loading/unloading of a new library.\n", &setlist), &showlist);
4080 c = add_set_enum_cmd ("follow-fork-mode",
4082 follow_fork_mode_kind_names, &follow_fork_mode_string,
4083 "Set debugger response to a program call of fork \
4085 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4086 parent - the original process is debugged after a fork\n\
4087 child - the new process is debugged after a fork\n\
4088 The unfollowed process will continue to run.\n\
4089 By default, the debugger will follow the parent process.", &setlist);
4090 add_show_from_set (c, &showlist);
4092 c = add_set_enum_cmd ("scheduler-locking", class_run, scheduler_enums, /* array of string names */
4093 &scheduler_mode, /* current mode */
4094 "Set mode for locking scheduler during execution.\n\
4095 off == no locking (threads may preempt at any time)\n\
4096 on == full locking (no thread except the current thread may run)\n\
4097 step == scheduler locked during every single-step operation.\n\
4098 In this mode, no other thread may run during a step command.\n\
4099 Other threads may run while stepping over a function call ('next').", &setlist);
4101 set_cmd_sfunc (c, set_schedlock_func); /* traps on target vector */
4102 add_show_from_set (c, &showlist);
4104 c = add_set_cmd ("step-mode", class_run,
4105 var_boolean, (char *) &step_stop_if_no_debug,
4106 "Set mode of the step operation. When set, doing a step over a\n\
4107 function without debug line information will stop at the first\n\
4108 instruction of that function. Otherwise, the function is skipped and\n\
4109 the step command stops at a different source line.", &setlist);
4110 add_show_from_set (c, &showlist);
4112 /* ptid initializations */
4113 null_ptid = ptid_build (0, 0, 0);
4114 minus_one_ptid = ptid_build (-1, 0, 0);
4115 inferior_ptid = null_ptid;
4116 target_last_wait_ptid = minus_one_ptid;