1 /* Target-struct-independent code to start (run) and stop an inferior process.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 #include "gdb_string.h"
30 #include "breakpoint.h"
34 #include "cli/cli-script.h"
36 #include "gdbthread.h"
45 /* Prototypes for local functions */
47 static void signals_info (char *, int);
49 static void handle_command (char *, int);
51 static void sig_print_info (enum target_signal
);
53 static void sig_print_header (void);
55 static void resume_cleanups (void *);
57 static int hook_stop_stub (void *);
59 static void delete_breakpoint_current_contents (void *);
61 static void set_follow_fork_mode_command (char *arg
, int from_tty
,
62 struct cmd_list_element
* c
);
64 static struct inferior_status
*xmalloc_inferior_status (void);
66 static void free_inferior_status (struct inferior_status
*);
68 static int restore_selected_frame (void *);
70 static void build_infrun (void);
72 static void follow_inferior_fork (int parent_pid
, int child_pid
,
73 int has_forked
, int has_vforked
);
75 static void follow_fork (int parent_pid
, int child_pid
);
77 static void follow_vfork (int parent_pid
, int child_pid
);
79 static void set_schedlock_func (char *args
, int from_tty
,
80 struct cmd_list_element
* c
);
82 struct execution_control_state
;
84 static int currently_stepping (struct execution_control_state
*ecs
);
86 static void xdb_handle_command (char *args
, int from_tty
);
88 void _initialize_infrun (void);
90 int inferior_ignoring_startup_exec_events
= 0;
91 int inferior_ignoring_leading_exec_events
= 0;
93 /* When set, stop the 'step' command if we enter a function which has
94 no line number information. The normal behavior is that we step
95 over such function. */
96 int step_stop_if_no_debug
= 0;
98 /* In asynchronous mode, but simulating synchronous execution. */
100 int sync_execution
= 0;
102 /* wait_for_inferior and normal_stop use this to notify the user
103 when the inferior stopped in a different thread than it had been
106 static ptid_t previous_inferior_ptid
;
108 /* This is true for configurations that may follow through execl() and
109 similar functions. At present this is only true for HP-UX native. */
111 #ifndef MAY_FOLLOW_EXEC
112 #define MAY_FOLLOW_EXEC (0)
115 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
117 /* Dynamic function trampolines are similar to solib trampolines in that they
118 are between the caller and the callee. The difference is that when you
119 enter a dynamic trampoline, you can't determine the callee's address. Some
120 (usually complex) code needs to run in the dynamic trampoline to figure out
121 the callee's address. This macro is usually called twice. First, when we
122 enter the trampoline (looks like a normal function call at that point). It
123 should return the PC of a point within the trampoline where the callee's
124 address is known. Second, when we hit the breakpoint, this routine returns
125 the callee's address. At that point, things proceed as per a step resume
128 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
129 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
132 /* If the program uses ELF-style shared libraries, then calls to
133 functions in shared libraries go through stubs, which live in a
134 table called the PLT (Procedure Linkage Table). The first time the
135 function is called, the stub sends control to the dynamic linker,
136 which looks up the function's real address, patches the stub so
137 that future calls will go directly to the function, and then passes
138 control to the function.
140 If we are stepping at the source level, we don't want to see any of
141 this --- we just want to skip over the stub and the dynamic linker.
142 The simple approach is to single-step until control leaves the
145 However, on some systems (e.g., Red Hat Linux 5.2) the dynamic
146 linker calls functions in the shared C library, so you can't tell
147 from the PC alone whether the dynamic linker is still running. In
148 this case, we use a step-resume breakpoint to get us past the
149 dynamic linker, as if we were using "next" to step over a function
152 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
153 linker code or not. Normally, this means we single-step. However,
154 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
155 address where we can place a step-resume breakpoint to get past the
156 linker's symbol resolution function.
158 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
159 pretty portable way, by comparing the PC against the address ranges
160 of the dynamic linker's sections.
162 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
163 it depends on internal details of the dynamic linker. It's usually
164 not too hard to figure out where to put a breakpoint, but it
165 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
166 sanity checking. If it can't figure things out, returning zero and
167 getting the (possibly confusing) stepping behavior is better than
168 signalling an error, which will obscure the change in the
171 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
172 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
175 #ifndef SKIP_SOLIB_RESOLVER
176 #define SKIP_SOLIB_RESOLVER(pc) 0
179 /* In some shared library schemes, the return path from a shared library
180 call may need to go through a trampoline too. */
182 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
183 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
186 /* This function returns TRUE if pc is the address of an instruction
187 that lies within the dynamic linker (such as the event hook, or the
190 This function must be used only when a dynamic linker event has
191 been caught, and the inferior is being stepped out of the hook, or
192 undefined results are guaranteed. */
194 #ifndef SOLIB_IN_DYNAMIC_LINKER
195 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
198 /* On MIPS16, a function that returns a floating point value may call
199 a library helper function to copy the return value to a floating point
200 register. The IGNORE_HELPER_CALL macro returns non-zero if we
201 should ignore (i.e. step over) this function call. */
202 #ifndef IGNORE_HELPER_CALL
203 #define IGNORE_HELPER_CALL(pc) 0
206 /* On some systems, the PC may be left pointing at an instruction that won't
207 actually be executed. This is usually indicated by a bit in the PSW. If
208 we find ourselves in such a state, then we step the target beyond the
209 nullified instruction before returning control to the user so as to avoid
212 #ifndef INSTRUCTION_NULLIFIED
213 #define INSTRUCTION_NULLIFIED 0
216 /* We can't step off a permanent breakpoint in the ordinary way, because we
217 can't remove it. Instead, we have to advance the PC to the next
218 instruction. This macro should expand to a pointer to a function that
219 does that, or zero if we have no such function. If we don't have a
220 definition for it, we have to report an error. */
221 #ifndef SKIP_PERMANENT_BREAKPOINT
222 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
224 default_skip_permanent_breakpoint (void)
227 The program is stopped at a permanent breakpoint, but GDB does not know\n\
228 how to step past a permanent breakpoint on this architecture. Try using\n\
229 a command like `return' or `jump' to continue execution.");
234 /* Convert the #defines into values. This is temporary until wfi control
235 flow is completely sorted out. */
237 #ifndef HAVE_STEPPABLE_WATCHPOINT
238 #define HAVE_STEPPABLE_WATCHPOINT 0
240 #undef HAVE_STEPPABLE_WATCHPOINT
241 #define HAVE_STEPPABLE_WATCHPOINT 1
244 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
245 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
247 #undef HAVE_NONSTEPPABLE_WATCHPOINT
248 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
251 #ifndef HAVE_CONTINUABLE_WATCHPOINT
252 #define HAVE_CONTINUABLE_WATCHPOINT 0
254 #undef HAVE_CONTINUABLE_WATCHPOINT
255 #define HAVE_CONTINUABLE_WATCHPOINT 1
258 #ifndef CANNOT_STEP_HW_WATCHPOINTS
259 #define CANNOT_STEP_HW_WATCHPOINTS 0
261 #undef CANNOT_STEP_HW_WATCHPOINTS
262 #define CANNOT_STEP_HW_WATCHPOINTS 1
265 /* Tables of how to react to signals; the user sets them. */
267 static unsigned char *signal_stop
;
268 static unsigned char *signal_print
;
269 static unsigned char *signal_program
;
271 #define SET_SIGS(nsigs,sigs,flags) \
273 int signum = (nsigs); \
274 while (signum-- > 0) \
275 if ((sigs)[signum]) \
276 (flags)[signum] = 1; \
279 #define UNSET_SIGS(nsigs,sigs,flags) \
281 int signum = (nsigs); \
282 while (signum-- > 0) \
283 if ((sigs)[signum]) \
284 (flags)[signum] = 0; \
287 /* Value to pass to target_resume() to cause all threads to resume */
289 #define RESUME_ALL (pid_to_ptid (-1))
291 /* Command list pointer for the "stop" placeholder. */
293 static struct cmd_list_element
*stop_command
;
295 /* Nonzero if breakpoints are now inserted in the inferior. */
297 static int breakpoints_inserted
;
299 /* Function inferior was in as of last step command. */
301 static struct symbol
*step_start_function
;
303 /* Nonzero if we are expecting a trace trap and should proceed from it. */
305 static int trap_expected
;
308 /* Nonzero if we want to give control to the user when we're notified
309 of shared library events by the dynamic linker. */
310 static int stop_on_solib_events
;
314 /* Nonzero if the next time we try to continue the inferior, it will
315 step one instruction and generate a spurious trace trap.
316 This is used to compensate for a bug in HP-UX. */
318 static int trap_expected_after_continue
;
321 /* Nonzero means expecting a trace trap
322 and should stop the inferior and return silently when it happens. */
326 /* Nonzero means expecting a trap and caller will handle it themselves.
327 It is used after attach, due to attaching to a process;
328 when running in the shell before the child program has been exec'd;
329 and when running some kinds of remote stuff (FIXME?). */
331 int stop_soon_quietly
;
333 /* Nonzero if proceed is being used for a "finish" command or a similar
334 situation when stop_registers should be saved. */
336 int proceed_to_finish
;
338 /* Save register contents here when about to pop a stack dummy frame,
339 if-and-only-if proceed_to_finish is set.
340 Thus this contains the return value from the called function (assuming
341 values are returned in a register). */
343 char *stop_registers
;
345 /* Nonzero if program stopped due to error trying to insert breakpoints. */
347 static int breakpoints_failed
;
349 /* Nonzero after stop if current stack frame should be printed. */
351 static int stop_print_frame
;
353 static struct breakpoint
*step_resume_breakpoint
= NULL
;
354 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
356 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
357 interactions with an inferior that is running a kernel function
358 (aka, a system call or "syscall"). wait_for_inferior therefore
359 may have a need to know when the inferior is in a syscall. This
360 is a count of the number of inferior threads which are known to
361 currently be running in a syscall. */
362 static int number_of_threads_in_syscalls
;
364 /* This is a cached copy of the pid/waitstatus of the last event
365 returned by target_wait()/target_wait_hook(). This information is
366 returned by get_last_target_status(). */
367 static ptid_t target_last_wait_ptid
;
368 static struct target_waitstatus target_last_waitstatus
;
370 /* This is used to remember when a fork, vfork or exec event
371 was caught by a catchpoint, and thus the event is to be
372 followed at the next resume of the inferior, and not
376 enum target_waitkind kind
;
386 char *execd_pathname
;
390 /* Some platforms don't allow us to do anything meaningful with a
391 vforked child until it has exec'd. Vforked processes on such
392 platforms can only be followed after they've exec'd.
394 When this is set to 0, a vfork can be immediately followed,
395 and an exec can be followed merely as an exec. When this is
396 set to 1, a vfork event has been seen, but cannot be followed
397 until the exec is seen.
399 (In the latter case, inferior_ptid is still the parent of the
400 vfork, and pending_follow.fork_event.child_pid is the child. The
401 appropriate process is followed, according to the setting of
402 follow-fork-mode.) */
403 static int follow_vfork_when_exec
;
405 static const char follow_fork_mode_ask
[] = "ask";
406 static const char follow_fork_mode_both
[] = "both";
407 static const char follow_fork_mode_child
[] = "child";
408 static const char follow_fork_mode_parent
[] = "parent";
410 static const char *follow_fork_mode_kind_names
[] =
412 follow_fork_mode_ask
,
413 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
414 kernel problem. It's also not terribly useful without a GUI to
415 help the user drive two debuggers. So for now, I'm disabling the
417 /* follow_fork_mode_both, */
418 follow_fork_mode_child
,
419 follow_fork_mode_parent
,
423 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
427 follow_inferior_fork (int parent_pid
, int child_pid
, int has_forked
,
430 int followed_parent
= 0;
431 int followed_child
= 0;
433 /* Which process did the user want us to follow? */
434 const char *follow_mode
= follow_fork_mode_string
;
436 /* Or, did the user not know, and want us to ask? */
437 if (follow_fork_mode_string
== follow_fork_mode_ask
)
439 internal_error (__FILE__
, __LINE__
,
440 "follow_inferior_fork: \"ask\" mode not implemented");
441 /* follow_mode = follow_fork_mode_...; */
444 /* If we're to be following the parent, then detach from child_pid.
445 We're already following the parent, so need do nothing explicit
447 if (follow_mode
== follow_fork_mode_parent
)
451 /* We're already attached to the parent, by default. */
453 /* Before detaching from the child, remove all breakpoints from
454 it. (This won't actually modify the breakpoint list, but will
455 physically remove the breakpoints from the child.) */
456 if (!has_vforked
|| !follow_vfork_when_exec
)
458 detach_breakpoints (child_pid
);
459 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
460 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
464 /* Detach from the child. */
467 target_require_detach (child_pid
, "", 1);
470 /* If we're to be following the child, then attach to it, detach
471 from inferior_ptid, and set inferior_ptid to child_pid. */
472 else if (follow_mode
== follow_fork_mode_child
)
474 char child_pid_spelling
[100]; /* Arbitrary length. */
478 /* Before detaching from the parent, detach all breakpoints from
479 the child. But only if we're forking, or if we follow vforks
480 as soon as they happen. (If we're following vforks only when
481 the child has exec'd, then it's very wrong to try to write
482 back the "shadow contents" of inserted breakpoints now -- they
483 belong to the child's pre-exec'd a.out.) */
484 if (!has_vforked
|| !follow_vfork_when_exec
)
486 detach_breakpoints (child_pid
);
489 /* Before detaching from the parent, remove all breakpoints from it. */
490 remove_breakpoints ();
492 /* Also reset the solib inferior hook from the parent. */
493 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
494 SOLIB_REMOVE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
497 /* Detach from the parent. */
499 target_detach (NULL
, 1);
501 /* Attach to the child. */
502 inferior_ptid
= pid_to_ptid (child_pid
);
503 sprintf (child_pid_spelling
, "%d", child_pid
);
506 target_require_attach (child_pid_spelling
, 1);
508 /* Was there a step_resume breakpoint? (There was if the user
509 did a "next" at the fork() call.) If so, explicitly reset its
512 step_resumes are a form of bp that are made to be per-thread.
513 Since we created the step_resume bp when the parent process
514 was being debugged, and now are switching to the child process,
515 from the breakpoint package's viewpoint, that's a switch of
516 "threads". We must update the bp's notion of which thread
517 it is for, or it'll be ignored when it triggers... */
518 if (step_resume_breakpoint
&&
519 (!has_vforked
|| !follow_vfork_when_exec
))
520 breakpoint_re_set_thread (step_resume_breakpoint
);
522 /* Reinsert all breakpoints in the child. (The user may've set
523 breakpoints after catching the fork, in which case those
524 actually didn't get set in the child, but only in the parent.) */
525 if (!has_vforked
|| !follow_vfork_when_exec
)
527 breakpoint_re_set ();
528 insert_breakpoints ();
532 /* If we're to be following both parent and child, then fork ourselves,
533 and attach the debugger clone to the child. */
534 else if (follow_mode
== follow_fork_mode_both
)
536 char pid_suffix
[100]; /* Arbitrary length. */
538 /* Clone ourselves to follow the child. This is the end of our
539 involvement with child_pid; our clone will take it from here... */
541 target_clone_and_follow_inferior (child_pid
, &followed_child
);
542 followed_parent
= !followed_child
;
544 /* We continue to follow the parent. To help distinguish the two
545 debuggers, though, both we and our clone will reset our prompts. */
546 sprintf (pid_suffix
, "[%d] ", PIDGET (inferior_ptid
));
547 set_prompt (strcat (get_prompt (), pid_suffix
));
550 /* The parent and child of a vfork share the same address space.
551 Also, on some targets the order in which vfork and exec events
552 are received for parent in child requires some delicate handling
555 For instance, on ptrace-based HPUX we receive the child's vfork
556 event first, at which time the parent has been suspended by the
557 OS and is essentially untouchable until the child's exit or second
558 exec event arrives. At that time, the parent's vfork event is
559 delivered to us, and that's when we see and decide how to follow
560 the vfork. But to get to that point, we must continue the child
561 until it execs or exits. To do that smoothly, all breakpoints
562 must be removed from the child, in case there are any set between
563 the vfork() and exec() calls. But removing them from the child
564 also removes them from the parent, due to the shared-address-space
565 nature of a vfork'd parent and child. On HPUX, therefore, we must
566 take care to restore the bp's to the parent before we continue it.
567 Else, it's likely that we may not stop in the expected place. (The
568 worst scenario is when the user tries to step over a vfork() call;
569 the step-resume bp must be restored for the step to properly stop
570 in the parent after the call completes!)
572 Sequence of events, as reported to gdb from HPUX:
574 Parent Child Action for gdb to take
575 -------------------------------------------------------
576 1 VFORK Continue child
582 target_post_follow_vfork (parent_pid
,
588 pending_follow
.fork_event
.saw_parent_fork
= 0;
589 pending_follow
.fork_event
.saw_child_fork
= 0;
593 follow_fork (int parent_pid
, int child_pid
)
595 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
599 /* Forward declaration. */
600 static void follow_exec (int, char *);
603 follow_vfork (int parent_pid
, int child_pid
)
605 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
607 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
608 if (pending_follow
.fork_event
.saw_child_exec
609 && (PIDGET (inferior_ptid
) == child_pid
))
611 pending_follow
.fork_event
.saw_child_exec
= 0;
612 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
613 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
614 xfree (pending_follow
.execd_pathname
);
618 /* EXECD_PATHNAME is assumed to be non-NULL. */
621 follow_exec (int pid
, char *execd_pathname
)
624 struct target_ops
*tgt
;
626 if (!may_follow_exec
)
629 /* Did this exec() follow a vfork()? If so, we must follow the
630 vfork now too. Do it before following the exec. */
631 if (follow_vfork_when_exec
&&
632 (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
))
634 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
635 follow_vfork (PIDGET (inferior_ptid
),
636 pending_follow
.fork_event
.child_pid
);
637 follow_vfork_when_exec
= 0;
638 saved_pid
= PIDGET (inferior_ptid
);
640 /* Did we follow the parent? If so, we're done. If we followed
641 the child then we must also follow its exec(). */
642 if (PIDGET (inferior_ptid
) == pending_follow
.fork_event
.parent_pid
)
646 /* This is an exec event that we actually wish to pay attention to.
647 Refresh our symbol table to the newly exec'd program, remove any
650 If there are breakpoints, they aren't really inserted now,
651 since the exec() transformed our inferior into a fresh set
654 We want to preserve symbolic breakpoints on the list, since
655 we have hopes that they can be reset after the new a.out's
656 symbol table is read.
658 However, any "raw" breakpoints must be removed from the list
659 (e.g., the solib bp's), since their address is probably invalid
662 And, we DON'T want to call delete_breakpoints() here, since
663 that may write the bp's "shadow contents" (the instruction
664 value that was overwritten witha TRAP instruction). Since
665 we now have a new a.out, those shadow contents aren't valid. */
666 update_breakpoints_after_exec ();
668 /* If there was one, it's gone now. We cannot truly step-to-next
669 statement through an exec(). */
670 step_resume_breakpoint
= NULL
;
671 step_range_start
= 0;
674 /* If there was one, it's gone now. */
675 through_sigtramp_breakpoint
= NULL
;
677 /* What is this a.out's name? */
678 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
680 /* We've followed the inferior through an exec. Therefore, the
681 inferior has essentially been killed & reborn. */
683 /* First collect the run target in effect. */
684 tgt
= find_run_target ();
685 /* If we can't find one, things are in a very strange state... */
687 error ("Could find run target to save before following exec");
689 gdb_flush (gdb_stdout
);
690 target_mourn_inferior ();
691 inferior_ptid
= pid_to_ptid (saved_pid
);
692 /* Because mourn_inferior resets inferior_ptid. */
695 /* That a.out is now the one to use. */
696 exec_file_attach (execd_pathname
, 0);
698 /* And also is where symbols can be found. */
699 symbol_file_add_main (execd_pathname
, 0);
701 /* Reset the shared library package. This ensures that we get
702 a shlib event when the child reaches "_start", at which point
703 the dld will have had a chance to initialize the child. */
704 #if defined(SOLIB_RESTART)
707 #ifdef SOLIB_CREATE_INFERIOR_HOOK
708 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
711 /* Reinsert all breakpoints. (Those which were symbolic have
712 been reset to the proper address in the new a.out, thanks
713 to symbol_file_command...) */
714 insert_breakpoints ();
716 /* The next resume of this inferior should bring it to the shlib
717 startup breakpoints. (If the user had also set bp's on
718 "main" from the old (parent) process, then they'll auto-
719 matically get reset there in the new process.) */
722 /* Non-zero if we just simulating a single-step. This is needed
723 because we cannot remove the breakpoints in the inferior process
724 until after the `wait' in `wait_for_inferior'. */
725 static int singlestep_breakpoints_inserted_p
= 0;
728 /* Things to clean up if we QUIT out of resume (). */
731 resume_cleanups (void *ignore
)
736 static const char schedlock_off
[] = "off";
737 static const char schedlock_on
[] = "on";
738 static const char schedlock_step
[] = "step";
739 static const char *scheduler_mode
= schedlock_off
;
740 static const char *scheduler_enums
[] =
749 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
751 if (c
->type
== set_cmd
)
752 if (!target_can_lock_scheduler
)
754 scheduler_mode
= schedlock_off
;
755 error ("Target '%s' cannot support this command.",
761 /* Resume the inferior, but allow a QUIT. This is useful if the user
762 wants to interrupt some lengthy single-stepping operation
763 (for child processes, the SIGINT goes to the inferior, and so
764 we get a SIGINT random_signal, but for remote debugging and perhaps
765 other targets, that's not true).
767 STEP nonzero if we should step (zero to continue instead).
768 SIG is the signal to give the inferior (zero for none). */
770 resume (int step
, enum target_signal sig
)
772 int should_resume
= 1;
773 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
776 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
779 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
780 over an instruction that causes a page fault without triggering
781 a hardware watchpoint. The kernel properly notices that it shouldn't
782 stop, because the hardware watchpoint is not triggered, but it forgets
783 the step request and continues the program normally.
784 Work around the problem by removing hardware watchpoints if a step is
785 requested, GDB will check for a hardware watchpoint trigger after the
787 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
788 remove_hw_watchpoints ();
791 /* Normally, by the time we reach `resume', the breakpoints are either
792 removed or inserted, as appropriate. The exception is if we're sitting
793 at a permanent breakpoint; we need to step over it, but permanent
794 breakpoints can't be removed. So we have to test for it here. */
795 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
796 SKIP_PERMANENT_BREAKPOINT ();
798 if (SOFTWARE_SINGLE_STEP_P () && step
)
800 /* Do it the hard way, w/temp breakpoints */
801 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
802 /* ...and don't ask hardware to do it. */
804 /* and do not pull these breakpoints until after a `wait' in
805 `wait_for_inferior' */
806 singlestep_breakpoints_inserted_p
= 1;
809 /* Handle any optimized stores to the inferior NOW... */
810 #ifdef DO_DEFERRED_STORES
814 /* If there were any forks/vforks/execs that were caught and are
815 now to be followed, then do so. */
816 switch (pending_follow
.kind
)
818 case (TARGET_WAITKIND_FORKED
):
819 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
820 follow_fork (PIDGET (inferior_ptid
),
821 pending_follow
.fork_event
.child_pid
);
824 case (TARGET_WAITKIND_VFORKED
):
826 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
828 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
829 follow_vfork (PIDGET (inferior_ptid
),
830 pending_follow
.fork_event
.child_pid
);
832 /* Did we follow the child, but not yet see the child's exec event?
833 If so, then it actually ought to be waiting for us; we respond to
834 parent vfork events. We don't actually want to resume the child
835 in this situation; we want to just get its exec event. */
836 if (!saw_child_exec
&&
837 (PIDGET (inferior_ptid
) == pending_follow
.fork_event
.child_pid
))
842 case (TARGET_WAITKIND_EXECD
):
843 /* If we saw a vfork event but couldn't follow it until we saw
844 an exec, then now might be the time! */
845 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
846 /* follow_exec is called as soon as the exec event is seen. */
853 /* Install inferior's terminal modes. */
854 target_terminal_inferior ();
860 resume_ptid
= RESUME_ALL
; /* Default */
862 if ((step
|| singlestep_breakpoints_inserted_p
) &&
863 !breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
865 /* Stepping past a breakpoint without inserting breakpoints.
866 Make sure only the current thread gets to step, so that
867 other threads don't sneak past breakpoints while they are
870 resume_ptid
= inferior_ptid
;
873 if ((scheduler_mode
== schedlock_on
) ||
874 (scheduler_mode
== schedlock_step
&&
875 (step
|| singlestep_breakpoints_inserted_p
)))
877 /* User-settable 'scheduler' mode requires solo thread resume. */
878 resume_ptid
= inferior_ptid
;
881 #ifdef CANNOT_STEP_BREAKPOINT
882 /* Most targets can step a breakpoint instruction, thus executing it
883 normally. But if this one cannot, just continue and we will hit
885 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
888 target_resume (resume_ptid
, step
, sig
);
891 discard_cleanups (old_cleanups
);
895 /* Clear out all variables saying what to do when inferior is continued.
896 First do this, then set the ones you want, then call `proceed'. */
899 clear_proceed_status (void)
902 step_range_start
= 0;
904 step_frame_address
= 0;
905 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
907 stop_soon_quietly
= 0;
908 proceed_to_finish
= 0;
909 breakpoint_proceeded
= 1; /* We're about to proceed... */
911 /* Discard any remaining commands or status from previous stop. */
912 bpstat_clear (&stop_bpstat
);
915 /* Basic routine for continuing the program in various fashions.
917 ADDR is the address to resume at, or -1 for resume where stopped.
918 SIGGNAL is the signal to give it, or 0 for none,
919 or -1 for act according to how it stopped.
920 STEP is nonzero if should trap after one instruction.
921 -1 means return after that and print nothing.
922 You should probably set various step_... variables
923 before calling here, if you are stepping.
925 You should call clear_proceed_status before calling proceed. */
928 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
933 step_start_function
= find_pc_function (read_pc ());
937 if (addr
== (CORE_ADDR
) -1)
939 /* If there is a breakpoint at the address we will resume at,
940 step one instruction before inserting breakpoints
941 so that we do not stop right away (and report a second
942 hit at this breakpoint). */
944 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
947 #ifndef STEP_SKIPS_DELAY
948 #define STEP_SKIPS_DELAY(pc) (0)
949 #define STEP_SKIPS_DELAY_P (0)
951 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
952 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
953 is slow (it needs to read memory from the target). */
954 if (STEP_SKIPS_DELAY_P
955 && breakpoint_here_p (read_pc () + 4)
956 && STEP_SKIPS_DELAY (read_pc ()))
964 #ifdef PREPARE_TO_PROCEED
965 /* In a multi-threaded task we may select another thread
966 and then continue or step.
968 But if the old thread was stopped at a breakpoint, it
969 will immediately cause another breakpoint stop without
970 any execution (i.e. it will report a breakpoint hit
971 incorrectly). So we must step over it first.
973 PREPARE_TO_PROCEED checks the current thread against the thread
974 that reported the most recent event. If a step-over is required
975 it returns TRUE and sets the current thread to the old thread. */
976 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
981 #endif /* PREPARE_TO_PROCEED */
984 if (trap_expected_after_continue
)
986 /* If (step == 0), a trap will be automatically generated after
987 the first instruction is executed. Force step one
988 instruction to clear this condition. This should not occur
989 if step is nonzero, but it is harmless in that case. */
991 trap_expected_after_continue
= 0;
993 #endif /* HP_OS_BUG */
996 /* We will get a trace trap after one instruction.
997 Continue it automatically and insert breakpoints then. */
1001 int temp
= insert_breakpoints ();
1004 print_sys_errmsg ("insert_breakpoints", temp
);
1005 error ("Cannot insert breakpoints.\n\
1006 The same program may be running in another process,\n\
1007 or you may have requested too many hardware\n\
1008 breakpoints and/or watchpoints.\n");
1011 breakpoints_inserted
= 1;
1014 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1015 stop_signal
= siggnal
;
1016 /* If this signal should not be seen by program,
1017 give it zero. Used for debugging signals. */
1018 else if (!signal_program
[stop_signal
])
1019 stop_signal
= TARGET_SIGNAL_0
;
1021 annotate_starting ();
1023 /* Make sure that output from GDB appears before output from the
1025 gdb_flush (gdb_stdout
);
1027 /* Resume inferior. */
1028 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1030 /* Wait for it to stop (if not standalone)
1031 and in any case decode why it stopped, and act accordingly. */
1032 /* Do this only if we are not using the event loop, or if the target
1033 does not support asynchronous execution. */
1034 if (!event_loop_p
|| !target_can_async_p ())
1036 wait_for_inferior ();
1041 /* Record the pc and sp of the program the last time it stopped.
1042 These are just used internally by wait_for_inferior, but need
1043 to be preserved over calls to it and cleared when the inferior
1045 static CORE_ADDR prev_pc
;
1046 static CORE_ADDR prev_func_start
;
1047 static char *prev_func_name
;
1050 /* Start remote-debugging of a machine over a serial link. */
1055 init_thread_list ();
1056 init_wait_for_inferior ();
1057 stop_soon_quietly
= 1;
1060 /* Always go on waiting for the target, regardless of the mode. */
1061 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1062 indicate to wait_for_inferior that a target should timeout if
1063 nothing is returned (instead of just blocking). Because of this,
1064 targets expecting an immediate response need to, internally, set
1065 things up so that the target_wait() is forced to eventually
1067 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1068 differentiate to its caller what the state of the target is after
1069 the initial open has been performed. Here we're assuming that
1070 the target has stopped. It should be possible to eventually have
1071 target_open() return to the caller an indication that the target
1072 is currently running and GDB state should be set to the same as
1073 for an async run. */
1074 wait_for_inferior ();
1078 /* Initialize static vars when a new inferior begins. */
1081 init_wait_for_inferior (void)
1083 /* These are meaningless until the first time through wait_for_inferior. */
1085 prev_func_start
= 0;
1086 prev_func_name
= NULL
;
1089 trap_expected_after_continue
= 0;
1091 breakpoints_inserted
= 0;
1092 breakpoint_init_inferior (inf_starting
);
1094 /* Don't confuse first call to proceed(). */
1095 stop_signal
= TARGET_SIGNAL_0
;
1097 /* The first resume is not following a fork/vfork/exec. */
1098 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1099 pending_follow
.fork_event
.saw_parent_fork
= 0;
1100 pending_follow
.fork_event
.saw_child_fork
= 0;
1101 pending_follow
.fork_event
.saw_child_exec
= 0;
1103 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1104 number_of_threads_in_syscalls
= 0;
1106 clear_proceed_status ();
1110 delete_breakpoint_current_contents (void *arg
)
1112 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1113 if (*breakpointp
!= NULL
)
1115 delete_breakpoint (*breakpointp
);
1116 *breakpointp
= NULL
;
1120 /* This enum encodes possible reasons for doing a target_wait, so that
1121 wfi can call target_wait in one place. (Ultimately the call will be
1122 moved out of the infinite loop entirely.) */
1126 infwait_normal_state
,
1127 infwait_thread_hop_state
,
1128 infwait_nullified_state
,
1129 infwait_nonstep_watch_state
1132 /* Why did the inferior stop? Used to print the appropriate messages
1133 to the interface from within handle_inferior_event(). */
1134 enum inferior_stop_reason
1136 /* We don't know why. */
1138 /* Step, next, nexti, stepi finished. */
1140 /* Found breakpoint. */
1142 /* Inferior terminated by signal. */
1144 /* Inferior exited. */
1146 /* Inferior received signal, and user asked to be notified. */
1150 /* This structure contains what used to be local variables in
1151 wait_for_inferior. Probably many of them can return to being
1152 locals in handle_inferior_event. */
1154 struct execution_control_state
1156 struct target_waitstatus ws
;
1157 struct target_waitstatus
*wp
;
1160 CORE_ADDR stop_func_start
;
1161 CORE_ADDR stop_func_end
;
1162 char *stop_func_name
;
1163 struct symtab_and_line sal
;
1164 int remove_breakpoints_on_following_step
;
1166 struct symtab
*current_symtab
;
1167 int handling_longjmp
; /* FIXME */
1169 ptid_t saved_inferior_ptid
;
1171 int stepping_through_solib_after_catch
;
1172 bpstat stepping_through_solib_catchpoints
;
1173 int enable_hw_watchpoints_after_wait
;
1174 int stepping_through_sigtramp
;
1175 int new_thread_event
;
1176 struct target_waitstatus tmpstatus
;
1177 enum infwait_states infwait_state
;
1182 void init_execution_control_state (struct execution_control_state
* ecs
);
1184 void handle_inferior_event (struct execution_control_state
* ecs
);
1186 static void check_sigtramp2 (struct execution_control_state
*ecs
);
1187 static void step_into_function (struct execution_control_state
*ecs
);
1188 static void step_over_function (struct execution_control_state
*ecs
);
1189 static void stop_stepping (struct execution_control_state
*ecs
);
1190 static void prepare_to_wait (struct execution_control_state
*ecs
);
1191 static void keep_going (struct execution_control_state
*ecs
);
1192 static void print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
);
1194 /* Wait for control to return from inferior to debugger.
1195 If inferior gets a signal, we may decide to start it up again
1196 instead of returning. That is why there is a loop in this function.
1197 When this function actually returns it means the inferior
1198 should be left stopped and GDB should read more commands. */
1201 wait_for_inferior (void)
1203 struct cleanup
*old_cleanups
;
1204 struct execution_control_state ecss
;
1205 struct execution_control_state
*ecs
;
1207 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1208 &step_resume_breakpoint
);
1209 make_cleanup (delete_breakpoint_current_contents
,
1210 &through_sigtramp_breakpoint
);
1212 /* wfi still stays in a loop, so it's OK just to take the address of
1213 a local to get the ecs pointer. */
1216 /* Fill in with reasonable starting values. */
1217 init_execution_control_state (ecs
);
1219 /* We'll update this if & when we switch to a new thread. */
1220 previous_inferior_ptid
= inferior_ptid
;
1222 overlay_cache_invalid
= 1;
1224 /* We have to invalidate the registers BEFORE calling target_wait
1225 because they can be loaded from the target while in target_wait.
1226 This makes remote debugging a bit more efficient for those
1227 targets that provide critical registers as part of their normal
1228 status mechanism. */
1230 registers_changed ();
1234 if (target_wait_hook
)
1235 ecs
->ptid
= target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
1237 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
1239 /* Now figure out what to do with the result of the result. */
1240 handle_inferior_event (ecs
);
1242 if (!ecs
->wait_some_more
)
1245 do_cleanups (old_cleanups
);
1248 /* Asynchronous version of wait_for_inferior. It is called by the
1249 event loop whenever a change of state is detected on the file
1250 descriptor corresponding to the target. It can be called more than
1251 once to complete a single execution command. In such cases we need
1252 to keep the state in a global variable ASYNC_ECSS. If it is the
1253 last time that this function is called for a single execution
1254 command, then report to the user that the inferior has stopped, and
1255 do the necessary cleanups. */
1257 struct execution_control_state async_ecss
;
1258 struct execution_control_state
*async_ecs
;
1261 fetch_inferior_event (void *client_data
)
1263 static struct cleanup
*old_cleanups
;
1265 async_ecs
= &async_ecss
;
1267 if (!async_ecs
->wait_some_more
)
1269 old_cleanups
= make_exec_cleanup (delete_step_resume_breakpoint
,
1270 &step_resume_breakpoint
);
1271 make_exec_cleanup (delete_breakpoint_current_contents
,
1272 &through_sigtramp_breakpoint
);
1274 /* Fill in with reasonable starting values. */
1275 init_execution_control_state (async_ecs
);
1277 /* We'll update this if & when we switch to a new thread. */
1278 previous_inferior_ptid
= inferior_ptid
;
1280 overlay_cache_invalid
= 1;
1282 /* We have to invalidate the registers BEFORE calling target_wait
1283 because they can be loaded from the target while in target_wait.
1284 This makes remote debugging a bit more efficient for those
1285 targets that provide critical registers as part of their normal
1286 status mechanism. */
1288 registers_changed ();
1291 if (target_wait_hook
)
1292 async_ecs
->ptid
= target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1294 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1296 /* Now figure out what to do with the result of the result. */
1297 handle_inferior_event (async_ecs
);
1299 if (!async_ecs
->wait_some_more
)
1301 /* Do only the cleanups that have been added by this
1302 function. Let the continuations for the commands do the rest,
1303 if there are any. */
1304 do_exec_cleanups (old_cleanups
);
1306 if (step_multi
&& stop_step
)
1307 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1309 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1313 /* Prepare an execution control state for looping through a
1314 wait_for_inferior-type loop. */
1317 init_execution_control_state (struct execution_control_state
*ecs
)
1319 /* ecs->another_trap? */
1320 ecs
->random_signal
= 0;
1321 ecs
->remove_breakpoints_on_following_step
= 0;
1322 ecs
->handling_longjmp
= 0; /* FIXME */
1323 ecs
->update_step_sp
= 0;
1324 ecs
->stepping_through_solib_after_catch
= 0;
1325 ecs
->stepping_through_solib_catchpoints
= NULL
;
1326 ecs
->enable_hw_watchpoints_after_wait
= 0;
1327 ecs
->stepping_through_sigtramp
= 0;
1328 ecs
->sal
= find_pc_line (prev_pc
, 0);
1329 ecs
->current_line
= ecs
->sal
.line
;
1330 ecs
->current_symtab
= ecs
->sal
.symtab
;
1331 ecs
->infwait_state
= infwait_normal_state
;
1332 ecs
->waiton_ptid
= pid_to_ptid (-1);
1333 ecs
->wp
= &(ecs
->ws
);
1336 /* Call this function before setting step_resume_breakpoint, as a
1337 sanity check. There should never be more than one step-resume
1338 breakpoint per thread, so we should never be setting a new
1339 step_resume_breakpoint when one is already active. */
1341 check_for_old_step_resume_breakpoint (void)
1343 if (step_resume_breakpoint
)
1344 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1347 /* Return the cached copy of the last pid/waitstatus returned by
1348 target_wait()/target_wait_hook(). The data is actually cached by
1349 handle_inferior_event(), which gets called immediately after
1350 target_wait()/target_wait_hook(). */
1353 get_last_target_status(ptid_t
*ptidp
, struct target_waitstatus
*status
)
1355 *ptidp
= target_last_wait_ptid
;
1356 *status
= target_last_waitstatus
;
1359 /* Switch thread contexts, maintaining "infrun state". */
1362 context_switch (struct execution_control_state
*ecs
)
1364 /* Caution: it may happen that the new thread (or the old one!)
1365 is not in the thread list. In this case we must not attempt
1366 to "switch context", or we run the risk that our context may
1367 be lost. This may happen as a result of the target module
1368 mishandling thread creation. */
1370 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1371 { /* Perform infrun state context switch: */
1372 /* Save infrun state for the old thread. */
1373 save_infrun_state (inferior_ptid
, prev_pc
,
1374 prev_func_start
, prev_func_name
,
1375 trap_expected
, step_resume_breakpoint
,
1376 through_sigtramp_breakpoint
, step_range_start
,
1377 step_range_end
, step_frame_address
,
1378 ecs
->handling_longjmp
, ecs
->another_trap
,
1379 ecs
->stepping_through_solib_after_catch
,
1380 ecs
->stepping_through_solib_catchpoints
,
1381 ecs
->stepping_through_sigtramp
,
1382 ecs
->current_line
, ecs
->current_symtab
,
1385 /* Load infrun state for the new thread. */
1386 load_infrun_state (ecs
->ptid
, &prev_pc
,
1387 &prev_func_start
, &prev_func_name
,
1388 &trap_expected
, &step_resume_breakpoint
,
1389 &through_sigtramp_breakpoint
, &step_range_start
,
1390 &step_range_end
, &step_frame_address
,
1391 &ecs
->handling_longjmp
, &ecs
->another_trap
,
1392 &ecs
->stepping_through_solib_after_catch
,
1393 &ecs
->stepping_through_solib_catchpoints
,
1394 &ecs
->stepping_through_sigtramp
,
1395 &ecs
->current_line
, &ecs
->current_symtab
,
1398 inferior_ptid
= ecs
->ptid
;
1402 /* Given an execution control state that has been freshly filled in
1403 by an event from the inferior, figure out what it means and take
1404 appropriate action. */
1407 handle_inferior_event (struct execution_control_state
*ecs
)
1410 int stepped_after_stopped_by_watchpoint
;
1412 /* Cache the last pid/waitstatus. */
1413 target_last_wait_ptid
= ecs
->ptid
;
1414 target_last_waitstatus
= *ecs
->wp
;
1416 /* Keep this extra brace for now, minimizes diffs. */
1418 switch (ecs
->infwait_state
)
1420 case infwait_thread_hop_state
:
1421 /* Cancel the waiton_ptid. */
1422 ecs
->waiton_ptid
= pid_to_ptid (-1);
1423 /* Fall thru to the normal_state case. */
1425 case infwait_normal_state
:
1426 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1427 is serviced in this loop, below. */
1428 if (ecs
->enable_hw_watchpoints_after_wait
)
1430 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1431 ecs
->enable_hw_watchpoints_after_wait
= 0;
1433 stepped_after_stopped_by_watchpoint
= 0;
1436 case infwait_nullified_state
:
1439 case infwait_nonstep_watch_state
:
1440 insert_breakpoints ();
1442 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1443 handle things like signals arriving and other things happening
1444 in combination correctly? */
1445 stepped_after_stopped_by_watchpoint
= 1;
1448 ecs
->infwait_state
= infwait_normal_state
;
1450 flush_cached_frames ();
1452 /* If it's a new process, add it to the thread database */
1454 ecs
->new_thread_event
= (! ptid_equal (ecs
->ptid
, inferior_ptid
)
1455 && ! in_thread_list (ecs
->ptid
));
1457 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1458 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1459 && ecs
->new_thread_event
)
1461 add_thread (ecs
->ptid
);
1463 ui_out_text (uiout
, "[New ");
1464 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->ptid
));
1465 ui_out_text (uiout
, "]\n");
1468 /* NOTE: This block is ONLY meant to be invoked in case of a
1469 "thread creation event"! If it is invoked for any other
1470 sort of event (such as a new thread landing on a breakpoint),
1471 the event will be discarded, which is almost certainly
1474 To avoid this, the low-level module (eg. target_wait)
1475 should call in_thread_list and add_thread, so that the
1476 new thread is known by the time we get here. */
1478 /* We may want to consider not doing a resume here in order
1479 to give the user a chance to play with the new thread.
1480 It might be good to make that a user-settable option. */
1482 /* At this point, all threads are stopped (happens
1483 automatically in either the OS or the native code).
1484 Therefore we need to continue all threads in order to
1487 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1488 prepare_to_wait (ecs
);
1493 switch (ecs
->ws
.kind
)
1495 case TARGET_WAITKIND_LOADED
:
1496 /* Ignore gracefully during startup of the inferior, as it
1497 might be the shell which has just loaded some objects,
1498 otherwise add the symbols for the newly loaded objects. */
1500 if (!stop_soon_quietly
)
1502 /* Remove breakpoints, SOLIB_ADD might adjust
1503 breakpoint addresses via breakpoint_re_set. */
1504 if (breakpoints_inserted
)
1505 remove_breakpoints ();
1507 /* Check for any newly added shared libraries if we're
1508 supposed to be adding them automatically. Switch
1509 terminal for any messages produced by
1510 breakpoint_re_set. */
1511 target_terminal_ours_for_output ();
1512 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
1513 target_terminal_inferior ();
1515 /* Reinsert breakpoints and continue. */
1516 if (breakpoints_inserted
)
1517 insert_breakpoints ();
1520 resume (0, TARGET_SIGNAL_0
);
1521 prepare_to_wait (ecs
);
1524 case TARGET_WAITKIND_SPURIOUS
:
1525 resume (0, TARGET_SIGNAL_0
);
1526 prepare_to_wait (ecs
);
1529 case TARGET_WAITKIND_EXITED
:
1530 target_terminal_ours (); /* Must do this before mourn anyway */
1531 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1533 /* Record the exit code in the convenience variable $_exitcode, so
1534 that the user can inspect this again later. */
1535 set_internalvar (lookup_internalvar ("_exitcode"),
1536 value_from_longest (builtin_type_int
,
1537 (LONGEST
) ecs
->ws
.value
.integer
));
1538 gdb_flush (gdb_stdout
);
1539 target_mourn_inferior ();
1540 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1541 stop_print_frame
= 0;
1542 stop_stepping (ecs
);
1545 case TARGET_WAITKIND_SIGNALLED
:
1546 stop_print_frame
= 0;
1547 stop_signal
= ecs
->ws
.value
.sig
;
1548 target_terminal_ours (); /* Must do this before mourn anyway */
1550 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1551 reach here unless the inferior is dead. However, for years
1552 target_kill() was called here, which hints that fatal signals aren't
1553 really fatal on some systems. If that's true, then some changes
1555 target_mourn_inferior ();
1557 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1558 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1559 stop_stepping (ecs
);
1562 /* The following are the only cases in which we keep going;
1563 the above cases end in a continue or goto. */
1564 case TARGET_WAITKIND_FORKED
:
1565 stop_signal
= TARGET_SIGNAL_TRAP
;
1566 pending_follow
.kind
= ecs
->ws
.kind
;
1568 /* Ignore fork events reported for the parent; we're only
1569 interested in reacting to forks of the child. Note that
1570 we expect the child's fork event to be available if we
1571 waited for it now. */
1572 if (ptid_equal (inferior_ptid
, ecs
->ptid
))
1574 pending_follow
.fork_event
.saw_parent_fork
= 1;
1575 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1576 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1577 prepare_to_wait (ecs
);
1582 pending_follow
.fork_event
.saw_child_fork
= 1;
1583 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1584 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1587 stop_pc
= read_pc_pid (ecs
->ptid
);
1588 ecs
->saved_inferior_ptid
= inferior_ptid
;
1589 inferior_ptid
= ecs
->ptid
;
1590 /* The second argument of bpstat_stop_status is meant to help
1591 distinguish between a breakpoint trap and a singlestep trap.
1592 This is only important on targets where DECR_PC_AFTER_BREAK
1593 is non-zero. The prev_pc test is meant to distinguish between
1594 singlestepping a trap instruction, and singlestepping thru a
1595 jump to the instruction following a trap instruction. */
1597 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1598 currently_stepping (ecs
) &&
1600 stop_pc
- DECR_PC_AFTER_BREAK
);
1601 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1602 inferior_ptid
= ecs
->saved_inferior_ptid
;
1603 goto process_event_stop_test
;
1605 /* If this a platform which doesn't allow a debugger to touch a
1606 vfork'd inferior until after it exec's, then we'd best keep
1607 our fingers entirely off the inferior, other than continuing
1608 it. This has the unfortunate side-effect that catchpoints
1609 of vforks will be ignored. But since the platform doesn't
1610 allow the inferior be touched at vfork time, there's really
1612 case TARGET_WAITKIND_VFORKED
:
1613 stop_signal
= TARGET_SIGNAL_TRAP
;
1614 pending_follow
.kind
= ecs
->ws
.kind
;
1616 /* Is this a vfork of the parent? If so, then give any
1617 vfork catchpoints a chance to trigger now. (It's
1618 dangerous to do so if the child canot be touched until
1619 it execs, and the child has not yet exec'd. We probably
1620 should warn the user to that effect when the catchpoint
1622 if (ptid_equal (ecs
->ptid
, inferior_ptid
))
1624 pending_follow
.fork_event
.saw_parent_fork
= 1;
1625 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1626 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1629 /* If we've seen the child's vfork event but cannot really touch
1630 the child until it execs, then we must continue the child now.
1631 Else, give any vfork catchpoints a chance to trigger now. */
1634 pending_follow
.fork_event
.saw_child_fork
= 1;
1635 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1636 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1637 target_post_startup_inferior (
1638 pid_to_ptid (pending_follow
.fork_event
.child_pid
));
1639 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1640 if (follow_vfork_when_exec
)
1642 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1643 prepare_to_wait (ecs
);
1648 stop_pc
= read_pc ();
1649 /* The second argument of bpstat_stop_status is meant to help
1650 distinguish between a breakpoint trap and a singlestep trap.
1651 This is only important on targets where DECR_PC_AFTER_BREAK
1652 is non-zero. The prev_pc test is meant to distinguish between
1653 singlestepping a trap instruction, and singlestepping thru a
1654 jump to the instruction following a trap instruction. */
1656 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1657 currently_stepping (ecs
) &&
1659 stop_pc
- DECR_PC_AFTER_BREAK
);
1660 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1661 goto process_event_stop_test
;
1663 case TARGET_WAITKIND_EXECD
:
1664 stop_signal
= TARGET_SIGNAL_TRAP
;
1666 /* Is this a target which reports multiple exec events per actual
1667 call to exec()? (HP-UX using ptrace does, for example.) If so,
1668 ignore all but the last one. Just resume the exec'r, and wait
1669 for the next exec event. */
1670 if (inferior_ignoring_leading_exec_events
)
1672 inferior_ignoring_leading_exec_events
--;
1673 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1674 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.parent_pid
);
1675 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1676 prepare_to_wait (ecs
);
1679 inferior_ignoring_leading_exec_events
=
1680 target_reported_exec_events_per_exec_call () - 1;
1682 pending_follow
.execd_pathname
=
1683 savestring (ecs
->ws
.value
.execd_pathname
,
1684 strlen (ecs
->ws
.value
.execd_pathname
));
1686 /* Did inferior_ptid exec, or did a (possibly not-yet-followed)
1687 child of a vfork exec?
1689 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1690 HP-UX, events associated with a vforking inferior come in
1691 threes: a vfork event for the child (always first), followed
1692 a vfork event for the parent and an exec event for the child.
1693 The latter two can come in either order.
1695 If we get the parent vfork event first, life's good: We follow
1696 either the parent or child, and then the child's exec event is
1699 But if we get the child's exec event first, then we delay
1700 responding to it until we handle the parent's vfork. Because,
1701 otherwise we can't satisfy a "catch vfork". */
1702 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1704 pending_follow
.fork_event
.saw_child_exec
= 1;
1706 /* On some targets, the child must be resumed before
1707 the parent vfork event is delivered. A single-step
1709 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1710 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1711 /* We expect the parent vfork event to be available now. */
1712 prepare_to_wait (ecs
);
1716 /* This causes the eventpoints and symbol table to be reset. Must
1717 do this now, before trying to determine whether to stop. */
1718 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1719 xfree (pending_follow
.execd_pathname
);
1721 stop_pc
= read_pc_pid (ecs
->ptid
);
1722 ecs
->saved_inferior_ptid
= inferior_ptid
;
1723 inferior_ptid
= ecs
->ptid
;
1724 /* The second argument of bpstat_stop_status is meant to help
1725 distinguish between a breakpoint trap and a singlestep trap.
1726 This is only important on targets where DECR_PC_AFTER_BREAK
1727 is non-zero. The prev_pc test is meant to distinguish between
1728 singlestepping a trap instruction, and singlestepping thru a
1729 jump to the instruction following a trap instruction. */
1731 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1732 currently_stepping (ecs
) &&
1734 stop_pc
- DECR_PC_AFTER_BREAK
);
1735 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1736 inferior_ptid
= ecs
->saved_inferior_ptid
;
1737 goto process_event_stop_test
;
1739 /* These syscall events are returned on HP-UX, as part of its
1740 implementation of page-protection-based "hardware" watchpoints.
1741 HP-UX has unfortunate interactions between page-protections and
1742 some system calls. Our solution is to disable hardware watches
1743 when a system call is entered, and reenable them when the syscall
1744 completes. The downside of this is that we may miss the precise
1745 point at which a watched piece of memory is modified. "Oh well."
1747 Note that we may have multiple threads running, which may each
1748 enter syscalls at roughly the same time. Since we don't have a
1749 good notion currently of whether a watched piece of memory is
1750 thread-private, we'd best not have any page-protections active
1751 when any thread is in a syscall. Thus, we only want to reenable
1752 hardware watches when no threads are in a syscall.
1754 Also, be careful not to try to gather much state about a thread
1755 that's in a syscall. It's frequently a losing proposition. */
1756 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1757 number_of_threads_in_syscalls
++;
1758 if (number_of_threads_in_syscalls
== 1)
1760 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1762 resume (0, TARGET_SIGNAL_0
);
1763 prepare_to_wait (ecs
);
1766 /* Before examining the threads further, step this thread to
1767 get it entirely out of the syscall. (We get notice of the
1768 event when the thread is just on the verge of exiting a
1769 syscall. Stepping one instruction seems to get it back
1772 Note that although the logical place to reenable h/w watches
1773 is here, we cannot. We cannot reenable them before stepping
1774 the thread (this causes the next wait on the thread to hang).
1776 Nor can we enable them after stepping until we've done a wait.
1777 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1778 here, which will be serviced immediately after the target
1780 case TARGET_WAITKIND_SYSCALL_RETURN
:
1781 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1783 if (number_of_threads_in_syscalls
> 0)
1785 number_of_threads_in_syscalls
--;
1786 ecs
->enable_hw_watchpoints_after_wait
=
1787 (number_of_threads_in_syscalls
== 0);
1789 prepare_to_wait (ecs
);
1792 case TARGET_WAITKIND_STOPPED
:
1793 stop_signal
= ecs
->ws
.value
.sig
;
1796 /* We had an event in the inferior, but we are not interested
1797 in handling it at this level. The lower layers have already
1798 done what needs to be done, if anything. This case can
1799 occur only when the target is async or extended-async. One
1800 of the circumstamces for this to happen is when the
1801 inferior produces output for the console. The inferior has
1802 not stopped, and we are ignoring the event. */
1803 case TARGET_WAITKIND_IGNORE
:
1804 ecs
->wait_some_more
= 1;
1808 /* We may want to consider not doing a resume here in order to give
1809 the user a chance to play with the new thread. It might be good
1810 to make that a user-settable option. */
1812 /* At this point, all threads are stopped (happens automatically in
1813 either the OS or the native code). Therefore we need to continue
1814 all threads in order to make progress. */
1815 if (ecs
->new_thread_event
)
1817 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1818 prepare_to_wait (ecs
);
1822 stop_pc
= read_pc_pid (ecs
->ptid
);
1824 /* See if a thread hit a thread-specific breakpoint that was meant for
1825 another thread. If so, then step that thread past the breakpoint,
1828 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1830 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1831 ecs
->random_signal
= 0;
1832 else if (breakpoints_inserted
1833 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1835 ecs
->random_signal
= 0;
1836 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1841 /* Saw a breakpoint, but it was hit by the wrong thread.
1843 if (DECR_PC_AFTER_BREAK
)
1844 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->ptid
);
1846 remove_status
= remove_breakpoints ();
1847 /* Did we fail to remove breakpoints? If so, try
1848 to set the PC past the bp. (There's at least
1849 one situation in which we can fail to remove
1850 the bp's: On HP-UX's that use ttrace, we can't
1851 change the address space of a vforking child
1852 process until the child exits (well, okay, not
1853 then either :-) or execs. */
1854 if (remove_status
!= 0)
1856 /* FIXME! This is obviously non-portable! */
1857 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4,
1859 /* We need to restart all the threads now,
1860 * unles we're running in scheduler-locked mode.
1861 * Use currently_stepping to determine whether to
1864 /* FIXME MVS: is there any reason not to call resume()? */
1865 if (scheduler_mode
== schedlock_on
)
1866 target_resume (ecs
->ptid
,
1867 currently_stepping (ecs
),
1870 target_resume (RESUME_ALL
,
1871 currently_stepping (ecs
),
1873 prepare_to_wait (ecs
);
1878 breakpoints_inserted
= 0;
1879 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
1880 context_switch (ecs
);
1881 ecs
->waiton_ptid
= ecs
->ptid
;
1882 ecs
->wp
= &(ecs
->ws
);
1883 ecs
->another_trap
= 1;
1885 ecs
->infwait_state
= infwait_thread_hop_state
;
1887 registers_changed ();
1894 ecs
->random_signal
= 1;
1896 /* See if something interesting happened to the non-current thread. If
1897 so, then switch to that thread, and eventually give control back to
1900 Note that if there's any kind of pending follow (i.e., of a fork,
1901 vfork or exec), we don't want to do this now. Rather, we'll let
1902 the next resume handle it. */
1903 if (! ptid_equal (ecs
->ptid
, inferior_ptid
) &&
1904 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1908 /* If it's a random signal for a non-current thread, notify user
1909 if he's expressed an interest. */
1910 if (ecs
->random_signal
1911 && signal_print
[stop_signal
])
1913 /* ??rehrauer: I don't understand the rationale for this code. If the
1914 inferior will stop as a result of this signal, then the act of handling
1915 the stop ought to print a message that's couches the stoppage in user
1916 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1917 won't stop as a result of the signal -- i.e., if the signal is merely
1918 a side-effect of something GDB's doing "under the covers" for the
1919 user, such as stepping threads over a breakpoint they shouldn't stop
1920 for -- then the message seems to be a serious annoyance at best.
1922 For now, remove the message altogether. */
1925 target_terminal_ours_for_output ();
1926 printf_filtered ("\nProgram received signal %s, %s.\n",
1927 target_signal_to_name (stop_signal
),
1928 target_signal_to_string (stop_signal
));
1929 gdb_flush (gdb_stdout
);
1933 /* If it's not SIGTRAP and not a signal we want to stop for, then
1934 continue the thread. */
1936 if (stop_signal
!= TARGET_SIGNAL_TRAP
1937 && !signal_stop
[stop_signal
])
1940 target_terminal_inferior ();
1942 /* Clear the signal if it should not be passed. */
1943 if (signal_program
[stop_signal
] == 0)
1944 stop_signal
= TARGET_SIGNAL_0
;
1946 target_resume (ecs
->ptid
, 0, stop_signal
);
1947 prepare_to_wait (ecs
);
1951 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1952 and fall into the rest of wait_for_inferior(). */
1954 context_switch (ecs
);
1957 context_hook (pid_to_thread_id (ecs
->ptid
));
1959 flush_cached_frames ();
1962 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1964 /* Pull the single step breakpoints out of the target. */
1965 SOFTWARE_SINGLE_STEP (0, 0);
1966 singlestep_breakpoints_inserted_p
= 0;
1969 /* If PC is pointing at a nullified instruction, then step beyond
1970 it so that the user won't be confused when GDB appears to be ready
1973 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1974 if (INSTRUCTION_NULLIFIED
)
1976 registers_changed ();
1977 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1979 /* We may have received a signal that we want to pass to
1980 the inferior; therefore, we must not clobber the waitstatus
1983 ecs
->infwait_state
= infwait_nullified_state
;
1984 ecs
->waiton_ptid
= ecs
->ptid
;
1985 ecs
->wp
= &(ecs
->tmpstatus
);
1986 prepare_to_wait (ecs
);
1990 /* It may not be necessary to disable the watchpoint to stop over
1991 it. For example, the PA can (with some kernel cooperation)
1992 single step over a watchpoint without disabling the watchpoint. */
1993 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1996 prepare_to_wait (ecs
);
2000 /* It is far more common to need to disable a watchpoint to step
2001 the inferior over it. FIXME. What else might a debug
2002 register or page protection watchpoint scheme need here? */
2003 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2005 /* At this point, we are stopped at an instruction which has
2006 attempted to write to a piece of memory under control of
2007 a watchpoint. The instruction hasn't actually executed
2008 yet. If we were to evaluate the watchpoint expression
2009 now, we would get the old value, and therefore no change
2010 would seem to have occurred.
2012 In order to make watchpoints work `right', we really need
2013 to complete the memory write, and then evaluate the
2014 watchpoint expression. The following code does that by
2015 removing the watchpoint (actually, all watchpoints and
2016 breakpoints), single-stepping the target, re-inserting
2017 watchpoints, and then falling through to let normal
2018 single-step processing handle proceed. Since this
2019 includes evaluating watchpoints, things will come to a
2020 stop in the correct manner. */
2022 if (DECR_PC_AFTER_BREAK
)
2023 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
2025 remove_breakpoints ();
2026 registers_changed ();
2027 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
2029 ecs
->waiton_ptid
= ecs
->ptid
;
2030 ecs
->wp
= &(ecs
->ws
);
2031 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2032 prepare_to_wait (ecs
);
2036 /* It may be possible to simply continue after a watchpoint. */
2037 if (HAVE_CONTINUABLE_WATCHPOINT
)
2038 STOPPED_BY_WATCHPOINT (ecs
->ws
);
2040 ecs
->stop_func_start
= 0;
2041 ecs
->stop_func_end
= 0;
2042 ecs
->stop_func_name
= 0;
2043 /* Don't care about return value; stop_func_start and stop_func_name
2044 will both be 0 if it doesn't work. */
2045 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2046 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2047 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
2048 ecs
->another_trap
= 0;
2049 bpstat_clear (&stop_bpstat
);
2051 stop_stack_dummy
= 0;
2052 stop_print_frame
= 1;
2053 ecs
->random_signal
= 0;
2054 stopped_by_random_signal
= 0;
2055 breakpoints_failed
= 0;
2057 /* Look at the cause of the stop, and decide what to do.
2058 The alternatives are:
2059 1) break; to really stop and return to the debugger,
2060 2) drop through to start up again
2061 (set ecs->another_trap to 1 to single step once)
2062 3) set ecs->random_signal to 1, and the decision between 1 and 2
2063 will be made according to the signal handling tables. */
2065 /* First, distinguish signals caused by the debugger from signals
2066 that have to do with the program's own actions.
2067 Note that breakpoint insns may cause SIGTRAP or SIGILL
2068 or SIGEMT, depending on the operating system version.
2069 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2070 and change it to SIGTRAP. */
2072 if (stop_signal
== TARGET_SIGNAL_TRAP
2073 || (breakpoints_inserted
&&
2074 (stop_signal
== TARGET_SIGNAL_ILL
2075 || stop_signal
== TARGET_SIGNAL_EMT
2077 || stop_soon_quietly
)
2079 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2081 stop_print_frame
= 0;
2082 stop_stepping (ecs
);
2085 if (stop_soon_quietly
)
2087 stop_stepping (ecs
);
2091 /* Don't even think about breakpoints
2092 if just proceeded over a breakpoint.
2094 However, if we are trying to proceed over a breakpoint
2095 and end up in sigtramp, then through_sigtramp_breakpoint
2096 will be set and we should check whether we've hit the
2098 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2099 && through_sigtramp_breakpoint
== NULL
)
2100 bpstat_clear (&stop_bpstat
);
2103 /* See if there is a breakpoint at the current PC. */
2105 /* The second argument of bpstat_stop_status is meant to help
2106 distinguish between a breakpoint trap and a singlestep trap.
2107 This is only important on targets where DECR_PC_AFTER_BREAK
2108 is non-zero. The prev_pc test is meant to distinguish between
2109 singlestepping a trap instruction, and singlestepping thru a
2110 jump to the instruction following a trap instruction. */
2112 stop_bpstat
= bpstat_stop_status
2114 /* Pass TRUE if our reason for stopping is something other
2115 than hitting a breakpoint. We do this by checking that
2116 1) stepping is going on and 2) we didn't hit a breakpoint
2117 in a signal handler without an intervening stop in
2118 sigtramp, which is detected by a new stack pointer value
2119 below any usual function calling stack adjustments. */
2120 (currently_stepping (ecs
)
2121 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
2123 && INNER_THAN (read_sp (), (step_sp
- 16))))
2125 /* Following in case break condition called a
2127 stop_print_frame
= 1;
2130 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2132 = !(bpstat_explains_signal (stop_bpstat
)
2134 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2135 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2136 FRAME_FP (get_current_frame ())))
2137 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2142 = !(bpstat_explains_signal (stop_bpstat
)
2143 /* End of a stack dummy. Some systems (e.g. Sony
2144 news) give another signal besides SIGTRAP, so
2145 check here as well as above. */
2146 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2147 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2148 FRAME_FP (get_current_frame ())))
2150 if (!ecs
->random_signal
)
2151 stop_signal
= TARGET_SIGNAL_TRAP
;
2155 /* When we reach this point, we've pretty much decided
2156 that the reason for stopping must've been a random
2157 (unexpected) signal. */
2160 ecs
->random_signal
= 1;
2161 /* If a fork, vfork or exec event was seen, then there are two
2162 possible responses we can make:
2164 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2165 then we must stop now and issue a prompt. We will resume
2166 the inferior when the user tells us to.
2167 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2168 then we must resume the inferior now and keep checking.
2170 In either case, we must take appropriate steps to "follow" the
2171 the fork/vfork/exec when the inferior is resumed. For example,
2172 if follow-fork-mode is "child", then we must detach from the
2173 parent inferior and follow the new child inferior.
2175 In either case, setting pending_follow causes the next resume()
2176 to take the appropriate following action. */
2177 process_event_stop_test
:
2178 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2180 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2183 stop_signal
= TARGET_SIGNAL_0
;
2188 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2190 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2192 stop_signal
= TARGET_SIGNAL_0
;
2197 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2199 pending_follow
.kind
= ecs
->ws
.kind
;
2200 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2203 stop_signal
= TARGET_SIGNAL_0
;
2209 /* For the program's own signals, act according to
2210 the signal handling tables. */
2212 if (ecs
->random_signal
)
2214 /* Signal not for debugging purposes. */
2217 stopped_by_random_signal
= 1;
2219 if (signal_print
[stop_signal
])
2222 target_terminal_ours_for_output ();
2223 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2225 if (signal_stop
[stop_signal
])
2227 stop_stepping (ecs
);
2230 /* If not going to stop, give terminal back
2231 if we took it away. */
2233 target_terminal_inferior ();
2235 /* Clear the signal if it should not be passed. */
2236 if (signal_program
[stop_signal
] == 0)
2237 stop_signal
= TARGET_SIGNAL_0
;
2239 /* I'm not sure whether this needs to be check_sigtramp2 or
2240 whether it could/should be keep_going.
2242 This used to jump to step_over_function if we are stepping,
2245 Suppose the user does a `next' over a function call, and while
2246 that call is in progress, the inferior receives a signal for
2247 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2248 that case, when we reach this point, there is already a
2249 step-resume breakpoint established, right where it should be:
2250 immediately after the function call the user is "next"-ing
2251 over. If we call step_over_function now, two bad things
2254 - we'll create a new breakpoint, at wherever the current
2255 frame's return address happens to be. That could be
2256 anywhere, depending on what function call happens to be on
2257 the top of the stack at that point. Point is, it's probably
2258 not where we need it.
2260 - the existing step-resume breakpoint (which is at the correct
2261 address) will get orphaned: step_resume_breakpoint will point
2262 to the new breakpoint, and the old step-resume breakpoint
2263 will never be cleaned up.
2265 The old behavior was meant to help HP-UX single-step out of
2266 sigtramps. It would place the new breakpoint at prev_pc, which
2267 was certainly wrong. I don't know the details there, so fixing
2268 this probably breaks that. As with anything else, it's up to
2269 the HP-UX maintainer to furnish a fix that doesn't break other
2270 platforms. --JimB, 20 May 1999 */
2271 check_sigtramp2 (ecs
);
2276 /* Handle cases caused by hitting a breakpoint. */
2278 CORE_ADDR jmp_buf_pc
;
2279 struct bpstat_what what
;
2281 what
= bpstat_what (stop_bpstat
);
2283 if (what
.call_dummy
)
2285 stop_stack_dummy
= 1;
2287 trap_expected_after_continue
= 1;
2291 switch (what
.main_action
)
2293 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2294 /* If we hit the breakpoint at longjmp, disable it for the
2295 duration of this command. Then, install a temporary
2296 breakpoint at the target of the jmp_buf. */
2297 disable_longjmp_breakpoint ();
2298 remove_breakpoints ();
2299 breakpoints_inserted
= 0;
2300 if (!GET_LONGJMP_TARGET_P ()
2301 || !GET_LONGJMP_TARGET (&jmp_buf_pc
))
2307 /* Need to blow away step-resume breakpoint, as it
2308 interferes with us */
2309 if (step_resume_breakpoint
!= NULL
)
2311 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2313 /* Not sure whether we need to blow this away too, but probably
2314 it is like the step-resume breakpoint. */
2315 if (through_sigtramp_breakpoint
!= NULL
)
2317 delete_breakpoint (through_sigtramp_breakpoint
);
2318 through_sigtramp_breakpoint
= NULL
;
2322 /* FIXME - Need to implement nested temporary breakpoints */
2323 if (step_over_calls
> 0)
2324 set_longjmp_resume_breakpoint (jmp_buf_pc
,
2325 get_current_frame ());
2328 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2329 ecs
->handling_longjmp
= 1; /* FIXME */
2333 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2334 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2335 remove_breakpoints ();
2336 breakpoints_inserted
= 0;
2338 /* FIXME - Need to implement nested temporary breakpoints */
2340 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2341 step_frame_address
)))
2343 ecs
->another_trap
= 1;
2348 disable_longjmp_breakpoint ();
2349 ecs
->handling_longjmp
= 0; /* FIXME */
2350 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2352 /* else fallthrough */
2354 case BPSTAT_WHAT_SINGLE
:
2355 if (breakpoints_inserted
)
2357 remove_breakpoints ();
2359 breakpoints_inserted
= 0;
2360 ecs
->another_trap
= 1;
2361 /* Still need to check other stuff, at least the case
2362 where we are stepping and step out of the right range. */
2365 case BPSTAT_WHAT_STOP_NOISY
:
2366 stop_print_frame
= 1;
2368 /* We are about to nuke the step_resume_breakpoint and
2369 through_sigtramp_breakpoint via the cleanup chain, so
2370 no need to worry about it here. */
2372 stop_stepping (ecs
);
2375 case BPSTAT_WHAT_STOP_SILENT
:
2376 stop_print_frame
= 0;
2378 /* We are about to nuke the step_resume_breakpoint and
2379 through_sigtramp_breakpoint via the cleanup chain, so
2380 no need to worry about it here. */
2382 stop_stepping (ecs
);
2385 case BPSTAT_WHAT_STEP_RESUME
:
2386 /* This proably demands a more elegant solution, but, yeah
2389 This function's use of the simple variable
2390 step_resume_breakpoint doesn't seem to accomodate
2391 simultaneously active step-resume bp's, although the
2392 breakpoint list certainly can.
2394 If we reach here and step_resume_breakpoint is already
2395 NULL, then apparently we have multiple active
2396 step-resume bp's. We'll just delete the breakpoint we
2397 stopped at, and carry on.
2399 Correction: what the code currently does is delete a
2400 step-resume bp, but it makes no effort to ensure that
2401 the one deleted is the one currently stopped at. MVS */
2403 if (step_resume_breakpoint
== NULL
)
2405 step_resume_breakpoint
=
2406 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2408 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2411 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2412 if (through_sigtramp_breakpoint
)
2413 delete_breakpoint (through_sigtramp_breakpoint
);
2414 through_sigtramp_breakpoint
= NULL
;
2416 /* If were waiting for a trap, hitting the step_resume_break
2417 doesn't count as getting it. */
2419 ecs
->another_trap
= 1;
2422 case BPSTAT_WHAT_CHECK_SHLIBS
:
2423 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2426 /* Remove breakpoints, we eventually want to step over the
2427 shlib event breakpoint, and SOLIB_ADD might adjust
2428 breakpoint addresses via breakpoint_re_set. */
2429 if (breakpoints_inserted
)
2430 remove_breakpoints ();
2431 breakpoints_inserted
= 0;
2433 /* Check for any newly added shared libraries if we're
2434 supposed to be adding them automatically. Switch
2435 terminal for any messages produced by
2436 breakpoint_re_set. */
2437 target_terminal_ours_for_output ();
2438 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
2439 target_terminal_inferior ();
2441 /* Try to reenable shared library breakpoints, additional
2442 code segments in shared libraries might be mapped in now. */
2443 re_enable_breakpoints_in_shlibs ();
2445 /* If requested, stop when the dynamic linker notifies
2446 gdb of events. This allows the user to get control
2447 and place breakpoints in initializer routines for
2448 dynamically loaded objects (among other things). */
2449 if (stop_on_solib_events
)
2451 stop_stepping (ecs
);
2455 /* If we stopped due to an explicit catchpoint, then the
2456 (see above) call to SOLIB_ADD pulled in any symbols
2457 from a newly-loaded library, if appropriate.
2459 We do want the inferior to stop, but not where it is
2460 now, which is in the dynamic linker callback. Rather,
2461 we would like it stop in the user's program, just after
2462 the call that caused this catchpoint to trigger. That
2463 gives the user a more useful vantage from which to
2464 examine their program's state. */
2465 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2467 /* ??rehrauer: If I could figure out how to get the
2468 right return PC from here, we could just set a temp
2469 breakpoint and resume. I'm not sure we can without
2470 cracking open the dld's shared libraries and sniffing
2471 their unwind tables and text/data ranges, and that's
2472 not a terribly portable notion.
2474 Until that time, we must step the inferior out of the
2475 dld callback, and also out of the dld itself (and any
2476 code or stubs in libdld.sl, such as "shl_load" and
2477 friends) until we reach non-dld code. At that point,
2478 we can stop stepping. */
2479 bpstat_get_triggered_catchpoints (stop_bpstat
,
2480 &ecs
->stepping_through_solib_catchpoints
);
2481 ecs
->stepping_through_solib_after_catch
= 1;
2483 /* Be sure to lift all breakpoints, so the inferior does
2484 actually step past this point... */
2485 ecs
->another_trap
= 1;
2490 /* We want to step over this breakpoint, then keep going. */
2491 ecs
->another_trap
= 1;
2498 case BPSTAT_WHAT_LAST
:
2499 /* Not a real code, but listed here to shut up gcc -Wall. */
2501 case BPSTAT_WHAT_KEEP_CHECKING
:
2506 /* We come here if we hit a breakpoint but should not
2507 stop for it. Possibly we also were stepping
2508 and should stop for that. So fall through and
2509 test for stepping. But, if not stepping,
2512 /* Are we stepping to get the inferior out of the dynamic
2513 linker's hook (and possibly the dld itself) after catching
2515 if (ecs
->stepping_through_solib_after_catch
)
2517 #if defined(SOLIB_ADD)
2518 /* Have we reached our destination? If not, keep going. */
2519 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2521 ecs
->another_trap
= 1;
2526 /* Else, stop and report the catchpoint(s) whose triggering
2527 caused us to begin stepping. */
2528 ecs
->stepping_through_solib_after_catch
= 0;
2529 bpstat_clear (&stop_bpstat
);
2530 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2531 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2532 stop_print_frame
= 1;
2533 stop_stepping (ecs
);
2537 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2539 /* This is the old way of detecting the end of the stack dummy.
2540 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2541 handled above. As soon as we can test it on all of them, all
2542 architectures should define it. */
2544 /* If this is the breakpoint at the end of a stack dummy,
2545 just stop silently, unless the user was doing an si/ni, in which
2546 case she'd better know what she's doing. */
2548 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2549 FRAME_FP (get_current_frame ()))
2552 stop_print_frame
= 0;
2553 stop_stack_dummy
= 1;
2555 trap_expected_after_continue
= 1;
2557 stop_stepping (ecs
);
2562 if (step_resume_breakpoint
)
2564 /* Having a step-resume breakpoint overrides anything
2565 else having to do with stepping commands until
2566 that breakpoint is reached. */
2567 /* I'm not sure whether this needs to be check_sigtramp2 or
2568 whether it could/should be keep_going. */
2569 check_sigtramp2 (ecs
);
2574 if (step_range_end
== 0)
2576 /* Likewise if we aren't even stepping. */
2577 /* I'm not sure whether this needs to be check_sigtramp2 or
2578 whether it could/should be keep_going. */
2579 check_sigtramp2 (ecs
);
2584 /* If stepping through a line, keep going if still within it.
2586 Note that step_range_end is the address of the first instruction
2587 beyond the step range, and NOT the address of the last instruction
2589 if (stop_pc
>= step_range_start
2590 && stop_pc
< step_range_end
)
2592 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2593 So definately need to check for sigtramp here. */
2594 check_sigtramp2 (ecs
);
2599 /* We stepped out of the stepping range. */
2601 /* If we are stepping at the source level and entered the runtime
2602 loader dynamic symbol resolution code, we keep on single stepping
2603 until we exit the run time loader code and reach the callee's
2605 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2607 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2609 if (pc_after_resolver
)
2611 /* Set up a step-resume breakpoint at the address
2612 indicated by SKIP_SOLIB_RESOLVER. */
2613 struct symtab_and_line sr_sal
;
2615 sr_sal
.pc
= pc_after_resolver
;
2617 check_for_old_step_resume_breakpoint ();
2618 step_resume_breakpoint
=
2619 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2620 if (breakpoints_inserted
)
2621 insert_breakpoints ();
2628 /* We can't update step_sp every time through the loop, because
2629 reading the stack pointer would slow down stepping too much.
2630 But we can update it every time we leave the step range. */
2631 ecs
->update_step_sp
= 1;
2633 /* Did we just take a signal? */
2634 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2635 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2636 && INNER_THAN (read_sp (), step_sp
))
2638 /* We've just taken a signal; go until we are back to
2639 the point where we took it and one more. */
2641 /* Note: The test above succeeds not only when we stepped
2642 into a signal handler, but also when we step past the last
2643 statement of a signal handler and end up in the return stub
2644 of the signal handler trampoline. To distinguish between
2645 these two cases, check that the frame is INNER_THAN the
2646 previous one below. pai/1997-09-11 */
2650 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2652 if (INNER_THAN (current_frame
, step_frame_address
))
2654 /* We have just taken a signal; go until we are back to
2655 the point where we took it and one more. */
2657 /* This code is needed at least in the following case:
2658 The user types "next" and then a signal arrives (before
2659 the "next" is done). */
2661 /* Note that if we are stopped at a breakpoint, then we need
2662 the step_resume breakpoint to override any breakpoints at
2663 the same location, so that we will still step over the
2664 breakpoint even though the signal happened. */
2665 struct symtab_and_line sr_sal
;
2668 sr_sal
.symtab
= NULL
;
2670 sr_sal
.pc
= prev_pc
;
2671 /* We could probably be setting the frame to
2672 step_frame_address; I don't think anyone thought to
2674 check_for_old_step_resume_breakpoint ();
2675 step_resume_breakpoint
=
2676 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2677 if (breakpoints_inserted
)
2678 insert_breakpoints ();
2682 /* We just stepped out of a signal handler and into
2683 its calling trampoline.
2685 Normally, we'd call step_over_function from
2686 here, but for some reason GDB can't unwind the
2687 stack correctly to find the real PC for the point
2688 user code where the signal trampoline will return
2689 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2690 But signal trampolines are pretty small stubs of
2691 code, anyway, so it's OK instead to just
2692 single-step out. Note: assuming such trampolines
2693 don't exhibit recursion on any platform... */
2694 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2695 &ecs
->stop_func_start
,
2696 &ecs
->stop_func_end
);
2697 /* Readjust stepping range */
2698 step_range_start
= ecs
->stop_func_start
;
2699 step_range_end
= ecs
->stop_func_end
;
2700 ecs
->stepping_through_sigtramp
= 1;
2705 /* If this is stepi or nexti, make sure that the stepping range
2706 gets us past that instruction. */
2707 if (step_range_end
== 1)
2708 /* FIXME: Does this run afoul of the code below which, if
2709 we step into the middle of a line, resets the stepping
2711 step_range_end
= (step_range_start
= prev_pc
) + 1;
2713 ecs
->remove_breakpoints_on_following_step
= 1;
2718 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2719 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2720 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2721 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2722 || ecs
->stop_func_name
== 0)
2724 /* It's a subroutine call. */
2726 if ((step_over_calls
== STEP_OVER_NONE
)
2727 || ((step_range_end
== 1)
2728 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2730 /* I presume that step_over_calls is only 0 when we're
2731 supposed to be stepping at the assembly language level
2732 ("stepi"). Just stop. */
2733 /* Also, maybe we just did a "nexti" inside a prolog,
2734 so we thought it was a subroutine call but it was not.
2735 Stop as well. FENN */
2737 print_stop_reason (END_STEPPING_RANGE
, 0);
2738 stop_stepping (ecs
);
2742 if (step_over_calls
== STEP_OVER_ALL
|| IGNORE_HELPER_CALL (stop_pc
))
2744 /* We're doing a "next". */
2746 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2747 && INNER_THAN (step_frame_address
, read_sp()))
2748 /* We stepped out of a signal handler, and into its
2749 calling trampoline. This is misdetected as a
2750 subroutine call, but stepping over the signal
2751 trampoline isn't such a bad idea. In order to do
2752 that, we have to ignore the value in
2753 step_frame_address, since that doesn't represent the
2754 frame that'll reach when we return from the signal
2755 trampoline. Otherwise we'll probably continue to the
2756 end of the program. */
2757 step_frame_address
= 0;
2759 step_over_function (ecs
);
2764 /* If we are in a function call trampoline (a stub between
2765 the calling routine and the real function), locate the real
2766 function. That's what tells us (a) whether we want to step
2767 into it at all, and (b) what prologue we want to run to
2768 the end of, if we do step into it. */
2769 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2771 ecs
->stop_func_start
= tmp
;
2774 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2777 struct symtab_and_line xxx
;
2778 /* Why isn't this s_a_l called "sr_sal", like all of the
2779 other s_a_l's where this code is duplicated? */
2780 INIT_SAL (&xxx
); /* initialize to zeroes */
2782 xxx
.section
= find_pc_overlay (xxx
.pc
);
2783 check_for_old_step_resume_breakpoint ();
2784 step_resume_breakpoint
=
2785 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2786 insert_breakpoints ();
2792 /* If we have line number information for the function we
2793 are thinking of stepping into, step into it.
2795 If there are several symtabs at that PC (e.g. with include
2796 files), just want to know whether *any* of them have line
2797 numbers. find_pc_line handles this. */
2799 struct symtab_and_line tmp_sal
;
2801 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2802 if (tmp_sal
.line
!= 0)
2804 step_into_function (ecs
);
2809 /* If we have no line number and the step-stop-if-no-debug
2810 is set, we stop the step so that the user has a chance to
2811 switch in assembly mode. */
2812 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2815 print_stop_reason (END_STEPPING_RANGE
, 0);
2816 stop_stepping (ecs
);
2820 step_over_function (ecs
);
2826 /* We've wandered out of the step range. */
2828 ecs
->sal
= find_pc_line (stop_pc
, 0);
2830 if (step_range_end
== 1)
2832 /* It is stepi or nexti. We always want to stop stepping after
2835 print_stop_reason (END_STEPPING_RANGE
, 0);
2836 stop_stepping (ecs
);
2840 /* If we're in the return path from a shared library trampoline,
2841 we want to proceed through the trampoline when stepping. */
2842 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2846 /* Determine where this trampoline returns. */
2847 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2849 /* Only proceed through if we know where it's going. */
2852 /* And put the step-breakpoint there and go until there. */
2853 struct symtab_and_line sr_sal
;
2855 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2857 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2858 /* Do not specify what the fp should be when we stop
2859 since on some machines the prologue
2860 is where the new fp value is established. */
2861 check_for_old_step_resume_breakpoint ();
2862 step_resume_breakpoint
=
2863 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2864 if (breakpoints_inserted
)
2865 insert_breakpoints ();
2867 /* Restart without fiddling with the step ranges or
2874 if (ecs
->sal
.line
== 0)
2876 /* We have no line number information. That means to stop
2877 stepping (does this always happen right after one instruction,
2878 when we do "s" in a function with no line numbers,
2879 or can this happen as a result of a return or longjmp?). */
2881 print_stop_reason (END_STEPPING_RANGE
, 0);
2882 stop_stepping (ecs
);
2886 if ((stop_pc
== ecs
->sal
.pc
)
2887 && (ecs
->current_line
!= ecs
->sal
.line
|| ecs
->current_symtab
!= ecs
->sal
.symtab
))
2889 /* We are at the start of a different line. So stop. Note that
2890 we don't stop if we step into the middle of a different line.
2891 That is said to make things like for (;;) statements work
2894 print_stop_reason (END_STEPPING_RANGE
, 0);
2895 stop_stepping (ecs
);
2899 /* We aren't done stepping.
2901 Optimize by setting the stepping range to the line.
2902 (We might not be in the original line, but if we entered a
2903 new line in mid-statement, we continue stepping. This makes
2904 things like for(;;) statements work better.) */
2906 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2908 /* If this is the last line of the function, don't keep stepping
2909 (it would probably step us out of the function).
2910 This is particularly necessary for a one-line function,
2911 in which after skipping the prologue we better stop even though
2912 we will be in mid-line. */
2914 print_stop_reason (END_STEPPING_RANGE
, 0);
2915 stop_stepping (ecs
);
2918 step_range_start
= ecs
->sal
.pc
;
2919 step_range_end
= ecs
->sal
.end
;
2920 step_frame_address
= FRAME_FP (get_current_frame ());
2921 ecs
->current_line
= ecs
->sal
.line
;
2922 ecs
->current_symtab
= ecs
->sal
.symtab
;
2924 /* In the case where we just stepped out of a function into the middle
2925 of a line of the caller, continue stepping, but step_frame_address
2926 must be modified to current frame */
2928 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2929 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2930 step_frame_address
= current_frame
;
2935 } /* extra brace, to preserve old indentation */
2938 /* Are we in the middle of stepping? */
2941 currently_stepping (struct execution_control_state
*ecs
)
2943 return ((through_sigtramp_breakpoint
== NULL
2944 && !ecs
->handling_longjmp
2945 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2947 || ecs
->stepping_through_solib_after_catch
2948 || bpstat_should_step ());
2952 check_sigtramp2 (struct execution_control_state
*ecs
)
2955 && IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2956 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2957 && INNER_THAN (read_sp (), step_sp
))
2959 /* What has happened here is that we have just stepped the
2960 inferior with a signal (because it is a signal which
2961 shouldn't make us stop), thus stepping into sigtramp.
2963 So we need to set a step_resume_break_address breakpoint and
2964 continue until we hit it, and then step. FIXME: This should
2965 be more enduring than a step_resume breakpoint; we should
2966 know that we will later need to keep going rather than
2967 re-hitting the breakpoint here (see the testsuite,
2968 gdb.base/signals.exp where it says "exceedingly difficult"). */
2970 struct symtab_and_line sr_sal
;
2972 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2973 sr_sal
.pc
= prev_pc
;
2974 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2975 /* We perhaps could set the frame if we kept track of what the
2976 frame corresponding to prev_pc was. But we don't, so don't. */
2977 through_sigtramp_breakpoint
=
2978 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2979 if (breakpoints_inserted
)
2980 insert_breakpoints ();
2982 ecs
->remove_breakpoints_on_following_step
= 1;
2983 ecs
->another_trap
= 1;
2987 /* Subroutine call with source code we should not step over. Do step
2988 to the first line of code in it. */
2991 step_into_function (struct execution_control_state
*ecs
)
2994 struct symtab_and_line sr_sal
;
2996 s
= find_pc_symtab (stop_pc
);
2997 if (s
&& s
->language
!= language_asm
)
2998 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
3000 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
3001 /* Use the step_resume_break to step until the end of the prologue,
3002 even if that involves jumps (as it seems to on the vax under
3004 /* If the prologue ends in the middle of a source line, continue to
3005 the end of that source line (if it is still within the function).
3006 Otherwise, just go to end of prologue. */
3007 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
3008 /* no, don't either. It skips any code that's legitimately on the
3012 && ecs
->sal
.pc
!= ecs
->stop_func_start
3013 && ecs
->sal
.end
< ecs
->stop_func_end
)
3014 ecs
->stop_func_start
= ecs
->sal
.end
;
3017 if (ecs
->stop_func_start
== stop_pc
)
3019 /* We are already there: stop now. */
3021 print_stop_reason (END_STEPPING_RANGE
, 0);
3022 stop_stepping (ecs
);
3027 /* Put the step-breakpoint there and go until there. */
3028 INIT_SAL (&sr_sal
); /* initialize to zeroes */
3029 sr_sal
.pc
= ecs
->stop_func_start
;
3030 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3031 /* Do not specify what the fp should be when we stop since on
3032 some machines the prologue is where the new fp value is
3034 check_for_old_step_resume_breakpoint ();
3035 step_resume_breakpoint
=
3036 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
3037 if (breakpoints_inserted
)
3038 insert_breakpoints ();
3040 /* And make sure stepping stops right away then. */
3041 step_range_end
= step_range_start
;
3046 /* We've just entered a callee, and we wish to resume until it returns
3047 to the caller. Setting a step_resume breakpoint on the return
3048 address will catch a return from the callee.
3050 However, if the callee is recursing, we want to be careful not to
3051 catch returns of those recursive calls, but only of THIS instance
3054 To do this, we set the step_resume bp's frame to our current
3055 caller's frame (step_frame_address, which is set by the "next" or
3056 "until" command, before execution begins). */
3059 step_over_function (struct execution_control_state
*ecs
)
3061 struct symtab_and_line sr_sal
;
3063 INIT_SAL (&sr_sal
); /* initialize to zeros */
3064 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3065 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3067 check_for_old_step_resume_breakpoint ();
3068 step_resume_breakpoint
=
3069 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
3071 if (step_frame_address
&& !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
3072 step_resume_breakpoint
->frame
= step_frame_address
;
3074 if (breakpoints_inserted
)
3075 insert_breakpoints ();
3079 stop_stepping (struct execution_control_state
*ecs
)
3081 if (target_has_execution
)
3083 /* Are we stopping for a vfork event? We only stop when we see
3084 the child's event. However, we may not yet have seen the
3085 parent's event. And, inferior_ptid is still set to the
3086 parent's pid, until we resume again and follow either the
3089 To ensure that we can really touch inferior_ptid (aka, the
3090 parent process) -- which calls to functions like read_pc
3091 implicitly do -- wait on the parent if necessary. */
3092 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3093 && !pending_follow
.fork_event
.saw_parent_fork
)
3099 if (target_wait_hook
)
3100 parent_ptid
= target_wait_hook (pid_to_ptid (-1), &(ecs
->ws
));
3102 parent_ptid
= target_wait (pid_to_ptid (-1), &(ecs
->ws
));
3104 while (! ptid_equal (parent_ptid
, inferior_ptid
));
3107 /* Assuming the inferior still exists, set these up for next
3108 time, just like we did above if we didn't break out of the
3110 prev_pc
= read_pc ();
3111 prev_func_start
= ecs
->stop_func_start
;
3112 prev_func_name
= ecs
->stop_func_name
;
3115 /* Let callers know we don't want to wait for the inferior anymore. */
3116 ecs
->wait_some_more
= 0;
3119 /* This function handles various cases where we need to continue
3120 waiting for the inferior. */
3121 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3124 keep_going (struct execution_control_state
*ecs
)
3126 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3127 vforked child between its creation and subsequent exit or call to
3128 exec(). However, I had big problems in this rather creaky exec
3129 engine, getting that to work. The fundamental problem is that
3130 I'm trying to debug two processes via an engine that only
3131 understands a single process with possibly multiple threads.
3133 Hence, this spot is known to have problems when
3134 target_can_follow_vfork_prior_to_exec returns 1. */
3136 /* Save the pc before execution, to compare with pc after stop. */
3137 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3138 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3139 BREAK is defined, the
3140 original pc would not have
3141 been at the start of a
3143 prev_func_name
= ecs
->stop_func_name
;
3145 if (ecs
->update_step_sp
)
3146 step_sp
= read_sp ();
3147 ecs
->update_step_sp
= 0;
3149 /* If we did not do break;, it means we should keep running the
3150 inferior and not return to debugger. */
3152 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3154 /* We took a signal (which we are supposed to pass through to
3155 the inferior, else we'd have done a break above) and we
3156 haven't yet gotten our trap. Simply continue. */
3157 resume (currently_stepping (ecs
), stop_signal
);
3161 /* Either the trap was not expected, but we are continuing
3162 anyway (the user asked that this signal be passed to the
3165 The signal was SIGTRAP, e.g. it was our signal, but we
3166 decided we should resume from it.
3168 We're going to run this baby now!
3170 Insert breakpoints now, unless we are trying to one-proceed
3171 past a breakpoint. */
3172 /* If we've just finished a special step resume and we don't
3173 want to hit a breakpoint, pull em out. */
3174 if (step_resume_breakpoint
== NULL
3175 && through_sigtramp_breakpoint
== NULL
3176 && ecs
->remove_breakpoints_on_following_step
)
3178 ecs
->remove_breakpoints_on_following_step
= 0;
3179 remove_breakpoints ();
3180 breakpoints_inserted
= 0;
3182 else if (!breakpoints_inserted
&&
3183 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3185 breakpoints_failed
= insert_breakpoints ();
3186 if (breakpoints_failed
)
3188 stop_stepping (ecs
);
3191 breakpoints_inserted
= 1;
3194 trap_expected
= ecs
->another_trap
;
3196 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3197 specifies that such a signal should be delivered to the
3200 Typically, this would occure when a user is debugging a
3201 target monitor on a simulator: the target monitor sets a
3202 breakpoint; the simulator encounters this break-point and
3203 halts the simulation handing control to GDB; GDB, noteing
3204 that the break-point isn't valid, returns control back to the
3205 simulator; the simulator then delivers the hardware
3206 equivalent of a SIGNAL_TRAP to the program being debugged. */
3208 if (stop_signal
== TARGET_SIGNAL_TRAP
3209 && !signal_program
[stop_signal
])
3210 stop_signal
= TARGET_SIGNAL_0
;
3212 #ifdef SHIFT_INST_REGS
3213 /* I'm not sure when this following segment applies. I do know,
3214 now, that we shouldn't rewrite the regs when we were stopped
3215 by a random signal from the inferior process. */
3216 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3217 (this is only used on the 88k). */
3219 if (!bpstat_explains_signal (stop_bpstat
)
3220 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
3221 && !stopped_by_random_signal
)
3223 #endif /* SHIFT_INST_REGS */
3225 resume (currently_stepping (ecs
), stop_signal
);
3228 prepare_to_wait (ecs
);
3231 /* This function normally comes after a resume, before
3232 handle_inferior_event exits. It takes care of any last bits of
3233 housekeeping, and sets the all-important wait_some_more flag. */
3236 prepare_to_wait (struct execution_control_state
*ecs
)
3238 if (ecs
->infwait_state
== infwait_normal_state
)
3240 overlay_cache_invalid
= 1;
3242 /* We have to invalidate the registers BEFORE calling
3243 target_wait because they can be loaded from the target while
3244 in target_wait. This makes remote debugging a bit more
3245 efficient for those targets that provide critical registers
3246 as part of their normal status mechanism. */
3248 registers_changed ();
3249 ecs
->waiton_ptid
= pid_to_ptid (-1);
3250 ecs
->wp
= &(ecs
->ws
);
3252 /* This is the old end of the while loop. Let everybody know we
3253 want to wait for the inferior some more and get called again
3255 ecs
->wait_some_more
= 1;
3258 /* Print why the inferior has stopped. We always print something when
3259 the inferior exits, or receives a signal. The rest of the cases are
3260 dealt with later on in normal_stop() and print_it_typical(). Ideally
3261 there should be a call to this function from handle_inferior_event()
3262 each time stop_stepping() is called.*/
3264 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3266 switch (stop_reason
)
3269 /* We don't deal with these cases from handle_inferior_event()
3272 case END_STEPPING_RANGE
:
3273 /* We are done with a step/next/si/ni command. */
3274 /* For now print nothing. */
3275 /* Print a message only if not in the middle of doing a "step n"
3276 operation for n > 1 */
3277 if (!step_multi
|| !stop_step
)
3278 if (ui_out_is_mi_like_p (uiout
))
3279 ui_out_field_string (uiout
, "reason", "end-stepping-range");
3281 case BREAKPOINT_HIT
:
3282 /* We found a breakpoint. */
3283 /* For now print nothing. */
3286 /* The inferior was terminated by a signal. */
3287 annotate_signalled ();
3288 if (ui_out_is_mi_like_p (uiout
))
3289 ui_out_field_string (uiout
, "reason", "exited-signalled");
3290 ui_out_text (uiout
, "\nProgram terminated with signal ");
3291 annotate_signal_name ();
3292 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3293 annotate_signal_name_end ();
3294 ui_out_text (uiout
, ", ");
3295 annotate_signal_string ();
3296 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3297 annotate_signal_string_end ();
3298 ui_out_text (uiout
, ".\n");
3299 ui_out_text (uiout
, "The program no longer exists.\n");
3302 /* The inferior program is finished. */
3303 annotate_exited (stop_info
);
3306 if (ui_out_is_mi_like_p (uiout
))
3307 ui_out_field_string (uiout
, "reason", "exited");
3308 ui_out_text (uiout
, "\nProgram exited with code ");
3309 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) stop_info
);
3310 ui_out_text (uiout
, ".\n");
3314 if (ui_out_is_mi_like_p (uiout
))
3315 ui_out_field_string (uiout
, "reason", "exited-normally");
3316 ui_out_text (uiout
, "\nProgram exited normally.\n");
3319 case SIGNAL_RECEIVED
:
3320 /* Signal received. The signal table tells us to print about
3323 ui_out_text (uiout
, "\nProgram received signal ");
3324 annotate_signal_name ();
3325 if (ui_out_is_mi_like_p (uiout
))
3326 ui_out_field_string (uiout
, "reason", "signal-received");
3327 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3328 annotate_signal_name_end ();
3329 ui_out_text (uiout
, ", ");
3330 annotate_signal_string ();
3331 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3332 annotate_signal_string_end ();
3333 ui_out_text (uiout
, ".\n");
3336 internal_error (__FILE__
, __LINE__
,
3337 "print_stop_reason: unrecognized enum value");
3343 /* Here to return control to GDB when the inferior stops for real.
3344 Print appropriate messages, remove breakpoints, give terminal our modes.
3346 STOP_PRINT_FRAME nonzero means print the executing frame
3347 (pc, function, args, file, line number and line text).
3348 BREAKPOINTS_FAILED nonzero means stop was due to error
3349 attempting to insert breakpoints. */
3354 /* As with the notification of thread events, we want to delay
3355 notifying the user that we've switched thread context until
3356 the inferior actually stops.
3358 (Note that there's no point in saying anything if the inferior
3360 if (! ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3361 && target_has_execution
)
3363 target_terminal_ours_for_output ();
3364 printf_filtered ("[Switching to %s]\n",
3365 target_pid_or_tid_to_str (inferior_ptid
));
3366 previous_inferior_ptid
= inferior_ptid
;
3369 /* Make sure that the current_frame's pc is correct. This
3370 is a correction for setting up the frame info before doing
3371 DECR_PC_AFTER_BREAK */
3372 if (target_has_execution
&& get_current_frame ())
3373 (get_current_frame ())->pc
= read_pc ();
3375 if (breakpoints_failed
)
3377 target_terminal_ours_for_output ();
3378 print_sys_errmsg ("While inserting breakpoints", breakpoints_failed
);
3379 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3380 The same program may be running in another process,\n\
3381 or you may have requested too many hardware breakpoints\n\
3382 and/or watchpoints.\n");
3385 if (target_has_execution
&& breakpoints_inserted
)
3387 if (remove_breakpoints ())
3389 target_terminal_ours_for_output ();
3390 printf_filtered ("Cannot remove breakpoints because ");
3391 printf_filtered ("program is no longer writable.\n");
3392 printf_filtered ("It might be running in another process.\n");
3393 printf_filtered ("Further execution is probably impossible.\n");
3396 breakpoints_inserted
= 0;
3398 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3399 Delete any breakpoint that is to be deleted at the next stop. */
3401 breakpoint_auto_delete (stop_bpstat
);
3403 /* If an auto-display called a function and that got a signal,
3404 delete that auto-display to avoid an infinite recursion. */
3406 if (stopped_by_random_signal
)
3407 disable_current_display ();
3409 /* Don't print a message if in the middle of doing a "step n"
3410 operation for n > 1 */
3411 if (step_multi
&& stop_step
)
3414 target_terminal_ours ();
3416 /* Look up the hook_stop and run it if it exists. */
3418 if (stop_command
&& stop_command
->hook_pre
)
3420 catch_errors (hook_stop_stub
, stop_command
->hook_pre
,
3421 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3424 if (!target_has_stack
)
3430 /* Select innermost stack frame - i.e., current frame is frame 0,
3431 and current location is based on that.
3432 Don't do this on return from a stack dummy routine,
3433 or if the program has exited. */
3435 if (!stop_stack_dummy
)
3437 select_frame (get_current_frame (), 0);
3439 /* Print current location without a level number, if
3440 we have changed functions or hit a breakpoint.
3441 Print source line if we have one.
3442 bpstat_print() contains the logic deciding in detail
3443 what to print, based on the event(s) that just occurred. */
3445 if (stop_print_frame
3450 int do_frame_printing
= 1;
3452 bpstat_ret
= bpstat_print (stop_bpstat
);
3457 && step_frame_address
== FRAME_FP (get_current_frame ())
3458 && step_start_function
== find_pc_function (stop_pc
))
3459 source_flag
= SRC_LINE
; /* finished step, just print source line */
3461 source_flag
= SRC_AND_LOC
; /* print location and source line */
3463 case PRINT_SRC_AND_LOC
:
3464 source_flag
= SRC_AND_LOC
; /* print location and source line */
3466 case PRINT_SRC_ONLY
:
3467 source_flag
= SRC_LINE
;
3470 source_flag
= SRC_LINE
; /* something bogus */
3471 do_frame_printing
= 0;
3474 internal_error (__FILE__
, __LINE__
,
3477 /* For mi, have the same behavior every time we stop:
3478 print everything but the source line. */
3479 if (ui_out_is_mi_like_p (uiout
))
3480 source_flag
= LOC_AND_ADDRESS
;
3482 if (ui_out_is_mi_like_p (uiout
))
3483 ui_out_field_int (uiout
, "thread-id",
3484 pid_to_thread_id (inferior_ptid
));
3485 /* The behavior of this routine with respect to the source
3487 SRC_LINE: Print only source line
3488 LOCATION: Print only location
3489 SRC_AND_LOC: Print location and source line */
3490 if (do_frame_printing
)
3491 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
3493 /* Display the auto-display expressions. */
3498 /* Save the function value return registers, if we care.
3499 We might be about to restore their previous contents. */
3500 if (proceed_to_finish
)
3501 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
3503 if (stop_stack_dummy
)
3505 /* Pop the empty frame that contains the stack dummy.
3506 POP_FRAME ends with a setting of the current frame, so we
3507 can use that next. */
3509 /* Set stop_pc to what it was before we called the function.
3510 Can't rely on restore_inferior_status because that only gets
3511 called if we don't stop in the called function. */
3512 stop_pc
= read_pc ();
3513 select_frame (get_current_frame (), 0);
3517 annotate_stopped ();
3521 hook_stop_stub (void *cmd
)
3523 execute_user_command ((struct cmd_list_element
*) cmd
, 0);
3528 signal_stop_state (int signo
)
3530 return signal_stop
[signo
];
3534 signal_print_state (int signo
)
3536 return signal_print
[signo
];
3540 signal_pass_state (int signo
)
3542 return signal_program
[signo
];
3545 int signal_stop_update (signo
, state
)
3549 int ret
= signal_stop
[signo
];
3550 signal_stop
[signo
] = state
;
3554 int signal_print_update (signo
, state
)
3558 int ret
= signal_print
[signo
];
3559 signal_print
[signo
] = state
;
3563 int signal_pass_update (signo
, state
)
3567 int ret
= signal_program
[signo
];
3568 signal_program
[signo
] = state
;
3573 sig_print_header (void)
3576 Signal Stop\tPrint\tPass to program\tDescription\n");
3580 sig_print_info (enum target_signal oursig
)
3582 char *name
= target_signal_to_name (oursig
);
3583 int name_padding
= 13 - strlen (name
);
3585 if (name_padding
<= 0)
3588 printf_filtered ("%s", name
);
3589 printf_filtered ("%*.*s ", name_padding
, name_padding
,
3591 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3592 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3593 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3594 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3597 /* Specify how various signals in the inferior should be handled. */
3600 handle_command (char *args
, int from_tty
)
3603 int digits
, wordlen
;
3604 int sigfirst
, signum
, siglast
;
3605 enum target_signal oursig
;
3608 unsigned char *sigs
;
3609 struct cleanup
*old_chain
;
3613 error_no_arg ("signal to handle");
3616 /* Allocate and zero an array of flags for which signals to handle. */
3618 nsigs
= (int) TARGET_SIGNAL_LAST
;
3619 sigs
= (unsigned char *) alloca (nsigs
);
3620 memset (sigs
, 0, nsigs
);
3622 /* Break the command line up into args. */
3624 argv
= buildargv (args
);
3629 old_chain
= make_cleanup_freeargv (argv
);
3631 /* Walk through the args, looking for signal oursigs, signal names, and
3632 actions. Signal numbers and signal names may be interspersed with
3633 actions, with the actions being performed for all signals cumulatively
3634 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3636 while (*argv
!= NULL
)
3638 wordlen
= strlen (*argv
);
3639 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3643 sigfirst
= siglast
= -1;
3645 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3647 /* Apply action to all signals except those used by the
3648 debugger. Silently skip those. */
3651 siglast
= nsigs
- 1;
3653 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3655 SET_SIGS (nsigs
, sigs
, signal_stop
);
3656 SET_SIGS (nsigs
, sigs
, signal_print
);
3658 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3660 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3662 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3664 SET_SIGS (nsigs
, sigs
, signal_print
);
3666 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3668 SET_SIGS (nsigs
, sigs
, signal_program
);
3670 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3672 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3674 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3676 SET_SIGS (nsigs
, sigs
, signal_program
);
3678 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3680 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3681 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3683 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3685 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3687 else if (digits
> 0)
3689 /* It is numeric. The numeric signal refers to our own
3690 internal signal numbering from target.h, not to host/target
3691 signal number. This is a feature; users really should be
3692 using symbolic names anyway, and the common ones like
3693 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3695 sigfirst
= siglast
= (int)
3696 target_signal_from_command (atoi (*argv
));
3697 if ((*argv
)[digits
] == '-')
3700 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3702 if (sigfirst
> siglast
)
3704 /* Bet he didn't figure we'd think of this case... */
3712 oursig
= target_signal_from_name (*argv
);
3713 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3715 sigfirst
= siglast
= (int) oursig
;
3719 /* Not a number and not a recognized flag word => complain. */
3720 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3724 /* If any signal numbers or symbol names were found, set flags for
3725 which signals to apply actions to. */
3727 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3729 switch ((enum target_signal
) signum
)
3731 case TARGET_SIGNAL_TRAP
:
3732 case TARGET_SIGNAL_INT
:
3733 if (!allsigs
&& !sigs
[signum
])
3735 if (query ("%s is used by the debugger.\n\
3736 Are you sure you want to change it? ",
3737 target_signal_to_name
3738 ((enum target_signal
) signum
)))
3744 printf_unfiltered ("Not confirmed, unchanged.\n");
3745 gdb_flush (gdb_stdout
);
3749 case TARGET_SIGNAL_0
:
3750 case TARGET_SIGNAL_DEFAULT
:
3751 case TARGET_SIGNAL_UNKNOWN
:
3752 /* Make sure that "all" doesn't print these. */
3763 target_notice_signals (inferior_ptid
);
3767 /* Show the results. */
3768 sig_print_header ();
3769 for (signum
= 0; signum
< nsigs
; signum
++)
3773 sig_print_info (signum
);
3778 do_cleanups (old_chain
);
3782 xdb_handle_command (char *args
, int from_tty
)
3785 struct cleanup
*old_chain
;
3787 /* Break the command line up into args. */
3789 argv
= buildargv (args
);
3794 old_chain
= make_cleanup_freeargv (argv
);
3795 if (argv
[1] != (char *) NULL
)
3800 bufLen
= strlen (argv
[0]) + 20;
3801 argBuf
= (char *) xmalloc (bufLen
);
3805 enum target_signal oursig
;
3807 oursig
= target_signal_from_name (argv
[0]);
3808 memset (argBuf
, 0, bufLen
);
3809 if (strcmp (argv
[1], "Q") == 0)
3810 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3813 if (strcmp (argv
[1], "s") == 0)
3815 if (!signal_stop
[oursig
])
3816 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3818 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3820 else if (strcmp (argv
[1], "i") == 0)
3822 if (!signal_program
[oursig
])
3823 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3825 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3827 else if (strcmp (argv
[1], "r") == 0)
3829 if (!signal_print
[oursig
])
3830 sprintf (argBuf
, "%s %s", argv
[0], "print");
3832 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3838 handle_command (argBuf
, from_tty
);
3840 printf_filtered ("Invalid signal handling flag.\n");
3845 do_cleanups (old_chain
);
3848 /* Print current contents of the tables set by the handle command.
3849 It is possible we should just be printing signals actually used
3850 by the current target (but for things to work right when switching
3851 targets, all signals should be in the signal tables). */
3854 signals_info (char *signum_exp
, int from_tty
)
3856 enum target_signal oursig
;
3857 sig_print_header ();
3861 /* First see if this is a symbol name. */
3862 oursig
= target_signal_from_name (signum_exp
);
3863 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3865 /* No, try numeric. */
3867 target_signal_from_command (parse_and_eval_long (signum_exp
));
3869 sig_print_info (oursig
);
3873 printf_filtered ("\n");
3874 /* These ugly casts brought to you by the native VAX compiler. */
3875 for (oursig
= TARGET_SIGNAL_FIRST
;
3876 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3877 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3881 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3882 && oursig
!= TARGET_SIGNAL_DEFAULT
3883 && oursig
!= TARGET_SIGNAL_0
)
3884 sig_print_info (oursig
);
3887 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3890 struct inferior_status
3892 enum target_signal stop_signal
;
3896 int stop_stack_dummy
;
3897 int stopped_by_random_signal
;
3899 CORE_ADDR step_range_start
;
3900 CORE_ADDR step_range_end
;
3901 CORE_ADDR step_frame_address
;
3902 enum step_over_calls_kind step_over_calls
;
3903 CORE_ADDR step_resume_break_address
;
3904 int stop_after_trap
;
3905 int stop_soon_quietly
;
3906 CORE_ADDR selected_frame_address
;
3907 char *stop_registers
;
3909 /* These are here because if call_function_by_hand has written some
3910 registers and then decides to call error(), we better not have changed
3915 int breakpoint_proceeded
;
3916 int restore_stack_info
;
3917 int proceed_to_finish
;
3920 static struct inferior_status
*
3921 xmalloc_inferior_status (void)
3923 struct inferior_status
*inf_status
;
3924 inf_status
= xmalloc (sizeof (struct inferior_status
));
3925 inf_status
->stop_registers
= xmalloc (REGISTER_BYTES
);
3926 inf_status
->registers
= xmalloc (REGISTER_BYTES
);
3931 free_inferior_status (struct inferior_status
*inf_status
)
3933 xfree (inf_status
->registers
);
3934 xfree (inf_status
->stop_registers
);
3939 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3942 int size
= REGISTER_RAW_SIZE (regno
);
3943 void *buf
= alloca (size
);
3944 store_signed_integer (buf
, size
, val
);
3945 memcpy (&inf_status
->registers
[REGISTER_BYTE (regno
)], buf
, size
);
3948 /* Save all of the information associated with the inferior<==>gdb
3949 connection. INF_STATUS is a pointer to a "struct inferior_status"
3950 (defined in inferior.h). */
3952 struct inferior_status
*
3953 save_inferior_status (int restore_stack_info
)
3955 struct inferior_status
*inf_status
= xmalloc_inferior_status ();
3957 inf_status
->stop_signal
= stop_signal
;
3958 inf_status
->stop_pc
= stop_pc
;
3959 inf_status
->stop_step
= stop_step
;
3960 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3961 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3962 inf_status
->trap_expected
= trap_expected
;
3963 inf_status
->step_range_start
= step_range_start
;
3964 inf_status
->step_range_end
= step_range_end
;
3965 inf_status
->step_frame_address
= step_frame_address
;
3966 inf_status
->step_over_calls
= step_over_calls
;
3967 inf_status
->stop_after_trap
= stop_after_trap
;
3968 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3969 /* Save original bpstat chain here; replace it with copy of chain.
3970 If caller's caller is walking the chain, they'll be happier if we
3971 hand them back the original chain when restore_inferior_status is
3973 inf_status
->stop_bpstat
= stop_bpstat
;
3974 stop_bpstat
= bpstat_copy (stop_bpstat
);
3975 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3976 inf_status
->restore_stack_info
= restore_stack_info
;
3977 inf_status
->proceed_to_finish
= proceed_to_finish
;
3979 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
3981 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3983 record_selected_frame (&(inf_status
->selected_frame_address
),
3984 &(inf_status
->selected_level
));
3988 struct restore_selected_frame_args
3990 CORE_ADDR frame_address
;
3995 restore_selected_frame (void *args
)
3997 struct restore_selected_frame_args
*fr
=
3998 (struct restore_selected_frame_args
*) args
;
3999 struct frame_info
*frame
;
4000 int level
= fr
->level
;
4002 frame
= find_relative_frame (get_current_frame (), &level
);
4004 /* If inf_status->selected_frame_address is NULL, there was no
4005 previously selected frame. */
4006 if (frame
== NULL
||
4007 /* FRAME_FP (frame) != fr->frame_address || */
4008 /* elz: deleted this check as a quick fix to the problem that
4009 for function called by hand gdb creates no internal frame
4010 structure and the real stack and gdb's idea of stack are
4011 different if nested calls by hands are made.
4013 mvs: this worries me. */
4016 warning ("Unable to restore previously selected frame.\n");
4020 select_frame (frame
, fr
->level
);
4026 restore_inferior_status (struct inferior_status
*inf_status
)
4028 stop_signal
= inf_status
->stop_signal
;
4029 stop_pc
= inf_status
->stop_pc
;
4030 stop_step
= inf_status
->stop_step
;
4031 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4032 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4033 trap_expected
= inf_status
->trap_expected
;
4034 step_range_start
= inf_status
->step_range_start
;
4035 step_range_end
= inf_status
->step_range_end
;
4036 step_frame_address
= inf_status
->step_frame_address
;
4037 step_over_calls
= inf_status
->step_over_calls
;
4038 stop_after_trap
= inf_status
->stop_after_trap
;
4039 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
4040 bpstat_clear (&stop_bpstat
);
4041 stop_bpstat
= inf_status
->stop_bpstat
;
4042 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4043 proceed_to_finish
= inf_status
->proceed_to_finish
;
4045 /* FIXME: Is the restore of stop_registers always needed */
4046 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
4048 /* The inferior can be gone if the user types "print exit(0)"
4049 (and perhaps other times). */
4050 if (target_has_execution
)
4051 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
4053 /* FIXME: If we are being called after stopping in a function which
4054 is called from gdb, we should not be trying to restore the
4055 selected frame; it just prints a spurious error message (The
4056 message is useful, however, in detecting bugs in gdb (like if gdb
4057 clobbers the stack)). In fact, should we be restoring the
4058 inferior status at all in that case? . */
4060 if (target_has_stack
&& inf_status
->restore_stack_info
)
4062 struct restore_selected_frame_args fr
;
4063 fr
.level
= inf_status
->selected_level
;
4064 fr
.frame_address
= inf_status
->selected_frame_address
;
4065 /* The point of catch_errors is that if the stack is clobbered,
4066 walking the stack might encounter a garbage pointer and error()
4067 trying to dereference it. */
4068 if (catch_errors (restore_selected_frame
, &fr
,
4069 "Unable to restore previously selected frame:\n",
4070 RETURN_MASK_ERROR
) == 0)
4071 /* Error in restoring the selected frame. Select the innermost
4075 select_frame (get_current_frame (), 0);
4079 free_inferior_status (inf_status
);
4083 do_restore_inferior_status_cleanup (void *sts
)
4085 restore_inferior_status (sts
);
4089 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4091 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4095 discard_inferior_status (struct inferior_status
*inf_status
)
4097 /* See save_inferior_status for info on stop_bpstat. */
4098 bpstat_clear (&inf_status
->stop_bpstat
);
4099 free_inferior_status (inf_status
);
4102 /* Oft used ptids */
4104 ptid_t minus_one_ptid
;
4106 /* Create a ptid given the necessary PID, LWP, and TID components. */
4109 ptid_build (int pid
, long lwp
, long tid
)
4119 /* Create a ptid from just a pid. */
4122 pid_to_ptid (int pid
)
4124 return ptid_build (pid
, 0, 0);
4127 /* Fetch the pid (process id) component from a ptid. */
4130 ptid_get_pid (ptid_t ptid
)
4135 /* Fetch the lwp (lightweight process) component from a ptid. */
4138 ptid_get_lwp (ptid_t ptid
)
4143 /* Fetch the tid (thread id) component from a ptid. */
4146 ptid_get_tid (ptid_t ptid
)
4151 /* ptid_equal() is used to test equality of two ptids. */
4154 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4156 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4157 && ptid1
.tid
== ptid2
.tid
);
4160 /* restore_inferior_ptid() will be used by the cleanup machinery
4161 to restore the inferior_ptid value saved in a call to
4162 save_inferior_ptid(). */
4165 restore_inferior_ptid (void *arg
)
4167 ptid_t
*saved_ptid_ptr
= arg
;
4168 inferior_ptid
= *saved_ptid_ptr
;
4172 /* Save the value of inferior_ptid so that it may be restored by a
4173 later call to do_cleanups(). Returns the struct cleanup pointer
4174 needed for later doing the cleanup. */
4177 save_inferior_ptid (void)
4179 ptid_t
*saved_ptid_ptr
;
4181 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4182 *saved_ptid_ptr
= inferior_ptid
;
4183 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4190 stop_registers
= xmalloc (REGISTER_BYTES
);
4194 _initialize_infrun (void)
4197 register int numsigs
;
4198 struct cmd_list_element
*c
;
4202 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4203 register_gdbarch_swap (NULL
, 0, build_infrun
);
4205 add_info ("signals", signals_info
,
4206 "What debugger does when program gets various signals.\n\
4207 Specify a signal as argument to print info on that signal only.");
4208 add_info_alias ("handle", "signals", 0);
4210 add_com ("handle", class_run
, handle_command
,
4211 concat ("Specify how to handle a signal.\n\
4212 Args are signals and actions to apply to those signals.\n\
4213 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4214 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4215 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4216 The special arg \"all\" is recognized to mean all signals except those\n\
4217 used by the debugger, typically SIGTRAP and SIGINT.\n",
4218 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4219 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4220 Stop means reenter debugger if this signal happens (implies print).\n\
4221 Print means print a message if this signal happens.\n\
4222 Pass means let program see this signal; otherwise program doesn't know.\n\
4223 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4224 Pass and Stop may be combined.", NULL
));
4227 add_com ("lz", class_info
, signals_info
,
4228 "What debugger does when program gets various signals.\n\
4229 Specify a signal as argument to print info on that signal only.");
4230 add_com ("z", class_run
, xdb_handle_command
,
4231 concat ("Specify how to handle a signal.\n\
4232 Args are signals and actions to apply to those signals.\n\
4233 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4234 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4235 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4236 The special arg \"all\" is recognized to mean all signals except those\n\
4237 used by the debugger, typically SIGTRAP and SIGINT.\n",
4238 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4239 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4240 nopass), \"Q\" (noprint)\n\
4241 Stop means reenter debugger if this signal happens (implies print).\n\
4242 Print means print a message if this signal happens.\n\
4243 Pass means let program see this signal; otherwise program doesn't know.\n\
4244 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4245 Pass and Stop may be combined.", NULL
));
4249 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
4250 "There is no `stop' command, but you can set a hook on `stop'.\n\
4251 This allows you to set a list of commands to be run each time execution\n\
4252 of the program stops.", &cmdlist
);
4254 numsigs
= (int) TARGET_SIGNAL_LAST
;
4255 signal_stop
= (unsigned char *)
4256 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4257 signal_print
= (unsigned char *)
4258 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4259 signal_program
= (unsigned char *)
4260 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4261 for (i
= 0; i
< numsigs
; i
++)
4264 signal_print
[i
] = 1;
4265 signal_program
[i
] = 1;
4268 /* Signals caused by debugger's own actions
4269 should not be given to the program afterwards. */
4270 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4271 signal_program
[TARGET_SIGNAL_INT
] = 0;
4273 /* Signals that are not errors should not normally enter the debugger. */
4274 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4275 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4276 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4277 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4278 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4279 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4280 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4281 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4282 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4283 signal_print
[TARGET_SIGNAL_IO
] = 0;
4284 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4285 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4286 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4287 signal_print
[TARGET_SIGNAL_URG
] = 0;
4288 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4289 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4291 /* These signals are used internally by user-level thread
4292 implementations. (See signal(5) on Solaris.) Like the above
4293 signals, a healthy program receives and handles them as part of
4294 its normal operation. */
4295 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4296 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4297 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4298 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4299 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4300 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4304 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4305 (char *) &stop_on_solib_events
,
4306 "Set stopping for shared library events.\n\
4307 If nonzero, gdb will give control to the user when the dynamic linker\n\
4308 notifies gdb of shared library events. The most common event of interest\n\
4309 to the user would be loading/unloading of a new library.\n",
4314 c
= add_set_enum_cmd ("follow-fork-mode",
4316 follow_fork_mode_kind_names
,
4317 &follow_fork_mode_string
,
4318 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4319 kernel problem. It's also not terribly useful without a GUI to
4320 help the user drive two debuggers. So for now, I'm disabling
4321 the "both" option. */
4322 /* "Set debugger response to a program call of fork \
4324 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4325 parent - the original process is debugged after a fork\n\
4326 child - the new process is debugged after a fork\n\
4327 both - both the parent and child are debugged after a fork\n\
4328 ask - the debugger will ask for one of the above choices\n\
4329 For \"both\", another copy of the debugger will be started to follow\n\
4330 the new child process. The original debugger will continue to follow\n\
4331 the original parent process. To distinguish their prompts, the\n\
4332 debugger copy's prompt will be changed.\n\
4333 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4334 By default, the debugger will follow the parent process.",
4336 "Set debugger response to a program call of fork \
4338 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4339 parent - the original process is debugged after a fork\n\
4340 child - the new process is debugged after a fork\n\
4341 ask - the debugger will ask for one of the above choices\n\
4342 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4343 By default, the debugger will follow the parent process.",
4345 add_show_from_set (c
, &showlist
);
4347 c
= add_set_enum_cmd ("scheduler-locking", class_run
,
4348 scheduler_enums
, /* array of string names */
4349 &scheduler_mode
, /* current mode */
4350 "Set mode for locking scheduler during execution.\n\
4351 off == no locking (threads may preempt at any time)\n\
4352 on == full locking (no thread except the current thread may run)\n\
4353 step == scheduler locked during every single-step operation.\n\
4354 In this mode, no other thread may run during a step command.\n\
4355 Other threads may run while stepping over a function call ('next').",
4358 set_cmd_sfunc (c
, set_schedlock_func
); /* traps on target vector */
4359 add_show_from_set (c
, &showlist
);
4361 c
= add_set_cmd ("step-mode", class_run
,
4362 var_boolean
, (char*) &step_stop_if_no_debug
,
4363 "Set mode of the step operation. When set, doing a step over a\n\
4364 function without debug line information will stop at the first\n\
4365 instruction of that function. Otherwise, the function is skipped and\n\
4366 the step command stops at a different source line.",
4368 add_show_from_set (c
, &showlist
);
4370 /* ptid initializations */
4371 null_ptid
= ptid_build (0, 0, 0);
4372 minus_one_ptid
= ptid_build (-1, 0, 0);
4373 inferior_ptid
= null_ptid
;
4374 target_last_wait_ptid
= minus_one_ptid
;