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 (DEPRECATED_IGNORE_HELPER_CALL (stop_pc))
2349 /* We're doing a "next", set a breakpoint at callee's return
2350 address (the address at which the caller will
2352 insert_step_resume_breakpoint (get_prev_frame (get_current_frame ()),
2358 if (step_over_calls == STEP_OVER_ALL)
2360 /* We're doing a "next", set a breakpoint at callee's return
2361 address (the address at which the caller will
2363 insert_step_resume_breakpoint (get_prev_frame (get_current_frame ()),
2369 /* If we are in a function call trampoline (a stub between the
2370 calling routine and the real function), locate the real
2371 function. That's what tells us (a) whether we want to step
2372 into it at all, and (b) what prologue we want to run to the
2373 end of, if we do step into it. */
2374 real_stop_pc = skip_language_trampoline (stop_pc);
2375 if (real_stop_pc == 0)
2376 real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc);
2377 if (real_stop_pc != 0)
2378 ecs->stop_func_start = real_stop_pc;
2380 if (IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs->stop_func_start))
2382 struct symtab_and_line sr_sal;
2384 sr_sal.pc = ecs->stop_func_start;
2386 check_for_old_step_resume_breakpoint ();
2387 step_resume_breakpoint =
2388 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2389 if (breakpoints_inserted)
2390 insert_breakpoints ();
2396 /* If we have line number information for the function we are
2397 thinking of stepping into, step into it.
2399 If there are several symtabs at that PC (e.g. with include
2400 files), just want to know whether *any* of them have line
2401 numbers. find_pc_line handles this. */
2403 struct symtab_and_line tmp_sal;
2405 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
2406 if (tmp_sal.line != 0)
2408 step_into_function (ecs);
2413 /* If we have no line number and the step-stop-if-no-debug is
2414 set, we stop the step so that the user has a chance to switch
2415 in assembly mode. */
2416 if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug)
2419 print_stop_reason (END_STEPPING_RANGE, 0);
2420 stop_stepping (ecs);
2424 /* Set a breakpoint at callee's return address (the address at
2425 which the caller will resume). */
2426 insert_step_resume_breakpoint (get_prev_frame (get_current_frame ()), ecs);
2431 /* If we're in the return path from a shared library trampoline,
2432 we want to proceed through the trampoline when stepping. */
2433 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2435 /* Determine where this trampoline returns. */
2436 CORE_ADDR real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc);
2438 /* Only proceed through if we know where it's going. */
2441 /* And put the step-breakpoint there and go until there. */
2442 struct symtab_and_line sr_sal;
2444 init_sal (&sr_sal); /* initialize to zeroes */
2445 sr_sal.pc = real_stop_pc;
2446 sr_sal.section = find_pc_overlay (sr_sal.pc);
2447 /* Do not specify what the fp should be when we stop
2448 since on some machines the prologue
2449 is where the new fp value is established. */
2450 check_for_old_step_resume_breakpoint ();
2451 step_resume_breakpoint =
2452 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2453 if (breakpoints_inserted)
2454 insert_breakpoints ();
2456 /* Restart without fiddling with the step ranges or
2463 /* NOTE: tausq/2004-05-24: This if block used to be done before all
2464 the trampoline processing logic, however, there are some trampolines
2465 that have no names, so we should do trampoline handling first. */
2466 if (step_over_calls == STEP_OVER_UNDEBUGGABLE
2467 && ecs->stop_func_name == NULL)
2469 /* The inferior just stepped into, or returned to, an
2470 undebuggable function (where there is no symbol, not even a
2471 minimal symbol, corresponding to the address where the
2472 inferior stopped). Since we want to skip this kind of code,
2473 we keep going until the inferior returns from this
2475 if (step_stop_if_no_debug)
2477 /* If we have no line number and the step-stop-if-no-debug
2478 is set, we stop the step so that the user has a chance to
2479 switch in assembly mode. */
2481 print_stop_reason (END_STEPPING_RANGE, 0);
2482 stop_stepping (ecs);
2487 /* Set a breakpoint at callee's return address (the address
2488 at which the caller will resume). */
2489 insert_step_resume_breakpoint (get_prev_frame (get_current_frame ()),
2496 if (step_range_end == 1)
2498 /* It is stepi or nexti. We always want to stop stepping after
2501 print_stop_reason (END_STEPPING_RANGE, 0);
2502 stop_stepping (ecs);
2506 ecs->sal = find_pc_line (stop_pc, 0);
2508 if (ecs->sal.line == 0)
2510 /* We have no line number information. That means to stop
2511 stepping (does this always happen right after one instruction,
2512 when we do "s" in a function with no line numbers,
2513 or can this happen as a result of a return or longjmp?). */
2515 print_stop_reason (END_STEPPING_RANGE, 0);
2516 stop_stepping (ecs);
2520 if ((stop_pc == ecs->sal.pc)
2521 && (ecs->current_line != ecs->sal.line
2522 || ecs->current_symtab != ecs->sal.symtab))
2524 /* We are at the start of a different line. So stop. Note that
2525 we don't stop if we step into the middle of a different line.
2526 That is said to make things like for (;;) statements work
2529 print_stop_reason (END_STEPPING_RANGE, 0);
2530 stop_stepping (ecs);
2534 /* We aren't done stepping.
2536 Optimize by setting the stepping range to the line.
2537 (We might not be in the original line, but if we entered a
2538 new line in mid-statement, we continue stepping. This makes
2539 things like for(;;) statements work better.) */
2541 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
2543 /* If this is the last line of the function, don't keep stepping
2544 (it would probably step us out of the function).
2545 This is particularly necessary for a one-line function,
2546 in which after skipping the prologue we better stop even though
2547 we will be in mid-line. */
2549 print_stop_reason (END_STEPPING_RANGE, 0);
2550 stop_stepping (ecs);
2553 step_range_start = ecs->sal.pc;
2554 step_range_end = ecs->sal.end;
2555 step_frame_id = get_frame_id (get_current_frame ());
2556 ecs->current_line = ecs->sal.line;
2557 ecs->current_symtab = ecs->sal.symtab;
2559 /* In the case where we just stepped out of a function into the
2560 middle of a line of the caller, continue stepping, but
2561 step_frame_id must be modified to current frame */
2563 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too
2564 generous. It will trigger on things like a step into a frameless
2565 stackless leaf function. I think the logic should instead look
2566 at the unwound frame ID has that should give a more robust
2567 indication of what happened. */
2568 if (step-ID == current-ID)
2569 still stepping in same function;
2570 else if (step-ID == unwind (current-ID))
2571 stepped into a function;
2573 stepped out of a function;
2574 /* Of course this assumes that the frame ID unwind code is robust
2575 and we're willing to introduce frame unwind logic into this
2576 function. Fortunately, those days are nearly upon us. */
2579 struct frame_id current_frame = get_frame_id (get_current_frame ());
2580 if (!(frame_id_inner (current_frame, step_frame_id)))
2581 step_frame_id = current_frame;
2587 /* Are we in the middle of stepping? */
2590 currently_stepping (struct execution_control_state *ecs)
2592 return ((!ecs->handling_longjmp
2593 && ((step_range_end && step_resume_breakpoint == NULL)
2595 || ecs->stepping_through_solib_after_catch
2596 || bpstat_should_step ());
2599 /* Subroutine call with source code we should not step over. Do step
2600 to the first line of code in it. */
2603 step_into_function (struct execution_control_state *ecs)
2606 struct symtab_and_line sr_sal;
2608 s = find_pc_symtab (stop_pc);
2609 if (s && s->language != language_asm)
2610 ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start);
2612 ecs->sal = find_pc_line (ecs->stop_func_start, 0);
2613 /* Use the step_resume_break to step until the end of the prologue,
2614 even if that involves jumps (as it seems to on the vax under
2616 /* If the prologue ends in the middle of a source line, continue to
2617 the end of that source line (if it is still within the function).
2618 Otherwise, just go to end of prologue. */
2620 && ecs->sal.pc != ecs->stop_func_start
2621 && ecs->sal.end < ecs->stop_func_end)
2622 ecs->stop_func_start = ecs->sal.end;
2624 /* Architectures which require breakpoint adjustment might not be able
2625 to place a breakpoint at the computed address. If so, the test
2626 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
2627 ecs->stop_func_start to an address at which a breakpoint may be
2628 legitimately placed.
2630 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
2631 made, GDB will enter an infinite loop when stepping through
2632 optimized code consisting of VLIW instructions which contain
2633 subinstructions corresponding to different source lines. On
2634 FR-V, it's not permitted to place a breakpoint on any but the
2635 first subinstruction of a VLIW instruction. When a breakpoint is
2636 set, GDB will adjust the breakpoint address to the beginning of
2637 the VLIW instruction. Thus, we need to make the corresponding
2638 adjustment here when computing the stop address. */
2640 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch))
2642 ecs->stop_func_start
2643 = gdbarch_adjust_breakpoint_address (current_gdbarch,
2644 ecs->stop_func_start);
2647 if (ecs->stop_func_start == stop_pc)
2649 /* We are already there: stop now. */
2651 print_stop_reason (END_STEPPING_RANGE, 0);
2652 stop_stepping (ecs);
2657 /* Put the step-breakpoint there and go until there. */
2658 init_sal (&sr_sal); /* initialize to zeroes */
2659 sr_sal.pc = ecs->stop_func_start;
2660 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
2661 /* Do not specify what the fp should be when we stop since on
2662 some machines the prologue is where the new fp value is
2664 check_for_old_step_resume_breakpoint ();
2665 step_resume_breakpoint =
2666 set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume);
2667 if (breakpoints_inserted)
2668 insert_breakpoints ();
2670 /* And make sure stepping stops right away then. */
2671 step_range_end = step_range_start;
2676 /* Insert a "step resume breakpoint" at RETURN_FRAME.pc. This is used
2677 to skip a function (next, skip-no-debug) or signal. It's assumed
2678 that the function/signal handler being skipped eventually returns
2679 to the breakpoint inserted at RETURN_FRAME.pc.
2681 For the skip-function case, the function may have been reached by
2682 either single stepping a call / return / signal-return instruction,
2683 or by hitting a breakpoint. In all cases, the RETURN_FRAME belongs
2684 to the skip-function's caller.
2686 For the signals case, this is called with the interrupted
2687 function's frame. The signal handler, when it returns, will resume
2688 the interrupted function at RETURN_FRAME.pc. */
2691 insert_step_resume_breakpoint (struct frame_info *return_frame,
2692 struct execution_control_state *ecs)
2694 struct symtab_and_line sr_sal;
2696 init_sal (&sr_sal); /* initialize to zeros */
2698 sr_sal.pc = ADDR_BITS_REMOVE (get_frame_pc (return_frame));
2699 sr_sal.section = find_pc_overlay (sr_sal.pc);
2701 check_for_old_step_resume_breakpoint ();
2703 step_resume_breakpoint
2704 = set_momentary_breakpoint (sr_sal, get_frame_id (return_frame),
2707 if (breakpoints_inserted)
2708 insert_breakpoints ();
2712 stop_stepping (struct execution_control_state *ecs)
2714 /* Let callers know we don't want to wait for the inferior anymore. */
2715 ecs->wait_some_more = 0;
2718 /* This function handles various cases where we need to continue
2719 waiting for the inferior. */
2720 /* (Used to be the keep_going: label in the old wait_for_inferior) */
2723 keep_going (struct execution_control_state *ecs)
2725 /* Save the pc before execution, to compare with pc after stop. */
2726 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
2728 /* If we did not do break;, it means we should keep running the
2729 inferior and not return to debugger. */
2731 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
2733 /* We took a signal (which we are supposed to pass through to
2734 the inferior, else we'd have done a break above) and we
2735 haven't yet gotten our trap. Simply continue. */
2736 resume (currently_stepping (ecs), stop_signal);
2740 /* Either the trap was not expected, but we are continuing
2741 anyway (the user asked that this signal be passed to the
2744 The signal was SIGTRAP, e.g. it was our signal, but we
2745 decided we should resume from it.
2747 We're going to run this baby now!
2749 Insert breakpoints now, unless we are trying to one-proceed
2750 past a breakpoint. */
2751 /* If we've just finished a special step resume and we don't
2752 want to hit a breakpoint, pull em out. */
2753 if (step_resume_breakpoint == NULL
2754 && ecs->remove_breakpoints_on_following_step)
2756 ecs->remove_breakpoints_on_following_step = 0;
2757 remove_breakpoints ();
2758 breakpoints_inserted = 0;
2760 else if (!breakpoints_inserted && !ecs->another_trap)
2762 breakpoints_failed = insert_breakpoints ();
2763 if (breakpoints_failed)
2765 stop_stepping (ecs);
2768 breakpoints_inserted = 1;
2771 trap_expected = ecs->another_trap;
2773 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
2774 specifies that such a signal should be delivered to the
2777 Typically, this would occure when a user is debugging a
2778 target monitor on a simulator: the target monitor sets a
2779 breakpoint; the simulator encounters this break-point and
2780 halts the simulation handing control to GDB; GDB, noteing
2781 that the break-point isn't valid, returns control back to the
2782 simulator; the simulator then delivers the hardware
2783 equivalent of a SIGNAL_TRAP to the program being debugged. */
2785 if (stop_signal == TARGET_SIGNAL_TRAP && !signal_program[stop_signal])
2786 stop_signal = TARGET_SIGNAL_0;
2789 resume (currently_stepping (ecs), stop_signal);
2792 prepare_to_wait (ecs);
2795 /* This function normally comes after a resume, before
2796 handle_inferior_event exits. It takes care of any last bits of
2797 housekeeping, and sets the all-important wait_some_more flag. */
2800 prepare_to_wait (struct execution_control_state *ecs)
2802 if (ecs->infwait_state == infwait_normal_state)
2804 overlay_cache_invalid = 1;
2806 /* We have to invalidate the registers BEFORE calling
2807 target_wait because they can be loaded from the target while
2808 in target_wait. This makes remote debugging a bit more
2809 efficient for those targets that provide critical registers
2810 as part of their normal status mechanism. */
2812 registers_changed ();
2813 ecs->waiton_ptid = pid_to_ptid (-1);
2814 ecs->wp = &(ecs->ws);
2816 /* This is the old end of the while loop. Let everybody know we
2817 want to wait for the inferior some more and get called again
2819 ecs->wait_some_more = 1;
2822 /* Print why the inferior has stopped. We always print something when
2823 the inferior exits, or receives a signal. The rest of the cases are
2824 dealt with later on in normal_stop() and print_it_typical(). Ideally
2825 there should be a call to this function from handle_inferior_event()
2826 each time stop_stepping() is called.*/
2828 print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
2830 switch (stop_reason)
2833 /* We don't deal with these cases from handle_inferior_event()
2836 case END_STEPPING_RANGE:
2837 /* We are done with a step/next/si/ni command. */
2838 /* For now print nothing. */
2839 /* Print a message only if not in the middle of doing a "step n"
2840 operation for n > 1 */
2841 if (!step_multi || !stop_step)
2842 if (ui_out_is_mi_like_p (uiout))
2843 ui_out_field_string (uiout, "reason", "end-stepping-range");
2845 case BREAKPOINT_HIT:
2846 /* We found a breakpoint. */
2847 /* For now print nothing. */
2850 /* The inferior was terminated by a signal. */
2851 annotate_signalled ();
2852 if (ui_out_is_mi_like_p (uiout))
2853 ui_out_field_string (uiout, "reason", "exited-signalled");
2854 ui_out_text (uiout, "\nProgram terminated with signal ");
2855 annotate_signal_name ();
2856 ui_out_field_string (uiout, "signal-name",
2857 target_signal_to_name (stop_info));
2858 annotate_signal_name_end ();
2859 ui_out_text (uiout, ", ");
2860 annotate_signal_string ();
2861 ui_out_field_string (uiout, "signal-meaning",
2862 target_signal_to_string (stop_info));
2863 annotate_signal_string_end ();
2864 ui_out_text (uiout, ".\n");
2865 ui_out_text (uiout, "The program no longer exists.\n");
2868 /* The inferior program is finished. */
2869 annotate_exited (stop_info);
2872 if (ui_out_is_mi_like_p (uiout))
2873 ui_out_field_string (uiout, "reason", "exited");
2874 ui_out_text (uiout, "\nProgram exited with code ");
2875 ui_out_field_fmt (uiout, "exit-code", "0%o",
2876 (unsigned int) stop_info);
2877 ui_out_text (uiout, ".\n");
2881 if (ui_out_is_mi_like_p (uiout))
2882 ui_out_field_string (uiout, "reason", "exited-normally");
2883 ui_out_text (uiout, "\nProgram exited normally.\n");
2886 case SIGNAL_RECEIVED:
2887 /* Signal received. The signal table tells us to print about
2890 ui_out_text (uiout, "\nProgram received signal ");
2891 annotate_signal_name ();
2892 if (ui_out_is_mi_like_p (uiout))
2893 ui_out_field_string (uiout, "reason", "signal-received");
2894 ui_out_field_string (uiout, "signal-name",
2895 target_signal_to_name (stop_info));
2896 annotate_signal_name_end ();
2897 ui_out_text (uiout, ", ");
2898 annotate_signal_string ();
2899 ui_out_field_string (uiout, "signal-meaning",
2900 target_signal_to_string (stop_info));
2901 annotate_signal_string_end ();
2902 ui_out_text (uiout, ".\n");
2905 internal_error (__FILE__, __LINE__,
2906 "print_stop_reason: unrecognized enum value");
2912 /* Here to return control to GDB when the inferior stops for real.
2913 Print appropriate messages, remove breakpoints, give terminal our modes.
2915 STOP_PRINT_FRAME nonzero means print the executing frame
2916 (pc, function, args, file, line number and line text).
2917 BREAKPOINTS_FAILED nonzero means stop was due to error
2918 attempting to insert breakpoints. */
2923 struct target_waitstatus last;
2926 get_last_target_status (&last_ptid, &last);
2928 /* As with the notification of thread events, we want to delay
2929 notifying the user that we've switched thread context until
2930 the inferior actually stops.
2932 There's no point in saying anything if the inferior has exited.
2933 Note that SIGNALLED here means "exited with a signal", not
2934 "received a signal". */
2935 if (!ptid_equal (previous_inferior_ptid, inferior_ptid)
2936 && target_has_execution
2937 && last.kind != TARGET_WAITKIND_SIGNALLED
2938 && last.kind != TARGET_WAITKIND_EXITED)
2940 target_terminal_ours_for_output ();
2941 printf_filtered ("[Switching to %s]\n",
2942 target_pid_or_tid_to_str (inferior_ptid));
2943 previous_inferior_ptid = inferior_ptid;
2946 /* NOTE drow/2004-01-17: Is this still necessary? */
2947 /* Make sure that the current_frame's pc is correct. This
2948 is a correction for setting up the frame info before doing
2949 DECR_PC_AFTER_BREAK */
2950 if (target_has_execution)
2951 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
2952 DECR_PC_AFTER_BREAK, the program counter can change. Ask the
2953 frame code to check for this and sort out any resultant mess.
2954 DECR_PC_AFTER_BREAK needs to just go away. */
2955 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
2957 if (target_has_execution && breakpoints_inserted)
2959 if (remove_breakpoints ())
2961 target_terminal_ours_for_output ();
2962 printf_filtered ("Cannot remove breakpoints because ");
2963 printf_filtered ("program is no longer writable.\n");
2964 printf_filtered ("It might be running in another process.\n");
2965 printf_filtered ("Further execution is probably impossible.\n");
2968 breakpoints_inserted = 0;
2970 /* Delete the breakpoint we stopped at, if it wants to be deleted.
2971 Delete any breakpoint that is to be deleted at the next stop. */
2973 breakpoint_auto_delete (stop_bpstat);
2975 /* If an auto-display called a function and that got a signal,
2976 delete that auto-display to avoid an infinite recursion. */
2978 if (stopped_by_random_signal)
2979 disable_current_display ();
2981 /* Don't print a message if in the middle of doing a "step n"
2982 operation for n > 1 */
2983 if (step_multi && stop_step)
2986 target_terminal_ours ();
2988 /* Look up the hook_stop and run it (CLI internally handles problem
2989 of stop_command's pre-hook not existing). */
2991 catch_errors (hook_stop_stub, stop_command,
2992 "Error while running hook_stop:\n", RETURN_MASK_ALL);
2994 if (!target_has_stack)
3000 /* Select innermost stack frame - i.e., current frame is frame 0,
3001 and current location is based on that.
3002 Don't do this on return from a stack dummy routine,
3003 or if the program has exited. */
3005 if (!stop_stack_dummy)
3007 select_frame (get_current_frame ());
3009 /* Print current location without a level number, if
3010 we have changed functions or hit a breakpoint.
3011 Print source line if we have one.
3012 bpstat_print() contains the logic deciding in detail
3013 what to print, based on the event(s) that just occurred. */
3015 if (stop_print_frame && deprecated_selected_frame)
3019 int do_frame_printing = 1;
3021 bpstat_ret = bpstat_print (stop_bpstat);
3025 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3026 (or should) carry around the function and does (or
3027 should) use that when doing a frame comparison. */
3029 && frame_id_eq (step_frame_id,
3030 get_frame_id (get_current_frame ()))
3031 && step_start_function == find_pc_function (stop_pc))
3032 source_flag = SRC_LINE; /* finished step, just print source line */
3034 source_flag = SRC_AND_LOC; /* print location and source line */
3036 case PRINT_SRC_AND_LOC:
3037 source_flag = SRC_AND_LOC; /* print location and source line */
3039 case PRINT_SRC_ONLY:
3040 source_flag = SRC_LINE;
3043 source_flag = SRC_LINE; /* something bogus */
3044 do_frame_printing = 0;
3047 internal_error (__FILE__, __LINE__, "Unknown value.");
3049 /* For mi, have the same behavior every time we stop:
3050 print everything but the source line. */
3051 if (ui_out_is_mi_like_p (uiout))
3052 source_flag = LOC_AND_ADDRESS;
3054 if (ui_out_is_mi_like_p (uiout))
3055 ui_out_field_int (uiout, "thread-id",
3056 pid_to_thread_id (inferior_ptid));
3057 /* The behavior of this routine with respect to the source
3059 SRC_LINE: Print only source line
3060 LOCATION: Print only location
3061 SRC_AND_LOC: Print location and source line */
3062 if (do_frame_printing)
3063 print_stack_frame (get_selected_frame (), 0, source_flag);
3065 /* Display the auto-display expressions. */
3070 /* Save the function value return registers, if we care.
3071 We might be about to restore their previous contents. */
3072 if (proceed_to_finish)
3073 /* NB: The copy goes through to the target picking up the value of
3074 all the registers. */
3075 regcache_cpy (stop_registers, current_regcache);
3077 if (stop_stack_dummy)
3079 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3080 ends with a setting of the current frame, so we can use that
3082 frame_pop (get_current_frame ());
3083 /* Set stop_pc to what it was before we called the function.
3084 Can't rely on restore_inferior_status because that only gets
3085 called if we don't stop in the called function. */
3086 stop_pc = read_pc ();
3087 select_frame (get_current_frame ());
3091 annotate_stopped ();
3092 observer_notify_normal_stop (stop_bpstat);
3096 hook_stop_stub (void *cmd)
3098 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
3103 signal_stop_state (int signo)
3105 return signal_stop[signo];
3109 signal_print_state (int signo)
3111 return signal_print[signo];
3115 signal_pass_state (int signo)
3117 return signal_program[signo];
3121 signal_stop_update (int signo, int state)
3123 int ret = signal_stop[signo];
3124 signal_stop[signo] = state;
3129 signal_print_update (int signo, int state)
3131 int ret = signal_print[signo];
3132 signal_print[signo] = state;
3137 signal_pass_update (int signo, int state)
3139 int ret = signal_program[signo];
3140 signal_program[signo] = state;
3145 sig_print_header (void)
3148 Signal Stop\tPrint\tPass to program\tDescription\n");
3152 sig_print_info (enum target_signal oursig)
3154 char *name = target_signal_to_name (oursig);
3155 int name_padding = 13 - strlen (name);
3157 if (name_padding <= 0)
3160 printf_filtered ("%s", name);
3161 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
3162 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3163 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3164 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3165 printf_filtered ("%s\n", target_signal_to_string (oursig));
3168 /* Specify how various signals in the inferior should be handled. */
3171 handle_command (char *args, int from_tty)
3174 int digits, wordlen;
3175 int sigfirst, signum, siglast;
3176 enum target_signal oursig;
3179 unsigned char *sigs;
3180 struct cleanup *old_chain;
3184 error_no_arg ("signal to handle");
3187 /* Allocate and zero an array of flags for which signals to handle. */
3189 nsigs = (int) TARGET_SIGNAL_LAST;
3190 sigs = (unsigned char *) alloca (nsigs);
3191 memset (sigs, 0, nsigs);
3193 /* Break the command line up into args. */
3195 argv = buildargv (args);
3200 old_chain = make_cleanup_freeargv (argv);
3202 /* Walk through the args, looking for signal oursigs, signal names, and
3203 actions. Signal numbers and signal names may be interspersed with
3204 actions, with the actions being performed for all signals cumulatively
3205 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3207 while (*argv != NULL)
3209 wordlen = strlen (*argv);
3210 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3214 sigfirst = siglast = -1;
3216 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3218 /* Apply action to all signals except those used by the
3219 debugger. Silently skip those. */
3222 siglast = nsigs - 1;
3224 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3226 SET_SIGS (nsigs, sigs, signal_stop);
3227 SET_SIGS (nsigs, sigs, signal_print);
3229 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3231 UNSET_SIGS (nsigs, sigs, signal_program);
3233 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3235 SET_SIGS (nsigs, sigs, signal_print);
3237 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3239 SET_SIGS (nsigs, sigs, signal_program);
3241 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3243 UNSET_SIGS (nsigs, sigs, signal_stop);
3245 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3247 SET_SIGS (nsigs, sigs, signal_program);
3249 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3251 UNSET_SIGS (nsigs, sigs, signal_print);
3252 UNSET_SIGS (nsigs, sigs, signal_stop);
3254 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3256 UNSET_SIGS (nsigs, sigs, signal_program);
3258 else if (digits > 0)
3260 /* It is numeric. The numeric signal refers to our own
3261 internal signal numbering from target.h, not to host/target
3262 signal number. This is a feature; users really should be
3263 using symbolic names anyway, and the common ones like
3264 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3266 sigfirst = siglast = (int)
3267 target_signal_from_command (atoi (*argv));
3268 if ((*argv)[digits] == '-')
3271 target_signal_from_command (atoi ((*argv) + digits + 1));
3273 if (sigfirst > siglast)
3275 /* Bet he didn't figure we'd think of this case... */
3283 oursig = target_signal_from_name (*argv);
3284 if (oursig != TARGET_SIGNAL_UNKNOWN)
3286 sigfirst = siglast = (int) oursig;
3290 /* Not a number and not a recognized flag word => complain. */
3291 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3295 /* If any signal numbers or symbol names were found, set flags for
3296 which signals to apply actions to. */
3298 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3300 switch ((enum target_signal) signum)
3302 case TARGET_SIGNAL_TRAP:
3303 case TARGET_SIGNAL_INT:
3304 if (!allsigs && !sigs[signum])
3306 if (query ("%s is used by the debugger.\n\
3307 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum)))
3313 printf_unfiltered ("Not confirmed, unchanged.\n");
3314 gdb_flush (gdb_stdout);
3318 case TARGET_SIGNAL_0:
3319 case TARGET_SIGNAL_DEFAULT:
3320 case TARGET_SIGNAL_UNKNOWN:
3321 /* Make sure that "all" doesn't print these. */
3332 target_notice_signals (inferior_ptid);
3336 /* Show the results. */
3337 sig_print_header ();
3338 for (signum = 0; signum < nsigs; signum++)
3342 sig_print_info (signum);
3347 do_cleanups (old_chain);
3351 xdb_handle_command (char *args, int from_tty)
3354 struct cleanup *old_chain;
3356 /* Break the command line up into args. */
3358 argv = buildargv (args);
3363 old_chain = make_cleanup_freeargv (argv);
3364 if (argv[1] != (char *) NULL)
3369 bufLen = strlen (argv[0]) + 20;
3370 argBuf = (char *) xmalloc (bufLen);
3374 enum target_signal oursig;
3376 oursig = target_signal_from_name (argv[0]);
3377 memset (argBuf, 0, bufLen);
3378 if (strcmp (argv[1], "Q") == 0)
3379 sprintf (argBuf, "%s %s", argv[0], "noprint");
3382 if (strcmp (argv[1], "s") == 0)
3384 if (!signal_stop[oursig])
3385 sprintf (argBuf, "%s %s", argv[0], "stop");
3387 sprintf (argBuf, "%s %s", argv[0], "nostop");
3389 else if (strcmp (argv[1], "i") == 0)
3391 if (!signal_program[oursig])
3392 sprintf (argBuf, "%s %s", argv[0], "pass");
3394 sprintf (argBuf, "%s %s", argv[0], "nopass");
3396 else if (strcmp (argv[1], "r") == 0)
3398 if (!signal_print[oursig])
3399 sprintf (argBuf, "%s %s", argv[0], "print");
3401 sprintf (argBuf, "%s %s", argv[0], "noprint");
3407 handle_command (argBuf, from_tty);
3409 printf_filtered ("Invalid signal handling flag.\n");
3414 do_cleanups (old_chain);
3417 /* Print current contents of the tables set by the handle command.
3418 It is possible we should just be printing signals actually used
3419 by the current target (but for things to work right when switching
3420 targets, all signals should be in the signal tables). */
3423 signals_info (char *signum_exp, int from_tty)
3425 enum target_signal oursig;
3426 sig_print_header ();
3430 /* First see if this is a symbol name. */
3431 oursig = target_signal_from_name (signum_exp);
3432 if (oursig == TARGET_SIGNAL_UNKNOWN)
3434 /* No, try numeric. */
3436 target_signal_from_command (parse_and_eval_long (signum_exp));
3438 sig_print_info (oursig);
3442 printf_filtered ("\n");
3443 /* These ugly casts brought to you by the native VAX compiler. */
3444 for (oursig = TARGET_SIGNAL_FIRST;
3445 (int) oursig < (int) TARGET_SIGNAL_LAST;
3446 oursig = (enum target_signal) ((int) oursig + 1))
3450 if (oursig != TARGET_SIGNAL_UNKNOWN
3451 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
3452 sig_print_info (oursig);
3455 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3458 struct inferior_status
3460 enum target_signal stop_signal;
3464 int stop_stack_dummy;
3465 int stopped_by_random_signal;
3467 CORE_ADDR step_range_start;
3468 CORE_ADDR step_range_end;
3469 struct frame_id step_frame_id;
3470 enum step_over_calls_kind step_over_calls;
3471 CORE_ADDR step_resume_break_address;
3472 int stop_after_trap;
3474 struct regcache *stop_registers;
3476 /* These are here because if call_function_by_hand has written some
3477 registers and then decides to call error(), we better not have changed
3479 struct regcache *registers;
3481 /* A frame unique identifier. */
3482 struct frame_id selected_frame_id;
3484 int breakpoint_proceeded;
3485 int restore_stack_info;
3486 int proceed_to_finish;
3490 write_inferior_status_register (struct inferior_status *inf_status, int regno,
3493 int size = DEPRECATED_REGISTER_RAW_SIZE (regno);
3494 void *buf = alloca (size);
3495 store_signed_integer (buf, size, val);
3496 regcache_raw_write (inf_status->registers, regno, buf);
3499 /* Save all of the information associated with the inferior<==>gdb
3500 connection. INF_STATUS is a pointer to a "struct inferior_status"
3501 (defined in inferior.h). */
3503 struct inferior_status *
3504 save_inferior_status (int restore_stack_info)
3506 struct inferior_status *inf_status = XMALLOC (struct inferior_status);
3508 inf_status->stop_signal = stop_signal;
3509 inf_status->stop_pc = stop_pc;
3510 inf_status->stop_step = stop_step;
3511 inf_status->stop_stack_dummy = stop_stack_dummy;
3512 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3513 inf_status->trap_expected = trap_expected;
3514 inf_status->step_range_start = step_range_start;
3515 inf_status->step_range_end = step_range_end;
3516 inf_status->step_frame_id = step_frame_id;
3517 inf_status->step_over_calls = step_over_calls;
3518 inf_status->stop_after_trap = stop_after_trap;
3519 inf_status->stop_soon = stop_soon;
3520 /* Save original bpstat chain here; replace it with copy of chain.
3521 If caller's caller is walking the chain, they'll be happier if we
3522 hand them back the original chain when restore_inferior_status is
3524 inf_status->stop_bpstat = stop_bpstat;
3525 stop_bpstat = bpstat_copy (stop_bpstat);
3526 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3527 inf_status->restore_stack_info = restore_stack_info;
3528 inf_status->proceed_to_finish = proceed_to_finish;
3530 inf_status->stop_registers = regcache_dup_no_passthrough (stop_registers);
3532 inf_status->registers = regcache_dup (current_regcache);
3534 inf_status->selected_frame_id = get_frame_id (deprecated_selected_frame);
3539 restore_selected_frame (void *args)
3541 struct frame_id *fid = (struct frame_id *) args;
3542 struct frame_info *frame;
3544 frame = frame_find_by_id (*fid);
3546 /* If inf_status->selected_frame_id is NULL, there was no previously
3550 warning ("Unable to restore previously selected frame.\n");
3554 select_frame (frame);
3560 restore_inferior_status (struct inferior_status *inf_status)
3562 stop_signal = inf_status->stop_signal;
3563 stop_pc = inf_status->stop_pc;
3564 stop_step = inf_status->stop_step;
3565 stop_stack_dummy = inf_status->stop_stack_dummy;
3566 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3567 trap_expected = inf_status->trap_expected;
3568 step_range_start = inf_status->step_range_start;
3569 step_range_end = inf_status->step_range_end;
3570 step_frame_id = inf_status->step_frame_id;
3571 step_over_calls = inf_status->step_over_calls;
3572 stop_after_trap = inf_status->stop_after_trap;
3573 stop_soon = inf_status->stop_soon;
3574 bpstat_clear (&stop_bpstat);
3575 stop_bpstat = inf_status->stop_bpstat;
3576 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3577 proceed_to_finish = inf_status->proceed_to_finish;
3579 /* FIXME: Is the restore of stop_registers always needed. */
3580 regcache_xfree (stop_registers);
3581 stop_registers = inf_status->stop_registers;
3583 /* The inferior can be gone if the user types "print exit(0)"
3584 (and perhaps other times). */
3585 if (target_has_execution)
3586 /* NB: The register write goes through to the target. */
3587 regcache_cpy (current_regcache, inf_status->registers);
3588 regcache_xfree (inf_status->registers);
3590 /* FIXME: If we are being called after stopping in a function which
3591 is called from gdb, we should not be trying to restore the
3592 selected frame; it just prints a spurious error message (The
3593 message is useful, however, in detecting bugs in gdb (like if gdb
3594 clobbers the stack)). In fact, should we be restoring the
3595 inferior status at all in that case? . */
3597 if (target_has_stack && inf_status->restore_stack_info)
3599 /* The point of catch_errors is that if the stack is clobbered,
3600 walking the stack might encounter a garbage pointer and
3601 error() trying to dereference it. */
3603 (restore_selected_frame, &inf_status->selected_frame_id,
3604 "Unable to restore previously selected frame:\n",
3605 RETURN_MASK_ERROR) == 0)
3606 /* Error in restoring the selected frame. Select the innermost
3608 select_frame (get_current_frame ());
3616 do_restore_inferior_status_cleanup (void *sts)
3618 restore_inferior_status (sts);
3622 make_cleanup_restore_inferior_status (struct inferior_status *inf_status)
3624 return make_cleanup (do_restore_inferior_status_cleanup, inf_status);
3628 discard_inferior_status (struct inferior_status *inf_status)
3630 /* See save_inferior_status for info on stop_bpstat. */
3631 bpstat_clear (&inf_status->stop_bpstat);
3632 regcache_xfree (inf_status->registers);
3633 regcache_xfree (inf_status->stop_registers);
3638 inferior_has_forked (int pid, int *child_pid)
3640 struct target_waitstatus last;
3643 get_last_target_status (&last_ptid, &last);
3645 if (last.kind != TARGET_WAITKIND_FORKED)
3648 if (ptid_get_pid (last_ptid) != pid)
3651 *child_pid = last.value.related_pid;
3656 inferior_has_vforked (int pid, int *child_pid)
3658 struct target_waitstatus last;
3661 get_last_target_status (&last_ptid, &last);
3663 if (last.kind != TARGET_WAITKIND_VFORKED)
3666 if (ptid_get_pid (last_ptid) != pid)
3669 *child_pid = last.value.related_pid;
3674 inferior_has_execd (int pid, char **execd_pathname)
3676 struct target_waitstatus last;
3679 get_last_target_status (&last_ptid, &last);
3681 if (last.kind != TARGET_WAITKIND_EXECD)
3684 if (ptid_get_pid (last_ptid) != pid)
3687 *execd_pathname = xstrdup (last.value.execd_pathname);
3691 /* Oft used ptids */
3693 ptid_t minus_one_ptid;
3695 /* Create a ptid given the necessary PID, LWP, and TID components. */
3698 ptid_build (int pid, long lwp, long tid)
3708 /* Create a ptid from just a pid. */
3711 pid_to_ptid (int pid)
3713 return ptid_build (pid, 0, 0);
3716 /* Fetch the pid (process id) component from a ptid. */
3719 ptid_get_pid (ptid_t ptid)
3724 /* Fetch the lwp (lightweight process) component from a ptid. */
3727 ptid_get_lwp (ptid_t ptid)
3732 /* Fetch the tid (thread id) component from a ptid. */
3735 ptid_get_tid (ptid_t ptid)
3740 /* ptid_equal() is used to test equality of two ptids. */
3743 ptid_equal (ptid_t ptid1, ptid_t ptid2)
3745 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
3746 && ptid1.tid == ptid2.tid);
3749 /* restore_inferior_ptid() will be used by the cleanup machinery
3750 to restore the inferior_ptid value saved in a call to
3751 save_inferior_ptid(). */
3754 restore_inferior_ptid (void *arg)
3756 ptid_t *saved_ptid_ptr = arg;
3757 inferior_ptid = *saved_ptid_ptr;
3761 /* Save the value of inferior_ptid so that it may be restored by a
3762 later call to do_cleanups(). Returns the struct cleanup pointer
3763 needed for later doing the cleanup. */
3766 save_inferior_ptid (void)
3768 ptid_t *saved_ptid_ptr;
3770 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
3771 *saved_ptid_ptr = inferior_ptid;
3772 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
3779 stop_registers = regcache_xmalloc (current_gdbarch);
3783 _initialize_infrun (void)
3787 struct cmd_list_element *c;
3789 DEPRECATED_REGISTER_GDBARCH_SWAP (stop_registers);
3790 deprecated_register_gdbarch_swap (NULL, 0, build_infrun);
3792 add_info ("signals", signals_info,
3793 "What debugger does when program gets various signals.\n\
3794 Specify a signal as argument to print info on that signal only.");
3795 add_info_alias ("handle", "signals", 0);
3797 add_com ("handle", class_run, handle_command,
3798 concat ("Specify how to handle a signal.\n\
3799 Args are signals and actions to apply to those signals.\n\
3800 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3801 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3802 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3803 The special arg \"all\" is recognized to mean all signals except those\n\
3804 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3805 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3806 Stop means reenter debugger if this signal happens (implies print).\n\
3807 Print means print a message if this signal happens.\n\
3808 Pass means let program see this signal; otherwise program doesn't know.\n\
3809 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3810 Pass and Stop may be combined.", NULL));
3813 add_com ("lz", class_info, signals_info,
3814 "What debugger does when program gets various signals.\n\
3815 Specify a signal as argument to print info on that signal only.");
3816 add_com ("z", class_run, xdb_handle_command,
3817 concat ("Specify how to handle a signal.\n\
3818 Args are signals and actions to apply to those signals.\n\
3819 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3820 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3821 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3822 The special arg \"all\" is recognized to mean all signals except those\n\
3823 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3824 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3825 nopass), \"Q\" (noprint)\n\
3826 Stop means reenter debugger if this signal happens (implies print).\n\
3827 Print means print a message if this signal happens.\n\
3828 Pass means let program see this signal; otherwise program doesn't know.\n\
3829 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3830 Pass and Stop may be combined.", NULL));
3835 add_cmd ("stop", class_obscure, not_just_help_class_command, "There is no `stop' command, but you can set a hook on `stop'.\n\
3836 This allows you to set a list of commands to be run each time execution\n\
3837 of the program stops.", &cmdlist);
3839 numsigs = (int) TARGET_SIGNAL_LAST;
3840 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
3841 signal_print = (unsigned char *)
3842 xmalloc (sizeof (signal_print[0]) * numsigs);
3843 signal_program = (unsigned char *)
3844 xmalloc (sizeof (signal_program[0]) * numsigs);
3845 for (i = 0; i < numsigs; i++)
3848 signal_print[i] = 1;
3849 signal_program[i] = 1;
3852 /* Signals caused by debugger's own actions
3853 should not be given to the program afterwards. */
3854 signal_program[TARGET_SIGNAL_TRAP] = 0;
3855 signal_program[TARGET_SIGNAL_INT] = 0;
3857 /* Signals that are not errors should not normally enter the debugger. */
3858 signal_stop[TARGET_SIGNAL_ALRM] = 0;
3859 signal_print[TARGET_SIGNAL_ALRM] = 0;
3860 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
3861 signal_print[TARGET_SIGNAL_VTALRM] = 0;
3862 signal_stop[TARGET_SIGNAL_PROF] = 0;
3863 signal_print[TARGET_SIGNAL_PROF] = 0;
3864 signal_stop[TARGET_SIGNAL_CHLD] = 0;
3865 signal_print[TARGET_SIGNAL_CHLD] = 0;
3866 signal_stop[TARGET_SIGNAL_IO] = 0;
3867 signal_print[TARGET_SIGNAL_IO] = 0;
3868 signal_stop[TARGET_SIGNAL_POLL] = 0;
3869 signal_print[TARGET_SIGNAL_POLL] = 0;
3870 signal_stop[TARGET_SIGNAL_URG] = 0;
3871 signal_print[TARGET_SIGNAL_URG] = 0;
3872 signal_stop[TARGET_SIGNAL_WINCH] = 0;
3873 signal_print[TARGET_SIGNAL_WINCH] = 0;
3875 /* These signals are used internally by user-level thread
3876 implementations. (See signal(5) on Solaris.) Like the above
3877 signals, a healthy program receives and handles them as part of
3878 its normal operation. */
3879 signal_stop[TARGET_SIGNAL_LWP] = 0;
3880 signal_print[TARGET_SIGNAL_LWP] = 0;
3881 signal_stop[TARGET_SIGNAL_WAITING] = 0;
3882 signal_print[TARGET_SIGNAL_WAITING] = 0;
3883 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
3884 signal_print[TARGET_SIGNAL_CANCEL] = 0;
3888 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
3889 (char *) &stop_on_solib_events,
3890 "Set stopping for shared library events.\n\
3891 If nonzero, gdb will give control to the user when the dynamic linker\n\
3892 notifies gdb of shared library events. The most common event of interest\n\
3893 to the user would be loading/unloading of a new library.\n", &setlist), &showlist);
3896 c = add_set_enum_cmd ("follow-fork-mode",
3898 follow_fork_mode_kind_names, &follow_fork_mode_string,
3899 "Set debugger response to a program call of fork \
3901 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3902 parent - the original process is debugged after a fork\n\
3903 child - the new process is debugged after a fork\n\
3904 The unfollowed process will continue to run.\n\
3905 By default, the debugger will follow the parent process.", &setlist);
3906 add_show_from_set (c, &showlist);
3908 c = add_set_enum_cmd ("scheduler-locking", class_run, scheduler_enums, /* array of string names */
3909 &scheduler_mode, /* current mode */
3910 "Set mode for locking scheduler during execution.\n\
3911 off == no locking (threads may preempt at any time)\n\
3912 on == full locking (no thread except the current thread may run)\n\
3913 step == scheduler locked during every single-step operation.\n\
3914 In this mode, no other thread may run during a step command.\n\
3915 Other threads may run while stepping over a function call ('next').", &setlist);
3917 set_cmd_sfunc (c, set_schedlock_func); /* traps on target vector */
3918 add_show_from_set (c, &showlist);
3920 c = add_set_cmd ("step-mode", class_run,
3921 var_boolean, (char *) &step_stop_if_no_debug,
3922 "Set mode of the step operation. When set, doing a step over a\n\
3923 function without debug line information will stop at the first\n\
3924 instruction of that function. Otherwise, the function is skipped and\n\
3925 the step command stops at a different source line.", &setlist);
3926 add_show_from_set (c, &showlist);
3928 /* ptid initializations */
3929 null_ptid = ptid_build (0, 0, 0);
3930 minus_one_ptid = ptid_build (-1, 0, 0);
3931 inferior_ptid = null_ptid;
3932 target_last_wait_ptid = minus_one_ptid;