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