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));
52 sig_print_info
PARAMS ((int));
55 sig_print_header
PARAMS ((void));
58 resume_cleanups
PARAMS ((int));
61 hook_stop_stub
PARAMS ((char *));
63 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
64 program. It needs to examine the jmp_buf argument and extract the PC
65 from it. The return value is non-zero on success, zero otherwise. */
66 #ifndef GET_LONGJMP_TARGET
67 #define GET_LONGJMP_TARGET(PC_ADDR) 0
71 /* Some machines have trampoline code that sits between function callers
72 and the actual functions themselves. If this machine doesn't have
73 such things, disable their processing. */
74 #ifndef SKIP_TRAMPOLINE_CODE
75 #define SKIP_TRAMPOLINE_CODE(pc) 0
78 /* On Irix 5, some function calls automatically skip the first few
79 instructions, so we need a more complicated test to see if we are
80 the start of a function. */
81 #ifndef AT_FUNCTION_START
82 #define AT_FUNCTION_START(pc,func_name,func_addr) 0
85 /* For SVR4 shared libraries, each call goes through a small piece of
86 trampoline code in the ".init" section. IN_SOLIB_TRAMPOLINE evaluates
87 to nonzero if we are current stopped in one of these. */
88 #ifndef IN_SOLIB_TRAMPOLINE
89 #define IN_SOLIB_TRAMPOLINE(pc,name) 0
92 /* On some systems, the PC may be left pointing at an instruction that won't
93 actually be executed. This is usually indicated by a bit in the PSW. If
94 we find ourselves in such a state, then we step the target beyond the
95 nullified instruction before returning control to the user so as to avoid
98 #ifndef INSTRUCTION_NULLIFIED
99 #define INSTRUCTION_NULLIFIED 0
102 /* Tables of how to react to signals; the user sets them. */
104 static unsigned char *signal_stop
;
105 static unsigned char *signal_print
;
106 static unsigned char *signal_program
;
108 #define SET_SIGS(nsigs,sigs,flags) \
110 int signum = (nsigs); \
111 while (signum-- > 0) \
112 if ((sigs)[signum]) \
113 (flags)[signum] = 1; \
116 #define UNSET_SIGS(nsigs,sigs,flags) \
118 int signum = (nsigs); \
119 while (signum-- > 0) \
120 if ((sigs)[signum]) \
121 (flags)[signum] = 0; \
125 /* Command list pointer for the "stop" placeholder. */
127 static struct cmd_list_element
*stop_command
;
129 /* Nonzero if breakpoints are now inserted in the inferior. */
131 static int breakpoints_inserted
;
133 /* Function inferior was in as of last step command. */
135 static struct symbol
*step_start_function
;
137 /* Nonzero if we are expecting a trace trap and should proceed from it. */
139 static int trap_expected
;
141 /* Nonzero if the next time we try to continue the inferior, it will
142 step one instruction and generate a spurious trace trap.
143 This is used to compensate for a bug in HP-UX. */
145 static int trap_expected_after_continue
;
147 /* Nonzero means expecting a trace trap
148 and should stop the inferior and return silently when it happens. */
152 /* Nonzero means expecting a trap and caller will handle it themselves.
153 It is used after attach, due to attaching to a process;
154 when running in the shell before the child program has been exec'd;
155 and when running some kinds of remote stuff (FIXME?). */
157 int stop_soon_quietly
;
159 /* Nonzero if proceed is being used for a "finish" command or a similar
160 situation when stop_registers should be saved. */
162 int proceed_to_finish
;
164 /* Save register contents here when about to pop a stack dummy frame,
165 if-and-only-if proceed_to_finish is set.
166 Thus this contains the return value from the called function (assuming
167 values are returned in a register). */
169 char stop_registers
[REGISTER_BYTES
];
171 /* Nonzero if program stopped due to error trying to insert breakpoints. */
173 static int breakpoints_failed
;
175 /* Nonzero after stop if current stack frame should be printed. */
177 static int stop_print_frame
;
179 #ifdef NO_SINGLE_STEP
180 extern int one_stepped
; /* From machine dependent code */
181 extern void single_step (); /* Same. */
182 #endif /* NO_SINGLE_STEP */
185 /* Things to clean up if we QUIT out of resume (). */
188 resume_cleanups (arg
)
194 /* Resume the inferior, but allow a QUIT. This is useful if the user
195 wants to interrupt some lengthy single-stepping operation
196 (for child processes, the SIGINT goes to the inferior, and so
197 we get a SIGINT random_signal, but for remote debugging and perhaps
198 other targets, that's not true).
200 STEP nonzero if we should step (zero to continue instead).
201 SIG is the signal to give the inferior (zero for none). */
207 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
210 #ifdef CANNOT_STEP_BREAKPOINT
211 /* Most targets can step a breakpoint instruction, thus executing it
212 normally. But if this one cannot, just continue and we will hit
214 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
218 #ifdef NO_SINGLE_STEP
220 single_step(sig
); /* Do it the hard way, w/temp breakpoints */
221 step
= 0; /* ...and don't ask hardware to do it. */
225 /* Handle any optimized stores to the inferior NOW... */
226 #ifdef DO_DEFERRED_STORES
230 /* Install inferior's terminal modes. */
231 target_terminal_inferior ();
233 target_resume (-1, step
, sig
);
234 discard_cleanups (old_cleanups
);
238 /* Clear out all variables saying what to do when inferior is continued.
239 First do this, then set the ones you want, then call `proceed'. */
242 clear_proceed_status ()
245 step_range_start
= 0;
247 step_frame_address
= 0;
248 step_over_calls
= -1;
250 stop_soon_quietly
= 0;
251 proceed_to_finish
= 0;
252 breakpoint_proceeded
= 1; /* We're about to proceed... */
254 /* Discard any remaining commands or status from previous stop. */
255 bpstat_clear (&stop_bpstat
);
258 /* Basic routine for continuing the program in various fashions.
260 ADDR is the address to resume at, or -1 for resume where stopped.
261 SIGGNAL is the signal to give it, or 0 for none,
262 or -1 for act according to how it stopped.
263 STEP is nonzero if should trap after one instruction.
264 -1 means return after that and print nothing.
265 You should probably set various step_... variables
266 before calling here, if you are stepping.
268 You should call clear_proceed_status before calling proceed. */
271 proceed (addr
, siggnal
, step
)
279 step_start_function
= find_pc_function (read_pc ());
283 if (addr
== (CORE_ADDR
)-1)
285 /* If there is a breakpoint at the address we will resume at,
286 step one instruction before inserting breakpoints
287 so that we do not stop right away. */
289 if (breakpoint_here_p (read_pc ()))
295 if (trap_expected_after_continue
)
297 /* If (step == 0), a trap will be automatically generated after
298 the first instruction is executed. Force step one
299 instruction to clear this condition. This should not occur
300 if step is nonzero, but it is harmless in that case. */
302 trap_expected_after_continue
= 0;
306 /* We will get a trace trap after one instruction.
307 Continue it automatically and insert breakpoints then. */
311 int temp
= insert_breakpoints ();
314 print_sys_errmsg ("ptrace", temp
);
315 error ("Cannot insert breakpoints.\n\
316 The same program may be running in another process.");
318 breakpoints_inserted
= 1;
322 stop_signal
= siggnal
;
323 /* If this signal should not be seen by program,
324 give it zero. Used for debugging signals. */
325 else if (stop_signal
< NSIG
&& !signal_program
[stop_signal
])
328 /* Resume inferior. */
329 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
331 /* Wait for it to stop (if not standalone)
332 and in any case decode why it stopped, and act accordingly. */
334 wait_for_inferior ();
338 /* Record the pc and sp of the program the last time it stopped.
339 These are just used internally by wait_for_inferior, but need
340 to be preserved over calls to it and cleared when the inferior
342 static CORE_ADDR prev_pc
;
343 static CORE_ADDR prev_sp
;
344 static CORE_ADDR prev_func_start
;
345 static char *prev_func_name
;
348 /* Start remote-debugging of a machine over a serial link. */
353 init_wait_for_inferior ();
354 clear_proceed_status ();
355 stop_soon_quietly
= 1;
357 wait_for_inferior ();
361 /* Initialize static vars when a new inferior begins. */
364 init_wait_for_inferior ()
366 /* These are meaningless until the first time through wait_for_inferior. */
370 prev_func_name
= NULL
;
372 trap_expected_after_continue
= 0;
373 breakpoints_inserted
= 0;
374 breakpoint_init_inferior ();
375 stop_signal
= 0; /* Don't confuse first call to proceed(). */
379 delete_breakpoint_current_contents (arg
)
382 struct breakpoint
**breakpointp
= (struct breakpoint
**)arg
;
383 if (*breakpointp
!= NULL
)
384 delete_breakpoint (*breakpointp
);
387 /* Wait for control to return from inferior to debugger.
388 If inferior gets a signal, we may decide to start it up again
389 instead of returning. That is why there is a loop in this function.
390 When this function actually returns it means the inferior
391 should be left stopped and GDB should read more commands. */
396 struct cleanup
*old_cleanups
;
400 CORE_ADDR stop_sp
= 0;
401 CORE_ADDR stop_func_start
;
402 char *stop_func_name
;
403 CORE_ADDR prologue_pc
= 0, tmp
;
404 struct symtab_and_line sal
;
405 int remove_breakpoints_on_following_step
= 0;
407 struct symtab
*current_symtab
;
408 int handling_longjmp
= 0; /* FIXME */
409 struct breakpoint
*step_resume_breakpoint
= NULL
;
412 old_cleanups
= make_cleanup (delete_breakpoint_current_contents
,
413 &step_resume_breakpoint
);
414 sal
= find_pc_line(prev_pc
, 0);
415 current_line
= sal
.line
;
416 current_symtab
= sal
.symtab
;
418 /* Are we stepping? */
419 #define CURRENTLY_STEPPING() ((step_resume_breakpoint == NULL \
420 && !handling_longjmp \
423 || bpstat_should_step ())
427 /* Clean up saved state that will become invalid. */
428 flush_cached_frames ();
429 registers_changed ();
431 pid
= target_wait (-1, &w
);
433 #ifdef SIGTRAP_STOP_AFTER_LOAD
435 /* Somebody called load(2), and it gave us a "trap signal after load".
436 Ignore it gracefully. */
438 SIGTRAP_STOP_AFTER_LOAD (w
);
441 /* See if the process still exists; clean up if it doesn't. */
444 target_terminal_ours (); /* Must do this before mourn anyway */
446 printf_filtered ("\nProgram exited with code 0%o.\n",
447 (unsigned int)WEXITSTATUS (w
));
450 printf_filtered ("\nProgram exited normally.\n");
451 gdb_flush (gdb_stdout
);
452 target_mourn_inferior ();
453 #ifdef NO_SINGLE_STEP
456 stop_print_frame
= 0;
459 else if (!WIFSTOPPED (w
))
463 stop_print_frame
= 0;
464 stop_signal
= WTERMSIG (w
);
465 target_terminal_ours (); /* Must do this before mourn anyway */
466 target_kill (); /* kill mourns as well */
467 #ifdef PRINT_RANDOM_SIGNAL
468 printf_filtered ("\nProgram terminated: ");
469 PRINT_RANDOM_SIGNAL (stop_signal
);
471 printf_filtered ("\nProgram terminated with signal ");
472 signame
= strsigno (stop_signal
);
474 printf_filtered ("%d", stop_signal
);
476 /* Do we need to print the number in addition to the name? */
477 printf_filtered ("%s (%d)", signame
, stop_signal
);
478 printf_filtered (", %s\n", safe_strsignal (stop_signal
));
480 printf_filtered ("The program no longer exists.\n");
481 gdb_flush (gdb_stdout
);
482 #ifdef NO_SINGLE_STEP
488 stop_signal
= WSTOPSIG (w
);
490 if (pid
!= inferior_pid
)
492 int save_pid
= inferior_pid
;
494 inferior_pid
= pid
; /* Setup for target memory/regs */
495 registers_changed ();
496 stop_pc
= read_pc ();
497 inferior_pid
= save_pid
;
498 registers_changed ();
501 stop_pc
= read_pc ();
503 if (stop_signal
== SIGTRAP
504 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
506 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
, pid
))
508 /* Saw a breakpoint, but it was hit by the wrong thread. Just continue. */
509 if (breakpoints_inserted
)
511 if (pid
!= inferior_pid
)
513 int save_pid
= inferior_pid
;
516 registers_changed ();
517 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
518 inferior_pid
= save_pid
;
519 registers_changed ();
522 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
524 remove_breakpoints ();
525 target_resume (pid
, 1, 0); /* Single step */
526 /* FIXME: What if a signal arrives instead of the single-step
528 target_wait (pid
, &w
);
529 insert_breakpoints ();
531 target_resume (-1, 0, 0);
535 if (pid
!= inferior_pid
)
539 if (pid
!= inferior_pid
)
543 if (!in_thread_list (pid
))
545 fprintf_unfiltered (gdb_stderr
, "[New %s]\n", target_pid_to_str (pid
));
548 target_resume (-1, 0, 0);
553 if (stop_signal
>= NSIG
|| signal_print
[stop_signal
])
558 target_terminal_ours_for_output ();
559 printf_filtered ("\nProgram received signal ");
560 signame
= strsigno (stop_signal
);
562 printf_filtered ("%d", stop_signal
);
564 printf_filtered ("%s (%d)", signame
, stop_signal
);
565 printf_filtered (", %s\n", safe_strsignal (stop_signal
));
567 gdb_flush (gdb_stdout
);
570 if (stop_signal
== SIGTRAP
571 || stop_signal
>= NSIG
572 || signal_stop
[stop_signal
])
576 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid
));
578 flush_cached_frames ();
579 registers_changed ();
581 if (step_resume_breakpoint
)
583 delete_breakpoint (step_resume_breakpoint
);
584 step_resume_breakpoint
= NULL
;
588 prev_func_name
= NULL
;
589 step_range_start
= 0;
591 step_frame_address
= 0;
592 handling_longjmp
= 0;
598 target_terminal_inferior ();
600 /* Clear the signal if it should not be passed. */
601 if (signal_program
[stop_signal
] == 0)
604 target_resume (pid
, 0, stop_signal
);
610 #ifdef NO_SINGLE_STEP
612 single_step (0); /* This actually cleans up the ss */
613 #endif /* NO_SINGLE_STEP */
615 /* If PC is pointing at a nullified instruction, then step beyond it so that
616 the user won't be confused when GDB appears to be ready to execute it. */
618 if (INSTRUCTION_NULLIFIED
)
624 set_current_frame ( create_new_frame (read_fp (), stop_pc
));
626 stop_frame_address
= FRAME_FP (get_current_frame ());
627 stop_sp
= read_sp ();
630 /* Don't care about return value; stop_func_start and stop_func_name
631 will both be 0 if it doesn't work. */
632 find_pc_partial_function (stop_pc
, &stop_func_name
, &stop_func_start
,
634 stop_func_start
+= FUNCTION_START_OFFSET
;
636 bpstat_clear (&stop_bpstat
);
638 stop_stack_dummy
= 0;
639 stop_print_frame
= 1;
641 stopped_by_random_signal
= 0;
642 breakpoints_failed
= 0;
644 /* Look at the cause of the stop, and decide what to do.
645 The alternatives are:
646 1) break; to really stop and return to the debugger,
647 2) drop through to start up again
648 (set another_trap to 1 to single step once)
649 3) set random_signal to 1, and the decision between 1 and 2
650 will be made according to the signal handling tables. */
652 /* First, distinguish signals caused by the debugger from signals
653 that have to do with the program's own actions.
654 Note that breakpoint insns may cause SIGTRAP or SIGILL
655 or SIGEMT, depending on the operating system version.
656 Here we detect when a SIGILL or SIGEMT is really a breakpoint
657 and change it to SIGTRAP. */
659 if (stop_signal
== SIGTRAP
660 || (breakpoints_inserted
&&
661 (stop_signal
== SIGILL
663 || stop_signal
== SIGEMT
666 || stop_soon_quietly
)
668 if (stop_signal
== SIGTRAP
&& stop_after_trap
)
670 stop_print_frame
= 0;
673 if (stop_soon_quietly
)
676 /* Don't even think about breakpoints
677 if just proceeded over a breakpoint.
679 However, if we are trying to proceed over a breakpoint
680 and end up in sigtramp, then step_resume_breakpoint
681 will be set and we should check whether we've hit the
683 if (stop_signal
== SIGTRAP
&& trap_expected
684 && step_resume_breakpoint
== NULL
)
685 bpstat_clear (&stop_bpstat
);
688 /* See if there is a breakpoint at the current PC. */
689 stop_bpstat
= bpstat_stop_status
690 (&stop_pc
, stop_frame_address
,
691 #if DECR_PC_AFTER_BREAK
692 /* Notice the case of stepping through a jump
693 that lands just after a breakpoint.
694 Don't confuse that with hitting the breakpoint.
695 What we check for is that 1) stepping is going on
696 and 2) the pc before the last insn does not match
697 the address of the breakpoint before the current pc. */
698 (prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
699 && CURRENTLY_STEPPING ())
700 #else /* DECR_PC_AFTER_BREAK zero */
702 #endif /* DECR_PC_AFTER_BREAK zero */
704 /* Following in case break condition called a
706 stop_print_frame
= 1;
709 if (stop_signal
== SIGTRAP
)
711 = !(bpstat_explains_signal (stop_bpstat
)
713 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
714 || PC_IN_CALL_DUMMY (stop_pc
, stop_sp
, stop_frame_address
)
715 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
716 || (step_range_end
&& step_resume_breakpoint
== NULL
));
720 = !(bpstat_explains_signal (stop_bpstat
)
721 /* End of a stack dummy. Some systems (e.g. Sony
722 news) give another signal besides SIGTRAP,
723 so check here as well as above. */
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. */
729 stop_signal
= SIGTRAP
;
735 /* For the program's own signals, act according to
736 the signal handling tables. */
740 /* Signal not for debugging purposes. */
743 stopped_by_random_signal
= 1;
745 if (stop_signal
>= NSIG
746 || signal_print
[stop_signal
])
750 target_terminal_ours_for_output ();
751 #ifdef PRINT_RANDOM_SIGNAL
752 PRINT_RANDOM_SIGNAL (stop_signal
);
754 printf_filtered ("\nProgram received signal ");
755 signame
= strsigno (stop_signal
);
757 printf_filtered ("%d", stop_signal
);
759 /* Do we need to print the number as well as the name? */
760 printf_filtered ("%s (%d)", signame
, stop_signal
);
761 printf_filtered (", %s\n", safe_strsignal (stop_signal
));
762 #endif /* PRINT_RANDOM_SIGNAL */
763 gdb_flush (gdb_stdout
);
765 if (stop_signal
>= NSIG
766 || signal_stop
[stop_signal
])
768 /* If not going to stop, give terminal back
769 if we took it away. */
771 target_terminal_inferior ();
773 /* Clear the signal if it should not be passed. */
774 if (signal_program
[stop_signal
] == 0)
777 /* I'm not sure whether this needs to be check_sigtramp2 or
778 whether it could/should be keep_going. */
779 goto check_sigtramp2
;
782 /* Handle cases caused by hitting a breakpoint. */
784 CORE_ADDR jmp_buf_pc
;
785 struct bpstat_what what
;
787 what
= bpstat_what (stop_bpstat
);
791 stop_stack_dummy
= 1;
793 trap_expected_after_continue
= 1;
797 switch (what
.main_action
)
799 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
800 /* If we hit the breakpoint at longjmp, disable it for the
801 duration of this command. Then, install a temporary
802 breakpoint at the target of the jmp_buf. */
803 disable_longjmp_breakpoint();
804 remove_breakpoints ();
805 breakpoints_inserted
= 0;
806 if (!GET_LONGJMP_TARGET(&jmp_buf_pc
)) goto keep_going
;
808 /* Need to blow away step-resume breakpoint, as it
809 interferes with us */
810 if (step_resume_breakpoint
!= NULL
)
812 delete_breakpoint (step_resume_breakpoint
);
813 step_resume_breakpoint
= NULL
;
814 what
.step_resume
= 0;
818 /* FIXME - Need to implement nested temporary breakpoints */
819 if (step_over_calls
> 0)
820 set_longjmp_resume_breakpoint(jmp_buf_pc
,
821 get_current_frame());
824 set_longjmp_resume_breakpoint(jmp_buf_pc
, NULL
);
825 handling_longjmp
= 1; /* FIXME */
828 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
829 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
830 remove_breakpoints ();
831 breakpoints_inserted
= 0;
833 /* FIXME - Need to implement nested temporary breakpoints */
835 && (stop_frame_address
836 INNER_THAN step_frame_address
))
842 disable_longjmp_breakpoint();
843 handling_longjmp
= 0; /* FIXME */
844 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
846 /* else fallthrough */
848 case BPSTAT_WHAT_SINGLE
:
849 if (breakpoints_inserted
)
850 remove_breakpoints ();
851 breakpoints_inserted
= 0;
853 /* Still need to check other stuff, at least the case
854 where we are stepping and step out of the right range. */
857 case BPSTAT_WHAT_STOP_NOISY
:
858 stop_print_frame
= 1;
859 /* We are about to nuke the step_resume_breakpoint via the
860 cleanup chain, so no need to worry about it here. */
863 case BPSTAT_WHAT_STOP_SILENT
:
864 stop_print_frame
= 0;
865 /* We are about to nuke the step_resume_breakpoint via the
866 cleanup chain, so no need to worry about it here. */
869 case BPSTAT_WHAT_LAST
:
870 /* Not a real code, but listed here to shut up gcc -Wall. */
872 case BPSTAT_WHAT_KEEP_CHECKING
:
876 if (what
.step_resume
)
878 delete_breakpoint (step_resume_breakpoint
);
879 step_resume_breakpoint
= NULL
;
881 /* If were waiting for a trap, hitting the step_resume_break
882 doesn't count as getting it. */
888 /* We come here if we hit a breakpoint but should not
889 stop for it. Possibly we also were stepping
890 and should stop for that. So fall through and
891 test for stepping. But, if not stepping,
894 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
895 /* This is the old way of detecting the end of the stack dummy.
896 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
897 handled above. As soon as we can test it on all of them, all
898 architectures should define it. */
900 /* If this is the breakpoint at the end of a stack dummy,
901 just stop silently, unless the user was doing an si/ni, in which
902 case she'd better know what she's doing. */
904 if (PC_IN_CALL_DUMMY (stop_pc
, stop_sp
, stop_frame_address
)
907 stop_print_frame
= 0;
908 stop_stack_dummy
= 1;
910 trap_expected_after_continue
= 1;
914 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
916 if (step_resume_breakpoint
)
917 /* Having a step-resume breakpoint overrides anything
918 else having to do with stepping commands until
919 that breakpoint is reached. */
920 /* I suspect this could/should be keep_going, because if the
921 check_sigtramp2 check succeeds, then it will put in another
922 step_resume_breakpoint, and we aren't (yet) prepared to nest
924 goto check_sigtramp2
;
926 if (step_range_end
== 0)
927 /* Likewise if we aren't even stepping. */
928 /* I'm not sure whether this needs to be check_sigtramp2 or
929 whether it could/should be keep_going. */
930 goto check_sigtramp2
;
932 /* If stepping through a line, keep going if still within it. */
933 if (stop_pc
>= step_range_start
934 && stop_pc
< step_range_end
935 /* The step range might include the start of the
936 function, so if we are at the start of the
937 step range and either the stack or frame pointers
938 just changed, we've stepped outside */
939 && !(stop_pc
== step_range_start
940 && stop_frame_address
941 && (stop_sp INNER_THAN prev_sp
942 || stop_frame_address
!= step_frame_address
)))
944 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
945 So definately need to check for sigtramp here. */
946 goto check_sigtramp2
;
949 /* We stepped out of the stepping range. See if that was due
950 to a subroutine call that we should proceed to the end of. */
952 /* Did we just take a signal? */
953 if (IN_SIGTRAMP (stop_pc
, stop_func_name
)
954 && !IN_SIGTRAMP (prev_pc
, prev_func_name
))
956 /* This code is needed at least in the following case:
957 The user types "next" and then a signal arrives (before
958 the "next" is done). */
959 /* We've just taken a signal; go until we are back to
960 the point where we took it and one more. */
962 struct symtab_and_line sr_sal
;
965 sr_sal
.symtab
= NULL
;
967 step_resume_breakpoint
=
968 set_momentary_breakpoint (sr_sal
, get_current_frame (),
970 if (breakpoints_inserted
)
971 insert_breakpoints ();
974 /* If this is stepi or nexti, make sure that the stepping range
975 gets us past that instruction. */
976 if (step_range_end
== 1)
977 /* FIXME: Does this run afoul of the code below which, if
978 we step into the middle of a line, resets the stepping
980 step_range_end
= (step_range_start
= prev_pc
) + 1;
982 remove_breakpoints_on_following_step
= 1;
988 /* Do this after the IN_SIGTRAMP check; it might give
990 prologue_pc
= stop_func_start
;
991 SKIP_PROLOGUE (prologue_pc
);
994 if ((/* Might be a non-recursive call. If the symbols are missing
995 enough that stop_func_start == prev_func_start even though
996 they are really two functions, we will treat some calls as
998 stop_func_start
!= prev_func_start
1000 /* Might be a recursive call if either we have a prologue
1001 or the call instruction itself saves the PC on the stack. */
1002 || prologue_pc
!= stop_func_start
1003 || stop_sp
!= prev_sp
)
1004 && (/* PC is completely out of bounds of any known objfiles. Treat
1005 like a subroutine call. */
1008 /* If we do a call, we will be at the start of a function. */
1009 || stop_pc
== stop_func_start
1010 || AT_FUNCTION_START (stop_pc
, stop_func_name
, stop_func_start
)
1013 /* Not conservative enough for 4.11. FIXME: enable this
1015 /* Except on the Alpha with -O (and perhaps other machines
1016 with similar calling conventions), in which we might
1017 call the address after the load of gp. Since prologues
1018 don't contain calls, we can't return to within one, and
1019 we don't jump back into them, so this check is OK. */
1020 || stop_pc
< prologue_pc
1023 /* If we end up in certain places, it means we did a subroutine
1024 call. I'm not completely sure this is necessary now that we
1025 have the above checks with stop_func_start (and now that
1026 find_pc_partial_function is pickier). */
1027 || IN_SOLIB_TRAMPOLINE (stop_pc
, stop_func_name
)
1029 /* If none of the above apply, it is a jump within a function,
1030 or a return from a subroutine. The other case is longjmp,
1031 which can no longer happen here as long as the
1032 handling_longjmp stuff is working. */
1035 /* It's a subroutine call. */
1037 if (step_over_calls
== 0)
1039 /* I presume that step_over_calls is only 0 when we're
1040 supposed to be stepping at the assembly language level
1041 ("stepi"). Just stop. */
1046 if (step_over_calls
> 0)
1047 /* We're doing a "next". */
1048 goto step_over_function
;
1050 /* If we are in a function call trampoline (a stub between
1051 the calling routine and the real function), locate the real
1052 function. That's what tells us (a) whether we want to step
1053 into it at all, and (b) what prologue we want to run to
1054 the end of, if we do step into it. */
1055 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
1057 stop_func_start
= tmp
;
1059 /* If we have line number information for the function we
1060 are thinking of stepping into, step into it.
1062 If there are several symtabs at that PC (e.g. with include
1063 files), just want to know whether *any* of them have line
1064 numbers. find_pc_line handles this. */
1066 struct symtab_and_line tmp_sal
;
1068 tmp_sal
= find_pc_line (stop_func_start
, 0);
1069 if (tmp_sal
.line
!= 0)
1070 goto step_into_function
;
1074 /* A subroutine call has happened. */
1076 /* Set a special breakpoint after the return */
1077 struct symtab_and_line sr_sal
;
1080 (SAVED_PC_AFTER_CALL (get_current_frame ()));
1081 sr_sal
.symtab
= NULL
;
1083 step_resume_breakpoint
=
1084 set_momentary_breakpoint (sr_sal
, get_current_frame (),
1086 if (breakpoints_inserted
)
1087 insert_breakpoints ();
1092 /* Subroutine call with source code we should not step over.
1093 Do step to the first line of code in it. */
1094 SKIP_PROLOGUE (stop_func_start
);
1095 sal
= find_pc_line (stop_func_start
, 0);
1096 /* Use the step_resume_break to step until
1097 the end of the prologue, even if that involves jumps
1098 (as it seems to on the vax under 4.2). */
1099 /* If the prologue ends in the middle of a source line,
1100 continue to the end of that source line.
1101 Otherwise, just go to end of prologue. */
1102 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1103 /* no, don't either. It skips any code that's
1104 legitimately on the first line. */
1106 if (sal
.end
&& sal
.pc
!= stop_func_start
)
1107 stop_func_start
= sal
.end
;
1110 if (stop_func_start
== stop_pc
)
1112 /* We are already there: stop now. */
1117 /* Put the step-breakpoint there and go until there. */
1119 struct symtab_and_line sr_sal
;
1121 sr_sal
.pc
= stop_func_start
;
1122 sr_sal
.symtab
= NULL
;
1124 /* Do not specify what the fp should be when we stop
1125 since on some machines the prologue
1126 is where the new fp value is established. */
1127 step_resume_breakpoint
=
1128 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
1129 if (breakpoints_inserted
)
1130 insert_breakpoints ();
1132 /* And make sure stepping stops right away then. */
1133 step_range_end
= step_range_start
;
1138 /* We've wandered out of the step range. */
1140 sal
= find_pc_line(stop_pc
, 0);
1142 if (step_range_end
== 1)
1144 /* It is stepi or nexti. We always want to stop stepping after
1152 /* We have no line number information. That means to stop
1153 stepping (does this always happen right after one instruction,
1154 when we do "s" in a function with no line numbers,
1155 or can this happen as a result of a return or longjmp?). */
1160 if (stop_pc
== sal
.pc
1161 && (current_line
!= sal
.line
|| current_symtab
!= sal
.symtab
))
1163 /* We are at the start of a different line. So stop. Note that
1164 we don't stop if we step into the middle of a different line.
1165 That is said to make things like for (;;) statements work
1171 /* We aren't done stepping.
1173 Optimize by setting the stepping range to the line.
1174 (We might not be in the original line, but if we entered a
1175 new line in mid-statement, we continue stepping. This makes
1176 things like for(;;) statements work better.) */
1177 step_range_start
= sal
.pc
;
1178 step_range_end
= sal
.end
;
1183 && IN_SIGTRAMP (stop_pc
, stop_func_name
)
1184 && !IN_SIGTRAMP (prev_pc
, prev_func_name
))
1186 /* What has happened here is that we have just stepped the inferior
1187 with a signal (because it is a signal which shouldn't make
1188 us stop), thus stepping into sigtramp.
1190 So we need to set a step_resume_break_address breakpoint
1191 and continue until we hit it, and then step. FIXME: This should
1192 be more enduring than a step_resume breakpoint; we should know
1193 that we will later need to keep going rather than re-hitting
1194 the breakpoint here (see testsuite/gdb.t06/signals.exp where
1195 it says "exceedingly difficult"). */
1196 struct symtab_and_line sr_sal
;
1198 sr_sal
.pc
= prev_pc
;
1199 sr_sal
.symtab
= NULL
;
1201 step_resume_breakpoint
=
1202 set_momentary_breakpoint (sr_sal
, get_current_frame (),
1204 if (breakpoints_inserted
)
1205 insert_breakpoints ();
1207 remove_breakpoints_on_following_step
= 1;
1212 /* Come to this label when you need to resume the inferior.
1213 It's really much cleaner to do a goto than a maze of if-else
1216 /* Save the pc before execution, to compare with pc after stop. */
1217 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
1218 prev_func_start
= stop_func_start
; /* Ok, since if DECR_PC_AFTER
1219 BREAK is defined, the
1220 original pc would not have
1221 been at the start of a
1223 prev_func_name
= stop_func_name
;
1226 /* If we did not do break;, it means we should keep
1227 running the inferior and not return to debugger. */
1229 if (trap_expected
&& stop_signal
!= SIGTRAP
)
1231 /* We took a signal (which we are supposed to pass through to
1232 the inferior, else we'd have done a break above) and we
1233 haven't yet gotten our trap. Simply continue. */
1234 resume (CURRENTLY_STEPPING (), stop_signal
);
1238 /* Either the trap was not expected, but we are continuing
1239 anyway (the user asked that this signal be passed to the
1242 The signal was SIGTRAP, e.g. it was our signal, but we
1243 decided we should resume from it.
1245 We're going to run this baby now!
1247 Insert breakpoints now, unless we are trying
1248 to one-proceed past a breakpoint. */
1249 /* If we've just finished a special step resume and we don't
1250 want to hit a breakpoint, pull em out. */
1251 if (step_resume_breakpoint
== NULL
&&
1252 remove_breakpoints_on_following_step
)
1254 remove_breakpoints_on_following_step
= 0;
1255 remove_breakpoints ();
1256 breakpoints_inserted
= 0;
1258 else if (!breakpoints_inserted
&&
1259 (step_resume_breakpoint
!= NULL
|| !another_trap
))
1261 breakpoints_failed
= insert_breakpoints ();
1262 if (breakpoints_failed
)
1264 breakpoints_inserted
= 1;
1267 trap_expected
= another_trap
;
1269 if (stop_signal
== SIGTRAP
)
1272 #ifdef SHIFT_INST_REGS
1273 /* I'm not sure when this following segment applies. I do know, now,
1274 that we shouldn't rewrite the regs when we were stopped by a
1275 random signal from the inferior process. */
1276 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
1277 (this is only used on the 88k). */
1279 if (!bpstat_explains_signal (stop_bpstat
)
1280 && (stop_signal
!= SIGCLD
)
1281 && !stopped_by_random_signal
)
1283 #endif /* SHIFT_INST_REGS */
1285 resume (CURRENTLY_STEPPING (), stop_signal
);
1290 if (target_has_execution
)
1292 /* Assuming the inferior still exists, set these up for next
1293 time, just like we did above if we didn't break out of the
1295 prev_pc
= read_pc ();
1296 prev_func_start
= stop_func_start
;
1297 prev_func_name
= stop_func_name
;
1300 do_cleanups (old_cleanups
);
1303 /* Here to return control to GDB when the inferior stops for real.
1304 Print appropriate messages, remove breakpoints, give terminal our modes.
1306 STOP_PRINT_FRAME nonzero means print the executing frame
1307 (pc, function, args, file, line number and line text).
1308 BREAKPOINTS_FAILED nonzero means stop was due to error
1309 attempting to insert breakpoints. */
1314 /* Make sure that the current_frame's pc is correct. This
1315 is a correction for setting up the frame info before doing
1316 DECR_PC_AFTER_BREAK */
1317 if (target_has_execution
&& get_current_frame())
1318 (get_current_frame ())->pc
= read_pc ();
1320 if (breakpoints_failed
)
1322 target_terminal_ours_for_output ();
1323 print_sys_errmsg ("ptrace", breakpoints_failed
);
1324 printf_filtered ("Stopped; cannot insert breakpoints.\n\
1325 The same program may be running in another process.\n");
1328 if (target_has_execution
&& breakpoints_inserted
)
1329 if (remove_breakpoints ())
1331 target_terminal_ours_for_output ();
1332 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
1333 It might be running in another process.\n\
1334 Further execution is probably impossible.\n");
1337 breakpoints_inserted
= 0;
1339 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1340 Delete any breakpoint that is to be deleted at the next stop. */
1342 breakpoint_auto_delete (stop_bpstat
);
1344 /* If an auto-display called a function and that got a signal,
1345 delete that auto-display to avoid an infinite recursion. */
1347 if (stopped_by_random_signal
)
1348 disable_current_display ();
1350 if (step_multi
&& stop_step
)
1353 target_terminal_ours ();
1355 /* Look up the hook_stop and run it if it exists. */
1357 if (stop_command
->hook
)
1359 catch_errors (hook_stop_stub
, (char *)stop_command
->hook
,
1360 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
1363 if (!target_has_stack
)
1366 /* Select innermost stack frame except on return from a stack dummy routine,
1367 or if the program has exited. Print it without a level number if
1368 we have changed functions or hit a breakpoint. Print source line
1370 if (!stop_stack_dummy
)
1372 select_frame (get_current_frame (), 0);
1374 if (stop_print_frame
)
1378 source_only
= bpstat_print (stop_bpstat
);
1379 source_only
= source_only
||
1381 && step_frame_address
== stop_frame_address
1382 && step_start_function
== find_pc_function (stop_pc
));
1384 print_stack_frame (selected_frame
, -1, source_only
? -1: 1);
1386 /* Display the auto-display expressions. */
1391 /* Save the function value return registers, if we care.
1392 We might be about to restore their previous contents. */
1393 if (proceed_to_finish
)
1394 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
1396 if (stop_stack_dummy
)
1398 /* Pop the empty frame that contains the stack dummy.
1399 POP_FRAME ends with a setting of the current frame, so we
1400 can use that next. */
1402 select_frame (get_current_frame (), 0);
1407 hook_stop_stub (cmd
)
1410 execute_user_command ((struct cmd_list_element
*)cmd
, 0);
1414 int signal_stop_state (signo
)
1417 return ((signo
>= 0 && signo
< NSIG
) ? signal_stop
[signo
] : 0);
1420 int signal_print_state (signo
)
1423 return ((signo
>= 0 && signo
< NSIG
) ? signal_print
[signo
] : 0);
1426 int signal_pass_state (signo
)
1429 return ((signo
>= 0 && signo
< NSIG
) ? signal_program
[signo
] : 0);
1435 printf_filtered ("Signal\t\tStop\tPrint\tPass to program\tDescription\n");
1439 sig_print_info (number
)
1444 if ((name
= strsigno (number
)) == NULL
)
1445 printf_filtered ("%d\t\t", number
);
1447 printf_filtered ("%s (%d)\t", name
, number
);
1448 printf_filtered ("%s\t", signal_stop
[number
] ? "Yes" : "No");
1449 printf_filtered ("%s\t", signal_print
[number
] ? "Yes" : "No");
1450 printf_filtered ("%s\t\t", signal_program
[number
] ? "Yes" : "No");
1451 printf_filtered ("%s\n", safe_strsignal (number
));
1454 /* Specify how various signals in the inferior should be handled. */
1457 handle_command (args
, from_tty
)
1462 int digits
, wordlen
;
1463 int sigfirst
, signum
, siglast
;
1466 unsigned char *sigs
;
1467 struct cleanup
*old_chain
;
1471 error_no_arg ("signal to handle");
1474 /* Allocate and zero an array of flags for which signals to handle. */
1476 nsigs
= signo_max () + 1;
1477 sigs
= (unsigned char *) alloca (nsigs
);
1478 memset (sigs
, 0, nsigs
);
1480 /* Break the command line up into args. */
1482 argv
= buildargv (args
);
1487 old_chain
= make_cleanup (freeargv
, (char *) argv
);
1489 /* Walk through the args, looking for signal numbers, signal names, and
1490 actions. Signal numbers and signal names may be interspersed with
1491 actions, with the actions being performed for all signals cumulatively
1492 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
1494 while (*argv
!= NULL
)
1496 wordlen
= strlen (*argv
);
1497 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++) {;}
1499 sigfirst
= siglast
= -1;
1501 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
1503 /* Apply action to all signals except those used by the
1504 debugger. Silently skip those. */
1507 siglast
= nsigs
- 1;
1509 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
1511 SET_SIGS (nsigs
, sigs
, signal_stop
);
1512 SET_SIGS (nsigs
, sigs
, signal_print
);
1514 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
1516 UNSET_SIGS (nsigs
, sigs
, signal_program
);
1518 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
1520 SET_SIGS (nsigs
, sigs
, signal_print
);
1522 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
1524 SET_SIGS (nsigs
, sigs
, signal_program
);
1526 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
1528 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
1530 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
1532 SET_SIGS (nsigs
, sigs
, signal_program
);
1534 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
1536 UNSET_SIGS (nsigs
, sigs
, signal_print
);
1537 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
1539 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
1541 UNSET_SIGS (nsigs
, sigs
, signal_program
);
1543 else if (digits
> 0)
1545 sigfirst
= siglast
= atoi (*argv
);
1546 if ((*argv
)[digits
] == '-')
1548 siglast
= atoi ((*argv
) + digits
+ 1);
1550 if (sigfirst
> siglast
)
1552 /* Bet he didn't figure we'd think of this case... */
1557 if (sigfirst
< 0 || sigfirst
>= nsigs
)
1559 error ("Signal %d not in range 0-%d", sigfirst
, nsigs
- 1);
1561 if (siglast
< 0 || siglast
>= nsigs
)
1563 error ("Signal %d not in range 0-%d", siglast
, nsigs
- 1);
1566 else if ((signum
= strtosigno (*argv
)) != 0)
1568 sigfirst
= siglast
= signum
;
1572 /* Not a number and not a recognized flag word => complain. */
1573 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
1576 /* If any signal numbers or symbol names were found, set flags for
1577 which signals to apply actions to. */
1579 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
1585 if (!allsigs
&& !sigs
[signum
])
1587 if (query ("%s is used by the debugger.\nAre you sure you want to change it? ", strsigno (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. */
1628 signals_info (signum_exp
, from_tty
)
1633 sig_print_header ();
1637 /* First see if this is a symbol name. */
1638 i
= strtosigno (signum_exp
);
1641 /* Nope, maybe it's an address which evaluates to a signal
1643 i
= parse_and_eval_address (signum_exp
);
1644 if (i
>= NSIG
|| i
< 0)
1645 error ("Signal number out of bounds.");
1651 printf_filtered ("\n");
1652 for (i
= 0; i
< NSIG
; i
++)
1659 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
1662 /* Save all of the information associated with the inferior<==>gdb
1663 connection. INF_STATUS is a pointer to a "struct inferior_status"
1664 (defined in inferior.h). */
1667 save_inferior_status (inf_status
, restore_stack_info
)
1668 struct inferior_status
*inf_status
;
1669 int restore_stack_info
;
1671 inf_status
->stop_signal
= stop_signal
;
1672 inf_status
->stop_pc
= stop_pc
;
1673 inf_status
->stop_frame_address
= stop_frame_address
;
1674 inf_status
->stop_step
= stop_step
;
1675 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
1676 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
1677 inf_status
->trap_expected
= trap_expected
;
1678 inf_status
->step_range_start
= step_range_start
;
1679 inf_status
->step_range_end
= step_range_end
;
1680 inf_status
->step_frame_address
= step_frame_address
;
1681 inf_status
->step_over_calls
= step_over_calls
;
1682 inf_status
->stop_after_trap
= stop_after_trap
;
1683 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
1684 /* Save original bpstat chain here; replace it with copy of chain.
1685 If caller's caller is walking the chain, they'll be happier if we
1686 hand them back the original chain when restore_i_s is called. */
1687 inf_status
->stop_bpstat
= stop_bpstat
;
1688 stop_bpstat
= bpstat_copy (stop_bpstat
);
1689 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
1690 inf_status
->restore_stack_info
= restore_stack_info
;
1691 inf_status
->proceed_to_finish
= proceed_to_finish
;
1693 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
1695 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
1697 record_selected_frame (&(inf_status
->selected_frame_address
),
1698 &(inf_status
->selected_level
));
1702 struct restore_selected_frame_args
{
1703 FRAME_ADDR frame_address
;
1707 static int restore_selected_frame
PARAMS ((char *));
1709 /* Restore the selected frame. args is really a struct
1710 restore_selected_frame_args * (declared as char * for catch_errors)
1711 telling us what frame to restore. Returns 1 for success, or 0 for
1712 failure. An error message will have been printed on error. */
1714 restore_selected_frame (args
)
1717 struct restore_selected_frame_args
*fr
=
1718 (struct restore_selected_frame_args
*) args
;
1720 int level
= fr
->level
;
1722 fid
= find_relative_frame (get_current_frame (), &level
);
1724 /* If inf_status->selected_frame_address is NULL, there was no
1725 previously selected frame. */
1727 FRAME_FP (fid
) != fr
->frame_address
||
1730 warning ("Unable to restore previously selected frame.\n");
1733 select_frame (fid
, fr
->level
);
1738 restore_inferior_status (inf_status
)
1739 struct inferior_status
*inf_status
;
1741 stop_signal
= inf_status
->stop_signal
;
1742 stop_pc
= inf_status
->stop_pc
;
1743 stop_frame_address
= inf_status
->stop_frame_address
;
1744 stop_step
= inf_status
->stop_step
;
1745 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
1746 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
1747 trap_expected
= inf_status
->trap_expected
;
1748 step_range_start
= inf_status
->step_range_start
;
1749 step_range_end
= inf_status
->step_range_end
;
1750 step_frame_address
= inf_status
->step_frame_address
;
1751 step_over_calls
= inf_status
->step_over_calls
;
1752 stop_after_trap
= inf_status
->stop_after_trap
;
1753 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
1754 bpstat_clear (&stop_bpstat
);
1755 stop_bpstat
= inf_status
->stop_bpstat
;
1756 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
1757 proceed_to_finish
= inf_status
->proceed_to_finish
;
1759 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
1761 /* The inferior can be gone if the user types "print exit(0)"
1762 (and perhaps other times). */
1763 if (target_has_execution
)
1764 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
1766 /* The inferior can be gone if the user types "print exit(0)"
1767 (and perhaps other times). */
1769 /* FIXME: If we are being called after stopping in a function which
1770 is called from gdb, we should not be trying to restore the
1771 selected frame; it just prints a spurious error message (The
1772 message is useful, however, in detecting bugs in gdb (like if gdb
1773 clobbers the stack)). In fact, should we be restoring the
1774 inferior status at all in that case? . */
1776 if (target_has_stack
&& inf_status
->restore_stack_info
)
1778 struct restore_selected_frame_args fr
;
1779 fr
.level
= inf_status
->selected_level
;
1780 fr
.frame_address
= inf_status
->selected_frame_address
;
1781 /* The point of catch_errors is that if the stack is clobbered,
1782 walking the stack might encounter a garbage pointer and error()
1783 trying to dereference it. */
1784 if (catch_errors (restore_selected_frame
, &fr
,
1785 "Unable to restore previously selected frame:\n",
1786 RETURN_MASK_ERROR
) == 0)
1787 /* Error in restoring the selected frame. Select the innermost
1789 select_frame (get_current_frame (), 0);
1795 _initialize_infrun ()
1798 register int numsigs
;
1800 add_info ("signals", signals_info
,
1801 "What debugger does when program gets various signals.\n\
1802 Specify a signal number as argument to print info on that signal only.");
1803 add_info_alias ("handle", "signals", 0);
1805 add_com ("handle", class_run
, handle_command
,
1806 "Specify how to handle a signal.\n\
1807 Args are signal numbers and actions to apply to those signals.\n\
1808 Signal numbers may be numeric (ex. 11) or symbolic (ex. SIGSEGV).\n\
1809 Numeric ranges may be specified with the form LOW-HIGH (ex. 14-21).\n\
1810 The special arg \"all\" is recognized to mean all signals except those\n\
1811 used by the debugger, typically SIGTRAP and SIGINT.\n\
1812 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
1813 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
1814 Stop means reenter debugger if this signal happens (implies print).\n\
1815 Print means print a message if this signal happens.\n\
1816 Pass means let program see this signal; otherwise program doesn't know.\n\
1817 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
1818 Pass and Stop may be combined.");
1820 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
1821 "There is no `stop' command, but you can set a hook on `stop'.\n\
1822 This allows you to set a list of commands to be run each time execution\n\
1823 of the program stops.", &cmdlist
);
1825 numsigs
= signo_max () + 1;
1826 signal_stop
= (unsigned char *)
1827 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
1828 signal_print
= (unsigned char *)
1829 xmalloc (sizeof (signal_print
[0]) * numsigs
);
1830 signal_program
= (unsigned char *)
1831 xmalloc (sizeof (signal_program
[0]) * numsigs
);
1832 for (i
= 0; i
< numsigs
; i
++)
1835 signal_print
[i
] = 1;
1836 signal_program
[i
] = 1;
1839 /* Signals caused by debugger's own actions
1840 should not be given to the program afterwards. */
1841 signal_program
[SIGTRAP
] = 0;
1842 signal_program
[SIGINT
] = 0;
1844 /* Signals that are not errors should not normally enter the debugger. */
1846 signal_stop
[SIGALRM
] = 0;
1847 signal_print
[SIGALRM
] = 0;
1848 #endif /* SIGALRM */
1850 signal_stop
[SIGVTALRM
] = 0;
1851 signal_print
[SIGVTALRM
] = 0;
1852 #endif /* SIGVTALRM */
1854 signal_stop
[SIGPROF
] = 0;
1855 signal_print
[SIGPROF
] = 0;
1856 #endif /* SIGPROF */
1858 signal_stop
[SIGCHLD
] = 0;
1859 signal_print
[SIGCHLD
] = 0;
1860 #endif /* SIGCHLD */
1862 signal_stop
[SIGCLD
] = 0;
1863 signal_print
[SIGCLD
] = 0;
1866 signal_stop
[SIGIO
] = 0;
1867 signal_print
[SIGIO
] = 0;
1870 signal_stop
[SIGURG
] = 0;
1871 signal_print
[SIGURG
] = 0;