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