1 /* Start (run) and stop the inferior process, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Notes on the algorithm used in wait_for_inferior to determine if we
21 just did a subroutine call when stepping. We have the following
22 information at that point:
24 Current and previous (just before this step) pc.
25 Current and previous sp.
26 Current and previous start of current function.
28 If the starts of the functions don't match, then
30 a) We did a subroutine call.
32 In this case, the pc will be at the beginning of a function.
34 b) We did a subroutine return.
40 If we did a longjump, we were doing "nexti", since a next would
41 have attempted to skip over the assembly language routine in which
42 the longjmp is coded and would have simply been the equivalent of a
43 continue. I consider this ok behaivior. We'd like one of two
44 things to happen if we are doing a nexti through the longjmp()
45 routine: 1) It behaves as a stepi, or 2) It acts like a continue as
46 above. Given that this is a special case, and that anybody who
47 thinks that the concept of sub calls is meaningful in the context
48 of a longjmp, I'll take either one. Let's see what happens.
50 Acts like a subroutine return. I can handle that with no problem
53 -->So: If the current and previous beginnings of the current
54 function don't match, *and* the pc is at the start of a function,
55 we've done a subroutine call. If the pc is not at the start of a
56 function, we *didn't* do a subroutine call.
58 -->If the beginnings of the current and previous function do match,
61 a) We just did a recursive call.
63 In this case, we would be at the very beginning of a
64 function and 1) it will have a prologue (don't jump to
65 before prologue, or 2) (we assume here that it doesn't have
66 a prologue) there will have been a change in the stack
67 pointer over the last instruction. (Ie. it's got to put
68 the saved pc somewhere. The stack is the usual place. In
69 a recursive call a register is only an option if there's a
70 prologue to do something with it. This is even true on
71 register window machines; the prologue sets up the new
72 window. It might not be true on a register window machine
73 where the call instruction moved the register window
74 itself. Hmmm. One would hope that the stack pointer would
75 also change. If it doesn't, somebody send me a note, and
76 I'll work out a more general theory.
77 bug-gdb@prep.ai.mit.edu). This is true (albeit slipperly
78 so) on all machines I'm aware of:
80 m68k: Call changes stack pointer. Regular jumps don't.
82 sparc: Recursive calls must have frames and therefor,
85 vax: All calls have frames and hence change the
88 b) We did a return from a recursive call. I don't see that we
89 have either the ability or the need to distinguish this
90 from an ordinary jump. The stack frame will be printed
91 when and if the frame pointer changes; if we are in a
92 function without a frame pointer, it's the users own
95 c) We did a jump within a function. We assume that this is
96 true if we didn't do a recursive call.
98 d) We are in no-man's land ("I see no symbols here"). We
99 don't worry about this; it will make calls look like simple
100 jumps (and the stack frames will be printed when the frame
101 pointer moves), which is a reasonably non-violent response.
108 #include "inferior.h"
109 #include "breakpoint.h"
113 #include "terminal.h" /* For #ifdef TIOCGPGRP and new_tty */
118 /* unistd.h is needed to #define X_OK */
122 #include <sys/file.h>
125 #ifdef SET_STACK_LIMIT_HUGE
126 #include <sys/time.h>
127 #include <sys/resource.h>
129 extern int original_stack_limit
;
130 #endif /* SET_STACK_LIMIT_HUGE */
132 /* Prototypes for local functions */
135 signals_info
PARAMS ((char *, int));
138 handle_command
PARAMS ((char *, int));
141 sig_print_info
PARAMS ((int));
144 sig_print_header
PARAMS ((void));
147 remove_step_breakpoint
PARAMS ((void));
150 insert_step_breakpoint
PARAMS ((void));
153 resume
PARAMS ((int, int));
156 resume_cleanups
PARAMS ((int));
158 extern char **environ
;
160 extern struct target_ops child_ops
; /* In inftarg.c */
162 /* Sigtramp is a routine that the kernel calls (which then calls the
163 signal handler). On most machines it is a library routine that
164 is linked into the executable.
166 This macro, given a program counter value and the name of the
167 function in which that PC resides (which can be null if the
168 name is not known), returns nonzero if the PC and name show
169 that we are in sigtramp.
171 On most machines just see if the name is sigtramp (and if we have
172 no name, assume we are not in sigtramp). */
173 #if !defined (IN_SIGTRAMP)
174 #define IN_SIGTRAMP(pc, name) \
175 (name && !strcmp ("_sigtramp", name))
178 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
179 program. It needs to examine the jmp_buf argument and extract the PC
180 from it. The return value is non-zero on success, zero otherwise. */
181 #ifndef GET_LONGJMP_TARGET
182 #define GET_LONGJMP_TARGET(PC_ADDR) 0
186 /* Some machines have trampoline code that sits between function callers
187 and the actual functions themselves. If this machine doesn't have
188 such things, disable their processing. */
189 #ifndef SKIP_TRAMPOLINE_CODE
190 #define SKIP_TRAMPOLINE_CODE(pc) 0
193 /* For SVR4 shared libraries, each call goes through a small piece of
194 trampoline code in the ".init" section. IN_SOLIB_TRAMPOLINE evaluates
195 to nonzero if we are current stopped in one of these. */
196 #ifndef IN_SOLIB_TRAMPOLINE
197 #define IN_SOLIB_TRAMPOLINE(pc,name) 0
200 /* Notify other parts of gdb that might care that signal handling may
201 have changed for one or more signals. */
202 #ifndef NOTICE_SIGNAL_HANDLING_CHANGE
203 #define NOTICE_SIGNAL_HANDLING_CHANGE /* No actions */
208 int safe_to_init_tdesc_context
= 0;
209 extern dc_dcontext_t current_context
;
212 /* Tables of how to react to signals; the user sets them. */
214 static char *signal_stop
;
215 static char *signal_print
;
216 static char *signal_program
;
218 /* Nonzero if breakpoints are now inserted in the inferior. */
219 /* Nonstatic for initialization during xxx_create_inferior. FIXME. */
221 /*static*/ int breakpoints_inserted
;
223 /* Function inferior was in as of last step command. */
225 static struct symbol
*step_start_function
;
227 /* Nonzero => address for special breakpoint for resuming stepping. */
229 static CORE_ADDR step_resume_break_address
;
231 /* Pointer to orig contents of the byte where the special breakpoint is. */
233 static char step_resume_break_shadow
[BREAKPOINT_MAX
];
235 /* Nonzero means the special breakpoint is a duplicate
236 so it has not itself been inserted. */
238 static int step_resume_break_duplicate
;
240 /* Nonzero if we are expecting a trace trap and should proceed from it. */
242 static int trap_expected
;
244 /* Nonzero if the next time we try to continue the inferior, it will
245 step one instruction and generate a spurious trace trap.
246 This is used to compensate for a bug in HP-UX. */
248 static int trap_expected_after_continue
;
250 /* Nonzero means expecting a trace trap
251 and should stop the inferior and return silently when it happens. */
255 /* Nonzero means expecting a trap and caller will handle it themselves.
256 It is used after attach, due to attaching to a process;
257 when running in the shell before the child program has been exec'd;
258 and when running some kinds of remote stuff (FIXME?). */
260 int stop_soon_quietly
;
262 /* Nonzero if pc has been changed by the debugger
263 since the inferior stopped. */
267 /* Nonzero if proceed is being used for a "finish" command or a similar
268 situation when stop_registers should be saved. */
270 int proceed_to_finish
;
272 /* Save register contents here when about to pop a stack dummy frame,
273 if-and-only-if proceed_to_finish is set.
274 Thus this contains the return value from the called function (assuming
275 values are returned in a register). */
277 char stop_registers
[REGISTER_BYTES
];
279 /* Nonzero if program stopped due to error trying to insert breakpoints. */
281 static int breakpoints_failed
;
283 /* Nonzero after stop if current stack frame should be printed. */
285 static int stop_print_frame
;
287 #ifdef NO_SINGLE_STEP
288 extern int one_stepped
; /* From machine dependent code */
289 extern void single_step (); /* Same. */
290 #endif /* NO_SINGLE_STEP */
293 /* Things to clean up if we QUIT out of resume (). */
296 resume_cleanups (arg
)
302 /* Resume the inferior, but allow a QUIT. This is useful if the user
303 wants to interrupt some lengthy single-stepping operation
304 (for child processes, the SIGINT goes to the inferior, and so
305 we get a SIGINT random_signal, but for remote debugging and perhaps
306 other targets, that's not true).
308 STEP nonzero if we should step (zero to continue instead).
309 SIG is the signal to give the inferior (zero for none). */
315 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
318 #ifdef NO_SINGLE_STEP
320 single_step(sig
); /* Do it the hard way, w/temp breakpoints */
321 step
= 0; /* ...and don't ask hardware to do it. */
325 /* Handle any optimized stores to the inferior NOW... */
326 #ifdef DO_DEFERRED_STORES
330 target_resume (step
, sig
);
331 discard_cleanups (old_cleanups
);
335 /* Clear out all variables saying what to do when inferior is continued.
336 First do this, then set the ones you want, then call `proceed'. */
339 clear_proceed_status ()
342 step_range_start
= 0;
344 step_frame_address
= 0;
345 step_over_calls
= -1;
346 step_resume_break_address
= 0;
348 stop_soon_quietly
= 0;
349 proceed_to_finish
= 0;
350 breakpoint_proceeded
= 1; /* We're about to proceed... */
352 /* Discard any remaining commands or status from previous stop. */
353 bpstat_clear (&stop_bpstat
);
356 /* Basic routine for continuing the program in various fashions.
358 ADDR is the address to resume at, or -1 for resume where stopped.
359 SIGGNAL is the signal to give it, or 0 for none,
360 or -1 for act according to how it stopped.
361 STEP is nonzero if should trap after one instruction.
362 -1 means return after that and print nothing.
363 You should probably set various step_... variables
364 before calling here, if you are stepping.
366 You should call clear_proceed_status before calling proceed. */
369 proceed (addr
, siggnal
, step
)
377 step_start_function
= find_pc_function (read_pc ());
381 if (addr
== (CORE_ADDR
)-1)
383 /* If there is a breakpoint at the address we will resume at,
384 step one instruction before inserting breakpoints
385 so that we do not stop right away. */
387 if (!pc_changed
&& breakpoint_here_p (read_pc ()))
392 write_register (PC_REGNUM
, addr
);
394 write_register (NPC_REGNUM
, addr
+ 4);
396 write_register (NNPC_REGNUM
, addr
+ 8);
401 if (trap_expected_after_continue
)
403 /* If (step == 0), a trap will be automatically generated after
404 the first instruction is executed. Force step one
405 instruction to clear this condition. This should not occur
406 if step is nonzero, but it is harmless in that case. */
408 trap_expected_after_continue
= 0;
412 /* We will get a trace trap after one instruction.
413 Continue it automatically and insert breakpoints then. */
417 int temp
= insert_breakpoints ();
420 print_sys_errmsg ("ptrace", temp
);
421 error ("Cannot insert breakpoints.\n\
422 The same program may be running in another process.");
424 breakpoints_inserted
= 1;
427 /* Install inferior's terminal modes. */
428 target_terminal_inferior ();
431 stop_signal
= siggnal
;
432 /* If this signal should not be seen by program,
433 give it zero. Used for debugging signals. */
434 else if (stop_signal
< NSIG
&& !signal_program
[stop_signal
])
437 /* Resume inferior. */
438 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
440 /* Wait for it to stop (if not standalone)
441 and in any case decode why it stopped, and act accordingly. */
443 wait_for_inferior ();
447 /* Record the pc and sp of the program the last time it stopped.
448 These are just used internally by wait_for_inferior, but need
449 to be preserved over calls to it and cleared when the inferior
451 static CORE_ADDR prev_pc
;
452 static CORE_ADDR prev_sp
;
453 static CORE_ADDR prev_func_start
;
454 static char *prev_func_name
;
457 /* Start an inferior Unix child process and sets inferior_pid to its pid.
458 EXEC_FILE is the file to run.
459 ALLARGS is a string containing the arguments to the program.
460 ENV is the environment vector to pass. Errors reported with error(). */
463 #define SHELL_FILE "/bin/sh"
467 child_create_inferior (exec_file
, allargs
, env
)
475 static char default_shell_file
[] = SHELL_FILE
;
478 /* Set debug_fork then attach to the child while it sleeps, to debug. */
479 static int debug_fork
= 0;
480 /* This is set to the result of setpgrp, which if vforked, will be visible
481 to you in the parent process. It's only used by humans for debugging. */
482 static int debug_setpgrp
= 657473;
485 /* The user might want tilde-expansion, and in general probably wants
486 the program to behave the same way as if run from
487 his/her favorite shell. So we let the shell run it for us.
488 FIXME, this should probably search the local environment (as
489 modified by the setenv command), not the env gdb inherited. */
490 shell_file
= getenv ("SHELL");
491 if (shell_file
== NULL
)
492 shell_file
= default_shell_file
;
494 len
= 5 + strlen (exec_file
) + 1 + strlen (allargs
) + 1 + /*slop*/ 10;
495 /* If desired, concat something onto the front of ALLARGS.
496 SHELL_COMMAND is the result. */
497 #ifdef SHELL_COMMAND_CONCAT
498 shell_command
= (char *) alloca (strlen (SHELL_COMMAND_CONCAT
) + len
);
499 strcpy (shell_command
, SHELL_COMMAND_CONCAT
);
501 shell_command
= (char *) alloca (len
);
502 shell_command
[0] = '\0';
504 strcat (shell_command
, "exec ");
505 strcat (shell_command
, exec_file
);
506 strcat (shell_command
, " ");
507 strcat (shell_command
, allargs
);
509 /* exec is said to fail if the executable is open. */
512 /* Retain a copy of our environment variables, since the child will
513 replace the value of environ and if we're vforked, we have to
515 save_our_env
= environ
;
517 /* Tell the terminal handling subsystem what tty we plan to run on;
518 it will just record the information for later. */
520 new_tty_prefork (inferior_io_terminal
);
522 /* It is generally good practice to flush any possible pending stdio
523 output prior to doing a fork, to avoid the possibility of both the
524 parent and child flushing the same data after the fork. */
529 #if defined(USG) && !defined(HAVE_VFORK)
539 perror_with_name ("vfork");
547 /* Run inferior in a separate process group. */
548 #ifdef NEED_POSIX_SETPGID
549 debug_setpgrp
= setpgid (0, 0);
551 #if defined(USG) && !defined(SETPGRP_ARGS)
552 debug_setpgrp
= setpgrp ();
554 debug_setpgrp
= setpgrp (getpid (), getpid ());
556 #endif /* NEED_POSIX_SETPGID */
557 if (debug_setpgrp
== -1)
558 perror("setpgrp failed in child");
559 #endif /* TIOCGPGRP */
561 #ifdef SET_STACK_LIMIT_HUGE
562 /* Reset the stack limit back to what it was. */
566 getrlimit (RLIMIT_STACK
, &rlim
);
567 rlim
.rlim_cur
= original_stack_limit
;
568 setrlimit (RLIMIT_STACK
, &rlim
);
570 #endif /* SET_STACK_LIMIT_HUGE */
572 /* Ask the tty subsystem to switch to the one we specified earlier
573 (or to share the current terminal, if none was specified). */
577 /* Changing the signal handlers for the inferior after
578 a vfork can also change them for the superior, so we don't mess
579 with signals here. See comments in
580 initialize_signals for how we get the right signal handlers
584 proc_set_exec_trap (); /* Use SVR4 /proc interface */
586 call_ptrace (0, 0, 0, 0); /* "Trace me, Dr. Memory!" */
589 /* There is no execlpe call, so we have to set the environment
590 for our child in the global variable. If we've vforked, this
591 clobbers the parent, but environ is restored a few lines down
592 in the parent. By the way, yes we do need to look down the
593 path to find $SHELL. Rich Pixley says so, and I agree. */
595 execlp (shell_file
, shell_file
, "-c", shell_command
, (char *)0);
597 fprintf (stderr
, "Cannot exec %s: %s.\n", shell_file
,
598 safe_strerror (errno
));
603 /* Restore our environment in case a vforked child clob'd it. */
604 environ
= save_our_env
;
606 /* Now that we have a child process, make it our target. */
607 push_target (&child_ops
);
609 #ifdef CREATE_INFERIOR_HOOK
610 CREATE_INFERIOR_HOOK (pid
);
613 /* The process was started by the fork that created it,
614 but it will have stopped one instruction after execing the shell.
615 Here we must get it up to actual execution of the real program. */
617 inferior_pid
= pid
; /* Needed for wait_for_inferior stuff below */
619 clear_proceed_status ();
621 /* We will get a trace trap after one instruction.
622 Continue it automatically. Eventually (after shell does an exec)
623 it will get another trace trap. Then insert breakpoints and continue. */
625 #ifdef START_INFERIOR_TRAPS_EXPECTED
626 pending_execs
= START_INFERIOR_TRAPS_EXPECTED
;
631 init_wait_for_inferior ();
633 /* Set up the "saved terminal modes" of the inferior
634 based on what modes we are starting it with. */
635 target_terminal_init ();
637 /* Install inferior's terminal modes. */
638 target_terminal_inferior ();
642 stop_soon_quietly
= 1; /* Make wait_for_inferior be quiet */
643 wait_for_inferior ();
644 if (stop_signal
!= SIGTRAP
)
646 /* Let shell child handle its own signals in its own way */
647 /* FIXME, what if child has exit()ed? Must exit loop somehow */
648 resume (0, stop_signal
);
652 /* We handle SIGTRAP, however; it means child did an exec. */
653 if (0 == --pending_execs
)
655 resume (0, 0); /* Just make it go on */
658 stop_soon_quietly
= 0;
660 /* We are now in the child process of interest, having exec'd the
661 correct program, and are poised at the first instruction of the
663 #ifdef SOLIB_CREATE_INFERIOR_HOOK
664 SOLIB_CREATE_INFERIOR_HOOK (pid
);
667 /* Should this perhaps just be a "proceed" call? FIXME */
668 insert_step_breakpoint ();
669 breakpoints_failed
= insert_breakpoints ();
670 if (!breakpoints_failed
)
672 breakpoints_inserted
= 1;
673 target_terminal_inferior();
674 /* Start the child program going on its first instruction, single-
675 stepping if we need to. */
676 resume (bpstat_should_step (), 0);
677 wait_for_inferior ();
682 /* Start remote-debugging of a machine over a serial link. */
687 init_wait_for_inferior ();
688 clear_proceed_status ();
689 stop_soon_quietly
= 1;
691 wait_for_inferior ();
695 /* Initialize static vars when a new inferior begins. */
698 init_wait_for_inferior ()
700 /* These are meaningless until the first time through wait_for_inferior. */
704 prev_func_name
= NULL
;
706 trap_expected_after_continue
= 0;
707 breakpoints_inserted
= 0;
708 mark_breakpoints_out ();
709 stop_signal
= 0; /* Don't confuse first call to proceed(). */
713 /* Attach to process PID, then initialize for debugging it
714 and wait for the trace-trap that results from attaching. */
717 child_attach (args
, from_tty
)
727 error_no_arg ("process-id to attach");
729 #ifndef ATTACH_DETACH
730 error ("Can't attach to a process on this machine.");
734 if (pid
== getpid()) /* Trying to masturbate? */
735 error ("I refuse to debug myself!");
737 if (target_has_execution
)
739 if (query ("A program is being debugged already. Kill it? "))
742 error ("Inferior not killed.");
745 exec_file
= (char *) get_exec_file (1);
749 printf ("Attaching program: %s pid %d\n",
756 push_target (&child_ops
);
758 mark_breakpoints_out ();
759 target_terminal_init ();
760 clear_proceed_status ();
761 stop_soon_quietly
= 1;
762 /*proceed (-1, 0, -2);*/
763 target_terminal_inferior ();
764 wait_for_inferior ();
766 SOLIB_ADD ((char *)0, from_tty
, (struct target_ops
*)0);
769 #endif /* ATTACH_DETACH */
772 /* Wait for control to return from inferior to debugger.
773 If inferior gets a signal, we may decide to start it up again
774 instead of returning. That is why there is a loop in this function.
775 When this function actually returns it means the inferior
776 should be left stopped and GDB should read more commands. */
785 CORE_ADDR stop_func_start
;
786 char *stop_func_name
;
787 CORE_ADDR prologue_pc
, tmp
;
788 int stop_step_resume_break
;
789 struct symtab_and_line sal
;
790 int remove_breakpoints_on_following_step
= 0;
792 int handling_longjmp
= 0; /* FIXME */
794 sal
= find_pc_line(prev_pc
, 0);
795 current_line
= sal
.line
;
799 /* Clean up saved state that will become invalid. */
801 flush_cached_frames ();
802 registers_changed ();
806 #ifdef SIGTRAP_STOP_AFTER_LOAD
808 /* Somebody called load(2), and it gave us a "trap signal after load".
809 Ignore it gracefully. */
811 SIGTRAP_STOP_AFTER_LOAD (w
);
814 /* See if the process still exists; clean up if it doesn't. */
817 target_terminal_ours (); /* Must do this before mourn anyway */
819 printf_filtered ("\nProgram exited with code 0%o.\n",
820 (unsigned int)WEXITSTATUS (w
));
823 printf_filtered ("\nProgram exited normally.\n");
825 target_mourn_inferior ();
826 #ifdef NO_SINGLE_STEP
829 stop_print_frame
= 0;
832 else if (!WIFSTOPPED (w
))
834 stop_print_frame
= 0;
835 stop_signal
= WTERMSIG (w
);
836 target_terminal_ours (); /* Must do this before mourn anyway */
837 target_kill (); /* kill mourns as well */
838 #ifdef PRINT_RANDOM_SIGNAL
839 printf_filtered ("\nProgram terminated: ");
840 PRINT_RANDOM_SIGNAL (stop_signal
);
842 printf_filtered ("\nProgram terminated with signal %d, %s\n",
843 stop_signal
, safe_strsignal (stop_signal
));
845 printf_filtered ("The inferior process no longer exists.\n");
847 #ifdef NO_SINGLE_STEP
853 #ifdef NO_SINGLE_STEP
855 single_step (0); /* This actually cleans up the ss */
856 #endif /* NO_SINGLE_STEP */
858 stop_pc
= read_pc ();
859 set_current_frame ( create_new_frame (read_register (FP_REGNUM
),
862 stop_frame_address
= FRAME_FP (get_current_frame ());
863 stop_sp
= read_register (SP_REGNUM
);
866 /* Don't care about return value; stop_func_start and stop_func_name
867 will both be 0 if it doesn't work. */
868 (void) find_pc_partial_function (stop_pc
, &stop_func_name
,
870 stop_func_start
+= FUNCTION_START_OFFSET
;
872 bpstat_clear (&stop_bpstat
);
874 stop_stack_dummy
= 0;
875 stop_print_frame
= 1;
876 stop_step_resume_break
= 0;
878 stopped_by_random_signal
= 0;
879 breakpoints_failed
= 0;
881 /* Look at the cause of the stop, and decide what to do.
882 The alternatives are:
883 1) break; to really stop and return to the debugger,
884 2) drop through to start up again
885 (set another_trap to 1 to single step once)
886 3) set random_signal to 1, and the decision between 1 and 2
887 will be made according to the signal handling tables. */
889 stop_signal
= WSTOPSIG (w
);
891 /* First, distinguish signals caused by the debugger from signals
892 that have to do with the program's own actions.
893 Note that breakpoint insns may cause SIGTRAP or SIGILL
894 or SIGEMT, depending on the operating system version.
895 Here we detect when a SIGILL or SIGEMT is really a breakpoint
896 and change it to SIGTRAP. */
898 if (stop_signal
== SIGTRAP
899 || (breakpoints_inserted
&&
900 (stop_signal
== SIGILL
902 || stop_signal
== SIGEMT
905 || stop_soon_quietly
)
907 if (stop_signal
== SIGTRAP
&& stop_after_trap
)
909 stop_print_frame
= 0;
912 if (stop_soon_quietly
)
915 /* Don't even think about breakpoints
916 if just proceeded over a breakpoint.
918 However, if we are trying to proceed over a breakpoint
919 and end up in sigtramp, then step_resume_break_address
920 will be set and we should check whether we've hit the
922 if (stop_signal
== SIGTRAP
&& trap_expected
923 && step_resume_break_address
== 0)
924 bpstat_clear (&stop_bpstat
);
927 /* See if there is a breakpoint at the current PC. */
928 #if DECR_PC_AFTER_BREAK
929 /* Notice the case of stepping through a jump
930 that lands just after a breakpoint.
931 Don't confuse that with hitting the breakpoint.
932 What we check for is that 1) stepping is going on
933 and 2) the pc before the last insn does not match
934 the address of the breakpoint before the current pc. */
935 if (prev_pc
== stop_pc
- DECR_PC_AFTER_BREAK
937 || step_resume_break_address
938 || handling_longjmp
/* FIXME */)
939 #endif /* DECR_PC_AFTER_BREAK not zero */
941 /* See if we stopped at the special breakpoint for
942 stepping over a subroutine call. If both are zero,
943 this wasn't the reason for the stop. */
944 if (step_resume_break_address
945 && stop_pc
- DECR_PC_AFTER_BREAK
946 == step_resume_break_address
)
948 stop_step_resume_break
= 1;
949 if (DECR_PC_AFTER_BREAK
)
951 stop_pc
-= DECR_PC_AFTER_BREAK
;
952 write_register (PC_REGNUM
, stop_pc
);
959 bpstat_stop_status (&stop_pc
, stop_frame_address
);
960 /* Following in case break condition called a
962 stop_print_frame
= 1;
967 if (stop_signal
== SIGTRAP
)
969 = !(bpstat_explains_signal (stop_bpstat
)
971 || stop_step_resume_break
972 || PC_IN_CALL_DUMMY (stop_pc
, stop_sp
, stop_frame_address
)
973 || (step_range_end
&& !step_resume_break_address
));
977 = !(bpstat_explains_signal (stop_bpstat
)
978 || stop_step_resume_break
979 /* End of a stack dummy. Some systems (e.g. Sony
980 news) give another signal besides SIGTRAP,
981 so check here as well as above. */
982 || PC_IN_CALL_DUMMY (stop_pc
, stop_sp
, stop_frame_address
)
985 stop_signal
= SIGTRAP
;
991 /* For the program's own signals, act according to
992 the signal handling tables. */
996 /* Signal not for debugging purposes. */
999 stopped_by_random_signal
= 1;
1001 if (stop_signal
>= NSIG
1002 || signal_print
[stop_signal
])
1005 target_terminal_ours_for_output ();
1006 #ifdef PRINT_RANDOM_SIGNAL
1007 PRINT_RANDOM_SIGNAL (stop_signal
);
1009 printf_filtered ("\nProgram received signal %d, %s\n",
1010 stop_signal
, safe_strsignal (stop_signal
));
1011 #endif /* PRINT_RANDOM_SIGNAL */
1014 if (stop_signal
>= NSIG
1015 || signal_stop
[stop_signal
])
1017 /* If not going to stop, give terminal back
1018 if we took it away. */
1020 target_terminal_inferior ();
1022 /* Note that virtually all the code below does `if !random_signal'.
1023 Perhaps this code should end with a goto or continue. At least
1024 one (now fixed) bug was caused by this -- a !random_signal was
1025 missing in one of the tests below. */
1028 /* Handle cases caused by hitting a breakpoint. */
1031 if (bpstat_explains_signal (stop_bpstat
))
1033 CORE_ADDR jmp_buf_pc
;
1035 switch (stop_bpstat
->breakpoint_at
->type
) /* FIXME */
1037 /* If we hit the breakpoint at longjmp, disable it for the
1038 duration of this command. Then, install a temporary
1039 breakpoint at the target of the jmp_buf. */
1041 disable_longjmp_breakpoint();
1042 remove_breakpoints ();
1043 breakpoints_inserted
= 0;
1044 if (!GET_LONGJMP_TARGET(&jmp_buf_pc
)) goto keep_going
;
1046 /* Need to blow away step-resume breakpoint, as it
1047 interferes with us */
1048 remove_step_breakpoint ();
1049 step_resume_break_address
= 0;
1050 stop_step_resume_break
= 0;
1052 #if 0 /* FIXME - Need to implement nested temporary breakpoints */
1053 if (step_over_calls
> 0)
1054 set_longjmp_resume_breakpoint(jmp_buf_pc
,
1055 get_current_frame());
1058 set_longjmp_resume_breakpoint(jmp_buf_pc
, NULL
);
1059 handling_longjmp
= 1; /* FIXME */
1062 case bp_longjmp_resume
:
1063 remove_breakpoints ();
1064 breakpoints_inserted
= 0;
1065 #if 0 /* FIXME - Need to implement nested temporary breakpoints */
1067 && (stop_frame_address
1068 INNER_THAN step_frame_address
))
1074 disable_longjmp_breakpoint();
1075 handling_longjmp
= 0; /* FIXME */
1079 fprintf(stderr
, "Unknown breakpoint type %d\n",
1080 stop_bpstat
->breakpoint_at
->type
);
1085 /* Does a breakpoint want us to stop? */
1086 if (bpstat_stop (stop_bpstat
))
1088 stop_print_frame
= bpstat_should_print (stop_bpstat
);
1091 /* Otherwise, must remove breakpoints and single-step
1092 to get us past the one we hit. */
1095 remove_breakpoints ();
1096 remove_step_breakpoint ();
1097 breakpoints_inserted
= 0;
1103 else if (stop_step_resume_break
)
1105 /* But if we have hit the step-resumption breakpoint,
1106 remove it. It has done its job getting us here.
1107 The sp test is to make sure that we don't get hung
1108 up in recursive calls in functions without frame
1109 pointers. If the stack pointer isn't outside of
1110 where the breakpoint was set (within a routine to be
1111 stepped over), we're in the middle of a recursive
1112 call. Not true for reg window machines (sparc)
1113 because the must change frames to call things and
1114 the stack pointer doesn't have to change if it
1115 the bp was set in a routine without a frame (pc can
1116 be stored in some other window).
1118 The removal of the sp test is to allow calls to
1119 alloca. Nasty things were happening. Oh, well,
1120 gdb can only handle one level deep of lack of
1124 Disable test for step_frame_address match so that we always stop even if the
1125 frames don't match. Reason: if we hit the step_resume_breakpoint, there is
1126 no way to temporarily disable it so that we can step past it. If we leave
1127 the breakpoint in, then we loop forever repeatedly hitting, but never
1128 getting past the breakpoint. This change keeps nexting over recursive
1129 function calls from hanging gdb.
1132 if (* step_frame_address
== 0
1133 || (step_frame_address
== stop_frame_address
))
1136 remove_step_breakpoint ();
1137 step_resume_break_address
= 0;
1139 /* If were waiting for a trap, hitting the step_resume_break
1140 doesn't count as getting it. */
1146 /* We come here if we hit a breakpoint but should not
1147 stop for it. Possibly we also were stepping
1148 and should stop for that. So fall through and
1149 test for stepping. But, if not stepping,
1152 /* If this is the breakpoint at the end of a stack dummy,
1153 just stop silently. */
1155 && PC_IN_CALL_DUMMY (stop_pc
, stop_sp
, stop_frame_address
))
1157 stop_print_frame
= 0;
1158 stop_stack_dummy
= 1;
1160 trap_expected_after_continue
= 1;
1165 if (step_resume_break_address
)
1166 /* Having a step-resume breakpoint overrides anything
1167 else having to do with stepping commands until
1168 that breakpoint is reached. */
1170 /* If stepping through a line, keep going if still within it. */
1171 else if (!random_signal
1173 && stop_pc
>= step_range_start
1174 && stop_pc
< step_range_end
1175 /* The step range might include the start of the
1176 function, so if we are at the start of the
1177 step range and either the stack or frame pointers
1178 just changed, we've stepped outside */
1179 && !(stop_pc
== step_range_start
1180 && stop_frame_address
1181 && (stop_sp INNER_THAN prev_sp
1182 || stop_frame_address
!= step_frame_address
)))
1187 /* We stepped out of the stepping range. See if that was due
1188 to a subroutine call that we should proceed to the end of. */
1189 else if (!random_signal
&& step_range_end
)
1191 if (stop_func_start
)
1193 prologue_pc
= stop_func_start
;
1194 SKIP_PROLOGUE (prologue_pc
);
1197 /* Did we just take a signal? */
1198 if (IN_SIGTRAMP (stop_pc
, stop_func_name
)
1199 && !IN_SIGTRAMP (prev_pc
, prev_func_name
))
1201 /* This code is needed at least in the following case:
1202 The user types "next" and then a signal arrives (before
1203 the "next" is done). */
1204 /* We've just taken a signal; go until we are back to
1205 the point where we took it and one more. */
1206 step_resume_break_address
= prev_pc
;
1207 step_resume_break_duplicate
=
1208 breakpoint_here_p (step_resume_break_address
);
1209 if (breakpoints_inserted
)
1210 insert_step_breakpoint ();
1211 /* Make sure that the stepping range gets us past
1212 that instruction. */
1213 if (step_range_end
== 1)
1214 step_range_end
= (step_range_start
= prev_pc
) + 1;
1215 remove_breakpoints_on_following_step
= 1;
1219 /* ==> See comments at top of file on this algorithm. <==*/
1221 if ((stop_pc
== stop_func_start
1222 || IN_SOLIB_TRAMPOLINE (stop_pc
, stop_func_name
))
1223 && (stop_func_start
!= prev_func_start
1224 || prologue_pc
!= stop_func_start
1225 || stop_sp
!= prev_sp
))
1227 /* It's a subroutine call.
1228 (0) If we are not stepping over any calls ("stepi"), we
1230 (1) If we're doing a "next", we want to continue through
1231 the call ("step over the call").
1232 (2) If we are in a function-call trampoline (a stub between
1233 the calling routine and the real function), locate
1234 the real function and change stop_func_start.
1235 (3) If we're doing a "step", and there are no debug symbols
1236 at the target of the call, we want to continue through
1237 it ("step over the call").
1238 (4) Otherwise, we want to stop soon, after the function
1239 prologue ("step into the call"). */
1241 if (step_over_calls
== 0)
1243 /* I presume that step_over_calls is only 0 when we're
1244 supposed to be stepping at the assembly language level. */
1249 if (step_over_calls
> 0)
1250 goto step_over_function
;
1252 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
1254 stop_func_start
= tmp
;
1256 if (find_pc_function (stop_func_start
) != 0)
1257 goto step_into_function
;
1260 /* A subroutine call has happened. */
1261 /* Set a special breakpoint after the return */
1262 step_resume_break_address
=
1264 (SAVED_PC_AFTER_CALL (get_current_frame ()));
1265 step_resume_break_duplicate
1266 = breakpoint_here_p (step_resume_break_address
);
1267 if (breakpoints_inserted
)
1268 insert_step_breakpoint ();
1272 /* Subroutine call with source code we should not step over.
1273 Do step to the first line of code in it. */
1274 SKIP_PROLOGUE (stop_func_start
);
1275 sal
= find_pc_line (stop_func_start
, 0);
1276 /* Use the step_resume_break to step until
1277 the end of the prologue, even if that involves jumps
1278 (as it seems to on the vax under 4.2). */
1279 /* If the prologue ends in the middle of a source line,
1280 continue to the end of that source line.
1281 Otherwise, just go to end of prologue. */
1282 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1283 /* no, don't either. It skips any code that's
1284 legitimately on the first line. */
1286 if (sal
.end
&& sal
.pc
!= stop_func_start
)
1287 stop_func_start
= sal
.end
;
1290 if (stop_func_start
== stop_pc
)
1292 /* We are already there: stop now. */
1297 /* Put the step-breakpoint there and go until there. */
1299 step_resume_break_address
= stop_func_start
;
1301 step_resume_break_duplicate
1302 = breakpoint_here_p (step_resume_break_address
);
1303 if (breakpoints_inserted
)
1304 insert_step_breakpoint ();
1305 /* Do not specify what the fp should be when we stop
1306 since on some machines the prologue
1307 is where the new fp value is established. */
1308 step_frame_address
= 0;
1309 /* And make sure stepping stops right away then. */
1310 step_range_end
= step_range_start
;
1315 /* We've wandered out of the step range (but haven't done a
1316 subroutine call or return). */
1318 sal
= find_pc_line(stop_pc
, 0);
1320 if (step_range_end
== 1 || /* stepi or nexti */
1321 sal
.line
== 0 || /* ...or no line # info */
1322 (stop_pc
== sal
.pc
/* ...or we're at the start */
1323 && current_line
!= sal
.line
)) { /* of a different line */
1324 /* Stop because we're done stepping. */
1328 /* We aren't done stepping, and we have line number info for $pc.
1329 Optimize by setting the step_range for the line.
1330 (We might not be in the original line, but if we entered a
1331 new line in mid-statement, we continue stepping. This makes
1332 things like for(;;) statements work better.) */
1333 step_range_start
= sal
.pc
;
1334 step_range_end
= sal
.end
;
1337 /* We never fall through here */
1341 && IN_SIGTRAMP (stop_pc
, stop_func_name
)
1342 && !IN_SIGTRAMP (prev_pc
, prev_func_name
))
1344 /* What has happened here is that we have just stepped the inferior
1345 with a signal (because it is a signal which shouldn't make
1346 us stop), thus stepping into sigtramp.
1348 So we need to set a step_resume_break_address breakpoint
1349 and continue until we hit it, and then step. */
1350 step_resume_break_address
= prev_pc
;
1351 /* Always 1, I think, but it's probably easier to have
1352 the step_resume_break as usual rather than trying to
1353 re-use the breakpoint which is already there. */
1354 step_resume_break_duplicate
=
1355 breakpoint_here_p (step_resume_break_address
);
1356 if (breakpoints_inserted
)
1357 insert_step_breakpoint ();
1358 remove_breakpoints_on_following_step
= 1;
1362 /* My apologies to the gods of structured programming. */
1363 /* Come to this label when you need to resume the inferior. It's really much
1364 cleaner at this time to do a goto than to try and figure out what the
1365 if-else chain ought to look like!! */
1370 /* Save the pc before execution, to compare with pc after stop. */
1371 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
1372 prev_func_start
= stop_func_start
; /* Ok, since if DECR_PC_AFTER
1373 BREAK is defined, the
1374 original pc would not have
1375 been at the start of a
1377 prev_func_name
= stop_func_name
;
1380 /* If we did not do break;, it means we should keep
1381 running the inferior and not return to debugger. */
1383 if (trap_expected
&& stop_signal
!= SIGTRAP
)
1385 /* We took a signal (which we are supposed to pass through to
1386 the inferior, else we'd have done a break above) and we
1387 haven't yet gotten our trap. Simply continue. */
1388 resume ((step_range_end
&& !step_resume_break_address
)
1389 || (trap_expected
&& !step_resume_break_address
)
1390 || bpstat_should_step (),
1395 /* Either the trap was not expected, but we are continuing
1396 anyway (the user asked that this signal be passed to the
1399 The signal was SIGTRAP, e.g. it was our signal, but we
1400 decided we should resume from it.
1402 We're going to run this baby now!
1404 Insert breakpoints now, unless we are trying
1405 to one-proceed past a breakpoint. */
1406 /* If we've just finished a special step resume and we don't
1407 want to hit a breakpoint, pull em out. */
1408 if (!step_resume_break_address
&&
1409 remove_breakpoints_on_following_step
)
1411 remove_breakpoints_on_following_step
= 0;
1412 remove_breakpoints ();
1413 breakpoints_inserted
= 0;
1415 else if (!breakpoints_inserted
&&
1416 (step_resume_break_address
!= 0 || !another_trap
))
1418 insert_step_breakpoint ();
1419 breakpoints_failed
= insert_breakpoints ();
1420 if (breakpoints_failed
)
1422 breakpoints_inserted
= 1;
1425 trap_expected
= another_trap
;
1427 if (stop_signal
== SIGTRAP
)
1430 #ifdef SHIFT_INST_REGS
1431 /* I'm not sure when this following segment applies. I do know, now,
1432 that we shouldn't rewrite the regs when we were stopped by a
1433 random signal from the inferior process. */
1435 if (!bpstat_explains_signal (stop_bpstat
)
1436 && (stop_signal
!= SIGCLD
)
1437 && !stopped_by_random_signal
)
1439 CORE_ADDR pc_contents
= read_register (PC_REGNUM
);
1440 CORE_ADDR npc_contents
= read_register (NPC_REGNUM
);
1441 if (pc_contents
!= npc_contents
)
1443 write_register (NNPC_REGNUM
, npc_contents
);
1444 write_register (NPC_REGNUM
, pc_contents
);
1447 #endif /* SHIFT_INST_REGS */
1449 resume ((!step_resume_break_address
1450 && !handling_longjmp
1453 || bpstat_should_step (),
1459 if (target_has_execution
)
1461 /* Assuming the inferior still exists, set these up for next
1462 time, just like we did above if we didn't break out of the
1464 prev_pc
= read_pc ();
1465 prev_func_start
= stop_func_start
;
1466 prev_func_name
= stop_func_name
;
1471 /* Here to return control to GDB when the inferior stops for real.
1472 Print appropriate messages, remove breakpoints, give terminal our modes.
1474 STOP_PRINT_FRAME nonzero means print the executing frame
1475 (pc, function, args, file, line number and line text).
1476 BREAKPOINTS_FAILED nonzero means stop was due to error
1477 attempting to insert breakpoints. */
1482 /* Make sure that the current_frame's pc is correct. This
1483 is a correction for setting up the frame info before doing
1484 DECR_PC_AFTER_BREAK */
1485 if (target_has_execution
)
1486 (get_current_frame ())->pc
= read_pc ();
1488 if (breakpoints_failed
)
1490 target_terminal_ours_for_output ();
1491 print_sys_errmsg ("ptrace", breakpoints_failed
);
1492 printf_filtered ("Stopped; cannot insert breakpoints.\n\
1493 The same program may be running in another process.\n");
1496 if (target_has_execution
)
1497 remove_step_breakpoint ();
1499 if (target_has_execution
&& breakpoints_inserted
)
1500 if (remove_breakpoints ())
1502 target_terminal_ours_for_output ();
1503 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
1504 It might be running in another process.\n\
1505 Further execution is probably impossible.\n");
1508 breakpoints_inserted
= 0;
1510 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1511 Delete any breakpoint that is to be deleted at the next stop. */
1513 breakpoint_auto_delete (stop_bpstat
);
1515 /* If an auto-display called a function and that got a signal,
1516 delete that auto-display to avoid an infinite recursion. */
1518 if (stopped_by_random_signal
)
1519 disable_current_display ();
1521 if (step_multi
&& stop_step
)
1524 target_terminal_ours ();
1526 if (!target_has_stack
)
1529 /* Select innermost stack frame except on return from a stack dummy routine,
1530 or if the program has exited. Print it without a level number if
1531 we have changed functions or hit a breakpoint. Print source line
1533 if (!stop_stack_dummy
)
1535 select_frame (get_current_frame (), 0);
1537 if (stop_print_frame
)
1541 source_only
= bpstat_print (stop_bpstat
);
1542 source_only
= source_only
||
1544 && step_frame_address
== stop_frame_address
1545 && step_start_function
== find_pc_function (stop_pc
));
1547 print_stack_frame (selected_frame
, -1, source_only
? -1: 1);
1549 /* Display the auto-display expressions. */
1554 /* Save the function value return registers, if we care.
1555 We might be about to restore their previous contents. */
1556 if (proceed_to_finish
)
1557 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
1559 if (stop_stack_dummy
)
1561 /* Pop the empty frame that contains the stack dummy.
1562 POP_FRAME ends with a setting of the current frame, so we
1563 can use that next. */
1565 select_frame (get_current_frame (), 0);
1570 insert_step_breakpoint ()
1572 if (step_resume_break_address
&& !step_resume_break_duplicate
)
1573 target_insert_breakpoint (step_resume_break_address
,
1574 step_resume_break_shadow
);
1578 remove_step_breakpoint ()
1580 if (step_resume_break_address
&& !step_resume_break_duplicate
)
1581 target_remove_breakpoint (step_resume_break_address
,
1582 step_resume_break_shadow
);
1585 int signal_stop_state (signo
)
1588 return ((signo
>= 0 && signo
< NSIG
) ? signal_stop
[signo
] : 0);
1591 int signal_print_state (signo
)
1594 return ((signo
>= 0 && signo
< NSIG
) ? signal_print
[signo
] : 0);
1597 int signal_pass_state (signo
)
1600 return ((signo
>= 0 && signo
< NSIG
) ? signal_program
[signo
] : 0);
1606 printf_filtered ("Signal\t\tStop\tPrint\tPass to program\tDescription\n");
1610 sig_print_info (number
)
1615 if ((name
= strsigno (number
)) == NULL
)
1616 printf_filtered ("%d\t\t", number
);
1618 printf_filtered ("%s (%d)\t", name
, number
);
1619 printf_filtered ("%s\t", signal_stop
[number
] ? "Yes" : "No");
1620 printf_filtered ("%s\t", signal_print
[number
] ? "Yes" : "No");
1621 printf_filtered ("%s\t\t", signal_program
[number
] ? "Yes" : "No");
1622 printf_filtered ("%s\n", safe_strsignal (number
));
1625 /* Specify how various signals in the inferior should be handled. */
1628 handle_command (args
, from_tty
)
1632 register char *p
= args
;
1634 register int digits
, wordlen
;
1638 error_no_arg ("signal to handle");
1642 /* Find the end of the next word in the args. */
1644 p
[wordlen
] && p
[wordlen
] != ' ' && p
[wordlen
] != '\t';
1646 /* Set nextarg to the start of the word after the one we just
1647 found, and null-terminate this one. */
1648 if (p
[wordlen
] == '\0')
1649 nextarg
= p
+ wordlen
;
1653 nextarg
= p
+ wordlen
+ 1;
1657 for (digits
= 0; p
[digits
] >= '0' && p
[digits
] <= '9'; digits
++);
1661 /* It is the first argument--must be the signal to operate on. */
1662 if (digits
== wordlen
)
1666 if (signum
<= 0 || signum
> signo_max ())
1669 error ("Invalid signal %s given as argument to \"handle\".", p
);
1675 signum
= strtosigno (p
);
1677 error ("No such signal \"%s\"", p
);
1680 if (signum
== SIGTRAP
|| signum
== SIGINT
)
1682 if (!query ("%s is used by the debugger.\nAre you sure you want to change it? ", strsigno (signum
)))
1683 error ("Not confirmed.");
1686 /* Else, if already got a signal number, look for flag words
1687 saying what to do for it. */
1688 else if (!strncmp (p
, "stop", wordlen
))
1690 signal_stop
[signum
] = 1;
1691 signal_print
[signum
] = 1;
1693 else if (wordlen
>= 2 && !strncmp (p
, "print", wordlen
))
1694 signal_print
[signum
] = 1;
1695 else if (wordlen
>= 2 && !strncmp (p
, "pass", wordlen
))
1696 signal_program
[signum
] = 1;
1697 else if (!strncmp (p
, "ignore", wordlen
))
1698 signal_program
[signum
] = 0;
1699 else if (wordlen
>= 3 && !strncmp (p
, "nostop", wordlen
))
1700 signal_stop
[signum
] = 0;
1701 else if (wordlen
>= 4 && !strncmp (p
, "noprint", wordlen
))
1703 signal_print
[signum
] = 0;
1704 signal_stop
[signum
] = 0;
1706 else if (wordlen
>= 4 && !strncmp (p
, "nopass", wordlen
))
1707 signal_program
[signum
] = 0;
1708 else if (wordlen
>= 3 && !strncmp (p
, "noignore", wordlen
))
1709 signal_program
[signum
] = 1;
1710 /* Not a number and not a recognized flag word => complain. */
1713 error ("Unrecognized or ambiguous flag word: \"%s\".", p
);
1716 /* Find start of next word. */
1718 while (*p
== ' ' || *p
== '\t') p
++;
1721 NOTICE_SIGNAL_HANDLING_CHANGE
;
1725 /* Show the results. */
1726 sig_print_header ();
1727 sig_print_info (signum
);
1731 /* Print current contents of the tables set by the handle command. */
1734 signals_info (signum_exp
, from_tty
)
1739 sig_print_header ();
1743 /* First see if this is a symbol name. */
1744 i
= strtosigno (signum_exp
);
1747 /* Nope, maybe it's an address which evaluates to a signal
1749 i
= parse_and_eval_address (signum_exp
);
1750 if (i
>= NSIG
|| i
< 0)
1751 error ("Signal number out of bounds.");
1757 printf_filtered ("\n");
1758 for (i
= 0; i
< NSIG
; i
++)
1765 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
1768 /* Save all of the information associated with the inferior<==>gdb
1769 connection. INF_STATUS is a pointer to a "struct inferior_status"
1770 (defined in inferior.h). */
1773 save_inferior_status (inf_status
, restore_stack_info
)
1774 struct inferior_status
*inf_status
;
1775 int restore_stack_info
;
1777 inf_status
->pc_changed
= pc_changed
;
1778 inf_status
->stop_signal
= stop_signal
;
1779 inf_status
->stop_pc
= stop_pc
;
1780 inf_status
->stop_frame_address
= stop_frame_address
;
1781 inf_status
->stop_step
= stop_step
;
1782 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
1783 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
1784 inf_status
->trap_expected
= trap_expected
;
1785 inf_status
->step_range_start
= step_range_start
;
1786 inf_status
->step_range_end
= step_range_end
;
1787 inf_status
->step_frame_address
= step_frame_address
;
1788 inf_status
->step_over_calls
= step_over_calls
;
1789 inf_status
->step_resume_break_address
= step_resume_break_address
;
1790 inf_status
->stop_after_trap
= stop_after_trap
;
1791 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
1792 /* Save original bpstat chain here; replace it with copy of chain.
1793 If caller's caller is walking the chain, they'll be happier if we
1794 hand them back the original chain when restore_i_s is called. */
1795 inf_status
->stop_bpstat
= stop_bpstat
;
1796 stop_bpstat
= bpstat_copy (stop_bpstat
);
1797 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
1798 inf_status
->restore_stack_info
= restore_stack_info
;
1799 inf_status
->proceed_to_finish
= proceed_to_finish
;
1801 bcopy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
1803 record_selected_frame (&(inf_status
->selected_frame_address
),
1804 &(inf_status
->selected_level
));
1809 restore_inferior_status (inf_status
)
1810 struct inferior_status
*inf_status
;
1813 int level
= inf_status
->selected_level
;
1815 pc_changed
= inf_status
->pc_changed
;
1816 stop_signal
= inf_status
->stop_signal
;
1817 stop_pc
= inf_status
->stop_pc
;
1818 stop_frame_address
= inf_status
->stop_frame_address
;
1819 stop_step
= inf_status
->stop_step
;
1820 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
1821 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
1822 trap_expected
= inf_status
->trap_expected
;
1823 step_range_start
= inf_status
->step_range_start
;
1824 step_range_end
= inf_status
->step_range_end
;
1825 step_frame_address
= inf_status
->step_frame_address
;
1826 step_over_calls
= inf_status
->step_over_calls
;
1827 step_resume_break_address
= inf_status
->step_resume_break_address
;
1828 stop_after_trap
= inf_status
->stop_after_trap
;
1829 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
1830 bpstat_clear (&stop_bpstat
);
1831 stop_bpstat
= inf_status
->stop_bpstat
;
1832 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
1833 proceed_to_finish
= inf_status
->proceed_to_finish
;
1835 bcopy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
1837 /* The inferior can be gone if the user types "print exit(0)"
1838 (and perhaps other times). */
1839 if (target_has_stack
&& inf_status
->restore_stack_info
)
1841 fid
= find_relative_frame (get_current_frame (),
1844 /* If inf_status->selected_frame_address is NULL, there was no
1845 previously selected frame. */
1847 FRAME_FP (fid
) != inf_status
->selected_frame_address
||
1851 /* I'm not sure this error message is a good idea. I have
1852 only seen it occur after "Can't continue previously
1853 requested operation" (we get called from do_cleanups), in
1854 which case it just adds insult to injury (one confusing
1855 error message after another. Besides which, does the
1856 user really care if we can't restore the previously
1858 fprintf (stderr
, "Unable to restore previously selected frame.\n");
1860 select_frame (get_current_frame (), 0);
1864 select_frame (fid
, inf_status
->selected_level
);
1870 _initialize_infrun ()
1873 register int numsigs
;
1875 add_info ("signals", signals_info
,
1876 "What debugger does when program gets various signals.\n\
1877 Specify a signal number as argument to print info on that signal only.");
1879 add_com ("handle", class_run
, handle_command
,
1880 "Specify how to handle a signal.\n\
1881 Args are signal number followed by flags.\n\
1882 Flags allowed are \"stop\", \"print\", \"pass\",\n\
1883 \"nostop\", \"noprint\" or \"nopass\".\n\
1884 Print means print a message if this signal happens.\n\
1885 Stop means reenter debugger if this signal happens (implies print).\n\
1886 Pass means let program see this signal; otherwise program doesn't know.\n\
1887 Pass and Stop may be combined.");
1889 numsigs
= signo_max () + 1;
1890 signal_stop
= xmalloc (sizeof (signal_stop
[0]) * numsigs
);
1891 signal_print
= xmalloc (sizeof (signal_print
[0]) * numsigs
);
1892 signal_program
= xmalloc (sizeof (signal_program
[0]) * numsigs
);
1893 for (i
= 0; i
< numsigs
; i
++)
1896 signal_print
[i
] = 1;
1897 signal_program
[i
] = 1;
1900 /* Signals caused by debugger's own actions
1901 should not be given to the program afterwards. */
1902 signal_program
[SIGTRAP
] = 0;
1903 signal_program
[SIGINT
] = 0;
1905 /* Signals that are not errors should not normally enter the debugger. */
1907 signal_stop
[SIGALRM
] = 0;
1908 signal_print
[SIGALRM
] = 0;
1909 #endif /* SIGALRM */
1911 signal_stop
[SIGVTALRM
] = 0;
1912 signal_print
[SIGVTALRM
] = 0;
1913 #endif /* SIGVTALRM */
1915 signal_stop
[SIGPROF
] = 0;
1916 signal_print
[SIGPROF
] = 0;
1917 #endif /* SIGPROF */
1919 signal_stop
[SIGCHLD
] = 0;
1920 signal_print
[SIGCHLD
] = 0;
1921 #endif /* SIGCHLD */
1923 signal_stop
[SIGCLD
] = 0;
1924 signal_print
[SIGCLD
] = 0;
1927 signal_stop
[SIGIO
] = 0;
1928 signal_print
[SIGIO
] = 0;
1931 signal_stop
[SIGURG
] = 0;
1932 signal_print
[SIGURG
] = 0;