1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
27 #include "breakpoint.h"
32 #include "gdbthread.h"
34 #include "symfile.h" /* for overlay functions */
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 ((char *));
52 static void delete_breakpoint_current_contents
PARAMS ((PTR
));
54 int inferior_ignoring_startup_exec_events
= 0;
55 int inferior_ignoring_leading_exec_events
= 0;
58 /* wait_for_inferior and normal_stop use this to notify the user
59 when the inferior stopped in a different thread than it had been
61 static int switched_from_inferior_pid
;
64 /* resume and wait_for_inferior use this to ensure that when
65 stepping over a hit breakpoint in a threaded application
66 only the thread that hit the breakpoint is stepped and the
67 other threads don't continue. This prevents having another
68 thread run past the breakpoint while it is temporarily
71 This is not thread-specific, so it isn't saved as part of
74 Versions of gdb which don't use the "step == this thread steps
75 and others continue" model but instead use the "step == this
76 thread steps and others wait" shouldn't do this. */
77 static int thread_step_needed
= 0;
79 void _initialize_infrun
PARAMS ((void));
81 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
82 program. It needs to examine the jmp_buf argument and extract the PC
83 from it. The return value is non-zero on success, zero otherwise. */
85 #ifndef GET_LONGJMP_TARGET
86 #define GET_LONGJMP_TARGET(PC_ADDR) 0
90 /* Some machines have trampoline code that sits between function callers
91 and the actual functions themselves. If this machine doesn't have
92 such things, disable their processing. */
94 #ifndef SKIP_TRAMPOLINE_CODE
95 #define SKIP_TRAMPOLINE_CODE(pc) 0
98 /* Dynamic function trampolines are similar to solib trampolines in that they
99 are between the caller and the callee. The difference is that when you
100 enter a dynamic trampoline, you can't determine the callee's address. Some
101 (usually complex) code needs to run in the dynamic trampoline to figure out
102 the callee's address. This macro is usually called twice. First, when we
103 enter the trampoline (looks like a normal function call at that point). It
104 should return the PC of a point within the trampoline where the callee's
105 address is known. Second, when we hit the breakpoint, this routine returns
106 the callee's address. At that point, things proceed as per a step resume
109 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
110 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
113 /* On SVR4 based systems, determining the callee's address is exceedingly
114 difficult and depends on the implementation of the run time loader.
115 If we are stepping at the source level, we single step until we exit
116 the run time loader code and reach the callee's address. */
118 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
119 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
122 /* For SVR4 shared libraries, each call goes through a small piece of
123 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
124 to nonzero if we are current stopped in one of these. */
126 #ifndef IN_SOLIB_CALL_TRAMPOLINE
127 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
130 /* In some shared library schemes, the return path from a shared library
131 call may need to go through a trampoline too. */
133 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
134 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
137 /* On MIPS16, a function that returns a floating point value may call
138 a library helper function to copy the return value to a floating point
139 register. The IGNORE_HELPER_CALL macro returns non-zero if we
140 should ignore (i.e. step over) this function call. */
141 #ifndef IGNORE_HELPER_CALL
142 #define IGNORE_HELPER_CALL(pc) 0
145 /* On some systems, the PC may be left pointing at an instruction that won't
146 actually be executed. This is usually indicated by a bit in the PSW. If
147 we find ourselves in such a state, then we step the target beyond the
148 nullified instruction before returning control to the user so as to avoid
151 #ifndef INSTRUCTION_NULLIFIED
152 #define INSTRUCTION_NULLIFIED 0
155 /* Tables of how to react to signals; the user sets them. */
157 static unsigned char *signal_stop
;
158 static unsigned char *signal_print
;
159 static unsigned char *signal_program
;
161 #define SET_SIGS(nsigs,sigs,flags) \
163 int signum = (nsigs); \
164 while (signum-- > 0) \
165 if ((sigs)[signum]) \
166 (flags)[signum] = 1; \
169 #define UNSET_SIGS(nsigs,sigs,flags) \
171 int signum = (nsigs); \
172 while (signum-- > 0) \
173 if ((sigs)[signum]) \
174 (flags)[signum] = 0; \
178 /* Command list pointer for the "stop" placeholder. */
180 static struct cmd_list_element
*stop_command
;
182 /* Nonzero if breakpoints are now inserted in the inferior. */
184 static int breakpoints_inserted
;
186 /* Function inferior was in as of last step command. */
188 static struct symbol
*step_start_function
;
190 /* Nonzero if we are expecting a trace trap and should proceed from it. */
192 static int trap_expected
;
195 /* Nonzero if we want to give control to the user when we're notified
196 of shared library events by the dynamic linker. */
197 static int stop_on_solib_events
;
201 /* Nonzero if the next time we try to continue the inferior, it will
202 step one instruction and generate a spurious trace trap.
203 This is used to compensate for a bug in HP-UX. */
205 static int trap_expected_after_continue
;
208 /* Nonzero means expecting a trace trap
209 and should stop the inferior and return silently when it happens. */
213 /* Nonzero means expecting a trap and caller will handle it themselves.
214 It is used after attach, due to attaching to a process;
215 when running in the shell before the child program has been exec'd;
216 and when running some kinds of remote stuff (FIXME?). */
218 int stop_soon_quietly
;
220 /* Nonzero if proceed is being used for a "finish" command or a similar
221 situation when stop_registers should be saved. */
223 int proceed_to_finish
;
225 /* Save register contents here when about to pop a stack dummy frame,
226 if-and-only-if proceed_to_finish is set.
227 Thus this contains the return value from the called function (assuming
228 values are returned in a register). */
230 char stop_registers
[REGISTER_BYTES
];
232 /* Nonzero if program stopped due to error trying to insert breakpoints. */
234 static int breakpoints_failed
;
236 /* Nonzero after stop if current stack frame should be printed. */
238 static int stop_print_frame
;
240 static struct breakpoint
*step_resume_breakpoint
= NULL
;
241 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
243 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
244 interactions with an inferior that is running a kernel function
245 (aka, a system call or "syscall"). wait_for_inferior therefore
246 may have a need to know when the inferior is in a syscall. This
247 is a count of the number of inferior threads which are known to
248 currently be running in a syscall. */
249 static int number_of_threads_in_syscalls
;
251 /* This is used to remember when a fork, vfork or exec event
252 was caught by a catchpoint, and thus the event is to be
253 followed at the next resume of the inferior, and not
256 enum target_waitkind kind
;
264 char * execd_pathname
;
267 /* Some platforms don't allow us to do anything meaningful with a
268 vforked child until it has exec'd. Vforked processes on such
269 platforms can only be followed after they've exec'd.
271 When this is set to 0, a vfork can be immediately followed,
272 and an exec can be followed merely as an exec. When this is
273 set to 1, a vfork event has been seen, but cannot be followed
274 until the exec is seen.
276 (In the latter case, inferior_pid is still the parent of the
277 vfork, and pending_follow.fork_event.child_pid is the child. The
278 appropriate process is followed, according to the setting of
279 follow-fork-mode.) */
280 static int follow_vfork_when_exec
;
282 static char * follow_fork_mode_kind_names
[] = {
283 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
284 kernel problem. It's also not terribly useful without a GUI to
285 help the user drive two debuggers. So for now, I'm disabling
287 "parent", "child", "both", "ask" };
289 "parent", "child", "ask" };
291 static char * follow_fork_mode_string
= NULL
;
294 #if defined(HPUXHPPA)
296 follow_inferior_fork (parent_pid
, child_pid
, has_forked
, has_vforked
)
302 int followed_parent
= 0;
303 int followed_child
= 0;
306 /* Which process did the user want us to follow? */
308 savestring (follow_fork_mode_string
, strlen (follow_fork_mode_string
));
310 /* Or, did the user not know, and want us to ask? */
311 if (STREQ (follow_fork_mode_string
, "ask"))
313 char requested_mode
[100];
316 error ("\"ask\" mode NYI");
317 follow_mode
= savestring (requested_mode
, strlen (requested_mode
));
320 /* If we're to be following the parent, then detach from child_pid.
321 We're already following the parent, so need do nothing explicit
323 if (STREQ (follow_mode
, "parent"))
327 /* We're already attached to the parent, by default. */
329 /* Before detaching from the child, remove all breakpoints from
330 it. (This won't actually modify the breakpoint list, but will
331 physically remove the breakpoints from the child.) */
332 if (! has_vforked
|| ! follow_vfork_when_exec
)
334 detach_breakpoints (child_pid
);
335 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
338 /* Detach from the child. */
341 target_require_detach (child_pid
, "", 1);
344 /* If we're to be following the child, then attach to it, detach
345 from inferior_pid, and set inferior_pid to child_pid. */
346 else if (STREQ (follow_mode
, "child"))
348 char child_pid_spelling
[100]; /* Arbitrary length. */
352 /* Before detaching from the parent, detach all breakpoints from
353 the child. But only if we're forking, or if we follow vforks
354 as soon as they happen. (If we're following vforks only when
355 the child has exec'd, then it's very wrong to try to write
356 back the "shadow contents" of inserted breakpoints now -- they
357 belong to the child's pre-exec'd a.out.) */
358 if (! has_vforked
|| ! follow_vfork_when_exec
)
360 detach_breakpoints (child_pid
);
363 /* Before detaching from the parent, remove all breakpoints from it. */
364 remove_breakpoints ();
366 /* Also reset the solib inferior hook from the parent. */
367 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid
);
369 /* Detach from the parent. */
371 target_detach (NULL
, 1);
373 /* Attach to the child. */
374 inferior_pid
= child_pid
;
375 sprintf (child_pid_spelling
, "%d", child_pid
);
378 target_require_attach (child_pid_spelling
, 1);
380 /* Was there a step_resume breakpoint? (There was if the user
381 did a "next" at the fork() call.) If so, explicitly reset its
384 step_resumes are a form of bp that are made to be per-thread.
385 Since we created the step_resume bp when the parent process
386 was being debugged, and now are switching to the child process,
387 from the breakpoint package's viewpoint, that's a switch of
388 "threads". We must update the bp's notion of which thread
389 it is for, or it'll be ignored when it triggers... */
390 if (step_resume_breakpoint
&& (! has_vforked
|| ! follow_vfork_when_exec
))
391 breakpoint_re_set_thread (step_resume_breakpoint
);
393 /* Reinsert all breakpoints in the child. (The user may've set
394 breakpoints after catching the fork, in which case those
395 actually didn't get set in the child, but only in the parent.) */
396 if (! has_vforked
|| ! follow_vfork_when_exec
)
398 breakpoint_re_set ();
399 insert_breakpoints ();
403 /* If we're to be following both parent and child, then fork ourselves,
404 and attach the debugger clone to the child. */
405 else if (STREQ (follow_mode
, "both"))
407 char pid_suffix
[100]; /* Arbitrary length. */
409 /* Clone ourselves to follow the child. This is the end of our
410 involvement with child_pid; our clone will take it from here... */
412 target_clone_and_follow_inferior (child_pid
, &followed_child
);
413 followed_parent
= !followed_child
;
415 /* We continue to follow the parent. To help distinguish the two
416 debuggers, though, both we and our clone will reset our prompts. */
417 sprintf (pid_suffix
, "[%d] ", inferior_pid
);
418 set_prompt (strcat (get_prompt (), pid_suffix
));
421 /* The parent and child of a vfork share the same address space.
422 Also, on some targets the order in which vfork and exec events
423 are received for parent in child requires some delicate handling
426 For instance, on ptrace-based HPUX we receive the child's vfork
427 event first, at which time the parent has been suspended by the
428 OS and is essentially untouchable until the child's exit or second
429 exec event arrives. At that time, the parent's vfork event is
430 delivered to us, and that's when we see and decide how to follow
431 the vfork. But to get to that point, we must continue the child
432 until it execs or exits. To do that smoothly, all breakpoints
433 must be removed from the child, in case there are any set between
434 the vfork() and exec() calls. But removing them from the child
435 also removes them from the parent, due to the shared-address-space
436 nature of a vfork'd parent and child. On HPUX, therefore, we must
437 take care to restore the bp's to the parent before we continue it.
438 Else, it's likely that we may not stop in the expected place. (The
439 worst scenario is when the user tries to step over a vfork() call;
440 the step-resume bp must be restored for the step to properly stop
441 in the parent after the call completes!)
443 Sequence of events, as reported to gdb from HPUX:
445 Parent Child Action for gdb to take
446 -------------------------------------------------------
447 1 VFORK Continue child
453 target_post_follow_vfork (parent_pid
,
459 pending_follow
.fork_event
.saw_parent_fork
= 0;
460 pending_follow
.fork_event
.saw_child_fork
= 0;
466 follow_fork (parent_pid
, child_pid
)
470 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
474 /* Forward declaration. */
475 static void follow_exec
PARAMS((int, char *));
478 follow_vfork (parent_pid
, child_pid
)
482 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
484 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
485 if (pending_follow
.fork_event
.saw_child_exec
&& (inferior_pid
== child_pid
))
487 pending_follow
.fork_event
.saw_child_exec
= 0;
488 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
489 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
490 free (pending_follow
.execd_pathname
);
493 #endif /* HPUXHPPA */
496 follow_exec (pid
, execd_pathname
)
498 char * execd_pathname
;
502 extern struct target_ops child_ops
;
504 /* Did this exec() follow a vfork()? If so, we must follow the
505 vfork now too. Do it before following the exec. */
506 if (follow_vfork_when_exec
&& (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
))
508 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
509 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
510 follow_vfork_when_exec
= 0;
511 saved_pid
= inferior_pid
;
513 /* Did we follow the parent? If so, we're done. If we followed
514 the child then we must also follow its exec(). */
515 if (inferior_pid
== pending_follow
.fork_event
.parent_pid
)
519 /* This is an exec event that we actually wish to pay attention to.
520 Refresh our symbol table to the newly exec'd program, remove any
523 If there are breakpoints, they aren't really inserted now,
524 since the exec() transformed our inferior into a fresh set
527 We want to preserve symbolic breakpoints on the list, since
528 we have hopes that they can be reset after the new a.out's
529 symbol table is read.
531 However, any "raw" breakpoints must be removed from the list
532 (e.g., the solib bp's), since their address is probably invalid
535 And, we DON'T want to call delete_breakpoints() here, since
536 that may write the bp's "shadow contents" (the instruction
537 value that was overwritten witha TRAP instruction). Since
538 we now have a new a.out, those shadow contents aren't valid. */
539 update_breakpoints_after_exec ();
541 /* If there was one, it's gone now. We cannot truly step-to-next
542 statement through an exec(). */
543 step_resume_breakpoint
= NULL
;
544 step_range_start
= 0;
547 /* If there was one, it's gone now. */
548 through_sigtramp_breakpoint
= NULL
;
550 /* What is this a.out's name? */
551 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
553 /* We've followed the inferior through an exec. Therefore, the
554 inferior has essentially been killed & reborn. */
555 gdb_flush (gdb_stdout
);
556 target_mourn_inferior ();
557 inferior_pid
= saved_pid
; /* Because mourn_inferior resets inferior_pid. */
558 push_target (&child_ops
);
560 /* That a.out is now the one to use. */
561 exec_file_attach (execd_pathname
, 0);
563 /* And also is where symbols can be found. */
564 symbol_file_command (execd_pathname
, 0);
566 /* Reset the shared library package. This ensures that we get
567 a shlib event when the child reaches "_start", at which point
568 the dld will have had a chance to initialize the child. */
570 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid
);
572 /* Reinsert all breakpoints. (Those which were symbolic have
573 been reset to the proper address in the new a.out, thanks
574 to symbol_file_command...) */
575 insert_breakpoints ();
577 /* The next resume of this inferior should bring it to the shlib
578 startup breakpoints. (If the user had also set bp's on
579 "main" from the old (parent) process, then they'll auto-
580 matically get reset there in the new process.) */
584 /* Non-zero if we just simulating a single-step. This is needed
585 because we cannot remove the breakpoints in the inferior process
586 until after the `wait' in `wait_for_inferior'. */
587 static int singlestep_breakpoints_inserted_p
= 0;
590 /* Things to clean up if we QUIT out of resume (). */
593 resume_cleanups (arg
)
599 /* Resume the inferior, but allow a QUIT. This is useful if the user
600 wants to interrupt some lengthy single-stepping operation
601 (for child processes, the SIGINT goes to the inferior, and so
602 we get a SIGINT random_signal, but for remote debugging and perhaps
603 other targets, that's not true).
605 STEP nonzero if we should step (zero to continue instead).
606 SIG is the signal to give the inferior (zero for none). */
610 enum target_signal sig
;
612 int should_resume
= 1;
613 struct cleanup
*old_cleanups
= make_cleanup ((make_cleanup_func
)
617 #ifdef CANNOT_STEP_BREAKPOINT
618 /* Most targets can step a breakpoint instruction, thus executing it
619 normally. But if this one cannot, just continue and we will hit
621 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
625 if (SOFTWARE_SINGLE_STEP_P
&& step
)
627 /* Do it the hard way, w/temp breakpoints */
628 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints*/);
629 /* ...and don't ask hardware to do it. */
631 /* and do not pull these breakpoints until after a `wait' in
632 `wait_for_inferior' */
633 singlestep_breakpoints_inserted_p
= 1;
636 /* Handle any optimized stores to the inferior NOW... */
637 #ifdef DO_DEFERRED_STORES
642 /* If there were any forks/vforks/execs that were caught and are
643 now to be followed, then do so. */
644 switch (pending_follow
.kind
)
646 case (TARGET_WAITKIND_FORKED
):
647 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
648 follow_fork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
651 case (TARGET_WAITKIND_VFORKED
):
653 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
655 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
656 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
658 /* Did we follow the child, but not yet see the child's exec event?
659 If so, then it actually ought to be waiting for us; we respond to
660 parent vfork events. We don't actually want to resume the child
661 in this situation; we want to just get its exec event. */
662 if (! saw_child_exec
&& (inferior_pid
== pending_follow
.fork_event
.child_pid
))
667 case (TARGET_WAITKIND_EXECD
):
668 /* If we saw a vfork event but couldn't follow it until we saw
669 an exec, then now might be the time! */
670 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
671 /* follow_exec is called as soon as the exec event is seen. */
677 #endif /* HPUXHPPA */
679 /* Install inferior's terminal modes. */
680 target_terminal_inferior ();
685 if (thread_step_needed
)
687 /* We stopped on a BPT instruction;
688 don't continue other threads and
689 just step this thread. */
690 thread_step_needed
= 0;
692 if (!breakpoint_here_p(read_pc()))
694 /* Breakpoint deleted: ok to do regular resume
695 where all the threads either step or continue. */
696 target_resume (-1, step
, sig
);
702 warning ( "Internal error, changing continue to step." );
703 remove_breakpoints ();
704 breakpoints_inserted
= 0;
709 target_resume (inferior_pid
, step
, sig
);
713 #endif /* HPUXHPPA */
715 /* Vanilla resume. */
716 target_resume (-1, step
, sig
);
719 discard_cleanups (old_cleanups
);
723 /* Clear out all variables saying what to do when inferior is continued.
724 First do this, then set the ones you want, then call `proceed'. */
727 clear_proceed_status ()
730 step_range_start
= 0;
732 step_frame_address
= 0;
733 step_over_calls
= -1;
735 stop_soon_quietly
= 0;
736 proceed_to_finish
= 0;
737 breakpoint_proceeded
= 1; /* We're about to proceed... */
739 /* Discard any remaining commands or status from previous stop. */
740 bpstat_clear (&stop_bpstat
);
743 /* Basic routine for continuing the program in various fashions.
745 ADDR is the address to resume at, or -1 for resume where stopped.
746 SIGGNAL is the signal to give it, or 0 for none,
747 or -1 for act according to how it stopped.
748 STEP is nonzero if should trap after one instruction.
749 -1 means return after that and print nothing.
750 You should probably set various step_... variables
751 before calling here, if you are stepping.
753 You should call clear_proceed_status before calling proceed. */
756 proceed (addr
, siggnal
, step
)
758 enum target_signal siggnal
;
764 step_start_function
= find_pc_function (read_pc ());
768 if (addr
== (CORE_ADDR
)-1)
770 /* If there is a breakpoint at the address we will resume at,
771 step one instruction before inserting breakpoints
772 so that we do not stop right away (and report a second
773 hit at this breakpoint). */
775 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
778 #ifndef STEP_SKIPS_DELAY
779 #define STEP_SKIPS_DELAY(pc) (0)
780 #define STEP_SKIPS_DELAY_P (0)
782 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
783 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
784 is slow (it needs to read memory from the target). */
785 if (STEP_SKIPS_DELAY_P
786 && breakpoint_here_p (read_pc () + 4)
787 && STEP_SKIPS_DELAY (read_pc ()))
794 /* New address; we don't need to single-step a thread
795 over a breakpoint we just hit, 'cause we aren't
796 continuing from there.
798 It's not worth worrying about the case where a user
799 asks for a "jump" at the current PC--if they get the
800 hiccup of re-hiting a hit breakpoint, what else do
802 thread_step_needed
= 0;
805 #ifdef PREPARE_TO_PROCEED
806 /* In a multi-threaded task we may select another thread
807 and then continue or step.
809 But if the old thread was stopped at a breakpoint, it
810 will immediately cause another breakpoint stop without
811 any execution (i.e. it will report a breakpoint hit
812 incorrectly). So we must step over it first.
814 PREPARE_TO_PROCEED checks the current thread against the thread
815 that reported the most recent event. If a step-over is required
816 it returns TRUE and sets the current thread to the old thread. */
817 if (PREPARE_TO_PROCEED() && breakpoint_here_p (read_pc()))
820 thread_step_needed
= 1;
823 #endif /* PREPARE_TO_PROCEED */
826 if (trap_expected_after_continue
)
828 /* If (step == 0), a trap will be automatically generated after
829 the first instruction is executed. Force step one
830 instruction to clear this condition. This should not occur
831 if step is nonzero, but it is harmless in that case. */
833 trap_expected_after_continue
= 0;
835 #endif /* HP_OS_BUG */
838 /* We will get a trace trap after one instruction.
839 Continue it automatically and insert breakpoints then. */
843 int temp
= insert_breakpoints ();
846 print_sys_errmsg ("ptrace", temp
);
847 error ("Cannot insert breakpoints.\n\
848 The same program may be running in another process.");
851 breakpoints_inserted
= 1;
854 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
855 stop_signal
= siggnal
;
856 /* If this signal should not be seen by program,
857 give it zero. Used for debugging signals. */
858 else if (!signal_program
[stop_signal
])
859 stop_signal
= TARGET_SIGNAL_0
;
861 annotate_starting ();
863 /* Make sure that output from GDB appears before output from the
865 gdb_flush (gdb_stdout
);
867 /* Resume inferior. */
868 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
870 /* Wait for it to stop (if not standalone)
871 and in any case decode why it stopped, and act accordingly. */
873 wait_for_inferior ();
877 /* Record the pc and sp of the program the last time it stopped.
878 These are just used internally by wait_for_inferior, but need
879 to be preserved over calls to it and cleared when the inferior
881 static CORE_ADDR prev_pc
;
882 static CORE_ADDR prev_func_start
;
883 static char *prev_func_name
;
886 /* Start remote-debugging of a machine over a serial link. */
892 init_wait_for_inferior ();
893 stop_soon_quietly
= 1;
895 wait_for_inferior ();
899 /* Initialize static vars when a new inferior begins. */
902 init_wait_for_inferior ()
904 /* These are meaningless until the first time through wait_for_inferior. */
907 prev_func_name
= NULL
;
910 trap_expected_after_continue
= 0;
912 breakpoints_inserted
= 0;
913 breakpoint_init_inferior (inf_starting
);
915 /* Don't confuse first call to proceed(). */
916 stop_signal
= TARGET_SIGNAL_0
;
918 /* The first resume is not following a fork/vfork/exec. */
919 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
920 pending_follow
.fork_event
.saw_parent_fork
= 0;
921 pending_follow
.fork_event
.saw_child_fork
= 0;
922 pending_follow
.fork_event
.saw_child_exec
= 0;
924 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
925 number_of_threads_in_syscalls
= 0;
927 clear_proceed_status ();
931 delete_breakpoint_current_contents (arg
)
934 struct breakpoint
**breakpointp
= (struct breakpoint
**)arg
;
935 if (*breakpointp
!= NULL
)
937 delete_breakpoint (*breakpointp
);
942 /* Wait for control to return from inferior to debugger.
943 If inferior gets a signal, we may decide to start it up again
944 instead of returning. That is why there is a loop in this function.
945 When this function actually returns it means the inferior
946 should be left stopped and GDB should read more commands. */
951 struct cleanup
*old_cleanups
;
952 struct target_waitstatus w
;
954 int random_signal
= 0;
955 CORE_ADDR stop_func_start
;
956 CORE_ADDR stop_func_end
;
957 char *stop_func_name
;
959 CORE_ADDR prologue_pc
= 0;
962 struct symtab_and_line sal
;
963 int remove_breakpoints_on_following_step
= 0;
965 struct symtab
*current_symtab
;
966 int handling_longjmp
= 0; /* FIXME */
968 int saved_inferior_pid
;
969 int update_step_sp
= 0;
970 int stepping_through_solib_after_catch
= 0;
971 bpstat stepping_through_solib_catchpoints
= NULL
;
972 int enable_hw_watchpoints_after_wait
= 0;
973 int stepping_through_sigtramp
= 0;
974 int new_thread_event
;
976 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
977 int stepped_after_stopped_by_watchpoint
;
980 old_cleanups
= make_cleanup (delete_breakpoint_current_contents
,
981 &step_resume_breakpoint
);
982 make_cleanup (delete_breakpoint_current_contents
,
983 &through_sigtramp_breakpoint
);
984 sal
= find_pc_line(prev_pc
, 0);
985 current_line
= sal
.line
;
986 current_symtab
= sal
.symtab
;
988 /* Are we stepping? */
989 #define CURRENTLY_STEPPING() \
990 ((through_sigtramp_breakpoint == NULL \
991 && !handling_longjmp \
992 && ((step_range_end && step_resume_breakpoint == NULL) \
994 || stepping_through_solib_after_catch \
995 || bpstat_should_step ())
997 thread_step_needed
= 0;
1000 /* We'll update this if & when we switch to a new thread. */
1001 switched_from_inferior_pid
= inferior_pid
;
1006 extern int overlay_cache_invalid
; /* declared in symfile.h */
1008 overlay_cache_invalid
= 1;
1010 /* We have to invalidate the registers BEFORE calling target_wait because
1011 they can be loaded from the target while in target_wait. This makes
1012 remote debugging a bit more efficient for those targets that provide
1013 critical registers as part of their normal status mechanism. */
1015 registers_changed ();
1017 if (target_wait_hook
)
1018 pid
= target_wait_hook (-1, &w
);
1020 pid
= target_wait (-1, &w
);
1022 /* Since we've done a wait, we have a new event. Don't carry
1023 over any expectations about needing to step over a
1025 thread_step_needed
= 0;
1027 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event is
1028 serviced in this loop, below. */
1029 if (enable_hw_watchpoints_after_wait
)
1031 TARGET_ENABLE_HW_WATCHPOINTS(inferior_pid
);
1032 enable_hw_watchpoints_after_wait
= 0;
1036 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
1037 stepped_after_stopped_by_watchpoint
= 0;
1042 We goto this label from elsewhere in wait_for_inferior when we want
1043 to continue the main loop without calling "wait" and trashing the
1044 waitstatus contained in W. */
1047 flush_cached_frames ();
1049 /* If it's a new process, add it to the thread database */
1051 new_thread_event
= ((pid
!= inferior_pid
) && !in_thread_list (pid
));
1053 if (w
.kind
!= TARGET_WAITKIND_EXITED
1054 && w
.kind
!= TARGET_WAITKIND_SIGNALLED
1055 && new_thread_event
)
1061 fprintf_unfiltered (gdb_stderr
, "[New %s]\n", target_pid_or_tid_to_str (pid
));
1064 printf_filtered ("[New %s]\n", target_pid_to_str (pid
));
1068 /* We may want to consider not doing a resume here in order to give
1069 the user a chance to play with the new thread. It might be good
1070 to make that a user-settable option. */
1072 /* At this point, all threads are stopped (happens automatically in
1073 either the OS or the native code). Therefore we need to continue
1074 all threads in order to make progress. */
1076 target_resume (-1, 0, TARGET_SIGNAL_0
);
1083 case TARGET_WAITKIND_LOADED
:
1084 /* Ignore gracefully during startup of the inferior, as it
1085 might be the shell which has just loaded some objects,
1086 otherwise add the symbols for the newly loaded objects. */
1088 if (!stop_soon_quietly
)
1090 extern int auto_solib_add
;
1092 /* Remove breakpoints, SOLIB_ADD might adjust
1093 breakpoint addresses via breakpoint_re_set. */
1094 if (breakpoints_inserted
)
1095 remove_breakpoints ();
1097 /* Check for any newly added shared libraries if we're
1098 supposed to be adding them automatically. */
1101 /* Switch terminal for any messages produced by
1102 breakpoint_re_set. */
1103 target_terminal_ours_for_output ();
1104 SOLIB_ADD (NULL
, 0, NULL
);
1105 target_terminal_inferior ();
1108 /* Reinsert breakpoints and continue. */
1109 if (breakpoints_inserted
)
1110 insert_breakpoints ();
1113 resume (0, TARGET_SIGNAL_0
);
1116 case TARGET_WAITKIND_SPURIOUS
:
1117 resume (0, TARGET_SIGNAL_0
);
1120 case TARGET_WAITKIND_EXITED
:
1121 target_terminal_ours (); /* Must do this before mourn anyway */
1122 annotate_exited (w
.value
.integer
);
1123 if (w
.value
.integer
)
1124 printf_filtered ("\nProgram exited with code 0%o.\n",
1125 (unsigned int)w
.value
.integer
);
1127 printf_filtered ("\nProgram exited normally.\n");
1129 /* Record the exit code in the convenience variable $_exitcode, so
1130 that the user can inspect this again later. */
1131 set_internalvar (lookup_internalvar ("_exitcode"),
1132 value_from_longest (builtin_type_int
,
1133 (LONGEST
) w
.value
.integer
));
1134 gdb_flush (gdb_stdout
);
1135 target_mourn_inferior ();
1136 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P*/
1137 stop_print_frame
= 0;
1140 case TARGET_WAITKIND_SIGNALLED
:
1141 stop_print_frame
= 0;
1142 stop_signal
= w
.value
.sig
;
1143 target_terminal_ours (); /* Must do this before mourn anyway */
1144 annotate_signalled ();
1146 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1147 mean it is already dead? This has been here since GDB 2.8, so
1148 perhaps it means rms didn't understand unix waitstatuses?
1149 For the moment I'm just kludging around this in remote.c
1150 rather than trying to change it here --kingdon, 5 Dec 1994. */
1151 target_kill (); /* kill mourns as well */
1153 printf_filtered ("\nProgram terminated with signal ");
1154 annotate_signal_name ();
1155 printf_filtered ("%s", target_signal_to_name (stop_signal
));
1156 annotate_signal_name_end ();
1157 printf_filtered (", ");
1158 annotate_signal_string ();
1159 printf_filtered ("%s", target_signal_to_string (stop_signal
));
1160 annotate_signal_string_end ();
1161 printf_filtered (".\n");
1163 printf_filtered ("The program no longer exists.\n");
1164 gdb_flush (gdb_stdout
);
1165 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P*/
1168 /* The following are the only cases in which we keep going;
1169 the above cases end in a continue or goto. */
1170 case TARGET_WAITKIND_FORKED
:
1171 stop_signal
= TARGET_SIGNAL_TRAP
;
1172 pending_follow
.kind
= w
.kind
;
1174 /* Ignore fork events reported for the parent; we're only
1175 interested in reacting to forks of the child. Note that
1176 we expect the child's fork event to be available if we
1177 waited for it now. */
1178 if (inferior_pid
== pid
)
1180 pending_follow
.fork_event
.saw_parent_fork
= 1;
1181 pending_follow
.fork_event
.parent_pid
= pid
;
1182 pending_follow
.fork_event
.child_pid
= w
.value
.related_pid
;
1187 pending_follow
.fork_event
.saw_child_fork
= 1;
1188 pending_follow
.fork_event
.child_pid
= pid
;
1189 pending_follow
.fork_event
.parent_pid
= w
.value
.related_pid
;
1192 stop_pc
= read_pc_pid (pid
);
1193 saved_inferior_pid
= inferior_pid
;
1195 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1196 #if DECR_PC_AFTER_BREAK
1197 (prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1198 && CURRENTLY_STEPPING ())
1199 #else /* DECR_PC_AFTER_BREAK zero */
1201 #endif /* DECR_PC_AFTER_BREAK zero */
1203 random_signal
= ! bpstat_explains_signal (stop_bpstat
);
1204 inferior_pid
= saved_inferior_pid
;
1205 goto process_event_stop_test
;
1207 /* If this a platform which doesn't allow a debugger to touch a
1208 vfork'd inferior until after it exec's, then we'd best keep
1209 our fingers entirely off the inferior, other than continuing
1210 it. This has the unfortunate side-effect that catchpoints
1211 of vforks will be ignored. But since the platform doesn't
1212 allow the inferior be touched at vfork time, there's really
1214 case TARGET_WAITKIND_VFORKED
:
1215 stop_signal
= TARGET_SIGNAL_TRAP
;
1216 pending_follow
.kind
= w
.kind
;
1218 /* Is this a vfork of the parent? If so, then give any
1219 vfork catchpoints a chance to trigger now. (It's
1220 dangerous to do so if the child canot be touched until
1221 it execs, and the child has not yet exec'd. We probably
1222 should warn the user to that effect when the catchpoint
1224 if (pid
== inferior_pid
)
1226 pending_follow
.fork_event
.saw_parent_fork
= 1;
1227 pending_follow
.fork_event
.parent_pid
= pid
;
1228 pending_follow
.fork_event
.child_pid
= w
.value
.related_pid
;
1231 /* If we've seen the child's vfork event but cannot really touch
1232 the child until it execs, then we must continue the child now.
1233 Else, give any vfork catchpoints a chance to trigger now. */
1236 pending_follow
.fork_event
.saw_child_fork
= 1;
1237 pending_follow
.fork_event
.child_pid
= pid
;
1238 pending_follow
.fork_event
.parent_pid
= w
.value
.related_pid
;
1239 target_post_startup_inferior (pending_follow
.fork_event
.child_pid
);
1240 follow_vfork_when_exec
= ! target_can_follow_vfork_prior_to_exec ();
1241 if (follow_vfork_when_exec
)
1243 target_resume (pid
, 0, TARGET_SIGNAL_0
);
1248 stop_pc
= read_pc ();
1249 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1250 #if DECR_PC_AFTER_BREAK
1251 (prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1252 && CURRENTLY_STEPPING ())
1253 #else /* DECR_PC_AFTER_BREAK zero */
1255 #endif /* DECR_PC_AFTER_BREAK zero */
1257 random_signal
= ! bpstat_explains_signal (stop_bpstat
);
1258 goto process_event_stop_test
;
1260 case TARGET_WAITKIND_EXECD
:
1261 stop_signal
= TARGET_SIGNAL_TRAP
;
1263 /* Is this a target which reports multiple exec events per actual
1264 call to exec()? (HP-UX using ptrace does, for example.) If so,
1265 ignore all but the last one. Just resume the exec'r, and wait
1266 for the next exec event. */
1267 if (inferior_ignoring_leading_exec_events
)
1269 inferior_ignoring_leading_exec_events
--;
1270 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1271 ENSURE_VFORKING_PARENT_REMAINS_STOPPED(pending_follow
.fork_event
.parent_pid
);
1272 target_resume (pid
, 0, TARGET_SIGNAL_0
);
1275 inferior_ignoring_leading_exec_events
=
1276 target_reported_exec_events_per_exec_call () - 1;
1278 pending_follow
.execd_pathname
= savestring (w
.value
.execd_pathname
,
1279 strlen (w
.value
.execd_pathname
));
1281 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1282 child of a vfork exec?
1284 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1285 HP-UX, events associated with a vforking inferior come in
1286 threes: a vfork event for the child (always first), followed
1287 a vfork event for the parent and an exec event for the child.
1288 The latter two can come in either order.
1290 If we get the parent vfork event first, life's good: We follow
1291 either the parent or child, and then the child's exec event is
1294 But if we get the child's exec event first, then we delay
1295 responding to it until we handle the parent's vfork. Because,
1296 otherwise we can't satisfy a "catch vfork". */
1297 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1299 pending_follow
.fork_event
.saw_child_exec
= 1;
1301 /* On some targets, the child must be resumed before
1302 the parent vfork event is delivered. A single-step
1304 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK())
1305 target_resume (pid
, 1, TARGET_SIGNAL_0
);
1306 continue; /* We expect the parent vfork event to be available now. */
1309 /* This causes the eventpoints and symbol table to be reset. Must
1310 do this now, before trying to determine whether to stop. */
1311 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
1312 free (pending_follow
.execd_pathname
);
1314 stop_pc
= read_pc_pid (pid
);
1315 saved_inferior_pid
= inferior_pid
;
1317 stop_bpstat
= bpstat_stop_status (&stop_pc
,
1318 #if DECR_PC_AFTER_BREAK
1319 (prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1320 && CURRENTLY_STEPPING ())
1321 #else /* DECR_PC_AFTER_BREAK zero */
1323 #endif /* DECR_PC_AFTER_BREAK zero */
1325 random_signal
= ! bpstat_explains_signal (stop_bpstat
);
1326 inferior_pid
= saved_inferior_pid
;
1327 goto process_event_stop_test
;
1329 /* These syscall events are returned on HP-UX, as part of its
1330 implementation of page-protection-based "hardware" watchpoints.
1331 HP-UX has unfortunate interactions between page-protections and
1332 some system calls. Our solution is to disable hardware watches
1333 when a system call is entered, and reenable them when the syscall
1334 completes. The downside of this is that we may miss the precise
1335 point at which a watched piece of memory is modified. "Oh well."
1337 Note that we may have multiple threads running, which may each
1338 enter syscalls at roughly the same time. Since we don't have a
1339 good notion currently of whether a watched piece of memory is
1340 thread-private, we'd best not have any page-protections active
1341 when any thread is in a syscall. Thus, we only want to reenable
1342 hardware watches when no threads are in a syscall.
1344 Also, be careful not to try to gather much state about a thread
1345 that's in a syscall. It's frequently a losing proposition. */
1346 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1347 number_of_threads_in_syscalls
++;
1348 if (number_of_threads_in_syscalls
== 1)
1350 TARGET_DISABLE_HW_WATCHPOINTS(inferior_pid
);
1352 resume (0, TARGET_SIGNAL_0
);
1355 /* Before examining the threads further, step this thread to
1356 get it entirely out of the syscall. (We get notice of the
1357 event when the thread is just on the verge of exiting a
1358 syscall. Stepping one instruction seems to get it back
1361 Note that although the logical place to reenable h/w watches
1362 is here, we cannot. We cannot reenable them before stepping
1363 the thread (this causes the next wait on the thread to hang).
1365 Nor can we enable them after stepping until we've done a
1366 wait. Thus, we simply set the flag enable_hw_watchpoints_after_wait
1367 here, which will be serviced immediately after the target
1369 case TARGET_WAITKIND_SYSCALL_RETURN
:
1370 target_resume (pid
, 1, TARGET_SIGNAL_0
);
1372 if (number_of_threads_in_syscalls
> 0)
1374 number_of_threads_in_syscalls
--;
1375 enable_hw_watchpoints_after_wait
=
1376 (number_of_threads_in_syscalls
== 0);
1380 case TARGET_WAITKIND_STOPPED
:
1381 stop_signal
= w
.value
.sig
;
1385 /* We may want to consider not doing a resume here in order to give
1386 the user a chance to play with the new thread. It might be good
1387 to make that a user-settable option. */
1389 /* At this point, all threads are stopped (happens automatically in
1390 either the OS or the native code). Therefore we need to continue
1391 all threads in order to make progress. */
1392 if (new_thread_event
)
1394 target_resume (-1, 0, TARGET_SIGNAL_0
);
1398 stop_pc
= read_pc_pid (pid
);
1400 /* See if a thread hit a thread-specific breakpoint that was meant for
1401 another thread. If so, then step that thread past the breakpoint,
1404 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1406 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1409 if (breakpoints_inserted
1410 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1413 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
, pid
))
1417 /* Saw a breakpoint, but it was hit by the wrong thread. Just continue. */
1418 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, pid
);
1420 remove_status
= remove_breakpoints ();
1421 /* Did we fail to remove breakpoints? If so, try to set the
1422 PC past the bp. (There's at least one situation in which
1423 we can fail to remove the bp's: On HP-UX's that use ttrace,
1424 we can't change the address space of a vforking child process
1425 until the child exits (well, okay, not then either :-) or
1427 if (remove_status
!= 0)
1429 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, pid
);
1433 target_resume (pid
, 1, TARGET_SIGNAL_0
); /* Single step */
1434 /* FIXME: What if a signal arrives instead of the single-step
1437 if (target_wait_hook
)
1438 target_wait_hook (pid
, &w
);
1440 target_wait (pid
, &w
);
1441 insert_breakpoints ();
1444 /* We need to restart all the threads now. */
1445 target_resume (-1, 0, TARGET_SIGNAL_0
);
1450 /* This breakpoint matches--either it is the right
1451 thread or it's a generic breakpoint for all threads.
1452 Remember that we'll need to step just _this_ thread
1453 on any following user continuation! */
1454 thread_step_needed
= 1;
1461 /* See if something interesting happened to the non-current thread. If
1462 so, then switch to that thread, and eventually give control back to
1465 Note that if there's any kind of pending follow (i.e., of a fork,
1466 vfork or exec), we don't want to do this now. Rather, we'll let
1467 the next resume handle it. */
1468 if ((pid
!= inferior_pid
) &&
1469 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1473 /* If it's a random signal for a non-current thread, notify user
1474 if he's expressed an interest. */
1476 && signal_print
[stop_signal
])
1478 /* ??rehrauer: I don't understand the rationale for this code. If the
1479 inferior will stop as a result of this signal, then the act of handling
1480 the stop ought to print a message that's couches the stoppage in user
1481 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1482 won't stop as a result of the signal -- i.e., if the signal is merely
1483 a side-effect of something GDB's doing "under the covers" for the
1484 user, such as stepping threads over a breakpoint they shouldn't stop
1485 for -- then the message seems to be a serious annoyance at best.
1487 For now, remove the message altogether. */
1490 target_terminal_ours_for_output ();
1491 printf_filtered ("\nProgram received signal %s, %s.\n",
1492 target_signal_to_name (stop_signal
),
1493 target_signal_to_string (stop_signal
));
1494 gdb_flush (gdb_stdout
);
1498 /* If it's not SIGTRAP and not a signal we want to stop for, then
1499 continue the thread. */
1501 if (stop_signal
!= TARGET_SIGNAL_TRAP
1502 && !signal_stop
[stop_signal
])
1505 target_terminal_inferior ();
1507 /* Clear the signal if it should not be passed. */
1508 if (signal_program
[stop_signal
] == 0)
1509 stop_signal
= TARGET_SIGNAL_0
;
1511 target_resume (pid
, 0, stop_signal
);
1515 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1516 and fall into the rest of wait_for_inferior(). */
1518 /* Save infrun state for the old thread. */
1519 save_infrun_state (inferior_pid
, prev_pc
,
1520 prev_func_start
, prev_func_name
,
1521 trap_expected
, step_resume_breakpoint
,
1522 through_sigtramp_breakpoint
,
1523 step_range_start
, step_range_end
,
1524 step_frame_address
, handling_longjmp
,
1526 stepping_through_solib_after_catch
,
1527 stepping_through_solib_catchpoints
,
1528 stepping_through_sigtramp
);
1531 switched_from_inferior_pid
= inferior_pid
;
1536 /* Load infrun state for the new thread. */
1537 load_infrun_state (inferior_pid
, &prev_pc
,
1538 &prev_func_start
, &prev_func_name
,
1539 &trap_expected
, &step_resume_breakpoint
,
1540 &through_sigtramp_breakpoint
,
1541 &step_range_start
, &step_range_end
,
1542 &step_frame_address
, &handling_longjmp
,
1544 &stepping_through_solib_after_catch
,
1545 &stepping_through_solib_catchpoints
,
1546 &stepping_through_sigtramp
);
1549 context_hook (pid_to_thread_id (pid
));
1551 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid
));
1552 flush_cached_frames ();
1555 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1557 /* Pull the single step breakpoints out of the target. */
1558 SOFTWARE_SINGLE_STEP (0, 0);
1559 singlestep_breakpoints_inserted_p
= 0;
1562 /* If PC is pointing at a nullified instruction, then step beyond
1563 it so that the user won't be confused when GDB appears to be ready
1566 #if 0 /* XXX DEBUG */
1567 printf ("infrun.c:1607: pc = 0x%x\n", read_pc ());
1569 /* if (INSTRUCTION_NULLIFIED && CURRENTLY_STEPPING ()) */
1570 if (INSTRUCTION_NULLIFIED
)
1572 struct target_waitstatus tmpstatus
;
1574 all_registers_info ((char *)0, 0);
1576 registers_changed ();
1577 target_resume (pid
, 1, TARGET_SIGNAL_0
);
1579 /* We may have received a signal that we want to pass to
1580 the inferior; therefore, we must not clobber the waitstatus
1581 in W. So we call wait ourselves, then continue the loop
1582 at the "have_waited" label. */
1583 if (target_wait_hook
)
1584 target_wait_hook (pid
, &tmpstatus
);
1586 target_wait (pid
, &tmpstatus
);
1591 #ifdef HAVE_STEPPABLE_WATCHPOINT
1592 /* It may not be necessary to disable the watchpoint to stop over
1593 it. For example, the PA can (with some kernel cooperation)
1594 single step over a watchpoint without disabling the watchpoint. */
1595 if (STOPPED_BY_WATCHPOINT (w
))
1602 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
1603 /* It is far more common to need to disable a watchpoint
1604 to step the inferior over it. FIXME. What else might
1605 a debug register or page protection watchpoint scheme need
1607 if (STOPPED_BY_WATCHPOINT (w
))
1609 /* At this point, we are stopped at an instruction which has attempted to write
1610 to a piece of memory under control of a watchpoint. The instruction hasn't
1611 actually executed yet. If we were to evaluate the watchpoint expression
1612 now, we would get the old value, and therefore no change would seem to have
1615 In order to make watchpoints work `right', we really need to complete the
1616 memory write, and then evaluate the watchpoint expression. The following
1617 code does that by removing the watchpoint (actually, all watchpoints and
1618 breakpoints), single-stepping the target, re-inserting watchpoints, and then
1619 falling through to let normal single-step processing handle proceed. Since
1620 this includes evaluating watchpoints, things will come to a stop in the
1623 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
1625 remove_breakpoints ();
1626 registers_changed();
1627 target_resume (pid
, 1, TARGET_SIGNAL_0
); /* Single step */
1629 if (target_wait_hook
)
1630 target_wait_hook (pid
, &w
);
1632 target_wait (pid
, &w
);
1633 insert_breakpoints ();
1635 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1636 handle things like signals arriving and other things happening
1637 in combination correctly? */
1638 stepped_after_stopped_by_watchpoint
= 1;
1643 #ifdef HAVE_CONTINUABLE_WATCHPOINT
1644 /* It may be possible to simply continue after a watchpoint. */
1645 STOPPED_BY_WATCHPOINT (w
);
1648 stop_func_start
= 0;
1651 /* Don't care about return value; stop_func_start and stop_func_name
1652 will both be 0 if it doesn't work. */
1653 find_pc_partial_function (stop_pc
, &stop_func_name
, &stop_func_start
,
1655 stop_func_start
+= FUNCTION_START_OFFSET
;
1657 bpstat_clear (&stop_bpstat
);
1659 stop_stack_dummy
= 0;
1660 stop_print_frame
= 1;
1662 stopped_by_random_signal
= 0;
1663 breakpoints_failed
= 0;
1665 /* Look at the cause of the stop, and decide what to do.
1666 The alternatives are:
1667 1) break; to really stop and return to the debugger,
1668 2) drop through to start up again
1669 (set another_trap to 1 to single step once)
1670 3) set random_signal to 1, and the decision between 1 and 2
1671 will be made according to the signal handling tables. */
1673 /* First, distinguish signals caused by the debugger from signals
1674 that have to do with the program's own actions.
1675 Note that breakpoint insns may cause SIGTRAP or SIGILL
1676 or SIGEMT, depending on the operating system version.
1677 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1678 and change it to SIGTRAP. */
1680 if (stop_signal
== TARGET_SIGNAL_TRAP
1681 || (breakpoints_inserted
&&
1682 (stop_signal
== TARGET_SIGNAL_ILL
1683 || stop_signal
== TARGET_SIGNAL_EMT
1685 || stop_soon_quietly
)
1687 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
1689 stop_print_frame
= 0;
1692 if (stop_soon_quietly
)
1695 /* Don't even think about breakpoints
1696 if just proceeded over a breakpoint.
1698 However, if we are trying to proceed over a breakpoint
1699 and end up in sigtramp, then through_sigtramp_breakpoint
1700 will be set and we should check whether we've hit the
1702 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
1703 && through_sigtramp_breakpoint
== NULL
)
1704 bpstat_clear (&stop_bpstat
);
1707 /* See if there is a breakpoint at the current PC. */
1708 stop_bpstat
= bpstat_stop_status
1710 (DECR_PC_AFTER_BREAK
?
1711 /* Notice the case of stepping through a jump
1712 that lands just after a breakpoint.
1713 Don't confuse that with hitting the breakpoint.
1714 What we check for is that 1) stepping is going on
1715 and 2) the pc before the last insn does not match
1716 the address of the breakpoint before the current pc
1717 and 3) we didn't hit a breakpoint in a signal handler
1718 without an intervening stop in sigtramp, which is
1719 detected by a new stack pointer value below
1720 any usual function calling stack adjustments. */
1721 (CURRENTLY_STEPPING ()
1722 && prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
1724 && INNER_THAN (read_sp (), (step_sp
- 16)))) :
1727 /* Following in case break condition called a
1729 stop_print_frame
= 1;
1732 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1734 = !(bpstat_explains_signal (stop_bpstat
)
1736 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1737 || PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
1738 FRAME_FP (get_current_frame ()))
1739 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1740 || (step_range_end
&& step_resume_breakpoint
== NULL
));
1745 = !(bpstat_explains_signal (stop_bpstat
)
1746 /* End of a stack dummy. Some systems (e.g. Sony
1747 news) give another signal besides SIGTRAP,
1748 so check here as well as above. */
1749 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1750 || PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
1751 FRAME_FP (get_current_frame ()))
1752 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1755 stop_signal
= TARGET_SIGNAL_TRAP
;
1759 /* When we reach this point, we've pretty much decided
1760 that the reason for stopping must've been a random
1761 (unexpected) signal. */
1765 /* If a fork, vfork or exec event was seen, then there are two
1766 possible responses we can make:
1768 1. If a catchpoint triggers for the event (random_signal == 0),
1769 then we must stop now and issue a prompt. We will resume
1770 the inferior when the user tells us to.
1771 2. If no catchpoint triggers for the event (random_signal == 1),
1772 then we must resume the inferior now and keep checking.
1774 In either case, we must take appropriate steps to "follow" the
1775 the fork/vfork/exec when the inferior is resumed. For example,
1776 if follow-fork-mode is "child", then we must detach from the
1777 parent inferior and follow the new child inferior.
1779 In either case, setting pending_follow causes the next resume()
1780 to take the appropriate following action. */
1781 process_event_stop_test
:
1782 if (w
.kind
== TARGET_WAITKIND_FORKED
)
1784 if (random_signal
) /* I.e., no catchpoint triggered for this. */
1787 stop_signal
= TARGET_SIGNAL_0
;
1791 else if (w
.kind
== TARGET_WAITKIND_VFORKED
)
1793 if (random_signal
) /* I.e., no catchpoint triggered for this. */
1795 stop_signal
= TARGET_SIGNAL_0
;
1799 else if (w
.kind
== TARGET_WAITKIND_EXECD
)
1801 pending_follow
.kind
= w
.kind
;
1802 if (random_signal
) /* I.e., no catchpoint triggered for this. */
1805 stop_signal
= TARGET_SIGNAL_0
;
1810 /* For the program's own signals, act according to
1811 the signal handling tables. */
1815 /* Signal not for debugging purposes. */
1818 stopped_by_random_signal
= 1;
1820 if (signal_print
[stop_signal
])
1823 target_terminal_ours_for_output ();
1825 printf_filtered ("\nProgram received signal ");
1826 annotate_signal_name ();
1827 printf_filtered ("%s", target_signal_to_name (stop_signal
));
1828 annotate_signal_name_end ();
1829 printf_filtered (", ");
1830 annotate_signal_string ();
1831 printf_filtered ("%s", target_signal_to_string (stop_signal
));
1832 annotate_signal_string_end ();
1833 printf_filtered (".\n");
1834 gdb_flush (gdb_stdout
);
1836 if (signal_stop
[stop_signal
])
1838 /* If not going to stop, give terminal back
1839 if we took it away. */
1841 target_terminal_inferior ();
1843 /* Clear the signal if it should not be passed. */
1844 if (signal_program
[stop_signal
] == 0)
1845 stop_signal
= TARGET_SIGNAL_0
;
1847 /* If we're in the middle of a "next" command, let the code for
1848 stepping over a function handle this. pai/1997-09-10
1850 A previous comment here suggested it was possible to change
1851 this to jump to keep_going in all cases. */
1853 if (step_over_calls
> 0)
1854 goto step_over_function
;
1856 goto check_sigtramp2
;
1859 /* Handle cases caused by hitting a breakpoint. */
1861 CORE_ADDR jmp_buf_pc
;
1862 struct bpstat_what what
;
1864 what
= bpstat_what (stop_bpstat
);
1866 if (what
.call_dummy
)
1868 stop_stack_dummy
= 1;
1870 trap_expected_after_continue
= 1;
1874 switch (what
.main_action
)
1876 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
1877 /* If we hit the breakpoint at longjmp, disable it for the
1878 duration of this command. Then, install a temporary
1879 breakpoint at the target of the jmp_buf. */
1880 disable_longjmp_breakpoint();
1881 remove_breakpoints ();
1882 breakpoints_inserted
= 0;
1883 if (!GET_LONGJMP_TARGET(&jmp_buf_pc
)) goto keep_going
;
1885 /* Need to blow away step-resume breakpoint, as it
1886 interferes with us */
1887 if (step_resume_breakpoint
!= NULL
)
1889 delete_breakpoint (step_resume_breakpoint
);
1890 step_resume_breakpoint
= NULL
;
1892 /* Not sure whether we need to blow this away too, but probably
1893 it is like the step-resume breakpoint. */
1894 if (through_sigtramp_breakpoint
!= NULL
)
1896 delete_breakpoint (through_sigtramp_breakpoint
);
1897 through_sigtramp_breakpoint
= NULL
;
1901 /* FIXME - Need to implement nested temporary breakpoints */
1902 if (step_over_calls
> 0)
1903 set_longjmp_resume_breakpoint(jmp_buf_pc
,
1904 get_current_frame());
1907 set_longjmp_resume_breakpoint(jmp_buf_pc
, NULL
);
1908 handling_longjmp
= 1; /* FIXME */
1911 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
1912 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
1913 remove_breakpoints ();
1914 breakpoints_inserted
= 0;
1916 /* FIXME - Need to implement nested temporary breakpoints */
1918 && (INNER_THAN (FRAME_FP (get_current_frame ()),
1919 step_frame_address
)))
1925 disable_longjmp_breakpoint();
1926 handling_longjmp
= 0; /* FIXME */
1927 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
1929 /* else fallthrough */
1931 case BPSTAT_WHAT_SINGLE
:
1932 if (breakpoints_inserted
)
1934 thread_step_needed
= 1;
1935 remove_breakpoints ();
1937 breakpoints_inserted
= 0;
1939 /* Still need to check other stuff, at least the case
1940 where we are stepping and step out of the right range. */
1943 case BPSTAT_WHAT_STOP_NOISY
:
1944 stop_print_frame
= 1;
1946 /* We are about to nuke the step_resume_breakpoint and
1947 through_sigtramp_breakpoint via the cleanup chain, so
1948 no need to worry about it here. */
1952 case BPSTAT_WHAT_STOP_SILENT
:
1953 stop_print_frame
= 0;
1955 /* We are about to nuke the step_resume_breakpoint and
1956 through_sigtramp_breakpoint via the cleanup chain, so
1957 no need to worry about it here. */
1961 case BPSTAT_WHAT_STEP_RESUME
:
1962 /* This proably demands a more elegant solution, but, yeah
1965 This function's use of the simple variable step_resume_breakpoint
1966 doesn't seem to accomodate simultaneously active step-resume bp's,
1967 although the breakpoint list certainly can.
1969 If we reach here and step_resume_breakpoint is already NULL, then
1970 apparently we have multiple active step-resume bp's. We'll just
1971 delete the breakpoint we stopped at, and carry on. */
1972 if (step_resume_breakpoint
== NULL
)
1974 step_resume_breakpoint
=
1975 bpstat_find_step_resume_breakpoint (stop_bpstat
);
1977 delete_breakpoint (step_resume_breakpoint
);
1978 step_resume_breakpoint
= NULL
;
1981 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
1982 if (through_sigtramp_breakpoint
)
1983 delete_breakpoint (through_sigtramp_breakpoint
);
1984 through_sigtramp_breakpoint
= NULL
;
1986 /* If were waiting for a trap, hitting the step_resume_break
1987 doesn't count as getting it. */
1992 case BPSTAT_WHAT_CHECK_SHLIBS
:
1993 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
1996 extern int auto_solib_add
;
1998 /* Remove breakpoints, we eventually want to step over the
1999 shlib event breakpoint, and SOLIB_ADD might adjust
2000 breakpoint addresses via breakpoint_re_set. */
2001 if (breakpoints_inserted
)
2002 remove_breakpoints ();
2003 breakpoints_inserted
= 0;
2005 /* Check for any newly added shared libraries if we're
2006 supposed to be adding them automatically. */
2009 /* Switch terminal for any messages produced by
2010 breakpoint_re_set. */
2011 target_terminal_ours_for_output ();
2012 SOLIB_ADD (NULL
, 0, NULL
);
2013 target_terminal_inferior ();
2016 /* Try to reenable shared library breakpoints, additional
2017 code segments in shared libraries might be mapped in now. */
2018 re_enable_breakpoints_in_shlibs ();
2020 /* If requested, stop when the dynamic linker notifies
2021 gdb of events. This allows the user to get control
2022 and place breakpoints in initializer routines for
2023 dynamically loaded objects (among other things). */
2024 if (stop_on_solib_events
)
2026 stop_print_frame
= 0;
2030 /* If we stopped due to an explicit catchpoint, then the
2031 (see above) call to SOLIB_ADD pulled in any symbols
2032 from a newly-loaded library, if appropriate.
2034 We do want the inferior to stop, but not where it is
2035 now, which is in the dynamic linker callback. Rather,
2036 we would like it stop in the user's program, just after
2037 the call that caused this catchpoint to trigger. That
2038 gives the user a more useful vantage from which to
2039 examine their program's state. */
2040 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2042 /* ??rehrauer: If I could figure out how to get the
2043 right return PC from here, we could just set a temp
2044 breakpoint and resume. I'm not sure we can without
2045 cracking open the dld's shared libraries and sniffing
2046 their unwind tables and text/data ranges, and that's
2047 not a terribly portable notion.
2049 Until that time, we must step the inferior out of the
2050 dld callback, and also out of the dld itself (and any
2051 code or stubs in libdld.sl, such as "shl_load" and
2052 friends) until we reach non-dld code. At that point,
2053 we can stop stepping. */
2054 bpstat_get_triggered_catchpoints (stop_bpstat
,
2055 &stepping_through_solib_catchpoints
);
2056 stepping_through_solib_after_catch
= 1;
2058 /* Be sure to lift all breakpoints, so the inferior does
2059 actually step past this point... */
2065 /* We want to step over this breakpoint, then keep going. */
2073 case BPSTAT_WHAT_LAST
:
2074 /* Not a real code, but listed here to shut up gcc -Wall. */
2076 case BPSTAT_WHAT_KEEP_CHECKING
:
2081 /* We come here if we hit a breakpoint but should not
2082 stop for it. Possibly we also were stepping
2083 and should stop for that. So fall through and
2084 test for stepping. But, if not stepping,
2087 /* Are we stepping to get the inferior out of the dynamic
2088 linker's hook (and possibly the dld itself) after catching
2090 if (stepping_through_solib_after_catch
)
2092 #if defined(SOLIB_ADD)
2093 /* Have we reached our destination? If not, keep going. */
2094 if (SOLIB_IN_DYNAMIC_LINKER (pid
, stop_pc
))
2100 /* Else, stop and report the catchpoint(s) whose triggering
2101 caused us to begin stepping. */
2102 stepping_through_solib_after_catch
= 0;
2103 bpstat_clear (&stop_bpstat
);
2104 stop_bpstat
= bpstat_copy (stepping_through_solib_catchpoints
);
2105 bpstat_clear (&stepping_through_solib_catchpoints
);
2106 stop_print_frame
= 1;
2110 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
2111 /* This is the old way of detecting the end of the stack dummy.
2112 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2113 handled above. As soon as we can test it on all of them, all
2114 architectures should define it. */
2116 /* If this is the breakpoint at the end of a stack dummy,
2117 just stop silently, unless the user was doing an si/ni, in which
2118 case she'd better know what she's doing. */
2120 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (), FRAME_FP (get_current_frame ()))
2123 stop_print_frame
= 0;
2124 stop_stack_dummy
= 1;
2126 trap_expected_after_continue
= 1;
2130 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
2132 if (step_resume_breakpoint
)
2133 /* Having a step-resume breakpoint overrides anything
2134 else having to do with stepping commands until
2135 that breakpoint is reached. */
2136 /* I'm not sure whether this needs to be check_sigtramp2 or
2137 whether it could/should be keep_going. */
2138 goto check_sigtramp2
;
2140 if (step_range_end
== 0)
2141 /* Likewise if we aren't even stepping. */
2142 /* I'm not sure whether this needs to be check_sigtramp2 or
2143 whether it could/should be keep_going. */
2144 goto check_sigtramp2
;
2146 /* If stepping through a line, keep going if still within it.
2148 Note that step_range_end is the address of the first instruction
2149 beyond the step range, and NOT the address of the last instruction
2151 if (stop_pc
>= step_range_start
2152 && stop_pc
< step_range_end
2154 /* I haven't a clue what might trigger this clause, and it seems wrong anyway,
2155 so I've disabled it until someone complains. -Stu 10/24/95 */
2157 /* The step range might include the start of the
2158 function, so if we are at the start of the
2159 step range and either the stack or frame pointers
2160 just changed, we've stepped outside */
2161 && !(stop_pc
== step_range_start
2162 && FRAME_FP (get_current_frame ())
2163 && (INNER_THAN (read_sp (), step_sp
)
2164 || FRAME_FP (get_current_frame ()) != step_frame_address
))
2168 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2169 So definately need to check for sigtramp here. */
2170 goto check_sigtramp2
;
2173 /* We stepped out of the stepping range. */
2175 /* If we are stepping at the source level and entered the runtime
2176 loader dynamic symbol resolution code, we keep on single stepping
2177 until we exit the run time loader code and reach the callee's
2179 if (step_over_calls
< 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2182 /* We can't update step_sp every time through the loop, because
2183 reading the stack pointer would slow down stepping too much.
2184 But we can update it every time we leave the step range. */
2187 /* Did we just take a signal? */
2188 if (IN_SIGTRAMP (stop_pc
, stop_func_name
)
2189 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2190 && INNER_THAN (read_sp (), step_sp
))
2192 /* We've just taken a signal; go until we are back to
2193 the point where we took it and one more. */
2195 /* Note: The test above succeeds not only when we stepped
2196 into a signal handler, but also when we step past the last
2197 statement of a signal handler and end up in the return stub
2198 of the signal handler trampoline. To distinguish between
2199 these two cases, check that the frame is INNER_THAN the
2200 previous one below. pai/1997-09-11 */
2204 CORE_ADDR current_frame
= FRAME_FP (get_current_frame());
2206 if (INNER_THAN (current_frame
, step_frame_address
))
2208 /* We have just taken a signal; go until we are back to
2209 the point where we took it and one more. */
2211 /* This code is needed at least in the following case:
2212 The user types "next" and then a signal arrives (before
2213 the "next" is done). */
2215 /* Note that if we are stopped at a breakpoint, then we need
2216 the step_resume breakpoint to override any breakpoints at
2217 the same location, so that we will still step over the
2218 breakpoint even though the signal happened. */
2219 struct symtab_and_line sr_sal
;
2222 sr_sal
.symtab
= NULL
;
2224 sr_sal
.pc
= prev_pc
;
2225 /* We could probably be setting the frame to
2226 step_frame_address; I don't think anyone thought to try it. */
2227 step_resume_breakpoint
=
2228 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2229 if (breakpoints_inserted
)
2230 insert_breakpoints ();
2234 /* We just stepped out of a signal handler and into its calling
2237 Normally, we'd jump to step_over_function from here,
2238 but for some reason GDB can't unwind the stack correctly to find
2239 the real PC for the point user code where the signal trampoline will
2240 return -- FRAME_SAVED_PC fails, at least on HP-UX 10.20. But signal
2241 trampolines are pretty small stubs of code, anyway, so it's OK instead
2242 to just single-step out. Note: assuming such trampolines don't
2243 exhibit recursion on any platform... */
2244 find_pc_partial_function (stop_pc
, &stop_func_name
, &stop_func_start
,
2246 /* Readjust stepping range */
2247 step_range_start
= stop_func_start
;
2248 step_range_end
= stop_func_end
;
2249 stepping_through_sigtramp
= 1;
2254 /* If this is stepi or nexti, make sure that the stepping range
2255 gets us past that instruction. */
2256 if (step_range_end
== 1)
2257 /* FIXME: Does this run afoul of the code below which, if
2258 we step into the middle of a line, resets the stepping
2260 step_range_end
= (step_range_start
= prev_pc
) + 1;
2262 remove_breakpoints_on_following_step
= 1;
2267 /* I disabled this test because it was too complicated and slow. The
2268 SKIP_PROLOGUE was especially slow, because it caused unnecessary
2269 prologue examination on various architectures. The code in the #else
2270 clause has been tested on the Sparc, Mips, PA, and Power
2271 architectures, so it's pretty likely to be correct. -Stu 10/24/95 */
2273 /* See if we left the step range due to a subroutine call that
2274 we should proceed to the end of. */
2276 if (stop_func_start
)
2280 /* Do this after the IN_SIGTRAMP check; it might give
2282 prologue_pc
= stop_func_start
;
2284 /* Don't skip the prologue if this is assembly source */
2285 s
= find_pc_symtab (stop_pc
);
2286 if (s
&& s
->language
!= language_asm
)
2287 SKIP_PROLOGUE (prologue_pc
);
2290 if (!(INNER_THAN (step_sp
, read_sp ())) /* don't mistake (sig)return as a call */
2291 && (/* Might be a non-recursive call. If the symbols are missing
2292 enough that stop_func_start == prev_func_start even though
2293 they are really two functions, we will treat some calls as
2295 stop_func_start
!= prev_func_start
2297 /* Might be a recursive call if either we have a prologue
2298 or the call instruction itself saves the PC on the stack. */
2299 || prologue_pc
!= stop_func_start
2300 || read_sp () != step_sp
)
2301 && (/* PC is completely out of bounds of any known objfiles. Treat
2302 like a subroutine call. */
2305 /* If we do a call, we will be at the start of a function... */
2306 || stop_pc
== stop_func_start
2308 /* ...except on the Alpha with -O (and also Irix 5 and
2309 perhaps others), in which we might call the address
2310 after the load of gp. Since prologues don't contain
2311 calls, we can't return to within one, and we don't
2312 jump back into them, so this check is OK. */
2314 || stop_pc
< prologue_pc
2316 /* ...and if it is a leaf function, the prologue might
2317 consist of gp loading only, so the call transfers to
2318 the first instruction after the prologue. */
2319 || (stop_pc
== prologue_pc
2321 /* Distinguish this from the case where we jump back
2322 to the first instruction after the prologue,
2323 within a function. */
2324 && stop_func_start
!= prev_func_start
)
2326 /* If we end up in certain places, it means we did a subroutine
2327 call. I'm not completely sure this is necessary now that we
2328 have the above checks with stop_func_start (and now that
2329 find_pc_partial_function is pickier). */
2330 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, stop_func_name
)
2332 /* If none of the above apply, it is a jump within a function,
2333 or a return from a subroutine. The other case is longjmp,
2334 which can no longer happen here as long as the
2335 handling_longjmp stuff is working. */
2338 /* This test is a much more streamlined, (but hopefully correct)
2339 replacement for the code above. It's been tested on the Sparc,
2340 Mips, PA, and Power architectures with good results. */
2342 if (stop_pc
== stop_func_start
/* Quick test */
2343 || (in_prologue (stop_pc
, stop_func_start
) &&
2344 ! IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, stop_func_name
))
2345 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, stop_func_name
)
2346 || stop_func_name
== 0)
2350 /* It's a subroutine call. */
2352 if (step_over_calls
== 0)
2354 /* I presume that step_over_calls is only 0 when we're
2355 supposed to be stepping at the assembly language level
2356 ("stepi"). Just stop. */
2361 if (step_over_calls
> 0 || IGNORE_HELPER_CALL (stop_pc
))
2362 /* We're doing a "next". */
2363 goto step_over_function
;
2365 /* If we are in a function call trampoline (a stub between
2366 the calling routine and the real function), locate the real
2367 function. That's what tells us (a) whether we want to step
2368 into it at all, and (b) what prologue we want to run to
2369 the end of, if we do step into it. */
2370 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2372 stop_func_start
= tmp
;
2375 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2378 struct symtab_and_line xxx
;
2379 /* Why isn't this s_a_l called "sr_sal", like all of the
2380 other s_a_l's where this code is duplicated? */
2381 INIT_SAL (&xxx
); /* initialize to zeroes */
2383 xxx
.section
= find_pc_overlay (xxx
.pc
);
2384 step_resume_breakpoint
=
2385 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2386 insert_breakpoints ();
2391 /* If we have line number information for the function we
2392 are thinking of stepping into, step into it.
2394 If there are several symtabs at that PC (e.g. with include
2395 files), just want to know whether *any* of them have line
2396 numbers. find_pc_line handles this. */
2398 struct symtab_and_line tmp_sal
;
2400 tmp_sal
= find_pc_line (stop_func_start
, 0);
2401 if (tmp_sal
.line
!= 0)
2402 goto step_into_function
;
2406 /* A subroutine call has happened. */
2408 /* Set a special breakpoint after the return */
2409 struct symtab_and_line sr_sal
;
2412 sr_sal
.symtab
= NULL
;
2415 /* If we came here after encountering a signal in the middle of
2416 a "next", use the stashed-away previous frame pc */
2418 = stopped_by_random_signal
2420 : ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2422 step_resume_breakpoint
=
2423 set_momentary_breakpoint (sr_sal
,
2424 stopped_by_random_signal
? NULL
: get_current_frame (),
2427 /* We've just entered a callee, and we wish to resume until
2428 it returns to the caller. Setting a step_resume bp on
2429 the return PC will catch a return from the callee.
2431 However, if the callee is recursing, we want to be careful
2432 not to catch returns of those recursive calls, but of THIS
2433 instance of the call.
2435 To do this, we set the step_resume bp's frame to our current
2436 caller's frame (step_frame_address, which is set by the "next"
2437 or "until" command, before execution begins).
2439 But ... don't do it if we're single-stepping out of a sigtramp,
2440 because the reason we're single-stepping is precisely because
2441 unwinding is a problem (HP-UX 10.20, e.g.) and the frame address
2442 is likely to be incorrect. No danger of sigtramp recursion */
2444 if (stepping_through_sigtramp
)
2446 step_resume_breakpoint
->frame
= NULL
;
2447 stepping_through_sigtramp
= 0;
2449 else if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
2450 step_resume_breakpoint
->frame
= step_frame_address
;
2452 if (breakpoints_inserted
)
2453 insert_breakpoints ();
2458 /* Subroutine call with source code we should not step over.
2459 Do step to the first line of code in it. */
2463 s
= find_pc_symtab (stop_pc
);
2464 if (s
&& s
->language
!= language_asm
)
2465 SKIP_PROLOGUE (stop_func_start
);
2467 sal
= find_pc_line (stop_func_start
, 0);
2468 /* Use the step_resume_break to step until
2469 the end of the prologue, even if that involves jumps
2470 (as it seems to on the vax under 4.2). */
2471 /* If the prologue ends in the middle of a source line,
2472 continue to the end of that source line (if it is still
2473 within the function). Otherwise, just go to end of prologue. */
2474 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2475 /* no, don't either. It skips any code that's
2476 legitimately on the first line. */
2478 if (sal
.end
&& sal
.pc
!= stop_func_start
&& sal
.end
< stop_func_end
)
2479 stop_func_start
= sal
.end
;
2482 if (stop_func_start
== stop_pc
)
2484 /* We are already there: stop now. */
2489 /* Put the step-breakpoint there and go until there. */
2491 struct symtab_and_line sr_sal
;
2493 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2494 sr_sal
.pc
= stop_func_start
;
2495 sr_sal
.section
= find_pc_overlay (stop_func_start
);
2496 /* Do not specify what the fp should be when we stop
2497 since on some machines the prologue
2498 is where the new fp value is established. */
2499 step_resume_breakpoint
=
2500 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2501 if (breakpoints_inserted
)
2502 insert_breakpoints ();
2504 /* And make sure stepping stops right away then. */
2505 step_range_end
= step_range_start
;
2510 /* We've wandered out of the step range. */
2512 sal
= find_pc_line(stop_pc
, 0);
2514 if (step_range_end
== 1)
2516 /* It is stepi or nexti. We always want to stop stepping after
2522 /* If we're in the return path from a shared library trampoline,
2523 we want to proceed through the trampoline when stepping. */
2524 if (IN_SOLIB_RETURN_TRAMPOLINE(stop_pc
, stop_func_name
))
2528 /* Determine where this trampoline returns. */
2529 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2531 /* Only proceed through if we know where it's going. */
2534 /* And put the step-breakpoint there and go until there. */
2535 struct symtab_and_line sr_sal
;
2537 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2539 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2540 /* Do not specify what the fp should be when we stop
2541 since on some machines the prologue
2542 is where the new fp value is established. */
2543 step_resume_breakpoint
=
2544 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2545 if (breakpoints_inserted
)
2546 insert_breakpoints ();
2548 /* Restart without fiddling with the step ranges or
2556 /* We have no line number information. That means to stop
2557 stepping (does this always happen right after one instruction,
2558 when we do "s" in a function with no line numbers,
2559 or can this happen as a result of a return or longjmp?). */
2564 if ((stop_pc
== sal
.pc
)
2565 && (current_line
!= sal
.line
|| current_symtab
!= sal
.symtab
))
2567 /* We are at the start of a different line. So stop. Note that
2568 we don't stop if we step into the middle of a different line.
2569 That is said to make things like for (;;) statements work
2575 /* We aren't done stepping.
2577 Optimize by setting the stepping range to the line.
2578 (We might not be in the original line, but if we entered a
2579 new line in mid-statement, we continue stepping. This makes
2580 things like for(;;) statements work better.) */
2582 if (stop_func_end
&& sal
.end
>= stop_func_end
)
2584 /* If this is the last line of the function, don't keep stepping
2585 (it would probably step us out of the function).
2586 This is particularly necessary for a one-line function,
2587 in which after skipping the prologue we better stop even though
2588 we will be in mid-line. */
2592 step_range_start
= sal
.pc
;
2593 step_range_end
= sal
.end
;
2594 step_frame_address
= FRAME_FP (get_current_frame ());
2595 current_line
= sal
.line
;
2596 current_symtab
= sal
.symtab
;
2598 /* In the case where we just stepped out of a function into the middle
2599 of a line of the caller, continue stepping, but step_frame_address
2600 must be modified to current frame */
2602 CORE_ADDR current_frame
= FRAME_FP (get_current_frame());
2603 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2604 step_frame_address
= current_frame
;
2612 && IN_SIGTRAMP (stop_pc
, stop_func_name
)
2613 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2614 && INNER_THAN (read_sp (), step_sp
))
2616 /* What has happened here is that we have just stepped the inferior
2617 with a signal (because it is a signal which shouldn't make
2618 us stop), thus stepping into sigtramp.
2620 So we need to set a step_resume_break_address breakpoint
2621 and continue until we hit it, and then step. FIXME: This should
2622 be more enduring than a step_resume breakpoint; we should know
2623 that we will later need to keep going rather than re-hitting
2624 the breakpoint here (see testsuite/gdb.t06/signals.exp where
2625 it says "exceedingly difficult"). */
2626 struct symtab_and_line sr_sal
;
2628 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2629 sr_sal
.pc
= prev_pc
;
2630 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2631 /* We perhaps could set the frame if we kept track of what
2632 the frame corresponding to prev_pc was. But we don't,
2634 through_sigtramp_breakpoint
=
2635 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2636 if (breakpoints_inserted
)
2637 insert_breakpoints ();
2639 remove_breakpoints_on_following_step
= 1;
2644 /* Come to this label when you need to resume the inferior.
2645 It's really much cleaner to do a goto than a maze of if-else
2648 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug
2649 a vforked child beetween its creation and subsequent exit or
2650 call to exec(). However, I had big problems in this rather
2651 creaky exec engine, getting that to work. The fundamental
2652 problem is that I'm trying to debug two processes via an
2653 engine that only understands a single process with possibly
2656 Hence, this spot is known to have problems when
2657 target_can_follow_vfork_prior_to_exec returns 1. */
2659 /* Save the pc before execution, to compare with pc after stop. */
2660 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
2661 prev_func_start
= stop_func_start
; /* Ok, since if DECR_PC_AFTER
2662 BREAK is defined, the
2663 original pc would not have
2664 been at the start of a
2666 prev_func_name
= stop_func_name
;
2669 step_sp
= read_sp ();
2672 /* If we did not do break;, it means we should keep
2673 running the inferior and not return to debugger. */
2675 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
2677 /* We took a signal (which we are supposed to pass through to
2678 the inferior, else we'd have done a break above) and we
2679 haven't yet gotten our trap. Simply continue. */
2680 resume (CURRENTLY_STEPPING (), stop_signal
);
2684 /* Either the trap was not expected, but we are continuing
2685 anyway (the user asked that this signal be passed to the
2688 The signal was SIGTRAP, e.g. it was our signal, but we
2689 decided we should resume from it.
2691 We're going to run this baby now!
2693 Insert breakpoints now, unless we are trying
2694 to one-proceed past a breakpoint. */
2695 /* If we've just finished a special step resume and we don't
2696 want to hit a breakpoint, pull em out. */
2697 if (step_resume_breakpoint
== NULL
2698 && through_sigtramp_breakpoint
== NULL
2699 && remove_breakpoints_on_following_step
)
2701 remove_breakpoints_on_following_step
= 0;
2702 remove_breakpoints ();
2703 breakpoints_inserted
= 0;
2705 else if (!breakpoints_inserted
&&
2706 (through_sigtramp_breakpoint
!= NULL
|| !another_trap
))
2708 breakpoints_failed
= insert_breakpoints ();
2709 if (breakpoints_failed
)
2711 breakpoints_inserted
= 1;
2714 trap_expected
= another_trap
;
2716 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2717 stop_signal
= TARGET_SIGNAL_0
;
2719 #ifdef SHIFT_INST_REGS
2720 /* I'm not sure when this following segment applies. I do know, now,
2721 that we shouldn't rewrite the regs when we were stopped by a
2722 random signal from the inferior process. */
2723 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2724 (this is only used on the 88k). */
2726 if (!bpstat_explains_signal (stop_bpstat
)
2727 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
2728 && !stopped_by_random_signal
)
2730 #endif /* SHIFT_INST_REGS */
2732 resume (CURRENTLY_STEPPING (), stop_signal
);
2737 if (target_has_execution
)
2739 /* Are we stopping for a vfork event? We only stop when we see
2740 the child's event. However, we may not yet have seen the
2741 parent's event. And, inferior_pid is still set to the parent's
2742 pid, until we resume again and follow either the parent or child.
2744 To ensure that we can really touch inferior_pid (aka, the
2745 parent process) -- which calls to functions like read_pc
2746 implicitly do -- wait on the parent if necessary. */
2747 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
2748 && ! pending_follow
.fork_event
.saw_parent_fork
)
2753 if (target_wait_hook
)
2754 parent_pid
= target_wait_hook (-1, &w
);
2756 parent_pid
= target_wait (-1, &w
);
2757 } while (parent_pid
!= inferior_pid
);
2761 /* Assuming the inferior still exists, set these up for next
2762 time, just like we did above if we didn't break out of the
2764 prev_pc
= read_pc ();
2765 prev_func_start
= stop_func_start
;
2766 prev_func_name
= stop_func_name
;
2768 do_cleanups (old_cleanups
);
2771 /* This function returns TRUE if ep is an internal breakpoint
2772 set to catch generic shared library (aka dynamically-linked
2773 library) events. (This is *NOT* the same as a catchpoint for a
2774 shlib event. The latter is something a user can set; this is
2775 something gdb sets for its own use, and isn't ever shown to a
2778 is_internal_shlib_eventpoint (ep
)
2779 struct breakpoint
* ep
;
2782 (ep
->type
== bp_shlib_event
)
2786 /* This function returns TRUE if bs indicates that the inferior
2787 stopped due to a shared library (aka dynamically-linked library)
2790 stopped_for_internal_shlib_event (bs
)
2793 /* Note that multiple eventpoints may've caused the stop. Any
2794 that are associated with shlib events will be accepted. */
2795 for (;bs
!= NULL
; bs
= bs
->next
)
2797 if ((bs
->breakpoint_at
!= NULL
)
2798 && is_internal_shlib_eventpoint (bs
->breakpoint_at
))
2802 /* If we get here, then no candidate was found. */
2806 /* This function returns TRUE if bs indicates that the inferior
2807 stopped due to a shared library (aka dynamically-linked library)
2808 event caught by a catchpoint.
2810 If TRUE, cp_p is set to point to the catchpoint.
2812 Else, the value of cp_p is undefined. */
2814 stopped_for_shlib_catchpoint (bs
, cp_p
)
2816 struct breakpoint
** cp_p
;
2818 /* Note that multiple eventpoints may've caused the stop. Any
2819 that are associated with shlib events will be accepted. */
2822 for (;bs
!= NULL
; bs
= bs
->next
)
2824 if ((bs
->breakpoint_at
!= NULL
)
2825 && ep_is_shlib_catchpoint (bs
->breakpoint_at
))
2827 *cp_p
= bs
->breakpoint_at
;
2832 /* If we get here, then no candidate was found. */
2837 /* Here to return control to GDB when the inferior stops for real.
2838 Print appropriate messages, remove breakpoints, give terminal our modes.
2840 STOP_PRINT_FRAME nonzero means print the executing frame
2841 (pc, function, args, file, line number and line text).
2842 BREAKPOINTS_FAILED nonzero means stop was due to error
2843 attempting to insert breakpoints. */
2850 /* As with the notification of thread events, we want to delay
2851 notifying the user that we've switched thread context until
2852 the inferior actually stops.
2854 (Note that there's no point in saying anything if the inferior
2856 if ((switched_from_inferior_pid
!= inferior_pid
) &&
2857 target_has_execution
)
2859 target_terminal_ours_for_output ();
2860 printf_filtered ("[Switched to %s]\n", target_pid_or_tid_to_str (inferior_pid
));
2861 switched_from_inferior_pid
= inferior_pid
;
2865 /* Make sure that the current_frame's pc is correct. This
2866 is a correction for setting up the frame info before doing
2867 DECR_PC_AFTER_BREAK */
2868 if (target_has_execution
&& get_current_frame())
2869 (get_current_frame ())->pc
= read_pc ();
2871 if (breakpoints_failed
)
2873 target_terminal_ours_for_output ();
2874 print_sys_errmsg ("ptrace", breakpoints_failed
);
2875 printf_filtered ("Stopped; cannot insert breakpoints.\n\
2876 The same program may be running in another process.\n");
2879 if (target_has_execution
&& breakpoints_inserted
)
2881 if (remove_breakpoints ())
2883 target_terminal_ours_for_output ();
2884 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
2885 It might be running in another process.\n\
2886 Further execution is probably impossible.\n");
2889 breakpoints_inserted
= 0;
2891 /* Delete the breakpoint we stopped at, if it wants to be deleted.
2892 Delete any breakpoint that is to be deleted at the next stop. */
2894 breakpoint_auto_delete (stop_bpstat
);
2896 /* If an auto-display called a function and that got a signal,
2897 delete that auto-display to avoid an infinite recursion. */
2899 if (stopped_by_random_signal
)
2900 disable_current_display ();
2902 /* Don't print a message if in the middle of doing a "step n"
2903 operation for n > 1 */
2904 if (step_multi
&& stop_step
)
2907 target_terminal_ours ();
2909 /* Did we stop because the user set the stop_on_solib_events
2910 variable? (If so, we report this as a generic, "Stopped due
2911 to shlib event" message.) */
2912 if (stopped_for_internal_shlib_event (stop_bpstat
))
2914 printf_filtered ("Stopped due to shared library event\n");
2917 /* Look up the hook_stop and run it if it exists. */
2919 if (stop_command
&& stop_command
->hook
)
2921 catch_errors (hook_stop_stub
, (char *)stop_command
->hook
,
2922 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
2925 if (!target_has_stack
)
2931 /* Select innermost stack frame - i.e., current frame is frame 0,
2932 and current location is based on that.
2933 Don't do this on return from a stack dummy routine,
2934 or if the program has exited. */
2936 if (!stop_stack_dummy
)
2938 select_frame (get_current_frame (), 0);
2940 /* Print current location without a level number, if
2941 we have changed functions or hit a breakpoint.
2942 Print source line if we have one.
2943 bpstat_print() contains the logic deciding in detail
2944 what to print, based on the event(s) that just occurred. */
2946 if (stop_print_frame
)
2951 bpstat_ret
= bpstat_print (stop_bpstat
);
2952 /* bpstat_print() returned one of:
2953 -1: Didn't print anything
2954 0: Printed preliminary "Breakpoint n, " message, desires
2956 1: Printed something, don't tack on location */
2958 if (bpstat_ret
== -1)
2960 && step_frame_address
== FRAME_FP (get_current_frame ())
2961 && step_start_function
== find_pc_function (stop_pc
))
2962 source_flag
= -1; /* finished step, just print source line */
2964 source_flag
= 1; /* print location and source line */
2965 else if (bpstat_ret
== 0) /* hit bpt, desire location */
2966 source_flag
= 1; /* print location and source line */
2967 else /* bpstat_ret == 1, hit bpt, do not desire location */
2968 source_flag
= -1; /* just print source line */
2970 /* The behavior of this routine with respect to the source
2972 -1: Print only source line
2973 0: Print only location
2974 1: Print location and source line */
2975 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
2977 /* Display the auto-display expressions. */
2982 /* Save the function value return registers, if we care.
2983 We might be about to restore their previous contents. */
2984 if (proceed_to_finish
)
2985 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
2987 if (stop_stack_dummy
)
2989 /* Pop the empty frame that contains the stack dummy.
2990 POP_FRAME ends with a setting of the current frame, so we
2991 can use that next. */
2993 /* Set stop_pc to what it was before we called the function. Can't rely
2994 on restore_inferior_status because that only gets called if we don't
2995 stop in the called function. */
2996 stop_pc
= read_pc();
2997 select_frame (get_current_frame (), 0);
3001 TUIDO (((TuiOpaqueFuncPtr
)tui_vCheckDataValues
, selected_frame
));
3004 annotate_stopped ();
3008 hook_stop_stub (cmd
)
3011 execute_user_command ((struct cmd_list_element
*)cmd
, 0);
3015 int signal_stop_state (signo
)
3018 return signal_stop
[signo
];
3021 int signal_print_state (signo
)
3024 return signal_print
[signo
];
3027 int signal_pass_state (signo
)
3030 return signal_program
[signo
];
3037 Signal Stop\tPrint\tPass to program\tDescription\n");
3041 sig_print_info (oursig
)
3042 enum target_signal oursig
;
3044 char *name
= target_signal_to_name (oursig
);
3045 int name_padding
= 13 - strlen (name
);
3046 if (name_padding
<= 0)
3049 printf_filtered ("%s", name
);
3050 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
3051 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3052 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3053 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3054 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3057 /* Specify how various signals in the inferior should be handled. */
3060 handle_command (args
, from_tty
)
3065 int digits
, wordlen
;
3066 int sigfirst
, signum
, siglast
;
3067 enum target_signal oursig
;
3070 unsigned char *sigs
;
3071 struct cleanup
*old_chain
;
3075 error_no_arg ("signal to handle");
3078 /* Allocate and zero an array of flags for which signals to handle. */
3080 nsigs
= (int)TARGET_SIGNAL_LAST
;
3081 sigs
= (unsigned char *) alloca (nsigs
);
3082 memset (sigs
, 0, nsigs
);
3084 /* Break the command line up into args. */
3086 argv
= buildargv (args
);
3091 old_chain
= make_cleanup ((make_cleanup_func
) freeargv
, (char *) argv
);
3093 /* Walk through the args, looking for signal oursigs, signal names, and
3094 actions. Signal numbers and signal names may be interspersed with
3095 actions, with the actions being performed for all signals cumulatively
3096 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3098 while (*argv
!= NULL
)
3100 wordlen
= strlen (*argv
);
3101 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++) {;}
3103 sigfirst
= siglast
= -1;
3105 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3107 /* Apply action to all signals except those used by the
3108 debugger. Silently skip those. */
3111 siglast
= nsigs
- 1;
3113 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3115 SET_SIGS (nsigs
, sigs
, signal_stop
);
3116 SET_SIGS (nsigs
, sigs
, signal_print
);
3118 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3120 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3122 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3124 SET_SIGS (nsigs
, sigs
, signal_print
);
3126 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3128 SET_SIGS (nsigs
, sigs
, signal_program
);
3130 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3132 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3134 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3136 SET_SIGS (nsigs
, sigs
, signal_program
);
3138 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3140 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3141 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3143 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3145 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3147 else if (digits
> 0)
3149 /* It is numeric. The numeric signal refers to our own internal
3150 signal numbering from target.h, not to host/target signal number.
3151 This is a feature; users really should be using symbolic names
3152 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
3153 will work right anyway. */
3155 sigfirst
= siglast
= (int) target_signal_from_command (atoi (*argv
));
3156 if ((*argv
)[digits
] == '-')
3159 (int) target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3161 if (sigfirst
> siglast
)
3163 /* Bet he didn't figure we'd think of this case... */
3171 oursig
= target_signal_from_name (*argv
);
3172 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3174 sigfirst
= siglast
= (int)oursig
;
3178 /* Not a number and not a recognized flag word => complain. */
3179 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3183 /* If any signal numbers or symbol names were found, set flags for
3184 which signals to apply actions to. */
3186 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3188 switch ((enum target_signal
)signum
)
3190 case TARGET_SIGNAL_TRAP
:
3191 case TARGET_SIGNAL_INT
:
3192 if (!allsigs
&& !sigs
[signum
])
3194 if (query ("%s is used by the debugger.\n\
3195 Are you sure you want to change it? ",
3196 target_signal_to_name
3197 ((enum target_signal
)signum
)))
3203 printf_unfiltered ("Not confirmed, unchanged.\n");
3204 gdb_flush (gdb_stdout
);
3208 case TARGET_SIGNAL_0
:
3209 case TARGET_SIGNAL_DEFAULT
:
3210 case TARGET_SIGNAL_UNKNOWN
:
3211 /* Make sure that "all" doesn't print these. */
3222 target_notice_signals(inferior_pid
);
3226 /* Show the results. */
3227 sig_print_header ();
3228 for (signum
= 0; signum
< nsigs
; signum
++)
3232 sig_print_info (signum
);
3237 do_cleanups (old_chain
);
3241 xdb_handle_command (args
, from_tty
)
3246 struct cleanup
*old_chain
;
3248 /* Break the command line up into args. */
3250 argv
= buildargv (args
);
3255 old_chain
= make_cleanup (freeargv
, (char *) argv
);
3256 if (argv
[1] != (char *)NULL
)
3261 bufLen
= strlen(argv
[0]) + 20;
3262 argBuf
= (char *)xmalloc(bufLen
);
3266 enum target_signal oursig
;
3268 oursig
= target_signal_from_name (argv
[0]);
3269 memset(argBuf
, 0, bufLen
);
3270 if (strcmp(argv
[1], "Q") == 0)
3271 sprintf(argBuf
, "%s %s", argv
[0], "noprint");
3274 if (strcmp(argv
[1], "s") == 0)
3276 if (!signal_stop
[oursig
])
3277 sprintf(argBuf
, "%s %s", argv
[0], "stop");
3279 sprintf(argBuf
, "%s %s", argv
[0], "nostop");
3281 else if (strcmp(argv
[1], "i") == 0)
3283 if (!signal_program
[oursig
])
3284 sprintf(argBuf
, "%s %s", argv
[0], "pass");
3286 sprintf(argBuf
, "%s %s", argv
[0], "nopass");
3288 else if (strcmp(argv
[1], "r") == 0)
3290 if (!signal_print
[oursig
])
3291 sprintf(argBuf
, "%s %s", argv
[0], "print");
3293 sprintf(argBuf
, "%s %s", argv
[0], "noprint");
3299 handle_command(argBuf
, from_tty
);
3301 printf_filtered("Invalid signal handling flag.\n");
3306 do_cleanups (old_chain
);
3309 /* Print current contents of the tables set by the handle command.
3310 It is possible we should just be printing signals actually used
3311 by the current target (but for things to work right when switching
3312 targets, all signals should be in the signal tables). */
3315 signals_info (signum_exp
, from_tty
)
3319 enum target_signal oursig
;
3320 sig_print_header ();
3324 /* First see if this is a symbol name. */
3325 oursig
= target_signal_from_name (signum_exp
);
3326 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3328 /* No, try numeric. */
3330 target_signal_from_command (parse_and_eval_address (signum_exp
));
3332 sig_print_info (oursig
);
3336 printf_filtered ("\n");
3337 /* These ugly casts brought to you by the native VAX compiler. */
3338 for (oursig
= TARGET_SIGNAL_FIRST
;
3339 (int)oursig
< (int)TARGET_SIGNAL_LAST
;
3340 oursig
= (enum target_signal
)((int)oursig
+ 1))
3344 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3345 && oursig
!= TARGET_SIGNAL_DEFAULT
3346 && oursig
!= TARGET_SIGNAL_0
)
3347 sig_print_info (oursig
);
3350 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3353 /* Save all of the information associated with the inferior<==>gdb
3354 connection. INF_STATUS is a pointer to a "struct inferior_status"
3355 (defined in inferior.h). */
3358 save_inferior_status (inf_status
, restore_stack_info
)
3359 struct inferior_status
*inf_status
;
3360 int restore_stack_info
;
3362 inf_status
->stop_signal
= stop_signal
;
3363 inf_status
->stop_pc
= stop_pc
;
3364 inf_status
->stop_step
= stop_step
;
3365 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3366 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3367 inf_status
->trap_expected
= trap_expected
;
3368 inf_status
->step_range_start
= step_range_start
;
3369 inf_status
->step_range_end
= step_range_end
;
3370 inf_status
->step_frame_address
= step_frame_address
;
3371 inf_status
->step_over_calls
= step_over_calls
;
3372 inf_status
->stop_after_trap
= stop_after_trap
;
3373 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3374 /* Save original bpstat chain here; replace it with copy of chain.
3375 If caller's caller is walking the chain, they'll be happier if we
3376 hand them back the original chain when restore_i_s is called. */
3377 inf_status
->stop_bpstat
= stop_bpstat
;
3378 stop_bpstat
= bpstat_copy (stop_bpstat
);
3379 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3380 inf_status
->restore_stack_info
= restore_stack_info
;
3381 inf_status
->proceed_to_finish
= proceed_to_finish
;
3383 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
3385 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3387 record_selected_frame (&(inf_status
->selected_frame_address
),
3388 &(inf_status
->selected_level
));
3392 struct restore_selected_frame_args
{
3393 CORE_ADDR frame_address
;
3397 static int restore_selected_frame
PARAMS ((char *));
3399 /* Restore the selected frame. args is really a struct
3400 restore_selected_frame_args * (declared as char * for catch_errors)
3401 telling us what frame to restore. Returns 1 for success, or 0 for
3402 failure. An error message will have been printed on error. */
3405 restore_selected_frame (args
)
3408 struct restore_selected_frame_args
*fr
=
3409 (struct restore_selected_frame_args
*) args
;
3410 struct frame_info
*frame
;
3411 int level
= fr
->level
;
3413 frame
= find_relative_frame (get_current_frame (), &level
);
3415 /* If inf_status->selected_frame_address is NULL, there was no
3416 previously selected frame. */
3417 if (frame
== NULL
||
3418 /* FRAME_FP (frame) != fr->frame_address ||*/ /* elz: deleted this check as a quick fix
3419 to the problem that for function called by hand
3420 gdb creates no internal frame structure
3421 and the real stack and gdb's idea of stack
3422 are different if nested calls by hands are made*/
3425 warning ("Unable to restore previously selected frame.\n");
3429 select_frame (frame
, fr
->level
);
3435 restore_inferior_status (inf_status
)
3436 struct inferior_status
*inf_status
;
3438 stop_signal
= inf_status
->stop_signal
;
3439 stop_pc
= inf_status
->stop_pc
;
3440 stop_step
= inf_status
->stop_step
;
3441 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3442 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3443 trap_expected
= inf_status
->trap_expected
;
3444 step_range_start
= inf_status
->step_range_start
;
3445 step_range_end
= inf_status
->step_range_end
;
3446 step_frame_address
= inf_status
->step_frame_address
;
3447 step_over_calls
= inf_status
->step_over_calls
;
3448 stop_after_trap
= inf_status
->stop_after_trap
;
3449 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
3450 bpstat_clear (&stop_bpstat
);
3451 stop_bpstat
= inf_status
->stop_bpstat
;
3452 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3453 proceed_to_finish
= inf_status
->proceed_to_finish
;
3455 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
3457 /* The inferior can be gone if the user types "print exit(0)"
3458 (and perhaps other times). */
3459 if (target_has_execution
)
3460 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3462 /* The inferior can be gone if the user types "print exit(0)"
3463 (and perhaps other times). */
3465 /* FIXME: If we are being called after stopping in a function which
3466 is called from gdb, we should not be trying to restore the
3467 selected frame; it just prints a spurious error message (The
3468 message is useful, however, in detecting bugs in gdb (like if gdb
3469 clobbers the stack)). In fact, should we be restoring the
3470 inferior status at all in that case? . */
3472 if (target_has_stack
&& inf_status
->restore_stack_info
)
3474 struct restore_selected_frame_args fr
;
3475 fr
.level
= inf_status
->selected_level
;
3476 fr
.frame_address
= inf_status
->selected_frame_address
;
3477 /* The point of catch_errors is that if the stack is clobbered,
3478 walking the stack might encounter a garbage pointer and error()
3479 trying to dereference it. */
3480 if (catch_errors (restore_selected_frame
, &fr
,
3481 "Unable to restore previously selected frame:\n",
3482 RETURN_MASK_ERROR
) == 0)
3483 /* Error in restoring the selected frame. Select the innermost
3487 select_frame (get_current_frame (), 0);
3495 set_follow_fork_mode_command (arg
, from_tty
, c
)
3498 struct cmd_list_element
* c
;
3500 if (! STREQ (arg
, "parent") &&
3501 ! STREQ (arg
, "child") &&
3502 ! STREQ (arg
, "both") &&
3503 ! STREQ (arg
, "ask"))
3504 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
3506 if (follow_fork_mode_string
!= NULL
)
3507 free (follow_fork_mode_string
);
3508 follow_fork_mode_string
= savestring (arg
, strlen (arg
));
3514 _initialize_infrun ()
3517 register int numsigs
;
3518 struct cmd_list_element
* c
;
3520 add_info ("signals", signals_info
,
3521 "What debugger does when program gets various signals.\n\
3522 Specify a signal as argument to print info on that signal only.");
3523 add_info_alias ("handle", "signals", 0);
3525 add_com ("handle", class_run
, handle_command
,
3526 concat ("Specify how to handle a signal.\n\
3527 Args are signals and actions to apply to those signals.\n\
3528 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3529 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3530 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3531 The special arg \"all\" is recognized to mean all signals except those\n\
3532 used by the debugger, typically SIGTRAP and SIGINT.\n",
3533 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3534 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3535 Stop means reenter debugger if this signal happens (implies print).\n\
3536 Print means print a message if this signal happens.\n\
3537 Pass means let program see this signal; otherwise program doesn't know.\n\
3538 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3539 Pass and Stop may be combined.", NULL
));
3542 add_com("lz", class_info
, signals_info
,
3543 "What debugger does when program gets various signals.\n\
3544 Specify a signal as argument to print info on that signal only.");
3545 add_com("z", class_run
, xdb_handle_command
,
3546 concat ("Specify how to handle a signal.\n\
3547 Args are signals and actions to apply to those signals.\n\
3548 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3549 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3550 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3551 The special arg \"all\" is recognized to mean all signals except those\n\
3552 used by the debugger, typically SIGTRAP and SIGINT.\n",
3553 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3554 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3555 nopass), \"Q\" (noprint)\n\
3556 Stop means reenter debugger if this signal happens (implies print).\n\
3557 Print means print a message if this signal happens.\n\
3558 Pass means let program see this signal; otherwise program doesn't know.\n\
3559 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3560 Pass and Stop may be combined.", NULL
));
3564 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
3565 "There is no `stop' command, but you can set a hook on `stop'.\n\
3566 This allows you to set a list of commands to be run each time execution\n\
3567 of the program stops.", &cmdlist
);
3569 numsigs
= (int)TARGET_SIGNAL_LAST
;
3570 signal_stop
= (unsigned char *)
3571 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
3572 signal_print
= (unsigned char *)
3573 xmalloc (sizeof (signal_print
[0]) * numsigs
);
3574 signal_program
= (unsigned char *)
3575 xmalloc (sizeof (signal_program
[0]) * numsigs
);
3576 for (i
= 0; i
< numsigs
; i
++)
3579 signal_print
[i
] = 1;
3580 signal_program
[i
] = 1;
3583 /* Signals caused by debugger's own actions
3584 should not be given to the program afterwards. */
3585 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
3586 signal_program
[TARGET_SIGNAL_INT
] = 0;
3588 /* Signals that are not errors should not normally enter the debugger. */
3589 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
3590 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
3591 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
3592 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
3593 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
3594 signal_print
[TARGET_SIGNAL_PROF
] = 0;
3595 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
3596 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
3597 signal_stop
[TARGET_SIGNAL_IO
] = 0;
3598 signal_print
[TARGET_SIGNAL_IO
] = 0;
3599 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
3600 signal_print
[TARGET_SIGNAL_POLL
] = 0;
3601 signal_stop
[TARGET_SIGNAL_URG
] = 0;
3602 signal_print
[TARGET_SIGNAL_URG
] = 0;
3606 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
3607 (char *) &stop_on_solib_events
,
3608 "Set stopping for shared library events.\n\
3609 If nonzero, gdb will give control to the user when the dynamic linker\n\
3610 notifies gdb of shared library events. The most common event of interest\n\
3611 to the user would be loading/unloading of a new library.\n",
3616 c
= add_set_enum_cmd ("follow-fork-mode",
3618 follow_fork_mode_kind_names
,
3619 (char *) &follow_fork_mode_string
,
3620 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
3621 kernel problem. It's also not terribly useful without a GUI to
3622 help the user drive two debuggers. So for now, I'm disabling
3624 /* "Set debugger response to a program call of fork or vfork.\n\
3625 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3626 parent - the original process is debugged after a fork\n\
3627 child - the new process is debugged after a fork\n\
3628 both - both the parent and child are debugged after a fork\n\
3629 ask - the debugger will ask for one of the above choices\n\
3630 For \"both\", another copy of the debugger will be started to follow\n\
3631 the new child process. The original debugger will continue to follow\n\
3632 the original parent process. To distinguish their prompts, the\n\
3633 debugger copy's prompt will be changed.\n\
3634 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3635 By default, the debugger will follow the parent process.",
3637 "Set debugger response to a program call of fork or vfork.\n\
3638 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3639 parent - the original process is debugged after a fork\n\
3640 child - the new process is debugged after a fork\n\
3641 ask - the debugger will ask for one of the above choices\n\
3642 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3643 By default, the debugger will follow the parent process.",
3645 /* c->function.sfunc = ;*/
3646 add_show_from_set (c
, &showlist
);
3648 set_follow_fork_mode_command ("parent", 0, NULL
);