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. */
27 #include "breakpoint.h"
36 /* unistd.h is needed to #define X_OK */
43 /* Prototypes for local functions */
46 signals_info
PARAMS ((char *, int));
49 handle_command
PARAMS ((char *, int));
51 static void sig_print_info
PARAMS ((enum target_signal
));
54 sig_print_header
PARAMS ((void));
57 resume_cleanups
PARAMS ((int));
60 hook_stop_stub
PARAMS ((char *));
62 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
63 program. It needs to examine the jmp_buf argument and extract the PC
64 from it. The return value is non-zero on success, zero otherwise. */
65 #ifndef GET_LONGJMP_TARGET
66 #define GET_LONGJMP_TARGET(PC_ADDR) 0
70 /* Some machines have trampoline code that sits between function callers
71 and the actual functions themselves. If this machine doesn't have
72 such things, disable their processing. */
73 #ifndef SKIP_TRAMPOLINE_CODE
74 #define SKIP_TRAMPOLINE_CODE(pc) 0
77 /* On Irix 5, some function calls automatically skip the first few
78 instructions, so we need a more complicated test to see if we are
79 the start of a function. */
80 #ifndef AT_FUNCTION_START
81 #define AT_FUNCTION_START(pc,func_name,func_addr) 0
84 /* For SVR4 shared libraries, each call goes through a small piece of
85 trampoline code in the ".init" section. IN_SOLIB_TRAMPOLINE evaluates
86 to nonzero if we are current stopped in one of these. */
87 #ifndef IN_SOLIB_TRAMPOLINE
88 #define IN_SOLIB_TRAMPOLINE(pc,name) 0
91 /* On some systems, the PC may be left pointing at an instruction that won't
92 actually be executed. This is usually indicated by a bit in the PSW. If
93 we find ourselves in such a state, then we step the target beyond the
94 nullified instruction before returning control to the user so as to avoid
97 #ifndef INSTRUCTION_NULLIFIED
98 #define INSTRUCTION_NULLIFIED 0
101 /* Tables of how to react to signals; the user sets them. */
103 static unsigned char *signal_stop
;
104 static unsigned char *signal_print
;
105 static unsigned char *signal_program
;
107 #define SET_SIGS(nsigs,sigs,flags) \
109 int signum = (nsigs); \
110 while (signum-- > 0) \
111 if ((sigs)[signum]) \
112 (flags)[signum] = 1; \
115 #define UNSET_SIGS(nsigs,sigs,flags) \
117 int signum = (nsigs); \
118 while (signum-- > 0) \
119 if ((sigs)[signum]) \
120 (flags)[signum] = 0; \
124 /* Command list pointer for the "stop" placeholder. */
126 static struct cmd_list_element
*stop_command
;
128 /* Nonzero if breakpoints are now inserted in the inferior. */
130 static int breakpoints_inserted
;
132 /* Function inferior was in as of last step command. */
134 static struct symbol
*step_start_function
;
136 /* Nonzero if we are expecting a trace trap and should proceed from it. */
138 static int trap_expected
;
140 /* Nonzero if the next time we try to continue the inferior, it will
141 step one instruction and generate a spurious trace trap.
142 This is used to compensate for a bug in HP-UX. */
144 static int trap_expected_after_continue
;
146 /* Nonzero means expecting a trace trap
147 and should stop the inferior and return silently when it happens. */
151 /* Nonzero means expecting a trap and caller will handle it themselves.
152 It is used after attach, due to attaching to a process;
153 when running in the shell before the child program has been exec'd;
154 and when running some kinds of remote stuff (FIXME?). */
156 int stop_soon_quietly
;
158 /* Nonzero if proceed is being used for a "finish" command or a similar
159 situation when stop_registers should be saved. */
161 int proceed_to_finish
;
163 /* Save register contents here when about to pop a stack dummy frame,
164 if-and-only-if proceed_to_finish is set.
165 Thus this contains the return value from the called function (assuming
166 values are returned in a register). */
168 char stop_registers
[REGISTER_BYTES
];
170 /* Nonzero if program stopped due to error trying to insert breakpoints. */
172 static int breakpoints_failed
;
174 /* Nonzero after stop if current stack frame should be printed. */
176 static int stop_print_frame
;
178 #ifdef NO_SINGLE_STEP
179 extern int one_stepped
; /* From machine dependent code */
180 extern void single_step (); /* Same. */
181 #endif /* NO_SINGLE_STEP */
184 /* Things to clean up if we QUIT out of resume (). */
187 resume_cleanups (arg
)
193 /* Resume the inferior, but allow a QUIT. This is useful if the user
194 wants to interrupt some lengthy single-stepping operation
195 (for child processes, the SIGINT goes to the inferior, and so
196 we get a SIGINT random_signal, but for remote debugging and perhaps
197 other targets, that's not true).
199 STEP nonzero if we should step (zero to continue instead).
200 SIG is the signal to give the inferior (zero for none). */
204 enum target_signal sig
;
206 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
209 #ifdef CANNOT_STEP_BREAKPOINT
210 /* Most targets can step a breakpoint instruction, thus executing it
211 normally. But if this one cannot, just continue and we will hit
213 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
217 #ifdef NO_SINGLE_STEP
219 single_step(sig
); /* Do it the hard way, w/temp breakpoints */
220 step
= 0; /* ...and don't ask hardware to do it. */
224 /* Handle any optimized stores to the inferior NOW... */
225 #ifdef DO_DEFERRED_STORES
229 /* Install inferior's terminal modes. */
230 target_terminal_inferior ();
232 target_resume (-1, step
, sig
);
233 discard_cleanups (old_cleanups
);
237 /* Clear out all variables saying what to do when inferior is continued.
238 First do this, then set the ones you want, then call `proceed'. */
241 clear_proceed_status ()
244 step_range_start
= 0;
246 step_frame_address
= 0;
247 step_over_calls
= -1;
249 stop_soon_quietly
= 0;
250 proceed_to_finish
= 0;
251 breakpoint_proceeded
= 1; /* We're about to proceed... */
253 /* Discard any remaining commands or status from previous stop. */
254 bpstat_clear (&stop_bpstat
);
257 /* Basic routine for continuing the program in various fashions.
259 ADDR is the address to resume at, or -1 for resume where stopped.
260 SIGGNAL is the signal to give it, or 0 for none,
261 or -1 for act according to how it stopped.
262 STEP is nonzero if should trap after one instruction.
263 -1 means return after that and print nothing.
264 You should probably set various step_... variables
265 before calling here, if you are stepping.
267 You should call clear_proceed_status before calling proceed. */
270 proceed (addr
, siggnal
, step
)
272 enum target_signal siggnal
;
278 step_start_function
= find_pc_function (read_pc ());
282 if (addr
== (CORE_ADDR
)-1)
284 /* If there is a breakpoint at the address we will resume at,
285 step one instruction before inserting breakpoints
286 so that we do not stop right away. */
288 if (breakpoint_here_p (read_pc ()))
294 if (trap_expected_after_continue
)
296 /* If (step == 0), a trap will be automatically generated after
297 the first instruction is executed. Force step one
298 instruction to clear this condition. This should not occur
299 if step is nonzero, but it is harmless in that case. */
301 trap_expected_after_continue
= 0;
305 /* We will get a trace trap after one instruction.
306 Continue it automatically and insert breakpoints then. */
310 int temp
= insert_breakpoints ();
313 print_sys_errmsg ("ptrace", temp
);
314 error ("Cannot insert breakpoints.\n\
315 The same program may be running in another process.");
317 breakpoints_inserted
= 1;
321 stop_signal
= siggnal
;
322 /* If this signal should not be seen by program,
323 give it zero. Used for debugging signals. */
324 else if (!signal_program
[stop_signal
])
327 /* Resume inferior. */
328 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
330 /* Wait for it to stop (if not standalone)
331 and in any case decode why it stopped, and act accordingly. */
333 wait_for_inferior ();
337 /* Record the pc and sp of the program the last time it stopped.
338 These are just used internally by wait_for_inferior, but need
339 to be preserved over calls to it and cleared when the inferior
341 static CORE_ADDR prev_pc
;
342 static CORE_ADDR prev_sp
;
343 static CORE_ADDR prev_func_start
;
344 static char *prev_func_name
;
347 /* Start remote-debugging of a machine over a serial link. */
352 init_wait_for_inferior ();
353 clear_proceed_status ();
354 stop_soon_quietly
= 1;
356 wait_for_inferior ();
360 /* Initialize static vars when a new inferior begins. */
363 init_wait_for_inferior ()
365 /* These are meaningless until the first time through wait_for_inferior. */
369 prev_func_name
= NULL
;
371 trap_expected_after_continue
= 0;
372 breakpoints_inserted
= 0;
373 breakpoint_init_inferior ();
375 /* Don't confuse first call to proceed(). */
376 stop_signal
= TARGET_SIGNAL_0
;
380 delete_breakpoint_current_contents (arg
)
383 struct breakpoint
**breakpointp
= (struct breakpoint
**)arg
;
384 if (*breakpointp
!= NULL
)
385 delete_breakpoint (*breakpointp
);
388 /* Wait for control to return from inferior to debugger.
389 If inferior gets a signal, we may decide to start it up again
390 instead of returning. That is why there is a loop in this function.
391 When this function actually returns it means the inferior
392 should be left stopped and GDB should read more commands. */
397 struct cleanup
*old_cleanups
;
398 struct target_waitstatus w
;
401 CORE_ADDR stop_sp
= 0;
402 CORE_ADDR stop_func_start
;
403 CORE_ADDR stop_func_end
;
404 char *stop_func_name
;
405 CORE_ADDR prologue_pc
= 0, tmp
;
406 struct symtab_and_line sal
;
407 int remove_breakpoints_on_following_step
= 0;
409 struct symtab
*current_symtab
;
410 int handling_longjmp
= 0; /* FIXME */
411 struct breakpoint
*step_resume_breakpoint
= NULL
;
414 old_cleanups
= make_cleanup (delete_breakpoint_current_contents
,
415 &step_resume_breakpoint
);
416 sal
= find_pc_line(prev_pc
, 0);
417 current_line
= sal
.line
;
418 current_symtab
= sal
.symtab
;
420 /* Are we stepping? */
421 #define CURRENTLY_STEPPING() ((step_resume_breakpoint == NULL \
422 && !handling_longjmp \
425 || bpstat_should_step ())
429 /* Clean up saved state that will become invalid. */
430 flush_cached_frames ();
431 registers_changed ();
433 pid
= target_wait (-1, &w
);
435 #ifdef SIGTRAP_STOP_AFTER_LOAD
437 /* Somebody called load(2), and it gave us a "trap signal after load".
438 Ignore it gracefully. */
440 SIGTRAP_STOP_AFTER_LOAD (w
);
443 /* See if the process still exists; clean up if it doesn't. */
444 if (w
.kind
== TARGET_WAITKIND_EXITED
)
446 target_terminal_ours (); /* Must do this before mourn anyway */
448 printf_filtered ("\nProgram exited with code 0%o.\n",
449 (unsigned int)w
.value
.integer
);
452 printf_filtered ("\nProgram exited normally.\n");
453 gdb_flush (gdb_stdout
);
454 target_mourn_inferior ();
455 #ifdef NO_SINGLE_STEP
458 stop_print_frame
= 0;
461 else if (w
.kind
== TARGET_WAITKIND_SIGNALLED
)
465 stop_print_frame
= 0;
466 stop_signal
= w
.value
.sig
;
467 target_terminal_ours (); /* Must do this before mourn anyway */
468 target_kill (); /* kill mourns as well */
469 printf_filtered ("\nProgram terminated with signal %s, %s.\n",
470 target_signal_to_name (stop_signal
),
471 target_signal_to_string (stop_signal
));
473 printf_filtered ("The program no longer exists.\n");
474 gdb_flush (gdb_stdout
);
475 #ifdef NO_SINGLE_STEP
481 stop_signal
= w
.value
.sig
;
483 if (pid
!= inferior_pid
)
485 int save_pid
= inferior_pid
;
487 inferior_pid
= pid
; /* Setup for target memory/regs */
488 registers_changed ();
489 stop_pc
= read_pc ();
490 inferior_pid
= save_pid
;
491 registers_changed ();
494 stop_pc
= read_pc ();
496 if (stop_signal
== TARGET_SIGNAL_TRAP
497 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
499 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
, pid
))
501 /* Saw a breakpoint, but it was hit by the wrong thread. Just continue. */
502 if (breakpoints_inserted
)
504 if (pid
!= inferior_pid
)
506 int save_pid
= inferior_pid
;
509 registers_changed ();
510 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
511 inferior_pid
= save_pid
;
512 registers_changed ();
515 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
517 remove_breakpoints ();
518 target_resume (pid
, 1, TARGET_SIGNAL_0
); /* Single step */
519 /* FIXME: What if a signal arrives instead of the single-step
521 target_wait (pid
, &w
);
522 insert_breakpoints ();
524 target_resume (-1, 0, TARGET_SIGNAL_0
);
528 if (pid
!= inferior_pid
)
532 if (pid
!= inferior_pid
)
536 if (!in_thread_list (pid
))
538 fprintf_unfiltered (gdb_stderr
, "[New %s]\n", target_pid_to_str (pid
));
541 target_resume (-1, 0, TARGET_SIGNAL_0
);
546 if (signal_print
[stop_signal
])
551 target_terminal_ours_for_output ();
552 printf_filtered ("\nProgram received signal %s, %s.\n",
553 target_signal_to_name (stop_signal
),
554 target_signal_to_string (stop_signal
));
555 gdb_flush (gdb_stdout
);
558 if (stop_signal
== TARGET_SIGNAL_TRAP
559 || signal_stop
[stop_signal
])
563 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid
));
565 flush_cached_frames ();
566 registers_changed ();
568 if (step_resume_breakpoint
)
570 delete_breakpoint (step_resume_breakpoint
);
571 step_resume_breakpoint
= NULL
;
575 prev_func_name
= NULL
;
576 step_range_start
= 0;
578 step_frame_address
= 0;
579 handling_longjmp
= 0;
585 target_terminal_inferior ();
587 /* Clear the signal if it should not be passed. */
588 if (signal_program
[stop_signal
] == 0)
589 stop_signal
= TARGET_SIGNAL_0
;
591 target_resume (pid
, 0, stop_signal
);
597 #ifdef NO_SINGLE_STEP
599 single_step (0); /* This actually cleans up the ss */
600 #endif /* NO_SINGLE_STEP */
602 /* If PC is pointing at a nullified instruction, then step beyond it so that
603 the user won't be confused when GDB appears to be ready to execute it. */
605 if (INSTRUCTION_NULLIFIED
)
611 set_current_frame ( create_new_frame (read_fp (), stop_pc
));
613 stop_frame_address
= FRAME_FP (get_current_frame ());
614 stop_sp
= read_sp ();
617 /* Don't care about return value; stop_func_start and stop_func_name
618 will both be 0 if it doesn't work. */
619 find_pc_partial_function (stop_pc
, &stop_func_name
, &stop_func_start
,
621 stop_func_start
+= FUNCTION_START_OFFSET
;
623 bpstat_clear (&stop_bpstat
);
625 stop_stack_dummy
= 0;
626 stop_print_frame
= 1;
628 stopped_by_random_signal
= 0;
629 breakpoints_failed
= 0;
631 /* Look at the cause of the stop, and decide what to do.
632 The alternatives are:
633 1) break; to really stop and return to the debugger,
634 2) drop through to start up again
635 (set another_trap to 1 to single step once)
636 3) set random_signal to 1, and the decision between 1 and 2
637 will be made according to the signal handling tables. */
639 /* First, distinguish signals caused by the debugger from signals
640 that have to do with the program's own actions.
641 Note that breakpoint insns may cause SIGTRAP or SIGILL
642 or SIGEMT, depending on the operating system version.
643 Here we detect when a SIGILL or SIGEMT is really a breakpoint
644 and change it to SIGTRAP. */
646 if (stop_signal
== TARGET_SIGNAL_TRAP
647 || (breakpoints_inserted
&&
648 (stop_signal
== TARGET_SIGNAL_ILL
649 || stop_signal
== TARGET_SIGNAL_EMT
651 || stop_soon_quietly
)
653 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
655 stop_print_frame
= 0;
658 if (stop_soon_quietly
)
661 /* Don't even think about breakpoints
662 if just proceeded over a breakpoint.
664 However, if we are trying to proceed over a breakpoint
665 and end up in sigtramp, then step_resume_breakpoint
666 will be set and we should check whether we've hit the
668 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
669 && step_resume_breakpoint
== NULL
)
670 bpstat_clear (&stop_bpstat
);
673 /* See if there is a breakpoint at the current PC. */
674 stop_bpstat
= bpstat_stop_status
675 (&stop_pc
, stop_frame_address
,
676 #if DECR_PC_AFTER_BREAK
677 /* Notice the case of stepping through a jump
678 that lands just after a breakpoint.
679 Don't confuse that with hitting the breakpoint.
680 What we check for is that 1) stepping is going on
681 and 2) the pc before the last insn does not match
682 the address of the breakpoint before the current pc. */
683 (prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
684 && CURRENTLY_STEPPING ())
685 #else /* DECR_PC_AFTER_BREAK zero */
687 #endif /* DECR_PC_AFTER_BREAK zero */
689 /* Following in case break condition called a
691 stop_print_frame
= 1;
694 if (stop_signal
== TARGET_SIGNAL_TRAP
)
696 = !(bpstat_explains_signal (stop_bpstat
)
698 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
699 || PC_IN_CALL_DUMMY (stop_pc
, stop_sp
, stop_frame_address
)
700 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
701 || (step_range_end
&& step_resume_breakpoint
== NULL
));
705 = !(bpstat_explains_signal (stop_bpstat
)
706 /* End of a stack dummy. Some systems (e.g. Sony
707 news) give another signal besides SIGTRAP,
708 so check here as well as above. */
709 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
710 || PC_IN_CALL_DUMMY (stop_pc
, stop_sp
, stop_frame_address
)
711 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
714 stop_signal
= TARGET_SIGNAL_TRAP
;
720 /* For the program's own signals, act according to
721 the signal handling tables. */
725 /* Signal not for debugging purposes. */
728 stopped_by_random_signal
= 1;
730 if (signal_print
[stop_signal
])
734 target_terminal_ours_for_output ();
735 printf_filtered ("\nProgram received signal %s, %s.\n",
736 target_signal_to_name (stop_signal
),
737 target_signal_to_string (stop_signal
));
738 gdb_flush (gdb_stdout
);
740 if (signal_stop
[stop_signal
])
742 /* If not going to stop, give terminal back
743 if we took it away. */
745 target_terminal_inferior ();
747 /* Clear the signal if it should not be passed. */
748 if (signal_program
[stop_signal
] == 0)
749 stop_signal
= TARGET_SIGNAL_0
;
751 /* I'm not sure whether this needs to be check_sigtramp2 or
752 whether it could/should be keep_going. */
753 goto check_sigtramp2
;
756 /* Handle cases caused by hitting a breakpoint. */
758 CORE_ADDR jmp_buf_pc
;
759 struct bpstat_what what
;
761 what
= bpstat_what (stop_bpstat
);
765 stop_stack_dummy
= 1;
767 trap_expected_after_continue
= 1;
771 switch (what
.main_action
)
773 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
774 /* If we hit the breakpoint at longjmp, disable it for the
775 duration of this command. Then, install a temporary
776 breakpoint at the target of the jmp_buf. */
777 disable_longjmp_breakpoint();
778 remove_breakpoints ();
779 breakpoints_inserted
= 0;
780 if (!GET_LONGJMP_TARGET(&jmp_buf_pc
)) goto keep_going
;
782 /* Need to blow away step-resume breakpoint, as it
783 interferes with us */
784 if (step_resume_breakpoint
!= NULL
)
786 delete_breakpoint (step_resume_breakpoint
);
787 step_resume_breakpoint
= NULL
;
788 what
.step_resume
= 0;
792 /* FIXME - Need to implement nested temporary breakpoints */
793 if (step_over_calls
> 0)
794 set_longjmp_resume_breakpoint(jmp_buf_pc
,
795 get_current_frame());
798 set_longjmp_resume_breakpoint(jmp_buf_pc
, NULL
);
799 handling_longjmp
= 1; /* FIXME */
802 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
803 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
804 remove_breakpoints ();
805 breakpoints_inserted
= 0;
807 /* FIXME - Need to implement nested temporary breakpoints */
809 && (stop_frame_address
810 INNER_THAN step_frame_address
))
816 disable_longjmp_breakpoint();
817 handling_longjmp
= 0; /* FIXME */
818 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
820 /* else fallthrough */
822 case BPSTAT_WHAT_SINGLE
:
823 if (breakpoints_inserted
)
824 remove_breakpoints ();
825 breakpoints_inserted
= 0;
827 /* Still need to check other stuff, at least the case
828 where we are stepping and step out of the right range. */
831 case BPSTAT_WHAT_STOP_NOISY
:
832 stop_print_frame
= 1;
833 /* We are about to nuke the step_resume_breakpoint via the
834 cleanup chain, so no need to worry about it here. */
837 case BPSTAT_WHAT_STOP_SILENT
:
838 stop_print_frame
= 0;
839 /* We are about to nuke the step_resume_breakpoint via the
840 cleanup chain, so no need to worry about it here. */
843 case BPSTAT_WHAT_LAST
:
844 /* Not a real code, but listed here to shut up gcc -Wall. */
846 case BPSTAT_WHAT_KEEP_CHECKING
:
850 if (what
.step_resume
)
852 delete_breakpoint (step_resume_breakpoint
);
853 step_resume_breakpoint
= NULL
;
855 /* If were waiting for a trap, hitting the step_resume_break
856 doesn't count as getting it. */
862 /* We come here if we hit a breakpoint but should not
863 stop for it. Possibly we also were stepping
864 and should stop for that. So fall through and
865 test for stepping. But, if not stepping,
868 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
869 /* This is the old way of detecting the end of the stack dummy.
870 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
871 handled above. As soon as we can test it on all of them, all
872 architectures should define it. */
874 /* If this is the breakpoint at the end of a stack dummy,
875 just stop silently, unless the user was doing an si/ni, in which
876 case she'd better know what she's doing. */
878 if (PC_IN_CALL_DUMMY (stop_pc
, stop_sp
, stop_frame_address
)
881 stop_print_frame
= 0;
882 stop_stack_dummy
= 1;
884 trap_expected_after_continue
= 1;
888 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
890 if (step_resume_breakpoint
)
891 /* Having a step-resume breakpoint overrides anything
892 else having to do with stepping commands until
893 that breakpoint is reached. */
894 /* I suspect this could/should be keep_going, because if the
895 check_sigtramp2 check succeeds, then it will put in another
896 step_resume_breakpoint, and we aren't (yet) prepared to nest
898 goto check_sigtramp2
;
900 if (step_range_end
== 0)
901 /* Likewise if we aren't even stepping. */
902 /* I'm not sure whether this needs to be check_sigtramp2 or
903 whether it could/should be keep_going. */
904 goto check_sigtramp2
;
906 /* If stepping through a line, keep going if still within it. */
907 if (stop_pc
>= step_range_start
908 && stop_pc
< step_range_end
909 /* The step range might include the start of the
910 function, so if we are at the start of the
911 step range and either the stack or frame pointers
912 just changed, we've stepped outside */
913 && !(stop_pc
== step_range_start
914 && stop_frame_address
915 && (stop_sp INNER_THAN prev_sp
916 || stop_frame_address
!= step_frame_address
)))
918 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
919 So definately need to check for sigtramp here. */
920 goto check_sigtramp2
;
923 /* We stepped out of the stepping range. See if that was due
924 to a subroutine call that we should proceed to the end of. */
926 /* Did we just take a signal? */
927 if (IN_SIGTRAMP (stop_pc
, stop_func_name
)
928 && !IN_SIGTRAMP (prev_pc
, prev_func_name
))
930 /* This code is needed at least in the following case:
931 The user types "next" and then a signal arrives (before
932 the "next" is done). */
933 /* We've just taken a signal; go until we are back to
934 the point where we took it and one more. */
936 struct symtab_and_line sr_sal
;
939 sr_sal
.symtab
= NULL
;
941 step_resume_breakpoint
=
942 set_momentary_breakpoint (sr_sal
, get_current_frame (),
944 if (breakpoints_inserted
)
945 insert_breakpoints ();
948 /* If this is stepi or nexti, make sure that the stepping range
949 gets us past that instruction. */
950 if (step_range_end
== 1)
951 /* FIXME: Does this run afoul of the code below which, if
952 we step into the middle of a line, resets the stepping
954 step_range_end
= (step_range_start
= prev_pc
) + 1;
956 remove_breakpoints_on_following_step
= 1;
962 /* Do this after the IN_SIGTRAMP check; it might give
964 prologue_pc
= stop_func_start
;
965 SKIP_PROLOGUE (prologue_pc
);
968 if ((/* Might be a non-recursive call. If the symbols are missing
969 enough that stop_func_start == prev_func_start even though
970 they are really two functions, we will treat some calls as
972 stop_func_start
!= prev_func_start
974 /* Might be a recursive call if either we have a prologue
975 or the call instruction itself saves the PC on the stack. */
976 || prologue_pc
!= stop_func_start
977 || stop_sp
!= prev_sp
)
978 && (/* PC is completely out of bounds of any known objfiles. Treat
979 like a subroutine call. */
982 /* If we do a call, we will be at the start of a function... */
983 || stop_pc
== stop_func_start
985 /* Should be taken care of by the stop_pc < prologue_pc check
986 below. Also, on irix5 where this checks for stop_pc
987 equal to stop_func_start plus 12, it would seem to be
988 wrong for a function with a 4 byte prologue, and an 8 byte
989 call; a "return" could end up at stop_func_start+12. */
991 || AT_FUNCTION_START (stop_pc
, stop_func_name
, stop_func_start
)
994 /* ...except on the Alpha with -O (and also Irix 5 and
995 perhaps others), in which we might call the address
996 after the load of gp. Since prologues don't contain
997 calls, we can't return to within one, and we don't
998 jump back into them, so this check is OK. */
1000 || stop_pc
< prologue_pc
1002 /* If we end up in certain places, it means we did a subroutine
1003 call. I'm not completely sure this is necessary now that we
1004 have the above checks with stop_func_start (and now that
1005 find_pc_partial_function is pickier). */
1006 || IN_SOLIB_TRAMPOLINE (stop_pc
, stop_func_name
)
1008 /* If none of the above apply, it is a jump within a function,
1009 or a return from a subroutine. The other case is longjmp,
1010 which can no longer happen here as long as the
1011 handling_longjmp stuff is working. */
1014 /* It's a subroutine call. */
1016 if (step_over_calls
== 0)
1018 /* I presume that step_over_calls is only 0 when we're
1019 supposed to be stepping at the assembly language level
1020 ("stepi"). Just stop. */
1025 if (step_over_calls
> 0)
1026 /* We're doing a "next". */
1027 goto step_over_function
;
1029 /* If we are in a function call trampoline (a stub between
1030 the calling routine and the real function), locate the real
1031 function. That's what tells us (a) whether we want to step
1032 into it at all, and (b) what prologue we want to run to
1033 the end of, if we do step into it. */
1034 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
1036 stop_func_start
= tmp
;
1038 /* If we have line number information for the function we
1039 are thinking of stepping into, step into it.
1041 If there are several symtabs at that PC (e.g. with include
1042 files), just want to know whether *any* of them have line
1043 numbers. find_pc_line handles this. */
1045 struct symtab_and_line tmp_sal
;
1047 tmp_sal
= find_pc_line (stop_func_start
, 0);
1048 if (tmp_sal
.line
!= 0)
1049 goto step_into_function
;
1053 /* A subroutine call has happened. */
1055 /* Set a special breakpoint after the return */
1056 struct symtab_and_line sr_sal
;
1059 (SAVED_PC_AFTER_CALL (get_current_frame ()));
1060 sr_sal
.symtab
= NULL
;
1062 step_resume_breakpoint
=
1063 set_momentary_breakpoint (sr_sal
, get_current_frame (),
1065 if (breakpoints_inserted
)
1066 insert_breakpoints ();
1071 /* Subroutine call with source code we should not step over.
1072 Do step to the first line of code in it. */
1073 SKIP_PROLOGUE (stop_func_start
);
1074 sal
= find_pc_line (stop_func_start
, 0);
1075 /* Use the step_resume_break to step until
1076 the end of the prologue, even if that involves jumps
1077 (as it seems to on the vax under 4.2). */
1078 /* If the prologue ends in the middle of a source line,
1079 continue to the end of that source line (if it is still
1080 within the function). Otherwise, just go to end of prologue. */
1081 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1082 /* no, don't either. It skips any code that's
1083 legitimately on the first line. */
1085 if (sal
.end
&& sal
.pc
!= stop_func_start
&& sal
.end
< stop_func_end
)
1086 stop_func_start
= sal
.end
;
1089 if (stop_func_start
== stop_pc
)
1091 /* We are already there: stop now. */
1096 /* Put the step-breakpoint there and go until there. */
1098 struct symtab_and_line sr_sal
;
1100 sr_sal
.pc
= stop_func_start
;
1101 sr_sal
.symtab
= NULL
;
1103 /* Do not specify what the fp should be when we stop
1104 since on some machines the prologue
1105 is where the new fp value is established. */
1106 step_resume_breakpoint
=
1107 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
1108 if (breakpoints_inserted
)
1109 insert_breakpoints ();
1111 /* And make sure stepping stops right away then. */
1112 step_range_end
= step_range_start
;
1117 /* We've wandered out of the step range. */
1119 sal
= find_pc_line(stop_pc
, 0);
1121 if (step_range_end
== 1)
1123 /* It is stepi or nexti. We always want to stop stepping after
1131 /* We have no line number information. That means to stop
1132 stepping (does this always happen right after one instruction,
1133 when we do "s" in a function with no line numbers,
1134 or can this happen as a result of a return or longjmp?). */
1139 if (stop_pc
== sal
.pc
1140 && (current_line
!= sal
.line
|| current_symtab
!= sal
.symtab
))
1142 /* We are at the start of a different line. So stop. Note that
1143 we don't stop if we step into the middle of a different line.
1144 That is said to make things like for (;;) statements work
1150 /* We aren't done stepping.
1152 Optimize by setting the stepping range to the line.
1153 (We might not be in the original line, but if we entered a
1154 new line in mid-statement, we continue stepping. This makes
1155 things like for(;;) statements work better.) */
1157 if (stop_func_end
&& sal
.end
>= stop_func_end
)
1159 /* If this is the last line of the function, don't keep stepping
1160 (it would probably step us out of the function).
1161 This is particularly necessary for a one-line function,
1162 in which after skipping the prologue we better stop even though
1163 we will be in mid-line. */
1167 step_range_start
= sal
.pc
;
1168 step_range_end
= sal
.end
;
1173 && IN_SIGTRAMP (stop_pc
, stop_func_name
)
1174 && !IN_SIGTRAMP (prev_pc
, prev_func_name
))
1176 /* What has happened here is that we have just stepped the inferior
1177 with a signal (because it is a signal which shouldn't make
1178 us stop), thus stepping into sigtramp.
1180 So we need to set a step_resume_break_address breakpoint
1181 and continue until we hit it, and then step. FIXME: This should
1182 be more enduring than a step_resume breakpoint; we should know
1183 that we will later need to keep going rather than re-hitting
1184 the breakpoint here (see testsuite/gdb.t06/signals.exp where
1185 it says "exceedingly difficult"). */
1186 struct symtab_and_line sr_sal
;
1188 sr_sal
.pc
= prev_pc
;
1189 sr_sal
.symtab
= NULL
;
1191 step_resume_breakpoint
=
1192 set_momentary_breakpoint (sr_sal
, get_current_frame (),
1194 if (breakpoints_inserted
)
1195 insert_breakpoints ();
1197 remove_breakpoints_on_following_step
= 1;
1202 /* Come to this label when you need to resume the inferior.
1203 It's really much cleaner to do a goto than a maze of if-else
1206 /* Save the pc before execution, to compare with pc after stop. */
1207 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
1208 prev_func_start
= stop_func_start
; /* Ok, since if DECR_PC_AFTER
1209 BREAK is defined, the
1210 original pc would not have
1211 been at the start of a
1213 prev_func_name
= stop_func_name
;
1216 /* If we did not do break;, it means we should keep
1217 running the inferior and not return to debugger. */
1219 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
1221 /* We took a signal (which we are supposed to pass through to
1222 the inferior, else we'd have done a break above) and we
1223 haven't yet gotten our trap. Simply continue. */
1224 resume (CURRENTLY_STEPPING (), stop_signal
);
1228 /* Either the trap was not expected, but we are continuing
1229 anyway (the user asked that this signal be passed to the
1232 The signal was SIGTRAP, e.g. it was our signal, but we
1233 decided we should resume from it.
1235 We're going to run this baby now!
1237 Insert breakpoints now, unless we are trying
1238 to one-proceed past a breakpoint. */
1239 /* If we've just finished a special step resume and we don't
1240 want to hit a breakpoint, pull em out. */
1241 if (step_resume_breakpoint
== NULL
&&
1242 remove_breakpoints_on_following_step
)
1244 remove_breakpoints_on_following_step
= 0;
1245 remove_breakpoints ();
1246 breakpoints_inserted
= 0;
1248 else if (!breakpoints_inserted
&&
1249 (step_resume_breakpoint
!= NULL
|| !another_trap
))
1251 breakpoints_failed
= insert_breakpoints ();
1252 if (breakpoints_failed
)
1254 breakpoints_inserted
= 1;
1257 trap_expected
= another_trap
;
1259 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1260 stop_signal
= TARGET_SIGNAL_0
;
1262 #ifdef SHIFT_INST_REGS
1263 /* I'm not sure when this following segment applies. I do know, now,
1264 that we shouldn't rewrite the regs when we were stopped by a
1265 random signal from the inferior process. */
1266 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
1267 (this is only used on the 88k). */
1269 if (!bpstat_explains_signal (stop_bpstat
)
1270 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
1271 && !stopped_by_random_signal
)
1273 #endif /* SHIFT_INST_REGS */
1275 resume (CURRENTLY_STEPPING (), stop_signal
);
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
&& get_current_frame())
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 signal_stop
[signo
];
1410 int signal_print_state (signo
)
1413 return signal_print
[signo
];
1416 int signal_pass_state (signo
)
1419 return signal_program
[signo
];
1426 Signal Stop\tPrint\tPass to program\tDescription\n");
1430 sig_print_info (oursig
)
1431 enum target_signal oursig
;
1433 char *name
= target_signal_to_name (oursig
);
1434 printf_filtered ("%s", name
);
1435 printf_filtered ("%*.*s ", 13 - strlen (name
), 13 - strlen (name
),
1437 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
1438 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
1439 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
1440 printf_filtered ("%s\n", target_signal_to_string (oursig
));
1443 /* Specify how various signals in the inferior should be handled. */
1446 handle_command (args
, from_tty
)
1451 int digits
, wordlen
;
1452 int sigfirst
, signum
, siglast
;
1453 enum target_signal oursig
;
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
= (int)TARGET_SIGNAL_LAST
;
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 oursigs, 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 /* It is numeric. The numeric signal refers to our own internal
1536 signal numbering from target.h, not to host/target signal number.
1537 This is a feature; users really should be using symbolic names
1538 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
1539 will work right anyway. */
1541 sigfirst
= siglast
= atoi (*argv
);
1542 if ((*argv
)[digits
] == '-')
1544 siglast
= atoi ((*argv
) + digits
+ 1);
1546 if (sigfirst
> siglast
)
1548 /* Bet he didn't figure we'd think of this case... */
1553 if (sigfirst
< 0 || sigfirst
>= nsigs
)
1555 error ("Signal %d not in range 0-%d", sigfirst
, nsigs
- 1);
1557 if (siglast
< 0 || siglast
>= nsigs
)
1559 error ("Signal %d not in range 0-%d", siglast
, nsigs
- 1);
1562 else if ((oursig
= target_signal_from_name (*argv
))
1563 != TARGET_SIGNAL_UNKNOWN
)
1565 sigfirst
= siglast
= (int)oursig
;
1569 /* Not a number and not a recognized flag word => complain. */
1570 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
1573 /* If any signal numbers or symbol names were found, set flags for
1574 which signals to apply actions to. */
1576 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
1578 switch ((enum target_signal
)signum
)
1580 case TARGET_SIGNAL_TRAP
:
1581 case TARGET_SIGNAL_INT
:
1582 if (!allsigs
&& !sigs
[signum
])
1584 if (query ("%s is used by the debugger.\n\
1585 Are you sure you want to change it? ",
1586 target_signal_to_name
1587 ((enum target_signal
)signum
)))
1593 printf_unfiltered ("Not confirmed, unchanged.\n");
1594 gdb_flush (gdb_stdout
);
1607 target_notice_signals(inferior_pid
);
1611 /* Show the results. */
1612 sig_print_header ();
1613 for (signum
= 0; signum
< nsigs
; signum
++)
1617 sig_print_info (signum
);
1622 do_cleanups (old_chain
);
1625 /* Print current contents of the tables set by the handle command.
1626 It is possible we should just be printing signals actually used
1627 by the current target (but for things to work right when switching
1628 targets, all signals should be in the signal tables). */
1631 signals_info (signum_exp
, from_tty
)
1635 enum target_signal oursig
;
1636 sig_print_header ();
1640 /* First see if this is a symbol name. */
1641 oursig
= target_signal_from_name (signum_exp
);
1642 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
1644 /* Nope, maybe it's an address which evaluates to a signal
1646 /* The numeric signal refers to our own internal
1647 signal numbering from target.h, not to host/target signal number.
1648 This is a feature; users really should be using symbolic names
1649 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
1650 will work right anyway. */
1651 int i
= parse_and_eval_address (signum_exp
);
1652 if (i
>= (int)TARGET_SIGNAL_LAST
1654 || i
== TARGET_SIGNAL_UNKNOWN
)
1655 error ("Signal number out of bounds.");
1656 oursig
= (enum target_signal
)i
;
1658 sig_print_info (oursig
);
1662 printf_filtered ("\n");
1663 for (oursig
= 0; oursig
< TARGET_SIGNAL_LAST
; ++oursig
)
1667 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
1668 sig_print_info (oursig
);
1671 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
1674 /* Save all of the information associated with the inferior<==>gdb
1675 connection. INF_STATUS is a pointer to a "struct inferior_status"
1676 (defined in inferior.h). */
1679 save_inferior_status (inf_status
, restore_stack_info
)
1680 struct inferior_status
*inf_status
;
1681 int restore_stack_info
;
1683 inf_status
->stop_signal
= stop_signal
;
1684 inf_status
->stop_pc
= stop_pc
;
1685 inf_status
->stop_frame_address
= stop_frame_address
;
1686 inf_status
->stop_step
= stop_step
;
1687 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
1688 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
1689 inf_status
->trap_expected
= trap_expected
;
1690 inf_status
->step_range_start
= step_range_start
;
1691 inf_status
->step_range_end
= step_range_end
;
1692 inf_status
->step_frame_address
= step_frame_address
;
1693 inf_status
->step_over_calls
= step_over_calls
;
1694 inf_status
->stop_after_trap
= stop_after_trap
;
1695 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
1696 /* Save original bpstat chain here; replace it with copy of chain.
1697 If caller's caller is walking the chain, they'll be happier if we
1698 hand them back the original chain when restore_i_s is called. */
1699 inf_status
->stop_bpstat
= stop_bpstat
;
1700 stop_bpstat
= bpstat_copy (stop_bpstat
);
1701 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
1702 inf_status
->restore_stack_info
= restore_stack_info
;
1703 inf_status
->proceed_to_finish
= proceed_to_finish
;
1705 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
1707 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
1709 record_selected_frame (&(inf_status
->selected_frame_address
),
1710 &(inf_status
->selected_level
));
1714 struct restore_selected_frame_args
{
1715 FRAME_ADDR frame_address
;
1719 static int restore_selected_frame
PARAMS ((char *));
1721 /* Restore the selected frame. args is really a struct
1722 restore_selected_frame_args * (declared as char * for catch_errors)
1723 telling us what frame to restore. Returns 1 for success, or 0 for
1724 failure. An error message will have been printed on error. */
1726 restore_selected_frame (args
)
1729 struct restore_selected_frame_args
*fr
=
1730 (struct restore_selected_frame_args
*) args
;
1732 int level
= fr
->level
;
1734 fid
= find_relative_frame (get_current_frame (), &level
);
1736 /* If inf_status->selected_frame_address is NULL, there was no
1737 previously selected frame. */
1739 FRAME_FP (fid
) != fr
->frame_address
||
1742 warning ("Unable to restore previously selected frame.\n");
1745 select_frame (fid
, fr
->level
);
1750 restore_inferior_status (inf_status
)
1751 struct inferior_status
*inf_status
;
1753 stop_signal
= inf_status
->stop_signal
;
1754 stop_pc
= inf_status
->stop_pc
;
1755 stop_frame_address
= inf_status
->stop_frame_address
;
1756 stop_step
= inf_status
->stop_step
;
1757 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
1758 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
1759 trap_expected
= inf_status
->trap_expected
;
1760 step_range_start
= inf_status
->step_range_start
;
1761 step_range_end
= inf_status
->step_range_end
;
1762 step_frame_address
= inf_status
->step_frame_address
;
1763 step_over_calls
= inf_status
->step_over_calls
;
1764 stop_after_trap
= inf_status
->stop_after_trap
;
1765 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
1766 bpstat_clear (&stop_bpstat
);
1767 stop_bpstat
= inf_status
->stop_bpstat
;
1768 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
1769 proceed_to_finish
= inf_status
->proceed_to_finish
;
1771 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
1773 /* The inferior can be gone if the user types "print exit(0)"
1774 (and perhaps other times). */
1775 if (target_has_execution
)
1776 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
1778 /* The inferior can be gone if the user types "print exit(0)"
1779 (and perhaps other times). */
1781 /* FIXME: If we are being called after stopping in a function which
1782 is called from gdb, we should not be trying to restore the
1783 selected frame; it just prints a spurious error message (The
1784 message is useful, however, in detecting bugs in gdb (like if gdb
1785 clobbers the stack)). In fact, should we be restoring the
1786 inferior status at all in that case? . */
1788 if (target_has_stack
&& inf_status
->restore_stack_info
)
1790 struct restore_selected_frame_args fr
;
1791 fr
.level
= inf_status
->selected_level
;
1792 fr
.frame_address
= inf_status
->selected_frame_address
;
1793 /* The point of catch_errors is that if the stack is clobbered,
1794 walking the stack might encounter a garbage pointer and error()
1795 trying to dereference it. */
1796 if (catch_errors (restore_selected_frame
, &fr
,
1797 "Unable to restore previously selected frame:\n",
1798 RETURN_MASK_ERROR
) == 0)
1799 /* Error in restoring the selected frame. Select the innermost
1801 select_frame (get_current_frame (), 0);
1807 _initialize_infrun ()
1810 register int numsigs
;
1812 add_info ("signals", signals_info
,
1813 "What debugger does when program gets various signals.\n\
1814 Specify a signal number as argument to print info on that signal only.");
1815 add_info_alias ("handle", "signals", 0);
1817 add_com ("handle", class_run
, handle_command
,
1818 "Specify how to handle a signal.\n\
1819 Args are signal numbers and actions to apply to those signals.\n\
1820 Signal numbers may be numeric (ex. 11) or symbolic (ex. SIGSEGV).\n\
1821 Numeric ranges may be specified with the form LOW-HIGH (ex. 14-21).\n\
1822 The special arg \"all\" is recognized to mean all signals except those\n\
1823 used by the debugger, typically SIGTRAP and SIGINT.\n\
1824 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
1825 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
1826 Stop means reenter debugger if this signal happens (implies print).\n\
1827 Print means print a message if this signal happens.\n\
1828 Pass means let program see this signal; otherwise program doesn't know.\n\
1829 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
1830 Pass and Stop may be combined.");
1832 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
1833 "There is no `stop' command, but you can set a hook on `stop'.\n\
1834 This allows you to set a list of commands to be run each time execution\n\
1835 of the program stops.", &cmdlist
);
1837 numsigs
= (int)TARGET_SIGNAL_LAST
;
1838 signal_stop
= (unsigned char *)
1839 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
1840 signal_print
= (unsigned char *)
1841 xmalloc (sizeof (signal_print
[0]) * numsigs
);
1842 signal_program
= (unsigned char *)
1843 xmalloc (sizeof (signal_program
[0]) * numsigs
);
1844 for (i
= 0; i
< numsigs
; i
++)
1847 signal_print
[i
] = 1;
1848 signal_program
[i
] = 1;
1851 /* Signals caused by debugger's own actions
1852 should not be given to the program afterwards. */
1853 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
1854 signal_program
[TARGET_SIGNAL_INT
] = 0;
1856 /* Signals that are not errors should not normally enter the debugger. */
1857 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
1858 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
1859 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
1860 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
1861 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
1862 signal_print
[TARGET_SIGNAL_PROF
] = 0;
1863 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
1864 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
1865 signal_stop
[TARGET_SIGNAL_IO
] = 0;
1866 signal_print
[TARGET_SIGNAL_IO
] = 0;
1867 signal_stop
[TARGET_SIGNAL_URG
] = 0;
1868 signal_print
[TARGET_SIGNAL_URG
] = 0;