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 unsigned char *signal_stop;
215 static unsigned char *signal_print;
216 static unsigned char *signal_program;
218 #define SET_SIGS(nsigs,sigs,flags) \
220 int signum = (nsigs); \
221 while (signum-- > 0) \
222 if ((sigs)[signum]) \
223 (flags)[signum] = 1; \
226 #define UNSET_SIGS(nsigs,sigs,flags) \
228 int signum = (nsigs); \
229 while (signum-- > 0) \
230 if ((sigs)[signum]) \
231 (flags)[signum] = 0; \
234 /* Nonzero if breakpoints are now inserted in the inferior. */
235 /* Nonstatic for initialization during xxx_create_inferior. FIXME. */
237 /*static*/ int breakpoints_inserted;
239 /* Function inferior was in as of last step command. */
241 static struct symbol *step_start_function;
243 /* Nonzero => address for special breakpoint for resuming stepping. */
245 static CORE_ADDR step_resume_break_address;
247 /* Pointer to orig contents of the byte where the special breakpoint is. */
249 static char step_resume_break_shadow[BREAKPOINT_MAX];
251 /* Nonzero means the special breakpoint is a duplicate
252 so it has not itself been inserted. */
254 static int step_resume_break_duplicate;
256 /* Nonzero if we are expecting a trace trap and should proceed from it. */
258 static int trap_expected;
260 /* Nonzero if the next time we try to continue the inferior, it will
261 step one instruction and generate a spurious trace trap.
262 This is used to compensate for a bug in HP-UX. */
264 static int trap_expected_after_continue;
266 /* Nonzero means expecting a trace trap
267 and should stop the inferior and return silently when it happens. */
271 /* Nonzero means expecting a trap and caller will handle it themselves.
272 It is used after attach, due to attaching to a process;
273 when running in the shell before the child program has been exec'd;
274 and when running some kinds of remote stuff (FIXME?). */
276 int stop_soon_quietly;
278 /* Nonzero if pc has been changed by the debugger
279 since the inferior stopped. */
283 /* Nonzero if proceed is being used for a "finish" command or a similar
284 situation when stop_registers should be saved. */
286 int proceed_to_finish;
288 /* Save register contents here when about to pop a stack dummy frame,
289 if-and-only-if proceed_to_finish is set.
290 Thus this contains the return value from the called function (assuming
291 values are returned in a register). */
293 char stop_registers[REGISTER_BYTES];
295 /* Nonzero if program stopped due to error trying to insert breakpoints. */
297 static int breakpoints_failed;
299 /* Nonzero after stop if current stack frame should be printed. */
301 static int stop_print_frame;
303 #ifdef NO_SINGLE_STEP
304 extern int one_stepped; /* From machine dependent code */
305 extern void single_step (); /* Same. */
306 #endif /* NO_SINGLE_STEP */
309 /* Things to clean up if we QUIT out of resume (). */
312 resume_cleanups (arg)
318 /* Resume the inferior, but allow a QUIT. This is useful if the user
319 wants to interrupt some lengthy single-stepping operation
320 (for child processes, the SIGINT goes to the inferior, and so
321 we get a SIGINT random_signal, but for remote debugging and perhaps
322 other targets, that's not true).
324 STEP nonzero if we should step (zero to continue instead).
325 SIG is the signal to give the inferior (zero for none). */
331 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
334 #ifdef NO_SINGLE_STEP
336 single_step(sig); /* Do it the hard way, w/temp breakpoints */
337 step = 0; /* ...and don't ask hardware to do it. */
341 /* Handle any optimized stores to the inferior NOW... */
342 #ifdef DO_DEFERRED_STORES
346 target_resume (step, sig);
347 discard_cleanups (old_cleanups);
351 /* Clear out all variables saying what to do when inferior is continued.
352 First do this, then set the ones you want, then call `proceed'. */
355 clear_proceed_status ()
358 step_range_start = 0;
360 step_frame_address = 0;
361 step_over_calls = -1;
362 step_resume_break_address = 0;
364 stop_soon_quietly = 0;
365 proceed_to_finish = 0;
366 breakpoint_proceeded = 1; /* We're about to proceed... */
368 /* Discard any remaining commands or status from previous stop. */
369 bpstat_clear (&stop_bpstat);
372 /* Basic routine for continuing the program in various fashions.
374 ADDR is the address to resume at, or -1 for resume where stopped.
375 SIGGNAL is the signal to give it, or 0 for none,
376 or -1 for act according to how it stopped.
377 STEP is nonzero if should trap after one instruction.
378 -1 means return after that and print nothing.
379 You should probably set various step_... variables
380 before calling here, if you are stepping.
382 You should call clear_proceed_status before calling proceed. */
385 proceed (addr, siggnal, step)
393 step_start_function = find_pc_function (read_pc ());
397 if (addr == (CORE_ADDR)-1)
399 /* If there is a breakpoint at the address we will resume at,
400 step one instruction before inserting breakpoints
401 so that we do not stop right away. */
403 if (!pc_changed && breakpoint_here_p (read_pc ()))
408 write_register (PC_REGNUM, addr);
410 write_register (NPC_REGNUM, addr + 4);
412 write_register (NNPC_REGNUM, addr + 8);
417 if (trap_expected_after_continue)
419 /* If (step == 0), a trap will be automatically generated after
420 the first instruction is executed. Force step one
421 instruction to clear this condition. This should not occur
422 if step is nonzero, but it is harmless in that case. */
424 trap_expected_after_continue = 0;
428 /* We will get a trace trap after one instruction.
429 Continue it automatically and insert breakpoints then. */
433 int temp = insert_breakpoints ();
436 print_sys_errmsg ("ptrace", temp);
437 error ("Cannot insert breakpoints.\n\
438 The same program may be running in another process.");
440 breakpoints_inserted = 1;
443 /* Install inferior's terminal modes. */
444 target_terminal_inferior ();
447 stop_signal = siggnal;
448 /* If this signal should not be seen by program,
449 give it zero. Used for debugging signals. */
450 else if (stop_signal < NSIG && !signal_program[stop_signal])
453 /* Resume inferior. */
454 resume (oneproc || step || bpstat_should_step (), stop_signal);
456 /* Wait for it to stop (if not standalone)
457 and in any case decode why it stopped, and act accordingly. */
459 wait_for_inferior ();
463 /* Record the pc and sp of the program the last time it stopped.
464 These are just used internally by wait_for_inferior, but need
465 to be preserved over calls to it and cleared when the inferior
467 static CORE_ADDR prev_pc;
468 static CORE_ADDR prev_sp;
469 static CORE_ADDR prev_func_start;
470 static char *prev_func_name;
473 /* Start an inferior Unix child process and sets inferior_pid to its pid.
474 EXEC_FILE is the file to run.
475 ALLARGS is a string containing the arguments to the program.
476 ENV is the environment vector to pass. Errors reported with error(). */
479 #define SHELL_FILE "/bin/sh"
483 child_create_inferior (exec_file, allargs, env)
491 static char default_shell_file[] = SHELL_FILE;
494 /* Set debug_fork then attach to the child while it sleeps, to debug. */
495 static int debug_fork = 0;
496 /* This is set to the result of setpgrp, which if vforked, will be visible
497 to you in the parent process. It's only used by humans for debugging. */
498 static int debug_setpgrp = 657473;
501 /* The user might want tilde-expansion, and in general probably wants
502 the program to behave the same way as if run from
503 his/her favorite shell. So we let the shell run it for us.
504 FIXME, this should probably search the local environment (as
505 modified by the setenv command), not the env gdb inherited. */
506 shell_file = getenv ("SHELL");
507 if (shell_file == NULL)
508 shell_file = default_shell_file;
510 len = 5 + strlen (exec_file) + 1 + strlen (allargs) + 1 + /*slop*/ 10;
511 /* If desired, concat something onto the front of ALLARGS.
512 SHELL_COMMAND is the result. */
513 #ifdef SHELL_COMMAND_CONCAT
514 shell_command = (char *) alloca (strlen (SHELL_COMMAND_CONCAT) + len);
515 strcpy (shell_command, SHELL_COMMAND_CONCAT);
517 shell_command = (char *) alloca (len);
518 shell_command[0] = '\0';
520 strcat (shell_command, "exec ");
521 strcat (shell_command, exec_file);
522 strcat (shell_command, " ");
523 strcat (shell_command, allargs);
525 /* exec is said to fail if the executable is open. */
528 /* Retain a copy of our environment variables, since the child will
529 replace the value of environ and if we're vforked, we have to
531 save_our_env = environ;
533 /* Tell the terminal handling subsystem what tty we plan to run on;
534 it will just record the information for later. */
536 new_tty_prefork (inferior_io_terminal);
538 /* It is generally good practice to flush any possible pending stdio
539 output prior to doing a fork, to avoid the possibility of both the
540 parent and child flushing the same data after the fork. */
545 #if defined(USG) && !defined(HAVE_VFORK)
555 perror_with_name ("vfork");
563 /* Run inferior in a separate process group. */
564 #ifdef NEED_POSIX_SETPGID
565 debug_setpgrp = setpgid (0, 0);
567 #if defined(USG) && !defined(SETPGRP_ARGS)
568 debug_setpgrp = setpgrp ();
570 debug_setpgrp = setpgrp (getpid (), getpid ());
572 #endif /* NEED_POSIX_SETPGID */
573 if (debug_setpgrp == -1)
574 perror("setpgrp failed in child");
575 #endif /* TIOCGPGRP */
577 #ifdef SET_STACK_LIMIT_HUGE
578 /* Reset the stack limit back to what it was. */
582 getrlimit (RLIMIT_STACK, &rlim);
583 rlim.rlim_cur = original_stack_limit;
584 setrlimit (RLIMIT_STACK, &rlim);
586 #endif /* SET_STACK_LIMIT_HUGE */
588 /* Ask the tty subsystem to switch to the one we specified earlier
589 (or to share the current terminal, if none was specified). */
593 /* Changing the signal handlers for the inferior after
594 a vfork can also change them for the superior, so we don't mess
595 with signals here. See comments in
596 initialize_signals for how we get the right signal handlers
600 /* Use SVR4 /proc interface */
601 proc_set_exec_trap ();
603 /* "Trace me, Dr. Memory!" */
604 call_ptrace (0, 0, (PTRACE_ARG3_TYPE) 0, 0);
607 /* There is no execlpe call, so we have to set the environment
608 for our child in the global variable. If we've vforked, this
609 clobbers the parent, but environ is restored a few lines down
610 in the parent. By the way, yes we do need to look down the
611 path to find $SHELL. Rich Pixley says so, and I agree. */
613 execlp (shell_file, shell_file, "-c", shell_command, (char *)0);
615 fprintf (stderr, "Cannot exec %s: %s.\n", shell_file,
616 safe_strerror (errno));
621 /* Restore our environment in case a vforked child clob'd it. */
622 environ = save_our_env;
624 /* Now that we have a child process, make it our target. */
625 push_target (&child_ops);
627 #ifdef CREATE_INFERIOR_HOOK
628 CREATE_INFERIOR_HOOK (pid);
631 /* The process was started by the fork that created it,
632 but it will have stopped one instruction after execing the shell.
633 Here we must get it up to actual execution of the real program. */
635 inferior_pid = pid; /* Needed for wait_for_inferior stuff below */
637 clear_proceed_status ();
639 /* We will get a trace trap after one instruction.
640 Continue it automatically. Eventually (after shell does an exec)
641 it will get another trace trap. Then insert breakpoints and continue. */
643 #ifdef START_INFERIOR_TRAPS_EXPECTED
644 pending_execs = START_INFERIOR_TRAPS_EXPECTED;
649 init_wait_for_inferior ();
651 /* Set up the "saved terminal modes" of the inferior
652 based on what modes we are starting it with. */
653 target_terminal_init ();
655 /* Install inferior's terminal modes. */
656 target_terminal_inferior ();
660 stop_soon_quietly = 1; /* Make wait_for_inferior be quiet */
661 wait_for_inferior ();
662 if (stop_signal != SIGTRAP)
664 /* Let shell child handle its own signals in its own way */
665 /* FIXME, what if child has exit()ed? Must exit loop somehow */
666 resume (0, stop_signal);
670 /* We handle SIGTRAP, however; it means child did an exec. */
671 if (0 == --pending_execs)
673 resume (0, 0); /* Just make it go on */
676 stop_soon_quietly = 0;
678 /* We are now in the child process of interest, having exec'd the
679 correct program, and are poised at the first instruction of the
681 #ifdef SOLIB_CREATE_INFERIOR_HOOK
682 SOLIB_CREATE_INFERIOR_HOOK (pid);
685 /* Pedal to the metal. Away we go. */
686 proceed ((CORE_ADDR) -1, 0, 0);
689 /* Start remote-debugging of a machine over a serial link. */
694 init_wait_for_inferior ();
695 clear_proceed_status ();
696 stop_soon_quietly = 1;
698 wait_for_inferior ();
702 /* Initialize static vars when a new inferior begins. */
705 init_wait_for_inferior ()
707 /* These are meaningless until the first time through wait_for_inferior. */
711 prev_func_name = NULL;
713 trap_expected_after_continue = 0;
714 breakpoints_inserted = 0;
715 mark_breakpoints_out ();
716 stop_signal = 0; /* Don't confuse first call to proceed(). */
720 /* Attach to process PID, then initialize for debugging it
721 and wait for the trace-trap that results from attaching. */
724 child_attach (args, from_tty)
734 error_no_arg ("process-id to attach");
736 #ifndef ATTACH_DETACH
737 error ("Can't attach to a process on this machine.");
741 if (pid == getpid()) /* Trying to masturbate? */
742 error ("I refuse to debug myself!");
744 if (target_has_execution)
746 if (query ("A program is being debugged already. Kill it? "))
749 error ("Inferior not killed.");
752 exec_file = (char *) get_exec_file (1);
756 printf ("Attaching program: %s pid %d\n",
763 push_target (&child_ops);
765 mark_breakpoints_out ();
766 target_terminal_init ();
767 clear_proceed_status ();
768 stop_soon_quietly = 1;
769 /*proceed (-1, 0, -2);*/
770 target_terminal_inferior ();
771 wait_for_inferior ();
773 SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
776 #endif /* ATTACH_DETACH */
779 /* Wait for control to return from inferior to debugger.
780 If inferior gets a signal, we may decide to start it up again
781 instead of returning. That is why there is a loop in this function.
782 When this function actually returns it means the inferior
783 should be left stopped and GDB should read more commands. */
792 CORE_ADDR stop_func_start;
793 char *stop_func_name;
794 CORE_ADDR prologue_pc, tmp;
795 int stop_step_resume_break;
796 struct symtab_and_line sal;
797 int remove_breakpoints_on_following_step = 0;
799 int handling_longjmp = 0; /* FIXME */
801 sal = find_pc_line(prev_pc, 0);
802 current_line = sal.line;
806 /* Clean up saved state that will become invalid. */
808 flush_cached_frames ();
809 registers_changed ();
813 #ifdef SIGTRAP_STOP_AFTER_LOAD
815 /* Somebody called load(2), and it gave us a "trap signal after load".
816 Ignore it gracefully. */
818 SIGTRAP_STOP_AFTER_LOAD (w);
821 /* See if the process still exists; clean up if it doesn't. */
824 target_terminal_ours (); /* Must do this before mourn anyway */
826 printf_filtered ("\nProgram exited with code 0%o.\n",
827 (unsigned int)WEXITSTATUS (w));
830 printf_filtered ("\nProgram exited normally.\n");
832 target_mourn_inferior ();
833 #ifdef NO_SINGLE_STEP
836 stop_print_frame = 0;
839 else if (!WIFSTOPPED (w))
841 stop_print_frame = 0;
842 stop_signal = WTERMSIG (w);
843 target_terminal_ours (); /* Must do this before mourn anyway */
844 target_kill (); /* kill mourns as well */
845 #ifdef PRINT_RANDOM_SIGNAL
846 printf_filtered ("\nProgram terminated: ");
847 PRINT_RANDOM_SIGNAL (stop_signal);
849 printf_filtered ("\nProgram terminated with signal %d, %s\n",
850 stop_signal, safe_strsignal (stop_signal));
852 printf_filtered ("The inferior process no longer exists.\n");
854 #ifdef NO_SINGLE_STEP
860 #ifdef NO_SINGLE_STEP
862 single_step (0); /* This actually cleans up the ss */
863 #endif /* NO_SINGLE_STEP */
865 stop_pc = read_pc ();
866 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
869 stop_frame_address = FRAME_FP (get_current_frame ());
870 stop_sp = read_register (SP_REGNUM);
873 /* Don't care about return value; stop_func_start and stop_func_name
874 will both be 0 if it doesn't work. */
875 find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start);
876 stop_func_start += FUNCTION_START_OFFSET;
878 bpstat_clear (&stop_bpstat);
880 stop_stack_dummy = 0;
881 stop_print_frame = 1;
882 stop_step_resume_break = 0;
884 stopped_by_random_signal = 0;
885 breakpoints_failed = 0;
887 /* Look at the cause of the stop, and decide what to do.
888 The alternatives are:
889 1) break; to really stop and return to the debugger,
890 2) drop through to start up again
891 (set another_trap to 1 to single step once)
892 3) set random_signal to 1, and the decision between 1 and 2
893 will be made according to the signal handling tables. */
895 stop_signal = WSTOPSIG (w);
897 /* First, distinguish signals caused by the debugger from signals
898 that have to do with the program's own actions.
899 Note that breakpoint insns may cause SIGTRAP or SIGILL
900 or SIGEMT, depending on the operating system version.
901 Here we detect when a SIGILL or SIGEMT is really a breakpoint
902 and change it to SIGTRAP. */
904 if (stop_signal == SIGTRAP
905 || (breakpoints_inserted &&
906 (stop_signal == SIGILL
908 || stop_signal == SIGEMT
911 || stop_soon_quietly)
913 if (stop_signal == SIGTRAP && stop_after_trap)
915 stop_print_frame = 0;
918 if (stop_soon_quietly)
921 /* Don't even think about breakpoints
922 if just proceeded over a breakpoint.
924 However, if we are trying to proceed over a breakpoint
925 and end up in sigtramp, then step_resume_break_address
926 will be set and we should check whether we've hit the
928 if (stop_signal == SIGTRAP && trap_expected
929 && step_resume_break_address == 0)
930 bpstat_clear (&stop_bpstat);
933 /* See if there is a breakpoint at the current PC. */
934 #if DECR_PC_AFTER_BREAK
935 /* Notice the case of stepping through a jump
936 that lands just after a breakpoint.
937 Don't confuse that with hitting the breakpoint.
938 What we check for is that 1) stepping is going on
939 and 2) the pc before the last insn does not match
940 the address of the breakpoint before the current pc. */
941 if (prev_pc == stop_pc - DECR_PC_AFTER_BREAK
943 || step_resume_break_address
944 || handling_longjmp /* FIXME */)
945 #endif /* DECR_PC_AFTER_BREAK not zero */
947 /* See if we stopped at the special breakpoint for
948 stepping over a subroutine call. If both are zero,
949 this wasn't the reason for the stop. */
950 if (step_resume_break_address
951 && stop_pc - DECR_PC_AFTER_BREAK
952 == step_resume_break_address)
954 stop_step_resume_break = 1;
955 if (DECR_PC_AFTER_BREAK)
957 stop_pc -= DECR_PC_AFTER_BREAK;
958 write_register (PC_REGNUM, stop_pc);
965 bpstat_stop_status (&stop_pc, stop_frame_address);
966 /* Following in case break condition called a
968 stop_print_frame = 1;
973 if (stop_signal == SIGTRAP)
975 = !(bpstat_explains_signal (stop_bpstat)
977 || stop_step_resume_break
978 || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
979 || (step_range_end && !step_resume_break_address));
983 = !(bpstat_explains_signal (stop_bpstat)
984 || stop_step_resume_break
985 /* End of a stack dummy. Some systems (e.g. Sony
986 news) give another signal besides SIGTRAP,
987 so check here as well as above. */
988 || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
991 stop_signal = SIGTRAP;
997 /* For the program's own signals, act according to
998 the signal handling tables. */
1002 /* Signal not for debugging purposes. */
1005 stopped_by_random_signal = 1;
1007 if (stop_signal >= NSIG
1008 || signal_print[stop_signal])
1011 target_terminal_ours_for_output ();
1012 #ifdef PRINT_RANDOM_SIGNAL
1013 PRINT_RANDOM_SIGNAL (stop_signal);
1015 printf_filtered ("\nProgram received signal %d, %s\n",
1016 stop_signal, safe_strsignal (stop_signal));
1017 #endif /* PRINT_RANDOM_SIGNAL */
1020 if (stop_signal >= NSIG
1021 || signal_stop[stop_signal])
1023 /* If not going to stop, give terminal back
1024 if we took it away. */
1026 target_terminal_inferior ();
1028 /* Note that virtually all the code below does `if !random_signal'.
1029 Perhaps this code should end with a goto or continue. At least
1030 one (now fixed) bug was caused by this -- a !random_signal was
1031 missing in one of the tests below. */
1034 /* Handle cases caused by hitting a breakpoint. */
1037 if (bpstat_explains_signal (stop_bpstat))
1039 CORE_ADDR jmp_buf_pc;
1041 switch (stop_bpstat->breakpoint_at->type) /* FIXME */
1043 /* If we hit the breakpoint at longjmp, disable it for the
1044 duration of this command. Then, install a temporary
1045 breakpoint at the target of the jmp_buf. */
1047 disable_longjmp_breakpoint();
1048 remove_breakpoints ();
1049 breakpoints_inserted = 0;
1050 if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
1052 /* Need to blow away step-resume breakpoint, as it
1053 interferes with us */
1054 remove_step_breakpoint ();
1055 step_resume_break_address = 0;
1056 stop_step_resume_break = 0;
1058 #if 0 /* FIXME - Need to implement nested temporary breakpoints */
1059 if (step_over_calls > 0)
1060 set_longjmp_resume_breakpoint(jmp_buf_pc,
1061 get_current_frame());
1064 set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
1065 handling_longjmp = 1; /* FIXME */
1068 case bp_longjmp_resume:
1069 remove_breakpoints ();
1070 breakpoints_inserted = 0;
1071 #if 0 /* FIXME - Need to implement nested temporary breakpoints */
1073 && (stop_frame_address
1074 INNER_THAN step_frame_address))
1080 disable_longjmp_breakpoint();
1081 handling_longjmp = 0; /* FIXME */
1085 fprintf(stderr, "Unknown breakpoint type %d\n",
1086 stop_bpstat->breakpoint_at->type);
1091 /* Does a breakpoint want us to stop? */
1092 if (bpstat_stop (stop_bpstat))
1094 stop_print_frame = bpstat_should_print (stop_bpstat);
1097 /* Otherwise, must remove breakpoints and single-step
1098 to get us past the one we hit. */
1101 remove_breakpoints ();
1102 remove_step_breakpoint ();
1103 breakpoints_inserted = 0;
1109 else if (stop_step_resume_break)
1111 /* But if we have hit the step-resumption breakpoint,
1112 remove it. It has done its job getting us here.
1113 The sp test is to make sure that we don't get hung
1114 up in recursive calls in functions without frame
1115 pointers. If the stack pointer isn't outside of
1116 where the breakpoint was set (within a routine to be
1117 stepped over), we're in the middle of a recursive
1118 call. Not true for reg window machines (sparc)
1119 because the must change frames to call things and
1120 the stack pointer doesn't have to change if it
1121 the bp was set in a routine without a frame (pc can
1122 be stored in some other window).
1124 The removal of the sp test is to allow calls to
1125 alloca. Nasty things were happening. Oh, well,
1126 gdb can only handle one level deep of lack of
1130 Disable test for step_frame_address match so that we always stop even if the
1131 frames don't match. Reason: if we hit the step_resume_breakpoint, there is
1132 no way to temporarily disable it so that we can step past it. If we leave
1133 the breakpoint in, then we loop forever repeatedly hitting, but never
1134 getting past the breakpoint. This change keeps nexting over recursive
1135 function calls from hanging gdb.
1138 if (* step_frame_address == 0
1139 || (step_frame_address == stop_frame_address))
1142 remove_step_breakpoint ();
1143 step_resume_break_address = 0;
1145 /* If were waiting for a trap, hitting the step_resume_break
1146 doesn't count as getting it. */
1152 /* We come here if we hit a breakpoint but should not
1153 stop for it. Possibly we also were stepping
1154 and should stop for that. So fall through and
1155 test for stepping. But, if not stepping,
1158 /* If this is the breakpoint at the end of a stack dummy,
1159 just stop silently. */
1161 && PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address))
1163 stop_print_frame = 0;
1164 stop_stack_dummy = 1;
1166 trap_expected_after_continue = 1;
1171 if (step_resume_break_address)
1172 /* Having a step-resume breakpoint overrides anything
1173 else having to do with stepping commands until
1174 that breakpoint is reached. */
1176 /* If stepping through a line, keep going if still within it. */
1177 else if (!random_signal
1179 && stop_pc >= step_range_start
1180 && stop_pc < step_range_end
1181 /* The step range might include the start of the
1182 function, so if we are at the start of the
1183 step range and either the stack or frame pointers
1184 just changed, we've stepped outside */
1185 && !(stop_pc == step_range_start
1186 && stop_frame_address
1187 && (stop_sp INNER_THAN prev_sp
1188 || stop_frame_address != step_frame_address)))
1193 /* We stepped out of the stepping range. See if that was due
1194 to a subroutine call that we should proceed to the end of. */
1195 else if (!random_signal && step_range_end)
1197 if (stop_func_start)
1199 prologue_pc = stop_func_start;
1200 SKIP_PROLOGUE (prologue_pc);
1203 /* Did we just take a signal? */
1204 if (IN_SIGTRAMP (stop_pc, stop_func_name)
1205 && !IN_SIGTRAMP (prev_pc, prev_func_name))
1207 /* This code is needed at least in the following case:
1208 The user types "next" and then a signal arrives (before
1209 the "next" is done). */
1210 /* We've just taken a signal; go until we are back to
1211 the point where we took it and one more. */
1212 step_resume_break_address = prev_pc;
1213 step_resume_break_duplicate =
1214 breakpoint_here_p (step_resume_break_address);
1215 if (breakpoints_inserted)
1216 insert_step_breakpoint ();
1217 /* Make sure that the stepping range gets us past
1218 that instruction. */
1219 if (step_range_end == 1)
1220 step_range_end = (step_range_start = prev_pc) + 1;
1221 remove_breakpoints_on_following_step = 1;
1225 /* ==> See comments at top of file on this algorithm. <==*/
1227 if ((stop_pc == stop_func_start
1228 || IN_SOLIB_TRAMPOLINE (stop_pc, stop_func_name))
1229 && (stop_func_start != prev_func_start
1230 || prologue_pc != stop_func_start
1231 || stop_sp != prev_sp))
1233 /* It's a subroutine call.
1234 (0) If we are not stepping over any calls ("stepi"), we
1236 (1) If we're doing a "next", we want to continue through
1237 the call ("step over the call").
1238 (2) If we are in a function-call trampoline (a stub between
1239 the calling routine and the real function), locate
1240 the real function and change stop_func_start.
1241 (3) If we're doing a "step", and there are no debug symbols
1242 at the target of the call, we want to continue through
1243 it ("step over the call").
1244 (4) Otherwise, we want to stop soon, after the function
1245 prologue ("step into the call"). */
1247 if (step_over_calls == 0)
1249 /* I presume that step_over_calls is only 0 when we're
1250 supposed to be stepping at the assembly language level. */
1255 if (step_over_calls > 0)
1256 goto step_over_function;
1258 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1260 stop_func_start = tmp;
1262 if (find_pc_function (stop_func_start) != 0)
1263 goto step_into_function;
1266 /* A subroutine call has happened. */
1267 /* Set a special breakpoint after the return */
1268 step_resume_break_address =
1270 (SAVED_PC_AFTER_CALL (get_current_frame ()));
1271 step_resume_break_duplicate
1272 = breakpoint_here_p (step_resume_break_address);
1273 if (breakpoints_inserted)
1274 insert_step_breakpoint ();
1278 /* Subroutine call with source code we should not step over.
1279 Do step to the first line of code in it. */
1280 SKIP_PROLOGUE (stop_func_start);
1281 sal = find_pc_line (stop_func_start, 0);
1282 /* Use the step_resume_break to step until
1283 the end of the prologue, even if that involves jumps
1284 (as it seems to on the vax under 4.2). */
1285 /* If the prologue ends in the middle of a source line,
1286 continue to the end of that source line.
1287 Otherwise, just go to end of prologue. */
1288 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1289 /* no, don't either. It skips any code that's
1290 legitimately on the first line. */
1292 if (sal.end && sal.pc != stop_func_start)
1293 stop_func_start = sal.end;
1296 if (stop_func_start == stop_pc)
1298 /* We are already there: stop now. */
1303 /* Put the step-breakpoint there and go until there. */
1305 step_resume_break_address = stop_func_start;
1307 step_resume_break_duplicate
1308 = breakpoint_here_p (step_resume_break_address);
1309 if (breakpoints_inserted)
1310 insert_step_breakpoint ();
1311 /* Do not specify what the fp should be when we stop
1312 since on some machines the prologue
1313 is where the new fp value is established. */
1314 step_frame_address = 0;
1315 /* And make sure stepping stops right away then. */
1316 step_range_end = step_range_start;
1321 /* We've wandered out of the step range (but haven't done a
1322 subroutine call or return). */
1324 sal = find_pc_line(stop_pc, 0);
1326 if (step_range_end == 1 || /* stepi or nexti */
1327 sal.line == 0 || /* ...or no line # info */
1328 (stop_pc == sal.pc /* ...or we're at the start */
1329 && current_line != sal.line)) { /* of a different line */
1330 /* Stop because we're done stepping. */
1334 /* We aren't done stepping, and we have line number info for $pc.
1335 Optimize by setting the step_range for the line.
1336 (We might not be in the original line, but if we entered a
1337 new line in mid-statement, we continue stepping. This makes
1338 things like for(;;) statements work better.) */
1339 step_range_start = sal.pc;
1340 step_range_end = sal.end;
1343 /* We never fall through here */
1347 && IN_SIGTRAMP (stop_pc, stop_func_name)
1348 && !IN_SIGTRAMP (prev_pc, prev_func_name))
1350 /* What has happened here is that we have just stepped the inferior
1351 with a signal (because it is a signal which shouldn't make
1352 us stop), thus stepping into sigtramp.
1354 So we need to set a step_resume_break_address breakpoint
1355 and continue until we hit it, and then step. */
1356 step_resume_break_address = prev_pc;
1357 /* Always 1, I think, but it's probably easier to have
1358 the step_resume_break as usual rather than trying to
1359 re-use the breakpoint which is already there. */
1360 step_resume_break_duplicate =
1361 breakpoint_here_p (step_resume_break_address);
1362 if (breakpoints_inserted)
1363 insert_step_breakpoint ();
1364 remove_breakpoints_on_following_step = 1;
1368 /* My apologies to the gods of structured programming. */
1369 /* Come to this label when you need to resume the inferior. It's really much
1370 cleaner at this time to do a goto than to try and figure out what the
1371 if-else chain ought to look like!! */
1376 /* Save the pc before execution, to compare with pc after stop. */
1377 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
1378 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
1379 BREAK is defined, the
1380 original pc would not have
1381 been at the start of a
1383 prev_func_name = stop_func_name;
1386 /* If we did not do break;, it means we should keep
1387 running the inferior and not return to debugger. */
1389 if (trap_expected && stop_signal != SIGTRAP)
1391 /* We took a signal (which we are supposed to pass through to
1392 the inferior, else we'd have done a break above) and we
1393 haven't yet gotten our trap. Simply continue. */
1394 resume ((step_range_end && !step_resume_break_address)
1395 || (trap_expected && !step_resume_break_address)
1396 || bpstat_should_step (),
1401 /* Either the trap was not expected, but we are continuing
1402 anyway (the user asked that this signal be passed to the
1405 The signal was SIGTRAP, e.g. it was our signal, but we
1406 decided we should resume from it.
1408 We're going to run this baby now!
1410 Insert breakpoints now, unless we are trying
1411 to one-proceed past a breakpoint. */
1412 /* If we've just finished a special step resume and we don't
1413 want to hit a breakpoint, pull em out. */
1414 if (!step_resume_break_address &&
1415 remove_breakpoints_on_following_step)
1417 remove_breakpoints_on_following_step = 0;
1418 remove_breakpoints ();
1419 breakpoints_inserted = 0;
1421 else if (!breakpoints_inserted &&
1422 (step_resume_break_address != 0 || !another_trap))
1424 insert_step_breakpoint ();
1425 breakpoints_failed = insert_breakpoints ();
1426 if (breakpoints_failed)
1428 breakpoints_inserted = 1;
1431 trap_expected = another_trap;
1433 if (stop_signal == SIGTRAP)
1436 #ifdef SHIFT_INST_REGS
1437 /* I'm not sure when this following segment applies. I do know, now,
1438 that we shouldn't rewrite the regs when we were stopped by a
1439 random signal from the inferior process. */
1441 if (!bpstat_explains_signal (stop_bpstat)
1442 && (stop_signal != SIGCLD)
1443 && !stopped_by_random_signal)
1445 CORE_ADDR pc_contents = read_register (PC_REGNUM);
1446 CORE_ADDR npc_contents = read_register (NPC_REGNUM);
1447 if (pc_contents != npc_contents)
1449 write_register (NNPC_REGNUM, npc_contents);
1450 write_register (NPC_REGNUM, pc_contents);
1453 #endif /* SHIFT_INST_REGS */
1455 resume ((!step_resume_break_address
1456 && !handling_longjmp
1459 || bpstat_should_step (),
1465 if (target_has_execution)
1467 /* Assuming the inferior still exists, set these up for next
1468 time, just like we did above if we didn't break out of the
1470 prev_pc = read_pc ();
1471 prev_func_start = stop_func_start;
1472 prev_func_name = stop_func_name;
1477 /* Here to return control to GDB when the inferior stops for real.
1478 Print appropriate messages, remove breakpoints, give terminal our modes.
1480 STOP_PRINT_FRAME nonzero means print the executing frame
1481 (pc, function, args, file, line number and line text).
1482 BREAKPOINTS_FAILED nonzero means stop was due to error
1483 attempting to insert breakpoints. */
1488 /* Make sure that the current_frame's pc is correct. This
1489 is a correction for setting up the frame info before doing
1490 DECR_PC_AFTER_BREAK */
1491 if (target_has_execution)
1492 (get_current_frame ())->pc = read_pc ();
1494 if (breakpoints_failed)
1496 target_terminal_ours_for_output ();
1497 print_sys_errmsg ("ptrace", breakpoints_failed);
1498 printf_filtered ("Stopped; cannot insert breakpoints.\n\
1499 The same program may be running in another process.\n");
1502 if (target_has_execution)
1503 remove_step_breakpoint ();
1505 if (target_has_execution && breakpoints_inserted)
1506 if (remove_breakpoints ())
1508 target_terminal_ours_for_output ();
1509 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
1510 It might be running in another process.\n\
1511 Further execution is probably impossible.\n");
1514 breakpoints_inserted = 0;
1516 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1517 Delete any breakpoint that is to be deleted at the next stop. */
1519 breakpoint_auto_delete (stop_bpstat);
1521 /* If an auto-display called a function and that got a signal,
1522 delete that auto-display to avoid an infinite recursion. */
1524 if (stopped_by_random_signal)
1525 disable_current_display ();
1527 if (step_multi && stop_step)
1530 target_terminal_ours ();
1532 if (!target_has_stack)
1535 /* Select innermost stack frame except on return from a stack dummy routine,
1536 or if the program has exited. Print it without a level number if
1537 we have changed functions or hit a breakpoint. Print source line
1539 if (!stop_stack_dummy)
1541 select_frame (get_current_frame (), 0);
1543 if (stop_print_frame)
1547 source_only = bpstat_print (stop_bpstat);
1548 source_only = source_only ||
1550 && step_frame_address == stop_frame_address
1551 && step_start_function == find_pc_function (stop_pc));
1553 print_stack_frame (selected_frame, -1, source_only? -1: 1);
1555 /* Display the auto-display expressions. */
1560 /* Save the function value return registers, if we care.
1561 We might be about to restore their previous contents. */
1562 if (proceed_to_finish)
1563 read_register_bytes (0, stop_registers, REGISTER_BYTES);
1565 if (stop_stack_dummy)
1567 /* Pop the empty frame that contains the stack dummy.
1568 POP_FRAME ends with a setting of the current frame, so we
1569 can use that next. */
1571 select_frame (get_current_frame (), 0);
1576 insert_step_breakpoint ()
1578 if (step_resume_break_address && !step_resume_break_duplicate)
1579 target_insert_breakpoint (step_resume_break_address,
1580 step_resume_break_shadow);
1584 remove_step_breakpoint ()
1586 if (step_resume_break_address && !step_resume_break_duplicate)
1587 target_remove_breakpoint (step_resume_break_address,
1588 step_resume_break_shadow);
1591 int signal_stop_state (signo)
1594 return ((signo >= 0 && signo < NSIG) ? signal_stop[signo] : 0);
1597 int signal_print_state (signo)
1600 return ((signo >= 0 && signo < NSIG) ? signal_print[signo] : 0);
1603 int signal_pass_state (signo)
1606 return ((signo >= 0 && signo < NSIG) ? signal_program[signo] : 0);
1612 printf_filtered ("Signal\t\tStop\tPrint\tPass to program\tDescription\n");
1616 sig_print_info (number)
1621 if ((name = strsigno (number)) == NULL)
1622 printf_filtered ("%d\t\t", number);
1624 printf_filtered ("%s (%d)\t", name, number);
1625 printf_filtered ("%s\t", signal_stop[number] ? "Yes" : "No");
1626 printf_filtered ("%s\t", signal_print[number] ? "Yes" : "No");
1627 printf_filtered ("%s\t\t", signal_program[number] ? "Yes" : "No");
1628 printf_filtered ("%s\n", safe_strsignal (number));
1631 /* Specify how various signals in the inferior should be handled. */
1634 handle_command (args, from_tty)
1639 int digits, wordlen;
1640 int sigfirst, signum, siglast;
1643 unsigned char *sigs;
1644 struct cleanup *old_chain;
1648 error_no_arg ("signal to handle");
1651 /* Allocate and zero an array of flags for which signals to handle. */
1653 nsigs = signo_max () + 1;
1654 sigs = (unsigned char *) alloca (nsigs);
1655 memset (sigs, 0, nsigs);
1657 /* Break the command line up into args. */
1659 argv = buildargv (args);
1664 old_chain = make_cleanup (freeargv, (char *) argv);
1666 /* Walk through the args, looking for signal numbers, signal names, and
1667 actions. Signal numbers and signal names may be interspersed with
1668 actions, with the actions being performed for all signals cumulatively
1669 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
1671 while (*argv != NULL)
1673 wordlen = strlen (*argv);
1674 for (digits = 0; isdigit ((*argv)[digits]); digits++) {;}
1676 sigfirst = siglast = -1;
1678 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
1680 /* Apply action to all signals except those used by the
1681 debugger. Silently skip those. */
1684 siglast = nsigs - 1;
1686 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
1688 SET_SIGS (nsigs, sigs, signal_stop);
1689 SET_SIGS (nsigs, sigs, signal_print);
1691 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
1693 UNSET_SIGS (nsigs, sigs, signal_program);
1695 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
1697 SET_SIGS (nsigs, sigs, signal_print);
1699 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
1701 SET_SIGS (nsigs, sigs, signal_program);
1703 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
1705 UNSET_SIGS (nsigs, sigs, signal_stop);
1707 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
1709 SET_SIGS (nsigs, sigs, signal_program);
1711 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
1713 UNSET_SIGS (nsigs, sigs, signal_print);
1714 UNSET_SIGS (nsigs, sigs, signal_stop);
1716 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
1718 UNSET_SIGS (nsigs, sigs, signal_program);
1720 else if (digits > 0)
1722 sigfirst = siglast = atoi (*argv);
1723 if ((*argv)[digits] == '-')
1725 siglast = atoi ((*argv) + digits + 1);
1727 if (sigfirst > siglast)
1729 /* Bet he didn't figure we'd think of this case... */
1734 if (sigfirst < 0 || sigfirst >= nsigs)
1736 error ("Signal %d not in range 0-%d", sigfirst, nsigs - 1);
1738 if (siglast < 0 || siglast >= nsigs)
1740 error ("Signal %d not in range 0-%d", siglast, nsigs - 1);
1743 else if ((signum = strtosigno (*argv)) != 0)
1745 sigfirst = siglast = signum;
1749 /* Not a number and not a recognized flag word => complain. */
1750 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
1753 /* If any signal numbers or symbol names were found, set flags for
1754 which signals to apply actions to. */
1756 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
1762 if (!allsigs && !sigs[signum])
1764 if (query ("%s is used by the debugger.\nAre you sure you want to change it? ", strsigno (signum)))
1770 printf ("Not confirmed, unchanged.\n");
1784 NOTICE_SIGNAL_HANDLING_CHANGE;
1788 /* Show the results. */
1789 sig_print_header ();
1790 for (signum = 0; signum < nsigs; signum++)
1794 sig_print_info (signum);
1799 do_cleanups (old_chain);
1802 /* Print current contents of the tables set by the handle command. */
1805 signals_info (signum_exp, from_tty)
1810 sig_print_header ();
1814 /* First see if this is a symbol name. */
1815 i = strtosigno (signum_exp);
1818 /* Nope, maybe it's an address which evaluates to a signal
1820 i = parse_and_eval_address (signum_exp);
1821 if (i >= NSIG || i < 0)
1822 error ("Signal number out of bounds.");
1828 printf_filtered ("\n");
1829 for (i = 0; i < NSIG; i++)
1836 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
1839 /* Save all of the information associated with the inferior<==>gdb
1840 connection. INF_STATUS is a pointer to a "struct inferior_status"
1841 (defined in inferior.h). */
1844 save_inferior_status (inf_status, restore_stack_info)
1845 struct inferior_status *inf_status;
1846 int restore_stack_info;
1848 inf_status->pc_changed = pc_changed;
1849 inf_status->stop_signal = stop_signal;
1850 inf_status->stop_pc = stop_pc;
1851 inf_status->stop_frame_address = stop_frame_address;
1852 inf_status->stop_step = stop_step;
1853 inf_status->stop_stack_dummy = stop_stack_dummy;
1854 inf_status->stopped_by_random_signal = stopped_by_random_signal;
1855 inf_status->trap_expected = trap_expected;
1856 inf_status->step_range_start = step_range_start;
1857 inf_status->step_range_end = step_range_end;
1858 inf_status->step_frame_address = step_frame_address;
1859 inf_status->step_over_calls = step_over_calls;
1860 inf_status->step_resume_break_address = step_resume_break_address;
1861 inf_status->stop_after_trap = stop_after_trap;
1862 inf_status->stop_soon_quietly = stop_soon_quietly;
1863 /* Save original bpstat chain here; replace it with copy of chain.
1864 If caller's caller is walking the chain, they'll be happier if we
1865 hand them back the original chain when restore_i_s is called. */
1866 inf_status->stop_bpstat = stop_bpstat;
1867 stop_bpstat = bpstat_copy (stop_bpstat);
1868 inf_status->breakpoint_proceeded = breakpoint_proceeded;
1869 inf_status->restore_stack_info = restore_stack_info;
1870 inf_status->proceed_to_finish = proceed_to_finish;
1872 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
1874 record_selected_frame (&(inf_status->selected_frame_address),
1875 &(inf_status->selected_level));
1880 restore_inferior_status (inf_status)
1881 struct inferior_status *inf_status;
1884 int level = inf_status->selected_level;
1886 pc_changed = inf_status->pc_changed;
1887 stop_signal = inf_status->stop_signal;
1888 stop_pc = inf_status->stop_pc;
1889 stop_frame_address = inf_status->stop_frame_address;
1890 stop_step = inf_status->stop_step;
1891 stop_stack_dummy = inf_status->stop_stack_dummy;
1892 stopped_by_random_signal = inf_status->stopped_by_random_signal;
1893 trap_expected = inf_status->trap_expected;
1894 step_range_start = inf_status->step_range_start;
1895 step_range_end = inf_status->step_range_end;
1896 step_frame_address = inf_status->step_frame_address;
1897 step_over_calls = inf_status->step_over_calls;
1898 step_resume_break_address = inf_status->step_resume_break_address;
1899 stop_after_trap = inf_status->stop_after_trap;
1900 stop_soon_quietly = inf_status->stop_soon_quietly;
1901 bpstat_clear (&stop_bpstat);
1902 stop_bpstat = inf_status->stop_bpstat;
1903 breakpoint_proceeded = inf_status->breakpoint_proceeded;
1904 proceed_to_finish = inf_status->proceed_to_finish;
1906 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
1908 /* The inferior can be gone if the user types "print exit(0)"
1909 (and perhaps other times). */
1910 if (target_has_stack && inf_status->restore_stack_info)
1912 fid = find_relative_frame (get_current_frame (),
1915 /* If inf_status->selected_frame_address is NULL, there was no
1916 previously selected frame. */
1918 FRAME_FP (fid) != inf_status->selected_frame_address ||
1922 /* I'm not sure this error message is a good idea. I have
1923 only seen it occur after "Can't continue previously
1924 requested operation" (we get called from do_cleanups), in
1925 which case it just adds insult to injury (one confusing
1926 error message after another. Besides which, does the
1927 user really care if we can't restore the previously
1929 fprintf (stderr, "Unable to restore previously selected frame.\n");
1931 select_frame (get_current_frame (), 0);
1935 select_frame (fid, inf_status->selected_level);
1941 _initialize_infrun ()
1944 register int numsigs;
1946 add_info ("signals", signals_info,
1947 "What debugger does when program gets various signals.\n\
1948 Specify a signal number as argument to print info on that signal only.");
1949 add_info_alias ("handle", "signals", 0);
1951 add_com ("handle", class_run, handle_command,
1952 "Specify how to handle a signal.\n\
1953 Args are signal numbers and actions to apply to those signals.\n\
1954 Signal numbers may be numeric (ex. 11) or symbolic (ex. SIGSEGV).\n\
1955 Numeric ranges may be specified with the form LOW-HIGH (ex. 14-21).\n\
1956 The special arg \"all\" is recognized to mean all signals except those\n\
1957 used by the debugger, typically SIGTRAP and SIGINT.\n\
1958 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
1959 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
1960 Stop means reenter debugger if this signal happens (implies print).\n\
1961 Print means print a message if this signal happens.\n\
1962 Pass means let program see this signal; otherwise program doesn't know.\n\
1963 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
1964 Pass and Stop may be combined.");
1966 numsigs = signo_max () + 1;
1967 signal_stop = (unsigned char *)
1968 xmalloc (sizeof (signal_stop[0]) * numsigs);
1969 signal_print = (unsigned char *)
1970 xmalloc (sizeof (signal_print[0]) * numsigs);
1971 signal_program = (unsigned char *)
1972 xmalloc (sizeof (signal_program[0]) * numsigs);
1973 for (i = 0; i < numsigs; i++)
1976 signal_print[i] = 1;
1977 signal_program[i] = 1;
1980 /* Signals caused by debugger's own actions
1981 should not be given to the program afterwards. */
1982 signal_program[SIGTRAP] = 0;
1983 signal_program[SIGINT] = 0;
1985 /* Signals that are not errors should not normally enter the debugger. */
1987 signal_stop[SIGALRM] = 0;
1988 signal_print[SIGALRM] = 0;
1989 #endif /* SIGALRM */
1991 signal_stop[SIGVTALRM] = 0;
1992 signal_print[SIGVTALRM] = 0;
1993 #endif /* SIGVTALRM */
1995 signal_stop[SIGPROF] = 0;
1996 signal_print[SIGPROF] = 0;
1997 #endif /* SIGPROF */
1999 signal_stop[SIGCHLD] = 0;
2000 signal_print[SIGCHLD] = 0;
2001 #endif /* SIGCHLD */
2003 signal_stop[SIGCLD] = 0;
2004 signal_print[SIGCLD] = 0;
2007 signal_stop[SIGIO] = 0;
2008 signal_print[SIGIO] = 0;
2011 signal_stop[SIGURG] = 0;
2012 signal_print[SIGURG] = 0;