1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
28 #include "breakpoint.h"
33 #include "gdbthread.h"
41 /* Prototypes for local functions */
43 static void signals_info (char *, int);
45 static void handle_command (char *, int);
47 static void sig_print_info (enum target_signal
);
49 static void sig_print_header (void);
51 static void resume_cleanups (void *);
53 static int hook_stop_stub (void *);
55 static void delete_breakpoint_current_contents (void *);
57 static void set_follow_fork_mode_command (char *arg
, int from_tty
,
58 struct cmd_list_element
* c
);
60 static struct inferior_status
*xmalloc_inferior_status (void);
62 static void free_inferior_status (struct inferior_status
*);
64 static int restore_selected_frame (void *);
66 static void build_infrun (void);
68 static void follow_inferior_fork (int parent_pid
, int child_pid
,
69 int has_forked
, int has_vforked
);
71 static void follow_fork (int parent_pid
, int child_pid
);
73 static void follow_vfork (int parent_pid
, int child_pid
);
75 static void set_schedlock_func (char *args
, int from_tty
,
76 struct cmd_list_element
* c
);
78 struct execution_control_state
;
80 static int currently_stepping (struct execution_control_state
*ecs
);
82 static void xdb_handle_command (char *args
, int from_tty
);
84 void _initialize_infrun (void);
86 int inferior_ignoring_startup_exec_events
= 0;
87 int inferior_ignoring_leading_exec_events
= 0;
89 /* When set, stop the 'step' command if we enter a function which has
90 no line number information. The normal behavior is that we step
91 over such function. */
92 int step_stop_if_no_debug
= 0;
94 /* In asynchronous mode, but simulating synchronous execution. */
96 int sync_execution
= 0;
98 /* wait_for_inferior and normal_stop use this to notify the user
99 when the inferior stopped in a different thread than it had been
102 static ptid_t previous_inferior_ptid
;
104 /* This is true for configurations that may follow through execl() and
105 similar functions. At present this is only true for HP-UX native. */
107 #ifndef MAY_FOLLOW_EXEC
108 #define MAY_FOLLOW_EXEC (0)
111 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
113 /* resume and wait_for_inferior use this to ensure that when
114 stepping over a hit breakpoint in a threaded application
115 only the thread that hit the breakpoint is stepped and the
116 other threads don't continue. This prevents having another
117 thread run past the breakpoint while it is temporarily
120 This is not thread-specific, so it isn't saved as part of
123 Versions of gdb which don't use the "step == this thread steps
124 and others continue" model but instead use the "step == this
125 thread steps and others wait" shouldn't do this. */
127 static int thread_step_needed
= 0;
129 /* This is true if thread_step_needed should actually be used. At
130 present this is only true for HP-UX native. */
132 #ifndef USE_THREAD_STEP_NEEDED
133 #define USE_THREAD_STEP_NEEDED (0)
136 static int use_thread_step_needed
= USE_THREAD_STEP_NEEDED
;
138 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
139 program. It needs to examine the jmp_buf argument and extract the PC
140 from it. The return value is non-zero on success, zero otherwise. */
142 #ifndef GET_LONGJMP_TARGET
143 #define GET_LONGJMP_TARGET(PC_ADDR) 0
147 /* Some machines have trampoline code that sits between function callers
148 and the actual functions themselves. If this machine doesn't have
149 such things, disable their processing. */
151 #ifndef SKIP_TRAMPOLINE_CODE
152 #define SKIP_TRAMPOLINE_CODE(pc) 0
155 /* Dynamic function trampolines are similar to solib trampolines in that they
156 are between the caller and the callee. The difference is that when you
157 enter a dynamic trampoline, you can't determine the callee's address. Some
158 (usually complex) code needs to run in the dynamic trampoline to figure out
159 the callee's address. This macro is usually called twice. First, when we
160 enter the trampoline (looks like a normal function call at that point). It
161 should return the PC of a point within the trampoline where the callee's
162 address is known. Second, when we hit the breakpoint, this routine returns
163 the callee's address. At that point, things proceed as per a step resume
166 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
167 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
170 /* If the program uses ELF-style shared libraries, then calls to
171 functions in shared libraries go through stubs, which live in a
172 table called the PLT (Procedure Linkage Table). The first time the
173 function is called, the stub sends control to the dynamic linker,
174 which looks up the function's real address, patches the stub so
175 that future calls will go directly to the function, and then passes
176 control to the function.
178 If we are stepping at the source level, we don't want to see any of
179 this --- we just want to skip over the stub and the dynamic linker.
180 The simple approach is to single-step until control leaves the
183 However, on some systems (e.g., Red Hat Linux 5.2) the dynamic
184 linker calls functions in the shared C library, so you can't tell
185 from the PC alone whether the dynamic linker is still running. In
186 this case, we use a step-resume breakpoint to get us past the
187 dynamic linker, as if we were using "next" to step over a function
190 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
191 linker code or not. Normally, this means we single-step. However,
192 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
193 address where we can place a step-resume breakpoint to get past the
194 linker's symbol resolution function.
196 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
197 pretty portable way, by comparing the PC against the address ranges
198 of the dynamic linker's sections.
200 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
201 it depends on internal details of the dynamic linker. It's usually
202 not too hard to figure out where to put a breakpoint, but it
203 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
204 sanity checking. If it can't figure things out, returning zero and
205 getting the (possibly confusing) stepping behavior is better than
206 signalling an error, which will obscure the change in the
209 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
210 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
213 #ifndef SKIP_SOLIB_RESOLVER
214 #define SKIP_SOLIB_RESOLVER(pc) 0
217 /* For SVR4 shared libraries, each call goes through a small piece of
218 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
219 to nonzero if we are current stopped in one of these. */
221 #ifndef IN_SOLIB_CALL_TRAMPOLINE
222 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
225 /* In some shared library schemes, the return path from a shared library
226 call may need to go through a trampoline too. */
228 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
229 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
232 /* This function returns TRUE if pc is the address of an instruction
233 that lies within the dynamic linker (such as the event hook, or the
236 This function must be used only when a dynamic linker event has
237 been caught, and the inferior is being stepped out of the hook, or
238 undefined results are guaranteed. */
240 #ifndef SOLIB_IN_DYNAMIC_LINKER
241 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
244 /* On MIPS16, a function that returns a floating point value may call
245 a library helper function to copy the return value to a floating point
246 register. The IGNORE_HELPER_CALL macro returns non-zero if we
247 should ignore (i.e. step over) this function call. */
248 #ifndef IGNORE_HELPER_CALL
249 #define IGNORE_HELPER_CALL(pc) 0
252 /* On some systems, the PC may be left pointing at an instruction that won't
253 actually be executed. This is usually indicated by a bit in the PSW. If
254 we find ourselves in such a state, then we step the target beyond the
255 nullified instruction before returning control to the user so as to avoid
258 #ifndef INSTRUCTION_NULLIFIED
259 #define INSTRUCTION_NULLIFIED 0
262 /* We can't step off a permanent breakpoint in the ordinary way, because we
263 can't remove it. Instead, we have to advance the PC to the next
264 instruction. This macro should expand to a pointer to a function that
265 does that, or zero if we have no such function. If we don't have a
266 definition for it, we have to report an error. */
267 #ifndef SKIP_PERMANENT_BREAKPOINT
268 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
270 default_skip_permanent_breakpoint (void)
273 fprintf_filtered (gdb_stderr
, "\
274 The program is stopped at a permanent breakpoint, but GDB does not know\n\
275 how to step past a permanent breakpoint on this architecture. Try using\n\
276 a command like `return' or `jump' to continue execution.\n");
277 return_to_top_level (RETURN_ERROR
);
282 /* Convert the #defines into values. This is temporary until wfi control
283 flow is completely sorted out. */
285 #ifndef HAVE_STEPPABLE_WATCHPOINT
286 #define HAVE_STEPPABLE_WATCHPOINT 0
288 #undef HAVE_STEPPABLE_WATCHPOINT
289 #define HAVE_STEPPABLE_WATCHPOINT 1
292 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
293 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
295 #undef HAVE_NONSTEPPABLE_WATCHPOINT
296 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
299 #ifndef HAVE_CONTINUABLE_WATCHPOINT
300 #define HAVE_CONTINUABLE_WATCHPOINT 0
302 #undef HAVE_CONTINUABLE_WATCHPOINT
303 #define HAVE_CONTINUABLE_WATCHPOINT 1
306 #ifndef CANNOT_STEP_HW_WATCHPOINTS
307 #define CANNOT_STEP_HW_WATCHPOINTS 0
309 #undef CANNOT_STEP_HW_WATCHPOINTS
310 #define CANNOT_STEP_HW_WATCHPOINTS 1
313 /* Tables of how to react to signals; the user sets them. */
315 static unsigned char *signal_stop
;
316 static unsigned char *signal_print
;
317 static unsigned char *signal_program
;
319 #define SET_SIGS(nsigs,sigs,flags) \
321 int signum = (nsigs); \
322 while (signum-- > 0) \
323 if ((sigs)[signum]) \
324 (flags)[signum] = 1; \
327 #define UNSET_SIGS(nsigs,sigs,flags) \
329 int signum = (nsigs); \
330 while (signum-- > 0) \
331 if ((sigs)[signum]) \
332 (flags)[signum] = 0; \
335 /* Value to pass to target_resume() to cause all threads to resume */
337 #define RESUME_ALL (pid_to_ptid (-1))
339 /* Command list pointer for the "stop" placeholder. */
341 static struct cmd_list_element
*stop_command
;
343 /* Nonzero if breakpoints are now inserted in the inferior. */
345 static int breakpoints_inserted
;
347 /* Function inferior was in as of last step command. */
349 static struct symbol
*step_start_function
;
351 /* Nonzero if we are expecting a trace trap and should proceed from it. */
353 static int trap_expected
;
356 /* Nonzero if we want to give control to the user when we're notified
357 of shared library events by the dynamic linker. */
358 static int stop_on_solib_events
;
362 /* Nonzero if the next time we try to continue the inferior, it will
363 step one instruction and generate a spurious trace trap.
364 This is used to compensate for a bug in HP-UX. */
366 static int trap_expected_after_continue
;
369 /* Nonzero means expecting a trace trap
370 and should stop the inferior and return silently when it happens. */
374 /* Nonzero means expecting a trap and caller will handle it themselves.
375 It is used after attach, due to attaching to a process;
376 when running in the shell before the child program has been exec'd;
377 and when running some kinds of remote stuff (FIXME?). */
379 int stop_soon_quietly
;
381 /* Nonzero if proceed is being used for a "finish" command or a similar
382 situation when stop_registers should be saved. */
384 int proceed_to_finish
;
386 /* Save register contents here when about to pop a stack dummy frame,
387 if-and-only-if proceed_to_finish is set.
388 Thus this contains the return value from the called function (assuming
389 values are returned in a register). */
391 char *stop_registers
;
393 /* Nonzero if program stopped due to error trying to insert breakpoints. */
395 static int breakpoints_failed
;
397 /* Nonzero after stop if current stack frame should be printed. */
399 static int stop_print_frame
;
401 static struct breakpoint
*step_resume_breakpoint
= NULL
;
402 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
404 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
405 interactions with an inferior that is running a kernel function
406 (aka, a system call or "syscall"). wait_for_inferior therefore
407 may have a need to know when the inferior is in a syscall. This
408 is a count of the number of inferior threads which are known to
409 currently be running in a syscall. */
410 static int number_of_threads_in_syscalls
;
412 /* This is a cached copy of the pid/waitstatus of the last event
413 returned by target_wait()/target_wait_hook(). This information is
414 returned by get_last_target_status(). */
415 static ptid_t target_last_wait_ptid
;
416 static struct target_waitstatus target_last_waitstatus
;
418 /* This is used to remember when a fork, vfork or exec event
419 was caught by a catchpoint, and thus the event is to be
420 followed at the next resume of the inferior, and not
424 enum target_waitkind kind
;
434 char *execd_pathname
;
438 /* Some platforms don't allow us to do anything meaningful with a
439 vforked child until it has exec'd. Vforked processes on such
440 platforms can only be followed after they've exec'd.
442 When this is set to 0, a vfork can be immediately followed,
443 and an exec can be followed merely as an exec. When this is
444 set to 1, a vfork event has been seen, but cannot be followed
445 until the exec is seen.
447 (In the latter case, inferior_ptid is still the parent of the
448 vfork, and pending_follow.fork_event.child_pid is the child. The
449 appropriate process is followed, according to the setting of
450 follow-fork-mode.) */
451 static int follow_vfork_when_exec
;
453 static const char follow_fork_mode_ask
[] = "ask";
454 static const char follow_fork_mode_both
[] = "both";
455 static const char follow_fork_mode_child
[] = "child";
456 static const char follow_fork_mode_parent
[] = "parent";
458 static const char *follow_fork_mode_kind_names
[] =
460 follow_fork_mode_ask
,
461 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
462 kernel problem. It's also not terribly useful without a GUI to
463 help the user drive two debuggers. So for now, I'm disabling the
465 /* follow_fork_mode_both, */
466 follow_fork_mode_child
,
467 follow_fork_mode_parent
,
471 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
475 follow_inferior_fork (int parent_pid
, int child_pid
, int has_forked
,
478 int followed_parent
= 0;
479 int followed_child
= 0;
481 /* Which process did the user want us to follow? */
482 const char *follow_mode
= follow_fork_mode_string
;
484 /* Or, did the user not know, and want us to ask? */
485 if (follow_fork_mode_string
== follow_fork_mode_ask
)
487 internal_error (__FILE__
, __LINE__
,
488 "follow_inferior_fork: \"ask\" mode not implemented");
489 /* follow_mode = follow_fork_mode_...; */
492 /* If we're to be following the parent, then detach from child_pid.
493 We're already following the parent, so need do nothing explicit
495 if (follow_mode
== follow_fork_mode_parent
)
499 /* We're already attached to the parent, by default. */
501 /* Before detaching from the child, remove all breakpoints from
502 it. (This won't actually modify the breakpoint list, but will
503 physically remove the breakpoints from the child.) */
504 if (!has_vforked
|| !follow_vfork_when_exec
)
506 detach_breakpoints (child_pid
);
507 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
508 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
512 /* Detach from the child. */
515 target_require_detach (child_pid
, "", 1);
518 /* If we're to be following the child, then attach to it, detach
519 from inferior_ptid, and set inferior_ptid to child_pid. */
520 else if (follow_mode
== follow_fork_mode_child
)
522 char child_pid_spelling
[100]; /* Arbitrary length. */
526 /* Before detaching from the parent, detach all breakpoints from
527 the child. But only if we're forking, or if we follow vforks
528 as soon as they happen. (If we're following vforks only when
529 the child has exec'd, then it's very wrong to try to write
530 back the "shadow contents" of inserted breakpoints now -- they
531 belong to the child's pre-exec'd a.out.) */
532 if (!has_vforked
|| !follow_vfork_when_exec
)
534 detach_breakpoints (child_pid
);
537 /* Before detaching from the parent, remove all breakpoints from it. */
538 remove_breakpoints ();
540 /* Also reset the solib inferior hook from the parent. */
541 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
542 SOLIB_REMOVE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
545 /* Detach from the parent. */
547 target_detach (NULL
, 1);
549 /* Attach to the child. */
550 inferior_ptid
= pid_to_ptid (child_pid
);
551 sprintf (child_pid_spelling
, "%d", child_pid
);
554 target_require_attach (child_pid_spelling
, 1);
556 /* Was there a step_resume breakpoint? (There was if the user
557 did a "next" at the fork() call.) If so, explicitly reset its
560 step_resumes are a form of bp that are made to be per-thread.
561 Since we created the step_resume bp when the parent process
562 was being debugged, and now are switching to the child process,
563 from the breakpoint package's viewpoint, that's a switch of
564 "threads". We must update the bp's notion of which thread
565 it is for, or it'll be ignored when it triggers... */
566 if (step_resume_breakpoint
&&
567 (!has_vforked
|| !follow_vfork_when_exec
))
568 breakpoint_re_set_thread (step_resume_breakpoint
);
570 /* Reinsert all breakpoints in the child. (The user may've set
571 breakpoints after catching the fork, in which case those
572 actually didn't get set in the child, but only in the parent.) */
573 if (!has_vforked
|| !follow_vfork_when_exec
)
575 breakpoint_re_set ();
576 insert_breakpoints ();
580 /* If we're to be following both parent and child, then fork ourselves,
581 and attach the debugger clone to the child. */
582 else if (follow_mode
== follow_fork_mode_both
)
584 char pid_suffix
[100]; /* Arbitrary length. */
586 /* Clone ourselves to follow the child. This is the end of our
587 involvement with child_pid; our clone will take it from here... */
589 target_clone_and_follow_inferior (child_pid
, &followed_child
);
590 followed_parent
= !followed_child
;
592 /* We continue to follow the parent. To help distinguish the two
593 debuggers, though, both we and our clone will reset our prompts. */
594 sprintf (pid_suffix
, "[%d] ", PIDGET (inferior_ptid
));
595 set_prompt (strcat (get_prompt (), pid_suffix
));
598 /* The parent and child of a vfork share the same address space.
599 Also, on some targets the order in which vfork and exec events
600 are received for parent in child requires some delicate handling
603 For instance, on ptrace-based HPUX we receive the child's vfork
604 event first, at which time the parent has been suspended by the
605 OS and is essentially untouchable until the child's exit or second
606 exec event arrives. At that time, the parent's vfork event is
607 delivered to us, and that's when we see and decide how to follow
608 the vfork. But to get to that point, we must continue the child
609 until it execs or exits. To do that smoothly, all breakpoints
610 must be removed from the child, in case there are any set between
611 the vfork() and exec() calls. But removing them from the child
612 also removes them from the parent, due to the shared-address-space
613 nature of a vfork'd parent and child. On HPUX, therefore, we must
614 take care to restore the bp's to the parent before we continue it.
615 Else, it's likely that we may not stop in the expected place. (The
616 worst scenario is when the user tries to step over a vfork() call;
617 the step-resume bp must be restored for the step to properly stop
618 in the parent after the call completes!)
620 Sequence of events, as reported to gdb from HPUX:
622 Parent Child Action for gdb to take
623 -------------------------------------------------------
624 1 VFORK Continue child
630 target_post_follow_vfork (parent_pid
,
636 pending_follow
.fork_event
.saw_parent_fork
= 0;
637 pending_follow
.fork_event
.saw_child_fork
= 0;
641 follow_fork (int parent_pid
, int child_pid
)
643 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
647 /* Forward declaration. */
648 static void follow_exec (int, char *);
651 follow_vfork (int parent_pid
, int child_pid
)
653 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
655 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
656 if (pending_follow
.fork_event
.saw_child_exec
657 && (PIDGET (inferior_ptid
) == child_pid
))
659 pending_follow
.fork_event
.saw_child_exec
= 0;
660 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
661 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
662 xfree (pending_follow
.execd_pathname
);
666 /* EXECD_PATHNAME is assumed to be non-NULL. */
669 follow_exec (int pid
, char *execd_pathname
)
672 struct target_ops
*tgt
;
674 if (!may_follow_exec
)
677 /* Did this exec() follow a vfork()? If so, we must follow the
678 vfork now too. Do it before following the exec. */
679 if (follow_vfork_when_exec
&&
680 (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
))
682 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
683 follow_vfork (PIDGET (inferior_ptid
),
684 pending_follow
.fork_event
.child_pid
);
685 follow_vfork_when_exec
= 0;
686 saved_pid
= PIDGET (inferior_ptid
);
688 /* Did we follow the parent? If so, we're done. If we followed
689 the child then we must also follow its exec(). */
690 if (PIDGET (inferior_ptid
) == pending_follow
.fork_event
.parent_pid
)
694 /* This is an exec event that we actually wish to pay attention to.
695 Refresh our symbol table to the newly exec'd program, remove any
698 If there are breakpoints, they aren't really inserted now,
699 since the exec() transformed our inferior into a fresh set
702 We want to preserve symbolic breakpoints on the list, since
703 we have hopes that they can be reset after the new a.out's
704 symbol table is read.
706 However, any "raw" breakpoints must be removed from the list
707 (e.g., the solib bp's), since their address is probably invalid
710 And, we DON'T want to call delete_breakpoints() here, since
711 that may write the bp's "shadow contents" (the instruction
712 value that was overwritten witha TRAP instruction). Since
713 we now have a new a.out, those shadow contents aren't valid. */
714 update_breakpoints_after_exec ();
716 /* If there was one, it's gone now. We cannot truly step-to-next
717 statement through an exec(). */
718 step_resume_breakpoint
= NULL
;
719 step_range_start
= 0;
722 /* If there was one, it's gone now. */
723 through_sigtramp_breakpoint
= NULL
;
725 /* What is this a.out's name? */
726 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
728 /* We've followed the inferior through an exec. Therefore, the
729 inferior has essentially been killed & reborn. */
731 /* First collect the run target in effect. */
732 tgt
= find_run_target ();
733 /* If we can't find one, things are in a very strange state... */
735 error ("Could find run target to save before following exec");
737 gdb_flush (gdb_stdout
);
738 target_mourn_inferior ();
739 inferior_ptid
= pid_to_ptid (saved_pid
);
740 /* Because mourn_inferior resets inferior_ptid. */
743 /* That a.out is now the one to use. */
744 exec_file_attach (execd_pathname
, 0);
746 /* And also is where symbols can be found. */
747 symbol_file_add_main (execd_pathname
, 0);
749 /* Reset the shared library package. This ensures that we get
750 a shlib event when the child reaches "_start", at which point
751 the dld will have had a chance to initialize the child. */
752 #if defined(SOLIB_RESTART)
755 #ifdef SOLIB_CREATE_INFERIOR_HOOK
756 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
759 /* Reinsert all breakpoints. (Those which were symbolic have
760 been reset to the proper address in the new a.out, thanks
761 to symbol_file_command...) */
762 insert_breakpoints ();
764 /* The next resume of this inferior should bring it to the shlib
765 startup breakpoints. (If the user had also set bp's on
766 "main" from the old (parent) process, then they'll auto-
767 matically get reset there in the new process.) */
770 /* Non-zero if we just simulating a single-step. This is needed
771 because we cannot remove the breakpoints in the inferior process
772 until after the `wait' in `wait_for_inferior'. */
773 static int singlestep_breakpoints_inserted_p
= 0;
776 /* Things to clean up if we QUIT out of resume (). */
779 resume_cleanups (void *ignore
)
784 static const char schedlock_off
[] = "off";
785 static const char schedlock_on
[] = "on";
786 static const char schedlock_step
[] = "step";
787 static const char *scheduler_mode
= schedlock_off
;
788 static const char *scheduler_enums
[] =
797 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
799 if (c
->type
== set_cmd
)
800 if (!target_can_lock_scheduler
)
802 scheduler_mode
= schedlock_off
;
803 error ("Target '%s' cannot support this command.",
809 /* Resume the inferior, but allow a QUIT. This is useful if the user
810 wants to interrupt some lengthy single-stepping operation
811 (for child processes, the SIGINT goes to the inferior, and so
812 we get a SIGINT random_signal, but for remote debugging and perhaps
813 other targets, that's not true).
815 STEP nonzero if we should step (zero to continue instead).
816 SIG is the signal to give the inferior (zero for none). */
818 resume (int step
, enum target_signal sig
)
820 int should_resume
= 1;
821 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
824 #ifdef CANNOT_STEP_BREAKPOINT
825 /* Most targets can step a breakpoint instruction, thus executing it
826 normally. But if this one cannot, just continue and we will hit
828 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
832 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
833 over an instruction that causes a page fault without triggering
834 a hardware watchpoint. The kernel properly notices that it shouldn't
835 stop, because the hardware watchpoint is not triggered, but it forgets
836 the step request and continues the program normally.
837 Work around the problem by removing hardware watchpoints if a step is
838 requested, GDB will check for a hardware watchpoint trigger after the
840 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
841 remove_hw_watchpoints ();
844 /* Normally, by the time we reach `resume', the breakpoints are either
845 removed or inserted, as appropriate. The exception is if we're sitting
846 at a permanent breakpoint; we need to step over it, but permanent
847 breakpoints can't be removed. So we have to test for it here. */
848 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
849 SKIP_PERMANENT_BREAKPOINT ();
851 if (SOFTWARE_SINGLE_STEP_P () && step
)
853 /* Do it the hard way, w/temp breakpoints */
854 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
855 /* ...and don't ask hardware to do it. */
857 /* and do not pull these breakpoints until after a `wait' in
858 `wait_for_inferior' */
859 singlestep_breakpoints_inserted_p
= 1;
862 /* Handle any optimized stores to the inferior NOW... */
863 #ifdef DO_DEFERRED_STORES
867 /* If there were any forks/vforks/execs that were caught and are
868 now to be followed, then do so. */
869 switch (pending_follow
.kind
)
871 case (TARGET_WAITKIND_FORKED
):
872 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
873 follow_fork (PIDGET (inferior_ptid
),
874 pending_follow
.fork_event
.child_pid
);
877 case (TARGET_WAITKIND_VFORKED
):
879 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
881 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
882 follow_vfork (PIDGET (inferior_ptid
),
883 pending_follow
.fork_event
.child_pid
);
885 /* Did we follow the child, but not yet see the child's exec event?
886 If so, then it actually ought to be waiting for us; we respond to
887 parent vfork events. We don't actually want to resume the child
888 in this situation; we want to just get its exec event. */
889 if (!saw_child_exec
&&
890 (PIDGET (inferior_ptid
) == pending_follow
.fork_event
.child_pid
))
895 case (TARGET_WAITKIND_EXECD
):
896 /* If we saw a vfork event but couldn't follow it until we saw
897 an exec, then now might be the time! */
898 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
899 /* follow_exec is called as soon as the exec event is seen. */
906 /* Install inferior's terminal modes. */
907 target_terminal_inferior ();
913 if (use_thread_step_needed
&& thread_step_needed
)
915 /* We stopped on a BPT instruction;
916 don't continue other threads and
917 just step this thread. */
918 thread_step_needed
= 0;
920 if (!breakpoint_here_p (read_pc ()))
922 /* Breakpoint deleted: ok to do regular resume
923 where all the threads either step or continue. */
924 resume_ptid
= RESUME_ALL
;
930 warning ("Internal error, changing continue to step.");
931 remove_breakpoints ();
932 breakpoints_inserted
= 0;
936 resume_ptid
= inferior_ptid
;
941 /* Vanilla resume. */
942 if ((scheduler_mode
== schedlock_on
) ||
943 (scheduler_mode
== schedlock_step
&& step
!= 0))
944 resume_ptid
= inferior_ptid
;
946 resume_ptid
= RESUME_ALL
;
948 target_resume (resume_ptid
, step
, sig
);
951 discard_cleanups (old_cleanups
);
955 /* Clear out all variables saying what to do when inferior is continued.
956 First do this, then set the ones you want, then call `proceed'. */
959 clear_proceed_status (void)
962 step_range_start
= 0;
964 step_frame_address
= 0;
965 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
967 stop_soon_quietly
= 0;
968 proceed_to_finish
= 0;
969 breakpoint_proceeded
= 1; /* We're about to proceed... */
971 /* Discard any remaining commands or status from previous stop. */
972 bpstat_clear (&stop_bpstat
);
975 /* Basic routine for continuing the program in various fashions.
977 ADDR is the address to resume at, or -1 for resume where stopped.
978 SIGGNAL is the signal to give it, or 0 for none,
979 or -1 for act according to how it stopped.
980 STEP is nonzero if should trap after one instruction.
981 -1 means return after that and print nothing.
982 You should probably set various step_... variables
983 before calling here, if you are stepping.
985 You should call clear_proceed_status before calling proceed. */
988 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
993 step_start_function
= find_pc_function (read_pc ());
997 if (addr
== (CORE_ADDR
) -1)
999 /* If there is a breakpoint at the address we will resume at,
1000 step one instruction before inserting breakpoints
1001 so that we do not stop right away (and report a second
1002 hit at this breakpoint). */
1004 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
1007 #ifndef STEP_SKIPS_DELAY
1008 #define STEP_SKIPS_DELAY(pc) (0)
1009 #define STEP_SKIPS_DELAY_P (0)
1011 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
1012 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
1013 is slow (it needs to read memory from the target). */
1014 if (STEP_SKIPS_DELAY_P
1015 && breakpoint_here_p (read_pc () + 4)
1016 && STEP_SKIPS_DELAY (read_pc ()))
1023 /* New address; we don't need to single-step a thread
1024 over a breakpoint we just hit, 'cause we aren't
1025 continuing from there.
1027 It's not worth worrying about the case where a user
1028 asks for a "jump" at the current PC--if they get the
1029 hiccup of re-hiting a hit breakpoint, what else do
1031 thread_step_needed
= 0;
1034 #ifdef PREPARE_TO_PROCEED
1035 /* In a multi-threaded task we may select another thread
1036 and then continue or step.
1038 But if the old thread was stopped at a breakpoint, it
1039 will immediately cause another breakpoint stop without
1040 any execution (i.e. it will report a breakpoint hit
1041 incorrectly). So we must step over it first.
1043 PREPARE_TO_PROCEED checks the current thread against the thread
1044 that reported the most recent event. If a step-over is required
1045 it returns TRUE and sets the current thread to the old thread. */
1046 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
1049 thread_step_needed
= 1;
1052 #endif /* PREPARE_TO_PROCEED */
1055 if (trap_expected_after_continue
)
1057 /* If (step == 0), a trap will be automatically generated after
1058 the first instruction is executed. Force step one
1059 instruction to clear this condition. This should not occur
1060 if step is nonzero, but it is harmless in that case. */
1062 trap_expected_after_continue
= 0;
1064 #endif /* HP_OS_BUG */
1067 /* We will get a trace trap after one instruction.
1068 Continue it automatically and insert breakpoints then. */
1072 int temp
= insert_breakpoints ();
1075 print_sys_errmsg ("insert_breakpoints", temp
);
1076 error ("Cannot insert breakpoints.\n\
1077 The same program may be running in another process,\n\
1078 or you may have requested too many hardware\n\
1079 breakpoints and/or watchpoints.\n");
1082 breakpoints_inserted
= 1;
1085 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1086 stop_signal
= siggnal
;
1087 /* If this signal should not be seen by program,
1088 give it zero. Used for debugging signals. */
1089 else if (!signal_program
[stop_signal
])
1090 stop_signal
= TARGET_SIGNAL_0
;
1092 annotate_starting ();
1094 /* Make sure that output from GDB appears before output from the
1096 gdb_flush (gdb_stdout
);
1098 /* Resume inferior. */
1099 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1101 /* Wait for it to stop (if not standalone)
1102 and in any case decode why it stopped, and act accordingly. */
1103 /* Do this only if we are not using the event loop, or if the target
1104 does not support asynchronous execution. */
1105 if (!event_loop_p
|| !target_can_async_p ())
1107 wait_for_inferior ();
1112 /* Record the pc and sp of the program the last time it stopped.
1113 These are just used internally by wait_for_inferior, but need
1114 to be preserved over calls to it and cleared when the inferior
1116 static CORE_ADDR prev_pc
;
1117 static CORE_ADDR prev_func_start
;
1118 static char *prev_func_name
;
1121 /* Start remote-debugging of a machine over a serial link. */
1126 init_thread_list ();
1127 init_wait_for_inferior ();
1128 stop_soon_quietly
= 1;
1131 /* Always go on waiting for the target, regardless of the mode. */
1132 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1133 indicate to wait_for_inferior that a target should timeout if
1134 nothing is returned (instead of just blocking). Because of this,
1135 targets expecting an immediate response need to, internally, set
1136 things up so that the target_wait() is forced to eventually
1138 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1139 differentiate to its caller what the state of the target is after
1140 the initial open has been performed. Here we're assuming that
1141 the target has stopped. It should be possible to eventually have
1142 target_open() return to the caller an indication that the target
1143 is currently running and GDB state should be set to the same as
1144 for an async run. */
1145 wait_for_inferior ();
1149 /* Initialize static vars when a new inferior begins. */
1152 init_wait_for_inferior (void)
1154 /* These are meaningless until the first time through wait_for_inferior. */
1156 prev_func_start
= 0;
1157 prev_func_name
= NULL
;
1160 trap_expected_after_continue
= 0;
1162 breakpoints_inserted
= 0;
1163 breakpoint_init_inferior (inf_starting
);
1165 /* Don't confuse first call to proceed(). */
1166 stop_signal
= TARGET_SIGNAL_0
;
1168 /* The first resume is not following a fork/vfork/exec. */
1169 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1170 pending_follow
.fork_event
.saw_parent_fork
= 0;
1171 pending_follow
.fork_event
.saw_child_fork
= 0;
1172 pending_follow
.fork_event
.saw_child_exec
= 0;
1174 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1175 number_of_threads_in_syscalls
= 0;
1177 clear_proceed_status ();
1181 delete_breakpoint_current_contents (void *arg
)
1183 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1184 if (*breakpointp
!= NULL
)
1186 delete_breakpoint (*breakpointp
);
1187 *breakpointp
= NULL
;
1191 /* This enum encodes possible reasons for doing a target_wait, so that
1192 wfi can call target_wait in one place. (Ultimately the call will be
1193 moved out of the infinite loop entirely.) */
1197 infwait_normal_state
,
1198 infwait_thread_hop_state
,
1199 infwait_nullified_state
,
1200 infwait_nonstep_watch_state
1203 /* Why did the inferior stop? Used to print the appropriate messages
1204 to the interface from within handle_inferior_event(). */
1205 enum inferior_stop_reason
1207 /* We don't know why. */
1209 /* Step, next, nexti, stepi finished. */
1211 /* Found breakpoint. */
1213 /* Inferior terminated by signal. */
1215 /* Inferior exited. */
1217 /* Inferior received signal, and user asked to be notified. */
1221 /* This structure contains what used to be local variables in
1222 wait_for_inferior. Probably many of them can return to being
1223 locals in handle_inferior_event. */
1225 struct execution_control_state
1227 struct target_waitstatus ws
;
1228 struct target_waitstatus
*wp
;
1231 CORE_ADDR stop_func_start
;
1232 CORE_ADDR stop_func_end
;
1233 char *stop_func_name
;
1234 struct symtab_and_line sal
;
1235 int remove_breakpoints_on_following_step
;
1237 struct symtab
*current_symtab
;
1238 int handling_longjmp
; /* FIXME */
1240 ptid_t saved_inferior_ptid
;
1242 int stepping_through_solib_after_catch
;
1243 bpstat stepping_through_solib_catchpoints
;
1244 int enable_hw_watchpoints_after_wait
;
1245 int stepping_through_sigtramp
;
1246 int new_thread_event
;
1247 struct target_waitstatus tmpstatus
;
1248 enum infwait_states infwait_state
;
1253 void init_execution_control_state (struct execution_control_state
* ecs
);
1255 void handle_inferior_event (struct execution_control_state
* ecs
);
1257 static void check_sigtramp2 (struct execution_control_state
*ecs
);
1258 static void step_into_function (struct execution_control_state
*ecs
);
1259 static void step_over_function (struct execution_control_state
*ecs
);
1260 static void stop_stepping (struct execution_control_state
*ecs
);
1261 static void prepare_to_wait (struct execution_control_state
*ecs
);
1262 static void keep_going (struct execution_control_state
*ecs
);
1263 static void print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
);
1265 /* Wait for control to return from inferior to debugger.
1266 If inferior gets a signal, we may decide to start it up again
1267 instead of returning. That is why there is a loop in this function.
1268 When this function actually returns it means the inferior
1269 should be left stopped and GDB should read more commands. */
1272 wait_for_inferior (void)
1274 struct cleanup
*old_cleanups
;
1275 struct execution_control_state ecss
;
1276 struct execution_control_state
*ecs
;
1278 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1279 &step_resume_breakpoint
);
1280 make_cleanup (delete_breakpoint_current_contents
,
1281 &through_sigtramp_breakpoint
);
1283 /* wfi still stays in a loop, so it's OK just to take the address of
1284 a local to get the ecs pointer. */
1287 /* Fill in with reasonable starting values. */
1288 init_execution_control_state (ecs
);
1290 thread_step_needed
= 0;
1292 /* We'll update this if & when we switch to a new thread. */
1293 previous_inferior_ptid
= inferior_ptid
;
1295 overlay_cache_invalid
= 1;
1297 /* We have to invalidate the registers BEFORE calling target_wait
1298 because they can be loaded from the target while in target_wait.
1299 This makes remote debugging a bit more efficient for those
1300 targets that provide critical registers as part of their normal
1301 status mechanism. */
1303 registers_changed ();
1307 if (target_wait_hook
)
1308 ecs
->ptid
= target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
1310 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
1312 /* Now figure out what to do with the result of the result. */
1313 handle_inferior_event (ecs
);
1315 if (!ecs
->wait_some_more
)
1318 do_cleanups (old_cleanups
);
1321 /* Asynchronous version of wait_for_inferior. It is called by the
1322 event loop whenever a change of state is detected on the file
1323 descriptor corresponding to the target. It can be called more than
1324 once to complete a single execution command. In such cases we need
1325 to keep the state in a global variable ASYNC_ECSS. If it is the
1326 last time that this function is called for a single execution
1327 command, then report to the user that the inferior has stopped, and
1328 do the necessary cleanups. */
1330 struct execution_control_state async_ecss
;
1331 struct execution_control_state
*async_ecs
;
1334 fetch_inferior_event (void *client_data
)
1336 static struct cleanup
*old_cleanups
;
1338 async_ecs
= &async_ecss
;
1340 if (!async_ecs
->wait_some_more
)
1342 old_cleanups
= make_exec_cleanup (delete_step_resume_breakpoint
,
1343 &step_resume_breakpoint
);
1344 make_exec_cleanup (delete_breakpoint_current_contents
,
1345 &through_sigtramp_breakpoint
);
1347 /* Fill in with reasonable starting values. */
1348 init_execution_control_state (async_ecs
);
1350 thread_step_needed
= 0;
1352 /* We'll update this if & when we switch to a new thread. */
1353 previous_inferior_ptid
= inferior_ptid
;
1355 overlay_cache_invalid
= 1;
1357 /* We have to invalidate the registers BEFORE calling target_wait
1358 because they can be loaded from the target while in target_wait.
1359 This makes remote debugging a bit more efficient for those
1360 targets that provide critical registers as part of their normal
1361 status mechanism. */
1363 registers_changed ();
1366 if (target_wait_hook
)
1367 async_ecs
->ptid
= target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1369 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1371 /* Now figure out what to do with the result of the result. */
1372 handle_inferior_event (async_ecs
);
1374 if (!async_ecs
->wait_some_more
)
1376 /* Do only the cleanups that have been added by this
1377 function. Let the continuations for the commands do the rest,
1378 if there are any. */
1379 do_exec_cleanups (old_cleanups
);
1381 if (step_multi
&& stop_step
)
1382 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1384 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1388 /* Prepare an execution control state for looping through a
1389 wait_for_inferior-type loop. */
1392 init_execution_control_state (struct execution_control_state
*ecs
)
1394 /* ecs->another_trap? */
1395 ecs
->random_signal
= 0;
1396 ecs
->remove_breakpoints_on_following_step
= 0;
1397 ecs
->handling_longjmp
= 0; /* FIXME */
1398 ecs
->update_step_sp
= 0;
1399 ecs
->stepping_through_solib_after_catch
= 0;
1400 ecs
->stepping_through_solib_catchpoints
= NULL
;
1401 ecs
->enable_hw_watchpoints_after_wait
= 0;
1402 ecs
->stepping_through_sigtramp
= 0;
1403 ecs
->sal
= find_pc_line (prev_pc
, 0);
1404 ecs
->current_line
= ecs
->sal
.line
;
1405 ecs
->current_symtab
= ecs
->sal
.symtab
;
1406 ecs
->infwait_state
= infwait_normal_state
;
1407 ecs
->waiton_ptid
= pid_to_ptid (-1);
1408 ecs
->wp
= &(ecs
->ws
);
1411 /* Call this function before setting step_resume_breakpoint, as a
1412 sanity check. There should never be more than one step-resume
1413 breakpoint per thread, so we should never be setting a new
1414 step_resume_breakpoint when one is already active. */
1416 check_for_old_step_resume_breakpoint (void)
1418 if (step_resume_breakpoint
)
1419 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1422 /* Return the cached copy of the last pid/waitstatus returned by
1423 target_wait()/target_wait_hook(). The data is actually cached by
1424 handle_inferior_event(), which gets called immediately after
1425 target_wait()/target_wait_hook(). */
1428 get_last_target_status(ptid_t
*ptidp
, struct target_waitstatus
*status
)
1430 *ptidp
= target_last_wait_ptid
;
1431 *status
= target_last_waitstatus
;
1434 /* Switch thread contexts, maintaining "infrun state". */
1437 context_switch (struct execution_control_state
*ecs
)
1439 /* Caution: it may happen that the new thread (or the old one!)
1440 is not in the thread list. In this case we must not attempt
1441 to "switch context", or we run the risk that our context may
1442 be lost. This may happen as a result of the target module
1443 mishandling thread creation. */
1445 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1446 { /* Perform infrun state context switch: */
1447 /* Save infrun state for the old thread. */
1448 save_infrun_state (inferior_ptid
, prev_pc
,
1449 prev_func_start
, prev_func_name
,
1450 trap_expected
, step_resume_breakpoint
,
1451 through_sigtramp_breakpoint
, step_range_start
,
1452 step_range_end
, step_frame_address
,
1453 ecs
->handling_longjmp
, ecs
->another_trap
,
1454 ecs
->stepping_through_solib_after_catch
,
1455 ecs
->stepping_through_solib_catchpoints
,
1456 ecs
->stepping_through_sigtramp
,
1457 ecs
->current_line
, ecs
->current_symtab
,
1460 /* Load infrun state for the new thread. */
1461 load_infrun_state (ecs
->ptid
, &prev_pc
,
1462 &prev_func_start
, &prev_func_name
,
1463 &trap_expected
, &step_resume_breakpoint
,
1464 &through_sigtramp_breakpoint
, &step_range_start
,
1465 &step_range_end
, &step_frame_address
,
1466 &ecs
->handling_longjmp
, &ecs
->another_trap
,
1467 &ecs
->stepping_through_solib_after_catch
,
1468 &ecs
->stepping_through_solib_catchpoints
,
1469 &ecs
->stepping_through_sigtramp
,
1470 &ecs
->current_line
, &ecs
->current_symtab
,
1473 inferior_ptid
= ecs
->ptid
;
1477 /* Given an execution control state that has been freshly filled in
1478 by an event from the inferior, figure out what it means and take
1479 appropriate action. */
1482 handle_inferior_event (struct execution_control_state
*ecs
)
1485 int stepped_after_stopped_by_watchpoint
;
1487 /* Cache the last pid/waitstatus. */
1488 target_last_wait_ptid
= ecs
->ptid
;
1489 target_last_waitstatus
= *ecs
->wp
;
1491 /* Keep this extra brace for now, minimizes diffs. */
1493 switch (ecs
->infwait_state
)
1495 case infwait_thread_hop_state
:
1496 /* Cancel the waiton_ptid. */
1497 ecs
->waiton_ptid
= pid_to_ptid (-1);
1498 /* Fall thru to the normal_state case. */
1500 case infwait_normal_state
:
1501 /* Since we've done a wait, we have a new event. Don't
1502 carry over any expectations about needing to step over a
1504 thread_step_needed
= 0;
1506 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1507 is serviced in this loop, below. */
1508 if (ecs
->enable_hw_watchpoints_after_wait
)
1510 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1511 ecs
->enable_hw_watchpoints_after_wait
= 0;
1513 stepped_after_stopped_by_watchpoint
= 0;
1516 case infwait_nullified_state
:
1519 case infwait_nonstep_watch_state
:
1520 insert_breakpoints ();
1522 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1523 handle things like signals arriving and other things happening
1524 in combination correctly? */
1525 stepped_after_stopped_by_watchpoint
= 1;
1528 ecs
->infwait_state
= infwait_normal_state
;
1530 flush_cached_frames ();
1532 /* If it's a new process, add it to the thread database */
1534 ecs
->new_thread_event
= (! ptid_equal (ecs
->ptid
, inferior_ptid
)
1535 && ! in_thread_list (ecs
->ptid
));
1537 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1538 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1539 && ecs
->new_thread_event
)
1541 add_thread (ecs
->ptid
);
1544 ui_out_text (uiout
, "[New ");
1545 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->ptid
));
1546 ui_out_text (uiout
, "]\n");
1548 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs
->ptid
));
1552 /* NOTE: This block is ONLY meant to be invoked in case of a
1553 "thread creation event"! If it is invoked for any other
1554 sort of event (such as a new thread landing on a breakpoint),
1555 the event will be discarded, which is almost certainly
1558 To avoid this, the low-level module (eg. target_wait)
1559 should call in_thread_list and add_thread, so that the
1560 new thread is known by the time we get here. */
1562 /* We may want to consider not doing a resume here in order
1563 to give the user a chance to play with the new thread.
1564 It might be good to make that a user-settable option. */
1566 /* At this point, all threads are stopped (happens
1567 automatically in either the OS or the native code).
1568 Therefore we need to continue all threads in order to
1571 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1572 prepare_to_wait (ecs
);
1577 switch (ecs
->ws
.kind
)
1579 case TARGET_WAITKIND_LOADED
:
1580 /* Ignore gracefully during startup of the inferior, as it
1581 might be the shell which has just loaded some objects,
1582 otherwise add the symbols for the newly loaded objects. */
1584 if (!stop_soon_quietly
)
1586 /* Remove breakpoints, SOLIB_ADD might adjust
1587 breakpoint addresses via breakpoint_re_set. */
1588 if (breakpoints_inserted
)
1589 remove_breakpoints ();
1591 /* Check for any newly added shared libraries if we're
1592 supposed to be adding them automatically. */
1595 /* Switch terminal for any messages produced by
1596 breakpoint_re_set. */
1597 target_terminal_ours_for_output ();
1598 SOLIB_ADD (NULL
, 0, NULL
);
1599 target_terminal_inferior ();
1602 /* Reinsert breakpoints and continue. */
1603 if (breakpoints_inserted
)
1604 insert_breakpoints ();
1607 resume (0, TARGET_SIGNAL_0
);
1608 prepare_to_wait (ecs
);
1611 case TARGET_WAITKIND_SPURIOUS
:
1612 resume (0, TARGET_SIGNAL_0
);
1613 prepare_to_wait (ecs
);
1616 case TARGET_WAITKIND_EXITED
:
1617 target_terminal_ours (); /* Must do this before mourn anyway */
1618 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1620 /* Record the exit code in the convenience variable $_exitcode, so
1621 that the user can inspect this again later. */
1622 set_internalvar (lookup_internalvar ("_exitcode"),
1623 value_from_longest (builtin_type_int
,
1624 (LONGEST
) ecs
->ws
.value
.integer
));
1625 gdb_flush (gdb_stdout
);
1626 target_mourn_inferior ();
1627 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1628 stop_print_frame
= 0;
1629 stop_stepping (ecs
);
1632 case TARGET_WAITKIND_SIGNALLED
:
1633 stop_print_frame
= 0;
1634 stop_signal
= ecs
->ws
.value
.sig
;
1635 target_terminal_ours (); /* Must do this before mourn anyway */
1637 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1638 reach here unless the inferior is dead. However, for years
1639 target_kill() was called here, which hints that fatal signals aren't
1640 really fatal on some systems. If that's true, then some changes
1642 target_mourn_inferior ();
1644 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1645 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1646 stop_stepping (ecs
);
1649 /* The following are the only cases in which we keep going;
1650 the above cases end in a continue or goto. */
1651 case TARGET_WAITKIND_FORKED
:
1652 stop_signal
= TARGET_SIGNAL_TRAP
;
1653 pending_follow
.kind
= ecs
->ws
.kind
;
1655 /* Ignore fork events reported for the parent; we're only
1656 interested in reacting to forks of the child. Note that
1657 we expect the child's fork event to be available if we
1658 waited for it now. */
1659 if (ptid_equal (inferior_ptid
, ecs
->ptid
))
1661 pending_follow
.fork_event
.saw_parent_fork
= 1;
1662 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1663 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1664 prepare_to_wait (ecs
);
1669 pending_follow
.fork_event
.saw_child_fork
= 1;
1670 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1671 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1674 stop_pc
= read_pc_pid (ecs
->ptid
);
1675 ecs
->saved_inferior_ptid
= inferior_ptid
;
1676 inferior_ptid
= ecs
->ptid
;
1677 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1678 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1679 inferior_ptid
= ecs
->saved_inferior_ptid
;
1680 goto process_event_stop_test
;
1682 /* If this a platform which doesn't allow a debugger to touch a
1683 vfork'd inferior until after it exec's, then we'd best keep
1684 our fingers entirely off the inferior, other than continuing
1685 it. This has the unfortunate side-effect that catchpoints
1686 of vforks will be ignored. But since the platform doesn't
1687 allow the inferior be touched at vfork time, there's really
1689 case TARGET_WAITKIND_VFORKED
:
1690 stop_signal
= TARGET_SIGNAL_TRAP
;
1691 pending_follow
.kind
= ecs
->ws
.kind
;
1693 /* Is this a vfork of the parent? If so, then give any
1694 vfork catchpoints a chance to trigger now. (It's
1695 dangerous to do so if the child canot be touched until
1696 it execs, and the child has not yet exec'd. We probably
1697 should warn the user to that effect when the catchpoint
1699 if (ptid_equal (ecs
->ptid
, inferior_ptid
))
1701 pending_follow
.fork_event
.saw_parent_fork
= 1;
1702 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1703 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1706 /* If we've seen the child's vfork event but cannot really touch
1707 the child until it execs, then we must continue the child now.
1708 Else, give any vfork catchpoints a chance to trigger now. */
1711 pending_follow
.fork_event
.saw_child_fork
= 1;
1712 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1713 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1714 target_post_startup_inferior (
1715 pid_to_ptid (pending_follow
.fork_event
.child_pid
));
1716 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1717 if (follow_vfork_when_exec
)
1719 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1720 prepare_to_wait (ecs
);
1725 stop_pc
= read_pc ();
1726 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1727 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1728 goto process_event_stop_test
;
1730 case TARGET_WAITKIND_EXECD
:
1731 stop_signal
= TARGET_SIGNAL_TRAP
;
1733 /* Is this a target which reports multiple exec events per actual
1734 call to exec()? (HP-UX using ptrace does, for example.) If so,
1735 ignore all but the last one. Just resume the exec'r, and wait
1736 for the next exec event. */
1737 if (inferior_ignoring_leading_exec_events
)
1739 inferior_ignoring_leading_exec_events
--;
1740 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1741 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.parent_pid
);
1742 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1743 prepare_to_wait (ecs
);
1746 inferior_ignoring_leading_exec_events
=
1747 target_reported_exec_events_per_exec_call () - 1;
1749 pending_follow
.execd_pathname
=
1750 savestring (ecs
->ws
.value
.execd_pathname
,
1751 strlen (ecs
->ws
.value
.execd_pathname
));
1753 /* Did inferior_ptid exec, or did a (possibly not-yet-followed)
1754 child of a vfork exec?
1756 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1757 HP-UX, events associated with a vforking inferior come in
1758 threes: a vfork event for the child (always first), followed
1759 a vfork event for the parent and an exec event for the child.
1760 The latter two can come in either order.
1762 If we get the parent vfork event first, life's good: We follow
1763 either the parent or child, and then the child's exec event is
1766 But if we get the child's exec event first, then we delay
1767 responding to it until we handle the parent's vfork. Because,
1768 otherwise we can't satisfy a "catch vfork". */
1769 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1771 pending_follow
.fork_event
.saw_child_exec
= 1;
1773 /* On some targets, the child must be resumed before
1774 the parent vfork event is delivered. A single-step
1776 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1777 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1778 /* We expect the parent vfork event to be available now. */
1779 prepare_to_wait (ecs
);
1783 /* This causes the eventpoints and symbol table to be reset. Must
1784 do this now, before trying to determine whether to stop. */
1785 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1786 xfree (pending_follow
.execd_pathname
);
1788 stop_pc
= read_pc_pid (ecs
->ptid
);
1789 ecs
->saved_inferior_ptid
= inferior_ptid
;
1790 inferior_ptid
= ecs
->ptid
;
1791 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1792 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1793 inferior_ptid
= ecs
->saved_inferior_ptid
;
1794 goto process_event_stop_test
;
1796 /* These syscall events are returned on HP-UX, as part of its
1797 implementation of page-protection-based "hardware" watchpoints.
1798 HP-UX has unfortunate interactions between page-protections and
1799 some system calls. Our solution is to disable hardware watches
1800 when a system call is entered, and reenable them when the syscall
1801 completes. The downside of this is that we may miss the precise
1802 point at which a watched piece of memory is modified. "Oh well."
1804 Note that we may have multiple threads running, which may each
1805 enter syscalls at roughly the same time. Since we don't have a
1806 good notion currently of whether a watched piece of memory is
1807 thread-private, we'd best not have any page-protections active
1808 when any thread is in a syscall. Thus, we only want to reenable
1809 hardware watches when no threads are in a syscall.
1811 Also, be careful not to try to gather much state about a thread
1812 that's in a syscall. It's frequently a losing proposition. */
1813 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1814 number_of_threads_in_syscalls
++;
1815 if (number_of_threads_in_syscalls
== 1)
1817 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1819 resume (0, TARGET_SIGNAL_0
);
1820 prepare_to_wait (ecs
);
1823 /* Before examining the threads further, step this thread to
1824 get it entirely out of the syscall. (We get notice of the
1825 event when the thread is just on the verge of exiting a
1826 syscall. Stepping one instruction seems to get it back
1829 Note that although the logical place to reenable h/w watches
1830 is here, we cannot. We cannot reenable them before stepping
1831 the thread (this causes the next wait on the thread to hang).
1833 Nor can we enable them after stepping until we've done a wait.
1834 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1835 here, which will be serviced immediately after the target
1837 case TARGET_WAITKIND_SYSCALL_RETURN
:
1838 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1840 if (number_of_threads_in_syscalls
> 0)
1842 number_of_threads_in_syscalls
--;
1843 ecs
->enable_hw_watchpoints_after_wait
=
1844 (number_of_threads_in_syscalls
== 0);
1846 prepare_to_wait (ecs
);
1849 case TARGET_WAITKIND_STOPPED
:
1850 stop_signal
= ecs
->ws
.value
.sig
;
1853 /* We had an event in the inferior, but we are not interested
1854 in handling it at this level. The lower layers have already
1855 done what needs to be done, if anything. This case can
1856 occur only when the target is async or extended-async. One
1857 of the circumstamces for this to happen is when the
1858 inferior produces output for the console. The inferior has
1859 not stopped, and we are ignoring the event. */
1860 case TARGET_WAITKIND_IGNORE
:
1861 ecs
->wait_some_more
= 1;
1865 /* We may want to consider not doing a resume here in order to give
1866 the user a chance to play with the new thread. It might be good
1867 to make that a user-settable option. */
1869 /* At this point, all threads are stopped (happens automatically in
1870 either the OS or the native code). Therefore we need to continue
1871 all threads in order to make progress. */
1872 if (ecs
->new_thread_event
)
1874 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1875 prepare_to_wait (ecs
);
1879 stop_pc
= read_pc_pid (ecs
->ptid
);
1881 /* See if a thread hit a thread-specific breakpoint that was meant for
1882 another thread. If so, then step that thread past the breakpoint,
1885 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1887 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1888 ecs
->random_signal
= 0;
1889 else if (breakpoints_inserted
1890 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1892 ecs
->random_signal
= 0;
1893 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1898 /* Saw a breakpoint, but it was hit by the wrong thread.
1900 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->ptid
);
1902 remove_status
= remove_breakpoints ();
1903 /* Did we fail to remove breakpoints? If so, try
1904 to set the PC past the bp. (There's at least
1905 one situation in which we can fail to remove
1906 the bp's: On HP-UX's that use ttrace, we can't
1907 change the address space of a vforking child
1908 process until the child exits (well, okay, not
1909 then either :-) or execs. */
1910 if (remove_status
!= 0)
1912 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->ptid
);
1913 /* We need to restart all the threads now,
1914 * unles we're running in scheduler-locked mode.
1915 * Use currently_stepping to determine whether to
1918 /* FIXME MVS: is there any reason not to call resume()? */
1919 if (scheduler_mode
== schedlock_on
)
1920 target_resume (ecs
->ptid
,
1921 currently_stepping (ecs
),
1924 target_resume (RESUME_ALL
,
1925 currently_stepping (ecs
),
1927 prepare_to_wait (ecs
);
1932 breakpoints_inserted
= 0;
1933 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
1934 context_switch (ecs
);
1935 ecs
->waiton_ptid
= ecs
->ptid
;
1936 ecs
->wp
= &(ecs
->ws
);
1937 thread_step_needed
= 1;
1938 ecs
->another_trap
= 1;
1940 /* keep_stepping will call resume, and the
1941 combination of "thread_step_needed" and
1942 "ecs->another_trap" will cause resume to
1943 solo-step the thread. The subsequent trap
1944 event will be handled like any other singlestep
1947 ecs
->infwait_state
= infwait_thread_hop_state
;
1949 registers_changed ();
1955 /* This breakpoint matches--either it is the right
1956 thread or it's a generic breakpoint for all threads.
1957 Remember that we'll need to step just _this_ thread
1958 on any following user continuation! */
1959 thread_step_needed
= 1;
1964 ecs
->random_signal
= 1;
1966 /* See if something interesting happened to the non-current thread. If
1967 so, then switch to that thread, and eventually give control back to
1970 Note that if there's any kind of pending follow (i.e., of a fork,
1971 vfork or exec), we don't want to do this now. Rather, we'll let
1972 the next resume handle it. */
1973 if (! ptid_equal (ecs
->ptid
, inferior_ptid
) &&
1974 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1978 /* If it's a random signal for a non-current thread, notify user
1979 if he's expressed an interest. */
1980 if (ecs
->random_signal
1981 && signal_print
[stop_signal
])
1983 /* ??rehrauer: I don't understand the rationale for this code. If the
1984 inferior will stop as a result of this signal, then the act of handling
1985 the stop ought to print a message that's couches the stoppage in user
1986 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1987 won't stop as a result of the signal -- i.e., if the signal is merely
1988 a side-effect of something GDB's doing "under the covers" for the
1989 user, such as stepping threads over a breakpoint they shouldn't stop
1990 for -- then the message seems to be a serious annoyance at best.
1992 For now, remove the message altogether. */
1995 target_terminal_ours_for_output ();
1996 printf_filtered ("\nProgram received signal %s, %s.\n",
1997 target_signal_to_name (stop_signal
),
1998 target_signal_to_string (stop_signal
));
1999 gdb_flush (gdb_stdout
);
2003 /* If it's not SIGTRAP and not a signal we want to stop for, then
2004 continue the thread. */
2006 if (stop_signal
!= TARGET_SIGNAL_TRAP
2007 && !signal_stop
[stop_signal
])
2010 target_terminal_inferior ();
2012 /* Clear the signal if it should not be passed. */
2013 if (signal_program
[stop_signal
] == 0)
2014 stop_signal
= TARGET_SIGNAL_0
;
2016 target_resume (ecs
->ptid
, 0, stop_signal
);
2017 prepare_to_wait (ecs
);
2021 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
2022 and fall into the rest of wait_for_inferior(). */
2024 context_switch (ecs
);
2027 context_hook (pid_to_thread_id (ecs
->ptid
));
2029 flush_cached_frames ();
2032 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
2034 /* Pull the single step breakpoints out of the target. */
2035 SOFTWARE_SINGLE_STEP (0, 0);
2036 singlestep_breakpoints_inserted_p
= 0;
2039 /* If PC is pointing at a nullified instruction, then step beyond
2040 it so that the user won't be confused when GDB appears to be ready
2043 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
2044 if (INSTRUCTION_NULLIFIED
)
2046 registers_changed ();
2047 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
2049 /* We may have received a signal that we want to pass to
2050 the inferior; therefore, we must not clobber the waitstatus
2053 ecs
->infwait_state
= infwait_nullified_state
;
2054 ecs
->waiton_ptid
= ecs
->ptid
;
2055 ecs
->wp
= &(ecs
->tmpstatus
);
2056 prepare_to_wait (ecs
);
2060 /* It may not be necessary to disable the watchpoint to stop over
2061 it. For example, the PA can (with some kernel cooperation)
2062 single step over a watchpoint without disabling the watchpoint. */
2063 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2066 prepare_to_wait (ecs
);
2070 /* It is far more common to need to disable a watchpoint to step
2071 the inferior over it. FIXME. What else might a debug
2072 register or page protection watchpoint scheme need here? */
2073 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2075 /* At this point, we are stopped at an instruction which has
2076 attempted to write to a piece of memory under control of
2077 a watchpoint. The instruction hasn't actually executed
2078 yet. If we were to evaluate the watchpoint expression
2079 now, we would get the old value, and therefore no change
2080 would seem to have occurred.
2082 In order to make watchpoints work `right', we really need
2083 to complete the memory write, and then evaluate the
2084 watchpoint expression. The following code does that by
2085 removing the watchpoint (actually, all watchpoints and
2086 breakpoints), single-stepping the target, re-inserting
2087 watchpoints, and then falling through to let normal
2088 single-step processing handle proceed. Since this
2089 includes evaluating watchpoints, things will come to a
2090 stop in the correct manner. */
2092 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
2094 remove_breakpoints ();
2095 registers_changed ();
2096 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
2098 ecs
->waiton_ptid
= ecs
->ptid
;
2099 ecs
->wp
= &(ecs
->ws
);
2100 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2101 prepare_to_wait (ecs
);
2105 /* It may be possible to simply continue after a watchpoint. */
2106 if (HAVE_CONTINUABLE_WATCHPOINT
)
2107 STOPPED_BY_WATCHPOINT (ecs
->ws
);
2109 ecs
->stop_func_start
= 0;
2110 ecs
->stop_func_end
= 0;
2111 ecs
->stop_func_name
= 0;
2112 /* Don't care about return value; stop_func_start and stop_func_name
2113 will both be 0 if it doesn't work. */
2114 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2115 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2116 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
2117 ecs
->another_trap
= 0;
2118 bpstat_clear (&stop_bpstat
);
2120 stop_stack_dummy
= 0;
2121 stop_print_frame
= 1;
2122 ecs
->random_signal
= 0;
2123 stopped_by_random_signal
= 0;
2124 breakpoints_failed
= 0;
2126 /* Look at the cause of the stop, and decide what to do.
2127 The alternatives are:
2128 1) break; to really stop and return to the debugger,
2129 2) drop through to start up again
2130 (set ecs->another_trap to 1 to single step once)
2131 3) set ecs->random_signal to 1, and the decision between 1 and 2
2132 will be made according to the signal handling tables. */
2134 /* First, distinguish signals caused by the debugger from signals
2135 that have to do with the program's own actions.
2136 Note that breakpoint insns may cause SIGTRAP or SIGILL
2137 or SIGEMT, depending on the operating system version.
2138 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2139 and change it to SIGTRAP. */
2141 if (stop_signal
== TARGET_SIGNAL_TRAP
2142 || (breakpoints_inserted
&&
2143 (stop_signal
== TARGET_SIGNAL_ILL
2144 || stop_signal
== TARGET_SIGNAL_EMT
2146 || stop_soon_quietly
)
2148 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2150 stop_print_frame
= 0;
2151 stop_stepping (ecs
);
2154 if (stop_soon_quietly
)
2156 stop_stepping (ecs
);
2160 /* Don't even think about breakpoints
2161 if just proceeded over a breakpoint.
2163 However, if we are trying to proceed over a breakpoint
2164 and end up in sigtramp, then through_sigtramp_breakpoint
2165 will be set and we should check whether we've hit the
2167 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2168 && through_sigtramp_breakpoint
== NULL
)
2169 bpstat_clear (&stop_bpstat
);
2172 /* See if there is a breakpoint at the current PC. */
2173 stop_bpstat
= bpstat_stop_status
2175 /* Pass TRUE if our reason for stopping is something other
2176 than hitting a breakpoint. We do this by checking that
2177 1) stepping is going on and 2) we didn't hit a breakpoint
2178 in a signal handler without an intervening stop in
2179 sigtramp, which is detected by a new stack pointer value
2180 below any usual function calling stack adjustments. */
2181 (currently_stepping (ecs
)
2183 && INNER_THAN (read_sp (), (step_sp
- 16))))
2185 /* Following in case break condition called a
2187 stop_print_frame
= 1;
2190 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2192 = !(bpstat_explains_signal (stop_bpstat
)
2194 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2195 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2196 FRAME_FP (get_current_frame ())))
2197 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2202 = !(bpstat_explains_signal (stop_bpstat
)
2203 /* End of a stack dummy. Some systems (e.g. Sony
2204 news) give another signal besides SIGTRAP, so
2205 check here as well as above. */
2206 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2207 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2208 FRAME_FP (get_current_frame ())))
2210 if (!ecs
->random_signal
)
2211 stop_signal
= TARGET_SIGNAL_TRAP
;
2215 /* When we reach this point, we've pretty much decided
2216 that the reason for stopping must've been a random
2217 (unexpected) signal. */
2220 ecs
->random_signal
= 1;
2221 /* If a fork, vfork or exec event was seen, then there are two
2222 possible responses we can make:
2224 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2225 then we must stop now and issue a prompt. We will resume
2226 the inferior when the user tells us to.
2227 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2228 then we must resume the inferior now and keep checking.
2230 In either case, we must take appropriate steps to "follow" the
2231 the fork/vfork/exec when the inferior is resumed. For example,
2232 if follow-fork-mode is "child", then we must detach from the
2233 parent inferior and follow the new child inferior.
2235 In either case, setting pending_follow causes the next resume()
2236 to take the appropriate following action. */
2237 process_event_stop_test
:
2238 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2240 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2243 stop_signal
= TARGET_SIGNAL_0
;
2248 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2250 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2252 stop_signal
= TARGET_SIGNAL_0
;
2257 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2259 pending_follow
.kind
= ecs
->ws
.kind
;
2260 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2263 stop_signal
= TARGET_SIGNAL_0
;
2269 /* For the program's own signals, act according to
2270 the signal handling tables. */
2272 if (ecs
->random_signal
)
2274 /* Signal not for debugging purposes. */
2277 stopped_by_random_signal
= 1;
2279 if (signal_print
[stop_signal
])
2282 target_terminal_ours_for_output ();
2283 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2285 if (signal_stop
[stop_signal
])
2287 stop_stepping (ecs
);
2290 /* If not going to stop, give terminal back
2291 if we took it away. */
2293 target_terminal_inferior ();
2295 /* Clear the signal if it should not be passed. */
2296 if (signal_program
[stop_signal
] == 0)
2297 stop_signal
= TARGET_SIGNAL_0
;
2299 /* I'm not sure whether this needs to be check_sigtramp2 or
2300 whether it could/should be keep_going.
2302 This used to jump to step_over_function if we are stepping,
2305 Suppose the user does a `next' over a function call, and while
2306 that call is in progress, the inferior receives a signal for
2307 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2308 that case, when we reach this point, there is already a
2309 step-resume breakpoint established, right where it should be:
2310 immediately after the function call the user is "next"-ing
2311 over. If we call step_over_function now, two bad things
2314 - we'll create a new breakpoint, at wherever the current
2315 frame's return address happens to be. That could be
2316 anywhere, depending on what function call happens to be on
2317 the top of the stack at that point. Point is, it's probably
2318 not where we need it.
2320 - the existing step-resume breakpoint (which is at the correct
2321 address) will get orphaned: step_resume_breakpoint will point
2322 to the new breakpoint, and the old step-resume breakpoint
2323 will never be cleaned up.
2325 The old behavior was meant to help HP-UX single-step out of
2326 sigtramps. It would place the new breakpoint at prev_pc, which
2327 was certainly wrong. I don't know the details there, so fixing
2328 this probably breaks that. As with anything else, it's up to
2329 the HP-UX maintainer to furnish a fix that doesn't break other
2330 platforms. --JimB, 20 May 1999 */
2331 check_sigtramp2 (ecs
);
2336 /* Handle cases caused by hitting a breakpoint. */
2338 CORE_ADDR jmp_buf_pc
;
2339 struct bpstat_what what
;
2341 what
= bpstat_what (stop_bpstat
);
2343 if (what
.call_dummy
)
2345 stop_stack_dummy
= 1;
2347 trap_expected_after_continue
= 1;
2351 switch (what
.main_action
)
2353 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2354 /* If we hit the breakpoint at longjmp, disable it for the
2355 duration of this command. Then, install a temporary
2356 breakpoint at the target of the jmp_buf. */
2357 disable_longjmp_breakpoint ();
2358 remove_breakpoints ();
2359 breakpoints_inserted
= 0;
2360 if (!GET_LONGJMP_TARGET (&jmp_buf_pc
))
2366 /* Need to blow away step-resume breakpoint, as it
2367 interferes with us */
2368 if (step_resume_breakpoint
!= NULL
)
2370 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2372 /* Not sure whether we need to blow this away too, but probably
2373 it is like the step-resume breakpoint. */
2374 if (through_sigtramp_breakpoint
!= NULL
)
2376 delete_breakpoint (through_sigtramp_breakpoint
);
2377 through_sigtramp_breakpoint
= NULL
;
2381 /* FIXME - Need to implement nested temporary breakpoints */
2382 if (step_over_calls
> 0)
2383 set_longjmp_resume_breakpoint (jmp_buf_pc
,
2384 get_current_frame ());
2387 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2388 ecs
->handling_longjmp
= 1; /* FIXME */
2392 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2393 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2394 remove_breakpoints ();
2395 breakpoints_inserted
= 0;
2397 /* FIXME - Need to implement nested temporary breakpoints */
2399 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2400 step_frame_address
)))
2402 ecs
->another_trap
= 1;
2407 disable_longjmp_breakpoint ();
2408 ecs
->handling_longjmp
= 0; /* FIXME */
2409 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2411 /* else fallthrough */
2413 case BPSTAT_WHAT_SINGLE
:
2414 if (breakpoints_inserted
)
2416 thread_step_needed
= 1;
2417 remove_breakpoints ();
2419 breakpoints_inserted
= 0;
2420 ecs
->another_trap
= 1;
2421 /* Still need to check other stuff, at least the case
2422 where we are stepping and step out of the right range. */
2425 case BPSTAT_WHAT_STOP_NOISY
:
2426 stop_print_frame
= 1;
2428 /* We are about to nuke the step_resume_breakpoint and
2429 through_sigtramp_breakpoint via the cleanup chain, so
2430 no need to worry about it here. */
2432 stop_stepping (ecs
);
2435 case BPSTAT_WHAT_STOP_SILENT
:
2436 stop_print_frame
= 0;
2438 /* We are about to nuke the step_resume_breakpoint and
2439 through_sigtramp_breakpoint via the cleanup chain, so
2440 no need to worry about it here. */
2442 stop_stepping (ecs
);
2445 case BPSTAT_WHAT_STEP_RESUME
:
2446 /* This proably demands a more elegant solution, but, yeah
2449 This function's use of the simple variable
2450 step_resume_breakpoint doesn't seem to accomodate
2451 simultaneously active step-resume bp's, although the
2452 breakpoint list certainly can.
2454 If we reach here and step_resume_breakpoint is already
2455 NULL, then apparently we have multiple active
2456 step-resume bp's. We'll just delete the breakpoint we
2457 stopped at, and carry on.
2459 Correction: what the code currently does is delete a
2460 step-resume bp, but it makes no effort to ensure that
2461 the one deleted is the one currently stopped at. MVS */
2463 if (step_resume_breakpoint
== NULL
)
2465 step_resume_breakpoint
=
2466 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2468 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2471 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2472 if (through_sigtramp_breakpoint
)
2473 delete_breakpoint (through_sigtramp_breakpoint
);
2474 through_sigtramp_breakpoint
= NULL
;
2476 /* If were waiting for a trap, hitting the step_resume_break
2477 doesn't count as getting it. */
2479 ecs
->another_trap
= 1;
2482 case BPSTAT_WHAT_CHECK_SHLIBS
:
2483 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2486 /* Remove breakpoints, we eventually want to step over the
2487 shlib event breakpoint, and SOLIB_ADD might adjust
2488 breakpoint addresses via breakpoint_re_set. */
2489 if (breakpoints_inserted
)
2490 remove_breakpoints ();
2491 breakpoints_inserted
= 0;
2493 /* Check for any newly added shared libraries if we're
2494 supposed to be adding them automatically. */
2497 /* Switch terminal for any messages produced by
2498 breakpoint_re_set. */
2499 target_terminal_ours_for_output ();
2500 SOLIB_ADD (NULL
, 0, NULL
);
2501 target_terminal_inferior ();
2504 /* Try to reenable shared library breakpoints, additional
2505 code segments in shared libraries might be mapped in now. */
2506 re_enable_breakpoints_in_shlibs ();
2508 /* If requested, stop when the dynamic linker notifies
2509 gdb of events. This allows the user to get control
2510 and place breakpoints in initializer routines for
2511 dynamically loaded objects (among other things). */
2512 if (stop_on_solib_events
)
2514 stop_stepping (ecs
);
2518 /* If we stopped due to an explicit catchpoint, then the
2519 (see above) call to SOLIB_ADD pulled in any symbols
2520 from a newly-loaded library, if appropriate.
2522 We do want the inferior to stop, but not where it is
2523 now, which is in the dynamic linker callback. Rather,
2524 we would like it stop in the user's program, just after
2525 the call that caused this catchpoint to trigger. That
2526 gives the user a more useful vantage from which to
2527 examine their program's state. */
2528 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2530 /* ??rehrauer: If I could figure out how to get the
2531 right return PC from here, we could just set a temp
2532 breakpoint and resume. I'm not sure we can without
2533 cracking open the dld's shared libraries and sniffing
2534 their unwind tables and text/data ranges, and that's
2535 not a terribly portable notion.
2537 Until that time, we must step the inferior out of the
2538 dld callback, and also out of the dld itself (and any
2539 code or stubs in libdld.sl, such as "shl_load" and
2540 friends) until we reach non-dld code. At that point,
2541 we can stop stepping. */
2542 bpstat_get_triggered_catchpoints (stop_bpstat
,
2543 &ecs
->stepping_through_solib_catchpoints
);
2544 ecs
->stepping_through_solib_after_catch
= 1;
2546 /* Be sure to lift all breakpoints, so the inferior does
2547 actually step past this point... */
2548 ecs
->another_trap
= 1;
2553 /* We want to step over this breakpoint, then keep going. */
2554 ecs
->another_trap
= 1;
2561 case BPSTAT_WHAT_LAST
:
2562 /* Not a real code, but listed here to shut up gcc -Wall. */
2564 case BPSTAT_WHAT_KEEP_CHECKING
:
2569 /* We come here if we hit a breakpoint but should not
2570 stop for it. Possibly we also were stepping
2571 and should stop for that. So fall through and
2572 test for stepping. But, if not stepping,
2575 /* Are we stepping to get the inferior out of the dynamic
2576 linker's hook (and possibly the dld itself) after catching
2578 if (ecs
->stepping_through_solib_after_catch
)
2580 #if defined(SOLIB_ADD)
2581 /* Have we reached our destination? If not, keep going. */
2582 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2584 ecs
->another_trap
= 1;
2589 /* Else, stop and report the catchpoint(s) whose triggering
2590 caused us to begin stepping. */
2591 ecs
->stepping_through_solib_after_catch
= 0;
2592 bpstat_clear (&stop_bpstat
);
2593 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2594 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2595 stop_print_frame
= 1;
2596 stop_stepping (ecs
);
2600 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2602 /* This is the old way of detecting the end of the stack dummy.
2603 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2604 handled above. As soon as we can test it on all of them, all
2605 architectures should define it. */
2607 /* If this is the breakpoint at the end of a stack dummy,
2608 just stop silently, unless the user was doing an si/ni, in which
2609 case she'd better know what she's doing. */
2611 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2612 FRAME_FP (get_current_frame ()))
2615 stop_print_frame
= 0;
2616 stop_stack_dummy
= 1;
2618 trap_expected_after_continue
= 1;
2620 stop_stepping (ecs
);
2625 if (step_resume_breakpoint
)
2627 /* Having a step-resume breakpoint overrides anything
2628 else having to do with stepping commands until
2629 that breakpoint is reached. */
2630 /* I'm not sure whether this needs to be check_sigtramp2 or
2631 whether it could/should be keep_going. */
2632 check_sigtramp2 (ecs
);
2637 if (step_range_end
== 0)
2639 /* Likewise if we aren't even stepping. */
2640 /* I'm not sure whether this needs to be check_sigtramp2 or
2641 whether it could/should be keep_going. */
2642 check_sigtramp2 (ecs
);
2647 /* If stepping through a line, keep going if still within it.
2649 Note that step_range_end is the address of the first instruction
2650 beyond the step range, and NOT the address of the last instruction
2652 if (stop_pc
>= step_range_start
2653 && stop_pc
< step_range_end
)
2655 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2656 So definately need to check for sigtramp here. */
2657 check_sigtramp2 (ecs
);
2662 /* We stepped out of the stepping range. */
2664 /* If we are stepping at the source level and entered the runtime
2665 loader dynamic symbol resolution code, we keep on single stepping
2666 until we exit the run time loader code and reach the callee's
2668 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2670 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2672 if (pc_after_resolver
)
2674 /* Set up a step-resume breakpoint at the address
2675 indicated by SKIP_SOLIB_RESOLVER. */
2676 struct symtab_and_line sr_sal
;
2678 sr_sal
.pc
= pc_after_resolver
;
2680 check_for_old_step_resume_breakpoint ();
2681 step_resume_breakpoint
=
2682 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2683 if (breakpoints_inserted
)
2684 insert_breakpoints ();
2691 /* We can't update step_sp every time through the loop, because
2692 reading the stack pointer would slow down stepping too much.
2693 But we can update it every time we leave the step range. */
2694 ecs
->update_step_sp
= 1;
2696 /* Did we just take a signal? */
2697 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2698 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2699 && INNER_THAN (read_sp (), step_sp
))
2701 /* We've just taken a signal; go until we are back to
2702 the point where we took it and one more. */
2704 /* Note: The test above succeeds not only when we stepped
2705 into a signal handler, but also when we step past the last
2706 statement of a signal handler and end up in the return stub
2707 of the signal handler trampoline. To distinguish between
2708 these two cases, check that the frame is INNER_THAN the
2709 previous one below. pai/1997-09-11 */
2713 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2715 if (INNER_THAN (current_frame
, step_frame_address
))
2717 /* We have just taken a signal; go until we are back to
2718 the point where we took it and one more. */
2720 /* This code is needed at least in the following case:
2721 The user types "next" and then a signal arrives (before
2722 the "next" is done). */
2724 /* Note that if we are stopped at a breakpoint, then we need
2725 the step_resume breakpoint to override any breakpoints at
2726 the same location, so that we will still step over the
2727 breakpoint even though the signal happened. */
2728 struct symtab_and_line sr_sal
;
2731 sr_sal
.symtab
= NULL
;
2733 sr_sal
.pc
= prev_pc
;
2734 /* We could probably be setting the frame to
2735 step_frame_address; I don't think anyone thought to
2737 check_for_old_step_resume_breakpoint ();
2738 step_resume_breakpoint
=
2739 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2740 if (breakpoints_inserted
)
2741 insert_breakpoints ();
2745 /* We just stepped out of a signal handler and into
2746 its calling trampoline.
2748 Normally, we'd call step_over_function from
2749 here, but for some reason GDB can't unwind the
2750 stack correctly to find the real PC for the point
2751 user code where the signal trampoline will return
2752 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2753 But signal trampolines are pretty small stubs of
2754 code, anyway, so it's OK instead to just
2755 single-step out. Note: assuming such trampolines
2756 don't exhibit recursion on any platform... */
2757 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2758 &ecs
->stop_func_start
,
2759 &ecs
->stop_func_end
);
2760 /* Readjust stepping range */
2761 step_range_start
= ecs
->stop_func_start
;
2762 step_range_end
= ecs
->stop_func_end
;
2763 ecs
->stepping_through_sigtramp
= 1;
2768 /* If this is stepi or nexti, make sure that the stepping range
2769 gets us past that instruction. */
2770 if (step_range_end
== 1)
2771 /* FIXME: Does this run afoul of the code below which, if
2772 we step into the middle of a line, resets the stepping
2774 step_range_end
= (step_range_start
= prev_pc
) + 1;
2776 ecs
->remove_breakpoints_on_following_step
= 1;
2781 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2782 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2783 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2784 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2785 || ecs
->stop_func_name
== 0)
2787 /* It's a subroutine call. */
2789 if (step_over_calls
== STEP_OVER_NONE
)
2791 /* I presume that step_over_calls is only 0 when we're
2792 supposed to be stepping at the assembly language level
2793 ("stepi"). Just stop. */
2795 print_stop_reason (END_STEPPING_RANGE
, 0);
2796 stop_stepping (ecs
);
2800 if (step_over_calls
== STEP_OVER_ALL
|| IGNORE_HELPER_CALL (stop_pc
))
2802 /* We're doing a "next". */
2804 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2805 && INNER_THAN (step_frame_address
, read_sp()))
2806 /* We stepped out of a signal handler, and into its
2807 calling trampoline. This is misdetected as a
2808 subroutine call, but stepping over the signal
2809 trampoline isn't such a bad idea. In order to do
2810 that, we have to ignore the value in
2811 step_frame_address, since that doesn't represent the
2812 frame that'll reach when we return from the signal
2813 trampoline. Otherwise we'll probably continue to the
2814 end of the program. */
2815 step_frame_address
= 0;
2817 step_over_function (ecs
);
2822 /* If we are in a function call trampoline (a stub between
2823 the calling routine and the real function), locate the real
2824 function. That's what tells us (a) whether we want to step
2825 into it at all, and (b) what prologue we want to run to
2826 the end of, if we do step into it. */
2827 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2829 ecs
->stop_func_start
= tmp
;
2832 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2835 struct symtab_and_line xxx
;
2836 /* Why isn't this s_a_l called "sr_sal", like all of the
2837 other s_a_l's where this code is duplicated? */
2838 INIT_SAL (&xxx
); /* initialize to zeroes */
2840 xxx
.section
= find_pc_overlay (xxx
.pc
);
2841 check_for_old_step_resume_breakpoint ();
2842 step_resume_breakpoint
=
2843 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2844 insert_breakpoints ();
2850 /* If we have line number information for the function we
2851 are thinking of stepping into, step into it.
2853 If there are several symtabs at that PC (e.g. with include
2854 files), just want to know whether *any* of them have line
2855 numbers. find_pc_line handles this. */
2857 struct symtab_and_line tmp_sal
;
2859 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2860 if (tmp_sal
.line
!= 0)
2862 step_into_function (ecs
);
2867 /* If we have no line number and the step-stop-if-no-debug
2868 is set, we stop the step so that the user has a chance to
2869 switch in assembly mode. */
2870 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2873 print_stop_reason (END_STEPPING_RANGE
, 0);
2874 stop_stepping (ecs
);
2878 step_over_function (ecs
);
2884 /* We've wandered out of the step range. */
2886 ecs
->sal
= find_pc_line (stop_pc
, 0);
2888 if (step_range_end
== 1)
2890 /* It is stepi or nexti. We always want to stop stepping after
2893 print_stop_reason (END_STEPPING_RANGE
, 0);
2894 stop_stepping (ecs
);
2898 /* If we're in the return path from a shared library trampoline,
2899 we want to proceed through the trampoline when stepping. */
2900 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2904 /* Determine where this trampoline returns. */
2905 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2907 /* Only proceed through if we know where it's going. */
2910 /* And put the step-breakpoint there and go until there. */
2911 struct symtab_and_line sr_sal
;
2913 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2915 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2916 /* Do not specify what the fp should be when we stop
2917 since on some machines the prologue
2918 is where the new fp value is established. */
2919 check_for_old_step_resume_breakpoint ();
2920 step_resume_breakpoint
=
2921 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2922 if (breakpoints_inserted
)
2923 insert_breakpoints ();
2925 /* Restart without fiddling with the step ranges or
2932 if (ecs
->sal
.line
== 0)
2934 /* We have no line number information. That means to stop
2935 stepping (does this always happen right after one instruction,
2936 when we do "s" in a function with no line numbers,
2937 or can this happen as a result of a return or longjmp?). */
2939 print_stop_reason (END_STEPPING_RANGE
, 0);
2940 stop_stepping (ecs
);
2944 if ((stop_pc
== ecs
->sal
.pc
)
2945 && (ecs
->current_line
!= ecs
->sal
.line
|| ecs
->current_symtab
!= ecs
->sal
.symtab
))
2947 /* We are at the start of a different line. So stop. Note that
2948 we don't stop if we step into the middle of a different line.
2949 That is said to make things like for (;;) statements work
2952 print_stop_reason (END_STEPPING_RANGE
, 0);
2953 stop_stepping (ecs
);
2957 /* We aren't done stepping.
2959 Optimize by setting the stepping range to the line.
2960 (We might not be in the original line, but if we entered a
2961 new line in mid-statement, we continue stepping. This makes
2962 things like for(;;) statements work better.) */
2964 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2966 /* If this is the last line of the function, don't keep stepping
2967 (it would probably step us out of the function).
2968 This is particularly necessary for a one-line function,
2969 in which after skipping the prologue we better stop even though
2970 we will be in mid-line. */
2972 print_stop_reason (END_STEPPING_RANGE
, 0);
2973 stop_stepping (ecs
);
2976 step_range_start
= ecs
->sal
.pc
;
2977 step_range_end
= ecs
->sal
.end
;
2978 step_frame_address
= FRAME_FP (get_current_frame ());
2979 ecs
->current_line
= ecs
->sal
.line
;
2980 ecs
->current_symtab
= ecs
->sal
.symtab
;
2982 /* In the case where we just stepped out of a function into the middle
2983 of a line of the caller, continue stepping, but step_frame_address
2984 must be modified to current frame */
2986 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2987 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2988 step_frame_address
= current_frame
;
2993 } /* extra brace, to preserve old indentation */
2996 /* Are we in the middle of stepping? */
2999 currently_stepping (struct execution_control_state
*ecs
)
3001 return ((through_sigtramp_breakpoint
== NULL
3002 && !ecs
->handling_longjmp
3003 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
3005 || ecs
->stepping_through_solib_after_catch
3006 || bpstat_should_step ());
3010 check_sigtramp2 (struct execution_control_state
*ecs
)
3013 && IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
3014 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
3015 && INNER_THAN (read_sp (), step_sp
))
3017 /* What has happened here is that we have just stepped the
3018 inferior with a signal (because it is a signal which
3019 shouldn't make us stop), thus stepping into sigtramp.
3021 So we need to set a step_resume_break_address breakpoint and
3022 continue until we hit it, and then step. FIXME: This should
3023 be more enduring than a step_resume breakpoint; we should
3024 know that we will later need to keep going rather than
3025 re-hitting the breakpoint here (see the testsuite,
3026 gdb.base/signals.exp where it says "exceedingly difficult"). */
3028 struct symtab_and_line sr_sal
;
3030 INIT_SAL (&sr_sal
); /* initialize to zeroes */
3031 sr_sal
.pc
= prev_pc
;
3032 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3033 /* We perhaps could set the frame if we kept track of what the
3034 frame corresponding to prev_pc was. But we don't, so don't. */
3035 through_sigtramp_breakpoint
=
3036 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
3037 if (breakpoints_inserted
)
3038 insert_breakpoints ();
3040 ecs
->remove_breakpoints_on_following_step
= 1;
3041 ecs
->another_trap
= 1;
3045 /* Subroutine call with source code we should not step over. Do step
3046 to the first line of code in it. */
3049 step_into_function (struct execution_control_state
*ecs
)
3052 struct symtab_and_line sr_sal
;
3054 s
= find_pc_symtab (stop_pc
);
3055 if (s
&& s
->language
!= language_asm
)
3056 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
3058 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
3059 /* Use the step_resume_break to step until the end of the prologue,
3060 even if that involves jumps (as it seems to on the vax under
3062 /* If the prologue ends in the middle of a source line, continue to
3063 the end of that source line (if it is still within the function).
3064 Otherwise, just go to end of prologue. */
3065 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
3066 /* no, don't either. It skips any code that's legitimately on the
3070 && ecs
->sal
.pc
!= ecs
->stop_func_start
3071 && ecs
->sal
.end
< ecs
->stop_func_end
)
3072 ecs
->stop_func_start
= ecs
->sal
.end
;
3075 if (ecs
->stop_func_start
== stop_pc
)
3077 /* We are already there: stop now. */
3079 print_stop_reason (END_STEPPING_RANGE
, 0);
3080 stop_stepping (ecs
);
3085 /* Put the step-breakpoint there and go until there. */
3086 INIT_SAL (&sr_sal
); /* initialize to zeroes */
3087 sr_sal
.pc
= ecs
->stop_func_start
;
3088 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3089 /* Do not specify what the fp should be when we stop since on
3090 some machines the prologue is where the new fp value is
3092 check_for_old_step_resume_breakpoint ();
3093 step_resume_breakpoint
=
3094 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
3095 if (breakpoints_inserted
)
3096 insert_breakpoints ();
3098 /* And make sure stepping stops right away then. */
3099 step_range_end
= step_range_start
;
3104 /* We've just entered a callee, and we wish to resume until it returns
3105 to the caller. Setting a step_resume breakpoint on the return
3106 address will catch a return from the callee.
3108 However, if the callee is recursing, we want to be careful not to
3109 catch returns of those recursive calls, but only of THIS instance
3112 To do this, we set the step_resume bp's frame to our current
3113 caller's frame (step_frame_address, which is set by the "next" or
3114 "until" command, before execution begins). */
3117 step_over_function (struct execution_control_state
*ecs
)
3119 struct symtab_and_line sr_sal
;
3121 INIT_SAL (&sr_sal
); /* initialize to zeros */
3122 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3123 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3125 check_for_old_step_resume_breakpoint ();
3126 step_resume_breakpoint
=
3127 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
3129 if (step_frame_address
&& !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
3130 step_resume_breakpoint
->frame
= step_frame_address
;
3132 if (breakpoints_inserted
)
3133 insert_breakpoints ();
3137 stop_stepping (struct execution_control_state
*ecs
)
3139 if (target_has_execution
)
3141 /* Are we stopping for a vfork event? We only stop when we see
3142 the child's event. However, we may not yet have seen the
3143 parent's event. And, inferior_ptid is still set to the
3144 parent's pid, until we resume again and follow either the
3147 To ensure that we can really touch inferior_ptid (aka, the
3148 parent process) -- which calls to functions like read_pc
3149 implicitly do -- wait on the parent if necessary. */
3150 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3151 && !pending_follow
.fork_event
.saw_parent_fork
)
3157 if (target_wait_hook
)
3158 parent_ptid
= target_wait_hook (pid_to_ptid (-1), &(ecs
->ws
));
3160 parent_ptid
= target_wait (pid_to_ptid (-1), &(ecs
->ws
));
3162 while (! ptid_equal (parent_ptid
, inferior_ptid
));
3165 /* Assuming the inferior still exists, set these up for next
3166 time, just like we did above if we didn't break out of the
3168 prev_pc
= read_pc ();
3169 prev_func_start
= ecs
->stop_func_start
;
3170 prev_func_name
= ecs
->stop_func_name
;
3173 /* Let callers know we don't want to wait for the inferior anymore. */
3174 ecs
->wait_some_more
= 0;
3177 /* This function handles various cases where we need to continue
3178 waiting for the inferior. */
3179 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3182 keep_going (struct execution_control_state
*ecs
)
3184 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3185 vforked child between its creation and subsequent exit or call to
3186 exec(). However, I had big problems in this rather creaky exec
3187 engine, getting that to work. The fundamental problem is that
3188 I'm trying to debug two processes via an engine that only
3189 understands a single process with possibly multiple threads.
3191 Hence, this spot is known to have problems when
3192 target_can_follow_vfork_prior_to_exec returns 1. */
3194 /* Save the pc before execution, to compare with pc after stop. */
3195 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3196 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3197 BREAK is defined, the
3198 original pc would not have
3199 been at the start of a
3201 prev_func_name
= ecs
->stop_func_name
;
3203 if (ecs
->update_step_sp
)
3204 step_sp
= read_sp ();
3205 ecs
->update_step_sp
= 0;
3207 /* If we did not do break;, it means we should keep running the
3208 inferior and not return to debugger. */
3210 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3212 /* We took a signal (which we are supposed to pass through to
3213 the inferior, else we'd have done a break above) and we
3214 haven't yet gotten our trap. Simply continue. */
3215 resume (currently_stepping (ecs
), stop_signal
);
3219 /* Either the trap was not expected, but we are continuing
3220 anyway (the user asked that this signal be passed to the
3223 The signal was SIGTRAP, e.g. it was our signal, but we
3224 decided we should resume from it.
3226 We're going to run this baby now!
3228 Insert breakpoints now, unless we are trying to one-proceed
3229 past a breakpoint. */
3230 /* If we've just finished a special step resume and we don't
3231 want to hit a breakpoint, pull em out. */
3232 if (step_resume_breakpoint
== NULL
3233 && through_sigtramp_breakpoint
== NULL
3234 && ecs
->remove_breakpoints_on_following_step
)
3236 ecs
->remove_breakpoints_on_following_step
= 0;
3237 remove_breakpoints ();
3238 breakpoints_inserted
= 0;
3240 else if (!breakpoints_inserted
&&
3241 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3243 breakpoints_failed
= insert_breakpoints ();
3244 if (breakpoints_failed
)
3246 stop_stepping (ecs
);
3249 breakpoints_inserted
= 1;
3252 trap_expected
= ecs
->another_trap
;
3254 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3255 specifies that such a signal should be delivered to the
3258 Typically, this would occure when a user is debugging a
3259 target monitor on a simulator: the target monitor sets a
3260 breakpoint; the simulator encounters this break-point and
3261 halts the simulation handing control to GDB; GDB, noteing
3262 that the break-point isn't valid, returns control back to the
3263 simulator; the simulator then delivers the hardware
3264 equivalent of a SIGNAL_TRAP to the program being debugged. */
3266 if (stop_signal
== TARGET_SIGNAL_TRAP
3267 && !signal_program
[stop_signal
])
3268 stop_signal
= TARGET_SIGNAL_0
;
3270 #ifdef SHIFT_INST_REGS
3271 /* I'm not sure when this following segment applies. I do know,
3272 now, that we shouldn't rewrite the regs when we were stopped
3273 by a random signal from the inferior process. */
3274 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3275 (this is only used on the 88k). */
3277 if (!bpstat_explains_signal (stop_bpstat
)
3278 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
3279 && !stopped_by_random_signal
)
3281 #endif /* SHIFT_INST_REGS */
3283 resume (currently_stepping (ecs
), stop_signal
);
3286 prepare_to_wait (ecs
);
3289 /* This function normally comes after a resume, before
3290 handle_inferior_event exits. It takes care of any last bits of
3291 housekeeping, and sets the all-important wait_some_more flag. */
3294 prepare_to_wait (struct execution_control_state
*ecs
)
3296 if (ecs
->infwait_state
== infwait_normal_state
)
3298 overlay_cache_invalid
= 1;
3300 /* We have to invalidate the registers BEFORE calling
3301 target_wait because they can be loaded from the target while
3302 in target_wait. This makes remote debugging a bit more
3303 efficient for those targets that provide critical registers
3304 as part of their normal status mechanism. */
3306 registers_changed ();
3307 ecs
->waiton_ptid
= pid_to_ptid (-1);
3308 ecs
->wp
= &(ecs
->ws
);
3310 /* This is the old end of the while loop. Let everybody know we
3311 want to wait for the inferior some more and get called again
3313 ecs
->wait_some_more
= 1;
3316 /* Print why the inferior has stopped. We always print something when
3317 the inferior exits, or receives a signal. The rest of the cases are
3318 dealt with later on in normal_stop() and print_it_typical(). Ideally
3319 there should be a call to this function from handle_inferior_event()
3320 each time stop_stepping() is called.*/
3322 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3324 switch (stop_reason
)
3327 /* We don't deal with these cases from handle_inferior_event()
3330 case END_STEPPING_RANGE
:
3331 /* We are done with a step/next/si/ni command. */
3332 /* For now print nothing. */
3334 /* Print a message only if not in the middle of doing a "step n"
3335 operation for n > 1 */
3336 if (!step_multi
|| !stop_step
)
3337 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3338 ui_out_field_string (uiout
, "reason", "end-stepping-range");
3341 case BREAKPOINT_HIT
:
3342 /* We found a breakpoint. */
3343 /* For now print nothing. */
3346 /* The inferior was terminated by a signal. */
3348 annotate_signalled ();
3349 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3350 ui_out_field_string (uiout
, "reason", "exited-signalled");
3351 ui_out_text (uiout
, "\nProgram terminated with signal ");
3352 annotate_signal_name ();
3353 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3354 annotate_signal_name_end ();
3355 ui_out_text (uiout
, ", ");
3356 annotate_signal_string ();
3357 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3358 annotate_signal_string_end ();
3359 ui_out_text (uiout
, ".\n");
3360 ui_out_text (uiout
, "The program no longer exists.\n");
3362 annotate_signalled ();
3363 printf_filtered ("\nProgram terminated with signal ");
3364 annotate_signal_name ();
3365 printf_filtered ("%s", target_signal_to_name (stop_info
));
3366 annotate_signal_name_end ();
3367 printf_filtered (", ");
3368 annotate_signal_string ();
3369 printf_filtered ("%s", target_signal_to_string (stop_info
));
3370 annotate_signal_string_end ();
3371 printf_filtered (".\n");
3373 printf_filtered ("The program no longer exists.\n");
3374 gdb_flush (gdb_stdout
);
3378 /* The inferior program is finished. */
3380 annotate_exited (stop_info
);
3383 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3384 ui_out_field_string (uiout
, "reason", "exited");
3385 ui_out_text (uiout
, "\nProgram exited with code ");
3386 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) stop_info
);
3387 ui_out_text (uiout
, ".\n");
3391 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3392 ui_out_field_string (uiout
, "reason", "exited-normally");
3393 ui_out_text (uiout
, "\nProgram exited normally.\n");
3396 annotate_exited (stop_info
);
3398 printf_filtered ("\nProgram exited with code 0%o.\n",
3399 (unsigned int) stop_info
);
3401 printf_filtered ("\nProgram exited normally.\n");
3404 case SIGNAL_RECEIVED
:
3405 /* Signal received. The signal table tells us to print about
3409 ui_out_text (uiout
, "\nProgram received signal ");
3410 annotate_signal_name ();
3411 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3412 annotate_signal_name_end ();
3413 ui_out_text (uiout
, ", ");
3414 annotate_signal_string ();
3415 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3416 annotate_signal_string_end ();
3417 ui_out_text (uiout
, ".\n");
3420 printf_filtered ("\nProgram received signal ");
3421 annotate_signal_name ();
3422 printf_filtered ("%s", target_signal_to_name (stop_info
));
3423 annotate_signal_name_end ();
3424 printf_filtered (", ");
3425 annotate_signal_string ();
3426 printf_filtered ("%s", target_signal_to_string (stop_info
));
3427 annotate_signal_string_end ();
3428 printf_filtered (".\n");
3429 gdb_flush (gdb_stdout
);
3433 internal_error (__FILE__
, __LINE__
,
3434 "print_stop_reason: unrecognized enum value");
3440 /* Here to return control to GDB when the inferior stops for real.
3441 Print appropriate messages, remove breakpoints, give terminal our modes.
3443 STOP_PRINT_FRAME nonzero means print the executing frame
3444 (pc, function, args, file, line number and line text).
3445 BREAKPOINTS_FAILED nonzero means stop was due to error
3446 attempting to insert breakpoints. */
3451 /* As with the notification of thread events, we want to delay
3452 notifying the user that we've switched thread context until
3453 the inferior actually stops.
3455 (Note that there's no point in saying anything if the inferior
3457 if (! ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3458 && target_has_execution
)
3460 target_terminal_ours_for_output ();
3461 printf_filtered ("[Switching to %s]\n",
3462 target_pid_or_tid_to_str (inferior_ptid
));
3463 previous_inferior_ptid
= inferior_ptid
;
3466 /* Make sure that the current_frame's pc is correct. This
3467 is a correction for setting up the frame info before doing
3468 DECR_PC_AFTER_BREAK */
3469 if (target_has_execution
&& get_current_frame ())
3470 (get_current_frame ())->pc
= read_pc ();
3472 if (breakpoints_failed
)
3474 target_terminal_ours_for_output ();
3475 print_sys_errmsg ("While inserting breakpoints", breakpoints_failed
);
3476 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3477 The same program may be running in another process,\n\
3478 or you may have requested too many hardware breakpoints\n\
3479 and/or watchpoints.\n");
3482 if (target_has_execution
&& breakpoints_inserted
)
3484 if (remove_breakpoints ())
3486 target_terminal_ours_for_output ();
3487 printf_filtered ("Cannot remove breakpoints because ");
3488 printf_filtered ("program is no longer writable.\n");
3489 printf_filtered ("It might be running in another process.\n");
3490 printf_filtered ("Further execution is probably impossible.\n");
3493 breakpoints_inserted
= 0;
3495 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3496 Delete any breakpoint that is to be deleted at the next stop. */
3498 breakpoint_auto_delete (stop_bpstat
);
3500 /* If an auto-display called a function and that got a signal,
3501 delete that auto-display to avoid an infinite recursion. */
3503 if (stopped_by_random_signal
)
3504 disable_current_display ();
3506 /* Don't print a message if in the middle of doing a "step n"
3507 operation for n > 1 */
3508 if (step_multi
&& stop_step
)
3511 target_terminal_ours ();
3513 /* Look up the hook_stop and run it if it exists. */
3515 if (stop_command
&& stop_command
->hook_pre
)
3517 catch_errors (hook_stop_stub
, stop_command
->hook_pre
,
3518 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3521 if (!target_has_stack
)
3527 /* Select innermost stack frame - i.e., current frame is frame 0,
3528 and current location is based on that.
3529 Don't do this on return from a stack dummy routine,
3530 or if the program has exited. */
3532 if (!stop_stack_dummy
)
3534 select_frame (get_current_frame (), 0);
3536 /* Print current location without a level number, if
3537 we have changed functions or hit a breakpoint.
3538 Print source line if we have one.
3539 bpstat_print() contains the logic deciding in detail
3540 what to print, based on the event(s) that just occurred. */
3542 if (stop_print_frame
3547 int do_frame_printing
= 1;
3549 bpstat_ret
= bpstat_print (stop_bpstat
);
3554 && step_frame_address
== FRAME_FP (get_current_frame ())
3555 && step_start_function
== find_pc_function (stop_pc
))
3556 source_flag
= SRC_LINE
; /* finished step, just print source line */
3558 source_flag
= SRC_AND_LOC
; /* print location and source line */
3560 case PRINT_SRC_AND_LOC
:
3561 source_flag
= SRC_AND_LOC
; /* print location and source line */
3563 case PRINT_SRC_ONLY
:
3564 source_flag
= SRC_LINE
;
3567 source_flag
= SRC_LINE
; /* something bogus */
3568 do_frame_printing
= 0;
3571 internal_error (__FILE__
, __LINE__
,
3575 /* For mi, have the same behavior every time we stop:
3576 print everything but the source line. */
3577 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3578 source_flag
= LOC_AND_ADDRESS
;
3582 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3583 ui_out_field_int (uiout
, "thread-id",
3584 pid_to_thread_id (inferior_ptid
));
3586 /* The behavior of this routine with respect to the source
3588 SRC_LINE: Print only source line
3589 LOCATION: Print only location
3590 SRC_AND_LOC: Print location and source line */
3591 if (do_frame_printing
)
3592 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
3594 /* Display the auto-display expressions. */
3599 /* Save the function value return registers, if we care.
3600 We might be about to restore their previous contents. */
3601 if (proceed_to_finish
)
3602 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
3604 if (stop_stack_dummy
)
3606 /* Pop the empty frame that contains the stack dummy.
3607 POP_FRAME ends with a setting of the current frame, so we
3608 can use that next. */
3610 /* Set stop_pc to what it was before we called the function.
3611 Can't rely on restore_inferior_status because that only gets
3612 called if we don't stop in the called function. */
3613 stop_pc
= read_pc ();
3614 select_frame (get_current_frame (), 0);
3618 TUIDO (((TuiOpaqueFuncPtr
) tui_vCheckDataValues
, selected_frame
));
3621 annotate_stopped ();
3625 hook_stop_stub (void *cmd
)
3627 execute_user_command ((struct cmd_list_element
*) cmd
, 0);
3632 signal_stop_state (int signo
)
3634 return signal_stop
[signo
];
3638 signal_print_state (int signo
)
3640 return signal_print
[signo
];
3644 signal_pass_state (int signo
)
3646 return signal_program
[signo
];
3649 int signal_stop_update (signo
, state
)
3653 int ret
= signal_stop
[signo
];
3654 signal_stop
[signo
] = state
;
3658 int signal_print_update (signo
, state
)
3662 int ret
= signal_print
[signo
];
3663 signal_print
[signo
] = state
;
3667 int signal_pass_update (signo
, state
)
3671 int ret
= signal_program
[signo
];
3672 signal_program
[signo
] = state
;
3677 sig_print_header (void)
3680 Signal Stop\tPrint\tPass to program\tDescription\n");
3684 sig_print_info (enum target_signal oursig
)
3686 char *name
= target_signal_to_name (oursig
);
3687 int name_padding
= 13 - strlen (name
);
3689 if (name_padding
<= 0)
3692 printf_filtered ("%s", name
);
3693 printf_filtered ("%*.*s ", name_padding
, name_padding
,
3695 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3696 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3697 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3698 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3701 /* Specify how various signals in the inferior should be handled. */
3704 handle_command (char *args
, int from_tty
)
3707 int digits
, wordlen
;
3708 int sigfirst
, signum
, siglast
;
3709 enum target_signal oursig
;
3712 unsigned char *sigs
;
3713 struct cleanup
*old_chain
;
3717 error_no_arg ("signal to handle");
3720 /* Allocate and zero an array of flags for which signals to handle. */
3722 nsigs
= (int) TARGET_SIGNAL_LAST
;
3723 sigs
= (unsigned char *) alloca (nsigs
);
3724 memset (sigs
, 0, nsigs
);
3726 /* Break the command line up into args. */
3728 argv
= buildargv (args
);
3733 old_chain
= make_cleanup_freeargv (argv
);
3735 /* Walk through the args, looking for signal oursigs, signal names, and
3736 actions. Signal numbers and signal names may be interspersed with
3737 actions, with the actions being performed for all signals cumulatively
3738 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3740 while (*argv
!= NULL
)
3742 wordlen
= strlen (*argv
);
3743 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3747 sigfirst
= siglast
= -1;
3749 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3751 /* Apply action to all signals except those used by the
3752 debugger. Silently skip those. */
3755 siglast
= nsigs
- 1;
3757 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3759 SET_SIGS (nsigs
, sigs
, signal_stop
);
3760 SET_SIGS (nsigs
, sigs
, signal_print
);
3762 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3764 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3766 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3768 SET_SIGS (nsigs
, sigs
, signal_print
);
3770 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3772 SET_SIGS (nsigs
, sigs
, signal_program
);
3774 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3776 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3778 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3780 SET_SIGS (nsigs
, sigs
, signal_program
);
3782 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3784 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3785 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3787 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3789 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3791 else if (digits
> 0)
3793 /* It is numeric. The numeric signal refers to our own
3794 internal signal numbering from target.h, not to host/target
3795 signal number. This is a feature; users really should be
3796 using symbolic names anyway, and the common ones like
3797 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3799 sigfirst
= siglast
= (int)
3800 target_signal_from_command (atoi (*argv
));
3801 if ((*argv
)[digits
] == '-')
3804 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3806 if (sigfirst
> siglast
)
3808 /* Bet he didn't figure we'd think of this case... */
3816 oursig
= target_signal_from_name (*argv
);
3817 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3819 sigfirst
= siglast
= (int) oursig
;
3823 /* Not a number and not a recognized flag word => complain. */
3824 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3828 /* If any signal numbers or symbol names were found, set flags for
3829 which signals to apply actions to. */
3831 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3833 switch ((enum target_signal
) signum
)
3835 case TARGET_SIGNAL_TRAP
:
3836 case TARGET_SIGNAL_INT
:
3837 if (!allsigs
&& !sigs
[signum
])
3839 if (query ("%s is used by the debugger.\n\
3840 Are you sure you want to change it? ",
3841 target_signal_to_name
3842 ((enum target_signal
) signum
)))
3848 printf_unfiltered ("Not confirmed, unchanged.\n");
3849 gdb_flush (gdb_stdout
);
3853 case TARGET_SIGNAL_0
:
3854 case TARGET_SIGNAL_DEFAULT
:
3855 case TARGET_SIGNAL_UNKNOWN
:
3856 /* Make sure that "all" doesn't print these. */
3867 target_notice_signals (inferior_ptid
);
3871 /* Show the results. */
3872 sig_print_header ();
3873 for (signum
= 0; signum
< nsigs
; signum
++)
3877 sig_print_info (signum
);
3882 do_cleanups (old_chain
);
3886 xdb_handle_command (char *args
, int from_tty
)
3889 struct cleanup
*old_chain
;
3891 /* Break the command line up into args. */
3893 argv
= buildargv (args
);
3898 old_chain
= make_cleanup_freeargv (argv
);
3899 if (argv
[1] != (char *) NULL
)
3904 bufLen
= strlen (argv
[0]) + 20;
3905 argBuf
= (char *) xmalloc (bufLen
);
3909 enum target_signal oursig
;
3911 oursig
= target_signal_from_name (argv
[0]);
3912 memset (argBuf
, 0, bufLen
);
3913 if (strcmp (argv
[1], "Q") == 0)
3914 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3917 if (strcmp (argv
[1], "s") == 0)
3919 if (!signal_stop
[oursig
])
3920 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3922 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3924 else if (strcmp (argv
[1], "i") == 0)
3926 if (!signal_program
[oursig
])
3927 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3929 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3931 else if (strcmp (argv
[1], "r") == 0)
3933 if (!signal_print
[oursig
])
3934 sprintf (argBuf
, "%s %s", argv
[0], "print");
3936 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3942 handle_command (argBuf
, from_tty
);
3944 printf_filtered ("Invalid signal handling flag.\n");
3949 do_cleanups (old_chain
);
3952 /* Print current contents of the tables set by the handle command.
3953 It is possible we should just be printing signals actually used
3954 by the current target (but for things to work right when switching
3955 targets, all signals should be in the signal tables). */
3958 signals_info (char *signum_exp
, int from_tty
)
3960 enum target_signal oursig
;
3961 sig_print_header ();
3965 /* First see if this is a symbol name. */
3966 oursig
= target_signal_from_name (signum_exp
);
3967 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3969 /* No, try numeric. */
3971 target_signal_from_command (parse_and_eval_long (signum_exp
));
3973 sig_print_info (oursig
);
3977 printf_filtered ("\n");
3978 /* These ugly casts brought to you by the native VAX compiler. */
3979 for (oursig
= TARGET_SIGNAL_FIRST
;
3980 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3981 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3985 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3986 && oursig
!= TARGET_SIGNAL_DEFAULT
3987 && oursig
!= TARGET_SIGNAL_0
)
3988 sig_print_info (oursig
);
3991 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3994 struct inferior_status
3996 enum target_signal stop_signal
;
4000 int stop_stack_dummy
;
4001 int stopped_by_random_signal
;
4003 CORE_ADDR step_range_start
;
4004 CORE_ADDR step_range_end
;
4005 CORE_ADDR step_frame_address
;
4006 enum step_over_calls_kind step_over_calls
;
4007 CORE_ADDR step_resume_break_address
;
4008 int stop_after_trap
;
4009 int stop_soon_quietly
;
4010 CORE_ADDR selected_frame_address
;
4011 char *stop_registers
;
4013 /* These are here because if call_function_by_hand has written some
4014 registers and then decides to call error(), we better not have changed
4019 int breakpoint_proceeded
;
4020 int restore_stack_info
;
4021 int proceed_to_finish
;
4024 static struct inferior_status
*
4025 xmalloc_inferior_status (void)
4027 struct inferior_status
*inf_status
;
4028 inf_status
= xmalloc (sizeof (struct inferior_status
));
4029 inf_status
->stop_registers
= xmalloc (REGISTER_BYTES
);
4030 inf_status
->registers
= xmalloc (REGISTER_BYTES
);
4035 free_inferior_status (struct inferior_status
*inf_status
)
4037 xfree (inf_status
->registers
);
4038 xfree (inf_status
->stop_registers
);
4043 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
4046 int size
= REGISTER_RAW_SIZE (regno
);
4047 void *buf
= alloca (size
);
4048 store_signed_integer (buf
, size
, val
);
4049 memcpy (&inf_status
->registers
[REGISTER_BYTE (regno
)], buf
, size
);
4052 /* Save all of the information associated with the inferior<==>gdb
4053 connection. INF_STATUS is a pointer to a "struct inferior_status"
4054 (defined in inferior.h). */
4056 struct inferior_status
*
4057 save_inferior_status (int restore_stack_info
)
4059 struct inferior_status
*inf_status
= xmalloc_inferior_status ();
4061 inf_status
->stop_signal
= stop_signal
;
4062 inf_status
->stop_pc
= stop_pc
;
4063 inf_status
->stop_step
= stop_step
;
4064 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
4065 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
4066 inf_status
->trap_expected
= trap_expected
;
4067 inf_status
->step_range_start
= step_range_start
;
4068 inf_status
->step_range_end
= step_range_end
;
4069 inf_status
->step_frame_address
= step_frame_address
;
4070 inf_status
->step_over_calls
= step_over_calls
;
4071 inf_status
->stop_after_trap
= stop_after_trap
;
4072 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
4073 /* Save original bpstat chain here; replace it with copy of chain.
4074 If caller's caller is walking the chain, they'll be happier if we
4075 hand them back the original chain when restore_inferior_status is
4077 inf_status
->stop_bpstat
= stop_bpstat
;
4078 stop_bpstat
= bpstat_copy (stop_bpstat
);
4079 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
4080 inf_status
->restore_stack_info
= restore_stack_info
;
4081 inf_status
->proceed_to_finish
= proceed_to_finish
;
4083 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
4085 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
4087 record_selected_frame (&(inf_status
->selected_frame_address
),
4088 &(inf_status
->selected_level
));
4092 struct restore_selected_frame_args
4094 CORE_ADDR frame_address
;
4099 restore_selected_frame (void *args
)
4101 struct restore_selected_frame_args
*fr
=
4102 (struct restore_selected_frame_args
*) args
;
4103 struct frame_info
*frame
;
4104 int level
= fr
->level
;
4106 frame
= find_relative_frame (get_current_frame (), &level
);
4108 /* If inf_status->selected_frame_address is NULL, there was no
4109 previously selected frame. */
4110 if (frame
== NULL
||
4111 /* FRAME_FP (frame) != fr->frame_address || */
4112 /* elz: deleted this check as a quick fix to the problem that
4113 for function called by hand gdb creates no internal frame
4114 structure and the real stack and gdb's idea of stack are
4115 different if nested calls by hands are made.
4117 mvs: this worries me. */
4120 warning ("Unable to restore previously selected frame.\n");
4124 select_frame (frame
, fr
->level
);
4130 restore_inferior_status (struct inferior_status
*inf_status
)
4132 stop_signal
= inf_status
->stop_signal
;
4133 stop_pc
= inf_status
->stop_pc
;
4134 stop_step
= inf_status
->stop_step
;
4135 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4136 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4137 trap_expected
= inf_status
->trap_expected
;
4138 step_range_start
= inf_status
->step_range_start
;
4139 step_range_end
= inf_status
->step_range_end
;
4140 step_frame_address
= inf_status
->step_frame_address
;
4141 step_over_calls
= inf_status
->step_over_calls
;
4142 stop_after_trap
= inf_status
->stop_after_trap
;
4143 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
4144 bpstat_clear (&stop_bpstat
);
4145 stop_bpstat
= inf_status
->stop_bpstat
;
4146 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4147 proceed_to_finish
= inf_status
->proceed_to_finish
;
4149 /* FIXME: Is the restore of stop_registers always needed */
4150 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
4152 /* The inferior can be gone if the user types "print exit(0)"
4153 (and perhaps other times). */
4154 if (target_has_execution
)
4155 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
4157 /* FIXME: If we are being called after stopping in a function which
4158 is called from gdb, we should not be trying to restore the
4159 selected frame; it just prints a spurious error message (The
4160 message is useful, however, in detecting bugs in gdb (like if gdb
4161 clobbers the stack)). In fact, should we be restoring the
4162 inferior status at all in that case? . */
4164 if (target_has_stack
&& inf_status
->restore_stack_info
)
4166 struct restore_selected_frame_args fr
;
4167 fr
.level
= inf_status
->selected_level
;
4168 fr
.frame_address
= inf_status
->selected_frame_address
;
4169 /* The point of catch_errors is that if the stack is clobbered,
4170 walking the stack might encounter a garbage pointer and error()
4171 trying to dereference it. */
4172 if (catch_errors (restore_selected_frame
, &fr
,
4173 "Unable to restore previously selected frame:\n",
4174 RETURN_MASK_ERROR
) == 0)
4175 /* Error in restoring the selected frame. Select the innermost
4179 select_frame (get_current_frame (), 0);
4183 free_inferior_status (inf_status
);
4187 do_restore_inferior_status_cleanup (void *sts
)
4189 restore_inferior_status (sts
);
4193 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4195 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4199 discard_inferior_status (struct inferior_status
*inf_status
)
4201 /* See save_inferior_status for info on stop_bpstat. */
4202 bpstat_clear (&inf_status
->stop_bpstat
);
4203 free_inferior_status (inf_status
);
4206 /* Oft used ptids */
4208 ptid_t minus_one_ptid
;
4210 /* Create a ptid given the necessary PID, LWP, and TID components. */
4213 ptid_build (int pid
, long lwp
, long tid
)
4223 /* Create a ptid from just a pid. */
4226 pid_to_ptid (int pid
)
4228 return ptid_build (pid
, 0, 0);
4231 /* Fetch the pid (process id) component from a ptid. */
4234 ptid_get_pid (ptid_t ptid
)
4239 /* Fetch the lwp (lightweight process) component from a ptid. */
4242 ptid_get_lwp (ptid_t ptid
)
4247 /* Fetch the tid (thread id) component from a ptid. */
4250 ptid_get_tid (ptid_t ptid
)
4255 /* ptid_equal() is used to test equality of two ptids. */
4258 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4260 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4261 && ptid1
.tid
== ptid2
.tid
);
4264 /* restore_inferior_ptid() will be used by the cleanup machinery
4265 to restore the inferior_ptid value saved in a call to
4266 save_inferior_ptid(). */
4269 restore_inferior_ptid (void *arg
)
4271 ptid_t
*saved_ptid_ptr
= arg
;
4272 inferior_ptid
= *saved_ptid_ptr
;
4276 /* Save the value of inferior_ptid so that it may be restored by a
4277 later call to do_cleanups(). Returns the struct cleanup pointer
4278 needed for later doing the cleanup. */
4281 save_inferior_ptid (void)
4283 ptid_t
*saved_ptid_ptr
;
4285 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4286 *saved_ptid_ptr
= inferior_ptid
;
4287 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4294 stop_registers
= xmalloc (REGISTER_BYTES
);
4298 _initialize_infrun (void)
4301 register int numsigs
;
4302 struct cmd_list_element
*c
;
4306 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4307 register_gdbarch_swap (NULL
, 0, build_infrun
);
4309 add_info ("signals", signals_info
,
4310 "What debugger does when program gets various signals.\n\
4311 Specify a signal as argument to print info on that signal only.");
4312 add_info_alias ("handle", "signals", 0);
4314 add_com ("handle", class_run
, handle_command
,
4315 concat ("Specify how to handle a signal.\n\
4316 Args are signals and actions to apply to those signals.\n\
4317 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4318 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4319 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4320 The special arg \"all\" is recognized to mean all signals except those\n\
4321 used by the debugger, typically SIGTRAP and SIGINT.\n",
4322 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4323 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4324 Stop means reenter debugger if this signal happens (implies print).\n\
4325 Print means print a message if this signal happens.\n\
4326 Pass means let program see this signal; otherwise program doesn't know.\n\
4327 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4328 Pass and Stop may be combined.", NULL
));
4331 add_com ("lz", class_info
, signals_info
,
4332 "What debugger does when program gets various signals.\n\
4333 Specify a signal as argument to print info on that signal only.");
4334 add_com ("z", class_run
, xdb_handle_command
,
4335 concat ("Specify how to handle a signal.\n\
4336 Args are signals and actions to apply to those signals.\n\
4337 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4338 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4339 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4340 The special arg \"all\" is recognized to mean all signals except those\n\
4341 used by the debugger, typically SIGTRAP and SIGINT.\n",
4342 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4343 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4344 nopass), \"Q\" (noprint)\n\
4345 Stop means reenter debugger if this signal happens (implies print).\n\
4346 Print means print a message if this signal happens.\n\
4347 Pass means let program see this signal; otherwise program doesn't know.\n\
4348 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4349 Pass and Stop may be combined.", NULL
));
4353 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
4354 "There is no `stop' command, but you can set a hook on `stop'.\n\
4355 This allows you to set a list of commands to be run each time execution\n\
4356 of the program stops.", &cmdlist
);
4358 numsigs
= (int) TARGET_SIGNAL_LAST
;
4359 signal_stop
= (unsigned char *)
4360 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4361 signal_print
= (unsigned char *)
4362 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4363 signal_program
= (unsigned char *)
4364 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4365 for (i
= 0; i
< numsigs
; i
++)
4368 signal_print
[i
] = 1;
4369 signal_program
[i
] = 1;
4372 /* Signals caused by debugger's own actions
4373 should not be given to the program afterwards. */
4374 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4375 signal_program
[TARGET_SIGNAL_INT
] = 0;
4377 /* Signals that are not errors should not normally enter the debugger. */
4378 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4379 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4380 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4381 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4382 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4383 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4384 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4385 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4386 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4387 signal_print
[TARGET_SIGNAL_IO
] = 0;
4388 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4389 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4390 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4391 signal_print
[TARGET_SIGNAL_URG
] = 0;
4392 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4393 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4395 /* These signals are used internally by user-level thread
4396 implementations. (See signal(5) on Solaris.) Like the above
4397 signals, a healthy program receives and handles them as part of
4398 its normal operation. */
4399 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4400 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4401 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4402 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4403 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4404 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4408 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4409 (char *) &stop_on_solib_events
,
4410 "Set stopping for shared library events.\n\
4411 If nonzero, gdb will give control to the user when the dynamic linker\n\
4412 notifies gdb of shared library events. The most common event of interest\n\
4413 to the user would be loading/unloading of a new library.\n",
4418 c
= add_set_enum_cmd ("follow-fork-mode",
4420 follow_fork_mode_kind_names
,
4421 &follow_fork_mode_string
,
4422 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4423 kernel problem. It's also not terribly useful without a GUI to
4424 help the user drive two debuggers. So for now, I'm disabling
4425 the "both" option. */
4426 /* "Set debugger response to a program call of fork \
4428 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4429 parent - the original process is debugged after a fork\n\
4430 child - the new process is debugged after a fork\n\
4431 both - both the parent and child are debugged after a fork\n\
4432 ask - the debugger will ask for one of the above choices\n\
4433 For \"both\", another copy of the debugger will be started to follow\n\
4434 the new child process. The original debugger will continue to follow\n\
4435 the original parent process. To distinguish their prompts, the\n\
4436 debugger copy's prompt will be changed.\n\
4437 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4438 By default, the debugger will follow the parent process.",
4440 "Set debugger response to a program call of fork \
4442 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4443 parent - the original process is debugged after a fork\n\
4444 child - the new process is debugged after a fork\n\
4445 ask - the debugger will ask for one of the above choices\n\
4446 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4447 By default, the debugger will follow the parent process.",
4449 /* c->function.sfunc = ; */
4450 add_show_from_set (c
, &showlist
);
4452 c
= add_set_enum_cmd ("scheduler-locking", class_run
,
4453 scheduler_enums
, /* array of string names */
4454 &scheduler_mode
, /* current mode */
4455 "Set mode for locking scheduler during execution.\n\
4456 off == no locking (threads may preempt at any time)\n\
4457 on == full locking (no thread except the current thread may run)\n\
4458 step == scheduler locked during every single-step operation.\n\
4459 In this mode, no other thread may run during a step command.\n\
4460 Other threads may run while stepping over a function call ('next').",
4463 c
->function
.sfunc
= set_schedlock_func
; /* traps on target vector */
4464 add_show_from_set (c
, &showlist
);
4466 c
= add_set_cmd ("step-mode", class_run
,
4467 var_boolean
, (char*) &step_stop_if_no_debug
,
4468 "Set mode of the step operation. When set, doing a step over a\n\
4469 function without debug line information will stop at the first\n\
4470 instruction of that function. Otherwise, the function is skipped and\n\
4471 the step command stops at a different source line.",
4473 add_show_from_set (c
, &showlist
);
4475 /* ptid initializations */
4476 null_ptid
= ptid_build (0, 0, 0);
4477 minus_one_ptid
= ptid_build (-1, 0, 0);
4478 inferior_ptid
= null_ptid
;
4479 target_last_wait_ptid
= minus_one_ptid
;