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, Boston, MA 02111-1307, USA. */
21 #include "gdb_string.h"
26 #include "breakpoint.h"
31 #include "gdbthread.h"
33 #include "symfile.h" /* for overlay functions */
38 /* Prototypes for local functions */
40 static void signals_info
PARAMS ((char *, int));
42 static void handle_command
PARAMS ((char *, int));
44 static void sig_print_info
PARAMS ((enum target_signal
));
46 static void sig_print_header
PARAMS ((void));
48 static void resume_cleanups
PARAMS ((int));
50 static int hook_stop_stub
PARAMS ((PTR
));
52 static void delete_breakpoint_current_contents
PARAMS ((PTR
));
54 static void set_follow_fork_mode_command
PARAMS ((char *arg
, int from_tty
, struct cmd_list_element
*c
));
56 int inferior_ignoring_startup_exec_events
= 0;
57 int inferior_ignoring_leading_exec_events
= 0;
59 /* wait_for_inferior and normal_stop use this to notify the user
60 when the inferior stopped in a different thread than it had been
62 static int switched_from_inferior_pid
;
64 /* This will be true for configurations that may actually report an
65 inferior pid different from the original. At present this is only
66 true for HP-UX native. */
68 #ifndef MAY_SWITCH_FROM_INFERIOR_PID
69 #define MAY_SWITCH_FROM_INFERIOR_PID (0)
72 static int may_switch_from_inferior_pid
= MAY_SWITCH_FROM_INFERIOR_PID
;
74 /* This is true for configurations that may follow through execl() and
75 similar functions. At present this is only true for HP-UX native. */
77 #ifndef MAY_FOLLOW_EXEC
78 #define MAY_FOLLOW_EXEC (0)
81 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
83 /* resume and wait_for_inferior use this to ensure that when
84 stepping over a hit breakpoint in a threaded application
85 only the thread that hit the breakpoint is stepped and the
86 other threads don't continue. This prevents having another
87 thread run past the breakpoint while it is temporarily
90 This is not thread-specific, so it isn't saved as part of
93 Versions of gdb which don't use the "step == this thread steps
94 and others continue" model but instead use the "step == this
95 thread steps and others wait" shouldn't do this. */
96 static int thread_step_needed
= 0;
98 /* This is true if thread_step_needed should actually be used. At
99 present this is only true for HP-UX native. */
101 #ifndef USE_THREAD_STEP_NEEDED
102 #define USE_THREAD_STEP_NEEDED (0)
105 static int use_thread_step_needed
= USE_THREAD_STEP_NEEDED
;
107 void _initialize_infrun
PARAMS ((void));
109 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
110 program. It needs to examine the jmp_buf argument and extract the PC
111 from it. The return value is non-zero on success, zero otherwise. */
113 #ifndef GET_LONGJMP_TARGET
114 #define GET_LONGJMP_TARGET(PC_ADDR) 0
118 /* Some machines have trampoline code that sits between function callers
119 and the actual functions themselves. If this machine doesn't have
120 such things, disable their processing. */
122 #ifndef SKIP_TRAMPOLINE_CODE
123 #define SKIP_TRAMPOLINE_CODE(pc) 0
126 /* Dynamic function trampolines are similar to solib trampolines in that they
127 are between the caller and the callee. The difference is that when you
128 enter a dynamic trampoline, you can't determine the callee's address. Some
129 (usually complex) code needs to run in the dynamic trampoline to figure out
130 the callee's address. This macro is usually called twice. First, when we
131 enter the trampoline (looks like a normal function call at that point). It
132 should return the PC of a point within the trampoline where the callee's
133 address is known. Second, when we hit the breakpoint, this routine returns
134 the callee's address. At that point, things proceed as per a step resume
137 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
138 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
141 /* On SVR4 based systems, determining the callee's address is exceedingly
142 difficult and depends on the implementation of the run time loader.
143 If we are stepping at the source level, we single step until we exit
144 the run time loader code and reach the callee's address. */
146 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
147 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
150 /* For SVR4 shared libraries, each call goes through a small piece of
151 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
152 to nonzero if we are current stopped in one of these. */
154 #ifndef IN_SOLIB_CALL_TRAMPOLINE
155 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
158 /* In some shared library schemes, the return path from a shared library
159 call may need to go through a trampoline too. */
161 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
162 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
165 /* This function returns TRUE if pc is the address of an instruction
166 that lies within the dynamic linker (such as the event hook, or the
169 This function must be used only when a dynamic linker event has
170 been caught, and the inferior is being stepped out of the hook, or
171 undefined results are guaranteed. */
173 #ifndef SOLIB_IN_DYNAMIC_LINKER
174 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
177 /* On MIPS16, a function that returns a floating point value may call
178 a library helper function to copy the return value to a floating point
179 register. The IGNORE_HELPER_CALL macro returns non-zero if we
180 should ignore (i.e. step over) this function call. */
181 #ifndef IGNORE_HELPER_CALL
182 #define IGNORE_HELPER_CALL(pc) 0
185 /* On some systems, the PC may be left pointing at an instruction that won't
186 actually be executed. This is usually indicated by a bit in the PSW. If
187 we find ourselves in such a state, then we step the target beyond the
188 nullified instruction before returning control to the user so as to avoid
191 #ifndef INSTRUCTION_NULLIFIED
192 #define INSTRUCTION_NULLIFIED 0
195 /* Convert the #defines into values. This is temporary until wfi control
196 flow is completely sorted out. */
198 #ifndef HAVE_STEPPABLE_WATCHPOINT
199 #define HAVE_STEPPABLE_WATCHPOINT 0
201 #undef HAVE_STEPPABLE_WATCHPOINT
202 #define HAVE_STEPPABLE_WATCHPOINT 1
205 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
206 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
208 #undef HAVE_NONSTEPPABLE_WATCHPOINT
209 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
212 #ifndef HAVE_CONTINUABLE_WATCHPOINT
213 #define HAVE_CONTINUABLE_WATCHPOINT 0
215 #undef HAVE_CONTINUABLE_WATCHPOINT
216 #define HAVE_CONTINUABLE_WATCHPOINT 1
219 /* Tables of how to react to signals; the user sets them. */
221 static unsigned char *signal_stop
;
222 static unsigned char *signal_print
;
223 static unsigned char *signal_program
;
225 #define SET_SIGS(nsigs,sigs,flags) \
227 int signum = (nsigs); \
228 while (signum-- > 0) \
229 if ((sigs)[signum]) \
230 (flags)[signum] = 1; \
233 #define UNSET_SIGS(nsigs,sigs,flags) \
235 int signum = (nsigs); \
236 while (signum-- > 0) \
237 if ((sigs)[signum]) \
238 (flags)[signum] = 0; \
242 /* Command list pointer for the "stop" placeholder. */
244 static struct cmd_list_element
*stop_command
;
246 /* Nonzero if breakpoints are now inserted in the inferior. */
248 static int breakpoints_inserted
;
250 /* Function inferior was in as of last step command. */
252 static struct symbol
*step_start_function
;
254 /* Nonzero if we are expecting a trace trap and should proceed from it. */
256 static int trap_expected
;
259 /* Nonzero if we want to give control to the user when we're notified
260 of shared library events by the dynamic linker. */
261 static int stop_on_solib_events
;
265 /* Nonzero if the next time we try to continue the inferior, it will
266 step one instruction and generate a spurious trace trap.
267 This is used to compensate for a bug in HP-UX. */
269 static int trap_expected_after_continue
;
272 /* Nonzero means expecting a trace trap
273 and should stop the inferior and return silently when it happens. */
277 /* Nonzero means expecting a trap and caller will handle it themselves.
278 It is used after attach, due to attaching to a process;
279 when running in the shell before the child program has been exec'd;
280 and when running some kinds of remote stuff (FIXME?). */
282 int stop_soon_quietly
;
284 /* Nonzero if proceed is being used for a "finish" command or a similar
285 situation when stop_registers should be saved. */
287 int proceed_to_finish
;
289 /* Save register contents here when about to pop a stack dummy frame,
290 if-and-only-if proceed_to_finish is set.
291 Thus this contains the return value from the called function (assuming
292 values are returned in a register). */
294 char *stop_registers
;
296 /* Nonzero if program stopped due to error trying to insert breakpoints. */
298 static int breakpoints_failed
;
300 /* Nonzero after stop if current stack frame should be printed. */
302 static int stop_print_frame
;
304 static struct breakpoint
*step_resume_breakpoint
= NULL
;
305 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
307 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
308 interactions with an inferior that is running a kernel function
309 (aka, a system call or "syscall"). wait_for_inferior therefore
310 may have a need to know when the inferior is in a syscall. This
311 is a count of the number of inferior threads which are known to
312 currently be running in a syscall. */
313 static int number_of_threads_in_syscalls
;
315 /* This is used to remember when a fork, vfork or exec event
316 was caught by a catchpoint, and thus the event is to be
317 followed at the next resume of the inferior, and not
321 enum target_waitkind kind
;
331 char *execd_pathname
;
335 /* Some platforms don't allow us to do anything meaningful with a
336 vforked child until it has exec'd. Vforked processes on such
337 platforms can only be followed after they've exec'd.
339 When this is set to 0, a vfork can be immediately followed,
340 and an exec can be followed merely as an exec. When this is
341 set to 1, a vfork event has been seen, but cannot be followed
342 until the exec is seen.
344 (In the latter case, inferior_pid is still the parent of the
345 vfork, and pending_follow.fork_event.child_pid is the child. The
346 appropriate process is followed, according to the setting of
347 follow-fork-mode.) */
348 static int follow_vfork_when_exec
;
350 static char *follow_fork_mode_kind_names
[] =
352 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
353 kernel problem. It's also not terribly useful without a GUI to
354 help the user drive two debuggers. So for now, I'm disabling
356 "parent", "child", "both", "ask" };
358 "parent", "child", "ask"};
360 static char *follow_fork_mode_string
= NULL
;
364 follow_inferior_fork (parent_pid
, child_pid
, has_forked
, has_vforked
)
370 int followed_parent
= 0;
371 int followed_child
= 0;
374 /* Which process did the user want us to follow? */
376 savestring (follow_fork_mode_string
, strlen (follow_fork_mode_string
));
378 /* Or, did the user not know, and want us to ask? */
379 if (STREQ (follow_fork_mode_string
, "ask"))
381 char requested_mode
[100];
384 error ("\"ask\" mode NYI");
385 follow_mode
= savestring (requested_mode
, strlen (requested_mode
));
388 /* If we're to be following the parent, then detach from child_pid.
389 We're already following the parent, so need do nothing explicit
391 if (STREQ (follow_mode
, "parent"))
395 /* We're already attached to the parent, by default. */
397 /* Before detaching from the child, remove all breakpoints from
398 it. (This won't actually modify the breakpoint list, but will
399 physically remove the breakpoints from the child.) */
400 if (!has_vforked
|| !follow_vfork_when_exec
)
402 detach_breakpoints (child_pid
);
403 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
404 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
408 /* Detach from the child. */
411 target_require_detach (child_pid
, "", 1);
414 /* If we're to be following the child, then attach to it, detach
415 from inferior_pid, and set inferior_pid to child_pid. */
416 else if (STREQ (follow_mode
, "child"))
418 char child_pid_spelling
[100]; /* Arbitrary length. */
422 /* Before detaching from the parent, detach all breakpoints from
423 the child. But only if we're forking, or if we follow vforks
424 as soon as they happen. (If we're following vforks only when
425 the child has exec'd, then it's very wrong to try to write
426 back the "shadow contents" of inserted breakpoints now -- they
427 belong to the child's pre-exec'd a.out.) */
428 if (!has_vforked
|| !follow_vfork_when_exec
)
430 detach_breakpoints (child_pid
);
433 /* Before detaching from the parent, remove all breakpoints from it. */
434 remove_breakpoints ();
436 /* Also reset the solib inferior hook from the parent. */
437 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
438 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid
);
441 /* Detach from the parent. */
443 target_detach (NULL
, 1);
445 /* Attach to the child. */
446 inferior_pid
= child_pid
;
447 sprintf (child_pid_spelling
, "%d", child_pid
);
450 target_require_attach (child_pid_spelling
, 1);
452 /* Was there a step_resume breakpoint? (There was if the user
453 did a "next" at the fork() call.) If so, explicitly reset its
456 step_resumes are a form of bp that are made to be per-thread.
457 Since we created the step_resume bp when the parent process
458 was being debugged, and now are switching to the child process,
459 from the breakpoint package's viewpoint, that's a switch of
460 "threads". We must update the bp's notion of which thread
461 it is for, or it'll be ignored when it triggers... */
462 if (step_resume_breakpoint
&&
463 (!has_vforked
|| !follow_vfork_when_exec
))
464 breakpoint_re_set_thread (step_resume_breakpoint
);
466 /* Reinsert all breakpoints in the child. (The user may've set
467 breakpoints after catching the fork, in which case those
468 actually didn't get set in the child, but only in the parent.) */
469 if (!has_vforked
|| !follow_vfork_when_exec
)
471 breakpoint_re_set ();
472 insert_breakpoints ();
476 /* If we're to be following both parent and child, then fork ourselves,
477 and attach the debugger clone to the child. */
478 else if (STREQ (follow_mode
, "both"))
480 char pid_suffix
[100]; /* Arbitrary length. */
482 /* Clone ourselves to follow the child. This is the end of our
483 involvement with child_pid; our clone will take it from here... */
485 target_clone_and_follow_inferior (child_pid
, &followed_child
);
486 followed_parent
= !followed_child
;
488 /* We continue to follow the parent. To help distinguish the two
489 debuggers, though, both we and our clone will reset our prompts. */
490 sprintf (pid_suffix
, "[%d] ", inferior_pid
);
491 set_prompt (strcat (get_prompt (), pid_suffix
));
494 /* The parent and child of a vfork share the same address space.
495 Also, on some targets the order in which vfork and exec events
496 are received for parent in child requires some delicate handling
499 For instance, on ptrace-based HPUX we receive the child's vfork
500 event first, at which time the parent has been suspended by the
501 OS and is essentially untouchable until the child's exit or second
502 exec event arrives. At that time, the parent's vfork event is
503 delivered to us, and that's when we see and decide how to follow
504 the vfork. But to get to that point, we must continue the child
505 until it execs or exits. To do that smoothly, all breakpoints
506 must be removed from the child, in case there are any set between
507 the vfork() and exec() calls. But removing them from the child
508 also removes them from the parent, due to the shared-address-space
509 nature of a vfork'd parent and child. On HPUX, therefore, we must
510 take care to restore the bp's to the parent before we continue it.
511 Else, it's likely that we may not stop in the expected place. (The
512 worst scenario is when the user tries to step over a vfork() call;
513 the step-resume bp must be restored for the step to properly stop
514 in the parent after the call completes!)
516 Sequence of events, as reported to gdb from HPUX:
518 Parent Child Action for gdb to take
519 -------------------------------------------------------
520 1 VFORK Continue child
526 target_post_follow_vfork (parent_pid
,
532 pending_follow
.fork_event
.saw_parent_fork
= 0;
533 pending_follow
.fork_event
.saw_child_fork
= 0;
539 follow_fork (parent_pid
, child_pid
)
543 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
547 /* Forward declaration. */
548 static void follow_exec
PARAMS ((int, char *));
551 follow_vfork (parent_pid
, child_pid
)
555 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
557 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
558 if (pending_follow
.fork_event
.saw_child_exec
&& (inferior_pid
== child_pid
))
560 pending_follow
.fork_event
.saw_child_exec
= 0;
561 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
562 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
563 free (pending_follow
.execd_pathname
);
568 follow_exec (pid
, execd_pathname
)
570 char *execd_pathname
;
573 struct target_ops
*tgt
;
575 if (!may_follow_exec
)
578 /* Did this exec() follow a vfork()? If so, we must follow the
579 vfork now too. Do it before following the exec. */
580 if (follow_vfork_when_exec
&&
581 (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
))
583 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
584 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
585 follow_vfork_when_exec
= 0;
586 saved_pid
= inferior_pid
;
588 /* Did we follow the parent? If so, we're done. If we followed
589 the child then we must also follow its exec(). */
590 if (inferior_pid
== pending_follow
.fork_event
.parent_pid
)
594 /* This is an exec event that we actually wish to pay attention to.
595 Refresh our symbol table to the newly exec'd program, remove any
598 If there are breakpoints, they aren't really inserted now,
599 since the exec() transformed our inferior into a fresh set
602 We want to preserve symbolic breakpoints on the list, since
603 we have hopes that they can be reset after the new a.out's
604 symbol table is read.
606 However, any "raw" breakpoints must be removed from the list
607 (e.g., the solib bp's), since their address is probably invalid
610 And, we DON'T want to call delete_breakpoints() here, since
611 that may write the bp's "shadow contents" (the instruction
612 value that was overwritten witha TRAP instruction). Since
613 we now have a new a.out, those shadow contents aren't valid. */
614 update_breakpoints_after_exec ();
616 /* If there was one, it's gone now. We cannot truly step-to-next
617 statement through an exec(). */
618 step_resume_breakpoint
= NULL
;
619 step_range_start
= 0;
622 /* If there was one, it's gone now. */
623 through_sigtramp_breakpoint
= NULL
;
625 /* What is this a.out's name? */
626 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
628 /* We've followed the inferior through an exec. Therefore, the
629 inferior has essentially been killed & reborn. */
631 /* First collect the run target in effect. */
632 tgt
= find_run_target ();
633 /* If we can't find one, things are in a very strange state... */
635 error ("Could find run target to save before following exec");
637 gdb_flush (gdb_stdout
);
638 target_mourn_inferior ();
639 inferior_pid
= saved_pid
; /* Because mourn_inferior resets inferior_pid. */
642 /* That a.out is now the one to use. */
643 exec_file_attach (execd_pathname
, 0);
645 /* And also is where symbols can be found. */
646 symbol_file_command (execd_pathname
, 0);
648 /* Reset the shared library package. This ensures that we get
649 a shlib event when the child reaches "_start", at which point
650 the dld will have had a chance to initialize the child. */
651 #if defined(SOLIB_RESTART)
654 #ifdef SOLIB_CREATE_INFERIOR_HOOK
655 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid
);
658 /* Reinsert all breakpoints. (Those which were symbolic have
659 been reset to the proper address in the new a.out, thanks
660 to symbol_file_command...) */
661 insert_breakpoints ();
663 /* The next resume of this inferior should bring it to the shlib
664 startup breakpoints. (If the user had also set bp's on
665 "main" from the old (parent) process, then they'll auto-
666 matically get reset there in the new process.) */
669 /* Non-zero if we just simulating a single-step. This is needed
670 because we cannot remove the breakpoints in the inferior process
671 until after the `wait' in `wait_for_inferior'. */
672 static int singlestep_breakpoints_inserted_p
= 0;
675 /* Things to clean up if we QUIT out of resume (). */
678 resume_cleanups (arg
)
684 static char schedlock_off
[] = "off";
685 static char schedlock_on
[] = "on";
686 static char schedlock_step
[] = "step";
687 static char *scheduler_mode
= schedlock_off
;
688 static char *scheduler_enums
[] =
689 {schedlock_off
, schedlock_on
, schedlock_step
};
692 set_schedlock_func (args
, from_tty
, c
)
695 struct cmd_list_element
*c
;
697 if (c
->type
== set_cmd
)
698 if (!target_can_lock_scheduler
)
700 scheduler_mode
= schedlock_off
;
701 error ("Target '%s' cannot support this command.",
707 /* Resume the inferior, but allow a QUIT. This is useful if the user
708 wants to interrupt some lengthy single-stepping operation
709 (for child processes, the SIGINT goes to the inferior, and so
710 we get a SIGINT random_signal, but for remote debugging and perhaps
711 other targets, that's not true).
713 STEP nonzero if we should step (zero to continue instead).
714 SIG is the signal to give the inferior (zero for none). */
718 enum target_signal sig
;
720 int should_resume
= 1;
721 struct cleanup
*old_cleanups
= make_cleanup ((make_cleanup_func
)
725 #ifdef CANNOT_STEP_BREAKPOINT
726 /* Most targets can step a breakpoint instruction, thus executing it
727 normally. But if this one cannot, just continue and we will hit
729 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
733 if (SOFTWARE_SINGLE_STEP_P
&& step
)
735 /* Do it the hard way, w/temp breakpoints */
736 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints*/ );
737 /* ...and don't ask hardware to do it. */
739 /* and do not pull these breakpoints until after a `wait' in
740 `wait_for_inferior' */
741 singlestep_breakpoints_inserted_p
= 1;
744 /* Handle any optimized stores to the inferior NOW... */
745 #ifdef DO_DEFERRED_STORES
749 /* If there were any forks/vforks/execs that were caught and are
750 now to be followed, then do so. */
751 switch (pending_follow
.kind
)
753 case (TARGET_WAITKIND_FORKED
):
754 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
755 follow_fork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
758 case (TARGET_WAITKIND_VFORKED
):
760 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
762 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
763 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
765 /* Did we follow the child, but not yet see the child's exec event?
766 If so, then it actually ought to be waiting for us; we respond to
767 parent vfork events. We don't actually want to resume the child
768 in this situation; we want to just get its exec event. */
769 if (!saw_child_exec
&&
770 (inferior_pid
== pending_follow
.fork_event
.child_pid
))
775 case (TARGET_WAITKIND_EXECD
):
776 /* If we saw a vfork event but couldn't follow it until we saw
777 an exec, then now might be the time! */
778 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
779 /* follow_exec is called as soon as the exec event is seen. */
786 /* Install inferior's terminal modes. */
787 target_terminal_inferior ();
791 if (use_thread_step_needed
&& thread_step_needed
)
793 /* We stopped on a BPT instruction;
794 don't continue other threads and
795 just step this thread. */
796 thread_step_needed
= 0;
798 if (!breakpoint_here_p (read_pc ()))
800 /* Breakpoint deleted: ok to do regular resume
801 where all the threads either step or continue. */
802 target_resume (-1, step
, sig
);
808 warning ("Internal error, changing continue to step.");
809 remove_breakpoints ();
810 breakpoints_inserted
= 0;
815 target_resume (inferior_pid
, step
, sig
);
820 /* Vanilla resume. */
822 if ((scheduler_mode
== schedlock_on
) ||
823 (scheduler_mode
== schedlock_step
&& step
!= 0))
824 target_resume (inferior_pid
, step
, sig
);
826 target_resume (-1, step
, sig
);
830 discard_cleanups (old_cleanups
);
834 /* Clear out all variables saying what to do when inferior is continued.
835 First do this, then set the ones you want, then call `proceed'. */
838 clear_proceed_status ()
841 step_range_start
= 0;
843 step_frame_address
= 0;
844 step_over_calls
= -1;
846 stop_soon_quietly
= 0;
847 proceed_to_finish
= 0;
848 breakpoint_proceeded
= 1; /* We're about to proceed... */
850 /* Discard any remaining commands or status from previous stop. */
851 bpstat_clear (&stop_bpstat
);
854 /* Basic routine for continuing the program in various fashions.
856 ADDR is the address to resume at, or -1 for resume where stopped.
857 SIGGNAL is the signal to give it, or 0 for none,
858 or -1 for act according to how it stopped.
859 STEP is nonzero if should trap after one instruction.
860 -1 means return after that and print nothing.
861 You should probably set various step_... variables
862 before calling here, if you are stepping.
864 You should call clear_proceed_status before calling proceed. */
867 proceed (addr
, siggnal
, step
)
869 enum target_signal siggnal
;
875 step_start_function
= find_pc_function (read_pc ());
879 if (addr
== (CORE_ADDR
) - 1)
881 /* If there is a breakpoint at the address we will resume at,
882 step one instruction before inserting breakpoints
883 so that we do not stop right away (and report a second
884 hit at this breakpoint). */
886 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
889 #ifndef STEP_SKIPS_DELAY
890 #define STEP_SKIPS_DELAY(pc) (0)
891 #define STEP_SKIPS_DELAY_P (0)
893 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
894 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
895 is slow (it needs to read memory from the target). */
896 if (STEP_SKIPS_DELAY_P
897 && breakpoint_here_p (read_pc () + 4)
898 && STEP_SKIPS_DELAY (read_pc ()))
905 /* New address; we don't need to single-step a thread
906 over a breakpoint we just hit, 'cause we aren't
907 continuing from there.
909 It's not worth worrying about the case where a user
910 asks for a "jump" at the current PC--if they get the
911 hiccup of re-hiting a hit breakpoint, what else do
913 thread_step_needed
= 0;
916 #ifdef PREPARE_TO_PROCEED
917 /* In a multi-threaded task we may select another thread
918 and then continue or step.
920 But if the old thread was stopped at a breakpoint, it
921 will immediately cause another breakpoint stop without
922 any execution (i.e. it will report a breakpoint hit
923 incorrectly). So we must step over it first.
925 PREPARE_TO_PROCEED checks the current thread against the thread
926 that reported the most recent event. If a step-over is required
927 it returns TRUE and sets the current thread to the old thread. */
928 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
931 thread_step_needed
= 1;
934 #endif /* PREPARE_TO_PROCEED */
937 if (trap_expected_after_continue
)
939 /* If (step == 0), a trap will be automatically generated after
940 the first instruction is executed. Force step one
941 instruction to clear this condition. This should not occur
942 if step is nonzero, but it is harmless in that case. */
944 trap_expected_after_continue
= 0;
946 #endif /* HP_OS_BUG */
949 /* We will get a trace trap after one instruction.
950 Continue it automatically and insert breakpoints then. */
954 int temp
= insert_breakpoints ();
957 print_sys_errmsg ("ptrace", temp
);
958 error ("Cannot insert breakpoints.\n\
959 The same program may be running in another process.");
962 breakpoints_inserted
= 1;
965 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
966 stop_signal
= siggnal
;
967 /* If this signal should not be seen by program,
968 give it zero. Used for debugging signals. */
969 else if (!signal_program
[stop_signal
])
970 stop_signal
= TARGET_SIGNAL_0
;
972 annotate_starting ();
974 /* Make sure that output from GDB appears before output from the
976 gdb_flush (gdb_stdout
);
978 /* Resume inferior. */
979 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
981 /* Wait for it to stop (if not standalone)
982 and in any case decode why it stopped, and act accordingly. */
984 wait_for_inferior ();
988 /* Record the pc and sp of the program the last time it stopped.
989 These are just used internally by wait_for_inferior, but need
990 to be preserved over calls to it and cleared when the inferior
992 static CORE_ADDR prev_pc
;
993 static CORE_ADDR prev_func_start
;
994 static char *prev_func_name
;
997 /* Start remote-debugging of a machine over a serial link. */
1002 init_thread_list ();
1003 init_wait_for_inferior ();
1004 stop_soon_quietly
= 1;
1006 wait_for_inferior ();
1010 /* Initialize static vars when a new inferior begins. */
1013 init_wait_for_inferior ()
1015 /* These are meaningless until the first time through wait_for_inferior. */
1017 prev_func_start
= 0;
1018 prev_func_name
= NULL
;
1021 trap_expected_after_continue
= 0;
1023 breakpoints_inserted
= 0;
1024 breakpoint_init_inferior (inf_starting
);
1026 /* Don't confuse first call to proceed(). */
1027 stop_signal
= TARGET_SIGNAL_0
;
1029 /* The first resume is not following a fork/vfork/exec. */
1030 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1031 pending_follow
.fork_event
.saw_parent_fork
= 0;
1032 pending_follow
.fork_event
.saw_child_fork
= 0;
1033 pending_follow
.fork_event
.saw_child_exec
= 0;
1035 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1036 number_of_threads_in_syscalls
= 0;
1038 clear_proceed_status ();
1042 delete_breakpoint_current_contents (arg
)
1045 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1046 if (*breakpointp
!= NULL
)
1048 delete_breakpoint (*breakpointp
);
1049 *breakpointp
= NULL
;
1053 /* This enum encodes possible reasons for doing a target_wait, so that
1054 wfi can call target_wait in one place. (Ultimately the call will be
1055 moved out of the infinite loop entirely.) */
1057 enum infwait_states
{
1058 infwait_normal_state
,
1059 infwait_thread_hop_state
,
1060 infwait_nullified_state
,
1061 infwait_nonstep_watch_state
1064 /* This structure contains what used to be local variables in
1065 wait_for_inferior. Probably many of them can return to being
1066 locals in handle_inferior_event. */
1068 struct execution_control_state
{
1069 struct target_waitstatus ws
;
1070 struct target_waitstatus
*wp
;
1073 CORE_ADDR stop_func_start
;
1074 CORE_ADDR stop_func_end
;
1075 char *stop_func_name
;
1076 struct symtab_and_line sal
;
1077 int remove_breakpoints_on_following_step
;
1079 struct symtab
*current_symtab
;
1080 int handling_longjmp
; /* FIXME */
1082 int saved_inferior_pid
;
1084 int stepping_through_solib_after_catch
;
1085 bpstat stepping_through_solib_catchpoints
;
1086 int enable_hw_watchpoints_after_wait
;
1087 int stepping_through_sigtramp
;
1088 int new_thread_event
;
1089 struct target_waitstatus tmpstatus
;
1090 enum infwait_states infwait_state
;
1095 void init_execution_control_state
PARAMS ((struct execution_control_state
*ecs
));
1097 void handle_inferior_event
PARAMS ((struct execution_control_state
*ecs
));
1099 /* Wait for control to return from inferior to debugger.
1100 If inferior gets a signal, we may decide to start it up again
1101 instead of returning. That is why there is a loop in this function.
1102 When this function actually returns it means the inferior
1103 should be left stopped and GDB should read more commands. */
1106 wait_for_inferior ()
1108 struct cleanup
*old_cleanups
;
1109 struct execution_control_state ecss
;
1110 struct execution_control_state
*ecs
;
1112 old_cleanups
= make_cleanup (delete_breakpoint_current_contents
,
1113 &step_resume_breakpoint
);
1114 make_cleanup (delete_breakpoint_current_contents
,
1115 &through_sigtramp_breakpoint
);
1117 /* wfi still stays in a loop, so it's OK just to take the address of
1118 a local to get the ecs pointer. */
1121 /* Fill in with reasonable starting values. */
1122 init_execution_control_state (ecs
);
1124 thread_step_needed
= 0;
1126 /* We'll update this if & when we switch to a new thread. */
1127 if (may_switch_from_inferior_pid
)
1128 switched_from_inferior_pid
= inferior_pid
;
1130 overlay_cache_invalid
= 1;
1132 /* We have to invalidate the registers BEFORE calling target_wait
1133 because they can be loaded from the target while in target_wait.
1134 This makes remote debugging a bit more efficient for those
1135 targets that provide critical registers as part of their normal
1136 status mechanism. */
1138 registers_changed ();
1142 if (target_wait_hook
)
1143 ecs
->pid
= target_wait_hook (ecs
->waiton_pid
, ecs
->wp
);
1145 ecs
->pid
= target_wait (ecs
->waiton_pid
, ecs
->wp
);
1147 /* Now figure out what to do with the result of the result. */
1148 handle_inferior_event (ecs
);
1150 if (!ecs
->wait_some_more
)
1153 do_cleanups (old_cleanups
);
1156 /* Prepare an execution control state for looping through a
1157 wait_for_inferior-type loop. */
1160 init_execution_control_state (ecs
)
1161 struct execution_control_state
*ecs
;
1163 ecs
->random_signal
= 0;
1164 ecs
->remove_breakpoints_on_following_step
= 0;
1165 ecs
->handling_longjmp
= 0; /* FIXME */
1166 ecs
->update_step_sp
= 0;
1167 ecs
->stepping_through_solib_after_catch
= 0;
1168 ecs
->stepping_through_solib_catchpoints
= NULL
;
1169 ecs
->enable_hw_watchpoints_after_wait
= 0;
1170 ecs
->stepping_through_sigtramp
= 0;
1171 ecs
->sal
= find_pc_line (prev_pc
, 0);
1172 ecs
->current_line
= ecs
->sal
.line
;
1173 ecs
->current_symtab
= ecs
->sal
.symtab
;
1174 ecs
->infwait_state
= infwait_normal_state
;
1175 ecs
->waiton_pid
= -1;
1176 ecs
->wp
= &(ecs
->ws
);
1179 /* Given an execution control state that has been freshly filled in
1180 by an event from the inferior, figure out what it means and take
1181 appropriate action. */
1184 handle_inferior_event (ecs
)
1185 struct execution_control_state
*ecs
;
1188 int stepped_after_stopped_by_watchpoint
;
1190 /* Keep this extra brace for now, minimizes diffs. */
1192 switch (ecs
->infwait_state
)
1194 case infwait_normal_state
:
1195 /* Since we've done a wait, we have a new event. Don't
1196 carry over any expectations about needing to step over a
1198 thread_step_needed
= 0;
1200 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1201 is serviced in this loop, below. */
1202 if (ecs
->enable_hw_watchpoints_after_wait
)
1204 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid
);
1205 ecs
->enable_hw_watchpoints_after_wait
= 0;
1207 stepped_after_stopped_by_watchpoint
= 0;
1210 case infwait_thread_hop_state
:
1211 insert_breakpoints ();
1213 /* We need to restart all the threads now,
1214 * unles we're running in scheduler-locked mode.
1215 * FIXME: shouldn't we look at currently_stepping ()?
1217 if (scheduler_mode
== schedlock_on
)
1218 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1220 target_resume (-1, 0, TARGET_SIGNAL_0
);
1221 ecs
->infwait_state
= infwait_normal_state
;
1224 case infwait_nullified_state
:
1227 case infwait_nonstep_watch_state
:
1228 insert_breakpoints ();
1230 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1231 handle things like signals arriving and other things happening
1232 in combination correctly? */
1233 stepped_after_stopped_by_watchpoint
= 1;
1236 ecs
->infwait_state
= infwait_normal_state
;
1238 flush_cached_frames ();
1240 /* If it's a new process, add it to the thread database */
1242 ecs
->new_thread_event
= ((ecs
->pid
!= inferior_pid
) && !in_thread_list (ecs
->pid
));
1244 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1245 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1246 && ecs
->new_thread_event
)
1248 add_thread (ecs
->pid
);
1250 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs
->pid
));
1253 /* NOTE: This block is ONLY meant to be invoked in case of a
1254 "thread creation event"! If it is invoked for any other
1255 sort of event (such as a new thread landing on a breakpoint),
1256 the event will be discarded, which is almost certainly
1259 To avoid this, the low-level module (eg. target_wait)
1260 should call in_thread_list and add_thread, so that the
1261 new thread is known by the time we get here. */
1263 /* We may want to consider not doing a resume here in order
1264 to give the user a chance to play with the new thread.
1265 It might be good to make that a user-settable option. */
1267 /* At this point, all threads are stopped (happens
1268 automatically in either the OS or the native code).
1269 Therefore we need to continue all threads in order to
1272 target_resume (-1, 0, TARGET_SIGNAL_0
);
1277 switch (ecs
->ws
.kind
)
1279 case TARGET_WAITKIND_LOADED
:
1280 /* Ignore gracefully during startup of the inferior, as it
1281 might be the shell which has just loaded some objects,
1282 otherwise add the symbols for the newly loaded objects. */
1284 if (!stop_soon_quietly
)
1286 /* Remove breakpoints, SOLIB_ADD might adjust
1287 breakpoint addresses via breakpoint_re_set. */
1288 if (breakpoints_inserted
)
1289 remove_breakpoints ();
1291 /* Check for any newly added shared libraries if we're
1292 supposed to be adding them automatically. */
1295 /* Switch terminal for any messages produced by
1296 breakpoint_re_set. */
1297 target_terminal_ours_for_output ();
1298 SOLIB_ADD (NULL
, 0, NULL
);
1299 target_terminal_inferior ();
1302 /* Reinsert breakpoints and continue. */
1303 if (breakpoints_inserted
)
1304 insert_breakpoints ();
1307 resume (0, TARGET_SIGNAL_0
);
1310 case TARGET_WAITKIND_SPURIOUS
:
1311 resume (0, TARGET_SIGNAL_0
);
1314 case TARGET_WAITKIND_EXITED
:
1315 target_terminal_ours (); /* Must do this before mourn anyway */
1316 annotate_exited (ecs
->ws
.value
.integer
);
1317 if (ecs
->ws
.value
.integer
)
1318 printf_filtered ("\nProgram exited with code 0%o.\n",
1319 (unsigned int) ecs
->ws
.value
.integer
);
1321 printf_filtered ("\nProgram exited normally.\n");
1323 /* Record the exit code in the convenience variable $_exitcode, so
1324 that the user can inspect this again later. */
1325 set_internalvar (lookup_internalvar ("_exitcode"),
1326 value_from_longest (builtin_type_int
,
1327 (LONGEST
) ecs
->ws
.value
.integer
));
1328 gdb_flush (gdb_stdout
);
1329 target_mourn_inferior ();
1330 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P*/
1331 stop_print_frame
= 0;
1334 case TARGET_WAITKIND_SIGNALLED
:
1335 stop_print_frame
= 0;
1336 stop_signal
= ecs
->ws
.value
.sig
;
1337 target_terminal_ours (); /* Must do this before mourn anyway */
1338 annotate_signalled ();
1340 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1341 mean it is already dead? This has been here since GDB 2.8, so
1342 perhaps it means rms didn't understand unix waitstatuses?
1343 For the moment I'm just kludging around this in remote.c
1344 rather than trying to change it here --kingdon, 5 Dec 1994. */
1345 target_kill (); /* kill mourns as well */
1347 printf_filtered ("\nProgram terminated with signal ");
1348 annotate_signal_name ();
1349 printf_filtered ("%s", target_signal_to_name (stop_signal
));
1350 annotate_signal_name_end ();
1351 printf_filtered (", ");
1352 annotate_signal_string ();
1353 printf_filtered ("%s", target_signal_to_string (stop_signal
));
1354 annotate_signal_string_end ();
1355 printf_filtered (".\n");
1357 printf_filtered ("The program no longer exists.\n");
1358 gdb_flush (gdb_stdout
);
1359 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P*/
1362 /* The following are the only cases in which we keep going;
1363 the above cases end in a continue or goto. */
1364 case TARGET_WAITKIND_FORKED
:
1365 stop_signal
= TARGET_SIGNAL_TRAP
;
1366 pending_follow
.kind
= ecs
->ws
.kind
;
1368 /* Ignore fork events reported for the parent; we're only
1369 interested in reacting to forks of the child. Note that
1370 we expect the child's fork event to be available if we
1371 waited for it now. */
1372 if (inferior_pid
== ecs
->pid
)
1374 pending_follow
.fork_event
.saw_parent_fork
= 1;
1375 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1376 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1381 pending_follow
.fork_event
.saw_child_fork
= 1;
1382 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1383 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1386 stop_pc
= read_pc_pid (ecs
->pid
);
1387 ecs
->saved_inferior_pid
= inferior_pid
;
1388 inferior_pid
= ecs
->pid
;
1389 stop_bpstat
= bpstat_stop_status
1391 (DECR_PC_AFTER_BREAK
?
1392 (prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1393 && currently_stepping (ecs
))
1396 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1397 inferior_pid
= ecs
->saved_inferior_pid
;
1398 goto process_event_stop_test
;
1400 /* If this a platform which doesn't allow a debugger to touch a
1401 vfork'd inferior until after it exec's, then we'd best keep
1402 our fingers entirely off the inferior, other than continuing
1403 it. This has the unfortunate side-effect that catchpoints
1404 of vforks will be ignored. But since the platform doesn't
1405 allow the inferior be touched at vfork time, there's really
1407 case TARGET_WAITKIND_VFORKED
:
1408 stop_signal
= TARGET_SIGNAL_TRAP
;
1409 pending_follow
.kind
= ecs
->ws
.kind
;
1411 /* Is this a vfork of the parent? If so, then give any
1412 vfork catchpoints a chance to trigger now. (It's
1413 dangerous to do so if the child canot be touched until
1414 it execs, and the child has not yet exec'd. We probably
1415 should warn the user to that effect when the catchpoint
1417 if (ecs
->pid
== inferior_pid
)
1419 pending_follow
.fork_event
.saw_parent_fork
= 1;
1420 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1421 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1424 /* If we've seen the child's vfork event but cannot really touch
1425 the child until it execs, then we must continue the child now.
1426 Else, give any vfork catchpoints a chance to trigger now. */
1429 pending_follow
.fork_event
.saw_child_fork
= 1;
1430 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1431 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1432 target_post_startup_inferior (pending_follow
.fork_event
.child_pid
);
1433 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1434 if (follow_vfork_when_exec
)
1436 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1441 stop_pc
= read_pc ();
1442 stop_bpstat
= bpstat_stop_status
1444 (DECR_PC_AFTER_BREAK
?
1445 (prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1446 && currently_stepping (ecs
))
1449 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1450 goto process_event_stop_test
;
1452 case TARGET_WAITKIND_EXECD
:
1453 stop_signal
= TARGET_SIGNAL_TRAP
;
1455 /* Is this a target which reports multiple exec events per actual
1456 call to exec()? (HP-UX using ptrace does, for example.) If so,
1457 ignore all but the last one. Just resume the exec'r, and wait
1458 for the next exec event. */
1459 if (inferior_ignoring_leading_exec_events
)
1461 inferior_ignoring_leading_exec_events
--;
1462 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1463 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.parent_pid
);
1464 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1467 inferior_ignoring_leading_exec_events
=
1468 target_reported_exec_events_per_exec_call () - 1;
1470 pending_follow
.execd_pathname
= savestring (ecs
->ws
.value
.execd_pathname
,
1471 strlen (ecs
->ws
.value
.execd_pathname
));
1473 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1474 child of a vfork exec?
1476 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1477 HP-UX, events associated with a vforking inferior come in
1478 threes: a vfork event for the child (always first), followed
1479 a vfork event for the parent and an exec event for the child.
1480 The latter two can come in either order.
1482 If we get the parent vfork event first, life's good: We follow
1483 either the parent or child, and then the child's exec event is
1486 But if we get the child's exec event first, then we delay
1487 responding to it until we handle the parent's vfork. Because,
1488 otherwise we can't satisfy a "catch vfork". */
1489 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1491 pending_follow
.fork_event
.saw_child_exec
= 1;
1493 /* On some targets, the child must be resumed before
1494 the parent vfork event is delivered. A single-step
1496 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1497 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1498 /* We expect the parent vfork event to be available now. */
1502 /* This causes the eventpoints and symbol table to be reset. Must
1503 do this now, before trying to determine whether to stop. */
1504 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
1505 free (pending_follow
.execd_pathname
);
1507 stop_pc
= read_pc_pid (ecs
->pid
);
1508 ecs
->saved_inferior_pid
= inferior_pid
;
1509 inferior_pid
= ecs
->pid
;
1510 stop_bpstat
= bpstat_stop_status
1512 (DECR_PC_AFTER_BREAK
?
1513 (prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1514 && currently_stepping (ecs
))
1517 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1518 inferior_pid
= ecs
->saved_inferior_pid
;
1519 goto process_event_stop_test
;
1521 /* These syscall events are returned on HP-UX, as part of its
1522 implementation of page-protection-based "hardware" watchpoints.
1523 HP-UX has unfortunate interactions between page-protections and
1524 some system calls. Our solution is to disable hardware watches
1525 when a system call is entered, and reenable them when the syscall
1526 completes. The downside of this is that we may miss the precise
1527 point at which a watched piece of memory is modified. "Oh well."
1529 Note that we may have multiple threads running, which may each
1530 enter syscalls at roughly the same time. Since we don't have a
1531 good notion currently of whether a watched piece of memory is
1532 thread-private, we'd best not have any page-protections active
1533 when any thread is in a syscall. Thus, we only want to reenable
1534 hardware watches when no threads are in a syscall.
1536 Also, be careful not to try to gather much state about a thread
1537 that's in a syscall. It's frequently a losing proposition. */
1538 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1539 number_of_threads_in_syscalls
++;
1540 if (number_of_threads_in_syscalls
== 1)
1542 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid
);
1544 resume (0, TARGET_SIGNAL_0
);
1547 /* Before examining the threads further, step this thread to
1548 get it entirely out of the syscall. (We get notice of the
1549 event when the thread is just on the verge of exiting a
1550 syscall. Stepping one instruction seems to get it back
1553 Note that although the logical place to reenable h/w watches
1554 is here, we cannot. We cannot reenable them before stepping
1555 the thread (this causes the next wait on the thread to hang).
1557 Nor can we enable them after stepping until we've done a wait.
1558 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1559 here, which will be serviced immediately after the target
1561 case TARGET_WAITKIND_SYSCALL_RETURN
:
1562 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1564 if (number_of_threads_in_syscalls
> 0)
1566 number_of_threads_in_syscalls
--;
1567 ecs
->enable_hw_watchpoints_after_wait
=
1568 (number_of_threads_in_syscalls
== 0);
1572 case TARGET_WAITKIND_STOPPED
:
1573 stop_signal
= ecs
->ws
.value
.sig
;
1577 /* We may want to consider not doing a resume here in order to give
1578 the user a chance to play with the new thread. It might be good
1579 to make that a user-settable option. */
1581 /* At this point, all threads are stopped (happens automatically in
1582 either the OS or the native code). Therefore we need to continue
1583 all threads in order to make progress. */
1584 if (ecs
->new_thread_event
)
1586 target_resume (-1, 0, TARGET_SIGNAL_0
);
1590 stop_pc
= read_pc_pid (ecs
->pid
);
1592 /* See if a thread hit a thread-specific breakpoint that was meant for
1593 another thread. If so, then step that thread past the breakpoint,
1596 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1598 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1599 ecs
->random_signal
= 0;
1600 else if (breakpoints_inserted
1601 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1603 ecs
->random_signal
= 0;
1604 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1609 /* Saw a breakpoint, but it was hit by the wrong thread.
1611 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->pid
);
1613 remove_status
= remove_breakpoints ();
1614 /* Did we fail to remove breakpoints? If so, try
1615 to set the PC past the bp. (There's at least
1616 one situation in which we can fail to remove
1617 the bp's: On HP-UX's that use ttrace, we can't
1618 change the address space of a vforking child
1619 process until the child exits (well, okay, not
1620 then either :-) or execs. */
1621 if (remove_status
!= 0)
1623 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->pid
);
1627 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1628 /* FIXME: What if a signal arrives instead of the
1629 single-step happening? */
1631 ecs
->waiton_pid
= ecs
->pid
;
1632 ecs
->wp
= &(ecs
->ws
);
1633 ecs
->infwait_state
= infwait_thread_hop_state
;
1637 /* We need to restart all the threads now,
1638 * unles we're running in scheduler-locked mode.
1639 * FIXME: shouldn't we look at currently_stepping ()?
1641 if (scheduler_mode
== schedlock_on
)
1642 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1644 target_resume (-1, 0, TARGET_SIGNAL_0
);
1649 /* This breakpoint matches--either it is the right
1650 thread or it's a generic breakpoint for all threads.
1651 Remember that we'll need to step just _this_ thread
1652 on any following user continuation! */
1653 thread_step_needed
= 1;
1658 ecs
->random_signal
= 1;
1660 /* See if something interesting happened to the non-current thread. If
1661 so, then switch to that thread, and eventually give control back to
1664 Note that if there's any kind of pending follow (i.e., of a fork,
1665 vfork or exec), we don't want to do this now. Rather, we'll let
1666 the next resume handle it. */
1667 if ((ecs
->pid
!= inferior_pid
) &&
1668 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1672 /* If it's a random signal for a non-current thread, notify user
1673 if he's expressed an interest. */
1674 if (ecs
->random_signal
1675 && signal_print
[stop_signal
])
1677 /* ??rehrauer: I don't understand the rationale for this code. If the
1678 inferior will stop as a result of this signal, then the act of handling
1679 the stop ought to print a message that's couches the stoppage in user
1680 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1681 won't stop as a result of the signal -- i.e., if the signal is merely
1682 a side-effect of something GDB's doing "under the covers" for the
1683 user, such as stepping threads over a breakpoint they shouldn't stop
1684 for -- then the message seems to be a serious annoyance at best.
1686 For now, remove the message altogether. */
1689 target_terminal_ours_for_output ();
1690 printf_filtered ("\nProgram received signal %s, %s.\n",
1691 target_signal_to_name (stop_signal
),
1692 target_signal_to_string (stop_signal
));
1693 gdb_flush (gdb_stdout
);
1697 /* If it's not SIGTRAP and not a signal we want to stop for, then
1698 continue the thread. */
1700 if (stop_signal
!= TARGET_SIGNAL_TRAP
1701 && !signal_stop
[stop_signal
])
1704 target_terminal_inferior ();
1706 /* Clear the signal if it should not be passed. */
1707 if (signal_program
[stop_signal
] == 0)
1708 stop_signal
= TARGET_SIGNAL_0
;
1710 target_resume (ecs
->pid
, 0, stop_signal
);
1714 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1715 and fall into the rest of wait_for_inferior(). */
1717 /* Save infrun state for the old thread. */
1718 save_infrun_state (inferior_pid
, prev_pc
,
1719 prev_func_start
, prev_func_name
,
1720 trap_expected
, step_resume_breakpoint
,
1721 through_sigtramp_breakpoint
,
1722 step_range_start
, step_range_end
,
1723 step_frame_address
, ecs
->handling_longjmp
,
1725 ecs
->stepping_through_solib_after_catch
,
1726 ecs
->stepping_through_solib_catchpoints
,
1727 ecs
->stepping_through_sigtramp
);
1729 if (may_switch_from_inferior_pid
)
1730 switched_from_inferior_pid
= inferior_pid
;
1732 inferior_pid
= ecs
->pid
;
1734 /* Load infrun state for the new thread. */
1735 load_infrun_state (inferior_pid
, &prev_pc
,
1736 &prev_func_start
, &prev_func_name
,
1737 &trap_expected
, &step_resume_breakpoint
,
1738 &through_sigtramp_breakpoint
,
1739 &step_range_start
, &step_range_end
,
1740 &step_frame_address
, &ecs
->handling_longjmp
,
1742 &ecs
->stepping_through_solib_after_catch
,
1743 &ecs
->stepping_through_solib_catchpoints
,
1744 &ecs
->stepping_through_sigtramp
);
1747 context_hook (pid_to_thread_id (ecs
->pid
));
1749 printf_filtered ("[Switching to %s]\n", target_pid_to_str (ecs
->pid
));
1750 flush_cached_frames ();
1753 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1755 /* Pull the single step breakpoints out of the target. */
1756 SOFTWARE_SINGLE_STEP (0, 0);
1757 singlestep_breakpoints_inserted_p
= 0;
1760 /* If PC is pointing at a nullified instruction, then step beyond
1761 it so that the user won't be confused when GDB appears to be ready
1764 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1765 if (INSTRUCTION_NULLIFIED
)
1767 registers_changed ();
1768 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1770 /* We may have received a signal that we want to pass to
1771 the inferior; therefore, we must not clobber the waitstatus
1774 ecs
->infwait_state
= infwait_nullified_state
;
1775 ecs
->waiton_pid
= ecs
->pid
;
1776 ecs
->wp
= &(ecs
->tmpstatus
);
1780 /* It may not be necessary to disable the watchpoint to stop over
1781 it. For example, the PA can (with some kernel cooperation)
1782 single step over a watchpoint without disabling the watchpoint. */
1783 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1789 /* It is far more common to need to disable a watchpoint to step
1790 the inferior over it. FIXME. What else might a debug
1791 register or page protection watchpoint scheme need here? */
1792 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1794 /* At this point, we are stopped at an instruction which has
1795 attempted to write to a piece of memory under control of
1796 a watchpoint. The instruction hasn't actually executed
1797 yet. If we were to evaluate the watchpoint expression
1798 now, we would get the old value, and therefore no change
1799 would seem to have occurred.
1801 In order to make watchpoints work `right', we really need
1802 to complete the memory write, and then evaluate the
1803 watchpoint expression. The following code does that by
1804 removing the watchpoint (actually, all watchpoints and
1805 breakpoints), single-stepping the target, re-inserting
1806 watchpoints, and then falling through to let normal
1807 single-step processing handle proceed. Since this
1808 includes evaluating watchpoints, things will come to a
1809 stop in the correct manner. */
1811 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
1813 remove_breakpoints ();
1814 registers_changed ();
1815 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
); /* Single step */
1817 ecs
->waiton_pid
= ecs
->pid
;
1818 ecs
->wp
= &(ecs
->ws
);
1819 ecs
->infwait_state
= infwait_nonstep_watch_state
;
1823 /* It may be possible to simply continue after a watchpoint. */
1824 if (HAVE_CONTINUABLE_WATCHPOINT
)
1825 STOPPED_BY_WATCHPOINT (ecs
->ws
);
1827 ecs
->stop_func_start
= 0;
1828 ecs
->stop_func_end
= 0;
1829 ecs
->stop_func_name
= 0;
1830 /* Don't care about return value; stop_func_start and stop_func_name
1831 will both be 0 if it doesn't work. */
1832 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
1833 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
1834 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
1835 ecs
->another_trap
= 0;
1836 bpstat_clear (&stop_bpstat
);
1838 stop_stack_dummy
= 0;
1839 stop_print_frame
= 1;
1840 ecs
->random_signal
= 0;
1841 stopped_by_random_signal
= 0;
1842 breakpoints_failed
= 0;
1844 /* Look at the cause of the stop, and decide what to do.
1845 The alternatives are:
1846 1) break; to really stop and return to the debugger,
1847 2) drop through to start up again
1848 (set ecs->another_trap to 1 to single step once)
1849 3) set ecs->random_signal to 1, and the decision between 1 and 2
1850 will be made according to the signal handling tables. */
1852 /* First, distinguish signals caused by the debugger from signals
1853 that have to do with the program's own actions.
1854 Note that breakpoint insns may cause SIGTRAP or SIGILL
1855 or SIGEMT, depending on the operating system version.
1856 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1857 and change it to SIGTRAP. */
1859 if (stop_signal
== TARGET_SIGNAL_TRAP
1860 || (breakpoints_inserted
&&
1861 (stop_signal
== TARGET_SIGNAL_ILL
1862 || stop_signal
== TARGET_SIGNAL_EMT
1864 || stop_soon_quietly
)
1866 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
1868 stop_print_frame
= 0;
1871 if (stop_soon_quietly
)
1874 /* Don't even think about breakpoints
1875 if just proceeded over a breakpoint.
1877 However, if we are trying to proceed over a breakpoint
1878 and end up in sigtramp, then through_sigtramp_breakpoint
1879 will be set and we should check whether we've hit the
1881 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
1882 && through_sigtramp_breakpoint
== NULL
)
1883 bpstat_clear (&stop_bpstat
);
1886 /* See if there is a breakpoint at the current PC. */
1887 stop_bpstat
= bpstat_stop_status
1889 (DECR_PC_AFTER_BREAK
?
1890 /* Notice the case of stepping through a jump
1891 that lands just after a breakpoint.
1892 Don't confuse that with hitting the breakpoint.
1893 What we check for is that 1) stepping is going on
1894 and 2) the pc before the last insn does not match
1895 the address of the breakpoint before the current pc
1896 and 3) we didn't hit a breakpoint in a signal handler
1897 without an intervening stop in sigtramp, which is
1898 detected by a new stack pointer value below
1899 any usual function calling stack adjustments. */
1900 (currently_stepping (ecs
)
1901 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1903 && INNER_THAN (read_sp (), (step_sp
- 16)))) :
1906 /* Following in case break condition called a
1908 stop_print_frame
= 1;
1911 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1913 = !(bpstat_explains_signal (stop_bpstat
)
1915 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
1916 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
1917 FRAME_FP (get_current_frame ())))
1918 || (step_range_end
&& step_resume_breakpoint
== NULL
));
1923 = !(bpstat_explains_signal (stop_bpstat
)
1924 /* End of a stack dummy. Some systems (e.g. Sony
1925 news) give another signal besides SIGTRAP, so
1926 check here as well as above. */
1927 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
1928 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
1929 FRAME_FP (get_current_frame ())))
1931 if (!ecs
->random_signal
)
1932 stop_signal
= TARGET_SIGNAL_TRAP
;
1936 /* When we reach this point, we've pretty much decided
1937 that the reason for stopping must've been a random
1938 (unexpected) signal. */
1941 ecs
->random_signal
= 1;
1942 /* If a fork, vfork or exec event was seen, then there are two
1943 possible responses we can make:
1945 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
1946 then we must stop now and issue a prompt. We will resume
1947 the inferior when the user tells us to.
1948 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
1949 then we must resume the inferior now and keep checking.
1951 In either case, we must take appropriate steps to "follow" the
1952 the fork/vfork/exec when the inferior is resumed. For example,
1953 if follow-fork-mode is "child", then we must detach from the
1954 parent inferior and follow the new child inferior.
1956 In either case, setting pending_follow causes the next resume()
1957 to take the appropriate following action. */
1958 process_event_stop_test
:
1959 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
1961 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
1964 stop_signal
= TARGET_SIGNAL_0
;
1968 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
1970 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
1972 stop_signal
= TARGET_SIGNAL_0
;
1976 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
1978 pending_follow
.kind
= ecs
->ws
.kind
;
1979 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
1982 stop_signal
= TARGET_SIGNAL_0
;
1987 /* For the program's own signals, act according to
1988 the signal handling tables. */
1990 if (ecs
->random_signal
)
1992 /* Signal not for debugging purposes. */
1995 stopped_by_random_signal
= 1;
1997 if (signal_print
[stop_signal
])
2000 target_terminal_ours_for_output ();
2002 printf_filtered ("\nProgram received signal ");
2003 annotate_signal_name ();
2004 printf_filtered ("%s", target_signal_to_name (stop_signal
));
2005 annotate_signal_name_end ();
2006 printf_filtered (", ");
2007 annotate_signal_string ();
2008 printf_filtered ("%s", target_signal_to_string (stop_signal
));
2009 annotate_signal_string_end ();
2010 printf_filtered (".\n");
2011 gdb_flush (gdb_stdout
);
2013 if (signal_stop
[stop_signal
])
2015 /* If not going to stop, give terminal back
2016 if we took it away. */
2018 target_terminal_inferior ();
2020 /* Clear the signal if it should not be passed. */
2021 if (signal_program
[stop_signal
] == 0)
2022 stop_signal
= TARGET_SIGNAL_0
;
2024 /* If we're in the middle of a "next" command, let the code for
2025 stepping over a function handle this. pai/1997-09-10
2027 A previous comment here suggested it was possible to change
2028 this to jump to keep_going in all cases. */
2030 if (step_over_calls
> 0)
2031 goto step_over_function
;
2033 goto check_sigtramp2
;
2036 /* Handle cases caused by hitting a breakpoint. */
2038 CORE_ADDR jmp_buf_pc
;
2039 struct bpstat_what what
;
2041 what
= bpstat_what (stop_bpstat
);
2043 if (what
.call_dummy
)
2045 stop_stack_dummy
= 1;
2047 trap_expected_after_continue
= 1;
2051 switch (what
.main_action
)
2053 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2054 /* If we hit the breakpoint at longjmp, disable it for the
2055 duration of this command. Then, install a temporary
2056 breakpoint at the target of the jmp_buf. */
2057 disable_longjmp_breakpoint ();
2058 remove_breakpoints ();
2059 breakpoints_inserted
= 0;
2060 if (!GET_LONGJMP_TARGET (&jmp_buf_pc
))
2063 /* Need to blow away step-resume breakpoint, as it
2064 interferes with us */
2065 if (step_resume_breakpoint
!= NULL
)
2067 delete_breakpoint (step_resume_breakpoint
);
2068 step_resume_breakpoint
= NULL
;
2070 /* Not sure whether we need to blow this away too, but probably
2071 it is like the step-resume breakpoint. */
2072 if (through_sigtramp_breakpoint
!= NULL
)
2074 delete_breakpoint (through_sigtramp_breakpoint
);
2075 through_sigtramp_breakpoint
= NULL
;
2079 /* FIXME - Need to implement nested temporary breakpoints */
2080 if (step_over_calls
> 0)
2081 set_longjmp_resume_breakpoint (jmp_buf_pc
,
2082 get_current_frame ());
2085 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2086 ecs
->handling_longjmp
= 1; /* FIXME */
2089 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2090 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2091 remove_breakpoints ();
2092 breakpoints_inserted
= 0;
2094 /* FIXME - Need to implement nested temporary breakpoints */
2096 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2097 step_frame_address
)))
2099 ecs
->another_trap
= 1;
2103 disable_longjmp_breakpoint ();
2104 ecs
->handling_longjmp
= 0; /* FIXME */
2105 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2107 /* else fallthrough */
2109 case BPSTAT_WHAT_SINGLE
:
2110 if (breakpoints_inserted
)
2112 thread_step_needed
= 1;
2113 remove_breakpoints ();
2115 breakpoints_inserted
= 0;
2116 ecs
->another_trap
= 1;
2117 /* Still need to check other stuff, at least the case
2118 where we are stepping and step out of the right range. */
2121 case BPSTAT_WHAT_STOP_NOISY
:
2122 stop_print_frame
= 1;
2124 /* We are about to nuke the step_resume_breakpoint and
2125 through_sigtramp_breakpoint via the cleanup chain, so
2126 no need to worry about it here. */
2130 case BPSTAT_WHAT_STOP_SILENT
:
2131 stop_print_frame
= 0;
2133 /* We are about to nuke the step_resume_breakpoint and
2134 through_sigtramp_breakpoint via the cleanup chain, so
2135 no need to worry about it here. */
2139 case BPSTAT_WHAT_STEP_RESUME
:
2140 /* This proably demands a more elegant solution, but, yeah
2143 This function's use of the simple variable
2144 step_resume_breakpoint doesn't seem to accomodate
2145 simultaneously active step-resume bp's, although the
2146 breakpoint list certainly can.
2148 If we reach here and step_resume_breakpoint is already
2149 NULL, then apparently we have multiple active
2150 step-resume bp's. We'll just delete the breakpoint we
2151 stopped at, and carry on. */
2152 if (step_resume_breakpoint
== NULL
)
2154 step_resume_breakpoint
=
2155 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2157 delete_breakpoint (step_resume_breakpoint
);
2158 step_resume_breakpoint
= NULL
;
2161 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2162 if (through_sigtramp_breakpoint
)
2163 delete_breakpoint (through_sigtramp_breakpoint
);
2164 through_sigtramp_breakpoint
= NULL
;
2166 /* If were waiting for a trap, hitting the step_resume_break
2167 doesn't count as getting it. */
2169 ecs
->another_trap
= 1;
2172 case BPSTAT_WHAT_CHECK_SHLIBS
:
2173 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2176 /* Remove breakpoints, we eventually want to step over the
2177 shlib event breakpoint, and SOLIB_ADD might adjust
2178 breakpoint addresses via breakpoint_re_set. */
2179 if (breakpoints_inserted
)
2180 remove_breakpoints ();
2181 breakpoints_inserted
= 0;
2183 /* Check for any newly added shared libraries if we're
2184 supposed to be adding them automatically. */
2187 /* Switch terminal for any messages produced by
2188 breakpoint_re_set. */
2189 target_terminal_ours_for_output ();
2190 SOLIB_ADD (NULL
, 0, NULL
);
2191 target_terminal_inferior ();
2194 /* Try to reenable shared library breakpoints, additional
2195 code segments in shared libraries might be mapped in now. */
2196 re_enable_breakpoints_in_shlibs ();
2198 /* If requested, stop when the dynamic linker notifies
2199 gdb of events. This allows the user to get control
2200 and place breakpoints in initializer routines for
2201 dynamically loaded objects (among other things). */
2202 if (stop_on_solib_events
)
2204 stop_print_frame
= 0;
2208 /* If we stopped due to an explicit catchpoint, then the
2209 (see above) call to SOLIB_ADD pulled in any symbols
2210 from a newly-loaded library, if appropriate.
2212 We do want the inferior to stop, but not where it is
2213 now, which is in the dynamic linker callback. Rather,
2214 we would like it stop in the user's program, just after
2215 the call that caused this catchpoint to trigger. That
2216 gives the user a more useful vantage from which to
2217 examine their program's state. */
2218 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2220 /* ??rehrauer: If I could figure out how to get the
2221 right return PC from here, we could just set a temp
2222 breakpoint and resume. I'm not sure we can without
2223 cracking open the dld's shared libraries and sniffing
2224 their unwind tables and text/data ranges, and that's
2225 not a terribly portable notion.
2227 Until that time, we must step the inferior out of the
2228 dld callback, and also out of the dld itself (and any
2229 code or stubs in libdld.sl, such as "shl_load" and
2230 friends) until we reach non-dld code. At that point,
2231 we can stop stepping. */
2232 bpstat_get_triggered_catchpoints (stop_bpstat
,
2233 &ecs
->stepping_through_solib_catchpoints
);
2234 ecs
->stepping_through_solib_after_catch
= 1;
2236 /* Be sure to lift all breakpoints, so the inferior does
2237 actually step past this point... */
2238 ecs
->another_trap
= 1;
2243 /* We want to step over this breakpoint, then keep going. */
2244 ecs
->another_trap
= 1;
2251 case BPSTAT_WHAT_LAST
:
2252 /* Not a real code, but listed here to shut up gcc -Wall. */
2254 case BPSTAT_WHAT_KEEP_CHECKING
:
2259 /* We come here if we hit a breakpoint but should not
2260 stop for it. Possibly we also were stepping
2261 and should stop for that. So fall through and
2262 test for stepping. But, if not stepping,
2265 /* Are we stepping to get the inferior out of the dynamic
2266 linker's hook (and possibly the dld itself) after catching
2268 if (ecs
->stepping_through_solib_after_catch
)
2270 #if defined(SOLIB_ADD)
2271 /* Have we reached our destination? If not, keep going. */
2272 if (SOLIB_IN_DYNAMIC_LINKER (ecs
->pid
, stop_pc
))
2274 ecs
->another_trap
= 1;
2278 /* Else, stop and report the catchpoint(s) whose triggering
2279 caused us to begin stepping. */
2280 ecs
->stepping_through_solib_after_catch
= 0;
2281 bpstat_clear (&stop_bpstat
);
2282 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2283 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2284 stop_print_frame
= 1;
2288 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2290 /* This is the old way of detecting the end of the stack dummy.
2291 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2292 handled above. As soon as we can test it on all of them, all
2293 architectures should define it. */
2295 /* If this is the breakpoint at the end of a stack dummy,
2296 just stop silently, unless the user was doing an si/ni, in which
2297 case she'd better know what she's doing. */
2299 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2300 FRAME_FP (get_current_frame ()))
2303 stop_print_frame
= 0;
2304 stop_stack_dummy
= 1;
2306 trap_expected_after_continue
= 1;
2312 if (step_resume_breakpoint
)
2313 /* Having a step-resume breakpoint overrides anything
2314 else having to do with stepping commands until
2315 that breakpoint is reached. */
2316 /* I'm not sure whether this needs to be check_sigtramp2 or
2317 whether it could/should be keep_going. */
2318 goto check_sigtramp2
;
2320 if (step_range_end
== 0)
2321 /* Likewise if we aren't even stepping. */
2322 /* I'm not sure whether this needs to be check_sigtramp2 or
2323 whether it could/should be keep_going. */
2324 goto check_sigtramp2
;
2326 /* If stepping through a line, keep going if still within it.
2328 Note that step_range_end is the address of the first instruction
2329 beyond the step range, and NOT the address of the last instruction
2331 if (stop_pc
>= step_range_start
2332 && stop_pc
< step_range_end
)
2334 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2335 So definately need to check for sigtramp here. */
2336 goto check_sigtramp2
;
2339 /* We stepped out of the stepping range. */
2341 /* If we are stepping at the source level and entered the runtime
2342 loader dynamic symbol resolution code, we keep on single stepping
2343 until we exit the run time loader code and reach the callee's
2345 if (step_over_calls
< 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2348 /* We can't update step_sp every time through the loop, because
2349 reading the stack pointer would slow down stepping too much.
2350 But we can update it every time we leave the step range. */
2351 ecs
->update_step_sp
= 1;
2353 /* Did we just take a signal? */
2354 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2355 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2356 && INNER_THAN (read_sp (), step_sp
))
2358 /* We've just taken a signal; go until we are back to
2359 the point where we took it and one more. */
2361 /* Note: The test above succeeds not only when we stepped
2362 into a signal handler, but also when we step past the last
2363 statement of a signal handler and end up in the return stub
2364 of the signal handler trampoline. To distinguish between
2365 these two cases, check that the frame is INNER_THAN the
2366 previous one below. pai/1997-09-11 */
2370 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2372 if (INNER_THAN (current_frame
, step_frame_address
))
2374 /* We have just taken a signal; go until we are back to
2375 the point where we took it and one more. */
2377 /* This code is needed at least in the following case:
2378 The user types "next" and then a signal arrives (before
2379 the "next" is done). */
2381 /* Note that if we are stopped at a breakpoint, then we need
2382 the step_resume breakpoint to override any breakpoints at
2383 the same location, so that we will still step over the
2384 breakpoint even though the signal happened. */
2385 struct symtab_and_line sr_sal
;
2388 sr_sal
.symtab
= NULL
;
2390 sr_sal
.pc
= prev_pc
;
2391 /* We could probably be setting the frame to
2392 step_frame_address; I don't think anyone thought to
2394 step_resume_breakpoint
=
2395 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2396 if (breakpoints_inserted
)
2397 insert_breakpoints ();
2401 /* We just stepped out of a signal handler and into
2402 its calling trampoline.
2404 Normally, we'd jump to step_over_function from
2405 here, but for some reason GDB can't unwind the
2406 stack correctly to find the real PC for the point
2407 user code where the signal trampoline will return
2408 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2409 But signal trampolines are pretty small stubs of
2410 code, anyway, so it's OK instead to just
2411 single-step out. Note: assuming such trampolines
2412 don't exhibit recursion on any platform... */
2413 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2414 &ecs
->stop_func_start
,
2415 &ecs
->stop_func_end
);
2416 /* Readjust stepping range */
2417 step_range_start
= ecs
->stop_func_start
;
2418 step_range_end
= ecs
->stop_func_end
;
2419 ecs
->stepping_through_sigtramp
= 1;
2424 /* If this is stepi or nexti, make sure that the stepping range
2425 gets us past that instruction. */
2426 if (step_range_end
== 1)
2427 /* FIXME: Does this run afoul of the code below which, if
2428 we step into the middle of a line, resets the stepping
2430 step_range_end
= (step_range_start
= prev_pc
) + 1;
2432 ecs
->remove_breakpoints_on_following_step
= 1;
2436 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2437 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2438 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2439 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2440 || ecs
->stop_func_name
== 0)
2442 /* It's a subroutine call. */
2444 if (step_over_calls
== 0)
2446 /* I presume that step_over_calls is only 0 when we're
2447 supposed to be stepping at the assembly language level
2448 ("stepi"). Just stop. */
2453 if (step_over_calls
> 0 || IGNORE_HELPER_CALL (stop_pc
))
2454 /* We're doing a "next". */
2455 goto step_over_function
;
2457 /* If we are in a function call trampoline (a stub between
2458 the calling routine and the real function), locate the real
2459 function. That's what tells us (a) whether we want to step
2460 into it at all, and (b) what prologue we want to run to
2461 the end of, if we do step into it. */
2462 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2464 ecs
->stop_func_start
= tmp
;
2467 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2470 struct symtab_and_line xxx
;
2471 /* Why isn't this s_a_l called "sr_sal", like all of the
2472 other s_a_l's where this code is duplicated? */
2473 INIT_SAL (&xxx
); /* initialize to zeroes */
2475 xxx
.section
= find_pc_overlay (xxx
.pc
);
2476 step_resume_breakpoint
=
2477 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2478 insert_breakpoints ();
2483 /* If we have line number information for the function we
2484 are thinking of stepping into, step into it.
2486 If there are several symtabs at that PC (e.g. with include
2487 files), just want to know whether *any* of them have line
2488 numbers. find_pc_line handles this. */
2490 struct symtab_and_line tmp_sal
;
2492 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2493 if (tmp_sal
.line
!= 0)
2494 goto step_into_function
;
2498 /* A subroutine call has happened. */
2500 /* Set a special breakpoint after the return */
2501 struct symtab_and_line sr_sal
;
2504 sr_sal
.symtab
= NULL
;
2507 /* If we came here after encountering a signal in the middle of
2508 a "next", use the stashed-away previous frame pc */
2510 = stopped_by_random_signal
2512 : ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2514 step_resume_breakpoint
=
2515 set_momentary_breakpoint (sr_sal
,
2516 stopped_by_random_signal
?
2517 NULL
: get_current_frame (),
2520 /* We've just entered a callee, and we wish to resume until
2521 it returns to the caller. Setting a step_resume bp on
2522 the return PC will catch a return from the callee.
2524 However, if the callee is recursing, we want to be
2525 careful not to catch returns of those recursive calls,
2526 but of THIS instance of the call.
2528 To do this, we set the step_resume bp's frame to our
2529 current caller's frame (step_frame_address, which is
2530 set by the "next" or "until" command, before execution
2533 But ... don't do it if we're single-stepping out of a
2534 sigtramp, because the reason we're single-stepping is
2535 precisely because unwinding is a problem (HP-UX 10.20,
2536 e.g.) and the frame address is likely to be incorrect.
2537 No danger of sigtramp recursion. */
2539 if (ecs
->stepping_through_sigtramp
)
2541 step_resume_breakpoint
->frame
= (CORE_ADDR
) NULL
;
2542 ecs
->stepping_through_sigtramp
= 0;
2544 else if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
2545 step_resume_breakpoint
->frame
= step_frame_address
;
2547 if (breakpoints_inserted
)
2548 insert_breakpoints ();
2553 /* Subroutine call with source code we should not step over.
2554 Do step to the first line of code in it. */
2558 s
= find_pc_symtab (stop_pc
);
2559 if (s
&& s
->language
!= language_asm
)
2560 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2562 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2563 /* Use the step_resume_break to step until
2564 the end of the prologue, even if that involves jumps
2565 (as it seems to on the vax under 4.2). */
2566 /* If the prologue ends in the middle of a source line,
2567 continue to the end of that source line (if it is still
2568 within the function). Otherwise, just go to end of prologue. */
2569 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2570 /* no, don't either. It skips any code that's
2571 legitimately on the first line. */
2573 if (ecs
->sal
.end
&& ecs
->sal
.pc
!= ecs
->stop_func_start
&& ecs
->sal
.end
< ecs
->stop_func_end
)
2574 ecs
->stop_func_start
= ecs
->sal
.end
;
2577 if (ecs
->stop_func_start
== stop_pc
)
2579 /* We are already there: stop now. */
2584 /* Put the step-breakpoint there and go until there. */
2586 struct symtab_and_line sr_sal
;
2588 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2589 sr_sal
.pc
= ecs
->stop_func_start
;
2590 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
2591 /* Do not specify what the fp should be when we stop
2592 since on some machines the prologue
2593 is where the new fp value is established. */
2594 step_resume_breakpoint
=
2595 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2596 if (breakpoints_inserted
)
2597 insert_breakpoints ();
2599 /* And make sure stepping stops right away then. */
2600 step_range_end
= step_range_start
;
2605 /* We've wandered out of the step range. */
2607 ecs
->sal
= find_pc_line (stop_pc
, 0);
2609 if (step_range_end
== 1)
2611 /* It is stepi or nexti. We always want to stop stepping after
2617 /* If we're in the return path from a shared library trampoline,
2618 we want to proceed through the trampoline when stepping. */
2619 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2623 /* Determine where this trampoline returns. */
2624 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2626 /* Only proceed through if we know where it's going. */
2629 /* And put the step-breakpoint there and go until there. */
2630 struct symtab_and_line sr_sal
;
2632 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2634 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2635 /* Do not specify what the fp should be when we stop
2636 since on some machines the prologue
2637 is where the new fp value is established. */
2638 step_resume_breakpoint
=
2639 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2640 if (breakpoints_inserted
)
2641 insert_breakpoints ();
2643 /* Restart without fiddling with the step ranges or
2649 if (ecs
->sal
.line
== 0)
2651 /* We have no line number information. That means to stop
2652 stepping (does this always happen right after one instruction,
2653 when we do "s" in a function with no line numbers,
2654 or can this happen as a result of a return or longjmp?). */
2659 if ((stop_pc
== ecs
->sal
.pc
)
2660 && (ecs
->current_line
!= ecs
->sal
.line
|| ecs
->current_symtab
!= ecs
->sal
.symtab
))
2662 /* We are at the start of a different line. So stop. Note that
2663 we don't stop if we step into the middle of a different line.
2664 That is said to make things like for (;;) statements work
2670 /* We aren't done stepping.
2672 Optimize by setting the stepping range to the line.
2673 (We might not be in the original line, but if we entered a
2674 new line in mid-statement, we continue stepping. This makes
2675 things like for(;;) statements work better.) */
2677 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2679 /* If this is the last line of the function, don't keep stepping
2680 (it would probably step us out of the function).
2681 This is particularly necessary for a one-line function,
2682 in which after skipping the prologue we better stop even though
2683 we will be in mid-line. */
2687 step_range_start
= ecs
->sal
.pc
;
2688 step_range_end
= ecs
->sal
.end
;
2689 step_frame_address
= FRAME_FP (get_current_frame ());
2690 ecs
->current_line
= ecs
->sal
.line
;
2691 ecs
->current_symtab
= ecs
->sal
.symtab
;
2693 /* In the case where we just stepped out of a function into the middle
2694 of a line of the caller, continue stepping, but step_frame_address
2695 must be modified to current frame */
2697 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2698 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2699 step_frame_address
= current_frame
;
2707 && IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2708 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2709 && INNER_THAN (read_sp (), step_sp
))
2711 /* What has happened here is that we have just stepped the inferior
2712 with a signal (because it is a signal which shouldn't make
2713 us stop), thus stepping into sigtramp.
2715 So we need to set a step_resume_break_address breakpoint
2716 and continue until we hit it, and then step. FIXME: This should
2717 be more enduring than a step_resume breakpoint; we should know
2718 that we will later need to keep going rather than re-hitting
2719 the breakpoint here (see testsuite/gdb.t06/signals.exp where
2720 it says "exceedingly difficult"). */
2721 struct symtab_and_line sr_sal
;
2723 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2724 sr_sal
.pc
= prev_pc
;
2725 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2726 /* We perhaps could set the frame if we kept track of what
2727 the frame corresponding to prev_pc was. But we don't,
2729 through_sigtramp_breakpoint
=
2730 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2731 if (breakpoints_inserted
)
2732 insert_breakpoints ();
2734 ecs
->remove_breakpoints_on_following_step
= 1;
2735 ecs
->another_trap
= 1;
2739 /* Come to this label when you need to resume the inferior.
2740 It's really much cleaner to do a goto than a maze of if-else
2743 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug
2744 a vforked child beetween its creation and subsequent exit or
2745 call to exec(). However, I had big problems in this rather
2746 creaky exec engine, getting that to work. The fundamental
2747 problem is that I'm trying to debug two processes via an
2748 engine that only understands a single process with possibly
2751 Hence, this spot is known to have problems when
2752 target_can_follow_vfork_prior_to_exec returns 1. */
2754 /* Save the pc before execution, to compare with pc after stop. */
2755 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
2756 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
2757 BREAK is defined, the
2758 original pc would not have
2759 been at the start of a
2761 prev_func_name
= ecs
->stop_func_name
;
2763 if (ecs
->update_step_sp
)
2764 step_sp
= read_sp ();
2765 ecs
->update_step_sp
= 0;
2767 /* If we did not do break;, it means we should keep
2768 running the inferior and not return to debugger. */
2770 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
2772 /* We took a signal (which we are supposed to pass through to
2773 the inferior, else we'd have done a break above) and we
2774 haven't yet gotten our trap. Simply continue. */
2775 resume (currently_stepping (ecs
), stop_signal
);
2779 /* Either the trap was not expected, but we are continuing
2780 anyway (the user asked that this signal be passed to the
2783 The signal was SIGTRAP, e.g. it was our signal, but we
2784 decided we should resume from it.
2786 We're going to run this baby now!
2788 Insert breakpoints now, unless we are trying
2789 to one-proceed past a breakpoint. */
2790 /* If we've just finished a special step resume and we don't
2791 want to hit a breakpoint, pull em out. */
2792 if (step_resume_breakpoint
== NULL
2793 && through_sigtramp_breakpoint
== NULL
2794 && ecs
->remove_breakpoints_on_following_step
)
2796 ecs
->remove_breakpoints_on_following_step
= 0;
2797 remove_breakpoints ();
2798 breakpoints_inserted
= 0;
2800 else if (!breakpoints_inserted
&&
2801 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
2803 breakpoints_failed
= insert_breakpoints ();
2804 if (breakpoints_failed
)
2806 breakpoints_inserted
= 1;
2809 trap_expected
= ecs
->another_trap
;
2811 /* Do not deliver SIGNAL_TRAP (except when the user
2812 explicitly specifies that such a signal should be
2813 delivered to the target program).
2815 Typically, this would occure when a user is debugging a
2816 target monitor on a simulator: the target monitor sets a
2817 breakpoint; the simulator encounters this break-point and
2818 halts the simulation handing control to GDB; GDB, noteing
2819 that the break-point isn't valid, returns control back to
2820 the simulator; the simulator then delivers the hardware
2821 equivalent of a SIGNAL_TRAP to the program being
2824 if (stop_signal
== TARGET_SIGNAL_TRAP
2825 && !signal_program
[stop_signal
])
2826 stop_signal
= TARGET_SIGNAL_0
;
2828 #ifdef SHIFT_INST_REGS
2829 /* I'm not sure when this following segment applies. I do know,
2830 now, that we shouldn't rewrite the regs when we were stopped
2831 by a random signal from the inferior process. */
2832 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2833 (this is only used on the 88k). */
2835 if (!bpstat_explains_signal (stop_bpstat
)
2836 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
2837 && !stopped_by_random_signal
)
2839 #endif /* SHIFT_INST_REGS */
2841 resume (currently_stepping (ecs
), stop_signal
);
2844 /* Former continues in the main loop goto here. */
2846 /* This used to be at the top of the loop. */
2847 if (ecs
->infwait_state
== infwait_normal_state
)
2849 overlay_cache_invalid
= 1;
2851 /* We have to invalidate the registers BEFORE calling
2852 target_wait because they can be loaded from the target
2853 while in target_wait. This makes remote debugging a bit
2854 more efficient for those targets that provide critical
2855 registers as part of their normal status mechanism. */
2857 registers_changed ();
2858 ecs
->waiton_pid
= -1;
2859 ecs
->wp
= &(ecs
->ws
);
2861 /* This is the old end of the while loop. Let everybody know
2862 we want to wait for the inferior some more and get called
2864 ecs
->wait_some_more
= 1;
2868 /* Former breaks in the main loop goto here. */
2872 if (target_has_execution
)
2874 /* Are we stopping for a vfork event? We only stop when we see
2875 the child's event. However, we may not yet have seen the
2876 parent's event. And, inferior_pid is still set to the parent's
2877 pid, until we resume again and follow either the parent or child.
2879 To ensure that we can really touch inferior_pid (aka, the
2880 parent process) -- which calls to functions like read_pc
2881 implicitly do -- wait on the parent if necessary. */
2882 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
2883 && !pending_follow
.fork_event
.saw_parent_fork
)
2889 if (target_wait_hook
)
2890 parent_pid
= target_wait_hook (-1, &(ecs
->ws
));
2892 parent_pid
= target_wait (-1, &(ecs
->ws
));
2894 while (parent_pid
!= inferior_pid
);
2897 /* Assuming the inferior still exists, set these up for next
2898 time, just like we did above if we didn't break out of the
2900 prev_pc
= read_pc ();
2901 prev_func_start
= ecs
->stop_func_start
;
2902 prev_func_name
= ecs
->stop_func_name
;
2904 /* Let callers know we don't want to wait for the inferior anymore. */
2905 ecs
->wait_some_more
= 0;
2908 /* Are we in the middle of stepping? */
2911 currently_stepping (ecs
)
2912 struct execution_control_state
*ecs
;
2914 return ((through_sigtramp_breakpoint
== NULL
2915 && !ecs
->handling_longjmp
2916 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2918 || ecs
->stepping_through_solib_after_catch
2919 || bpstat_should_step ());
2922 /* This function returns TRUE if ep is an internal breakpoint
2923 set to catch generic shared library (aka dynamically-linked
2924 library) events. (This is *NOT* the same as a catchpoint for a
2925 shlib event. The latter is something a user can set; this is
2926 something gdb sets for its own use, and isn't ever shown to a
2929 is_internal_shlib_eventpoint (ep
)
2930 struct breakpoint
*ep
;
2933 (ep
->type
== bp_shlib_event
)
2937 /* This function returns TRUE if bs indicates that the inferior
2938 stopped due to a shared library (aka dynamically-linked library)
2941 stopped_for_internal_shlib_event (bs
)
2944 /* Note that multiple eventpoints may've caused the stop. Any
2945 that are associated with shlib events will be accepted. */
2946 for (; bs
!= NULL
; bs
= bs
->next
)
2948 if ((bs
->breakpoint_at
!= NULL
)
2949 && is_internal_shlib_eventpoint (bs
->breakpoint_at
))
2953 /* If we get here, then no candidate was found. */
2957 /* This function returns TRUE if bs indicates that the inferior
2958 stopped due to a shared library (aka dynamically-linked library)
2959 event caught by a catchpoint.
2961 If TRUE, cp_p is set to point to the catchpoint.
2963 Else, the value of cp_p is undefined. */
2965 stopped_for_shlib_catchpoint (bs
, cp_p
)
2967 struct breakpoint
**cp_p
;
2969 /* Note that multiple eventpoints may've caused the stop. Any
2970 that are associated with shlib events will be accepted. */
2973 for (; bs
!= NULL
; bs
= bs
->next
)
2975 if ((bs
->breakpoint_at
!= NULL
)
2976 && ep_is_shlib_catchpoint (bs
->breakpoint_at
))
2978 *cp_p
= bs
->breakpoint_at
;
2983 /* If we get here, then no candidate was found. */
2988 /* Here to return control to GDB when the inferior stops for real.
2989 Print appropriate messages, remove breakpoints, give terminal our modes.
2991 STOP_PRINT_FRAME nonzero means print the executing frame
2992 (pc, function, args, file, line number and line text).
2993 BREAKPOINTS_FAILED nonzero means stop was due to error
2994 attempting to insert breakpoints. */
2999 /* As with the notification of thread events, we want to delay
3000 notifying the user that we've switched thread context until
3001 the inferior actually stops.
3003 (Note that there's no point in saying anything if the inferior
3005 if (may_switch_from_inferior_pid
3006 && (switched_from_inferior_pid
!= inferior_pid
)
3007 && target_has_execution
)
3009 target_terminal_ours_for_output ();
3010 printf_filtered ("[Switched to %s]\n",
3011 target_pid_or_tid_to_str (inferior_pid
));
3012 switched_from_inferior_pid
= inferior_pid
;
3015 /* Make sure that the current_frame's pc is correct. This
3016 is a correction for setting up the frame info before doing
3017 DECR_PC_AFTER_BREAK */
3018 if (target_has_execution
&& get_current_frame ())
3019 (get_current_frame ())->pc
= read_pc ();
3021 if (breakpoints_failed
)
3023 target_terminal_ours_for_output ();
3024 print_sys_errmsg ("ptrace", breakpoints_failed
);
3025 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3026 The same program may be running in another process.\n");
3029 if (target_has_execution
&& breakpoints_inserted
)
3031 if (remove_breakpoints ())
3033 target_terminal_ours_for_output ();
3034 printf_filtered ("Cannot remove breakpoints because ");
3035 printf_filtered ("program is no longer writable.\n");
3036 printf_filtered ("It might be running in another process.\n");
3037 printf_filtered ("Further execution is probably impossible.\n");
3040 breakpoints_inserted
= 0;
3042 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3043 Delete any breakpoint that is to be deleted at the next stop. */
3045 breakpoint_auto_delete (stop_bpstat
);
3047 /* If an auto-display called a function and that got a signal,
3048 delete that auto-display to avoid an infinite recursion. */
3050 if (stopped_by_random_signal
)
3051 disable_current_display ();
3053 /* Don't print a message if in the middle of doing a "step n"
3054 operation for n > 1 */
3055 if (step_multi
&& stop_step
)
3058 target_terminal_ours ();
3060 /* Did we stop because the user set the stop_on_solib_events
3061 variable? (If so, we report this as a generic, "Stopped due
3062 to shlib event" message.) */
3063 if (stopped_for_internal_shlib_event (stop_bpstat
))
3065 printf_filtered ("Stopped due to shared library event\n");
3068 /* Look up the hook_stop and run it if it exists. */
3070 if (stop_command
&& stop_command
->hook
)
3072 catch_errors (hook_stop_stub
, stop_command
->hook
,
3073 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3076 if (!target_has_stack
)
3082 /* Select innermost stack frame - i.e., current frame is frame 0,
3083 and current location is based on that.
3084 Don't do this on return from a stack dummy routine,
3085 or if the program has exited. */
3087 if (!stop_stack_dummy
)
3089 select_frame (get_current_frame (), 0);
3091 /* Print current location without a level number, if
3092 we have changed functions or hit a breakpoint.
3093 Print source line if we have one.
3094 bpstat_print() contains the logic deciding in detail
3095 what to print, based on the event(s) that just occurred. */
3097 if (stop_print_frame
)
3102 bpstat_ret
= bpstat_print (stop_bpstat
);
3103 /* bpstat_print() returned one of:
3104 -1: Didn't print anything
3105 0: Printed preliminary "Breakpoint n, " message, desires
3107 1: Printed something, don't tack on location */
3109 if (bpstat_ret
== -1)
3111 && step_frame_address
== FRAME_FP (get_current_frame ())
3112 && step_start_function
== find_pc_function (stop_pc
))
3113 source_flag
= -1; /* finished step, just print source line */
3115 source_flag
= 1; /* print location and source line */
3116 else if (bpstat_ret
== 0) /* hit bpt, desire location */
3117 source_flag
= 1; /* print location and source line */
3118 else /* bpstat_ret == 1, hit bpt, do not desire location */
3119 source_flag
= -1; /* just print source line */
3121 /* The behavior of this routine with respect to the source
3123 -1: Print only source line
3124 0: Print only location
3125 1: Print location and source line */
3126 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
3128 /* Display the auto-display expressions. */
3133 /* Save the function value return registers, if we care.
3134 We might be about to restore their previous contents. */
3135 if (proceed_to_finish
)
3136 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
3138 if (stop_stack_dummy
)
3140 /* Pop the empty frame that contains the stack dummy.
3141 POP_FRAME ends with a setting of the current frame, so we
3142 can use that next. */
3144 /* Set stop_pc to what it was before we called the function.
3145 Can't rely on restore_inferior_status because that only gets
3146 called if we don't stop in the called function. */
3147 stop_pc
= read_pc ();
3148 select_frame (get_current_frame (), 0);
3152 TUIDO (((TuiOpaqueFuncPtr
) tui_vCheckDataValues
, selected_frame
));
3155 annotate_stopped ();
3159 hook_stop_stub (cmd
)
3162 execute_user_command ((struct cmd_list_element
*) cmd
, 0);
3167 signal_stop_state (signo
)
3170 return signal_stop
[signo
];
3174 signal_print_state (signo
)
3177 return signal_print
[signo
];
3181 signal_pass_state (signo
)
3184 return signal_program
[signo
];
3191 Signal Stop\tPrint\tPass to program\tDescription\n");
3195 sig_print_info (oursig
)
3196 enum target_signal oursig
;
3198 char *name
= target_signal_to_name (oursig
);
3199 int name_padding
= 13 - strlen (name
);
3200 if (name_padding
<= 0)
3203 printf_filtered ("%s", name
);
3204 printf_filtered ("%*.*s ", name_padding
, name_padding
,
3206 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3207 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3208 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3209 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3212 /* Specify how various signals in the inferior should be handled. */
3215 handle_command (args
, from_tty
)
3220 int digits
, wordlen
;
3221 int sigfirst
, signum
, siglast
;
3222 enum target_signal oursig
;
3225 unsigned char *sigs
;
3226 struct cleanup
*old_chain
;
3230 error_no_arg ("signal to handle");
3233 /* Allocate and zero an array of flags for which signals to handle. */
3235 nsigs
= (int) TARGET_SIGNAL_LAST
;
3236 sigs
= (unsigned char *) alloca (nsigs
);
3237 memset (sigs
, 0, nsigs
);
3239 /* Break the command line up into args. */
3241 argv
= buildargv (args
);
3246 old_chain
= make_cleanup_freeargv (argv
);
3248 /* Walk through the args, looking for signal oursigs, signal names, and
3249 actions. Signal numbers and signal names may be interspersed with
3250 actions, with the actions being performed for all signals cumulatively
3251 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3253 while (*argv
!= NULL
)
3255 wordlen
= strlen (*argv
);
3256 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3260 sigfirst
= siglast
= -1;
3262 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3264 /* Apply action to all signals except those used by the
3265 debugger. Silently skip those. */
3268 siglast
= nsigs
- 1;
3270 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3272 SET_SIGS (nsigs
, sigs
, signal_stop
);
3273 SET_SIGS (nsigs
, sigs
, signal_print
);
3275 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3277 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3279 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3281 SET_SIGS (nsigs
, sigs
, signal_print
);
3283 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3285 SET_SIGS (nsigs
, sigs
, signal_program
);
3287 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3289 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3291 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3293 SET_SIGS (nsigs
, sigs
, signal_program
);
3295 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3297 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3298 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3300 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3302 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3304 else if (digits
> 0)
3306 /* It is numeric. The numeric signal refers to our own
3307 internal signal numbering from target.h, not to host/target
3308 signal number. This is a feature; users really should be
3309 using symbolic names anyway, and the common ones like
3310 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3312 sigfirst
= siglast
= (int)
3313 target_signal_from_command (atoi (*argv
));
3314 if ((*argv
)[digits
] == '-')
3317 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3319 if (sigfirst
> siglast
)
3321 /* Bet he didn't figure we'd think of this case... */
3329 oursig
= target_signal_from_name (*argv
);
3330 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3332 sigfirst
= siglast
= (int) oursig
;
3336 /* Not a number and not a recognized flag word => complain. */
3337 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3341 /* If any signal numbers or symbol names were found, set flags for
3342 which signals to apply actions to. */
3344 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3346 switch ((enum target_signal
) signum
)
3348 case TARGET_SIGNAL_TRAP
:
3349 case TARGET_SIGNAL_INT
:
3350 if (!allsigs
&& !sigs
[signum
])
3352 if (query ("%s is used by the debugger.\n\
3353 Are you sure you want to change it? ",
3354 target_signal_to_name
3355 ((enum target_signal
) signum
)))
3361 printf_unfiltered ("Not confirmed, unchanged.\n");
3362 gdb_flush (gdb_stdout
);
3366 case TARGET_SIGNAL_0
:
3367 case TARGET_SIGNAL_DEFAULT
:
3368 case TARGET_SIGNAL_UNKNOWN
:
3369 /* Make sure that "all" doesn't print these. */
3380 target_notice_signals (inferior_pid
);
3384 /* Show the results. */
3385 sig_print_header ();
3386 for (signum
= 0; signum
< nsigs
; signum
++)
3390 sig_print_info (signum
);
3395 do_cleanups (old_chain
);
3399 xdb_handle_command (args
, from_tty
)
3404 struct cleanup
*old_chain
;
3406 /* Break the command line up into args. */
3408 argv
= buildargv (args
);
3413 old_chain
= make_cleanup_freeargv (argv
);
3414 if (argv
[1] != (char *) NULL
)
3419 bufLen
= strlen (argv
[0]) + 20;
3420 argBuf
= (char *) xmalloc (bufLen
);
3424 enum target_signal oursig
;
3426 oursig
= target_signal_from_name (argv
[0]);
3427 memset (argBuf
, 0, bufLen
);
3428 if (strcmp (argv
[1], "Q") == 0)
3429 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3432 if (strcmp (argv
[1], "s") == 0)
3434 if (!signal_stop
[oursig
])
3435 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3437 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3439 else if (strcmp (argv
[1], "i") == 0)
3441 if (!signal_program
[oursig
])
3442 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3444 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3446 else if (strcmp (argv
[1], "r") == 0)
3448 if (!signal_print
[oursig
])
3449 sprintf (argBuf
, "%s %s", argv
[0], "print");
3451 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3457 handle_command (argBuf
, from_tty
);
3459 printf_filtered ("Invalid signal handling flag.\n");
3464 do_cleanups (old_chain
);
3467 /* Print current contents of the tables set by the handle command.
3468 It is possible we should just be printing signals actually used
3469 by the current target (but for things to work right when switching
3470 targets, all signals should be in the signal tables). */
3473 signals_info (signum_exp
, from_tty
)
3477 enum target_signal oursig
;
3478 sig_print_header ();
3482 /* First see if this is a symbol name. */
3483 oursig
= target_signal_from_name (signum_exp
);
3484 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3486 /* No, try numeric. */
3488 target_signal_from_command (parse_and_eval_address (signum_exp
));
3490 sig_print_info (oursig
);
3494 printf_filtered ("\n");
3495 /* These ugly casts brought to you by the native VAX compiler. */
3496 for (oursig
= TARGET_SIGNAL_FIRST
;
3497 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3498 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3502 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3503 && oursig
!= TARGET_SIGNAL_DEFAULT
3504 && oursig
!= TARGET_SIGNAL_0
)
3505 sig_print_info (oursig
);
3508 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3511 struct inferior_status
3513 enum target_signal stop_signal
;
3517 int stop_stack_dummy
;
3518 int stopped_by_random_signal
;
3520 CORE_ADDR step_range_start
;
3521 CORE_ADDR step_range_end
;
3522 CORE_ADDR step_frame_address
;
3523 int step_over_calls
;
3524 CORE_ADDR step_resume_break_address
;
3525 int stop_after_trap
;
3526 int stop_soon_quietly
;
3527 CORE_ADDR selected_frame_address
;
3528 char *stop_registers
;
3530 /* These are here because if call_function_by_hand has written some
3531 registers and then decides to call error(), we better not have changed
3536 int breakpoint_proceeded
;
3537 int restore_stack_info
;
3538 int proceed_to_finish
;
3542 static struct inferior_status
*xmalloc_inferior_status
PARAMS ((void));
3543 static struct inferior_status
*
3544 xmalloc_inferior_status ()
3546 struct inferior_status
*inf_status
;
3547 inf_status
= xmalloc (sizeof (struct inferior_status
));
3548 inf_status
->stop_registers
= xmalloc (REGISTER_BYTES
);
3549 inf_status
->registers
= xmalloc (REGISTER_BYTES
);
3553 static void free_inferior_status
PARAMS ((struct inferior_status
*));
3555 free_inferior_status (inf_status
)
3556 struct inferior_status
*inf_status
;
3558 free (inf_status
->registers
);
3559 free (inf_status
->stop_registers
);
3564 write_inferior_status_register (inf_status
, regno
, val
)
3565 struct inferior_status
*inf_status
;
3569 int size
= REGISTER_RAW_SIZE(regno
);
3570 void *buf
= alloca (size
);
3571 store_signed_integer (buf
, size
, val
);
3572 memcpy (&inf_status
->registers
[REGISTER_BYTE (regno
)], buf
, size
);
3577 /* Save all of the information associated with the inferior<==>gdb
3578 connection. INF_STATUS is a pointer to a "struct inferior_status"
3579 (defined in inferior.h). */
3581 struct inferior_status
*
3582 save_inferior_status (restore_stack_info
)
3583 int restore_stack_info
;
3585 struct inferior_status
*inf_status
= xmalloc_inferior_status ();
3587 inf_status
->stop_signal
= stop_signal
;
3588 inf_status
->stop_pc
= stop_pc
;
3589 inf_status
->stop_step
= stop_step
;
3590 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3591 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3592 inf_status
->trap_expected
= trap_expected
;
3593 inf_status
->step_range_start
= step_range_start
;
3594 inf_status
->step_range_end
= step_range_end
;
3595 inf_status
->step_frame_address
= step_frame_address
;
3596 inf_status
->step_over_calls
= step_over_calls
;
3597 inf_status
->stop_after_trap
= stop_after_trap
;
3598 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3599 /* Save original bpstat chain here; replace it with copy of chain.
3600 If caller's caller is walking the chain, they'll be happier if we
3601 hand them back the original chain when restore_inferior_status is
3603 inf_status
->stop_bpstat
= stop_bpstat
;
3604 stop_bpstat
= bpstat_copy (stop_bpstat
);
3605 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3606 inf_status
->restore_stack_info
= restore_stack_info
;
3607 inf_status
->proceed_to_finish
= proceed_to_finish
;
3609 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
3611 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3613 record_selected_frame (&(inf_status
->selected_frame_address
),
3614 &(inf_status
->selected_level
));
3618 struct restore_selected_frame_args
3620 CORE_ADDR frame_address
;
3624 static int restore_selected_frame
PARAMS ((PTR
));
3627 restore_selected_frame (args
)
3630 struct restore_selected_frame_args
*fr
=
3631 (struct restore_selected_frame_args
*) args
;
3632 struct frame_info
*frame
;
3633 int level
= fr
->level
;
3635 frame
= find_relative_frame (get_current_frame (), &level
);
3637 /* If inf_status->selected_frame_address is NULL, there was no
3638 previously selected frame. */
3639 if (frame
== NULL
||
3640 /* FRAME_FP (frame) != fr->frame_address || */
3641 /* elz: deleted this check as a quick fix to the problem that
3642 for function called by hand gdb creates no internal frame
3643 structure and the real stack and gdb's idea of stack are
3644 different if nested calls by hands are made.
3646 mvs: this worries me. */
3649 warning ("Unable to restore previously selected frame.\n");
3653 select_frame (frame
, fr
->level
);
3659 restore_inferior_status (inf_status
)
3660 struct inferior_status
*inf_status
;
3662 stop_signal
= inf_status
->stop_signal
;
3663 stop_pc
= inf_status
->stop_pc
;
3664 stop_step
= inf_status
->stop_step
;
3665 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3666 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3667 trap_expected
= inf_status
->trap_expected
;
3668 step_range_start
= inf_status
->step_range_start
;
3669 step_range_end
= inf_status
->step_range_end
;
3670 step_frame_address
= inf_status
->step_frame_address
;
3671 step_over_calls
= inf_status
->step_over_calls
;
3672 stop_after_trap
= inf_status
->stop_after_trap
;
3673 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
3674 bpstat_clear (&stop_bpstat
);
3675 stop_bpstat
= inf_status
->stop_bpstat
;
3676 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3677 proceed_to_finish
= inf_status
->proceed_to_finish
;
3679 /* FIXME: Is the restore of stop_registers always needed */
3680 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
3682 /* The inferior can be gone if the user types "print exit(0)"
3683 (and perhaps other times). */
3684 if (target_has_execution
)
3685 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3687 /* FIXME: If we are being called after stopping in a function which
3688 is called from gdb, we should not be trying to restore the
3689 selected frame; it just prints a spurious error message (The
3690 message is useful, however, in detecting bugs in gdb (like if gdb
3691 clobbers the stack)). In fact, should we be restoring the
3692 inferior status at all in that case? . */
3694 if (target_has_stack
&& inf_status
->restore_stack_info
)
3696 struct restore_selected_frame_args fr
;
3697 fr
.level
= inf_status
->selected_level
;
3698 fr
.frame_address
= inf_status
->selected_frame_address
;
3699 /* The point of catch_errors is that if the stack is clobbered,
3700 walking the stack might encounter a garbage pointer and error()
3701 trying to dereference it. */
3702 if (catch_errors (restore_selected_frame
, &fr
,
3703 "Unable to restore previously selected frame:\n",
3704 RETURN_MASK_ERROR
) == 0)
3705 /* Error in restoring the selected frame. Select the innermost
3709 select_frame (get_current_frame (), 0);
3713 free_inferior_status (inf_status
);
3717 discard_inferior_status (inf_status
)
3718 struct inferior_status
*inf_status
;
3720 /* See save_inferior_status for info on stop_bpstat. */
3721 bpstat_clear (&inf_status
->stop_bpstat
);
3722 free_inferior_status (inf_status
);
3726 set_follow_fork_mode_command (arg
, from_tty
, c
)
3729 struct cmd_list_element
*c
;
3731 if (!STREQ (arg
, "parent") &&
3732 !STREQ (arg
, "child") &&
3733 !STREQ (arg
, "both") &&
3734 !STREQ (arg
, "ask"))
3735 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
3737 if (follow_fork_mode_string
!= NULL
)
3738 free (follow_fork_mode_string
);
3739 follow_fork_mode_string
= savestring (arg
, strlen (arg
));
3744 static void build_infrun
PARAMS ((void));
3748 stop_registers
= xmalloc (REGISTER_BYTES
);
3753 _initialize_infrun ()
3756 register int numsigs
;
3757 struct cmd_list_element
*c
;
3761 add_info ("signals", signals_info
,
3762 "What debugger does when program gets various signals.\n\
3763 Specify a signal as argument to print info on that signal only.");
3764 add_info_alias ("handle", "signals", 0);
3766 add_com ("handle", class_run
, handle_command
,
3767 concat ("Specify how to handle a signal.\n\
3768 Args are signals and actions to apply to those signals.\n\
3769 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3770 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3771 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3772 The special arg \"all\" is recognized to mean all signals except those\n\
3773 used by the debugger, typically SIGTRAP and SIGINT.\n",
3774 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3775 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3776 Stop means reenter debugger if this signal happens (implies print).\n\
3777 Print means print a message if this signal happens.\n\
3778 Pass means let program see this signal; otherwise program doesn't know.\n\
3779 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3780 Pass and Stop may be combined.", NULL
));
3783 add_com ("lz", class_info
, signals_info
,
3784 "What debugger does when program gets various signals.\n\
3785 Specify a signal as argument to print info on that signal only.");
3786 add_com ("z", class_run
, xdb_handle_command
,
3787 concat ("Specify how to handle a signal.\n\
3788 Args are signals and actions to apply to those signals.\n\
3789 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3790 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3791 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3792 The special arg \"all\" is recognized to mean all signals except those\n\
3793 used by the debugger, typically SIGTRAP and SIGINT.\n",
3794 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3795 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3796 nopass), \"Q\" (noprint)\n\
3797 Stop means reenter debugger if this signal happens (implies print).\n\
3798 Print means print a message if this signal happens.\n\
3799 Pass means let program see this signal; otherwise program doesn't know.\n\
3800 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3801 Pass and Stop may be combined.", NULL
));
3805 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
3806 "There is no `stop' command, but you can set a hook on `stop'.\n\
3807 This allows you to set a list of commands to be run each time execution\n\
3808 of the program stops.", &cmdlist
);
3810 numsigs
= (int) TARGET_SIGNAL_LAST
;
3811 signal_stop
= (unsigned char *)
3812 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
3813 signal_print
= (unsigned char *)
3814 xmalloc (sizeof (signal_print
[0]) * numsigs
);
3815 signal_program
= (unsigned char *)
3816 xmalloc (sizeof (signal_program
[0]) * numsigs
);
3817 for (i
= 0; i
< numsigs
; i
++)
3820 signal_print
[i
] = 1;
3821 signal_program
[i
] = 1;
3824 /* Signals caused by debugger's own actions
3825 should not be given to the program afterwards. */
3826 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
3827 signal_program
[TARGET_SIGNAL_INT
] = 0;
3829 /* Signals that are not errors should not normally enter the debugger. */
3830 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
3831 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
3832 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
3833 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
3834 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
3835 signal_print
[TARGET_SIGNAL_PROF
] = 0;
3836 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
3837 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
3838 signal_stop
[TARGET_SIGNAL_IO
] = 0;
3839 signal_print
[TARGET_SIGNAL_IO
] = 0;
3840 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
3841 signal_print
[TARGET_SIGNAL_POLL
] = 0;
3842 signal_stop
[TARGET_SIGNAL_URG
] = 0;
3843 signal_print
[TARGET_SIGNAL_URG
] = 0;
3844 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
3845 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
3847 /* These signals are used internally by user-level thread
3848 implementations. (See signal(5) on Solaris.) Like the above
3849 signals, a healthy program receives and handles them as part of
3850 its normal operation. */
3851 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
3852 signal_print
[TARGET_SIGNAL_LWP
] = 0;
3853 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
3854 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
3855 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
3856 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
3860 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
3861 (char *) &stop_on_solib_events
,
3862 "Set stopping for shared library events.\n\
3863 If nonzero, gdb will give control to the user when the dynamic linker\n\
3864 notifies gdb of shared library events. The most common event of interest\n\
3865 to the user would be loading/unloading of a new library.\n",
3870 c
= add_set_enum_cmd ("follow-fork-mode",
3872 follow_fork_mode_kind_names
,
3873 (char *) &follow_fork_mode_string
,
3874 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
3875 kernel problem. It's also not terribly useful without a GUI to
3876 help the user drive two debuggers. So for now, I'm disabling
3877 the "both" option. */
3878 /* "Set debugger response to a program call of fork \
3880 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3881 parent - the original process is debugged after a fork\n\
3882 child - the new process is debugged after a fork\n\
3883 both - both the parent and child are debugged after a fork\n\
3884 ask - the debugger will ask for one of the above choices\n\
3885 For \"both\", another copy of the debugger will be started to follow\n\
3886 the new child process. The original debugger will continue to follow\n\
3887 the original parent process. To distinguish their prompts, the\n\
3888 debugger copy's prompt will be changed.\n\
3889 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3890 By default, the debugger will follow the parent process.",
3892 "Set debugger response to a program call of fork \
3894 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3895 parent - the original process is debugged after a fork\n\
3896 child - the new process is debugged after a fork\n\
3897 ask - the debugger will ask for one of the above choices\n\
3898 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3899 By default, the debugger will follow the parent process.",
3901 /* c->function.sfunc = ;*/
3902 add_show_from_set (c
, &showlist
);
3904 set_follow_fork_mode_command ("parent", 0, NULL
);
3906 c
= add_set_enum_cmd ("scheduler-locking", class_run
,
3907 scheduler_enums
, /* array of string names */
3908 (char *) &scheduler_mode
, /* current mode */
3909 "Set mode for locking scheduler during execution.\n\
3910 off == no locking (threads may preempt at any time)\n\
3911 on == full locking (no thread except the current thread may run)\n\
3912 step == scheduler locked during every single-step operation.\n\
3913 In this mode, no other thread may run during a step command.\n\
3914 Other threads may run while stepping over a function call ('next').",
3917 c
->function
.sfunc
= set_schedlock_func
; /* traps on target vector */
3918 add_show_from_set (c
, &showlist
);