* infun.c (resume, resume_cleanups): New functions.
[deliverable/binutils-gdb.git] / gdb / infrun.c
1 /* Start (run) and stop the inferior process, for GDB.
2 Copyright (C) 1986, 1987, 1988, 1989, 1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 GDB 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 1, or (at your option)
9 any later version.
10
11 GDB 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.
15
16 You should have received a copy of the GNU General Public License
17 along with GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
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:
23
24 Current and previous (just before this step) pc.
25 Current and previous sp.
26 Current and previous start of current function.
27
28 If the start's of the functions don't match, then
29
30 a) We did a subroutine call.
31
32 In this case, the pc will be at the beginning of a function.
33
34 b) We did a subroutine return.
35
36 Otherwise.
37
38 c) We did a longjmp.
39
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.
49
50 Acts like a subroutine return. I can handle that with no problem
51 at all.
52
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.
57
58 -->If the beginnings of the current and previous function do match,
59 either:
60
61 a) We just did a recursive call.
62
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:
79
80 m68k: Call changes stack pointer. Regular jumps don't.
81
82 sparc: Recursive calls must have frames and therefor,
83 prologues.
84
85 vax: All calls have frames and hence change the
86 stack pointer.
87
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
93 lookout.
94
95 c) We did a jump within a function. We assume that this is
96 true if we didn't do a recursive call.
97
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.
102
103 #if 0
104 We skip this; it causes more problems than it's worth.
105 #ifdef SUN4_COMPILER_FEATURE
106 We do a special ifdef for the sun 4, forcing it to single step
107 into calls which don't have prologues. This means that we can't
108 nexti over leaf nodes, we can probably next over them (since they
109 won't have debugging symbols, usually), and we can next out of
110 functions returning structures (with a "call .stret4" at the end).
111 #endif
112 #endif
113 */
114
115
116
117
118
119 #include <stdio.h>
120 #include <string.h>
121 #include "defs.h"
122 #include "param.h"
123 #include "symtab.h"
124 #include "frame.h"
125 #include "inferior.h"
126 #include "breakpoint.h"
127 #include "wait.h"
128 #include "gdbcore.h"
129 #include "signame.h"
130 #include "command.h"
131 #include "terminal.h" /* For #ifdef TIOCGPGRP and new_tty */
132 #include "target.h"
133
134 #include <signal.h>
135
136 /* unistd.h is needed to #define X_OK */
137 #ifdef USG
138 #include <unistd.h>
139 #else
140 #include <sys/file.h>
141 #endif
142
143 #ifdef SET_STACK_LIMIT_HUGE
144 extern int original_stack_limit;
145 #endif /* SET_STACK_LIMIT_HUGE */
146
147 /* Required by <sys/user.h>. */
148 #include <sys/types.h>
149 /* Required by <sys/user.h>, at least on system V. */
150 #include <sys/dir.h>
151 /* Needed by IN_SIGTRAMP on some machines (e.g. vax). */
152 #include <sys/param.h>
153 /* Needed by IN_SIGTRAMP on some machines (e.g. vax). */
154 #include <sys/user.h>
155
156 extern char *getenv ();
157
158 extern struct target_ops child_ops; /* In inftarg.c */
159
160 /* Copy of inferior_io_terminal when inferior was last started. */
161
162 extern char *inferior_thisrun_terminal;
163
164
165 /* Sigtramp is a routine that the kernel calls (which then calls the
166 signal handler). On most machines it is a library routine that
167 is linked into the executable.
168
169 This macro, given a program counter value and the name of the
170 function in which that PC resides (which can be null if the
171 name is not known), returns nonzero if the PC and name show
172 that we are in sigtramp.
173
174 On most machines just see if the name is sigtramp (and if we have
175 no name, assume we are not in sigtramp). */
176 #if !defined (IN_SIGTRAMP)
177 #define IN_SIGTRAMP(pc, name) \
178 name && !strcmp ("_sigtramp", name)
179 #endif
180
181 /* Tables of how to react to signals; the user sets them. */
182
183 static char signal_stop[NSIG];
184 static char signal_print[NSIG];
185 static char signal_program[NSIG];
186
187 /* Nonzero if breakpoints are now inserted in the inferior. */
188 /* Nonstatic for initialization during xxx_create_inferior. FIXME. */
189
190 /*static*/ int breakpoints_inserted;
191
192 /* Function inferior was in as of last step command. */
193
194 static struct symbol *step_start_function;
195
196 /* Nonzero => address for special breakpoint for resuming stepping. */
197
198 static CORE_ADDR step_resume_break_address;
199
200 /* Pointer to orig contents of the byte where the special breakpoint is. */
201
202 static char step_resume_break_shadow[BREAKPOINT_MAX];
203
204 /* Nonzero means the special breakpoint is a duplicate
205 so it has not itself been inserted. */
206
207 static int step_resume_break_duplicate;
208
209 /* Nonzero if we are expecting a trace trap and should proceed from it. */
210
211 static int trap_expected;
212
213 /* Nonzero if the next time we try to continue the inferior, it will
214 step one instruction and generate a spurious trace trap.
215 This is used to compensate for a bug in HP-UX. */
216
217 static int trap_expected_after_continue;
218
219 /* Nonzero means expecting a trace trap
220 and should stop the inferior and return silently when it happens. */
221
222 int stop_after_trap;
223
224 /* Nonzero means expecting a trap and caller will handle it themselves.
225 It is used after attach, due to attaching to a process;
226 when running in the shell before the child program has been exec'd;
227 and when running some kinds of remote stuff (FIXME?). */
228
229 int stop_soon_quietly;
230
231 /* Nonzero if pc has been changed by the debugger
232 since the inferior stopped. */
233
234 int pc_changed;
235
236 /* Nonzero if proceed is being used for a "finish" command or a similar
237 situation when stop_registers should be saved. */
238
239 int proceed_to_finish;
240
241 /* Save register contents here when about to pop a stack dummy frame,
242 if-and-only-if proceed_to_finish is set.
243 Thus this contains the return value from the called function (assuming
244 values are returned in a register). */
245
246 char stop_registers[REGISTER_BYTES];
247
248 /* Nonzero if program stopped due to error trying to insert breakpoints. */
249
250 static int breakpoints_failed;
251
252 /* Nonzero after stop if current stack frame should be printed. */
253
254 static int stop_print_frame;
255
256 #ifdef NO_SINGLE_STEP
257 extern int one_stepped; /* From machine dependent code */
258 extern void single_step (); /* Same. */
259 #endif /* NO_SINGLE_STEP */
260
261 static void insert_step_breakpoint ();
262 static void remove_step_breakpoint ();
263 /*static*/ void wait_for_inferior ();
264 void init_wait_for_inferior ();
265 void normal_stop ();
266
267 \f
268 /* Things to clean up if we QUIT out of resume (). */
269 static void
270 resume_cleanups (arg)
271 int arg;
272 {
273 normal_stop ();
274 }
275
276 /* Resume the inferior, but allow a QUIT. This is useful if the user
277 wants to interrupt some lengthy single-stepping operation
278 (for child processes, the SIGINT goes to the inferior, and so
279 we get a SIGINT random_signal, but for remote debugging and perhaps
280 other targets, that's not true).
281
282 STEP nonzero if we should step (zero to continue instead).
283 SIG is the signal to give the inferior (zero for none). */
284 static void
285 resume (step, sig)
286 int step;
287 int sig;
288 {
289 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
290 QUIT;
291 target_resume (step, sig);
292 discard_cleanups (old_cleanups);
293 }
294
295 \f
296 /* Clear out all variables saying what to do when inferior is continued.
297 First do this, then set the ones you want, then call `proceed'. */
298
299 void
300 clear_proceed_status ()
301 {
302 trap_expected = 0;
303 step_range_start = 0;
304 step_range_end = 0;
305 step_frame_address = 0;
306 step_over_calls = -1;
307 step_resume_break_address = 0;
308 stop_after_trap = 0;
309 stop_soon_quietly = 0;
310 proceed_to_finish = 0;
311 breakpoint_proceeded = 1; /* We're about to proceed... */
312
313 /* Discard any remaining commands or status from previous stop. */
314 bpstat_clear (&stop_bpstat);
315 }
316
317 /* Basic routine for continuing the program in various fashions.
318
319 ADDR is the address to resume at, or -1 for resume where stopped.
320 SIGGNAL is the signal to give it, or 0 for none,
321 or -1 for act according to how it stopped.
322 STEP is nonzero if should trap after one instruction.
323 -1 means return after that and print nothing.
324 You should probably set various step_... variables
325 before calling here, if you are stepping.
326
327 You should call clear_proceed_status before calling proceed. */
328
329 void
330 proceed (addr, siggnal, step)
331 CORE_ADDR addr;
332 int siggnal;
333 int step;
334 {
335 int oneproc = 0;
336
337 if (step > 0)
338 step_start_function = find_pc_function (read_pc ());
339 if (step < 0)
340 stop_after_trap = 1;
341
342 if (addr == -1)
343 {
344 /* If there is a breakpoint at the address we will resume at,
345 step one instruction before inserting breakpoints
346 so that we do not stop right away. */
347
348 if (!pc_changed && breakpoint_here_p (read_pc ()))
349 oneproc = 1;
350 }
351 else
352 {
353 write_register (PC_REGNUM, addr);
354 #ifdef NPC_REGNUM
355 write_register (NPC_REGNUM, addr + 4);
356 #ifdef NNPC_REGNUM
357 write_register (NNPC_REGNUM, addr + 8);
358 #endif
359 #endif
360 }
361
362 if (trap_expected_after_continue)
363 {
364 /* If (step == 0), a trap will be automatically generated after
365 the first instruction is executed. Force step one
366 instruction to clear this condition. This should not occur
367 if step is nonzero, but it is harmless in that case. */
368 oneproc = 1;
369 trap_expected_after_continue = 0;
370 }
371
372 if (oneproc)
373 /* We will get a trace trap after one instruction.
374 Continue it automatically and insert breakpoints then. */
375 trap_expected = 1;
376 else
377 {
378 int temp = insert_breakpoints ();
379 if (temp)
380 {
381 print_sys_errmsg ("ptrace", temp);
382 error ("Cannot insert breakpoints.\n\
383 The same program may be running in another process.");
384 }
385 breakpoints_inserted = 1;
386 }
387
388 /* Install inferior's terminal modes. */
389 target_terminal_inferior ();
390
391 if (siggnal >= 0)
392 stop_signal = siggnal;
393 /* If this signal should not be seen by program,
394 give it zero. Used for debugging signals. */
395 else if (stop_signal < NSIG && !signal_program[stop_signal])
396 stop_signal= 0;
397
398 /* Handle any optimized stores to the inferior NOW... */
399 #ifdef DO_DEFERRED_STORES
400 DO_DEFERRED_STORES;
401 #endif
402
403 /* Resume inferior. */
404 resume (oneproc || step || bpstat_should_step (), stop_signal);
405
406 /* Wait for it to stop (if not standalone)
407 and in any case decode why it stopped, and act accordingly. */
408
409 wait_for_inferior ();
410 normal_stop ();
411 }
412
413 #if 0
414 /* This might be useful (not sure), but isn't currently used. See also
415 write_pc(). */
416 /* Writing the inferior pc as a register calls this function
417 to inform infrun that the pc has been set in the debugger. */
418
419 void
420 writing_pc (val)
421 CORE_ADDR val;
422 {
423 stop_pc = val;
424 pc_changed = 1;
425 }
426 #endif
427
428 /* Record the pc and sp of the program the last time it stopped.
429 These are just used internally by wait_for_inferior, but need
430 to be preserved over calls to it and cleared when the inferior
431 is started. */
432 static CORE_ADDR prev_pc;
433 static CORE_ADDR prev_sp;
434 static CORE_ADDR prev_func_start;
435 static char *prev_func_name;
436
437 \f
438 /* Start an inferior Unix child process and sets inferior_pid to its pid.
439 EXEC_FILE is the file to run.
440 ALLARGS is a string containing the arguments to the program.
441 ENV is the environment vector to pass. Errors reported with error(). */
442
443 #ifndef SHELL_FILE
444 #define SHELL_FILE "/bin/sh"
445 #endif
446
447 void
448 child_create_inferior (exec_file, allargs, env)
449 char *exec_file;
450 char *allargs;
451 char **env;
452 {
453 int pid;
454 char *shell_command;
455 extern int sys_nerr;
456 extern char *sys_errlist[];
457 char *shell_file;
458 static char default_shell_file[] = SHELL_FILE;
459 int len;
460 int pending_execs;
461 /* Set debug_fork then attach to the child while it sleeps, to debug. */
462 static int debug_fork = 0;
463 /* This is set to the result of setpgrp, which if vforked, will be visible
464 to you in the parent process. It's only used by humans for debugging. */
465 static int debug_setpgrp = 657473;
466
467 /* The user might want tilde-expansion, and in general probably wants
468 the program to behave the same way as if run from
469 his/her favorite shell. So we let the shell run it for us.
470 FIXME, this should probably search the local environment (as
471 modified by the setenv command), not the env gdb inherited. */
472 shell_file = getenv ("SHELL");
473 if (shell_file == NULL)
474 shell_file = default_shell_file;
475
476 len = 5 + strlen (exec_file) + 1 + strlen (allargs) + 1 + /*slop*/ 10;
477 /* If desired, concat something onto the front of ALLARGS.
478 SHELL_COMMAND is the result. */
479 #ifdef SHELL_COMMAND_CONCAT
480 shell_command = (char *) alloca (strlen (SHELL_COMMAND_CONCAT) + len);
481 strcpy (shell_command, SHELL_COMMAND_CONCAT);
482 #else
483 shell_command = (char *) alloca (len);
484 shell_command[0] = '\0';
485 #endif
486 strcat (shell_command, "exec ");
487 strcat (shell_command, exec_file);
488 strcat (shell_command, " ");
489 strcat (shell_command, allargs);
490
491 /* exec is said to fail if the executable is open. */
492 close_exec_file ();
493
494 #if defined(USG) && !defined(HAVE_VFORK)
495 pid = fork ();
496 #else
497 if (debug_fork)
498 pid = fork ();
499 else
500 pid = vfork ();
501 #endif
502
503 if (pid < 0)
504 perror_with_name ("vfork");
505
506 if (pid == 0)
507 {
508 if (debug_fork)
509 sleep (debug_fork);
510
511 #ifdef TIOCGPGRP
512 /* Run inferior in a separate process group. */
513 debug_setpgrp = setpgrp (getpid (), getpid ());
514 if (0 != debug_setpgrp)
515 perror("setpgrp failed in child");
516 #endif /* TIOCGPGRP */
517
518 #ifdef SET_STACK_LIMIT_HUGE
519 /* Reset the stack limit back to what it was. */
520 {
521 struct rlimit rlim;
522
523 getrlimit (RLIMIT_STACK, &rlim);
524 rlim.rlim_cur = original_stack_limit;
525 setrlimit (RLIMIT_STACK, &rlim);
526 }
527 #endif /* SET_STACK_LIMIT_HUGE */
528
529 /* Tell the terminal handling subsystem what tty we plan to run on;
530 it will now switch to that one if non-null. */
531
532 new_tty (inferior_io_terminal);
533
534 /* Changing the signal handlers for the inferior after
535 a vfork can also change them for the superior, so we don't mess
536 with signals here. See comments in
537 initialize_signals for how we get the right signal handlers
538 for the inferior. */
539
540 call_ptrace (0, 0, 0, 0); /* "Trace me, Dr. Memory!" */
541 execle (shell_file, shell_file, "-c", shell_command, (char *)0, env);
542
543 fprintf (stderr, "Cannot exec %s: %s.\n", shell_file,
544 errno < sys_nerr ? sys_errlist[errno] : "unknown error");
545 fflush (stderr);
546 _exit (0177);
547 }
548
549 /* Now that we have a child process, make it our target. */
550 push_target (&child_ops);
551
552 #ifdef CREATE_INFERIOR_HOOK
553 CREATE_INFERIOR_HOOK (pid);
554 #endif
555
556 /* The process was started by the fork that created it,
557 but it will have stopped one instruction after execing the shell.
558 Here we must get it up to actual execution of the real program. */
559
560 inferior_pid = pid; /* Needed for wait_for_inferior stuff below */
561
562 clear_proceed_status ();
563
564 #if defined (START_INFERIOR_HOOK)
565 START_INFERIOR_HOOK ();
566 #endif
567
568 /* We will get a trace trap after one instruction.
569 Continue it automatically. Eventually (after shell does an exec)
570 it will get another trace trap. Then insert breakpoints and continue. */
571
572 #ifdef START_INFERIOR_TRAPS_EXPECTED
573 pending_execs = START_INFERIOR_TRAPS_EXPECTED;
574 #else
575 pending_execs = 2;
576 #endif
577
578 init_wait_for_inferior ();
579
580 /* Set up the "saved terminal modes" of the inferior
581 based on what modes we are starting it with. */
582 target_terminal_init ();
583
584 /* Install inferior's terminal modes. */
585 target_terminal_inferior ();
586
587 while (1)
588 {
589 stop_soon_quietly = 1; /* Make wait_for_inferior be quiet */
590 wait_for_inferior ();
591 if (stop_signal != SIGTRAP)
592 {
593 /* Let shell child handle its own signals in its own way */
594 /* FIXME, what if child has exit()ed? Must exit loop somehow */
595 resume (0, stop_signal);
596 }
597 else
598 {
599 /* We handle SIGTRAP, however; it means child did an exec. */
600 if (0 == --pending_execs)
601 break;
602 resume (0, 0); /* Just make it go on */
603 }
604 }
605 stop_soon_quietly = 0;
606
607 /* Should this perhaps just be a "proceed" call? FIXME */
608 insert_step_breakpoint ();
609 breakpoints_failed = insert_breakpoints ();
610 if (!breakpoints_failed)
611 {
612 breakpoints_inserted = 1;
613 target_terminal_inferior();
614 /* Start the child program going on its first instruction, single-
615 stepping if we need to. */
616 resume (bpstat_should_step (), 0);
617 wait_for_inferior ();
618 normal_stop ();
619 }
620 }
621
622 /* Start remote-debugging of a machine over a serial link. */
623
624 void
625 start_remote ()
626 {
627 init_wait_for_inferior ();
628 clear_proceed_status ();
629 stop_soon_quietly = 1;
630 trap_expected = 0;
631 wait_for_inferior ();
632 normal_stop ();
633 }
634
635 /* Initialize static vars when a new inferior begins. */
636
637 void
638 init_wait_for_inferior ()
639 {
640 /* These are meaningless until the first time through wait_for_inferior. */
641 prev_pc = 0;
642 prev_sp = 0;
643 prev_func_start = 0;
644 prev_func_name = NULL;
645
646 trap_expected_after_continue = 0;
647 breakpoints_inserted = 0;
648 mark_breakpoints_out ();
649 stop_signal = 0; /* Don't confuse first call to proceed(). */
650 }
651
652
653 /* Attach to process PID, then initialize for debugging it
654 and wait for the trace-trap that results from attaching. */
655
656 void
657 child_attach (args, from_tty)
658 char *args;
659 int from_tty;
660 {
661 char *exec_file;
662 int pid;
663
664 dont_repeat();
665
666 if (!args)
667 error_no_arg ("process-id to attach");
668
669 #ifndef ATTACH_DETACH
670 error ("Can't attach to a process on this machine.");
671 #else
672 pid = atoi (args);
673
674 if (target_has_execution)
675 {
676 if (query ("A program is being debugged already. Kill it? "))
677 target_kill ((char *)0, from_tty);
678 else
679 error ("Inferior not killed.");
680 }
681
682 exec_file = (char *) get_exec_file (1);
683
684 if (from_tty)
685 {
686 printf ("Attaching program: %s pid %d\n",
687 exec_file, pid);
688 fflush (stdout);
689 }
690
691 attach (pid);
692 inferior_pid = pid;
693 push_target (&child_ops);
694
695 mark_breakpoints_out ();
696 target_terminal_init ();
697 clear_proceed_status ();
698 stop_soon_quietly = 1;
699 /*proceed (-1, 0, -2);*/
700 target_terminal_inferior ();
701 wait_for_inferior ();
702 normal_stop ();
703 #endif /* ATTACH_DETACH */
704 }
705 \f
706 /* Wait for control to return from inferior to debugger.
707 If inferior gets a signal, we may decide to start it up again
708 instead of returning. That is why there is a loop in this function.
709 When this function actually returns it means the inferior
710 should be left stopped and GDB should read more commands. */
711
712 void
713 wait_for_inferior ()
714 {
715 WAITTYPE w;
716 int another_trap;
717 int random_signal;
718 CORE_ADDR stop_sp;
719 CORE_ADDR stop_func_start;
720 char *stop_func_name;
721 CORE_ADDR prologue_pc;
722 int stop_step_resume_break;
723 struct symtab_and_line sal;
724 int remove_breakpoints_on_following_step = 0;
725
726 #if 0
727 /* This no longer works now that read_register is lazy;
728 it might try to ptrace when the process is not stopped. */
729 prev_pc = read_pc ();
730 (void) find_pc_partial_function (prev_pc, &prev_func_name,
731 &prev_func_start);
732 prev_func_start += FUNCTION_START_OFFSET;
733 prev_sp = read_register (SP_REGNUM);
734 #endif /* 0 */
735
736 while (1)
737 {
738 /* Clean up saved state that will become invalid. */
739 pc_changed = 0;
740 flush_cached_frames ();
741 registers_changed ();
742
743 target_wait (&w);
744
745 /* See if the process still exists; clean up if it doesn't. */
746 if (WIFEXITED (w))
747 {
748 target_terminal_ours (); /* Must do this before mourn anyway */
749 if (WEXITSTATUS (w))
750 printf ("\nProgram exited with code 0%o.\n",
751 (unsigned int)WEXITSTATUS (w));
752 else
753 if (!batch_mode())
754 printf ("\nProgram exited normally.\n");
755 fflush (stdout);
756 target_mourn_inferior ();
757 #ifdef NO_SINGLE_STEP
758 one_stepped = 0;
759 #endif
760 stop_print_frame = 0;
761 break;
762 }
763 else if (!WIFSTOPPED (w))
764 {
765 stop_print_frame = 0;
766 stop_signal = WTERMSIG (w);
767 target_terminal_ours (); /* Must do this before mourn anyway */
768 target_kill ((char *)0, 0); /* kill mourns as well */
769 #ifdef PRINT_RANDOM_SIGNAL
770 printf ("\nProgram terminated: ");
771 PRINT_RANDOM_SIGNAL (stop_signal);
772 #else
773 printf ("\nProgram terminated with signal %d, %s\n",
774 stop_signal,
775 stop_signal < NSIG
776 ? sys_siglist[stop_signal]
777 : "(undocumented)");
778 #endif
779 printf ("The inferior process no longer exists.\n");
780 fflush (stdout);
781 #ifdef NO_SINGLE_STEP
782 one_stepped = 0;
783 #endif
784 break;
785 }
786
787 #ifdef NO_SINGLE_STEP
788 if (one_stepped)
789 single_step (0); /* This actually cleans up the ss */
790 #endif /* NO_SINGLE_STEP */
791
792 stop_pc = read_pc ();
793 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
794 read_pc ()));
795
796 stop_frame_address = FRAME_FP (get_current_frame ());
797 stop_sp = read_register (SP_REGNUM);
798 stop_func_start = 0;
799 stop_func_name = 0;
800 /* Don't care about return value; stop_func_start and stop_func_name
801 will both be 0 if it doesn't work. */
802 (void) find_pc_partial_function (stop_pc, &stop_func_name,
803 &stop_func_start);
804 stop_func_start += FUNCTION_START_OFFSET;
805 another_trap = 0;
806 bpstat_clear (&stop_bpstat);
807 stop_step = 0;
808 stop_stack_dummy = 0;
809 stop_print_frame = 1;
810 stop_step_resume_break = 0;
811 random_signal = 0;
812 stopped_by_random_signal = 0;
813 breakpoints_failed = 0;
814
815 /* Look at the cause of the stop, and decide what to do.
816 The alternatives are:
817 1) break; to really stop and return to the debugger,
818 2) drop through to start up again
819 (set another_trap to 1 to single step once)
820 3) set random_signal to 1, and the decision between 1 and 2
821 will be made according to the signal handling tables. */
822
823 stop_signal = WSTOPSIG (w);
824
825 /* First, distinguish signals caused by the debugger from signals
826 that have to do with the program's own actions.
827 Note that breakpoint insns may cause SIGTRAP or SIGILL
828 or SIGEMT, depending on the operating system version.
829 Here we detect when a SIGILL or SIGEMT is really a breakpoint
830 and change it to SIGTRAP. */
831
832 if (stop_signal == SIGTRAP
833 || (breakpoints_inserted &&
834 (stop_signal == SIGILL
835 || stop_signal == SIGEMT))
836 || stop_soon_quietly)
837 {
838 if (stop_signal == SIGTRAP && stop_after_trap)
839 {
840 stop_print_frame = 0;
841 break;
842 }
843 if (stop_soon_quietly)
844 break;
845
846 /* Don't even think about breakpoints
847 if just proceeded over a breakpoint.
848
849 However, if we are trying to proceed over a breakpoint
850 and end up in sigtramp, then step_resume_break_address
851 will be set and we should check whether we've hit the
852 step breakpoint. */
853 if (stop_signal == SIGTRAP && trap_expected
854 && step_resume_break_address == NULL)
855 bpstat_clear (&stop_bpstat);
856 else
857 {
858 /* See if there is a breakpoint at the current PC. */
859 #if DECR_PC_AFTER_BREAK
860 /* Notice the case of stepping through a jump
861 that leads just after a breakpoint.
862 Don't confuse that with hitting the breakpoint.
863 What we check for is that 1) stepping is going on
864 and 2) the pc before the last insn does not match
865 the address of the breakpoint before the current pc. */
866 if (!(prev_pc != stop_pc - DECR_PC_AFTER_BREAK
867 && step_range_end && !step_resume_break_address))
868 #endif /* DECR_PC_AFTER_BREAK not zero */
869 {
870 /* See if we stopped at the special breakpoint for
871 stepping over a subroutine call. If both are zero,
872 this wasn't the reason for the stop. */
873 if (stop_pc - DECR_PC_AFTER_BREAK
874 == step_resume_break_address
875 && step_resume_break_address)
876 {
877 stop_step_resume_break = 1;
878 if (DECR_PC_AFTER_BREAK)
879 {
880 stop_pc -= DECR_PC_AFTER_BREAK;
881 write_register (PC_REGNUM, stop_pc);
882 pc_changed = 0;
883 }
884 }
885 else
886 {
887 stop_bpstat =
888 bpstat_stop_status (&stop_pc, stop_frame_address);
889 /* Following in case break condition called a
890 function. */
891 stop_print_frame = 1;
892 }
893 }
894 }
895
896 if (stop_signal == SIGTRAP)
897 random_signal
898 = !(bpstat_explains_signal (stop_bpstat)
899 || trap_expected
900 || stop_step_resume_break
901 || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
902 || (step_range_end && !step_resume_break_address));
903 else
904 {
905 random_signal
906 = !(bpstat_explains_signal (stop_bpstat)
907 || stop_step_resume_break
908 /* End of a stack dummy. Some systems (e.g. Sony
909 news) give another signal besides SIGTRAP,
910 so check here as well as above. */
911 || (stop_sp INNER_THAN stop_pc
912 && stop_pc INNER_THAN stop_frame_address)
913 );
914 if (!random_signal)
915 stop_signal = SIGTRAP;
916 }
917 }
918 else
919 random_signal = 1;
920
921 /* For the program's own signals, act according to
922 the signal handling tables. */
923
924 if (random_signal)
925 {
926 /* Signal not for debugging purposes. */
927 int printed = 0;
928
929 stopped_by_random_signal = 1;
930
931 if (stop_signal >= NSIG
932 || signal_print[stop_signal])
933 {
934 printed = 1;
935 target_terminal_ours_for_output ();
936 #ifdef PRINT_RANDOM_SIGNAL
937 PRINT_RANDOM_SIGNAL (stop_signal);
938 #else
939 printf ("\nProgram received signal %d, %s\n",
940 stop_signal,
941 stop_signal < NSIG
942 ? sys_siglist[stop_signal]
943 : "(undocumented)");
944 #endif /* PRINT_RANDOM_SIGNAL */
945 fflush (stdout);
946 }
947 if (stop_signal >= NSIG
948 || signal_stop[stop_signal])
949 break;
950 /* If not going to stop, give terminal back
951 if we took it away. */
952 else if (printed)
953 target_terminal_inferior ();
954 }
955
956 /* Handle cases caused by hitting a breakpoint. */
957
958 if (!random_signal
959 && (bpstat_explains_signal (stop_bpstat) || stop_step_resume_break))
960 {
961 /* Does a breakpoint want us to stop? */
962 if (bpstat_stop (stop_bpstat))
963 {
964 stop_print_frame = bpstat_should_print (stop_bpstat);
965 break;
966 }
967 /* But if we have hit the step-resumption breakpoint,
968 remove it. It has done its job getting us here.
969 The sp test is to make sure that we don't get hung
970 up in recursive calls in functions without frame
971 pointers. If the stack pointer isn't outside of
972 where the breakpoint was set (within a routine to be
973 stepped over), we're in the middle of a recursive
974 call. Not true for reg window machines (sparc)
975 because the must change frames to call things and
976 the stack pointer doesn't have to change if it
977 the bp was set in a routine without a frame (pc can
978 be stored in some other window).
979
980 The removal of the sp test is to allow calls to
981 alloca. Nasty things were happening. Oh, well,
982 gdb can only handle one level deep of lack of
983 frame pointer. */
984 if (stop_step_resume_break
985 && (step_frame_address == 0
986 || (stop_frame_address == step_frame_address)))
987 {
988 remove_step_breakpoint ();
989 step_resume_break_address = 0;
990
991 /* If were waiting for a trap, hitting the step_resume_break
992 doesn't count as getting it. */
993 if (trap_expected)
994 another_trap = 1;
995 }
996 /* Otherwise, must remove breakpoints and single-step
997 to get us past the one we hit. */
998 else
999 {
1000 remove_breakpoints ();
1001 remove_step_breakpoint ();
1002 breakpoints_inserted = 0;
1003 another_trap = 1;
1004 }
1005
1006 /* We come here if we hit a breakpoint but should not
1007 stop for it. Possibly we also were stepping
1008 and should stop for that. So fall through and
1009 test for stepping. But, if not stepping,
1010 do not stop. */
1011 }
1012
1013 /* If this is the breakpoint at the end of a stack dummy,
1014 just stop silently. */
1015 if (PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address))
1016 {
1017 stop_print_frame = 0;
1018 stop_stack_dummy = 1;
1019 #ifdef HP_OS_BUG
1020 trap_expected_after_continue = 1;
1021 #endif
1022 break;
1023 }
1024
1025 if (step_resume_break_address)
1026 /* Having a step-resume breakpoint overrides anything
1027 else having to do with stepping commands until
1028 that breakpoint is reached. */
1029 ;
1030 /* If stepping through a line, keep going if still within it. */
1031 else if (!random_signal
1032 && step_range_end
1033 && stop_pc >= step_range_start
1034 && stop_pc < step_range_end
1035 /* The step range might include the start of the
1036 function, so if we are at the start of the
1037 step range and either the stack or frame pointers
1038 just changed, we've stepped outside */
1039 && !(stop_pc == step_range_start
1040 && stop_frame_address
1041 && (stop_sp INNER_THAN prev_sp
1042 || stop_frame_address != step_frame_address)))
1043 {
1044 #if 0
1045 /* When "next"ing through a function,
1046 This causes an extra stop at the end.
1047 Is there any reason for this?
1048 It's confusing to the user. */
1049 /* Don't step through the return from a function
1050 unless that is the first instruction stepped through. */
1051 if (ABOUT_TO_RETURN (stop_pc))
1052 {
1053 stop_step = 1;
1054 break;
1055 }
1056 #endif
1057 }
1058
1059 /* We stepped out of the stepping range. See if that was due
1060 to a subroutine call that we should proceed to the end of. */
1061 else if (!random_signal && step_range_end)
1062 {
1063 if (stop_func_start)
1064 {
1065 prologue_pc = stop_func_start;
1066 SKIP_PROLOGUE (prologue_pc);
1067 }
1068
1069 /* Did we just take a signal? */
1070 if (IN_SIGTRAMP (stop_pc, stop_func_name)
1071 && !IN_SIGTRAMP (prev_pc, prev_func_name))
1072 {
1073 /* This code is needed at least in the following case:
1074 The user types "next" and then a signal arrives (before
1075 the "next" is done). */
1076 /* We've just taken a signal; go until we are back to
1077 the point where we took it and one more. */
1078 step_resume_break_address = prev_pc;
1079 step_resume_break_duplicate =
1080 breakpoint_here_p (step_resume_break_address);
1081 if (breakpoints_inserted)
1082 insert_step_breakpoint ();
1083 /* Make sure that the stepping range gets us past
1084 that instruction. */
1085 if (step_range_end == 1)
1086 step_range_end = (step_range_start = prev_pc) + 1;
1087 remove_breakpoints_on_following_step = 1;
1088 }
1089
1090 /* ==> See comments at top of file on this algorithm. <==*/
1091
1092 else if (stop_pc == stop_func_start
1093 && (stop_func_start != prev_func_start
1094 || prologue_pc != stop_func_start
1095 || stop_sp != prev_sp))
1096 {
1097 /* It's a subroutine call */
1098 if (step_over_calls > 0
1099 || (step_over_calls && find_pc_function (stop_pc) == 0))
1100 {
1101 /* A subroutine call has happened. */
1102 /* Set a special breakpoint after the return */
1103 step_resume_break_address =
1104 ADDR_BITS_REMOVE
1105 (SAVED_PC_AFTER_CALL (get_current_frame ()));
1106 step_resume_break_duplicate
1107 = breakpoint_here_p (step_resume_break_address);
1108 if (breakpoints_inserted)
1109 insert_step_breakpoint ();
1110 }
1111 /* Subroutine call with source code we should not step over.
1112 Do step to the first line of code in it. */
1113 else if (step_over_calls)
1114 {
1115 SKIP_PROLOGUE (stop_func_start);
1116 sal = find_pc_line (stop_func_start, 0);
1117 /* Use the step_resume_break to step until
1118 the end of the prologue, even if that involves jumps
1119 (as it seems to on the vax under 4.2). */
1120 /* If the prologue ends in the middle of a source line,
1121 continue to the end of that source line.
1122 Otherwise, just go to end of prologue. */
1123 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1124 /* no, don't either. It skips any code that's
1125 legitimately on the first line. */
1126 #else
1127 if (sal.end && sal.pc != stop_func_start)
1128 stop_func_start = sal.end;
1129 #endif
1130
1131 if (stop_func_start == stop_pc)
1132 {
1133 /* We are already there: stop now. */
1134 stop_step = 1;
1135 break;
1136 }
1137 else
1138 /* Put the step-breakpoint there and go until there. */
1139 {
1140 step_resume_break_address = stop_func_start;
1141
1142 step_resume_break_duplicate
1143 = breakpoint_here_p (step_resume_break_address);
1144 if (breakpoints_inserted)
1145 insert_step_breakpoint ();
1146 /* Do not specify what the fp should be when we stop
1147 since on some machines the prologue
1148 is where the new fp value is established. */
1149 step_frame_address = 0;
1150 /* And make sure stepping stops right away then. */
1151 step_range_end = step_range_start;
1152 }
1153 }
1154 else
1155 {
1156 /* We get here only if step_over_calls is 0 and we
1157 just stepped into a subroutine. I presume
1158 that step_over_calls is only 0 when we're
1159 supposed to be stepping at the assembly
1160 language level.*/
1161 stop_step = 1;
1162 break;
1163 }
1164 }
1165 /* No subroutince call; stop now. */
1166 else
1167 {
1168 stop_step = 1;
1169 break;
1170 }
1171 }
1172
1173 else if (trap_expected
1174 && IN_SIGTRAMP (stop_pc, stop_func_name)
1175 && !IN_SIGTRAMP (prev_pc, prev_func_name))
1176 {
1177 /* What has happened here is that we have just stepped the inferior
1178 with a signal (because it is a signal which shouldn't make
1179 us stop), thus stepping into sigtramp.
1180
1181 So we need to set a step_resume_break_address breakpoint
1182 and continue until we hit it, and then step. */
1183 step_resume_break_address = prev_pc;
1184 /* Always 1, I think, but it's probably easier to have
1185 the step_resume_break as usual rather than trying to
1186 re-use the breakpoint which is already there. */
1187 step_resume_break_duplicate =
1188 breakpoint_here_p (step_resume_break_address);
1189 if (breakpoints_inserted)
1190 insert_step_breakpoint ();
1191 remove_breakpoints_on_following_step = 1;
1192 another_trap = 1;
1193 }
1194
1195 /* Save the pc before execution, to compare with pc after stop. */
1196 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
1197 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
1198 BREAK is defined, the
1199 original pc would not have
1200 been at the start of a
1201 function. */
1202 prev_func_name = stop_func_name;
1203 prev_sp = stop_sp;
1204
1205 /* If we did not do break;, it means we should keep
1206 running the inferior and not return to debugger. */
1207
1208 if (trap_expected && stop_signal != SIGTRAP)
1209 {
1210 /* We took a signal (which we are supposed to pass through to
1211 the inferior, else we'd have done a break above) and we
1212 haven't yet gotten our trap. Simply continue. */
1213 resume ((step_range_end && !step_resume_break_address)
1214 || (trap_expected && !step_resume_break_address)
1215 || bpstat_should_step (),
1216 stop_signal);
1217 }
1218 else
1219 {
1220 /* Either the trap was not expected, but we are continuing
1221 anyway (the user asked that this signal be passed to the
1222 child)
1223 -- or --
1224 The signal was SIGTRAP, e.g. it was our signal, but we
1225 decided we should resume from it.
1226
1227 We're going to run this baby now!
1228
1229 Insert breakpoints now, unless we are trying
1230 to one-proceed past a breakpoint. */
1231 /* If we've just finished a special step resume and we don't
1232 want to hit a breakpoint, pull em out. */
1233 if (!step_resume_break_address &&
1234 remove_breakpoints_on_following_step)
1235 {
1236 remove_breakpoints_on_following_step = 0;
1237 remove_breakpoints ();
1238 breakpoints_inserted = 0;
1239 }
1240 else if (!breakpoints_inserted &&
1241 (step_resume_break_address != NULL || !another_trap))
1242 {
1243 insert_step_breakpoint ();
1244 breakpoints_failed = insert_breakpoints ();
1245 if (breakpoints_failed)
1246 break;
1247 breakpoints_inserted = 1;
1248 }
1249
1250 trap_expected = another_trap;
1251
1252 if (stop_signal == SIGTRAP)
1253 stop_signal = 0;
1254
1255 #ifdef SHIFT_INST_REGS
1256 /* I'm not sure when this following segment applies. I do know, now,
1257 that we shouldn't rewrite the regs when we were stopped by a
1258 random signal from the inferior process. */
1259
1260 if (!stop_breakpoint && (stop_signal != SIGCLD)
1261 && !stopped_by_random_signal)
1262 {
1263 CORE_ADDR pc_contents = read_register (PC_REGNUM);
1264 CORE_ADDR npc_contents = read_register (NPC_REGNUM);
1265 if (pc_contents != npc_contents)
1266 {
1267 write_register (NNPC_REGNUM, npc_contents);
1268 write_register (NPC_REGNUM, pc_contents);
1269 }
1270 }
1271 #endif /* SHIFT_INST_REGS */
1272
1273 resume ((step_range_end && !step_resume_break_address)
1274 || (trap_expected && !step_resume_break_address)
1275 || bpstat_should_step (),
1276 stop_signal);
1277 }
1278 }
1279 if (target_has_execution)
1280 {
1281 /* Assuming the inferior still exists, set these up for next
1282 time, just like we did above if we didn't break out of the
1283 loop. */
1284 prev_pc = read_pc ();
1285 prev_func_start = stop_func_start;
1286 prev_func_name = stop_func_name;
1287 prev_sp = stop_sp;
1288 }
1289 }
1290 \f
1291 /* Here to return control to GDB when the inferior stops for real.
1292 Print appropriate messages, remove breakpoints, give terminal our modes.
1293
1294 STOP_PRINT_FRAME nonzero means print the executing frame
1295 (pc, function, args, file, line number and line text).
1296 BREAKPOINTS_FAILED nonzero means stop was due to error
1297 attempting to insert breakpoints. */
1298
1299 void
1300 normal_stop ()
1301 {
1302 /* Make sure that the current_frame's pc is correct. This
1303 is a correction for setting up the frame info before doing
1304 DECR_PC_AFTER_BREAK */
1305 if (target_has_execution)
1306 (get_current_frame ())->pc = read_pc ();
1307
1308 if (breakpoints_failed)
1309 {
1310 target_terminal_ours_for_output ();
1311 print_sys_errmsg ("ptrace", breakpoints_failed);
1312 printf ("Stopped; cannot insert breakpoints.\n\
1313 The same program may be running in another process.\n");
1314 }
1315
1316 if (target_has_execution)
1317 remove_step_breakpoint ();
1318
1319 if (target_has_execution && breakpoints_inserted)
1320 if (remove_breakpoints ())
1321 {
1322 target_terminal_ours_for_output ();
1323 printf ("Cannot remove breakpoints because program is no longer writable.\n\
1324 It might be running in another process.\n\
1325 Further execution is probably impossible.\n");
1326 }
1327
1328 breakpoints_inserted = 0;
1329
1330 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1331 Delete any breakpoint that is to be deleted at the next stop. */
1332
1333 breakpoint_auto_delete (stop_bpstat);
1334
1335 /* If an auto-display called a function and that got a signal,
1336 delete that auto-display to avoid an infinite recursion. */
1337
1338 if (stopped_by_random_signal)
1339 disable_current_display ();
1340
1341 if (step_multi && stop_step)
1342 return;
1343
1344 target_terminal_ours ();
1345
1346 if (!target_has_stack)
1347 return;
1348
1349 /* Select innermost stack frame except on return from a stack dummy routine,
1350 or if the program has exited. */
1351 if (!stop_stack_dummy)
1352 {
1353 select_frame (get_current_frame (), 0);
1354
1355 if (stop_print_frame)
1356 {
1357 int source_only = bpstat_print (stop_bpstat);
1358 print_sel_frame
1359 (source_only
1360 || (stop_step
1361 && step_frame_address == stop_frame_address
1362 && step_start_function == find_pc_function (stop_pc)));
1363
1364 /* Display the auto-display expressions. */
1365 do_displays ();
1366 }
1367 }
1368
1369 /* Save the function value return registers, if we care.
1370 We might be about to restore their previous contents. */
1371 if (proceed_to_finish)
1372 read_register_bytes (0, stop_registers, REGISTER_BYTES);
1373
1374 if (stop_stack_dummy)
1375 {
1376 /* Pop the empty frame that contains the stack dummy.
1377 POP_FRAME ends with a setting of the current frame, so we
1378 can use that next. */
1379 POP_FRAME;
1380 select_frame (get_current_frame (), 0);
1381 }
1382 }
1383 \f
1384 static void
1385 insert_step_breakpoint ()
1386 {
1387 if (step_resume_break_address && !step_resume_break_duplicate)
1388 target_insert_breakpoint (step_resume_break_address,
1389 step_resume_break_shadow);
1390 }
1391
1392 static void
1393 remove_step_breakpoint ()
1394 {
1395 if (step_resume_break_address && !step_resume_break_duplicate)
1396 target_remove_breakpoint (step_resume_break_address,
1397 step_resume_break_shadow);
1398 }
1399 \f
1400 static void
1401 sig_print_header ()
1402 {
1403 printf_filtered ("Signal\t\tStop\tPrint\tPass to program\tDescription\n");
1404 }
1405
1406 static void
1407 sig_print_info (number)
1408 int number;
1409 {
1410 char *abbrev = sig_abbrev(number);
1411 if (abbrev == NULL)
1412 printf_filtered ("%d\t\t", number);
1413 else
1414 printf_filtered ("SIG%s (%d)\t", abbrev, number);
1415 printf_filtered ("%s\t", signal_stop[number] ? "Yes" : "No");
1416 printf_filtered ("%s\t", signal_print[number] ? "Yes" : "No");
1417 printf_filtered ("%s\t\t", signal_program[number] ? "Yes" : "No");
1418 printf_filtered ("%s\n", sys_siglist[number]);
1419 }
1420
1421 /* Specify how various signals in the inferior should be handled. */
1422
1423 static void
1424 handle_command (args, from_tty)
1425 char *args;
1426 int from_tty;
1427 {
1428 register char *p = args;
1429 int signum = 0;
1430 register int digits, wordlen;
1431 char *nextarg;
1432
1433 if (!args)
1434 error_no_arg ("signal to handle");
1435
1436 while (*p)
1437 {
1438 /* Find the end of the next word in the args. */
1439 for (wordlen = 0;
1440 p[wordlen] && p[wordlen] != ' ' && p[wordlen] != '\t';
1441 wordlen++);
1442 /* Set nextarg to the start of the word after the one we just
1443 found, and null-terminate this one. */
1444 if (p[wordlen] == '\0')
1445 nextarg = p + wordlen;
1446 else
1447 {
1448 p[wordlen] = '\0';
1449 nextarg = p + wordlen + 1;
1450 }
1451
1452
1453 for (digits = 0; p[digits] >= '0' && p[digits] <= '9'; digits++);
1454
1455 if (signum == 0)
1456 {
1457 /* It is the first argument--must be the signal to operate on. */
1458 if (digits == wordlen)
1459 {
1460 /* Numeric. */
1461 signum = atoi (p);
1462 if (signum <= 0 || signum >= NSIG)
1463 {
1464 p[wordlen] = '\0';
1465 error ("Invalid signal %s given as argument to \"handle\".", p);
1466 }
1467 }
1468 else
1469 {
1470 /* Symbolic. */
1471 signum = sig_number (p);
1472 if (signum == -1)
1473 error ("No such signal \"%s\"", p);
1474 }
1475
1476 if (signum == SIGTRAP || signum == SIGINT)
1477 {
1478 if (!query ("SIG%s is used by the debugger.\nAre you sure you want to change it? ", sig_abbrev (signum)))
1479 error ("Not confirmed.");
1480 }
1481 }
1482 /* Else, if already got a signal number, look for flag words
1483 saying what to do for it. */
1484 else if (!strncmp (p, "stop", wordlen))
1485 {
1486 signal_stop[signum] = 1;
1487 signal_print[signum] = 1;
1488 }
1489 else if (wordlen >= 2 && !strncmp (p, "print", wordlen))
1490 signal_print[signum] = 1;
1491 else if (wordlen >= 2 && !strncmp (p, "pass", wordlen))
1492 signal_program[signum] = 1;
1493 else if (!strncmp (p, "ignore", wordlen))
1494 signal_program[signum] = 0;
1495 else if (wordlen >= 3 && !strncmp (p, "nostop", wordlen))
1496 signal_stop[signum] = 0;
1497 else if (wordlen >= 4 && !strncmp (p, "noprint", wordlen))
1498 {
1499 signal_print[signum] = 0;
1500 signal_stop[signum] = 0;
1501 }
1502 else if (wordlen >= 4 && !strncmp (p, "nopass", wordlen))
1503 signal_program[signum] = 0;
1504 else if (wordlen >= 3 && !strncmp (p, "noignore", wordlen))
1505 signal_program[signum] = 1;
1506 /* Not a number and not a recognized flag word => complain. */
1507 else
1508 {
1509 error ("Unrecognized flag word: \"%s\".", p);
1510 }
1511
1512 /* Find start of next word. */
1513 p = nextarg;
1514 while (*p == ' ' || *p == '\t') p++;
1515 }
1516
1517 if (from_tty)
1518 {
1519 /* Show the results. */
1520 sig_print_header ();
1521 sig_print_info (signum);
1522 }
1523 }
1524
1525 /* Print current contents of the tables set by the handle command. */
1526
1527 static void
1528 signals_info (signum_exp)
1529 char *signum_exp;
1530 {
1531 register int i;
1532 sig_print_header ();
1533
1534 if (signum_exp)
1535 {
1536 /* First see if this is a symbol name. */
1537 i = sig_number (signum_exp);
1538 if (i == -1)
1539 {
1540 /* Nope, maybe it's an address which evaluates to a signal
1541 number. */
1542 i = parse_and_eval_address (signum_exp);
1543 if (i >= NSIG || i < 0)
1544 error ("Signal number out of bounds.");
1545 }
1546 sig_print_info (i);
1547 return;
1548 }
1549
1550 printf_filtered ("\n");
1551 for (i = 0; i < NSIG; i++)
1552 {
1553 QUIT;
1554
1555 sig_print_info (i);
1556 }
1557
1558 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
1559 }
1560 \f
1561 /* Save all of the information associated with the inferior<==>gdb
1562 connection. INF_STATUS is a pointer to a "struct inferior_status"
1563 (defined in inferior.h). */
1564
1565 void
1566 save_inferior_status (inf_status, restore_stack_info)
1567 struct inferior_status *inf_status;
1568 int restore_stack_info;
1569 {
1570 inf_status->pc_changed = pc_changed;
1571 inf_status->stop_signal = stop_signal;
1572 inf_status->stop_pc = stop_pc;
1573 inf_status->stop_frame_address = stop_frame_address;
1574 inf_status->stop_step = stop_step;
1575 inf_status->stop_stack_dummy = stop_stack_dummy;
1576 inf_status->stopped_by_random_signal = stopped_by_random_signal;
1577 inf_status->trap_expected = trap_expected;
1578 inf_status->step_range_start = step_range_start;
1579 inf_status->step_range_end = step_range_end;
1580 inf_status->step_frame_address = step_frame_address;
1581 inf_status->step_over_calls = step_over_calls;
1582 inf_status->step_resume_break_address = step_resume_break_address;
1583 inf_status->stop_after_trap = stop_after_trap;
1584 inf_status->stop_soon_quietly = stop_soon_quietly;
1585 /* Save original bpstat chain here; replace it with copy of chain.
1586 If caller's caller is walking the chain, they'll be happier if we
1587 hand them back the original chain when restore_i_s is called. */
1588 inf_status->stop_bpstat = stop_bpstat;
1589 stop_bpstat = bpstat_copy (stop_bpstat);
1590 inf_status->breakpoint_proceeded = breakpoint_proceeded;
1591 inf_status->restore_stack_info = restore_stack_info;
1592 inf_status->proceed_to_finish = proceed_to_finish;
1593
1594 bcopy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
1595
1596 record_selected_frame (&(inf_status->selected_frame_address),
1597 &(inf_status->selected_level));
1598 return;
1599 }
1600
1601 void
1602 restore_inferior_status (inf_status)
1603 struct inferior_status *inf_status;
1604 {
1605 FRAME fid;
1606 int level = inf_status->selected_level;
1607
1608 pc_changed = inf_status->pc_changed;
1609 stop_signal = inf_status->stop_signal;
1610 stop_pc = inf_status->stop_pc;
1611 stop_frame_address = inf_status->stop_frame_address;
1612 stop_step = inf_status->stop_step;
1613 stop_stack_dummy = inf_status->stop_stack_dummy;
1614 stopped_by_random_signal = inf_status->stopped_by_random_signal;
1615 trap_expected = inf_status->trap_expected;
1616 step_range_start = inf_status->step_range_start;
1617 step_range_end = inf_status->step_range_end;
1618 step_frame_address = inf_status->step_frame_address;
1619 step_over_calls = inf_status->step_over_calls;
1620 step_resume_break_address = inf_status->step_resume_break_address;
1621 stop_after_trap = inf_status->stop_after_trap;
1622 stop_soon_quietly = inf_status->stop_soon_quietly;
1623 bpstat_clear (&stop_bpstat);
1624 stop_bpstat = inf_status->stop_bpstat;
1625 breakpoint_proceeded = inf_status->breakpoint_proceeded;
1626 proceed_to_finish = inf_status->proceed_to_finish;
1627
1628 bcopy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
1629
1630 /* The inferior can be gone if the user types "print exit(0)"
1631 (and perhaps other times). */
1632 if (target_has_stack && inf_status->restore_stack_info)
1633 {
1634 fid = find_relative_frame (get_current_frame (),
1635 &level);
1636
1637 /* If inf_status->selected_frame_address is NULL, there was no
1638 previously selected frame. */
1639 if (fid == 0 ||
1640 FRAME_FP (fid) != inf_status->selected_frame_address ||
1641 level != 0)
1642 {
1643 #if 0
1644 /* I'm not sure this error message is a good idea. I have
1645 only seen it occur after "Can't continue previously
1646 requested operation" (we get called from do_cleanups), in
1647 which case it just adds insult to injury (one confusing
1648 error message after another. Besides which, does the
1649 user really care if we can't restore the previously
1650 selected frame? */
1651 fprintf (stderr, "Unable to restore previously selected frame.\n");
1652 #endif
1653 select_frame (get_current_frame (), 0);
1654 return;
1655 }
1656
1657 select_frame (fid, inf_status->selected_level);
1658 }
1659 }
1660
1661 \f
1662 void
1663 _initialize_infrun ()
1664 {
1665 register int i;
1666
1667 add_info ("signals", signals_info,
1668 "What debugger does when program gets various signals.\n\
1669 Specify a signal number as argument to print info on that signal only.");
1670
1671 add_com ("handle", class_run, handle_command,
1672 "Specify how to handle a signal.\n\
1673 Args are signal number followed by flags.\n\
1674 Flags allowed are \"stop\", \"print\", \"pass\",\n\
1675 \"nostop\", \"noprint\" or \"nopass\".\n\
1676 Print means print a message if this signal happens.\n\
1677 Stop means reenter debugger if this signal happens (implies print).\n\
1678 Pass means let program see this signal; otherwise program doesn't know.\n\
1679 Pass and Stop may be combined.");
1680
1681 for (i = 0; i < NSIG; i++)
1682 {
1683 signal_stop[i] = 1;
1684 signal_print[i] = 1;
1685 signal_program[i] = 1;
1686 }
1687
1688 /* Signals caused by debugger's own actions
1689 should not be given to the program afterwards. */
1690 signal_program[SIGTRAP] = 0;
1691 signal_program[SIGINT] = 0;
1692
1693 /* Signals that are not errors should not normally enter the debugger. */
1694 #ifdef SIGALRM
1695 signal_stop[SIGALRM] = 0;
1696 signal_print[SIGALRM] = 0;
1697 #endif /* SIGALRM */
1698 #ifdef SIGVTALRM
1699 signal_stop[SIGVTALRM] = 0;
1700 signal_print[SIGVTALRM] = 0;
1701 #endif /* SIGVTALRM */
1702 #ifdef SIGPROF
1703 signal_stop[SIGPROF] = 0;
1704 signal_print[SIGPROF] = 0;
1705 #endif /* SIGPROF */
1706 #ifdef SIGCHLD
1707 signal_stop[SIGCHLD] = 0;
1708 signal_print[SIGCHLD] = 0;
1709 #endif /* SIGCHLD */
1710 #ifdef SIGCLD
1711 signal_stop[SIGCLD] = 0;
1712 signal_print[SIGCLD] = 0;
1713 #endif /* SIGCLD */
1714 #ifdef SIGIO
1715 signal_stop[SIGIO] = 0;
1716 signal_print[SIGIO] = 0;
1717 #endif /* SIGIO */
1718 #ifdef SIGURG
1719 signal_stop[SIGURG] = 0;
1720 signal_print[SIGURG] = 0;
1721 #endif /* SIGURG */
1722 }
1723
This page took 0.065321 seconds and 5 git commands to generate.