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 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
118 program. It needs to examine the jmp_buf argument and extract the PC
119 from it. The return value is non-zero on success, zero otherwise. */
121 #ifndef GET_LONGJMP_TARGET
122 #define GET_LONGJMP_TARGET(PC_ADDR) 0
126 /* Dynamic function trampolines are similar to solib trampolines in that they
127 are between the caller and the callee. The difference is that when you
128 enter a dynamic trampoline, you can't determine the callee's address. Some
129 (usually complex) code needs to run in the dynamic trampoline to figure out
130 the callee's address. This macro is usually called twice. First, when we
131 enter the trampoline (looks like a normal function call at that point). It
132 should return the PC of a point within the trampoline where the callee's
133 address is known. Second, when we hit the breakpoint, this routine returns
134 the callee's address. At that point, things proceed as per a step resume
137 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
138 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
141 /* If the program uses ELF-style shared libraries, then calls to
142 functions in shared libraries go through stubs, which live in a
143 table called the PLT (Procedure Linkage Table). The first time the
144 function is called, the stub sends control to the dynamic linker,
145 which looks up the function's real address, patches the stub so
146 that future calls will go directly to the function, and then passes
147 control to the function.
149 If we are stepping at the source level, we don't want to see any of
150 this --- we just want to skip over the stub and the dynamic linker.
151 The simple approach is to single-step until control leaves the
154 However, on some systems (e.g., Red Hat Linux 5.2) the dynamic
155 linker calls functions in the shared C library, so you can't tell
156 from the PC alone whether the dynamic linker is still running. In
157 this case, we use a step-resume breakpoint to get us past the
158 dynamic linker, as if we were using "next" to step over a function
161 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
162 linker code or not. Normally, this means we single-step. However,
163 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
164 address where we can place a step-resume breakpoint to get past the
165 linker's symbol resolution function.
167 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
168 pretty portable way, by comparing the PC against the address ranges
169 of the dynamic linker's sections.
171 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
172 it depends on internal details of the dynamic linker. It's usually
173 not too hard to figure out where to put a breakpoint, but it
174 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
175 sanity checking. If it can't figure things out, returning zero and
176 getting the (possibly confusing) stepping behavior is better than
177 signalling an error, which will obscure the change in the
180 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
181 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
184 #ifndef SKIP_SOLIB_RESOLVER
185 #define SKIP_SOLIB_RESOLVER(pc) 0
188 /* In some shared library schemes, the return path from a shared library
189 call may need to go through a trampoline too. */
191 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
192 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
195 /* This function returns TRUE if pc is the address of an instruction
196 that lies within the dynamic linker (such as the event hook, or the
199 This function must be used only when a dynamic linker event has
200 been caught, and the inferior is being stepped out of the hook, or
201 undefined results are guaranteed. */
203 #ifndef SOLIB_IN_DYNAMIC_LINKER
204 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
207 /* On MIPS16, a function that returns a floating point value may call
208 a library helper function to copy the return value to a floating point
209 register. The IGNORE_HELPER_CALL macro returns non-zero if we
210 should ignore (i.e. step over) this function call. */
211 #ifndef IGNORE_HELPER_CALL
212 #define IGNORE_HELPER_CALL(pc) 0
215 /* On some systems, the PC may be left pointing at an instruction that won't
216 actually be executed. This is usually indicated by a bit in the PSW. If
217 we find ourselves in such a state, then we step the target beyond the
218 nullified instruction before returning control to the user so as to avoid
221 #ifndef INSTRUCTION_NULLIFIED
222 #define INSTRUCTION_NULLIFIED 0
225 /* We can't step off a permanent breakpoint in the ordinary way, because we
226 can't remove it. Instead, we have to advance the PC to the next
227 instruction. This macro should expand to a pointer to a function that
228 does that, or zero if we have no such function. If we don't have a
229 definition for it, we have to report an error. */
230 #ifndef SKIP_PERMANENT_BREAKPOINT
231 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
233 default_skip_permanent_breakpoint (void)
236 fprintf_filtered (gdb_stderr
, "\
237 The program is stopped at a permanent breakpoint, but GDB does not know\n\
238 how to step past a permanent breakpoint on this architecture. Try using\n\
239 a command like `return' or `jump' to continue execution.\n");
240 return_to_top_level (RETURN_ERROR
);
245 /* Convert the #defines into values. This is temporary until wfi control
246 flow is completely sorted out. */
248 #ifndef HAVE_STEPPABLE_WATCHPOINT
249 #define HAVE_STEPPABLE_WATCHPOINT 0
251 #undef HAVE_STEPPABLE_WATCHPOINT
252 #define HAVE_STEPPABLE_WATCHPOINT 1
255 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
256 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
258 #undef HAVE_NONSTEPPABLE_WATCHPOINT
259 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
262 #ifndef HAVE_CONTINUABLE_WATCHPOINT
263 #define HAVE_CONTINUABLE_WATCHPOINT 0
265 #undef HAVE_CONTINUABLE_WATCHPOINT
266 #define HAVE_CONTINUABLE_WATCHPOINT 1
269 #ifndef CANNOT_STEP_HW_WATCHPOINTS
270 #define CANNOT_STEP_HW_WATCHPOINTS 0
272 #undef CANNOT_STEP_HW_WATCHPOINTS
273 #define CANNOT_STEP_HW_WATCHPOINTS 1
276 /* Tables of how to react to signals; the user sets them. */
278 static unsigned char *signal_stop
;
279 static unsigned char *signal_print
;
280 static unsigned char *signal_program
;
282 #define SET_SIGS(nsigs,sigs,flags) \
284 int signum = (nsigs); \
285 while (signum-- > 0) \
286 if ((sigs)[signum]) \
287 (flags)[signum] = 1; \
290 #define UNSET_SIGS(nsigs,sigs,flags) \
292 int signum = (nsigs); \
293 while (signum-- > 0) \
294 if ((sigs)[signum]) \
295 (flags)[signum] = 0; \
298 /* Value to pass to target_resume() to cause all threads to resume */
300 #define RESUME_ALL (pid_to_ptid (-1))
302 /* Command list pointer for the "stop" placeholder. */
304 static struct cmd_list_element
*stop_command
;
306 /* Nonzero if breakpoints are now inserted in the inferior. */
308 static int breakpoints_inserted
;
310 /* Function inferior was in as of last step command. */
312 static struct symbol
*step_start_function
;
314 /* Nonzero if we are expecting a trace trap and should proceed from it. */
316 static int trap_expected
;
319 /* Nonzero if we want to give control to the user when we're notified
320 of shared library events by the dynamic linker. */
321 static int stop_on_solib_events
;
325 /* Nonzero if the next time we try to continue the inferior, it will
326 step one instruction and generate a spurious trace trap.
327 This is used to compensate for a bug in HP-UX. */
329 static int trap_expected_after_continue
;
332 /* Nonzero means expecting a trace trap
333 and should stop the inferior and return silently when it happens. */
337 /* Nonzero means expecting a trap and caller will handle it themselves.
338 It is used after attach, due to attaching to a process;
339 when running in the shell before the child program has been exec'd;
340 and when running some kinds of remote stuff (FIXME?). */
342 int stop_soon_quietly
;
344 /* Nonzero if proceed is being used for a "finish" command or a similar
345 situation when stop_registers should be saved. */
347 int proceed_to_finish
;
349 /* Save register contents here when about to pop a stack dummy frame,
350 if-and-only-if proceed_to_finish is set.
351 Thus this contains the return value from the called function (assuming
352 values are returned in a register). */
354 char *stop_registers
;
356 /* Nonzero if program stopped due to error trying to insert breakpoints. */
358 static int breakpoints_failed
;
360 /* Nonzero after stop if current stack frame should be printed. */
362 static int stop_print_frame
;
364 static struct breakpoint
*step_resume_breakpoint
= NULL
;
365 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
367 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
368 interactions with an inferior that is running a kernel function
369 (aka, a system call or "syscall"). wait_for_inferior therefore
370 may have a need to know when the inferior is in a syscall. This
371 is a count of the number of inferior threads which are known to
372 currently be running in a syscall. */
373 static int number_of_threads_in_syscalls
;
375 /* This is a cached copy of the pid/waitstatus of the last event
376 returned by target_wait()/target_wait_hook(). This information is
377 returned by get_last_target_status(). */
378 static ptid_t target_last_wait_ptid
;
379 static struct target_waitstatus target_last_waitstatus
;
381 /* This is used to remember when a fork, vfork or exec event
382 was caught by a catchpoint, and thus the event is to be
383 followed at the next resume of the inferior, and not
387 enum target_waitkind kind
;
397 char *execd_pathname
;
401 /* Some platforms don't allow us to do anything meaningful with a
402 vforked child until it has exec'd. Vforked processes on such
403 platforms can only be followed after they've exec'd.
405 When this is set to 0, a vfork can be immediately followed,
406 and an exec can be followed merely as an exec. When this is
407 set to 1, a vfork event has been seen, but cannot be followed
408 until the exec is seen.
410 (In the latter case, inferior_ptid is still the parent of the
411 vfork, and pending_follow.fork_event.child_pid is the child. The
412 appropriate process is followed, according to the setting of
413 follow-fork-mode.) */
414 static int follow_vfork_when_exec
;
416 static const char follow_fork_mode_ask
[] = "ask";
417 static const char follow_fork_mode_both
[] = "both";
418 static const char follow_fork_mode_child
[] = "child";
419 static const char follow_fork_mode_parent
[] = "parent";
421 static const char *follow_fork_mode_kind_names
[] =
423 follow_fork_mode_ask
,
424 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
425 kernel problem. It's also not terribly useful without a GUI to
426 help the user drive two debuggers. So for now, I'm disabling the
428 /* follow_fork_mode_both, */
429 follow_fork_mode_child
,
430 follow_fork_mode_parent
,
434 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
438 follow_inferior_fork (int parent_pid
, int child_pid
, int has_forked
,
441 int followed_parent
= 0;
442 int followed_child
= 0;
444 /* Which process did the user want us to follow? */
445 const char *follow_mode
= follow_fork_mode_string
;
447 /* Or, did the user not know, and want us to ask? */
448 if (follow_fork_mode_string
== follow_fork_mode_ask
)
450 internal_error (__FILE__
, __LINE__
,
451 "follow_inferior_fork: \"ask\" mode not implemented");
452 /* follow_mode = follow_fork_mode_...; */
455 /* If we're to be following the parent, then detach from child_pid.
456 We're already following the parent, so need do nothing explicit
458 if (follow_mode
== follow_fork_mode_parent
)
462 /* We're already attached to the parent, by default. */
464 /* Before detaching from the child, remove all breakpoints from
465 it. (This won't actually modify the breakpoint list, but will
466 physically remove the breakpoints from the child.) */
467 if (!has_vforked
|| !follow_vfork_when_exec
)
469 detach_breakpoints (child_pid
);
470 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
471 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
475 /* Detach from the child. */
478 target_require_detach (child_pid
, "", 1);
481 /* If we're to be following the child, then attach to it, detach
482 from inferior_ptid, and set inferior_ptid to child_pid. */
483 else if (follow_mode
== follow_fork_mode_child
)
485 char child_pid_spelling
[100]; /* Arbitrary length. */
489 /* Before detaching from the parent, detach all breakpoints from
490 the child. But only if we're forking, or if we follow vforks
491 as soon as they happen. (If we're following vforks only when
492 the child has exec'd, then it's very wrong to try to write
493 back the "shadow contents" of inserted breakpoints now -- they
494 belong to the child's pre-exec'd a.out.) */
495 if (!has_vforked
|| !follow_vfork_when_exec
)
497 detach_breakpoints (child_pid
);
500 /* Before detaching from the parent, remove all breakpoints from it. */
501 remove_breakpoints ();
503 /* Also reset the solib inferior hook from the parent. */
504 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
505 SOLIB_REMOVE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
508 /* Detach from the parent. */
510 target_detach (NULL
, 1);
512 /* Attach to the child. */
513 inferior_ptid
= pid_to_ptid (child_pid
);
514 sprintf (child_pid_spelling
, "%d", child_pid
);
517 target_require_attach (child_pid_spelling
, 1);
519 /* Was there a step_resume breakpoint? (There was if the user
520 did a "next" at the fork() call.) If so, explicitly reset its
523 step_resumes are a form of bp that are made to be per-thread.
524 Since we created the step_resume bp when the parent process
525 was being debugged, and now are switching to the child process,
526 from the breakpoint package's viewpoint, that's a switch of
527 "threads". We must update the bp's notion of which thread
528 it is for, or it'll be ignored when it triggers... */
529 if (step_resume_breakpoint
&&
530 (!has_vforked
|| !follow_vfork_when_exec
))
531 breakpoint_re_set_thread (step_resume_breakpoint
);
533 /* Reinsert all breakpoints in the child. (The user may've set
534 breakpoints after catching the fork, in which case those
535 actually didn't get set in the child, but only in the parent.) */
536 if (!has_vforked
|| !follow_vfork_when_exec
)
538 breakpoint_re_set ();
539 insert_breakpoints ();
543 /* If we're to be following both parent and child, then fork ourselves,
544 and attach the debugger clone to the child. */
545 else if (follow_mode
== follow_fork_mode_both
)
547 char pid_suffix
[100]; /* Arbitrary length. */
549 /* Clone ourselves to follow the child. This is the end of our
550 involvement with child_pid; our clone will take it from here... */
552 target_clone_and_follow_inferior (child_pid
, &followed_child
);
553 followed_parent
= !followed_child
;
555 /* We continue to follow the parent. To help distinguish the two
556 debuggers, though, both we and our clone will reset our prompts. */
557 sprintf (pid_suffix
, "[%d] ", PIDGET (inferior_ptid
));
558 set_prompt (strcat (get_prompt (), pid_suffix
));
561 /* The parent and child of a vfork share the same address space.
562 Also, on some targets the order in which vfork and exec events
563 are received for parent in child requires some delicate handling
566 For instance, on ptrace-based HPUX we receive the child's vfork
567 event first, at which time the parent has been suspended by the
568 OS and is essentially untouchable until the child's exit or second
569 exec event arrives. At that time, the parent's vfork event is
570 delivered to us, and that's when we see and decide how to follow
571 the vfork. But to get to that point, we must continue the child
572 until it execs or exits. To do that smoothly, all breakpoints
573 must be removed from the child, in case there are any set between
574 the vfork() and exec() calls. But removing them from the child
575 also removes them from the parent, due to the shared-address-space
576 nature of a vfork'd parent and child. On HPUX, therefore, we must
577 take care to restore the bp's to the parent before we continue it.
578 Else, it's likely that we may not stop in the expected place. (The
579 worst scenario is when the user tries to step over a vfork() call;
580 the step-resume bp must be restored for the step to properly stop
581 in the parent after the call completes!)
583 Sequence of events, as reported to gdb from HPUX:
585 Parent Child Action for gdb to take
586 -------------------------------------------------------
587 1 VFORK Continue child
593 target_post_follow_vfork (parent_pid
,
599 pending_follow
.fork_event
.saw_parent_fork
= 0;
600 pending_follow
.fork_event
.saw_child_fork
= 0;
604 follow_fork (int parent_pid
, int child_pid
)
606 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
610 /* Forward declaration. */
611 static void follow_exec (int, char *);
614 follow_vfork (int parent_pid
, int child_pid
)
616 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
618 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
619 if (pending_follow
.fork_event
.saw_child_exec
620 && (PIDGET (inferior_ptid
) == child_pid
))
622 pending_follow
.fork_event
.saw_child_exec
= 0;
623 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
624 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
625 xfree (pending_follow
.execd_pathname
);
629 /* EXECD_PATHNAME is assumed to be non-NULL. */
632 follow_exec (int pid
, char *execd_pathname
)
635 struct target_ops
*tgt
;
637 if (!may_follow_exec
)
640 /* Did this exec() follow a vfork()? If so, we must follow the
641 vfork now too. Do it before following the exec. */
642 if (follow_vfork_when_exec
&&
643 (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
))
645 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
646 follow_vfork (PIDGET (inferior_ptid
),
647 pending_follow
.fork_event
.child_pid
);
648 follow_vfork_when_exec
= 0;
649 saved_pid
= PIDGET (inferior_ptid
);
651 /* Did we follow the parent? If so, we're done. If we followed
652 the child then we must also follow its exec(). */
653 if (PIDGET (inferior_ptid
) == pending_follow
.fork_event
.parent_pid
)
657 /* This is an exec event that we actually wish to pay attention to.
658 Refresh our symbol table to the newly exec'd program, remove any
661 If there are breakpoints, they aren't really inserted now,
662 since the exec() transformed our inferior into a fresh set
665 We want to preserve symbolic breakpoints on the list, since
666 we have hopes that they can be reset after the new a.out's
667 symbol table is read.
669 However, any "raw" breakpoints must be removed from the list
670 (e.g., the solib bp's), since their address is probably invalid
673 And, we DON'T want to call delete_breakpoints() here, since
674 that may write the bp's "shadow contents" (the instruction
675 value that was overwritten witha TRAP instruction). Since
676 we now have a new a.out, those shadow contents aren't valid. */
677 update_breakpoints_after_exec ();
679 /* If there was one, it's gone now. We cannot truly step-to-next
680 statement through an exec(). */
681 step_resume_breakpoint
= NULL
;
682 step_range_start
= 0;
685 /* If there was one, it's gone now. */
686 through_sigtramp_breakpoint
= NULL
;
688 /* What is this a.out's name? */
689 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
691 /* We've followed the inferior through an exec. Therefore, the
692 inferior has essentially been killed & reborn. */
694 /* First collect the run target in effect. */
695 tgt
= find_run_target ();
696 /* If we can't find one, things are in a very strange state... */
698 error ("Could find run target to save before following exec");
700 gdb_flush (gdb_stdout
);
701 target_mourn_inferior ();
702 inferior_ptid
= pid_to_ptid (saved_pid
);
703 /* Because mourn_inferior resets inferior_ptid. */
706 /* That a.out is now the one to use. */
707 exec_file_attach (execd_pathname
, 0);
709 /* And also is where symbols can be found. */
710 symbol_file_add_main (execd_pathname
, 0);
712 /* Reset the shared library package. This ensures that we get
713 a shlib event when the child reaches "_start", at which point
714 the dld will have had a chance to initialize the child. */
715 #if defined(SOLIB_RESTART)
718 #ifdef SOLIB_CREATE_INFERIOR_HOOK
719 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
722 /* Reinsert all breakpoints. (Those which were symbolic have
723 been reset to the proper address in the new a.out, thanks
724 to symbol_file_command...) */
725 insert_breakpoints ();
727 /* The next resume of this inferior should bring it to the shlib
728 startup breakpoints. (If the user had also set bp's on
729 "main" from the old (parent) process, then they'll auto-
730 matically get reset there in the new process.) */
733 /* Non-zero if we just simulating a single-step. This is needed
734 because we cannot remove the breakpoints in the inferior process
735 until after the `wait' in `wait_for_inferior'. */
736 static int singlestep_breakpoints_inserted_p
= 0;
739 /* Things to clean up if we QUIT out of resume (). */
742 resume_cleanups (void *ignore
)
747 static const char schedlock_off
[] = "off";
748 static const char schedlock_on
[] = "on";
749 static const char schedlock_step
[] = "step";
750 static const char *scheduler_mode
= schedlock_off
;
751 static const char *scheduler_enums
[] =
760 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
762 if (c
->type
== set_cmd
)
763 if (!target_can_lock_scheduler
)
765 scheduler_mode
= schedlock_off
;
766 error ("Target '%s' cannot support this command.",
772 /* Resume the inferior, but allow a QUIT. This is useful if the user
773 wants to interrupt some lengthy single-stepping operation
774 (for child processes, the SIGINT goes to the inferior, and so
775 we get a SIGINT random_signal, but for remote debugging and perhaps
776 other targets, that's not true).
778 STEP nonzero if we should step (zero to continue instead).
779 SIG is the signal to give the inferior (zero for none). */
781 resume (int step
, enum target_signal sig
)
783 int should_resume
= 1;
784 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
787 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
790 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
791 over an instruction that causes a page fault without triggering
792 a hardware watchpoint. The kernel properly notices that it shouldn't
793 stop, because the hardware watchpoint is not triggered, but it forgets
794 the step request and continues the program normally.
795 Work around the problem by removing hardware watchpoints if a step is
796 requested, GDB will check for a hardware watchpoint trigger after the
798 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
799 remove_hw_watchpoints ();
802 /* Normally, by the time we reach `resume', the breakpoints are either
803 removed or inserted, as appropriate. The exception is if we're sitting
804 at a permanent breakpoint; we need to step over it, but permanent
805 breakpoints can't be removed. So we have to test for it here. */
806 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
807 SKIP_PERMANENT_BREAKPOINT ();
809 if (SOFTWARE_SINGLE_STEP_P () && step
)
811 /* Do it the hard way, w/temp breakpoints */
812 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
813 /* ...and don't ask hardware to do it. */
815 /* and do not pull these breakpoints until after a `wait' in
816 `wait_for_inferior' */
817 singlestep_breakpoints_inserted_p
= 1;
820 /* Handle any optimized stores to the inferior NOW... */
821 #ifdef DO_DEFERRED_STORES
825 /* If there were any forks/vforks/execs that were caught and are
826 now to be followed, then do so. */
827 switch (pending_follow
.kind
)
829 case (TARGET_WAITKIND_FORKED
):
830 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
831 follow_fork (PIDGET (inferior_ptid
),
832 pending_follow
.fork_event
.child_pid
);
835 case (TARGET_WAITKIND_VFORKED
):
837 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
839 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
840 follow_vfork (PIDGET (inferior_ptid
),
841 pending_follow
.fork_event
.child_pid
);
843 /* Did we follow the child, but not yet see the child's exec event?
844 If so, then it actually ought to be waiting for us; we respond to
845 parent vfork events. We don't actually want to resume the child
846 in this situation; we want to just get its exec event. */
847 if (!saw_child_exec
&&
848 (PIDGET (inferior_ptid
) == pending_follow
.fork_event
.child_pid
))
853 case (TARGET_WAITKIND_EXECD
):
854 /* If we saw a vfork event but couldn't follow it until we saw
855 an exec, then now might be the time! */
856 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
857 /* follow_exec is called as soon as the exec event is seen. */
864 /* Install inferior's terminal modes. */
865 target_terminal_inferior ();
871 resume_ptid
= RESUME_ALL
; /* Default */
873 if ((step
|| singlestep_breakpoints_inserted_p
) &&
874 !breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
876 /* Stepping past a breakpoint without inserting breakpoints.
877 Make sure only the current thread gets to step, so that
878 other threads don't sneak past breakpoints while they are
881 resume_ptid
= inferior_ptid
;
884 if ((scheduler_mode
== schedlock_on
) ||
885 (scheduler_mode
== schedlock_step
&&
886 (step
|| singlestep_breakpoints_inserted_p
)))
888 /* User-settable 'scheduler' mode requires solo thread resume. */
889 resume_ptid
= inferior_ptid
;
892 #ifdef CANNOT_STEP_BREAKPOINT
893 /* Most targets can step a breakpoint instruction, thus executing it
894 normally. But if this one cannot, just continue and we will hit
896 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
899 target_resume (resume_ptid
, step
, sig
);
902 discard_cleanups (old_cleanups
);
906 /* Clear out all variables saying what to do when inferior is continued.
907 First do this, then set the ones you want, then call `proceed'. */
910 clear_proceed_status (void)
913 step_range_start
= 0;
915 step_frame_address
= 0;
916 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
918 stop_soon_quietly
= 0;
919 proceed_to_finish
= 0;
920 breakpoint_proceeded
= 1; /* We're about to proceed... */
922 /* Discard any remaining commands or status from previous stop. */
923 bpstat_clear (&stop_bpstat
);
926 /* Basic routine for continuing the program in various fashions.
928 ADDR is the address to resume at, or -1 for resume where stopped.
929 SIGGNAL is the signal to give it, or 0 for none,
930 or -1 for act according to how it stopped.
931 STEP is nonzero if should trap after one instruction.
932 -1 means return after that and print nothing.
933 You should probably set various step_... variables
934 before calling here, if you are stepping.
936 You should call clear_proceed_status before calling proceed. */
939 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
944 step_start_function
= find_pc_function (read_pc ());
948 if (addr
== (CORE_ADDR
) -1)
950 /* If there is a breakpoint at the address we will resume at,
951 step one instruction before inserting breakpoints
952 so that we do not stop right away (and report a second
953 hit at this breakpoint). */
955 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
958 #ifndef STEP_SKIPS_DELAY
959 #define STEP_SKIPS_DELAY(pc) (0)
960 #define STEP_SKIPS_DELAY_P (0)
962 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
963 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
964 is slow (it needs to read memory from the target). */
965 if (STEP_SKIPS_DELAY_P
966 && breakpoint_here_p (read_pc () + 4)
967 && STEP_SKIPS_DELAY (read_pc ()))
975 #ifdef PREPARE_TO_PROCEED
976 /* In a multi-threaded task we may select another thread
977 and then continue or step.
979 But if the old thread was stopped at a breakpoint, it
980 will immediately cause another breakpoint stop without
981 any execution (i.e. it will report a breakpoint hit
982 incorrectly). So we must step over it first.
984 PREPARE_TO_PROCEED checks the current thread against the thread
985 that reported the most recent event. If a step-over is required
986 it returns TRUE and sets the current thread to the old thread. */
987 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
992 #endif /* PREPARE_TO_PROCEED */
995 if (trap_expected_after_continue
)
997 /* If (step == 0), a trap will be automatically generated after
998 the first instruction is executed. Force step one
999 instruction to clear this condition. This should not occur
1000 if step is nonzero, but it is harmless in that case. */
1002 trap_expected_after_continue
= 0;
1004 #endif /* HP_OS_BUG */
1007 /* We will get a trace trap after one instruction.
1008 Continue it automatically and insert breakpoints then. */
1012 int temp
= insert_breakpoints ();
1015 print_sys_errmsg ("insert_breakpoints", temp
);
1016 error ("Cannot insert breakpoints.\n\
1017 The same program may be running in another process,\n\
1018 or you may have requested too many hardware\n\
1019 breakpoints and/or watchpoints.\n");
1022 breakpoints_inserted
= 1;
1025 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1026 stop_signal
= siggnal
;
1027 /* If this signal should not be seen by program,
1028 give it zero. Used for debugging signals. */
1029 else if (!signal_program
[stop_signal
])
1030 stop_signal
= TARGET_SIGNAL_0
;
1032 annotate_starting ();
1034 /* Make sure that output from GDB appears before output from the
1036 gdb_flush (gdb_stdout
);
1038 /* Resume inferior. */
1039 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1041 /* Wait for it to stop (if not standalone)
1042 and in any case decode why it stopped, and act accordingly. */
1043 /* Do this only if we are not using the event loop, or if the target
1044 does not support asynchronous execution. */
1045 if (!event_loop_p
|| !target_can_async_p ())
1047 wait_for_inferior ();
1052 /* Record the pc and sp of the program the last time it stopped.
1053 These are just used internally by wait_for_inferior, but need
1054 to be preserved over calls to it and cleared when the inferior
1056 static CORE_ADDR prev_pc
;
1057 static CORE_ADDR prev_func_start
;
1058 static char *prev_func_name
;
1061 /* Start remote-debugging of a machine over a serial link. */
1066 init_thread_list ();
1067 init_wait_for_inferior ();
1068 stop_soon_quietly
= 1;
1071 /* Always go on waiting for the target, regardless of the mode. */
1072 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1073 indicate to wait_for_inferior that a target should timeout if
1074 nothing is returned (instead of just blocking). Because of this,
1075 targets expecting an immediate response need to, internally, set
1076 things up so that the target_wait() is forced to eventually
1078 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1079 differentiate to its caller what the state of the target is after
1080 the initial open has been performed. Here we're assuming that
1081 the target has stopped. It should be possible to eventually have
1082 target_open() return to the caller an indication that the target
1083 is currently running and GDB state should be set to the same as
1084 for an async run. */
1085 wait_for_inferior ();
1089 /* Initialize static vars when a new inferior begins. */
1092 init_wait_for_inferior (void)
1094 /* These are meaningless until the first time through wait_for_inferior. */
1096 prev_func_start
= 0;
1097 prev_func_name
= NULL
;
1100 trap_expected_after_continue
= 0;
1102 breakpoints_inserted
= 0;
1103 breakpoint_init_inferior (inf_starting
);
1105 /* Don't confuse first call to proceed(). */
1106 stop_signal
= TARGET_SIGNAL_0
;
1108 /* The first resume is not following a fork/vfork/exec. */
1109 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1110 pending_follow
.fork_event
.saw_parent_fork
= 0;
1111 pending_follow
.fork_event
.saw_child_fork
= 0;
1112 pending_follow
.fork_event
.saw_child_exec
= 0;
1114 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1115 number_of_threads_in_syscalls
= 0;
1117 clear_proceed_status ();
1121 delete_breakpoint_current_contents (void *arg
)
1123 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1124 if (*breakpointp
!= NULL
)
1126 delete_breakpoint (*breakpointp
);
1127 *breakpointp
= NULL
;
1131 /* This enum encodes possible reasons for doing a target_wait, so that
1132 wfi can call target_wait in one place. (Ultimately the call will be
1133 moved out of the infinite loop entirely.) */
1137 infwait_normal_state
,
1138 infwait_thread_hop_state
,
1139 infwait_nullified_state
,
1140 infwait_nonstep_watch_state
1143 /* Why did the inferior stop? Used to print the appropriate messages
1144 to the interface from within handle_inferior_event(). */
1145 enum inferior_stop_reason
1147 /* We don't know why. */
1149 /* Step, next, nexti, stepi finished. */
1151 /* Found breakpoint. */
1153 /* Inferior terminated by signal. */
1155 /* Inferior exited. */
1157 /* Inferior received signal, and user asked to be notified. */
1161 /* This structure contains what used to be local variables in
1162 wait_for_inferior. Probably many of them can return to being
1163 locals in handle_inferior_event. */
1165 struct execution_control_state
1167 struct target_waitstatus ws
;
1168 struct target_waitstatus
*wp
;
1171 CORE_ADDR stop_func_start
;
1172 CORE_ADDR stop_func_end
;
1173 char *stop_func_name
;
1174 struct symtab_and_line sal
;
1175 int remove_breakpoints_on_following_step
;
1177 struct symtab
*current_symtab
;
1178 int handling_longjmp
; /* FIXME */
1180 ptid_t saved_inferior_ptid
;
1182 int stepping_through_solib_after_catch
;
1183 bpstat stepping_through_solib_catchpoints
;
1184 int enable_hw_watchpoints_after_wait
;
1185 int stepping_through_sigtramp
;
1186 int new_thread_event
;
1187 struct target_waitstatus tmpstatus
;
1188 enum infwait_states infwait_state
;
1193 void init_execution_control_state (struct execution_control_state
* ecs
);
1195 void handle_inferior_event (struct execution_control_state
* ecs
);
1197 static void check_sigtramp2 (struct execution_control_state
*ecs
);
1198 static void step_into_function (struct execution_control_state
*ecs
);
1199 static void step_over_function (struct execution_control_state
*ecs
);
1200 static void stop_stepping (struct execution_control_state
*ecs
);
1201 static void prepare_to_wait (struct execution_control_state
*ecs
);
1202 static void keep_going (struct execution_control_state
*ecs
);
1203 static void print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
);
1205 /* Wait for control to return from inferior to debugger.
1206 If inferior gets a signal, we may decide to start it up again
1207 instead of returning. That is why there is a loop in this function.
1208 When this function actually returns it means the inferior
1209 should be left stopped and GDB should read more commands. */
1212 wait_for_inferior (void)
1214 struct cleanup
*old_cleanups
;
1215 struct execution_control_state ecss
;
1216 struct execution_control_state
*ecs
;
1218 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1219 &step_resume_breakpoint
);
1220 make_cleanup (delete_breakpoint_current_contents
,
1221 &through_sigtramp_breakpoint
);
1223 /* wfi still stays in a loop, so it's OK just to take the address of
1224 a local to get the ecs pointer. */
1227 /* Fill in with reasonable starting values. */
1228 init_execution_control_state (ecs
);
1230 /* We'll update this if & when we switch to a new thread. */
1231 previous_inferior_ptid
= inferior_ptid
;
1233 overlay_cache_invalid
= 1;
1235 /* We have to invalidate the registers BEFORE calling target_wait
1236 because they can be loaded from the target while in target_wait.
1237 This makes remote debugging a bit more efficient for those
1238 targets that provide critical registers as part of their normal
1239 status mechanism. */
1241 registers_changed ();
1245 if (target_wait_hook
)
1246 ecs
->ptid
= target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
1248 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
1250 /* Now figure out what to do with the result of the result. */
1251 handle_inferior_event (ecs
);
1253 if (!ecs
->wait_some_more
)
1256 do_cleanups (old_cleanups
);
1259 /* Asynchronous version of wait_for_inferior. It is called by the
1260 event loop whenever a change of state is detected on the file
1261 descriptor corresponding to the target. It can be called more than
1262 once to complete a single execution command. In such cases we need
1263 to keep the state in a global variable ASYNC_ECSS. If it is the
1264 last time that this function is called for a single execution
1265 command, then report to the user that the inferior has stopped, and
1266 do the necessary cleanups. */
1268 struct execution_control_state async_ecss
;
1269 struct execution_control_state
*async_ecs
;
1272 fetch_inferior_event (void *client_data
)
1274 static struct cleanup
*old_cleanups
;
1276 async_ecs
= &async_ecss
;
1278 if (!async_ecs
->wait_some_more
)
1280 old_cleanups
= make_exec_cleanup (delete_step_resume_breakpoint
,
1281 &step_resume_breakpoint
);
1282 make_exec_cleanup (delete_breakpoint_current_contents
,
1283 &through_sigtramp_breakpoint
);
1285 /* Fill in with reasonable starting values. */
1286 init_execution_control_state (async_ecs
);
1288 /* We'll update this if & when we switch to a new thread. */
1289 previous_inferior_ptid
= inferior_ptid
;
1291 overlay_cache_invalid
= 1;
1293 /* We have to invalidate the registers BEFORE calling target_wait
1294 because they can be loaded from the target while in target_wait.
1295 This makes remote debugging a bit more efficient for those
1296 targets that provide critical registers as part of their normal
1297 status mechanism. */
1299 registers_changed ();
1302 if (target_wait_hook
)
1303 async_ecs
->ptid
= target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1305 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1307 /* Now figure out what to do with the result of the result. */
1308 handle_inferior_event (async_ecs
);
1310 if (!async_ecs
->wait_some_more
)
1312 /* Do only the cleanups that have been added by this
1313 function. Let the continuations for the commands do the rest,
1314 if there are any. */
1315 do_exec_cleanups (old_cleanups
);
1317 if (step_multi
&& stop_step
)
1318 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1320 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1324 /* Prepare an execution control state for looping through a
1325 wait_for_inferior-type loop. */
1328 init_execution_control_state (struct execution_control_state
*ecs
)
1330 /* ecs->another_trap? */
1331 ecs
->random_signal
= 0;
1332 ecs
->remove_breakpoints_on_following_step
= 0;
1333 ecs
->handling_longjmp
= 0; /* FIXME */
1334 ecs
->update_step_sp
= 0;
1335 ecs
->stepping_through_solib_after_catch
= 0;
1336 ecs
->stepping_through_solib_catchpoints
= NULL
;
1337 ecs
->enable_hw_watchpoints_after_wait
= 0;
1338 ecs
->stepping_through_sigtramp
= 0;
1339 ecs
->sal
= find_pc_line (prev_pc
, 0);
1340 ecs
->current_line
= ecs
->sal
.line
;
1341 ecs
->current_symtab
= ecs
->sal
.symtab
;
1342 ecs
->infwait_state
= infwait_normal_state
;
1343 ecs
->waiton_ptid
= pid_to_ptid (-1);
1344 ecs
->wp
= &(ecs
->ws
);
1347 /* Call this function before setting step_resume_breakpoint, as a
1348 sanity check. There should never be more than one step-resume
1349 breakpoint per thread, so we should never be setting a new
1350 step_resume_breakpoint when one is already active. */
1352 check_for_old_step_resume_breakpoint (void)
1354 if (step_resume_breakpoint
)
1355 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1358 /* Return the cached copy of the last pid/waitstatus returned by
1359 target_wait()/target_wait_hook(). The data is actually cached by
1360 handle_inferior_event(), which gets called immediately after
1361 target_wait()/target_wait_hook(). */
1364 get_last_target_status(ptid_t
*ptidp
, struct target_waitstatus
*status
)
1366 *ptidp
= target_last_wait_ptid
;
1367 *status
= target_last_waitstatus
;
1370 /* Switch thread contexts, maintaining "infrun state". */
1373 context_switch (struct execution_control_state
*ecs
)
1375 /* Caution: it may happen that the new thread (or the old one!)
1376 is not in the thread list. In this case we must not attempt
1377 to "switch context", or we run the risk that our context may
1378 be lost. This may happen as a result of the target module
1379 mishandling thread creation. */
1381 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1382 { /* Perform infrun state context switch: */
1383 /* Save infrun state for the old thread. */
1384 save_infrun_state (inferior_ptid
, prev_pc
,
1385 prev_func_start
, prev_func_name
,
1386 trap_expected
, step_resume_breakpoint
,
1387 through_sigtramp_breakpoint
, step_range_start
,
1388 step_range_end
, step_frame_address
,
1389 ecs
->handling_longjmp
, ecs
->another_trap
,
1390 ecs
->stepping_through_solib_after_catch
,
1391 ecs
->stepping_through_solib_catchpoints
,
1392 ecs
->stepping_through_sigtramp
,
1393 ecs
->current_line
, ecs
->current_symtab
,
1396 /* Load infrun state for the new thread. */
1397 load_infrun_state (ecs
->ptid
, &prev_pc
,
1398 &prev_func_start
, &prev_func_name
,
1399 &trap_expected
, &step_resume_breakpoint
,
1400 &through_sigtramp_breakpoint
, &step_range_start
,
1401 &step_range_end
, &step_frame_address
,
1402 &ecs
->handling_longjmp
, &ecs
->another_trap
,
1403 &ecs
->stepping_through_solib_after_catch
,
1404 &ecs
->stepping_through_solib_catchpoints
,
1405 &ecs
->stepping_through_sigtramp
,
1406 &ecs
->current_line
, &ecs
->current_symtab
,
1409 inferior_ptid
= ecs
->ptid
;
1413 /* Given an execution control state that has been freshly filled in
1414 by an event from the inferior, figure out what it means and take
1415 appropriate action. */
1418 handle_inferior_event (struct execution_control_state
*ecs
)
1421 int stepped_after_stopped_by_watchpoint
;
1423 /* Cache the last pid/waitstatus. */
1424 target_last_wait_ptid
= ecs
->ptid
;
1425 target_last_waitstatus
= *ecs
->wp
;
1427 /* Keep this extra brace for now, minimizes diffs. */
1429 switch (ecs
->infwait_state
)
1431 case infwait_thread_hop_state
:
1432 /* Cancel the waiton_ptid. */
1433 ecs
->waiton_ptid
= pid_to_ptid (-1);
1434 /* Fall thru to the normal_state case. */
1436 case infwait_normal_state
:
1437 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1438 is serviced in this loop, below. */
1439 if (ecs
->enable_hw_watchpoints_after_wait
)
1441 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1442 ecs
->enable_hw_watchpoints_after_wait
= 0;
1444 stepped_after_stopped_by_watchpoint
= 0;
1447 case infwait_nullified_state
:
1450 case infwait_nonstep_watch_state
:
1451 insert_breakpoints ();
1453 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1454 handle things like signals arriving and other things happening
1455 in combination correctly? */
1456 stepped_after_stopped_by_watchpoint
= 1;
1459 ecs
->infwait_state
= infwait_normal_state
;
1461 flush_cached_frames ();
1463 /* If it's a new process, add it to the thread database */
1465 ecs
->new_thread_event
= (! ptid_equal (ecs
->ptid
, inferior_ptid
)
1466 && ! in_thread_list (ecs
->ptid
));
1468 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1469 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1470 && ecs
->new_thread_event
)
1472 add_thread (ecs
->ptid
);
1474 ui_out_text (uiout
, "[New ");
1475 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->ptid
));
1476 ui_out_text (uiout
, "]\n");
1479 /* NOTE: This block is ONLY meant to be invoked in case of a
1480 "thread creation event"! If it is invoked for any other
1481 sort of event (such as a new thread landing on a breakpoint),
1482 the event will be discarded, which is almost certainly
1485 To avoid this, the low-level module (eg. target_wait)
1486 should call in_thread_list and add_thread, so that the
1487 new thread is known by the time we get here. */
1489 /* We may want to consider not doing a resume here in order
1490 to give the user a chance to play with the new thread.
1491 It might be good to make that a user-settable option. */
1493 /* At this point, all threads are stopped (happens
1494 automatically in either the OS or the native code).
1495 Therefore we need to continue all threads in order to
1498 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1499 prepare_to_wait (ecs
);
1504 switch (ecs
->ws
.kind
)
1506 case TARGET_WAITKIND_LOADED
:
1507 /* Ignore gracefully during startup of the inferior, as it
1508 might be the shell which has just loaded some objects,
1509 otherwise add the symbols for the newly loaded objects. */
1511 if (!stop_soon_quietly
)
1513 /* Remove breakpoints, SOLIB_ADD might adjust
1514 breakpoint addresses via breakpoint_re_set. */
1515 if (breakpoints_inserted
)
1516 remove_breakpoints ();
1518 /* Check for any newly added shared libraries if we're
1519 supposed to be adding them automatically. Switch
1520 terminal for any messages produced by
1521 breakpoint_re_set. */
1522 target_terminal_ours_for_output ();
1523 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
1524 target_terminal_inferior ();
1526 /* Reinsert breakpoints and continue. */
1527 if (breakpoints_inserted
)
1528 insert_breakpoints ();
1531 resume (0, TARGET_SIGNAL_0
);
1532 prepare_to_wait (ecs
);
1535 case TARGET_WAITKIND_SPURIOUS
:
1536 resume (0, TARGET_SIGNAL_0
);
1537 prepare_to_wait (ecs
);
1540 case TARGET_WAITKIND_EXITED
:
1541 target_terminal_ours (); /* Must do this before mourn anyway */
1542 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1544 /* Record the exit code in the convenience variable $_exitcode, so
1545 that the user can inspect this again later. */
1546 set_internalvar (lookup_internalvar ("_exitcode"),
1547 value_from_longest (builtin_type_int
,
1548 (LONGEST
) ecs
->ws
.value
.integer
));
1549 gdb_flush (gdb_stdout
);
1550 target_mourn_inferior ();
1551 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1552 stop_print_frame
= 0;
1553 stop_stepping (ecs
);
1556 case TARGET_WAITKIND_SIGNALLED
:
1557 stop_print_frame
= 0;
1558 stop_signal
= ecs
->ws
.value
.sig
;
1559 target_terminal_ours (); /* Must do this before mourn anyway */
1561 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1562 reach here unless the inferior is dead. However, for years
1563 target_kill() was called here, which hints that fatal signals aren't
1564 really fatal on some systems. If that's true, then some changes
1566 target_mourn_inferior ();
1568 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1569 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1570 stop_stepping (ecs
);
1573 /* The following are the only cases in which we keep going;
1574 the above cases end in a continue or goto. */
1575 case TARGET_WAITKIND_FORKED
:
1576 stop_signal
= TARGET_SIGNAL_TRAP
;
1577 pending_follow
.kind
= ecs
->ws
.kind
;
1579 /* Ignore fork events reported for the parent; we're only
1580 interested in reacting to forks of the child. Note that
1581 we expect the child's fork event to be available if we
1582 waited for it now. */
1583 if (ptid_equal (inferior_ptid
, ecs
->ptid
))
1585 pending_follow
.fork_event
.saw_parent_fork
= 1;
1586 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1587 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1588 prepare_to_wait (ecs
);
1593 pending_follow
.fork_event
.saw_child_fork
= 1;
1594 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1595 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1598 stop_pc
= read_pc_pid (ecs
->ptid
);
1599 ecs
->saved_inferior_ptid
= inferior_ptid
;
1600 inferior_ptid
= ecs
->ptid
;
1601 /* The second argument of bpstat_stop_status is meant to help
1602 distinguish between a breakpoint trap and a singlestep trap.
1603 This is only important on targets where DECR_PC_AFTER_BREAK
1604 is non-zero. The prev_pc test is meant to distinguish between
1605 singlestepping a trap instruction, and singlestepping thru a
1606 jump to the instruction following a trap instruction. */
1608 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1609 currently_stepping (ecs
) &&
1611 stop_pc
- DECR_PC_AFTER_BREAK
);
1612 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1613 inferior_ptid
= ecs
->saved_inferior_ptid
;
1614 goto process_event_stop_test
;
1616 /* If this a platform which doesn't allow a debugger to touch a
1617 vfork'd inferior until after it exec's, then we'd best keep
1618 our fingers entirely off the inferior, other than continuing
1619 it. This has the unfortunate side-effect that catchpoints
1620 of vforks will be ignored. But since the platform doesn't
1621 allow the inferior be touched at vfork time, there's really
1623 case TARGET_WAITKIND_VFORKED
:
1624 stop_signal
= TARGET_SIGNAL_TRAP
;
1625 pending_follow
.kind
= ecs
->ws
.kind
;
1627 /* Is this a vfork of the parent? If so, then give any
1628 vfork catchpoints a chance to trigger now. (It's
1629 dangerous to do so if the child canot be touched until
1630 it execs, and the child has not yet exec'd. We probably
1631 should warn the user to that effect when the catchpoint
1633 if (ptid_equal (ecs
->ptid
, inferior_ptid
))
1635 pending_follow
.fork_event
.saw_parent_fork
= 1;
1636 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1637 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1640 /* If we've seen the child's vfork event but cannot really touch
1641 the child until it execs, then we must continue the child now.
1642 Else, give any vfork catchpoints a chance to trigger now. */
1645 pending_follow
.fork_event
.saw_child_fork
= 1;
1646 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1647 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1648 target_post_startup_inferior (
1649 pid_to_ptid (pending_follow
.fork_event
.child_pid
));
1650 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1651 if (follow_vfork_when_exec
)
1653 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1654 prepare_to_wait (ecs
);
1659 stop_pc
= read_pc ();
1660 /* The second argument of bpstat_stop_status is meant to help
1661 distinguish between a breakpoint trap and a singlestep trap.
1662 This is only important on targets where DECR_PC_AFTER_BREAK
1663 is non-zero. The prev_pc test is meant to distinguish between
1664 singlestepping a trap instruction, and singlestepping thru a
1665 jump to the instruction following a trap instruction. */
1667 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1668 currently_stepping (ecs
) &&
1670 stop_pc
- DECR_PC_AFTER_BREAK
);
1671 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1672 goto process_event_stop_test
;
1674 case TARGET_WAITKIND_EXECD
:
1675 stop_signal
= TARGET_SIGNAL_TRAP
;
1677 /* Is this a target which reports multiple exec events per actual
1678 call to exec()? (HP-UX using ptrace does, for example.) If so,
1679 ignore all but the last one. Just resume the exec'r, and wait
1680 for the next exec event. */
1681 if (inferior_ignoring_leading_exec_events
)
1683 inferior_ignoring_leading_exec_events
--;
1684 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1685 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.parent_pid
);
1686 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1687 prepare_to_wait (ecs
);
1690 inferior_ignoring_leading_exec_events
=
1691 target_reported_exec_events_per_exec_call () - 1;
1693 pending_follow
.execd_pathname
=
1694 savestring (ecs
->ws
.value
.execd_pathname
,
1695 strlen (ecs
->ws
.value
.execd_pathname
));
1697 /* Did inferior_ptid exec, or did a (possibly not-yet-followed)
1698 child of a vfork exec?
1700 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1701 HP-UX, events associated with a vforking inferior come in
1702 threes: a vfork event for the child (always first), followed
1703 a vfork event for the parent and an exec event for the child.
1704 The latter two can come in either order.
1706 If we get the parent vfork event first, life's good: We follow
1707 either the parent or child, and then the child's exec event is
1710 But if we get the child's exec event first, then we delay
1711 responding to it until we handle the parent's vfork. Because,
1712 otherwise we can't satisfy a "catch vfork". */
1713 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1715 pending_follow
.fork_event
.saw_child_exec
= 1;
1717 /* On some targets, the child must be resumed before
1718 the parent vfork event is delivered. A single-step
1720 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1721 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1722 /* We expect the parent vfork event to be available now. */
1723 prepare_to_wait (ecs
);
1727 /* This causes the eventpoints and symbol table to be reset. Must
1728 do this now, before trying to determine whether to stop. */
1729 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1730 xfree (pending_follow
.execd_pathname
);
1732 stop_pc
= read_pc_pid (ecs
->ptid
);
1733 ecs
->saved_inferior_ptid
= inferior_ptid
;
1734 inferior_ptid
= ecs
->ptid
;
1735 /* The second argument of bpstat_stop_status is meant to help
1736 distinguish between a breakpoint trap and a singlestep trap.
1737 This is only important on targets where DECR_PC_AFTER_BREAK
1738 is non-zero. The prev_pc test is meant to distinguish between
1739 singlestepping a trap instruction, and singlestepping thru a
1740 jump to the instruction following a trap instruction. */
1742 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1743 currently_stepping (ecs
) &&
1745 stop_pc
- DECR_PC_AFTER_BREAK
);
1746 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1747 inferior_ptid
= ecs
->saved_inferior_ptid
;
1748 goto process_event_stop_test
;
1750 /* These syscall events are returned on HP-UX, as part of its
1751 implementation of page-protection-based "hardware" watchpoints.
1752 HP-UX has unfortunate interactions between page-protections and
1753 some system calls. Our solution is to disable hardware watches
1754 when a system call is entered, and reenable them when the syscall
1755 completes. The downside of this is that we may miss the precise
1756 point at which a watched piece of memory is modified. "Oh well."
1758 Note that we may have multiple threads running, which may each
1759 enter syscalls at roughly the same time. Since we don't have a
1760 good notion currently of whether a watched piece of memory is
1761 thread-private, we'd best not have any page-protections active
1762 when any thread is in a syscall. Thus, we only want to reenable
1763 hardware watches when no threads are in a syscall.
1765 Also, be careful not to try to gather much state about a thread
1766 that's in a syscall. It's frequently a losing proposition. */
1767 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1768 number_of_threads_in_syscalls
++;
1769 if (number_of_threads_in_syscalls
== 1)
1771 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1773 resume (0, TARGET_SIGNAL_0
);
1774 prepare_to_wait (ecs
);
1777 /* Before examining the threads further, step this thread to
1778 get it entirely out of the syscall. (We get notice of the
1779 event when the thread is just on the verge of exiting a
1780 syscall. Stepping one instruction seems to get it back
1783 Note that although the logical place to reenable h/w watches
1784 is here, we cannot. We cannot reenable them before stepping
1785 the thread (this causes the next wait on the thread to hang).
1787 Nor can we enable them after stepping until we've done a wait.
1788 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1789 here, which will be serviced immediately after the target
1791 case TARGET_WAITKIND_SYSCALL_RETURN
:
1792 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1794 if (number_of_threads_in_syscalls
> 0)
1796 number_of_threads_in_syscalls
--;
1797 ecs
->enable_hw_watchpoints_after_wait
=
1798 (number_of_threads_in_syscalls
== 0);
1800 prepare_to_wait (ecs
);
1803 case TARGET_WAITKIND_STOPPED
:
1804 stop_signal
= ecs
->ws
.value
.sig
;
1807 /* We had an event in the inferior, but we are not interested
1808 in handling it at this level. The lower layers have already
1809 done what needs to be done, if anything. This case can
1810 occur only when the target is async or extended-async. One
1811 of the circumstamces for this to happen is when the
1812 inferior produces output for the console. The inferior has
1813 not stopped, and we are ignoring the event. */
1814 case TARGET_WAITKIND_IGNORE
:
1815 ecs
->wait_some_more
= 1;
1819 /* We may want to consider not doing a resume here in order to give
1820 the user a chance to play with the new thread. It might be good
1821 to make that a user-settable option. */
1823 /* At this point, all threads are stopped (happens automatically in
1824 either the OS or the native code). Therefore we need to continue
1825 all threads in order to make progress. */
1826 if (ecs
->new_thread_event
)
1828 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1829 prepare_to_wait (ecs
);
1833 stop_pc
= read_pc_pid (ecs
->ptid
);
1835 /* See if a thread hit a thread-specific breakpoint that was meant for
1836 another thread. If so, then step that thread past the breakpoint,
1839 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1841 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1842 ecs
->random_signal
= 0;
1843 else if (breakpoints_inserted
1844 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1846 ecs
->random_signal
= 0;
1847 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1852 /* Saw a breakpoint, but it was hit by the wrong thread.
1854 if (DECR_PC_AFTER_BREAK
)
1855 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->ptid
);
1857 remove_status
= remove_breakpoints ();
1858 /* Did we fail to remove breakpoints? If so, try
1859 to set the PC past the bp. (There's at least
1860 one situation in which we can fail to remove
1861 the bp's: On HP-UX's that use ttrace, we can't
1862 change the address space of a vforking child
1863 process until the child exits (well, okay, not
1864 then either :-) or execs. */
1865 if (remove_status
!= 0)
1867 /* FIXME! This is obviously non-portable! */
1868 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4,
1870 /* We need to restart all the threads now,
1871 * unles we're running in scheduler-locked mode.
1872 * Use currently_stepping to determine whether to
1875 /* FIXME MVS: is there any reason not to call resume()? */
1876 if (scheduler_mode
== schedlock_on
)
1877 target_resume (ecs
->ptid
,
1878 currently_stepping (ecs
),
1881 target_resume (RESUME_ALL
,
1882 currently_stepping (ecs
),
1884 prepare_to_wait (ecs
);
1889 breakpoints_inserted
= 0;
1890 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
1891 context_switch (ecs
);
1892 ecs
->waiton_ptid
= ecs
->ptid
;
1893 ecs
->wp
= &(ecs
->ws
);
1894 ecs
->another_trap
= 1;
1896 ecs
->infwait_state
= infwait_thread_hop_state
;
1898 registers_changed ();
1905 ecs
->random_signal
= 1;
1907 /* See if something interesting happened to the non-current thread. If
1908 so, then switch to that thread, and eventually give control back to
1911 Note that if there's any kind of pending follow (i.e., of a fork,
1912 vfork or exec), we don't want to do this now. Rather, we'll let
1913 the next resume handle it. */
1914 if (! ptid_equal (ecs
->ptid
, inferior_ptid
) &&
1915 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1919 /* If it's a random signal for a non-current thread, notify user
1920 if he's expressed an interest. */
1921 if (ecs
->random_signal
1922 && signal_print
[stop_signal
])
1924 /* ??rehrauer: I don't understand the rationale for this code. If the
1925 inferior will stop as a result of this signal, then the act of handling
1926 the stop ought to print a message that's couches the stoppage in user
1927 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1928 won't stop as a result of the signal -- i.e., if the signal is merely
1929 a side-effect of something GDB's doing "under the covers" for the
1930 user, such as stepping threads over a breakpoint they shouldn't stop
1931 for -- then the message seems to be a serious annoyance at best.
1933 For now, remove the message altogether. */
1936 target_terminal_ours_for_output ();
1937 printf_filtered ("\nProgram received signal %s, %s.\n",
1938 target_signal_to_name (stop_signal
),
1939 target_signal_to_string (stop_signal
));
1940 gdb_flush (gdb_stdout
);
1944 /* If it's not SIGTRAP and not a signal we want to stop for, then
1945 continue the thread. */
1947 if (stop_signal
!= TARGET_SIGNAL_TRAP
1948 && !signal_stop
[stop_signal
])
1951 target_terminal_inferior ();
1953 /* Clear the signal if it should not be passed. */
1954 if (signal_program
[stop_signal
] == 0)
1955 stop_signal
= TARGET_SIGNAL_0
;
1957 target_resume (ecs
->ptid
, 0, stop_signal
);
1958 prepare_to_wait (ecs
);
1962 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1963 and fall into the rest of wait_for_inferior(). */
1965 context_switch (ecs
);
1968 context_hook (pid_to_thread_id (ecs
->ptid
));
1970 flush_cached_frames ();
1973 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1975 /* Pull the single step breakpoints out of the target. */
1976 SOFTWARE_SINGLE_STEP (0, 0);
1977 singlestep_breakpoints_inserted_p
= 0;
1980 /* If PC is pointing at a nullified instruction, then step beyond
1981 it so that the user won't be confused when GDB appears to be ready
1984 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1985 if (INSTRUCTION_NULLIFIED
)
1987 registers_changed ();
1988 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1990 /* We may have received a signal that we want to pass to
1991 the inferior; therefore, we must not clobber the waitstatus
1994 ecs
->infwait_state
= infwait_nullified_state
;
1995 ecs
->waiton_ptid
= ecs
->ptid
;
1996 ecs
->wp
= &(ecs
->tmpstatus
);
1997 prepare_to_wait (ecs
);
2001 /* It may not be necessary to disable the watchpoint to stop over
2002 it. For example, the PA can (with some kernel cooperation)
2003 single step over a watchpoint without disabling the watchpoint. */
2004 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2007 prepare_to_wait (ecs
);
2011 /* It is far more common to need to disable a watchpoint to step
2012 the inferior over it. FIXME. What else might a debug
2013 register or page protection watchpoint scheme need here? */
2014 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2016 /* At this point, we are stopped at an instruction which has
2017 attempted to write to a piece of memory under control of
2018 a watchpoint. The instruction hasn't actually executed
2019 yet. If we were to evaluate the watchpoint expression
2020 now, we would get the old value, and therefore no change
2021 would seem to have occurred.
2023 In order to make watchpoints work `right', we really need
2024 to complete the memory write, and then evaluate the
2025 watchpoint expression. The following code does that by
2026 removing the watchpoint (actually, all watchpoints and
2027 breakpoints), single-stepping the target, re-inserting
2028 watchpoints, and then falling through to let normal
2029 single-step processing handle proceed. Since this
2030 includes evaluating watchpoints, things will come to a
2031 stop in the correct manner. */
2033 if (DECR_PC_AFTER_BREAK
)
2034 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
2036 remove_breakpoints ();
2037 registers_changed ();
2038 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
2040 ecs
->waiton_ptid
= ecs
->ptid
;
2041 ecs
->wp
= &(ecs
->ws
);
2042 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2043 prepare_to_wait (ecs
);
2047 /* It may be possible to simply continue after a watchpoint. */
2048 if (HAVE_CONTINUABLE_WATCHPOINT
)
2049 STOPPED_BY_WATCHPOINT (ecs
->ws
);
2051 ecs
->stop_func_start
= 0;
2052 ecs
->stop_func_end
= 0;
2053 ecs
->stop_func_name
= 0;
2054 /* Don't care about return value; stop_func_start and stop_func_name
2055 will both be 0 if it doesn't work. */
2056 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2057 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2058 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
2059 ecs
->another_trap
= 0;
2060 bpstat_clear (&stop_bpstat
);
2062 stop_stack_dummy
= 0;
2063 stop_print_frame
= 1;
2064 ecs
->random_signal
= 0;
2065 stopped_by_random_signal
= 0;
2066 breakpoints_failed
= 0;
2068 /* Look at the cause of the stop, and decide what to do.
2069 The alternatives are:
2070 1) break; to really stop and return to the debugger,
2071 2) drop through to start up again
2072 (set ecs->another_trap to 1 to single step once)
2073 3) set ecs->random_signal to 1, and the decision between 1 and 2
2074 will be made according to the signal handling tables. */
2076 /* First, distinguish signals caused by the debugger from signals
2077 that have to do with the program's own actions.
2078 Note that breakpoint insns may cause SIGTRAP or SIGILL
2079 or SIGEMT, depending on the operating system version.
2080 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2081 and change it to SIGTRAP. */
2083 if (stop_signal
== TARGET_SIGNAL_TRAP
2084 || (breakpoints_inserted
&&
2085 (stop_signal
== TARGET_SIGNAL_ILL
2086 || stop_signal
== TARGET_SIGNAL_EMT
2088 || stop_soon_quietly
)
2090 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2092 stop_print_frame
= 0;
2093 stop_stepping (ecs
);
2096 if (stop_soon_quietly
)
2098 stop_stepping (ecs
);
2102 /* Don't even think about breakpoints
2103 if just proceeded over a breakpoint.
2105 However, if we are trying to proceed over a breakpoint
2106 and end up in sigtramp, then through_sigtramp_breakpoint
2107 will be set and we should check whether we've hit the
2109 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2110 && through_sigtramp_breakpoint
== NULL
)
2111 bpstat_clear (&stop_bpstat
);
2114 /* See if there is a breakpoint at the current PC. */
2116 /* The second argument of bpstat_stop_status is meant to help
2117 distinguish between a breakpoint trap and a singlestep trap.
2118 This is only important on targets where DECR_PC_AFTER_BREAK
2119 is non-zero. The prev_pc test is meant to distinguish between
2120 singlestepping a trap instruction, and singlestepping thru a
2121 jump to the instruction following a trap instruction. */
2123 stop_bpstat
= bpstat_stop_status
2125 /* Pass TRUE if our reason for stopping is something other
2126 than hitting a breakpoint. We do this by checking that
2127 1) stepping is going on and 2) we didn't hit a breakpoint
2128 in a signal handler without an intervening stop in
2129 sigtramp, which is detected by a new stack pointer value
2130 below any usual function calling stack adjustments. */
2131 (currently_stepping (ecs
)
2132 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
2134 && INNER_THAN (read_sp (), (step_sp
- 16))))
2136 /* Following in case break condition called a
2138 stop_print_frame
= 1;
2141 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2143 = !(bpstat_explains_signal (stop_bpstat
)
2145 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2146 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2147 FRAME_FP (get_current_frame ())))
2148 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2153 = !(bpstat_explains_signal (stop_bpstat
)
2154 /* End of a stack dummy. Some systems (e.g. Sony
2155 news) give another signal besides SIGTRAP, so
2156 check here as well as above. */
2157 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2158 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2159 FRAME_FP (get_current_frame ())))
2161 if (!ecs
->random_signal
)
2162 stop_signal
= TARGET_SIGNAL_TRAP
;
2166 /* When we reach this point, we've pretty much decided
2167 that the reason for stopping must've been a random
2168 (unexpected) signal. */
2171 ecs
->random_signal
= 1;
2172 /* If a fork, vfork or exec event was seen, then there are two
2173 possible responses we can make:
2175 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2176 then we must stop now and issue a prompt. We will resume
2177 the inferior when the user tells us to.
2178 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2179 then we must resume the inferior now and keep checking.
2181 In either case, we must take appropriate steps to "follow" the
2182 the fork/vfork/exec when the inferior is resumed. For example,
2183 if follow-fork-mode is "child", then we must detach from the
2184 parent inferior and follow the new child inferior.
2186 In either case, setting pending_follow causes the next resume()
2187 to take the appropriate following action. */
2188 process_event_stop_test
:
2189 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2191 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2194 stop_signal
= TARGET_SIGNAL_0
;
2199 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2201 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2203 stop_signal
= TARGET_SIGNAL_0
;
2208 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2210 pending_follow
.kind
= ecs
->ws
.kind
;
2211 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2214 stop_signal
= TARGET_SIGNAL_0
;
2220 /* For the program's own signals, act according to
2221 the signal handling tables. */
2223 if (ecs
->random_signal
)
2225 /* Signal not for debugging purposes. */
2228 stopped_by_random_signal
= 1;
2230 if (signal_print
[stop_signal
])
2233 target_terminal_ours_for_output ();
2234 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2236 if (signal_stop
[stop_signal
])
2238 stop_stepping (ecs
);
2241 /* If not going to stop, give terminal back
2242 if we took it away. */
2244 target_terminal_inferior ();
2246 /* Clear the signal if it should not be passed. */
2247 if (signal_program
[stop_signal
] == 0)
2248 stop_signal
= TARGET_SIGNAL_0
;
2250 /* I'm not sure whether this needs to be check_sigtramp2 or
2251 whether it could/should be keep_going.
2253 This used to jump to step_over_function if we are stepping,
2256 Suppose the user does a `next' over a function call, and while
2257 that call is in progress, the inferior receives a signal for
2258 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2259 that case, when we reach this point, there is already a
2260 step-resume breakpoint established, right where it should be:
2261 immediately after the function call the user is "next"-ing
2262 over. If we call step_over_function now, two bad things
2265 - we'll create a new breakpoint, at wherever the current
2266 frame's return address happens to be. That could be
2267 anywhere, depending on what function call happens to be on
2268 the top of the stack at that point. Point is, it's probably
2269 not where we need it.
2271 - the existing step-resume breakpoint (which is at the correct
2272 address) will get orphaned: step_resume_breakpoint will point
2273 to the new breakpoint, and the old step-resume breakpoint
2274 will never be cleaned up.
2276 The old behavior was meant to help HP-UX single-step out of
2277 sigtramps. It would place the new breakpoint at prev_pc, which
2278 was certainly wrong. I don't know the details there, so fixing
2279 this probably breaks that. As with anything else, it's up to
2280 the HP-UX maintainer to furnish a fix that doesn't break other
2281 platforms. --JimB, 20 May 1999 */
2282 check_sigtramp2 (ecs
);
2287 /* Handle cases caused by hitting a breakpoint. */
2289 CORE_ADDR jmp_buf_pc
;
2290 struct bpstat_what what
;
2292 what
= bpstat_what (stop_bpstat
);
2294 if (what
.call_dummy
)
2296 stop_stack_dummy
= 1;
2298 trap_expected_after_continue
= 1;
2302 switch (what
.main_action
)
2304 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2305 /* If we hit the breakpoint at longjmp, disable it for the
2306 duration of this command. Then, install a temporary
2307 breakpoint at the target of the jmp_buf. */
2308 disable_longjmp_breakpoint ();
2309 remove_breakpoints ();
2310 breakpoints_inserted
= 0;
2311 if (!GET_LONGJMP_TARGET (&jmp_buf_pc
))
2317 /* Need to blow away step-resume breakpoint, as it
2318 interferes with us */
2319 if (step_resume_breakpoint
!= NULL
)
2321 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2323 /* Not sure whether we need to blow this away too, but probably
2324 it is like the step-resume breakpoint. */
2325 if (through_sigtramp_breakpoint
!= NULL
)
2327 delete_breakpoint (through_sigtramp_breakpoint
);
2328 through_sigtramp_breakpoint
= NULL
;
2332 /* FIXME - Need to implement nested temporary breakpoints */
2333 if (step_over_calls
> 0)
2334 set_longjmp_resume_breakpoint (jmp_buf_pc
,
2335 get_current_frame ());
2338 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2339 ecs
->handling_longjmp
= 1; /* FIXME */
2343 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2344 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2345 remove_breakpoints ();
2346 breakpoints_inserted
= 0;
2348 /* FIXME - Need to implement nested temporary breakpoints */
2350 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2351 step_frame_address
)))
2353 ecs
->another_trap
= 1;
2358 disable_longjmp_breakpoint ();
2359 ecs
->handling_longjmp
= 0; /* FIXME */
2360 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2362 /* else fallthrough */
2364 case BPSTAT_WHAT_SINGLE
:
2365 if (breakpoints_inserted
)
2367 remove_breakpoints ();
2369 breakpoints_inserted
= 0;
2370 ecs
->another_trap
= 1;
2371 /* Still need to check other stuff, at least the case
2372 where we are stepping and step out of the right range. */
2375 case BPSTAT_WHAT_STOP_NOISY
:
2376 stop_print_frame
= 1;
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_STOP_SILENT
:
2386 stop_print_frame
= 0;
2388 /* We are about to nuke the step_resume_breakpoint and
2389 through_sigtramp_breakpoint via the cleanup chain, so
2390 no need to worry about it here. */
2392 stop_stepping (ecs
);
2395 case BPSTAT_WHAT_STEP_RESUME
:
2396 /* This proably demands a more elegant solution, but, yeah
2399 This function's use of the simple variable
2400 step_resume_breakpoint doesn't seem to accomodate
2401 simultaneously active step-resume bp's, although the
2402 breakpoint list certainly can.
2404 If we reach here and step_resume_breakpoint is already
2405 NULL, then apparently we have multiple active
2406 step-resume bp's. We'll just delete the breakpoint we
2407 stopped at, and carry on.
2409 Correction: what the code currently does is delete a
2410 step-resume bp, but it makes no effort to ensure that
2411 the one deleted is the one currently stopped at. MVS */
2413 if (step_resume_breakpoint
== NULL
)
2415 step_resume_breakpoint
=
2416 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2418 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2421 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2422 if (through_sigtramp_breakpoint
)
2423 delete_breakpoint (through_sigtramp_breakpoint
);
2424 through_sigtramp_breakpoint
= NULL
;
2426 /* If were waiting for a trap, hitting the step_resume_break
2427 doesn't count as getting it. */
2429 ecs
->another_trap
= 1;
2432 case BPSTAT_WHAT_CHECK_SHLIBS
:
2433 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2436 /* Remove breakpoints, we eventually want to step over the
2437 shlib event breakpoint, and SOLIB_ADD might adjust
2438 breakpoint addresses via breakpoint_re_set. */
2439 if (breakpoints_inserted
)
2440 remove_breakpoints ();
2441 breakpoints_inserted
= 0;
2443 /* Check for any newly added shared libraries if we're
2444 supposed to be adding them automatically. Switch
2445 terminal for any messages produced by
2446 breakpoint_re_set. */
2447 target_terminal_ours_for_output ();
2448 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
2449 target_terminal_inferior ();
2451 /* Try to reenable shared library breakpoints, additional
2452 code segments in shared libraries might be mapped in now. */
2453 re_enable_breakpoints_in_shlibs ();
2455 /* If requested, stop when the dynamic linker notifies
2456 gdb of events. This allows the user to get control
2457 and place breakpoints in initializer routines for
2458 dynamically loaded objects (among other things). */
2459 if (stop_on_solib_events
)
2461 stop_stepping (ecs
);
2465 /* If we stopped due to an explicit catchpoint, then the
2466 (see above) call to SOLIB_ADD pulled in any symbols
2467 from a newly-loaded library, if appropriate.
2469 We do want the inferior to stop, but not where it is
2470 now, which is in the dynamic linker callback. Rather,
2471 we would like it stop in the user's program, just after
2472 the call that caused this catchpoint to trigger. That
2473 gives the user a more useful vantage from which to
2474 examine their program's state. */
2475 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2477 /* ??rehrauer: If I could figure out how to get the
2478 right return PC from here, we could just set a temp
2479 breakpoint and resume. I'm not sure we can without
2480 cracking open the dld's shared libraries and sniffing
2481 their unwind tables and text/data ranges, and that's
2482 not a terribly portable notion.
2484 Until that time, we must step the inferior out of the
2485 dld callback, and also out of the dld itself (and any
2486 code or stubs in libdld.sl, such as "shl_load" and
2487 friends) until we reach non-dld code. At that point,
2488 we can stop stepping. */
2489 bpstat_get_triggered_catchpoints (stop_bpstat
,
2490 &ecs
->stepping_through_solib_catchpoints
);
2491 ecs
->stepping_through_solib_after_catch
= 1;
2493 /* Be sure to lift all breakpoints, so the inferior does
2494 actually step past this point... */
2495 ecs
->another_trap
= 1;
2500 /* We want to step over this breakpoint, then keep going. */
2501 ecs
->another_trap
= 1;
2508 case BPSTAT_WHAT_LAST
:
2509 /* Not a real code, but listed here to shut up gcc -Wall. */
2511 case BPSTAT_WHAT_KEEP_CHECKING
:
2516 /* We come here if we hit a breakpoint but should not
2517 stop for it. Possibly we also were stepping
2518 and should stop for that. So fall through and
2519 test for stepping. But, if not stepping,
2522 /* Are we stepping to get the inferior out of the dynamic
2523 linker's hook (and possibly the dld itself) after catching
2525 if (ecs
->stepping_through_solib_after_catch
)
2527 #if defined(SOLIB_ADD)
2528 /* Have we reached our destination? If not, keep going. */
2529 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2531 ecs
->another_trap
= 1;
2536 /* Else, stop and report the catchpoint(s) whose triggering
2537 caused us to begin stepping. */
2538 ecs
->stepping_through_solib_after_catch
= 0;
2539 bpstat_clear (&stop_bpstat
);
2540 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2541 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2542 stop_print_frame
= 1;
2543 stop_stepping (ecs
);
2547 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2549 /* This is the old way of detecting the end of the stack dummy.
2550 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2551 handled above. As soon as we can test it on all of them, all
2552 architectures should define it. */
2554 /* If this is the breakpoint at the end of a stack dummy,
2555 just stop silently, unless the user was doing an si/ni, in which
2556 case she'd better know what she's doing. */
2558 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2559 FRAME_FP (get_current_frame ()))
2562 stop_print_frame
= 0;
2563 stop_stack_dummy
= 1;
2565 trap_expected_after_continue
= 1;
2567 stop_stepping (ecs
);
2572 if (step_resume_breakpoint
)
2574 /* Having a step-resume breakpoint overrides anything
2575 else having to do with stepping commands until
2576 that breakpoint is reached. */
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 (step_range_end
== 0)
2586 /* Likewise if we aren't even stepping. */
2587 /* I'm not sure whether this needs to be check_sigtramp2 or
2588 whether it could/should be keep_going. */
2589 check_sigtramp2 (ecs
);
2594 /* If stepping through a line, keep going if still within it.
2596 Note that step_range_end is the address of the first instruction
2597 beyond the step range, and NOT the address of the last instruction
2599 if (stop_pc
>= step_range_start
2600 && stop_pc
< step_range_end
)
2602 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2603 So definately need to check for sigtramp here. */
2604 check_sigtramp2 (ecs
);
2609 /* We stepped out of the stepping range. */
2611 /* If we are stepping at the source level and entered the runtime
2612 loader dynamic symbol resolution code, we keep on single stepping
2613 until we exit the run time loader code and reach the callee's
2615 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2617 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2619 if (pc_after_resolver
)
2621 /* Set up a step-resume breakpoint at the address
2622 indicated by SKIP_SOLIB_RESOLVER. */
2623 struct symtab_and_line sr_sal
;
2625 sr_sal
.pc
= pc_after_resolver
;
2627 check_for_old_step_resume_breakpoint ();
2628 step_resume_breakpoint
=
2629 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2630 if (breakpoints_inserted
)
2631 insert_breakpoints ();
2638 /* We can't update step_sp every time through the loop, because
2639 reading the stack pointer would slow down stepping too much.
2640 But we can update it every time we leave the step range. */
2641 ecs
->update_step_sp
= 1;
2643 /* Did we just take a signal? */
2644 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2645 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2646 && INNER_THAN (read_sp (), step_sp
))
2648 /* We've just taken a signal; go until we are back to
2649 the point where we took it and one more. */
2651 /* Note: The test above succeeds not only when we stepped
2652 into a signal handler, but also when we step past the last
2653 statement of a signal handler and end up in the return stub
2654 of the signal handler trampoline. To distinguish between
2655 these two cases, check that the frame is INNER_THAN the
2656 previous one below. pai/1997-09-11 */
2660 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2662 if (INNER_THAN (current_frame
, step_frame_address
))
2664 /* We have just taken a signal; go until we are back to
2665 the point where we took it and one more. */
2667 /* This code is needed at least in the following case:
2668 The user types "next" and then a signal arrives (before
2669 the "next" is done). */
2671 /* Note that if we are stopped at a breakpoint, then we need
2672 the step_resume breakpoint to override any breakpoints at
2673 the same location, so that we will still step over the
2674 breakpoint even though the signal happened. */
2675 struct symtab_and_line sr_sal
;
2678 sr_sal
.symtab
= NULL
;
2680 sr_sal
.pc
= prev_pc
;
2681 /* We could probably be setting the frame to
2682 step_frame_address; I don't think anyone thought to
2684 check_for_old_step_resume_breakpoint ();
2685 step_resume_breakpoint
=
2686 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2687 if (breakpoints_inserted
)
2688 insert_breakpoints ();
2692 /* We just stepped out of a signal handler and into
2693 its calling trampoline.
2695 Normally, we'd call step_over_function from
2696 here, but for some reason GDB can't unwind the
2697 stack correctly to find the real PC for the point
2698 user code where the signal trampoline will return
2699 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2700 But signal trampolines are pretty small stubs of
2701 code, anyway, so it's OK instead to just
2702 single-step out. Note: assuming such trampolines
2703 don't exhibit recursion on any platform... */
2704 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2705 &ecs
->stop_func_start
,
2706 &ecs
->stop_func_end
);
2707 /* Readjust stepping range */
2708 step_range_start
= ecs
->stop_func_start
;
2709 step_range_end
= ecs
->stop_func_end
;
2710 ecs
->stepping_through_sigtramp
= 1;
2715 /* If this is stepi or nexti, make sure that the stepping range
2716 gets us past that instruction. */
2717 if (step_range_end
== 1)
2718 /* FIXME: Does this run afoul of the code below which, if
2719 we step into the middle of a line, resets the stepping
2721 step_range_end
= (step_range_start
= prev_pc
) + 1;
2723 ecs
->remove_breakpoints_on_following_step
= 1;
2728 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2729 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2730 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2731 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2732 || ecs
->stop_func_name
== 0)
2734 /* It's a subroutine call. */
2736 if ((step_over_calls
== STEP_OVER_NONE
)
2737 || ((step_range_end
== 1)
2738 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2740 /* I presume that step_over_calls is only 0 when we're
2741 supposed to be stepping at the assembly language level
2742 ("stepi"). Just stop. */
2743 /* Also, maybe we just did a "nexti" inside a prolog,
2744 so we thought it was a subroutine call but it was not.
2745 Stop as well. FENN */
2747 print_stop_reason (END_STEPPING_RANGE
, 0);
2748 stop_stepping (ecs
);
2752 if (step_over_calls
== STEP_OVER_ALL
|| IGNORE_HELPER_CALL (stop_pc
))
2754 /* We're doing a "next". */
2756 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2757 && INNER_THAN (step_frame_address
, read_sp()))
2758 /* We stepped out of a signal handler, and into its
2759 calling trampoline. This is misdetected as a
2760 subroutine call, but stepping over the signal
2761 trampoline isn't such a bad idea. In order to do
2762 that, we have to ignore the value in
2763 step_frame_address, since that doesn't represent the
2764 frame that'll reach when we return from the signal
2765 trampoline. Otherwise we'll probably continue to the
2766 end of the program. */
2767 step_frame_address
= 0;
2769 step_over_function (ecs
);
2774 /* If we are in a function call trampoline (a stub between
2775 the calling routine and the real function), locate the real
2776 function. That's what tells us (a) whether we want to step
2777 into it at all, and (b) what prologue we want to run to
2778 the end of, if we do step into it. */
2779 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2781 ecs
->stop_func_start
= tmp
;
2784 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2787 struct symtab_and_line xxx
;
2788 /* Why isn't this s_a_l called "sr_sal", like all of the
2789 other s_a_l's where this code is duplicated? */
2790 INIT_SAL (&xxx
); /* initialize to zeroes */
2792 xxx
.section
= find_pc_overlay (xxx
.pc
);
2793 check_for_old_step_resume_breakpoint ();
2794 step_resume_breakpoint
=
2795 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2796 insert_breakpoints ();
2802 /* If we have line number information for the function we
2803 are thinking of stepping into, step into it.
2805 If there are several symtabs at that PC (e.g. with include
2806 files), just want to know whether *any* of them have line
2807 numbers. find_pc_line handles this. */
2809 struct symtab_and_line tmp_sal
;
2811 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2812 if (tmp_sal
.line
!= 0)
2814 step_into_function (ecs
);
2819 /* If we have no line number and the step-stop-if-no-debug
2820 is set, we stop the step so that the user has a chance to
2821 switch in assembly mode. */
2822 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2825 print_stop_reason (END_STEPPING_RANGE
, 0);
2826 stop_stepping (ecs
);
2830 step_over_function (ecs
);
2836 /* We've wandered out of the step range. */
2838 ecs
->sal
= find_pc_line (stop_pc
, 0);
2840 if (step_range_end
== 1)
2842 /* It is stepi or nexti. We always want to stop stepping after
2845 print_stop_reason (END_STEPPING_RANGE
, 0);
2846 stop_stepping (ecs
);
2850 /* If we're in the return path from a shared library trampoline,
2851 we want to proceed through the trampoline when stepping. */
2852 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2856 /* Determine where this trampoline returns. */
2857 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2859 /* Only proceed through if we know where it's going. */
2862 /* And put the step-breakpoint there and go until there. */
2863 struct symtab_and_line sr_sal
;
2865 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2867 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2868 /* Do not specify what the fp should be when we stop
2869 since on some machines the prologue
2870 is where the new fp value is established. */
2871 check_for_old_step_resume_breakpoint ();
2872 step_resume_breakpoint
=
2873 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2874 if (breakpoints_inserted
)
2875 insert_breakpoints ();
2877 /* Restart without fiddling with the step ranges or
2884 if (ecs
->sal
.line
== 0)
2886 /* We have no line number information. That means to stop
2887 stepping (does this always happen right after one instruction,
2888 when we do "s" in a function with no line numbers,
2889 or can this happen as a result of a return or longjmp?). */
2891 print_stop_reason (END_STEPPING_RANGE
, 0);
2892 stop_stepping (ecs
);
2896 if ((stop_pc
== ecs
->sal
.pc
)
2897 && (ecs
->current_line
!= ecs
->sal
.line
|| ecs
->current_symtab
!= ecs
->sal
.symtab
))
2899 /* We are at the start of a different line. So stop. Note that
2900 we don't stop if we step into the middle of a different line.
2901 That is said to make things like for (;;) statements work
2904 print_stop_reason (END_STEPPING_RANGE
, 0);
2905 stop_stepping (ecs
);
2909 /* We aren't done stepping.
2911 Optimize by setting the stepping range to the line.
2912 (We might not be in the original line, but if we entered a
2913 new line in mid-statement, we continue stepping. This makes
2914 things like for(;;) statements work better.) */
2916 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2918 /* If this is the last line of the function, don't keep stepping
2919 (it would probably step us out of the function).
2920 This is particularly necessary for a one-line function,
2921 in which after skipping the prologue we better stop even though
2922 we will be in mid-line. */
2924 print_stop_reason (END_STEPPING_RANGE
, 0);
2925 stop_stepping (ecs
);
2928 step_range_start
= ecs
->sal
.pc
;
2929 step_range_end
= ecs
->sal
.end
;
2930 step_frame_address
= FRAME_FP (get_current_frame ());
2931 ecs
->current_line
= ecs
->sal
.line
;
2932 ecs
->current_symtab
= ecs
->sal
.symtab
;
2934 /* In the case where we just stepped out of a function into the middle
2935 of a line of the caller, continue stepping, but step_frame_address
2936 must be modified to current frame */
2938 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2939 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2940 step_frame_address
= current_frame
;
2945 } /* extra brace, to preserve old indentation */
2948 /* Are we in the middle of stepping? */
2951 currently_stepping (struct execution_control_state
*ecs
)
2953 return ((through_sigtramp_breakpoint
== NULL
2954 && !ecs
->handling_longjmp
2955 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2957 || ecs
->stepping_through_solib_after_catch
2958 || bpstat_should_step ());
2962 check_sigtramp2 (struct execution_control_state
*ecs
)
2965 && IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2966 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2967 && INNER_THAN (read_sp (), step_sp
))
2969 /* What has happened here is that we have just stepped the
2970 inferior with a signal (because it is a signal which
2971 shouldn't make us stop), thus stepping into sigtramp.
2973 So we need to set a step_resume_break_address breakpoint and
2974 continue until we hit it, and then step. FIXME: This should
2975 be more enduring than a step_resume breakpoint; we should
2976 know that we will later need to keep going rather than
2977 re-hitting the breakpoint here (see the testsuite,
2978 gdb.base/signals.exp where it says "exceedingly difficult"). */
2980 struct symtab_and_line sr_sal
;
2982 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2983 sr_sal
.pc
= prev_pc
;
2984 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2985 /* We perhaps could set the frame if we kept track of what the
2986 frame corresponding to prev_pc was. But we don't, so don't. */
2987 through_sigtramp_breakpoint
=
2988 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2989 if (breakpoints_inserted
)
2990 insert_breakpoints ();
2992 ecs
->remove_breakpoints_on_following_step
= 1;
2993 ecs
->another_trap
= 1;
2997 /* Subroutine call with source code we should not step over. Do step
2998 to the first line of code in it. */
3001 step_into_function (struct execution_control_state
*ecs
)
3004 struct symtab_and_line sr_sal
;
3006 s
= find_pc_symtab (stop_pc
);
3007 if (s
&& s
->language
!= language_asm
)
3008 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
3010 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
3011 /* Use the step_resume_break to step until the end of the prologue,
3012 even if that involves jumps (as it seems to on the vax under
3014 /* If the prologue ends in the middle of a source line, continue to
3015 the end of that source line (if it is still within the function).
3016 Otherwise, just go to end of prologue. */
3017 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
3018 /* no, don't either. It skips any code that's legitimately on the
3022 && ecs
->sal
.pc
!= ecs
->stop_func_start
3023 && ecs
->sal
.end
< ecs
->stop_func_end
)
3024 ecs
->stop_func_start
= ecs
->sal
.end
;
3027 if (ecs
->stop_func_start
== stop_pc
)
3029 /* We are already there: stop now. */
3031 print_stop_reason (END_STEPPING_RANGE
, 0);
3032 stop_stepping (ecs
);
3037 /* Put the step-breakpoint there and go until there. */
3038 INIT_SAL (&sr_sal
); /* initialize to zeroes */
3039 sr_sal
.pc
= ecs
->stop_func_start
;
3040 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3041 /* Do not specify what the fp should be when we stop since on
3042 some machines the prologue is where the new fp value is
3044 check_for_old_step_resume_breakpoint ();
3045 step_resume_breakpoint
=
3046 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
3047 if (breakpoints_inserted
)
3048 insert_breakpoints ();
3050 /* And make sure stepping stops right away then. */
3051 step_range_end
= step_range_start
;
3056 /* We've just entered a callee, and we wish to resume until it returns
3057 to the caller. Setting a step_resume breakpoint on the return
3058 address will catch a return from the callee.
3060 However, if the callee is recursing, we want to be careful not to
3061 catch returns of those recursive calls, but only of THIS instance
3064 To do this, we set the step_resume bp's frame to our current
3065 caller's frame (step_frame_address, which is set by the "next" or
3066 "until" command, before execution begins). */
3069 step_over_function (struct execution_control_state
*ecs
)
3071 struct symtab_and_line sr_sal
;
3073 INIT_SAL (&sr_sal
); /* initialize to zeros */
3074 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3075 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3077 check_for_old_step_resume_breakpoint ();
3078 step_resume_breakpoint
=
3079 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
3081 if (step_frame_address
&& !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
3082 step_resume_breakpoint
->frame
= step_frame_address
;
3084 if (breakpoints_inserted
)
3085 insert_breakpoints ();
3089 stop_stepping (struct execution_control_state
*ecs
)
3091 if (target_has_execution
)
3093 /* Are we stopping for a vfork event? We only stop when we see
3094 the child's event. However, we may not yet have seen the
3095 parent's event. And, inferior_ptid is still set to the
3096 parent's pid, until we resume again and follow either the
3099 To ensure that we can really touch inferior_ptid (aka, the
3100 parent process) -- which calls to functions like read_pc
3101 implicitly do -- wait on the parent if necessary. */
3102 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3103 && !pending_follow
.fork_event
.saw_parent_fork
)
3109 if (target_wait_hook
)
3110 parent_ptid
= target_wait_hook (pid_to_ptid (-1), &(ecs
->ws
));
3112 parent_ptid
= target_wait (pid_to_ptid (-1), &(ecs
->ws
));
3114 while (! ptid_equal (parent_ptid
, inferior_ptid
));
3117 /* Assuming the inferior still exists, set these up for next
3118 time, just like we did above if we didn't break out of the
3120 prev_pc
= read_pc ();
3121 prev_func_start
= ecs
->stop_func_start
;
3122 prev_func_name
= ecs
->stop_func_name
;
3125 /* Let callers know we don't want to wait for the inferior anymore. */
3126 ecs
->wait_some_more
= 0;
3129 /* This function handles various cases where we need to continue
3130 waiting for the inferior. */
3131 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3134 keep_going (struct execution_control_state
*ecs
)
3136 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3137 vforked child between its creation and subsequent exit or call to
3138 exec(). However, I had big problems in this rather creaky exec
3139 engine, getting that to work. The fundamental problem is that
3140 I'm trying to debug two processes via an engine that only
3141 understands a single process with possibly multiple threads.
3143 Hence, this spot is known to have problems when
3144 target_can_follow_vfork_prior_to_exec returns 1. */
3146 /* Save the pc before execution, to compare with pc after stop. */
3147 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3148 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3149 BREAK is defined, the
3150 original pc would not have
3151 been at the start of a
3153 prev_func_name
= ecs
->stop_func_name
;
3155 if (ecs
->update_step_sp
)
3156 step_sp
= read_sp ();
3157 ecs
->update_step_sp
= 0;
3159 /* If we did not do break;, it means we should keep running the
3160 inferior and not return to debugger. */
3162 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3164 /* We took a signal (which we are supposed to pass through to
3165 the inferior, else we'd have done a break above) and we
3166 haven't yet gotten our trap. Simply continue. */
3167 resume (currently_stepping (ecs
), stop_signal
);
3171 /* Either the trap was not expected, but we are continuing
3172 anyway (the user asked that this signal be passed to the
3175 The signal was SIGTRAP, e.g. it was our signal, but we
3176 decided we should resume from it.
3178 We're going to run this baby now!
3180 Insert breakpoints now, unless we are trying to one-proceed
3181 past a breakpoint. */
3182 /* If we've just finished a special step resume and we don't
3183 want to hit a breakpoint, pull em out. */
3184 if (step_resume_breakpoint
== NULL
3185 && through_sigtramp_breakpoint
== NULL
3186 && ecs
->remove_breakpoints_on_following_step
)
3188 ecs
->remove_breakpoints_on_following_step
= 0;
3189 remove_breakpoints ();
3190 breakpoints_inserted
= 0;
3192 else if (!breakpoints_inserted
&&
3193 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3195 breakpoints_failed
= insert_breakpoints ();
3196 if (breakpoints_failed
)
3198 stop_stepping (ecs
);
3201 breakpoints_inserted
= 1;
3204 trap_expected
= ecs
->another_trap
;
3206 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3207 specifies that such a signal should be delivered to the
3210 Typically, this would occure when a user is debugging a
3211 target monitor on a simulator: the target monitor sets a
3212 breakpoint; the simulator encounters this break-point and
3213 halts the simulation handing control to GDB; GDB, noteing
3214 that the break-point isn't valid, returns control back to the
3215 simulator; the simulator then delivers the hardware
3216 equivalent of a SIGNAL_TRAP to the program being debugged. */
3218 if (stop_signal
== TARGET_SIGNAL_TRAP
3219 && !signal_program
[stop_signal
])
3220 stop_signal
= TARGET_SIGNAL_0
;
3222 #ifdef SHIFT_INST_REGS
3223 /* I'm not sure when this following segment applies. I do know,
3224 now, that we shouldn't rewrite the regs when we were stopped
3225 by a random signal from the inferior process. */
3226 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3227 (this is only used on the 88k). */
3229 if (!bpstat_explains_signal (stop_bpstat
)
3230 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
3231 && !stopped_by_random_signal
)
3233 #endif /* SHIFT_INST_REGS */
3235 resume (currently_stepping (ecs
), stop_signal
);
3238 prepare_to_wait (ecs
);
3241 /* This function normally comes after a resume, before
3242 handle_inferior_event exits. It takes care of any last bits of
3243 housekeeping, and sets the all-important wait_some_more flag. */
3246 prepare_to_wait (struct execution_control_state
*ecs
)
3248 if (ecs
->infwait_state
== infwait_normal_state
)
3250 overlay_cache_invalid
= 1;
3252 /* We have to invalidate the registers BEFORE calling
3253 target_wait because they can be loaded from the target while
3254 in target_wait. This makes remote debugging a bit more
3255 efficient for those targets that provide critical registers
3256 as part of their normal status mechanism. */
3258 registers_changed ();
3259 ecs
->waiton_ptid
= pid_to_ptid (-1);
3260 ecs
->wp
= &(ecs
->ws
);
3262 /* This is the old end of the while loop. Let everybody know we
3263 want to wait for the inferior some more and get called again
3265 ecs
->wait_some_more
= 1;
3268 /* Print why the inferior has stopped. We always print something when
3269 the inferior exits, or receives a signal. The rest of the cases are
3270 dealt with later on in normal_stop() and print_it_typical(). Ideally
3271 there should be a call to this function from handle_inferior_event()
3272 each time stop_stepping() is called.*/
3274 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3276 switch (stop_reason
)
3279 /* We don't deal with these cases from handle_inferior_event()
3282 case END_STEPPING_RANGE
:
3283 /* We are done with a step/next/si/ni command. */
3284 /* For now print nothing. */
3285 /* Print a message only if not in the middle of doing a "step n"
3286 operation for n > 1 */
3287 if (!step_multi
|| !stop_step
)
3288 if (ui_out_is_mi_like_p (uiout
))
3289 ui_out_field_string (uiout
, "reason", "end-stepping-range");
3291 case BREAKPOINT_HIT
:
3292 /* We found a breakpoint. */
3293 /* For now print nothing. */
3296 /* The inferior was terminated by a signal. */
3297 annotate_signalled ();
3298 if (ui_out_is_mi_like_p (uiout
))
3299 ui_out_field_string (uiout
, "reason", "exited-signalled");
3300 ui_out_text (uiout
, "\nProgram terminated with signal ");
3301 annotate_signal_name ();
3302 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3303 annotate_signal_name_end ();
3304 ui_out_text (uiout
, ", ");
3305 annotate_signal_string ();
3306 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3307 annotate_signal_string_end ();
3308 ui_out_text (uiout
, ".\n");
3309 ui_out_text (uiout
, "The program no longer exists.\n");
3312 /* The inferior program is finished. */
3313 annotate_exited (stop_info
);
3316 if (ui_out_is_mi_like_p (uiout
))
3317 ui_out_field_string (uiout
, "reason", "exited");
3318 ui_out_text (uiout
, "\nProgram exited with code ");
3319 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) stop_info
);
3320 ui_out_text (uiout
, ".\n");
3324 if (ui_out_is_mi_like_p (uiout
))
3325 ui_out_field_string (uiout
, "reason", "exited-normally");
3326 ui_out_text (uiout
, "\nProgram exited normally.\n");
3329 case SIGNAL_RECEIVED
:
3330 /* Signal received. The signal table tells us to print about
3333 ui_out_text (uiout
, "\nProgram received signal ");
3334 annotate_signal_name ();
3335 if (ui_out_is_mi_like_p (uiout
))
3336 ui_out_field_string (uiout
, "reason", "signal-received");
3337 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3338 annotate_signal_name_end ();
3339 ui_out_text (uiout
, ", ");
3340 annotate_signal_string ();
3341 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3342 annotate_signal_string_end ();
3343 ui_out_text (uiout
, ".\n");
3346 internal_error (__FILE__
, __LINE__
,
3347 "print_stop_reason: unrecognized enum value");
3353 /* Here to return control to GDB when the inferior stops for real.
3354 Print appropriate messages, remove breakpoints, give terminal our modes.
3356 STOP_PRINT_FRAME nonzero means print the executing frame
3357 (pc, function, args, file, line number and line text).
3358 BREAKPOINTS_FAILED nonzero means stop was due to error
3359 attempting to insert breakpoints. */
3364 /* As with the notification of thread events, we want to delay
3365 notifying the user that we've switched thread context until
3366 the inferior actually stops.
3368 (Note that there's no point in saying anything if the inferior
3370 if (! ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3371 && target_has_execution
)
3373 target_terminal_ours_for_output ();
3374 printf_filtered ("[Switching to %s]\n",
3375 target_pid_or_tid_to_str (inferior_ptid
));
3376 previous_inferior_ptid
= inferior_ptid
;
3379 /* Make sure that the current_frame's pc is correct. This
3380 is a correction for setting up the frame info before doing
3381 DECR_PC_AFTER_BREAK */
3382 if (target_has_execution
&& get_current_frame ())
3383 (get_current_frame ())->pc
= read_pc ();
3385 if (breakpoints_failed
)
3387 target_terminal_ours_for_output ();
3388 print_sys_errmsg ("While inserting breakpoints", breakpoints_failed
);
3389 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3390 The same program may be running in another process,\n\
3391 or you may have requested too many hardware breakpoints\n\
3392 and/or watchpoints.\n");
3395 if (target_has_execution
&& breakpoints_inserted
)
3397 if (remove_breakpoints ())
3399 target_terminal_ours_for_output ();
3400 printf_filtered ("Cannot remove breakpoints because ");
3401 printf_filtered ("program is no longer writable.\n");
3402 printf_filtered ("It might be running in another process.\n");
3403 printf_filtered ("Further execution is probably impossible.\n");
3406 breakpoints_inserted
= 0;
3408 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3409 Delete any breakpoint that is to be deleted at the next stop. */
3411 breakpoint_auto_delete (stop_bpstat
);
3413 /* If an auto-display called a function and that got a signal,
3414 delete that auto-display to avoid an infinite recursion. */
3416 if (stopped_by_random_signal
)
3417 disable_current_display ();
3419 /* Don't print a message if in the middle of doing a "step n"
3420 operation for n > 1 */
3421 if (step_multi
&& stop_step
)
3424 target_terminal_ours ();
3426 /* Look up the hook_stop and run it if it exists. */
3428 if (stop_command
&& stop_command
->hook_pre
)
3430 catch_errors (hook_stop_stub
, stop_command
->hook_pre
,
3431 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3434 if (!target_has_stack
)
3440 /* Select innermost stack frame - i.e., current frame is frame 0,
3441 and current location is based on that.
3442 Don't do this on return from a stack dummy routine,
3443 or if the program has exited. */
3445 if (!stop_stack_dummy
)
3447 select_frame (get_current_frame (), 0);
3449 /* Print current location without a level number, if
3450 we have changed functions or hit a breakpoint.
3451 Print source line if we have one.
3452 bpstat_print() contains the logic deciding in detail
3453 what to print, based on the event(s) that just occurred. */
3455 if (stop_print_frame
3460 int do_frame_printing
= 1;
3462 bpstat_ret
= bpstat_print (stop_bpstat
);
3467 && step_frame_address
== FRAME_FP (get_current_frame ())
3468 && step_start_function
== find_pc_function (stop_pc
))
3469 source_flag
= SRC_LINE
; /* finished step, just print source line */
3471 source_flag
= SRC_AND_LOC
; /* print location and source line */
3473 case PRINT_SRC_AND_LOC
:
3474 source_flag
= SRC_AND_LOC
; /* print location and source line */
3476 case PRINT_SRC_ONLY
:
3477 source_flag
= SRC_LINE
;
3480 source_flag
= SRC_LINE
; /* something bogus */
3481 do_frame_printing
= 0;
3484 internal_error (__FILE__
, __LINE__
,
3487 /* For mi, have the same behavior every time we stop:
3488 print everything but the source line. */
3489 if (ui_out_is_mi_like_p (uiout
))
3490 source_flag
= LOC_AND_ADDRESS
;
3492 if (ui_out_is_mi_like_p (uiout
))
3493 ui_out_field_int (uiout
, "thread-id",
3494 pid_to_thread_id (inferior_ptid
));
3495 /* The behavior of this routine with respect to the source
3497 SRC_LINE: Print only source line
3498 LOCATION: Print only location
3499 SRC_AND_LOC: Print location and source line */
3500 if (do_frame_printing
)
3501 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
3503 /* Display the auto-display expressions. */
3508 /* Save the function value return registers, if we care.
3509 We might be about to restore their previous contents. */
3510 if (proceed_to_finish
)
3511 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
3513 if (stop_stack_dummy
)
3515 /* Pop the empty frame that contains the stack dummy.
3516 POP_FRAME ends with a setting of the current frame, so we
3517 can use that next. */
3519 /* Set stop_pc to what it was before we called the function.
3520 Can't rely on restore_inferior_status because that only gets
3521 called if we don't stop in the called function. */
3522 stop_pc
= read_pc ();
3523 select_frame (get_current_frame (), 0);
3527 annotate_stopped ();
3531 hook_stop_stub (void *cmd
)
3533 execute_user_command ((struct cmd_list_element
*) cmd
, 0);
3538 signal_stop_state (int signo
)
3540 return signal_stop
[signo
];
3544 signal_print_state (int signo
)
3546 return signal_print
[signo
];
3550 signal_pass_state (int signo
)
3552 return signal_program
[signo
];
3555 int signal_stop_update (signo
, state
)
3559 int ret
= signal_stop
[signo
];
3560 signal_stop
[signo
] = state
;
3564 int signal_print_update (signo
, state
)
3568 int ret
= signal_print
[signo
];
3569 signal_print
[signo
] = state
;
3573 int signal_pass_update (signo
, state
)
3577 int ret
= signal_program
[signo
];
3578 signal_program
[signo
] = state
;
3583 sig_print_header (void)
3586 Signal Stop\tPrint\tPass to program\tDescription\n");
3590 sig_print_info (enum target_signal oursig
)
3592 char *name
= target_signal_to_name (oursig
);
3593 int name_padding
= 13 - strlen (name
);
3595 if (name_padding
<= 0)
3598 printf_filtered ("%s", name
);
3599 printf_filtered ("%*.*s ", name_padding
, name_padding
,
3601 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3602 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3603 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3604 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3607 /* Specify how various signals in the inferior should be handled. */
3610 handle_command (char *args
, int from_tty
)
3613 int digits
, wordlen
;
3614 int sigfirst
, signum
, siglast
;
3615 enum target_signal oursig
;
3618 unsigned char *sigs
;
3619 struct cleanup
*old_chain
;
3623 error_no_arg ("signal to handle");
3626 /* Allocate and zero an array of flags for which signals to handle. */
3628 nsigs
= (int) TARGET_SIGNAL_LAST
;
3629 sigs
= (unsigned char *) alloca (nsigs
);
3630 memset (sigs
, 0, nsigs
);
3632 /* Break the command line up into args. */
3634 argv
= buildargv (args
);
3639 old_chain
= make_cleanup_freeargv (argv
);
3641 /* Walk through the args, looking for signal oursigs, signal names, and
3642 actions. Signal numbers and signal names may be interspersed with
3643 actions, with the actions being performed for all signals cumulatively
3644 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3646 while (*argv
!= NULL
)
3648 wordlen
= strlen (*argv
);
3649 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3653 sigfirst
= siglast
= -1;
3655 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3657 /* Apply action to all signals except those used by the
3658 debugger. Silently skip those. */
3661 siglast
= nsigs
- 1;
3663 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3665 SET_SIGS (nsigs
, sigs
, signal_stop
);
3666 SET_SIGS (nsigs
, sigs
, signal_print
);
3668 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3670 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3672 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3674 SET_SIGS (nsigs
, sigs
, signal_print
);
3676 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3678 SET_SIGS (nsigs
, sigs
, signal_program
);
3680 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3682 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3684 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3686 SET_SIGS (nsigs
, sigs
, signal_program
);
3688 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3690 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3691 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3693 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3695 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3697 else if (digits
> 0)
3699 /* It is numeric. The numeric signal refers to our own
3700 internal signal numbering from target.h, not to host/target
3701 signal number. This is a feature; users really should be
3702 using symbolic names anyway, and the common ones like
3703 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3705 sigfirst
= siglast
= (int)
3706 target_signal_from_command (atoi (*argv
));
3707 if ((*argv
)[digits
] == '-')
3710 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3712 if (sigfirst
> siglast
)
3714 /* Bet he didn't figure we'd think of this case... */
3722 oursig
= target_signal_from_name (*argv
);
3723 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3725 sigfirst
= siglast
= (int) oursig
;
3729 /* Not a number and not a recognized flag word => complain. */
3730 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3734 /* If any signal numbers or symbol names were found, set flags for
3735 which signals to apply actions to. */
3737 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3739 switch ((enum target_signal
) signum
)
3741 case TARGET_SIGNAL_TRAP
:
3742 case TARGET_SIGNAL_INT
:
3743 if (!allsigs
&& !sigs
[signum
])
3745 if (query ("%s is used by the debugger.\n\
3746 Are you sure you want to change it? ",
3747 target_signal_to_name
3748 ((enum target_signal
) signum
)))
3754 printf_unfiltered ("Not confirmed, unchanged.\n");
3755 gdb_flush (gdb_stdout
);
3759 case TARGET_SIGNAL_0
:
3760 case TARGET_SIGNAL_DEFAULT
:
3761 case TARGET_SIGNAL_UNKNOWN
:
3762 /* Make sure that "all" doesn't print these. */
3773 target_notice_signals (inferior_ptid
);
3777 /* Show the results. */
3778 sig_print_header ();
3779 for (signum
= 0; signum
< nsigs
; signum
++)
3783 sig_print_info (signum
);
3788 do_cleanups (old_chain
);
3792 xdb_handle_command (char *args
, int from_tty
)
3795 struct cleanup
*old_chain
;
3797 /* Break the command line up into args. */
3799 argv
= buildargv (args
);
3804 old_chain
= make_cleanup_freeargv (argv
);
3805 if (argv
[1] != (char *) NULL
)
3810 bufLen
= strlen (argv
[0]) + 20;
3811 argBuf
= (char *) xmalloc (bufLen
);
3815 enum target_signal oursig
;
3817 oursig
= target_signal_from_name (argv
[0]);
3818 memset (argBuf
, 0, bufLen
);
3819 if (strcmp (argv
[1], "Q") == 0)
3820 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3823 if (strcmp (argv
[1], "s") == 0)
3825 if (!signal_stop
[oursig
])
3826 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3828 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3830 else if (strcmp (argv
[1], "i") == 0)
3832 if (!signal_program
[oursig
])
3833 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3835 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3837 else if (strcmp (argv
[1], "r") == 0)
3839 if (!signal_print
[oursig
])
3840 sprintf (argBuf
, "%s %s", argv
[0], "print");
3842 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3848 handle_command (argBuf
, from_tty
);
3850 printf_filtered ("Invalid signal handling flag.\n");
3855 do_cleanups (old_chain
);
3858 /* Print current contents of the tables set by the handle command.
3859 It is possible we should just be printing signals actually used
3860 by the current target (but for things to work right when switching
3861 targets, all signals should be in the signal tables). */
3864 signals_info (char *signum_exp
, int from_tty
)
3866 enum target_signal oursig
;
3867 sig_print_header ();
3871 /* First see if this is a symbol name. */
3872 oursig
= target_signal_from_name (signum_exp
);
3873 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3875 /* No, try numeric. */
3877 target_signal_from_command (parse_and_eval_long (signum_exp
));
3879 sig_print_info (oursig
);
3883 printf_filtered ("\n");
3884 /* These ugly casts brought to you by the native VAX compiler. */
3885 for (oursig
= TARGET_SIGNAL_FIRST
;
3886 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3887 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3891 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3892 && oursig
!= TARGET_SIGNAL_DEFAULT
3893 && oursig
!= TARGET_SIGNAL_0
)
3894 sig_print_info (oursig
);
3897 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3900 struct inferior_status
3902 enum target_signal stop_signal
;
3906 int stop_stack_dummy
;
3907 int stopped_by_random_signal
;
3909 CORE_ADDR step_range_start
;
3910 CORE_ADDR step_range_end
;
3911 CORE_ADDR step_frame_address
;
3912 enum step_over_calls_kind step_over_calls
;
3913 CORE_ADDR step_resume_break_address
;
3914 int stop_after_trap
;
3915 int stop_soon_quietly
;
3916 CORE_ADDR selected_frame_address
;
3917 char *stop_registers
;
3919 /* These are here because if call_function_by_hand has written some
3920 registers and then decides to call error(), we better not have changed
3925 int breakpoint_proceeded
;
3926 int restore_stack_info
;
3927 int proceed_to_finish
;
3930 static struct inferior_status
*
3931 xmalloc_inferior_status (void)
3933 struct inferior_status
*inf_status
;
3934 inf_status
= xmalloc (sizeof (struct inferior_status
));
3935 inf_status
->stop_registers
= xmalloc (REGISTER_BYTES
);
3936 inf_status
->registers
= xmalloc (REGISTER_BYTES
);
3941 free_inferior_status (struct inferior_status
*inf_status
)
3943 xfree (inf_status
->registers
);
3944 xfree (inf_status
->stop_registers
);
3949 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3952 int size
= REGISTER_RAW_SIZE (regno
);
3953 void *buf
= alloca (size
);
3954 store_signed_integer (buf
, size
, val
);
3955 memcpy (&inf_status
->registers
[REGISTER_BYTE (regno
)], buf
, size
);
3958 /* Save all of the information associated with the inferior<==>gdb
3959 connection. INF_STATUS is a pointer to a "struct inferior_status"
3960 (defined in inferior.h). */
3962 struct inferior_status
*
3963 save_inferior_status (int restore_stack_info
)
3965 struct inferior_status
*inf_status
= xmalloc_inferior_status ();
3967 inf_status
->stop_signal
= stop_signal
;
3968 inf_status
->stop_pc
= stop_pc
;
3969 inf_status
->stop_step
= stop_step
;
3970 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3971 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3972 inf_status
->trap_expected
= trap_expected
;
3973 inf_status
->step_range_start
= step_range_start
;
3974 inf_status
->step_range_end
= step_range_end
;
3975 inf_status
->step_frame_address
= step_frame_address
;
3976 inf_status
->step_over_calls
= step_over_calls
;
3977 inf_status
->stop_after_trap
= stop_after_trap
;
3978 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3979 /* Save original bpstat chain here; replace it with copy of chain.
3980 If caller's caller is walking the chain, they'll be happier if we
3981 hand them back the original chain when restore_inferior_status is
3983 inf_status
->stop_bpstat
= stop_bpstat
;
3984 stop_bpstat
= bpstat_copy (stop_bpstat
);
3985 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3986 inf_status
->restore_stack_info
= restore_stack_info
;
3987 inf_status
->proceed_to_finish
= proceed_to_finish
;
3989 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
3991 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3993 record_selected_frame (&(inf_status
->selected_frame_address
),
3994 &(inf_status
->selected_level
));
3998 struct restore_selected_frame_args
4000 CORE_ADDR frame_address
;
4005 restore_selected_frame (void *args
)
4007 struct restore_selected_frame_args
*fr
=
4008 (struct restore_selected_frame_args
*) args
;
4009 struct frame_info
*frame
;
4010 int level
= fr
->level
;
4012 frame
= find_relative_frame (get_current_frame (), &level
);
4014 /* If inf_status->selected_frame_address is NULL, there was no
4015 previously selected frame. */
4016 if (frame
== NULL
||
4017 /* FRAME_FP (frame) != fr->frame_address || */
4018 /* elz: deleted this check as a quick fix to the problem that
4019 for function called by hand gdb creates no internal frame
4020 structure and the real stack and gdb's idea of stack are
4021 different if nested calls by hands are made.
4023 mvs: this worries me. */
4026 warning ("Unable to restore previously selected frame.\n");
4030 select_frame (frame
, fr
->level
);
4036 restore_inferior_status (struct inferior_status
*inf_status
)
4038 stop_signal
= inf_status
->stop_signal
;
4039 stop_pc
= inf_status
->stop_pc
;
4040 stop_step
= inf_status
->stop_step
;
4041 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4042 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4043 trap_expected
= inf_status
->trap_expected
;
4044 step_range_start
= inf_status
->step_range_start
;
4045 step_range_end
= inf_status
->step_range_end
;
4046 step_frame_address
= inf_status
->step_frame_address
;
4047 step_over_calls
= inf_status
->step_over_calls
;
4048 stop_after_trap
= inf_status
->stop_after_trap
;
4049 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
4050 bpstat_clear (&stop_bpstat
);
4051 stop_bpstat
= inf_status
->stop_bpstat
;
4052 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4053 proceed_to_finish
= inf_status
->proceed_to_finish
;
4055 /* FIXME: Is the restore of stop_registers always needed */
4056 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
4058 /* The inferior can be gone if the user types "print exit(0)"
4059 (and perhaps other times). */
4060 if (target_has_execution
)
4061 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
4063 /* FIXME: If we are being called after stopping in a function which
4064 is called from gdb, we should not be trying to restore the
4065 selected frame; it just prints a spurious error message (The
4066 message is useful, however, in detecting bugs in gdb (like if gdb
4067 clobbers the stack)). In fact, should we be restoring the
4068 inferior status at all in that case? . */
4070 if (target_has_stack
&& inf_status
->restore_stack_info
)
4072 struct restore_selected_frame_args fr
;
4073 fr
.level
= inf_status
->selected_level
;
4074 fr
.frame_address
= inf_status
->selected_frame_address
;
4075 /* The point of catch_errors is that if the stack is clobbered,
4076 walking the stack might encounter a garbage pointer and error()
4077 trying to dereference it. */
4078 if (catch_errors (restore_selected_frame
, &fr
,
4079 "Unable to restore previously selected frame:\n",
4080 RETURN_MASK_ERROR
) == 0)
4081 /* Error in restoring the selected frame. Select the innermost
4085 select_frame (get_current_frame (), 0);
4089 free_inferior_status (inf_status
);
4093 do_restore_inferior_status_cleanup (void *sts
)
4095 restore_inferior_status (sts
);
4099 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4101 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4105 discard_inferior_status (struct inferior_status
*inf_status
)
4107 /* See save_inferior_status for info on stop_bpstat. */
4108 bpstat_clear (&inf_status
->stop_bpstat
);
4109 free_inferior_status (inf_status
);
4112 /* Oft used ptids */
4114 ptid_t minus_one_ptid
;
4116 /* Create a ptid given the necessary PID, LWP, and TID components. */
4119 ptid_build (int pid
, long lwp
, long tid
)
4129 /* Create a ptid from just a pid. */
4132 pid_to_ptid (int pid
)
4134 return ptid_build (pid
, 0, 0);
4137 /* Fetch the pid (process id) component from a ptid. */
4140 ptid_get_pid (ptid_t ptid
)
4145 /* Fetch the lwp (lightweight process) component from a ptid. */
4148 ptid_get_lwp (ptid_t ptid
)
4153 /* Fetch the tid (thread id) component from a ptid. */
4156 ptid_get_tid (ptid_t ptid
)
4161 /* ptid_equal() is used to test equality of two ptids. */
4164 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4166 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4167 && ptid1
.tid
== ptid2
.tid
);
4170 /* restore_inferior_ptid() will be used by the cleanup machinery
4171 to restore the inferior_ptid value saved in a call to
4172 save_inferior_ptid(). */
4175 restore_inferior_ptid (void *arg
)
4177 ptid_t
*saved_ptid_ptr
= arg
;
4178 inferior_ptid
= *saved_ptid_ptr
;
4182 /* Save the value of inferior_ptid so that it may be restored by a
4183 later call to do_cleanups(). Returns the struct cleanup pointer
4184 needed for later doing the cleanup. */
4187 save_inferior_ptid (void)
4189 ptid_t
*saved_ptid_ptr
;
4191 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4192 *saved_ptid_ptr
= inferior_ptid
;
4193 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4200 stop_registers
= xmalloc (REGISTER_BYTES
);
4204 _initialize_infrun (void)
4207 register int numsigs
;
4208 struct cmd_list_element
*c
;
4212 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4213 register_gdbarch_swap (NULL
, 0, build_infrun
);
4215 add_info ("signals", signals_info
,
4216 "What debugger does when program gets various signals.\n\
4217 Specify a signal as argument to print info on that signal only.");
4218 add_info_alias ("handle", "signals", 0);
4220 add_com ("handle", class_run
, handle_command
,
4221 concat ("Specify how to handle a signal.\n\
4222 Args are signals and actions to apply to those signals.\n\
4223 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4224 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4225 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4226 The special arg \"all\" is recognized to mean all signals except those\n\
4227 used by the debugger, typically SIGTRAP and SIGINT.\n",
4228 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4229 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4230 Stop means reenter debugger if this signal happens (implies print).\n\
4231 Print means print a message if this signal happens.\n\
4232 Pass means let program see this signal; otherwise program doesn't know.\n\
4233 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4234 Pass and Stop may be combined.", NULL
));
4237 add_com ("lz", class_info
, signals_info
,
4238 "What debugger does when program gets various signals.\n\
4239 Specify a signal as argument to print info on that signal only.");
4240 add_com ("z", class_run
, xdb_handle_command
,
4241 concat ("Specify how to handle a signal.\n\
4242 Args are signals and actions to apply to those signals.\n\
4243 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4244 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4245 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4246 The special arg \"all\" is recognized to mean all signals except those\n\
4247 used by the debugger, typically SIGTRAP and SIGINT.\n",
4248 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4249 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4250 nopass), \"Q\" (noprint)\n\
4251 Stop means reenter debugger if this signal happens (implies print).\n\
4252 Print means print a message if this signal happens.\n\
4253 Pass means let program see this signal; otherwise program doesn't know.\n\
4254 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4255 Pass and Stop may be combined.", NULL
));
4259 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
4260 "There is no `stop' command, but you can set a hook on `stop'.\n\
4261 This allows you to set a list of commands to be run each time execution\n\
4262 of the program stops.", &cmdlist
);
4264 numsigs
= (int) TARGET_SIGNAL_LAST
;
4265 signal_stop
= (unsigned char *)
4266 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4267 signal_print
= (unsigned char *)
4268 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4269 signal_program
= (unsigned char *)
4270 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4271 for (i
= 0; i
< numsigs
; i
++)
4274 signal_print
[i
] = 1;
4275 signal_program
[i
] = 1;
4278 /* Signals caused by debugger's own actions
4279 should not be given to the program afterwards. */
4280 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4281 signal_program
[TARGET_SIGNAL_INT
] = 0;
4283 /* Signals that are not errors should not normally enter the debugger. */
4284 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4285 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4286 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4287 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4288 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4289 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4290 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4291 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4292 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4293 signal_print
[TARGET_SIGNAL_IO
] = 0;
4294 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4295 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4296 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4297 signal_print
[TARGET_SIGNAL_URG
] = 0;
4298 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4299 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4301 /* These signals are used internally by user-level thread
4302 implementations. (See signal(5) on Solaris.) Like the above
4303 signals, a healthy program receives and handles them as part of
4304 its normal operation. */
4305 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4306 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4307 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4308 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4309 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4310 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4314 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4315 (char *) &stop_on_solib_events
,
4316 "Set stopping for shared library events.\n\
4317 If nonzero, gdb will give control to the user when the dynamic linker\n\
4318 notifies gdb of shared library events. The most common event of interest\n\
4319 to the user would be loading/unloading of a new library.\n",
4324 c
= add_set_enum_cmd ("follow-fork-mode",
4326 follow_fork_mode_kind_names
,
4327 &follow_fork_mode_string
,
4328 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4329 kernel problem. It's also not terribly useful without a GUI to
4330 help the user drive two debuggers. So for now, I'm disabling
4331 the "both" option. */
4332 /* "Set debugger response to a program call of fork \
4334 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4335 parent - the original process is debugged after a fork\n\
4336 child - the new process is debugged after a fork\n\
4337 both - both the parent and child are debugged after a fork\n\
4338 ask - the debugger will ask for one of the above choices\n\
4339 For \"both\", another copy of the debugger will be started to follow\n\
4340 the new child process. The original debugger will continue to follow\n\
4341 the original parent process. To distinguish their prompts, the\n\
4342 debugger copy's prompt will be changed.\n\
4343 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4344 By default, the debugger will follow the parent process.",
4346 "Set debugger response to a program call of fork \
4348 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4349 parent - the original process is debugged after a fork\n\
4350 child - the new process is debugged after a fork\n\
4351 ask - the debugger will ask for one of the above choices\n\
4352 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4353 By default, the debugger will follow the parent process.",
4355 /* c->function.sfunc = ; */
4356 add_show_from_set (c
, &showlist
);
4358 c
= add_set_enum_cmd ("scheduler-locking", class_run
,
4359 scheduler_enums
, /* array of string names */
4360 &scheduler_mode
, /* current mode */
4361 "Set mode for locking scheduler during execution.\n\
4362 off == no locking (threads may preempt at any time)\n\
4363 on == full locking (no thread except the current thread may run)\n\
4364 step == scheduler locked during every single-step operation.\n\
4365 In this mode, no other thread may run during a step command.\n\
4366 Other threads may run while stepping over a function call ('next').",
4369 c
->function
.sfunc
= set_schedlock_func
; /* traps on target vector */
4370 add_show_from_set (c
, &showlist
);
4372 c
= add_set_cmd ("step-mode", class_run
,
4373 var_boolean
, (char*) &step_stop_if_no_debug
,
4374 "Set mode of the step operation. When set, doing a step over a\n\
4375 function without debug line information will stop at the first\n\
4376 instruction of that function. Otherwise, the function is skipped and\n\
4377 the step command stops at a different source line.",
4379 add_show_from_set (c
, &showlist
);
4381 /* ptid initializations */
4382 null_ptid
= ptid_build (0, 0, 0);
4383 minus_one_ptid
= ptid_build (-1, 0, 0);
4384 inferior_ptid
= null_ptid
;
4385 target_last_wait_ptid
= minus_one_ptid
;