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 Free Software
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
26 #include "gdb_string.h"
31 #include "breakpoint.h"
35 #include "cli/cli-script.h"
37 #include "gdbthread.h"
46 /* Prototypes for local functions */
48 static void signals_info (char *, int);
50 static void handle_command (char *, int);
52 static void sig_print_info (enum target_signal
);
54 static void sig_print_header (void);
56 static void resume_cleanups (void *);
58 static int hook_stop_stub (void *);
60 static void delete_breakpoint_current_contents (void *);
62 static void set_follow_fork_mode_command (char *arg
, int from_tty
,
63 struct cmd_list_element
* c
);
65 static struct inferior_status
*xmalloc_inferior_status (void);
67 static void free_inferior_status (struct inferior_status
*);
69 static int restore_selected_frame (void *);
71 static void build_infrun (void);
73 static void follow_inferior_fork (int parent_pid
, int child_pid
,
74 int has_forked
, int has_vforked
);
76 static void follow_fork (int parent_pid
, int child_pid
);
78 static void follow_vfork (int parent_pid
, int child_pid
);
80 static void set_schedlock_func (char *args
, int from_tty
,
81 struct cmd_list_element
* c
);
83 struct execution_control_state
;
85 static int currently_stepping (struct execution_control_state
*ecs
);
87 static void xdb_handle_command (char *args
, int from_tty
);
89 void _initialize_infrun (void);
91 int inferior_ignoring_startup_exec_events
= 0;
92 int inferior_ignoring_leading_exec_events
= 0;
94 /* When set, stop the 'step' command if we enter a function which has
95 no line number information. The normal behavior is that we step
96 over such function. */
97 int step_stop_if_no_debug
= 0;
99 /* In asynchronous mode, but simulating synchronous execution. */
101 int sync_execution
= 0;
103 /* wait_for_inferior and normal_stop use this to notify the user
104 when the inferior stopped in a different thread than it had been
107 static ptid_t previous_inferior_ptid
;
109 /* This is true for configurations that may follow through execl() and
110 similar functions. At present this is only true for HP-UX native. */
112 #ifndef MAY_FOLLOW_EXEC
113 #define MAY_FOLLOW_EXEC (0)
116 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
118 /* Dynamic function trampolines are similar to solib trampolines in that they
119 are between the caller and the callee. The difference is that when you
120 enter a dynamic trampoline, you can't determine the callee's address. Some
121 (usually complex) code needs to run in the dynamic trampoline to figure out
122 the callee's address. This macro is usually called twice. First, when we
123 enter the trampoline (looks like a normal function call at that point). It
124 should return the PC of a point within the trampoline where the callee's
125 address is known. Second, when we hit the breakpoint, this routine returns
126 the callee's address. At that point, things proceed as per a step resume
129 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
130 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
133 /* If the program uses ELF-style shared libraries, then calls to
134 functions in shared libraries go through stubs, which live in a
135 table called the PLT (Procedure Linkage Table). The first time the
136 function is called, the stub sends control to the dynamic linker,
137 which looks up the function's real address, patches the stub so
138 that future calls will go directly to the function, and then passes
139 control to the function.
141 If we are stepping at the source level, we don't want to see any of
142 this --- we just want to skip over the stub and the dynamic linker.
143 The simple approach is to single-step until control leaves the
146 However, on some systems (e.g., Red Hat's 5.2 distribution) the
147 dynamic linker calls functions in the shared C library, so you
148 can't tell from the PC alone whether the dynamic linker is still
149 running. In this case, we use a step-resume breakpoint to get us
150 past the dynamic linker, as if we were using "next" to step over a
153 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
154 linker code or not. Normally, this means we single-step. However,
155 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
156 address where we can place a step-resume breakpoint to get past the
157 linker's symbol resolution function.
159 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
160 pretty portable way, by comparing the PC against the address ranges
161 of the dynamic linker's sections.
163 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
164 it depends on internal details of the dynamic linker. It's usually
165 not too hard to figure out where to put a breakpoint, but it
166 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
167 sanity checking. If it can't figure things out, returning zero and
168 getting the (possibly confusing) stepping behavior is better than
169 signalling an error, which will obscure the change in the
172 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
173 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
176 #ifndef SKIP_SOLIB_RESOLVER
177 #define SKIP_SOLIB_RESOLVER(pc) 0
180 /* In some shared library schemes, the return path from a shared library
181 call may need to go through a trampoline too. */
183 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
184 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
187 /* This function returns TRUE if pc is the address of an instruction
188 that lies within the dynamic linker (such as the event hook, or the
191 This function must be used only when a dynamic linker event has
192 been caught, and the inferior is being stepped out of the hook, or
193 undefined results are guaranteed. */
195 #ifndef SOLIB_IN_DYNAMIC_LINKER
196 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
199 /* On MIPS16, a function that returns a floating point value may call
200 a library helper function to copy the return value to a floating point
201 register. The IGNORE_HELPER_CALL macro returns non-zero if we
202 should ignore (i.e. step over) this function call. */
203 #ifndef IGNORE_HELPER_CALL
204 #define IGNORE_HELPER_CALL(pc) 0
207 /* On some systems, the PC may be left pointing at an instruction that won't
208 actually be executed. This is usually indicated by a bit in the PSW. If
209 we find ourselves in such a state, then we step the target beyond the
210 nullified instruction before returning control to the user so as to avoid
213 #ifndef INSTRUCTION_NULLIFIED
214 #define INSTRUCTION_NULLIFIED 0
217 /* We can't step off a permanent breakpoint in the ordinary way, because we
218 can't remove it. Instead, we have to advance the PC to the next
219 instruction. This macro should expand to a pointer to a function that
220 does that, or zero if we have no such function. If we don't have a
221 definition for it, we have to report an error. */
222 #ifndef SKIP_PERMANENT_BREAKPOINT
223 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
225 default_skip_permanent_breakpoint (void)
228 The program is stopped at a permanent breakpoint, but GDB does not know\n\
229 how to step past a permanent breakpoint on this architecture. Try using\n\
230 a command like `return' or `jump' to continue execution.");
235 /* Convert the #defines into values. This is temporary until wfi control
236 flow is completely sorted out. */
238 #ifndef HAVE_STEPPABLE_WATCHPOINT
239 #define HAVE_STEPPABLE_WATCHPOINT 0
241 #undef HAVE_STEPPABLE_WATCHPOINT
242 #define HAVE_STEPPABLE_WATCHPOINT 1
245 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
246 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
248 #undef HAVE_NONSTEPPABLE_WATCHPOINT
249 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
252 #ifndef HAVE_CONTINUABLE_WATCHPOINT
253 #define HAVE_CONTINUABLE_WATCHPOINT 0
255 #undef HAVE_CONTINUABLE_WATCHPOINT
256 #define HAVE_CONTINUABLE_WATCHPOINT 1
259 #ifndef CANNOT_STEP_HW_WATCHPOINTS
260 #define CANNOT_STEP_HW_WATCHPOINTS 0
262 #undef CANNOT_STEP_HW_WATCHPOINTS
263 #define CANNOT_STEP_HW_WATCHPOINTS 1
266 /* Tables of how to react to signals; the user sets them. */
268 static unsigned char *signal_stop
;
269 static unsigned char *signal_print
;
270 static unsigned char *signal_program
;
272 #define SET_SIGS(nsigs,sigs,flags) \
274 int signum = (nsigs); \
275 while (signum-- > 0) \
276 if ((sigs)[signum]) \
277 (flags)[signum] = 1; \
280 #define UNSET_SIGS(nsigs,sigs,flags) \
282 int signum = (nsigs); \
283 while (signum-- > 0) \
284 if ((sigs)[signum]) \
285 (flags)[signum] = 0; \
288 /* Value to pass to target_resume() to cause all threads to resume */
290 #define RESUME_ALL (pid_to_ptid (-1))
292 /* Command list pointer for the "stop" placeholder. */
294 static struct cmd_list_element
*stop_command
;
296 /* Nonzero if breakpoints are now inserted in the inferior. */
298 static int breakpoints_inserted
;
300 /* Function inferior was in as of last step command. */
302 static struct symbol
*step_start_function
;
304 /* Nonzero if we are expecting a trace trap and should proceed from it. */
306 static int trap_expected
;
309 /* Nonzero if we want to give control to the user when we're notified
310 of shared library events by the dynamic linker. */
311 static int stop_on_solib_events
;
315 /* Nonzero if the next time we try to continue the inferior, it will
316 step one instruction and generate a spurious trace trap.
317 This is used to compensate for a bug in HP-UX. */
319 static int trap_expected_after_continue
;
322 /* Nonzero means expecting a trace trap
323 and should stop the inferior and return silently when it happens. */
327 /* Nonzero means expecting a trap and caller will handle it themselves.
328 It is used after attach, due to attaching to a process;
329 when running in the shell before the child program has been exec'd;
330 and when running some kinds of remote stuff (FIXME?). */
332 int stop_soon_quietly
;
334 /* Nonzero if proceed is being used for a "finish" command or a similar
335 situation when stop_registers should be saved. */
337 int proceed_to_finish
;
339 /* Save register contents here when about to pop a stack dummy frame,
340 if-and-only-if proceed_to_finish is set.
341 Thus this contains the return value from the called function (assuming
342 values are returned in a register). */
344 char *stop_registers
;
346 /* Nonzero if program stopped due to error trying to insert breakpoints. */
348 static int breakpoints_failed
;
350 /* Nonzero after stop if current stack frame should be printed. */
352 static int stop_print_frame
;
354 static struct breakpoint
*step_resume_breakpoint
= NULL
;
355 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
357 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
358 interactions with an inferior that is running a kernel function
359 (aka, a system call or "syscall"). wait_for_inferior therefore
360 may have a need to know when the inferior is in a syscall. This
361 is a count of the number of inferior threads which are known to
362 currently be running in a syscall. */
363 static int number_of_threads_in_syscalls
;
365 /* This is a cached copy of the pid/waitstatus of the last event
366 returned by target_wait()/target_wait_hook(). This information is
367 returned by get_last_target_status(). */
368 static ptid_t target_last_wait_ptid
;
369 static struct target_waitstatus target_last_waitstatus
;
371 /* This is used to remember when a fork, vfork or exec event
372 was caught by a catchpoint, and thus the event is to be
373 followed at the next resume of the inferior, and not
377 enum target_waitkind kind
;
387 char *execd_pathname
;
391 /* Some platforms don't allow us to do anything meaningful with a
392 vforked child until it has exec'd. Vforked processes on such
393 platforms can only be followed after they've exec'd.
395 When this is set to 0, a vfork can be immediately followed,
396 and an exec can be followed merely as an exec. When this is
397 set to 1, a vfork event has been seen, but cannot be followed
398 until the exec is seen.
400 (In the latter case, inferior_ptid is still the parent of the
401 vfork, and pending_follow.fork_event.child_pid is the child. The
402 appropriate process is followed, according to the setting of
403 follow-fork-mode.) */
404 static int follow_vfork_when_exec
;
406 static const char follow_fork_mode_ask
[] = "ask";
407 static const char follow_fork_mode_both
[] = "both";
408 static const char follow_fork_mode_child
[] = "child";
409 static const char follow_fork_mode_parent
[] = "parent";
411 static const char *follow_fork_mode_kind_names
[] =
413 follow_fork_mode_ask
,
414 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
415 kernel problem. It's also not terribly useful without a GUI to
416 help the user drive two debuggers. So for now, I'm disabling the
418 /* follow_fork_mode_both, */
419 follow_fork_mode_child
,
420 follow_fork_mode_parent
,
424 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
428 follow_inferior_fork (int parent_pid
, int child_pid
, int has_forked
,
431 int followed_parent
= 0;
432 int followed_child
= 0;
434 /* Which process did the user want us to follow? */
435 const char *follow_mode
= follow_fork_mode_string
;
437 /* Or, did the user not know, and want us to ask? */
438 if (follow_fork_mode_string
== follow_fork_mode_ask
)
440 internal_error (__FILE__
, __LINE__
,
441 "follow_inferior_fork: \"ask\" mode not implemented");
442 /* follow_mode = follow_fork_mode_...; */
445 /* If we're to be following the parent, then detach from child_pid.
446 We're already following the parent, so need do nothing explicit
448 if (follow_mode
== follow_fork_mode_parent
)
452 /* We're already attached to the parent, by default. */
454 /* Before detaching from the child, remove all breakpoints from
455 it. (This won't actually modify the breakpoint list, but will
456 physically remove the breakpoints from the child.) */
457 if (!has_vforked
|| !follow_vfork_when_exec
)
459 detach_breakpoints (child_pid
);
460 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
461 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
465 /* Detach from the child. */
468 target_require_detach (child_pid
, "", 1);
471 /* If we're to be following the child, then attach to it, detach
472 from inferior_ptid, and set inferior_ptid to child_pid. */
473 else if (follow_mode
== follow_fork_mode_child
)
475 char child_pid_spelling
[100]; /* Arbitrary length. */
479 /* Before detaching from the parent, detach all breakpoints from
480 the child. But only if we're forking, or if we follow vforks
481 as soon as they happen. (If we're following vforks only when
482 the child has exec'd, then it's very wrong to try to write
483 back the "shadow contents" of inserted breakpoints now -- they
484 belong to the child's pre-exec'd a.out.) */
485 if (!has_vforked
|| !follow_vfork_when_exec
)
487 detach_breakpoints (child_pid
);
490 /* Before detaching from the parent, remove all breakpoints from it. */
491 remove_breakpoints ();
493 /* Also reset the solib inferior hook from the parent. */
494 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
495 SOLIB_REMOVE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
498 /* Detach from the parent. */
500 target_detach (NULL
, 1);
502 /* Attach to the child. */
503 inferior_ptid
= pid_to_ptid (child_pid
);
504 sprintf (child_pid_spelling
, "%d", child_pid
);
507 target_require_attach (child_pid_spelling
, 1);
509 /* Was there a step_resume breakpoint? (There was if the user
510 did a "next" at the fork() call.) If so, explicitly reset its
513 step_resumes are a form of bp that are made to be per-thread.
514 Since we created the step_resume bp when the parent process
515 was being debugged, and now are switching to the child process,
516 from the breakpoint package's viewpoint, that's a switch of
517 "threads". We must update the bp's notion of which thread
518 it is for, or it'll be ignored when it triggers... */
519 if (step_resume_breakpoint
&&
520 (!has_vforked
|| !follow_vfork_when_exec
))
521 breakpoint_re_set_thread (step_resume_breakpoint
);
523 /* Reinsert all breakpoints in the child. (The user may've set
524 breakpoints after catching the fork, in which case those
525 actually didn't get set in the child, but only in the parent.) */
526 if (!has_vforked
|| !follow_vfork_when_exec
)
528 breakpoint_re_set ();
529 insert_breakpoints ();
533 /* If we're to be following both parent and child, then fork ourselves,
534 and attach the debugger clone to the child. */
535 else if (follow_mode
== follow_fork_mode_both
)
537 char pid_suffix
[100]; /* Arbitrary length. */
539 /* Clone ourselves to follow the child. This is the end of our
540 involvement with child_pid; our clone will take it from here... */
542 target_clone_and_follow_inferior (child_pid
, &followed_child
);
543 followed_parent
= !followed_child
;
545 /* We continue to follow the parent. To help distinguish the two
546 debuggers, though, both we and our clone will reset our prompts. */
547 sprintf (pid_suffix
, "[%d] ", PIDGET (inferior_ptid
));
548 set_prompt (strcat (get_prompt (), pid_suffix
));
551 /* The parent and child of a vfork share the same address space.
552 Also, on some targets the order in which vfork and exec events
553 are received for parent in child requires some delicate handling
556 For instance, on ptrace-based HPUX we receive the child's vfork
557 event first, at which time the parent has been suspended by the
558 OS and is essentially untouchable until the child's exit or second
559 exec event arrives. At that time, the parent's vfork event is
560 delivered to us, and that's when we see and decide how to follow
561 the vfork. But to get to that point, we must continue the child
562 until it execs or exits. To do that smoothly, all breakpoints
563 must be removed from the child, in case there are any set between
564 the vfork() and exec() calls. But removing them from the child
565 also removes them from the parent, due to the shared-address-space
566 nature of a vfork'd parent and child. On HPUX, therefore, we must
567 take care to restore the bp's to the parent before we continue it.
568 Else, it's likely that we may not stop in the expected place. (The
569 worst scenario is when the user tries to step over a vfork() call;
570 the step-resume bp must be restored for the step to properly stop
571 in the parent after the call completes!)
573 Sequence of events, as reported to gdb from HPUX:
575 Parent Child Action for gdb to take
576 -------------------------------------------------------
577 1 VFORK Continue child
583 target_post_follow_vfork (parent_pid
,
589 pending_follow
.fork_event
.saw_parent_fork
= 0;
590 pending_follow
.fork_event
.saw_child_fork
= 0;
594 follow_fork (int parent_pid
, int child_pid
)
596 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
600 /* Forward declaration. */
601 static void follow_exec (int, char *);
604 follow_vfork (int parent_pid
, int child_pid
)
606 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
608 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
609 if (pending_follow
.fork_event
.saw_child_exec
610 && (PIDGET (inferior_ptid
) == child_pid
))
612 pending_follow
.fork_event
.saw_child_exec
= 0;
613 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
614 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
615 xfree (pending_follow
.execd_pathname
);
619 /* EXECD_PATHNAME is assumed to be non-NULL. */
622 follow_exec (int pid
, char *execd_pathname
)
625 struct target_ops
*tgt
;
627 if (!may_follow_exec
)
630 /* Did this exec() follow a vfork()? If so, we must follow the
631 vfork now too. Do it before following the exec. */
632 if (follow_vfork_when_exec
&&
633 (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
))
635 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
636 follow_vfork (PIDGET (inferior_ptid
),
637 pending_follow
.fork_event
.child_pid
);
638 follow_vfork_when_exec
= 0;
639 saved_pid
= PIDGET (inferior_ptid
);
641 /* Did we follow the parent? If so, we're done. If we followed
642 the child then we must also follow its exec(). */
643 if (PIDGET (inferior_ptid
) == pending_follow
.fork_event
.parent_pid
)
647 /* This is an exec event that we actually wish to pay attention to.
648 Refresh our symbol table to the newly exec'd program, remove any
651 If there are breakpoints, they aren't really inserted now,
652 since the exec() transformed our inferior into a fresh set
655 We want to preserve symbolic breakpoints on the list, since
656 we have hopes that they can be reset after the new a.out's
657 symbol table is read.
659 However, any "raw" breakpoints must be removed from the list
660 (e.g., the solib bp's), since their address is probably invalid
663 And, we DON'T want to call delete_breakpoints() here, since
664 that may write the bp's "shadow contents" (the instruction
665 value that was overwritten witha TRAP instruction). Since
666 we now have a new a.out, those shadow contents aren't valid. */
667 update_breakpoints_after_exec ();
669 /* If there was one, it's gone now. We cannot truly step-to-next
670 statement through an exec(). */
671 step_resume_breakpoint
= NULL
;
672 step_range_start
= 0;
675 /* If there was one, it's gone now. */
676 through_sigtramp_breakpoint
= NULL
;
678 /* What is this a.out's name? */
679 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
681 /* We've followed the inferior through an exec. Therefore, the
682 inferior has essentially been killed & reborn. */
684 /* First collect the run target in effect. */
685 tgt
= find_run_target ();
686 /* If we can't find one, things are in a very strange state... */
688 error ("Could find run target to save before following exec");
690 gdb_flush (gdb_stdout
);
691 target_mourn_inferior ();
692 inferior_ptid
= pid_to_ptid (saved_pid
);
693 /* Because mourn_inferior resets inferior_ptid. */
696 /* That a.out is now the one to use. */
697 exec_file_attach (execd_pathname
, 0);
699 /* And also is where symbols can be found. */
700 symbol_file_add_main (execd_pathname
, 0);
702 /* Reset the shared library package. This ensures that we get
703 a shlib event when the child reaches "_start", at which point
704 the dld will have had a chance to initialize the child. */
705 #if defined(SOLIB_RESTART)
708 #ifdef SOLIB_CREATE_INFERIOR_HOOK
709 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
712 /* Reinsert all breakpoints. (Those which were symbolic have
713 been reset to the proper address in the new a.out, thanks
714 to symbol_file_command...) */
715 insert_breakpoints ();
717 /* The next resume of this inferior should bring it to the shlib
718 startup breakpoints. (If the user had also set bp's on
719 "main" from the old (parent) process, then they'll auto-
720 matically get reset there in the new process.) */
723 /* Non-zero if we just simulating a single-step. This is needed
724 because we cannot remove the breakpoints in the inferior process
725 until after the `wait' in `wait_for_inferior'. */
726 static int singlestep_breakpoints_inserted_p
= 0;
729 /* Things to clean up if we QUIT out of resume (). */
732 resume_cleanups (void *ignore
)
737 static const char schedlock_off
[] = "off";
738 static const char schedlock_on
[] = "on";
739 static const char schedlock_step
[] = "step";
740 static const char *scheduler_mode
= schedlock_off
;
741 static const char *scheduler_enums
[] =
750 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
752 if (c
->type
== set_cmd
)
753 if (!target_can_lock_scheduler
)
755 scheduler_mode
= schedlock_off
;
756 error ("Target '%s' cannot support this command.",
762 /* Resume the inferior, but allow a QUIT. This is useful if the user
763 wants to interrupt some lengthy single-stepping operation
764 (for child processes, the SIGINT goes to the inferior, and so
765 we get a SIGINT random_signal, but for remote debugging and perhaps
766 other targets, that's not true).
768 STEP nonzero if we should step (zero to continue instead).
769 SIG is the signal to give the inferior (zero for none). */
771 resume (int step
, enum target_signal sig
)
773 int should_resume
= 1;
774 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
777 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
780 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
781 over an instruction that causes a page fault without triggering
782 a hardware watchpoint. The kernel properly notices that it shouldn't
783 stop, because the hardware watchpoint is not triggered, but it forgets
784 the step request and continues the program normally.
785 Work around the problem by removing hardware watchpoints if a step is
786 requested, GDB will check for a hardware watchpoint trigger after the
788 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
789 remove_hw_watchpoints ();
792 /* Normally, by the time we reach `resume', the breakpoints are either
793 removed or inserted, as appropriate. The exception is if we're sitting
794 at a permanent breakpoint; we need to step over it, but permanent
795 breakpoints can't be removed. So we have to test for it here. */
796 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
797 SKIP_PERMANENT_BREAKPOINT ();
799 if (SOFTWARE_SINGLE_STEP_P () && step
)
801 /* Do it the hard way, w/temp breakpoints */
802 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
803 /* ...and don't ask hardware to do it. */
805 /* and do not pull these breakpoints until after a `wait' in
806 `wait_for_inferior' */
807 singlestep_breakpoints_inserted_p
= 1;
810 /* Handle any optimized stores to the inferior NOW... */
811 #ifdef DO_DEFERRED_STORES
815 /* If there were any forks/vforks/execs that were caught and are
816 now to be followed, then do so. */
817 switch (pending_follow
.kind
)
819 case (TARGET_WAITKIND_FORKED
):
820 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
821 follow_fork (PIDGET (inferior_ptid
),
822 pending_follow
.fork_event
.child_pid
);
825 case (TARGET_WAITKIND_VFORKED
):
827 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
829 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
830 follow_vfork (PIDGET (inferior_ptid
),
831 pending_follow
.fork_event
.child_pid
);
833 /* Did we follow the child, but not yet see the child's exec event?
834 If so, then it actually ought to be waiting for us; we respond to
835 parent vfork events. We don't actually want to resume the child
836 in this situation; we want to just get its exec event. */
837 if (!saw_child_exec
&&
838 (PIDGET (inferior_ptid
) == pending_follow
.fork_event
.child_pid
))
843 case (TARGET_WAITKIND_EXECD
):
844 /* If we saw a vfork event but couldn't follow it until we saw
845 an exec, then now might be the time! */
846 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
847 /* follow_exec is called as soon as the exec event is seen. */
854 /* Install inferior's terminal modes. */
855 target_terminal_inferior ();
861 resume_ptid
= RESUME_ALL
; /* Default */
863 if ((step
|| singlestep_breakpoints_inserted_p
) &&
864 !breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
866 /* Stepping past a breakpoint without inserting breakpoints.
867 Make sure only the current thread gets to step, so that
868 other threads don't sneak past breakpoints while they are
871 resume_ptid
= inferior_ptid
;
874 if ((scheduler_mode
== schedlock_on
) ||
875 (scheduler_mode
== schedlock_step
&&
876 (step
|| singlestep_breakpoints_inserted_p
)))
878 /* User-settable 'scheduler' mode requires solo thread resume. */
879 resume_ptid
= inferior_ptid
;
882 #ifdef CANNOT_STEP_BREAKPOINT
883 /* Most targets can step a breakpoint instruction, thus executing it
884 normally. But if this one cannot, just continue and we will hit
886 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
889 target_resume (resume_ptid
, step
, sig
);
892 discard_cleanups (old_cleanups
);
896 /* Clear out all variables saying what to do when inferior is continued.
897 First do this, then set the ones you want, then call `proceed'. */
900 clear_proceed_status (void)
903 step_range_start
= 0;
905 step_frame_address
= 0;
906 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
908 stop_soon_quietly
= 0;
909 proceed_to_finish
= 0;
910 breakpoint_proceeded
= 1; /* We're about to proceed... */
912 /* Discard any remaining commands or status from previous stop. */
913 bpstat_clear (&stop_bpstat
);
916 /* Basic routine for continuing the program in various fashions.
918 ADDR is the address to resume at, or -1 for resume where stopped.
919 SIGGNAL is the signal to give it, or 0 for none,
920 or -1 for act according to how it stopped.
921 STEP is nonzero if should trap after one instruction.
922 -1 means return after that and print nothing.
923 You should probably set various step_... variables
924 before calling here, if you are stepping.
926 You should call clear_proceed_status before calling proceed. */
929 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
934 step_start_function
= find_pc_function (read_pc ());
938 if (addr
== (CORE_ADDR
) -1)
940 /* If there is a breakpoint at the address we will resume at,
941 step one instruction before inserting breakpoints
942 so that we do not stop right away (and report a second
943 hit at this breakpoint). */
945 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
948 #ifndef STEP_SKIPS_DELAY
949 #define STEP_SKIPS_DELAY(pc) (0)
950 #define STEP_SKIPS_DELAY_P (0)
952 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
953 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
954 is slow (it needs to read memory from the target). */
955 if (STEP_SKIPS_DELAY_P
956 && breakpoint_here_p (read_pc () + 4)
957 && STEP_SKIPS_DELAY (read_pc ()))
965 #ifdef PREPARE_TO_PROCEED
966 /* In a multi-threaded task we may select another thread
967 and then continue or step.
969 But if the old thread was stopped at a breakpoint, it
970 will immediately cause another breakpoint stop without
971 any execution (i.e. it will report a breakpoint hit
972 incorrectly). So we must step over it first.
974 PREPARE_TO_PROCEED checks the current thread against the thread
975 that reported the most recent event. If a step-over is required
976 it returns TRUE and sets the current thread to the old thread. */
977 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
982 #endif /* PREPARE_TO_PROCEED */
985 if (trap_expected_after_continue
)
987 /* If (step == 0), a trap will be automatically generated after
988 the first instruction is executed. Force step one
989 instruction to clear this condition. This should not occur
990 if step is nonzero, but it is harmless in that case. */
992 trap_expected_after_continue
= 0;
994 #endif /* HP_OS_BUG */
997 /* We will get a trace trap after one instruction.
998 Continue it automatically and insert breakpoints then. */
1002 int temp
= insert_breakpoints ();
1005 print_sys_errmsg ("insert_breakpoints", temp
);
1006 error ("Cannot insert breakpoints.\n\
1007 The same program may be running in another process,\n\
1008 or you may have requested too many hardware\n\
1009 breakpoints and/or watchpoints.\n");
1012 breakpoints_inserted
= 1;
1015 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1016 stop_signal
= siggnal
;
1017 /* If this signal should not be seen by program,
1018 give it zero. Used for debugging signals. */
1019 else if (!signal_program
[stop_signal
])
1020 stop_signal
= TARGET_SIGNAL_0
;
1022 annotate_starting ();
1024 /* Make sure that output from GDB appears before output from the
1026 gdb_flush (gdb_stdout
);
1028 /* Resume inferior. */
1029 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1031 /* Wait for it to stop (if not standalone)
1032 and in any case decode why it stopped, and act accordingly. */
1033 /* Do this only if we are not using the event loop, or if the target
1034 does not support asynchronous execution. */
1035 if (!event_loop_p
|| !target_can_async_p ())
1037 wait_for_inferior ();
1042 /* Record the pc and sp of the program the last time it stopped.
1043 These are just used internally by wait_for_inferior, but need
1044 to be preserved over calls to it and cleared when the inferior
1046 static CORE_ADDR prev_pc
;
1047 static CORE_ADDR prev_func_start
;
1048 static char *prev_func_name
;
1051 /* Start remote-debugging of a machine over a serial link. */
1056 init_thread_list ();
1057 init_wait_for_inferior ();
1058 stop_soon_quietly
= 1;
1061 /* Always go on waiting for the target, regardless of the mode. */
1062 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1063 indicate to wait_for_inferior that a target should timeout if
1064 nothing is returned (instead of just blocking). Because of this,
1065 targets expecting an immediate response need to, internally, set
1066 things up so that the target_wait() is forced to eventually
1068 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1069 differentiate to its caller what the state of the target is after
1070 the initial open has been performed. Here we're assuming that
1071 the target has stopped. It should be possible to eventually have
1072 target_open() return to the caller an indication that the target
1073 is currently running and GDB state should be set to the same as
1074 for an async run. */
1075 wait_for_inferior ();
1079 /* Initialize static vars when a new inferior begins. */
1082 init_wait_for_inferior (void)
1084 /* These are meaningless until the first time through wait_for_inferior. */
1086 prev_func_start
= 0;
1087 prev_func_name
= NULL
;
1090 trap_expected_after_continue
= 0;
1092 breakpoints_inserted
= 0;
1093 breakpoint_init_inferior (inf_starting
);
1095 /* Don't confuse first call to proceed(). */
1096 stop_signal
= TARGET_SIGNAL_0
;
1098 /* The first resume is not following a fork/vfork/exec. */
1099 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1100 pending_follow
.fork_event
.saw_parent_fork
= 0;
1101 pending_follow
.fork_event
.saw_child_fork
= 0;
1102 pending_follow
.fork_event
.saw_child_exec
= 0;
1104 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1105 number_of_threads_in_syscalls
= 0;
1107 clear_proceed_status ();
1111 delete_breakpoint_current_contents (void *arg
)
1113 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1114 if (*breakpointp
!= NULL
)
1116 delete_breakpoint (*breakpointp
);
1117 *breakpointp
= NULL
;
1121 /* This enum encodes possible reasons for doing a target_wait, so that
1122 wfi can call target_wait in one place. (Ultimately the call will be
1123 moved out of the infinite loop entirely.) */
1127 infwait_normal_state
,
1128 infwait_thread_hop_state
,
1129 infwait_nullified_state
,
1130 infwait_nonstep_watch_state
1133 /* Why did the inferior stop? Used to print the appropriate messages
1134 to the interface from within handle_inferior_event(). */
1135 enum inferior_stop_reason
1137 /* We don't know why. */
1139 /* Step, next, nexti, stepi finished. */
1141 /* Found breakpoint. */
1143 /* Inferior terminated by signal. */
1145 /* Inferior exited. */
1147 /* Inferior received signal, and user asked to be notified. */
1151 /* This structure contains what used to be local variables in
1152 wait_for_inferior. Probably many of them can return to being
1153 locals in handle_inferior_event. */
1155 struct execution_control_state
1157 struct target_waitstatus ws
;
1158 struct target_waitstatus
*wp
;
1161 CORE_ADDR stop_func_start
;
1162 CORE_ADDR stop_func_end
;
1163 char *stop_func_name
;
1164 struct symtab_and_line sal
;
1165 int remove_breakpoints_on_following_step
;
1167 struct symtab
*current_symtab
;
1168 int handling_longjmp
; /* FIXME */
1170 ptid_t saved_inferior_ptid
;
1172 int stepping_through_solib_after_catch
;
1173 bpstat stepping_through_solib_catchpoints
;
1174 int enable_hw_watchpoints_after_wait
;
1175 int stepping_through_sigtramp
;
1176 int new_thread_event
;
1177 struct target_waitstatus tmpstatus
;
1178 enum infwait_states infwait_state
;
1183 void init_execution_control_state (struct execution_control_state
* ecs
);
1185 void handle_inferior_event (struct execution_control_state
* ecs
);
1187 static void check_sigtramp2 (struct execution_control_state
*ecs
);
1188 static void step_into_function (struct execution_control_state
*ecs
);
1189 static void step_over_function (struct execution_control_state
*ecs
);
1190 static void stop_stepping (struct execution_control_state
*ecs
);
1191 static void prepare_to_wait (struct execution_control_state
*ecs
);
1192 static void keep_going (struct execution_control_state
*ecs
);
1193 static void print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
);
1195 /* Wait for control to return from inferior to debugger.
1196 If inferior gets a signal, we may decide to start it up again
1197 instead of returning. That is why there is a loop in this function.
1198 When this function actually returns it means the inferior
1199 should be left stopped and GDB should read more commands. */
1202 wait_for_inferior (void)
1204 struct cleanup
*old_cleanups
;
1205 struct execution_control_state ecss
;
1206 struct execution_control_state
*ecs
;
1208 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1209 &step_resume_breakpoint
);
1210 make_cleanup (delete_breakpoint_current_contents
,
1211 &through_sigtramp_breakpoint
);
1213 /* wfi still stays in a loop, so it's OK just to take the address of
1214 a local to get the ecs pointer. */
1217 /* Fill in with reasonable starting values. */
1218 init_execution_control_state (ecs
);
1220 /* We'll update this if & when we switch to a new thread. */
1221 previous_inferior_ptid
= inferior_ptid
;
1223 overlay_cache_invalid
= 1;
1225 /* We have to invalidate the registers BEFORE calling target_wait
1226 because they can be loaded from the target while in target_wait.
1227 This makes remote debugging a bit more efficient for those
1228 targets that provide critical registers as part of their normal
1229 status mechanism. */
1231 registers_changed ();
1235 if (target_wait_hook
)
1236 ecs
->ptid
= target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
1238 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
1240 /* Now figure out what to do with the result of the result. */
1241 handle_inferior_event (ecs
);
1243 if (!ecs
->wait_some_more
)
1246 do_cleanups (old_cleanups
);
1249 /* Asynchronous version of wait_for_inferior. It is called by the
1250 event loop whenever a change of state is detected on the file
1251 descriptor corresponding to the target. It can be called more than
1252 once to complete a single execution command. In such cases we need
1253 to keep the state in a global variable ASYNC_ECSS. If it is the
1254 last time that this function is called for a single execution
1255 command, then report to the user that the inferior has stopped, and
1256 do the necessary cleanups. */
1258 struct execution_control_state async_ecss
;
1259 struct execution_control_state
*async_ecs
;
1262 fetch_inferior_event (void *client_data
)
1264 static struct cleanup
*old_cleanups
;
1266 async_ecs
= &async_ecss
;
1268 if (!async_ecs
->wait_some_more
)
1270 old_cleanups
= make_exec_cleanup (delete_step_resume_breakpoint
,
1271 &step_resume_breakpoint
);
1272 make_exec_cleanup (delete_breakpoint_current_contents
,
1273 &through_sigtramp_breakpoint
);
1275 /* Fill in with reasonable starting values. */
1276 init_execution_control_state (async_ecs
);
1278 /* We'll update this if & when we switch to a new thread. */
1279 previous_inferior_ptid
= inferior_ptid
;
1281 overlay_cache_invalid
= 1;
1283 /* We have to invalidate the registers BEFORE calling target_wait
1284 because they can be loaded from the target while in target_wait.
1285 This makes remote debugging a bit more efficient for those
1286 targets that provide critical registers as part of their normal
1287 status mechanism. */
1289 registers_changed ();
1292 if (target_wait_hook
)
1293 async_ecs
->ptid
= target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1295 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1297 /* Now figure out what to do with the result of the result. */
1298 handle_inferior_event (async_ecs
);
1300 if (!async_ecs
->wait_some_more
)
1302 /* Do only the cleanups that have been added by this
1303 function. Let the continuations for the commands do the rest,
1304 if there are any. */
1305 do_exec_cleanups (old_cleanups
);
1307 if (step_multi
&& stop_step
)
1308 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1310 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1314 /* Prepare an execution control state for looping through a
1315 wait_for_inferior-type loop. */
1318 init_execution_control_state (struct execution_control_state
*ecs
)
1320 /* ecs->another_trap? */
1321 ecs
->random_signal
= 0;
1322 ecs
->remove_breakpoints_on_following_step
= 0;
1323 ecs
->handling_longjmp
= 0; /* FIXME */
1324 ecs
->update_step_sp
= 0;
1325 ecs
->stepping_through_solib_after_catch
= 0;
1326 ecs
->stepping_through_solib_catchpoints
= NULL
;
1327 ecs
->enable_hw_watchpoints_after_wait
= 0;
1328 ecs
->stepping_through_sigtramp
= 0;
1329 ecs
->sal
= find_pc_line (prev_pc
, 0);
1330 ecs
->current_line
= ecs
->sal
.line
;
1331 ecs
->current_symtab
= ecs
->sal
.symtab
;
1332 ecs
->infwait_state
= infwait_normal_state
;
1333 ecs
->waiton_ptid
= pid_to_ptid (-1);
1334 ecs
->wp
= &(ecs
->ws
);
1337 /* Call this function before setting step_resume_breakpoint, as a
1338 sanity check. There should never be more than one step-resume
1339 breakpoint per thread, so we should never be setting a new
1340 step_resume_breakpoint when one is already active. */
1342 check_for_old_step_resume_breakpoint (void)
1344 if (step_resume_breakpoint
)
1345 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1348 /* Return the cached copy of the last pid/waitstatus returned by
1349 target_wait()/target_wait_hook(). The data is actually cached by
1350 handle_inferior_event(), which gets called immediately after
1351 target_wait()/target_wait_hook(). */
1354 get_last_target_status(ptid_t
*ptidp
, struct target_waitstatus
*status
)
1356 *ptidp
= target_last_wait_ptid
;
1357 *status
= target_last_waitstatus
;
1360 /* Switch thread contexts, maintaining "infrun state". */
1363 context_switch (struct execution_control_state
*ecs
)
1365 /* Caution: it may happen that the new thread (or the old one!)
1366 is not in the thread list. In this case we must not attempt
1367 to "switch context", or we run the risk that our context may
1368 be lost. This may happen as a result of the target module
1369 mishandling thread creation. */
1371 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1372 { /* Perform infrun state context switch: */
1373 /* Save infrun state for the old thread. */
1374 save_infrun_state (inferior_ptid
, prev_pc
,
1375 prev_func_start
, prev_func_name
,
1376 trap_expected
, step_resume_breakpoint
,
1377 through_sigtramp_breakpoint
, step_range_start
,
1378 step_range_end
, step_frame_address
,
1379 ecs
->handling_longjmp
, ecs
->another_trap
,
1380 ecs
->stepping_through_solib_after_catch
,
1381 ecs
->stepping_through_solib_catchpoints
,
1382 ecs
->stepping_through_sigtramp
,
1383 ecs
->current_line
, ecs
->current_symtab
,
1386 /* Load infrun state for the new thread. */
1387 load_infrun_state (ecs
->ptid
, &prev_pc
,
1388 &prev_func_start
, &prev_func_name
,
1389 &trap_expected
, &step_resume_breakpoint
,
1390 &through_sigtramp_breakpoint
, &step_range_start
,
1391 &step_range_end
, &step_frame_address
,
1392 &ecs
->handling_longjmp
, &ecs
->another_trap
,
1393 &ecs
->stepping_through_solib_after_catch
,
1394 &ecs
->stepping_through_solib_catchpoints
,
1395 &ecs
->stepping_through_sigtramp
,
1396 &ecs
->current_line
, &ecs
->current_symtab
,
1399 inferior_ptid
= ecs
->ptid
;
1403 /* Given an execution control state that has been freshly filled in
1404 by an event from the inferior, figure out what it means and take
1405 appropriate action. */
1408 handle_inferior_event (struct execution_control_state
*ecs
)
1411 int stepped_after_stopped_by_watchpoint
;
1413 /* Cache the last pid/waitstatus. */
1414 target_last_wait_ptid
= ecs
->ptid
;
1415 target_last_waitstatus
= *ecs
->wp
;
1417 /* Keep this extra brace for now, minimizes diffs. */
1419 switch (ecs
->infwait_state
)
1421 case infwait_thread_hop_state
:
1422 /* Cancel the waiton_ptid. */
1423 ecs
->waiton_ptid
= pid_to_ptid (-1);
1424 /* Fall thru to the normal_state case. */
1426 case infwait_normal_state
:
1427 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1428 is serviced in this loop, below. */
1429 if (ecs
->enable_hw_watchpoints_after_wait
)
1431 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1432 ecs
->enable_hw_watchpoints_after_wait
= 0;
1434 stepped_after_stopped_by_watchpoint
= 0;
1437 case infwait_nullified_state
:
1440 case infwait_nonstep_watch_state
:
1441 insert_breakpoints ();
1443 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1444 handle things like signals arriving and other things happening
1445 in combination correctly? */
1446 stepped_after_stopped_by_watchpoint
= 1;
1449 ecs
->infwait_state
= infwait_normal_state
;
1451 flush_cached_frames ();
1453 /* If it's a new process, add it to the thread database */
1455 ecs
->new_thread_event
= (! ptid_equal (ecs
->ptid
, inferior_ptid
)
1456 && ! in_thread_list (ecs
->ptid
));
1458 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1459 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1460 && ecs
->new_thread_event
)
1462 add_thread (ecs
->ptid
);
1464 ui_out_text (uiout
, "[New ");
1465 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->ptid
));
1466 ui_out_text (uiout
, "]\n");
1469 /* NOTE: This block is ONLY meant to be invoked in case of a
1470 "thread creation event"! If it is invoked for any other
1471 sort of event (such as a new thread landing on a breakpoint),
1472 the event will be discarded, which is almost certainly
1475 To avoid this, the low-level module (eg. target_wait)
1476 should call in_thread_list and add_thread, so that the
1477 new thread is known by the time we get here. */
1479 /* We may want to consider not doing a resume here in order
1480 to give the user a chance to play with the new thread.
1481 It might be good to make that a user-settable option. */
1483 /* At this point, all threads are stopped (happens
1484 automatically in either the OS or the native code).
1485 Therefore we need to continue all threads in order to
1488 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1489 prepare_to_wait (ecs
);
1494 switch (ecs
->ws
.kind
)
1496 case TARGET_WAITKIND_LOADED
:
1497 /* Ignore gracefully during startup of the inferior, as it
1498 might be the shell which has just loaded some objects,
1499 otherwise add the symbols for the newly loaded objects. */
1501 if (!stop_soon_quietly
)
1503 /* Remove breakpoints, SOLIB_ADD might adjust
1504 breakpoint addresses via breakpoint_re_set. */
1505 if (breakpoints_inserted
)
1506 remove_breakpoints ();
1508 /* Check for any newly added shared libraries if we're
1509 supposed to be adding them automatically. Switch
1510 terminal for any messages produced by
1511 breakpoint_re_set. */
1512 target_terminal_ours_for_output ();
1513 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
1514 target_terminal_inferior ();
1516 /* Reinsert breakpoints and continue. */
1517 if (breakpoints_inserted
)
1518 insert_breakpoints ();
1521 resume (0, TARGET_SIGNAL_0
);
1522 prepare_to_wait (ecs
);
1525 case TARGET_WAITKIND_SPURIOUS
:
1526 resume (0, TARGET_SIGNAL_0
);
1527 prepare_to_wait (ecs
);
1530 case TARGET_WAITKIND_EXITED
:
1531 target_terminal_ours (); /* Must do this before mourn anyway */
1532 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1534 /* Record the exit code in the convenience variable $_exitcode, so
1535 that the user can inspect this again later. */
1536 set_internalvar (lookup_internalvar ("_exitcode"),
1537 value_from_longest (builtin_type_int
,
1538 (LONGEST
) ecs
->ws
.value
.integer
));
1539 gdb_flush (gdb_stdout
);
1540 target_mourn_inferior ();
1541 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1542 stop_print_frame
= 0;
1543 stop_stepping (ecs
);
1546 case TARGET_WAITKIND_SIGNALLED
:
1547 stop_print_frame
= 0;
1548 stop_signal
= ecs
->ws
.value
.sig
;
1549 target_terminal_ours (); /* Must do this before mourn anyway */
1551 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1552 reach here unless the inferior is dead. However, for years
1553 target_kill() was called here, which hints that fatal signals aren't
1554 really fatal on some systems. If that's true, then some changes
1556 target_mourn_inferior ();
1558 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1559 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1560 stop_stepping (ecs
);
1563 /* The following are the only cases in which we keep going;
1564 the above cases end in a continue or goto. */
1565 case TARGET_WAITKIND_FORKED
:
1566 stop_signal
= TARGET_SIGNAL_TRAP
;
1567 pending_follow
.kind
= ecs
->ws
.kind
;
1569 /* Ignore fork events reported for the parent; we're only
1570 interested in reacting to forks of the child. Note that
1571 we expect the child's fork event to be available if we
1572 waited for it now. */
1573 if (ptid_equal (inferior_ptid
, ecs
->ptid
))
1575 pending_follow
.fork_event
.saw_parent_fork
= 1;
1576 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1577 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1578 prepare_to_wait (ecs
);
1583 pending_follow
.fork_event
.saw_child_fork
= 1;
1584 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1585 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1588 stop_pc
= read_pc_pid (ecs
->ptid
);
1589 ecs
->saved_inferior_ptid
= inferior_ptid
;
1590 inferior_ptid
= ecs
->ptid
;
1591 /* The second argument of bpstat_stop_status is meant to help
1592 distinguish between a breakpoint trap and a singlestep trap.
1593 This is only important on targets where DECR_PC_AFTER_BREAK
1594 is non-zero. The prev_pc test is meant to distinguish between
1595 singlestepping a trap instruction, and singlestepping thru a
1596 jump to the instruction following a trap instruction. */
1598 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1599 currently_stepping (ecs
) &&
1601 stop_pc
- DECR_PC_AFTER_BREAK
);
1602 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1603 inferior_ptid
= ecs
->saved_inferior_ptid
;
1604 goto process_event_stop_test
;
1606 /* If this a platform which doesn't allow a debugger to touch a
1607 vfork'd inferior until after it exec's, then we'd best keep
1608 our fingers entirely off the inferior, other than continuing
1609 it. This has the unfortunate side-effect that catchpoints
1610 of vforks will be ignored. But since the platform doesn't
1611 allow the inferior be touched at vfork time, there's really
1613 case TARGET_WAITKIND_VFORKED
:
1614 stop_signal
= TARGET_SIGNAL_TRAP
;
1615 pending_follow
.kind
= ecs
->ws
.kind
;
1617 /* Is this a vfork of the parent? If so, then give any
1618 vfork catchpoints a chance to trigger now. (It's
1619 dangerous to do so if the child canot be touched until
1620 it execs, and the child has not yet exec'd. We probably
1621 should warn the user to that effect when the catchpoint
1623 if (ptid_equal (ecs
->ptid
, inferior_ptid
))
1625 pending_follow
.fork_event
.saw_parent_fork
= 1;
1626 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1627 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1630 /* If we've seen the child's vfork event but cannot really touch
1631 the child until it execs, then we must continue the child now.
1632 Else, give any vfork catchpoints a chance to trigger now. */
1635 pending_follow
.fork_event
.saw_child_fork
= 1;
1636 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1637 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1638 target_post_startup_inferior (
1639 pid_to_ptid (pending_follow
.fork_event
.child_pid
));
1640 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1641 if (follow_vfork_when_exec
)
1643 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1644 prepare_to_wait (ecs
);
1649 stop_pc
= read_pc ();
1650 /* The second argument of bpstat_stop_status is meant to help
1651 distinguish between a breakpoint trap and a singlestep trap.
1652 This is only important on targets where DECR_PC_AFTER_BREAK
1653 is non-zero. The prev_pc test is meant to distinguish between
1654 singlestepping a trap instruction, and singlestepping thru a
1655 jump to the instruction following a trap instruction. */
1657 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1658 currently_stepping (ecs
) &&
1660 stop_pc
- DECR_PC_AFTER_BREAK
);
1661 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1662 goto process_event_stop_test
;
1664 case TARGET_WAITKIND_EXECD
:
1665 stop_signal
= TARGET_SIGNAL_TRAP
;
1667 /* Is this a target which reports multiple exec events per actual
1668 call to exec()? (HP-UX using ptrace does, for example.) If so,
1669 ignore all but the last one. Just resume the exec'r, and wait
1670 for the next exec event. */
1671 if (inferior_ignoring_leading_exec_events
)
1673 inferior_ignoring_leading_exec_events
--;
1674 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1675 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.parent_pid
);
1676 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1677 prepare_to_wait (ecs
);
1680 inferior_ignoring_leading_exec_events
=
1681 target_reported_exec_events_per_exec_call () - 1;
1683 pending_follow
.execd_pathname
=
1684 savestring (ecs
->ws
.value
.execd_pathname
,
1685 strlen (ecs
->ws
.value
.execd_pathname
));
1687 /* Did inferior_ptid exec, or did a (possibly not-yet-followed)
1688 child of a vfork exec?
1690 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1691 HP-UX, events associated with a vforking inferior come in
1692 threes: a vfork event for the child (always first), followed
1693 a vfork event for the parent and an exec event for the child.
1694 The latter two can come in either order.
1696 If we get the parent vfork event first, life's good: We follow
1697 either the parent or child, and then the child's exec event is
1700 But if we get the child's exec event first, then we delay
1701 responding to it until we handle the parent's vfork. Because,
1702 otherwise we can't satisfy a "catch vfork". */
1703 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1705 pending_follow
.fork_event
.saw_child_exec
= 1;
1707 /* On some targets, the child must be resumed before
1708 the parent vfork event is delivered. A single-step
1710 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1711 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1712 /* We expect the parent vfork event to be available now. */
1713 prepare_to_wait (ecs
);
1717 /* This causes the eventpoints and symbol table to be reset. Must
1718 do this now, before trying to determine whether to stop. */
1719 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1720 xfree (pending_follow
.execd_pathname
);
1722 stop_pc
= read_pc_pid (ecs
->ptid
);
1723 ecs
->saved_inferior_ptid
= inferior_ptid
;
1724 inferior_ptid
= ecs
->ptid
;
1725 /* The second argument of bpstat_stop_status is meant to help
1726 distinguish between a breakpoint trap and a singlestep trap.
1727 This is only important on targets where DECR_PC_AFTER_BREAK
1728 is non-zero. The prev_pc test is meant to distinguish between
1729 singlestepping a trap instruction, and singlestepping thru a
1730 jump to the instruction following a trap instruction. */
1732 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1733 currently_stepping (ecs
) &&
1735 stop_pc
- DECR_PC_AFTER_BREAK
);
1736 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1737 inferior_ptid
= ecs
->saved_inferior_ptid
;
1738 goto process_event_stop_test
;
1740 /* These syscall events are returned on HP-UX, as part of its
1741 implementation of page-protection-based "hardware" watchpoints.
1742 HP-UX has unfortunate interactions between page-protections and
1743 some system calls. Our solution is to disable hardware watches
1744 when a system call is entered, and reenable them when the syscall
1745 completes. The downside of this is that we may miss the precise
1746 point at which a watched piece of memory is modified. "Oh well."
1748 Note that we may have multiple threads running, which may each
1749 enter syscalls at roughly the same time. Since we don't have a
1750 good notion currently of whether a watched piece of memory is
1751 thread-private, we'd best not have any page-protections active
1752 when any thread is in a syscall. Thus, we only want to reenable
1753 hardware watches when no threads are in a syscall.
1755 Also, be careful not to try to gather much state about a thread
1756 that's in a syscall. It's frequently a losing proposition. */
1757 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1758 number_of_threads_in_syscalls
++;
1759 if (number_of_threads_in_syscalls
== 1)
1761 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1763 resume (0, TARGET_SIGNAL_0
);
1764 prepare_to_wait (ecs
);
1767 /* Before examining the threads further, step this thread to
1768 get it entirely out of the syscall. (We get notice of the
1769 event when the thread is just on the verge of exiting a
1770 syscall. Stepping one instruction seems to get it back
1773 Note that although the logical place to reenable h/w watches
1774 is here, we cannot. We cannot reenable them before stepping
1775 the thread (this causes the next wait on the thread to hang).
1777 Nor can we enable them after stepping until we've done a wait.
1778 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1779 here, which will be serviced immediately after the target
1781 case TARGET_WAITKIND_SYSCALL_RETURN
:
1782 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1784 if (number_of_threads_in_syscalls
> 0)
1786 number_of_threads_in_syscalls
--;
1787 ecs
->enable_hw_watchpoints_after_wait
=
1788 (number_of_threads_in_syscalls
== 0);
1790 prepare_to_wait (ecs
);
1793 case TARGET_WAITKIND_STOPPED
:
1794 stop_signal
= ecs
->ws
.value
.sig
;
1797 /* We had an event in the inferior, but we are not interested
1798 in handling it at this level. The lower layers have already
1799 done what needs to be done, if anything. This case can
1800 occur only when the target is async or extended-async. One
1801 of the circumstamces for this to happen is when the
1802 inferior produces output for the console. The inferior has
1803 not stopped, and we are ignoring the event. */
1804 case TARGET_WAITKIND_IGNORE
:
1805 ecs
->wait_some_more
= 1;
1809 /* We may want to consider not doing a resume here in order to give
1810 the user a chance to play with the new thread. It might be good
1811 to make that a user-settable option. */
1813 /* At this point, all threads are stopped (happens automatically in
1814 either the OS or the native code). Therefore we need to continue
1815 all threads in order to make progress. */
1816 if (ecs
->new_thread_event
)
1818 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1819 prepare_to_wait (ecs
);
1823 stop_pc
= read_pc_pid (ecs
->ptid
);
1825 /* See if a thread hit a thread-specific breakpoint that was meant for
1826 another thread. If so, then step that thread past the breakpoint,
1829 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1831 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1832 ecs
->random_signal
= 0;
1833 else if (breakpoints_inserted
1834 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1836 ecs
->random_signal
= 0;
1837 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1842 /* Saw a breakpoint, but it was hit by the wrong thread.
1844 if (DECR_PC_AFTER_BREAK
)
1845 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->ptid
);
1847 remove_status
= remove_breakpoints ();
1848 /* Did we fail to remove breakpoints? If so, try
1849 to set the PC past the bp. (There's at least
1850 one situation in which we can fail to remove
1851 the bp's: On HP-UX's that use ttrace, we can't
1852 change the address space of a vforking child
1853 process until the child exits (well, okay, not
1854 then either :-) or execs. */
1855 if (remove_status
!= 0)
1857 /* FIXME! This is obviously non-portable! */
1858 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4,
1860 /* We need to restart all the threads now,
1861 * unles we're running in scheduler-locked mode.
1862 * Use currently_stepping to determine whether to
1865 /* FIXME MVS: is there any reason not to call resume()? */
1866 if (scheduler_mode
== schedlock_on
)
1867 target_resume (ecs
->ptid
,
1868 currently_stepping (ecs
),
1871 target_resume (RESUME_ALL
,
1872 currently_stepping (ecs
),
1874 prepare_to_wait (ecs
);
1879 breakpoints_inserted
= 0;
1880 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
1881 context_switch (ecs
);
1882 ecs
->waiton_ptid
= ecs
->ptid
;
1883 ecs
->wp
= &(ecs
->ws
);
1884 ecs
->another_trap
= 1;
1886 ecs
->infwait_state
= infwait_thread_hop_state
;
1888 registers_changed ();
1895 ecs
->random_signal
= 1;
1897 /* See if something interesting happened to the non-current thread. If
1898 so, then switch to that thread, and eventually give control back to
1901 Note that if there's any kind of pending follow (i.e., of a fork,
1902 vfork or exec), we don't want to do this now. Rather, we'll let
1903 the next resume handle it. */
1904 if (! ptid_equal (ecs
->ptid
, inferior_ptid
) &&
1905 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1909 /* If it's a random signal for a non-current thread, notify user
1910 if he's expressed an interest. */
1911 if (ecs
->random_signal
1912 && signal_print
[stop_signal
])
1914 /* ??rehrauer: I don't understand the rationale for this code. If the
1915 inferior will stop as a result of this signal, then the act of handling
1916 the stop ought to print a message that's couches the stoppage in user
1917 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1918 won't stop as a result of the signal -- i.e., if the signal is merely
1919 a side-effect of something GDB's doing "under the covers" for the
1920 user, such as stepping threads over a breakpoint they shouldn't stop
1921 for -- then the message seems to be a serious annoyance at best.
1923 For now, remove the message altogether. */
1926 target_terminal_ours_for_output ();
1927 printf_filtered ("\nProgram received signal %s, %s.\n",
1928 target_signal_to_name (stop_signal
),
1929 target_signal_to_string (stop_signal
));
1930 gdb_flush (gdb_stdout
);
1934 /* If it's not SIGTRAP and not a signal we want to stop for, then
1935 continue the thread. */
1937 if (stop_signal
!= TARGET_SIGNAL_TRAP
1938 && !signal_stop
[stop_signal
])
1941 target_terminal_inferior ();
1943 /* Clear the signal if it should not be passed. */
1944 if (signal_program
[stop_signal
] == 0)
1945 stop_signal
= TARGET_SIGNAL_0
;
1947 target_resume (ecs
->ptid
, 0, stop_signal
);
1948 prepare_to_wait (ecs
);
1952 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1953 and fall into the rest of wait_for_inferior(). */
1955 context_switch (ecs
);
1958 context_hook (pid_to_thread_id (ecs
->ptid
));
1960 flush_cached_frames ();
1963 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1965 /* Pull the single step breakpoints out of the target. */
1966 SOFTWARE_SINGLE_STEP (0, 0);
1967 singlestep_breakpoints_inserted_p
= 0;
1970 /* If PC is pointing at a nullified instruction, then step beyond
1971 it so that the user won't be confused when GDB appears to be ready
1974 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1975 if (INSTRUCTION_NULLIFIED
)
1977 registers_changed ();
1978 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1980 /* We may have received a signal that we want to pass to
1981 the inferior; therefore, we must not clobber the waitstatus
1984 ecs
->infwait_state
= infwait_nullified_state
;
1985 ecs
->waiton_ptid
= ecs
->ptid
;
1986 ecs
->wp
= &(ecs
->tmpstatus
);
1987 prepare_to_wait (ecs
);
1991 /* It may not be necessary to disable the watchpoint to stop over
1992 it. For example, the PA can (with some kernel cooperation)
1993 single step over a watchpoint without disabling the watchpoint. */
1994 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1997 prepare_to_wait (ecs
);
2001 /* It is far more common to need to disable a watchpoint to step
2002 the inferior over it. FIXME. What else might a debug
2003 register or page protection watchpoint scheme need here? */
2004 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2006 /* At this point, we are stopped at an instruction which has
2007 attempted to write to a piece of memory under control of
2008 a watchpoint. The instruction hasn't actually executed
2009 yet. If we were to evaluate the watchpoint expression
2010 now, we would get the old value, and therefore no change
2011 would seem to have occurred.
2013 In order to make watchpoints work `right', we really need
2014 to complete the memory write, and then evaluate the
2015 watchpoint expression. The following code does that by
2016 removing the watchpoint (actually, all watchpoints and
2017 breakpoints), single-stepping the target, re-inserting
2018 watchpoints, and then falling through to let normal
2019 single-step processing handle proceed. Since this
2020 includes evaluating watchpoints, things will come to a
2021 stop in the correct manner. */
2023 if (DECR_PC_AFTER_BREAK
)
2024 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
2026 remove_breakpoints ();
2027 registers_changed ();
2028 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
2030 ecs
->waiton_ptid
= ecs
->ptid
;
2031 ecs
->wp
= &(ecs
->ws
);
2032 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2033 prepare_to_wait (ecs
);
2037 /* It may be possible to simply continue after a watchpoint. */
2038 if (HAVE_CONTINUABLE_WATCHPOINT
)
2039 STOPPED_BY_WATCHPOINT (ecs
->ws
);
2041 ecs
->stop_func_start
= 0;
2042 ecs
->stop_func_end
= 0;
2043 ecs
->stop_func_name
= 0;
2044 /* Don't care about return value; stop_func_start and stop_func_name
2045 will both be 0 if it doesn't work. */
2046 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2047 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2048 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
2049 ecs
->another_trap
= 0;
2050 bpstat_clear (&stop_bpstat
);
2052 stop_stack_dummy
= 0;
2053 stop_print_frame
= 1;
2054 ecs
->random_signal
= 0;
2055 stopped_by_random_signal
= 0;
2056 breakpoints_failed
= 0;
2058 /* Look at the cause of the stop, and decide what to do.
2059 The alternatives are:
2060 1) break; to really stop and return to the debugger,
2061 2) drop through to start up again
2062 (set ecs->another_trap to 1 to single step once)
2063 3) set ecs->random_signal to 1, and the decision between 1 and 2
2064 will be made according to the signal handling tables. */
2066 /* First, distinguish signals caused by the debugger from signals
2067 that have to do with the program's own actions.
2068 Note that breakpoint insns may cause SIGTRAP or SIGILL
2069 or SIGEMT, depending on the operating system version.
2070 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2071 and change it to SIGTRAP. */
2073 if (stop_signal
== TARGET_SIGNAL_TRAP
2074 || (breakpoints_inserted
&&
2075 (stop_signal
== TARGET_SIGNAL_ILL
2076 || stop_signal
== TARGET_SIGNAL_EMT
2078 || stop_soon_quietly
)
2080 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2082 stop_print_frame
= 0;
2083 stop_stepping (ecs
);
2086 if (stop_soon_quietly
)
2088 stop_stepping (ecs
);
2092 /* Don't even think about breakpoints
2093 if just proceeded over a breakpoint.
2095 However, if we are trying to proceed over a breakpoint
2096 and end up in sigtramp, then through_sigtramp_breakpoint
2097 will be set and we should check whether we've hit the
2099 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2100 && through_sigtramp_breakpoint
== NULL
)
2101 bpstat_clear (&stop_bpstat
);
2104 /* See if there is a breakpoint at the current PC. */
2106 /* The second argument of bpstat_stop_status is meant to help
2107 distinguish between a breakpoint trap and a singlestep trap.
2108 This is only important on targets where DECR_PC_AFTER_BREAK
2109 is non-zero. The prev_pc test is meant to distinguish between
2110 singlestepping a trap instruction, and singlestepping thru a
2111 jump to the instruction following a trap instruction. */
2113 stop_bpstat
= bpstat_stop_status
2115 /* Pass TRUE if our reason for stopping is something other
2116 than hitting a breakpoint. We do this by checking that
2117 1) stepping is going on and 2) we didn't hit a breakpoint
2118 in a signal handler without an intervening stop in
2119 sigtramp, which is detected by a new stack pointer value
2120 below any usual function calling stack adjustments. */
2121 (currently_stepping (ecs
)
2122 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
2124 && INNER_THAN (read_sp (), (step_sp
- 16))))
2126 /* Following in case break condition called a
2128 stop_print_frame
= 1;
2131 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2133 = !(bpstat_explains_signal (stop_bpstat
)
2135 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2136 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2137 FRAME_FP (get_current_frame ())))
2138 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2143 = !(bpstat_explains_signal (stop_bpstat
)
2144 /* End of a stack dummy. Some systems (e.g. Sony
2145 news) give another signal besides SIGTRAP, so
2146 check here as well as above. */
2147 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2148 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2149 FRAME_FP (get_current_frame ())))
2151 if (!ecs
->random_signal
)
2152 stop_signal
= TARGET_SIGNAL_TRAP
;
2156 /* When we reach this point, we've pretty much decided
2157 that the reason for stopping must've been a random
2158 (unexpected) signal. */
2161 ecs
->random_signal
= 1;
2162 /* If a fork, vfork or exec event was seen, then there are two
2163 possible responses we can make:
2165 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2166 then we must stop now and issue a prompt. We will resume
2167 the inferior when the user tells us to.
2168 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2169 then we must resume the inferior now and keep checking.
2171 In either case, we must take appropriate steps to "follow" the
2172 the fork/vfork/exec when the inferior is resumed. For example,
2173 if follow-fork-mode is "child", then we must detach from the
2174 parent inferior and follow the new child inferior.
2176 In either case, setting pending_follow causes the next resume()
2177 to take the appropriate following action. */
2178 process_event_stop_test
:
2179 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2181 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2184 stop_signal
= TARGET_SIGNAL_0
;
2189 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2191 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2193 stop_signal
= TARGET_SIGNAL_0
;
2198 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2200 pending_follow
.kind
= ecs
->ws
.kind
;
2201 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2204 stop_signal
= TARGET_SIGNAL_0
;
2210 /* For the program's own signals, act according to
2211 the signal handling tables. */
2213 if (ecs
->random_signal
)
2215 /* Signal not for debugging purposes. */
2218 stopped_by_random_signal
= 1;
2220 if (signal_print
[stop_signal
])
2223 target_terminal_ours_for_output ();
2224 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2226 if (signal_stop
[stop_signal
])
2228 stop_stepping (ecs
);
2231 /* If not going to stop, give terminal back
2232 if we took it away. */
2234 target_terminal_inferior ();
2236 /* Clear the signal if it should not be passed. */
2237 if (signal_program
[stop_signal
] == 0)
2238 stop_signal
= TARGET_SIGNAL_0
;
2240 /* I'm not sure whether this needs to be check_sigtramp2 or
2241 whether it could/should be keep_going.
2243 This used to jump to step_over_function if we are stepping,
2246 Suppose the user does a `next' over a function call, and while
2247 that call is in progress, the inferior receives a signal for
2248 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2249 that case, when we reach this point, there is already a
2250 step-resume breakpoint established, right where it should be:
2251 immediately after the function call the user is "next"-ing
2252 over. If we call step_over_function now, two bad things
2255 - we'll create a new breakpoint, at wherever the current
2256 frame's return address happens to be. That could be
2257 anywhere, depending on what function call happens to be on
2258 the top of the stack at that point. Point is, it's probably
2259 not where we need it.
2261 - the existing step-resume breakpoint (which is at the correct
2262 address) will get orphaned: step_resume_breakpoint will point
2263 to the new breakpoint, and the old step-resume breakpoint
2264 will never be cleaned up.
2266 The old behavior was meant to help HP-UX single-step out of
2267 sigtramps. It would place the new breakpoint at prev_pc, which
2268 was certainly wrong. I don't know the details there, so fixing
2269 this probably breaks that. As with anything else, it's up to
2270 the HP-UX maintainer to furnish a fix that doesn't break other
2271 platforms. --JimB, 20 May 1999 */
2272 check_sigtramp2 (ecs
);
2277 /* Handle cases caused by hitting a breakpoint. */
2279 CORE_ADDR jmp_buf_pc
;
2280 struct bpstat_what what
;
2282 what
= bpstat_what (stop_bpstat
);
2284 if (what
.call_dummy
)
2286 stop_stack_dummy
= 1;
2288 trap_expected_after_continue
= 1;
2292 switch (what
.main_action
)
2294 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2295 /* If we hit the breakpoint at longjmp, disable it for the
2296 duration of this command. Then, install a temporary
2297 breakpoint at the target of the jmp_buf. */
2298 disable_longjmp_breakpoint ();
2299 remove_breakpoints ();
2300 breakpoints_inserted
= 0;
2301 if (!GET_LONGJMP_TARGET_P ()
2302 || !GET_LONGJMP_TARGET (&jmp_buf_pc
))
2308 /* Need to blow away step-resume breakpoint, as it
2309 interferes with us */
2310 if (step_resume_breakpoint
!= NULL
)
2312 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2314 /* Not sure whether we need to blow this away too, but probably
2315 it is like the step-resume breakpoint. */
2316 if (through_sigtramp_breakpoint
!= NULL
)
2318 delete_breakpoint (through_sigtramp_breakpoint
);
2319 through_sigtramp_breakpoint
= NULL
;
2323 /* FIXME - Need to implement nested temporary breakpoints */
2324 if (step_over_calls
> 0)
2325 set_longjmp_resume_breakpoint (jmp_buf_pc
,
2326 get_current_frame ());
2329 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2330 ecs
->handling_longjmp
= 1; /* FIXME */
2334 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2335 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2336 remove_breakpoints ();
2337 breakpoints_inserted
= 0;
2339 /* FIXME - Need to implement nested temporary breakpoints */
2341 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2342 step_frame_address
)))
2344 ecs
->another_trap
= 1;
2349 disable_longjmp_breakpoint ();
2350 ecs
->handling_longjmp
= 0; /* FIXME */
2351 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2353 /* else fallthrough */
2355 case BPSTAT_WHAT_SINGLE
:
2356 if (breakpoints_inserted
)
2358 remove_breakpoints ();
2360 breakpoints_inserted
= 0;
2361 ecs
->another_trap
= 1;
2362 /* Still need to check other stuff, at least the case
2363 where we are stepping and step out of the right range. */
2366 case BPSTAT_WHAT_STOP_NOISY
:
2367 stop_print_frame
= 1;
2369 /* We are about to nuke the step_resume_breakpoint and
2370 through_sigtramp_breakpoint via the cleanup chain, so
2371 no need to worry about it here. */
2373 stop_stepping (ecs
);
2376 case BPSTAT_WHAT_STOP_SILENT
:
2377 stop_print_frame
= 0;
2379 /* We are about to nuke the step_resume_breakpoint and
2380 through_sigtramp_breakpoint via the cleanup chain, so
2381 no need to worry about it here. */
2383 stop_stepping (ecs
);
2386 case BPSTAT_WHAT_STEP_RESUME
:
2387 /* This proably demands a more elegant solution, but, yeah
2390 This function's use of the simple variable
2391 step_resume_breakpoint doesn't seem to accomodate
2392 simultaneously active step-resume bp's, although the
2393 breakpoint list certainly can.
2395 If we reach here and step_resume_breakpoint is already
2396 NULL, then apparently we have multiple active
2397 step-resume bp's. We'll just delete the breakpoint we
2398 stopped at, and carry on.
2400 Correction: what the code currently does is delete a
2401 step-resume bp, but it makes no effort to ensure that
2402 the one deleted is the one currently stopped at. MVS */
2404 if (step_resume_breakpoint
== NULL
)
2406 step_resume_breakpoint
=
2407 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2409 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2412 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2413 if (through_sigtramp_breakpoint
)
2414 delete_breakpoint (through_sigtramp_breakpoint
);
2415 through_sigtramp_breakpoint
= NULL
;
2417 /* If were waiting for a trap, hitting the step_resume_break
2418 doesn't count as getting it. */
2420 ecs
->another_trap
= 1;
2423 case BPSTAT_WHAT_CHECK_SHLIBS
:
2424 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2427 /* Remove breakpoints, we eventually want to step over the
2428 shlib event breakpoint, and SOLIB_ADD might adjust
2429 breakpoint addresses via breakpoint_re_set. */
2430 if (breakpoints_inserted
)
2431 remove_breakpoints ();
2432 breakpoints_inserted
= 0;
2434 /* Check for any newly added shared libraries if we're
2435 supposed to be adding them automatically. Switch
2436 terminal for any messages produced by
2437 breakpoint_re_set. */
2438 target_terminal_ours_for_output ();
2439 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
2440 target_terminal_inferior ();
2442 /* Try to reenable shared library breakpoints, additional
2443 code segments in shared libraries might be mapped in now. */
2444 re_enable_breakpoints_in_shlibs ();
2446 /* If requested, stop when the dynamic linker notifies
2447 gdb of events. This allows the user to get control
2448 and place breakpoints in initializer routines for
2449 dynamically loaded objects (among other things). */
2450 if (stop_on_solib_events
)
2452 stop_stepping (ecs
);
2456 /* If we stopped due to an explicit catchpoint, then the
2457 (see above) call to SOLIB_ADD pulled in any symbols
2458 from a newly-loaded library, if appropriate.
2460 We do want the inferior to stop, but not where it is
2461 now, which is in the dynamic linker callback. Rather,
2462 we would like it stop in the user's program, just after
2463 the call that caused this catchpoint to trigger. That
2464 gives the user a more useful vantage from which to
2465 examine their program's state. */
2466 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2468 /* ??rehrauer: If I could figure out how to get the
2469 right return PC from here, we could just set a temp
2470 breakpoint and resume. I'm not sure we can without
2471 cracking open the dld's shared libraries and sniffing
2472 their unwind tables and text/data ranges, and that's
2473 not a terribly portable notion.
2475 Until that time, we must step the inferior out of the
2476 dld callback, and also out of the dld itself (and any
2477 code or stubs in libdld.sl, such as "shl_load" and
2478 friends) until we reach non-dld code. At that point,
2479 we can stop stepping. */
2480 bpstat_get_triggered_catchpoints (stop_bpstat
,
2481 &ecs
->stepping_through_solib_catchpoints
);
2482 ecs
->stepping_through_solib_after_catch
= 1;
2484 /* Be sure to lift all breakpoints, so the inferior does
2485 actually step past this point... */
2486 ecs
->another_trap
= 1;
2491 /* We want to step over this breakpoint, then keep going. */
2492 ecs
->another_trap
= 1;
2499 case BPSTAT_WHAT_LAST
:
2500 /* Not a real code, but listed here to shut up gcc -Wall. */
2502 case BPSTAT_WHAT_KEEP_CHECKING
:
2507 /* We come here if we hit a breakpoint but should not
2508 stop for it. Possibly we also were stepping
2509 and should stop for that. So fall through and
2510 test for stepping. But, if not stepping,
2513 /* Are we stepping to get the inferior out of the dynamic
2514 linker's hook (and possibly the dld itself) after catching
2516 if (ecs
->stepping_through_solib_after_catch
)
2518 #if defined(SOLIB_ADD)
2519 /* Have we reached our destination? If not, keep going. */
2520 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2522 ecs
->another_trap
= 1;
2527 /* Else, stop and report the catchpoint(s) whose triggering
2528 caused us to begin stepping. */
2529 ecs
->stepping_through_solib_after_catch
= 0;
2530 bpstat_clear (&stop_bpstat
);
2531 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2532 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2533 stop_print_frame
= 1;
2534 stop_stepping (ecs
);
2538 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2540 /* This is the old way of detecting the end of the stack dummy.
2541 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2542 handled above. As soon as we can test it on all of them, all
2543 architectures should define it. */
2545 /* If this is the breakpoint at the end of a stack dummy,
2546 just stop silently, unless the user was doing an si/ni, in which
2547 case she'd better know what she's doing. */
2549 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2550 FRAME_FP (get_current_frame ()))
2553 stop_print_frame
= 0;
2554 stop_stack_dummy
= 1;
2556 trap_expected_after_continue
= 1;
2558 stop_stepping (ecs
);
2563 if (step_resume_breakpoint
)
2565 /* Having a step-resume breakpoint overrides anything
2566 else having to do with stepping commands until
2567 that breakpoint is reached. */
2568 /* I'm not sure whether this needs to be check_sigtramp2 or
2569 whether it could/should be keep_going. */
2570 check_sigtramp2 (ecs
);
2575 if (step_range_end
== 0)
2577 /* Likewise if we aren't even stepping. */
2578 /* I'm not sure whether this needs to be check_sigtramp2 or
2579 whether it could/should be keep_going. */
2580 check_sigtramp2 (ecs
);
2585 /* If stepping through a line, keep going if still within it.
2587 Note that step_range_end is the address of the first instruction
2588 beyond the step range, and NOT the address of the last instruction
2590 if (stop_pc
>= step_range_start
2591 && stop_pc
< step_range_end
)
2593 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2594 So definately need to check for sigtramp here. */
2595 check_sigtramp2 (ecs
);
2600 /* We stepped out of the stepping range. */
2602 /* If we are stepping at the source level and entered the runtime
2603 loader dynamic symbol resolution code, we keep on single stepping
2604 until we exit the run time loader code and reach the callee's
2606 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2608 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2610 if (pc_after_resolver
)
2612 /* Set up a step-resume breakpoint at the address
2613 indicated by SKIP_SOLIB_RESOLVER. */
2614 struct symtab_and_line sr_sal
;
2616 sr_sal
.pc
= pc_after_resolver
;
2618 check_for_old_step_resume_breakpoint ();
2619 step_resume_breakpoint
=
2620 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2621 if (breakpoints_inserted
)
2622 insert_breakpoints ();
2629 /* We can't update step_sp every time through the loop, because
2630 reading the stack pointer would slow down stepping too much.
2631 But we can update it every time we leave the step range. */
2632 ecs
->update_step_sp
= 1;
2634 /* Did we just take a signal? */
2635 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2636 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2637 && INNER_THAN (read_sp (), step_sp
))
2639 /* We've just taken a signal; go until we are back to
2640 the point where we took it and one more. */
2642 /* Note: The test above succeeds not only when we stepped
2643 into a signal handler, but also when we step past the last
2644 statement of a signal handler and end up in the return stub
2645 of the signal handler trampoline. To distinguish between
2646 these two cases, check that the frame is INNER_THAN the
2647 previous one below. pai/1997-09-11 */
2651 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2653 if (INNER_THAN (current_frame
, step_frame_address
))
2655 /* We have just taken a signal; go until we are back to
2656 the point where we took it and one more. */
2658 /* This code is needed at least in the following case:
2659 The user types "next" and then a signal arrives (before
2660 the "next" is done). */
2662 /* Note that if we are stopped at a breakpoint, then we need
2663 the step_resume breakpoint to override any breakpoints at
2664 the same location, so that we will still step over the
2665 breakpoint even though the signal happened. */
2666 struct symtab_and_line sr_sal
;
2669 sr_sal
.symtab
= NULL
;
2671 sr_sal
.pc
= prev_pc
;
2672 /* We could probably be setting the frame to
2673 step_frame_address; I don't think anyone thought to
2675 check_for_old_step_resume_breakpoint ();
2676 step_resume_breakpoint
=
2677 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2678 if (breakpoints_inserted
)
2679 insert_breakpoints ();
2683 /* We just stepped out of a signal handler and into
2684 its calling trampoline.
2686 Normally, we'd call step_over_function from
2687 here, but for some reason GDB can't unwind the
2688 stack correctly to find the real PC for the point
2689 user code where the signal trampoline will return
2690 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2691 But signal trampolines are pretty small stubs of
2692 code, anyway, so it's OK instead to just
2693 single-step out. Note: assuming such trampolines
2694 don't exhibit recursion on any platform... */
2695 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2696 &ecs
->stop_func_start
,
2697 &ecs
->stop_func_end
);
2698 /* Readjust stepping range */
2699 step_range_start
= ecs
->stop_func_start
;
2700 step_range_end
= ecs
->stop_func_end
;
2701 ecs
->stepping_through_sigtramp
= 1;
2706 /* If this is stepi or nexti, make sure that the stepping range
2707 gets us past that instruction. */
2708 if (step_range_end
== 1)
2709 /* FIXME: Does this run afoul of the code below which, if
2710 we step into the middle of a line, resets the stepping
2712 step_range_end
= (step_range_start
= prev_pc
) + 1;
2714 ecs
->remove_breakpoints_on_following_step
= 1;
2719 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2720 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2721 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2722 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2723 || ecs
->stop_func_name
== 0)
2725 /* It's a subroutine call. */
2727 if ((step_over_calls
== STEP_OVER_NONE
)
2728 || ((step_range_end
== 1)
2729 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2731 /* I presume that step_over_calls is only 0 when we're
2732 supposed to be stepping at the assembly language level
2733 ("stepi"). Just stop. */
2734 /* Also, maybe we just did a "nexti" inside a prolog,
2735 so we thought it was a subroutine call but it was not.
2736 Stop as well. FENN */
2738 print_stop_reason (END_STEPPING_RANGE
, 0);
2739 stop_stepping (ecs
);
2743 if (step_over_calls
== STEP_OVER_ALL
|| IGNORE_HELPER_CALL (stop_pc
))
2745 /* We're doing a "next". */
2747 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2748 && INNER_THAN (step_frame_address
, read_sp()))
2749 /* We stepped out of a signal handler, and into its
2750 calling trampoline. This is misdetected as a
2751 subroutine call, but stepping over the signal
2752 trampoline isn't such a bad idea. In order to do
2753 that, we have to ignore the value in
2754 step_frame_address, since that doesn't represent the
2755 frame that'll reach when we return from the signal
2756 trampoline. Otherwise we'll probably continue to the
2757 end of the program. */
2758 step_frame_address
= 0;
2760 step_over_function (ecs
);
2765 /* If we are in a function call trampoline (a stub between
2766 the calling routine and the real function), locate the real
2767 function. That's what tells us (a) whether we want to step
2768 into it at all, and (b) what prologue we want to run to
2769 the end of, if we do step into it. */
2770 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2772 ecs
->stop_func_start
= tmp
;
2775 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2778 struct symtab_and_line xxx
;
2779 /* Why isn't this s_a_l called "sr_sal", like all of the
2780 other s_a_l's where this code is duplicated? */
2781 INIT_SAL (&xxx
); /* initialize to zeroes */
2783 xxx
.section
= find_pc_overlay (xxx
.pc
);
2784 check_for_old_step_resume_breakpoint ();
2785 step_resume_breakpoint
=
2786 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2787 insert_breakpoints ();
2793 /* If we have line number information for the function we
2794 are thinking of stepping into, step into it.
2796 If there are several symtabs at that PC (e.g. with include
2797 files), just want to know whether *any* of them have line
2798 numbers. find_pc_line handles this. */
2800 struct symtab_and_line tmp_sal
;
2802 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2803 if (tmp_sal
.line
!= 0)
2805 step_into_function (ecs
);
2810 /* If we have no line number and the step-stop-if-no-debug
2811 is set, we stop the step so that the user has a chance to
2812 switch in assembly mode. */
2813 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2816 print_stop_reason (END_STEPPING_RANGE
, 0);
2817 stop_stepping (ecs
);
2821 step_over_function (ecs
);
2827 /* We've wandered out of the step range. */
2829 ecs
->sal
= find_pc_line (stop_pc
, 0);
2831 if (step_range_end
== 1)
2833 /* It is stepi or nexti. We always want to stop stepping after
2836 print_stop_reason (END_STEPPING_RANGE
, 0);
2837 stop_stepping (ecs
);
2841 /* If we're in the return path from a shared library trampoline,
2842 we want to proceed through the trampoline when stepping. */
2843 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2847 /* Determine where this trampoline returns. */
2848 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2850 /* Only proceed through if we know where it's going. */
2853 /* And put the step-breakpoint there and go until there. */
2854 struct symtab_and_line sr_sal
;
2856 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2858 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2859 /* Do not specify what the fp should be when we stop
2860 since on some machines the prologue
2861 is where the new fp value is established. */
2862 check_for_old_step_resume_breakpoint ();
2863 step_resume_breakpoint
=
2864 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2865 if (breakpoints_inserted
)
2866 insert_breakpoints ();
2868 /* Restart without fiddling with the step ranges or
2875 if (ecs
->sal
.line
== 0)
2877 /* We have no line number information. That means to stop
2878 stepping (does this always happen right after one instruction,
2879 when we do "s" in a function with no line numbers,
2880 or can this happen as a result of a return or longjmp?). */
2882 print_stop_reason (END_STEPPING_RANGE
, 0);
2883 stop_stepping (ecs
);
2887 if ((stop_pc
== ecs
->sal
.pc
)
2888 && (ecs
->current_line
!= ecs
->sal
.line
|| ecs
->current_symtab
!= ecs
->sal
.symtab
))
2890 /* We are at the start of a different line. So stop. Note that
2891 we don't stop if we step into the middle of a different line.
2892 That is said to make things like for (;;) statements work
2895 print_stop_reason (END_STEPPING_RANGE
, 0);
2896 stop_stepping (ecs
);
2900 /* We aren't done stepping.
2902 Optimize by setting the stepping range to the line.
2903 (We might not be in the original line, but if we entered a
2904 new line in mid-statement, we continue stepping. This makes
2905 things like for(;;) statements work better.) */
2907 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2909 /* If this is the last line of the function, don't keep stepping
2910 (it would probably step us out of the function).
2911 This is particularly necessary for a one-line function,
2912 in which after skipping the prologue we better stop even though
2913 we will be in mid-line. */
2915 print_stop_reason (END_STEPPING_RANGE
, 0);
2916 stop_stepping (ecs
);
2919 step_range_start
= ecs
->sal
.pc
;
2920 step_range_end
= ecs
->sal
.end
;
2921 step_frame_address
= FRAME_FP (get_current_frame ());
2922 ecs
->current_line
= ecs
->sal
.line
;
2923 ecs
->current_symtab
= ecs
->sal
.symtab
;
2925 /* In the case where we just stepped out of a function into the middle
2926 of a line of the caller, continue stepping, but step_frame_address
2927 must be modified to current frame */
2929 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2930 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2931 step_frame_address
= current_frame
;
2936 } /* extra brace, to preserve old indentation */
2939 /* Are we in the middle of stepping? */
2942 currently_stepping (struct execution_control_state
*ecs
)
2944 return ((through_sigtramp_breakpoint
== NULL
2945 && !ecs
->handling_longjmp
2946 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2948 || ecs
->stepping_through_solib_after_catch
2949 || bpstat_should_step ());
2953 check_sigtramp2 (struct execution_control_state
*ecs
)
2956 && IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2957 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2958 && INNER_THAN (read_sp (), step_sp
))
2960 /* What has happened here is that we have just stepped the
2961 inferior with a signal (because it is a signal which
2962 shouldn't make us stop), thus stepping into sigtramp.
2964 So we need to set a step_resume_break_address breakpoint and
2965 continue until we hit it, and then step. FIXME: This should
2966 be more enduring than a step_resume breakpoint; we should
2967 know that we will later need to keep going rather than
2968 re-hitting the breakpoint here (see the testsuite,
2969 gdb.base/signals.exp where it says "exceedingly difficult"). */
2971 struct symtab_and_line sr_sal
;
2973 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2974 sr_sal
.pc
= prev_pc
;
2975 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2976 /* We perhaps could set the frame if we kept track of what the
2977 frame corresponding to prev_pc was. But we don't, so don't. */
2978 through_sigtramp_breakpoint
=
2979 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2980 if (breakpoints_inserted
)
2981 insert_breakpoints ();
2983 ecs
->remove_breakpoints_on_following_step
= 1;
2984 ecs
->another_trap
= 1;
2988 /* Subroutine call with source code we should not step over. Do step
2989 to the first line of code in it. */
2992 step_into_function (struct execution_control_state
*ecs
)
2995 struct symtab_and_line sr_sal
;
2997 s
= find_pc_symtab (stop_pc
);
2998 if (s
&& s
->language
!= language_asm
)
2999 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
3001 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
3002 /* Use the step_resume_break to step until the end of the prologue,
3003 even if that involves jumps (as it seems to on the vax under
3005 /* If the prologue ends in the middle of a source line, continue to
3006 the end of that source line (if it is still within the function).
3007 Otherwise, just go to end of prologue. */
3008 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
3009 /* no, don't either. It skips any code that's legitimately on the
3013 && ecs
->sal
.pc
!= ecs
->stop_func_start
3014 && ecs
->sal
.end
< ecs
->stop_func_end
)
3015 ecs
->stop_func_start
= ecs
->sal
.end
;
3018 if (ecs
->stop_func_start
== stop_pc
)
3020 /* We are already there: stop now. */
3022 print_stop_reason (END_STEPPING_RANGE
, 0);
3023 stop_stepping (ecs
);
3028 /* Put the step-breakpoint there and go until there. */
3029 INIT_SAL (&sr_sal
); /* initialize to zeroes */
3030 sr_sal
.pc
= ecs
->stop_func_start
;
3031 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3032 /* Do not specify what the fp should be when we stop since on
3033 some machines the prologue is where the new fp value is
3035 check_for_old_step_resume_breakpoint ();
3036 step_resume_breakpoint
=
3037 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
3038 if (breakpoints_inserted
)
3039 insert_breakpoints ();
3041 /* And make sure stepping stops right away then. */
3042 step_range_end
= step_range_start
;
3047 /* We've just entered a callee, and we wish to resume until it returns
3048 to the caller. Setting a step_resume breakpoint on the return
3049 address will catch a return from the callee.
3051 However, if the callee is recursing, we want to be careful not to
3052 catch returns of those recursive calls, but only of THIS instance
3055 To do this, we set the step_resume bp's frame to our current
3056 caller's frame (step_frame_address, which is set by the "next" or
3057 "until" command, before execution begins). */
3060 step_over_function (struct execution_control_state
*ecs
)
3062 struct symtab_and_line sr_sal
;
3064 INIT_SAL (&sr_sal
); /* initialize to zeros */
3065 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3066 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3068 check_for_old_step_resume_breakpoint ();
3069 step_resume_breakpoint
=
3070 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
3072 if (step_frame_address
&& !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
3073 step_resume_breakpoint
->frame
= step_frame_address
;
3075 if (breakpoints_inserted
)
3076 insert_breakpoints ();
3080 stop_stepping (struct execution_control_state
*ecs
)
3082 if (target_has_execution
)
3084 /* Are we stopping for a vfork event? We only stop when we see
3085 the child's event. However, we may not yet have seen the
3086 parent's event. And, inferior_ptid is still set to the
3087 parent's pid, until we resume again and follow either the
3090 To ensure that we can really touch inferior_ptid (aka, the
3091 parent process) -- which calls to functions like read_pc
3092 implicitly do -- wait on the parent if necessary. */
3093 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3094 && !pending_follow
.fork_event
.saw_parent_fork
)
3100 if (target_wait_hook
)
3101 parent_ptid
= target_wait_hook (pid_to_ptid (-1), &(ecs
->ws
));
3103 parent_ptid
= target_wait (pid_to_ptid (-1), &(ecs
->ws
));
3105 while (! ptid_equal (parent_ptid
, inferior_ptid
));
3108 /* Assuming the inferior still exists, set these up for next
3109 time, just like we did above if we didn't break out of the
3111 prev_pc
= read_pc ();
3112 prev_func_start
= ecs
->stop_func_start
;
3113 prev_func_name
= ecs
->stop_func_name
;
3116 /* Let callers know we don't want to wait for the inferior anymore. */
3117 ecs
->wait_some_more
= 0;
3120 /* This function handles various cases where we need to continue
3121 waiting for the inferior. */
3122 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3125 keep_going (struct execution_control_state
*ecs
)
3127 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3128 vforked child between its creation and subsequent exit or call to
3129 exec(). However, I had big problems in this rather creaky exec
3130 engine, getting that to work. The fundamental problem is that
3131 I'm trying to debug two processes via an engine that only
3132 understands a single process with possibly multiple threads.
3134 Hence, this spot is known to have problems when
3135 target_can_follow_vfork_prior_to_exec returns 1. */
3137 /* Save the pc before execution, to compare with pc after stop. */
3138 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3139 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3140 BREAK is defined, the
3141 original pc would not have
3142 been at the start of a
3144 prev_func_name
= ecs
->stop_func_name
;
3146 if (ecs
->update_step_sp
)
3147 step_sp
= read_sp ();
3148 ecs
->update_step_sp
= 0;
3150 /* If we did not do break;, it means we should keep running the
3151 inferior and not return to debugger. */
3153 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3155 /* We took a signal (which we are supposed to pass through to
3156 the inferior, else we'd have done a break above) and we
3157 haven't yet gotten our trap. Simply continue. */
3158 resume (currently_stepping (ecs
), stop_signal
);
3162 /* Either the trap was not expected, but we are continuing
3163 anyway (the user asked that this signal be passed to the
3166 The signal was SIGTRAP, e.g. it was our signal, but we
3167 decided we should resume from it.
3169 We're going to run this baby now!
3171 Insert breakpoints now, unless we are trying to one-proceed
3172 past a breakpoint. */
3173 /* If we've just finished a special step resume and we don't
3174 want to hit a breakpoint, pull em out. */
3175 if (step_resume_breakpoint
== NULL
3176 && through_sigtramp_breakpoint
== NULL
3177 && ecs
->remove_breakpoints_on_following_step
)
3179 ecs
->remove_breakpoints_on_following_step
= 0;
3180 remove_breakpoints ();
3181 breakpoints_inserted
= 0;
3183 else if (!breakpoints_inserted
&&
3184 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3186 breakpoints_failed
= insert_breakpoints ();
3187 if (breakpoints_failed
)
3189 stop_stepping (ecs
);
3192 breakpoints_inserted
= 1;
3195 trap_expected
= ecs
->another_trap
;
3197 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3198 specifies that such a signal should be delivered to the
3201 Typically, this would occure when a user is debugging a
3202 target monitor on a simulator: the target monitor sets a
3203 breakpoint; the simulator encounters this break-point and
3204 halts the simulation handing control to GDB; GDB, noteing
3205 that the break-point isn't valid, returns control back to the
3206 simulator; the simulator then delivers the hardware
3207 equivalent of a SIGNAL_TRAP to the program being debugged. */
3209 if (stop_signal
== TARGET_SIGNAL_TRAP
3210 && !signal_program
[stop_signal
])
3211 stop_signal
= TARGET_SIGNAL_0
;
3213 #ifdef SHIFT_INST_REGS
3214 /* I'm not sure when this following segment applies. I do know,
3215 now, that we shouldn't rewrite the regs when we were stopped
3216 by a random signal from the inferior process. */
3217 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3218 (this is only used on the 88k). */
3220 if (!bpstat_explains_signal (stop_bpstat
)
3221 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
3222 && !stopped_by_random_signal
)
3224 #endif /* SHIFT_INST_REGS */
3226 resume (currently_stepping (ecs
), stop_signal
);
3229 prepare_to_wait (ecs
);
3232 /* This function normally comes after a resume, before
3233 handle_inferior_event exits. It takes care of any last bits of
3234 housekeeping, and sets the all-important wait_some_more flag. */
3237 prepare_to_wait (struct execution_control_state
*ecs
)
3239 if (ecs
->infwait_state
== infwait_normal_state
)
3241 overlay_cache_invalid
= 1;
3243 /* We have to invalidate the registers BEFORE calling
3244 target_wait because they can be loaded from the target while
3245 in target_wait. This makes remote debugging a bit more
3246 efficient for those targets that provide critical registers
3247 as part of their normal status mechanism. */
3249 registers_changed ();
3250 ecs
->waiton_ptid
= pid_to_ptid (-1);
3251 ecs
->wp
= &(ecs
->ws
);
3253 /* This is the old end of the while loop. Let everybody know we
3254 want to wait for the inferior some more and get called again
3256 ecs
->wait_some_more
= 1;
3259 /* Print why the inferior has stopped. We always print something when
3260 the inferior exits, or receives a signal. The rest of the cases are
3261 dealt with later on in normal_stop() and print_it_typical(). Ideally
3262 there should be a call to this function from handle_inferior_event()
3263 each time stop_stepping() is called.*/
3265 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3267 switch (stop_reason
)
3270 /* We don't deal with these cases from handle_inferior_event()
3273 case END_STEPPING_RANGE
:
3274 /* We are done with a step/next/si/ni command. */
3275 /* For now print nothing. */
3276 /* Print a message only if not in the middle of doing a "step n"
3277 operation for n > 1 */
3278 if (!step_multi
|| !stop_step
)
3279 if (ui_out_is_mi_like_p (uiout
))
3280 ui_out_field_string (uiout
, "reason", "end-stepping-range");
3282 case BREAKPOINT_HIT
:
3283 /* We found a breakpoint. */
3284 /* For now print nothing. */
3287 /* The inferior was terminated by a signal. */
3288 annotate_signalled ();
3289 if (ui_out_is_mi_like_p (uiout
))
3290 ui_out_field_string (uiout
, "reason", "exited-signalled");
3291 ui_out_text (uiout
, "\nProgram terminated with signal ");
3292 annotate_signal_name ();
3293 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3294 annotate_signal_name_end ();
3295 ui_out_text (uiout
, ", ");
3296 annotate_signal_string ();
3297 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3298 annotate_signal_string_end ();
3299 ui_out_text (uiout
, ".\n");
3300 ui_out_text (uiout
, "The program no longer exists.\n");
3303 /* The inferior program is finished. */
3304 annotate_exited (stop_info
);
3307 if (ui_out_is_mi_like_p (uiout
))
3308 ui_out_field_string (uiout
, "reason", "exited");
3309 ui_out_text (uiout
, "\nProgram exited with code ");
3310 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) stop_info
);
3311 ui_out_text (uiout
, ".\n");
3315 if (ui_out_is_mi_like_p (uiout
))
3316 ui_out_field_string (uiout
, "reason", "exited-normally");
3317 ui_out_text (uiout
, "\nProgram exited normally.\n");
3320 case SIGNAL_RECEIVED
:
3321 /* Signal received. The signal table tells us to print about
3324 ui_out_text (uiout
, "\nProgram received signal ");
3325 annotate_signal_name ();
3326 if (ui_out_is_mi_like_p (uiout
))
3327 ui_out_field_string (uiout
, "reason", "signal-received");
3328 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3329 annotate_signal_name_end ();
3330 ui_out_text (uiout
, ", ");
3331 annotate_signal_string ();
3332 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3333 annotate_signal_string_end ();
3334 ui_out_text (uiout
, ".\n");
3337 internal_error (__FILE__
, __LINE__
,
3338 "print_stop_reason: unrecognized enum value");
3344 /* Here to return control to GDB when the inferior stops for real.
3345 Print appropriate messages, remove breakpoints, give terminal our modes.
3347 STOP_PRINT_FRAME nonzero means print the executing frame
3348 (pc, function, args, file, line number and line text).
3349 BREAKPOINTS_FAILED nonzero means stop was due to error
3350 attempting to insert breakpoints. */
3355 /* As with the notification of thread events, we want to delay
3356 notifying the user that we've switched thread context until
3357 the inferior actually stops.
3359 (Note that there's no point in saying anything if the inferior
3361 if (! ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3362 && target_has_execution
)
3364 target_terminal_ours_for_output ();
3365 printf_filtered ("[Switching to %s]\n",
3366 target_pid_or_tid_to_str (inferior_ptid
));
3367 previous_inferior_ptid
= inferior_ptid
;
3370 /* Make sure that the current_frame's pc is correct. This
3371 is a correction for setting up the frame info before doing
3372 DECR_PC_AFTER_BREAK */
3373 if (target_has_execution
&& get_current_frame ())
3374 (get_current_frame ())->pc
= read_pc ();
3376 if (breakpoints_failed
)
3378 target_terminal_ours_for_output ();
3379 print_sys_errmsg ("While inserting breakpoints", breakpoints_failed
);
3380 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3381 The same program may be running in another process,\n\
3382 or you may have requested too many hardware breakpoints\n\
3383 and/or watchpoints.\n");
3386 if (target_has_execution
&& breakpoints_inserted
)
3388 if (remove_breakpoints ())
3390 target_terminal_ours_for_output ();
3391 printf_filtered ("Cannot remove breakpoints because ");
3392 printf_filtered ("program is no longer writable.\n");
3393 printf_filtered ("It might be running in another process.\n");
3394 printf_filtered ("Further execution is probably impossible.\n");
3397 breakpoints_inserted
= 0;
3399 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3400 Delete any breakpoint that is to be deleted at the next stop. */
3402 breakpoint_auto_delete (stop_bpstat
);
3404 /* If an auto-display called a function and that got a signal,
3405 delete that auto-display to avoid an infinite recursion. */
3407 if (stopped_by_random_signal
)
3408 disable_current_display ();
3410 /* Don't print a message if in the middle of doing a "step n"
3411 operation for n > 1 */
3412 if (step_multi
&& stop_step
)
3415 target_terminal_ours ();
3417 /* Look up the hook_stop and run it if it exists. */
3419 if (stop_command
&& stop_command
->hook_pre
)
3421 catch_errors (hook_stop_stub
, stop_command
->hook_pre
,
3422 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3425 if (!target_has_stack
)
3431 /* Select innermost stack frame - i.e., current frame is frame 0,
3432 and current location is based on that.
3433 Don't do this on return from a stack dummy routine,
3434 or if the program has exited. */
3436 if (!stop_stack_dummy
)
3438 select_frame (get_current_frame (), 0);
3440 /* Print current location without a level number, if
3441 we have changed functions or hit a breakpoint.
3442 Print source line if we have one.
3443 bpstat_print() contains the logic deciding in detail
3444 what to print, based on the event(s) that just occurred. */
3446 if (stop_print_frame
3451 int do_frame_printing
= 1;
3453 bpstat_ret
= bpstat_print (stop_bpstat
);
3458 && step_frame_address
== FRAME_FP (get_current_frame ())
3459 && step_start_function
== find_pc_function (stop_pc
))
3460 source_flag
= SRC_LINE
; /* finished step, just print source line */
3462 source_flag
= SRC_AND_LOC
; /* print location and source line */
3464 case PRINT_SRC_AND_LOC
:
3465 source_flag
= SRC_AND_LOC
; /* print location and source line */
3467 case PRINT_SRC_ONLY
:
3468 source_flag
= SRC_LINE
;
3471 source_flag
= SRC_LINE
; /* something bogus */
3472 do_frame_printing
= 0;
3475 internal_error (__FILE__
, __LINE__
,
3478 /* For mi, have the same behavior every time we stop:
3479 print everything but the source line. */
3480 if (ui_out_is_mi_like_p (uiout
))
3481 source_flag
= LOC_AND_ADDRESS
;
3483 if (ui_out_is_mi_like_p (uiout
))
3484 ui_out_field_int (uiout
, "thread-id",
3485 pid_to_thread_id (inferior_ptid
));
3486 /* The behavior of this routine with respect to the source
3488 SRC_LINE: Print only source line
3489 LOCATION: Print only location
3490 SRC_AND_LOC: Print location and source line */
3491 if (do_frame_printing
)
3492 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
3494 /* Display the auto-display expressions. */
3499 /* Save the function value return registers, if we care.
3500 We might be about to restore their previous contents. */
3501 if (proceed_to_finish
)
3502 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
3504 if (stop_stack_dummy
)
3506 /* Pop the empty frame that contains the stack dummy.
3507 POP_FRAME ends with a setting of the current frame, so we
3508 can use that next. */
3510 /* Set stop_pc to what it was before we called the function.
3511 Can't rely on restore_inferior_status because that only gets
3512 called if we don't stop in the called function. */
3513 stop_pc
= read_pc ();
3514 select_frame (get_current_frame (), 0);
3518 annotate_stopped ();
3522 hook_stop_stub (void *cmd
)
3524 execute_user_command ((struct cmd_list_element
*) cmd
, 0);
3529 signal_stop_state (int signo
)
3531 return signal_stop
[signo
];
3535 signal_print_state (int signo
)
3537 return signal_print
[signo
];
3541 signal_pass_state (int signo
)
3543 return signal_program
[signo
];
3546 int signal_stop_update (signo
, state
)
3550 int ret
= signal_stop
[signo
];
3551 signal_stop
[signo
] = state
;
3555 int signal_print_update (signo
, state
)
3559 int ret
= signal_print
[signo
];
3560 signal_print
[signo
] = state
;
3564 int signal_pass_update (signo
, state
)
3568 int ret
= signal_program
[signo
];
3569 signal_program
[signo
] = state
;
3574 sig_print_header (void)
3577 Signal Stop\tPrint\tPass to program\tDescription\n");
3581 sig_print_info (enum target_signal oursig
)
3583 char *name
= target_signal_to_name (oursig
);
3584 int name_padding
= 13 - strlen (name
);
3586 if (name_padding
<= 0)
3589 printf_filtered ("%s", name
);
3590 printf_filtered ("%*.*s ", name_padding
, name_padding
,
3592 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3593 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3594 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3595 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3598 /* Specify how various signals in the inferior should be handled. */
3601 handle_command (char *args
, int from_tty
)
3604 int digits
, wordlen
;
3605 int sigfirst
, signum
, siglast
;
3606 enum target_signal oursig
;
3609 unsigned char *sigs
;
3610 struct cleanup
*old_chain
;
3614 error_no_arg ("signal to handle");
3617 /* Allocate and zero an array of flags for which signals to handle. */
3619 nsigs
= (int) TARGET_SIGNAL_LAST
;
3620 sigs
= (unsigned char *) alloca (nsigs
);
3621 memset (sigs
, 0, nsigs
);
3623 /* Break the command line up into args. */
3625 argv
= buildargv (args
);
3630 old_chain
= make_cleanup_freeargv (argv
);
3632 /* Walk through the args, looking for signal oursigs, signal names, and
3633 actions. Signal numbers and signal names may be interspersed with
3634 actions, with the actions being performed for all signals cumulatively
3635 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3637 while (*argv
!= NULL
)
3639 wordlen
= strlen (*argv
);
3640 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3644 sigfirst
= siglast
= -1;
3646 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3648 /* Apply action to all signals except those used by the
3649 debugger. Silently skip those. */
3652 siglast
= nsigs
- 1;
3654 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3656 SET_SIGS (nsigs
, sigs
, signal_stop
);
3657 SET_SIGS (nsigs
, sigs
, signal_print
);
3659 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3661 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3663 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3665 SET_SIGS (nsigs
, sigs
, signal_print
);
3667 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3669 SET_SIGS (nsigs
, sigs
, signal_program
);
3671 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3673 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3675 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3677 SET_SIGS (nsigs
, sigs
, signal_program
);
3679 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3681 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3682 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3684 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3686 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3688 else if (digits
> 0)
3690 /* It is numeric. The numeric signal refers to our own
3691 internal signal numbering from target.h, not to host/target
3692 signal number. This is a feature; users really should be
3693 using symbolic names anyway, and the common ones like
3694 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3696 sigfirst
= siglast
= (int)
3697 target_signal_from_command (atoi (*argv
));
3698 if ((*argv
)[digits
] == '-')
3701 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3703 if (sigfirst
> siglast
)
3705 /* Bet he didn't figure we'd think of this case... */
3713 oursig
= target_signal_from_name (*argv
);
3714 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3716 sigfirst
= siglast
= (int) oursig
;
3720 /* Not a number and not a recognized flag word => complain. */
3721 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3725 /* If any signal numbers or symbol names were found, set flags for
3726 which signals to apply actions to. */
3728 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3730 switch ((enum target_signal
) signum
)
3732 case TARGET_SIGNAL_TRAP
:
3733 case TARGET_SIGNAL_INT
:
3734 if (!allsigs
&& !sigs
[signum
])
3736 if (query ("%s is used by the debugger.\n\
3737 Are you sure you want to change it? ",
3738 target_signal_to_name
3739 ((enum target_signal
) signum
)))
3745 printf_unfiltered ("Not confirmed, unchanged.\n");
3746 gdb_flush (gdb_stdout
);
3750 case TARGET_SIGNAL_0
:
3751 case TARGET_SIGNAL_DEFAULT
:
3752 case TARGET_SIGNAL_UNKNOWN
:
3753 /* Make sure that "all" doesn't print these. */
3764 target_notice_signals (inferior_ptid
);
3768 /* Show the results. */
3769 sig_print_header ();
3770 for (signum
= 0; signum
< nsigs
; signum
++)
3774 sig_print_info (signum
);
3779 do_cleanups (old_chain
);
3783 xdb_handle_command (char *args
, int from_tty
)
3786 struct cleanup
*old_chain
;
3788 /* Break the command line up into args. */
3790 argv
= buildargv (args
);
3795 old_chain
= make_cleanup_freeargv (argv
);
3796 if (argv
[1] != (char *) NULL
)
3801 bufLen
= strlen (argv
[0]) + 20;
3802 argBuf
= (char *) xmalloc (bufLen
);
3806 enum target_signal oursig
;
3808 oursig
= target_signal_from_name (argv
[0]);
3809 memset (argBuf
, 0, bufLen
);
3810 if (strcmp (argv
[1], "Q") == 0)
3811 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3814 if (strcmp (argv
[1], "s") == 0)
3816 if (!signal_stop
[oursig
])
3817 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3819 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3821 else if (strcmp (argv
[1], "i") == 0)
3823 if (!signal_program
[oursig
])
3824 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3826 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3828 else if (strcmp (argv
[1], "r") == 0)
3830 if (!signal_print
[oursig
])
3831 sprintf (argBuf
, "%s %s", argv
[0], "print");
3833 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3839 handle_command (argBuf
, from_tty
);
3841 printf_filtered ("Invalid signal handling flag.\n");
3846 do_cleanups (old_chain
);
3849 /* Print current contents of the tables set by the handle command.
3850 It is possible we should just be printing signals actually used
3851 by the current target (but for things to work right when switching
3852 targets, all signals should be in the signal tables). */
3855 signals_info (char *signum_exp
, int from_tty
)
3857 enum target_signal oursig
;
3858 sig_print_header ();
3862 /* First see if this is a symbol name. */
3863 oursig
= target_signal_from_name (signum_exp
);
3864 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3866 /* No, try numeric. */
3868 target_signal_from_command (parse_and_eval_long (signum_exp
));
3870 sig_print_info (oursig
);
3874 printf_filtered ("\n");
3875 /* These ugly casts brought to you by the native VAX compiler. */
3876 for (oursig
= TARGET_SIGNAL_FIRST
;
3877 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3878 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3882 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3883 && oursig
!= TARGET_SIGNAL_DEFAULT
3884 && oursig
!= TARGET_SIGNAL_0
)
3885 sig_print_info (oursig
);
3888 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3891 struct inferior_status
3893 enum target_signal stop_signal
;
3897 int stop_stack_dummy
;
3898 int stopped_by_random_signal
;
3900 CORE_ADDR step_range_start
;
3901 CORE_ADDR step_range_end
;
3902 CORE_ADDR step_frame_address
;
3903 enum step_over_calls_kind step_over_calls
;
3904 CORE_ADDR step_resume_break_address
;
3905 int stop_after_trap
;
3906 int stop_soon_quietly
;
3907 CORE_ADDR selected_frame_address
;
3908 char *stop_registers
;
3910 /* These are here because if call_function_by_hand has written some
3911 registers and then decides to call error(), we better not have changed
3916 int breakpoint_proceeded
;
3917 int restore_stack_info
;
3918 int proceed_to_finish
;
3921 static struct inferior_status
*
3922 xmalloc_inferior_status (void)
3924 struct inferior_status
*inf_status
;
3925 inf_status
= xmalloc (sizeof (struct inferior_status
));
3926 inf_status
->stop_registers
= xmalloc (REGISTER_BYTES
);
3927 inf_status
->registers
= xmalloc (REGISTER_BYTES
);
3932 free_inferior_status (struct inferior_status
*inf_status
)
3934 xfree (inf_status
->registers
);
3935 xfree (inf_status
->stop_registers
);
3940 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3943 int size
= REGISTER_RAW_SIZE (regno
);
3944 void *buf
= alloca (size
);
3945 store_signed_integer (buf
, size
, val
);
3946 memcpy (&inf_status
->registers
[REGISTER_BYTE (regno
)], buf
, size
);
3949 /* Save all of the information associated with the inferior<==>gdb
3950 connection. INF_STATUS is a pointer to a "struct inferior_status"
3951 (defined in inferior.h). */
3953 struct inferior_status
*
3954 save_inferior_status (int restore_stack_info
)
3956 struct inferior_status
*inf_status
= xmalloc_inferior_status ();
3958 inf_status
->stop_signal
= stop_signal
;
3959 inf_status
->stop_pc
= stop_pc
;
3960 inf_status
->stop_step
= stop_step
;
3961 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3962 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3963 inf_status
->trap_expected
= trap_expected
;
3964 inf_status
->step_range_start
= step_range_start
;
3965 inf_status
->step_range_end
= step_range_end
;
3966 inf_status
->step_frame_address
= step_frame_address
;
3967 inf_status
->step_over_calls
= step_over_calls
;
3968 inf_status
->stop_after_trap
= stop_after_trap
;
3969 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3970 /* Save original bpstat chain here; replace it with copy of chain.
3971 If caller's caller is walking the chain, they'll be happier if we
3972 hand them back the original chain when restore_inferior_status is
3974 inf_status
->stop_bpstat
= stop_bpstat
;
3975 stop_bpstat
= bpstat_copy (stop_bpstat
);
3976 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3977 inf_status
->restore_stack_info
= restore_stack_info
;
3978 inf_status
->proceed_to_finish
= proceed_to_finish
;
3980 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
3982 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3984 record_selected_frame (&(inf_status
->selected_frame_address
),
3985 &(inf_status
->selected_level
));
3989 struct restore_selected_frame_args
3991 CORE_ADDR frame_address
;
3996 restore_selected_frame (void *args
)
3998 struct restore_selected_frame_args
*fr
=
3999 (struct restore_selected_frame_args
*) args
;
4000 struct frame_info
*frame
;
4001 int level
= fr
->level
;
4003 frame
= find_relative_frame (get_current_frame (), &level
);
4005 /* If inf_status->selected_frame_address is NULL, there was no
4006 previously selected frame. */
4007 if (frame
== NULL
||
4008 /* FRAME_FP (frame) != fr->frame_address || */
4009 /* elz: deleted this check as a quick fix to the problem that
4010 for function called by hand gdb creates no internal frame
4011 structure and the real stack and gdb's idea of stack are
4012 different if nested calls by hands are made.
4014 mvs: this worries me. */
4017 warning ("Unable to restore previously selected frame.\n");
4021 select_frame (frame
, fr
->level
);
4027 restore_inferior_status (struct inferior_status
*inf_status
)
4029 stop_signal
= inf_status
->stop_signal
;
4030 stop_pc
= inf_status
->stop_pc
;
4031 stop_step
= inf_status
->stop_step
;
4032 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4033 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4034 trap_expected
= inf_status
->trap_expected
;
4035 step_range_start
= inf_status
->step_range_start
;
4036 step_range_end
= inf_status
->step_range_end
;
4037 step_frame_address
= inf_status
->step_frame_address
;
4038 step_over_calls
= inf_status
->step_over_calls
;
4039 stop_after_trap
= inf_status
->stop_after_trap
;
4040 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
4041 bpstat_clear (&stop_bpstat
);
4042 stop_bpstat
= inf_status
->stop_bpstat
;
4043 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4044 proceed_to_finish
= inf_status
->proceed_to_finish
;
4046 /* FIXME: Is the restore of stop_registers always needed */
4047 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
4049 /* The inferior can be gone if the user types "print exit(0)"
4050 (and perhaps other times). */
4051 if (target_has_execution
)
4052 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
4054 /* FIXME: If we are being called after stopping in a function which
4055 is called from gdb, we should not be trying to restore the
4056 selected frame; it just prints a spurious error message (The
4057 message is useful, however, in detecting bugs in gdb (like if gdb
4058 clobbers the stack)). In fact, should we be restoring the
4059 inferior status at all in that case? . */
4061 if (target_has_stack
&& inf_status
->restore_stack_info
)
4063 struct restore_selected_frame_args fr
;
4064 fr
.level
= inf_status
->selected_level
;
4065 fr
.frame_address
= inf_status
->selected_frame_address
;
4066 /* The point of catch_errors is that if the stack is clobbered,
4067 walking the stack might encounter a garbage pointer and error()
4068 trying to dereference it. */
4069 if (catch_errors (restore_selected_frame
, &fr
,
4070 "Unable to restore previously selected frame:\n",
4071 RETURN_MASK_ERROR
) == 0)
4072 /* Error in restoring the selected frame. Select the innermost
4076 select_frame (get_current_frame (), 0);
4080 free_inferior_status (inf_status
);
4084 do_restore_inferior_status_cleanup (void *sts
)
4086 restore_inferior_status (sts
);
4090 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4092 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4096 discard_inferior_status (struct inferior_status
*inf_status
)
4098 /* See save_inferior_status for info on stop_bpstat. */
4099 bpstat_clear (&inf_status
->stop_bpstat
);
4100 free_inferior_status (inf_status
);
4103 /* Oft used ptids */
4105 ptid_t minus_one_ptid
;
4107 /* Create a ptid given the necessary PID, LWP, and TID components. */
4110 ptid_build (int pid
, long lwp
, long tid
)
4120 /* Create a ptid from just a pid. */
4123 pid_to_ptid (int pid
)
4125 return ptid_build (pid
, 0, 0);
4128 /* Fetch the pid (process id) component from a ptid. */
4131 ptid_get_pid (ptid_t ptid
)
4136 /* Fetch the lwp (lightweight process) component from a ptid. */
4139 ptid_get_lwp (ptid_t ptid
)
4144 /* Fetch the tid (thread id) component from a ptid. */
4147 ptid_get_tid (ptid_t ptid
)
4152 /* ptid_equal() is used to test equality of two ptids. */
4155 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4157 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4158 && ptid1
.tid
== ptid2
.tid
);
4161 /* restore_inferior_ptid() will be used by the cleanup machinery
4162 to restore the inferior_ptid value saved in a call to
4163 save_inferior_ptid(). */
4166 restore_inferior_ptid (void *arg
)
4168 ptid_t
*saved_ptid_ptr
= arg
;
4169 inferior_ptid
= *saved_ptid_ptr
;
4173 /* Save the value of inferior_ptid so that it may be restored by a
4174 later call to do_cleanups(). Returns the struct cleanup pointer
4175 needed for later doing the cleanup. */
4178 save_inferior_ptid (void)
4180 ptid_t
*saved_ptid_ptr
;
4182 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4183 *saved_ptid_ptr
= inferior_ptid
;
4184 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4191 stop_registers
= xmalloc (REGISTER_BYTES
);
4195 _initialize_infrun (void)
4198 register int numsigs
;
4199 struct cmd_list_element
*c
;
4203 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4204 register_gdbarch_swap (NULL
, 0, build_infrun
);
4206 add_info ("signals", signals_info
,
4207 "What debugger does when program gets various signals.\n\
4208 Specify a signal as argument to print info on that signal only.");
4209 add_info_alias ("handle", "signals", 0);
4211 add_com ("handle", class_run
, handle_command
,
4212 concat ("Specify how to handle a signal.\n\
4213 Args are signals and actions to apply to those signals.\n\
4214 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4215 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4216 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4217 The special arg \"all\" is recognized to mean all signals except those\n\
4218 used by the debugger, typically SIGTRAP and SIGINT.\n",
4219 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4220 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4221 Stop means reenter debugger if this signal happens (implies print).\n\
4222 Print means print a message if this signal happens.\n\
4223 Pass means let program see this signal; otherwise program doesn't know.\n\
4224 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4225 Pass and Stop may be combined.", NULL
));
4228 add_com ("lz", class_info
, signals_info
,
4229 "What debugger does when program gets various signals.\n\
4230 Specify a signal as argument to print info on that signal only.");
4231 add_com ("z", class_run
, xdb_handle_command
,
4232 concat ("Specify how to handle a signal.\n\
4233 Args are signals and actions to apply to those signals.\n\
4234 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4235 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4236 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4237 The special arg \"all\" is recognized to mean all signals except those\n\
4238 used by the debugger, typically SIGTRAP and SIGINT.\n",
4239 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4240 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4241 nopass), \"Q\" (noprint)\n\
4242 Stop means reenter debugger if this signal happens (implies print).\n\
4243 Print means print a message if this signal happens.\n\
4244 Pass means let program see this signal; otherwise program doesn't know.\n\
4245 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4246 Pass and Stop may be combined.", NULL
));
4250 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
4251 "There is no `stop' command, but you can set a hook on `stop'.\n\
4252 This allows you to set a list of commands to be run each time execution\n\
4253 of the program stops.", &cmdlist
);
4255 numsigs
= (int) TARGET_SIGNAL_LAST
;
4256 signal_stop
= (unsigned char *)
4257 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4258 signal_print
= (unsigned char *)
4259 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4260 signal_program
= (unsigned char *)
4261 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4262 for (i
= 0; i
< numsigs
; i
++)
4265 signal_print
[i
] = 1;
4266 signal_program
[i
] = 1;
4269 /* Signals caused by debugger's own actions
4270 should not be given to the program afterwards. */
4271 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4272 signal_program
[TARGET_SIGNAL_INT
] = 0;
4274 /* Signals that are not errors should not normally enter the debugger. */
4275 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4276 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4277 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4278 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4279 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4280 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4281 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4282 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4283 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4284 signal_print
[TARGET_SIGNAL_IO
] = 0;
4285 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4286 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4287 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4288 signal_print
[TARGET_SIGNAL_URG
] = 0;
4289 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4290 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4292 /* These signals are used internally by user-level thread
4293 implementations. (See signal(5) on Solaris.) Like the above
4294 signals, a healthy program receives and handles them as part of
4295 its normal operation. */
4296 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4297 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4298 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4299 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4300 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4301 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4305 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4306 (char *) &stop_on_solib_events
,
4307 "Set stopping for shared library events.\n\
4308 If nonzero, gdb will give control to the user when the dynamic linker\n\
4309 notifies gdb of shared library events. The most common event of interest\n\
4310 to the user would be loading/unloading of a new library.\n",
4315 c
= add_set_enum_cmd ("follow-fork-mode",
4317 follow_fork_mode_kind_names
,
4318 &follow_fork_mode_string
,
4319 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4320 kernel problem. It's also not terribly useful without a GUI to
4321 help the user drive two debuggers. So for now, I'm disabling
4322 the "both" option. */
4323 /* "Set debugger response to a program call of fork \
4325 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4326 parent - the original process is debugged after a fork\n\
4327 child - the new process is debugged after a fork\n\
4328 both - both the parent and child are debugged after a fork\n\
4329 ask - the debugger will ask for one of the above choices\n\
4330 For \"both\", another copy of the debugger will be started to follow\n\
4331 the new child process. The original debugger will continue to follow\n\
4332 the original parent process. To distinguish their prompts, the\n\
4333 debugger copy's prompt will be changed.\n\
4334 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4335 By default, the debugger will follow the parent process.",
4337 "Set debugger response to a program call of fork \
4339 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4340 parent - the original process is debugged after a fork\n\
4341 child - the new process is debugged after a fork\n\
4342 ask - the debugger will ask for one of the above choices\n\
4343 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4344 By default, the debugger will follow the parent process.",
4346 add_show_from_set (c
, &showlist
);
4348 c
= add_set_enum_cmd ("scheduler-locking", class_run
,
4349 scheduler_enums
, /* array of string names */
4350 &scheduler_mode
, /* current mode */
4351 "Set mode for locking scheduler during execution.\n\
4352 off == no locking (threads may preempt at any time)\n\
4353 on == full locking (no thread except the current thread may run)\n\
4354 step == scheduler locked during every single-step operation.\n\
4355 In this mode, no other thread may run during a step command.\n\
4356 Other threads may run while stepping over a function call ('next').",
4359 set_cmd_sfunc (c
, set_schedlock_func
); /* traps on target vector */
4360 add_show_from_set (c
, &showlist
);
4362 c
= add_set_cmd ("step-mode", class_run
,
4363 var_boolean
, (char*) &step_stop_if_no_debug
,
4364 "Set mode of the step operation. When set, doing a step over a\n\
4365 function without debug line information will stop at the first\n\
4366 instruction of that function. Otherwise, the function is skipped and\n\
4367 the step command stops at a different source line.",
4369 add_show_from_set (c
, &showlist
);
4371 /* ptid initializations */
4372 null_ptid
= ptid_build (0, 0, 0);
4373 minus_one_ptid
= ptid_build (-1, 0, 0);
4374 inferior_ptid
= null_ptid
;
4375 target_last_wait_ptid
= minus_one_ptid
;