home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Atari / Gnu / gdb36p4s.zoo / infrun.c < prev    next >
C/C++ Source or Header  |  1993-04-06  |  44KB  |  1,466 lines

  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. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Notes on the algorithm used in wait_for_inferior to determine if we
  21.    just did a subroutine call when stepping.  We have the following
  22.    information at that point:
  23.  
  24.                   Current and previous (just before this step) pc.
  25.           Current and previous sp.
  26.           Current and previous start of current function.
  27.  
  28.    If the start's of the functions don't match, then
  29.  
  30.        a) We did a subroutine call.
  31.  
  32.    In this case, the pc will be at the beginning of a function.
  33.  
  34.     b) We did a subroutine return.
  35.  
  36.    Otherwise.
  37.  
  38.     c) We did a longjmp.
  39.  
  40.    If we did a longjump, we were doing "nexti", since a next would
  41.    have attempted to skip over the assembly language routine in which
  42.    the longjmp is coded and would have simply been the equivalent of a
  43.    continue.  I consider this ok behaivior.  We'd like one of two
  44.    things to happen if we are doing a nexti through the longjmp()
  45.    routine: 1) It behaves as a stepi, or 2) It acts like a continue as
  46.    above.  Given that this is a special case, and that anybody who
  47.    thinks that the concept of sub calls is meaningful in the context
  48.    of a longjmp, I'll take either one.  Let's see what happens.  
  49.  
  50.    Acts like a subroutine return.  I can handle that with no problem
  51.    at all.
  52.  
  53.    -->So: If the current and previous beginnings of the current
  54.    function don't match, *and* the pc is at the start of a function,
  55.    we've done a subroutine call.  If the pc is not at the start of a
  56.    function, we *didn't* do a subroutine call.  
  57.  
  58.    -->If the beginnings of the current and previous function do match,
  59.    either: 
  60.  
  61.        a) We just did a recursive call.
  62.  
  63.        In this case, we would be at the very beginning of a
  64.        function and 1) it will have a prologue (don't jump to
  65.        before prologue, or 2) (we assume here that it doesn't have
  66.        a prologue) there will have been a change in the stack
  67.        pointer over the last instruction.  (Ie. it's got to put
  68.        the saved pc somewhere.  The stack is the usual place.  In
  69.        a recursive call a register is only an option if there's a
  70.        prologue to do something with it.  This is even true on
  71.        register window machines; the prologue sets up the new
  72.        window.  It might not be true on a register window machine
  73.        where the call instruction moved the register window
  74.        itself.  Hmmm.  One would hope that the stack pointer would
  75.        also change.  If it doesn't, somebody send me a note, and
  76.        I'll work out a more general theory.
  77.        randy@wheaties.ai.mit.edu).  This is true (albeit slipperly
  78.        so) on all machines I'm aware of:
  79.  
  80.           m68k:    Call changes stack pointer.  Regular jumps don't.
  81.  
  82.           sparc:    Recursive calls must have frames and therefor,
  83.                     prologues.
  84.  
  85.           vax:    All calls have frames and hence change the
  86.                     stack pointer.
  87.  
  88.     b) We did a return from a recursive call.  I don't see that we
  89.        have either the ability or the need to distinguish this
  90.        from an ordinary jump.  The stack frame will be printed
  91.        when and if the frame pointer changes; if we are in a
  92.        function without a frame pointer, it's the users own
  93.        lookout.
  94.  
  95.     c) We did a jump within a function.  We assume that this is
  96.        true if we didn't do a recursive call.
  97.  
  98.     d) We are in no-man's land ("I see no symbols here").  We
  99.        don't worry about this; it will make calls look like simple
  100.        jumps (and the stack frames will be printed when the frame
  101.        pointer moves), which is a reasonably non-violent response.
  102.  
  103. #if 0
  104.     We skip this; it causes more problems than it's worth.
  105. #ifdef SUN4_COMPILER_FEATURE
  106.     We do a special ifdef for the sun 4, forcing it to single step
  107.   into calls which don't have prologues.  This means that we can't
  108.   nexti over leaf nodes, we can probably next over them (since they
  109.   won't have debugging symbols, usually), and we can next out of
  110.   functions returning structures (with a "call .stret4" at the end).
  111. #endif
  112. #endif
  113. */
  114.    
  115.  
  116.    
  117.    
  118.  
  119. #include <stdio.h>
  120. #include "defs.h"
  121. #include "param.h"
  122. #include "symtab.h"
  123. #include "frame.h"
  124. #include "inferior.h"
  125. #include "wait.h"
  126.  
  127. #include <signal.h>
  128.  
  129. /* unistd.h is needed to #define X_OK */
  130. #ifdef USG
  131. #include <unistd.h>
  132. #else
  133. #include <sys/file.h>
  134. #endif
  135.  
  136. #ifdef UMAX_PTRACE
  137. #include <aouthdr.h>
  138. #include <sys/param.h>
  139. #include <sys/ptrace.h>
  140. #endif /* UMAX_PTRACE */
  141.  
  142. #ifndef atarist
  143. /* Required by <sys/user.h>.  */
  144. #include <sys/types.h>
  145. /* Required by <sys/user.h>, at least on system V.  */
  146. #include <sys/dir.h>
  147. /* Needed by IN_SIGTRAMP on some machines (e.g. vax).  */
  148. #include <sys/param.h>
  149. /* Needed by IN_SIGTRAMP on some machines (e.g. vax).  */
  150. #include <sys/user.h>
  151. #endif
  152.  
  153. extern char *sys_siglist[];
  154. extern int errno;
  155.  
  156. /* Sigtramp is a routine that the kernel calls (which then calls the
  157.    signal handler).  On most machines it is a library routine that
  158.    is linked into the executable.
  159.  
  160.    This macro, given a program counter value and the name of the
  161.    function in which that PC resides (which can be null if the
  162.    name is not known), returns nonzero if the PC and name show
  163.    that we are in sigtramp.
  164.  
  165.    On most machines just see if the name is sigtramp (and if we have
  166.    no name, assume we are not in sigtramp).  */
  167. #if !defined (IN_SIGTRAMP)
  168. #define IN_SIGTRAMP(pc, name) \
  169.   name && !strcmp ("_sigtramp", name)
  170. #endif
  171.  
  172. /* Tables of how to react to signals; the user sets them.  */
  173.  
  174. static char signal_stop[NSIG];
  175. static char signal_print[NSIG];
  176. static char signal_program[NSIG];
  177.  
  178. /* Nonzero if breakpoints are now inserted in the inferior.  */
  179.  
  180. static int breakpoints_inserted;
  181.  
  182. /* Function inferior was in as of last step command.  */
  183.  
  184. static struct symbol *step_start_function;
  185.  
  186. /* This is the sequence of bytes we insert for a breakpoint.  */
  187.  
  188. static char break_insn[] = BREAKPOINT;
  189.  
  190. /* Nonzero => address for special breakpoint for resuming stepping.  */
  191.  
  192. static CORE_ADDR step_resume_break_address;
  193.  
  194. /* Original contents of the byte where the special breakpoint is.  */
  195.  
  196. static char step_resume_break_shadow[sizeof break_insn];
  197.  
  198. /* Nonzero means the special breakpoint is a duplicate
  199.    so it has not itself been inserted.  */
  200.  
  201. static int step_resume_break_duplicate;
  202.  
  203. /* Nonzero if we are expecting a trace trap and should proceed from it.
  204.    2 means expecting 2 trace traps and should continue both times.
  205.    That occurs when we tell sh to exec the program: we will get
  206.    a trap after the exec of sh and a second when the program is exec'd.  */
  207.  
  208. static int trap_expected;
  209.  
  210. /* Nonzero if the next time we try to continue the inferior, it will
  211.    step one instruction and generate a spurious trace trap.
  212.    This is used to compensate for a bug in HP-UX.  */
  213.  
  214. static int trap_expected_after_continue;
  215.  
  216. /* Nonzero means expecting a trace trap
  217.    and should stop the inferior and return silently when it happens.  */
  218.  
  219. int stop_after_trap;
  220.  
  221. /* Nonzero means expecting a trace trap due to attaching to a process.  */
  222.  
  223. int stop_after_attach;
  224.  
  225. /* Nonzero if pc has been changed by the debugger
  226.    since the inferior stopped.  */
  227.  
  228. int pc_changed;
  229.  
  230. #ifndef atarist
  231. /* Nonzero if debugging a remote machine via a serial link or ethernet.  */
  232.  
  233. int remote_debugging;
  234. #endif
  235.  
  236. /* Save register contents here when about to pop a stack dummy frame.  */
  237.  
  238. char stop_registers[REGISTER_BYTES];
  239.  
  240. /* Nonzero if program stopped due to error trying to insert breakpoints.  */
  241.  
  242. static int breakpoints_failed;
  243.  
  244. /* Nonzero if inferior is in sh before our program got exec'd.  */
  245.  
  246. static int running_in_shell;
  247.  
  248. /* Nonzero after stop if current stack frame should be printed.  */
  249.  
  250. static int stop_print_frame;
  251.  
  252. #ifdef NO_SINGLE_STEP
  253. extern int one_stepped;        /* From machine dependent code */
  254. extern void single_step ();    /* Same. */
  255. #endif /* NO_SINGLE_STEP */
  256.  
  257. static void insert_step_breakpoint ();
  258. static void remove_step_breakpoint ();
  259. static void wait_for_inferior ();
  260. static void normal_stop ();
  261.  
  262.  
  263. /* Clear out all variables saying what to do when inferior is continued.
  264.    First do this, then set the ones you want, then call `proceed'.  */
  265.  
  266. void
  267. clear_proceed_status ()
  268. {
  269.   trap_expected = 0;
  270.   step_range_start = 0;
  271.   step_range_end = 0;
  272.   step_frame_address = 0;
  273.   step_over_calls = -1;
  274.   step_resume_break_address = 0;
  275.   stop_after_trap = 0;
  276.   stop_after_attach = 0;
  277.  
  278.   /* Discard any remaining commands left by breakpoint we had stopped at.  */
  279.   clear_breakpoint_commands ();
  280. }
  281.  
  282. /* Basic routine for continuing the program in various fashions.
  283.  
  284.    ADDR is the address to resume at, or -1 for resume where stopped.
  285.    SIGNAL is the signal to give it, or 0 for none,
  286.      or -1 for act according to how it stopped.
  287.    STEP is nonzero if should trap after one instruction.
  288.      -1 means return after that and print nothing.
  289.      You should probably set various step_... variables
  290.      before calling here, if you are stepping.
  291.  
  292.    You should call clear_proceed_status before calling proceed.  */
  293.  
  294. void
  295. proceed (addr, signal, step)
  296.      CORE_ADDR addr;
  297.      int signal;
  298.      int step;
  299. {
  300.   int oneproc = 0;
  301.  
  302.   if (step > 0)
  303.     step_start_function = find_pc_function (read_pc ());
  304.   if (step < 0)
  305.     stop_after_trap = 1;
  306.  
  307.   if (addr == -1)
  308.     {
  309.       /* If there is a breakpoint at the address we will resume at,
  310.      step one instruction before inserting breakpoints
  311.      so that we do not stop right away.  */
  312.  
  313.       if (!pc_changed && breakpoint_here_p (read_pc ()))
  314.     oneproc = 1;
  315.     }
  316.   else
  317.     {
  318.       write_register (PC_REGNUM, addr);
  319. #ifdef NPC_REGNUM
  320.       write_register (NPC_REGNUM, addr + 4);
  321. #endif
  322.     }
  323.  
  324.   if (trap_expected_after_continue)
  325.     {
  326.       /* If (step == 0), a trap will be automatically generated after
  327.      the first instruction is executed.  Force step one
  328.      instruction to clear this condition.  This should not occur
  329.      if step is nonzero, but it is harmless in that case.  */
  330.       oneproc = 1;
  331.       trap_expected_after_continue = 0;
  332.     }
  333.  
  334.   if (oneproc)
  335.     /* We will get a trace trap after one instruction.
  336.        Continue it automatically and insert breakpoints then.  */
  337.     trap_expected = 1;
  338.   else
  339.     {
  340.       int temp = insert_breakpoints ();
  341.       if (temp)
  342.     {
  343.       print_sys_errmsg ("ptrace", temp);
  344.       error ("Cannot insert breakpoints.\n\
  345. The same program may be running in another process.");
  346.     }
  347.       breakpoints_inserted = 1;
  348.     }
  349.  
  350.   /* Install inferior's terminal modes.  */
  351.   terminal_inferior ();
  352.  
  353.   if (signal >= 0)
  354.     stop_signal = signal;
  355.   /* If this signal should not be seen by program,
  356.      give it zero.  Used for debugging signals.  */
  357.   else if (stop_signal < NSIG && !signal_program[stop_signal])
  358.     stop_signal= 0;
  359.  
  360.   /* Resume inferior.  */
  361.   resume (oneproc || step, stop_signal);
  362.  
  363.   /* Wait for it to stop (if not standalone)
  364.      and in any case decode why it stopped, and act accordingly.  */
  365.  
  366.   wait_for_inferior ();
  367.   normal_stop ();
  368. }
  369.  
  370. /* Writing the inferior pc as a register calls this function
  371.    to inform infrun that the pc has been set in the debugger.  */
  372.  
  373. void
  374. writing_pc (val)
  375.      CORE_ADDR val;
  376. {
  377.   stop_pc = val;
  378.   pc_changed = 1;
  379. }
  380.  
  381. /* Start an inferior process for the first time.
  382.    Actually it was started by the fork that created it,
  383.    but it will have stopped one instruction after execing sh.
  384.    Here we must get it up to actual execution of the real program.  */
  385.  
  386. void
  387. start_inferior ()
  388. {
  389.   /* We will get a trace trap after one instruction.
  390.      Continue it automatically.  Eventually (after shell does an exec)
  391.      it will get another trace trap.  Then insert breakpoints and continue.  */
  392.  
  393. #ifdef START_INFERIOR_TRAPS_EXPECTED
  394.   trap_expected = START_INFERIOR_TRAPS_EXPECTED;
  395. #else
  396.   trap_expected = 2;
  397. #endif
  398.  
  399.   running_in_shell = 0;        /* Set to 1 at first SIGTRAP, 0 at second.  */
  400.   trap_expected_after_continue = 0;
  401.   breakpoints_inserted = 0;
  402.   mark_breakpoints_out ();
  403.  
  404.   /* Set up the "saved terminal modes" of the inferior
  405.      based on what modes we are starting it with.  */
  406.   terminal_init_inferior ();
  407.  
  408.   /* Install inferior's terminal modes.  */
  409.   terminal_inferior ();
  410.  
  411. #ifndef atarist
  412.   if (remote_debugging)
  413.     {
  414.       trap_expected = 0;
  415.       fetch_inferior_registers();
  416.       set_current_frame (create_new_frame (read_register (FP_REGNUM),
  417.                        read_pc ()));
  418.       stop_frame_address = FRAME_FP (get_current_frame());
  419.       inferior_pid = 3;
  420.       if (insert_breakpoints())
  421.     fatal("Can't insert breakpoints");
  422.       breakpoints_inserted = 1;
  423.       proceed(-1, -1, 0);
  424.     }
  425.   else
  426. #endif
  427.     {
  428.       wait_for_inferior ();
  429.       normal_stop ();
  430.     }
  431. }
  432.  
  433. #ifndef atarist
  434. /* Start remote-debugging of a machine over a serial link.  */
  435.  
  436. void
  437. start_remote ()
  438. {
  439.   clear_proceed_status ();
  440.   running_in_shell = 0;
  441.   trap_expected = 0;
  442.   inferior_pid = 3;
  443.   breakpoints_inserted = 0;
  444.   mark_breakpoints_out ();
  445.   wait_for_inferior ();
  446.   normal_stop();
  447. }
  448. #endif
  449.  
  450. #ifdef ATTACH_DETACH
  451.  
  452. /* Attach to process PID, then initialize for debugging it
  453.    and wait for the trace-trap that results from attaching.  */
  454.  
  455. void
  456. attach_program (pid)
  457.      int pid;
  458. {
  459.   attach (pid);
  460.   inferior_pid = pid;
  461.  
  462.   mark_breakpoints_out ();
  463.   terminal_init_inferior ();
  464.   clear_proceed_status ();
  465.   stop_after_attach = 1;
  466.   /*proceed (-1, 0, -2);*/
  467.   terminal_inferior ();
  468.   wait_for_inferior ();
  469.   normal_stop ();
  470. }
  471. #endif /* ATTACH_DETACH */
  472.  
  473. /* Wait for control to return from inferior to debugger.
  474.    If inferior gets a signal, we may decide to start it up again
  475.    instead of returning.  That is why there is a loop in this function.
  476.    When this function actually returns it means the inferior
  477.    should be left stopped and GDB should read more commands.  */
  478.  
  479. static void
  480. wait_for_inferior ()
  481. {
  482.   register int pid;
  483.   WAITTYPE w;
  484.   CORE_ADDR pc;
  485.   int tem;
  486.   int another_trap;
  487.   int random_signal;
  488.   CORE_ADDR stop_sp, prev_sp;
  489.   CORE_ADDR prev_func_start, stop_func_start;
  490.   char *prev_func_name, *stop_func_name;
  491.   CORE_ADDR prologue_pc;
  492.   int stop_step_resume_break;
  493.   CORE_ADDR step_resume_break_sp;
  494.   int newmisc;
  495.   int newfun_pc;
  496.   struct symtab_and_line sal;
  497.   int prev_pc;
  498.   extern CORE_ADDR text_end;
  499.   int remove_breakpoints_on_following_step = 0;
  500.  
  501.   prev_pc = read_pc ();
  502.   (void) find_pc_partial_function (prev_pc, &prev_func_name,
  503.                    &prev_func_start);
  504.   prev_func_start += FUNCTION_START_OFFSET;
  505.   prev_sp = read_register (SP_REGNUM);
  506.  
  507.   while (1)
  508.     {
  509.       /* Clean up saved state that will become invalid.  */
  510.       pc_changed = 0;
  511.       flush_cached_frames ();
  512.  
  513.       if (remote_debugging)
  514.     remote_wait (&w);
  515.       else
  516.     {
  517.       pid = wait (&w);
  518.       if (pid != inferior_pid)
  519.         continue;
  520.     }
  521.  
  522.       /* See if the process still exists; clean up if it doesn't.  */
  523.       if (WIFEXITED (w))
  524.     {
  525.       terminal_ours_for_output ();
  526.       if (WRETCODE (w))
  527.         printf ("\nProgram exited with code 0%o.\n", WRETCODE (w));
  528.       else
  529.         printf ("\nProgram exited normally.\n");
  530.       fflush (stdout);
  531.       inferior_died ();
  532. #ifdef NO_SINGLE_STEP
  533.       one_stepped = 0;
  534. #endif
  535.       stop_print_frame = 0;
  536.       break;
  537.     }
  538.       else if (!WIFSTOPPED (w))
  539.     {
  540.       kill_inferior ();
  541.       stop_print_frame = 0;
  542.       stop_signal = WTERMSIG (w);
  543.       terminal_ours_for_output ();
  544.       printf ("\nProgram terminated with signal %d, %s\n",
  545.           stop_signal,
  546.           stop_signal < NSIG
  547.           ? sys_siglist[stop_signal]
  548.           : "(undocumented)");
  549.       printf ("The inferior process no longer exists.\n");
  550.       fflush (stdout);
  551. #ifdef NO_SINGLE_STEP
  552.       one_stepped = 0;
  553. #endif
  554.       break;
  555.     }
  556.       
  557. #ifdef NO_SINGLE_STEP
  558.       if (one_stepped)
  559.     single_step (0);    /* This actually cleans up the ss */
  560. #endif /* NO_SINGLE_STEP */
  561.       
  562.       fetch_inferior_registers ();
  563.       stop_pc = read_pc ();
  564.       set_current_frame ( create_new_frame (read_register (FP_REGNUM),
  565.                         read_pc ()));
  566.       
  567.       stop_frame_address = FRAME_FP (get_current_frame ());
  568.       stop_sp = read_register (SP_REGNUM);
  569.       stop_func_start = 0;
  570.       stop_func_name = 0;
  571.       /* Don't care about return value; stop_func_start and stop_func_name
  572.      will both be 0 if it doesn't work.  */
  573.       (void) find_pc_partial_function (stop_pc, &stop_func_name,
  574.                        &stop_func_start);
  575.       stop_func_start += FUNCTION_START_OFFSET;
  576.       another_trap = 0;
  577.       stop_breakpoint = 0;
  578.       stop_step = 0;
  579.       stop_stack_dummy = 0;
  580.       stop_print_frame = 1;
  581.       stop_step_resume_break = 0;
  582.       random_signal = 0;
  583.       stopped_by_random_signal = 0;
  584.       breakpoints_failed = 0;
  585.       
  586.       /* Look at the cause of the stop, and decide what to do.
  587.      The alternatives are:
  588.      1) break; to really stop and return to the debugger,
  589.      2) drop through to start up again
  590.      (set another_trap to 1 to single step once)
  591.      3) set random_signal to 1, and the decision between 1 and 2
  592.      will be made according to the signal handling tables.  */
  593.       
  594.       stop_signal = WSTOPSIG (w);
  595.       
  596.       /* First, distinguish signals caused by the debugger from signals
  597.      that have to do with the program's own actions.
  598.      Note that breakpoint insns may cause SIGTRAP or SIGILL
  599.      or SIGEMT, depending on the operating system version.
  600.      Here we detect when a SIGILL or SIGEMT is really a breakpoint
  601.      and change it to SIGTRAP.  */
  602.       
  603.       if (stop_signal == SIGTRAP
  604.       || (breakpoints_inserted &&
  605.           (stop_signal == SIGILL
  606.            || stop_signal == SIGEMT))
  607.       || stop_after_attach)
  608.     {
  609.       if (stop_signal == SIGTRAP && stop_after_trap)
  610.         {
  611.           stop_print_frame = 0;
  612.           break;
  613.         }
  614.       if (stop_after_attach)
  615.         break;
  616.       /* Don't even think about breakpoints
  617.          if still running the shell that will exec the program
  618.          or if just proceeded over a breakpoint.  */
  619.       if (stop_signal == SIGTRAP && trap_expected)
  620.         stop_breakpoint = 0;
  621.       else
  622.         {
  623.           /* See if there is a breakpoint at the current PC.  */
  624. #if DECR_PC_AFTER_BREAK
  625.           /* Notice the case of stepping through a jump
  626.          that leads just after a breakpoint.
  627.          Don't confuse that with hitting the breakpoint.
  628.          What we check for is that 1) stepping is going on
  629.          and 2) the pc before the last insn does not match
  630.          the address of the breakpoint before the current pc.  */
  631.           if (!(prev_pc != stop_pc - DECR_PC_AFTER_BREAK
  632.             && step_range_end && !step_resume_break_address))
  633. #endif /* DECR_PC_AFTER_BREAK not zero */
  634.         {
  635.           /* See if we stopped at the special breakpoint for
  636.              stepping over a subroutine call.  */
  637.           if (stop_pc - DECR_PC_AFTER_BREAK
  638.               == step_resume_break_address)
  639.             {
  640.               stop_step_resume_break = 1;
  641.               if (DECR_PC_AFTER_BREAK)
  642.             {
  643.               stop_pc -= DECR_PC_AFTER_BREAK;
  644.               write_register (PC_REGNUM, stop_pc);
  645.               pc_changed = 0;
  646.             }
  647.             }
  648.           else
  649.             {
  650.               stop_breakpoint =
  651.             breakpoint_stop_status (stop_pc, stop_frame_address);
  652.               /* Following in case break condition called a
  653.              function.  */
  654.               stop_print_frame = 1;
  655.               if (stop_breakpoint && DECR_PC_AFTER_BREAK)
  656.             {
  657.               stop_pc -= DECR_PC_AFTER_BREAK;
  658.               write_register (PC_REGNUM, stop_pc);
  659. #ifdef NPC_REGNUM
  660.               write_register (NPC_REGNUM, stop_pc + 4);
  661. #endif
  662.               pc_changed = 0;
  663.             }
  664.             }
  665.         }
  666.         }
  667.       
  668.       if (stop_signal == SIGTRAP)
  669.         random_signal
  670.           = !(stop_breakpoint || trap_expected
  671.           || stop_step_resume_break
  672. #ifndef CANNOT_EXECUTE_STACK
  673.           || (stop_sp INNER_THAN stop_pc
  674.               && stop_pc INNER_THAN stop_frame_address)
  675. #else
  676.           || stop_pc == text_end - 2
  677. #endif
  678.           || (step_range_end && !step_resume_break_address));
  679.       else
  680.         {
  681.           random_signal
  682.         = !(stop_breakpoint
  683.             || stop_step_resume_break
  684. #if defined (sony_news) || defined (atarist)
  685.             || (stop_sp INNER_THAN stop_pc
  686.             && stop_pc INNER_THAN stop_frame_address)
  687. #endif
  688.             
  689.             );
  690.           if (!random_signal)
  691.         stop_signal = SIGTRAP;
  692.         }
  693.     }
  694.       else
  695.     random_signal = 1;
  696.       
  697.       /* For the program's own signals, act according to
  698.      the signal handling tables.  */
  699.       
  700.       if (random_signal
  701.       && !(running_in_shell && stop_signal == SIGSEGV))
  702.     {
  703.       /* Signal not for debugging purposes.  */
  704.       int printed = 0;
  705.       
  706.       stopped_by_random_signal = 1;
  707.       
  708.       if (stop_signal >= NSIG
  709.           || signal_print[stop_signal])
  710.         {
  711.           printed = 1;
  712.           terminal_ours_for_output ();
  713.           printf ("\nProgram received signal %d, %s\n",
  714.               stop_signal,
  715.               stop_signal < NSIG
  716.               ? sys_siglist[stop_signal]
  717.               : "(undocumented)");
  718.           fflush (stdout);
  719.         }
  720.       if (stop_signal >= NSIG
  721.           || signal_stop[stop_signal])
  722.         break;
  723.       /* If not going to stop, give terminal back
  724.          if we took it away.  */
  725.       else if (printed)
  726.         terminal_inferior ();
  727.     }
  728.       
  729.       /* Handle cases caused by hitting a breakpoint.  */
  730.       
  731.       if (!random_signal
  732.       && (stop_breakpoint || stop_step_resume_break))
  733.     {
  734.       /* Does a breakpoint want us to stop?  */
  735.       if (stop_breakpoint && stop_breakpoint != -1
  736.           && stop_breakpoint != -0x1000001)
  737.         {
  738.           /* 0x1000000 is set in stop_breakpoint as returned by
  739.          breakpoint_stop_status to indicate a silent
  740.          breakpoint.  */
  741.           if ((stop_breakpoint > 0 ? stop_breakpoint :
  742.            -stop_breakpoint)
  743.           & 0x1000000)
  744.         {
  745.           stop_print_frame = 0;
  746.           if (stop_breakpoint > 0)
  747.             stop_breakpoint -= 0x1000000;
  748.           else
  749.             stop_breakpoint += 0x1000000;
  750.         }
  751.           break;
  752.         }
  753.       /* But if we have hit the step-resumption breakpoint,
  754.          remove it.  It has done its job getting us here.
  755.          The sp test is to make sure that we don't get hung
  756.          up in recursive calls in functions without frame
  757.          pointers.  If the stack pointer isn't outside of
  758.          where the breakpoint was set (within a routine to be
  759.          stepped over), we're in the middle of a recursive
  760.          call. Not true for reg window machines (sparc)
  761.          because the must change frames to call things and
  762.          the stack pointer doesn't have to change if it
  763.          the bp was set in a routine without a frame (pc can
  764.          be stored in some other window).
  765.          
  766.          The removal of the sp test is to allow calls to
  767.          alloca.  Nasty things were happening.  Oh, well,
  768.          gdb can only handle one level deep of lack of
  769.          frame pointer. */
  770.       if (stop_step_resume_break
  771.           && (step_frame_address == 0
  772.           || (stop_frame_address == step_frame_address)))
  773.         {
  774.           remove_step_breakpoint ();
  775.           step_resume_break_address = 0;
  776.         }
  777.       /* Otherwise, must remove breakpoints and single-step
  778.          to get us past the one we hit.  */
  779.       else
  780.         {
  781.           remove_breakpoints ();
  782.           remove_step_breakpoint ();
  783.           breakpoints_inserted = 0;
  784.           another_trap = 1;
  785.         }
  786.       
  787.       /* We come here if we hit a breakpoint but should not
  788.          stop for it.  Possibly we also were stepping
  789.          and should stop for that.  So fall through and
  790.          test for stepping.  But, if not stepping,
  791.          do not stop.  */
  792.     }
  793.       
  794.       /* If this is the breakpoint at the end of a stack dummy,
  795.      just stop silently.  */
  796. #ifndef CANNOT_EXECUTE_STACK
  797.       if (stop_sp INNER_THAN stop_pc
  798.       && stop_pc INNER_THAN stop_frame_address)
  799. #else
  800.     if (stop_pc == text_end - 2)
  801. #endif
  802.       {
  803.         stop_print_frame = 0;
  804.         stop_stack_dummy = 1;
  805. #ifdef HP_OS_BUG
  806.         trap_expected_after_continue = 1;
  807. #endif
  808.         break;
  809.       }
  810.       
  811.       if (step_resume_break_address)
  812.     /* Having a step-resume breakpoint overrides anything
  813.        else having to do with stepping commands until
  814.        that breakpoint is reached.  */
  815.     ;
  816.       /* If stepping through a line, keep going if still within it.  */
  817.       else if (!random_signal
  818.            && step_range_end
  819.            && stop_pc >= step_range_start
  820.            && stop_pc < step_range_end
  821.            /* The step range might include the start of the
  822.           function, so if we are at the start of the
  823.           step range and either the stack or frame pointers
  824.           just changed, we've stepped outside */
  825.            && !(stop_pc == step_range_start
  826.             && stop_frame_address
  827.             && (stop_sp INNER_THAN prev_sp
  828.             || stop_frame_address != step_frame_address)))
  829.     {
  830.       /* Don't step through the return from a function
  831.          unless that is the first instruction stepped through.  */
  832.       if (ABOUT_TO_RETURN (stop_pc))
  833.         {
  834.           stop_step = 1;
  835.           break;
  836.         }
  837.     }
  838.       
  839.       /* We stepped out of the stepping range.  See if that was due
  840.      to a subroutine call that we should proceed to the end of.  */
  841.       else if (!random_signal && step_range_end)
  842.     {
  843.       if (stop_func_start)
  844.         {
  845.           prologue_pc = stop_func_start;
  846.           SKIP_PROLOGUE (prologue_pc);
  847.         }
  848.  
  849.       /* Did we just take a signal?  */
  850.       if (IN_SIGTRAMP (stop_pc, stop_func_name)
  851.           && !IN_SIGTRAMP (prev_pc, prev_func_name))
  852.         {
  853.           /* This code is needed at least in the following case:
  854.          The user types "next" and then a signal arrives (before
  855.          the "next" is done).  */
  856.           /* We've just taken a signal; go until we are back to
  857.          the point where we took it and one more.  */
  858.           step_resume_break_address = prev_pc;
  859.           step_resume_break_duplicate =
  860.         breakpoint_here_p (step_resume_break_address);
  861.           step_resume_break_sp = stop_sp;
  862.           if (breakpoints_inserted)
  863.         insert_step_breakpoint ();
  864.           /* Make sure that the stepping range gets us past
  865.          that instruction.  */
  866.           if (step_range_end == 1)
  867.         step_range_end = (step_range_start = prev_pc) + 1;
  868.           remove_breakpoints_on_following_step = 1;
  869.         }
  870.  
  871.       /* ==> See comments at top of file on this algorithm.  <==*/
  872.       
  873.       else if (stop_pc == stop_func_start
  874.           && (stop_func_start != prev_func_start
  875.           || prologue_pc != stop_func_start
  876.           || stop_sp != prev_sp))
  877.         {
  878.           /* It's a subroutine call */
  879.           /* find_pc_function and find_pc_line may call
  880.          psymtab_to_symtab */
  881.           terminal_ours_for_output ();
  882.           if (step_over_calls > 0 
  883.           || (step_over_calls &&  find_pc_function (stop_pc) == 0))
  884.         {
  885.           /* A subroutine call has happened.  */
  886.           /* Set a special breakpoint after the return */
  887.           step_resume_break_address =
  888.             SAVED_PC_AFTER_CALL (get_current_frame ());
  889.           step_resume_break_duplicate
  890.             = breakpoint_here_p (step_resume_break_address);
  891.           step_resume_break_sp = stop_sp;
  892.           if (breakpoints_inserted)
  893.             insert_step_breakpoint ();
  894.         }
  895.           /* Subroutine call with source code we should not step over.
  896.          Do step to the first line of code in it.  */
  897.           else if (step_over_calls)
  898.         {
  899.           SKIP_PROLOGUE (stop_func_start);
  900.           sal = find_pc_line (stop_func_start, 0);
  901.           /* Use the step_resume_break to step until
  902.              the end of the prologue, even if that involves jumps
  903.              (as it seems to on the vax under 4.2).  */
  904.           /* If the prologue ends in the middle of a source line,
  905.              continue to the end of that source line.
  906.              Otherwise, just go to end of prologue.  */
  907. #ifdef PROLOGUE_FIRSTLINE_OVERLAP
  908.           /* no, don't either.  It skips any code that's
  909.              legitimately on the first line.  */
  910. #else
  911.           if (sal.end && sal.pc != stop_func_start)
  912.             stop_func_start = sal.end;
  913. #endif
  914.           
  915.           if (stop_func_start == stop_pc)
  916.             {
  917.               /* We are already there: stop now.  */
  918.               stop_step = 1;
  919.               break;
  920.             }
  921.           else
  922.             /* Put the step-breakpoint there and go until there. */
  923.             {
  924.               step_resume_break_address = stop_func_start;
  925.               step_resume_break_sp = stop_sp;
  926.               
  927.               step_resume_break_duplicate
  928.             = breakpoint_here_p (step_resume_break_address);
  929.               if (breakpoints_inserted)
  930.             insert_step_breakpoint ();
  931.               /* Do not specify what the fp should be when we stop
  932.              since on some machines the prologue
  933.              is where the new fp value is established.  */
  934.               step_frame_address = 0;
  935.               /* And make sure stepping stops right away then.  */
  936.               step_range_end = step_range_start;
  937.             }
  938.         }
  939.           else
  940.         {
  941.           /* We get here only if step_over_calls is 0 and we
  942.              just stepped into a subroutine.  I presume
  943.              that step_over_calls is only 0 when we're
  944.              supposed to be stepping at the assembly
  945.              language level.*/
  946.           stop_step = 1;
  947.           break;
  948.         }
  949.           terminal_inferior ();
  950.         }
  951.       /* No subroutince call; stop now.  */
  952.       else
  953.         {
  954.           stop_step = 1;
  955.           break;
  956.         }
  957.     }
  958.  
  959.       /* Save the pc before execution, to compare with pc after stop.  */
  960.       prev_pc = read_pc ();    /* Might have been DECR_AFTER_BREAK */
  961.       prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
  962.                       BREAK is defined, the
  963.                       original pc would not have
  964.                       been at the start of a
  965.                       function. */
  966.       prev_func_name = stop_func_name;
  967.       prev_sp = stop_sp;
  968.  
  969.       /* If we did not do break;, it means we should keep
  970.      running the inferior and not return to debugger.  */
  971.  
  972.       /* If trap_expected is 2, it means continue once more
  973.      and insert breakpoints at the next trap.
  974.      If trap_expected is 1 and the signal was SIGSEGV, it means
  975.      the shell is doing some memory allocation--just resume it
  976.      with SIGSEGV.
  977.      Otherwise insert breakpoints now, and possibly single step.  */
  978.  
  979.       if (trap_expected > 1)
  980.     {
  981.       trap_expected--;
  982.       running_in_shell = 1;
  983.       resume (0, 0);
  984.     }
  985.       else if (running_in_shell && stop_signal == SIGSEGV)
  986.     {
  987.       resume (0, SIGSEGV);
  988.     }
  989.       else if (trap_expected && stop_signal != SIGTRAP)
  990.     {
  991.       /* We took a signal which we are supposed to pass through to
  992.          the inferior and we haven't yet gotten our trap.  Simply
  993.          continue.  */
  994.       resume ((step_range_end && !step_resume_break_address)
  995.           || trap_expected,
  996.           stop_signal);
  997.     }
  998.       else
  999.     {
  1000. #ifdef atarist
  1001.       if (running_in_shell)
  1002.         relocate_addresses ();
  1003. #endif
  1004.       /* Here, we are not awaiting another exec to get
  1005.          the program we really want to debug.
  1006.          Insert breakpoints now, unless we are trying
  1007.          to one-proceed past a breakpoint.  */
  1008.       running_in_shell = 0;
  1009.       /* If we've just finished a special step resume and we don't
  1010.          want to hit a breakpoint, pull em out.  */
  1011.       if (!step_resume_break_address &&
  1012.           remove_breakpoints_on_following_step)
  1013.         {
  1014.           remove_breakpoints_on_following_step = 0;
  1015.           remove_breakpoints ();
  1016.           breakpoints_inserted = 0;
  1017.         }
  1018.       else if (!breakpoints_inserted && !another_trap)
  1019.         {
  1020.           insert_step_breakpoint ();
  1021.           breakpoints_failed = insert_breakpoints ();
  1022.           if (breakpoints_failed)
  1023.         break;
  1024.           breakpoints_inserted = 1;
  1025.         }
  1026.  
  1027.       trap_expected = another_trap;
  1028.  
  1029.       if (stop_signal == SIGTRAP)
  1030.         stop_signal = 0;
  1031.  
  1032.       resume ((step_range_end && !step_resume_break_address)
  1033.           || trap_expected,
  1034.           stop_signal);
  1035.     }
  1036.     }
  1037. }
  1038.  
  1039. /* Here to return control to GDB when the inferior stops for real.
  1040.    Print appropriate messages, remove breakpoints, give terminal our modes.
  1041.  
  1042.    RUNNING_IN_SHELL nonzero means the shell got a signal before
  1043.    exec'ing the program we wanted to run.
  1044.    STOP_PRINT_FRAME nonzero means print the executing frame
  1045.    (pc, function, args, file, line number and line text).
  1046.    BREAKPOINTS_FAILED nonzero means stop was due to error
  1047.    attempting to insert breakpoints.  */
  1048.  
  1049. static void
  1050. normal_stop ()
  1051. {
  1052.   /* Make sure that the current_frame's pc is correct.  This
  1053.      is a correction for setting up the frame info before doing
  1054.      DECR_PC_AFTER_BREAK */
  1055.   if (inferior_pid)
  1056.     (get_current_frame ())->pc = read_pc ();
  1057.   
  1058.   if (breakpoints_failed)
  1059.     {
  1060.       terminal_ours_for_output ();
  1061.       print_sys_errmsg ("ptrace", breakpoints_failed);
  1062.       printf ("Stopped; cannot insert breakpoints.\n\
  1063. The same program may be running in another process.\n");
  1064.     }
  1065.  
  1066.   if (inferior_pid)
  1067.     remove_step_breakpoint ();
  1068.  
  1069.   if (inferior_pid && breakpoints_inserted)
  1070.     if (remove_breakpoints ())
  1071.       {
  1072.     terminal_ours_for_output ();
  1073.     printf ("Cannot remove breakpoints because program is no longer writable.\n\
  1074. It must be running in another process.\n\
  1075. Further execution is probably impossible.\n");
  1076.       }
  1077.  
  1078.   breakpoints_inserted = 0;
  1079.  
  1080.   /* Delete the breakpoint we stopped at, if it wants to be deleted.
  1081.      Delete any breakpoint that is to be deleted at the next stop.  */
  1082.  
  1083.   breakpoint_auto_delete (stop_breakpoint);
  1084.  
  1085.   /* If an auto-display called a function and that got a signal,
  1086.      delete that auto-display to avoid an infinite recursion.  */
  1087.  
  1088.   if (stopped_by_random_signal)
  1089.     {
  1090.       terminal_ours_for_output ();
  1091.       disable_current_display ();
  1092.     }
  1093.  
  1094.   if (step_multi && stop_step)
  1095.     return;
  1096.  
  1097.   terminal_ours ();
  1098.  
  1099.   if (running_in_shell)
  1100.     {
  1101. #ifndef atarist
  1102.       if (stop_signal == SIGSEGV)
  1103.     {
  1104.       char *exec_file = (char *) get_exec_file (1);
  1105.  
  1106.       if (access (exec_file, X_OK) != 0)
  1107.         printf ("The file \"%s\" is not executable.\n", exec_file);
  1108.       else
  1109.         /* I don't think we should ever get here.
  1110.            wait_for_inferior now ignores SIGSEGV's which happen in
  1111.            the shell (since the Bourne shell (/bin/sh) has some
  1112.            rather, er, uh, *unorthodox* memory management
  1113.            involving catching SIGSEGV).  */
  1114.         printf ("\
  1115. You have just encountered a bug in \"sh\".  GDB starts your program\n\
  1116. by running \"sh\" with a command to exec your program.\n\
  1117. This is so that \"sh\" will process wildcards and I/O redirection.\n\
  1118. This time, \"sh\" crashed.\n\
  1119. \n\
  1120. One known bug in \"sh\" bites when the environment takes up a lot of space.\n\
  1121. Try \"info env\" to see the environment; then use \"delete env\" to kill\n\
  1122. some variables whose values are large; then do \"run\" again.\n\
  1123. \n\
  1124. If that works, you might want to put those \"delete env\" commands\n\
  1125. into a \".gdbinit\" file in this directory so they will happen every time.\n");
  1126.     }
  1127. #endif
  1128.       /* Don't confuse user with his program's symbols on sh's data.  */
  1129.       stop_print_frame = 0;
  1130.     }
  1131.  
  1132.   if (inferior_pid == 0)
  1133.     return;
  1134.  
  1135.   /* Select innermost stack frame except on return from a stack dummy routine,
  1136.      or if the program has exited.  */
  1137.   if (!stop_stack_dummy)
  1138.     {
  1139.       select_frame (get_current_frame (), 0);
  1140.  
  1141.       if (stop_print_frame)
  1142.     {
  1143.       if (stop_breakpoint > 0)
  1144.         printf ("\nBpt %d, ", stop_breakpoint);
  1145.       print_sel_frame (stop_step
  1146.                && step_frame_address == stop_frame_address
  1147.                && step_start_function == find_pc_function (stop_pc));
  1148.       /* Display the auto-display expressions.  */
  1149.       do_displays ();
  1150.     }
  1151.     }
  1152.  
  1153.   /* Save the function value return registers
  1154.      We might be about to restore their previous contents.  */
  1155.   read_register_bytes (0, stop_registers, REGISTER_BYTES);
  1156.  
  1157.   if (stop_stack_dummy)
  1158.     {
  1159.       /* Pop the empty frame that contains the stack dummy.
  1160.          POP_FRAME ends with a setting of the current frame, so we
  1161.      can use that next. */
  1162.       POP_FRAME;
  1163.       select_frame (get_current_frame (), 0);
  1164.     }
  1165. }
  1166.  
  1167. static void
  1168. insert_step_breakpoint ()
  1169. {
  1170.   if (step_resume_break_address && !step_resume_break_duplicate)
  1171.     {
  1172.       read_memory (step_resume_break_address,
  1173.            step_resume_break_shadow, sizeof break_insn);
  1174.       write_memory (step_resume_break_address,
  1175.             break_insn, sizeof break_insn);
  1176.     }
  1177. }
  1178.  
  1179. static void
  1180. remove_step_breakpoint ()
  1181. {
  1182.   if (step_resume_break_address && !step_resume_break_duplicate)
  1183.     write_memory (step_resume_break_address, step_resume_break_shadow,
  1184.           sizeof break_insn);
  1185. }
  1186.  
  1187. /* Specify how various signals in the inferior should be handled.  */
  1188.  
  1189. static void
  1190. handle_command (args, from_tty)
  1191.      char *args;
  1192.      int from_tty;
  1193. {
  1194.   register char *p = args;
  1195.   int signum = 0;
  1196.   register int digits, wordlen;
  1197.  
  1198.   if (!args)
  1199.     error_no_arg ("signal to handle");
  1200.  
  1201.   while (*p)
  1202.     {
  1203.       /* Find the end of the next word in the args.  */
  1204.       for (wordlen = 0; p[wordlen] && p[wordlen] != ' ' && p[wordlen] != '\t';
  1205.        wordlen++);
  1206.       for (digits = 0; p[digits] >= '0' && p[digits] <= '9'; digits++);
  1207.  
  1208.       /* If it is all digits, it is signal number to operate on.  */
  1209.       if (digits == wordlen)
  1210.     {
  1211.       signum = atoi (p);
  1212.       if (signum <= 0 || signum >= NSIG)
  1213.         {
  1214.           p[wordlen] = '\0';
  1215.           error ("Invalid signal %s given as argument to \"handle\".", p);
  1216.         }
  1217.       if (signum == SIGTRAP || signum == SIGINT)
  1218.         {
  1219.           if (!query ("Signal %d is used by the debugger.\nAre you sure you want to change it? ", signum))
  1220.         error ("Not confirmed.");
  1221.         }
  1222.     }
  1223.       else if (signum == 0)
  1224.     error ("First argument is not a signal number.");
  1225.  
  1226.       /* Else, if already got a signal number, look for flag words
  1227.      saying what to do for it.  */
  1228.       else if (!strncmp (p, "stop", wordlen))
  1229.     {
  1230.       signal_stop[signum] = 1;
  1231.       signal_print[signum] = 1;
  1232.     }
  1233.       else if (wordlen >= 2 && !strncmp (p, "print", wordlen))
  1234.     signal_print[signum] = 1;
  1235.       else if (wordlen >= 2 && !strncmp (p, "pass", wordlen))
  1236.     signal_program[signum] = 1;
  1237.       else if (!strncmp (p, "ignore", wordlen))
  1238.     signal_program[signum] = 0;
  1239.       else if (wordlen >= 3 && !strncmp (p, "nostop", wordlen))
  1240.     signal_stop[signum] = 0;
  1241.       else if (wordlen >= 4 && !strncmp (p, "noprint", wordlen))
  1242.     {
  1243.       signal_print[signum] = 0;
  1244.       signal_stop[signum] = 0;
  1245.     }
  1246.       else if (wordlen >= 4 && !strncmp (p, "nopass", wordlen))
  1247.     signal_program[signum] = 0;
  1248.       else if (wordlen >= 3 && !strncmp (p, "noignore", wordlen))
  1249.     signal_program[signum] = 1;
  1250.       /* Not a number and not a recognized flag word => complain.  */
  1251.       else
  1252.     {
  1253.       p[wordlen] = 0;
  1254.       error ("Unrecognized flag word: \"%s\".", p);
  1255.     }
  1256.  
  1257.       /* Find start of next word.  */
  1258.       p += wordlen;
  1259.       while (*p == ' ' || *p == '\t') p++;
  1260.     }
  1261.  
  1262.   if (from_tty)
  1263.     {
  1264.       /* Show the results.  */
  1265.       printf ("Number\tStop\tPrint\tPass to program\tDescription\n");
  1266.       printf ("%d\t", signum);
  1267.       printf ("%s\t", signal_stop[signum] ? "Yes" : "No");
  1268.       printf ("%s\t", signal_print[signum] ? "Yes" : "No");
  1269.       printf ("%s\t\t", signal_program[signum] ? "Yes" : "No");
  1270.       printf ("%s\n", sys_siglist[signum]);
  1271.     }
  1272. }
  1273.  
  1274. /* Print current contents of the tables set by the handle command.  */
  1275.  
  1276. static void
  1277. signals_info (signum_exp)
  1278.      char *signum_exp;
  1279. {
  1280.   register int i;
  1281.   printf_filtered ("Number\tStop\tPrint\tPass to program\tDescription\n");
  1282.  
  1283.   if (signum_exp)
  1284.     {
  1285.       i = parse_and_eval_address (signum_exp);
  1286.       if (i >= NSIG || i < 0)
  1287.     error ("Signal number out of bounds.");
  1288.       printf_filtered ("%d\t", i);
  1289.       printf_filtered ("%s\t", signal_stop[i] ? "Yes" : "No");
  1290.       printf_filtered ("%s\t", signal_print[i] ? "Yes" : "No");
  1291.       printf_filtered ("%s\t\t", signal_program[i] ? "Yes" : "No");
  1292.       printf_filtered ("%s\n", sys_siglist[i]);
  1293.       return;
  1294.     }
  1295.  
  1296.   printf_filtered ("\n");
  1297.   for (i = 0; i < NSIG; i++)
  1298.     {
  1299.       QUIT;
  1300.  
  1301.       printf_filtered ("%d\t", i);
  1302.       printf_filtered ("%s\t", signal_stop[i] ? "Yes" : "No");
  1303.       printf_filtered ("%s\t", signal_print[i] ? "Yes" : "No");
  1304.       printf_filtered ("%s\t\t", signal_program[i] ? "Yes" : "No");
  1305.       printf_filtered ("%s\n", sys_siglist[i]);
  1306.     }
  1307.  
  1308.   printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
  1309. }
  1310.  
  1311. /* Save all of the information associated with the inferior<==>gdb
  1312.    connection.  INF_STATUS is a pointer to a "struct inferior_status"
  1313.    (defined in inferior.h).  */
  1314.  
  1315. struct command_line *get_breakpoint_commands ();
  1316.  
  1317. void
  1318. save_inferior_status (inf_status, restore_stack_info)
  1319.      struct inferior_status *inf_status;
  1320.      int restore_stack_info;
  1321. {
  1322.   inf_status->pc_changed = pc_changed;
  1323.   inf_status->stop_signal = stop_signal;
  1324.   inf_status->stop_pc = stop_pc;
  1325.   inf_status->stop_frame_address = stop_frame_address;
  1326.   inf_status->stop_breakpoint = stop_breakpoint;
  1327.   inf_status->stop_step = stop_step;
  1328.   inf_status->stop_stack_dummy = stop_stack_dummy;
  1329.   inf_status->stopped_by_random_signal = stopped_by_random_signal;
  1330.   inf_status->trap_expected = trap_expected;
  1331.   inf_status->step_range_start = step_range_start;
  1332.   inf_status->step_range_end = step_range_end;
  1333.   inf_status->step_frame_address = step_frame_address;
  1334.   inf_status->step_over_calls = step_over_calls;
  1335.   inf_status->step_resume_break_address = step_resume_break_address;
  1336.   inf_status->stop_after_trap = stop_after_trap;
  1337.   inf_status->stop_after_attach = stop_after_attach;
  1338.   inf_status->breakpoint_commands = get_breakpoint_commands ();
  1339.   inf_status->restore_stack_info = restore_stack_info;
  1340.   
  1341.   bcopy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
  1342.   
  1343.   record_selected_frame (&(inf_status->selected_frame_address),
  1344.              &(inf_status->selected_level));
  1345.   return;
  1346. }
  1347.  
  1348. void
  1349. restore_inferior_status (inf_status)
  1350.      struct inferior_status *inf_status;
  1351. {
  1352.   FRAME fid;
  1353.   int level = inf_status->selected_level;
  1354.  
  1355.   pc_changed = inf_status->pc_changed;
  1356.   stop_signal = inf_status->stop_signal;
  1357.   stop_pc = inf_status->stop_pc;
  1358.   stop_frame_address = inf_status->stop_frame_address;
  1359.   stop_breakpoint = inf_status->stop_breakpoint;
  1360.   stop_step = inf_status->stop_step;
  1361.   stop_stack_dummy = inf_status->stop_stack_dummy;
  1362.   stopped_by_random_signal = inf_status->stopped_by_random_signal;
  1363.   trap_expected = inf_status->trap_expected;
  1364.   step_range_start = inf_status->step_range_start;
  1365.   step_range_end = inf_status->step_range_end;
  1366.   step_frame_address = inf_status->step_frame_address;
  1367.   step_over_calls = inf_status->step_over_calls;
  1368.   step_resume_break_address = inf_status->step_resume_break_address;
  1369.   stop_after_trap = inf_status->stop_after_trap;
  1370.   stop_after_attach = inf_status->stop_after_attach;
  1371.   set_breakpoint_commands (inf_status->breakpoint_commands);
  1372.  
  1373.   bcopy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
  1374.  
  1375.   /* The inferior can be gone if the user types "print exit(0)"
  1376.      (and perhaps other times).  */
  1377.   if (have_inferior_p() && inf_status->restore_stack_info)
  1378.     {
  1379.       fid = find_relative_frame (get_current_frame (),
  1380.                  &level);
  1381.  
  1382.       if (fid == 0 ||
  1383.       FRAME_FP (fid) != inf_status->selected_frame_address ||
  1384.       level != 0)
  1385.     {
  1386.       /* I'm not sure this error message is a good idea.  I have
  1387.          only seen it occur after "Can't continue previously
  1388.          requested operation" (we get called from do_cleanups), in
  1389.          which case it just adds insult to injury (one confusing
  1390.          error message after another.  Besides which, does the
  1391.          user really care if we can't restore the previously
  1392.          selected frame?  */
  1393.       fprintf (stderr, "Unable to restore previously selected frame.\n");
  1394.       select_frame (get_current_frame (), 0);
  1395.       return;
  1396.     }
  1397.       
  1398.       select_frame (fid, inf_status->selected_level);
  1399.     }
  1400.   return;
  1401. }
  1402.  
  1403.  
  1404. void
  1405. _initialize_infrun ()
  1406. {
  1407.   register int i;
  1408.  
  1409.   add_info ("signals", signals_info,
  1410.         "What debugger does when program gets various signals.\n\
  1411. Specify a signal number as argument to print info on that signal only.");
  1412.  
  1413.   add_com ("handle", class_run, handle_command,
  1414.        "Specify how to handle a signal.\n\
  1415. Args are signal number followed by flags.\n\
  1416. Flags allowed are \"stop\", \"print\", \"pass\",\n\
  1417.  \"nostop\", \"noprint\" or \"nopass\".\n\
  1418. Print means print a message if this signal happens.\n\
  1419. Stop means reenter debugger if this signal happens (implies print).\n\
  1420. Pass means let program see this signal; otherwise program doesn't know.\n\
  1421. Pass and Stop may be combined.");
  1422.  
  1423.   for (i = 0; i < NSIG; i++)
  1424.     {
  1425.       signal_stop[i] = 1;
  1426.       signal_print[i] = 1;
  1427.       signal_program[i] = 1;
  1428.     }
  1429.  
  1430.   /* Signals caused by debugger's own actions
  1431.      should not be given to the program afterwards.  */
  1432.   signal_program[SIGTRAP] = 0;
  1433.   signal_program[SIGINT] = 0;
  1434.  
  1435.   /* Signals that are not errors should not normally enter the debugger.  */
  1436. #ifdef SIGALRM
  1437.   signal_stop[SIGALRM] = 0;
  1438.   signal_print[SIGALRM] = 0;
  1439. #endif /* SIGALRM */
  1440. #ifdef SIGVTALRM
  1441.   signal_stop[SIGVTALRM] = 0;
  1442.   signal_print[SIGVTALRM] = 0;
  1443. #endif /* SIGVTALRM */
  1444. #ifdef SIGPROF
  1445.   signal_stop[SIGPROF] = 0;
  1446.   signal_print[SIGPROF] = 0;
  1447. #endif /* SIGPROF */
  1448. #ifdef SIGCHLD
  1449.   signal_stop[SIGCHLD] = 0;
  1450.   signal_print[SIGCHLD] = 0;
  1451. #endif /* SIGCHLD */
  1452. #ifdef SIGCLD
  1453.   signal_stop[SIGCLD] = 0;
  1454.   signal_print[SIGCLD] = 0;
  1455. #endif /* SIGCLD */
  1456. #ifdef SIGIO
  1457.   signal_stop[SIGIO] = 0;
  1458.   signal_print[SIGIO] = 0;
  1459. #endif /* SIGIO */
  1460. #ifdef SIGURG
  1461.   signal_stop[SIGURG] = 0;
  1462.   signal_print[SIGURG] = 0;
  1463. #endif /* SIGURG */
  1464. }
  1465.  
  1466.