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