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.",
811 /* Resume the inferior, but allow a QUIT. This is useful if the user
812 wants to interrupt some lengthy single-stepping operation
813 (for child processes, the SIGINT goes to the inferior, and so
814 we get a SIGINT random_signal, but for remote debugging and perhaps
815 other targets, that's not true).
817 STEP nonzero if we should step (zero to continue instead).
818 SIG is the signal to give the inferior (zero for none). */
820 resume (int step
, enum target_signal sig
)
822 int should_resume
= 1;
823 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
826 #ifdef CANNOT_STEP_BREAKPOINT
827 /* Most targets can step a breakpoint instruction, thus executing it
828 normally. But if this one cannot, just continue and we will hit
830 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
834 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
835 over an instruction that causes a page fault without triggering
836 a hardware watchpoint. The kernel properly notices that it shouldn't
837 stop, because the hardware watchpoint is not triggered, but it forgets
838 the step request and continues the program normally.
839 Work around the problem by removing hardware watchpoints if a step is
840 requested, GDB will check for a hardware watchpoint trigger after the
842 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
843 remove_hw_watchpoints ();
846 /* Normally, by the time we reach `resume', the breakpoints are either
847 removed or inserted, as appropriate. The exception is if we're sitting
848 at a permanent breakpoint; we need to step over it, but permanent
849 breakpoints can't be removed. So we have to test for it here. */
850 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
851 SKIP_PERMANENT_BREAKPOINT ();
853 if (SOFTWARE_SINGLE_STEP_P () && step
)
855 /* Do it the hard way, w/temp breakpoints */
856 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
857 /* ...and don't ask hardware to do it. */
859 /* and do not pull these breakpoints until after a `wait' in
860 `wait_for_inferior' */
861 singlestep_breakpoints_inserted_p
= 1;
864 /* Handle any optimized stores to the inferior NOW... */
865 #ifdef DO_DEFERRED_STORES
869 /* If there were any forks/vforks/execs that were caught and are
870 now to be followed, then do so. */
871 switch (pending_follow
.kind
)
873 case (TARGET_WAITKIND_FORKED
):
874 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
875 follow_fork (PIDGET (inferior_ptid
),
876 pending_follow
.fork_event
.child_pid
);
879 case (TARGET_WAITKIND_VFORKED
):
881 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
883 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
884 follow_vfork (PIDGET (inferior_ptid
),
885 pending_follow
.fork_event
.child_pid
);
887 /* Did we follow the child, but not yet see the child's exec event?
888 If so, then it actually ought to be waiting for us; we respond to
889 parent vfork events. We don't actually want to resume the child
890 in this situation; we want to just get its exec event. */
891 if (!saw_child_exec
&&
892 (PIDGET (inferior_ptid
) == pending_follow
.fork_event
.child_pid
))
897 case (TARGET_WAITKIND_EXECD
):
898 /* If we saw a vfork event but couldn't follow it until we saw
899 an exec, then now might be the time! */
900 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
901 /* follow_exec is called as soon as the exec event is seen. */
908 /* Install inferior's terminal modes. */
909 target_terminal_inferior ();
915 if (use_thread_step_needed
&& thread_step_needed
)
917 /* We stopped on a BPT instruction;
918 don't continue other threads and
919 just step this thread. */
920 thread_step_needed
= 0;
922 if (!breakpoint_here_p (read_pc ()))
924 /* Breakpoint deleted: ok to do regular resume
925 where all the threads either step or continue. */
926 resume_ptid
= RESUME_ALL
;
932 warning ("Internal error, changing continue to step.");
933 remove_breakpoints ();
934 breakpoints_inserted
= 0;
938 resume_ptid
= inferior_ptid
;
943 /* Vanilla resume. */
944 if ((scheduler_mode
== schedlock_on
) ||
945 (scheduler_mode
== schedlock_step
&& step
!= 0))
946 resume_ptid
= inferior_ptid
;
948 resume_ptid
= RESUME_ALL
;
950 target_resume (resume_ptid
, step
, sig
);
953 discard_cleanups (old_cleanups
);
957 /* Clear out all variables saying what to do when inferior is continued.
958 First do this, then set the ones you want, then call `proceed'. */
961 clear_proceed_status (void)
964 step_range_start
= 0;
966 step_frame_address
= 0;
967 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
969 stop_soon_quietly
= 0;
970 proceed_to_finish
= 0;
971 breakpoint_proceeded
= 1; /* We're about to proceed... */
973 /* Discard any remaining commands or status from previous stop. */
974 bpstat_clear (&stop_bpstat
);
977 /* Basic routine for continuing the program in various fashions.
979 ADDR is the address to resume at, or -1 for resume where stopped.
980 SIGGNAL is the signal to give it, or 0 for none,
981 or -1 for act according to how it stopped.
982 STEP is nonzero if should trap after one instruction.
983 -1 means return after that and print nothing.
984 You should probably set various step_... variables
985 before calling here, if you are stepping.
987 You should call clear_proceed_status before calling proceed. */
990 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
995 step_start_function
= find_pc_function (read_pc ());
999 if (addr
== (CORE_ADDR
) -1)
1001 /* If there is a breakpoint at the address we will resume at,
1002 step one instruction before inserting breakpoints
1003 so that we do not stop right away (and report a second
1004 hit at this breakpoint). */
1006 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
1009 #ifndef STEP_SKIPS_DELAY
1010 #define STEP_SKIPS_DELAY(pc) (0)
1011 #define STEP_SKIPS_DELAY_P (0)
1013 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
1014 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
1015 is slow (it needs to read memory from the target). */
1016 if (STEP_SKIPS_DELAY_P
1017 && breakpoint_here_p (read_pc () + 4)
1018 && STEP_SKIPS_DELAY (read_pc ()))
1025 /* New address; we don't need to single-step a thread
1026 over a breakpoint we just hit, 'cause we aren't
1027 continuing from there.
1029 It's not worth worrying about the case where a user
1030 asks for a "jump" at the current PC--if they get the
1031 hiccup of re-hiting a hit breakpoint, what else do
1033 thread_step_needed
= 0;
1036 #ifdef PREPARE_TO_PROCEED
1037 /* In a multi-threaded task we may select another thread
1038 and then continue or step.
1040 But if the old thread was stopped at a breakpoint, it
1041 will immediately cause another breakpoint stop without
1042 any execution (i.e. it will report a breakpoint hit
1043 incorrectly). So we must step over it first.
1045 PREPARE_TO_PROCEED checks the current thread against the thread
1046 that reported the most recent event. If a step-over is required
1047 it returns TRUE and sets the current thread to the old thread. */
1048 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
1051 thread_step_needed
= 1;
1054 #endif /* PREPARE_TO_PROCEED */
1057 if (trap_expected_after_continue
)
1059 /* If (step == 0), a trap will be automatically generated after
1060 the first instruction is executed. Force step one
1061 instruction to clear this condition. This should not occur
1062 if step is nonzero, but it is harmless in that case. */
1064 trap_expected_after_continue
= 0;
1066 #endif /* HP_OS_BUG */
1069 /* We will get a trace trap after one instruction.
1070 Continue it automatically and insert breakpoints then. */
1074 int temp
= insert_breakpoints ();
1077 print_sys_errmsg ("insert_breakpoints", temp
);
1078 error ("Cannot insert breakpoints.\n\
1079 The same program may be running in another process,\n\
1080 or you may have requested too many hardware\n\
1081 breakpoints and/or watchpoints.\n");
1084 breakpoints_inserted
= 1;
1087 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1088 stop_signal
= siggnal
;
1089 /* If this signal should not be seen by program,
1090 give it zero. Used for debugging signals. */
1091 else if (!signal_program
[stop_signal
])
1092 stop_signal
= TARGET_SIGNAL_0
;
1094 annotate_starting ();
1096 /* Make sure that output from GDB appears before output from the
1098 gdb_flush (gdb_stdout
);
1100 /* Resume inferior. */
1101 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1103 /* Wait for it to stop (if not standalone)
1104 and in any case decode why it stopped, and act accordingly. */
1105 /* Do this only if we are not using the event loop, or if the target
1106 does not support asynchronous execution. */
1107 if (!event_loop_p
|| !target_can_async_p ())
1109 wait_for_inferior ();
1114 /* Record the pc and sp of the program the last time it stopped.
1115 These are just used internally by wait_for_inferior, but need
1116 to be preserved over calls to it and cleared when the inferior
1118 static CORE_ADDR prev_pc
;
1119 static CORE_ADDR prev_func_start
;
1120 static char *prev_func_name
;
1123 /* Start remote-debugging of a machine over a serial link. */
1128 init_thread_list ();
1129 init_wait_for_inferior ();
1130 stop_soon_quietly
= 1;
1133 /* Always go on waiting for the target, regardless of the mode. */
1134 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1135 indicate to wait_for_inferior that a target should timeout if
1136 nothing is returned (instead of just blocking). Because of this,
1137 targets expecting an immediate response need to, internally, set
1138 things up so that the target_wait() is forced to eventually
1140 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1141 differentiate to its caller what the state of the target is after
1142 the initial open has been performed. Here we're assuming that
1143 the target has stopped. It should be possible to eventually have
1144 target_open() return to the caller an indication that the target
1145 is currently running and GDB state should be set to the same as
1146 for an async run. */
1147 wait_for_inferior ();
1151 /* Initialize static vars when a new inferior begins. */
1154 init_wait_for_inferior (void)
1156 /* These are meaningless until the first time through wait_for_inferior. */
1158 prev_func_start
= 0;
1159 prev_func_name
= NULL
;
1162 trap_expected_after_continue
= 0;
1164 breakpoints_inserted
= 0;
1165 breakpoint_init_inferior (inf_starting
);
1167 /* Don't confuse first call to proceed(). */
1168 stop_signal
= TARGET_SIGNAL_0
;
1170 /* The first resume is not following a fork/vfork/exec. */
1171 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1172 pending_follow
.fork_event
.saw_parent_fork
= 0;
1173 pending_follow
.fork_event
.saw_child_fork
= 0;
1174 pending_follow
.fork_event
.saw_child_exec
= 0;
1176 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1177 number_of_threads_in_syscalls
= 0;
1179 clear_proceed_status ();
1183 delete_breakpoint_current_contents (void *arg
)
1185 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1186 if (*breakpointp
!= NULL
)
1188 delete_breakpoint (*breakpointp
);
1189 *breakpointp
= NULL
;
1193 /* This enum encodes possible reasons for doing a target_wait, so that
1194 wfi can call target_wait in one place. (Ultimately the call will be
1195 moved out of the infinite loop entirely.) */
1199 infwait_normal_state
,
1200 infwait_thread_hop_state
,
1201 infwait_nullified_state
,
1202 infwait_nonstep_watch_state
1205 /* Why did the inferior stop? Used to print the appropriate messages
1206 to the interface from within handle_inferior_event(). */
1207 enum inferior_stop_reason
1209 /* We don't know why. */
1211 /* Step, next, nexti, stepi finished. */
1213 /* Found breakpoint. */
1215 /* Inferior terminated by signal. */
1217 /* Inferior exited. */
1219 /* Inferior received signal, and user asked to be notified. */
1223 /* This structure contains what used to be local variables in
1224 wait_for_inferior. Probably many of them can return to being
1225 locals in handle_inferior_event. */
1227 struct execution_control_state
1229 struct target_waitstatus ws
;
1230 struct target_waitstatus
*wp
;
1233 CORE_ADDR stop_func_start
;
1234 CORE_ADDR stop_func_end
;
1235 char *stop_func_name
;
1236 struct symtab_and_line sal
;
1237 int remove_breakpoints_on_following_step
;
1239 struct symtab
*current_symtab
;
1240 int handling_longjmp
; /* FIXME */
1242 ptid_t saved_inferior_ptid
;
1244 int stepping_through_solib_after_catch
;
1245 bpstat stepping_through_solib_catchpoints
;
1246 int enable_hw_watchpoints_after_wait
;
1247 int stepping_through_sigtramp
;
1248 int new_thread_event
;
1249 struct target_waitstatus tmpstatus
;
1250 enum infwait_states infwait_state
;
1255 void init_execution_control_state (struct execution_control_state
* ecs
);
1257 void handle_inferior_event (struct execution_control_state
* ecs
);
1259 static void check_sigtramp2 (struct execution_control_state
*ecs
);
1260 static void step_into_function (struct execution_control_state
*ecs
);
1261 static void step_over_function (struct execution_control_state
*ecs
);
1262 static void stop_stepping (struct execution_control_state
*ecs
);
1263 static void prepare_to_wait (struct execution_control_state
*ecs
);
1264 static void keep_going (struct execution_control_state
*ecs
);
1265 static void print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
);
1267 /* Wait for control to return from inferior to debugger.
1268 If inferior gets a signal, we may decide to start it up again
1269 instead of returning. That is why there is a loop in this function.
1270 When this function actually returns it means the inferior
1271 should be left stopped and GDB should read more commands. */
1274 wait_for_inferior (void)
1276 struct cleanup
*old_cleanups
;
1277 struct execution_control_state ecss
;
1278 struct execution_control_state
*ecs
;
1280 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1281 &step_resume_breakpoint
);
1282 make_cleanup (delete_breakpoint_current_contents
,
1283 &through_sigtramp_breakpoint
);
1285 /* wfi still stays in a loop, so it's OK just to take the address of
1286 a local to get the ecs pointer. */
1289 /* Fill in with reasonable starting values. */
1290 init_execution_control_state (ecs
);
1292 thread_step_needed
= 0;
1294 /* We'll update this if & when we switch to a new thread. */
1295 previous_inferior_ptid
= inferior_ptid
;
1297 overlay_cache_invalid
= 1;
1299 /* We have to invalidate the registers BEFORE calling target_wait
1300 because they can be loaded from the target while in target_wait.
1301 This makes remote debugging a bit more efficient for those
1302 targets that provide critical registers as part of their normal
1303 status mechanism. */
1305 registers_changed ();
1309 if (target_wait_hook
)
1310 ecs
->ptid
= target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
1312 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
1314 /* Now figure out what to do with the result of the result. */
1315 handle_inferior_event (ecs
);
1317 if (!ecs
->wait_some_more
)
1320 do_cleanups (old_cleanups
);
1323 /* Asynchronous version of wait_for_inferior. It is called by the
1324 event loop whenever a change of state is detected on the file
1325 descriptor corresponding to the target. It can be called more than
1326 once to complete a single execution command. In such cases we need
1327 to keep the state in a global variable ASYNC_ECSS. If it is the
1328 last time that this function is called for a single execution
1329 command, then report to the user that the inferior has stopped, and
1330 do the necessary cleanups. */
1332 struct execution_control_state async_ecss
;
1333 struct execution_control_state
*async_ecs
;
1336 fetch_inferior_event (void *client_data
)
1338 static struct cleanup
*old_cleanups
;
1340 async_ecs
= &async_ecss
;
1342 if (!async_ecs
->wait_some_more
)
1344 old_cleanups
= make_exec_cleanup (delete_step_resume_breakpoint
,
1345 &step_resume_breakpoint
);
1346 make_exec_cleanup (delete_breakpoint_current_contents
,
1347 &through_sigtramp_breakpoint
);
1349 /* Fill in with reasonable starting values. */
1350 init_execution_control_state (async_ecs
);
1352 thread_step_needed
= 0;
1354 /* We'll update this if & when we switch to a new thread. */
1355 previous_inferior_ptid
= inferior_ptid
;
1357 overlay_cache_invalid
= 1;
1359 /* We have to invalidate the registers BEFORE calling target_wait
1360 because they can be loaded from the target while in target_wait.
1361 This makes remote debugging a bit more efficient for those
1362 targets that provide critical registers as part of their normal
1363 status mechanism. */
1365 registers_changed ();
1368 if (target_wait_hook
)
1369 async_ecs
->ptid
= target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1371 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1373 /* Now figure out what to do with the result of the result. */
1374 handle_inferior_event (async_ecs
);
1376 if (!async_ecs
->wait_some_more
)
1378 /* Do only the cleanups that have been added by this
1379 function. Let the continuations for the commands do the rest,
1380 if there are any. */
1381 do_exec_cleanups (old_cleanups
);
1383 if (step_multi
&& stop_step
)
1384 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1386 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1390 /* Prepare an execution control state for looping through a
1391 wait_for_inferior-type loop. */
1394 init_execution_control_state (struct execution_control_state
*ecs
)
1396 /* ecs->another_trap? */
1397 ecs
->random_signal
= 0;
1398 ecs
->remove_breakpoints_on_following_step
= 0;
1399 ecs
->handling_longjmp
= 0; /* FIXME */
1400 ecs
->update_step_sp
= 0;
1401 ecs
->stepping_through_solib_after_catch
= 0;
1402 ecs
->stepping_through_solib_catchpoints
= NULL
;
1403 ecs
->enable_hw_watchpoints_after_wait
= 0;
1404 ecs
->stepping_through_sigtramp
= 0;
1405 ecs
->sal
= find_pc_line (prev_pc
, 0);
1406 ecs
->current_line
= ecs
->sal
.line
;
1407 ecs
->current_symtab
= ecs
->sal
.symtab
;
1408 ecs
->infwait_state
= infwait_normal_state
;
1409 ecs
->waiton_ptid
= pid_to_ptid (-1);
1410 ecs
->wp
= &(ecs
->ws
);
1413 /* Call this function before setting step_resume_breakpoint, as a
1414 sanity check. There should never be more than one step-resume
1415 breakpoint per thread, so we should never be setting a new
1416 step_resume_breakpoint when one is already active. */
1418 check_for_old_step_resume_breakpoint (void)
1420 if (step_resume_breakpoint
)
1421 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1424 /* Return the cached copy of the last pid/waitstatus returned by
1425 target_wait()/target_wait_hook(). The data is actually cached by
1426 handle_inferior_event(), which gets called immediately after
1427 target_wait()/target_wait_hook(). */
1430 get_last_target_status(ptid_t
*ptidp
, struct target_waitstatus
*status
)
1432 *ptidp
= target_last_wait_ptid
;
1433 *status
= target_last_waitstatus
;
1436 /* Given an execution control state that has been freshly filled in
1437 by an event from the inferior, figure out what it means and take
1438 appropriate action. */
1441 handle_inferior_event (struct execution_control_state
*ecs
)
1444 int stepped_after_stopped_by_watchpoint
;
1446 /* Cache the last pid/waitstatus. */
1447 target_last_wait_ptid
= ecs
->ptid
;
1448 target_last_waitstatus
= *ecs
->wp
;
1450 /* Keep this extra brace for now, minimizes diffs. */
1452 switch (ecs
->infwait_state
)
1454 case infwait_normal_state
:
1455 /* Since we've done a wait, we have a new event. Don't
1456 carry over any expectations about needing to step over a
1458 thread_step_needed
= 0;
1460 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1461 is serviced in this loop, below. */
1462 if (ecs
->enable_hw_watchpoints_after_wait
)
1464 TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1465 ecs
->enable_hw_watchpoints_after_wait
= 0;
1467 stepped_after_stopped_by_watchpoint
= 0;
1470 case infwait_thread_hop_state
:
1471 insert_breakpoints ();
1473 /* We need to restart all the threads now,
1474 * unless we're running in scheduler-locked mode.
1475 * Use currently_stepping to determine whether to
1479 if (scheduler_mode
== schedlock_on
)
1480 target_resume (ecs
->ptid
,
1481 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1483 target_resume (RESUME_ALL
,
1484 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1485 ecs
->infwait_state
= infwait_normal_state
;
1486 prepare_to_wait (ecs
);
1489 case infwait_nullified_state
:
1492 case infwait_nonstep_watch_state
:
1493 insert_breakpoints ();
1495 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1496 handle things like signals arriving and other things happening
1497 in combination correctly? */
1498 stepped_after_stopped_by_watchpoint
= 1;
1501 ecs
->infwait_state
= infwait_normal_state
;
1503 flush_cached_frames ();
1505 /* If it's a new process, add it to the thread database */
1507 ecs
->new_thread_event
= (! ptid_equal (ecs
->ptid
, inferior_ptid
)
1508 && ! in_thread_list (ecs
->ptid
));
1510 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1511 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1512 && ecs
->new_thread_event
)
1514 add_thread (ecs
->ptid
);
1517 ui_out_text (uiout
, "[New ");
1518 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->ptid
));
1519 ui_out_text (uiout
, "]\n");
1521 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs
->ptid
));
1525 /* NOTE: This block is ONLY meant to be invoked in case of a
1526 "thread creation event"! If it is invoked for any other
1527 sort of event (such as a new thread landing on a breakpoint),
1528 the event will be discarded, which is almost certainly
1531 To avoid this, the low-level module (eg. target_wait)
1532 should call in_thread_list and add_thread, so that the
1533 new thread is known by the time we get here. */
1535 /* We may want to consider not doing a resume here in order
1536 to give the user a chance to play with the new thread.
1537 It might be good to make that a user-settable option. */
1539 /* At this point, all threads are stopped (happens
1540 automatically in either the OS or the native code).
1541 Therefore we need to continue all threads in order to
1544 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1545 prepare_to_wait (ecs
);
1550 switch (ecs
->ws
.kind
)
1552 case TARGET_WAITKIND_LOADED
:
1553 /* Ignore gracefully during startup of the inferior, as it
1554 might be the shell which has just loaded some objects,
1555 otherwise add the symbols for the newly loaded objects. */
1557 if (!stop_soon_quietly
)
1559 /* Remove breakpoints, SOLIB_ADD might adjust
1560 breakpoint addresses via breakpoint_re_set. */
1561 if (breakpoints_inserted
)
1562 remove_breakpoints ();
1564 /* Check for any newly added shared libraries if we're
1565 supposed to be adding them automatically. */
1568 /* Switch terminal for any messages produced by
1569 breakpoint_re_set. */
1570 target_terminal_ours_for_output ();
1571 SOLIB_ADD (NULL
, 0, NULL
);
1572 target_terminal_inferior ();
1575 /* Reinsert breakpoints and continue. */
1576 if (breakpoints_inserted
)
1577 insert_breakpoints ();
1580 resume (0, TARGET_SIGNAL_0
);
1581 prepare_to_wait (ecs
);
1584 case TARGET_WAITKIND_SPURIOUS
:
1585 resume (0, TARGET_SIGNAL_0
);
1586 prepare_to_wait (ecs
);
1589 case TARGET_WAITKIND_EXITED
:
1590 target_terminal_ours (); /* Must do this before mourn anyway */
1591 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1593 /* Record the exit code in the convenience variable $_exitcode, so
1594 that the user can inspect this again later. */
1595 set_internalvar (lookup_internalvar ("_exitcode"),
1596 value_from_longest (builtin_type_int
,
1597 (LONGEST
) ecs
->ws
.value
.integer
));
1598 gdb_flush (gdb_stdout
);
1599 target_mourn_inferior ();
1600 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1601 stop_print_frame
= 0;
1602 stop_stepping (ecs
);
1605 case TARGET_WAITKIND_SIGNALLED
:
1606 stop_print_frame
= 0;
1607 stop_signal
= ecs
->ws
.value
.sig
;
1608 target_terminal_ours (); /* Must do this before mourn anyway */
1610 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1611 reach here unless the inferior is dead. However, for years
1612 target_kill() was called here, which hints that fatal signals aren't
1613 really fatal on some systems. If that's true, then some changes
1615 target_mourn_inferior ();
1617 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1618 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P() */
1619 stop_stepping (ecs
);
1622 /* The following are the only cases in which we keep going;
1623 the above cases end in a continue or goto. */
1624 case TARGET_WAITKIND_FORKED
:
1625 stop_signal
= TARGET_SIGNAL_TRAP
;
1626 pending_follow
.kind
= ecs
->ws
.kind
;
1628 /* Ignore fork events reported for the parent; we're only
1629 interested in reacting to forks of the child. Note that
1630 we expect the child's fork event to be available if we
1631 waited for it now. */
1632 if (ptid_equal (inferior_ptid
, ecs
->ptid
))
1634 pending_follow
.fork_event
.saw_parent_fork
= 1;
1635 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1636 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1637 prepare_to_wait (ecs
);
1642 pending_follow
.fork_event
.saw_child_fork
= 1;
1643 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1644 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1647 stop_pc
= read_pc_pid (ecs
->ptid
);
1648 ecs
->saved_inferior_ptid
= inferior_ptid
;
1649 inferior_ptid
= ecs
->ptid
;
1650 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1651 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1652 inferior_ptid
= ecs
->saved_inferior_ptid
;
1653 goto process_event_stop_test
;
1655 /* If this a platform which doesn't allow a debugger to touch a
1656 vfork'd inferior until after it exec's, then we'd best keep
1657 our fingers entirely off the inferior, other than continuing
1658 it. This has the unfortunate side-effect that catchpoints
1659 of vforks will be ignored. But since the platform doesn't
1660 allow the inferior be touched at vfork time, there's really
1662 case TARGET_WAITKIND_VFORKED
:
1663 stop_signal
= TARGET_SIGNAL_TRAP
;
1664 pending_follow
.kind
= ecs
->ws
.kind
;
1666 /* Is this a vfork of the parent? If so, then give any
1667 vfork catchpoints a chance to trigger now. (It's
1668 dangerous to do so if the child canot be touched until
1669 it execs, and the child has not yet exec'd. We probably
1670 should warn the user to that effect when the catchpoint
1672 if (ptid_equal (ecs
->ptid
, inferior_ptid
))
1674 pending_follow
.fork_event
.saw_parent_fork
= 1;
1675 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1676 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1679 /* If we've seen the child's vfork event but cannot really touch
1680 the child until it execs, then we must continue the child now.
1681 Else, give any vfork catchpoints a chance to trigger now. */
1684 pending_follow
.fork_event
.saw_child_fork
= 1;
1685 pending_follow
.fork_event
.child_pid
= PIDGET (ecs
->ptid
);
1686 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1687 target_post_startup_inferior (
1688 pid_to_ptid (pending_follow
.fork_event
.child_pid
));
1689 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1690 if (follow_vfork_when_exec
)
1692 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1693 prepare_to_wait (ecs
);
1698 stop_pc
= read_pc ();
1699 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1700 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1701 goto process_event_stop_test
;
1703 case TARGET_WAITKIND_EXECD
:
1704 stop_signal
= TARGET_SIGNAL_TRAP
;
1706 /* Is this a target which reports multiple exec events per actual
1707 call to exec()? (HP-UX using ptrace does, for example.) If so,
1708 ignore all but the last one. Just resume the exec'r, and wait
1709 for the next exec event. */
1710 if (inferior_ignoring_leading_exec_events
)
1712 inferior_ignoring_leading_exec_events
--;
1713 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1714 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.parent_pid
);
1715 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1716 prepare_to_wait (ecs
);
1719 inferior_ignoring_leading_exec_events
=
1720 target_reported_exec_events_per_exec_call () - 1;
1722 pending_follow
.execd_pathname
=
1723 savestring (ecs
->ws
.value
.execd_pathname
,
1724 strlen (ecs
->ws
.value
.execd_pathname
));
1726 /* Did inferior_ptid exec, or did a (possibly not-yet-followed)
1727 child of a vfork exec?
1729 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1730 HP-UX, events associated with a vforking inferior come in
1731 threes: a vfork event for the child (always first), followed
1732 a vfork event for the parent and an exec event for the child.
1733 The latter two can come in either order.
1735 If we get the parent vfork event first, life's good: We follow
1736 either the parent or child, and then the child's exec event is
1739 But if we get the child's exec event first, then we delay
1740 responding to it until we handle the parent's vfork. Because,
1741 otherwise we can't satisfy a "catch vfork". */
1742 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1744 pending_follow
.fork_event
.saw_child_exec
= 1;
1746 /* On some targets, the child must be resumed before
1747 the parent vfork event is delivered. A single-step
1749 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1750 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1751 /* We expect the parent vfork event to be available now. */
1752 prepare_to_wait (ecs
);
1756 /* This causes the eventpoints and symbol table to be reset. Must
1757 do this now, before trying to determine whether to stop. */
1758 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1759 xfree (pending_follow
.execd_pathname
);
1761 stop_pc
= read_pc_pid (ecs
->ptid
);
1762 ecs
->saved_inferior_ptid
= inferior_ptid
;
1763 inferior_ptid
= ecs
->ptid
;
1764 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1765 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1766 inferior_ptid
= ecs
->saved_inferior_ptid
;
1767 goto process_event_stop_test
;
1769 /* These syscall events are returned on HP-UX, as part of its
1770 implementation of page-protection-based "hardware" watchpoints.
1771 HP-UX has unfortunate interactions between page-protections and
1772 some system calls. Our solution is to disable hardware watches
1773 when a system call is entered, and reenable them when the syscall
1774 completes. The downside of this is that we may miss the precise
1775 point at which a watched piece of memory is modified. "Oh well."
1777 Note that we may have multiple threads running, which may each
1778 enter syscalls at roughly the same time. Since we don't have a
1779 good notion currently of whether a watched piece of memory is
1780 thread-private, we'd best not have any page-protections active
1781 when any thread is in a syscall. Thus, we only want to reenable
1782 hardware watches when no threads are in a syscall.
1784 Also, be careful not to try to gather much state about a thread
1785 that's in a syscall. It's frequently a losing proposition. */
1786 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1787 number_of_threads_in_syscalls
++;
1788 if (number_of_threads_in_syscalls
== 1)
1790 TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid
));
1792 resume (0, TARGET_SIGNAL_0
);
1793 prepare_to_wait (ecs
);
1796 /* Before examining the threads further, step this thread to
1797 get it entirely out of the syscall. (We get notice of the
1798 event when the thread is just on the verge of exiting a
1799 syscall. Stepping one instruction seems to get it back
1802 Note that although the logical place to reenable h/w watches
1803 is here, we cannot. We cannot reenable them before stepping
1804 the thread (this causes the next wait on the thread to hang).
1806 Nor can we enable them after stepping until we've done a wait.
1807 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1808 here, which will be serviced immediately after the target
1810 case TARGET_WAITKIND_SYSCALL_RETURN
:
1811 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1813 if (number_of_threads_in_syscalls
> 0)
1815 number_of_threads_in_syscalls
--;
1816 ecs
->enable_hw_watchpoints_after_wait
=
1817 (number_of_threads_in_syscalls
== 0);
1819 prepare_to_wait (ecs
);
1822 case TARGET_WAITKIND_STOPPED
:
1823 stop_signal
= ecs
->ws
.value
.sig
;
1826 /* We had an event in the inferior, but we are not interested
1827 in handling it at this level. The lower layers have already
1828 done what needs to be done, if anything. This case can
1829 occur only when the target is async or extended-async. One
1830 of the circumstamces for this to happen is when the
1831 inferior produces output for the console. The inferior has
1832 not stopped, and we are ignoring the event. */
1833 case TARGET_WAITKIND_IGNORE
:
1834 ecs
->wait_some_more
= 1;
1838 /* We may want to consider not doing a resume here in order to give
1839 the user a chance to play with the new thread. It might be good
1840 to make that a user-settable option. */
1842 /* At this point, all threads are stopped (happens automatically in
1843 either the OS or the native code). Therefore we need to continue
1844 all threads in order to make progress. */
1845 if (ecs
->new_thread_event
)
1847 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1848 prepare_to_wait (ecs
);
1852 stop_pc
= read_pc_pid (ecs
->ptid
);
1854 /* See if a thread hit a thread-specific breakpoint that was meant for
1855 another thread. If so, then step that thread past the breakpoint,
1858 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1860 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
1861 ecs
->random_signal
= 0;
1862 else if (breakpoints_inserted
1863 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1865 ecs
->random_signal
= 0;
1866 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1871 /* Saw a breakpoint, but it was hit by the wrong thread.
1873 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->ptid
);
1875 remove_status
= remove_breakpoints ();
1876 /* Did we fail to remove breakpoints? If so, try
1877 to set the PC past the bp. (There's at least
1878 one situation in which we can fail to remove
1879 the bp's: On HP-UX's that use ttrace, we can't
1880 change the address space of a vforking child
1881 process until the child exits (well, okay, not
1882 then either :-) or execs. */
1883 if (remove_status
!= 0)
1885 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->ptid
);
1886 /* We need to restart all the threads now,
1887 * unles we're running in scheduler-locked mode.
1888 * Use currently_stepping to determine whether to
1891 if (scheduler_mode
== schedlock_on
)
1892 target_resume (ecs
->ptid
,
1893 currently_stepping (ecs
),
1896 target_resume (RESUME_ALL
,
1897 currently_stepping (ecs
),
1899 prepare_to_wait (ecs
);
1904 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1905 /* FIXME: What if a signal arrives instead of the
1906 single-step happening? */
1908 ecs
->waiton_ptid
= ecs
->ptid
;
1909 ecs
->wp
= &(ecs
->ws
);
1910 ecs
->infwait_state
= infwait_thread_hop_state
;
1911 prepare_to_wait (ecs
);
1917 /* This breakpoint matches--either it is the right
1918 thread or it's a generic breakpoint for all threads.
1919 Remember that we'll need to step just _this_ thread
1920 on any following user continuation! */
1921 thread_step_needed
= 1;
1926 ecs
->random_signal
= 1;
1928 /* See if something interesting happened to the non-current thread. If
1929 so, then switch to that thread, and eventually give control back to
1932 Note that if there's any kind of pending follow (i.e., of a fork,
1933 vfork or exec), we don't want to do this now. Rather, we'll let
1934 the next resume handle it. */
1935 if (! ptid_equal (ecs
->ptid
, inferior_ptid
) &&
1936 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1940 /* If it's a random signal for a non-current thread, notify user
1941 if he's expressed an interest. */
1942 if (ecs
->random_signal
1943 && signal_print
[stop_signal
])
1945 /* ??rehrauer: I don't understand the rationale for this code. If the
1946 inferior will stop as a result of this signal, then the act of handling
1947 the stop ought to print a message that's couches the stoppage in user
1948 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1949 won't stop as a result of the signal -- i.e., if the signal is merely
1950 a side-effect of something GDB's doing "under the covers" for the
1951 user, such as stepping threads over a breakpoint they shouldn't stop
1952 for -- then the message seems to be a serious annoyance at best.
1954 For now, remove the message altogether. */
1957 target_terminal_ours_for_output ();
1958 printf_filtered ("\nProgram received signal %s, %s.\n",
1959 target_signal_to_name (stop_signal
),
1960 target_signal_to_string (stop_signal
));
1961 gdb_flush (gdb_stdout
);
1965 /* If it's not SIGTRAP and not a signal we want to stop for, then
1966 continue the thread. */
1968 if (stop_signal
!= TARGET_SIGNAL_TRAP
1969 && !signal_stop
[stop_signal
])
1972 target_terminal_inferior ();
1974 /* Clear the signal if it should not be passed. */
1975 if (signal_program
[stop_signal
] == 0)
1976 stop_signal
= TARGET_SIGNAL_0
;
1978 target_resume (ecs
->ptid
, 0, stop_signal
);
1979 prepare_to_wait (ecs
);
1983 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1984 and fall into the rest of wait_for_inferior(). */
1986 /* Caution: it may happen that the new thread (or the old one!)
1987 is not in the thread list. In this case we must not attempt
1988 to "switch context", or we run the risk that our context may
1989 be lost. This may happen as a result of the target module
1990 mishandling thread creation. */
1992 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1993 { /* Perform infrun state context switch: */
1994 /* Save infrun state for the old thread. */
1995 save_infrun_state (inferior_ptid
, prev_pc
,
1996 prev_func_start
, prev_func_name
,
1997 trap_expected
, step_resume_breakpoint
,
1998 through_sigtramp_breakpoint
,
1999 step_range_start
, step_range_end
,
2000 step_frame_address
, ecs
->handling_longjmp
,
2002 ecs
->stepping_through_solib_after_catch
,
2003 ecs
->stepping_through_solib_catchpoints
,
2004 ecs
->stepping_through_sigtramp
);
2006 /* Load infrun state for the new thread. */
2007 load_infrun_state (ecs
->ptid
, &prev_pc
,
2008 &prev_func_start
, &prev_func_name
,
2009 &trap_expected
, &step_resume_breakpoint
,
2010 &through_sigtramp_breakpoint
,
2011 &step_range_start
, &step_range_end
,
2012 &step_frame_address
, &ecs
->handling_longjmp
,
2014 &ecs
->stepping_through_solib_after_catch
,
2015 &ecs
->stepping_through_solib_catchpoints
,
2016 &ecs
->stepping_through_sigtramp
);
2019 inferior_ptid
= ecs
->ptid
;
2022 context_hook (pid_to_thread_id (ecs
->ptid
));
2024 flush_cached_frames ();
2027 if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p
)
2029 /* Pull the single step breakpoints out of the target. */
2030 SOFTWARE_SINGLE_STEP (0, 0);
2031 singlestep_breakpoints_inserted_p
= 0;
2034 /* If PC is pointing at a nullified instruction, then step beyond
2035 it so that the user won't be confused when GDB appears to be ready
2038 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
2039 if (INSTRUCTION_NULLIFIED
)
2041 registers_changed ();
2042 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
2044 /* We may have received a signal that we want to pass to
2045 the inferior; therefore, we must not clobber the waitstatus
2048 ecs
->infwait_state
= infwait_nullified_state
;
2049 ecs
->waiton_ptid
= ecs
->ptid
;
2050 ecs
->wp
= &(ecs
->tmpstatus
);
2051 prepare_to_wait (ecs
);
2055 /* It may not be necessary to disable the watchpoint to stop over
2056 it. For example, the PA can (with some kernel cooperation)
2057 single step over a watchpoint without disabling the watchpoint. */
2058 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2061 prepare_to_wait (ecs
);
2065 /* It is far more common to need to disable a watchpoint to step
2066 the inferior over it. FIXME. What else might a debug
2067 register or page protection watchpoint scheme need here? */
2068 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2070 /* At this point, we are stopped at an instruction which has
2071 attempted to write to a piece of memory under control of
2072 a watchpoint. The instruction hasn't actually executed
2073 yet. If we were to evaluate the watchpoint expression
2074 now, we would get the old value, and therefore no change
2075 would seem to have occurred.
2077 In order to make watchpoints work `right', we really need
2078 to complete the memory write, and then evaluate the
2079 watchpoint expression. The following code does that by
2080 removing the watchpoint (actually, all watchpoints and
2081 breakpoints), single-stepping the target, re-inserting
2082 watchpoints, and then falling through to let normal
2083 single-step processing handle proceed. Since this
2084 includes evaluating watchpoints, things will come to a
2085 stop in the correct manner. */
2087 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
2089 remove_breakpoints ();
2090 registers_changed ();
2091 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
2093 ecs
->waiton_ptid
= ecs
->ptid
;
2094 ecs
->wp
= &(ecs
->ws
);
2095 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2096 prepare_to_wait (ecs
);
2100 /* It may be possible to simply continue after a watchpoint. */
2101 if (HAVE_CONTINUABLE_WATCHPOINT
)
2102 STOPPED_BY_WATCHPOINT (ecs
->ws
);
2104 ecs
->stop_func_start
= 0;
2105 ecs
->stop_func_end
= 0;
2106 ecs
->stop_func_name
= 0;
2107 /* Don't care about return value; stop_func_start and stop_func_name
2108 will both be 0 if it doesn't work. */
2109 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2110 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2111 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
2112 ecs
->another_trap
= 0;
2113 bpstat_clear (&stop_bpstat
);
2115 stop_stack_dummy
= 0;
2116 stop_print_frame
= 1;
2117 ecs
->random_signal
= 0;
2118 stopped_by_random_signal
= 0;
2119 breakpoints_failed
= 0;
2121 /* Look at the cause of the stop, and decide what to do.
2122 The alternatives are:
2123 1) break; to really stop and return to the debugger,
2124 2) drop through to start up again
2125 (set ecs->another_trap to 1 to single step once)
2126 3) set ecs->random_signal to 1, and the decision between 1 and 2
2127 will be made according to the signal handling tables. */
2129 /* First, distinguish signals caused by the debugger from signals
2130 that have to do with the program's own actions.
2131 Note that breakpoint insns may cause SIGTRAP or SIGILL
2132 or SIGEMT, depending on the operating system version.
2133 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2134 and change it to SIGTRAP. */
2136 if (stop_signal
== TARGET_SIGNAL_TRAP
2137 || (breakpoints_inserted
&&
2138 (stop_signal
== TARGET_SIGNAL_ILL
2139 || stop_signal
== TARGET_SIGNAL_EMT
2141 || stop_soon_quietly
)
2143 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2145 stop_print_frame
= 0;
2146 stop_stepping (ecs
);
2149 if (stop_soon_quietly
)
2151 stop_stepping (ecs
);
2155 /* Don't even think about breakpoints
2156 if just proceeded over a breakpoint.
2158 However, if we are trying to proceed over a breakpoint
2159 and end up in sigtramp, then through_sigtramp_breakpoint
2160 will be set and we should check whether we've hit the
2162 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2163 && through_sigtramp_breakpoint
== NULL
)
2164 bpstat_clear (&stop_bpstat
);
2167 /* See if there is a breakpoint at the current PC. */
2168 stop_bpstat
= bpstat_stop_status
2170 /* Pass TRUE if our reason for stopping is something other
2171 than hitting a breakpoint. We do this by checking that
2172 1) stepping is going on and 2) we didn't hit a breakpoint
2173 in a signal handler without an intervening stop in
2174 sigtramp, which is detected by a new stack pointer value
2175 below any usual function calling stack adjustments. */
2176 (currently_stepping (ecs
)
2178 && INNER_THAN (read_sp (), (step_sp
- 16))))
2180 /* Following in case break condition called a
2182 stop_print_frame
= 1;
2185 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2187 = !(bpstat_explains_signal (stop_bpstat
)
2189 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2190 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2191 FRAME_FP (get_current_frame ())))
2192 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2197 = !(bpstat_explains_signal (stop_bpstat
)
2198 /* End of a stack dummy. Some systems (e.g. Sony
2199 news) give another signal besides SIGTRAP, so
2200 check here as well as above. */
2201 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2202 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2203 FRAME_FP (get_current_frame ())))
2205 if (!ecs
->random_signal
)
2206 stop_signal
= TARGET_SIGNAL_TRAP
;
2210 /* When we reach this point, we've pretty much decided
2211 that the reason for stopping must've been a random
2212 (unexpected) signal. */
2215 ecs
->random_signal
= 1;
2216 /* If a fork, vfork or exec event was seen, then there are two
2217 possible responses we can make:
2219 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2220 then we must stop now and issue a prompt. We will resume
2221 the inferior when the user tells us to.
2222 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2223 then we must resume the inferior now and keep checking.
2225 In either case, we must take appropriate steps to "follow" the
2226 the fork/vfork/exec when the inferior is resumed. For example,
2227 if follow-fork-mode is "child", then we must detach from the
2228 parent inferior and follow the new child inferior.
2230 In either case, setting pending_follow causes the next resume()
2231 to take the appropriate following action. */
2232 process_event_stop_test
:
2233 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2235 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2238 stop_signal
= TARGET_SIGNAL_0
;
2243 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2245 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2247 stop_signal
= TARGET_SIGNAL_0
;
2252 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2254 pending_follow
.kind
= ecs
->ws
.kind
;
2255 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2258 stop_signal
= TARGET_SIGNAL_0
;
2264 /* For the program's own signals, act according to
2265 the signal handling tables. */
2267 if (ecs
->random_signal
)
2269 /* Signal not for debugging purposes. */
2272 stopped_by_random_signal
= 1;
2274 if (signal_print
[stop_signal
])
2277 target_terminal_ours_for_output ();
2278 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2280 if (signal_stop
[stop_signal
])
2282 stop_stepping (ecs
);
2285 /* If not going to stop, give terminal back
2286 if we took it away. */
2288 target_terminal_inferior ();
2290 /* Clear the signal if it should not be passed. */
2291 if (signal_program
[stop_signal
] == 0)
2292 stop_signal
= TARGET_SIGNAL_0
;
2294 /* I'm not sure whether this needs to be check_sigtramp2 or
2295 whether it could/should be keep_going.
2297 This used to jump to step_over_function if we are stepping,
2300 Suppose the user does a `next' over a function call, and while
2301 that call is in progress, the inferior receives a signal for
2302 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2303 that case, when we reach this point, there is already a
2304 step-resume breakpoint established, right where it should be:
2305 immediately after the function call the user is "next"-ing
2306 over. If we call step_over_function now, two bad things
2309 - we'll create a new breakpoint, at wherever the current
2310 frame's return address happens to be. That could be
2311 anywhere, depending on what function call happens to be on
2312 the top of the stack at that point. Point is, it's probably
2313 not where we need it.
2315 - the existing step-resume breakpoint (which is at the correct
2316 address) will get orphaned: step_resume_breakpoint will point
2317 to the new breakpoint, and the old step-resume breakpoint
2318 will never be cleaned up.
2320 The old behavior was meant to help HP-UX single-step out of
2321 sigtramps. It would place the new breakpoint at prev_pc, which
2322 was certainly wrong. I don't know the details there, so fixing
2323 this probably breaks that. As with anything else, it's up to
2324 the HP-UX maintainer to furnish a fix that doesn't break other
2325 platforms. --JimB, 20 May 1999 */
2326 check_sigtramp2 (ecs
);
2331 /* Handle cases caused by hitting a breakpoint. */
2333 CORE_ADDR jmp_buf_pc
;
2334 struct bpstat_what what
;
2336 what
= bpstat_what (stop_bpstat
);
2338 if (what
.call_dummy
)
2340 stop_stack_dummy
= 1;
2342 trap_expected_after_continue
= 1;
2346 switch (what
.main_action
)
2348 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2349 /* If we hit the breakpoint at longjmp, disable it for the
2350 duration of this command. Then, install a temporary
2351 breakpoint at the target of the jmp_buf. */
2352 disable_longjmp_breakpoint ();
2353 remove_breakpoints ();
2354 breakpoints_inserted
= 0;
2355 if (!GET_LONGJMP_TARGET (&jmp_buf_pc
))
2361 /* Need to blow away step-resume breakpoint, as it
2362 interferes with us */
2363 if (step_resume_breakpoint
!= NULL
)
2365 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2367 /* Not sure whether we need to blow this away too, but probably
2368 it is like the step-resume breakpoint. */
2369 if (through_sigtramp_breakpoint
!= NULL
)
2371 delete_breakpoint (through_sigtramp_breakpoint
);
2372 through_sigtramp_breakpoint
= NULL
;
2376 /* FIXME - Need to implement nested temporary breakpoints */
2377 if (step_over_calls
> 0)
2378 set_longjmp_resume_breakpoint (jmp_buf_pc
,
2379 get_current_frame ());
2382 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2383 ecs
->handling_longjmp
= 1; /* FIXME */
2387 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2388 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2389 remove_breakpoints ();
2390 breakpoints_inserted
= 0;
2392 /* FIXME - Need to implement nested temporary breakpoints */
2394 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2395 step_frame_address
)))
2397 ecs
->another_trap
= 1;
2402 disable_longjmp_breakpoint ();
2403 ecs
->handling_longjmp
= 0; /* FIXME */
2404 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2406 /* else fallthrough */
2408 case BPSTAT_WHAT_SINGLE
:
2409 if (breakpoints_inserted
)
2411 thread_step_needed
= 1;
2412 remove_breakpoints ();
2414 breakpoints_inserted
= 0;
2415 ecs
->another_trap
= 1;
2416 /* Still need to check other stuff, at least the case
2417 where we are stepping and step out of the right range. */
2420 case BPSTAT_WHAT_STOP_NOISY
:
2421 stop_print_frame
= 1;
2423 /* We are about to nuke the step_resume_breakpoint and
2424 through_sigtramp_breakpoint via the cleanup chain, so
2425 no need to worry about it here. */
2427 stop_stepping (ecs
);
2430 case BPSTAT_WHAT_STOP_SILENT
:
2431 stop_print_frame
= 0;
2433 /* We are about to nuke the step_resume_breakpoint and
2434 through_sigtramp_breakpoint via the cleanup chain, so
2435 no need to worry about it here. */
2437 stop_stepping (ecs
);
2440 case BPSTAT_WHAT_STEP_RESUME
:
2441 /* This proably demands a more elegant solution, but, yeah
2444 This function's use of the simple variable
2445 step_resume_breakpoint doesn't seem to accomodate
2446 simultaneously active step-resume bp's, although the
2447 breakpoint list certainly can.
2449 If we reach here and step_resume_breakpoint is already
2450 NULL, then apparently we have multiple active
2451 step-resume bp's. We'll just delete the breakpoint we
2452 stopped at, and carry on.
2454 Correction: what the code currently does is delete a
2455 step-resume bp, but it makes no effort to ensure that
2456 the one deleted is the one currently stopped at. MVS */
2458 if (step_resume_breakpoint
== NULL
)
2460 step_resume_breakpoint
=
2461 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2463 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2466 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2467 if (through_sigtramp_breakpoint
)
2468 delete_breakpoint (through_sigtramp_breakpoint
);
2469 through_sigtramp_breakpoint
= NULL
;
2471 /* If were waiting for a trap, hitting the step_resume_break
2472 doesn't count as getting it. */
2474 ecs
->another_trap
= 1;
2477 case BPSTAT_WHAT_CHECK_SHLIBS
:
2478 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2481 /* Remove breakpoints, we eventually want to step over the
2482 shlib event breakpoint, and SOLIB_ADD might adjust
2483 breakpoint addresses via breakpoint_re_set. */
2484 if (breakpoints_inserted
)
2485 remove_breakpoints ();
2486 breakpoints_inserted
= 0;
2488 /* Check for any newly added shared libraries if we're
2489 supposed to be adding them automatically. */
2492 /* Switch terminal for any messages produced by
2493 breakpoint_re_set. */
2494 target_terminal_ours_for_output ();
2495 SOLIB_ADD (NULL
, 0, NULL
);
2496 target_terminal_inferior ();
2499 /* Try to reenable shared library breakpoints, additional
2500 code segments in shared libraries might be mapped in now. */
2501 re_enable_breakpoints_in_shlibs ();
2503 /* If requested, stop when the dynamic linker notifies
2504 gdb of events. This allows the user to get control
2505 and place breakpoints in initializer routines for
2506 dynamically loaded objects (among other things). */
2507 if (stop_on_solib_events
)
2509 stop_stepping (ecs
);
2513 /* If we stopped due to an explicit catchpoint, then the
2514 (see above) call to SOLIB_ADD pulled in any symbols
2515 from a newly-loaded library, if appropriate.
2517 We do want the inferior to stop, but not where it is
2518 now, which is in the dynamic linker callback. Rather,
2519 we would like it stop in the user's program, just after
2520 the call that caused this catchpoint to trigger. That
2521 gives the user a more useful vantage from which to
2522 examine their program's state. */
2523 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2525 /* ??rehrauer: If I could figure out how to get the
2526 right return PC from here, we could just set a temp
2527 breakpoint and resume. I'm not sure we can without
2528 cracking open the dld's shared libraries and sniffing
2529 their unwind tables and text/data ranges, and that's
2530 not a terribly portable notion.
2532 Until that time, we must step the inferior out of the
2533 dld callback, and also out of the dld itself (and any
2534 code or stubs in libdld.sl, such as "shl_load" and
2535 friends) until we reach non-dld code. At that point,
2536 we can stop stepping. */
2537 bpstat_get_triggered_catchpoints (stop_bpstat
,
2538 &ecs
->stepping_through_solib_catchpoints
);
2539 ecs
->stepping_through_solib_after_catch
= 1;
2541 /* Be sure to lift all breakpoints, so the inferior does
2542 actually step past this point... */
2543 ecs
->another_trap
= 1;
2548 /* We want to step over this breakpoint, then keep going. */
2549 ecs
->another_trap
= 1;
2556 case BPSTAT_WHAT_LAST
:
2557 /* Not a real code, but listed here to shut up gcc -Wall. */
2559 case BPSTAT_WHAT_KEEP_CHECKING
:
2564 /* We come here if we hit a breakpoint but should not
2565 stop for it. Possibly we also were stepping
2566 and should stop for that. So fall through and
2567 test for stepping. But, if not stepping,
2570 /* Are we stepping to get the inferior out of the dynamic
2571 linker's hook (and possibly the dld itself) after catching
2573 if (ecs
->stepping_through_solib_after_catch
)
2575 #if defined(SOLIB_ADD)
2576 /* Have we reached our destination? If not, keep going. */
2577 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2579 ecs
->another_trap
= 1;
2584 /* Else, stop and report the catchpoint(s) whose triggering
2585 caused us to begin stepping. */
2586 ecs
->stepping_through_solib_after_catch
= 0;
2587 bpstat_clear (&stop_bpstat
);
2588 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2589 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2590 stop_print_frame
= 1;
2591 stop_stepping (ecs
);
2595 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2597 /* This is the old way of detecting the end of the stack dummy.
2598 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2599 handled above. As soon as we can test it on all of them, all
2600 architectures should define it. */
2602 /* If this is the breakpoint at the end of a stack dummy,
2603 just stop silently, unless the user was doing an si/ni, in which
2604 case she'd better know what she's doing. */
2606 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2607 FRAME_FP (get_current_frame ()))
2610 stop_print_frame
= 0;
2611 stop_stack_dummy
= 1;
2613 trap_expected_after_continue
= 1;
2615 stop_stepping (ecs
);
2620 if (step_resume_breakpoint
)
2622 /* Having a step-resume breakpoint overrides anything
2623 else having to do with stepping commands until
2624 that breakpoint is reached. */
2625 /* I'm not sure whether this needs to be check_sigtramp2 or
2626 whether it could/should be keep_going. */
2627 check_sigtramp2 (ecs
);
2632 if (step_range_end
== 0)
2634 /* Likewise if we aren't even stepping. */
2635 /* I'm not sure whether this needs to be check_sigtramp2 or
2636 whether it could/should be keep_going. */
2637 check_sigtramp2 (ecs
);
2642 /* If stepping through a line, keep going if still within it.
2644 Note that step_range_end is the address of the first instruction
2645 beyond the step range, and NOT the address of the last instruction
2647 if (stop_pc
>= step_range_start
2648 && stop_pc
< step_range_end
)
2650 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2651 So definately need to check for sigtramp here. */
2652 check_sigtramp2 (ecs
);
2657 /* We stepped out of the stepping range. */
2659 /* If we are stepping at the source level and entered the runtime
2660 loader dynamic symbol resolution code, we keep on single stepping
2661 until we exit the run time loader code and reach the callee's
2663 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2665 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2667 if (pc_after_resolver
)
2669 /* Set up a step-resume breakpoint at the address
2670 indicated by SKIP_SOLIB_RESOLVER. */
2671 struct symtab_and_line sr_sal
;
2673 sr_sal
.pc
= pc_after_resolver
;
2675 check_for_old_step_resume_breakpoint ();
2676 step_resume_breakpoint
=
2677 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2678 if (breakpoints_inserted
)
2679 insert_breakpoints ();
2686 /* We can't update step_sp every time through the loop, because
2687 reading the stack pointer would slow down stepping too much.
2688 But we can update it every time we leave the step range. */
2689 ecs
->update_step_sp
= 1;
2691 /* Did we just take a signal? */
2692 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2693 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2694 && INNER_THAN (read_sp (), step_sp
))
2696 /* We've just taken a signal; go until we are back to
2697 the point where we took it and one more. */
2699 /* Note: The test above succeeds not only when we stepped
2700 into a signal handler, but also when we step past the last
2701 statement of a signal handler and end up in the return stub
2702 of the signal handler trampoline. To distinguish between
2703 these two cases, check that the frame is INNER_THAN the
2704 previous one below. pai/1997-09-11 */
2708 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2710 if (INNER_THAN (current_frame
, step_frame_address
))
2712 /* We have just taken a signal; go until we are back to
2713 the point where we took it and one more. */
2715 /* This code is needed at least in the following case:
2716 The user types "next" and then a signal arrives (before
2717 the "next" is done). */
2719 /* Note that if we are stopped at a breakpoint, then we need
2720 the step_resume breakpoint to override any breakpoints at
2721 the same location, so that we will still step over the
2722 breakpoint even though the signal happened. */
2723 struct symtab_and_line sr_sal
;
2726 sr_sal
.symtab
= NULL
;
2728 sr_sal
.pc
= prev_pc
;
2729 /* We could probably be setting the frame to
2730 step_frame_address; I don't think anyone thought to
2732 check_for_old_step_resume_breakpoint ();
2733 step_resume_breakpoint
=
2734 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2735 if (breakpoints_inserted
)
2736 insert_breakpoints ();
2740 /* We just stepped out of a signal handler and into
2741 its calling trampoline.
2743 Normally, we'd call step_over_function from
2744 here, but for some reason GDB can't unwind the
2745 stack correctly to find the real PC for the point
2746 user code where the signal trampoline will return
2747 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2748 But signal trampolines are pretty small stubs of
2749 code, anyway, so it's OK instead to just
2750 single-step out. Note: assuming such trampolines
2751 don't exhibit recursion on any platform... */
2752 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2753 &ecs
->stop_func_start
,
2754 &ecs
->stop_func_end
);
2755 /* Readjust stepping range */
2756 step_range_start
= ecs
->stop_func_start
;
2757 step_range_end
= ecs
->stop_func_end
;
2758 ecs
->stepping_through_sigtramp
= 1;
2763 /* If this is stepi or nexti, make sure that the stepping range
2764 gets us past that instruction. */
2765 if (step_range_end
== 1)
2766 /* FIXME: Does this run afoul of the code below which, if
2767 we step into the middle of a line, resets the stepping
2769 step_range_end
= (step_range_start
= prev_pc
) + 1;
2771 ecs
->remove_breakpoints_on_following_step
= 1;
2776 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2777 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2778 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2779 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2780 || ecs
->stop_func_name
== 0)
2782 /* It's a subroutine call. */
2784 if (step_over_calls
== STEP_OVER_NONE
)
2786 /* I presume that step_over_calls is only 0 when we're
2787 supposed to be stepping at the assembly language level
2788 ("stepi"). Just stop. */
2790 print_stop_reason (END_STEPPING_RANGE
, 0);
2791 stop_stepping (ecs
);
2795 if (step_over_calls
== STEP_OVER_ALL
|| IGNORE_HELPER_CALL (stop_pc
))
2797 /* We're doing a "next". */
2799 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2800 && INNER_THAN (step_frame_address
, read_sp()))
2801 /* We stepped out of a signal handler, and into its
2802 calling trampoline. This is misdetected as a
2803 subroutine call, but stepping over the signal
2804 trampoline isn't such a bad idea. In order to do
2805 that, we have to ignore the value in
2806 step_frame_address, since that doesn't represent the
2807 frame that'll reach when we return from the signal
2808 trampoline. Otherwise we'll probably continue to the
2809 end of the program. */
2810 step_frame_address
= 0;
2812 step_over_function (ecs
);
2817 /* If we are in a function call trampoline (a stub between
2818 the calling routine and the real function), locate the real
2819 function. That's what tells us (a) whether we want to step
2820 into it at all, and (b) what prologue we want to run to
2821 the end of, if we do step into it. */
2822 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2824 ecs
->stop_func_start
= tmp
;
2827 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2830 struct symtab_and_line xxx
;
2831 /* Why isn't this s_a_l called "sr_sal", like all of the
2832 other s_a_l's where this code is duplicated? */
2833 INIT_SAL (&xxx
); /* initialize to zeroes */
2835 xxx
.section
= find_pc_overlay (xxx
.pc
);
2836 check_for_old_step_resume_breakpoint ();
2837 step_resume_breakpoint
=
2838 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2839 insert_breakpoints ();
2845 /* If we have line number information for the function we
2846 are thinking of stepping into, step into it.
2848 If there are several symtabs at that PC (e.g. with include
2849 files), just want to know whether *any* of them have line
2850 numbers. find_pc_line handles this. */
2852 struct symtab_and_line tmp_sal
;
2854 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2855 if (tmp_sal
.line
!= 0)
2857 step_into_function (ecs
);
2862 /* If we have no line number and the step-stop-if-no-debug
2863 is set, we stop the step so that the user has a chance to
2864 switch in assembly mode. */
2865 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2868 print_stop_reason (END_STEPPING_RANGE
, 0);
2869 stop_stepping (ecs
);
2873 step_over_function (ecs
);
2879 /* We've wandered out of the step range. */
2881 ecs
->sal
= find_pc_line (stop_pc
, 0);
2883 if (step_range_end
== 1)
2885 /* It is stepi or nexti. We always want to stop stepping after
2888 print_stop_reason (END_STEPPING_RANGE
, 0);
2889 stop_stepping (ecs
);
2893 /* If we're in the return path from a shared library trampoline,
2894 we want to proceed through the trampoline when stepping. */
2895 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2899 /* Determine where this trampoline returns. */
2900 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2902 /* Only proceed through if we know where it's going. */
2905 /* And put the step-breakpoint there and go until there. */
2906 struct symtab_and_line sr_sal
;
2908 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2910 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2911 /* Do not specify what the fp should be when we stop
2912 since on some machines the prologue
2913 is where the new fp value is established. */
2914 check_for_old_step_resume_breakpoint ();
2915 step_resume_breakpoint
=
2916 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2917 if (breakpoints_inserted
)
2918 insert_breakpoints ();
2920 /* Restart without fiddling with the step ranges or
2927 if (ecs
->sal
.line
== 0)
2929 /* We have no line number information. That means to stop
2930 stepping (does this always happen right after one instruction,
2931 when we do "s" in a function with no line numbers,
2932 or can this happen as a result of a return or longjmp?). */
2934 print_stop_reason (END_STEPPING_RANGE
, 0);
2935 stop_stepping (ecs
);
2939 if ((stop_pc
== ecs
->sal
.pc
)
2940 && (ecs
->current_line
!= ecs
->sal
.line
|| ecs
->current_symtab
!= ecs
->sal
.symtab
))
2942 /* We are at the start of a different line. So stop. Note that
2943 we don't stop if we step into the middle of a different line.
2944 That is said to make things like for (;;) statements work
2947 print_stop_reason (END_STEPPING_RANGE
, 0);
2948 stop_stepping (ecs
);
2952 /* We aren't done stepping.
2954 Optimize by setting the stepping range to the line.
2955 (We might not be in the original line, but if we entered a
2956 new line in mid-statement, we continue stepping. This makes
2957 things like for(;;) statements work better.) */
2959 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2961 /* If this is the last line of the function, don't keep stepping
2962 (it would probably step us out of the function).
2963 This is particularly necessary for a one-line function,
2964 in which after skipping the prologue we better stop even though
2965 we will be in mid-line. */
2967 print_stop_reason (END_STEPPING_RANGE
, 0);
2968 stop_stepping (ecs
);
2971 step_range_start
= ecs
->sal
.pc
;
2972 step_range_end
= ecs
->sal
.end
;
2973 step_frame_address
= FRAME_FP (get_current_frame ());
2974 ecs
->current_line
= ecs
->sal
.line
;
2975 ecs
->current_symtab
= ecs
->sal
.symtab
;
2977 /* In the case where we just stepped out of a function into the middle
2978 of a line of the caller, continue stepping, but step_frame_address
2979 must be modified to current frame */
2981 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2982 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2983 step_frame_address
= current_frame
;
2988 } /* extra brace, to preserve old indentation */
2991 /* Are we in the middle of stepping? */
2994 currently_stepping (struct execution_control_state
*ecs
)
2996 return ((through_sigtramp_breakpoint
== NULL
2997 && !ecs
->handling_longjmp
2998 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
3000 || ecs
->stepping_through_solib_after_catch
3001 || bpstat_should_step ());
3005 check_sigtramp2 (struct execution_control_state
*ecs
)
3008 && IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
3009 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
3010 && INNER_THAN (read_sp (), step_sp
))
3012 /* What has happened here is that we have just stepped the
3013 inferior with a signal (because it is a signal which
3014 shouldn't make us stop), thus stepping into sigtramp.
3016 So we need to set a step_resume_break_address breakpoint and
3017 continue until we hit it, and then step. FIXME: This should
3018 be more enduring than a step_resume breakpoint; we should
3019 know that we will later need to keep going rather than
3020 re-hitting the breakpoint here (see the testsuite,
3021 gdb.base/signals.exp where it says "exceedingly difficult"). */
3023 struct symtab_and_line sr_sal
;
3025 INIT_SAL (&sr_sal
); /* initialize to zeroes */
3026 sr_sal
.pc
= prev_pc
;
3027 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3028 /* We perhaps could set the frame if we kept track of what the
3029 frame corresponding to prev_pc was. But we don't, so don't. */
3030 through_sigtramp_breakpoint
=
3031 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
3032 if (breakpoints_inserted
)
3033 insert_breakpoints ();
3035 ecs
->remove_breakpoints_on_following_step
= 1;
3036 ecs
->another_trap
= 1;
3040 /* Subroutine call with source code we should not step over. Do step
3041 to the first line of code in it. */
3044 step_into_function (struct execution_control_state
*ecs
)
3047 struct symtab_and_line sr_sal
;
3049 s
= find_pc_symtab (stop_pc
);
3050 if (s
&& s
->language
!= language_asm
)
3051 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
3053 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
3054 /* Use the step_resume_break to step until the end of the prologue,
3055 even if that involves jumps (as it seems to on the vax under
3057 /* If the prologue ends in the middle of a source line, continue to
3058 the end of that source line (if it is still within the function).
3059 Otherwise, just go to end of prologue. */
3060 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
3061 /* no, don't either. It skips any code that's legitimately on the
3065 && ecs
->sal
.pc
!= ecs
->stop_func_start
3066 && ecs
->sal
.end
< ecs
->stop_func_end
)
3067 ecs
->stop_func_start
= ecs
->sal
.end
;
3070 if (ecs
->stop_func_start
== stop_pc
)
3072 /* We are already there: stop now. */
3074 print_stop_reason (END_STEPPING_RANGE
, 0);
3075 stop_stepping (ecs
);
3080 /* Put the step-breakpoint there and go until there. */
3081 INIT_SAL (&sr_sal
); /* initialize to zeroes */
3082 sr_sal
.pc
= ecs
->stop_func_start
;
3083 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3084 /* Do not specify what the fp should be when we stop since on
3085 some machines the prologue is where the new fp value is
3087 check_for_old_step_resume_breakpoint ();
3088 step_resume_breakpoint
=
3089 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
3090 if (breakpoints_inserted
)
3091 insert_breakpoints ();
3093 /* And make sure stepping stops right away then. */
3094 step_range_end
= step_range_start
;
3099 /* We've just entered a callee, and we wish to resume until it returns
3100 to the caller. Setting a step_resume breakpoint on the return
3101 address will catch a return from the callee.
3103 However, if the callee is recursing, we want to be careful not to
3104 catch returns of those recursive calls, but only of THIS instance
3107 To do this, we set the step_resume bp's frame to our current
3108 caller's frame (step_frame_address, which is set by the "next" or
3109 "until" command, before execution begins). */
3112 step_over_function (struct execution_control_state
*ecs
)
3114 struct symtab_and_line sr_sal
;
3116 INIT_SAL (&sr_sal
); /* initialize to zeros */
3117 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3118 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3120 check_for_old_step_resume_breakpoint ();
3121 step_resume_breakpoint
=
3122 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
3124 if (step_frame_address
&& !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
3125 step_resume_breakpoint
->frame
= step_frame_address
;
3127 if (breakpoints_inserted
)
3128 insert_breakpoints ();
3132 stop_stepping (struct execution_control_state
*ecs
)
3134 if (target_has_execution
)
3136 /* Are we stopping for a vfork event? We only stop when we see
3137 the child's event. However, we may not yet have seen the
3138 parent's event. And, inferior_ptid is still set to the
3139 parent's pid, until we resume again and follow either the
3142 To ensure that we can really touch inferior_ptid (aka, the
3143 parent process) -- which calls to functions like read_pc
3144 implicitly do -- wait on the parent if necessary. */
3145 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3146 && !pending_follow
.fork_event
.saw_parent_fork
)
3152 if (target_wait_hook
)
3153 parent_ptid
= target_wait_hook (pid_to_ptid (-1), &(ecs
->ws
));
3155 parent_ptid
= target_wait (pid_to_ptid (-1), &(ecs
->ws
));
3157 while (! ptid_equal (parent_ptid
, inferior_ptid
));
3160 /* Assuming the inferior still exists, set these up for next
3161 time, just like we did above if we didn't break out of the
3163 prev_pc
= read_pc ();
3164 prev_func_start
= ecs
->stop_func_start
;
3165 prev_func_name
= ecs
->stop_func_name
;
3168 /* Let callers know we don't want to wait for the inferior anymore. */
3169 ecs
->wait_some_more
= 0;
3172 /* This function handles various cases where we need to continue
3173 waiting for the inferior. */
3174 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3177 keep_going (struct execution_control_state
*ecs
)
3179 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3180 vforked child between its creation and subsequent exit or call to
3181 exec(). However, I had big problems in this rather creaky exec
3182 engine, getting that to work. The fundamental problem is that
3183 I'm trying to debug two processes via an engine that only
3184 understands a single process with possibly multiple threads.
3186 Hence, this spot is known to have problems when
3187 target_can_follow_vfork_prior_to_exec returns 1. */
3189 /* Save the pc before execution, to compare with pc after stop. */
3190 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3191 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3192 BREAK is defined, the
3193 original pc would not have
3194 been at the start of a
3196 prev_func_name
= ecs
->stop_func_name
;
3198 if (ecs
->update_step_sp
)
3199 step_sp
= read_sp ();
3200 ecs
->update_step_sp
= 0;
3202 /* If we did not do break;, it means we should keep running the
3203 inferior and not return to debugger. */
3205 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3207 /* We took a signal (which we are supposed to pass through to
3208 the inferior, else we'd have done a break above) and we
3209 haven't yet gotten our trap. Simply continue. */
3210 resume (currently_stepping (ecs
), stop_signal
);
3214 /* Either the trap was not expected, but we are continuing
3215 anyway (the user asked that this signal be passed to the
3218 The signal was SIGTRAP, e.g. it was our signal, but we
3219 decided we should resume from it.
3221 We're going to run this baby now!
3223 Insert breakpoints now, unless we are trying to one-proceed
3224 past a breakpoint. */
3225 /* If we've just finished a special step resume and we don't
3226 want to hit a breakpoint, pull em out. */
3227 if (step_resume_breakpoint
== NULL
3228 && through_sigtramp_breakpoint
== NULL
3229 && ecs
->remove_breakpoints_on_following_step
)
3231 ecs
->remove_breakpoints_on_following_step
= 0;
3232 remove_breakpoints ();
3233 breakpoints_inserted
= 0;
3235 else if (!breakpoints_inserted
&&
3236 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3238 breakpoints_failed
= insert_breakpoints ();
3239 if (breakpoints_failed
)
3241 stop_stepping (ecs
);
3244 breakpoints_inserted
= 1;
3247 trap_expected
= ecs
->another_trap
;
3249 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3250 specifies that such a signal should be delivered to the
3253 Typically, this would occure when a user is debugging a
3254 target monitor on a simulator: the target monitor sets a
3255 breakpoint; the simulator encounters this break-point and
3256 halts the simulation handing control to GDB; GDB, noteing
3257 that the break-point isn't valid, returns control back to the
3258 simulator; the simulator then delivers the hardware
3259 equivalent of a SIGNAL_TRAP to the program being debugged. */
3261 if (stop_signal
== TARGET_SIGNAL_TRAP
3262 && !signal_program
[stop_signal
])
3263 stop_signal
= TARGET_SIGNAL_0
;
3265 #ifdef SHIFT_INST_REGS
3266 /* I'm not sure when this following segment applies. I do know,
3267 now, that we shouldn't rewrite the regs when we were stopped
3268 by a random signal from the inferior process. */
3269 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3270 (this is only used on the 88k). */
3272 if (!bpstat_explains_signal (stop_bpstat
)
3273 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
3274 && !stopped_by_random_signal
)
3276 #endif /* SHIFT_INST_REGS */
3278 resume (currently_stepping (ecs
), stop_signal
);
3281 prepare_to_wait (ecs
);
3284 /* This function normally comes after a resume, before
3285 handle_inferior_event exits. It takes care of any last bits of
3286 housekeeping, and sets the all-important wait_some_more flag. */
3289 prepare_to_wait (struct execution_control_state
*ecs
)
3291 if (ecs
->infwait_state
== infwait_normal_state
)
3293 overlay_cache_invalid
= 1;
3295 /* We have to invalidate the registers BEFORE calling
3296 target_wait because they can be loaded from the target while
3297 in target_wait. This makes remote debugging a bit more
3298 efficient for those targets that provide critical registers
3299 as part of their normal status mechanism. */
3301 registers_changed ();
3302 ecs
->waiton_ptid
= pid_to_ptid (-1);
3303 ecs
->wp
= &(ecs
->ws
);
3305 /* This is the old end of the while loop. Let everybody know we
3306 want to wait for the inferior some more and get called again
3308 ecs
->wait_some_more
= 1;
3311 /* Print why the inferior has stopped. We always print something when
3312 the inferior exits, or receives a signal. The rest of the cases are
3313 dealt with later on in normal_stop() and print_it_typical(). Ideally
3314 there should be a call to this function from handle_inferior_event()
3315 each time stop_stepping() is called.*/
3317 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3319 switch (stop_reason
)
3322 /* We don't deal with these cases from handle_inferior_event()
3325 case END_STEPPING_RANGE
:
3326 /* We are done with a step/next/si/ni command. */
3327 /* For now print nothing. */
3329 /* Print a message only if not in the middle of doing a "step n"
3330 operation for n > 1 */
3331 if (!step_multi
|| !stop_step
)
3332 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3333 ui_out_field_string (uiout
, "reason", "end-stepping-range");
3336 case BREAKPOINT_HIT
:
3337 /* We found a breakpoint. */
3338 /* For now print nothing. */
3341 /* The inferior was terminated by a signal. */
3343 annotate_signalled ();
3344 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3345 ui_out_field_string (uiout
, "reason", "exited-signalled");
3346 ui_out_text (uiout
, "\nProgram terminated with signal ");
3347 annotate_signal_name ();
3348 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3349 annotate_signal_name_end ();
3350 ui_out_text (uiout
, ", ");
3351 annotate_signal_string ();
3352 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3353 annotate_signal_string_end ();
3354 ui_out_text (uiout
, ".\n");
3355 ui_out_text (uiout
, "The program no longer exists.\n");
3357 annotate_signalled ();
3358 printf_filtered ("\nProgram terminated with signal ");
3359 annotate_signal_name ();
3360 printf_filtered ("%s", target_signal_to_name (stop_info
));
3361 annotate_signal_name_end ();
3362 printf_filtered (", ");
3363 annotate_signal_string ();
3364 printf_filtered ("%s", target_signal_to_string (stop_info
));
3365 annotate_signal_string_end ();
3366 printf_filtered (".\n");
3368 printf_filtered ("The program no longer exists.\n");
3369 gdb_flush (gdb_stdout
);
3373 /* The inferior program is finished. */
3375 annotate_exited (stop_info
);
3378 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3379 ui_out_field_string (uiout
, "reason", "exited");
3380 ui_out_text (uiout
, "\nProgram exited with code ");
3381 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) stop_info
);
3382 ui_out_text (uiout
, ".\n");
3386 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3387 ui_out_field_string (uiout
, "reason", "exited-normally");
3388 ui_out_text (uiout
, "\nProgram exited normally.\n");
3391 annotate_exited (stop_info
);
3393 printf_filtered ("\nProgram exited with code 0%o.\n",
3394 (unsigned int) stop_info
);
3396 printf_filtered ("\nProgram exited normally.\n");
3399 case SIGNAL_RECEIVED
:
3400 /* Signal received. The signal table tells us to print about
3404 ui_out_text (uiout
, "\nProgram received signal ");
3405 annotate_signal_name ();
3406 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3407 annotate_signal_name_end ();
3408 ui_out_text (uiout
, ", ");
3409 annotate_signal_string ();
3410 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3411 annotate_signal_string_end ();
3412 ui_out_text (uiout
, ".\n");
3415 printf_filtered ("\nProgram received signal ");
3416 annotate_signal_name ();
3417 printf_filtered ("%s", target_signal_to_name (stop_info
));
3418 annotate_signal_name_end ();
3419 printf_filtered (", ");
3420 annotate_signal_string ();
3421 printf_filtered ("%s", target_signal_to_string (stop_info
));
3422 annotate_signal_string_end ();
3423 printf_filtered (".\n");
3424 gdb_flush (gdb_stdout
);
3428 internal_error (__FILE__
, __LINE__
,
3429 "print_stop_reason: unrecognized enum value");
3435 /* Here to return control to GDB when the inferior stops for real.
3436 Print appropriate messages, remove breakpoints, give terminal our modes.
3438 STOP_PRINT_FRAME nonzero means print the executing frame
3439 (pc, function, args, file, line number and line text).
3440 BREAKPOINTS_FAILED nonzero means stop was due to error
3441 attempting to insert breakpoints. */
3446 /* As with the notification of thread events, we want to delay
3447 notifying the user that we've switched thread context until
3448 the inferior actually stops.
3450 (Note that there's no point in saying anything if the inferior
3452 if (! ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3453 && target_has_execution
)
3455 target_terminal_ours_for_output ();
3456 printf_filtered ("[Switching to %s]\n",
3457 target_pid_or_tid_to_str (inferior_ptid
));
3458 previous_inferior_ptid
= inferior_ptid
;
3461 /* Make sure that the current_frame's pc is correct. This
3462 is a correction for setting up the frame info before doing
3463 DECR_PC_AFTER_BREAK */
3464 if (target_has_execution
&& get_current_frame ())
3465 (get_current_frame ())->pc
= read_pc ();
3467 if (breakpoints_failed
)
3469 target_terminal_ours_for_output ();
3470 print_sys_errmsg ("While inserting breakpoints", breakpoints_failed
);
3471 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3472 The same program may be running in another process,\n\
3473 or you may have requested too many hardware breakpoints\n\
3474 and/or watchpoints.\n");
3477 if (target_has_execution
&& breakpoints_inserted
)
3479 if (remove_breakpoints ())
3481 target_terminal_ours_for_output ();
3482 printf_filtered ("Cannot remove breakpoints because ");
3483 printf_filtered ("program is no longer writable.\n");
3484 printf_filtered ("It might be running in another process.\n");
3485 printf_filtered ("Further execution is probably impossible.\n");
3488 breakpoints_inserted
= 0;
3490 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3491 Delete any breakpoint that is to be deleted at the next stop. */
3493 breakpoint_auto_delete (stop_bpstat
);
3495 /* If an auto-display called a function and that got a signal,
3496 delete that auto-display to avoid an infinite recursion. */
3498 if (stopped_by_random_signal
)
3499 disable_current_display ();
3501 /* Don't print a message if in the middle of doing a "step n"
3502 operation for n > 1 */
3503 if (step_multi
&& stop_step
)
3506 target_terminal_ours ();
3508 /* Look up the hook_stop and run it if it exists. */
3510 if (stop_command
&& stop_command
->hook_pre
)
3512 catch_errors (hook_stop_stub
, stop_command
->hook_pre
,
3513 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3516 if (!target_has_stack
)
3522 /* Select innermost stack frame - i.e., current frame is frame 0,
3523 and current location is based on that.
3524 Don't do this on return from a stack dummy routine,
3525 or if the program has exited. */
3527 if (!stop_stack_dummy
)
3529 select_frame (get_current_frame (), 0);
3531 /* Print current location without a level number, if
3532 we have changed functions or hit a breakpoint.
3533 Print source line if we have one.
3534 bpstat_print() contains the logic deciding in detail
3535 what to print, based on the event(s) that just occurred. */
3537 if (stop_print_frame
3542 int do_frame_printing
= 1;
3544 bpstat_ret
= bpstat_print (stop_bpstat
);
3549 && step_frame_address
== FRAME_FP (get_current_frame ())
3550 && step_start_function
== find_pc_function (stop_pc
))
3551 source_flag
= SRC_LINE
; /* finished step, just print source line */
3553 source_flag
= SRC_AND_LOC
; /* print location and source line */
3555 case PRINT_SRC_AND_LOC
:
3556 source_flag
= SRC_AND_LOC
; /* print location and source line */
3558 case PRINT_SRC_ONLY
:
3559 source_flag
= SRC_LINE
;
3562 source_flag
= SRC_LINE
; /* something bogus */
3563 do_frame_printing
= 0;
3566 internal_error (__FILE__
, __LINE__
,
3570 /* For mi, have the same behavior every time we stop:
3571 print everything but the source line. */
3572 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3573 source_flag
= LOC_AND_ADDRESS
;
3577 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3578 ui_out_field_int (uiout
, "thread-id",
3579 pid_to_thread_id (inferior_ptid
));
3581 /* The behavior of this routine with respect to the source
3583 SRC_LINE: Print only source line
3584 LOCATION: Print only location
3585 SRC_AND_LOC: Print location and source line */
3586 if (do_frame_printing
)
3587 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
3589 /* Display the auto-display expressions. */
3594 /* Save the function value return registers, if we care.
3595 We might be about to restore their previous contents. */
3596 if (proceed_to_finish
)
3597 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
3599 if (stop_stack_dummy
)
3601 /* Pop the empty frame that contains the stack dummy.
3602 POP_FRAME ends with a setting of the current frame, so we
3603 can use that next. */
3605 /* Set stop_pc to what it was before we called the function.
3606 Can't rely on restore_inferior_status because that only gets
3607 called if we don't stop in the called function. */
3608 stop_pc
= read_pc ();
3609 select_frame (get_current_frame (), 0);
3613 TUIDO (((TuiOpaqueFuncPtr
) tui_vCheckDataValues
, selected_frame
));
3616 annotate_stopped ();
3620 hook_stop_stub (void *cmd
)
3622 execute_user_command ((struct cmd_list_element
*) cmd
, 0);
3627 signal_stop_state (int signo
)
3629 return signal_stop
[signo
];
3633 signal_print_state (int signo
)
3635 return signal_print
[signo
];
3639 signal_pass_state (int signo
)
3641 return signal_program
[signo
];
3644 int signal_stop_update (signo
, state
)
3648 int ret
= signal_stop
[signo
];
3649 signal_stop
[signo
] = state
;
3653 int signal_print_update (signo
, state
)
3657 int ret
= signal_print
[signo
];
3658 signal_print
[signo
] = state
;
3662 int signal_pass_update (signo
, state
)
3666 int ret
= signal_program
[signo
];
3667 signal_program
[signo
] = state
;
3672 sig_print_header (void)
3675 Signal Stop\tPrint\tPass to program\tDescription\n");
3679 sig_print_info (enum target_signal oursig
)
3681 char *name
= target_signal_to_name (oursig
);
3682 int name_padding
= 13 - strlen (name
);
3684 if (name_padding
<= 0)
3687 printf_filtered ("%s", name
);
3688 printf_filtered ("%*.*s ", name_padding
, name_padding
,
3690 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3691 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3692 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3693 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3696 /* Specify how various signals in the inferior should be handled. */
3699 handle_command (char *args
, int from_tty
)
3702 int digits
, wordlen
;
3703 int sigfirst
, signum
, siglast
;
3704 enum target_signal oursig
;
3707 unsigned char *sigs
;
3708 struct cleanup
*old_chain
;
3712 error_no_arg ("signal to handle");
3715 /* Allocate and zero an array of flags for which signals to handle. */
3717 nsigs
= (int) TARGET_SIGNAL_LAST
;
3718 sigs
= (unsigned char *) alloca (nsigs
);
3719 memset (sigs
, 0, nsigs
);
3721 /* Break the command line up into args. */
3723 argv
= buildargv (args
);
3728 old_chain
= make_cleanup_freeargv (argv
);
3730 /* Walk through the args, looking for signal oursigs, signal names, and
3731 actions. Signal numbers and signal names may be interspersed with
3732 actions, with the actions being performed for all signals cumulatively
3733 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3735 while (*argv
!= NULL
)
3737 wordlen
= strlen (*argv
);
3738 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3742 sigfirst
= siglast
= -1;
3744 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3746 /* Apply action to all signals except those used by the
3747 debugger. Silently skip those. */
3750 siglast
= nsigs
- 1;
3752 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3754 SET_SIGS (nsigs
, sigs
, signal_stop
);
3755 SET_SIGS (nsigs
, sigs
, signal_print
);
3757 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3759 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3761 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3763 SET_SIGS (nsigs
, sigs
, signal_print
);
3765 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3767 SET_SIGS (nsigs
, sigs
, signal_program
);
3769 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3771 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3773 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3775 SET_SIGS (nsigs
, sigs
, signal_program
);
3777 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3779 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3780 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3782 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3784 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3786 else if (digits
> 0)
3788 /* It is numeric. The numeric signal refers to our own
3789 internal signal numbering from target.h, not to host/target
3790 signal number. This is a feature; users really should be
3791 using symbolic names anyway, and the common ones like
3792 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3794 sigfirst
= siglast
= (int)
3795 target_signal_from_command (atoi (*argv
));
3796 if ((*argv
)[digits
] == '-')
3799 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3801 if (sigfirst
> siglast
)
3803 /* Bet he didn't figure we'd think of this case... */
3811 oursig
= target_signal_from_name (*argv
);
3812 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3814 sigfirst
= siglast
= (int) oursig
;
3818 /* Not a number and not a recognized flag word => complain. */
3819 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3823 /* If any signal numbers or symbol names were found, set flags for
3824 which signals to apply actions to. */
3826 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3828 switch ((enum target_signal
) signum
)
3830 case TARGET_SIGNAL_TRAP
:
3831 case TARGET_SIGNAL_INT
:
3832 if (!allsigs
&& !sigs
[signum
])
3834 if (query ("%s is used by the debugger.\n\
3835 Are you sure you want to change it? ",
3836 target_signal_to_name
3837 ((enum target_signal
) signum
)))
3843 printf_unfiltered ("Not confirmed, unchanged.\n");
3844 gdb_flush (gdb_stdout
);
3848 case TARGET_SIGNAL_0
:
3849 case TARGET_SIGNAL_DEFAULT
:
3850 case TARGET_SIGNAL_UNKNOWN
:
3851 /* Make sure that "all" doesn't print these. */
3862 target_notice_signals (inferior_ptid
);
3866 /* Show the results. */
3867 sig_print_header ();
3868 for (signum
= 0; signum
< nsigs
; signum
++)
3872 sig_print_info (signum
);
3877 do_cleanups (old_chain
);
3881 xdb_handle_command (char *args
, int from_tty
)
3884 struct cleanup
*old_chain
;
3886 /* Break the command line up into args. */
3888 argv
= buildargv (args
);
3893 old_chain
= make_cleanup_freeargv (argv
);
3894 if (argv
[1] != (char *) NULL
)
3899 bufLen
= strlen (argv
[0]) + 20;
3900 argBuf
= (char *) xmalloc (bufLen
);
3904 enum target_signal oursig
;
3906 oursig
= target_signal_from_name (argv
[0]);
3907 memset (argBuf
, 0, bufLen
);
3908 if (strcmp (argv
[1], "Q") == 0)
3909 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3912 if (strcmp (argv
[1], "s") == 0)
3914 if (!signal_stop
[oursig
])
3915 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3917 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3919 else if (strcmp (argv
[1], "i") == 0)
3921 if (!signal_program
[oursig
])
3922 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3924 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3926 else if (strcmp (argv
[1], "r") == 0)
3928 if (!signal_print
[oursig
])
3929 sprintf (argBuf
, "%s %s", argv
[0], "print");
3931 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3937 handle_command (argBuf
, from_tty
);
3939 printf_filtered ("Invalid signal handling flag.\n");
3944 do_cleanups (old_chain
);
3947 /* Print current contents of the tables set by the handle command.
3948 It is possible we should just be printing signals actually used
3949 by the current target (but for things to work right when switching
3950 targets, all signals should be in the signal tables). */
3953 signals_info (char *signum_exp
, int from_tty
)
3955 enum target_signal oursig
;
3956 sig_print_header ();
3960 /* First see if this is a symbol name. */
3961 oursig
= target_signal_from_name (signum_exp
);
3962 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3964 /* No, try numeric. */
3966 target_signal_from_command (parse_and_eval_long (signum_exp
));
3968 sig_print_info (oursig
);
3972 printf_filtered ("\n");
3973 /* These ugly casts brought to you by the native VAX compiler. */
3974 for (oursig
= TARGET_SIGNAL_FIRST
;
3975 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3976 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3980 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3981 && oursig
!= TARGET_SIGNAL_DEFAULT
3982 && oursig
!= TARGET_SIGNAL_0
)
3983 sig_print_info (oursig
);
3986 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3989 struct inferior_status
3991 enum target_signal stop_signal
;
3995 int stop_stack_dummy
;
3996 int stopped_by_random_signal
;
3998 CORE_ADDR step_range_start
;
3999 CORE_ADDR step_range_end
;
4000 CORE_ADDR step_frame_address
;
4001 enum step_over_calls_kind step_over_calls
;
4002 CORE_ADDR step_resume_break_address
;
4003 int stop_after_trap
;
4004 int stop_soon_quietly
;
4005 CORE_ADDR selected_frame_address
;
4006 char *stop_registers
;
4008 /* These are here because if call_function_by_hand has written some
4009 registers and then decides to call error(), we better not have changed
4014 int breakpoint_proceeded
;
4015 int restore_stack_info
;
4016 int proceed_to_finish
;
4019 static struct inferior_status
*
4020 xmalloc_inferior_status (void)
4022 struct inferior_status
*inf_status
;
4023 inf_status
= xmalloc (sizeof (struct inferior_status
));
4024 inf_status
->stop_registers
= xmalloc (REGISTER_BYTES
);
4025 inf_status
->registers
= xmalloc (REGISTER_BYTES
);
4030 free_inferior_status (struct inferior_status
*inf_status
)
4032 xfree (inf_status
->registers
);
4033 xfree (inf_status
->stop_registers
);
4038 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
4041 int size
= REGISTER_RAW_SIZE (regno
);
4042 void *buf
= alloca (size
);
4043 store_signed_integer (buf
, size
, val
);
4044 memcpy (&inf_status
->registers
[REGISTER_BYTE (regno
)], buf
, size
);
4047 /* Save all of the information associated with the inferior<==>gdb
4048 connection. INF_STATUS is a pointer to a "struct inferior_status"
4049 (defined in inferior.h). */
4051 struct inferior_status
*
4052 save_inferior_status (int restore_stack_info
)
4054 struct inferior_status
*inf_status
= xmalloc_inferior_status ();
4056 inf_status
->stop_signal
= stop_signal
;
4057 inf_status
->stop_pc
= stop_pc
;
4058 inf_status
->stop_step
= stop_step
;
4059 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
4060 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
4061 inf_status
->trap_expected
= trap_expected
;
4062 inf_status
->step_range_start
= step_range_start
;
4063 inf_status
->step_range_end
= step_range_end
;
4064 inf_status
->step_frame_address
= step_frame_address
;
4065 inf_status
->step_over_calls
= step_over_calls
;
4066 inf_status
->stop_after_trap
= stop_after_trap
;
4067 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
4068 /* Save original bpstat chain here; replace it with copy of chain.
4069 If caller's caller is walking the chain, they'll be happier if we
4070 hand them back the original chain when restore_inferior_status is
4072 inf_status
->stop_bpstat
= stop_bpstat
;
4073 stop_bpstat
= bpstat_copy (stop_bpstat
);
4074 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
4075 inf_status
->restore_stack_info
= restore_stack_info
;
4076 inf_status
->proceed_to_finish
= proceed_to_finish
;
4078 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
4080 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
4082 record_selected_frame (&(inf_status
->selected_frame_address
),
4083 &(inf_status
->selected_level
));
4087 struct restore_selected_frame_args
4089 CORE_ADDR frame_address
;
4094 restore_selected_frame (void *args
)
4096 struct restore_selected_frame_args
*fr
=
4097 (struct restore_selected_frame_args
*) args
;
4098 struct frame_info
*frame
;
4099 int level
= fr
->level
;
4101 frame
= find_relative_frame (get_current_frame (), &level
);
4103 /* If inf_status->selected_frame_address is NULL, there was no
4104 previously selected frame. */
4105 if (frame
== NULL
||
4106 /* FRAME_FP (frame) != fr->frame_address || */
4107 /* elz: deleted this check as a quick fix to the problem that
4108 for function called by hand gdb creates no internal frame
4109 structure and the real stack and gdb's idea of stack are
4110 different if nested calls by hands are made.
4112 mvs: this worries me. */
4115 warning ("Unable to restore previously selected frame.\n");
4119 select_frame (frame
, fr
->level
);
4125 restore_inferior_status (struct inferior_status
*inf_status
)
4127 stop_signal
= inf_status
->stop_signal
;
4128 stop_pc
= inf_status
->stop_pc
;
4129 stop_step
= inf_status
->stop_step
;
4130 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4131 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4132 trap_expected
= inf_status
->trap_expected
;
4133 step_range_start
= inf_status
->step_range_start
;
4134 step_range_end
= inf_status
->step_range_end
;
4135 step_frame_address
= inf_status
->step_frame_address
;
4136 step_over_calls
= inf_status
->step_over_calls
;
4137 stop_after_trap
= inf_status
->stop_after_trap
;
4138 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
4139 bpstat_clear (&stop_bpstat
);
4140 stop_bpstat
= inf_status
->stop_bpstat
;
4141 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4142 proceed_to_finish
= inf_status
->proceed_to_finish
;
4144 /* FIXME: Is the restore of stop_registers always needed */
4145 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
4147 /* The inferior can be gone if the user types "print exit(0)"
4148 (and perhaps other times). */
4149 if (target_has_execution
)
4150 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
4152 /* FIXME: If we are being called after stopping in a function which
4153 is called from gdb, we should not be trying to restore the
4154 selected frame; it just prints a spurious error message (The
4155 message is useful, however, in detecting bugs in gdb (like if gdb
4156 clobbers the stack)). In fact, should we be restoring the
4157 inferior status at all in that case? . */
4159 if (target_has_stack
&& inf_status
->restore_stack_info
)
4161 struct restore_selected_frame_args fr
;
4162 fr
.level
= inf_status
->selected_level
;
4163 fr
.frame_address
= inf_status
->selected_frame_address
;
4164 /* The point of catch_errors is that if the stack is clobbered,
4165 walking the stack might encounter a garbage pointer and error()
4166 trying to dereference it. */
4167 if (catch_errors (restore_selected_frame
, &fr
,
4168 "Unable to restore previously selected frame:\n",
4169 RETURN_MASK_ERROR
) == 0)
4170 /* Error in restoring the selected frame. Select the innermost
4174 select_frame (get_current_frame (), 0);
4178 free_inferior_status (inf_status
);
4182 do_restore_inferior_status_cleanup (void *sts
)
4184 restore_inferior_status (sts
);
4188 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4190 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4194 discard_inferior_status (struct inferior_status
*inf_status
)
4196 /* See save_inferior_status for info on stop_bpstat. */
4197 bpstat_clear (&inf_status
->stop_bpstat
);
4198 free_inferior_status (inf_status
);
4201 /* Oft used ptids */
4203 ptid_t minus_one_ptid
;
4205 /* Create a ptid given the necessary PID, LWP, and TID components. */
4208 ptid_build (int pid
, long lwp
, long tid
)
4218 /* Create a ptid from just a pid. */
4221 pid_to_ptid (int pid
)
4223 return ptid_build (pid
, 0, 0);
4226 /* Fetch the pid (process id) component from a ptid. */
4229 ptid_get_pid (ptid_t ptid
)
4234 /* Fetch the lwp (lightweight process) component from a ptid. */
4237 ptid_get_lwp (ptid_t ptid
)
4242 /* Fetch the tid (thread id) component from a ptid. */
4245 ptid_get_tid (ptid_t ptid
)
4250 /* ptid_equal() is used to test equality of two ptids. */
4253 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4255 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4256 && ptid1
.tid
== ptid2
.tid
);
4259 /* restore_inferior_ptid() will be used by the cleanup machinery
4260 to restore the inferior_ptid value saved in a call to
4261 save_inferior_ptid(). */
4264 restore_inferior_ptid (void *arg
)
4266 ptid_t
*saved_ptid_ptr
= arg
;
4267 inferior_ptid
= *saved_ptid_ptr
;
4271 /* Save the value of inferior_ptid so that it may be restored by a
4272 later call to do_cleanups(). Returns the struct cleanup pointer
4273 needed for later doing the cleanup. */
4276 save_inferior_ptid (void)
4278 ptid_t
*saved_ptid_ptr
;
4280 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4281 *saved_ptid_ptr
= inferior_ptid
;
4282 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4289 stop_registers
= xmalloc (REGISTER_BYTES
);
4293 _initialize_infrun (void)
4296 register int numsigs
;
4297 struct cmd_list_element
*c
;
4301 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4302 register_gdbarch_swap (NULL
, 0, build_infrun
);
4304 add_info ("signals", signals_info
,
4305 "What debugger does when program gets various signals.\n\
4306 Specify a signal as argument to print info on that signal only.");
4307 add_info_alias ("handle", "signals", 0);
4309 add_com ("handle", class_run
, handle_command
,
4310 concat ("Specify how to handle a signal.\n\
4311 Args are signals and actions to apply to those signals.\n\
4312 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4313 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4314 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4315 The special arg \"all\" is recognized to mean all signals except those\n\
4316 used by the debugger, typically SIGTRAP and SIGINT.\n",
4317 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4318 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4319 Stop means reenter debugger if this signal happens (implies print).\n\
4320 Print means print a message if this signal happens.\n\
4321 Pass means let program see this signal; otherwise program doesn't know.\n\
4322 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4323 Pass and Stop may be combined.", NULL
));
4326 add_com ("lz", class_info
, signals_info
,
4327 "What debugger does when program gets various signals.\n\
4328 Specify a signal as argument to print info on that signal only.");
4329 add_com ("z", class_run
, xdb_handle_command
,
4330 concat ("Specify how to handle a signal.\n\
4331 Args are signals and actions to apply to those signals.\n\
4332 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4333 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4334 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4335 The special arg \"all\" is recognized to mean all signals except those\n\
4336 used by the debugger, typically SIGTRAP and SIGINT.\n",
4337 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4338 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4339 nopass), \"Q\" (noprint)\n\
4340 Stop means reenter debugger if this signal happens (implies print).\n\
4341 Print means print a message if this signal happens.\n\
4342 Pass means let program see this signal; otherwise program doesn't know.\n\
4343 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4344 Pass and Stop may be combined.", NULL
));
4348 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
4349 "There is no `stop' command, but you can set a hook on `stop'.\n\
4350 This allows you to set a list of commands to be run each time execution\n\
4351 of the program stops.", &cmdlist
);
4353 numsigs
= (int) TARGET_SIGNAL_LAST
;
4354 signal_stop
= (unsigned char *)
4355 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4356 signal_print
= (unsigned char *)
4357 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4358 signal_program
= (unsigned char *)
4359 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4360 for (i
= 0; i
< numsigs
; i
++)
4363 signal_print
[i
] = 1;
4364 signal_program
[i
] = 1;
4367 /* Signals caused by debugger's own actions
4368 should not be given to the program afterwards. */
4369 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4370 signal_program
[TARGET_SIGNAL_INT
] = 0;
4372 /* Signals that are not errors should not normally enter the debugger. */
4373 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4374 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4375 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4376 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4377 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4378 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4379 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4380 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4381 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4382 signal_print
[TARGET_SIGNAL_IO
] = 0;
4383 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4384 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4385 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4386 signal_print
[TARGET_SIGNAL_URG
] = 0;
4387 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4388 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4390 /* These signals are used internally by user-level thread
4391 implementations. (See signal(5) on Solaris.) Like the above
4392 signals, a healthy program receives and handles them as part of
4393 its normal operation. */
4394 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4395 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4396 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4397 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4398 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4399 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4403 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4404 (char *) &stop_on_solib_events
,
4405 "Set stopping for shared library events.\n\
4406 If nonzero, gdb will give control to the user when the dynamic linker\n\
4407 notifies gdb of shared library events. The most common event of interest\n\
4408 to the user would be loading/unloading of a new library.\n",
4413 c
= add_set_enum_cmd ("follow-fork-mode",
4415 follow_fork_mode_kind_names
,
4416 &follow_fork_mode_string
,
4417 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4418 kernel problem. It's also not terribly useful without a GUI to
4419 help the user drive two debuggers. So for now, I'm disabling
4420 the "both" option. */
4421 /* "Set debugger response to a program call of fork \
4423 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4424 parent - the original process is debugged after a fork\n\
4425 child - the new process is debugged after a fork\n\
4426 both - both the parent and child are debugged after a fork\n\
4427 ask - the debugger will ask for one of the above choices\n\
4428 For \"both\", another copy of the debugger will be started to follow\n\
4429 the new child process. The original debugger will continue to follow\n\
4430 the original parent process. To distinguish their prompts, the\n\
4431 debugger copy's prompt will be changed.\n\
4432 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4433 By default, the debugger will follow the parent process.",
4435 "Set debugger response to a program call of fork \
4437 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4438 parent - the original process is debugged after a fork\n\
4439 child - the new process is debugged after a fork\n\
4440 ask - the debugger will ask for one of the above choices\n\
4441 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4442 By default, the debugger will follow the parent process.",
4444 /* c->function.sfunc = ; */
4445 add_show_from_set (c
, &showlist
);
4447 c
= add_set_enum_cmd ("scheduler-locking", class_run
,
4448 scheduler_enums
, /* array of string names */
4449 &scheduler_mode
, /* current mode */
4450 "Set mode for locking scheduler during execution.\n\
4451 off == no locking (threads may preempt at any time)\n\
4452 on == full locking (no thread except the current thread may run)\n\
4453 step == scheduler locked during every single-step operation.\n\
4454 In this mode, no other thread may run during a step command.\n\
4455 Other threads may run while stepping over a function call ('next').",
4458 c
->function
.sfunc
= set_schedlock_func
; /* traps on target vector */
4459 add_show_from_set (c
, &showlist
);
4461 c
= add_set_cmd ("step-mode", class_run
,
4462 var_boolean
, (char*) &step_stop_if_no_debug
,
4463 "Set mode of the step operation. When set, doing a step over a\n\
4464 function without debug line information will stop at the first\n\
4465 instruction of that function. Otherwise, the function is skipped and\n\
4466 the step command stops at a different source line.",
4468 add_show_from_set (c
, &showlist
);
4470 /* ptid initializations */
4471 null_ptid
= ptid_build (0, 0, 0);
4472 minus_one_ptid
= ptid_build (-1, 0, 0);
4473 inferior_ptid
= null_ptid
;
4474 target_last_wait_ptid
= minus_one_ptid
;