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