1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986-1989, 1991-1999 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
27 #include "breakpoint.h"
32 #include "gdbthread.h"
34 #include "symfile.h" /* for overlay functions */
37 #include "event-loop.h"
39 /* Prototypes for local functions */
41 static void signals_info (char *, int);
43 static void handle_command (char *, int);
45 static void sig_print_info (enum target_signal
);
47 static void sig_print_header (void);
49 static void resume_cleanups (int);
51 static int hook_stop_stub (void *);
53 static void delete_breakpoint_current_contents (void *);
55 static void set_follow_fork_mode_command (char *arg
, int from_tty
,
56 struct cmd_list_element
* c
);
58 static void complete_execution (void);
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 static int is_internal_shlib_eventpoint (struct breakpoint
* ep
);
80 static int stopped_for_internal_shlib_event (bpstat bs
);
82 struct execution_control_state
;
84 static int currently_stepping (struct execution_control_state
*ecs
);
86 static void xdb_handle_command (char *args
, int from_tty
);
88 void _initialize_infrun (void);
90 int inferior_ignoring_startup_exec_events
= 0;
91 int inferior_ignoring_leading_exec_events
= 0;
93 /* In asynchronous mode, but simulating synchronous execution. */
95 int sync_execution
= 0;
97 /* wait_for_inferior and normal_stop use this to notify the user
98 when the inferior stopped in a different thread than it had been
101 static int switched_from_inferior_pid
;
103 /* This will be true for configurations that may actually report an
104 inferior pid different from the original. At present this is only
105 true for HP-UX native. */
107 #ifndef MAY_SWITCH_FROM_INFERIOR_PID
108 #define MAY_SWITCH_FROM_INFERIOR_PID (0)
111 static int may_switch_from_inferior_pid
= MAY_SWITCH_FROM_INFERIOR_PID
;
113 /* This is true for configurations that may follow through execl() and
114 similar functions. At present this is only true for HP-UX native. */
116 #ifndef MAY_FOLLOW_EXEC
117 #define MAY_FOLLOW_EXEC (0)
120 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
122 /* resume and wait_for_inferior use this to ensure that when
123 stepping over a hit breakpoint in a threaded application
124 only the thread that hit the breakpoint is stepped and the
125 other threads don't continue. This prevents having another
126 thread run past the breakpoint while it is temporarily
129 This is not thread-specific, so it isn't saved as part of
132 Versions of gdb which don't use the "step == this thread steps
133 and others continue" model but instead use the "step == this
134 thread steps and others wait" shouldn't do this. */
136 static int thread_step_needed
= 0;
138 /* This is true if thread_step_needed should actually be used. At
139 present this is only true for HP-UX native. */
141 #ifndef USE_THREAD_STEP_NEEDED
142 #define USE_THREAD_STEP_NEEDED (0)
145 static int use_thread_step_needed
= USE_THREAD_STEP_NEEDED
;
147 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
148 program. It needs to examine the jmp_buf argument and extract the PC
149 from it. The return value is non-zero on success, zero otherwise. */
151 #ifndef GET_LONGJMP_TARGET
152 #define GET_LONGJMP_TARGET(PC_ADDR) 0
156 /* Some machines have trampoline code that sits between function callers
157 and the actual functions themselves. If this machine doesn't have
158 such things, disable their processing. */
160 #ifndef SKIP_TRAMPOLINE_CODE
161 #define SKIP_TRAMPOLINE_CODE(pc) 0
164 /* Dynamic function trampolines are similar to solib trampolines in that they
165 are between the caller and the callee. The difference is that when you
166 enter a dynamic trampoline, you can't determine the callee's address. Some
167 (usually complex) code needs to run in the dynamic trampoline to figure out
168 the callee's address. This macro is usually called twice. First, when we
169 enter the trampoline (looks like a normal function call at that point). It
170 should return the PC of a point within the trampoline where the callee's
171 address is known. Second, when we hit the breakpoint, this routine returns
172 the callee's address. At that point, things proceed as per a step resume
175 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
176 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
179 /* On SVR4 based systems, determining the callee's address is exceedingly
180 difficult and depends on the implementation of the run time loader.
181 If we are stepping at the source level, we single step until we exit
182 the run time loader code and reach the callee's address. */
184 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
185 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
188 /* For SVR4 shared libraries, each call goes through a small piece of
189 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
190 to nonzero if we are current stopped in one of these. */
192 #ifndef IN_SOLIB_CALL_TRAMPOLINE
193 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
196 /* In some shared library schemes, the return path from a shared library
197 call may need to go through a trampoline too. */
199 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
200 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
203 /* This function returns TRUE if pc is the address of an instruction
204 that lies within the dynamic linker (such as the event hook, or the
207 This function must be used only when a dynamic linker event has
208 been caught, and the inferior is being stepped out of the hook, or
209 undefined results are guaranteed. */
211 #ifndef SOLIB_IN_DYNAMIC_LINKER
212 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
215 /* On MIPS16, a function that returns a floating point value may call
216 a library helper function to copy the return value to a floating point
217 register. The IGNORE_HELPER_CALL macro returns non-zero if we
218 should ignore (i.e. step over) this function call. */
219 #ifndef IGNORE_HELPER_CALL
220 #define IGNORE_HELPER_CALL(pc) 0
223 /* On some systems, the PC may be left pointing at an instruction that won't
224 actually be executed. This is usually indicated by a bit in the PSW. If
225 we find ourselves in such a state, then we step the target beyond the
226 nullified instruction before returning control to the user so as to avoid
229 #ifndef INSTRUCTION_NULLIFIED
230 #define INSTRUCTION_NULLIFIED 0
233 /* Convert the #defines into values. This is temporary until wfi control
234 flow is completely sorted out. */
236 #ifndef HAVE_STEPPABLE_WATCHPOINT
237 #define HAVE_STEPPABLE_WATCHPOINT 0
239 #undef HAVE_STEPPABLE_WATCHPOINT
240 #define HAVE_STEPPABLE_WATCHPOINT 1
243 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
244 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
246 #undef HAVE_NONSTEPPABLE_WATCHPOINT
247 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
250 #ifndef HAVE_CONTINUABLE_WATCHPOINT
251 #define HAVE_CONTINUABLE_WATCHPOINT 0
253 #undef HAVE_CONTINUABLE_WATCHPOINT
254 #define HAVE_CONTINUABLE_WATCHPOINT 1
257 /* Tables of how to react to signals; the user sets them. */
259 static unsigned char *signal_stop
;
260 static unsigned char *signal_print
;
261 static unsigned char *signal_program
;
263 #define SET_SIGS(nsigs,sigs,flags) \
265 int signum = (nsigs); \
266 while (signum-- > 0) \
267 if ((sigs)[signum]) \
268 (flags)[signum] = 1; \
271 #define UNSET_SIGS(nsigs,sigs,flags) \
273 int signum = (nsigs); \
274 while (signum-- > 0) \
275 if ((sigs)[signum]) \
276 (flags)[signum] = 0; \
280 /* Command list pointer for the "stop" placeholder. */
282 static struct cmd_list_element
*stop_command
;
284 /* Nonzero if breakpoints are now inserted in the inferior. */
286 static int breakpoints_inserted
;
288 /* Function inferior was in as of last step command. */
290 static struct symbol
*step_start_function
;
292 /* Nonzero if we are expecting a trace trap and should proceed from it. */
294 static int trap_expected
;
297 /* Nonzero if we want to give control to the user when we're notified
298 of shared library events by the dynamic linker. */
299 static int stop_on_solib_events
;
303 /* Nonzero if the next time we try to continue the inferior, it will
304 step one instruction and generate a spurious trace trap.
305 This is used to compensate for a bug in HP-UX. */
307 static int trap_expected_after_continue
;
310 /* Nonzero means expecting a trace trap
311 and should stop the inferior and return silently when it happens. */
315 /* Nonzero means expecting a trap and caller will handle it themselves.
316 It is used after attach, due to attaching to a process;
317 when running in the shell before the child program has been exec'd;
318 and when running some kinds of remote stuff (FIXME?). */
320 int stop_soon_quietly
;
322 /* Nonzero if proceed is being used for a "finish" command or a similar
323 situation when stop_registers should be saved. */
325 int proceed_to_finish
;
327 /* Save register contents here when about to pop a stack dummy frame,
328 if-and-only-if proceed_to_finish is set.
329 Thus this contains the return value from the called function (assuming
330 values are returned in a register). */
332 char *stop_registers
;
334 /* Nonzero if program stopped due to error trying to insert breakpoints. */
336 static int breakpoints_failed
;
338 /* Nonzero after stop if current stack frame should be printed. */
340 static int stop_print_frame
;
342 static struct breakpoint
*step_resume_breakpoint
= NULL
;
343 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
345 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
346 interactions with an inferior that is running a kernel function
347 (aka, a system call or "syscall"). wait_for_inferior therefore
348 may have a need to know when the inferior is in a syscall. This
349 is a count of the number of inferior threads which are known to
350 currently be running in a syscall. */
351 static int number_of_threads_in_syscalls
;
353 /* This is used to remember when a fork, vfork or exec event
354 was caught by a catchpoint, and thus the event is to be
355 followed at the next resume of the inferior, and not
359 enum target_waitkind kind
;
369 char *execd_pathname
;
373 /* Some platforms don't allow us to do anything meaningful with a
374 vforked child until it has exec'd. Vforked processes on such
375 platforms can only be followed after they've exec'd.
377 When this is set to 0, a vfork can be immediately followed,
378 and an exec can be followed merely as an exec. When this is
379 set to 1, a vfork event has been seen, but cannot be followed
380 until the exec is seen.
382 (In the latter case, inferior_pid is still the parent of the
383 vfork, and pending_follow.fork_event.child_pid is the child. The
384 appropriate process is followed, according to the setting of
385 follow-fork-mode.) */
386 static int follow_vfork_when_exec
;
388 static char *follow_fork_mode_kind_names
[] =
390 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
391 kernel problem. It's also not terribly useful without a GUI to
392 help the user drive two debuggers. So for now, I'm disabling
394 "parent", "child", "both", "ask" };
396 "parent", "child", "ask"};
398 static char *follow_fork_mode_string
= NULL
;
402 follow_inferior_fork (int parent_pid
, int child_pid
, int has_forked
,
405 int followed_parent
= 0;
406 int followed_child
= 0;
408 /* Which process did the user want us to follow? */
410 savestring (follow_fork_mode_string
, strlen (follow_fork_mode_string
));
412 /* Or, did the user not know, and want us to ask? */
413 if (STREQ (follow_fork_mode_string
, "ask"))
415 char requested_mode
[100];
418 error ("\"ask\" mode NYI");
419 follow_mode
= savestring (requested_mode
, strlen (requested_mode
));
422 /* If we're to be following the parent, then detach from child_pid.
423 We're already following the parent, so need do nothing explicit
425 if (STREQ (follow_mode
, "parent"))
429 /* We're already attached to the parent, by default. */
431 /* Before detaching from the child, remove all breakpoints from
432 it. (This won't actually modify the breakpoint list, but will
433 physically remove the breakpoints from the child.) */
434 if (!has_vforked
|| !follow_vfork_when_exec
)
436 detach_breakpoints (child_pid
);
437 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
438 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
442 /* Detach from the child. */
445 target_require_detach (child_pid
, "", 1);
448 /* If we're to be following the child, then attach to it, detach
449 from inferior_pid, and set inferior_pid to child_pid. */
450 else if (STREQ (follow_mode
, "child"))
452 char child_pid_spelling
[100]; /* Arbitrary length. */
456 /* Before detaching from the parent, detach all breakpoints from
457 the child. But only if we're forking, or if we follow vforks
458 as soon as they happen. (If we're following vforks only when
459 the child has exec'd, then it's very wrong to try to write
460 back the "shadow contents" of inserted breakpoints now -- they
461 belong to the child's pre-exec'd a.out.) */
462 if (!has_vforked
|| !follow_vfork_when_exec
)
464 detach_breakpoints (child_pid
);
467 /* Before detaching from the parent, remove all breakpoints from it. */
468 remove_breakpoints ();
470 /* Also reset the solib inferior hook from the parent. */
471 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
472 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid
);
475 /* Detach from the parent. */
477 target_detach (NULL
, 1);
479 /* Attach to the child. */
480 inferior_pid
= child_pid
;
481 sprintf (child_pid_spelling
, "%d", child_pid
);
484 target_require_attach (child_pid_spelling
, 1);
486 /* Was there a step_resume breakpoint? (There was if the user
487 did a "next" at the fork() call.) If so, explicitly reset its
490 step_resumes are a form of bp that are made to be per-thread.
491 Since we created the step_resume bp when the parent process
492 was being debugged, and now are switching to the child process,
493 from the breakpoint package's viewpoint, that's a switch of
494 "threads". We must update the bp's notion of which thread
495 it is for, or it'll be ignored when it triggers... */
496 if (step_resume_breakpoint
&&
497 (!has_vforked
|| !follow_vfork_when_exec
))
498 breakpoint_re_set_thread (step_resume_breakpoint
);
500 /* Reinsert all breakpoints in the child. (The user may've set
501 breakpoints after catching the fork, in which case those
502 actually didn't get set in the child, but only in the parent.) */
503 if (!has_vforked
|| !follow_vfork_when_exec
)
505 breakpoint_re_set ();
506 insert_breakpoints ();
510 /* If we're to be following both parent and child, then fork ourselves,
511 and attach the debugger clone to the child. */
512 else if (STREQ (follow_mode
, "both"))
514 char pid_suffix
[100]; /* Arbitrary length. */
516 /* Clone ourselves to follow the child. This is the end of our
517 involvement with child_pid; our clone will take it from here... */
519 target_clone_and_follow_inferior (child_pid
, &followed_child
);
520 followed_parent
= !followed_child
;
522 /* We continue to follow the parent. To help distinguish the two
523 debuggers, though, both we and our clone will reset our prompts. */
524 sprintf (pid_suffix
, "[%d] ", inferior_pid
);
525 set_prompt (strcat (get_prompt (), pid_suffix
));
528 /* The parent and child of a vfork share the same address space.
529 Also, on some targets the order in which vfork and exec events
530 are received for parent in child requires some delicate handling
533 For instance, on ptrace-based HPUX we receive the child's vfork
534 event first, at which time the parent has been suspended by the
535 OS and is essentially untouchable until the child's exit or second
536 exec event arrives. At that time, the parent's vfork event is
537 delivered to us, and that's when we see and decide how to follow
538 the vfork. But to get to that point, we must continue the child
539 until it execs or exits. To do that smoothly, all breakpoints
540 must be removed from the child, in case there are any set between
541 the vfork() and exec() calls. But removing them from the child
542 also removes them from the parent, due to the shared-address-space
543 nature of a vfork'd parent and child. On HPUX, therefore, we must
544 take care to restore the bp's to the parent before we continue it.
545 Else, it's likely that we may not stop in the expected place. (The
546 worst scenario is when the user tries to step over a vfork() call;
547 the step-resume bp must be restored for the step to properly stop
548 in the parent after the call completes!)
550 Sequence of events, as reported to gdb from HPUX:
552 Parent Child Action for gdb to take
553 -------------------------------------------------------
554 1 VFORK Continue child
560 target_post_follow_vfork (parent_pid
,
566 pending_follow
.fork_event
.saw_parent_fork
= 0;
567 pending_follow
.fork_event
.saw_child_fork
= 0;
573 follow_fork (int parent_pid
, int child_pid
)
575 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
579 /* Forward declaration. */
580 static void follow_exec (int, char *);
583 follow_vfork (int parent_pid
, int child_pid
)
585 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
587 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
588 if (pending_follow
.fork_event
.saw_child_exec
&& (inferior_pid
== child_pid
))
590 pending_follow
.fork_event
.saw_child_exec
= 0;
591 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
592 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
593 free (pending_follow
.execd_pathname
);
598 follow_exec (int pid
, char *execd_pathname
)
601 struct target_ops
*tgt
;
603 if (!may_follow_exec
)
606 /* Did this exec() follow a vfork()? If so, we must follow the
607 vfork now too. Do it before following the exec. */
608 if (follow_vfork_when_exec
&&
609 (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
))
611 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
612 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
613 follow_vfork_when_exec
= 0;
614 saved_pid
= inferior_pid
;
616 /* Did we follow the parent? If so, we're done. If we followed
617 the child then we must also follow its exec(). */
618 if (inferior_pid
== pending_follow
.fork_event
.parent_pid
)
622 /* This is an exec event that we actually wish to pay attention to.
623 Refresh our symbol table to the newly exec'd program, remove any
626 If there are breakpoints, they aren't really inserted now,
627 since the exec() transformed our inferior into a fresh set
630 We want to preserve symbolic breakpoints on the list, since
631 we have hopes that they can be reset after the new a.out's
632 symbol table is read.
634 However, any "raw" breakpoints must be removed from the list
635 (e.g., the solib bp's), since their address is probably invalid
638 And, we DON'T want to call delete_breakpoints() here, since
639 that may write the bp's "shadow contents" (the instruction
640 value that was overwritten witha TRAP instruction). Since
641 we now have a new a.out, those shadow contents aren't valid. */
642 update_breakpoints_after_exec ();
644 /* If there was one, it's gone now. We cannot truly step-to-next
645 statement through an exec(). */
646 step_resume_breakpoint
= NULL
;
647 step_range_start
= 0;
650 /* If there was one, it's gone now. */
651 through_sigtramp_breakpoint
= NULL
;
653 /* What is this a.out's name? */
654 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
656 /* We've followed the inferior through an exec. Therefore, the
657 inferior has essentially been killed & reborn. */
659 /* First collect the run target in effect. */
660 tgt
= find_run_target ();
661 /* If we can't find one, things are in a very strange state... */
663 error ("Could find run target to save before following exec");
665 gdb_flush (gdb_stdout
);
666 target_mourn_inferior ();
667 inferior_pid
= saved_pid
; /* Because mourn_inferior resets inferior_pid. */
670 /* That a.out is now the one to use. */
671 exec_file_attach (execd_pathname
, 0);
673 /* And also is where symbols can be found. */
674 symbol_file_command (execd_pathname
, 0);
676 /* Reset the shared library package. This ensures that we get
677 a shlib event when the child reaches "_start", at which point
678 the dld will have had a chance to initialize the child. */
679 #if defined(SOLIB_RESTART)
682 #ifdef SOLIB_CREATE_INFERIOR_HOOK
683 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid
);
686 /* Reinsert all breakpoints. (Those which were symbolic have
687 been reset to the proper address in the new a.out, thanks
688 to symbol_file_command...) */
689 insert_breakpoints ();
691 /* The next resume of this inferior should bring it to the shlib
692 startup breakpoints. (If the user had also set bp's on
693 "main" from the old (parent) process, then they'll auto-
694 matically get reset there in the new process.) */
697 /* Non-zero if we just simulating a single-step. This is needed
698 because we cannot remove the breakpoints in the inferior process
699 until after the `wait' in `wait_for_inferior'. */
700 static int singlestep_breakpoints_inserted_p
= 0;
703 /* Things to clean up if we QUIT out of resume (). */
706 resume_cleanups (int arg
)
711 static char schedlock_off
[] = "off";
712 static char schedlock_on
[] = "on";
713 static char schedlock_step
[] = "step";
714 static char *scheduler_mode
= schedlock_off
;
715 static char *scheduler_enums
[] =
716 {schedlock_off
, schedlock_on
, schedlock_step
};
719 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
721 if (c
->type
== set_cmd
)
722 if (!target_can_lock_scheduler
)
724 scheduler_mode
= schedlock_off
;
725 error ("Target '%s' cannot support this command.",
731 /* Resume the inferior, but allow a QUIT. This is useful if the user
732 wants to interrupt some lengthy single-stepping operation
733 (for child processes, the SIGINT goes to the inferior, and so
734 we get a SIGINT random_signal, but for remote debugging and perhaps
735 other targets, that's not true).
737 STEP nonzero if we should step (zero to continue instead).
738 SIG is the signal to give the inferior (zero for none). */
740 resume (int step
, enum target_signal sig
)
742 int should_resume
= 1;
743 struct cleanup
*old_cleanups
= make_cleanup ((make_cleanup_func
)
747 #ifdef CANNOT_STEP_BREAKPOINT
748 /* Most targets can step a breakpoint instruction, thus executing it
749 normally. But if this one cannot, just continue and we will hit
751 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
755 if (SOFTWARE_SINGLE_STEP_P
&& step
)
757 /* Do it the hard way, w/temp breakpoints */
758 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
759 /* ...and don't ask hardware to do it. */
761 /* and do not pull these breakpoints until after a `wait' in
762 `wait_for_inferior' */
763 singlestep_breakpoints_inserted_p
= 1;
766 /* Handle any optimized stores to the inferior NOW... */
767 #ifdef DO_DEFERRED_STORES
771 /* If there were any forks/vforks/execs that were caught and are
772 now to be followed, then do so. */
773 switch (pending_follow
.kind
)
775 case (TARGET_WAITKIND_FORKED
):
776 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
777 follow_fork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
780 case (TARGET_WAITKIND_VFORKED
):
782 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
784 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
785 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
787 /* Did we follow the child, but not yet see the child's exec event?
788 If so, then it actually ought to be waiting for us; we respond to
789 parent vfork events. We don't actually want to resume the child
790 in this situation; we want to just get its exec event. */
791 if (!saw_child_exec
&&
792 (inferior_pid
== pending_follow
.fork_event
.child_pid
))
797 case (TARGET_WAITKIND_EXECD
):
798 /* If we saw a vfork event but couldn't follow it until we saw
799 an exec, then now might be the time! */
800 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
801 /* follow_exec is called as soon as the exec event is seen. */
808 /* Install inferior's terminal modes. */
809 target_terminal_inferior ();
813 if (use_thread_step_needed
&& thread_step_needed
)
815 /* We stopped on a BPT instruction;
816 don't continue other threads and
817 just step this thread. */
818 thread_step_needed
= 0;
820 if (!breakpoint_here_p (read_pc ()))
822 /* Breakpoint deleted: ok to do regular resume
823 where all the threads either step or continue. */
824 target_resume (-1, step
, sig
);
830 warning ("Internal error, changing continue to step.");
831 remove_breakpoints ();
832 breakpoints_inserted
= 0;
837 target_resume (inferior_pid
, step
, sig
);
842 /* Vanilla resume. */
844 if ((scheduler_mode
== schedlock_on
) ||
845 (scheduler_mode
== schedlock_step
&& step
!= 0))
846 target_resume (inferior_pid
, step
, sig
);
848 target_resume (-1, step
, sig
);
852 discard_cleanups (old_cleanups
);
856 /* Clear out all variables saying what to do when inferior is continued.
857 First do this, then set the ones you want, then call `proceed'. */
860 clear_proceed_status (void)
863 step_range_start
= 0;
865 step_frame_address
= 0;
866 step_over_calls
= -1;
868 stop_soon_quietly
= 0;
869 proceed_to_finish
= 0;
870 breakpoint_proceeded
= 1; /* We're about to proceed... */
872 /* Discard any remaining commands or status from previous stop. */
873 bpstat_clear (&stop_bpstat
);
876 /* Basic routine for continuing the program in various fashions.
878 ADDR is the address to resume at, or -1 for resume where stopped.
879 SIGGNAL is the signal to give it, or 0 for none,
880 or -1 for act according to how it stopped.
881 STEP is nonzero if should trap after one instruction.
882 -1 means return after that and print nothing.
883 You should probably set various step_... variables
884 before calling here, if you are stepping.
886 You should call clear_proceed_status before calling proceed. */
889 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
894 step_start_function
= find_pc_function (read_pc ());
898 if (addr
== (CORE_ADDR
) - 1)
900 /* If there is a breakpoint at the address we will resume at,
901 step one instruction before inserting breakpoints
902 so that we do not stop right away (and report a second
903 hit at this breakpoint). */
905 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
908 #ifndef STEP_SKIPS_DELAY
909 #define STEP_SKIPS_DELAY(pc) (0)
910 #define STEP_SKIPS_DELAY_P (0)
912 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
913 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
914 is slow (it needs to read memory from the target). */
915 if (STEP_SKIPS_DELAY_P
916 && breakpoint_here_p (read_pc () + 4)
917 && STEP_SKIPS_DELAY (read_pc ()))
924 /* New address; we don't need to single-step a thread
925 over a breakpoint we just hit, 'cause we aren't
926 continuing from there.
928 It's not worth worrying about the case where a user
929 asks for a "jump" at the current PC--if they get the
930 hiccup of re-hiting a hit breakpoint, what else do
932 thread_step_needed
= 0;
935 #ifdef PREPARE_TO_PROCEED
936 /* In a multi-threaded task we may select another thread
937 and then continue or step.
939 But if the old thread was stopped at a breakpoint, it
940 will immediately cause another breakpoint stop without
941 any execution (i.e. it will report a breakpoint hit
942 incorrectly). So we must step over it first.
944 PREPARE_TO_PROCEED checks the current thread against the thread
945 that reported the most recent event. If a step-over is required
946 it returns TRUE and sets the current thread to the old thread. */
947 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
950 thread_step_needed
= 1;
953 #endif /* PREPARE_TO_PROCEED */
956 if (trap_expected_after_continue
)
958 /* If (step == 0), a trap will be automatically generated after
959 the first instruction is executed. Force step one
960 instruction to clear this condition. This should not occur
961 if step is nonzero, but it is harmless in that case. */
963 trap_expected_after_continue
= 0;
965 #endif /* HP_OS_BUG */
968 /* We will get a trace trap after one instruction.
969 Continue it automatically and insert breakpoints then. */
973 int temp
= insert_breakpoints ();
976 print_sys_errmsg ("ptrace", temp
);
977 error ("Cannot insert breakpoints.\n\
978 The same program may be running in another process.");
981 breakpoints_inserted
= 1;
984 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
985 stop_signal
= siggnal
;
986 /* If this signal should not be seen by program,
987 give it zero. Used for debugging signals. */
988 else if (!signal_program
[stop_signal
])
989 stop_signal
= TARGET_SIGNAL_0
;
991 annotate_starting ();
993 /* Make sure that output from GDB appears before output from the
995 gdb_flush (gdb_stdout
);
997 /* Resume inferior. */
998 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1000 /* Wait for it to stop (if not standalone)
1001 and in any case decode why it stopped, and act accordingly. */
1002 /* Do this only if we are not using the event loop, or if the target
1003 does not support asynchronous execution. */
1004 if (!async_p
|| !target_has_async
)
1006 wait_for_inferior ();
1011 /* Record the pc and sp of the program the last time it stopped.
1012 These are just used internally by wait_for_inferior, but need
1013 to be preserved over calls to it and cleared when the inferior
1015 static CORE_ADDR prev_pc
;
1016 static CORE_ADDR prev_func_start
;
1017 static char *prev_func_name
;
1020 /* Start remote-debugging of a machine over a serial link. */
1025 init_thread_list ();
1026 init_wait_for_inferior ();
1027 stop_soon_quietly
= 1;
1030 /* Go on waiting only in case gdb is not started in async mode, or
1031 in case the target doesn't support async execution. */
1032 if (!async_p
|| !target_has_async
)
1034 wait_for_inferior ();
1039 /* The 'tar rem' command should always look synchronous,
1040 i.e. display the prompt only once it has connected and
1041 started the target. */
1043 push_prompt ("", "", "");
1044 delete_file_handler (input_fd
);
1045 target_executing
= 1;
1049 /* Initialize static vars when a new inferior begins. */
1052 init_wait_for_inferior (void)
1054 /* These are meaningless until the first time through wait_for_inferior. */
1056 prev_func_start
= 0;
1057 prev_func_name
= NULL
;
1060 trap_expected_after_continue
= 0;
1062 breakpoints_inserted
= 0;
1063 breakpoint_init_inferior (inf_starting
);
1065 /* Don't confuse first call to proceed(). */
1066 stop_signal
= TARGET_SIGNAL_0
;
1068 /* The first resume is not following a fork/vfork/exec. */
1069 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1070 pending_follow
.fork_event
.saw_parent_fork
= 0;
1071 pending_follow
.fork_event
.saw_child_fork
= 0;
1072 pending_follow
.fork_event
.saw_child_exec
= 0;
1074 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1075 number_of_threads_in_syscalls
= 0;
1077 clear_proceed_status ();
1081 delete_breakpoint_current_contents (void *arg
)
1083 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1084 if (*breakpointp
!= NULL
)
1086 delete_breakpoint (*breakpointp
);
1087 *breakpointp
= NULL
;
1091 /* This enum encodes possible reasons for doing a target_wait, so that
1092 wfi can call target_wait in one place. (Ultimately the call will be
1093 moved out of the infinite loop entirely.) */
1097 infwait_normal_state
,
1098 infwait_thread_hop_state
,
1099 infwait_nullified_state
,
1100 infwait_nonstep_watch_state
1103 /* This structure contains what used to be local variables in
1104 wait_for_inferior. Probably many of them can return to being
1105 locals in handle_inferior_event. */
1107 struct execution_control_state
1109 struct target_waitstatus ws
;
1110 struct target_waitstatus
*wp
;
1113 CORE_ADDR stop_func_start
;
1114 CORE_ADDR stop_func_end
;
1115 char *stop_func_name
;
1116 struct symtab_and_line sal
;
1117 int remove_breakpoints_on_following_step
;
1119 struct symtab
*current_symtab
;
1120 int handling_longjmp
; /* FIXME */
1122 int saved_inferior_pid
;
1124 int stepping_through_solib_after_catch
;
1125 bpstat stepping_through_solib_catchpoints
;
1126 int enable_hw_watchpoints_after_wait
;
1127 int stepping_through_sigtramp
;
1128 int new_thread_event
;
1129 struct target_waitstatus tmpstatus
;
1130 enum infwait_states infwait_state
;
1135 void init_execution_control_state (struct execution_control_state
* ecs
);
1137 void handle_inferior_event (struct execution_control_state
* ecs
);
1139 /* Wait for control to return from inferior to debugger.
1140 If inferior gets a signal, we may decide to start it up again
1141 instead of returning. That is why there is a loop in this function.
1142 When this function actually returns it means the inferior
1143 should be left stopped and GDB should read more commands. */
1146 wait_for_inferior (void)
1148 struct cleanup
*old_cleanups
;
1149 struct execution_control_state ecss
;
1150 struct execution_control_state
*ecs
;
1152 old_cleanups
= make_cleanup (delete_breakpoint_current_contents
,
1153 &step_resume_breakpoint
);
1154 make_cleanup (delete_breakpoint_current_contents
,
1155 &through_sigtramp_breakpoint
);
1157 /* wfi still stays in a loop, so it's OK just to take the address of
1158 a local to get the ecs pointer. */
1161 /* Fill in with reasonable starting values. */
1162 init_execution_control_state (ecs
);
1164 thread_step_needed
= 0;
1166 /* We'll update this if & when we switch to a new thread. */
1167 if (may_switch_from_inferior_pid
)
1168 switched_from_inferior_pid
= inferior_pid
;
1170 overlay_cache_invalid
= 1;
1172 /* We have to invalidate the registers BEFORE calling target_wait
1173 because they can be loaded from the target while in target_wait.
1174 This makes remote debugging a bit more efficient for those
1175 targets that provide critical registers as part of their normal
1176 status mechanism. */
1178 registers_changed ();
1182 if (target_wait_hook
)
1183 ecs
->pid
= target_wait_hook (ecs
->waiton_pid
, ecs
->wp
);
1185 ecs
->pid
= target_wait (ecs
->waiton_pid
, ecs
->wp
);
1187 /* Now figure out what to do with the result of the result. */
1188 handle_inferior_event (ecs
);
1190 if (!ecs
->wait_some_more
)
1193 do_cleanups (old_cleanups
);
1196 /* Asynchronous version of wait_for_inferior. It is called by the
1197 event loop whenever a change of state is detected on the file
1198 descriptor corresponding to the target. It can be called more than
1199 once to complete a single execution command. In such cases we need
1200 to keep the state in a global variable ASYNC_ECSS. If it is the
1201 last time that this function is called for a single execution
1202 command, then report to the user that the inferior has stopped, and
1203 do the necessary cleanups. */
1205 struct execution_control_state async_ecss
;
1206 struct execution_control_state
*async_ecs
;
1209 fetch_inferior_event (void)
1211 static struct cleanup
*old_cleanups
;
1213 async_ecs
= &async_ecss
;
1215 if (!async_ecs
->wait_some_more
)
1217 old_cleanups
= make_exec_cleanup (delete_breakpoint_current_contents
,
1218 &step_resume_breakpoint
);
1219 make_exec_cleanup (delete_breakpoint_current_contents
,
1220 &through_sigtramp_breakpoint
);
1222 /* Fill in with reasonable starting values. */
1223 init_execution_control_state (async_ecs
);
1225 thread_step_needed
= 0;
1227 /* We'll update this if & when we switch to a new thread. */
1228 if (may_switch_from_inferior_pid
)
1229 switched_from_inferior_pid
= inferior_pid
;
1231 overlay_cache_invalid
= 1;
1233 /* We have to invalidate the registers BEFORE calling target_wait
1234 because they can be loaded from the target while in target_wait.
1235 This makes remote debugging a bit more efficient for those
1236 targets that provide critical registers as part of their normal
1237 status mechanism. */
1239 registers_changed ();
1242 if (target_wait_hook
)
1243 async_ecs
->pid
= target_wait_hook (async_ecs
->waiton_pid
, async_ecs
->wp
);
1245 async_ecs
->pid
= target_wait (async_ecs
->waiton_pid
, async_ecs
->wp
);
1247 /* Now figure out what to do with the result of the result. */
1248 handle_inferior_event (async_ecs
);
1250 if (!async_ecs
->wait_some_more
)
1252 /* Do only the cleanups that have been added by this
1253 function. Let the continuations for the commands do the rest,
1254 if there are any. */
1255 do_exec_cleanups (old_cleanups
);
1257 /* Is there anything left to do for the command issued to
1259 do_all_continuations ();
1260 /* Reset things after target has stopped for the async commands. */
1261 complete_execution ();
1265 /* Prepare an execution control state for looping through a
1266 wait_for_inferior-type loop. */
1269 init_execution_control_state (struct execution_control_state
*ecs
)
1271 ecs
->random_signal
= 0;
1272 ecs
->remove_breakpoints_on_following_step
= 0;
1273 ecs
->handling_longjmp
= 0; /* FIXME */
1274 ecs
->update_step_sp
= 0;
1275 ecs
->stepping_through_solib_after_catch
= 0;
1276 ecs
->stepping_through_solib_catchpoints
= NULL
;
1277 ecs
->enable_hw_watchpoints_after_wait
= 0;
1278 ecs
->stepping_through_sigtramp
= 0;
1279 ecs
->sal
= find_pc_line (prev_pc
, 0);
1280 ecs
->current_line
= ecs
->sal
.line
;
1281 ecs
->current_symtab
= ecs
->sal
.symtab
;
1282 ecs
->infwait_state
= infwait_normal_state
;
1283 ecs
->waiton_pid
= -1;
1284 ecs
->wp
= &(ecs
->ws
);
1287 /* Call this function before setting step_resume_breakpoint, as a
1288 sanity check. We should never be setting a new
1289 step_resume_breakpoint when we have an old one active. */
1291 check_for_old_step_resume_breakpoint (void)
1293 if (step_resume_breakpoint
)
1294 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1297 /* Given an execution control state that has been freshly filled in
1298 by an event from the inferior, figure out what it means and take
1299 appropriate action. */
1302 handle_inferior_event (struct execution_control_state
*ecs
)
1305 int stepped_after_stopped_by_watchpoint
;
1307 /* Keep this extra brace for now, minimizes diffs. */
1309 switch (ecs
->infwait_state
)
1311 case infwait_normal_state
:
1312 /* Since we've done a wait, we have a new event. Don't
1313 carry over any expectations about needing to step over a
1315 thread_step_needed
= 0;
1317 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1318 is serviced in this loop, below. */
1319 if (ecs
->enable_hw_watchpoints_after_wait
)
1321 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid
);
1322 ecs
->enable_hw_watchpoints_after_wait
= 0;
1324 stepped_after_stopped_by_watchpoint
= 0;
1327 case infwait_thread_hop_state
:
1328 insert_breakpoints ();
1330 /* We need to restart all the threads now,
1331 * unles we're running in scheduler-locked mode.
1332 * FIXME: shouldn't we look at currently_stepping ()?
1334 if (scheduler_mode
== schedlock_on
)
1335 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1337 target_resume (-1, 0, TARGET_SIGNAL_0
);
1338 ecs
->infwait_state
= infwait_normal_state
;
1341 case infwait_nullified_state
:
1344 case infwait_nonstep_watch_state
:
1345 insert_breakpoints ();
1347 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1348 handle things like signals arriving and other things happening
1349 in combination correctly? */
1350 stepped_after_stopped_by_watchpoint
= 1;
1353 ecs
->infwait_state
= infwait_normal_state
;
1355 flush_cached_frames ();
1357 /* If it's a new process, add it to the thread database */
1359 ecs
->new_thread_event
= ((ecs
->pid
!= inferior_pid
) && !in_thread_list (ecs
->pid
));
1361 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1362 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1363 && ecs
->new_thread_event
)
1365 add_thread (ecs
->pid
);
1367 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs
->pid
));
1370 /* NOTE: This block is ONLY meant to be invoked in case of a
1371 "thread creation event"! If it is invoked for any other
1372 sort of event (such as a new thread landing on a breakpoint),
1373 the event will be discarded, which is almost certainly
1376 To avoid this, the low-level module (eg. target_wait)
1377 should call in_thread_list and add_thread, so that the
1378 new thread is known by the time we get here. */
1380 /* We may want to consider not doing a resume here in order
1381 to give the user a chance to play with the new thread.
1382 It might be good to make that a user-settable option. */
1384 /* At this point, all threads are stopped (happens
1385 automatically in either the OS or the native code).
1386 Therefore we need to continue all threads in order to
1389 target_resume (-1, 0, TARGET_SIGNAL_0
);
1394 switch (ecs
->ws
.kind
)
1396 case TARGET_WAITKIND_LOADED
:
1397 /* Ignore gracefully during startup of the inferior, as it
1398 might be the shell which has just loaded some objects,
1399 otherwise add the symbols for the newly loaded objects. */
1401 if (!stop_soon_quietly
)
1403 /* Remove breakpoints, SOLIB_ADD might adjust
1404 breakpoint addresses via breakpoint_re_set. */
1405 if (breakpoints_inserted
)
1406 remove_breakpoints ();
1408 /* Check for any newly added shared libraries if we're
1409 supposed to be adding them automatically. */
1412 /* Switch terminal for any messages produced by
1413 breakpoint_re_set. */
1414 target_terminal_ours_for_output ();
1415 SOLIB_ADD (NULL
, 0, NULL
);
1416 target_terminal_inferior ();
1419 /* Reinsert breakpoints and continue. */
1420 if (breakpoints_inserted
)
1421 insert_breakpoints ();
1424 resume (0, TARGET_SIGNAL_0
);
1427 case TARGET_WAITKIND_SPURIOUS
:
1428 resume (0, TARGET_SIGNAL_0
);
1431 case TARGET_WAITKIND_EXITED
:
1432 target_terminal_ours (); /* Must do this before mourn anyway */
1433 annotate_exited (ecs
->ws
.value
.integer
);
1434 if (ecs
->ws
.value
.integer
)
1435 printf_filtered ("\nProgram exited with code 0%o.\n",
1436 (unsigned int) ecs
->ws
.value
.integer
);
1438 printf_filtered ("\nProgram exited normally.\n");
1440 /* Record the exit code in the convenience variable $_exitcode, so
1441 that the user can inspect this again later. */
1442 set_internalvar (lookup_internalvar ("_exitcode"),
1443 value_from_longest (builtin_type_int
,
1444 (LONGEST
) ecs
->ws
.value
.integer
));
1445 gdb_flush (gdb_stdout
);
1446 target_mourn_inferior ();
1447 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P */
1448 stop_print_frame
= 0;
1451 case TARGET_WAITKIND_SIGNALLED
:
1452 stop_print_frame
= 0;
1453 stop_signal
= ecs
->ws
.value
.sig
;
1454 target_terminal_ours (); /* Must do this before mourn anyway */
1455 annotate_signalled ();
1457 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1458 mean it is already dead? This has been here since GDB 2.8, so
1459 perhaps it means rms didn't understand unix waitstatuses?
1460 For the moment I'm just kludging around this in remote.c
1461 rather than trying to change it here --kingdon, 5 Dec 1994. */
1462 target_kill (); /* kill mourns as well */
1464 printf_filtered ("\nProgram terminated with signal ");
1465 annotate_signal_name ();
1466 printf_filtered ("%s", target_signal_to_name (stop_signal
));
1467 annotate_signal_name_end ();
1468 printf_filtered (", ");
1469 annotate_signal_string ();
1470 printf_filtered ("%s", target_signal_to_string (stop_signal
));
1471 annotate_signal_string_end ();
1472 printf_filtered (".\n");
1474 printf_filtered ("The program no longer exists.\n");
1475 gdb_flush (gdb_stdout
);
1476 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P */
1479 /* The following are the only cases in which we keep going;
1480 the above cases end in a continue or goto. */
1481 case TARGET_WAITKIND_FORKED
:
1482 stop_signal
= TARGET_SIGNAL_TRAP
;
1483 pending_follow
.kind
= ecs
->ws
.kind
;
1485 /* Ignore fork events reported for the parent; we're only
1486 interested in reacting to forks of the child. Note that
1487 we expect the child's fork event to be available if we
1488 waited for it now. */
1489 if (inferior_pid
== ecs
->pid
)
1491 pending_follow
.fork_event
.saw_parent_fork
= 1;
1492 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1493 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1498 pending_follow
.fork_event
.saw_child_fork
= 1;
1499 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1500 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1503 stop_pc
= read_pc_pid (ecs
->pid
);
1504 ecs
->saved_inferior_pid
= inferior_pid
;
1505 inferior_pid
= ecs
->pid
;
1506 stop_bpstat
= bpstat_stop_status
1508 (DECR_PC_AFTER_BREAK
?
1509 (prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1510 && currently_stepping (ecs
))
1513 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1514 inferior_pid
= ecs
->saved_inferior_pid
;
1515 goto process_event_stop_test
;
1517 /* If this a platform which doesn't allow a debugger to touch a
1518 vfork'd inferior until after it exec's, then we'd best keep
1519 our fingers entirely off the inferior, other than continuing
1520 it. This has the unfortunate side-effect that catchpoints
1521 of vforks will be ignored. But since the platform doesn't
1522 allow the inferior be touched at vfork time, there's really
1524 case TARGET_WAITKIND_VFORKED
:
1525 stop_signal
= TARGET_SIGNAL_TRAP
;
1526 pending_follow
.kind
= ecs
->ws
.kind
;
1528 /* Is this a vfork of the parent? If so, then give any
1529 vfork catchpoints a chance to trigger now. (It's
1530 dangerous to do so if the child canot be touched until
1531 it execs, and the child has not yet exec'd. We probably
1532 should warn the user to that effect when the catchpoint
1534 if (ecs
->pid
== inferior_pid
)
1536 pending_follow
.fork_event
.saw_parent_fork
= 1;
1537 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1538 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1541 /* If we've seen the child's vfork event but cannot really touch
1542 the child until it execs, then we must continue the child now.
1543 Else, give any vfork catchpoints a chance to trigger now. */
1546 pending_follow
.fork_event
.saw_child_fork
= 1;
1547 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1548 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1549 target_post_startup_inferior (pending_follow
.fork_event
.child_pid
);
1550 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1551 if (follow_vfork_when_exec
)
1553 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1558 stop_pc
= read_pc ();
1559 stop_bpstat
= bpstat_stop_status
1561 (DECR_PC_AFTER_BREAK
?
1562 (prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1563 && currently_stepping (ecs
))
1566 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1567 goto process_event_stop_test
;
1569 case TARGET_WAITKIND_EXECD
:
1570 stop_signal
= TARGET_SIGNAL_TRAP
;
1572 /* Is this a target which reports multiple exec events per actual
1573 call to exec()? (HP-UX using ptrace does, for example.) If so,
1574 ignore all but the last one. Just resume the exec'r, and wait
1575 for the next exec event. */
1576 if (inferior_ignoring_leading_exec_events
)
1578 inferior_ignoring_leading_exec_events
--;
1579 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1580 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.parent_pid
);
1581 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1584 inferior_ignoring_leading_exec_events
=
1585 target_reported_exec_events_per_exec_call () - 1;
1587 pending_follow
.execd_pathname
=
1588 savestring (ecs
->ws
.value
.execd_pathname
,
1589 strlen (ecs
->ws
.value
.execd_pathname
));
1591 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1592 child of a vfork exec?
1594 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1595 HP-UX, events associated with a vforking inferior come in
1596 threes: a vfork event for the child (always first), followed
1597 a vfork event for the parent and an exec event for the child.
1598 The latter two can come in either order.
1600 If we get the parent vfork event first, life's good: We follow
1601 either the parent or child, and then the child's exec event is
1604 But if we get the child's exec event first, then we delay
1605 responding to it until we handle the parent's vfork. Because,
1606 otherwise we can't satisfy a "catch vfork". */
1607 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1609 pending_follow
.fork_event
.saw_child_exec
= 1;
1611 /* On some targets, the child must be resumed before
1612 the parent vfork event is delivered. A single-step
1614 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1615 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1616 /* We expect the parent vfork event to be available now. */
1620 /* This causes the eventpoints and symbol table to be reset. Must
1621 do this now, before trying to determine whether to stop. */
1622 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
1623 free (pending_follow
.execd_pathname
);
1625 stop_pc
= read_pc_pid (ecs
->pid
);
1626 ecs
->saved_inferior_pid
= inferior_pid
;
1627 inferior_pid
= ecs
->pid
;
1628 stop_bpstat
= bpstat_stop_status
1630 (DECR_PC_AFTER_BREAK
?
1631 (prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1632 && currently_stepping (ecs
))
1635 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1636 inferior_pid
= ecs
->saved_inferior_pid
;
1637 goto process_event_stop_test
;
1639 /* These syscall events are returned on HP-UX, as part of its
1640 implementation of page-protection-based "hardware" watchpoints.
1641 HP-UX has unfortunate interactions between page-protections and
1642 some system calls. Our solution is to disable hardware watches
1643 when a system call is entered, and reenable them when the syscall
1644 completes. The downside of this is that we may miss the precise
1645 point at which a watched piece of memory is modified. "Oh well."
1647 Note that we may have multiple threads running, which may each
1648 enter syscalls at roughly the same time. Since we don't have a
1649 good notion currently of whether a watched piece of memory is
1650 thread-private, we'd best not have any page-protections active
1651 when any thread is in a syscall. Thus, we only want to reenable
1652 hardware watches when no threads are in a syscall.
1654 Also, be careful not to try to gather much state about a thread
1655 that's in a syscall. It's frequently a losing proposition. */
1656 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1657 number_of_threads_in_syscalls
++;
1658 if (number_of_threads_in_syscalls
== 1)
1660 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid
);
1662 resume (0, TARGET_SIGNAL_0
);
1665 /* Before examining the threads further, step this thread to
1666 get it entirely out of the syscall. (We get notice of the
1667 event when the thread is just on the verge of exiting a
1668 syscall. Stepping one instruction seems to get it back
1671 Note that although the logical place to reenable h/w watches
1672 is here, we cannot. We cannot reenable them before stepping
1673 the thread (this causes the next wait on the thread to hang).
1675 Nor can we enable them after stepping until we've done a wait.
1676 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1677 here, which will be serviced immediately after the target
1679 case TARGET_WAITKIND_SYSCALL_RETURN
:
1680 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1682 if (number_of_threads_in_syscalls
> 0)
1684 number_of_threads_in_syscalls
--;
1685 ecs
->enable_hw_watchpoints_after_wait
=
1686 (number_of_threads_in_syscalls
== 0);
1690 case TARGET_WAITKIND_STOPPED
:
1691 stop_signal
= ecs
->ws
.value
.sig
;
1695 /* We may want to consider not doing a resume here in order to give
1696 the user a chance to play with the new thread. It might be good
1697 to make that a user-settable option. */
1699 /* At this point, all threads are stopped (happens automatically in
1700 either the OS or the native code). Therefore we need to continue
1701 all threads in order to make progress. */
1702 if (ecs
->new_thread_event
)
1704 target_resume (-1, 0, TARGET_SIGNAL_0
);
1708 stop_pc
= read_pc_pid (ecs
->pid
);
1710 /* See if a thread hit a thread-specific breakpoint that was meant for
1711 another thread. If so, then step that thread past the breakpoint,
1714 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1716 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1717 ecs
->random_signal
= 0;
1718 else if (breakpoints_inserted
1719 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1721 ecs
->random_signal
= 0;
1722 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1727 /* Saw a breakpoint, but it was hit by the wrong thread.
1729 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->pid
);
1731 remove_status
= remove_breakpoints ();
1732 /* Did we fail to remove breakpoints? If so, try
1733 to set the PC past the bp. (There's at least
1734 one situation in which we can fail to remove
1735 the bp's: On HP-UX's that use ttrace, we can't
1736 change the address space of a vforking child
1737 process until the child exits (well, okay, not
1738 then either :-) or execs. */
1739 if (remove_status
!= 0)
1741 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->pid
);
1745 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1746 /* FIXME: What if a signal arrives instead of the
1747 single-step happening? */
1749 ecs
->waiton_pid
= ecs
->pid
;
1750 ecs
->wp
= &(ecs
->ws
);
1751 ecs
->infwait_state
= infwait_thread_hop_state
;
1755 /* We need to restart all the threads now,
1756 * unles we're running in scheduler-locked mode.
1757 * FIXME: shouldn't we look at currently_stepping ()?
1759 if (scheduler_mode
== schedlock_on
)
1760 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1762 target_resume (-1, 0, TARGET_SIGNAL_0
);
1767 /* This breakpoint matches--either it is the right
1768 thread or it's a generic breakpoint for all threads.
1769 Remember that we'll need to step just _this_ thread
1770 on any following user continuation! */
1771 thread_step_needed
= 1;
1776 ecs
->random_signal
= 1;
1778 /* See if something interesting happened to the non-current thread. If
1779 so, then switch to that thread, and eventually give control back to
1782 Note that if there's any kind of pending follow (i.e., of a fork,
1783 vfork or exec), we don't want to do this now. Rather, we'll let
1784 the next resume handle it. */
1785 if ((ecs
->pid
!= inferior_pid
) &&
1786 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1790 /* If it's a random signal for a non-current thread, notify user
1791 if he's expressed an interest. */
1792 if (ecs
->random_signal
1793 && signal_print
[stop_signal
])
1795 /* ??rehrauer: I don't understand the rationale for this code. If the
1796 inferior will stop as a result of this signal, then the act of handling
1797 the stop ought to print a message that's couches the stoppage in user
1798 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1799 won't stop as a result of the signal -- i.e., if the signal is merely
1800 a side-effect of something GDB's doing "under the covers" for the
1801 user, such as stepping threads over a breakpoint they shouldn't stop
1802 for -- then the message seems to be a serious annoyance at best.
1804 For now, remove the message altogether. */
1807 target_terminal_ours_for_output ();
1808 printf_filtered ("\nProgram received signal %s, %s.\n",
1809 target_signal_to_name (stop_signal
),
1810 target_signal_to_string (stop_signal
));
1811 gdb_flush (gdb_stdout
);
1815 /* If it's not SIGTRAP and not a signal we want to stop for, then
1816 continue the thread. */
1818 if (stop_signal
!= TARGET_SIGNAL_TRAP
1819 && !signal_stop
[stop_signal
])
1822 target_terminal_inferior ();
1824 /* Clear the signal if it should not be passed. */
1825 if (signal_program
[stop_signal
] == 0)
1826 stop_signal
= TARGET_SIGNAL_0
;
1828 target_resume (ecs
->pid
, 0, stop_signal
);
1832 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1833 and fall into the rest of wait_for_inferior(). */
1835 /* Save infrun state for the old thread. */
1836 save_infrun_state (inferior_pid
, prev_pc
,
1837 prev_func_start
, prev_func_name
,
1838 trap_expected
, step_resume_breakpoint
,
1839 through_sigtramp_breakpoint
,
1840 step_range_start
, step_range_end
,
1841 step_frame_address
, ecs
->handling_longjmp
,
1843 ecs
->stepping_through_solib_after_catch
,
1844 ecs
->stepping_through_solib_catchpoints
,
1845 ecs
->stepping_through_sigtramp
);
1847 if (may_switch_from_inferior_pid
)
1848 switched_from_inferior_pid
= inferior_pid
;
1850 inferior_pid
= ecs
->pid
;
1852 /* Load infrun state for the new thread. */
1853 load_infrun_state (inferior_pid
, &prev_pc
,
1854 &prev_func_start
, &prev_func_name
,
1855 &trap_expected
, &step_resume_breakpoint
,
1856 &through_sigtramp_breakpoint
,
1857 &step_range_start
, &step_range_end
,
1858 &step_frame_address
, &ecs
->handling_longjmp
,
1860 &ecs
->stepping_through_solib_after_catch
,
1861 &ecs
->stepping_through_solib_catchpoints
,
1862 &ecs
->stepping_through_sigtramp
);
1865 context_hook (pid_to_thread_id (ecs
->pid
));
1867 printf_filtered ("[Switching to %s]\n", target_pid_to_str (ecs
->pid
));
1868 flush_cached_frames ();
1871 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1873 /* Pull the single step breakpoints out of the target. */
1874 SOFTWARE_SINGLE_STEP (0, 0);
1875 singlestep_breakpoints_inserted_p
= 0;
1878 /* If PC is pointing at a nullified instruction, then step beyond
1879 it so that the user won't be confused when GDB appears to be ready
1882 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1883 if (INSTRUCTION_NULLIFIED
)
1885 registers_changed ();
1886 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1888 /* We may have received a signal that we want to pass to
1889 the inferior; therefore, we must not clobber the waitstatus
1892 ecs
->infwait_state
= infwait_nullified_state
;
1893 ecs
->waiton_pid
= ecs
->pid
;
1894 ecs
->wp
= &(ecs
->tmpstatus
);
1898 /* It may not be necessary to disable the watchpoint to stop over
1899 it. For example, the PA can (with some kernel cooperation)
1900 single step over a watchpoint without disabling the watchpoint. */
1901 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1907 /* It is far more common to need to disable a watchpoint to step
1908 the inferior over it. FIXME. What else might a debug
1909 register or page protection watchpoint scheme need here? */
1910 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1912 /* At this point, we are stopped at an instruction which has
1913 attempted to write to a piece of memory under control of
1914 a watchpoint. The instruction hasn't actually executed
1915 yet. If we were to evaluate the watchpoint expression
1916 now, we would get the old value, and therefore no change
1917 would seem to have occurred.
1919 In order to make watchpoints work `right', we really need
1920 to complete the memory write, and then evaluate the
1921 watchpoint expression. The following code does that by
1922 removing the watchpoint (actually, all watchpoints and
1923 breakpoints), single-stepping the target, re-inserting
1924 watchpoints, and then falling through to let normal
1925 single-step processing handle proceed. Since this
1926 includes evaluating watchpoints, things will come to a
1927 stop in the correct manner. */
1929 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
1931 remove_breakpoints ();
1932 registers_changed ();
1933 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
); /* Single step */
1935 ecs
->waiton_pid
= ecs
->pid
;
1936 ecs
->wp
= &(ecs
->ws
);
1937 ecs
->infwait_state
= infwait_nonstep_watch_state
;
1941 /* It may be possible to simply continue after a watchpoint. */
1942 if (HAVE_CONTINUABLE_WATCHPOINT
)
1943 STOPPED_BY_WATCHPOINT (ecs
->ws
);
1945 ecs
->stop_func_start
= 0;
1946 ecs
->stop_func_end
= 0;
1947 ecs
->stop_func_name
= 0;
1948 /* Don't care about return value; stop_func_start and stop_func_name
1949 will both be 0 if it doesn't work. */
1950 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
1951 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
1952 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
1953 ecs
->another_trap
= 0;
1954 bpstat_clear (&stop_bpstat
);
1956 stop_stack_dummy
= 0;
1957 stop_print_frame
= 1;
1958 ecs
->random_signal
= 0;
1959 stopped_by_random_signal
= 0;
1960 breakpoints_failed
= 0;
1962 /* Look at the cause of the stop, and decide what to do.
1963 The alternatives are:
1964 1) break; to really stop and return to the debugger,
1965 2) drop through to start up again
1966 (set ecs->another_trap to 1 to single step once)
1967 3) set ecs->random_signal to 1, and the decision between 1 and 2
1968 will be made according to the signal handling tables. */
1970 /* First, distinguish signals caused by the debugger from signals
1971 that have to do with the program's own actions.
1972 Note that breakpoint insns may cause SIGTRAP or SIGILL
1973 or SIGEMT, depending on the operating system version.
1974 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1975 and change it to SIGTRAP. */
1977 if (stop_signal
== TARGET_SIGNAL_TRAP
1978 || (breakpoints_inserted
&&
1979 (stop_signal
== TARGET_SIGNAL_ILL
1980 || stop_signal
== TARGET_SIGNAL_EMT
1982 || stop_soon_quietly
)
1984 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
1986 stop_print_frame
= 0;
1989 if (stop_soon_quietly
)
1992 /* Don't even think about breakpoints
1993 if just proceeded over a breakpoint.
1995 However, if we are trying to proceed over a breakpoint
1996 and end up in sigtramp, then through_sigtramp_breakpoint
1997 will be set and we should check whether we've hit the
1999 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2000 && through_sigtramp_breakpoint
== NULL
)
2001 bpstat_clear (&stop_bpstat
);
2004 /* See if there is a breakpoint at the current PC. */
2005 stop_bpstat
= bpstat_stop_status
2007 (DECR_PC_AFTER_BREAK
?
2008 /* Notice the case of stepping through a jump
2009 that lands just after a breakpoint.
2010 Don't confuse that with hitting the breakpoint.
2011 What we check for is that 1) stepping is going on
2012 and 2) the pc before the last insn does not match
2013 the address of the breakpoint before the current pc
2014 and 3) we didn't hit a breakpoint in a signal handler
2015 without an intervening stop in sigtramp, which is
2016 detected by a new stack pointer value below
2017 any usual function calling stack adjustments. */
2018 (currently_stepping (ecs
)
2019 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
2021 && INNER_THAN (read_sp (), (step_sp
- 16)))) :
2024 /* Following in case break condition called a
2026 stop_print_frame
= 1;
2029 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2031 = !(bpstat_explains_signal (stop_bpstat
)
2033 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2034 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2035 FRAME_FP (get_current_frame ())))
2036 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2041 = !(bpstat_explains_signal (stop_bpstat
)
2042 /* End of a stack dummy. Some systems (e.g. Sony
2043 news) give another signal besides SIGTRAP, so
2044 check here as well as above. */
2045 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2046 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2047 FRAME_FP (get_current_frame ())))
2049 if (!ecs
->random_signal
)
2050 stop_signal
= TARGET_SIGNAL_TRAP
;
2054 /* When we reach this point, we've pretty much decided
2055 that the reason for stopping must've been a random
2056 (unexpected) signal. */
2059 ecs
->random_signal
= 1;
2060 /* If a fork, vfork or exec event was seen, then there are two
2061 possible responses we can make:
2063 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2064 then we must stop now and issue a prompt. We will resume
2065 the inferior when the user tells us to.
2066 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2067 then we must resume the inferior now and keep checking.
2069 In either case, we must take appropriate steps to "follow" the
2070 the fork/vfork/exec when the inferior is resumed. For example,
2071 if follow-fork-mode is "child", then we must detach from the
2072 parent inferior and follow the new child inferior.
2074 In either case, setting pending_follow causes the next resume()
2075 to take the appropriate following action. */
2076 process_event_stop_test
:
2077 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2079 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2082 stop_signal
= TARGET_SIGNAL_0
;
2086 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2088 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2090 stop_signal
= TARGET_SIGNAL_0
;
2094 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2096 pending_follow
.kind
= ecs
->ws
.kind
;
2097 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2100 stop_signal
= TARGET_SIGNAL_0
;
2105 /* For the program's own signals, act according to
2106 the signal handling tables. */
2108 if (ecs
->random_signal
)
2110 /* Signal not for debugging purposes. */
2113 stopped_by_random_signal
= 1;
2115 if (signal_print
[stop_signal
])
2118 target_terminal_ours_for_output ();
2120 printf_filtered ("\nProgram received signal ");
2121 annotate_signal_name ();
2122 printf_filtered ("%s", target_signal_to_name (stop_signal
));
2123 annotate_signal_name_end ();
2124 printf_filtered (", ");
2125 annotate_signal_string ();
2126 printf_filtered ("%s", target_signal_to_string (stop_signal
));
2127 annotate_signal_string_end ();
2128 printf_filtered (".\n");
2129 gdb_flush (gdb_stdout
);
2131 if (signal_stop
[stop_signal
])
2133 /* If not going to stop, give terminal back
2134 if we took it away. */
2136 target_terminal_inferior ();
2138 /* Clear the signal if it should not be passed. */
2139 if (signal_program
[stop_signal
] == 0)
2140 stop_signal
= TARGET_SIGNAL_0
;
2142 /* I'm not sure whether this needs to be check_sigtramp2 or
2143 whether it could/should be keep_going.
2145 This used to jump to step_over_function if we are stepping,
2148 Suppose the user does a `next' over a function call, and while
2149 that call is in progress, the inferior receives a signal for
2150 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2151 that case, when we reach this point, there is already a
2152 step-resume breakpoint established, right where it should be:
2153 immediately after the function call the user is "next"-ing
2154 over. If we jump to step_over_function now, two bad things
2157 - we'll create a new breakpoint, at wherever the current
2158 frame's return address happens to be. That could be
2159 anywhere, depending on what function call happens to be on
2160 the top of the stack at that point. Point is, it's probably
2161 not where we need it.
2163 - the existing step-resume breakpoint (which is at the correct
2164 address) will get orphaned: step_resume_breakpoint will point
2165 to the new breakpoint, and the old step-resume breakpoint
2166 will never be cleaned up.
2168 The old behavior was meant to help HP-UX single-step out of
2169 sigtramps. It would place the new breakpoint at prev_pc, which
2170 was certainly wrong. I don't know the details there, so fixing
2171 this probably breaks that. As with anything else, it's up to
2172 the HP-UX maintainer to furnish a fix that doesn't break other
2173 platforms. --JimB, 20 May 1999 */
2174 goto check_sigtramp2
;
2177 /* Handle cases caused by hitting a breakpoint. */
2179 CORE_ADDR jmp_buf_pc
;
2180 struct bpstat_what what
;
2182 what
= bpstat_what (stop_bpstat
);
2184 if (what
.call_dummy
)
2186 stop_stack_dummy
= 1;
2188 trap_expected_after_continue
= 1;
2192 switch (what
.main_action
)
2194 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2195 /* If we hit the breakpoint at longjmp, disable it for the
2196 duration of this command. Then, install a temporary
2197 breakpoint at the target of the jmp_buf. */
2198 disable_longjmp_breakpoint ();
2199 remove_breakpoints ();
2200 breakpoints_inserted
= 0;
2201 if (!GET_LONGJMP_TARGET (&jmp_buf_pc
))
2204 /* Need to blow away step-resume breakpoint, as it
2205 interferes with us */
2206 if (step_resume_breakpoint
!= NULL
)
2208 delete_breakpoint (step_resume_breakpoint
);
2209 step_resume_breakpoint
= NULL
;
2211 /* Not sure whether we need to blow this away too, but probably
2212 it is like the step-resume breakpoint. */
2213 if (through_sigtramp_breakpoint
!= NULL
)
2215 delete_breakpoint (through_sigtramp_breakpoint
);
2216 through_sigtramp_breakpoint
= NULL
;
2220 /* FIXME - Need to implement nested temporary breakpoints */
2221 if (step_over_calls
> 0)
2222 set_longjmp_resume_breakpoint (jmp_buf_pc
,
2223 get_current_frame ());
2226 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2227 ecs
->handling_longjmp
= 1; /* FIXME */
2230 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2231 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2232 remove_breakpoints ();
2233 breakpoints_inserted
= 0;
2235 /* FIXME - Need to implement nested temporary breakpoints */
2237 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2238 step_frame_address
)))
2240 ecs
->another_trap
= 1;
2244 disable_longjmp_breakpoint ();
2245 ecs
->handling_longjmp
= 0; /* FIXME */
2246 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2248 /* else fallthrough */
2250 case BPSTAT_WHAT_SINGLE
:
2251 if (breakpoints_inserted
)
2253 thread_step_needed
= 1;
2254 remove_breakpoints ();
2256 breakpoints_inserted
= 0;
2257 ecs
->another_trap
= 1;
2258 /* Still need to check other stuff, at least the case
2259 where we are stepping and step out of the right range. */
2262 case BPSTAT_WHAT_STOP_NOISY
:
2263 stop_print_frame
= 1;
2265 /* We are about to nuke the step_resume_breakpoint and
2266 through_sigtramp_breakpoint via the cleanup chain, so
2267 no need to worry about it here. */
2271 case BPSTAT_WHAT_STOP_SILENT
:
2272 stop_print_frame
= 0;
2274 /* We are about to nuke the step_resume_breakpoint and
2275 through_sigtramp_breakpoint via the cleanup chain, so
2276 no need to worry about it here. */
2280 case BPSTAT_WHAT_STEP_RESUME
:
2281 /* This proably demands a more elegant solution, but, yeah
2284 This function's use of the simple variable
2285 step_resume_breakpoint doesn't seem to accomodate
2286 simultaneously active step-resume bp's, although the
2287 breakpoint list certainly can.
2289 If we reach here and step_resume_breakpoint is already
2290 NULL, then apparently we have multiple active
2291 step-resume bp's. We'll just delete the breakpoint we
2292 stopped at, and carry on. */
2293 if (step_resume_breakpoint
== NULL
)
2295 step_resume_breakpoint
=
2296 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2298 delete_breakpoint (step_resume_breakpoint
);
2299 step_resume_breakpoint
= NULL
;
2302 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2303 if (through_sigtramp_breakpoint
)
2304 delete_breakpoint (through_sigtramp_breakpoint
);
2305 through_sigtramp_breakpoint
= NULL
;
2307 /* If were waiting for a trap, hitting the step_resume_break
2308 doesn't count as getting it. */
2310 ecs
->another_trap
= 1;
2313 case BPSTAT_WHAT_CHECK_SHLIBS
:
2314 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2317 /* Remove breakpoints, we eventually want to step over the
2318 shlib event breakpoint, and SOLIB_ADD might adjust
2319 breakpoint addresses via breakpoint_re_set. */
2320 if (breakpoints_inserted
)
2321 remove_breakpoints ();
2322 breakpoints_inserted
= 0;
2324 /* Check for any newly added shared libraries if we're
2325 supposed to be adding them automatically. */
2328 /* Switch terminal for any messages produced by
2329 breakpoint_re_set. */
2330 target_terminal_ours_for_output ();
2331 SOLIB_ADD (NULL
, 0, NULL
);
2332 target_terminal_inferior ();
2335 /* Try to reenable shared library breakpoints, additional
2336 code segments in shared libraries might be mapped in now. */
2337 re_enable_breakpoints_in_shlibs ();
2339 /* If requested, stop when the dynamic linker notifies
2340 gdb of events. This allows the user to get control
2341 and place breakpoints in initializer routines for
2342 dynamically loaded objects (among other things). */
2343 if (stop_on_solib_events
)
2345 stop_print_frame
= 0;
2349 /* If we stopped due to an explicit catchpoint, then the
2350 (see above) call to SOLIB_ADD pulled in any symbols
2351 from a newly-loaded library, if appropriate.
2353 We do want the inferior to stop, but not where it is
2354 now, which is in the dynamic linker callback. Rather,
2355 we would like it stop in the user's program, just after
2356 the call that caused this catchpoint to trigger. That
2357 gives the user a more useful vantage from which to
2358 examine their program's state. */
2359 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2361 /* ??rehrauer: If I could figure out how to get the
2362 right return PC from here, we could just set a temp
2363 breakpoint and resume. I'm not sure we can without
2364 cracking open the dld's shared libraries and sniffing
2365 their unwind tables and text/data ranges, and that's
2366 not a terribly portable notion.
2368 Until that time, we must step the inferior out of the
2369 dld callback, and also out of the dld itself (and any
2370 code or stubs in libdld.sl, such as "shl_load" and
2371 friends) until we reach non-dld code. At that point,
2372 we can stop stepping. */
2373 bpstat_get_triggered_catchpoints (stop_bpstat
,
2374 &ecs
->stepping_through_solib_catchpoints
);
2375 ecs
->stepping_through_solib_after_catch
= 1;
2377 /* Be sure to lift all breakpoints, so the inferior does
2378 actually step past this point... */
2379 ecs
->another_trap
= 1;
2384 /* We want to step over this breakpoint, then keep going. */
2385 ecs
->another_trap
= 1;
2392 case BPSTAT_WHAT_LAST
:
2393 /* Not a real code, but listed here to shut up gcc -Wall. */
2395 case BPSTAT_WHAT_KEEP_CHECKING
:
2400 /* We come here if we hit a breakpoint but should not
2401 stop for it. Possibly we also were stepping
2402 and should stop for that. So fall through and
2403 test for stepping. But, if not stepping,
2406 /* Are we stepping to get the inferior out of the dynamic
2407 linker's hook (and possibly the dld itself) after catching
2409 if (ecs
->stepping_through_solib_after_catch
)
2411 #if defined(SOLIB_ADD)
2412 /* Have we reached our destination? If not, keep going. */
2413 if (SOLIB_IN_DYNAMIC_LINKER (ecs
->pid
, stop_pc
))
2415 ecs
->another_trap
= 1;
2419 /* Else, stop and report the catchpoint(s) whose triggering
2420 caused us to begin stepping. */
2421 ecs
->stepping_through_solib_after_catch
= 0;
2422 bpstat_clear (&stop_bpstat
);
2423 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2424 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2425 stop_print_frame
= 1;
2429 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2431 /* This is the old way of detecting the end of the stack dummy.
2432 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2433 handled above. As soon as we can test it on all of them, all
2434 architectures should define it. */
2436 /* If this is the breakpoint at the end of a stack dummy,
2437 just stop silently, unless the user was doing an si/ni, in which
2438 case she'd better know what she's doing. */
2440 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2441 FRAME_FP (get_current_frame ()))
2444 stop_print_frame
= 0;
2445 stop_stack_dummy
= 1;
2447 trap_expected_after_continue
= 1;
2453 if (step_resume_breakpoint
)
2454 /* Having a step-resume breakpoint overrides anything
2455 else having to do with stepping commands until
2456 that breakpoint is reached. */
2457 /* I'm not sure whether this needs to be check_sigtramp2 or
2458 whether it could/should be keep_going. */
2459 goto check_sigtramp2
;
2461 if (step_range_end
== 0)
2462 /* Likewise if we aren't even stepping. */
2463 /* I'm not sure whether this needs to be check_sigtramp2 or
2464 whether it could/should be keep_going. */
2465 goto check_sigtramp2
;
2467 /* If stepping through a line, keep going if still within it.
2469 Note that step_range_end is the address of the first instruction
2470 beyond the step range, and NOT the address of the last instruction
2472 if (stop_pc
>= step_range_start
2473 && stop_pc
< step_range_end
)
2475 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2476 So definately need to check for sigtramp here. */
2477 goto check_sigtramp2
;
2480 /* We stepped out of the stepping range. */
2482 /* If we are stepping at the source level and entered the runtime
2483 loader dynamic symbol resolution code, we keep on single stepping
2484 until we exit the run time loader code and reach the callee's
2486 if (step_over_calls
< 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2489 /* We can't update step_sp every time through the loop, because
2490 reading the stack pointer would slow down stepping too much.
2491 But we can update it every time we leave the step range. */
2492 ecs
->update_step_sp
= 1;
2494 /* Did we just take a signal? */
2495 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2496 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2497 && INNER_THAN (read_sp (), step_sp
))
2499 /* We've just taken a signal; go until we are back to
2500 the point where we took it and one more. */
2502 /* Note: The test above succeeds not only when we stepped
2503 into a signal handler, but also when we step past the last
2504 statement of a signal handler and end up in the return stub
2505 of the signal handler trampoline. To distinguish between
2506 these two cases, check that the frame is INNER_THAN the
2507 previous one below. pai/1997-09-11 */
2511 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2513 if (INNER_THAN (current_frame
, step_frame_address
))
2515 /* We have just taken a signal; go until we are back to
2516 the point where we took it and one more. */
2518 /* This code is needed at least in the following case:
2519 The user types "next" and then a signal arrives (before
2520 the "next" is done). */
2522 /* Note that if we are stopped at a breakpoint, then we need
2523 the step_resume breakpoint to override any breakpoints at
2524 the same location, so that we will still step over the
2525 breakpoint even though the signal happened. */
2526 struct symtab_and_line sr_sal
;
2529 sr_sal
.symtab
= NULL
;
2531 sr_sal
.pc
= prev_pc
;
2532 /* We could probably be setting the frame to
2533 step_frame_address; I don't think anyone thought to
2535 check_for_old_step_resume_breakpoint ();
2536 step_resume_breakpoint
=
2537 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2538 if (breakpoints_inserted
)
2539 insert_breakpoints ();
2543 /* We just stepped out of a signal handler and into
2544 its calling trampoline.
2546 Normally, we'd jump to step_over_function from
2547 here, but for some reason GDB can't unwind the
2548 stack correctly to find the real PC for the point
2549 user code where the signal trampoline will return
2550 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2551 But signal trampolines are pretty small stubs of
2552 code, anyway, so it's OK instead to just
2553 single-step out. Note: assuming such trampolines
2554 don't exhibit recursion on any platform... */
2555 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2556 &ecs
->stop_func_start
,
2557 &ecs
->stop_func_end
);
2558 /* Readjust stepping range */
2559 step_range_start
= ecs
->stop_func_start
;
2560 step_range_end
= ecs
->stop_func_end
;
2561 ecs
->stepping_through_sigtramp
= 1;
2566 /* If this is stepi or nexti, make sure that the stepping range
2567 gets us past that instruction. */
2568 if (step_range_end
== 1)
2569 /* FIXME: Does this run afoul of the code below which, if
2570 we step into the middle of a line, resets the stepping
2572 step_range_end
= (step_range_start
= prev_pc
) + 1;
2574 ecs
->remove_breakpoints_on_following_step
= 1;
2578 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2579 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2580 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2581 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2582 || ecs
->stop_func_name
== 0)
2584 /* It's a subroutine call. */
2586 if (step_over_calls
== 0)
2588 /* I presume that step_over_calls is only 0 when we're
2589 supposed to be stepping at the assembly language level
2590 ("stepi"). Just stop. */
2595 if (step_over_calls
> 0 || IGNORE_HELPER_CALL (stop_pc
))
2596 /* We're doing a "next". */
2597 goto step_over_function
;
2599 /* If we are in a function call trampoline (a stub between
2600 the calling routine and the real function), locate the real
2601 function. That's what tells us (a) whether we want to step
2602 into it at all, and (b) what prologue we want to run to
2603 the end of, if we do step into it. */
2604 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2606 ecs
->stop_func_start
= tmp
;
2609 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2612 struct symtab_and_line xxx
;
2613 /* Why isn't this s_a_l called "sr_sal", like all of the
2614 other s_a_l's where this code is duplicated? */
2615 INIT_SAL (&xxx
); /* initialize to zeroes */
2617 xxx
.section
= find_pc_overlay (xxx
.pc
);
2618 check_for_old_step_resume_breakpoint ();
2619 step_resume_breakpoint
=
2620 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2621 insert_breakpoints ();
2626 /* If we have line number information for the function we
2627 are thinking of stepping into, step into it.
2629 If there are several symtabs at that PC (e.g. with include
2630 files), just want to know whether *any* of them have line
2631 numbers. find_pc_line handles this. */
2633 struct symtab_and_line tmp_sal
;
2635 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2636 if (tmp_sal
.line
!= 0)
2637 goto step_into_function
;
2641 /* A subroutine call has happened. */
2643 /* We've just entered a callee, and we wish to resume until it
2644 returns to the caller. Setting a step_resume breakpoint on
2645 the return address will catch a return from the callee.
2647 However, if the callee is recursing, we want to be careful
2648 not to catch returns of those recursive calls, but only of
2649 THIS instance of the call.
2651 To do this, we set the step_resume bp's frame to our current
2652 caller's frame (step_frame_address, which is set by the "next"
2653 or "until" command, before execution begins). */
2654 struct symtab_and_line sr_sal
;
2656 INIT_SAL (&sr_sal
); /* initialize to zeros */
2658 ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2659 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2661 check_for_old_step_resume_breakpoint ();
2662 step_resume_breakpoint
=
2663 set_momentary_breakpoint (sr_sal
, get_current_frame (),
2666 if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
2667 step_resume_breakpoint
->frame
= step_frame_address
;
2669 if (breakpoints_inserted
)
2670 insert_breakpoints ();
2675 /* Subroutine call with source code we should not step over.
2676 Do step to the first line of code in it. */
2680 s
= find_pc_symtab (stop_pc
);
2681 if (s
&& s
->language
!= language_asm
)
2682 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2684 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2685 /* Use the step_resume_break to step until
2686 the end of the prologue, even if that involves jumps
2687 (as it seems to on the vax under 4.2). */
2688 /* If the prologue ends in the middle of a source line,
2689 continue to the end of that source line (if it is still
2690 within the function). Otherwise, just go to end of prologue. */
2691 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2692 /* no, don't either. It skips any code that's
2693 legitimately on the first line. */
2695 if (ecs
->sal
.end
&& ecs
->sal
.pc
!= ecs
->stop_func_start
&& ecs
->sal
.end
< ecs
->stop_func_end
)
2696 ecs
->stop_func_start
= ecs
->sal
.end
;
2699 if (ecs
->stop_func_start
== stop_pc
)
2701 /* We are already there: stop now. */
2706 /* Put the step-breakpoint there and go until there. */
2708 struct symtab_and_line sr_sal
;
2710 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2711 sr_sal
.pc
= ecs
->stop_func_start
;
2712 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
2713 /* Do not specify what the fp should be when we stop
2714 since on some machines the prologue
2715 is where the new fp value is established. */
2716 check_for_old_step_resume_breakpoint ();
2717 step_resume_breakpoint
=
2718 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2719 if (breakpoints_inserted
)
2720 insert_breakpoints ();
2722 /* And make sure stepping stops right away then. */
2723 step_range_end
= step_range_start
;
2728 /* We've wandered out of the step range. */
2730 ecs
->sal
= find_pc_line (stop_pc
, 0);
2732 if (step_range_end
== 1)
2734 /* It is stepi or nexti. We always want to stop stepping after
2740 /* If we're in the return path from a shared library trampoline,
2741 we want to proceed through the trampoline when stepping. */
2742 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2746 /* Determine where this trampoline returns. */
2747 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2749 /* Only proceed through if we know where it's going. */
2752 /* And put the step-breakpoint there and go until there. */
2753 struct symtab_and_line sr_sal
;
2755 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2757 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2758 /* Do not specify what the fp should be when we stop
2759 since on some machines the prologue
2760 is where the new fp value is established. */
2761 check_for_old_step_resume_breakpoint ();
2762 step_resume_breakpoint
=
2763 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2764 if (breakpoints_inserted
)
2765 insert_breakpoints ();
2767 /* Restart without fiddling with the step ranges or
2773 if (ecs
->sal
.line
== 0)
2775 /* We have no line number information. That means to stop
2776 stepping (does this always happen right after one instruction,
2777 when we do "s" in a function with no line numbers,
2778 or can this happen as a result of a return or longjmp?). */
2783 if ((stop_pc
== ecs
->sal
.pc
)
2784 && (ecs
->current_line
!= ecs
->sal
.line
|| ecs
->current_symtab
!= ecs
->sal
.symtab
))
2786 /* We are at the start of a different line. So stop. Note that
2787 we don't stop if we step into the middle of a different line.
2788 That is said to make things like for (;;) statements work
2794 /* We aren't done stepping.
2796 Optimize by setting the stepping range to the line.
2797 (We might not be in the original line, but if we entered a
2798 new line in mid-statement, we continue stepping. This makes
2799 things like for(;;) statements work better.) */
2801 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2803 /* If this is the last line of the function, don't keep stepping
2804 (it would probably step us out of the function).
2805 This is particularly necessary for a one-line function,
2806 in which after skipping the prologue we better stop even though
2807 we will be in mid-line. */
2811 step_range_start
= ecs
->sal
.pc
;
2812 step_range_end
= ecs
->sal
.end
;
2813 step_frame_address
= FRAME_FP (get_current_frame ());
2814 ecs
->current_line
= ecs
->sal
.line
;
2815 ecs
->current_symtab
= ecs
->sal
.symtab
;
2817 /* In the case where we just stepped out of a function into the middle
2818 of a line of the caller, continue stepping, but step_frame_address
2819 must be modified to current frame */
2821 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2822 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2823 step_frame_address
= current_frame
;
2831 && IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2832 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2833 && INNER_THAN (read_sp (), step_sp
))
2835 /* What has happened here is that we have just stepped the inferior
2836 with a signal (because it is a signal which shouldn't make
2837 us stop), thus stepping into sigtramp.
2839 So we need to set a step_resume_break_address breakpoint
2840 and continue until we hit it, and then step. FIXME: This should
2841 be more enduring than a step_resume breakpoint; we should know
2842 that we will later need to keep going rather than re-hitting
2843 the breakpoint here (see testsuite/gdb.t06/signals.exp where
2844 it says "exceedingly difficult"). */
2845 struct symtab_and_line sr_sal
;
2847 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2848 sr_sal
.pc
= prev_pc
;
2849 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2850 /* We perhaps could set the frame if we kept track of what
2851 the frame corresponding to prev_pc was. But we don't,
2853 through_sigtramp_breakpoint
=
2854 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2855 if (breakpoints_inserted
)
2856 insert_breakpoints ();
2858 ecs
->remove_breakpoints_on_following_step
= 1;
2859 ecs
->another_trap
= 1;
2863 /* Come to this label when you need to resume the inferior.
2864 It's really much cleaner to do a goto than a maze of if-else
2867 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug
2868 a vforked child beetween its creation and subsequent exit or
2869 call to exec(). However, I had big problems in this rather
2870 creaky exec engine, getting that to work. The fundamental
2871 problem is that I'm trying to debug two processes via an
2872 engine that only understands a single process with possibly
2875 Hence, this spot is known to have problems when
2876 target_can_follow_vfork_prior_to_exec returns 1. */
2878 /* Save the pc before execution, to compare with pc after stop. */
2879 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
2880 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
2881 BREAK is defined, the
2882 original pc would not have
2883 been at the start of a
2885 prev_func_name
= ecs
->stop_func_name
;
2887 if (ecs
->update_step_sp
)
2888 step_sp
= read_sp ();
2889 ecs
->update_step_sp
= 0;
2891 /* If we did not do break;, it means we should keep
2892 running the inferior and not return to debugger. */
2894 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
2896 /* We took a signal (which we are supposed to pass through to
2897 the inferior, else we'd have done a break above) and we
2898 haven't yet gotten our trap. Simply continue. */
2899 resume (currently_stepping (ecs
), stop_signal
);
2903 /* Either the trap was not expected, but we are continuing
2904 anyway (the user asked that this signal be passed to the
2907 The signal was SIGTRAP, e.g. it was our signal, but we
2908 decided we should resume from it.
2910 We're going to run this baby now!
2912 Insert breakpoints now, unless we are trying
2913 to one-proceed past a breakpoint. */
2914 /* If we've just finished a special step resume and we don't
2915 want to hit a breakpoint, pull em out. */
2916 if (step_resume_breakpoint
== NULL
2917 && through_sigtramp_breakpoint
== NULL
2918 && ecs
->remove_breakpoints_on_following_step
)
2920 ecs
->remove_breakpoints_on_following_step
= 0;
2921 remove_breakpoints ();
2922 breakpoints_inserted
= 0;
2924 else if (!breakpoints_inserted
&&
2925 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
2927 breakpoints_failed
= insert_breakpoints ();
2928 if (breakpoints_failed
)
2930 breakpoints_inserted
= 1;
2933 trap_expected
= ecs
->another_trap
;
2935 /* Do not deliver SIGNAL_TRAP (except when the user
2936 explicitly specifies that such a signal should be
2937 delivered to the target program).
2939 Typically, this would occure when a user is debugging a
2940 target monitor on a simulator: the target monitor sets a
2941 breakpoint; the simulator encounters this break-point and
2942 halts the simulation handing control to GDB; GDB, noteing
2943 that the break-point isn't valid, returns control back to
2944 the simulator; the simulator then delivers the hardware
2945 equivalent of a SIGNAL_TRAP to the program being
2948 if (stop_signal
== TARGET_SIGNAL_TRAP
2949 && !signal_program
[stop_signal
])
2950 stop_signal
= TARGET_SIGNAL_0
;
2952 #ifdef SHIFT_INST_REGS
2953 /* I'm not sure when this following segment applies. I do know,
2954 now, that we shouldn't rewrite the regs when we were stopped
2955 by a random signal from the inferior process. */
2956 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2957 (this is only used on the 88k). */
2959 if (!bpstat_explains_signal (stop_bpstat
)
2960 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
2961 && !stopped_by_random_signal
)
2963 #endif /* SHIFT_INST_REGS */
2965 resume (currently_stepping (ecs
), stop_signal
);
2968 /* Former continues in the main loop goto here. */
2970 /* This used to be at the top of the loop. */
2971 if (ecs
->infwait_state
== infwait_normal_state
)
2973 overlay_cache_invalid
= 1;
2975 /* We have to invalidate the registers BEFORE calling
2976 target_wait because they can be loaded from the target
2977 while in target_wait. This makes remote debugging a bit
2978 more efficient for those targets that provide critical
2979 registers as part of their normal status mechanism. */
2981 registers_changed ();
2982 ecs
->waiton_pid
= -1;
2983 ecs
->wp
= &(ecs
->ws
);
2985 /* This is the old end of the while loop. Let everybody know
2986 we want to wait for the inferior some more and get called
2988 ecs
->wait_some_more
= 1;
2992 /* Former breaks in the main loop goto here. */
2996 if (target_has_execution
)
2998 /* Are we stopping for a vfork event? We only stop when we see
2999 the child's event. However, we may not yet have seen the
3000 parent's event. And, inferior_pid is still set to the parent's
3001 pid, until we resume again and follow either the parent or child.
3003 To ensure that we can really touch inferior_pid (aka, the
3004 parent process) -- which calls to functions like read_pc
3005 implicitly do -- wait on the parent if necessary. */
3006 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3007 && !pending_follow
.fork_event
.saw_parent_fork
)
3013 if (target_wait_hook
)
3014 parent_pid
= target_wait_hook (-1, &(ecs
->ws
));
3016 parent_pid
= target_wait (-1, &(ecs
->ws
));
3018 while (parent_pid
!= inferior_pid
);
3021 /* Assuming the inferior still exists, set these up for next
3022 time, just like we did above if we didn't break out of the
3024 prev_pc
= read_pc ();
3025 prev_func_start
= ecs
->stop_func_start
;
3026 prev_func_name
= ecs
->stop_func_name
;
3028 /* Let callers know we don't want to wait for the inferior anymore. */
3029 ecs
->wait_some_more
= 0;
3032 /* Are we in the middle of stepping? */
3035 currently_stepping (struct execution_control_state
*ecs
)
3037 return ((through_sigtramp_breakpoint
== NULL
3038 && !ecs
->handling_longjmp
3039 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
3041 || ecs
->stepping_through_solib_after_catch
3042 || bpstat_should_step ());
3045 /* This function returns TRUE if ep is an internal breakpoint
3046 set to catch generic shared library (aka dynamically-linked
3047 library) events. (This is *NOT* the same as a catchpoint for a
3048 shlib event. The latter is something a user can set; this is
3049 something gdb sets for its own use, and isn't ever shown to a
3052 is_internal_shlib_eventpoint (struct breakpoint
*ep
)
3055 (ep
->type
== bp_shlib_event
)
3059 /* This function returns TRUE if bs indicates that the inferior
3060 stopped due to a shared library (aka dynamically-linked library)
3064 stopped_for_internal_shlib_event (bpstat bs
)
3066 /* Note that multiple eventpoints may've caused the stop. Any
3067 that are associated with shlib events will be accepted. */
3068 for (; bs
!= NULL
; bs
= bs
->next
)
3070 if ((bs
->breakpoint_at
!= NULL
)
3071 && is_internal_shlib_eventpoint (bs
->breakpoint_at
))
3075 /* If we get here, then no candidate was found. */
3079 /* Reset proper settings after an asynchronous command has finished.
3080 If the execution command was in synchronous mode, register stdin
3081 with the event loop, and reset the prompt. */
3084 complete_execution (void)
3086 extern int cleanup_sigint_signal_handler (void);
3088 target_executing
= 0;
3091 add_file_handler (input_fd
, (file_handler_func
*) call_readline
, 0);
3094 cleanup_sigint_signal_handler ();
3095 display_gdb_prompt (0);
3099 /* Here to return control to GDB when the inferior stops for real.
3100 Print appropriate messages, remove breakpoints, give terminal our modes.
3102 STOP_PRINT_FRAME nonzero means print the executing frame
3103 (pc, function, args, file, line number and line text).
3104 BREAKPOINTS_FAILED nonzero means stop was due to error
3105 attempting to insert breakpoints. */
3110 /* As with the notification of thread events, we want to delay
3111 notifying the user that we've switched thread context until
3112 the inferior actually stops.
3114 (Note that there's no point in saying anything if the inferior
3116 if (may_switch_from_inferior_pid
3117 && (switched_from_inferior_pid
!= inferior_pid
)
3118 && target_has_execution
)
3120 target_terminal_ours_for_output ();
3121 printf_filtered ("[Switched to %s]\n",
3122 target_pid_or_tid_to_str (inferior_pid
));
3123 switched_from_inferior_pid
= inferior_pid
;
3126 /* Make sure that the current_frame's pc is correct. This
3127 is a correction for setting up the frame info before doing
3128 DECR_PC_AFTER_BREAK */
3129 if (target_has_execution
&& get_current_frame ())
3130 (get_current_frame ())->pc
= read_pc ();
3132 if (breakpoints_failed
)
3134 target_terminal_ours_for_output ();
3135 print_sys_errmsg ("ptrace", breakpoints_failed
);
3136 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3137 The same program may be running in another process.\n");
3140 if (target_has_execution
&& breakpoints_inserted
)
3142 if (remove_breakpoints ())
3144 target_terminal_ours_for_output ();
3145 printf_filtered ("Cannot remove breakpoints because ");
3146 printf_filtered ("program is no longer writable.\n");
3147 printf_filtered ("It might be running in another process.\n");
3148 printf_filtered ("Further execution is probably impossible.\n");
3151 breakpoints_inserted
= 0;
3153 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3154 Delete any breakpoint that is to be deleted at the next stop. */
3156 breakpoint_auto_delete (stop_bpstat
);
3158 /* If an auto-display called a function and that got a signal,
3159 delete that auto-display to avoid an infinite recursion. */
3161 if (stopped_by_random_signal
)
3162 disable_current_display ();
3164 /* Don't print a message if in the middle of doing a "step n"
3165 operation for n > 1 */
3166 if (step_multi
&& stop_step
)
3169 target_terminal_ours ();
3171 /* Did we stop because the user set the stop_on_solib_events
3172 variable? (If so, we report this as a generic, "Stopped due
3173 to shlib event" message.) */
3174 if (stopped_for_internal_shlib_event (stop_bpstat
))
3176 printf_filtered ("Stopped due to shared library event\n");
3179 /* Look up the hook_stop and run it if it exists. */
3181 if (stop_command
&& stop_command
->hook
)
3183 catch_errors (hook_stop_stub
, stop_command
->hook
,
3184 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3187 if (!target_has_stack
)
3193 /* Select innermost stack frame - i.e., current frame is frame 0,
3194 and current location is based on that.
3195 Don't do this on return from a stack dummy routine,
3196 or if the program has exited. */
3198 if (!stop_stack_dummy
)
3200 select_frame (get_current_frame (), 0);
3202 /* Print current location without a level number, if
3203 we have changed functions or hit a breakpoint.
3204 Print source line if we have one.
3205 bpstat_print() contains the logic deciding in detail
3206 what to print, based on the event(s) that just occurred. */
3208 if (stop_print_frame
)
3213 bpstat_ret
= bpstat_print (stop_bpstat
);
3214 /* bpstat_print() returned one of:
3215 -1: Didn't print anything
3216 0: Printed preliminary "Breakpoint n, " message, desires
3218 1: Printed something, don't tack on location */
3220 if (bpstat_ret
== -1)
3222 && step_frame_address
== FRAME_FP (get_current_frame ())
3223 && step_start_function
== find_pc_function (stop_pc
))
3224 source_flag
= -1; /* finished step, just print source line */
3226 source_flag
= 1; /* print location and source line */
3227 else if (bpstat_ret
== 0) /* hit bpt, desire location */
3228 source_flag
= 1; /* print location and source line */
3229 else /* bpstat_ret == 1, hit bpt, do not desire location */
3230 source_flag
= -1; /* just print source line */
3232 /* The behavior of this routine with respect to the source
3234 -1: Print only source line
3235 0: Print only location
3236 1: Print location and source line */
3237 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
3239 /* Display the auto-display expressions. */
3244 /* Save the function value return registers, if we care.
3245 We might be about to restore their previous contents. */
3246 if (proceed_to_finish
)
3247 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
3249 if (stop_stack_dummy
)
3251 /* Pop the empty frame that contains the stack dummy.
3252 POP_FRAME ends with a setting of the current frame, so we
3253 can use that next. */
3255 /* Set stop_pc to what it was before we called the function.
3256 Can't rely on restore_inferior_status because that only gets
3257 called if we don't stop in the called function. */
3258 stop_pc
= read_pc ();
3259 select_frame (get_current_frame (), 0);
3263 TUIDO (((TuiOpaqueFuncPtr
) tui_vCheckDataValues
, selected_frame
));
3266 annotate_stopped ();
3270 hook_stop_stub (void *cmd
)
3272 execute_user_command ((struct cmd_list_element
*) cmd
, 0);
3277 signal_stop_state (int signo
)
3279 return signal_stop
[signo
];
3283 signal_print_state (int signo
)
3285 return signal_print
[signo
];
3289 signal_pass_state (int signo
)
3291 return signal_program
[signo
];
3295 sig_print_header (void)
3298 Signal Stop\tPrint\tPass to program\tDescription\n");
3302 sig_print_info (enum target_signal oursig
)
3304 char *name
= target_signal_to_name (oursig
);
3305 int name_padding
= 13 - strlen (name
);
3307 if (name_padding
<= 0)
3310 printf_filtered ("%s", name
);
3311 printf_filtered ("%*.*s ", name_padding
, name_padding
,
3313 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3314 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3315 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3316 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3319 /* Specify how various signals in the inferior should be handled. */
3322 handle_command (char *args
, int from_tty
)
3325 int digits
, wordlen
;
3326 int sigfirst
, signum
, siglast
;
3327 enum target_signal oursig
;
3330 unsigned char *sigs
;
3331 struct cleanup
*old_chain
;
3335 error_no_arg ("signal to handle");
3338 /* Allocate and zero an array of flags for which signals to handle. */
3340 nsigs
= (int) TARGET_SIGNAL_LAST
;
3341 sigs
= (unsigned char *) alloca (nsigs
);
3342 memset (sigs
, 0, nsigs
);
3344 /* Break the command line up into args. */
3346 argv
= buildargv (args
);
3351 old_chain
= make_cleanup_freeargv (argv
);
3353 /* Walk through the args, looking for signal oursigs, signal names, and
3354 actions. Signal numbers and signal names may be interspersed with
3355 actions, with the actions being performed for all signals cumulatively
3356 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3358 while (*argv
!= NULL
)
3360 wordlen
= strlen (*argv
);
3361 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3365 sigfirst
= siglast
= -1;
3367 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3369 /* Apply action to all signals except those used by the
3370 debugger. Silently skip those. */
3373 siglast
= nsigs
- 1;
3375 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3377 SET_SIGS (nsigs
, sigs
, signal_stop
);
3378 SET_SIGS (nsigs
, sigs
, signal_print
);
3380 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3382 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3384 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3386 SET_SIGS (nsigs
, sigs
, signal_print
);
3388 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3390 SET_SIGS (nsigs
, sigs
, signal_program
);
3392 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3394 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3396 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3398 SET_SIGS (nsigs
, sigs
, signal_program
);
3400 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3402 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3403 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3405 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3407 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3409 else if (digits
> 0)
3411 /* It is numeric. The numeric signal refers to our own
3412 internal signal numbering from target.h, not to host/target
3413 signal number. This is a feature; users really should be
3414 using symbolic names anyway, and the common ones like
3415 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3417 sigfirst
= siglast
= (int)
3418 target_signal_from_command (atoi (*argv
));
3419 if ((*argv
)[digits
] == '-')
3422 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3424 if (sigfirst
> siglast
)
3426 /* Bet he didn't figure we'd think of this case... */
3434 oursig
= target_signal_from_name (*argv
);
3435 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3437 sigfirst
= siglast
= (int) oursig
;
3441 /* Not a number and not a recognized flag word => complain. */
3442 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3446 /* If any signal numbers or symbol names were found, set flags for
3447 which signals to apply actions to. */
3449 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3451 switch ((enum target_signal
) signum
)
3453 case TARGET_SIGNAL_TRAP
:
3454 case TARGET_SIGNAL_INT
:
3455 if (!allsigs
&& !sigs
[signum
])
3457 if (query ("%s is used by the debugger.\n\
3458 Are you sure you want to change it? ",
3459 target_signal_to_name
3460 ((enum target_signal
) signum
)))
3466 printf_unfiltered ("Not confirmed, unchanged.\n");
3467 gdb_flush (gdb_stdout
);
3471 case TARGET_SIGNAL_0
:
3472 case TARGET_SIGNAL_DEFAULT
:
3473 case TARGET_SIGNAL_UNKNOWN
:
3474 /* Make sure that "all" doesn't print these. */
3485 target_notice_signals (inferior_pid
);
3489 /* Show the results. */
3490 sig_print_header ();
3491 for (signum
= 0; signum
< nsigs
; signum
++)
3495 sig_print_info (signum
);
3500 do_cleanups (old_chain
);
3504 xdb_handle_command (char *args
, int from_tty
)
3507 struct cleanup
*old_chain
;
3509 /* Break the command line up into args. */
3511 argv
= buildargv (args
);
3516 old_chain
= make_cleanup_freeargv (argv
);
3517 if (argv
[1] != (char *) NULL
)
3522 bufLen
= strlen (argv
[0]) + 20;
3523 argBuf
= (char *) xmalloc (bufLen
);
3527 enum target_signal oursig
;
3529 oursig
= target_signal_from_name (argv
[0]);
3530 memset (argBuf
, 0, bufLen
);
3531 if (strcmp (argv
[1], "Q") == 0)
3532 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3535 if (strcmp (argv
[1], "s") == 0)
3537 if (!signal_stop
[oursig
])
3538 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3540 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3542 else if (strcmp (argv
[1], "i") == 0)
3544 if (!signal_program
[oursig
])
3545 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3547 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3549 else if (strcmp (argv
[1], "r") == 0)
3551 if (!signal_print
[oursig
])
3552 sprintf (argBuf
, "%s %s", argv
[0], "print");
3554 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3560 handle_command (argBuf
, from_tty
);
3562 printf_filtered ("Invalid signal handling flag.\n");
3567 do_cleanups (old_chain
);
3570 /* Print current contents of the tables set by the handle command.
3571 It is possible we should just be printing signals actually used
3572 by the current target (but for things to work right when switching
3573 targets, all signals should be in the signal tables). */
3576 signals_info (char *signum_exp
, int from_tty
)
3578 enum target_signal oursig
;
3579 sig_print_header ();
3583 /* First see if this is a symbol name. */
3584 oursig
= target_signal_from_name (signum_exp
);
3585 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3587 /* No, try numeric. */
3589 target_signal_from_command (parse_and_eval_address (signum_exp
));
3591 sig_print_info (oursig
);
3595 printf_filtered ("\n");
3596 /* These ugly casts brought to you by the native VAX compiler. */
3597 for (oursig
= TARGET_SIGNAL_FIRST
;
3598 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3599 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3603 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3604 && oursig
!= TARGET_SIGNAL_DEFAULT
3605 && oursig
!= TARGET_SIGNAL_0
)
3606 sig_print_info (oursig
);
3609 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3612 struct inferior_status
3614 enum target_signal stop_signal
;
3618 int stop_stack_dummy
;
3619 int stopped_by_random_signal
;
3621 CORE_ADDR step_range_start
;
3622 CORE_ADDR step_range_end
;
3623 CORE_ADDR step_frame_address
;
3624 int step_over_calls
;
3625 CORE_ADDR step_resume_break_address
;
3626 int stop_after_trap
;
3627 int stop_soon_quietly
;
3628 CORE_ADDR selected_frame_address
;
3629 char *stop_registers
;
3631 /* These are here because if call_function_by_hand has written some
3632 registers and then decides to call error(), we better not have changed
3637 int breakpoint_proceeded
;
3638 int restore_stack_info
;
3639 int proceed_to_finish
;
3642 static struct inferior_status
*
3643 xmalloc_inferior_status (void)
3645 struct inferior_status
*inf_status
;
3646 inf_status
= xmalloc (sizeof (struct inferior_status
));
3647 inf_status
->stop_registers
= xmalloc (REGISTER_BYTES
);
3648 inf_status
->registers
= xmalloc (REGISTER_BYTES
);
3653 free_inferior_status (struct inferior_status
*inf_status
)
3655 free (inf_status
->registers
);
3656 free (inf_status
->stop_registers
);
3661 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3664 int size
= REGISTER_RAW_SIZE (regno
);
3665 void *buf
= alloca (size
);
3666 store_signed_integer (buf
, size
, val
);
3667 memcpy (&inf_status
->registers
[REGISTER_BYTE (regno
)], buf
, size
);
3670 /* Save all of the information associated with the inferior<==>gdb
3671 connection. INF_STATUS is a pointer to a "struct inferior_status"
3672 (defined in inferior.h). */
3674 struct inferior_status
*
3675 save_inferior_status (int restore_stack_info
)
3677 struct inferior_status
*inf_status
= xmalloc_inferior_status ();
3679 inf_status
->stop_signal
= stop_signal
;
3680 inf_status
->stop_pc
= stop_pc
;
3681 inf_status
->stop_step
= stop_step
;
3682 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3683 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3684 inf_status
->trap_expected
= trap_expected
;
3685 inf_status
->step_range_start
= step_range_start
;
3686 inf_status
->step_range_end
= step_range_end
;
3687 inf_status
->step_frame_address
= step_frame_address
;
3688 inf_status
->step_over_calls
= step_over_calls
;
3689 inf_status
->stop_after_trap
= stop_after_trap
;
3690 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3691 /* Save original bpstat chain here; replace it with copy of chain.
3692 If caller's caller is walking the chain, they'll be happier if we
3693 hand them back the original chain when restore_inferior_status is
3695 inf_status
->stop_bpstat
= stop_bpstat
;
3696 stop_bpstat
= bpstat_copy (stop_bpstat
);
3697 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3698 inf_status
->restore_stack_info
= restore_stack_info
;
3699 inf_status
->proceed_to_finish
= proceed_to_finish
;
3701 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
3703 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3705 record_selected_frame (&(inf_status
->selected_frame_address
),
3706 &(inf_status
->selected_level
));
3710 struct restore_selected_frame_args
3712 CORE_ADDR frame_address
;
3717 restore_selected_frame (void *args
)
3719 struct restore_selected_frame_args
*fr
=
3720 (struct restore_selected_frame_args
*) args
;
3721 struct frame_info
*frame
;
3722 int level
= fr
->level
;
3724 frame
= find_relative_frame (get_current_frame (), &level
);
3726 /* If inf_status->selected_frame_address is NULL, there was no
3727 previously selected frame. */
3728 if (frame
== NULL
||
3729 /* FRAME_FP (frame) != fr->frame_address || */
3730 /* elz: deleted this check as a quick fix to the problem that
3731 for function called by hand gdb creates no internal frame
3732 structure and the real stack and gdb's idea of stack are
3733 different if nested calls by hands are made.
3735 mvs: this worries me. */
3738 warning ("Unable to restore previously selected frame.\n");
3742 select_frame (frame
, fr
->level
);
3748 restore_inferior_status (struct inferior_status
*inf_status
)
3750 stop_signal
= inf_status
->stop_signal
;
3751 stop_pc
= inf_status
->stop_pc
;
3752 stop_step
= inf_status
->stop_step
;
3753 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3754 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3755 trap_expected
= inf_status
->trap_expected
;
3756 step_range_start
= inf_status
->step_range_start
;
3757 step_range_end
= inf_status
->step_range_end
;
3758 step_frame_address
= inf_status
->step_frame_address
;
3759 step_over_calls
= inf_status
->step_over_calls
;
3760 stop_after_trap
= inf_status
->stop_after_trap
;
3761 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
3762 bpstat_clear (&stop_bpstat
);
3763 stop_bpstat
= inf_status
->stop_bpstat
;
3764 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3765 proceed_to_finish
= inf_status
->proceed_to_finish
;
3767 /* FIXME: Is the restore of stop_registers always needed */
3768 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
3770 /* The inferior can be gone if the user types "print exit(0)"
3771 (and perhaps other times). */
3772 if (target_has_execution
)
3773 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3775 /* FIXME: If we are being called after stopping in a function which
3776 is called from gdb, we should not be trying to restore the
3777 selected frame; it just prints a spurious error message (The
3778 message is useful, however, in detecting bugs in gdb (like if gdb
3779 clobbers the stack)). In fact, should we be restoring the
3780 inferior status at all in that case? . */
3782 if (target_has_stack
&& inf_status
->restore_stack_info
)
3784 struct restore_selected_frame_args fr
;
3785 fr
.level
= inf_status
->selected_level
;
3786 fr
.frame_address
= inf_status
->selected_frame_address
;
3787 /* The point of catch_errors is that if the stack is clobbered,
3788 walking the stack might encounter a garbage pointer and error()
3789 trying to dereference it. */
3790 if (catch_errors (restore_selected_frame
, &fr
,
3791 "Unable to restore previously selected frame:\n",
3792 RETURN_MASK_ERROR
) == 0)
3793 /* Error in restoring the selected frame. Select the innermost
3797 select_frame (get_current_frame (), 0);
3801 free_inferior_status (inf_status
);
3805 discard_inferior_status (struct inferior_status
*inf_status
)
3807 /* See save_inferior_status for info on stop_bpstat. */
3808 bpstat_clear (&inf_status
->stop_bpstat
);
3809 free_inferior_status (inf_status
);
3813 set_follow_fork_mode_command (char *arg
, int from_tty
,
3814 struct cmd_list_element
*c
)
3816 if (!STREQ (arg
, "parent") &&
3817 !STREQ (arg
, "child") &&
3818 !STREQ (arg
, "both") &&
3819 !STREQ (arg
, "ask"))
3820 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
3822 if (follow_fork_mode_string
!= NULL
)
3823 free (follow_fork_mode_string
);
3824 follow_fork_mode_string
= savestring (arg
, strlen (arg
));
3830 stop_registers
= xmalloc (REGISTER_BYTES
);
3834 _initialize_infrun (void)
3837 register int numsigs
;
3838 struct cmd_list_element
*c
;
3842 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
3843 register_gdbarch_swap (NULL
, 0, build_infrun
);
3845 add_info ("signals", signals_info
,
3846 "What debugger does when program gets various signals.\n\
3847 Specify a signal as argument to print info on that signal only.");
3848 add_info_alias ("handle", "signals", 0);
3850 add_com ("handle", class_run
, handle_command
,
3851 concat ("Specify how to handle a signal.\n\
3852 Args are signals and actions to apply to those signals.\n\
3853 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3854 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3855 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3856 The special arg \"all\" is recognized to mean all signals except those\n\
3857 used by the debugger, typically SIGTRAP and SIGINT.\n",
3858 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3859 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3860 Stop means reenter debugger if this signal happens (implies print).\n\
3861 Print means print a message if this signal happens.\n\
3862 Pass means let program see this signal; otherwise program doesn't know.\n\
3863 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3864 Pass and Stop may be combined.", NULL
));
3867 add_com ("lz", class_info
, signals_info
,
3868 "What debugger does when program gets various signals.\n\
3869 Specify a signal as argument to print info on that signal only.");
3870 add_com ("z", class_run
, xdb_handle_command
,
3871 concat ("Specify how to handle a signal.\n\
3872 Args are signals and actions to apply to those signals.\n\
3873 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3874 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3875 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3876 The special arg \"all\" is recognized to mean all signals except those\n\
3877 used by the debugger, typically SIGTRAP and SIGINT.\n",
3878 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3879 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3880 nopass), \"Q\" (noprint)\n\
3881 Stop means reenter debugger if this signal happens (implies print).\n\
3882 Print means print a message if this signal happens.\n\
3883 Pass means let program see this signal; otherwise program doesn't know.\n\
3884 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3885 Pass and Stop may be combined.", NULL
));
3889 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
3890 "There is no `stop' command, but you can set a hook on `stop'.\n\
3891 This allows you to set a list of commands to be run each time execution\n\
3892 of the program stops.", &cmdlist
);
3894 numsigs
= (int) TARGET_SIGNAL_LAST
;
3895 signal_stop
= (unsigned char *)
3896 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
3897 signal_print
= (unsigned char *)
3898 xmalloc (sizeof (signal_print
[0]) * numsigs
);
3899 signal_program
= (unsigned char *)
3900 xmalloc (sizeof (signal_program
[0]) * numsigs
);
3901 for (i
= 0; i
< numsigs
; i
++)
3904 signal_print
[i
] = 1;
3905 signal_program
[i
] = 1;
3908 /* Signals caused by debugger's own actions
3909 should not be given to the program afterwards. */
3910 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
3911 signal_program
[TARGET_SIGNAL_INT
] = 0;
3913 /* Signals that are not errors should not normally enter the debugger. */
3914 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
3915 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
3916 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
3917 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
3918 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
3919 signal_print
[TARGET_SIGNAL_PROF
] = 0;
3920 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
3921 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
3922 signal_stop
[TARGET_SIGNAL_IO
] = 0;
3923 signal_print
[TARGET_SIGNAL_IO
] = 0;
3924 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
3925 signal_print
[TARGET_SIGNAL_POLL
] = 0;
3926 signal_stop
[TARGET_SIGNAL_URG
] = 0;
3927 signal_print
[TARGET_SIGNAL_URG
] = 0;
3928 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
3929 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
3931 /* These signals are used internally by user-level thread
3932 implementations. (See signal(5) on Solaris.) Like the above
3933 signals, a healthy program receives and handles them as part of
3934 its normal operation. */
3935 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
3936 signal_print
[TARGET_SIGNAL_LWP
] = 0;
3937 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
3938 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
3939 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
3940 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
3944 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
3945 (char *) &stop_on_solib_events
,
3946 "Set stopping for shared library events.\n\
3947 If nonzero, gdb will give control to the user when the dynamic linker\n\
3948 notifies gdb of shared library events. The most common event of interest\n\
3949 to the user would be loading/unloading of a new library.\n",
3954 c
= add_set_enum_cmd ("follow-fork-mode",
3956 follow_fork_mode_kind_names
,
3957 (char *) &follow_fork_mode_string
,
3958 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
3959 kernel problem. It's also not terribly useful without a GUI to
3960 help the user drive two debuggers. So for now, I'm disabling
3961 the "both" option. */
3962 /* "Set debugger response to a program call of fork \
3964 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3965 parent - the original process is debugged after a fork\n\
3966 child - the new process is debugged after a fork\n\
3967 both - both the parent and child are debugged after a fork\n\
3968 ask - the debugger will ask for one of the above choices\n\
3969 For \"both\", another copy of the debugger will be started to follow\n\
3970 the new child process. The original debugger will continue to follow\n\
3971 the original parent process. To distinguish their prompts, the\n\
3972 debugger copy's prompt will be changed.\n\
3973 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3974 By default, the debugger will follow the parent process.",
3976 "Set debugger response to a program call of fork \
3978 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3979 parent - the original process is debugged after a fork\n\
3980 child - the new process is debugged after a fork\n\
3981 ask - the debugger will ask for one of the above choices\n\
3982 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3983 By default, the debugger will follow the parent process.",
3985 /* c->function.sfunc = ; */
3986 add_show_from_set (c
, &showlist
);
3988 set_follow_fork_mode_command ("parent", 0, NULL
);
3990 c
= add_set_enum_cmd ("scheduler-locking", class_run
,
3991 scheduler_enums
, /* array of string names */
3992 (char *) &scheduler_mode
, /* current mode */
3993 "Set mode for locking scheduler during execution.\n\
3994 off == no locking (threads may preempt at any time)\n\
3995 on == full locking (no thread except the current thread may run)\n\
3996 step == scheduler locked during every single-step operation.\n\
3997 In this mode, no other thread may run during a step command.\n\
3998 Other threads may run while stepping over a function call ('next').",
4001 c
->function
.sfunc
= set_schedlock_func
; /* traps on target vector */
4002 add_show_from_set (c
, &showlist
);