1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
5 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
26 #include "gdb_string.h"
31 #include "breakpoint.h"
35 #include "cli/cli-script.h"
37 #include "gdbthread.h"
46 /* Prototypes for local functions */
48 static void signals_info (char *, int);
50 static void handle_command (char *, int);
52 static void sig_print_info (enum target_signal
);
54 static void sig_print_header (void);
56 static void resume_cleanups (void *);
58 static int hook_stop_stub (void *);
60 static void delete_breakpoint_current_contents (void *);
62 static void set_follow_fork_mode_command (char *arg
, int from_tty
,
63 struct cmd_list_element
*c
);
65 static int restore_selected_frame (void *);
67 static void build_infrun (void);
69 static void follow_inferior_fork (int parent_pid
, int child_pid
,
70 int has_forked
, int has_vforked
);
72 static void follow_fork (int parent_pid
, int child_pid
);
74 static void follow_vfork (int parent_pid
, int child_pid
);
76 static void set_schedlock_func (char *args
, int from_tty
,
77 struct cmd_list_element
*c
);
79 struct execution_control_state
;
81 static int currently_stepping (struct execution_control_state
*ecs
);
83 static void xdb_handle_command (char *args
, int from_tty
);
85 void _initialize_infrun (void);
87 int inferior_ignoring_startup_exec_events
= 0;
88 int inferior_ignoring_leading_exec_events
= 0;
90 /* When set, stop the 'step' command if we enter a function which has
91 no line number information. The normal behavior is that we step
92 over such function. */
93 int step_stop_if_no_debug
= 0;
95 /* In asynchronous mode, but simulating synchronous execution. */
97 int sync_execution
= 0;
99 /* wait_for_inferior and normal_stop use this to notify the user
100 when the inferior stopped in a different thread than it had been
103 static ptid_t previous_inferior_ptid
;
105 /* This is true for configurations that may follow through execl() and
106 similar functions. At present this is only true for HP-UX native. */
108 #ifndef MAY_FOLLOW_EXEC
109 #define MAY_FOLLOW_EXEC (0)
112 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
114 /* Dynamic function trampolines are similar to solib trampolines in that they
115 are between the caller and the callee. The difference is that when you
116 enter a dynamic trampoline, you can't determine the callee's address. Some
117 (usually complex) code needs to run in the dynamic trampoline to figure out
118 the callee's address. This macro is usually called twice. First, when we
119 enter the trampoline (looks like a normal function call at that point). It
120 should return the PC of a point within the trampoline where the callee's
121 address is known. Second, when we hit the breakpoint, this routine returns
122 the callee's address. At that point, things proceed as per a step resume
125 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
126 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
129 /* If the program uses ELF-style shared libraries, then calls to
130 functions in shared libraries go through stubs, which live in a
131 table called the PLT (Procedure Linkage Table). The first time the
132 function is called, the stub sends control to the dynamic linker,
133 which looks up the function's real address, patches the stub so
134 that future calls will go directly to the function, and then passes
135 control to the function.
137 If we are stepping at the source level, we don't want to see any of
138 this --- we just want to skip over the stub and the dynamic linker.
139 The simple approach is to single-step until control leaves the
142 However, on some systems (e.g., Red Hat's 5.2 distribution) the
143 dynamic linker calls functions in the shared C library, so you
144 can't tell from the PC alone whether the dynamic linker is still
145 running. In this case, we use a step-resume breakpoint to get us
146 past the dynamic linker, as if we were using "next" to step over a
149 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
150 linker code or not. Normally, this means we single-step. However,
151 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
152 address where we can place a step-resume breakpoint to get past the
153 linker's symbol resolution function.
155 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
156 pretty portable way, by comparing the PC against the address ranges
157 of the dynamic linker's sections.
159 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
160 it depends on internal details of the dynamic linker. It's usually
161 not too hard to figure out where to put a breakpoint, but it
162 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
163 sanity checking. If it can't figure things out, returning zero and
164 getting the (possibly confusing) stepping behavior is better than
165 signalling an error, which will obscure the change in the
168 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
169 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
172 #ifndef SKIP_SOLIB_RESOLVER
173 #define SKIP_SOLIB_RESOLVER(pc) 0
176 /* In some shared library schemes, the return path from a shared library
177 call may need to go through a trampoline too. */
179 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
180 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
183 /* This function returns TRUE if pc is the address of an instruction
184 that lies within the dynamic linker (such as the event hook, or the
187 This function must be used only when a dynamic linker event has
188 been caught, and the inferior is being stepped out of the hook, or
189 undefined results are guaranteed. */
191 #ifndef SOLIB_IN_DYNAMIC_LINKER
192 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
195 /* On MIPS16, a function that returns a floating point value may call
196 a library helper function to copy the return value to a floating point
197 register. The IGNORE_HELPER_CALL macro returns non-zero if we
198 should ignore (i.e. step over) this function call. */
199 #ifndef IGNORE_HELPER_CALL
200 #define IGNORE_HELPER_CALL(pc) 0
203 /* On some systems, the PC may be left pointing at an instruction that won't
204 actually be executed. This is usually indicated by a bit in the PSW. If
205 we find ourselves in such a state, then we step the target beyond the
206 nullified instruction before returning control to the user so as to avoid
209 #ifndef INSTRUCTION_NULLIFIED
210 #define INSTRUCTION_NULLIFIED 0
213 /* We can't step off a permanent breakpoint in the ordinary way, because we
214 can't remove it. Instead, we have to advance the PC to the next
215 instruction. This macro should expand to a pointer to a function that
216 does that, or zero if we have no such function. If we don't have a
217 definition for it, we have to report an error. */
218 #ifndef SKIP_PERMANENT_BREAKPOINT
219 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
221 default_skip_permanent_breakpoint (void)
224 The program is stopped at a permanent breakpoint, but GDB does not know\n\
225 how to step past a permanent breakpoint on this architecture. Try using\n\
226 a command like `return' or `jump' to continue execution.");
231 /* Convert the #defines into values. This is temporary until wfi control
232 flow is completely sorted out. */
234 #ifndef HAVE_STEPPABLE_WATCHPOINT
235 #define HAVE_STEPPABLE_WATCHPOINT 0
237 #undef HAVE_STEPPABLE_WATCHPOINT
238 #define HAVE_STEPPABLE_WATCHPOINT 1
241 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
242 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
244 #undef HAVE_NONSTEPPABLE_WATCHPOINT
245 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
248 #ifndef HAVE_CONTINUABLE_WATCHPOINT
249 #define HAVE_CONTINUABLE_WATCHPOINT 0
251 #undef HAVE_CONTINUABLE_WATCHPOINT
252 #define HAVE_CONTINUABLE_WATCHPOINT 1
255 #ifndef CANNOT_STEP_HW_WATCHPOINTS
256 #define CANNOT_STEP_HW_WATCHPOINTS 0
258 #undef CANNOT_STEP_HW_WATCHPOINTS
259 #define CANNOT_STEP_HW_WATCHPOINTS 1
262 /* Tables of how to react to signals; the user sets them. */
264 static unsigned char *signal_stop
;
265 static unsigned char *signal_print
;
266 static unsigned char *signal_program
;
268 #define SET_SIGS(nsigs,sigs,flags) \
270 int signum = (nsigs); \
271 while (signum-- > 0) \
272 if ((sigs)[signum]) \
273 (flags)[signum] = 1; \
276 #define UNSET_SIGS(nsigs,sigs,flags) \
278 int signum = (nsigs); \
279 while (signum-- > 0) \
280 if ((sigs)[signum]) \
281 (flags)[signum] = 0; \
284 /* Value to pass to target_resume() to cause all threads to resume */
286 #define RESUME_ALL (pid_to_ptid (-1))
288 /* Command list pointer for the "stop" placeholder. */
290 static struct cmd_list_element
*stop_command
;
292 /* Nonzero if breakpoints are now inserted in the inferior. */
294 static int breakpoints_inserted
;
296 /* Function inferior was in as of last step command. */
298 static struct symbol
*step_start_function
;
300 /* Nonzero if we are expecting a trace trap and should proceed from it. */
302 static int trap_expected
;
305 /* Nonzero if we want to give control to the user when we're notified
306 of shared library events by the dynamic linker. */
307 static int stop_on_solib_events
;
311 /* Nonzero if the next time we try to continue the inferior, it will
312 step one instruction and generate a spurious trace trap.
313 This is used to compensate for a bug in HP-UX. */
315 static int trap_expected_after_continue
;
318 /* Nonzero means expecting a trace trap
319 and should stop the inferior and return silently when it happens. */
323 /* Nonzero means expecting a trap and caller will handle it themselves.
324 It is used after attach, due to attaching to a process;
325 when running in the shell before the child program has been exec'd;
326 and when running some kinds of remote stuff (FIXME?). */
328 int stop_soon_quietly
;
330 /* Nonzero if proceed is being used for a "finish" command or a similar
331 situation when stop_registers should be saved. */
333 int proceed_to_finish
;
335 /* Save register contents here when about to pop a stack dummy frame,
336 if-and-only-if proceed_to_finish is set.
337 Thus this contains the return value from the called function (assuming
338 values are returned in a register). */
340 struct regcache
*stop_registers
;
342 /* Nonzero if program stopped due to error trying to insert breakpoints. */
344 static int breakpoints_failed
;
346 /* Nonzero after stop if current stack frame should be printed. */
348 static int stop_print_frame
;
350 static struct breakpoint
*step_resume_breakpoint
= NULL
;
351 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
353 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
354 interactions with an inferior that is running a kernel function
355 (aka, a system call or "syscall"). wait_for_inferior therefore
356 may have a need to know when the inferior is in a syscall. This
357 is a count of the number of inferior threads which are known to
358 currently be running in a syscall. */
359 static int number_of_threads_in_syscalls
;
361 /* This is a cached copy of the pid/waitstatus of the last event
362 returned by target_wait()/target_wait_hook(). This information is
363 returned by get_last_target_status(). */
364 static ptid_t target_last_wait_ptid
;
365 static struct target_waitstatus target_last_waitstatus
;
367 /* This is used to remember when a fork, vfork or exec event
368 was caught by a catchpoint, and thus the event is to be
369 followed at the next resume of the inferior, and not
373 enum target_waitkind kind
;
383 char *execd_pathname
;
387 /* Some platforms don't allow us to do anything meaningful with a
388 vforked child until it has exec'd. Vforked processes on such
389 platforms can only be followed after they've exec'd.
391 When this is set to 0, a vfork can be immediately followed,
392 and an exec can be followed merely as an exec. When this is
393 set to 1, a vfork event has been seen, but cannot be followed
394 until the exec is seen.
396 (In the latter case, inferior_ptid is still the parent of the
397 vfork, and pending_follow.fork_event.child_pid is the child. The
398 appropriate process is followed, according to the setting of
399 follow-fork-mode.) */
400 static int follow_vfork_when_exec
;
402 static const char follow_fork_mode_ask
[] = "ask";
403 static const char follow_fork_mode_both
[] = "both";
404 static const char follow_fork_mode_child
[] = "child";
405 static const char follow_fork_mode_parent
[] = "parent";
407 static const char *follow_fork_mode_kind_names
[] = {
408 follow_fork_mode_ask
,
409 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
410 kernel problem. It's also not terribly useful without a GUI to
411 help the user drive two debuggers. So for now, I'm disabling the
413 /* follow_fork_mode_both, */
414 follow_fork_mode_child
,
415 follow_fork_mode_parent
,
419 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
423 follow_inferior_fork (int parent_pid
, int child_pid
, int has_forked
,
426 int followed_parent
= 0;
427 int followed_child
= 0;
429 /* Which process did the user want us to follow? */
430 const char *follow_mode
= follow_fork_mode_string
;
432 /* Or, did the user not know, and want us to ask? */
433 if (follow_fork_mode_string
== follow_fork_mode_ask
)
435 internal_error (__FILE__
, __LINE__
,
436 "follow_inferior_fork: \"ask\" mode not implemented");
437 /* follow_mode = follow_fork_mode_...; */
440 /* If we're to be following the parent, then detach from child_pid.
441 We're already following the parent, so need do nothing explicit
443 if (follow_mode
== follow_fork_mode_parent
)
447 /* We're already attached to the parent, by default. */
449 /* Before detaching from the child, remove all breakpoints from
450 it. (This won't actually modify the breakpoint list, but will
451 physically remove the breakpoints from the child.) */
452 if (!has_vforked
|| !follow_vfork_when_exec
)
454 detach_breakpoints (child_pid
);
455 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
456 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
460 /* Detach from the child. */
463 target_require_detach (child_pid
, "", 1);
466 /* If we're to be following the child, then attach to it, detach
467 from inferior_ptid, and set inferior_ptid to child_pid. */
468 else if (follow_mode
== follow_fork_mode_child
)
470 char child_pid_spelling
[100]; /* Arbitrary length. */
474 /* Before detaching from the parent, detach all breakpoints from
475 the child. But only if we're forking, or if we follow vforks
476 as soon as they happen. (If we're following vforks only when
477 the child has exec'd, then it's very wrong to try to write
478 back the "shadow contents" of inserted breakpoints now -- they
479 belong to the child's pre-exec'd a.out.) */
480 if (!has_vforked
|| !follow_vfork_when_exec
)
482 detach_breakpoints (child_pid
);
485 /* Before detaching from the parent, remove all breakpoints from it. */
486 remove_breakpoints ();
488 /* Also reset the solib inferior hook from the parent. */
489 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
490 SOLIB_REMOVE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
493 /* Detach from the parent. */
495 target_detach (NULL
, 1);
497 /* Attach to the child. */
498 inferior_ptid
= pid_to_ptid (child_pid
);
499 sprintf (child_pid_spelling
, "%d", child_pid
);
502 target_require_attach (child_pid_spelling
, 1);
504 /* Was there a step_resume breakpoint? (There was if the user
505 did a "next" at the fork() call.) If so, explicitly reset its
508 step_resumes are a form of bp that are made to be per-thread.
509 Since we created the step_resume bp when the parent process
510 was being debugged, and now are switching to the child process,
511 from the breakpoint package's viewpoint, that's a switch of
512 "threads". We must update the bp's notion of which thread
513 it is for, or it'll be ignored when it triggers... */
514 if (step_resume_breakpoint
&& (!has_vforked
|| !follow_vfork_when_exec
))
515 breakpoint_re_set_thread (step_resume_breakpoint
);
517 /* Reinsert all breakpoints in the child. (The user may've set
518 breakpoints after catching the fork, in which case those
519 actually didn't get set in the child, but only in the parent.) */
520 if (!has_vforked
|| !follow_vfork_when_exec
)
522 breakpoint_re_set ();
523 insert_breakpoints ();
527 /* If we're to be following both parent and child, then fork ourselves,
528 and attach the debugger clone to the child. */
529 else if (follow_mode
== follow_fork_mode_both
)
531 char pid_suffix
[100]; /* Arbitrary length. */
533 /* Clone ourselves to follow the child. This is the end of our
534 involvement with child_pid; our clone will take it from here... */
536 target_clone_and_follow_inferior (child_pid
, &followed_child
);
537 followed_parent
= !followed_child
;
539 /* We continue to follow the parent. To help distinguish the two
540 debuggers, though, both we and our clone will reset our prompts. */
541 sprintf (pid_suffix
, "[%d] ", PIDGET (inferior_ptid
));
542 set_prompt (strcat (get_prompt (), pid_suffix
));
545 /* The parent and child of a vfork share the same address space.
546 Also, on some targets the order in which vfork and exec events
547 are received for parent in child requires some delicate handling
550 For instance, on ptrace-based HPUX we receive the child's vfork
551 event first, at which time the parent has been suspended by the
552 OS and is essentially untouchable until the child's exit or second
553 exec event arrives. At that time, the parent's vfork event is
554 delivered to us, and that's when we see and decide how to follow
555 the vfork. But to get to that point, we must continue the child
556 until it execs or exits. To do that smoothly, all breakpoints
557 must be removed from the child, in case there are any set between
558 the vfork() and exec() calls. But removing them from the child
559 also removes them from the parent, due to the shared-address-space
560 nature of a vfork'd parent and child. On HPUX, therefore, we must
561 take care to restore the bp's to the parent before we continue it.
562 Else, it's likely that we may not stop in the expected place. (The
563 worst scenario is when the user tries to step over a vfork() call;
564 the step-resume bp must be restored for the step to properly stop
565 in the parent after the call completes!)
567 Sequence of events, as reported to gdb from HPUX:
569 Parent Child Action for gdb to take
570 -------------------------------------------------------
571 1 VFORK Continue child
577 target_post_follow_vfork (parent_pid
,
578 followed_parent
, child_pid
, followed_child
);
581 pending_follow
.fork_event
.saw_parent_fork
= 0;
582 pending_follow
.fork_event
.saw_child_fork
= 0;
586 follow_fork (int parent_pid
, int child_pid
)
588 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
592 /* Forward declaration. */
593 static void follow_exec (int, char *);
596 follow_vfork (int parent_pid
, int child_pid
)
598 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
600 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
601 if (pending_follow
.fork_event
.saw_child_exec
602 && (PIDGET (inferior_ptid
) == child_pid
))
604 pending_follow
.fork_event
.saw_child_exec
= 0;
605 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
606 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
607 xfree (pending_follow
.execd_pathname
);
611 /* EXECD_PATHNAME is assumed to be non-NULL. */
614 follow_exec (int pid
, char *execd_pathname
)
617 struct target_ops
*tgt
;
619 if (!may_follow_exec
)
622 /* Did this exec() follow a vfork()? If so, we must follow the
623 vfork now too. Do it before following the exec. */
624 if (follow_vfork_when_exec
&&
625 (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
))
627 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
628 follow_vfork (PIDGET (inferior_ptid
),
629 pending_follow
.fork_event
.child_pid
);
630 follow_vfork_when_exec
= 0;
631 saved_pid
= PIDGET (inferior_ptid
);
633 /* Did we follow the parent? If so, we're done. If we followed
634 the child then we must also follow its exec(). */
635 if (PIDGET (inferior_ptid
) == pending_follow
.fork_event
.parent_pid
)
639 /* This is an exec event that we actually wish to pay attention to.
640 Refresh our symbol table to the newly exec'd program, remove any
643 If there are breakpoints, they aren't really inserted now,
644 since the exec() transformed our inferior into a fresh set
647 We want to preserve symbolic breakpoints on the list, since
648 we have hopes that they can be reset after the new a.out's
649 symbol table is read.
651 However, any "raw" breakpoints must be removed from the list
652 (e.g., the solib bp's), since their address is probably invalid
655 And, we DON'T want to call delete_breakpoints() here, since
656 that may write the bp's "shadow contents" (the instruction
657 value that was overwritten witha TRAP instruction). Since
658 we now have a new a.out, those shadow contents aren't valid. */
659 update_breakpoints_after_exec ();
661 /* If there was one, it's gone now. We cannot truly step-to-next
662 statement through an exec(). */
663 step_resume_breakpoint
= NULL
;
664 step_range_start
= 0;
667 /* If there was one, it's gone now. */
668 through_sigtramp_breakpoint
= NULL
;
670 /* What is this a.out's name? */
671 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
673 /* We've followed the inferior through an exec. Therefore, the
674 inferior has essentially been killed & reborn. */
676 /* First collect the run target in effect. */
677 tgt
= find_run_target ();
678 /* If we can't find one, things are in a very strange state... */
680 error ("Could find run target to save before following exec");
682 gdb_flush (gdb_stdout
);
683 target_mourn_inferior ();
684 inferior_ptid
= pid_to_ptid (saved_pid
);
685 /* Because mourn_inferior resets inferior_ptid. */
688 /* That a.out is now the one to use. */
689 exec_file_attach (execd_pathname
, 0);
691 /* And also is where symbols can be found. */
692 symbol_file_add_main (execd_pathname
, 0);
694 /* Reset the shared library package. This ensures that we get
695 a shlib event when the child reaches "_start", at which point
696 the dld will have had a chance to initialize the child. */
697 #if defined(SOLIB_RESTART)
700 #ifdef SOLIB_CREATE_INFERIOR_HOOK
701 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
704 /* Reinsert all breakpoints. (Those which were symbolic have
705 been reset to the proper address in the new a.out, thanks
706 to symbol_file_command...) */
707 insert_breakpoints ();
709 /* The next resume of this inferior should bring it to the shlib
710 startup breakpoints. (If the user had also set bp's on
711 "main" from the old (parent) process, then they'll auto-
712 matically get reset there in the new process.) */
715 /* Non-zero if we just simulating a single-step. This is needed
716 because we cannot remove the breakpoints in the inferior process
717 until after the `wait' in `wait_for_inferior'. */
718 static int singlestep_breakpoints_inserted_p
= 0;
721 /* Things to clean up if we QUIT out of resume (). */
724 resume_cleanups (void *ignore
)
729 static const char schedlock_off
[] = "off";
730 static const char schedlock_on
[] = "on";
731 static const char schedlock_step
[] = "step";
732 static const char *scheduler_mode
= schedlock_off
;
733 static const char *scheduler_enums
[] = {
741 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
743 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
744 the set command passed as a parameter. The clone operation will
745 include (BUG?) any ``set'' command callback, if present.
746 Commands like ``info set'' call all the ``show'' command
747 callbacks. Unfortunatly, for ``show'' commands cloned from
748 ``set'', this includes callbacks belonging to ``set'' commands.
749 Making this worse, this only occures if add_show_from_set() is
750 called after add_cmd_sfunc() (BUG?). */
751 if (cmd_type (c
) == set_cmd
)
752 if (!target_can_lock_scheduler
)
754 scheduler_mode
= schedlock_off
;
755 error ("Target '%s' cannot support this command.", target_shortname
);
760 /* Resume the inferior, but allow a QUIT. This is useful if the user
761 wants to interrupt some lengthy single-stepping operation
762 (for child processes, the SIGINT goes to the inferior, and so
763 we get a SIGINT random_signal, but for remote debugging and perhaps
764 other targets, that's not true).
766 STEP nonzero if we should step (zero to continue instead).
767 SIG is the signal to give the inferior (zero for none). */
769 resume (int step
, enum target_signal sig
)
771 int should_resume
= 1;
772 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
775 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
778 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
779 over an instruction that causes a page fault without triggering
780 a hardware watchpoint. The kernel properly notices that it shouldn't
781 stop, because the hardware watchpoint is not triggered, but it forgets
782 the step request and continues the program normally.
783 Work around the problem by removing hardware watchpoints if a step is
784 requested, GDB will check for a hardware watchpoint trigger after the
786 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
787 remove_hw_watchpoints ();
790 /* Normally, by the time we reach `resume', the breakpoints are either
791 removed or inserted, as appropriate. The exception is if we're sitting
792 at a permanent breakpoint; we need to step over it, but permanent
793 breakpoints can't be removed. So we have to test for it here. */
794 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
795 SKIP_PERMANENT_BREAKPOINT ();
797 if (SOFTWARE_SINGLE_STEP_P () && step
)
799 /* Do it the hard way, w/temp breakpoints */
800 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
801 /* ...and don't ask hardware to do it. */
803 /* and do not pull these breakpoints until after a `wait' in
804 `wait_for_inferior' */
805 singlestep_breakpoints_inserted_p
= 1;
808 /* Handle any optimized stores to the inferior NOW... */
809 #ifdef DO_DEFERRED_STORES
813 /* If there were any forks/vforks/execs that were caught and are
814 now to be followed, then do so. */
815 switch (pending_follow
.kind
)
817 case (TARGET_WAITKIND_FORKED
):
818 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
819 follow_fork (PIDGET (inferior_ptid
),
820 pending_follow
.fork_event
.child_pid
);
823 case (TARGET_WAITKIND_VFORKED
):
825 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
827 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
828 follow_vfork (PIDGET (inferior_ptid
),
829 pending_follow
.fork_event
.child_pid
);
831 /* Did we follow the child, but not yet see the child's exec event?
832 If so, then it actually ought to be waiting for us; we respond to
833 parent vfork events. We don't actually want to resume the child
834 in this situation; we want to just get its exec event. */
835 if (!saw_child_exec
&&
836 (PIDGET (inferior_ptid
) == pending_follow
.fork_event
.child_pid
))
841 case (TARGET_WAITKIND_EXECD
):
842 /* If we saw a vfork event but couldn't follow it until we saw
843 an exec, then now might be the time! */
844 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
845 /* follow_exec is called as soon as the exec event is seen. */
852 /* Install inferior's terminal modes. */
853 target_terminal_inferior ();
859 resume_ptid
= RESUME_ALL
; /* Default */
861 if ((step
|| singlestep_breakpoints_inserted_p
) &&
862 !breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
864 /* Stepping past a breakpoint without inserting breakpoints.
865 Make sure only the current thread gets to step, so that
866 other threads don't sneak past breakpoints while they are
869 resume_ptid
= inferior_ptid
;
872 if ((scheduler_mode
== schedlock_on
) ||
873 (scheduler_mode
== schedlock_step
&&
874 (step
|| singlestep_breakpoints_inserted_p
)))
876 /* User-settable 'scheduler' mode requires solo thread resume. */
877 resume_ptid
= inferior_ptid
;
880 #ifdef CANNOT_STEP_BREAKPOINT
881 /* Most targets can step a breakpoint instruction, thus executing it
882 normally. But if this one cannot, just continue and we will hit
884 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
887 target_resume (resume_ptid
, step
, sig
);
890 discard_cleanups (old_cleanups
);
894 /* Clear out all variables saying what to do when inferior is continued.
895 First do this, then set the ones you want, then call `proceed'. */
898 clear_proceed_status (void)
901 step_range_start
= 0;
903 step_frame_address
= 0;
904 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
906 stop_soon_quietly
= 0;
907 proceed_to_finish
= 0;
908 breakpoint_proceeded
= 1; /* We're about to proceed... */
910 /* Discard any remaining commands or status from previous stop. */
911 bpstat_clear (&stop_bpstat
);
914 /* Basic routine for continuing the program in various fashions.
916 ADDR is the address to resume at, or -1 for resume where stopped.
917 SIGGNAL is the signal to give it, or 0 for none,
918 or -1 for act according to how it stopped.
919 STEP is nonzero if should trap after one instruction.
920 -1 means return after that and print nothing.
921 You should probably set various step_... variables
922 before calling here, if you are stepping.
924 You should call clear_proceed_status before calling proceed. */
927 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
932 step_start_function
= find_pc_function (read_pc ());
936 if (addr
== (CORE_ADDR
) -1)
938 /* If there is a breakpoint at the address we will resume at,
939 step one instruction before inserting breakpoints
940 so that we do not stop right away (and report a second
941 hit at this breakpoint). */
943 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
946 #ifndef STEP_SKIPS_DELAY
947 #define STEP_SKIPS_DELAY(pc) (0)
948 #define STEP_SKIPS_DELAY_P (0)
950 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
951 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
952 is slow (it needs to read memory from the target). */
953 if (STEP_SKIPS_DELAY_P
954 && breakpoint_here_p (read_pc () + 4)
955 && STEP_SKIPS_DELAY (read_pc ()))
963 #ifdef PREPARE_TO_PROCEED
964 /* In a multi-threaded task we may select another thread
965 and then continue or step.
967 But if the old thread was stopped at a breakpoint, it
968 will immediately cause another breakpoint stop without
969 any execution (i.e. it will report a breakpoint hit
970 incorrectly). So we must step over it first.
972 PREPARE_TO_PROCEED checks the current thread against the thread
973 that reported the most recent event. If a step-over is required
974 it returns TRUE and sets the current thread to the old thread. */
975 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
980 #endif /* PREPARE_TO_PROCEED */
983 if (trap_expected_after_continue
)
985 /* If (step == 0), a trap will be automatically generated after
986 the first instruction is executed. Force step one
987 instruction to clear this condition. This should not occur
988 if step is nonzero, but it is harmless in that case. */
990 trap_expected_after_continue
= 0;
992 #endif /* HP_OS_BUG */
995 /* We will get a trace trap after one instruction.
996 Continue it automatically and insert breakpoints then. */
1000 int temp
= insert_breakpoints ();
1003 print_sys_errmsg ("insert_breakpoints", temp
);
1004 error ("Cannot insert breakpoints.\n\
1005 The same program may be running in another process,\n\
1006 or you may have requested too many hardware\n\
1007 breakpoints and/or watchpoints.\n");
1010 breakpoints_inserted
= 1;
1013 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1014 stop_signal
= siggnal
;
1015 /* If this signal should not be seen by program,
1016 give it zero. Used for debugging signals. */
1017 else if (!signal_program
[stop_signal
])
1018 stop_signal
= TARGET_SIGNAL_0
;
1020 annotate_starting ();
1022 /* Make sure that output from GDB appears before output from the
1024 gdb_flush (gdb_stdout
);
1026 /* Resume inferior. */
1027 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1029 /* Wait for it to stop (if not standalone)
1030 and in any case decode why it stopped, and act accordingly. */
1031 /* Do this only if we are not using the event loop, or if the target
1032 does not support asynchronous execution. */
1033 if (!event_loop_p
|| !target_can_async_p ())
1035 wait_for_inferior ();
1040 /* Record the pc and sp of the program the last time it stopped.
1041 These are just used internally by wait_for_inferior, but need
1042 to be preserved over calls to it and cleared when the inferior
1044 static CORE_ADDR prev_pc
;
1045 static CORE_ADDR prev_func_start
;
1046 static char *prev_func_name
;
1049 /* Start remote-debugging of a machine over a serial link. */
1054 init_thread_list ();
1055 init_wait_for_inferior ();
1056 stop_soon_quietly
= 1;
1059 /* Always go on waiting for the target, regardless of the mode. */
1060 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1061 indicate to wait_for_inferior that a target should timeout if
1062 nothing is returned (instead of just blocking). Because of this,
1063 targets expecting an immediate response need to, internally, set
1064 things up so that the target_wait() is forced to eventually
1066 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1067 differentiate to its caller what the state of the target is after
1068 the initial open has been performed. Here we're assuming that
1069 the target has stopped. It should be possible to eventually have
1070 target_open() return to the caller an indication that the target
1071 is currently running and GDB state should be set to the same as
1072 for an async run. */
1073 wait_for_inferior ();
1077 /* Initialize static vars when a new inferior begins. */
1080 init_wait_for_inferior (void)
1082 /* These are meaningless until the first time through wait_for_inferior. */
1084 prev_func_start
= 0;
1085 prev_func_name
= NULL
;
1088 trap_expected_after_continue
= 0;
1090 breakpoints_inserted
= 0;
1091 breakpoint_init_inferior (inf_starting
);
1093 /* Don't confuse first call to proceed(). */
1094 stop_signal
= TARGET_SIGNAL_0
;
1096 /* The first resume is not following a fork/vfork/exec. */
1097 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1098 pending_follow
.fork_event
.saw_parent_fork
= 0;
1099 pending_follow
.fork_event
.saw_child_fork
= 0;
1100 pending_follow
.fork_event
.saw_child_exec
= 0;
1102 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1103 number_of_threads_in_syscalls
= 0;
1105 clear_proceed_status ();
1109 delete_breakpoint_current_contents (void *arg
)
1111 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1112 if (*breakpointp
!= NULL
)
1114 delete_breakpoint (*breakpointp
);
1115 *breakpointp
= NULL
;
1119 /* This enum encodes possible reasons for doing a target_wait, so that
1120 wfi can call target_wait in one place. (Ultimately the call will be
1121 moved out of the infinite loop entirely.) */
1125 infwait_normal_state
,
1126 infwait_thread_hop_state
,
1127 infwait_nullified_state
,
1128 infwait_nonstep_watch_state
1131 /* Why did the inferior stop? Used to print the appropriate messages
1132 to the interface from within handle_inferior_event(). */
1133 enum inferior_stop_reason
1135 /* We don't know why. */
1137 /* Step, next, nexti, stepi finished. */
1139 /* Found breakpoint. */
1141 /* Inferior terminated by signal. */
1143 /* Inferior exited. */
1145 /* Inferior received signal, and user asked to be notified. */
1149 /* This structure contains what used to be local variables in
1150 wait_for_inferior. Probably many of them can return to being
1151 locals in handle_inferior_event. */
1153 struct execution_control_state
1155 struct target_waitstatus ws
;
1156 struct target_waitstatus
*wp
;
1159 CORE_ADDR stop_func_start
;
1160 CORE_ADDR stop_func_end
;
1161 char *stop_func_name
;
1162 struct symtab_and_line sal
;
1163 int remove_breakpoints_on_following_step
;
1165 struct symtab
*current_symtab
;
1166 int handling_longjmp
; /* FIXME */
1168 ptid_t saved_inferior_ptid
;
1170 int stepping_through_solib_after_catch
;
1171 bpstat stepping_through_solib_catchpoints
;
1172 int enable_hw_watchpoints_after_wait
;
1173 int stepping_through_sigtramp
;
1174 int new_thread_event
;
1175 struct target_waitstatus tmpstatus
;
1176 enum infwait_states infwait_state
;
1181 void init_execution_control_state (struct execution_control_state
*ecs
);
1183 void handle_inferior_event (struct execution_control_state
*ecs
);
1185 static void check_sigtramp2 (struct execution_control_state
*ecs
);
1186 static void step_into_function (struct execution_control_state
*ecs
);
1187 static void step_over_function (struct execution_control_state
*ecs
);
1188 static void stop_stepping (struct execution_control_state
*ecs
);
1189 static void prepare_to_wait (struct execution_control_state
*ecs
);
1190 static void keep_going (struct execution_control_state
*ecs
);
1191 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
1194 /* Wait for control to return from inferior to debugger.
1195 If inferior gets a signal, we may decide to start it up again
1196 instead of returning. That is why there is a loop in this function.
1197 When this function actually returns it means the inferior
1198 should be left stopped and GDB should read more commands. */
1201 wait_for_inferior (void)
1203 struct cleanup
*old_cleanups
;
1204 struct execution_control_state ecss
;
1205 struct execution_control_state
*ecs
;
1207 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1208 &step_resume_breakpoint
);
1209 make_cleanup (delete_breakpoint_current_contents
,
1210 &through_sigtramp_breakpoint
);
1212 /* wfi still stays in a loop, so it's OK just to take the address of
1213 a local to get the ecs pointer. */
1216 /* Fill in with reasonable starting values. */
1217 init_execution_control_state (ecs
);
1219 /* We'll update this if & when we switch to a new thread. */
1220 previous_inferior_ptid
= inferior_ptid
;
1222 overlay_cache_invalid
= 1;
1224 /* We have to invalidate the registers BEFORE calling target_wait
1225 because they can be loaded from the target while in target_wait.
1226 This makes remote debugging a bit more efficient for those
1227 targets that provide critical registers as part of their normal
1228 status mechanism. */
1230 registers_changed ();
1234 if (target_wait_hook
)
1235 ecs
->ptid
= target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
1237 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
1239 /* Now figure out what to do with the result of the result. */
1240 handle_inferior_event (ecs
);
1242 if (!ecs
->wait_some_more
)
1245 do_cleanups (old_cleanups
);
1248 /* Asynchronous version of wait_for_inferior. It is called by the
1249 event loop whenever a change of state is detected on the file
1250 descriptor corresponding to the target. It can be called more than
1251 once to complete a single execution command. In such cases we need
1252 to keep the state in a global variable ASYNC_ECSS. If it is the
1253 last time that this function is called for a single execution
1254 command, then report to the user that the inferior has stopped, and
1255 do the necessary cleanups. */
1257 struct execution_control_state async_ecss
;
1258 struct execution_control_state
*async_ecs
;
1261 fetch_inferior_event (void *client_data
)
1263 static struct cleanup
*old_cleanups
;
1265 async_ecs
= &async_ecss
;
1267 if (!async_ecs
->wait_some_more
)
1269 old_cleanups
= make_exec_cleanup (delete_step_resume_breakpoint
,
1270 &step_resume_breakpoint
);
1271 make_exec_cleanup (delete_breakpoint_current_contents
,
1272 &through_sigtramp_breakpoint
);
1274 /* Fill in with reasonable starting values. */
1275 init_execution_control_state (async_ecs
);
1277 /* We'll update this if & when we switch to a new thread. */
1278 previous_inferior_ptid
= inferior_ptid
;
1280 overlay_cache_invalid
= 1;
1282 /* We have to invalidate the registers BEFORE calling target_wait
1283 because they can be loaded from the target while in target_wait.
1284 This makes remote debugging a bit more efficient for those
1285 targets that provide critical registers as part of their normal
1286 status mechanism. */
1288 registers_changed ();
1291 if (target_wait_hook
)
1293 target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1295 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1297 /* Now figure out what to do with the result of the result. */
1298 handle_inferior_event (async_ecs
);
1300 if (!async_ecs
->wait_some_more
)
1302 /* Do only the cleanups that have been added by this
1303 function. Let the continuations for the commands do the rest,
1304 if there are any. */
1305 do_exec_cleanups (old_cleanups
);
1307 if (step_multi
&& stop_step
)
1308 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1310 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1314 /* Prepare an execution control state for looping through a
1315 wait_for_inferior-type loop. */
1318 init_execution_control_state (struct execution_control_state
*ecs
)
1320 /* ecs->another_trap? */
1321 ecs
->random_signal
= 0;
1322 ecs
->remove_breakpoints_on_following_step
= 0;
1323 ecs
->handling_longjmp
= 0; /* FIXME */
1324 ecs
->update_step_sp
= 0;
1325 ecs
->stepping_through_solib_after_catch
= 0;
1326 ecs
->stepping_through_solib_catchpoints
= NULL
;
1327 ecs
->enable_hw_watchpoints_after_wait
= 0;
1328 ecs
->stepping_through_sigtramp
= 0;
1329 ecs
->sal
= find_pc_line (prev_pc
, 0);
1330 ecs
->current_line
= ecs
->sal
.line
;
1331 ecs
->current_symtab
= ecs
->sal
.symtab
;
1332 ecs
->infwait_state
= infwait_normal_state
;
1333 ecs
->waiton_ptid
= pid_to_ptid (-1);
1334 ecs
->wp
= &(ecs
->ws
);
1337 /* Call this function before setting step_resume_breakpoint, as a
1338 sanity check. There should never be more than one step-resume
1339 breakpoint per thread, so we should never be setting a new
1340 step_resume_breakpoint when one is already active. */
1342 check_for_old_step_resume_breakpoint (void)
1344 if (step_resume_breakpoint
)
1346 ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1349 /* Return the cached copy of the last pid/waitstatus returned by
1350 target_wait()/target_wait_hook(). The data is actually cached by
1351 handle_inferior_event(), which gets called immediately after
1352 target_wait()/target_wait_hook(). */
1355 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
1357 *ptidp
= target_last_wait_ptid
;
1358 *status
= target_last_waitstatus
;
1361 /* Switch thread contexts, maintaining "infrun state". */
1364 context_switch (struct execution_control_state
*ecs
)
1366 /* Caution: it may happen that the new thread (or the old one!)
1367 is not in the thread list. In this case we must not attempt
1368 to "switch context", or we run the risk that our context may
1369 be lost. This may happen as a result of the target module
1370 mishandling thread creation. */
1372 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1373 { /* Perform infrun state context switch: */
1374 /* Save infrun state for the old thread. */
1375 save_infrun_state (inferior_ptid
, prev_pc
,
1376 prev_func_start
, prev_func_name
,
1377 trap_expected
, step_resume_breakpoint
,
1378 through_sigtramp_breakpoint
, step_range_start
,
1379 step_range_end
, step_frame_address
,
1380 ecs
->handling_longjmp
, ecs
->another_trap
,
1381 ecs
->stepping_through_solib_after_catch
,
1382 ecs
->stepping_through_solib_catchpoints
,
1383 ecs
->stepping_through_sigtramp
,
1384 ecs
->current_line
, ecs
->current_symtab
, step_sp
);
1386 /* Load infrun state for the new thread. */
1387 load_infrun_state (ecs
->ptid
, &prev_pc
,
1388 &prev_func_start
, &prev_func_name
,
1389 &trap_expected
, &step_resume_breakpoint
,
1390 &through_sigtramp_breakpoint
, &step_range_start
,
1391 &step_range_end
, &step_frame_address
,
1392 &ecs
->handling_longjmp
, &ecs
->another_trap
,
1393 &ecs
->stepping_through_solib_after_catch
,
1394 &ecs
->stepping_through_solib_catchpoints
,
1395 &ecs
->stepping_through_sigtramp
,
1396 &ecs
->current_line
, &ecs
->current_symtab
, &step_sp
);
1398 inferior_ptid
= ecs
->ptid
;
1402 /* Given an execution control state that has been freshly filled in
1403 by an event from the inferior, figure out what it means and take
1404 appropriate action. */
1407 handle_inferior_event (struct execution_control_state
*ecs
)
1410 int stepped_after_stopped_by_watchpoint
;
1411 int sw_single_step_trap_p
= 0;
1413 /* Cache the last pid/waitstatus. */
1414 target_last_wait_ptid
= ecs
->ptid
;
1415 target_last_waitstatus
= *ecs
->wp
;
1417 switch (ecs
->infwait_state
)
1419 case infwait_thread_hop_state
:
1420 /* Cancel the waiton_ptid. */
1421 ecs
->waiton_ptid
= pid_to_ptid (-1);
1422 /* Fall thru to the normal_state case. */
1424 case infwait_normal_state
:
1425 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1426 is serviced in this loop, below. */
1427 if (ecs
->enable_hw_watchpoints_after_wait
)
1429 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1430 ecs
->enable_hw_watchpoints_after_wait
= 0;
1432 stepped_after_stopped_by_watchpoint
= 0;
1435 case infwait_nullified_state
:
1438 case infwait_nonstep_watch_state
:
1439 insert_breakpoints ();
1441 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1442 handle things like signals arriving and other things happening
1443 in combination correctly? */
1444 stepped_after_stopped_by_watchpoint
= 1;
1447 ecs
->infwait_state
= infwait_normal_state
;
1449 flush_cached_frames ();
1451 /* If it's a new process, add it to the thread database */
1453 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
1454 && !in_thread_list (ecs
->ptid
));
1456 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1457 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
1459 add_thread (ecs
->ptid
);
1461 ui_out_text (uiout
, "[New ");
1462 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->ptid
));
1463 ui_out_text (uiout
, "]\n");
1466 /* NOTE: This block is ONLY meant to be invoked in case of a
1467 "thread creation event"! If it is invoked for any other
1468 sort of event (such as a new thread landing on a breakpoint),
1469 the event will be discarded, which is almost certainly
1472 To avoid this, the low-level module (eg. target_wait)
1473 should call in_thread_list and add_thread, so that the
1474 new thread is known by the time we get here. */
1476 /* We may want to consider not doing a resume here in order
1477 to give the user a chance to play with the new thread.
1478 It might be good to make that a user-settable option. */
1480 /* At this point, all threads are stopped (happens
1481 automatically in either the OS or the native code).
1482 Therefore we need to continue all threads in order to
1485 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1486 prepare_to_wait (ecs
);
1491 switch (ecs
->ws
.kind
)
1493 case TARGET_WAITKIND_LOADED
:
1494 /* Ignore gracefully during startup of the inferior, as it
1495 might be the shell which has just loaded some objects,
1496 otherwise add the symbols for the newly loaded objects. */
1498 if (!stop_soon_quietly
)
1500 /* Remove breakpoints, SOLIB_ADD might adjust
1501 breakpoint addresses via breakpoint_re_set. */
1502 if (breakpoints_inserted
)
1503 remove_breakpoints ();
1505 /* Check for any newly added shared libraries if we're
1506 supposed to be adding them automatically. Switch
1507 terminal for any messages produced by
1508 breakpoint_re_set. */
1509 target_terminal_ours_for_output ();
1510 SOLIB_ADD (NULL
, 0, NULL
, auto_solib_add
);
1511 target_terminal_inferior ();
1513 /* Reinsert breakpoints and continue. */
1514 if (breakpoints_inserted
)
1515 insert_breakpoints ();
1518 resume (0, TARGET_SIGNAL_0
);
1519 prepare_to_wait (ecs
);
1522 case TARGET_WAITKIND_SPURIOUS
:
1523 resume (0, TARGET_SIGNAL_0
);
1524 prepare_to_wait (ecs
);
1527 case TARGET_WAITKIND_EXITED
:
1528 target_terminal_ours (); /* Must do this before mourn anyway */
1529 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1531 /* Record the exit code in the convenience variable $_exitcode, so
1532 that the user can inspect this again later. */
1533 set_internalvar (lookup_internalvar ("_exitcode"),
1534 value_from_longest (builtin_type_int
,
1535 (LONGEST
) ecs
->ws
.value
.integer
));
1536 gdb_flush (gdb_stdout
);
1537 target_mourn_inferior ();
1538 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1539 stop_print_frame
= 0;
1540 stop_stepping (ecs
);
1543 case TARGET_WAITKIND_SIGNALLED
:
1544 stop_print_frame
= 0;
1545 stop_signal
= ecs
->ws
.value
.sig
;
1546 target_terminal_ours (); /* Must do this before mourn anyway */
1548 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1549 reach here unless the inferior is dead. However, for years
1550 target_kill() was called here, which hints that fatal signals aren't
1551 really fatal on some systems. If that's true, then some changes
1553 target_mourn_inferior ();
1555 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1556 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1557 stop_stepping (ecs
);
1560 /* The following are the only cases in which we keep going;
1561 the above cases end in a continue or goto. */
1562 case TARGET_WAITKIND_FORKED
:
1563 stop_signal
= TARGET_SIGNAL_TRAP
;
1564 pending_follow
.kind
= ecs
->ws
.kind
;
1566 /* Ignore fork events reported for the parent; we're only
1567 interested in reacting to forks of the child. Note that
1568 we expect the child's fork event to be available if we
1569 waited for it now. */
1570 if (ptid_equal (inferior_ptid
, ecs
->ptid
))
1572 pending_follow
.fork_event
.saw_parent_fork
= 1;
1573 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1574 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1575 prepare_to_wait (ecs
);
1580 pending_follow
.fork_event
.saw_child_fork
= 1;
1581 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1582 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1585 stop_pc
= read_pc_pid (ecs
->ptid
);
1586 ecs
->saved_inferior_ptid
= inferior_ptid
;
1587 inferior_ptid
= ecs
->ptid
;
1588 /* The second argument of bpstat_stop_status is meant to help
1589 distinguish between a breakpoint trap and a singlestep trap.
1590 This is only important on targets where DECR_PC_AFTER_BREAK
1591 is non-zero. The prev_pc test is meant to distinguish between
1592 singlestepping a trap instruction, and singlestepping thru a
1593 jump to the instruction following a trap instruction. */
1595 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1596 currently_stepping (ecs
) &&
1598 stop_pc
- DECR_PC_AFTER_BREAK
);
1599 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1600 inferior_ptid
= ecs
->saved_inferior_ptid
;
1601 goto process_event_stop_test
;
1603 /* If this a platform which doesn't allow a debugger to touch a
1604 vfork'd inferior until after it exec's, then we'd best keep
1605 our fingers entirely off the inferior, other than continuing
1606 it. This has the unfortunate side-effect that catchpoints
1607 of vforks will be ignored. But since the platform doesn't
1608 allow the inferior be touched at vfork time, there's really
1610 case TARGET_WAITKIND_VFORKED
:
1611 stop_signal
= TARGET_SIGNAL_TRAP
;
1612 pending_follow
.kind
= ecs
->ws
.kind
;
1614 /* Is this a vfork of the parent? If so, then give any
1615 vfork catchpoints a chance to trigger now. (It's
1616 dangerous to do so if the child canot be touched until
1617 it execs, and the child has not yet exec'd. We probably
1618 should warn the user to that effect when the catchpoint
1620 if (ptid_equal (ecs
->ptid
, inferior_ptid
))
1622 pending_follow
.fork_event
.saw_parent_fork
= 1;
1623 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1624 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1627 /* If we've seen the child's vfork event but cannot really touch
1628 the child until it execs, then we must continue the child now.
1629 Else, give any vfork catchpoints a chance to trigger now. */
1632 pending_follow
.fork_event
.saw_child_fork
= 1;
1633 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1634 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1635 target_post_startup_inferior (pid_to_ptid
1636 (pending_follow
.fork_event
.
1638 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1639 if (follow_vfork_when_exec
)
1641 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1642 prepare_to_wait (ecs
);
1647 stop_pc
= read_pc ();
1648 /* The second argument of bpstat_stop_status is meant to help
1649 distinguish between a breakpoint trap and a singlestep trap.
1650 This is only important on targets where DECR_PC_AFTER_BREAK
1651 is non-zero. The prev_pc test is meant to distinguish between
1652 singlestepping a trap instruction, and singlestepping thru a
1653 jump to the instruction following a trap instruction. */
1655 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1656 currently_stepping (ecs
) &&
1658 stop_pc
- DECR_PC_AFTER_BREAK
);
1659 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1660 goto process_event_stop_test
;
1662 case TARGET_WAITKIND_EXECD
:
1663 stop_signal
= TARGET_SIGNAL_TRAP
;
1665 /* Is this a target which reports multiple exec events per actual
1666 call to exec()? (HP-UX using ptrace does, for example.) If so,
1667 ignore all but the last one. Just resume the exec'r, and wait
1668 for the next exec event. */
1669 if (inferior_ignoring_leading_exec_events
)
1671 inferior_ignoring_leading_exec_events
--;
1672 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1673 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.
1675 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1676 prepare_to_wait (ecs
);
1679 inferior_ignoring_leading_exec_events
=
1680 target_reported_exec_events_per_exec_call () - 1;
1682 pending_follow
.execd_pathname
=
1683 savestring (ecs
->ws
.value
.execd_pathname
,
1684 strlen (ecs
->ws
.value
.execd_pathname
));
1686 /* Did inferior_ptid exec, or did a (possibly not-yet-followed)
1687 child of a vfork exec?
1689 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1690 HP-UX, events associated with a vforking inferior come in
1691 threes: a vfork event for the child (always first), followed
1692 a vfork event for the parent and an exec event for the child.
1693 The latter two can come in either order.
1695 If we get the parent vfork event first, life's good: We follow
1696 either the parent or child, and then the child's exec event is
1699 But if we get the child's exec event first, then we delay
1700 responding to it until we handle the parent's vfork. Because,
1701 otherwise we can't satisfy a "catch vfork". */
1702 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1704 pending_follow
.fork_event
.saw_child_exec
= 1;
1706 /* On some targets, the child must be resumed before
1707 the parent vfork event is delivered. A single-step
1709 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1710 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1711 /* We expect the parent vfork event to be available now. */
1712 prepare_to_wait (ecs
);
1716 /* This causes the eventpoints and symbol table to be reset. Must
1717 do this now, before trying to determine whether to stop. */
1718 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1719 xfree (pending_follow
.execd_pathname
);
1721 stop_pc
= read_pc_pid (ecs
->ptid
);
1722 ecs
->saved_inferior_ptid
= inferior_ptid
;
1723 inferior_ptid
= ecs
->ptid
;
1724 /* The second argument of bpstat_stop_status is meant to help
1725 distinguish between a breakpoint trap and a singlestep trap.
1726 This is only important on targets where DECR_PC_AFTER_BREAK
1727 is non-zero. The prev_pc test is meant to distinguish between
1728 singlestepping a trap instruction, and singlestepping thru a
1729 jump to the instruction following a trap instruction. */
1731 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1732 currently_stepping (ecs
) &&
1734 stop_pc
- DECR_PC_AFTER_BREAK
);
1735 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1736 inferior_ptid
= ecs
->saved_inferior_ptid
;
1737 goto process_event_stop_test
;
1739 /* These syscall events are returned on HP-UX, as part of its
1740 implementation of page-protection-based "hardware" watchpoints.
1741 HP-UX has unfortunate interactions between page-protections and
1742 some system calls. Our solution is to disable hardware watches
1743 when a system call is entered, and reenable them when the syscall
1744 completes. The downside of this is that we may miss the precise
1745 point at which a watched piece of memory is modified. "Oh well."
1747 Note that we may have multiple threads running, which may each
1748 enter syscalls at roughly the same time. Since we don't have a
1749 good notion currently of whether a watched piece of memory is
1750 thread-private, we'd best not have any page-protections active
1751 when any thread is in a syscall. Thus, we only want to reenable
1752 hardware watches when no threads are in a syscall.
1754 Also, be careful not to try to gather much state about a thread
1755 that's in a syscall. It's frequently a losing proposition. */
1756 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1757 number_of_threads_in_syscalls
++;
1758 if (number_of_threads_in_syscalls
== 1)
1760 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1762 resume (0, TARGET_SIGNAL_0
);
1763 prepare_to_wait (ecs
);
1766 /* Before examining the threads further, step this thread to
1767 get it entirely out of the syscall. (We get notice of the
1768 event when the thread is just on the verge of exiting a
1769 syscall. Stepping one instruction seems to get it back
1772 Note that although the logical place to reenable h/w watches
1773 is here, we cannot. We cannot reenable them before stepping
1774 the thread (this causes the next wait on the thread to hang).
1776 Nor can we enable them after stepping until we've done a wait.
1777 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1778 here, which will be serviced immediately after the target
1780 case TARGET_WAITKIND_SYSCALL_RETURN
:
1781 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1783 if (number_of_threads_in_syscalls
> 0)
1785 number_of_threads_in_syscalls
--;
1786 ecs
->enable_hw_watchpoints_after_wait
=
1787 (number_of_threads_in_syscalls
== 0);
1789 prepare_to_wait (ecs
);
1792 case TARGET_WAITKIND_STOPPED
:
1793 stop_signal
= ecs
->ws
.value
.sig
;
1796 /* We had an event in the inferior, but we are not interested
1797 in handling it at this level. The lower layers have already
1798 done what needs to be done, if anything. This case can
1799 occur only when the target is async or extended-async. One
1800 of the circumstamces for this to happen is when the
1801 inferior produces output for the console. The inferior has
1802 not stopped, and we are ignoring the event. */
1803 case TARGET_WAITKIND_IGNORE
:
1804 ecs
->wait_some_more
= 1;
1808 /* We may want to consider not doing a resume here in order to give
1809 the user a chance to play with the new thread. It might be good
1810 to make that a user-settable option. */
1812 /* At this point, all threads are stopped (happens automatically in
1813 either the OS or the native code). Therefore we need to continue
1814 all threads in order to make progress. */
1815 if (ecs
->new_thread_event
)
1817 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1818 prepare_to_wait (ecs
);
1822 stop_pc
= read_pc_pid (ecs
->ptid
);
1824 /* See if a thread hit a thread-specific breakpoint that was meant for
1825 another thread. If so, then step that thread past the breakpoint,
1828 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1830 /* Check if a regular breakpoint has been hit before checking
1831 for a potential single step breakpoint. Otherwise, GDB will
1832 not see this breakpoint hit when stepping onto breakpoints. */
1833 if (breakpoints_inserted
1834 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1836 ecs
->random_signal
= 0;
1837 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1842 /* Saw a breakpoint, but it was hit by the wrong thread.
1844 if (DECR_PC_AFTER_BREAK
)
1845 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->ptid
);
1847 remove_status
= remove_breakpoints ();
1848 /* Did we fail to remove breakpoints? If so, try
1849 to set the PC past the bp. (There's at least
1850 one situation in which we can fail to remove
1851 the bp's: On HP-UX's that use ttrace, we can't
1852 change the address space of a vforking child
1853 process until the child exits (well, okay, not
1854 then either :-) or execs. */
1855 if (remove_status
!= 0)
1857 /* FIXME! This is obviously non-portable! */
1858 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->ptid
);
1859 /* We need to restart all the threads now,
1860 * unles we're running in scheduler-locked mode.
1861 * Use currently_stepping to determine whether to
1864 /* FIXME MVS: is there any reason not to call resume()? */
1865 if (scheduler_mode
== schedlock_on
)
1866 target_resume (ecs
->ptid
,
1867 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1869 target_resume (RESUME_ALL
,
1870 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1871 prepare_to_wait (ecs
);
1876 breakpoints_inserted
= 0;
1877 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
1878 context_switch (ecs
);
1879 ecs
->waiton_ptid
= ecs
->ptid
;
1880 ecs
->wp
= &(ecs
->ws
);
1881 ecs
->another_trap
= 1;
1883 ecs
->infwait_state
= infwait_thread_hop_state
;
1885 registers_changed ();
1890 else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1892 /* Readjust the stop_pc as it is off by DECR_PC_AFTER_BREAK
1893 compared to the value it would have if the system stepping
1894 capability was used. This allows the rest of the code in
1895 this function to use this address without having to worry
1896 whether software single step is in use or not. */
1897 if (DECR_PC_AFTER_BREAK
)
1899 stop_pc
-= DECR_PC_AFTER_BREAK
;
1900 write_pc_pid (stop_pc
, ecs
->ptid
);
1903 sw_single_step_trap_p
= 1;
1904 ecs
->random_signal
= 0;
1908 ecs
->random_signal
= 1;
1910 /* See if something interesting happened to the non-current thread. If
1911 so, then switch to that thread, and eventually give control back to
1914 Note that if there's any kind of pending follow (i.e., of a fork,
1915 vfork or exec), we don't want to do this now. Rather, we'll let
1916 the next resume handle it. */
1917 if (!ptid_equal (ecs
->ptid
, inferior_ptid
) &&
1918 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1922 /* If it's a random signal for a non-current thread, notify user
1923 if he's expressed an interest. */
1924 if (ecs
->random_signal
&& signal_print
[stop_signal
])
1926 /* ??rehrauer: I don't understand the rationale for this code. If the
1927 inferior will stop as a result of this signal, then the act of handling
1928 the stop ought to print a message that's couches the stoppage in user
1929 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1930 won't stop as a result of the signal -- i.e., if the signal is merely
1931 a side-effect of something GDB's doing "under the covers" for the
1932 user, such as stepping threads over a breakpoint they shouldn't stop
1933 for -- then the message seems to be a serious annoyance at best.
1935 For now, remove the message altogether. */
1938 target_terminal_ours_for_output ();
1939 printf_filtered ("\nProgram received signal %s, %s.\n",
1940 target_signal_to_name (stop_signal
),
1941 target_signal_to_string (stop_signal
));
1942 gdb_flush (gdb_stdout
);
1946 /* If it's not SIGTRAP and not a signal we want to stop for, then
1947 continue the thread. */
1949 if (stop_signal
!= TARGET_SIGNAL_TRAP
&& !signal_stop
[stop_signal
])
1952 target_terminal_inferior ();
1954 /* Clear the signal if it should not be passed. */
1955 if (signal_program
[stop_signal
] == 0)
1956 stop_signal
= TARGET_SIGNAL_0
;
1958 target_resume (ecs
->ptid
, 0, stop_signal
);
1959 prepare_to_wait (ecs
);
1963 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1964 and fall into the rest of wait_for_inferior(). */
1966 context_switch (ecs
);
1969 context_hook (pid_to_thread_id (ecs
->ptid
));
1971 flush_cached_frames ();
1974 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1976 /* Pull the single step breakpoints out of the target. */
1977 SOFTWARE_SINGLE_STEP (0, 0);
1978 singlestep_breakpoints_inserted_p
= 0;
1981 /* If PC is pointing at a nullified instruction, then step beyond
1982 it so that the user won't be confused when GDB appears to be ready
1985 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1986 if (INSTRUCTION_NULLIFIED
)
1988 registers_changed ();
1989 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1991 /* We may have received a signal that we want to pass to
1992 the inferior; therefore, we must not clobber the waitstatus
1995 ecs
->infwait_state
= infwait_nullified_state
;
1996 ecs
->waiton_ptid
= ecs
->ptid
;
1997 ecs
->wp
= &(ecs
->tmpstatus
);
1998 prepare_to_wait (ecs
);
2002 /* It may not be necessary to disable the watchpoint to stop over
2003 it. For example, the PA can (with some kernel cooperation)
2004 single step over a watchpoint without disabling the watchpoint. */
2005 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2008 prepare_to_wait (ecs
);
2012 /* It is far more common to need to disable a watchpoint to step
2013 the inferior over it. FIXME. What else might a debug
2014 register or page protection watchpoint scheme need here? */
2015 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2017 /* At this point, we are stopped at an instruction which has
2018 attempted to write to a piece of memory under control of
2019 a watchpoint. The instruction hasn't actually executed
2020 yet. If we were to evaluate the watchpoint expression
2021 now, we would get the old value, and therefore no change
2022 would seem to have occurred.
2024 In order to make watchpoints work `right', we really need
2025 to complete the memory write, and then evaluate the
2026 watchpoint expression. The following code does that by
2027 removing the watchpoint (actually, all watchpoints and
2028 breakpoints), single-stepping the target, re-inserting
2029 watchpoints, and then falling through to let normal
2030 single-step processing handle proceed. Since this
2031 includes evaluating watchpoints, things will come to a
2032 stop in the correct manner. */
2034 if (DECR_PC_AFTER_BREAK
)
2035 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
2037 remove_breakpoints ();
2038 registers_changed ();
2039 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
2041 ecs
->waiton_ptid
= ecs
->ptid
;
2042 ecs
->wp
= &(ecs
->ws
);
2043 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2044 prepare_to_wait (ecs
);
2048 /* It may be possible to simply continue after a watchpoint. */
2049 if (HAVE_CONTINUABLE_WATCHPOINT
)
2050 STOPPED_BY_WATCHPOINT (ecs
->ws
);
2052 ecs
->stop_func_start
= 0;
2053 ecs
->stop_func_end
= 0;
2054 ecs
->stop_func_name
= 0;
2055 /* Don't care about return value; stop_func_start and stop_func_name
2056 will both be 0 if it doesn't work. */
2057 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2058 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2059 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
2060 ecs
->another_trap
= 0;
2061 bpstat_clear (&stop_bpstat
);
2063 stop_stack_dummy
= 0;
2064 stop_print_frame
= 1;
2065 ecs
->random_signal
= 0;
2066 stopped_by_random_signal
= 0;
2067 breakpoints_failed
= 0;
2069 /* Look at the cause of the stop, and decide what to do.
2070 The alternatives are:
2071 1) break; to really stop and return to the debugger,
2072 2) drop through to start up again
2073 (set ecs->another_trap to 1 to single step once)
2074 3) set ecs->random_signal to 1, and the decision between 1 and 2
2075 will be made according to the signal handling tables. */
2077 /* First, distinguish signals caused by the debugger from signals
2078 that have to do with the program's own actions.
2079 Note that breakpoint insns may cause SIGTRAP or SIGILL
2080 or SIGEMT, depending on the operating system version.
2081 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2082 and change it to SIGTRAP. */
2084 if (stop_signal
== TARGET_SIGNAL_TRAP
2085 || (breakpoints_inserted
&&
2086 (stop_signal
== TARGET_SIGNAL_ILL
2087 || stop_signal
== TARGET_SIGNAL_EMT
)) || stop_soon_quietly
)
2089 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2091 stop_print_frame
= 0;
2092 stop_stepping (ecs
);
2095 if (stop_soon_quietly
)
2097 stop_stepping (ecs
);
2101 /* Don't even think about breakpoints
2102 if just proceeded over a breakpoint.
2104 However, if we are trying to proceed over a breakpoint
2105 and end up in sigtramp, then through_sigtramp_breakpoint
2106 will be set and we should check whether we've hit the
2108 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2109 && through_sigtramp_breakpoint
== NULL
)
2110 bpstat_clear (&stop_bpstat
);
2113 /* See if there is a breakpoint at the current PC. */
2115 /* The second argument of bpstat_stop_status is meant to help
2116 distinguish between a breakpoint trap and a singlestep trap.
2117 This is only important on targets where DECR_PC_AFTER_BREAK
2118 is non-zero. The prev_pc test is meant to distinguish between
2119 singlestepping a trap instruction, and singlestepping thru a
2120 jump to the instruction following a trap instruction. */
2125 /* Pass TRUE if our reason for stopping is something other
2126 than hitting a breakpoint. We do this by checking that
2127 either we detected earlier a software single step trap or
2128 1) stepping is going on and 2) we didn't hit a breakpoint
2129 in a signal handler without an intervening stop in
2130 sigtramp, which is detected by a new stack pointer value
2131 below any usual function calling stack adjustments. */
2132 sw_single_step_trap_p
2133 || (currently_stepping (ecs
)
2134 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
2136 && INNER_THAN (read_sp (), (step_sp
- 16)))));
2137 /* Following in case break condition called a
2139 stop_print_frame
= 1;
2142 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2144 = !(bpstat_explains_signal (stop_bpstat
)
2146 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2147 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2148 FRAME_FP (get_current_frame ())))
2149 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2153 ecs
->random_signal
= !(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 (),
2162 if (!ecs
->random_signal
)
2163 stop_signal
= TARGET_SIGNAL_TRAP
;
2167 /* When we reach this point, we've pretty much decided
2168 that the reason for stopping must've been a random
2169 (unexpected) signal. */
2172 ecs
->random_signal
= 1;
2173 /* If a fork, vfork or exec event was seen, then there are two
2174 possible responses we can make:
2176 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2177 then we must stop now and issue a prompt. We will resume
2178 the inferior when the user tells us to.
2179 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2180 then we must resume the inferior now and keep checking.
2182 In either case, we must take appropriate steps to "follow" the
2183 the fork/vfork/exec when the inferior is resumed. For example,
2184 if follow-fork-mode is "child", then we must detach from the
2185 parent inferior and follow the new child inferior.
2187 In either case, setting pending_follow causes the next resume()
2188 to take the appropriate following action. */
2189 process_event_stop_test
:
2190 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2192 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2195 stop_signal
= TARGET_SIGNAL_0
;
2200 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2202 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2204 stop_signal
= TARGET_SIGNAL_0
;
2209 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2211 pending_follow
.kind
= ecs
->ws
.kind
;
2212 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2215 stop_signal
= TARGET_SIGNAL_0
;
2221 /* For the program's own signals, act according to
2222 the signal handling tables. */
2224 if (ecs
->random_signal
)
2226 /* Signal not for debugging purposes. */
2229 stopped_by_random_signal
= 1;
2231 if (signal_print
[stop_signal
])
2234 target_terminal_ours_for_output ();
2235 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2237 if (signal_stop
[stop_signal
])
2239 stop_stepping (ecs
);
2242 /* If not going to stop, give terminal back
2243 if we took it away. */
2245 target_terminal_inferior ();
2247 /* Clear the signal if it should not be passed. */
2248 if (signal_program
[stop_signal
] == 0)
2249 stop_signal
= TARGET_SIGNAL_0
;
2251 /* I'm not sure whether this needs to be check_sigtramp2 or
2252 whether it could/should be keep_going.
2254 This used to jump to step_over_function if we are stepping,
2257 Suppose the user does a `next' over a function call, and while
2258 that call is in progress, the inferior receives a signal for
2259 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2260 that case, when we reach this point, there is already a
2261 step-resume breakpoint established, right where it should be:
2262 immediately after the function call the user is "next"-ing
2263 over. If we call step_over_function now, two bad things
2266 - we'll create a new breakpoint, at wherever the current
2267 frame's return address happens to be. That could be
2268 anywhere, depending on what function call happens to be on
2269 the top of the stack at that point. Point is, it's probably
2270 not where we need it.
2272 - the existing step-resume breakpoint (which is at the correct
2273 address) will get orphaned: step_resume_breakpoint will point
2274 to the new breakpoint, and the old step-resume breakpoint
2275 will never be cleaned up.
2277 The old behavior was meant to help HP-UX single-step out of
2278 sigtramps. It would place the new breakpoint at prev_pc, which
2279 was certainly wrong. I don't know the details there, so fixing
2280 this probably breaks that. As with anything else, it's up to
2281 the HP-UX maintainer to furnish a fix that doesn't break other
2282 platforms. --JimB, 20 May 1999 */
2283 check_sigtramp2 (ecs
);
2288 /* Handle cases caused by hitting a breakpoint. */
2290 CORE_ADDR jmp_buf_pc
;
2291 struct bpstat_what what
;
2293 what
= bpstat_what (stop_bpstat
);
2295 if (what
.call_dummy
)
2297 stop_stack_dummy
= 1;
2299 trap_expected_after_continue
= 1;
2303 switch (what
.main_action
)
2305 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2306 /* If we hit the breakpoint at longjmp, disable it for the
2307 duration of this command. Then, install a temporary
2308 breakpoint at the target of the jmp_buf. */
2309 disable_longjmp_breakpoint ();
2310 remove_breakpoints ();
2311 breakpoints_inserted
= 0;
2312 if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc
))
2318 /* Need to blow away step-resume breakpoint, as it
2319 interferes with us */
2320 if (step_resume_breakpoint
!= NULL
)
2322 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2324 /* Not sure whether we need to blow this away too, but probably
2325 it is like the step-resume breakpoint. */
2326 if (through_sigtramp_breakpoint
!= NULL
)
2328 delete_breakpoint (through_sigtramp_breakpoint
);
2329 through_sigtramp_breakpoint
= NULL
;
2333 /* FIXME - Need to implement nested temporary breakpoints */
2334 if (step_over_calls
> 0)
2335 set_longjmp_resume_breakpoint (jmp_buf_pc
, 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
==
2476 BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2478 /* ??rehrauer: If I could figure out how to get the
2479 right return PC from here, we could just set a temp
2480 breakpoint and resume. I'm not sure we can without
2481 cracking open the dld's shared libraries and sniffing
2482 their unwind tables and text/data ranges, and that's
2483 not a terribly portable notion.
2485 Until that time, we must step the inferior out of the
2486 dld callback, and also out of the dld itself (and any
2487 code or stubs in libdld.sl, such as "shl_load" and
2488 friends) until we reach non-dld code. At that point,
2489 we can stop stepping. */
2490 bpstat_get_triggered_catchpoints (stop_bpstat
,
2492 stepping_through_solib_catchpoints
);
2493 ecs
->stepping_through_solib_after_catch
= 1;
2495 /* Be sure to lift all breakpoints, so the inferior does
2496 actually step past this point... */
2497 ecs
->another_trap
= 1;
2502 /* We want to step over this breakpoint, then keep going. */
2503 ecs
->another_trap
= 1;
2510 case BPSTAT_WHAT_LAST
:
2511 /* Not a real code, but listed here to shut up gcc -Wall. */
2513 case BPSTAT_WHAT_KEEP_CHECKING
:
2518 /* We come here if we hit a breakpoint but should not
2519 stop for it. Possibly we also were stepping
2520 and should stop for that. So fall through and
2521 test for stepping. But, if not stepping,
2524 /* Are we stepping to get the inferior out of the dynamic
2525 linker's hook (and possibly the dld itself) after catching
2527 if (ecs
->stepping_through_solib_after_catch
)
2529 #if defined(SOLIB_ADD)
2530 /* Have we reached our destination? If not, keep going. */
2531 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2533 ecs
->another_trap
= 1;
2538 /* Else, stop and report the catchpoint(s) whose triggering
2539 caused us to begin stepping. */
2540 ecs
->stepping_through_solib_after_catch
= 0;
2541 bpstat_clear (&stop_bpstat
);
2542 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2543 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2544 stop_print_frame
= 1;
2545 stop_stepping (ecs
);
2549 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2551 /* This is the old way of detecting the end of the stack dummy.
2552 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2553 handled above. As soon as we can test it on all of them, all
2554 architectures should define it. */
2556 /* If this is the breakpoint at the end of a stack dummy,
2557 just stop silently, unless the user was doing an si/ni, in which
2558 case she'd better know what she's doing. */
2560 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2561 FRAME_FP (get_current_frame ()))
2564 stop_print_frame
= 0;
2565 stop_stack_dummy
= 1;
2567 trap_expected_after_continue
= 1;
2569 stop_stepping (ecs
);
2574 if (step_resume_breakpoint
)
2576 /* Having a step-resume breakpoint overrides anything
2577 else having to do with stepping commands until
2578 that breakpoint is reached. */
2579 /* I'm not sure whether this needs to be check_sigtramp2 or
2580 whether it could/should be keep_going. */
2581 check_sigtramp2 (ecs
);
2586 if (step_range_end
== 0)
2588 /* Likewise if we aren't even stepping. */
2589 /* I'm not sure whether this needs to be check_sigtramp2 or
2590 whether it could/should be keep_going. */
2591 check_sigtramp2 (ecs
);
2596 /* If stepping through a line, keep going if still within it.
2598 Note that step_range_end is the address of the first instruction
2599 beyond the step range, and NOT the address of the last instruction
2601 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
2603 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2604 So definately need to check for sigtramp here. */
2605 check_sigtramp2 (ecs
);
2610 /* We stepped out of the stepping range. */
2612 /* If we are stepping at the source level and entered the runtime
2613 loader dynamic symbol resolution code, we keep on single stepping
2614 until we exit the run time loader code and reach the callee's
2616 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2617 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2619 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2621 if (pc_after_resolver
)
2623 /* Set up a step-resume breakpoint at the address
2624 indicated by SKIP_SOLIB_RESOLVER. */
2625 struct symtab_and_line sr_sal
;
2627 sr_sal
.pc
= pc_after_resolver
;
2629 check_for_old_step_resume_breakpoint ();
2630 step_resume_breakpoint
=
2631 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2632 if (breakpoints_inserted
)
2633 insert_breakpoints ();
2640 /* We can't update step_sp every time through the loop, because
2641 reading the stack pointer would slow down stepping too much.
2642 But we can update it every time we leave the step range. */
2643 ecs
->update_step_sp
= 1;
2645 /* Did we just take a signal? */
2646 if (PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2647 && !PC_IN_SIGTRAMP (prev_pc
, prev_func_name
)
2648 && INNER_THAN (read_sp (), step_sp
))
2650 /* We've just taken a signal; go until we are back to
2651 the point where we took it and one more. */
2653 /* Note: The test above succeeds not only when we stepped
2654 into a signal handler, but also when we step past the last
2655 statement of a signal handler and end up in the return stub
2656 of the signal handler trampoline. To distinguish between
2657 these two cases, check that the frame is INNER_THAN the
2658 previous one below. pai/1997-09-11 */
2662 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2664 if (INNER_THAN (current_frame
, step_frame_address
))
2666 /* We have just taken a signal; go until we are back to
2667 the point where we took it and one more. */
2669 /* This code is needed at least in the following case:
2670 The user types "next" and then a signal arrives (before
2671 the "next" is done). */
2673 /* Note that if we are stopped at a breakpoint, then we need
2674 the step_resume breakpoint to override any breakpoints at
2675 the same location, so that we will still step over the
2676 breakpoint even though the signal happened. */
2677 struct symtab_and_line sr_sal
;
2680 sr_sal
.symtab
= NULL
;
2682 sr_sal
.pc
= prev_pc
;
2683 /* We could probably be setting the frame to
2684 step_frame_address; I don't think anyone thought to
2686 check_for_old_step_resume_breakpoint ();
2687 step_resume_breakpoint
=
2688 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2689 if (breakpoints_inserted
)
2690 insert_breakpoints ();
2694 /* We just stepped out of a signal handler and into
2695 its calling trampoline.
2697 Normally, we'd call step_over_function from
2698 here, but for some reason GDB can't unwind the
2699 stack correctly to find the real PC for the point
2700 user code where the signal trampoline will return
2701 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2702 But signal trampolines are pretty small stubs of
2703 code, anyway, so it's OK instead to just
2704 single-step out. Note: assuming such trampolines
2705 don't exhibit recursion on any platform... */
2706 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2707 &ecs
->stop_func_start
,
2708 &ecs
->stop_func_end
);
2709 /* Readjust stepping range */
2710 step_range_start
= ecs
->stop_func_start
;
2711 step_range_end
= ecs
->stop_func_end
;
2712 ecs
->stepping_through_sigtramp
= 1;
2717 /* If this is stepi or nexti, make sure that the stepping range
2718 gets us past that instruction. */
2719 if (step_range_end
== 1)
2720 /* FIXME: Does this run afoul of the code below which, if
2721 we step into the middle of a line, resets the stepping
2723 step_range_end
= (step_range_start
= prev_pc
) + 1;
2725 ecs
->remove_breakpoints_on_following_step
= 1;
2730 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2731 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2732 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2733 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2734 || ecs
->stop_func_name
== 0)
2736 /* It's a subroutine call. */
2738 if ((step_over_calls
== STEP_OVER_NONE
)
2739 || ((step_range_end
== 1)
2740 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2742 /* I presume that step_over_calls is only 0 when we're
2743 supposed to be stepping at the assembly language level
2744 ("stepi"). Just stop. */
2745 /* Also, maybe we just did a "nexti" inside a prolog,
2746 so we thought it was a subroutine call but it was not.
2747 Stop as well. FENN */
2749 print_stop_reason (END_STEPPING_RANGE
, 0);
2750 stop_stepping (ecs
);
2754 if (step_over_calls
== STEP_OVER_ALL
|| IGNORE_HELPER_CALL (stop_pc
))
2756 /* We're doing a "next". */
2758 if (PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2759 && INNER_THAN (step_frame_address
, read_sp ()))
2760 /* We stepped out of a signal handler, and into its
2761 calling trampoline. This is misdetected as a
2762 subroutine call, but stepping over the signal
2763 trampoline isn't such a bad idea. In order to do
2764 that, we have to ignore the value in
2765 step_frame_address, since that doesn't represent the
2766 frame that'll reach when we return from the signal
2767 trampoline. Otherwise we'll probably continue to the
2768 end of the program. */
2769 step_frame_address
= 0;
2771 step_over_function (ecs
);
2776 /* If we are in a function call trampoline (a stub between
2777 the calling routine and the real function), locate the real
2778 function. That's what tells us (a) whether we want to step
2779 into it at all, and (b) what prologue we want to run to
2780 the end of, if we do step into it. */
2781 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2783 ecs
->stop_func_start
= tmp
;
2786 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2789 struct symtab_and_line xxx
;
2790 /* Why isn't this s_a_l called "sr_sal", like all of the
2791 other s_a_l's where this code is duplicated? */
2792 INIT_SAL (&xxx
); /* initialize to zeroes */
2794 xxx
.section
= find_pc_overlay (xxx
.pc
);
2795 check_for_old_step_resume_breakpoint ();
2796 step_resume_breakpoint
=
2797 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2798 insert_breakpoints ();
2804 /* If we have line number information for the function we
2805 are thinking of stepping into, step into it.
2807 If there are several symtabs at that PC (e.g. with include
2808 files), just want to know whether *any* of them have line
2809 numbers. find_pc_line handles this. */
2811 struct symtab_and_line tmp_sal
;
2813 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2814 if (tmp_sal
.line
!= 0)
2816 step_into_function (ecs
);
2821 /* If we have no line number and the step-stop-if-no-debug
2822 is set, we stop the step so that the user has a chance to
2823 switch in assembly mode. */
2824 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2827 print_stop_reason (END_STEPPING_RANGE
, 0);
2828 stop_stepping (ecs
);
2832 step_over_function (ecs
);
2838 /* We've wandered out of the step range. */
2840 ecs
->sal
= find_pc_line (stop_pc
, 0);
2842 if (step_range_end
== 1)
2844 /* It is stepi or nexti. We always want to stop stepping after
2847 print_stop_reason (END_STEPPING_RANGE
, 0);
2848 stop_stepping (ecs
);
2852 /* If we're in the return path from a shared library trampoline,
2853 we want to proceed through the trampoline when stepping. */
2854 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2858 /* Determine where this trampoline returns. */
2859 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2861 /* Only proceed through if we know where it's going. */
2864 /* And put the step-breakpoint there and go until there. */
2865 struct symtab_and_line sr_sal
;
2867 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2869 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2870 /* Do not specify what the fp should be when we stop
2871 since on some machines the prologue
2872 is where the new fp value is established. */
2873 check_for_old_step_resume_breakpoint ();
2874 step_resume_breakpoint
=
2875 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2876 if (breakpoints_inserted
)
2877 insert_breakpoints ();
2879 /* Restart without fiddling with the step ranges or
2886 if (ecs
->sal
.line
== 0)
2888 /* We have no line number information. That means to stop
2889 stepping (does this always happen right after one instruction,
2890 when we do "s" in a function with no line numbers,
2891 or can this happen as a result of a return or longjmp?). */
2893 print_stop_reason (END_STEPPING_RANGE
, 0);
2894 stop_stepping (ecs
);
2898 if ((stop_pc
== ecs
->sal
.pc
)
2899 && (ecs
->current_line
!= ecs
->sal
.line
2900 || ecs
->current_symtab
!= ecs
->sal
.symtab
))
2902 /* We are at the start of a different line. So stop. Note that
2903 we don't stop if we step into the middle of a different line.
2904 That is said to make things like for (;;) statements work
2907 print_stop_reason (END_STEPPING_RANGE
, 0);
2908 stop_stepping (ecs
);
2912 /* We aren't done stepping.
2914 Optimize by setting the stepping range to the line.
2915 (We might not be in the original line, but if we entered a
2916 new line in mid-statement, we continue stepping. This makes
2917 things like for(;;) statements work better.) */
2919 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2921 /* If this is the last line of the function, don't keep stepping
2922 (it would probably step us out of the function).
2923 This is particularly necessary for a one-line function,
2924 in which after skipping the prologue we better stop even though
2925 we will be in mid-line. */
2927 print_stop_reason (END_STEPPING_RANGE
, 0);
2928 stop_stepping (ecs
);
2931 step_range_start
= ecs
->sal
.pc
;
2932 step_range_end
= ecs
->sal
.end
;
2933 step_frame_address
= FRAME_FP (get_current_frame ());
2934 ecs
->current_line
= ecs
->sal
.line
;
2935 ecs
->current_symtab
= ecs
->sal
.symtab
;
2937 /* In the case where we just stepped out of a function into the middle
2938 of a line of the caller, continue stepping, but step_frame_address
2939 must be modified to current frame */
2941 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2942 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2943 step_frame_address
= current_frame
;
2949 /* Are we in the middle of stepping? */
2952 currently_stepping (struct execution_control_state
*ecs
)
2954 return ((through_sigtramp_breakpoint
== NULL
2955 && !ecs
->handling_longjmp
2956 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2958 || ecs
->stepping_through_solib_after_catch
2959 || bpstat_should_step ());
2963 check_sigtramp2 (struct execution_control_state
*ecs
)
2966 && PC_IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2967 && !PC_IN_SIGTRAMP (prev_pc
, prev_func_name
)
2968 && INNER_THAN (read_sp (), step_sp
))
2970 /* What has happened here is that we have just stepped the
2971 inferior with a signal (because it is a signal which
2972 shouldn't make us stop), thus stepping into sigtramp.
2974 So we need to set a step_resume_break_address breakpoint and
2975 continue until we hit it, and then step. FIXME: This should
2976 be more enduring than a step_resume breakpoint; we should
2977 know that we will later need to keep going rather than
2978 re-hitting the breakpoint here (see the testsuite,
2979 gdb.base/signals.exp where it says "exceedingly difficult"). */
2981 struct symtab_and_line sr_sal
;
2983 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2984 sr_sal
.pc
= prev_pc
;
2985 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2986 /* We perhaps could set the frame if we kept track of what the
2987 frame corresponding to prev_pc was. But we don't, so don't. */
2988 through_sigtramp_breakpoint
=
2989 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2990 if (breakpoints_inserted
)
2991 insert_breakpoints ();
2993 ecs
->remove_breakpoints_on_following_step
= 1;
2994 ecs
->another_trap
= 1;
2998 /* Subroutine call with source code we should not step over. Do step
2999 to the first line of code in it. */
3002 step_into_function (struct execution_control_state
*ecs
)
3005 struct symtab_and_line sr_sal
;
3007 s
= find_pc_symtab (stop_pc
);
3008 if (s
&& s
->language
!= language_asm
)
3009 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
3011 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
3012 /* Use the step_resume_break to step until the end of the prologue,
3013 even if that involves jumps (as it seems to on the vax under
3015 /* If the prologue ends in the middle of a source line, continue to
3016 the end of that source line (if it is still within the function).
3017 Otherwise, just go to end of prologue. */
3018 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
3019 /* no, don't either. It skips any code that's legitimately on the
3023 && ecs
->sal
.pc
!= ecs
->stop_func_start
3024 && ecs
->sal
.end
< ecs
->stop_func_end
)
3025 ecs
->stop_func_start
= ecs
->sal
.end
;
3028 if (ecs
->stop_func_start
== stop_pc
)
3030 /* We are already there: stop now. */
3032 print_stop_reason (END_STEPPING_RANGE
, 0);
3033 stop_stepping (ecs
);
3038 /* Put the step-breakpoint there and go until there. */
3039 INIT_SAL (&sr_sal
); /* initialize to zeroes */
3040 sr_sal
.pc
= ecs
->stop_func_start
;
3041 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3042 /* Do not specify what the fp should be when we stop since on
3043 some machines the prologue is where the new fp value is
3045 check_for_old_step_resume_breakpoint ();
3046 step_resume_breakpoint
=
3047 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
3048 if (breakpoints_inserted
)
3049 insert_breakpoints ();
3051 /* And make sure stepping stops right away then. */
3052 step_range_end
= step_range_start
;
3057 /* We've just entered a callee, and we wish to resume until it returns
3058 to the caller. Setting a step_resume breakpoint on the return
3059 address will catch a return from the callee.
3061 However, if the callee is recursing, we want to be careful not to
3062 catch returns of those recursive calls, but only of THIS instance
3065 To do this, we set the step_resume bp's frame to our current
3066 caller's frame (step_frame_address, which is set by the "next" or
3067 "until" command, before execution begins). */
3070 step_over_function (struct execution_control_state
*ecs
)
3072 struct symtab_and_line sr_sal
;
3074 INIT_SAL (&sr_sal
); /* initialize to zeros */
3075 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3076 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3078 check_for_old_step_resume_breakpoint ();
3079 step_resume_breakpoint
=
3080 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
3082 if (step_frame_address
&& !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
3083 step_resume_breakpoint
->frame
= step_frame_address
;
3085 if (breakpoints_inserted
)
3086 insert_breakpoints ();
3090 stop_stepping (struct execution_control_state
*ecs
)
3092 if (target_has_execution
)
3094 /* Are we stopping for a vfork event? We only stop when we see
3095 the child's event. However, we may not yet have seen the
3096 parent's event. And, inferior_ptid is still set to the
3097 parent's pid, until we resume again and follow either the
3100 To ensure that we can really touch inferior_ptid (aka, the
3101 parent process) -- which calls to functions like read_pc
3102 implicitly do -- wait on the parent if necessary. */
3103 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3104 && !pending_follow
.fork_event
.saw_parent_fork
)
3110 if (target_wait_hook
)
3111 parent_ptid
= target_wait_hook (pid_to_ptid (-1), &(ecs
->ws
));
3113 parent_ptid
= target_wait (pid_to_ptid (-1), &(ecs
->ws
));
3115 while (!ptid_equal (parent_ptid
, inferior_ptid
));
3118 /* Assuming the inferior still exists, set these up for next
3119 time, just like we did above if we didn't break out of the
3121 prev_pc
= read_pc ();
3122 prev_func_start
= ecs
->stop_func_start
;
3123 prev_func_name
= ecs
->stop_func_name
;
3126 /* Let callers know we don't want to wait for the inferior anymore. */
3127 ecs
->wait_some_more
= 0;
3130 /* This function handles various cases where we need to continue
3131 waiting for the inferior. */
3132 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3135 keep_going (struct execution_control_state
*ecs
)
3137 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3138 vforked child between its creation and subsequent exit or call to
3139 exec(). However, I had big problems in this rather creaky exec
3140 engine, getting that to work. The fundamental problem is that
3141 I'm trying to debug two processes via an engine that only
3142 understands a single process with possibly multiple threads.
3144 Hence, this spot is known to have problems when
3145 target_can_follow_vfork_prior_to_exec returns 1. */
3147 /* Save the pc before execution, to compare with pc after stop. */
3148 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3149 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3150 BREAK is defined, the
3151 original pc would not have
3152 been at the start of a
3154 prev_func_name
= ecs
->stop_func_name
;
3156 if (ecs
->update_step_sp
)
3157 step_sp
= read_sp ();
3158 ecs
->update_step_sp
= 0;
3160 /* If we did not do break;, it means we should keep running the
3161 inferior and not return to debugger. */
3163 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3165 /* We took a signal (which we are supposed to pass through to
3166 the inferior, else we'd have done a break above) and we
3167 haven't yet gotten our trap. Simply continue. */
3168 resume (currently_stepping (ecs
), stop_signal
);
3172 /* Either the trap was not expected, but we are continuing
3173 anyway (the user asked that this signal be passed to the
3176 The signal was SIGTRAP, e.g. it was our signal, but we
3177 decided we should resume from it.
3179 We're going to run this baby now!
3181 Insert breakpoints now, unless we are trying to one-proceed
3182 past a breakpoint. */
3183 /* If we've just finished a special step resume and we don't
3184 want to hit a breakpoint, pull em out. */
3185 if (step_resume_breakpoint
== NULL
3186 && through_sigtramp_breakpoint
== NULL
3187 && ecs
->remove_breakpoints_on_following_step
)
3189 ecs
->remove_breakpoints_on_following_step
= 0;
3190 remove_breakpoints ();
3191 breakpoints_inserted
= 0;
3193 else if (!breakpoints_inserted
&&
3194 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3196 breakpoints_failed
= insert_breakpoints ();
3197 if (breakpoints_failed
)
3199 stop_stepping (ecs
);
3202 breakpoints_inserted
= 1;
3205 trap_expected
= ecs
->another_trap
;
3207 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3208 specifies that such a signal should be delivered to the
3211 Typically, this would occure when a user is debugging a
3212 target monitor on a simulator: the target monitor sets a
3213 breakpoint; the simulator encounters this break-point and
3214 halts the simulation handing control to GDB; GDB, noteing
3215 that the break-point isn't valid, returns control back to the
3216 simulator; the simulator then delivers the hardware
3217 equivalent of a SIGNAL_TRAP to the program being debugged. */
3219 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !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
) && !stopped_by_random_signal
)
3232 #endif /* SHIFT_INST_REGS */
3234 resume (currently_stepping (ecs
), stop_signal
);
3237 prepare_to_wait (ecs
);
3240 /* This function normally comes after a resume, before
3241 handle_inferior_event exits. It takes care of any last bits of
3242 housekeeping, and sets the all-important wait_some_more flag. */
3245 prepare_to_wait (struct execution_control_state
*ecs
)
3247 if (ecs
->infwait_state
== infwait_normal_state
)
3249 overlay_cache_invalid
= 1;
3251 /* We have to invalidate the registers BEFORE calling
3252 target_wait because they can be loaded from the target while
3253 in target_wait. This makes remote debugging a bit more
3254 efficient for those targets that provide critical registers
3255 as part of their normal status mechanism. */
3257 registers_changed ();
3258 ecs
->waiton_ptid
= pid_to_ptid (-1);
3259 ecs
->wp
= &(ecs
->ws
);
3261 /* This is the old end of the while loop. Let everybody know we
3262 want to wait for the inferior some more and get called again
3264 ecs
->wait_some_more
= 1;
3267 /* Print why the inferior has stopped. We always print something when
3268 the inferior exits, or receives a signal. The rest of the cases are
3269 dealt with later on in normal_stop() and print_it_typical(). Ideally
3270 there should be a call to this function from handle_inferior_event()
3271 each time stop_stepping() is called.*/
3273 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3275 switch (stop_reason
)
3278 /* We don't deal with these cases from handle_inferior_event()
3281 case END_STEPPING_RANGE
:
3282 /* We are done with a step/next/si/ni command. */
3283 /* For now print nothing. */
3284 /* Print a message only if not in the middle of doing a "step n"
3285 operation for n > 1 */
3286 if (!step_multi
|| !stop_step
)
3287 if (ui_out_is_mi_like_p (uiout
))
3288 ui_out_field_string (uiout
, "reason", "end-stepping-range");
3290 case BREAKPOINT_HIT
:
3291 /* We found a breakpoint. */
3292 /* For now print nothing. */
3295 /* The inferior was terminated by a signal. */
3296 annotate_signalled ();
3297 if (ui_out_is_mi_like_p (uiout
))
3298 ui_out_field_string (uiout
, "reason", "exited-signalled");
3299 ui_out_text (uiout
, "\nProgram terminated with signal ");
3300 annotate_signal_name ();
3301 ui_out_field_string (uiout
, "signal-name",
3302 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",
3307 target_signal_to_string (stop_info
));
3308 annotate_signal_string_end ();
3309 ui_out_text (uiout
, ".\n");
3310 ui_out_text (uiout
, "The program no longer exists.\n");
3313 /* The inferior program is finished. */
3314 annotate_exited (stop_info
);
3317 if (ui_out_is_mi_like_p (uiout
))
3318 ui_out_field_string (uiout
, "reason", "exited");
3319 ui_out_text (uiout
, "\nProgram exited with code ");
3320 ui_out_field_fmt (uiout
, "exit-code", "0%o",
3321 (unsigned int) stop_info
);
3322 ui_out_text (uiout
, ".\n");
3326 if (ui_out_is_mi_like_p (uiout
))
3327 ui_out_field_string (uiout
, "reason", "exited-normally");
3328 ui_out_text (uiout
, "\nProgram exited normally.\n");
3331 case SIGNAL_RECEIVED
:
3332 /* Signal received. The signal table tells us to print about
3335 ui_out_text (uiout
, "\nProgram received signal ");
3336 annotate_signal_name ();
3337 if (ui_out_is_mi_like_p (uiout
))
3338 ui_out_field_string (uiout
, "reason", "signal-received");
3339 ui_out_field_string (uiout
, "signal-name",
3340 target_signal_to_name (stop_info
));
3341 annotate_signal_name_end ();
3342 ui_out_text (uiout
, ", ");
3343 annotate_signal_string ();
3344 ui_out_field_string (uiout
, "signal-meaning",
3345 target_signal_to_string (stop_info
));
3346 annotate_signal_string_end ();
3347 ui_out_text (uiout
, ".\n");
3350 internal_error (__FILE__
, __LINE__
,
3351 "print_stop_reason: unrecognized enum value");
3357 /* Here to return control to GDB when the inferior stops for real.
3358 Print appropriate messages, remove breakpoints, give terminal our modes.
3360 STOP_PRINT_FRAME nonzero means print the executing frame
3361 (pc, function, args, file, line number and line text).
3362 BREAKPOINTS_FAILED nonzero means stop was due to error
3363 attempting to insert breakpoints. */
3368 /* As with the notification of thread events, we want to delay
3369 notifying the user that we've switched thread context until
3370 the inferior actually stops.
3372 (Note that there's no point in saying anything if the inferior
3374 if (!ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3375 && target_has_execution
)
3377 target_terminal_ours_for_output ();
3378 printf_filtered ("[Switching to %s]\n",
3379 target_pid_or_tid_to_str (inferior_ptid
));
3380 previous_inferior_ptid
= inferior_ptid
;
3383 /* Make sure that the current_frame's pc is correct. This
3384 is a correction for setting up the frame info before doing
3385 DECR_PC_AFTER_BREAK */
3386 if (target_has_execution
&& get_current_frame ())
3387 (get_current_frame ())->pc
= read_pc ();
3389 if (breakpoints_failed
)
3391 target_terminal_ours_for_output ();
3392 print_sys_errmsg ("While inserting breakpoints", breakpoints_failed
);
3393 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3394 The same program may be running in another process,\n\
3395 or you may have requested too many hardware breakpoints\n\
3396 and/or watchpoints.\n");
3399 if (target_has_execution
&& breakpoints_inserted
)
3401 if (remove_breakpoints ())
3403 target_terminal_ours_for_output ();
3404 printf_filtered ("Cannot remove breakpoints because ");
3405 printf_filtered ("program is no longer writable.\n");
3406 printf_filtered ("It might be running in another process.\n");
3407 printf_filtered ("Further execution is probably impossible.\n");
3410 breakpoints_inserted
= 0;
3412 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3413 Delete any breakpoint that is to be deleted at the next stop. */
3415 breakpoint_auto_delete (stop_bpstat
);
3417 /* If an auto-display called a function and that got a signal,
3418 delete that auto-display to avoid an infinite recursion. */
3420 if (stopped_by_random_signal
)
3421 disable_current_display ();
3423 /* Don't print a message if in the middle of doing a "step n"
3424 operation for n > 1 */
3425 if (step_multi
&& stop_step
)
3428 target_terminal_ours ();
3430 /* Look up the hook_stop and run it (CLI internally handles problem
3431 of stop_command's pre-hook not existing). */
3433 catch_errors (hook_stop_stub
, stop_command
,
3434 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3436 if (!target_has_stack
)
3442 /* Select innermost stack frame - i.e., current frame is frame 0,
3443 and current location is based on that.
3444 Don't do this on return from a stack dummy routine,
3445 or if the program has exited. */
3447 if (!stop_stack_dummy
)
3449 select_frame (get_current_frame ());
3451 /* Print current location without a level number, if
3452 we have changed functions or hit a breakpoint.
3453 Print source line if we have one.
3454 bpstat_print() contains the logic deciding in detail
3455 what to print, based on the event(s) that just occurred. */
3457 if (stop_print_frame
&& selected_frame
)
3461 int do_frame_printing
= 1;
3463 bpstat_ret
= bpstat_print (stop_bpstat
);
3468 && step_frame_address
== FRAME_FP (get_current_frame ())
3469 && step_start_function
== find_pc_function (stop_pc
))
3470 source_flag
= SRC_LINE
; /* finished step, just print source line */
3472 source_flag
= SRC_AND_LOC
; /* print location and source line */
3474 case PRINT_SRC_AND_LOC
:
3475 source_flag
= SRC_AND_LOC
; /* print location and source line */
3477 case PRINT_SRC_ONLY
:
3478 source_flag
= SRC_LINE
;
3481 source_flag
= SRC_LINE
; /* something bogus */
3482 do_frame_printing
= 0;
3485 internal_error (__FILE__
, __LINE__
, "Unknown value.");
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 /* NB: The copy goes through to the target picking up the value of
3512 all the registers. */
3513 regcache_cpy (stop_registers
, current_regcache
);
3515 if (stop_stack_dummy
)
3517 /* Pop the empty frame that contains the stack dummy.
3518 POP_FRAME ends with a setting of the current frame, so we
3519 can use that next. */
3521 /* Set stop_pc to what it was before we called the function.
3522 Can't rely on restore_inferior_status because that only gets
3523 called if we don't stop in the called function. */
3524 stop_pc
= read_pc ();
3525 select_frame (get_current_frame ());
3529 annotate_stopped ();
3533 hook_stop_stub (void *cmd
)
3535 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3540 signal_stop_state (int signo
)
3542 return signal_stop
[signo
];
3546 signal_print_state (int signo
)
3548 return signal_print
[signo
];
3552 signal_pass_state (int signo
)
3554 return signal_program
[signo
];
3558 signal_stop_update (signo
, state
)
3562 int ret
= signal_stop
[signo
];
3563 signal_stop
[signo
] = state
;
3568 signal_print_update (signo
, state
)
3572 int ret
= signal_print
[signo
];
3573 signal_print
[signo
] = state
;
3578 signal_pass_update (signo
, state
)
3582 int ret
= signal_program
[signo
];
3583 signal_program
[signo
] = state
;
3588 sig_print_header (void)
3591 Signal Stop\tPrint\tPass to program\tDescription\n");
3595 sig_print_info (enum target_signal oursig
)
3597 char *name
= target_signal_to_name (oursig
);
3598 int name_padding
= 13 - strlen (name
);
3600 if (name_padding
<= 0)
3603 printf_filtered ("%s", name
);
3604 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
3605 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3606 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3607 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3608 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3611 /* Specify how various signals in the inferior should be handled. */
3614 handle_command (char *args
, int from_tty
)
3617 int digits
, wordlen
;
3618 int sigfirst
, signum
, siglast
;
3619 enum target_signal oursig
;
3622 unsigned char *sigs
;
3623 struct cleanup
*old_chain
;
3627 error_no_arg ("signal to handle");
3630 /* Allocate and zero an array of flags for which signals to handle. */
3632 nsigs
= (int) TARGET_SIGNAL_LAST
;
3633 sigs
= (unsigned char *) alloca (nsigs
);
3634 memset (sigs
, 0, nsigs
);
3636 /* Break the command line up into args. */
3638 argv
= buildargv (args
);
3643 old_chain
= make_cleanup_freeargv (argv
);
3645 /* Walk through the args, looking for signal oursigs, signal names, and
3646 actions. Signal numbers and signal names may be interspersed with
3647 actions, with the actions being performed for all signals cumulatively
3648 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3650 while (*argv
!= NULL
)
3652 wordlen
= strlen (*argv
);
3653 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3657 sigfirst
= siglast
= -1;
3659 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3661 /* Apply action to all signals except those used by the
3662 debugger. Silently skip those. */
3665 siglast
= nsigs
- 1;
3667 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3669 SET_SIGS (nsigs
, sigs
, signal_stop
);
3670 SET_SIGS (nsigs
, sigs
, signal_print
);
3672 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3674 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3676 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3678 SET_SIGS (nsigs
, sigs
, signal_print
);
3680 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3682 SET_SIGS (nsigs
, sigs
, signal_program
);
3684 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3686 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3688 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3690 SET_SIGS (nsigs
, sigs
, signal_program
);
3692 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3694 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3695 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3697 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3699 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3701 else if (digits
> 0)
3703 /* It is numeric. The numeric signal refers to our own
3704 internal signal numbering from target.h, not to host/target
3705 signal number. This is a feature; users really should be
3706 using symbolic names anyway, and the common ones like
3707 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3709 sigfirst
= siglast
= (int)
3710 target_signal_from_command (atoi (*argv
));
3711 if ((*argv
)[digits
] == '-')
3714 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3716 if (sigfirst
> siglast
)
3718 /* Bet he didn't figure we'd think of this case... */
3726 oursig
= target_signal_from_name (*argv
);
3727 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3729 sigfirst
= siglast
= (int) oursig
;
3733 /* Not a number and not a recognized flag word => complain. */
3734 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3738 /* If any signal numbers or symbol names were found, set flags for
3739 which signals to apply actions to. */
3741 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3743 switch ((enum target_signal
) signum
)
3745 case TARGET_SIGNAL_TRAP
:
3746 case TARGET_SIGNAL_INT
:
3747 if (!allsigs
&& !sigs
[signum
])
3749 if (query ("%s is used by the debugger.\n\
3750 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
3756 printf_unfiltered ("Not confirmed, unchanged.\n");
3757 gdb_flush (gdb_stdout
);
3761 case TARGET_SIGNAL_0
:
3762 case TARGET_SIGNAL_DEFAULT
:
3763 case TARGET_SIGNAL_UNKNOWN
:
3764 /* Make sure that "all" doesn't print these. */
3775 target_notice_signals (inferior_ptid
);
3779 /* Show the results. */
3780 sig_print_header ();
3781 for (signum
= 0; signum
< nsigs
; signum
++)
3785 sig_print_info (signum
);
3790 do_cleanups (old_chain
);
3794 xdb_handle_command (char *args
, int from_tty
)
3797 struct cleanup
*old_chain
;
3799 /* Break the command line up into args. */
3801 argv
= buildargv (args
);
3806 old_chain
= make_cleanup_freeargv (argv
);
3807 if (argv
[1] != (char *) NULL
)
3812 bufLen
= strlen (argv
[0]) + 20;
3813 argBuf
= (char *) xmalloc (bufLen
);
3817 enum target_signal oursig
;
3819 oursig
= target_signal_from_name (argv
[0]);
3820 memset (argBuf
, 0, bufLen
);
3821 if (strcmp (argv
[1], "Q") == 0)
3822 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3825 if (strcmp (argv
[1], "s") == 0)
3827 if (!signal_stop
[oursig
])
3828 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3830 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3832 else if (strcmp (argv
[1], "i") == 0)
3834 if (!signal_program
[oursig
])
3835 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3837 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3839 else if (strcmp (argv
[1], "r") == 0)
3841 if (!signal_print
[oursig
])
3842 sprintf (argBuf
, "%s %s", argv
[0], "print");
3844 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3850 handle_command (argBuf
, from_tty
);
3852 printf_filtered ("Invalid signal handling flag.\n");
3857 do_cleanups (old_chain
);
3860 /* Print current contents of the tables set by the handle command.
3861 It is possible we should just be printing signals actually used
3862 by the current target (but for things to work right when switching
3863 targets, all signals should be in the signal tables). */
3866 signals_info (char *signum_exp
, int from_tty
)
3868 enum target_signal oursig
;
3869 sig_print_header ();
3873 /* First see if this is a symbol name. */
3874 oursig
= target_signal_from_name (signum_exp
);
3875 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3877 /* No, try numeric. */
3879 target_signal_from_command (parse_and_eval_long (signum_exp
));
3881 sig_print_info (oursig
);
3885 printf_filtered ("\n");
3886 /* These ugly casts brought to you by the native VAX compiler. */
3887 for (oursig
= TARGET_SIGNAL_FIRST
;
3888 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3889 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3893 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3894 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
3895 sig_print_info (oursig
);
3898 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3901 struct inferior_status
3903 enum target_signal stop_signal
;
3907 int stop_stack_dummy
;
3908 int stopped_by_random_signal
;
3910 CORE_ADDR step_range_start
;
3911 CORE_ADDR step_range_end
;
3912 CORE_ADDR step_frame_address
;
3913 enum step_over_calls_kind step_over_calls
;
3914 CORE_ADDR step_resume_break_address
;
3915 int stop_after_trap
;
3916 int stop_soon_quietly
;
3917 struct regcache
*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
3922 struct regcache
*registers
;
3924 /* A frame unique identifier. */
3925 struct frame_id selected_frame_id
;
3927 int breakpoint_proceeded
;
3928 int restore_stack_info
;
3929 int proceed_to_finish
;
3933 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3936 int size
= REGISTER_RAW_SIZE (regno
);
3937 void *buf
= alloca (size
);
3938 store_signed_integer (buf
, size
, val
);
3939 regcache_raw_write (inf_status
->registers
, regno
, buf
);
3942 /* Save all of the information associated with the inferior<==>gdb
3943 connection. INF_STATUS is a pointer to a "struct inferior_status"
3944 (defined in inferior.h). */
3946 struct inferior_status
*
3947 save_inferior_status (int restore_stack_info
)
3949 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
3951 inf_status
->stop_signal
= stop_signal
;
3952 inf_status
->stop_pc
= stop_pc
;
3953 inf_status
->stop_step
= stop_step
;
3954 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3955 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3956 inf_status
->trap_expected
= trap_expected
;
3957 inf_status
->step_range_start
= step_range_start
;
3958 inf_status
->step_range_end
= step_range_end
;
3959 inf_status
->step_frame_address
= step_frame_address
;
3960 inf_status
->step_over_calls
= step_over_calls
;
3961 inf_status
->stop_after_trap
= stop_after_trap
;
3962 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3963 /* Save original bpstat chain here; replace it with copy of chain.
3964 If caller's caller is walking the chain, they'll be happier if we
3965 hand them back the original chain when restore_inferior_status is
3967 inf_status
->stop_bpstat
= stop_bpstat
;
3968 stop_bpstat
= bpstat_copy (stop_bpstat
);
3969 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3970 inf_status
->restore_stack_info
= restore_stack_info
;
3971 inf_status
->proceed_to_finish
= proceed_to_finish
;
3973 inf_status
->stop_registers
= regcache_dup_no_passthrough (stop_registers
);
3975 inf_status
->registers
= regcache_dup (current_regcache
);
3977 get_frame_id (selected_frame
, &inf_status
->selected_frame_id
);
3982 restore_selected_frame (void *args
)
3984 struct frame_id
*fid
= (struct frame_id
*) args
;
3985 struct frame_info
*frame
;
3987 frame
= frame_find_by_id (*fid
);
3989 /* If inf_status->selected_frame_address is NULL, there was no
3990 previously selected frame. */
3993 warning ("Unable to restore previously selected frame.\n");
3997 select_frame (frame
);
4003 restore_inferior_status (struct inferior_status
*inf_status
)
4005 stop_signal
= inf_status
->stop_signal
;
4006 stop_pc
= inf_status
->stop_pc
;
4007 stop_step
= inf_status
->stop_step
;
4008 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4009 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4010 trap_expected
= inf_status
->trap_expected
;
4011 step_range_start
= inf_status
->step_range_start
;
4012 step_range_end
= inf_status
->step_range_end
;
4013 step_frame_address
= inf_status
->step_frame_address
;
4014 step_over_calls
= inf_status
->step_over_calls
;
4015 stop_after_trap
= inf_status
->stop_after_trap
;
4016 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
4017 bpstat_clear (&stop_bpstat
);
4018 stop_bpstat
= inf_status
->stop_bpstat
;
4019 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4020 proceed_to_finish
= inf_status
->proceed_to_finish
;
4022 /* FIXME: Is the restore of stop_registers always needed. */
4023 regcache_xfree (stop_registers
);
4024 stop_registers
= inf_status
->stop_registers
;
4026 /* The inferior can be gone if the user types "print exit(0)"
4027 (and perhaps other times). */
4028 if (target_has_execution
)
4029 /* NB: The register write goes through to the target. */
4030 regcache_cpy (current_regcache
, inf_status
->registers
);
4031 regcache_xfree (inf_status
->registers
);
4033 /* FIXME: If we are being called after stopping in a function which
4034 is called from gdb, we should not be trying to restore the
4035 selected frame; it just prints a spurious error message (The
4036 message is useful, however, in detecting bugs in gdb (like if gdb
4037 clobbers the stack)). In fact, should we be restoring the
4038 inferior status at all in that case? . */
4040 if (target_has_stack
&& inf_status
->restore_stack_info
)
4042 /* The point of catch_errors is that if the stack is clobbered,
4043 walking the stack might encounter a garbage pointer and
4044 error() trying to dereference it. */
4046 (restore_selected_frame
, &inf_status
->selected_frame_id
,
4047 "Unable to restore previously selected frame:\n",
4048 RETURN_MASK_ERROR
) == 0)
4049 /* Error in restoring the selected frame. Select the innermost
4051 select_frame (get_current_frame ());
4059 do_restore_inferior_status_cleanup (void *sts
)
4061 restore_inferior_status (sts
);
4065 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4067 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4071 discard_inferior_status (struct inferior_status
*inf_status
)
4073 /* See save_inferior_status for info on stop_bpstat. */
4074 bpstat_clear (&inf_status
->stop_bpstat
);
4075 regcache_xfree (inf_status
->registers
);
4076 regcache_xfree (inf_status
->stop_registers
);
4080 /* Oft used ptids */
4082 ptid_t minus_one_ptid
;
4084 /* Create a ptid given the necessary PID, LWP, and TID components. */
4087 ptid_build (int pid
, long lwp
, long tid
)
4097 /* Create a ptid from just a pid. */
4100 pid_to_ptid (int pid
)
4102 return ptid_build (pid
, 0, 0);
4105 /* Fetch the pid (process id) component from a ptid. */
4108 ptid_get_pid (ptid_t ptid
)
4113 /* Fetch the lwp (lightweight process) component from a ptid. */
4116 ptid_get_lwp (ptid_t ptid
)
4121 /* Fetch the tid (thread id) component from a ptid. */
4124 ptid_get_tid (ptid_t ptid
)
4129 /* ptid_equal() is used to test equality of two ptids. */
4132 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4134 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4135 && ptid1
.tid
== ptid2
.tid
);
4138 /* restore_inferior_ptid() will be used by the cleanup machinery
4139 to restore the inferior_ptid value saved in a call to
4140 save_inferior_ptid(). */
4143 restore_inferior_ptid (void *arg
)
4145 ptid_t
*saved_ptid_ptr
= arg
;
4146 inferior_ptid
= *saved_ptid_ptr
;
4150 /* Save the value of inferior_ptid so that it may be restored by a
4151 later call to do_cleanups(). Returns the struct cleanup pointer
4152 needed for later doing the cleanup. */
4155 save_inferior_ptid (void)
4157 ptid_t
*saved_ptid_ptr
;
4159 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4160 *saved_ptid_ptr
= inferior_ptid
;
4161 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4168 stop_registers
= regcache_xmalloc (current_gdbarch
);
4172 _initialize_infrun (void)
4175 register int numsigs
;
4176 struct cmd_list_element
*c
;
4178 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4179 register_gdbarch_swap (NULL
, 0, build_infrun
);
4181 add_info ("signals", signals_info
,
4182 "What debugger does when program gets various signals.\n\
4183 Specify a signal as argument to print info on that signal only.");
4184 add_info_alias ("handle", "signals", 0);
4186 add_com ("handle", class_run
, handle_command
,
4187 concat ("Specify how to handle a signal.\n\
4188 Args are signals and actions to apply to those signals.\n\
4189 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4190 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4191 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4192 The special arg \"all\" is recognized to mean all signals except those\n\
4193 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4194 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4195 Stop means reenter debugger if this signal happens (implies print).\n\
4196 Print means print a message if this signal happens.\n\
4197 Pass means let program see this signal; otherwise program doesn't know.\n\
4198 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4199 Pass and Stop may be combined.", NULL
));
4202 add_com ("lz", class_info
, signals_info
,
4203 "What debugger does when program gets various signals.\n\
4204 Specify a signal as argument to print info on that signal only.");
4205 add_com ("z", class_run
, xdb_handle_command
,
4206 concat ("Specify how to handle a signal.\n\
4207 Args are signals and actions to apply to those signals.\n\
4208 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4209 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4210 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4211 The special arg \"all\" is recognized to mean all signals except those\n\
4212 used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4213 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4214 nopass), \"Q\" (noprint)\n\
4215 Stop means reenter debugger if this signal happens (implies print).\n\
4216 Print means print a message if this signal happens.\n\
4217 Pass means let program see this signal; otherwise program doesn't know.\n\
4218 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4219 Pass and Stop may be combined.", NULL
));
4224 add_cmd ("stop", class_obscure
, not_just_help_class_command
, "There is no `stop' command, but you can set a hook on `stop'.\n\
4225 This allows you to set a list of commands to be run each time execution\n\
4226 of the program stops.", &cmdlist
);
4228 numsigs
= (int) TARGET_SIGNAL_LAST
;
4229 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4230 signal_print
= (unsigned char *)
4231 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4232 signal_program
= (unsigned char *)
4233 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4234 for (i
= 0; i
< numsigs
; i
++)
4237 signal_print
[i
] = 1;
4238 signal_program
[i
] = 1;
4241 /* Signals caused by debugger's own actions
4242 should not be given to the program afterwards. */
4243 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4244 signal_program
[TARGET_SIGNAL_INT
] = 0;
4246 /* Signals that are not errors should not normally enter the debugger. */
4247 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4248 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4249 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4250 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4251 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4252 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4253 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4254 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4255 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4256 signal_print
[TARGET_SIGNAL_IO
] = 0;
4257 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4258 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4259 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4260 signal_print
[TARGET_SIGNAL_URG
] = 0;
4261 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4262 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4264 /* These signals are used internally by user-level thread
4265 implementations. (See signal(5) on Solaris.) Like the above
4266 signals, a healthy program receives and handles them as part of
4267 its normal operation. */
4268 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4269 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4270 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4271 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4272 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4273 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4277 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4278 (char *) &stop_on_solib_events
,
4279 "Set stopping for shared library events.\n\
4280 If nonzero, gdb will give control to the user when the dynamic linker\n\
4281 notifies gdb of shared library events. The most common event of interest\n\
4282 to the user would be loading/unloading of a new library.\n", &setlist
), &showlist
);
4285 c
= add_set_enum_cmd ("follow-fork-mode",
4287 follow_fork_mode_kind_names
, &follow_fork_mode_string
,
4288 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4289 kernel problem. It's also not terribly useful without a GUI to
4290 help the user drive two debuggers. So for now, I'm disabling
4291 the "both" option. */
4292 /* "Set debugger response to a program call of fork \
4294 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4295 parent - the original process is debugged after a fork\n\
4296 child - the new process is debugged after a fork\n\
4297 both - both the parent and child are debugged after a fork\n\
4298 ask - the debugger will ask for one of the above choices\n\
4299 For \"both\", another copy of the debugger will be started to follow\n\
4300 the new child process. The original debugger will continue to follow\n\
4301 the original parent process. To distinguish their prompts, the\n\
4302 debugger copy's prompt will be changed.\n\
4303 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4304 By default, the debugger will follow the parent process.",
4306 "Set debugger response to a program call of fork \
4308 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4309 parent - the original process is debugged after a fork\n\
4310 child - the new process is debugged after a fork\n\
4311 ask - the debugger will ask for one of the above choices\n\
4312 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4313 By default, the debugger will follow the parent process.", &setlist
);
4314 add_show_from_set (c
, &showlist
);
4316 c
= add_set_enum_cmd ("scheduler-locking", class_run
, scheduler_enums
, /* array of string names */
4317 &scheduler_mode
, /* current mode */
4318 "Set mode for locking scheduler during execution.\n\
4319 off == no locking (threads may preempt at any time)\n\
4320 on == full locking (no thread except the current thread may run)\n\
4321 step == scheduler locked during every single-step operation.\n\
4322 In this mode, no other thread may run during a step command.\n\
4323 Other threads may run while stepping over a function call ('next').", &setlist
);
4325 set_cmd_sfunc (c
, set_schedlock_func
); /* traps on target vector */
4326 add_show_from_set (c
, &showlist
);
4328 c
= add_set_cmd ("step-mode", class_run
,
4329 var_boolean
, (char *) &step_stop_if_no_debug
,
4330 "Set mode of the step operation. When set, doing a step over a\n\
4331 function without debug line information will stop at the first\n\
4332 instruction of that function. Otherwise, the function is skipped and\n\
4333 the step command stops at a different source line.", &setlist
);
4334 add_show_from_set (c
, &showlist
);
4336 /* ptid initializations */
4337 null_ptid
= ptid_build (0, 0, 0);
4338 minus_one_ptid
= ptid_build (-1, 0, 0);
4339 inferior_ptid
= null_ptid
;
4340 target_last_wait_ptid
= minus_one_ptid
;