1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986, 1987, 1988, 1989, 1991, 1992, 1993
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* Notes on the algorithm used in wait_for_inferior to determine if we
22 just did a subroutine call when stepping. We have the following
23 information at that point:
25 Current and previous (just before this step) pc.
26 Current and previous sp.
27 Current and previous start of current function.
29 If the starts of the functions don't match, then
31 a) We did a subroutine call.
33 In this case, the pc will be at the beginning of a function.
35 b) We did a subroutine return.
41 If we did a longjump, we were doing "nexti", since a next would
42 have attempted to skip over the assembly language routine in which
43 the longjmp is coded and would have simply been the equivalent of a
44 continue. I consider this ok behaivior. We'd like one of two
45 things to happen if we are doing a nexti through the longjmp()
46 routine: 1) It behaves as a stepi, or 2) It acts like a continue as
47 above. Given that this is a special case, and that anybody who
48 thinks that the concept of sub calls is meaningful in the context
49 of a longjmp, I'll take either one. Let's see what happens.
51 Acts like a subroutine return. I can handle that with no problem
54 -->So: If the current and previous beginnings of the current
55 function don't match, *and* the pc is at the start of a function,
56 we've done a subroutine call. If the pc is not at the start of a
57 function, we *didn't* do a subroutine call.
59 -->If the beginnings of the current and previous function do match,
62 a) We just did a recursive call.
64 In this case, we would be at the very beginning of a
65 function and 1) it will have a prologue (don't jump to
66 before prologue, or 2) (we assume here that it doesn't have
67 a prologue) there will have been a change in the stack
68 pointer over the last instruction. (Ie. it's got to put
69 the saved pc somewhere. The stack is the usual place. In
70 a recursive call a register is only an option if there's a
71 prologue to do something with it. This is even true on
72 register window machines; the prologue sets up the new
73 window. It might not be true on a register window machine
74 where the call instruction moved the register window
75 itself. Hmmm. One would hope that the stack pointer would
76 also change. If it doesn't, somebody send me a note, and
77 I'll work out a more general theory.
78 bug-gdb@prep.ai.mit.edu). This is true (albeit slipperly
79 so) on all machines I'm aware of:
81 m68k: Call changes stack pointer. Regular jumps don't.
83 sparc: Recursive calls must have frames and therefor,
86 vax: All calls have frames and hence change the
89 b) We did a return from a recursive call. I don't see that we
90 have either the ability or the need to distinguish this
91 from an ordinary jump. The stack frame will be printed
92 when and if the frame pointer changes; if we are in a
93 function without a frame pointer, it's the users own
96 c) We did a jump within a function. We assume that this is
97 true if we didn't do a recursive call.
99 d) We are in no-man's land ("I see no symbols here"). We
100 don't worry about this; it will make calls look like simple
101 jumps (and the stack frames will be printed when the frame
102 pointer moves), which is a reasonably non-violent response.
110 #include "inferior.h"
111 #include "breakpoint.h"
119 /* unistd.h is needed to #define X_OK */
123 #include <sys/file.h>
126 /* Prototypes for local functions */
129 signals_info
PARAMS ((char *, int));
132 handle_command
PARAMS ((char *, int));
135 sig_print_info
PARAMS ((int));
138 sig_print_header
PARAMS ((void));
141 resume_cleanups
PARAMS ((int));
144 hook_stop_stub
PARAMS ((char *));
146 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
147 program. It needs to examine the jmp_buf argument and extract the PC
148 from it. The return value is non-zero on success, zero otherwise. */
149 #ifndef GET_LONGJMP_TARGET
150 #define GET_LONGJMP_TARGET(PC_ADDR) 0
154 /* Some machines have trampoline code that sits between function callers
155 and the actual functions themselves. If this machine doesn't have
156 such things, disable their processing. */
157 #ifndef SKIP_TRAMPOLINE_CODE
158 #define SKIP_TRAMPOLINE_CODE(pc) 0
161 /* For SVR4 shared libraries, each call goes through a small piece of
162 trampoline code in the ".init" section. IN_SOLIB_TRAMPOLINE evaluates
163 to nonzero if we are current stopped in one of these. */
164 #ifndef IN_SOLIB_TRAMPOLINE
165 #define IN_SOLIB_TRAMPOLINE(pc,name) 0
168 /* On some systems, the PC may be left pointing at an instruction that won't
169 actually be executed. This is usually indicated by a bit in the PSW. If
170 we find ourselves in such a state, then we step the target beyond the
171 nullified instruction before returning control to the user so as to avoid
174 #ifndef INSTRUCTION_NULLIFIED
175 #define INSTRUCTION_NULLIFIED 0
178 /* Tables of how to react to signals; the user sets them. */
180 static unsigned char *signal_stop
;
181 static unsigned char *signal_print
;
182 static unsigned char *signal_program
;
184 #define SET_SIGS(nsigs,sigs,flags) \
186 int signum = (nsigs); \
187 while (signum-- > 0) \
188 if ((sigs)[signum]) \
189 (flags)[signum] = 1; \
192 #define UNSET_SIGS(nsigs,sigs,flags) \
194 int signum = (nsigs); \
195 while (signum-- > 0) \
196 if ((sigs)[signum]) \
197 (flags)[signum] = 0; \
201 /* Command list pointer for the "stop" placeholder. */
203 static struct cmd_list_element
*stop_command
;
205 /* Nonzero if breakpoints are now inserted in the inferior. */
207 static int breakpoints_inserted
;
209 /* Function inferior was in as of last step command. */
211 static struct symbol
*step_start_function
;
213 /* Nonzero if we are expecting a trace trap and should proceed from it. */
215 static int trap_expected
;
217 /* Nonzero if the next time we try to continue the inferior, it will
218 step one instruction and generate a spurious trace trap.
219 This is used to compensate for a bug in HP-UX. */
221 static int trap_expected_after_continue
;
223 /* Nonzero means expecting a trace trap
224 and should stop the inferior and return silently when it happens. */
228 /* Nonzero means expecting a trap and caller will handle it themselves.
229 It is used after attach, due to attaching to a process;
230 when running in the shell before the child program has been exec'd;
231 and when running some kinds of remote stuff (FIXME?). */
233 int stop_soon_quietly
;
235 /* Nonzero if proceed is being used for a "finish" command or a similar
236 situation when stop_registers should be saved. */
238 int proceed_to_finish
;
240 /* Save register contents here when about to pop a stack dummy frame,
241 if-and-only-if proceed_to_finish is set.
242 Thus this contains the return value from the called function (assuming
243 values are returned in a register). */
245 char stop_registers
[REGISTER_BYTES
];
247 /* Nonzero if program stopped due to error trying to insert breakpoints. */
249 static int breakpoints_failed
;
251 /* Nonzero after stop if current stack frame should be printed. */
253 static int stop_print_frame
;
255 #ifdef NO_SINGLE_STEP
256 extern int one_stepped
; /* From machine dependent code */
257 extern void single_step (); /* Same. */
258 #endif /* NO_SINGLE_STEP */
261 /* Things to clean up if we QUIT out of resume (). */
264 resume_cleanups (arg
)
270 /* Resume the inferior, but allow a QUIT. This is useful if the user
271 wants to interrupt some lengthy single-stepping operation
272 (for child processes, the SIGINT goes to the inferior, and so
273 we get a SIGINT random_signal, but for remote debugging and perhaps
274 other targets, that's not true).
276 STEP nonzero if we should step (zero to continue instead).
277 SIG is the signal to give the inferior (zero for none). */
283 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
286 #ifdef NO_SINGLE_STEP
288 single_step(sig
); /* Do it the hard way, w/temp breakpoints */
289 step
= 0; /* ...and don't ask hardware to do it. */
293 /* Handle any optimized stores to the inferior NOW... */
294 #ifdef DO_DEFERRED_STORES
298 target_resume (inferior_pid
, step
, sig
);
299 discard_cleanups (old_cleanups
);
303 /* Clear out all variables saying what to do when inferior is continued.
304 First do this, then set the ones you want, then call `proceed'. */
307 clear_proceed_status ()
310 step_range_start
= 0;
312 step_frame_address
= 0;
313 step_over_calls
= -1;
315 stop_soon_quietly
= 0;
316 proceed_to_finish
= 0;
317 breakpoint_proceeded
= 1; /* We're about to proceed... */
319 /* Discard any remaining commands or status from previous stop. */
320 bpstat_clear (&stop_bpstat
);
323 /* Basic routine for continuing the program in various fashions.
325 ADDR is the address to resume at, or -1 for resume where stopped.
326 SIGGNAL is the signal to give it, or 0 for none,
327 or -1 for act according to how it stopped.
328 STEP is nonzero if should trap after one instruction.
329 -1 means return after that and print nothing.
330 You should probably set various step_... variables
331 before calling here, if you are stepping.
333 You should call clear_proceed_status before calling proceed. */
336 proceed (addr
, siggnal
, step
)
344 step_start_function
= find_pc_function (read_pc ());
348 if (addr
== (CORE_ADDR
)-1)
350 /* If there is a breakpoint at the address we will resume at,
351 step one instruction before inserting breakpoints
352 so that we do not stop right away. */
354 if (breakpoint_here_p (read_pc ()))
360 if (trap_expected_after_continue
)
362 /* If (step == 0), a trap will be automatically generated after
363 the first instruction is executed. Force step one
364 instruction to clear this condition. This should not occur
365 if step is nonzero, but it is harmless in that case. */
367 trap_expected_after_continue
= 0;
371 /* We will get a trace trap after one instruction.
372 Continue it automatically and insert breakpoints then. */
376 int temp
= insert_breakpoints ();
379 print_sys_errmsg ("ptrace", temp
);
380 error ("Cannot insert breakpoints.\n\
381 The same program may be running in another process.");
383 breakpoints_inserted
= 1;
386 /* Install inferior's terminal modes. */
387 target_terminal_inferior ();
390 stop_signal
= siggnal
;
391 /* If this signal should not be seen by program,
392 give it zero. Used for debugging signals. */
393 else if (stop_signal
< NSIG
&& !signal_program
[stop_signal
])
396 /* Resume inferior. */
397 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
399 /* Wait for it to stop (if not standalone)
400 and in any case decode why it stopped, and act accordingly. */
402 wait_for_inferior ();
406 /* Record the pc and sp of the program the last time it stopped.
407 These are just used internally by wait_for_inferior, but need
408 to be preserved over calls to it and cleared when the inferior
410 static CORE_ADDR prev_pc
;
411 static CORE_ADDR prev_sp
;
412 static CORE_ADDR prev_func_start
;
413 static char *prev_func_name
;
416 /* Start remote-debugging of a machine over a serial link. */
421 init_wait_for_inferior ();
422 clear_proceed_status ();
423 stop_soon_quietly
= 1;
425 wait_for_inferior ();
429 /* Initialize static vars when a new inferior begins. */
432 init_wait_for_inferior ()
434 /* These are meaningless until the first time through wait_for_inferior. */
438 prev_func_name
= NULL
;
440 trap_expected_after_continue
= 0;
441 breakpoints_inserted
= 0;
442 mark_breakpoints_out ();
443 stop_signal
= 0; /* Don't confuse first call to proceed(). */
447 delete_breakpoint_current_contents (arg
)
450 struct breakpoint
**breakpointp
= (struct breakpoint
**)arg
;
451 if (*breakpointp
!= NULL
)
452 delete_breakpoint (*breakpointp
);
455 /* Wait for control to return from inferior to debugger.
456 If inferior gets a signal, we may decide to start it up again
457 instead of returning. That is why there is a loop in this function.
458 When this function actually returns it means the inferior
459 should be left stopped and GDB should read more commands. */
464 struct cleanup
*old_cleanups
;
468 CORE_ADDR stop_sp
= 0;
469 CORE_ADDR stop_func_start
;
470 char *stop_func_name
;
471 CORE_ADDR prologue_pc
= 0, tmp
;
472 struct symtab_and_line sal
;
473 int remove_breakpoints_on_following_step
= 0;
475 int handling_longjmp
= 0; /* FIXME */
476 struct breakpoint
*step_resume_breakpoint
= NULL
;
479 old_cleanups
= make_cleanup (delete_breakpoint_current_contents
,
480 &step_resume_breakpoint
);
481 sal
= find_pc_line(prev_pc
, 0);
482 current_line
= sal
.line
;
486 /* Clean up saved state that will become invalid. */
487 flush_cached_frames ();
488 registers_changed ();
490 pid
= target_wait (&w
);
492 #ifdef SIGTRAP_STOP_AFTER_LOAD
494 /* Somebody called load(2), and it gave us a "trap signal after load".
495 Ignore it gracefully. */
497 SIGTRAP_STOP_AFTER_LOAD (w
);
500 /* See if the process still exists; clean up if it doesn't. */
503 target_terminal_ours (); /* Must do this before mourn anyway */
505 printf_filtered ("\nProgram exited with code 0%o.\n",
506 (unsigned int)WEXITSTATUS (w
));
509 printf_filtered ("\nProgram exited normally.\n");
511 target_mourn_inferior ();
512 #ifdef NO_SINGLE_STEP
515 stop_print_frame
= 0;
518 else if (!WIFSTOPPED (w
))
522 stop_print_frame
= 0;
523 stop_signal
= WTERMSIG (w
);
524 target_terminal_ours (); /* Must do this before mourn anyway */
525 target_kill (); /* kill mourns as well */
526 #ifdef PRINT_RANDOM_SIGNAL
527 printf_filtered ("\nProgram terminated: ");
528 PRINT_RANDOM_SIGNAL (stop_signal
);
530 printf_filtered ("\nProgram terminated with signal ");
531 signame
= strsigno (stop_signal
);
533 printf_filtered ("%d", stop_signal
);
535 /* Do we need to print the number in addition to the name? */
536 printf_filtered ("%s (%d)", signame
, stop_signal
);
537 printf_filtered (", %s\n", safe_strsignal (stop_signal
));
539 printf_filtered ("The program no longer exists.\n");
541 #ifdef NO_SINGLE_STEP
547 if (pid
!= inferior_pid
)
551 if (!in_thread_list (pid
))
553 fprintf (stderr
, "[New %s]\n", target_pid_to_str (pid
));
556 target_resume (pid
, 0, 0);
561 stop_signal
= WSTOPSIG (w
);
563 if (stop_signal
>= NSIG
|| signal_print
[stop_signal
])
568 target_terminal_ours_for_output ();
569 printf_filtered ("\nProgram received signal ");
570 signame
= strsigno (stop_signal
);
572 printf_filtered ("%d", stop_signal
);
574 printf_filtered ("%s (%d)", signame
, stop_signal
);
575 printf_filtered (", %s\n", safe_strsignal (stop_signal
));
580 if (stop_signal
>= NSIG
|| signal_stop
[stop_signal
])
583 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid
));
585 flush_cached_frames ();
586 registers_changed ();
588 if (step_resume_breakpoint
)
590 delete_breakpoint (step_resume_breakpoint
);
591 step_resume_breakpoint
= NULL
;
595 prev_func_name
= NULL
;
596 step_range_start
= 0;
598 step_frame_address
= 0;
599 handling_longjmp
= 0;
605 target_terminal_inferior ();
607 /* Clear the signal if it should not be passed. */
608 if (signal_program
[stop_signal
] == 0)
611 target_resume (pid
, 0, stop_signal
);
617 #ifdef NO_SINGLE_STEP
619 single_step (0); /* This actually cleans up the ss */
620 #endif /* NO_SINGLE_STEP */
622 /* If PC is pointing at a nullified instruction, then step beyond it so that
623 the user won't be confused when GDB appears to be ready to execute it. */
625 if (INSTRUCTION_NULLIFIED
)
631 stop_pc
= read_pc ();
632 set_current_frame ( create_new_frame (read_fp (), stop_pc
));
634 stop_frame_address
= FRAME_FP (get_current_frame ());
635 stop_sp
= read_sp ();
638 /* Don't care about return value; stop_func_start and stop_func_name
639 will both be 0 if it doesn't work. */
640 find_pc_partial_function (stop_pc
, &stop_func_name
, &stop_func_start
,
642 stop_func_start
+= FUNCTION_START_OFFSET
;
644 bpstat_clear (&stop_bpstat
);
646 stop_stack_dummy
= 0;
647 stop_print_frame
= 1;
649 stopped_by_random_signal
= 0;
650 breakpoints_failed
= 0;
652 /* Look at the cause of the stop, and decide what to do.
653 The alternatives are:
654 1) break; to really stop and return to the debugger,
655 2) drop through to start up again
656 (set another_trap to 1 to single step once)
657 3) set random_signal to 1, and the decision between 1 and 2
658 will be made according to the signal handling tables. */
660 stop_signal
= WSTOPSIG (w
);
662 /* First, distinguish signals caused by the debugger from signals
663 that have to do with the program's own actions.
664 Note that breakpoint insns may cause SIGTRAP or SIGILL
665 or SIGEMT, depending on the operating system version.
666 Here we detect when a SIGILL or SIGEMT is really a breakpoint
667 and change it to SIGTRAP. */
669 if (stop_signal
== SIGTRAP
670 || (breakpoints_inserted
&&
671 (stop_signal
== SIGILL
673 || stop_signal
== SIGEMT
676 || stop_soon_quietly
)
678 if (stop_signal
== SIGTRAP
&& stop_after_trap
)
680 stop_print_frame
= 0;
683 if (stop_soon_quietly
)
686 /* Don't even think about breakpoints
687 if just proceeded over a breakpoint.
689 However, if we are trying to proceed over a breakpoint
690 and end up in sigtramp, then step_resume_breakpoint
691 will be set and we should check whether we've hit the
693 if (stop_signal
== SIGTRAP
&& trap_expected
694 && step_resume_breakpoint
== NULL
)
695 bpstat_clear (&stop_bpstat
);
698 /* See if there is a breakpoint at the current PC. */
699 #if DECR_PC_AFTER_BREAK
700 /* Notice the case of stepping through a jump
701 that lands just after a breakpoint.
702 Don't confuse that with hitting the breakpoint.
703 What we check for is that 1) stepping is going on
704 and 2) the pc before the last insn does not match
705 the address of the breakpoint before the current pc. */
706 if (prev_pc
== stop_pc
- DECR_PC_AFTER_BREAK
708 || step_resume_breakpoint
!= NULL
709 || handling_longjmp
/* FIXME */)
710 #endif /* DECR_PC_AFTER_BREAK not zero */
713 bpstat_stop_status (&stop_pc
, stop_frame_address
);
714 /* Following in case break condition called a
716 stop_print_frame
= 1;
720 if (stop_signal
== SIGTRAP
)
722 = !(bpstat_explains_signal (stop_bpstat
)
724 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
725 || PC_IN_CALL_DUMMY (stop_pc
, stop_sp
, stop_frame_address
)
726 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
727 || (step_range_end
&& step_resume_breakpoint
== NULL
));
731 = !(bpstat_explains_signal (stop_bpstat
)
732 /* End of a stack dummy. Some systems (e.g. Sony
733 news) give another signal besides SIGTRAP,
734 so check here as well as above. */
735 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
736 || PC_IN_CALL_DUMMY (stop_pc
, stop_sp
, stop_frame_address
)
737 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
740 stop_signal
= SIGTRAP
;
746 /* For the program's own signals, act according to
747 the signal handling tables. */
751 /* Signal not for debugging purposes. */
754 stopped_by_random_signal
= 1;
756 if (stop_signal
>= NSIG
757 || signal_print
[stop_signal
])
761 target_terminal_ours_for_output ();
762 #ifdef PRINT_RANDOM_SIGNAL
763 PRINT_RANDOM_SIGNAL (stop_signal
);
765 printf_filtered ("\nProgram received signal ");
766 signame
= strsigno (stop_signal
);
768 printf_filtered ("%d", stop_signal
);
770 /* Do we need to print the number as well as the name? */
771 printf_filtered ("%s (%d)", signame
, stop_signal
);
772 printf_filtered (", %s\n", safe_strsignal (stop_signal
));
773 #endif /* PRINT_RANDOM_SIGNAL */
776 if (stop_signal
>= NSIG
777 || signal_stop
[stop_signal
])
779 /* If not going to stop, give terminal back
780 if we took it away. */
782 target_terminal_inferior ();
784 /* Clear the signal if it should not be passed. */
785 if (signal_program
[stop_signal
] == 0)
788 /* I'm not sure whether this needs to be check_sigtramp2 or
789 whether it could/should be keep_going. */
790 goto check_sigtramp2
;
793 /* Handle cases caused by hitting a breakpoint. */
795 CORE_ADDR jmp_buf_pc
;
796 struct bpstat_what what
;
798 what
= bpstat_what (stop_bpstat
);
802 stop_stack_dummy
= 1;
804 trap_expected_after_continue
= 1;
808 switch (what
.main_action
)
810 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
811 /* If we hit the breakpoint at longjmp, disable it for the
812 duration of this command. Then, install a temporary
813 breakpoint at the target of the jmp_buf. */
814 disable_longjmp_breakpoint();
815 remove_breakpoints ();
816 breakpoints_inserted
= 0;
817 if (!GET_LONGJMP_TARGET(&jmp_buf_pc
)) goto keep_going
;
819 /* Need to blow away step-resume breakpoint, as it
820 interferes with us */
821 if (step_resume_breakpoint
!= NULL
)
823 delete_breakpoint (step_resume_breakpoint
);
824 step_resume_breakpoint
= NULL
;
825 what
.step_resume
= 0;
829 /* FIXME - Need to implement nested temporary breakpoints */
830 if (step_over_calls
> 0)
831 set_longjmp_resume_breakpoint(jmp_buf_pc
,
832 get_current_frame());
835 set_longjmp_resume_breakpoint(jmp_buf_pc
, NULL
);
836 handling_longjmp
= 1; /* FIXME */
839 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
840 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
841 remove_breakpoints ();
842 breakpoints_inserted
= 0;
844 /* FIXME - Need to implement nested temporary breakpoints */
846 && (stop_frame_address
847 INNER_THAN step_frame_address
))
853 disable_longjmp_breakpoint();
854 handling_longjmp
= 0; /* FIXME */
855 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
857 /* else fallthrough */
859 case BPSTAT_WHAT_SINGLE
:
860 if (breakpoints_inserted
)
861 remove_breakpoints ();
862 breakpoints_inserted
= 0;
864 /* Still need to check other stuff, at least the case
865 where we are stepping and step out of the right range. */
868 case BPSTAT_WHAT_STOP_NOISY
:
869 stop_print_frame
= 1;
870 /* We are about to nuke the step_resume_breakpoint via the
871 cleanup chain, so no need to worry about it here. */
874 case BPSTAT_WHAT_STOP_SILENT
:
875 stop_print_frame
= 0;
876 /* We are about to nuke the step_resume_breakpoint via the
877 cleanup chain, so no need to worry about it here. */
880 case BPSTAT_WHAT_KEEP_CHECKING
:
884 if (what
.step_resume
)
886 delete_breakpoint (step_resume_breakpoint
);
887 step_resume_breakpoint
= NULL
;
889 /* If were waiting for a trap, hitting the step_resume_break
890 doesn't count as getting it. */
896 /* We come here if we hit a breakpoint but should not
897 stop for it. Possibly we also were stepping
898 and should stop for that. So fall through and
899 test for stepping. But, if not stepping,
902 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
903 /* This is the old way of detecting the end of the stack dummy.
904 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
905 handled above. As soon as we can test it on all of them, all
906 architectures should define it. */
908 /* If this is the breakpoint at the end of a stack dummy,
909 just stop silently, unless the user was doing an si/ni, in which
910 case she'd better know what she's doing. */
912 if (PC_IN_CALL_DUMMY (stop_pc
, stop_sp
, stop_frame_address
)
915 stop_print_frame
= 0;
916 stop_stack_dummy
= 1;
918 trap_expected_after_continue
= 1;
922 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
924 if (step_resume_breakpoint
)
925 /* Having a step-resume breakpoint overrides anything
926 else having to do with stepping commands until
927 that breakpoint is reached. */
928 /* I suspect this could/should be keep_going, because if the
929 check_sigtramp2 check succeeds, then it will put in another
930 step_resume_breakpoint, and we aren't (yet) prepared to nest
932 goto check_sigtramp2
;
934 if (step_range_end
== 0)
935 /* Likewise if we aren't even stepping. */
936 /* I'm not sure whether this needs to be check_sigtramp2 or
937 whether it could/should be keep_going. */
938 goto check_sigtramp2
;
940 /* If stepping through a line, keep going if still within it. */
941 if (stop_pc
>= step_range_start
942 && stop_pc
< step_range_end
943 /* The step range might include the start of the
944 function, so if we are at the start of the
945 step range and either the stack or frame pointers
946 just changed, we've stepped outside */
947 && !(stop_pc
== step_range_start
948 && stop_frame_address
949 && (stop_sp INNER_THAN prev_sp
950 || stop_frame_address
!= step_frame_address
)))
952 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
953 So definately need to check for sigtramp here. */
954 goto check_sigtramp2
;
957 /* We stepped out of the stepping range. See if that was due
958 to a subroutine call that we should proceed to the end of. */
960 /* Did we just take a signal? */
961 if (IN_SIGTRAMP (stop_pc
, stop_func_name
)
962 && !IN_SIGTRAMP (prev_pc
, prev_func_name
))
964 /* This code is needed at least in the following case:
965 The user types "next" and then a signal arrives (before
966 the "next" is done). */
967 /* We've just taken a signal; go until we are back to
968 the point where we took it and one more. */
970 struct symtab_and_line sr_sal
;
973 sr_sal
.symtab
= NULL
;
975 step_resume_breakpoint
=
976 set_momentary_breakpoint (sr_sal
, get_current_frame (),
978 if (breakpoints_inserted
)
979 insert_breakpoints ();
982 /* If this is stepi or nexti, make sure that the stepping range
983 gets us past that instruction. */
984 if (step_range_end
== 1)
985 /* FIXME: Does this run afoul of the code below which, if
986 we step into the middle of a line, resets the stepping
988 step_range_end
= (step_range_start
= prev_pc
) + 1;
990 remove_breakpoints_on_following_step
= 1;
996 /* Do this after the IN_SIGTRAMP check; it might give
998 prologue_pc
= stop_func_start
;
999 SKIP_PROLOGUE (prologue_pc
);
1002 /* ==> See comments at top of file on this algorithm. <==*/
1004 if ((stop_pc
== stop_func_start
1005 || IN_SOLIB_TRAMPOLINE (stop_pc
, stop_func_name
))
1006 && (stop_func_start
!= prev_func_start
1007 || prologue_pc
!= stop_func_start
1008 || stop_sp
!= prev_sp
))
1010 /* It's a subroutine call. */
1012 if (step_over_calls
== 0)
1014 /* I presume that step_over_calls is only 0 when we're
1015 supposed to be stepping at the assembly language level
1016 ("stepi"). Just stop. */
1021 if (step_over_calls
> 0)
1022 /* We're doing a "next". */
1023 goto step_over_function
;
1025 /* If we are in a function call trampoline (a stub between
1026 the calling routine and the real function), locate the real
1027 function. That's what tells us (a) whether we want to step
1028 into it at all, and (b) what prologue we want to run to
1029 the end of, if we do step into it. */
1030 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
1032 stop_func_start
= tmp
;
1034 /* If we have line number information for the function we
1035 are thinking of stepping into, step into it.
1037 If there are several symtabs at that PC (e.g. with include
1038 files), just want to know whether *any* of them have line
1039 numbers. find_pc_line handles this. */
1041 struct symtab_and_line tmp_sal
;
1043 tmp_sal
= find_pc_line (stop_func_start
, 0);
1044 if (tmp_sal
.line
!= 0)
1045 goto step_into_function
;
1049 /* A subroutine call has happened. */
1051 /* Set a special breakpoint after the return */
1052 struct symtab_and_line sr_sal
;
1055 (SAVED_PC_AFTER_CALL (get_current_frame ()));
1056 sr_sal
.symtab
= NULL
;
1058 step_resume_breakpoint
=
1059 set_momentary_breakpoint (sr_sal
, get_current_frame (),
1061 if (breakpoints_inserted
)
1062 insert_breakpoints ();
1067 /* Subroutine call with source code we should not step over.
1068 Do step to the first line of code in it. */
1069 SKIP_PROLOGUE (stop_func_start
);
1070 sal
= find_pc_line (stop_func_start
, 0);
1071 /* Use the step_resume_break to step until
1072 the end of the prologue, even if that involves jumps
1073 (as it seems to on the vax under 4.2). */
1074 /* If the prologue ends in the middle of a source line,
1075 continue to the end of that source line.
1076 Otherwise, just go to end of prologue. */
1077 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1078 /* no, don't either. It skips any code that's
1079 legitimately on the first line. */
1081 if (sal
.end
&& sal
.pc
!= stop_func_start
)
1082 stop_func_start
= sal
.end
;
1085 if (stop_func_start
== stop_pc
)
1087 /* We are already there: stop now. */
1092 /* Put the step-breakpoint there and go until there. */
1094 struct symtab_and_line sr_sal
;
1096 sr_sal
.pc
= stop_func_start
;
1097 sr_sal
.symtab
= NULL
;
1099 /* Do not specify what the fp should be when we stop
1100 since on some machines the prologue
1101 is where the new fp value is established. */
1102 step_resume_breakpoint
=
1103 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
1104 if (breakpoints_inserted
)
1105 insert_breakpoints ();
1107 /* And make sure stepping stops right away then. */
1108 step_range_end
= step_range_start
;
1113 /* We've wandered out of the step range (but haven't done a
1114 subroutine call or return). (Is that true? I think we get
1115 here if we did a return and maybe a longjmp). */
1117 sal
= find_pc_line(stop_pc
, 0);
1119 if (step_range_end
== 1)
1121 /* It is stepi or nexti. We always want to stop stepping after
1129 /* We have no line number information. That means to stop
1130 stepping (does this always happen right after one instruction,
1131 when we do "s" in a function with no line numbers,
1132 or can this happen as a result of a return or longjmp?). */
1137 if (stop_pc
== sal
.pc
&& current_line
!= sal
.line
)
1139 /* We are at the start of a different line. So stop. Note that
1140 we don't stop if we step into the middle of a different line.
1141 That is said to make things like for (;;) statements work
1147 /* We aren't done stepping.
1149 Optimize by setting the stepping range to the line.
1150 (We might not be in the original line, but if we entered a
1151 new line in mid-statement, we continue stepping. This makes
1152 things like for(;;) statements work better.) */
1153 step_range_start
= sal
.pc
;
1154 step_range_end
= sal
.end
;
1159 && IN_SIGTRAMP (stop_pc
, stop_func_name
)
1160 && !IN_SIGTRAMP (prev_pc
, prev_func_name
))
1162 /* What has happened here is that we have just stepped the inferior
1163 with a signal (because it is a signal which shouldn't make
1164 us stop), thus stepping into sigtramp.
1166 So we need to set a step_resume_break_address breakpoint
1167 and continue until we hit it, and then step. FIXME: This should
1168 be more enduring than a step_resume breakpoint; we should know
1169 that we will later need to keep going rather than re-hitting
1170 the breakpoint here (see testsuite/gdb.t06/signals.exp where
1171 it says "exceedingly difficult"). */
1172 struct symtab_and_line sr_sal
;
1174 sr_sal
.pc
= prev_pc
;
1175 sr_sal
.symtab
= NULL
;
1177 step_resume_breakpoint
=
1178 set_momentary_breakpoint (sr_sal
, get_current_frame (),
1180 if (breakpoints_inserted
)
1181 insert_breakpoints ();
1183 remove_breakpoints_on_following_step
= 1;
1188 /* Come to this label when you need to resume the inferior.
1189 It's really much cleaner to do a goto than a maze of if-else
1192 /* Save the pc before execution, to compare with pc after stop. */
1193 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
1194 prev_func_start
= stop_func_start
; /* Ok, since if DECR_PC_AFTER
1195 BREAK is defined, the
1196 original pc would not have
1197 been at the start of a
1199 prev_func_name
= stop_func_name
;
1202 /* If we did not do break;, it means we should keep
1203 running the inferior and not return to debugger. */
1205 if (trap_expected
&& stop_signal
!= SIGTRAP
)
1207 /* We took a signal (which we are supposed to pass through to
1208 the inferior, else we'd have done a break above) and we
1209 haven't yet gotten our trap. Simply continue. */
1210 resume ((step_range_end
&& step_resume_breakpoint
== NULL
)
1211 || (trap_expected
&& step_resume_breakpoint
== NULL
)
1212 || bpstat_should_step (),
1217 /* Either the trap was not expected, but we are continuing
1218 anyway (the user asked that this signal be passed to the
1221 The signal was SIGTRAP, e.g. it was our signal, but we
1222 decided we should resume from it.
1224 We're going to run this baby now!
1226 Insert breakpoints now, unless we are trying
1227 to one-proceed past a breakpoint. */
1228 /* If we've just finished a special step resume and we don't
1229 want to hit a breakpoint, pull em out. */
1230 if (step_resume_breakpoint
== NULL
&&
1231 remove_breakpoints_on_following_step
)
1233 remove_breakpoints_on_following_step
= 0;
1234 remove_breakpoints ();
1235 breakpoints_inserted
= 0;
1237 else if (!breakpoints_inserted
&&
1238 (step_resume_breakpoint
!= NULL
|| !another_trap
))
1240 breakpoints_failed
= insert_breakpoints ();
1241 if (breakpoints_failed
)
1243 breakpoints_inserted
= 1;
1246 trap_expected
= another_trap
;
1248 if (stop_signal
== SIGTRAP
)
1251 #ifdef SHIFT_INST_REGS
1252 /* I'm not sure when this following segment applies. I do know, now,
1253 that we shouldn't rewrite the regs when we were stopped by a
1254 random signal from the inferior process. */
1256 if (!bpstat_explains_signal (stop_bpstat
)
1257 && (stop_signal
!= SIGCLD
)
1258 && !stopped_by_random_signal
)
1260 CORE_ADDR pc_contents
= read_register (PC_REGNUM
);
1261 CORE_ADDR npc_contents
= read_register (NPC_REGNUM
);
1262 if (pc_contents
!= npc_contents
)
1264 write_register (NNPC_REGNUM
, npc_contents
);
1265 write_register (NPC_REGNUM
, pc_contents
);
1268 #endif /* SHIFT_INST_REGS */
1270 resume ((step_resume_breakpoint
== NULL
1271 && !handling_longjmp
1274 || bpstat_should_step (),
1280 if (target_has_execution
)
1282 /* Assuming the inferior still exists, set these up for next
1283 time, just like we did above if we didn't break out of the
1285 prev_pc
= read_pc ();
1286 prev_func_start
= stop_func_start
;
1287 prev_func_name
= stop_func_name
;
1290 do_cleanups (old_cleanups
);
1293 /* Here to return control to GDB when the inferior stops for real.
1294 Print appropriate messages, remove breakpoints, give terminal our modes.
1296 STOP_PRINT_FRAME nonzero means print the executing frame
1297 (pc, function, args, file, line number and line text).
1298 BREAKPOINTS_FAILED nonzero means stop was due to error
1299 attempting to insert breakpoints. */
1304 /* Make sure that the current_frame's pc is correct. This
1305 is a correction for setting up the frame info before doing
1306 DECR_PC_AFTER_BREAK */
1307 if (target_has_execution
)
1308 (get_current_frame ())->pc
= read_pc ();
1310 if (breakpoints_failed
)
1312 target_terminal_ours_for_output ();
1313 print_sys_errmsg ("ptrace", breakpoints_failed
);
1314 printf_filtered ("Stopped; cannot insert breakpoints.\n\
1315 The same program may be running in another process.\n");
1318 if (target_has_execution
&& breakpoints_inserted
)
1319 if (remove_breakpoints ())
1321 target_terminal_ours_for_output ();
1322 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
1323 It might be running in another process.\n\
1324 Further execution is probably impossible.\n");
1327 breakpoints_inserted
= 0;
1329 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1330 Delete any breakpoint that is to be deleted at the next stop. */
1332 breakpoint_auto_delete (stop_bpstat
);
1334 /* If an auto-display called a function and that got a signal,
1335 delete that auto-display to avoid an infinite recursion. */
1337 if (stopped_by_random_signal
)
1338 disable_current_display ();
1340 if (step_multi
&& stop_step
)
1343 target_terminal_ours ();
1345 /* Look up the hook_stop and run it if it exists. */
1347 if (stop_command
->hook
)
1349 catch_errors (hook_stop_stub
, (char *)stop_command
->hook
,
1350 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
1353 if (!target_has_stack
)
1356 /* Select innermost stack frame except on return from a stack dummy routine,
1357 or if the program has exited. Print it without a level number if
1358 we have changed functions or hit a breakpoint. Print source line
1360 if (!stop_stack_dummy
)
1362 select_frame (get_current_frame (), 0);
1364 if (stop_print_frame
)
1368 source_only
= bpstat_print (stop_bpstat
);
1369 source_only
= source_only
||
1371 && step_frame_address
== stop_frame_address
1372 && step_start_function
== find_pc_function (stop_pc
));
1374 print_stack_frame (selected_frame
, -1, source_only
? -1: 1);
1376 /* Display the auto-display expressions. */
1381 /* Save the function value return registers, if we care.
1382 We might be about to restore their previous contents. */
1383 if (proceed_to_finish
)
1384 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
1386 if (stop_stack_dummy
)
1388 /* Pop the empty frame that contains the stack dummy.
1389 POP_FRAME ends with a setting of the current frame, so we
1390 can use that next. */
1392 select_frame (get_current_frame (), 0);
1397 hook_stop_stub (cmd
)
1400 execute_user_command ((struct cmd_list_element
*)cmd
, 0);
1404 int signal_stop_state (signo
)
1407 return ((signo
>= 0 && signo
< NSIG
) ? signal_stop
[signo
] : 0);
1410 int signal_print_state (signo
)
1413 return ((signo
>= 0 && signo
< NSIG
) ? signal_print
[signo
] : 0);
1416 int signal_pass_state (signo
)
1419 return ((signo
>= 0 && signo
< NSIG
) ? signal_program
[signo
] : 0);
1425 printf_filtered ("Signal\t\tStop\tPrint\tPass to program\tDescription\n");
1429 sig_print_info (number
)
1434 if ((name
= strsigno (number
)) == NULL
)
1435 printf_filtered ("%d\t\t", number
);
1437 printf_filtered ("%s (%d)\t", name
, number
);
1438 printf_filtered ("%s\t", signal_stop
[number
] ? "Yes" : "No");
1439 printf_filtered ("%s\t", signal_print
[number
] ? "Yes" : "No");
1440 printf_filtered ("%s\t\t", signal_program
[number
] ? "Yes" : "No");
1441 printf_filtered ("%s\n", safe_strsignal (number
));
1444 /* Specify how various signals in the inferior should be handled. */
1447 handle_command (args
, from_tty
)
1452 int digits
, wordlen
;
1453 int sigfirst
, signum
, siglast
;
1456 unsigned char *sigs
;
1457 struct cleanup
*old_chain
;
1461 error_no_arg ("signal to handle");
1464 /* Allocate and zero an array of flags for which signals to handle. */
1466 nsigs
= signo_max () + 1;
1467 sigs
= (unsigned char *) alloca (nsigs
);
1468 memset (sigs
, 0, nsigs
);
1470 /* Break the command line up into args. */
1472 argv
= buildargv (args
);
1477 old_chain
= make_cleanup (freeargv
, (char *) argv
);
1479 /* Walk through the args, looking for signal numbers, signal names, and
1480 actions. Signal numbers and signal names may be interspersed with
1481 actions, with the actions being performed for all signals cumulatively
1482 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
1484 while (*argv
!= NULL
)
1486 wordlen
= strlen (*argv
);
1487 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++) {;}
1489 sigfirst
= siglast
= -1;
1491 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
1493 /* Apply action to all signals except those used by the
1494 debugger. Silently skip those. */
1497 siglast
= nsigs
- 1;
1499 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
1501 SET_SIGS (nsigs
, sigs
, signal_stop
);
1502 SET_SIGS (nsigs
, sigs
, signal_print
);
1504 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
1506 UNSET_SIGS (nsigs
, sigs
, signal_program
);
1508 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
1510 SET_SIGS (nsigs
, sigs
, signal_print
);
1512 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
1514 SET_SIGS (nsigs
, sigs
, signal_program
);
1516 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
1518 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
1520 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
1522 SET_SIGS (nsigs
, sigs
, signal_program
);
1524 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
1526 UNSET_SIGS (nsigs
, sigs
, signal_print
);
1527 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
1529 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
1531 UNSET_SIGS (nsigs
, sigs
, signal_program
);
1533 else if (digits
> 0)
1535 sigfirst
= siglast
= atoi (*argv
);
1536 if ((*argv
)[digits
] == '-')
1538 siglast
= atoi ((*argv
) + digits
+ 1);
1540 if (sigfirst
> siglast
)
1542 /* Bet he didn't figure we'd think of this case... */
1547 if (sigfirst
< 0 || sigfirst
>= nsigs
)
1549 error ("Signal %d not in range 0-%d", sigfirst
, nsigs
- 1);
1551 if (siglast
< 0 || siglast
>= nsigs
)
1553 error ("Signal %d not in range 0-%d", siglast
, nsigs
- 1);
1556 else if ((signum
= strtosigno (*argv
)) != 0)
1558 sigfirst
= siglast
= signum
;
1562 /* Not a number and not a recognized flag word => complain. */
1563 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
1566 /* If any signal numbers or symbol names were found, set flags for
1567 which signals to apply actions to. */
1569 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
1575 if (!allsigs
&& !sigs
[signum
])
1577 if (query ("%s is used by the debugger.\nAre you sure you want to change it? ", strsigno (signum
)))
1583 printf ("Not confirmed, unchanged.\n");
1597 target_notice_signals();
1601 /* Show the results. */
1602 sig_print_header ();
1603 for (signum
= 0; signum
< nsigs
; signum
++)
1607 sig_print_info (signum
);
1612 do_cleanups (old_chain
);
1615 /* Print current contents of the tables set by the handle command. */
1618 signals_info (signum_exp
, from_tty
)
1623 sig_print_header ();
1627 /* First see if this is a symbol name. */
1628 i
= strtosigno (signum_exp
);
1631 /* Nope, maybe it's an address which evaluates to a signal
1633 i
= parse_and_eval_address (signum_exp
);
1634 if (i
>= NSIG
|| i
< 0)
1635 error ("Signal number out of bounds.");
1641 printf_filtered ("\n");
1642 for (i
= 0; i
< NSIG
; i
++)
1649 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
1652 /* Save all of the information associated with the inferior<==>gdb
1653 connection. INF_STATUS is a pointer to a "struct inferior_status"
1654 (defined in inferior.h). */
1657 save_inferior_status (inf_status
, restore_stack_info
)
1658 struct inferior_status
*inf_status
;
1659 int restore_stack_info
;
1661 inf_status
->stop_signal
= stop_signal
;
1662 inf_status
->stop_pc
= stop_pc
;
1663 inf_status
->stop_frame_address
= stop_frame_address
;
1664 inf_status
->stop_step
= stop_step
;
1665 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
1666 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
1667 inf_status
->trap_expected
= trap_expected
;
1668 inf_status
->step_range_start
= step_range_start
;
1669 inf_status
->step_range_end
= step_range_end
;
1670 inf_status
->step_frame_address
= step_frame_address
;
1671 inf_status
->step_over_calls
= step_over_calls
;
1672 inf_status
->stop_after_trap
= stop_after_trap
;
1673 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
1674 /* Save original bpstat chain here; replace it with copy of chain.
1675 If caller's caller is walking the chain, they'll be happier if we
1676 hand them back the original chain when restore_i_s is called. */
1677 inf_status
->stop_bpstat
= stop_bpstat
;
1678 stop_bpstat
= bpstat_copy (stop_bpstat
);
1679 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
1680 inf_status
->restore_stack_info
= restore_stack_info
;
1681 inf_status
->proceed_to_finish
= proceed_to_finish
;
1683 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
1685 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
1687 record_selected_frame (&(inf_status
->selected_frame_address
),
1688 &(inf_status
->selected_level
));
1692 struct restore_selected_frame_args
{
1693 FRAME_ADDR frame_address
;
1697 static int restore_selected_frame
PARAMS ((char *));
1699 /* Restore the selected frame. args is really a struct
1700 restore_selected_frame_args * (declared as char * for catch_errors)
1701 telling us what frame to restore. Returns 1 for success, or 0 for
1702 failure. An error message will have been printed on error. */
1704 restore_selected_frame (args
)
1707 struct restore_selected_frame_args
*fr
=
1708 (struct restore_selected_frame_args
*) args
;
1710 int level
= fr
->level
;
1712 fid
= find_relative_frame (get_current_frame (), &level
);
1714 /* If inf_status->selected_frame_address is NULL, there was no
1715 previously selected frame. */
1717 FRAME_FP (fid
) != fr
->frame_address
||
1720 warning ("Unable to restore previously selected frame.\n");
1723 select_frame (fid
, fr
->level
);
1728 restore_inferior_status (inf_status
)
1729 struct inferior_status
*inf_status
;
1731 stop_signal
= inf_status
->stop_signal
;
1732 stop_pc
= inf_status
->stop_pc
;
1733 stop_frame_address
= inf_status
->stop_frame_address
;
1734 stop_step
= inf_status
->stop_step
;
1735 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
1736 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
1737 trap_expected
= inf_status
->trap_expected
;
1738 step_range_start
= inf_status
->step_range_start
;
1739 step_range_end
= inf_status
->step_range_end
;
1740 step_frame_address
= inf_status
->step_frame_address
;
1741 step_over_calls
= inf_status
->step_over_calls
;
1742 stop_after_trap
= inf_status
->stop_after_trap
;
1743 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
1744 bpstat_clear (&stop_bpstat
);
1745 stop_bpstat
= inf_status
->stop_bpstat
;
1746 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
1747 proceed_to_finish
= inf_status
->proceed_to_finish
;
1749 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
1751 /* The inferior can be gone if the user types "print exit(0)"
1752 (and perhaps other times). */
1753 if (target_has_execution
)
1754 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
1756 /* The inferior can be gone if the user types "print exit(0)"
1757 (and perhaps other times). */
1759 /* FIXME: If we are being called after stopping in a function which
1760 is called from gdb, we should not be trying to restore the
1761 selected frame; it just prints a spurious error message (The
1762 message is useful, however, in detecting bugs in gdb (like if gdb
1763 clobbers the stack)). In fact, should we be restoring the
1764 inferior status at all in that case? . */
1766 if (target_has_stack
&& inf_status
->restore_stack_info
)
1768 struct restore_selected_frame_args fr
;
1769 fr
.level
= inf_status
->selected_level
;
1770 fr
.frame_address
= inf_status
->selected_frame_address
;
1771 /* The point of catch_errors is that if the stack is clobbered,
1772 walking the stack might encounter a garbage pointer and error()
1773 trying to dereference it. */
1774 if (catch_errors (restore_selected_frame
, &fr
,
1775 "Unable to restore previously selected frame:\n",
1776 RETURN_MASK_ERROR
) == 0)
1777 /* Error in restoring the selected frame. Select the innermost
1779 select_frame (get_current_frame (), 0);
1785 _initialize_infrun ()
1788 register int numsigs
;
1790 add_info ("signals", signals_info
,
1791 "What debugger does when program gets various signals.\n\
1792 Specify a signal number as argument to print info on that signal only.");
1793 add_info_alias ("handle", "signals", 0);
1795 add_com ("handle", class_run
, handle_command
,
1796 "Specify how to handle a signal.\n\
1797 Args are signal numbers and actions to apply to those signals.\n\
1798 Signal numbers may be numeric (ex. 11) or symbolic (ex. SIGSEGV).\n\
1799 Numeric ranges may be specified with the form LOW-HIGH (ex. 14-21).\n\
1800 The special arg \"all\" is recognized to mean all signals except those\n\
1801 used by the debugger, typically SIGTRAP and SIGINT.\n\
1802 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
1803 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
1804 Stop means reenter debugger if this signal happens (implies print).\n\
1805 Print means print a message if this signal happens.\n\
1806 Pass means let program see this signal; otherwise program doesn't know.\n\
1807 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
1808 Pass and Stop may be combined.");
1810 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
1811 "There is no `stop' command, but you can set a hook on `stop'.\n\
1812 This allows you to set a list of commands to be run each time execution\n\
1813 of the program stops.", &cmdlist
);
1815 numsigs
= signo_max () + 1;
1816 signal_stop
= (unsigned char *)
1817 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
1818 signal_print
= (unsigned char *)
1819 xmalloc (sizeof (signal_print
[0]) * numsigs
);
1820 signal_program
= (unsigned char *)
1821 xmalloc (sizeof (signal_program
[0]) * numsigs
);
1822 for (i
= 0; i
< numsigs
; i
++)
1825 signal_print
[i
] = 1;
1826 signal_program
[i
] = 1;
1829 /* Signals caused by debugger's own actions
1830 should not be given to the program afterwards. */
1831 signal_program
[SIGTRAP
] = 0;
1832 signal_program
[SIGINT
] = 0;
1834 /* Signals that are not errors should not normally enter the debugger. */
1836 signal_stop
[SIGALRM
] = 0;
1837 signal_print
[SIGALRM
] = 0;
1838 #endif /* SIGALRM */
1840 signal_stop
[SIGVTALRM
] = 0;
1841 signal_print
[SIGVTALRM
] = 0;
1842 #endif /* SIGVTALRM */
1844 signal_stop
[SIGPROF
] = 0;
1845 signal_print
[SIGPROF
] = 0;
1846 #endif /* SIGPROF */
1848 signal_stop
[SIGCHLD
] = 0;
1849 signal_print
[SIGCHLD
] = 0;
1850 #endif /* SIGCHLD */
1852 signal_stop
[SIGCLD
] = 0;
1853 signal_print
[SIGCLD
] = 0;
1856 signal_stop
[SIGIO
] = 0;
1857 signal_print
[SIGIO
] = 0;
1860 signal_stop
[SIGURG
] = 0;
1861 signal_print
[SIGURG
] = 0;