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 int restore_selected_frame (void *);
65 static void build_infrun (void);
67 static int follow_fork (void);
69 static void set_schedlock_func (char *args, int from_tty,
70 struct cmd_list_element *c);
72 struct execution_control_state;
74 static int currently_stepping (struct execution_control_state *ecs);
76 static void xdb_handle_command (char *args, int from_tty);
78 static int prepare_to_proceed (void);
80 void _initialize_infrun (void);
82 int inferior_ignoring_startup_exec_events = 0;
83 int inferior_ignoring_leading_exec_events = 0;
85 /* When set, stop the 'step' command if we enter a function which has
86 no line number information. The normal behavior is that we step
87 over such function. */
88 int step_stop_if_no_debug = 0;
90 /* In asynchronous mode, but simulating synchronous execution. */
92 int sync_execution = 0;
94 /* wait_for_inferior and normal_stop use this to notify the user
95 when the inferior stopped in a different thread than it had been
98 static ptid_t previous_inferior_ptid;
100 /* This is true for configurations that may follow through execl() and
101 similar functions. At present this is only true for HP-UX native. */
103 #ifndef MAY_FOLLOW_EXEC
104 #define MAY_FOLLOW_EXEC (0)
107 static int may_follow_exec = MAY_FOLLOW_EXEC;
109 /* If the program uses ELF-style shared libraries, then calls to
110 functions in shared libraries go through stubs, which live in a
111 table called the PLT (Procedure Linkage Table). The first time the
112 function is called, the stub sends control to the dynamic linker,
113 which looks up the function's real address, patches the stub so
114 that future calls will go directly to the function, and then passes
115 control to the function.
117 If we are stepping at the source level, we don't want to see any of
118 this --- we just want to skip over the stub and the dynamic linker.
119 The simple approach is to single-step until control leaves the
122 However, on some systems (e.g., Red Hat's 5.2 distribution) the
123 dynamic linker calls functions in the shared C library, so you
124 can't tell from the PC alone whether the dynamic linker is still
125 running. In this case, we use a step-resume breakpoint to get us
126 past the dynamic linker, as if we were using "next" to step over a
129 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
130 linker code or not. Normally, this means we single-step. However,
131 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
132 address where we can place a step-resume breakpoint to get past the
133 linker's symbol resolution function.
135 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
136 pretty portable way, by comparing the PC against the address ranges
137 of the dynamic linker's sections.
139 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
140 it depends on internal details of the dynamic linker. It's usually
141 not too hard to figure out where to put a breakpoint, but it
142 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
143 sanity checking. If it can't figure things out, returning zero and
144 getting the (possibly confusing) stepping behavior is better than
145 signalling an error, which will obscure the change in the
148 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
149 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
152 /* This function returns TRUE if pc is the address of an instruction
153 that lies within the dynamic linker (such as the event hook, or the
156 This function must be used only when a dynamic linker event has
157 been caught, and the inferior is being stepped out of the hook, or
158 undefined results are guaranteed. */
160 #ifndef SOLIB_IN_DYNAMIC_LINKER
161 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
164 /* On some systems, the PC may be left pointing at an instruction that won't
165 actually be executed. This is usually indicated by a bit in the PSW. If
166 we find ourselves in such a state, then we step the target beyond the
167 nullified instruction before returning control to the user so as to avoid
170 #ifndef INSTRUCTION_NULLIFIED
171 #define INSTRUCTION_NULLIFIED 0
174 /* We can't step off a permanent breakpoint in the ordinary way, because we
175 can't remove it. Instead, we have to advance the PC to the next
176 instruction. This macro should expand to a pointer to a function that
177 does that, or zero if we have no such function. If we don't have a
178 definition for it, we have to report an error. */
179 #ifndef SKIP_PERMANENT_BREAKPOINT
180 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
182 default_skip_permanent_breakpoint (void)
185 The program is stopped at a permanent breakpoint, but GDB does not know\n\
186 how to step past a permanent breakpoint on this architecture. Try using\n\
187 a command like `return' or `jump' to continue execution.");
192 /* Convert the #defines into values. This is temporary until wfi control
193 flow is completely sorted out. */
195 #ifndef HAVE_STEPPABLE_WATCHPOINT
196 #define HAVE_STEPPABLE_WATCHPOINT 0
198 #undef HAVE_STEPPABLE_WATCHPOINT
199 #define HAVE_STEPPABLE_WATCHPOINT 1
202 #ifndef CANNOT_STEP_HW_WATCHPOINTS
203 #define CANNOT_STEP_HW_WATCHPOINTS 0
205 #undef CANNOT_STEP_HW_WATCHPOINTS
206 #define CANNOT_STEP_HW_WATCHPOINTS 1
209 /* Tables of how to react to signals; the user sets them. */
211 static unsigned char *signal_stop;
212 static unsigned char *signal_print;
213 static unsigned char *signal_program;
215 #define SET_SIGS(nsigs,sigs,flags) \
217 int signum = (nsigs); \
218 while (signum-- > 0) \
219 if ((sigs)[signum]) \
220 (flags)[signum] = 1; \
223 #define UNSET_SIGS(nsigs,sigs,flags) \
225 int signum = (nsigs); \
226 while (signum-- > 0) \
227 if ((sigs)[signum]) \
228 (flags)[signum] = 0; \
231 /* Value to pass to target_resume() to cause all threads to resume */
233 #define RESUME_ALL (pid_to_ptid (-1))
235 /* Command list pointer for the "stop" placeholder. */
237 static struct cmd_list_element *stop_command;
239 /* Nonzero if breakpoints are now inserted in the inferior. */
241 static int breakpoints_inserted;
243 /* Function inferior was in as of last step command. */
245 static struct symbol *step_start_function;
247 /* Nonzero if we are expecting a trace trap and should proceed from it. */
249 static int trap_expected;
252 /* Nonzero if we want to give control to the user when we're notified
253 of shared library events by the dynamic linker. */
254 static int stop_on_solib_events;
257 /* Nonzero means expecting a trace trap
258 and should stop the inferior and return silently when it happens. */
262 /* Nonzero means expecting a trap and caller will handle it themselves.
263 It is used after attach, due to attaching to a process;
264 when running in the shell before the child program has been exec'd;
265 and when running some kinds of remote stuff (FIXME?). */
267 enum stop_kind stop_soon;
269 /* Nonzero if proceed is being used for a "finish" command or a similar
270 situation when stop_registers should be saved. */
272 int proceed_to_finish;
274 /* Save register contents here when about to pop a stack dummy frame,
275 if-and-only-if proceed_to_finish is set.
276 Thus this contains the return value from the called function (assuming
277 values are returned in a register). */
279 struct regcache *stop_registers;
281 /* Nonzero if program stopped due to error trying to insert breakpoints. */
283 static int breakpoints_failed;
285 /* Nonzero after stop if current stack frame should be printed. */
287 static int stop_print_frame;
289 static struct breakpoint *step_resume_breakpoint = NULL;
291 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
292 interactions with an inferior that is running a kernel function
293 (aka, a system call or "syscall"). wait_for_inferior therefore
294 may have a need to know when the inferior is in a syscall. This
295 is a count of the number of inferior threads which are known to
296 currently be running in a syscall. */
297 static int number_of_threads_in_syscalls;
299 /* This is a cached copy of the pid/waitstatus of the last event
300 returned by target_wait()/deprecated_target_wait_hook(). This
301 information is returned by get_last_target_status(). */
302 static ptid_t target_last_wait_ptid;
303 static struct target_waitstatus target_last_waitstatus;
305 /* This is used to remember when a fork, vfork or exec event
306 was caught by a catchpoint, and thus the event is to be
307 followed at the next resume of the inferior, and not
311 enum target_waitkind kind;
318 char *execd_pathname;
322 static const char follow_fork_mode_child[] = "child";
323 static const char follow_fork_mode_parent[] = "parent";
325 static const char *follow_fork_mode_kind_names[] = {
326 follow_fork_mode_child,
327 follow_fork_mode_parent,
331 static const char *follow_fork_mode_string = follow_fork_mode_parent;
337 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
339 return target_follow_fork (follow_child);
343 follow_inferior_reset_breakpoints (void)
345 /* Was there a step_resume breakpoint? (There was if the user
346 did a "next" at the fork() call.) If so, explicitly reset its
349 step_resumes are a form of bp that are made to be per-thread.
350 Since we created the step_resume bp when the parent process
351 was being debugged, and now are switching to the child process,
352 from the breakpoint package's viewpoint, that's a switch of
353 "threads". We must update the bp's notion of which thread
354 it is for, or it'll be ignored when it triggers. */
356 if (step_resume_breakpoint)
357 breakpoint_re_set_thread (step_resume_breakpoint);
359 /* Reinsert all breakpoints in the child. The user may have set
360 breakpoints after catching the fork, in which case those
361 were never set in the child, but only in the parent. This makes
362 sure the inserted breakpoints match the breakpoint list. */
364 breakpoint_re_set ();
365 insert_breakpoints ();
368 /* EXECD_PATHNAME is assumed to be non-NULL. */
371 follow_exec (int pid, char *execd_pathname)
374 struct target_ops *tgt;
376 if (!may_follow_exec)
379 /* This is an exec event that we actually wish to pay attention to.
380 Refresh our symbol table to the newly exec'd program, remove any
383 If there are breakpoints, they aren't really inserted now,
384 since the exec() transformed our inferior into a fresh set
387 We want to preserve symbolic breakpoints on the list, since
388 we have hopes that they can be reset after the new a.out's
389 symbol table is read.
391 However, any "raw" breakpoints must be removed from the list
392 (e.g., the solib bp's), since their address is probably invalid
395 And, we DON'T want to call delete_breakpoints() here, since
396 that may write the bp's "shadow contents" (the instruction
397 value that was overwritten witha TRAP instruction). Since
398 we now have a new a.out, those shadow contents aren't valid. */
399 update_breakpoints_after_exec ();
401 /* If there was one, it's gone now. We cannot truly step-to-next
402 statement through an exec(). */
403 step_resume_breakpoint = NULL;
404 step_range_start = 0;
407 /* What is this a.out's name? */
408 printf_unfiltered ("Executing new program: %s\n", execd_pathname);
410 /* We've followed the inferior through an exec. Therefore, the
411 inferior has essentially been killed & reborn. */
413 /* First collect the run target in effect. */
414 tgt = find_run_target ();
415 /* If we can't find one, things are in a very strange state... */
417 error ("Could find run target to save before following exec");
419 gdb_flush (gdb_stdout);
420 target_mourn_inferior ();
421 inferior_ptid = pid_to_ptid (saved_pid);
422 /* Because mourn_inferior resets inferior_ptid. */
425 /* That a.out is now the one to use. */
426 exec_file_attach (execd_pathname, 0);
428 /* And also is where symbols can be found. */
429 symbol_file_add_main (execd_pathname, 0);
431 /* Reset the shared library package. This ensures that we get
432 a shlib event when the child reaches "_start", at which point
433 the dld will have had a chance to initialize the child. */
434 #if defined(SOLIB_RESTART)
437 #ifdef SOLIB_CREATE_INFERIOR_HOOK
438 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
441 /* Reinsert all breakpoints. (Those which were symbolic have
442 been reset to the proper address in the new a.out, thanks
443 to symbol_file_command...) */
444 insert_breakpoints ();
446 /* The next resume of this inferior should bring it to the shlib
447 startup breakpoints. (If the user had also set bp's on
448 "main" from the old (parent) process, then they'll auto-
449 matically get reset there in the new process.) */
452 /* Non-zero if we just simulating a single-step. This is needed
453 because we cannot remove the breakpoints in the inferior process
454 until after the `wait' in `wait_for_inferior'. */
455 static int singlestep_breakpoints_inserted_p = 0;
457 /* The thread we inserted single-step breakpoints for. */
458 static ptid_t singlestep_ptid;
460 /* If another thread hit the singlestep breakpoint, we save the original
461 thread here so that we can resume single-stepping it later. */
462 static ptid_t saved_singlestep_ptid;
463 static int stepping_past_singlestep_breakpoint;
466 /* Things to clean up if we QUIT out of resume (). */
468 resume_cleanups (void *ignore)
473 static const char schedlock_off[] = "off";
474 static const char schedlock_on[] = "on";
475 static const char schedlock_step[] = "step";
476 static const char *scheduler_mode = schedlock_off;
477 static const char *scheduler_enums[] = {
485 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
487 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
488 the set command passed as a parameter. The clone operation will
489 include (BUG?) any ``set'' command callback, if present.
490 Commands like ``info set'' call all the ``show'' command
491 callbacks. Unfortunately, for ``show'' commands cloned from
492 ``set'', this includes callbacks belonging to ``set'' commands.
493 Making this worse, this only occures if add_show_from_set() is
494 called after add_cmd_sfunc() (BUG?). */
495 if (cmd_type (c) == set_cmd)
496 if (!target_can_lock_scheduler)
498 scheduler_mode = schedlock_off;
499 error ("Target '%s' cannot support this command.", target_shortname);
504 /* Resume the inferior, but allow a QUIT. This is useful if the user
505 wants to interrupt some lengthy single-stepping operation
506 (for child processes, the SIGINT goes to the inferior, and so
507 we get a SIGINT random_signal, but for remote debugging and perhaps
508 other targets, that's not true).
510 STEP nonzero if we should step (zero to continue instead).
511 SIG is the signal to give the inferior (zero for none). */
513 resume (int step, enum target_signal sig)
515 int should_resume = 1;
516 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
519 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
522 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
523 over an instruction that causes a page fault without triggering
524 a hardware watchpoint. The kernel properly notices that it shouldn't
525 stop, because the hardware watchpoint is not triggered, but it forgets
526 the step request and continues the program normally.
527 Work around the problem by removing hardware watchpoints if a step is
528 requested, GDB will check for a hardware watchpoint trigger after the
530 if (CANNOT_STEP_HW_WATCHPOINTS && step && breakpoints_inserted)
531 remove_hw_watchpoints ();
534 /* Normally, by the time we reach `resume', the breakpoints are either
535 removed or inserted, as appropriate. The exception is if we're sitting
536 at a permanent breakpoint; we need to step over it, but permanent
537 breakpoints can't be removed. So we have to test for it here. */
538 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here)
539 SKIP_PERMANENT_BREAKPOINT ();
541 if (SOFTWARE_SINGLE_STEP_P () && step)
543 /* Do it the hard way, w/temp breakpoints */
544 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ );
545 /* ...and don't ask hardware to do it. */
547 /* and do not pull these breakpoints until after a `wait' in
548 `wait_for_inferior' */
549 singlestep_breakpoints_inserted_p = 1;
550 singlestep_ptid = inferior_ptid;
553 /* If there were any forks/vforks/execs that were caught and are
554 now to be followed, then do so. */
555 switch (pending_follow.kind)
557 case TARGET_WAITKIND_FORKED:
558 case TARGET_WAITKIND_VFORKED:
559 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
564 case TARGET_WAITKIND_EXECD:
565 /* follow_exec is called as soon as the exec event is seen. */
566 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
573 /* Install inferior's terminal modes. */
574 target_terminal_inferior ();
580 resume_ptid = RESUME_ALL; /* Default */
582 if ((step || singlestep_breakpoints_inserted_p) &&
583 (stepping_past_singlestep_breakpoint
584 || (!breakpoints_inserted && breakpoint_here_p (read_pc ()))))
586 /* Stepping past a breakpoint without inserting breakpoints.
587 Make sure only the current thread gets to step, so that
588 other threads don't sneak past breakpoints while they are
591 resume_ptid = inferior_ptid;
594 if ((scheduler_mode == schedlock_on) ||
595 (scheduler_mode == schedlock_step &&
596 (step || singlestep_breakpoints_inserted_p)))
598 /* User-settable 'scheduler' mode requires solo thread resume. */
599 resume_ptid = inferior_ptid;
602 if (CANNOT_STEP_BREAKPOINT)
604 /* Most targets can step a breakpoint instruction, thus
605 executing it normally. But if this one cannot, just
606 continue and we will hit it anyway. */
607 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
610 target_resume (resume_ptid, step, sig);
613 discard_cleanups (old_cleanups);
617 /* Clear out all variables saying what to do when inferior is continued.
618 First do this, then set the ones you want, then call `proceed'. */
621 clear_proceed_status (void)
624 step_range_start = 0;
626 step_frame_id = null_frame_id;
627 step_over_calls = STEP_OVER_UNDEBUGGABLE;
629 stop_soon = NO_STOP_QUIETLY;
630 proceed_to_finish = 0;
631 breakpoint_proceeded = 1; /* We're about to proceed... */
633 /* Discard any remaining commands or status from previous stop. */
634 bpstat_clear (&stop_bpstat);
637 /* This should be suitable for any targets that support threads. */
640 prepare_to_proceed (void)
643 struct target_waitstatus wait_status;
645 /* Get the last target status returned by target_wait(). */
646 get_last_target_status (&wait_ptid, &wait_status);
648 /* Make sure we were stopped either at a breakpoint, or because
650 if (wait_status.kind != TARGET_WAITKIND_STOPPED
651 || (wait_status.value.sig != TARGET_SIGNAL_TRAP &&
652 wait_status.value.sig != TARGET_SIGNAL_INT))
657 if (!ptid_equal (wait_ptid, minus_one_ptid)
658 && !ptid_equal (inferior_ptid, wait_ptid))
660 /* Switched over from WAIT_PID. */
661 CORE_ADDR wait_pc = read_pc_pid (wait_ptid);
663 if (wait_pc != read_pc ())
665 /* Switch back to WAIT_PID thread. */
666 inferior_ptid = wait_ptid;
668 /* FIXME: This stuff came from switch_to_thread() in
669 thread.c (which should probably be a public function). */
670 flush_cached_frames ();
671 registers_changed ();
673 select_frame (get_current_frame ());
676 /* We return 1 to indicate that there is a breakpoint here,
677 so we need to step over it before continuing to avoid
678 hitting it straight away. */
679 if (breakpoint_here_p (wait_pc))
687 /* Record the pc of the program the last time it stopped. This is
688 just used internally by wait_for_inferior, but need to be preserved
689 over calls to it and cleared when the inferior is started. */
690 static CORE_ADDR prev_pc;
692 /* Basic routine for continuing the program in various fashions.
694 ADDR is the address to resume at, or -1 for resume where stopped.
695 SIGGNAL is the signal to give it, or 0 for none,
696 or -1 for act according to how it stopped.
697 STEP is nonzero if should trap after one instruction.
698 -1 means return after that and print nothing.
699 You should probably set various step_... variables
700 before calling here, if you are stepping.
702 You should call clear_proceed_status before calling proceed. */
705 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
710 step_start_function = find_pc_function (read_pc ());
714 if (addr == (CORE_ADDR) -1)
716 /* If there is a breakpoint at the address we will resume at,
717 step one instruction before inserting breakpoints
718 so that we do not stop right away (and report a second
719 hit at this breakpoint). */
721 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
724 #ifndef STEP_SKIPS_DELAY
725 #define STEP_SKIPS_DELAY(pc) (0)
726 #define STEP_SKIPS_DELAY_P (0)
728 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
729 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
730 is slow (it needs to read memory from the target). */
731 if (STEP_SKIPS_DELAY_P
732 && breakpoint_here_p (read_pc () + 4)
733 && STEP_SKIPS_DELAY (read_pc ()))
741 /* In a multi-threaded task we may select another thread
742 and then continue or step.
744 But if the old thread was stopped at a breakpoint, it
745 will immediately cause another breakpoint stop without
746 any execution (i.e. it will report a breakpoint hit
747 incorrectly). So we must step over it first.
749 prepare_to_proceed checks the current thread against the thread
750 that reported the most recent event. If a step-over is required
751 it returns TRUE and sets the current thread to the old thread. */
752 if (prepare_to_proceed () && breakpoint_here_p (read_pc ()))
756 /* We will get a trace trap after one instruction.
757 Continue it automatically and insert breakpoints then. */
761 insert_breakpoints ();
762 /* If we get here there was no call to error() in
763 insert breakpoints -- so they were inserted. */
764 breakpoints_inserted = 1;
767 if (siggnal != TARGET_SIGNAL_DEFAULT)
768 stop_signal = siggnal;
769 /* If this signal should not be seen by program,
770 give it zero. Used for debugging signals. */
771 else if (!signal_program[stop_signal])
772 stop_signal = TARGET_SIGNAL_0;
774 annotate_starting ();
776 /* Make sure that output from GDB appears before output from the
778 gdb_flush (gdb_stdout);
780 /* Refresh prev_pc value just prior to resuming. This used to be
781 done in stop_stepping, however, setting prev_pc there did not handle
782 scenarios such as inferior function calls or returning from
783 a function via the return command. In those cases, the prev_pc
784 value was not set properly for subsequent commands. The prev_pc value
785 is used to initialize the starting line number in the ecs. With an
786 invalid value, the gdb next command ends up stopping at the position
787 represented by the next line table entry past our start position.
788 On platforms that generate one line table entry per line, this
789 is not a problem. However, on the ia64, the compiler generates
790 extraneous line table entries that do not increase the line number.
791 When we issue the gdb next command on the ia64 after an inferior call
792 or a return command, we often end up a few instructions forward, still
793 within the original line we started.
795 An attempt was made to have init_execution_control_state () refresh
796 the prev_pc value before calculating the line number. This approach
797 did not work because on platforms that use ptrace, the pc register
798 cannot be read unless the inferior is stopped. At that point, we
799 are not guaranteed the inferior is stopped and so the read_pc ()
800 call can fail. Setting the prev_pc value here ensures the value is
801 updated correctly when the inferior is stopped. */
802 prev_pc = read_pc ();
804 /* Resume inferior. */
805 resume (oneproc || step || bpstat_should_step (), stop_signal);
807 /* Wait for it to stop (if not standalone)
808 and in any case decode why it stopped, and act accordingly. */
809 /* Do this only if we are not using the event loop, or if the target
810 does not support asynchronous execution. */
811 if (!event_loop_p || !target_can_async_p ())
813 wait_for_inferior ();
819 /* Start remote-debugging of a machine over a serial link. */
825 init_wait_for_inferior ();
826 stop_soon = STOP_QUIETLY;
829 /* Always go on waiting for the target, regardless of the mode. */
830 /* FIXME: cagney/1999-09-23: At present it isn't possible to
831 indicate to wait_for_inferior that a target should timeout if
832 nothing is returned (instead of just blocking). Because of this,
833 targets expecting an immediate response need to, internally, set
834 things up so that the target_wait() is forced to eventually
836 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
837 differentiate to its caller what the state of the target is after
838 the initial open has been performed. Here we're assuming that
839 the target has stopped. It should be possible to eventually have
840 target_open() return to the caller an indication that the target
841 is currently running and GDB state should be set to the same as
843 wait_for_inferior ();
847 /* Initialize static vars when a new inferior begins. */
850 init_wait_for_inferior (void)
852 /* These are meaningless until the first time through wait_for_inferior. */
855 breakpoints_inserted = 0;
856 breakpoint_init_inferior (inf_starting);
858 /* Don't confuse first call to proceed(). */
859 stop_signal = TARGET_SIGNAL_0;
861 /* The first resume is not following a fork/vfork/exec. */
862 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
864 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
865 number_of_threads_in_syscalls = 0;
867 clear_proceed_status ();
869 stepping_past_singlestep_breakpoint = 0;
872 /* This enum encodes possible reasons for doing a target_wait, so that
873 wfi can call target_wait in one place. (Ultimately the call will be
874 moved out of the infinite loop entirely.) */
878 infwait_normal_state,
879 infwait_thread_hop_state,
880 infwait_nullified_state,
881 infwait_nonstep_watch_state
884 /* Why did the inferior stop? Used to print the appropriate messages
885 to the interface from within handle_inferior_event(). */
886 enum inferior_stop_reason
888 /* We don't know why. */
890 /* Step, next, nexti, stepi finished. */
892 /* Found breakpoint. */
894 /* Inferior terminated by signal. */
896 /* Inferior exited. */
898 /* Inferior received signal, and user asked to be notified. */
902 /* This structure contains what used to be local variables in
903 wait_for_inferior. Probably many of them can return to being
904 locals in handle_inferior_event. */
906 struct execution_control_state
908 struct target_waitstatus ws;
909 struct target_waitstatus *wp;
912 CORE_ADDR stop_func_start;
913 CORE_ADDR stop_func_end;
914 char *stop_func_name;
915 struct symtab_and_line sal;
916 int remove_breakpoints_on_following_step;
918 struct symtab *current_symtab;
919 int handling_longjmp; /* FIXME */
921 ptid_t saved_inferior_ptid;
922 int stepping_through_solib_after_catch;
923 bpstat stepping_through_solib_catchpoints;
924 int enable_hw_watchpoints_after_wait;
925 int stepping_through_sigtramp;
926 int new_thread_event;
927 struct target_waitstatus tmpstatus;
928 enum infwait_states infwait_state;
933 void init_execution_control_state (struct execution_control_state *ecs);
935 void handle_inferior_event (struct execution_control_state *ecs);
937 static void step_into_function (struct execution_control_state *ecs);
938 static void insert_step_resume_breakpoint (struct frame_info *step_frame,
939 struct execution_control_state *ecs);
940 static void stop_stepping (struct execution_control_state *ecs);
941 static void prepare_to_wait (struct execution_control_state *ecs);
942 static void keep_going (struct execution_control_state *ecs);
943 static void print_stop_reason (enum inferior_stop_reason stop_reason,
946 /* Wait for control to return from inferior to debugger.
947 If inferior gets a signal, we may decide to start it up again
948 instead of returning. That is why there is a loop in this function.
949 When this function actually returns it means the inferior
950 should be left stopped and GDB should read more commands. */
953 wait_for_inferior (void)
955 struct cleanup *old_cleanups;
956 struct execution_control_state ecss;
957 struct execution_control_state *ecs;
959 old_cleanups = make_cleanup (delete_step_resume_breakpoint,
960 &step_resume_breakpoint);
962 /* wfi still stays in a loop, so it's OK just to take the address of
963 a local to get the ecs pointer. */
966 /* Fill in with reasonable starting values. */
967 init_execution_control_state (ecs);
969 /* We'll update this if & when we switch to a new thread. */
970 previous_inferior_ptid = inferior_ptid;
972 overlay_cache_invalid = 1;
974 /* We have to invalidate the registers BEFORE calling target_wait
975 because they can be loaded from the target while in target_wait.
976 This makes remote debugging a bit more efficient for those
977 targets that provide critical registers as part of their normal
980 registers_changed ();
984 if (deprecated_target_wait_hook)
985 ecs->ptid = deprecated_target_wait_hook (ecs->waiton_ptid, ecs->wp);
987 ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp);
989 /* Now figure out what to do with the result of the result. */
990 handle_inferior_event (ecs);
992 if (!ecs->wait_some_more)
995 do_cleanups (old_cleanups);
998 /* Asynchronous version of wait_for_inferior. It is called by the
999 event loop whenever a change of state is detected on the file
1000 descriptor corresponding to the target. It can be called more than
1001 once to complete a single execution command. In such cases we need
1002 to keep the state in a global variable ASYNC_ECSS. If it is the
1003 last time that this function is called for a single execution
1004 command, then report to the user that the inferior has stopped, and
1005 do the necessary cleanups. */
1007 struct execution_control_state async_ecss;
1008 struct execution_control_state *async_ecs;
1011 fetch_inferior_event (void *client_data)
1013 static struct cleanup *old_cleanups;
1015 async_ecs = &async_ecss;
1017 if (!async_ecs->wait_some_more)
1019 old_cleanups = make_exec_cleanup (delete_step_resume_breakpoint,
1020 &step_resume_breakpoint);
1022 /* Fill in with reasonable starting values. */
1023 init_execution_control_state (async_ecs);
1025 /* We'll update this if & when we switch to a new thread. */
1026 previous_inferior_ptid = inferior_ptid;
1028 overlay_cache_invalid = 1;
1030 /* We have to invalidate the registers BEFORE calling target_wait
1031 because they can be loaded from the target while in target_wait.
1032 This makes remote debugging a bit more efficient for those
1033 targets that provide critical registers as part of their normal
1034 status mechanism. */
1036 registers_changed ();
1039 if (deprecated_target_wait_hook)
1041 deprecated_target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp);
1043 async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp);
1045 /* Now figure out what to do with the result of the result. */
1046 handle_inferior_event (async_ecs);
1048 if (!async_ecs->wait_some_more)
1050 /* Do only the cleanups that have been added by this
1051 function. Let the continuations for the commands do the rest,
1052 if there are any. */
1053 do_exec_cleanups (old_cleanups);
1055 if (step_multi && stop_step)
1056 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
1058 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1062 /* Prepare an execution control state for looping through a
1063 wait_for_inferior-type loop. */
1066 init_execution_control_state (struct execution_control_state *ecs)
1068 /* ecs->another_trap? */
1069 ecs->random_signal = 0;
1070 ecs->remove_breakpoints_on_following_step = 0;
1071 ecs->handling_longjmp = 0; /* FIXME */
1072 ecs->stepping_through_solib_after_catch = 0;
1073 ecs->stepping_through_solib_catchpoints = NULL;
1074 ecs->enable_hw_watchpoints_after_wait = 0;
1075 ecs->stepping_through_sigtramp = 0;
1076 ecs->sal = find_pc_line (prev_pc, 0);
1077 ecs->current_line = ecs->sal.line;
1078 ecs->current_symtab = ecs->sal.symtab;
1079 ecs->infwait_state = infwait_normal_state;
1080 ecs->waiton_ptid = pid_to_ptid (-1);
1081 ecs->wp = &(ecs->ws);
1084 /* Call this function before setting step_resume_breakpoint, as a
1085 sanity check. There should never be more than one step-resume
1086 breakpoint per thread, so we should never be setting a new
1087 step_resume_breakpoint when one is already active. */
1089 check_for_old_step_resume_breakpoint (void)
1091 if (step_resume_breakpoint)
1093 ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1096 /* Return the cached copy of the last pid/waitstatus returned by
1097 target_wait()/deprecated_target_wait_hook(). The data is actually
1098 cached by handle_inferior_event(), which gets called immediately
1099 after target_wait()/deprecated_target_wait_hook(). */
1102 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
1104 *ptidp = target_last_wait_ptid;
1105 *status = target_last_waitstatus;
1108 /* Switch thread contexts, maintaining "infrun state". */
1111 context_switch (struct execution_control_state *ecs)
1113 /* Caution: it may happen that the new thread (or the old one!)
1114 is not in the thread list. In this case we must not attempt
1115 to "switch context", or we run the risk that our context may
1116 be lost. This may happen as a result of the target module
1117 mishandling thread creation. */
1119 if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid))
1120 { /* Perform infrun state context switch: */
1121 /* Save infrun state for the old thread. */
1122 save_infrun_state (inferior_ptid, prev_pc,
1123 trap_expected, step_resume_breakpoint,
1125 step_range_end, &step_frame_id,
1126 ecs->handling_longjmp, ecs->another_trap,
1127 ecs->stepping_through_solib_after_catch,
1128 ecs->stepping_through_solib_catchpoints,
1129 ecs->stepping_through_sigtramp,
1130 ecs->current_line, ecs->current_symtab);
1132 /* Load infrun state for the new thread. */
1133 load_infrun_state (ecs->ptid, &prev_pc,
1134 &trap_expected, &step_resume_breakpoint,
1136 &step_range_end, &step_frame_id,
1137 &ecs->handling_longjmp, &ecs->another_trap,
1138 &ecs->stepping_through_solib_after_catch,
1139 &ecs->stepping_through_solib_catchpoints,
1140 &ecs->stepping_through_sigtramp,
1141 &ecs->current_line, &ecs->current_symtab);
1143 inferior_ptid = ecs->ptid;
1147 adjust_pc_after_break (struct execution_control_state *ecs)
1149 CORE_ADDR breakpoint_pc;
1151 /* If this target does not decrement the PC after breakpoints, then
1152 we have nothing to do. */
1153 if (DECR_PC_AFTER_BREAK == 0)
1156 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
1157 we aren't, just return.
1159 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
1160 affected by DECR_PC_AFTER_BREAK. Other waitkinds which are implemented
1161 by software breakpoints should be handled through the normal breakpoint
1164 NOTE drow/2004-01-31: On some targets, breakpoints may generate
1165 different signals (SIGILL or SIGEMT for instance), but it is less
1166 clear where the PC is pointing afterwards. It may not match
1167 DECR_PC_AFTER_BREAK. I don't know any specific target that generates
1168 these signals at breakpoints (the code has been in GDB since at least
1169 1992) so I can not guess how to handle them here.
1171 In earlier versions of GDB, a target with HAVE_NONSTEPPABLE_WATCHPOINTS
1172 would have the PC after hitting a watchpoint affected by
1173 DECR_PC_AFTER_BREAK. I haven't found any target with both of these set
1174 in GDB history, and it seems unlikely to be correct, so
1175 HAVE_NONSTEPPABLE_WATCHPOINTS is not checked here. */
1177 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
1180 if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP)
1183 /* Find the location where (if we've hit a breakpoint) the
1184 breakpoint would be. */
1185 breakpoint_pc = read_pc_pid (ecs->ptid) - DECR_PC_AFTER_BREAK;
1187 if (SOFTWARE_SINGLE_STEP_P ())
1189 /* When using software single-step, a SIGTRAP can only indicate
1190 an inserted breakpoint. This actually makes things
1192 if (singlestep_breakpoints_inserted_p)
1193 /* When software single stepping, the instruction at [prev_pc]
1194 is never a breakpoint, but the instruction following
1195 [prev_pc] (in program execution order) always is. Assume
1196 that following instruction was reached and hence a software
1197 breakpoint was hit. */
1198 write_pc_pid (breakpoint_pc, ecs->ptid);
1199 else if (software_breakpoint_inserted_here_p (breakpoint_pc))
1200 /* The inferior was free running (i.e., no single-step
1201 breakpoints inserted) and it hit a software breakpoint. */
1202 write_pc_pid (breakpoint_pc, ecs->ptid);
1206 /* When using hardware single-step, a SIGTRAP is reported for
1207 both a completed single-step and a software breakpoint. Need
1208 to differentiate between the two as the latter needs
1209 adjusting but the former does not. */
1210 if (currently_stepping (ecs))
1212 if (prev_pc == breakpoint_pc
1213 && software_breakpoint_inserted_here_p (breakpoint_pc))
1214 /* Hardware single-stepped a software breakpoint (as
1215 occures when the inferior is resumed with PC pointing
1216 at not-yet-hit software breakpoint). Since the
1217 breakpoint really is executed, the inferior needs to be
1218 backed up to the breakpoint address. */
1219 write_pc_pid (breakpoint_pc, ecs->ptid);
1223 if (software_breakpoint_inserted_here_p (breakpoint_pc))
1224 /* The inferior was free running (i.e., no hardware
1225 single-step and no possibility of a false SIGTRAP) and
1226 hit a software breakpoint. */
1227 write_pc_pid (breakpoint_pc, ecs->ptid);
1232 /* Given an execution control state that has been freshly filled in
1233 by an event from the inferior, figure out what it means and take
1234 appropriate action. */
1236 int stepped_after_stopped_by_watchpoint;
1239 handle_inferior_event (struct execution_control_state *ecs)
1241 /* NOTE: cagney/2003-03-28: If you're looking at this code and
1242 thinking that the variable stepped_after_stopped_by_watchpoint
1243 isn't used, then you're wrong! The macro STOPPED_BY_WATCHPOINT,
1244 defined in the file "config/pa/nm-hppah.h", accesses the variable
1245 indirectly. Mutter something rude about the HP merge. */
1246 int sw_single_step_trap_p = 0;
1247 int stopped_by_watchpoint = -1; /* Mark as unknown. */
1249 /* Cache the last pid/waitstatus. */
1250 target_last_wait_ptid = ecs->ptid;
1251 target_last_waitstatus = *ecs->wp;
1253 adjust_pc_after_break (ecs);
1255 switch (ecs->infwait_state)
1257 case infwait_thread_hop_state:
1258 /* Cancel the waiton_ptid. */
1259 ecs->waiton_ptid = pid_to_ptid (-1);
1260 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1261 is serviced in this loop, below. */
1262 if (ecs->enable_hw_watchpoints_after_wait)
1264 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1265 ecs->enable_hw_watchpoints_after_wait = 0;
1267 stepped_after_stopped_by_watchpoint = 0;
1270 case infwait_normal_state:
1271 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1272 is serviced in this loop, below. */
1273 if (ecs->enable_hw_watchpoints_after_wait)
1275 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1276 ecs->enable_hw_watchpoints_after_wait = 0;
1278 stepped_after_stopped_by_watchpoint = 0;
1281 case infwait_nullified_state:
1282 stepped_after_stopped_by_watchpoint = 0;
1285 case infwait_nonstep_watch_state:
1286 insert_breakpoints ();
1288 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1289 handle things like signals arriving and other things happening
1290 in combination correctly? */
1291 stepped_after_stopped_by_watchpoint = 1;
1295 internal_error (__FILE__, __LINE__, "bad switch");
1297 ecs->infwait_state = infwait_normal_state;
1299 flush_cached_frames ();
1301 /* If it's a new process, add it to the thread database */
1303 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
1304 && !ptid_equal (ecs->ptid, minus_one_ptid)
1305 && !in_thread_list (ecs->ptid));
1307 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1308 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
1310 add_thread (ecs->ptid);
1312 ui_out_text (uiout, "[New ");
1313 ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid));
1314 ui_out_text (uiout, "]\n");
1317 /* NOTE: This block is ONLY meant to be invoked in case of a
1318 "thread creation event"! If it is invoked for any other
1319 sort of event (such as a new thread landing on a breakpoint),
1320 the event will be discarded, which is almost certainly
1323 To avoid this, the low-level module (eg. target_wait)
1324 should call in_thread_list and add_thread, so that the
1325 new thread is known by the time we get here. */
1327 /* We may want to consider not doing a resume here in order
1328 to give the user a chance to play with the new thread.
1329 It might be good to make that a user-settable option. */
1331 /* At this point, all threads are stopped (happens
1332 automatically in either the OS or the native code).
1333 Therefore we need to continue all threads in order to
1336 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
1337 prepare_to_wait (ecs);
1342 switch (ecs->ws.kind)
1344 case TARGET_WAITKIND_LOADED:
1345 /* Ignore gracefully during startup of the inferior, as it
1346 might be the shell which has just loaded some objects,
1347 otherwise add the symbols for the newly loaded objects. */
1349 if (stop_soon == NO_STOP_QUIETLY)
1351 /* Remove breakpoints, SOLIB_ADD might adjust
1352 breakpoint addresses via breakpoint_re_set. */
1353 if (breakpoints_inserted)
1354 remove_breakpoints ();
1356 /* Check for any newly added shared libraries if we're
1357 supposed to be adding them automatically. Switch
1358 terminal for any messages produced by
1359 breakpoint_re_set. */
1360 target_terminal_ours_for_output ();
1361 /* NOTE: cagney/2003-11-25: Make certain that the target
1362 stack's section table is kept up-to-date. Architectures,
1363 (e.g., PPC64), use the section table to perform
1364 operations such as address => section name and hence
1365 require the table to contain all sections (including
1366 those found in shared libraries). */
1367 /* NOTE: cagney/2003-11-25: Pass current_target and not
1368 exec_ops to SOLIB_ADD. This is because current GDB is
1369 only tooled to propagate section_table changes out from
1370 the "current_target" (see target_resize_to_sections), and
1371 not up from the exec stratum. This, of course, isn't
1372 right. "infrun.c" should only interact with the
1373 exec/process stratum, instead relying on the target stack
1374 to propagate relevant changes (stop, section table
1375 changed, ...) up to other layers. */
1376 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
1377 target_terminal_inferior ();
1379 /* Reinsert breakpoints and continue. */
1380 if (breakpoints_inserted)
1381 insert_breakpoints ();
1384 resume (0, TARGET_SIGNAL_0);
1385 prepare_to_wait (ecs);
1388 case TARGET_WAITKIND_SPURIOUS:
1389 resume (0, TARGET_SIGNAL_0);
1390 prepare_to_wait (ecs);
1393 case TARGET_WAITKIND_EXITED:
1394 target_terminal_ours (); /* Must do this before mourn anyway */
1395 print_stop_reason (EXITED, ecs->ws.value.integer);
1397 /* Record the exit code in the convenience variable $_exitcode, so
1398 that the user can inspect this again later. */
1399 set_internalvar (lookup_internalvar ("_exitcode"),
1400 value_from_longest (builtin_type_int,
1401 (LONGEST) ecs->ws.value.integer));
1402 gdb_flush (gdb_stdout);
1403 target_mourn_inferior ();
1404 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */
1405 stop_print_frame = 0;
1406 stop_stepping (ecs);
1409 case TARGET_WAITKIND_SIGNALLED:
1410 stop_print_frame = 0;
1411 stop_signal = ecs->ws.value.sig;
1412 target_terminal_ours (); /* Must do this before mourn anyway */
1414 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1415 reach here unless the inferior is dead. However, for years
1416 target_kill() was called here, which hints that fatal signals aren't
1417 really fatal on some systems. If that's true, then some changes
1419 target_mourn_inferior ();
1421 print_stop_reason (SIGNAL_EXITED, stop_signal);
1422 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */
1423 stop_stepping (ecs);
1426 /* The following are the only cases in which we keep going;
1427 the above cases end in a continue or goto. */
1428 case TARGET_WAITKIND_FORKED:
1429 case TARGET_WAITKIND_VFORKED:
1430 stop_signal = TARGET_SIGNAL_TRAP;
1431 pending_follow.kind = ecs->ws.kind;
1433 pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid);
1434 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1436 stop_pc = read_pc ();
1438 stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid, 0);
1440 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1442 /* If no catchpoint triggered for this, then keep going. */
1443 if (ecs->random_signal)
1445 stop_signal = TARGET_SIGNAL_0;
1449 goto process_event_stop_test;
1451 case TARGET_WAITKIND_EXECD:
1452 stop_signal = TARGET_SIGNAL_TRAP;
1454 /* NOTE drow/2002-12-05: This code should be pushed down into the
1455 target_wait function. Until then following vfork on HP/UX 10.20
1456 is probably broken by this. Of course, it's broken anyway. */
1457 /* Is this a target which reports multiple exec events per actual
1458 call to exec()? (HP-UX using ptrace does, for example.) If so,
1459 ignore all but the last one. Just resume the exec'r, and wait
1460 for the next exec event. */
1461 if (inferior_ignoring_leading_exec_events)
1463 inferior_ignoring_leading_exec_events--;
1464 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1465 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.
1467 target_resume (ecs->ptid, 0, TARGET_SIGNAL_0);
1468 prepare_to_wait (ecs);
1471 inferior_ignoring_leading_exec_events =
1472 target_reported_exec_events_per_exec_call () - 1;
1474 pending_follow.execd_pathname =
1475 savestring (ecs->ws.value.execd_pathname,
1476 strlen (ecs->ws.value.execd_pathname));
1478 /* This causes the eventpoints and symbol table to be reset. Must
1479 do this now, before trying to determine whether to stop. */
1480 follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname);
1481 xfree (pending_follow.execd_pathname);
1483 stop_pc = read_pc_pid (ecs->ptid);
1484 ecs->saved_inferior_ptid = inferior_ptid;
1485 inferior_ptid = ecs->ptid;
1487 stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid, 0);
1489 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1490 inferior_ptid = ecs->saved_inferior_ptid;
1492 /* If no catchpoint triggered for this, then keep going. */
1493 if (ecs->random_signal)
1495 stop_signal = TARGET_SIGNAL_0;
1499 goto process_event_stop_test;
1501 /* These syscall events are returned on HP-UX, as part of its
1502 implementation of page-protection-based "hardware" watchpoints.
1503 HP-UX has unfortunate interactions between page-protections and
1504 some system calls. Our solution is to disable hardware watches
1505 when a system call is entered, and reenable them when the syscall
1506 completes. The downside of this is that we may miss the precise
1507 point at which a watched piece of memory is modified. "Oh well."
1509 Note that we may have multiple threads running, which may each
1510 enter syscalls at roughly the same time. Since we don't have a
1511 good notion currently of whether a watched piece of memory is
1512 thread-private, we'd best not have any page-protections active
1513 when any thread is in a syscall. Thus, we only want to reenable
1514 hardware watches when no threads are in a syscall.
1516 Also, be careful not to try to gather much state about a thread
1517 that's in a syscall. It's frequently a losing proposition. */
1518 case TARGET_WAITKIND_SYSCALL_ENTRY:
1519 number_of_threads_in_syscalls++;
1520 if (number_of_threads_in_syscalls == 1)
1522 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid));
1524 resume (0, TARGET_SIGNAL_0);
1525 prepare_to_wait (ecs);
1528 /* Before examining the threads further, step this thread to
1529 get it entirely out of the syscall. (We get notice of the
1530 event when the thread is just on the verge of exiting a
1531 syscall. Stepping one instruction seems to get it back
1534 Note that although the logical place to reenable h/w watches
1535 is here, we cannot. We cannot reenable them before stepping
1536 the thread (this causes the next wait on the thread to hang).
1538 Nor can we enable them after stepping until we've done a wait.
1539 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1540 here, which will be serviced immediately after the target
1542 case TARGET_WAITKIND_SYSCALL_RETURN:
1543 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
1545 if (number_of_threads_in_syscalls > 0)
1547 number_of_threads_in_syscalls--;
1548 ecs->enable_hw_watchpoints_after_wait =
1549 (number_of_threads_in_syscalls == 0);
1551 prepare_to_wait (ecs);
1554 case TARGET_WAITKIND_STOPPED:
1555 stop_signal = ecs->ws.value.sig;
1558 /* We had an event in the inferior, but we are not interested
1559 in handling it at this level. The lower layers have already
1560 done what needs to be done, if anything.
1562 One of the possible circumstances for this is when the
1563 inferior produces output for the console. The inferior has
1564 not stopped, and we are ignoring the event. Another possible
1565 circumstance is any event which the lower level knows will be
1566 reported multiple times without an intervening resume. */
1567 case TARGET_WAITKIND_IGNORE:
1568 prepare_to_wait (ecs);
1572 /* We may want to consider not doing a resume here in order to give
1573 the user a chance to play with the new thread. It might be good
1574 to make that a user-settable option. */
1576 /* At this point, all threads are stopped (happens automatically in
1577 either the OS or the native code). Therefore we need to continue
1578 all threads in order to make progress. */
1579 if (ecs->new_thread_event)
1581 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
1582 prepare_to_wait (ecs);
1586 stop_pc = read_pc_pid (ecs->ptid);
1588 if (stepping_past_singlestep_breakpoint)
1590 gdb_assert (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p);
1591 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
1592 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
1594 stepping_past_singlestep_breakpoint = 0;
1596 /* We've either finished single-stepping past the single-step
1597 breakpoint, or stopped for some other reason. It would be nice if
1598 we could tell, but we can't reliably. */
1599 if (stop_signal == TARGET_SIGNAL_TRAP)
1601 /* Pull the single step breakpoints out of the target. */
1602 SOFTWARE_SINGLE_STEP (0, 0);
1603 singlestep_breakpoints_inserted_p = 0;
1605 ecs->random_signal = 0;
1607 ecs->ptid = saved_singlestep_ptid;
1608 context_switch (ecs);
1609 if (deprecated_context_hook)
1610 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
1612 resume (1, TARGET_SIGNAL_0);
1613 prepare_to_wait (ecs);
1618 stepping_past_singlestep_breakpoint = 0;
1620 /* See if a thread hit a thread-specific breakpoint that was meant for
1621 another thread. If so, then step that thread past the breakpoint,
1624 if (stop_signal == TARGET_SIGNAL_TRAP)
1626 int thread_hop_needed = 0;
1628 /* Check if a regular breakpoint has been hit before checking
1629 for a potential single step breakpoint. Otherwise, GDB will
1630 not see this breakpoint hit when stepping onto breakpoints. */
1631 if (breakpoints_inserted && breakpoint_here_p (stop_pc))
1633 ecs->random_signal = 0;
1634 if (!breakpoint_thread_match (stop_pc, ecs->ptid))
1635 thread_hop_needed = 1;
1637 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1639 ecs->random_signal = 0;
1640 /* The call to in_thread_list is necessary because PTIDs sometimes
1641 change when we go from single-threaded to multi-threaded. If
1642 the singlestep_ptid is still in the list, assume that it is
1643 really different from ecs->ptid. */
1644 if (!ptid_equal (singlestep_ptid, ecs->ptid)
1645 && in_thread_list (singlestep_ptid))
1647 thread_hop_needed = 1;
1648 stepping_past_singlestep_breakpoint = 1;
1649 saved_singlestep_ptid = singlestep_ptid;
1653 if (thread_hop_needed)
1657 /* Saw a breakpoint, but it was hit by the wrong thread.
1660 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1662 /* Pull the single step breakpoints out of the target. */
1663 SOFTWARE_SINGLE_STEP (0, 0);
1664 singlestep_breakpoints_inserted_p = 0;
1667 remove_status = remove_breakpoints ();
1668 /* Did we fail to remove breakpoints? If so, try
1669 to set the PC past the bp. (There's at least
1670 one situation in which we can fail to remove
1671 the bp's: On HP-UX's that use ttrace, we can't
1672 change the address space of a vforking child
1673 process until the child exits (well, okay, not
1674 then either :-) or execs. */
1675 if (remove_status != 0)
1677 /* FIXME! This is obviously non-portable! */
1678 write_pc_pid (stop_pc + 4, ecs->ptid);
1679 /* We need to restart all the threads now,
1680 * unles we're running in scheduler-locked mode.
1681 * Use currently_stepping to determine whether to
1684 /* FIXME MVS: is there any reason not to call resume()? */
1685 if (scheduler_mode == schedlock_on)
1686 target_resume (ecs->ptid,
1687 currently_stepping (ecs), TARGET_SIGNAL_0);
1689 target_resume (RESUME_ALL,
1690 currently_stepping (ecs), TARGET_SIGNAL_0);
1691 prepare_to_wait (ecs);
1696 breakpoints_inserted = 0;
1697 if (!ptid_equal (inferior_ptid, ecs->ptid))
1698 context_switch (ecs);
1699 ecs->waiton_ptid = ecs->ptid;
1700 ecs->wp = &(ecs->ws);
1701 ecs->another_trap = 1;
1703 ecs->infwait_state = infwait_thread_hop_state;
1705 registers_changed ();
1709 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1711 sw_single_step_trap_p = 1;
1712 ecs->random_signal = 0;
1716 ecs->random_signal = 1;
1718 /* See if something interesting happened to the non-current thread. If
1719 so, then switch to that thread. */
1720 if (!ptid_equal (ecs->ptid, inferior_ptid))
1722 context_switch (ecs);
1724 if (deprecated_context_hook)
1725 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
1727 flush_cached_frames ();
1730 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
1732 /* Pull the single step breakpoints out of the target. */
1733 SOFTWARE_SINGLE_STEP (0, 0);
1734 singlestep_breakpoints_inserted_p = 0;
1737 /* If PC is pointing at a nullified instruction, then step beyond
1738 it so that the user won't be confused when GDB appears to be ready
1741 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1742 if (INSTRUCTION_NULLIFIED)
1744 registers_changed ();
1745 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
1747 /* We may have received a signal that we want to pass to
1748 the inferior; therefore, we must not clobber the waitstatus
1751 ecs->infwait_state = infwait_nullified_state;
1752 ecs->waiton_ptid = ecs->ptid;
1753 ecs->wp = &(ecs->tmpstatus);
1754 prepare_to_wait (ecs);
1758 /* It may not be necessary to disable the watchpoint to stop over
1759 it. For example, the PA can (with some kernel cooperation)
1760 single step over a watchpoint without disabling the watchpoint. */
1761 if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1764 prepare_to_wait (ecs);
1768 /* It is far more common to need to disable a watchpoint to step
1769 the inferior over it. FIXME. What else might a debug
1770 register or page protection watchpoint scheme need here? */
1771 if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1773 /* At this point, we are stopped at an instruction which has
1774 attempted to write to a piece of memory under control of
1775 a watchpoint. The instruction hasn't actually executed
1776 yet. If we were to evaluate the watchpoint expression
1777 now, we would get the old value, and therefore no change
1778 would seem to have occurred.
1780 In order to make watchpoints work `right', we really need
1781 to complete the memory write, and then evaluate the
1782 watchpoint expression. The following code does that by
1783 removing the watchpoint (actually, all watchpoints and
1784 breakpoints), single-stepping the target, re-inserting
1785 watchpoints, and then falling through to let normal
1786 single-step processing handle proceed. Since this
1787 includes evaluating watchpoints, things will come to a
1788 stop in the correct manner. */
1790 remove_breakpoints ();
1791 registers_changed ();
1792 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */
1794 ecs->waiton_ptid = ecs->ptid;
1795 ecs->wp = &(ecs->ws);
1796 ecs->infwait_state = infwait_nonstep_watch_state;
1797 prepare_to_wait (ecs);
1801 /* It may be possible to simply continue after a watchpoint. */
1802 if (HAVE_CONTINUABLE_WATCHPOINT)
1803 stopped_by_watchpoint = STOPPED_BY_WATCHPOINT (ecs->ws);
1805 ecs->stop_func_start = 0;
1806 ecs->stop_func_end = 0;
1807 ecs->stop_func_name = 0;
1808 /* Don't care about return value; stop_func_start and stop_func_name
1809 will both be 0 if it doesn't work. */
1810 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
1811 &ecs->stop_func_start, &ecs->stop_func_end);
1812 ecs->stop_func_start += DEPRECATED_FUNCTION_START_OFFSET;
1813 ecs->another_trap = 0;
1814 bpstat_clear (&stop_bpstat);
1816 stop_stack_dummy = 0;
1817 stop_print_frame = 1;
1818 ecs->random_signal = 0;
1819 stopped_by_random_signal = 0;
1820 breakpoints_failed = 0;
1822 /* Look at the cause of the stop, and decide what to do.
1823 The alternatives are:
1824 1) break; to really stop and return to the debugger,
1825 2) drop through to start up again
1826 (set ecs->another_trap to 1 to single step once)
1827 3) set ecs->random_signal to 1, and the decision between 1 and 2
1828 will be made according to the signal handling tables. */
1830 /* First, distinguish signals caused by the debugger from signals
1831 that have to do with the program's own actions. Note that
1832 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
1833 on the operating system version. Here we detect when a SIGILL or
1834 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
1835 something similar for SIGSEGV, since a SIGSEGV will be generated
1836 when we're trying to execute a breakpoint instruction on a
1837 non-executable stack. This happens for call dummy breakpoints
1838 for architectures like SPARC that place call dummies on the
1841 if (stop_signal == TARGET_SIGNAL_TRAP
1842 || (breakpoints_inserted &&
1843 (stop_signal == TARGET_SIGNAL_ILL
1844 || stop_signal == TARGET_SIGNAL_SEGV
1845 || stop_signal == TARGET_SIGNAL_EMT))
1846 || stop_soon == STOP_QUIETLY
1847 || stop_soon == STOP_QUIETLY_NO_SIGSTOP)
1849 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
1851 stop_print_frame = 0;
1852 stop_stepping (ecs);
1856 /* This is originated from start_remote(), start_inferior() and
1857 shared libraries hook functions. */
1858 if (stop_soon == STOP_QUIETLY)
1860 stop_stepping (ecs);
1864 /* This originates from attach_command(). We need to overwrite
1865 the stop_signal here, because some kernels don't ignore a
1866 SIGSTOP in a subsequent ptrace(PTRACE_SONT,SOGSTOP) call.
1867 See more comments in inferior.h. */
1868 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP)
1870 stop_stepping (ecs);
1871 if (stop_signal == TARGET_SIGNAL_STOP)
1872 stop_signal = TARGET_SIGNAL_0;
1876 /* Don't even think about breakpoints if just proceeded over a
1878 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected)
1879 bpstat_clear (&stop_bpstat);
1882 /* See if there is a breakpoint at the current PC. */
1883 stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid,
1884 stopped_by_watchpoint);
1886 /* Following in case break condition called a
1888 stop_print_frame = 1;
1891 /* NOTE: cagney/2003-03-29: These two checks for a random signal
1892 at one stage in the past included checks for an inferior
1893 function call's call dummy's return breakpoint. The original
1894 comment, that went with the test, read:
1896 ``End of a stack dummy. Some systems (e.g. Sony news) give
1897 another signal besides SIGTRAP, so check here as well as
1900 If someone ever tries to get get call dummys on a
1901 non-executable stack to work (where the target would stop
1902 with something like a SIGSEGV), then those tests might need
1903 to be re-instated. Given, however, that the tests were only
1904 enabled when momentary breakpoints were not being used, I
1905 suspect that it won't be the case.
1907 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
1908 be necessary for call dummies on a non-executable stack on
1911 if (stop_signal == TARGET_SIGNAL_TRAP)
1913 = !(bpstat_explains_signal (stop_bpstat)
1915 || (step_range_end && step_resume_breakpoint == NULL));
1918 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1919 if (!ecs->random_signal)
1920 stop_signal = TARGET_SIGNAL_TRAP;
1924 /* When we reach this point, we've pretty much decided
1925 that the reason for stopping must've been a random
1926 (unexpected) signal. */
1929 ecs->random_signal = 1;
1931 process_event_stop_test:
1932 /* For the program's own signals, act according to
1933 the signal handling tables. */
1935 if (ecs->random_signal)
1937 /* Signal not for debugging purposes. */
1940 stopped_by_random_signal = 1;
1942 if (signal_print[stop_signal])
1945 target_terminal_ours_for_output ();
1946 print_stop_reason (SIGNAL_RECEIVED, stop_signal);
1948 if (signal_stop[stop_signal])
1950 stop_stepping (ecs);
1953 /* If not going to stop, give terminal back
1954 if we took it away. */
1956 target_terminal_inferior ();
1958 /* Clear the signal if it should not be passed. */
1959 if (signal_program[stop_signal] == 0)
1960 stop_signal = TARGET_SIGNAL_0;
1962 if (step_range_end != 0
1963 && stop_signal != TARGET_SIGNAL_0
1964 && stop_pc >= step_range_start && stop_pc < step_range_end
1965 && frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id))
1967 /* The inferior is about to take a signal that will take it
1968 out of the single step range. Set a breakpoint at the
1969 current PC (which is presumably where the signal handler
1970 will eventually return) and then allow the inferior to
1973 Note that this is only needed for a signal delivered
1974 while in the single-step range. Nested signals aren't a
1975 problem as they eventually all return. */
1976 insert_step_resume_breakpoint (get_current_frame (), ecs);
1982 /* Handle cases caused by hitting a breakpoint. */
1984 CORE_ADDR jmp_buf_pc;
1985 struct bpstat_what what;
1987 what = bpstat_what (stop_bpstat);
1989 if (what.call_dummy)
1991 stop_stack_dummy = 1;
1994 switch (what.main_action)
1996 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
1997 /* If we hit the breakpoint at longjmp, disable it for the
1998 duration of this command. Then, install a temporary
1999 breakpoint at the target of the jmp_buf. */
2000 disable_longjmp_breakpoint ();
2001 remove_breakpoints ();
2002 breakpoints_inserted = 0;
2003 if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc))
2009 /* Need to blow away step-resume breakpoint, as it
2010 interferes with us */
2011 if (step_resume_breakpoint != NULL)
2013 delete_step_resume_breakpoint (&step_resume_breakpoint);
2017 /* FIXME - Need to implement nested temporary breakpoints */
2018 if (step_over_calls > 0)
2019 set_longjmp_resume_breakpoint (jmp_buf_pc, get_current_frame ());
2022 set_longjmp_resume_breakpoint (jmp_buf_pc, null_frame_id);
2023 ecs->handling_longjmp = 1; /* FIXME */
2027 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
2028 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
2029 remove_breakpoints ();
2030 breakpoints_inserted = 0;
2032 /* FIXME - Need to implement nested temporary breakpoints */
2034 && (frame_id_inner (get_frame_id (get_current_frame ()),
2037 ecs->another_trap = 1;
2042 disable_longjmp_breakpoint ();
2043 ecs->handling_longjmp = 0; /* FIXME */
2044 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
2046 /* else fallthrough */
2048 case BPSTAT_WHAT_SINGLE:
2049 if (breakpoints_inserted)
2051 remove_breakpoints ();
2053 breakpoints_inserted = 0;
2054 ecs->another_trap = 1;
2055 /* Still need to check other stuff, at least the case
2056 where we are stepping and step out of the right range. */
2059 case BPSTAT_WHAT_STOP_NOISY:
2060 stop_print_frame = 1;
2062 /* We are about to nuke the step_resume_breakpointt via the
2063 cleanup chain, so no need to worry about it here. */
2065 stop_stepping (ecs);
2068 case BPSTAT_WHAT_STOP_SILENT:
2069 stop_print_frame = 0;
2071 /* We are about to nuke the step_resume_breakpoin via the
2072 cleanup chain, so no need to worry about it here. */
2074 stop_stepping (ecs);
2077 case BPSTAT_WHAT_STEP_RESUME:
2078 /* This proably demands a more elegant solution, but, yeah
2081 This function's use of the simple variable
2082 step_resume_breakpoint doesn't seem to accomodate
2083 simultaneously active step-resume bp's, although the
2084 breakpoint list certainly can.
2086 If we reach here and step_resume_breakpoint is already
2087 NULL, then apparently we have multiple active
2088 step-resume bp's. We'll just delete the breakpoint we
2089 stopped at, and carry on.
2091 Correction: what the code currently does is delete a
2092 step-resume bp, but it makes no effort to ensure that
2093 the one deleted is the one currently stopped at. MVS */
2095 if (step_resume_breakpoint == NULL)
2097 step_resume_breakpoint =
2098 bpstat_find_step_resume_breakpoint (stop_bpstat);
2100 delete_step_resume_breakpoint (&step_resume_breakpoint);
2103 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2104 /* If were waiting for a trap, hitting the step_resume_break
2105 doesn't count as getting it. */
2107 ecs->another_trap = 1;
2110 case BPSTAT_WHAT_CHECK_SHLIBS:
2111 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2114 /* Remove breakpoints, we eventually want to step over the
2115 shlib event breakpoint, and SOLIB_ADD might adjust
2116 breakpoint addresses via breakpoint_re_set. */
2117 if (breakpoints_inserted)
2118 remove_breakpoints ();
2119 breakpoints_inserted = 0;
2121 /* Check for any newly added shared libraries if we're
2122 supposed to be adding them automatically. Switch
2123 terminal for any messages produced by
2124 breakpoint_re_set. */
2125 target_terminal_ours_for_output ();
2126 /* NOTE: cagney/2003-11-25: Make certain that the target
2127 stack's section table is kept up-to-date. Architectures,
2128 (e.g., PPC64), use the section table to perform
2129 operations such as address => section name and hence
2130 require the table to contain all sections (including
2131 those found in shared libraries). */
2132 /* NOTE: cagney/2003-11-25: Pass current_target and not
2133 exec_ops to SOLIB_ADD. This is because current GDB is
2134 only tooled to propagate section_table changes out from
2135 the "current_target" (see target_resize_to_sections), and
2136 not up from the exec stratum. This, of course, isn't
2137 right. "infrun.c" should only interact with the
2138 exec/process stratum, instead relying on the target stack
2139 to propagate relevant changes (stop, section table
2140 changed, ...) up to other layers. */
2141 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
2142 target_terminal_inferior ();
2144 /* Try to reenable shared library breakpoints, additional
2145 code segments in shared libraries might be mapped in now. */
2146 re_enable_breakpoints_in_shlibs ();
2148 /* If requested, stop when the dynamic linker notifies
2149 gdb of events. This allows the user to get control
2150 and place breakpoints in initializer routines for
2151 dynamically loaded objects (among other things). */
2152 if (stop_on_solib_events || stop_stack_dummy)
2154 stop_stepping (ecs);
2158 /* If we stopped due to an explicit catchpoint, then the
2159 (see above) call to SOLIB_ADD pulled in any symbols
2160 from a newly-loaded library, if appropriate.
2162 We do want the inferior to stop, but not where it is
2163 now, which is in the dynamic linker callback. Rather,
2164 we would like it stop in the user's program, just after
2165 the call that caused this catchpoint to trigger. That
2166 gives the user a more useful vantage from which to
2167 examine their program's state. */
2168 else if (what.main_action ==
2169 BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2171 /* ??rehrauer: If I could figure out how to get the
2172 right return PC from here, we could just set a temp
2173 breakpoint and resume. I'm not sure we can without
2174 cracking open the dld's shared libraries and sniffing
2175 their unwind tables and text/data ranges, and that's
2176 not a terribly portable notion.
2178 Until that time, we must step the inferior out of the
2179 dld callback, and also out of the dld itself (and any
2180 code or stubs in libdld.sl, such as "shl_load" and
2181 friends) until we reach non-dld code. At that point,
2182 we can stop stepping. */
2183 bpstat_get_triggered_catchpoints (stop_bpstat,
2185 stepping_through_solib_catchpoints);
2186 ecs->stepping_through_solib_after_catch = 1;
2188 /* Be sure to lift all breakpoints, so the inferior does
2189 actually step past this point... */
2190 ecs->another_trap = 1;
2195 /* We want to step over this breakpoint, then keep going. */
2196 ecs->another_trap = 1;
2203 case BPSTAT_WHAT_LAST:
2204 /* Not a real code, but listed here to shut up gcc -Wall. */
2206 case BPSTAT_WHAT_KEEP_CHECKING:
2211 /* We come here if we hit a breakpoint but should not
2212 stop for it. Possibly we also were stepping
2213 and should stop for that. So fall through and
2214 test for stepping. But, if not stepping,
2217 /* Are we stepping to get the inferior out of the dynamic
2218 linker's hook (and possibly the dld itself) after catching
2220 if (ecs->stepping_through_solib_after_catch)
2222 #if defined(SOLIB_ADD)
2223 /* Have we reached our destination? If not, keep going. */
2224 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
2226 ecs->another_trap = 1;
2231 /* Else, stop and report the catchpoint(s) whose triggering
2232 caused us to begin stepping. */
2233 ecs->stepping_through_solib_after_catch = 0;
2234 bpstat_clear (&stop_bpstat);
2235 stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints);
2236 bpstat_clear (&ecs->stepping_through_solib_catchpoints);
2237 stop_print_frame = 1;
2238 stop_stepping (ecs);
2242 if (step_resume_breakpoint)
2244 /* Having a step-resume breakpoint overrides anything
2245 else having to do with stepping commands until
2246 that breakpoint is reached. */
2251 if (step_range_end == 0)
2253 /* Likewise if we aren't even stepping. */
2258 /* If stepping through a line, keep going if still within it.
2260 Note that step_range_end is the address of the first instruction
2261 beyond the step range, and NOT the address of the last instruction
2263 if (stop_pc >= step_range_start && stop_pc < step_range_end)
2269 /* We stepped out of the stepping range. */
2271 /* If we are stepping at the source level and entered the runtime
2272 loader dynamic symbol resolution code, we keep on single stepping
2273 until we exit the run time loader code and reach the callee's
2275 if (step_over_calls == STEP_OVER_UNDEBUGGABLE
2276 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2278 CORE_ADDR pc_after_resolver =
2279 gdbarch_skip_solib_resolver (current_gdbarch, stop_pc);
2281 if (pc_after_resolver)
2283 /* Set up a step-resume breakpoint at the address
2284 indicated by SKIP_SOLIB_RESOLVER. */
2285 struct symtab_and_line sr_sal;
2287 sr_sal.pc = pc_after_resolver;
2289 check_for_old_step_resume_breakpoint ();
2290 step_resume_breakpoint =
2291 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2292 if (breakpoints_inserted)
2293 insert_breakpoints ();
2300 if (step_range_end != 1
2301 && (step_over_calls == STEP_OVER_UNDEBUGGABLE
2302 || step_over_calls == STEP_OVER_ALL)
2303 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME)
2305 /* The inferior, while doing a "step" or "next", has ended up in
2306 a signal trampoline (either by a signal being delivered or by
2307 the signal handler returning). Just single-step until the
2308 inferior leaves the trampoline (either by calling the handler
2314 if (frame_id_eq (frame_unwind_id (get_current_frame ()),
2317 /* It's a subroutine call. */
2318 CORE_ADDR real_stop_pc;
2320 if ((step_over_calls == STEP_OVER_NONE)
2321 || ((step_range_end == 1)
2322 && in_prologue (prev_pc, ecs->stop_func_start)))
2324 /* I presume that step_over_calls is only 0 when we're
2325 supposed to be stepping at the assembly language level
2326 ("stepi"). Just stop. */
2327 /* Also, maybe we just did a "nexti" inside a prolog, so we
2328 thought it was a subroutine call but it was not. Stop as
2331 print_stop_reason (END_STEPPING_RANGE, 0);
2332 stop_stepping (ecs);
2336 #ifdef DEPRECATED_IGNORE_HELPER_CALL
2337 /* On MIPS16, a function that returns a floating point value may
2338 call a library helper function to copy the return value to a
2339 floating point register. The DEPRECATED_IGNORE_HELPER_CALL
2340 macro returns non-zero if we should ignore (i.e. step over)
2341 this function call. */
2342 /* FIXME: cagney/2004-07-21: These custom ``ignore frame when
2343 stepping'' function attributes (SIGTRAMP_FRAME,
2344 DEPRECATED_IGNORE_HELPER_CALL, SKIP_TRAMPOLINE_CODE,
2345 skip_language_trampoline frame, et.al.) need to be replaced
2346 with generic attributes bound to the frame's function. */
2347 if (step_over_calls == STEP_OVER_ALL
2348 || DEPRECATED_IGNORE_HELPER_CALL (stop_pc))
2350 /* We're doing a "next", set a breakpoint at callee's return
2351 address (the address at which the caller will
2353 insert_step_resume_breakpoint (get_prev_frame (get_current_frame ()),
2360 /* If we are in a function call trampoline (a stub between the
2361 calling routine and the real function), locate the real
2362 function. That's what tells us (a) whether we want to step
2363 into it at all, and (b) what prologue we want to run to the
2364 end of, if we do step into it. */
2365 real_stop_pc = skip_language_trampoline (stop_pc);
2366 if (real_stop_pc == 0)
2367 real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc);
2368 if (real_stop_pc != 0)
2369 ecs->stop_func_start = real_stop_pc;
2371 if (IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs->stop_func_start))
2373 struct symtab_and_line sr_sal;
2375 sr_sal.pc = ecs->stop_func_start;
2377 check_for_old_step_resume_breakpoint ();
2378 step_resume_breakpoint =
2379 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2380 if (breakpoints_inserted)
2381 insert_breakpoints ();
2387 /* If we have line number information for the function we are
2388 thinking of stepping into, step into it.
2390 If there are several symtabs at that PC (e.g. with include
2391 files), just want to know whether *any* of them have line
2392 numbers. find_pc_line handles this. */
2394 struct symtab_and_line tmp_sal;
2396 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
2397 if (tmp_sal.line != 0)
2399 step_into_function (ecs);
2404 /* If we have no line number and the step-stop-if-no-debug is
2405 set, we stop the step so that the user has a chance to switch
2406 in assembly mode. */
2407 if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug)
2410 print_stop_reason (END_STEPPING_RANGE, 0);
2411 stop_stepping (ecs);
2415 /* Set a breakpoint at callee's return address (the address at
2416 which the caller will resume). */
2417 insert_step_resume_breakpoint (get_prev_frame (get_current_frame ()), ecs);
2422 /* If we're in the return path from a shared library trampoline,
2423 we want to proceed through the trampoline when stepping. */
2424 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2426 /* Determine where this trampoline returns. */
2427 CORE_ADDR real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc);
2429 /* Only proceed through if we know where it's going. */
2432 /* And put the step-breakpoint there and go until there. */
2433 struct symtab_and_line sr_sal;
2435 init_sal (&sr_sal); /* initialize to zeroes */
2436 sr_sal.pc = real_stop_pc;
2437 sr_sal.section = find_pc_overlay (sr_sal.pc);
2438 /* Do not specify what the fp should be when we stop
2439 since on some machines the prologue
2440 is where the new fp value is established. */
2441 check_for_old_step_resume_breakpoint ();
2442 step_resume_breakpoint =
2443 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2444 if (breakpoints_inserted)
2445 insert_breakpoints ();
2447 /* Restart without fiddling with the step ranges or
2454 /* NOTE: tausq/2004-05-24: This if block used to be done before all
2455 the trampoline processing logic, however, there are some trampolines
2456 that have no names, so we should do trampoline handling first. */
2457 if (step_over_calls == STEP_OVER_UNDEBUGGABLE
2458 && ecs->stop_func_name == NULL)
2460 /* The inferior just stepped into, or returned to, an
2461 undebuggable function (where there is no symbol, not even a
2462 minimal symbol, corresponding to the address where the
2463 inferior stopped). Since we want to skip this kind of code,
2464 we keep going until the inferior returns from this
2466 if (step_stop_if_no_debug)
2468 /* If we have no line number and the step-stop-if-no-debug
2469 is set, we stop the step so that the user has a chance to
2470 switch in assembly mode. */
2472 print_stop_reason (END_STEPPING_RANGE, 0);
2473 stop_stepping (ecs);
2478 /* Set a breakpoint at callee's return address (the address
2479 at which the caller will resume). */
2480 insert_step_resume_breakpoint (get_prev_frame (get_current_frame ()),
2487 if (step_range_end == 1)
2489 /* It is stepi or nexti. We always want to stop stepping after
2492 print_stop_reason (END_STEPPING_RANGE, 0);
2493 stop_stepping (ecs);
2497 ecs->sal = find_pc_line (stop_pc, 0);
2499 if (ecs->sal.line == 0)
2501 /* We have no line number information. That means to stop
2502 stepping (does this always happen right after one instruction,
2503 when we do "s" in a function with no line numbers,
2504 or can this happen as a result of a return or longjmp?). */
2506 print_stop_reason (END_STEPPING_RANGE, 0);
2507 stop_stepping (ecs);
2511 if ((stop_pc == ecs->sal.pc)
2512 && (ecs->current_line != ecs->sal.line
2513 || ecs->current_symtab != ecs->sal.symtab))
2515 /* We are at the start of a different line. So stop. Note that
2516 we don't stop if we step into the middle of a different line.
2517 That is said to make things like for (;;) statements work
2520 print_stop_reason (END_STEPPING_RANGE, 0);
2521 stop_stepping (ecs);
2525 /* We aren't done stepping.
2527 Optimize by setting the stepping range to the line.
2528 (We might not be in the original line, but if we entered a
2529 new line in mid-statement, we continue stepping. This makes
2530 things like for(;;) statements work better.) */
2532 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
2534 /* If this is the last line of the function, don't keep stepping
2535 (it would probably step us out of the function).
2536 This is particularly necessary for a one-line function,
2537 in which after skipping the prologue we better stop even though
2538 we will be in mid-line. */
2540 print_stop_reason (END_STEPPING_RANGE, 0);
2541 stop_stepping (ecs);
2544 step_range_start = ecs->sal.pc;
2545 step_range_end = ecs->sal.end;
2546 step_frame_id = get_frame_id (get_current_frame ());
2547 ecs->current_line = ecs->sal.line;
2548 ecs->current_symtab = ecs->sal.symtab;
2550 /* In the case where we just stepped out of a function into the
2551 middle of a line of the caller, continue stepping, but
2552 step_frame_id must be modified to current frame */
2554 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too
2555 generous. It will trigger on things like a step into a frameless
2556 stackless leaf function. I think the logic should instead look
2557 at the unwound frame ID has that should give a more robust
2558 indication of what happened. */
2559 if (step-ID == current-ID)
2560 still stepping in same function;
2561 else if (step-ID == unwind (current-ID))
2562 stepped into a function;
2564 stepped out of a function;
2565 /* Of course this assumes that the frame ID unwind code is robust
2566 and we're willing to introduce frame unwind logic into this
2567 function. Fortunately, those days are nearly upon us. */
2570 struct frame_id current_frame = get_frame_id (get_current_frame ());
2571 if (!(frame_id_inner (current_frame, step_frame_id)))
2572 step_frame_id = current_frame;
2578 /* Are we in the middle of stepping? */
2581 currently_stepping (struct execution_control_state *ecs)
2583 return ((!ecs->handling_longjmp
2584 && ((step_range_end && step_resume_breakpoint == NULL)
2586 || ecs->stepping_through_solib_after_catch
2587 || bpstat_should_step ());
2590 /* Subroutine call with source code we should not step over. Do step
2591 to the first line of code in it. */
2594 step_into_function (struct execution_control_state *ecs)
2597 struct symtab_and_line sr_sal;
2599 s = find_pc_symtab (stop_pc);
2600 if (s && s->language != language_asm)
2601 ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start);
2603 ecs->sal = find_pc_line (ecs->stop_func_start, 0);
2604 /* Use the step_resume_break to step until the end of the prologue,
2605 even if that involves jumps (as it seems to on the vax under
2607 /* If the prologue ends in the middle of a source line, continue to
2608 the end of that source line (if it is still within the function).
2609 Otherwise, just go to end of prologue. */
2611 && ecs->sal.pc != ecs->stop_func_start
2612 && ecs->sal.end < ecs->stop_func_end)
2613 ecs->stop_func_start = ecs->sal.end;
2615 /* Architectures which require breakpoint adjustment might not be able
2616 to place a breakpoint at the computed address. If so, the test
2617 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
2618 ecs->stop_func_start to an address at which a breakpoint may be
2619 legitimately placed.
2621 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
2622 made, GDB will enter an infinite loop when stepping through
2623 optimized code consisting of VLIW instructions which contain
2624 subinstructions corresponding to different source lines. On
2625 FR-V, it's not permitted to place a breakpoint on any but the
2626 first subinstruction of a VLIW instruction. When a breakpoint is
2627 set, GDB will adjust the breakpoint address to the beginning of
2628 the VLIW instruction. Thus, we need to make the corresponding
2629 adjustment here when computing the stop address. */
2631 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch))
2633 ecs->stop_func_start
2634 = gdbarch_adjust_breakpoint_address (current_gdbarch,
2635 ecs->stop_func_start);
2638 if (ecs->stop_func_start == stop_pc)
2640 /* We are already there: stop now. */
2642 print_stop_reason (END_STEPPING_RANGE, 0);
2643 stop_stepping (ecs);
2648 /* Put the step-breakpoint there and go until there. */
2649 init_sal (&sr_sal); /* initialize to zeroes */
2650 sr_sal.pc = ecs->stop_func_start;
2651 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
2652 /* Do not specify what the fp should be when we stop since on
2653 some machines the prologue is where the new fp value is
2655 check_for_old_step_resume_breakpoint ();
2656 step_resume_breakpoint =
2657 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2658 if (breakpoints_inserted)
2659 insert_breakpoints ();
2661 /* And make sure stepping stops right away then. */
2662 step_range_end = step_range_start;
2667 /* Insert a "step resume breakpoint" at RETURN_FRAME.pc. This is used
2668 to skip a function (next, skip-no-debug) or signal. It's assumed
2669 that the function/signal handler being skipped eventually returns
2670 to the breakpoint inserted at RETURN_FRAME.pc.
2672 For the skip-function case, the function may have been reached by
2673 either single stepping a call / return / signal-return instruction,
2674 or by hitting a breakpoint. In all cases, the RETURN_FRAME belongs
2675 to the skip-function's caller.
2677 For the signals case, this is called with the interrupted
2678 function's frame. The signal handler, when it returns, will resume
2679 the interrupted function at RETURN_FRAME.pc. */
2682 insert_step_resume_breakpoint (struct frame_info *return_frame,
2683 struct execution_control_state *ecs)
2685 struct symtab_and_line sr_sal;
2687 init_sal (&sr_sal); /* initialize to zeros */
2689 sr_sal.pc = ADDR_BITS_REMOVE (get_frame_pc (return_frame));
2690 sr_sal.section = find_pc_overlay (sr_sal.pc);
2692 check_for_old_step_resume_breakpoint ();
2694 step_resume_breakpoint
2695 = set_momentary_breakpoint (sr_sal, get_frame_id (return_frame),
2698 if (breakpoints_inserted)
2699 insert_breakpoints ();
2703 stop_stepping (struct execution_control_state *ecs)
2705 /* Let callers know we don't want to wait for the inferior anymore. */
2706 ecs->wait_some_more = 0;
2709 /* This function handles various cases where we need to continue
2710 waiting for the inferior. */
2711 /* (Used to be the keep_going: label in the old wait_for_inferior) */
2714 keep_going (struct execution_control_state *ecs)
2716 /* Save the pc before execution, to compare with pc after stop. */
2717 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
2719 /* If we did not do break;, it means we should keep running the
2720 inferior and not return to debugger. */
2722 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
2724 /* We took a signal (which we are supposed to pass through to
2725 the inferior, else we'd have done a break above) and we
2726 haven't yet gotten our trap. Simply continue. */
2727 resume (currently_stepping (ecs), stop_signal);
2731 /* Either the trap was not expected, but we are continuing
2732 anyway (the user asked that this signal be passed to the
2735 The signal was SIGTRAP, e.g. it was our signal, but we
2736 decided we should resume from it.
2738 We're going to run this baby now!
2740 Insert breakpoints now, unless we are trying to one-proceed
2741 past a breakpoint. */
2742 /* If we've just finished a special step resume and we don't
2743 want to hit a breakpoint, pull em out. */
2744 if (step_resume_breakpoint == NULL
2745 && ecs->remove_breakpoints_on_following_step)
2747 ecs->remove_breakpoints_on_following_step = 0;
2748 remove_breakpoints ();
2749 breakpoints_inserted = 0;
2751 else if (!breakpoints_inserted && !ecs->another_trap)
2753 breakpoints_failed = insert_breakpoints ();
2754 if (breakpoints_failed)
2756 stop_stepping (ecs);
2759 breakpoints_inserted = 1;
2762 trap_expected = ecs->another_trap;
2764 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
2765 specifies that such a signal should be delivered to the
2768 Typically, this would occure when a user is debugging a
2769 target monitor on a simulator: the target monitor sets a
2770 breakpoint; the simulator encounters this break-point and
2771 halts the simulation handing control to GDB; GDB, noteing
2772 that the break-point isn't valid, returns control back to the
2773 simulator; the simulator then delivers the hardware
2774 equivalent of a SIGNAL_TRAP to the program being debugged. */
2776 if (stop_signal == TARGET_SIGNAL_TRAP && !signal_program[stop_signal])
2777 stop_signal = TARGET_SIGNAL_0;
2780 resume (currently_stepping (ecs), stop_signal);
2783 prepare_to_wait (ecs);
2786 /* This function normally comes after a resume, before
2787 handle_inferior_event exits. It takes care of any last bits of
2788 housekeeping, and sets the all-important wait_some_more flag. */
2791 prepare_to_wait (struct execution_control_state *ecs)
2793 if (ecs->infwait_state == infwait_normal_state)
2795 overlay_cache_invalid = 1;
2797 /* We have to invalidate the registers BEFORE calling
2798 target_wait because they can be loaded from the target while
2799 in target_wait. This makes remote debugging a bit more
2800 efficient for those targets that provide critical registers
2801 as part of their normal status mechanism. */
2803 registers_changed ();
2804 ecs->waiton_ptid = pid_to_ptid (-1);
2805 ecs->wp = &(ecs->ws);
2807 /* This is the old end of the while loop. Let everybody know we
2808 want to wait for the inferior some more and get called again
2810 ecs->wait_some_more = 1;
2813 /* Print why the inferior has stopped. We always print something when
2814 the inferior exits, or receives a signal. The rest of the cases are
2815 dealt with later on in normal_stop() and print_it_typical(). Ideally
2816 there should be a call to this function from handle_inferior_event()
2817 each time stop_stepping() is called.*/
2819 print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
2821 switch (stop_reason)
2824 /* We don't deal with these cases from handle_inferior_event()
2827 case END_STEPPING_RANGE:
2828 /* We are done with a step/next/si/ni command. */
2829 /* For now print nothing. */
2830 /* Print a message only if not in the middle of doing a "step n"
2831 operation for n > 1 */
2832 if (!step_multi || !stop_step)
2833 if (ui_out_is_mi_like_p (uiout))
2834 ui_out_field_string (uiout, "reason", "end-stepping-range");
2836 case BREAKPOINT_HIT:
2837 /* We found a breakpoint. */
2838 /* For now print nothing. */
2841 /* The inferior was terminated by a signal. */
2842 annotate_signalled ();
2843 if (ui_out_is_mi_like_p (uiout))
2844 ui_out_field_string (uiout, "reason", "exited-signalled");
2845 ui_out_text (uiout, "\nProgram terminated with signal ");
2846 annotate_signal_name ();
2847 ui_out_field_string (uiout, "signal-name",
2848 target_signal_to_name (stop_info));
2849 annotate_signal_name_end ();
2850 ui_out_text (uiout, ", ");
2851 annotate_signal_string ();
2852 ui_out_field_string (uiout, "signal-meaning",
2853 target_signal_to_string (stop_info));
2854 annotate_signal_string_end ();
2855 ui_out_text (uiout, ".\n");
2856 ui_out_text (uiout, "The program no longer exists.\n");
2859 /* The inferior program is finished. */
2860 annotate_exited (stop_info);
2863 if (ui_out_is_mi_like_p (uiout))
2864 ui_out_field_string (uiout, "reason", "exited");
2865 ui_out_text (uiout, "\nProgram exited with code ");
2866 ui_out_field_fmt (uiout, "exit-code", "0%o",
2867 (unsigned int) stop_info);
2868 ui_out_text (uiout, ".\n");
2872 if (ui_out_is_mi_like_p (uiout))
2873 ui_out_field_string (uiout, "reason", "exited-normally");
2874 ui_out_text (uiout, "\nProgram exited normally.\n");
2877 case SIGNAL_RECEIVED:
2878 /* Signal received. The signal table tells us to print about
2881 ui_out_text (uiout, "\nProgram received signal ");
2882 annotate_signal_name ();
2883 if (ui_out_is_mi_like_p (uiout))
2884 ui_out_field_string (uiout, "reason", "signal-received");
2885 ui_out_field_string (uiout, "signal-name",
2886 target_signal_to_name (stop_info));
2887 annotate_signal_name_end ();
2888 ui_out_text (uiout, ", ");
2889 annotate_signal_string ();
2890 ui_out_field_string (uiout, "signal-meaning",
2891 target_signal_to_string (stop_info));
2892 annotate_signal_string_end ();
2893 ui_out_text (uiout, ".\n");
2896 internal_error (__FILE__, __LINE__,
2897 "print_stop_reason: unrecognized enum value");
2903 /* Here to return control to GDB when the inferior stops for real.
2904 Print appropriate messages, remove breakpoints, give terminal our modes.
2906 STOP_PRINT_FRAME nonzero means print the executing frame
2907 (pc, function, args, file, line number and line text).
2908 BREAKPOINTS_FAILED nonzero means stop was due to error
2909 attempting to insert breakpoints. */
2914 struct target_waitstatus last;
2917 get_last_target_status (&last_ptid, &last);
2919 /* As with the notification of thread events, we want to delay
2920 notifying the user that we've switched thread context until
2921 the inferior actually stops.
2923 There's no point in saying anything if the inferior has exited.
2924 Note that SIGNALLED here means "exited with a signal", not
2925 "received a signal". */
2926 if (!ptid_equal (previous_inferior_ptid, inferior_ptid)
2927 && target_has_execution
2928 && last.kind != TARGET_WAITKIND_SIGNALLED
2929 && last.kind != TARGET_WAITKIND_EXITED)
2931 target_terminal_ours_for_output ();
2932 printf_filtered ("[Switching to %s]\n",
2933 target_pid_or_tid_to_str (inferior_ptid));
2934 previous_inferior_ptid = inferior_ptid;
2937 /* NOTE drow/2004-01-17: Is this still necessary? */
2938 /* Make sure that the current_frame's pc is correct. This
2939 is a correction for setting up the frame info before doing
2940 DECR_PC_AFTER_BREAK */
2941 if (target_has_execution)
2942 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
2943 DECR_PC_AFTER_BREAK, the program counter can change. Ask the
2944 frame code to check for this and sort out any resultant mess.
2945 DECR_PC_AFTER_BREAK needs to just go away. */
2946 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
2948 if (target_has_execution && breakpoints_inserted)
2950 if (remove_breakpoints ())
2952 target_terminal_ours_for_output ();
2953 printf_filtered ("Cannot remove breakpoints because ");
2954 printf_filtered ("program is no longer writable.\n");
2955 printf_filtered ("It might be running in another process.\n");
2956 printf_filtered ("Further execution is probably impossible.\n");
2959 breakpoints_inserted = 0;
2961 /* Delete the breakpoint we stopped at, if it wants to be deleted.
2962 Delete any breakpoint that is to be deleted at the next stop. */
2964 breakpoint_auto_delete (stop_bpstat);
2966 /* If an auto-display called a function and that got a signal,
2967 delete that auto-display to avoid an infinite recursion. */
2969 if (stopped_by_random_signal)
2970 disable_current_display ();
2972 /* Don't print a message if in the middle of doing a "step n"
2973 operation for n > 1 */
2974 if (step_multi && stop_step)
2977 target_terminal_ours ();
2979 /* Look up the hook_stop and run it (CLI internally handles problem
2980 of stop_command's pre-hook not existing). */
2982 catch_errors (hook_stop_stub, stop_command,
2983 "Error while running hook_stop:\n", RETURN_MASK_ALL);
2985 if (!target_has_stack)
2991 /* Select innermost stack frame - i.e., current frame is frame 0,
2992 and current location is based on that.
2993 Don't do this on return from a stack dummy routine,
2994 or if the program has exited. */
2996 if (!stop_stack_dummy)
2998 select_frame (get_current_frame ());
3000 /* Print current location without a level number, if
3001 we have changed functions or hit a breakpoint.
3002 Print source line if we have one.
3003 bpstat_print() contains the logic deciding in detail
3004 what to print, based on the event(s) that just occurred. */
3006 if (stop_print_frame && deprecated_selected_frame)
3010 int do_frame_printing = 1;
3012 bpstat_ret = bpstat_print (stop_bpstat);
3016 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3017 (or should) carry around the function and does (or
3018 should) use that when doing a frame comparison. */
3020 && frame_id_eq (step_frame_id,
3021 get_frame_id (get_current_frame ()))
3022 && step_start_function == find_pc_function (stop_pc))
3023 source_flag = SRC_LINE; /* finished step, just print source line */
3025 source_flag = SRC_AND_LOC; /* print location and source line */
3027 case PRINT_SRC_AND_LOC:
3028 source_flag = SRC_AND_LOC; /* print location and source line */
3030 case PRINT_SRC_ONLY:
3031 source_flag = SRC_LINE;
3034 source_flag = SRC_LINE; /* something bogus */
3035 do_frame_printing = 0;
3038 internal_error (__FILE__, __LINE__, "Unknown value.");
3040 /* For mi, have the same behavior every time we stop:
3041 print everything but the source line. */
3042 if (ui_out_is_mi_like_p (uiout))
3043 source_flag = LOC_AND_ADDRESS;
3045 if (ui_out_is_mi_like_p (uiout))
3046 ui_out_field_int (uiout, "thread-id",
3047 pid_to_thread_id (inferior_ptid));
3048 /* The behavior of this routine with respect to the source
3050 SRC_LINE: Print only source line
3051 LOCATION: Print only location
3052 SRC_AND_LOC: Print location and source line */
3053 if (do_frame_printing)
3054 print_stack_frame (get_selected_frame (), 0, source_flag);
3056 /* Display the auto-display expressions. */
3061 /* Save the function value return registers, if we care.
3062 We might be about to restore their previous contents. */
3063 if (proceed_to_finish)
3064 /* NB: The copy goes through to the target picking up the value of
3065 all the registers. */
3066 regcache_cpy (stop_registers, current_regcache);
3068 if (stop_stack_dummy)
3070 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3071 ends with a setting of the current frame, so we can use that
3073 frame_pop (get_current_frame ());
3074 /* Set stop_pc to what it was before we called the function.
3075 Can't rely on restore_inferior_status because that only gets
3076 called if we don't stop in the called function. */
3077 stop_pc = read_pc ();
3078 select_frame (get_current_frame ());
3082 annotate_stopped ();
3083 observer_notify_normal_stop (stop_bpstat);
3087 hook_stop_stub (void *cmd)
3089 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
3094 signal_stop_state (int signo)
3096 return signal_stop[signo];
3100 signal_print_state (int signo)
3102 return signal_print[signo];
3106 signal_pass_state (int signo)
3108 return signal_program[signo];
3112 signal_stop_update (int signo, int state)
3114 int ret = signal_stop[signo];
3115 signal_stop[signo] = state;
3120 signal_print_update (int signo, int state)
3122 int ret = signal_print[signo];
3123 signal_print[signo] = state;
3128 signal_pass_update (int signo, int state)
3130 int ret = signal_program[signo];
3131 signal_program[signo] = state;
3136 sig_print_header (void)
3139 Signal Stop\tPrint\tPass to program\tDescription\n");
3143 sig_print_info (enum target_signal oursig)
3145 char *name = target_signal_to_name (oursig);
3146 int name_padding = 13 - strlen (name);
3148 if (name_padding <= 0)
3151 printf_filtered ("%s", name);
3152 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
3153 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3154 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3155 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3156 printf_filtered ("%s\n", target_signal_to_string (oursig));
3159 /* Specify how various signals in the inferior should be handled. */
3162 handle_command (char *args, int from_tty)
3165 int digits, wordlen;
3166 int sigfirst, signum, siglast;
3167 enum target_signal oursig;
3170 unsigned char *sigs;
3171 struct cleanup *old_chain;
3175 error_no_arg ("signal to handle");
3178 /* Allocate and zero an array of flags for which signals to handle. */
3180 nsigs = (int) TARGET_SIGNAL_LAST;
3181 sigs = (unsigned char *) alloca (nsigs);
3182 memset (sigs, 0, nsigs);
3184 /* Break the command line up into args. */
3186 argv = buildargv (args);
3191 old_chain = make_cleanup_freeargv (argv);
3193 /* Walk through the args, looking for signal oursigs, signal names, and
3194 actions. Signal numbers and signal names may be interspersed with
3195 actions, with the actions being performed for all signals cumulatively
3196 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3198 while (*argv != NULL)
3200 wordlen = strlen (*argv);
3201 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3205 sigfirst = siglast = -1;
3207 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3209 /* Apply action to all signals except those used by the
3210 debugger. Silently skip those. */
3213 siglast = nsigs - 1;
3215 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3217 SET_SIGS (nsigs, sigs, signal_stop);
3218 SET_SIGS (nsigs, sigs, signal_print);
3220 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3222 UNSET_SIGS (nsigs, sigs, signal_program);
3224 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3226 SET_SIGS (nsigs, sigs, signal_print);
3228 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3230 SET_SIGS (nsigs, sigs, signal_program);
3232 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3234 UNSET_SIGS (nsigs, sigs, signal_stop);
3236 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3238 SET_SIGS (nsigs, sigs, signal_program);
3240 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3242 UNSET_SIGS (nsigs, sigs, signal_print);
3243 UNSET_SIGS (nsigs, sigs, signal_stop);
3245 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3247 UNSET_SIGS (nsigs, sigs, signal_program);
3249 else if (digits > 0)
3251 /* It is numeric. The numeric signal refers to our own
3252 internal signal numbering from target.h, not to host/target
3253 signal number. This is a feature; users really should be
3254 using symbolic names anyway, and the common ones like
3255 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3257 sigfirst = siglast = (int)
3258 target_signal_from_command (atoi (*argv));
3259 if ((*argv)[digits] == '-')
3262 target_signal_from_command (atoi ((*argv) + digits + 1));
3264 if (sigfirst > siglast)
3266 /* Bet he didn't figure we'd think of this case... */
3274 oursig = target_signal_from_name (*argv);
3275 if (oursig != TARGET_SIGNAL_UNKNOWN)
3277 sigfirst = siglast = (int) oursig;
3281 /* Not a number and not a recognized flag word => complain. */
3282 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3286 /* If any signal numbers or symbol names were found, set flags for
3287 which signals to apply actions to. */
3289 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3291 switch ((enum target_signal) signum)
3293 case TARGET_SIGNAL_TRAP:
3294 case TARGET_SIGNAL_INT:
3295 if (!allsigs && !sigs[signum])
3297 if (query ("%s is used by the debugger.\n\
3298 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum)))
3304 printf_unfiltered ("Not confirmed, unchanged.\n");
3305 gdb_flush (gdb_stdout);
3309 case TARGET_SIGNAL_0:
3310 case TARGET_SIGNAL_DEFAULT:
3311 case TARGET_SIGNAL_UNKNOWN:
3312 /* Make sure that "all" doesn't print these. */
3323 target_notice_signals (inferior_ptid);
3327 /* Show the results. */
3328 sig_print_header ();
3329 for (signum = 0; signum < nsigs; signum++)
3333 sig_print_info (signum);
3338 do_cleanups (old_chain);
3342 xdb_handle_command (char *args, int from_tty)
3345 struct cleanup *old_chain;
3347 /* Break the command line up into args. */
3349 argv = buildargv (args);
3354 old_chain = make_cleanup_freeargv (argv);
3355 if (argv[1] != (char *) NULL)
3360 bufLen = strlen (argv[0]) + 20;
3361 argBuf = (char *) xmalloc (bufLen);
3365 enum target_signal oursig;
3367 oursig = target_signal_from_name (argv[0]);
3368 memset (argBuf, 0, bufLen);
3369 if (strcmp (argv[1], "Q") == 0)
3370 sprintf (argBuf, "%s %s", argv[0], "noprint");
3373 if (strcmp (argv[1], "s") == 0)
3375 if (!signal_stop[oursig])
3376 sprintf (argBuf, "%s %s", argv[0], "stop");
3378 sprintf (argBuf, "%s %s", argv[0], "nostop");
3380 else if (strcmp (argv[1], "i") == 0)
3382 if (!signal_program[oursig])
3383 sprintf (argBuf, "%s %s", argv[0], "pass");
3385 sprintf (argBuf, "%s %s", argv[0], "nopass");
3387 else if (strcmp (argv[1], "r") == 0)
3389 if (!signal_print[oursig])
3390 sprintf (argBuf, "%s %s", argv[0], "print");
3392 sprintf (argBuf, "%s %s", argv[0], "noprint");
3398 handle_command (argBuf, from_tty);
3400 printf_filtered ("Invalid signal handling flag.\n");
3405 do_cleanups (old_chain);
3408 /* Print current contents of the tables set by the handle command.
3409 It is possible we should just be printing signals actually used
3410 by the current target (but for things to work right when switching
3411 targets, all signals should be in the signal tables). */
3414 signals_info (char *signum_exp, int from_tty)
3416 enum target_signal oursig;
3417 sig_print_header ();
3421 /* First see if this is a symbol name. */
3422 oursig = target_signal_from_name (signum_exp);
3423 if (oursig == TARGET_SIGNAL_UNKNOWN)
3425 /* No, try numeric. */
3427 target_signal_from_command (parse_and_eval_long (signum_exp));
3429 sig_print_info (oursig);
3433 printf_filtered ("\n");
3434 /* These ugly casts brought to you by the native VAX compiler. */
3435 for (oursig = TARGET_SIGNAL_FIRST;
3436 (int) oursig < (int) TARGET_SIGNAL_LAST;
3437 oursig = (enum target_signal) ((int) oursig + 1))
3441 if (oursig != TARGET_SIGNAL_UNKNOWN
3442 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
3443 sig_print_info (oursig);
3446 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3449 struct inferior_status
3451 enum target_signal stop_signal;
3455 int stop_stack_dummy;
3456 int stopped_by_random_signal;
3458 CORE_ADDR step_range_start;
3459 CORE_ADDR step_range_end;
3460 struct frame_id step_frame_id;
3461 enum step_over_calls_kind step_over_calls;
3462 CORE_ADDR step_resume_break_address;
3463 int stop_after_trap;
3465 struct regcache *stop_registers;
3467 /* These are here because if call_function_by_hand has written some
3468 registers and then decides to call error(), we better not have changed
3470 struct regcache *registers;
3472 /* A frame unique identifier. */
3473 struct frame_id selected_frame_id;
3475 int breakpoint_proceeded;
3476 int restore_stack_info;
3477 int proceed_to_finish;
3481 write_inferior_status_register (struct inferior_status *inf_status, int regno,
3484 int size = DEPRECATED_REGISTER_RAW_SIZE (regno);
3485 void *buf = alloca (size);
3486 store_signed_integer (buf, size, val);
3487 regcache_raw_write (inf_status->registers, regno, buf);
3490 /* Save all of the information associated with the inferior<==>gdb
3491 connection. INF_STATUS is a pointer to a "struct inferior_status"
3492 (defined in inferior.h). */
3494 struct inferior_status *
3495 save_inferior_status (int restore_stack_info)
3497 struct inferior_status *inf_status = XMALLOC (struct inferior_status);
3499 inf_status->stop_signal = stop_signal;
3500 inf_status->stop_pc = stop_pc;
3501 inf_status->stop_step = stop_step;
3502 inf_status->stop_stack_dummy = stop_stack_dummy;
3503 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3504 inf_status->trap_expected = trap_expected;
3505 inf_status->step_range_start = step_range_start;
3506 inf_status->step_range_end = step_range_end;
3507 inf_status->step_frame_id = step_frame_id;
3508 inf_status->step_over_calls = step_over_calls;
3509 inf_status->stop_after_trap = stop_after_trap;
3510 inf_status->stop_soon = stop_soon;
3511 /* Save original bpstat chain here; replace it with copy of chain.
3512 If caller's caller is walking the chain, they'll be happier if we
3513 hand them back the original chain when restore_inferior_status is
3515 inf_status->stop_bpstat = stop_bpstat;
3516 stop_bpstat = bpstat_copy (stop_bpstat);
3517 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3518 inf_status->restore_stack_info = restore_stack_info;
3519 inf_status->proceed_to_finish = proceed_to_finish;
3521 inf_status->stop_registers = regcache_dup_no_passthrough (stop_registers);
3523 inf_status->registers = regcache_dup (current_regcache);
3525 inf_status->selected_frame_id = get_frame_id (deprecated_selected_frame);
3530 restore_selected_frame (void *args)
3532 struct frame_id *fid = (struct frame_id *) args;
3533 struct frame_info *frame;
3535 frame = frame_find_by_id (*fid);
3537 /* If inf_status->selected_frame_id is NULL, there was no previously
3541 warning ("Unable to restore previously selected frame.\n");
3545 select_frame (frame);
3551 restore_inferior_status (struct inferior_status *inf_status)
3553 stop_signal = inf_status->stop_signal;
3554 stop_pc = inf_status->stop_pc;
3555 stop_step = inf_status->stop_step;
3556 stop_stack_dummy = inf_status->stop_stack_dummy;
3557 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3558 trap_expected = inf_status->trap_expected;
3559 step_range_start = inf_status->step_range_start;
3560 step_range_end = inf_status->step_range_end;
3561 step_frame_id = inf_status->step_frame_id;
3562 step_over_calls = inf_status->step_over_calls;
3563 stop_after_trap = inf_status->stop_after_trap;
3564 stop_soon = inf_status->stop_soon;
3565 bpstat_clear (&stop_bpstat);
3566 stop_bpstat = inf_status->stop_bpstat;
3567 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3568 proceed_to_finish = inf_status->proceed_to_finish;
3570 /* FIXME: Is the restore of stop_registers always needed. */
3571 regcache_xfree (stop_registers);
3572 stop_registers = inf_status->stop_registers;
3574 /* The inferior can be gone if the user types "print exit(0)"
3575 (and perhaps other times). */
3576 if (target_has_execution)
3577 /* NB: The register write goes through to the target. */
3578 regcache_cpy (current_regcache, inf_status->registers);
3579 regcache_xfree (inf_status->registers);
3581 /* FIXME: If we are being called after stopping in a function which
3582 is called from gdb, we should not be trying to restore the
3583 selected frame; it just prints a spurious error message (The
3584 message is useful, however, in detecting bugs in gdb (like if gdb
3585 clobbers the stack)). In fact, should we be restoring the
3586 inferior status at all in that case? . */
3588 if (target_has_stack && inf_status->restore_stack_info)
3590 /* The point of catch_errors is that if the stack is clobbered,
3591 walking the stack might encounter a garbage pointer and
3592 error() trying to dereference it. */
3594 (restore_selected_frame, &inf_status->selected_frame_id,
3595 "Unable to restore previously selected frame:\n",
3596 RETURN_MASK_ERROR) == 0)
3597 /* Error in restoring the selected frame. Select the innermost
3599 select_frame (get_current_frame ());
3607 do_restore_inferior_status_cleanup (void *sts)
3609 restore_inferior_status (sts);
3613 make_cleanup_restore_inferior_status (struct inferior_status *inf_status)
3615 return make_cleanup (do_restore_inferior_status_cleanup, inf_status);
3619 discard_inferior_status (struct inferior_status *inf_status)
3621 /* See save_inferior_status for info on stop_bpstat. */
3622 bpstat_clear (&inf_status->stop_bpstat);
3623 regcache_xfree (inf_status->registers);
3624 regcache_xfree (inf_status->stop_registers);
3629 inferior_has_forked (int pid, int *child_pid)
3631 struct target_waitstatus last;
3634 get_last_target_status (&last_ptid, &last);
3636 if (last.kind != TARGET_WAITKIND_FORKED)
3639 if (ptid_get_pid (last_ptid) != pid)
3642 *child_pid = last.value.related_pid;
3647 inferior_has_vforked (int pid, int *child_pid)
3649 struct target_waitstatus last;
3652 get_last_target_status (&last_ptid, &last);
3654 if (last.kind != TARGET_WAITKIND_VFORKED)
3657 if (ptid_get_pid (last_ptid) != pid)
3660 *child_pid = last.value.related_pid;
3665 inferior_has_execd (int pid, char **execd_pathname)
3667 struct target_waitstatus last;
3670 get_last_target_status (&last_ptid, &last);
3672 if (last.kind != TARGET_WAITKIND_EXECD)
3675 if (ptid_get_pid (last_ptid) != pid)
3678 *execd_pathname = xstrdup (last.value.execd_pathname);
3682 /* Oft used ptids */
3684 ptid_t minus_one_ptid;
3686 /* Create a ptid given the necessary PID, LWP, and TID components. */
3689 ptid_build (int pid, long lwp, long tid)
3699 /* Create a ptid from just a pid. */
3702 pid_to_ptid (int pid)
3704 return ptid_build (pid, 0, 0);
3707 /* Fetch the pid (process id) component from a ptid. */
3710 ptid_get_pid (ptid_t ptid)
3715 /* Fetch the lwp (lightweight process) component from a ptid. */
3718 ptid_get_lwp (ptid_t ptid)
3723 /* Fetch the tid (thread id) component from a ptid. */
3726 ptid_get_tid (ptid_t ptid)
3731 /* ptid_equal() is used to test equality of two ptids. */
3734 ptid_equal (ptid_t ptid1, ptid_t ptid2)
3736 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
3737 && ptid1.tid == ptid2.tid);
3740 /* restore_inferior_ptid() will be used by the cleanup machinery
3741 to restore the inferior_ptid value saved in a call to
3742 save_inferior_ptid(). */
3745 restore_inferior_ptid (void *arg)
3747 ptid_t *saved_ptid_ptr = arg;
3748 inferior_ptid = *saved_ptid_ptr;
3752 /* Save the value of inferior_ptid so that it may be restored by a
3753 later call to do_cleanups(). Returns the struct cleanup pointer
3754 needed for later doing the cleanup. */
3757 save_inferior_ptid (void)
3759 ptid_t *saved_ptid_ptr;
3761 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
3762 *saved_ptid_ptr = inferior_ptid;
3763 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
3770 stop_registers = regcache_xmalloc (current_gdbarch);
3774 _initialize_infrun (void)
3778 struct cmd_list_element *c;
3780 DEPRECATED_REGISTER_GDBARCH_SWAP (stop_registers);
3781 deprecated_register_gdbarch_swap (NULL, 0, build_infrun);
3783 add_info ("signals", signals_info,
3784 "What debugger does when program gets various signals.\n\
3785 Specify a signal as argument to print info on that signal only.");
3786 add_info_alias ("handle", "signals", 0);
3788 add_com ("handle", class_run, handle_command,
3789 concat ("Specify how to handle a signal.\n\
3790 Args are signals and actions to apply to those signals.\n\
3791 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3792 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3793 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3794 The special arg \"all\" is recognized to mean all signals except those\n\
3795 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3796 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3797 Stop means reenter debugger if this signal happens (implies print).\n\
3798 Print means print a message if this signal happens.\n\
3799 Pass means let program see this signal; otherwise program doesn't know.\n\
3800 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3801 Pass and Stop may be combined.", NULL));
3804 add_com ("lz", class_info, signals_info,
3805 "What debugger does when program gets various signals.\n\
3806 Specify a signal as argument to print info on that signal only.");
3807 add_com ("z", class_run, xdb_handle_command,
3808 concat ("Specify how to handle a signal.\n\
3809 Args are signals and actions to apply to those signals.\n\
3810 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3811 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3812 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3813 The special arg \"all\" is recognized to mean all signals except those\n\
3814 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3815 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3816 nopass), \"Q\" (noprint)\n\
3817 Stop means reenter debugger if this signal happens (implies print).\n\
3818 Print means print a message if this signal happens.\n\
3819 Pass means let program see this signal; otherwise program doesn't know.\n\
3820 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3821 Pass and Stop may be combined.", NULL));
3826 add_cmd ("stop", class_obscure, not_just_help_class_command, "There is no `stop' command, but you can set a hook on `stop'.\n\
3827 This allows you to set a list of commands to be run each time execution\n\
3828 of the program stops.", &cmdlist);
3830 numsigs = (int) TARGET_SIGNAL_LAST;
3831 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
3832 signal_print = (unsigned char *)
3833 xmalloc (sizeof (signal_print[0]) * numsigs);
3834 signal_program = (unsigned char *)
3835 xmalloc (sizeof (signal_program[0]) * numsigs);
3836 for (i = 0; i < numsigs; i++)
3839 signal_print[i] = 1;
3840 signal_program[i] = 1;
3843 /* Signals caused by debugger's own actions
3844 should not be given to the program afterwards. */
3845 signal_program[TARGET_SIGNAL_TRAP] = 0;
3846 signal_program[TARGET_SIGNAL_INT] = 0;
3848 /* Signals that are not errors should not normally enter the debugger. */
3849 signal_stop[TARGET_SIGNAL_ALRM] = 0;
3850 signal_print[TARGET_SIGNAL_ALRM] = 0;
3851 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
3852 signal_print[TARGET_SIGNAL_VTALRM] = 0;
3853 signal_stop[TARGET_SIGNAL_PROF] = 0;
3854 signal_print[TARGET_SIGNAL_PROF] = 0;
3855 signal_stop[TARGET_SIGNAL_CHLD] = 0;
3856 signal_print[TARGET_SIGNAL_CHLD] = 0;
3857 signal_stop[TARGET_SIGNAL_IO] = 0;
3858 signal_print[TARGET_SIGNAL_IO] = 0;
3859 signal_stop[TARGET_SIGNAL_POLL] = 0;
3860 signal_print[TARGET_SIGNAL_POLL] = 0;
3861 signal_stop[TARGET_SIGNAL_URG] = 0;
3862 signal_print[TARGET_SIGNAL_URG] = 0;
3863 signal_stop[TARGET_SIGNAL_WINCH] = 0;
3864 signal_print[TARGET_SIGNAL_WINCH] = 0;
3866 /* These signals are used internally by user-level thread
3867 implementations. (See signal(5) on Solaris.) Like the above
3868 signals, a healthy program receives and handles them as part of
3869 its normal operation. */
3870 signal_stop[TARGET_SIGNAL_LWP] = 0;
3871 signal_print[TARGET_SIGNAL_LWP] = 0;
3872 signal_stop[TARGET_SIGNAL_WAITING] = 0;
3873 signal_print[TARGET_SIGNAL_WAITING] = 0;
3874 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
3875 signal_print[TARGET_SIGNAL_CANCEL] = 0;
3879 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
3880 (char *) &stop_on_solib_events,
3881 "Set stopping for shared library events.\n\
3882 If nonzero, gdb will give control to the user when the dynamic linker\n\
3883 notifies gdb of shared library events. The most common event of interest\n\
3884 to the user would be loading/unloading of a new library.\n", &setlist), &showlist);
3887 c = add_set_enum_cmd ("follow-fork-mode",
3889 follow_fork_mode_kind_names, &follow_fork_mode_string,
3890 "Set debugger response to a program call of fork \
3892 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3893 parent - the original process is debugged after a fork\n\
3894 child - the new process is debugged after a fork\n\
3895 The unfollowed process will continue to run.\n\
3896 By default, the debugger will follow the parent process.", &setlist);
3897 add_show_from_set (c, &showlist);
3899 c = add_set_enum_cmd ("scheduler-locking", class_run, scheduler_enums, /* array of string names */
3900 &scheduler_mode, /* current mode */
3901 "Set mode for locking scheduler during execution.\n\
3902 off == no locking (threads may preempt at any time)\n\
3903 on == full locking (no thread except the current thread may run)\n\
3904 step == scheduler locked during every single-step operation.\n\
3905 In this mode, no other thread may run during a step command.\n\
3906 Other threads may run while stepping over a function call ('next').", &setlist);
3908 set_cmd_sfunc (c, set_schedlock_func); /* traps on target vector */
3909 add_show_from_set (c, &showlist);
3911 c = add_set_cmd ("step-mode", class_run,
3912 var_boolean, (char *) &step_stop_if_no_debug,
3913 "Set mode of the step operation. When set, doing a step over a\n\
3914 function without debug line information will stop at the first\n\
3915 instruction of that function. Otherwise, the function is skipped and\n\
3916 the step command stops at a different source line.", &setlist);
3917 add_show_from_set (c, &showlist);
3919 /* ptid initializations */
3920 null_ptid = ptid_build (0, 0, 0);
3921 minus_one_ptid = ptid_build (-1, 0, 0);
3922 inferior_ptid = null_ptid;
3923 target_last_wait_ptid = minus_one_ptid;