home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / GDB / GDB-4.13 / GDB-4 / gdb-4.13 / gdb / infrun.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-11  |  61.7 KB  |  2,038 lines

  1. /* Target-struct-independent code to start (run) and stop an inferior process.
  2.    Copyright 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994
  3.    Free Software Foundation, Inc.
  4.  
  5. This file is part of GDB.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "defs.h"
  22. #include <string.h>
  23. #include <ctype.h>
  24. #include "symtab.h"
  25. #include "frame.h"
  26. #include "inferior.h"
  27. #include "breakpoint.h"
  28. #include "wait.h"
  29. #include "gdbcore.h"
  30. #include "gdbcmd.h"
  31. #include "target.h"
  32. #include "thread.h"
  33. #include "annotate.h"
  34.  
  35. #include <signal.h>
  36.  
  37. /* unistd.h is needed to #define X_OK */
  38. #ifdef USG
  39. #include <unistd.h>
  40. #else
  41. #include <sys/file.h>
  42. #endif
  43.  
  44. /* Prototypes for local functions */
  45.  
  46. static void
  47. signals_info PARAMS ((char *, int));
  48.  
  49. static void
  50. handle_command PARAMS ((char *, int));
  51.  
  52. static void sig_print_info PARAMS ((enum target_signal));
  53.  
  54. static void
  55. sig_print_header PARAMS ((void));
  56.  
  57. static void
  58. resume_cleanups PARAMS ((int));
  59.  
  60. static int
  61. hook_stop_stub PARAMS ((char *));
  62.  
  63. /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
  64.    program.  It needs to examine the jmp_buf argument and extract the PC
  65.    from it.  The return value is non-zero on success, zero otherwise. */
  66. #ifndef GET_LONGJMP_TARGET
  67. #define GET_LONGJMP_TARGET(PC_ADDR) 0
  68. #endif
  69.  
  70.  
  71. /* Some machines have trampoline code that sits between function callers
  72.    and the actual functions themselves.  If this machine doesn't have
  73.    such things, disable their processing.  */
  74. #ifndef SKIP_TRAMPOLINE_CODE
  75. #define    SKIP_TRAMPOLINE_CODE(pc)    0
  76. #endif
  77.  
  78. /* For SVR4 shared libraries, each call goes through a small piece of
  79.    trampoline code in the ".plt" section.  IN_SOLIB_TRAMPOLINE evaluates
  80.    to nonzero if we are current stopped in one of these. */
  81. #ifndef IN_SOLIB_TRAMPOLINE
  82. #define IN_SOLIB_TRAMPOLINE(pc,name)    0
  83. #endif
  84.  
  85. /* On some systems, the PC may be left pointing at an instruction that  won't
  86.    actually be executed.  This is usually indicated by a bit in the PSW.  If
  87.    we find ourselves in such a state, then we step the target beyond the
  88.    nullified instruction before returning control to the user so as to avoid
  89.    confusion. */
  90.  
  91. #ifndef INSTRUCTION_NULLIFIED
  92. #define INSTRUCTION_NULLIFIED 0
  93. #endif
  94.  
  95. /* Tables of how to react to signals; the user sets them.  */
  96.  
  97. static unsigned char *signal_stop;
  98. static unsigned char *signal_print;
  99. static unsigned char *signal_program;
  100.  
  101. #define SET_SIGS(nsigs,sigs,flags) \
  102.   do { \
  103.     int signum = (nsigs); \
  104.     while (signum-- > 0) \
  105.       if ((sigs)[signum]) \
  106.     (flags)[signum] = 1; \
  107.   } while (0)
  108.  
  109. #define UNSET_SIGS(nsigs,sigs,flags) \
  110.   do { \
  111.     int signum = (nsigs); \
  112.     while (signum-- > 0) \
  113.       if ((sigs)[signum]) \
  114.     (flags)[signum] = 0; \
  115.   } while (0)
  116.  
  117.  
  118. /* Command list pointer for the "stop" placeholder.  */
  119.  
  120. static struct cmd_list_element *stop_command;
  121.  
  122. /* Nonzero if breakpoints are now inserted in the inferior.  */
  123.  
  124. static int breakpoints_inserted;
  125.  
  126. /* Function inferior was in as of last step command.  */
  127.  
  128. static struct symbol *step_start_function;
  129.  
  130. /* Nonzero if we are expecting a trace trap and should proceed from it.  */
  131.  
  132. static int trap_expected;
  133.  
  134. /* Nonzero if the next time we try to continue the inferior, it will
  135.    step one instruction and generate a spurious trace trap.
  136.    This is used to compensate for a bug in HP-UX.  */
  137.  
  138. static int trap_expected_after_continue;
  139.  
  140. /* Nonzero means expecting a trace trap
  141.    and should stop the inferior and return silently when it happens.  */
  142.  
  143. int stop_after_trap;
  144.  
  145. /* Nonzero means expecting a trap and caller will handle it themselves.
  146.    It is used after attach, due to attaching to a process;
  147.    when running in the shell before the child program has been exec'd;
  148.    and when running some kinds of remote stuff (FIXME?).  */
  149.  
  150. int stop_soon_quietly;
  151.  
  152. /* Nonzero if proceed is being used for a "finish" command or a similar
  153.    situation when stop_registers should be saved.  */
  154.  
  155. int proceed_to_finish;
  156.  
  157. /* Save register contents here when about to pop a stack dummy frame,
  158.    if-and-only-if proceed_to_finish is set.
  159.    Thus this contains the return value from the called function (assuming
  160.    values are returned in a register).  */
  161.  
  162. char stop_registers[REGISTER_BYTES];
  163.  
  164. /* Nonzero if program stopped due to error trying to insert breakpoints.  */
  165.  
  166. static int breakpoints_failed;
  167.  
  168. /* Nonzero after stop if current stack frame should be printed.  */
  169.  
  170. static int stop_print_frame;
  171.  
  172. #ifdef NO_SINGLE_STEP
  173. extern int one_stepped;        /* From machine dependent code */
  174. extern void single_step ();    /* Same. */
  175. #endif /* NO_SINGLE_STEP */
  176.  
  177.  
  178. /* Things to clean up if we QUIT out of resume ().  */
  179. /* ARGSUSED */
  180. static void
  181. resume_cleanups (arg)
  182.      int arg;
  183. {
  184.   normal_stop ();
  185. }
  186.  
  187. /* Resume the inferior, but allow a QUIT.  This is useful if the user
  188.    wants to interrupt some lengthy single-stepping operation
  189.    (for child processes, the SIGINT goes to the inferior, and so
  190.    we get a SIGINT random_signal, but for remote debugging and perhaps
  191.    other targets, that's not true).
  192.  
  193.    STEP nonzero if we should step (zero to continue instead).
  194.    SIG is the signal to give the inferior (zero for none).  */
  195. void
  196. resume (step, sig)
  197.      int step;
  198.      enum target_signal sig;
  199. {
  200.   struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
  201.   QUIT;
  202.  
  203. #ifdef CANNOT_STEP_BREAKPOINT
  204.   /* Most targets can step a breakpoint instruction, thus executing it
  205.      normally.  But if this one cannot, just continue and we will hit
  206.      it anyway.  */
  207.   if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
  208.     step = 0;
  209. #endif
  210.  
  211. #ifdef NO_SINGLE_STEP
  212.   if (step) {
  213.     single_step(sig);    /* Do it the hard way, w/temp breakpoints */
  214.     step = 0;        /* ...and don't ask hardware to do it.  */
  215.   }
  216. #endif
  217.  
  218.   /* Handle any optimized stores to the inferior NOW...  */
  219. #ifdef DO_DEFERRED_STORES
  220.   DO_DEFERRED_STORES;
  221. #endif
  222.  
  223.   /* Install inferior's terminal modes.  */
  224.   target_terminal_inferior ();
  225.  
  226.   target_resume (-1, step, sig);
  227.   discard_cleanups (old_cleanups);
  228. }
  229.  
  230.  
  231. /* Clear out all variables saying what to do when inferior is continued.
  232.    First do this, then set the ones you want, then call `proceed'.  */
  233.  
  234. void
  235. clear_proceed_status ()
  236. {
  237.   trap_expected = 0;
  238.   step_range_start = 0;
  239.   step_range_end = 0;
  240.   step_frame_address = 0;
  241.   step_over_calls = -1;
  242.   stop_after_trap = 0;
  243.   stop_soon_quietly = 0;
  244.   proceed_to_finish = 0;
  245.   breakpoint_proceeded = 1;    /* We're about to proceed... */
  246.  
  247.   /* Discard any remaining commands or status from previous stop.  */
  248.   bpstat_clear (&stop_bpstat);
  249. }
  250.  
  251. /* Basic routine for continuing the program in various fashions.
  252.  
  253.    ADDR is the address to resume at, or -1 for resume where stopped.
  254.    SIGGNAL is the signal to give it, or 0 for none,
  255.      or -1 for act according to how it stopped.
  256.    STEP is nonzero if should trap after one instruction.
  257.      -1 means return after that and print nothing.
  258.      You should probably set various step_... variables
  259.      before calling here, if you are stepping.
  260.  
  261.    You should call clear_proceed_status before calling proceed.  */
  262.  
  263. void
  264. proceed (addr, siggnal, step)
  265.      CORE_ADDR addr;
  266.      enum target_signal siggnal;
  267.      int step;
  268. {
  269.   int oneproc = 0;
  270.  
  271.   if (step > 0)
  272.     step_start_function = find_pc_function (read_pc ());
  273.   if (step < 0)
  274.     stop_after_trap = 1;
  275.  
  276.   if (addr == (CORE_ADDR)-1)
  277.     {
  278.       /* If there is a breakpoint at the address we will resume at,
  279.      step one instruction before inserting breakpoints
  280.      so that we do not stop right away.  */
  281.  
  282.       if (breakpoint_here_p (read_pc ()))
  283.     oneproc = 1;
  284.  
  285. #ifdef STEP_SKIPS_DELAY
  286.       /* Check breakpoint_here_p first, because breakpoint_here_p is fast
  287.      (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
  288.      is slow (it needs to read memory from the target).  */
  289.       if (breakpoint_here_p (read_pc () + 4)
  290.       && STEP_SKIPS_DELAY (read_pc ()))
  291.     oneproc = 1;
  292. #endif /* STEP_SKIPS_DELAY */
  293.     }
  294.   else
  295.     write_pc (addr);
  296.  
  297. #ifdef PREPARE_TO_PROCEED
  298.   /* In a multi-threaded task we may select another thread and then continue.
  299.      
  300.      In this case the thread that stopped at a breakpoint will immediately
  301.      cause another stop, if it is not stepped over first. On the other hand,
  302.      if (ADDR != -1) we only want to single step over the breakpoint if we did
  303.      switch to another thread.
  304.  
  305.      If we are single stepping, don't do any of the above.
  306.      (Note that in the current implementation single stepping another
  307.      thread after a breakpoint and then continuing will cause the original
  308.      breakpoint to be hit again, but you can always continue, so it's not
  309.      a big deal.)  */
  310.  
  311.   if (! step && PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
  312.     oneproc = 1;
  313. #endif /* PREPARE_TO_PROCEED */
  314.  
  315.   if (trap_expected_after_continue)
  316.     {
  317.       /* If (step == 0), a trap will be automatically generated after
  318.      the first instruction is executed.  Force step one
  319.      instruction to clear this condition.  This should not occur
  320.      if step is nonzero, but it is harmless in that case.  */
  321.       oneproc = 1;
  322.       trap_expected_after_continue = 0;
  323.     }
  324.  
  325.   if (oneproc)
  326.     /* We will get a trace trap after one instruction.
  327.        Continue it automatically and insert breakpoints then.  */
  328.     trap_expected = 1;
  329.   else
  330.     {
  331.       int temp = insert_breakpoints ();
  332.       if (temp)
  333.     {
  334.       print_sys_errmsg ("ptrace", temp);
  335.       error ("Cannot insert breakpoints.\n\
  336. The same program may be running in another process.");
  337.     }
  338.       breakpoints_inserted = 1;
  339.     }
  340.  
  341.   if (siggnal != TARGET_SIGNAL_DEFAULT)
  342.     stop_signal = siggnal;
  343.   /* If this signal should not be seen by program,
  344.      give it zero.  Used for debugging signals.  */
  345.   else if (!signal_program[stop_signal])
  346.     stop_signal = TARGET_SIGNAL_0;
  347.  
  348.   annotate_starting ();
  349.  
  350.   /* Resume inferior.  */
  351.   resume (oneproc || step || bpstat_should_step (), stop_signal);
  352.  
  353.   /* Wait for it to stop (if not standalone)
  354.      and in any case decode why it stopped, and act accordingly.  */
  355.  
  356.   wait_for_inferior ();
  357.   normal_stop ();
  358. }
  359.  
  360. /* Record the pc and sp of the program the last time it stopped.
  361.    These are just used internally by wait_for_inferior, but need
  362.    to be preserved over calls to it and cleared when the inferior
  363.    is started.  */
  364. static CORE_ADDR prev_pc;
  365. static CORE_ADDR prev_sp;
  366. static CORE_ADDR prev_func_start;
  367. static char *prev_func_name;
  368. static CORE_ADDR prev_frame_address;
  369.  
  370.  
  371. /* Start remote-debugging of a machine over a serial link.  */
  372.  
  373. void
  374. start_remote ()
  375. {
  376.   init_wait_for_inferior ();
  377.   clear_proceed_status ();
  378.   stop_soon_quietly = 1;
  379.   trap_expected = 0;
  380.   wait_for_inferior ();
  381.   normal_stop ();
  382. }
  383.  
  384. /* Initialize static vars when a new inferior begins.  */
  385.  
  386. void
  387. init_wait_for_inferior ()
  388. {
  389.   /* These are meaningless until the first time through wait_for_inferior.  */
  390.   prev_pc = 0;
  391.   prev_sp = 0;
  392.   prev_func_start = 0;
  393.   prev_func_name = NULL;
  394.   prev_frame_address = 0;
  395.  
  396.   trap_expected_after_continue = 0;
  397.   breakpoints_inserted = 0;
  398.   breakpoint_init_inferior ();
  399.  
  400.   /* Don't confuse first call to proceed(). */
  401.   stop_signal = TARGET_SIGNAL_0;
  402. }
  403.  
  404. static void
  405. delete_breakpoint_current_contents (arg)
  406.      PTR arg;
  407. {
  408.   struct breakpoint **breakpointp = (struct breakpoint **)arg;
  409.   if (*breakpointp != NULL)
  410.     delete_breakpoint (*breakpointp);
  411. }
  412.  
  413. /* Wait for control to return from inferior to debugger.
  414.    If inferior gets a signal, we may decide to start it up again
  415.    instead of returning.  That is why there is a loop in this function.
  416.    When this function actually returns it means the inferior
  417.    should be left stopped and GDB should read more commands.  */
  418.  
  419. void
  420. wait_for_inferior ()
  421. {
  422.   struct cleanup *old_cleanups;
  423.   struct target_waitstatus w;
  424.   int another_trap;
  425.   int random_signal;
  426.   CORE_ADDR stop_sp = 0;
  427.   CORE_ADDR stop_func_start;
  428.   CORE_ADDR stop_func_end;
  429.   char *stop_func_name;
  430.   CORE_ADDR prologue_pc = 0, tmp;
  431.   struct symtab_and_line sal;
  432.   int remove_breakpoints_on_following_step = 0;
  433.   int current_line;
  434.   struct symtab *current_symtab;
  435.   int handling_longjmp = 0;    /* FIXME */
  436.   struct breakpoint *step_resume_breakpoint = NULL;
  437.   struct breakpoint *through_sigtramp_breakpoint = NULL;
  438.   int pid;
  439.  
  440.   old_cleanups = make_cleanup (delete_breakpoint_current_contents,
  441.                    &step_resume_breakpoint);
  442.   make_cleanup (delete_breakpoint_current_contents,
  443.         &through_sigtramp_breakpoint);
  444.   sal = find_pc_line(prev_pc, 0);
  445.   current_line = sal.line;
  446.   current_symtab = sal.symtab;
  447.  
  448.   /* Are we stepping?  */
  449. #define CURRENTLY_STEPPING() \
  450.   ((through_sigtramp_breakpoint == NULL \
  451.     && !handling_longjmp \
  452.     && ((step_range_end && step_resume_breakpoint == NULL) \
  453.     || trap_expected)) \
  454.    || bpstat_should_step ())
  455.  
  456.   while (1)
  457.     {
  458.       /* We have to invalidate the registers BEFORE calling target_wait because
  459.      they can be loaded from the target while in target_wait.  This makes
  460.      remote debugging a bit more efficient for those targets that provide
  461.      critical registers as part of their normal status mechanism. */
  462.  
  463.       registers_changed ();
  464.  
  465.       pid = target_wait (-1, &w);
  466.  
  467.       flush_cached_frames ();
  468.  
  469.       /* If it's a new process, add it to the thread database */
  470.  
  471.       if (pid != inferior_pid
  472.       && !in_thread_list (pid))
  473.     {
  474.       fprintf_unfiltered (gdb_stderr, "[New %s]\n", target_pid_to_str (pid));
  475.       add_thread (pid);
  476.  
  477.       /* We may want to consider not doing a resume here in order to give
  478.          the user a chance to play with the new thread.  It might be good
  479.          to make that a user-settable option.  */
  480.  
  481.       /* At this point, all threads are stopped (happens automatically in
  482.          either the OS or the native code).  Therefore we need to continue
  483.          all threads in order to make progress.  */
  484.  
  485.       target_resume (-1, 0, TARGET_SIGNAL_0);
  486.       continue;
  487.     }
  488.  
  489.       switch (w.kind)
  490.     {
  491.     case TARGET_WAITKIND_LOADED:
  492.       /* Ignore it gracefully.  */
  493.       if (breakpoints_inserted)
  494.         {
  495.           mark_breakpoints_out ();
  496.           insert_breakpoints ();
  497.         }
  498.       resume (0, TARGET_SIGNAL_0);
  499.       continue;
  500.  
  501.     case TARGET_WAITKIND_SPURIOUS:
  502.       resume (0, TARGET_SIGNAL_0);
  503.       continue;
  504.  
  505.     case TARGET_WAITKIND_EXITED:
  506.       target_terminal_ours ();    /* Must do this before mourn anyway */
  507.       annotate_exited (w.value.integer);
  508.       if (w.value.integer)
  509.         printf_filtered ("\nProgram exited with code 0%o.\n", 
  510.                  (unsigned int)w.value.integer);
  511.       else
  512.         printf_filtered ("\nProgram exited normally.\n");
  513.       gdb_flush (gdb_stdout);
  514.       target_mourn_inferior ();
  515. #ifdef NO_SINGLE_STEP
  516.       one_stepped = 0;
  517. #endif
  518.       stop_print_frame = 0;
  519.       goto stop_stepping;
  520.  
  521.     case TARGET_WAITKIND_SIGNALLED:
  522.       stop_print_frame = 0;
  523.       stop_signal = w.value.sig;
  524.       target_terminal_ours ();    /* Must do this before mourn anyway */
  525.       annotate_signalled ();
  526.       target_kill ();        /* kill mourns as well */
  527.       printf_filtered ("\nProgram terminated with signal ");
  528.       annotate_signal_name ();
  529.       printf_filtered ("%s", target_signal_to_name (stop_signal));
  530.       annotate_signal_name_end ();
  531.       printf_filtered (", ");
  532.       annotate_signal_string ();
  533.       printf_filtered ("%s", target_signal_to_string (stop_signal));
  534.       annotate_signal_string_end ();
  535.       printf_filtered (".\n");
  536.  
  537.       printf_filtered ("The program no longer exists.\n");
  538.       gdb_flush (gdb_stdout);
  539. #ifdef NO_SINGLE_STEP
  540.       one_stepped = 0;
  541. #endif
  542.       goto stop_stepping;
  543.  
  544.     case TARGET_WAITKIND_STOPPED:
  545.       /* This is the only case in which we keep going; the above cases
  546.          end in a continue or goto.  */
  547.       break;
  548.     }
  549.  
  550.       stop_signal = w.value.sig;
  551.  
  552.       stop_pc = read_pc_pid (pid);
  553.  
  554.       /* See if a thread hit a thread-specific breakpoint that was meant for
  555.      another thread.  If so, then step that thread past the breakpoint,
  556.      and continue it.  */
  557.  
  558.       if (stop_signal == TARGET_SIGNAL_TRAP
  559.       && breakpoints_inserted
  560.       && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
  561.     {
  562.       random_signal = 0;
  563.       if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, pid))
  564.         {
  565.           /* Saw a breakpoint, but it was hit by the wrong thread.  Just continue. */
  566.           write_pc (stop_pc - DECR_PC_AFTER_BREAK);
  567.  
  568.           remove_breakpoints ();
  569.           target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
  570.           /* FIXME: What if a signal arrives instead of the single-step
  571.          happening?  */
  572.           target_wait (pid, &w);
  573.           insert_breakpoints ();
  574.           target_resume (pid, 0, TARGET_SIGNAL_0);
  575.           continue;
  576.         }
  577.     }
  578.       else
  579.     random_signal = 1;
  580.  
  581.       /* See if something interesting happened to the non-current thread.  If
  582.          so, then switch to that thread, and eventually give control back to
  583.      the user.  */
  584.  
  585.       if (pid != inferior_pid)
  586.     {
  587.       int printed = 0;
  588.  
  589.       /* If it's a random signal for a non-current thread, notify user
  590.          if he's expressed an interest.  */
  591.  
  592.       if (random_signal
  593.           && signal_print[stop_signal])
  594.         {
  595.           printed = 1;
  596.           target_terminal_ours_for_output ();
  597.           printf_filtered ("\nProgram received signal %s, %s.\n",
  598.                    target_signal_to_name (stop_signal),
  599.                    target_signal_to_string (stop_signal));
  600.           gdb_flush (gdb_stdout);
  601.         }
  602.  
  603.       /* If it's not SIGTRAP and not a signal we want to stop for, then
  604.          continue the thread. */
  605.  
  606.       if (stop_signal != TARGET_SIGNAL_TRAP
  607.           && !signal_stop[stop_signal])
  608.         {
  609.           if (printed)
  610.         target_terminal_inferior ();
  611.  
  612.           /* Clear the signal if it should not be passed.  */
  613.           if (signal_program[stop_signal] == 0)
  614.         stop_signal = TARGET_SIGNAL_0;
  615.  
  616.           target_resume (pid, 0, stop_signal);
  617.           continue;
  618.         }
  619.  
  620.       /* It's a SIGTRAP or a signal we're interested in.  Switch threads,
  621.          and fall into the rest of wait_for_inferior().  */
  622.  
  623.       inferior_pid = pid;
  624.       printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid));
  625.  
  626.       flush_cached_frames ();
  627.       trap_expected = 0;
  628.       if (step_resume_breakpoint)
  629.         {
  630.           delete_breakpoint (step_resume_breakpoint);
  631.           step_resume_breakpoint = NULL;
  632.         }
  633.  
  634.       /* Not sure whether we need to blow this away too,
  635.          but probably it is like the step-resume
  636.          breakpoint.  */
  637.       if (through_sigtramp_breakpoint)
  638.         {
  639.           delete_breakpoint (through_sigtramp_breakpoint);
  640.           through_sigtramp_breakpoint = NULL;
  641.         }
  642.       prev_pc = 0;
  643.       prev_sp = 0;
  644.       prev_func_name = NULL;
  645.       step_range_start = 0;
  646.       step_range_end = 0;
  647.       step_frame_address = 0;
  648.       handling_longjmp = 0;
  649.       another_trap = 0;
  650.     }
  651.  
  652. #ifdef NO_SINGLE_STEP
  653.       if (one_stepped)
  654.     single_step (0);    /* This actually cleans up the ss */
  655. #endif /* NO_SINGLE_STEP */
  656.       
  657.       /* If PC is pointing at a nullified instruction, then step beyond
  658.      it so that the user won't be confused when GDB appears to be ready
  659.      to execute it. */
  660.  
  661.       if (INSTRUCTION_NULLIFIED)
  662.     {
  663.       resume (1, 0);
  664.       continue;
  665.     }
  666.  
  667.       set_current_frame (create_new_frame (read_fp (), stop_pc));
  668.       select_frame (get_current_frame (), 0);
  669.  
  670. #ifdef HAVE_STEPPABLE_WATCHPOINT
  671.       /* It may not be necessary to disable the watchpoint to stop over
  672.      it.  For example, the PA can (with some kernel cooperation) 
  673.      single step over a watchpoint without disabling the watchpoint.  */
  674.       if (STOPPED_BY_WATCHPOINT (w))
  675.     {
  676.       resume (1, 0);
  677.       continue;
  678.     }
  679. #endif
  680.  
  681. #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
  682.       /* It is far more common to need to disable a watchpoint
  683.      to step the inferior over it.  FIXME.  What else might
  684.      a debug register or page protection watchpoint scheme need
  685.      here?  */
  686.       if (STOPPED_BY_WATCHPOINT (w))
  687.     {
  688.       remove_breakpoints ();
  689.       resume (1, 0);
  690.  
  691.       /* FIXME: This is bogus.  You can't interact with the
  692.          inferior except when it is stopped.  It apparently
  693.          happens to work on Irix4, but it depends on /proc
  694.          allowing us to muck with the memory of a running process,
  695.          and the kernel deciding to run one instruction of the
  696.          inferior before it executes our insert_breakpoints code,
  697.          which seems like an awfully dubious assumption.  */
  698.       insert_breakpoints ();
  699.  
  700.       continue;
  701.     }
  702. #endif
  703.  
  704. #ifdef HAVE_CONTINUABLE_WATCHPOINT
  705.       /* It may be possible to simply continue after a watchpoint.  */
  706.       STOPPED_BY_WATCHPOINT (w);
  707. #endif
  708.  
  709.       stop_frame_address = FRAME_FP (get_current_frame ());
  710.       stop_sp = read_sp ();
  711.       stop_func_start = 0;
  712.       stop_func_name = 0;
  713.       /* Don't care about return value; stop_func_start and stop_func_name
  714.      will both be 0 if it doesn't work.  */
  715.       find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start,
  716.                 &stop_func_end);
  717.       stop_func_start += FUNCTION_START_OFFSET;
  718.       another_trap = 0;
  719.       bpstat_clear (&stop_bpstat);
  720.       stop_step = 0;
  721.       stop_stack_dummy = 0;
  722.       stop_print_frame = 1;
  723.       random_signal = 0;
  724.       stopped_by_random_signal = 0;
  725.       breakpoints_failed = 0;
  726.       
  727.       /* Look at the cause of the stop, and decide what to do.
  728.      The alternatives are:
  729.      1) break; to really stop and return to the debugger,
  730.      2) drop through to start up again
  731.      (set another_trap to 1 to single step once)
  732.      3) set random_signal to 1, and the decision between 1 and 2
  733.      will be made according to the signal handling tables.  */
  734.       
  735.       /* First, distinguish signals caused by the debugger from signals
  736.      that have to do with the program's own actions.
  737.      Note that breakpoint insns may cause SIGTRAP or SIGILL
  738.      or SIGEMT, depending on the operating system version.
  739.      Here we detect when a SIGILL or SIGEMT is really a breakpoint
  740.      and change it to SIGTRAP.  */
  741.       
  742.       if (stop_signal == TARGET_SIGNAL_TRAP
  743.       || (breakpoints_inserted &&
  744.           (stop_signal == TARGET_SIGNAL_ILL
  745.            || stop_signal == TARGET_SIGNAL_EMT
  746.             ))
  747.       || stop_soon_quietly)
  748.     {
  749.       if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
  750.         {
  751.           stop_print_frame = 0;
  752.           break;
  753.         }
  754.       if (stop_soon_quietly)
  755.         break;
  756.  
  757.       /* Don't even think about breakpoints
  758.          if just proceeded over a breakpoint.
  759.  
  760.          However, if we are trying to proceed over a breakpoint
  761.          and end up in sigtramp, then through_sigtramp_breakpoint
  762.          will be set and we should check whether we've hit the
  763.          step breakpoint.  */
  764.       if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
  765.           && through_sigtramp_breakpoint == NULL)
  766.         bpstat_clear (&stop_bpstat);
  767.       else
  768.         {
  769.           /* See if there is a breakpoint at the current PC.  */
  770.           stop_bpstat = bpstat_stop_status
  771.         (&stop_pc, stop_frame_address,
  772. #if DECR_PC_AFTER_BREAK
  773.          /* Notice the case of stepping through a jump
  774.             that lands just after a breakpoint.
  775.             Don't confuse that with hitting the breakpoint.
  776.             What we check for is that 1) stepping is going on
  777.             and 2) the pc before the last insn does not match
  778.             the address of the breakpoint before the current pc.  */
  779.          (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
  780.           && CURRENTLY_STEPPING ())
  781. #else /* DECR_PC_AFTER_BREAK zero */
  782.          0
  783. #endif /* DECR_PC_AFTER_BREAK zero */
  784.          );
  785.           /* Following in case break condition called a
  786.          function.  */
  787.           stop_print_frame = 1;
  788.         }
  789.  
  790.       if (stop_signal == TARGET_SIGNAL_TRAP)
  791.         random_signal
  792.           = !(bpstat_explains_signal (stop_bpstat)
  793.           || trap_expected
  794. #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
  795.           || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
  796. #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET.  */
  797.           || (step_range_end && step_resume_breakpoint == NULL));
  798.       else
  799.         {
  800.           random_signal
  801.         = !(bpstat_explains_signal (stop_bpstat)
  802.             /* End of a stack dummy.  Some systems (e.g. Sony
  803.                news) give another signal besides SIGTRAP,
  804.                so check here as well as above.  */
  805. #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
  806.             || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
  807. #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET.  */
  808.             );
  809.           if (!random_signal)
  810.         stop_signal = TARGET_SIGNAL_TRAP;
  811.         }
  812.     }
  813.       else
  814.     random_signal = 1;
  815.  
  816.       /* For the program's own signals, act according to
  817.      the signal handling tables.  */
  818.  
  819.       if (random_signal)
  820.     {
  821.       /* Signal not for debugging purposes.  */
  822.       int printed = 0;
  823.       
  824.       stopped_by_random_signal = 1;
  825.       
  826.       if (signal_print[stop_signal])
  827.         {
  828.           printed = 1;
  829.           target_terminal_ours_for_output ();
  830.           annotate_signal ();
  831.           printf_filtered ("\nProgram received signal ");
  832.           annotate_signal_name ();
  833.           printf_filtered ("%s", target_signal_to_name (stop_signal));
  834.           annotate_signal_name_end ();
  835.           printf_filtered (", ");
  836.           annotate_signal_string ();
  837.           printf_filtered ("%s", target_signal_to_string (stop_signal));
  838.           annotate_signal_string_end ();
  839.           printf_filtered (".\n");
  840.           gdb_flush (gdb_stdout);
  841.         }
  842.       if (signal_stop[stop_signal])
  843.         break;
  844.       /* If not going to stop, give terminal back
  845.          if we took it away.  */
  846.       else if (printed)
  847.         target_terminal_inferior ();
  848.  
  849.       /* Clear the signal if it should not be passed.  */
  850.       if (signal_program[stop_signal] == 0)
  851.         stop_signal = TARGET_SIGNAL_0;
  852.  
  853.       /* I'm not sure whether this needs to be check_sigtramp2 or
  854.          whether it could/should be keep_going.  */
  855.       goto check_sigtramp2;
  856.     }
  857.  
  858.       /* Handle cases caused by hitting a breakpoint.  */
  859.       {
  860.     CORE_ADDR jmp_buf_pc;
  861.     struct bpstat_what what;
  862.  
  863.     what = bpstat_what (stop_bpstat);
  864.  
  865.     if (what.call_dummy)
  866.       {
  867.         stop_stack_dummy = 1;
  868. #ifdef HP_OS_BUG
  869.         trap_expected_after_continue = 1;
  870. #endif
  871.       }
  872.  
  873.     switch (what.main_action)
  874.       {
  875.       case BPSTAT_WHAT_SET_LONGJMP_RESUME:
  876.         /* If we hit the breakpoint at longjmp, disable it for the
  877.            duration of this command.  Then, install a temporary
  878.            breakpoint at the target of the jmp_buf. */
  879.         disable_longjmp_breakpoint();
  880.         remove_breakpoints ();
  881.         breakpoints_inserted = 0;
  882.         if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
  883.  
  884.         /* Need to blow away step-resume breakpoint, as it
  885.            interferes with us */
  886.         if (step_resume_breakpoint != NULL)
  887.           {
  888.         delete_breakpoint (step_resume_breakpoint);
  889.         step_resume_breakpoint = NULL;
  890.           }
  891.         /* Not sure whether we need to blow this away too, but probably
  892.            it is like the step-resume breakpoint.  */
  893.         if (through_sigtramp_breakpoint != NULL)
  894.           {
  895.         delete_breakpoint (through_sigtramp_breakpoint);
  896.         through_sigtramp_breakpoint = NULL;
  897.           }
  898.  
  899. #if 0
  900.         /* FIXME - Need to implement nested temporary breakpoints */
  901.         if (step_over_calls > 0)
  902.           set_longjmp_resume_breakpoint(jmp_buf_pc,
  903.                         get_current_frame());
  904.         else
  905. #endif                /* 0 */
  906.           set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
  907.         handling_longjmp = 1; /* FIXME */
  908.         goto keep_going;
  909.  
  910.       case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
  911.       case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
  912.         remove_breakpoints ();
  913.         breakpoints_inserted = 0;
  914. #if 0
  915.         /* FIXME - Need to implement nested temporary breakpoints */
  916.         if (step_over_calls
  917.         && (stop_frame_address
  918.             INNER_THAN step_frame_address))
  919.           {
  920.         another_trap = 1;
  921.         goto keep_going;
  922.           }
  923. #endif                /* 0 */
  924.         disable_longjmp_breakpoint();
  925.         handling_longjmp = 0; /* FIXME */
  926.         if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
  927.           break;
  928.         /* else fallthrough */
  929.  
  930.       case BPSTAT_WHAT_SINGLE:
  931.         if (breakpoints_inserted)
  932.           remove_breakpoints ();
  933.         breakpoints_inserted = 0;
  934.         another_trap = 1;
  935.         /* Still need to check other stuff, at least the case
  936.            where we are stepping and step out of the right range.  */
  937.         break;
  938.  
  939.       case BPSTAT_WHAT_STOP_NOISY:
  940.         stop_print_frame = 1;
  941.  
  942.         /* We are about to nuke the step_resume_breakpoint and
  943.            through_sigtramp_breakpoint via the cleanup chain, so
  944.            no need to worry about it here.  */
  945.  
  946.         goto stop_stepping;
  947.  
  948.       case BPSTAT_WHAT_STOP_SILENT:
  949.         stop_print_frame = 0;
  950.  
  951.         /* We are about to nuke the step_resume_breakpoint and
  952.            through_sigtramp_breakpoint via the cleanup chain, so
  953.            no need to worry about it here.  */
  954.  
  955.         goto stop_stepping;
  956.  
  957.       case BPSTAT_WHAT_STEP_RESUME:
  958.         delete_breakpoint (step_resume_breakpoint);
  959.         step_resume_breakpoint = NULL;
  960.         break;
  961.  
  962.       case BPSTAT_WHAT_THROUGH_SIGTRAMP:
  963.         delete_breakpoint (through_sigtramp_breakpoint);
  964.         through_sigtramp_breakpoint = NULL;
  965.  
  966.         /* If were waiting for a trap, hitting the step_resume_break
  967.            doesn't count as getting it.  */
  968.         if (trap_expected)
  969.           another_trap = 1;
  970.         break;
  971.  
  972.       case BPSTAT_WHAT_LAST:
  973.         /* Not a real code, but listed here to shut up gcc -Wall.  */
  974.  
  975.       case BPSTAT_WHAT_KEEP_CHECKING:
  976.         break;
  977.       }
  978.       }
  979.  
  980.       /* We come here if we hit a breakpoint but should not
  981.      stop for it.  Possibly we also were stepping
  982.      and should stop for that.  So fall through and
  983.      test for stepping.  But, if not stepping,
  984.      do not stop.  */
  985.  
  986. #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
  987.       /* This is the old way of detecting the end of the stack dummy.
  988.      An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
  989.      handled above.  As soon as we can test it on all of them, all
  990.      architectures should define it.  */
  991.  
  992.       /* If this is the breakpoint at the end of a stack dummy,
  993.      just stop silently, unless the user was doing an si/ni, in which
  994.      case she'd better know what she's doing.  */
  995.  
  996.       if (PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
  997.       && !step_range_end)
  998.     {
  999.       stop_print_frame = 0;
  1000.       stop_stack_dummy = 1;
  1001. #ifdef HP_OS_BUG
  1002.       trap_expected_after_continue = 1;
  1003. #endif
  1004.       break;
  1005.     }
  1006. #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET.  */
  1007.  
  1008.       if (step_resume_breakpoint)
  1009.     /* Having a step-resume breakpoint overrides anything
  1010.        else having to do with stepping commands until
  1011.        that breakpoint is reached.  */
  1012.     /* I'm not sure whether this needs to be check_sigtramp2 or
  1013.        whether it could/should be keep_going.  */
  1014.     goto check_sigtramp2;
  1015.  
  1016.       if (step_range_end == 0)
  1017.     /* Likewise if we aren't even stepping.  */
  1018.     /* I'm not sure whether this needs to be check_sigtramp2 or
  1019.        whether it could/should be keep_going.  */
  1020.     goto check_sigtramp2;
  1021.  
  1022.       /* If stepping through a line, keep going if still within it.  */
  1023.       if (stop_pc >= step_range_start
  1024.       && stop_pc < step_range_end
  1025.       /* The step range might include the start of the
  1026.          function, so if we are at the start of the
  1027.          step range and either the stack or frame pointers
  1028.          just changed, we've stepped outside */
  1029.       && !(stop_pc == step_range_start
  1030.            && stop_frame_address
  1031.            && (stop_sp INNER_THAN prev_sp
  1032.            || stop_frame_address != step_frame_address)))
  1033.     {
  1034.       /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
  1035.          So definately need to check for sigtramp here.  */
  1036.       goto check_sigtramp2;
  1037.     }
  1038.  
  1039.       /* We stepped out of the stepping range.  See if that was due
  1040.      to a subroutine call that we should proceed to the end of.  */
  1041.  
  1042.       /* Did we just take a signal?  */
  1043.       if (IN_SIGTRAMP (stop_pc, stop_func_name)
  1044.       && !IN_SIGTRAMP (prev_pc, prev_func_name))
  1045.     {
  1046.       /* We've just taken a signal; go until we are back to
  1047.          the point where we took it and one more.  */
  1048.  
  1049.       /* This code is needed at least in the following case:
  1050.          The user types "next" and then a signal arrives (before
  1051.          the "next" is done).  */
  1052.  
  1053.       /* Note that if we are stopped at a breakpoint, then we need
  1054.          the step_resume breakpoint to override any breakpoints at
  1055.          the same location, so that we will still step over the
  1056.          breakpoint even though the signal happened.  */
  1057.  
  1058.       {
  1059.         struct symtab_and_line sr_sal;
  1060.  
  1061.         sr_sal.pc = prev_pc;
  1062.         sr_sal.symtab = NULL;
  1063.         sr_sal.line = 0;
  1064.         /* We could probably be setting the frame to
  1065.            prev_frame_address; the reason we don't is that it didn't used
  1066.            to exist.  */
  1067.         step_resume_breakpoint =
  1068.           set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
  1069.         if (breakpoints_inserted)
  1070.           insert_breakpoints ();
  1071.       }
  1072.  
  1073.       /* If this is stepi or nexti, make sure that the stepping range
  1074.          gets us past that instruction.  */
  1075.       if (step_range_end == 1)
  1076.         /* FIXME: Does this run afoul of the code below which, if
  1077.            we step into the middle of a line, resets the stepping
  1078.            range?  */
  1079.         step_range_end = (step_range_start = prev_pc) + 1;
  1080.  
  1081.       remove_breakpoints_on_following_step = 1;
  1082.       goto keep_going;
  1083.     }
  1084.  
  1085. #if 1
  1086.       if (stop_func_start)
  1087.     {
  1088.       struct symtab *s;
  1089.  
  1090.       /* Do this after the IN_SIGTRAMP check; it might give
  1091.          an error.  */
  1092.       prologue_pc = stop_func_start;
  1093.  
  1094.       /* Don't skip the prologue if this is assembly source */
  1095.       s = find_pc_symtab (stop_pc);
  1096.       if (s && s->language != language_asm)
  1097.         SKIP_PROLOGUE (prologue_pc);
  1098.     }
  1099.  
  1100.       if ((/* Might be a non-recursive call.  If the symbols are missing
  1101.           enough that stop_func_start == prev_func_start even though
  1102.           they are really two functions, we will treat some calls as
  1103.           jumps.  */
  1104.        stop_func_start != prev_func_start
  1105.  
  1106.        /* Might be a recursive call if either we have a prologue
  1107.           or the call instruction itself saves the PC on the stack.  */
  1108.        || prologue_pc != stop_func_start
  1109.        || stop_sp != prev_sp)
  1110.       && (/* PC is completely out of bounds of any known objfiles.  Treat
  1111.          like a subroutine call. */
  1112.           ! stop_func_start
  1113.  
  1114.           /* If we do a call, we will be at the start of a function...  */
  1115.           || stop_pc == stop_func_start
  1116.  
  1117.           /* ...except on the Alpha with -O (and also Irix 5 and
  1118.          perhaps others), in which we might call the address
  1119.          after the load of gp.  Since prologues don't contain
  1120.          calls, we can't return to within one, and we don't
  1121.          jump back into them, so this check is OK.  */
  1122.  
  1123.           || stop_pc < prologue_pc
  1124.  
  1125.           /* ...and if it is a leaf function, the prologue might
  1126.           consist of gp loading only, so the call transfers to
  1127.           the first instruction after the prologue.  */
  1128.            || (stop_pc == prologue_pc
  1129.  
  1130.           /* Distinguish this from the case where we jump back
  1131.              to the first instruction after the prologue,
  1132.              within a function.  */
  1133.            && stop_func_start != prev_func_start)
  1134.  
  1135.           /* If we end up in certain places, it means we did a subroutine
  1136.          call.  I'm not completely sure this is necessary now that we
  1137.          have the above checks with stop_func_start (and now that
  1138.          find_pc_partial_function is pickier).  */
  1139.           || IN_SOLIB_TRAMPOLINE (stop_pc, stop_func_name)
  1140.  
  1141.           /* If none of the above apply, it is a jump within a function,
  1142.          or a return from a subroutine.  The other case is longjmp,
  1143.          which can no longer happen here as long as the
  1144.          handling_longjmp stuff is working.  */
  1145.           ))
  1146. #else
  1147. /* This is experimental code which greatly simplifies the subroutine call
  1148.    test.  I've actually tested on the Alpha, and it works great. -Stu */
  1149.  
  1150.     if (in_prologue (stop_pc, NULL)
  1151.         || (prev_func_start != 0
  1152.         && stop_func_start == 0))
  1153. #endif
  1154.     {
  1155.       /* It's a subroutine call.  */
  1156.  
  1157.       if (step_over_calls == 0)
  1158.         {
  1159.           /* I presume that step_over_calls is only 0 when we're
  1160.          supposed to be stepping at the assembly language level
  1161.          ("stepi").  Just stop.  */
  1162.           stop_step = 1;
  1163.           break;
  1164.         }
  1165.  
  1166.       if (step_over_calls > 0)
  1167.         /* We're doing a "next".  */
  1168.         goto step_over_function;
  1169.  
  1170.       /* If we are in a function call trampoline (a stub between
  1171.          the calling routine and the real function), locate the real
  1172.          function.  That's what tells us (a) whether we want to step
  1173.          into it at all, and (b) what prologue we want to run to
  1174.          the end of, if we do step into it.  */
  1175.       tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
  1176.       if (tmp != 0)
  1177.         stop_func_start = tmp;
  1178.  
  1179.       /* If we have line number information for the function we
  1180.          are thinking of stepping into, step into it.
  1181.  
  1182.          If there are several symtabs at that PC (e.g. with include
  1183.          files), just want to know whether *any* of them have line
  1184.          numbers.  find_pc_line handles this.  */
  1185.       {
  1186.         struct symtab_and_line tmp_sal;
  1187.  
  1188.         tmp_sal = find_pc_line (stop_func_start, 0);
  1189.         if (tmp_sal.line != 0)
  1190.           goto step_into_function;
  1191.       }
  1192.  
  1193. step_over_function:
  1194.       /* A subroutine call has happened.  */
  1195.       {
  1196.         /* Set a special breakpoint after the return */
  1197.         struct symtab_and_line sr_sal;
  1198.         sr_sal.pc = 
  1199.           ADDR_BITS_REMOVE
  1200.         (SAVED_PC_AFTER_CALL (get_current_frame ()));
  1201.         sr_sal.symtab = NULL;
  1202.         sr_sal.line = 0;
  1203.         step_resume_breakpoint =
  1204.           set_momentary_breakpoint (sr_sal, get_current_frame (),
  1205.                     bp_step_resume);
  1206.         step_resume_breakpoint->frame = prev_frame_address;
  1207.         if (breakpoints_inserted)
  1208.           insert_breakpoints ();
  1209.       }
  1210.       goto keep_going;
  1211.  
  1212. step_into_function:
  1213.       /* Subroutine call with source code we should not step over.
  1214.          Do step to the first line of code in it.  */
  1215.       {
  1216.         struct symtab *s;
  1217.  
  1218.         s = find_pc_symtab (stop_pc);
  1219.         if (s && s->language != language_asm)
  1220.           SKIP_PROLOGUE (stop_func_start);
  1221.       }
  1222.       sal = find_pc_line (stop_func_start, 0);
  1223.       /* Use the step_resume_break to step until
  1224.          the end of the prologue, even if that involves jumps
  1225.          (as it seems to on the vax under 4.2).  */
  1226.       /* If the prologue ends in the middle of a source line,
  1227.          continue to the end of that source line (if it is still
  1228.          within the function).  Otherwise, just go to end of prologue.  */
  1229. #ifdef PROLOGUE_FIRSTLINE_OVERLAP
  1230.       /* no, don't either.  It skips any code that's
  1231.          legitimately on the first line.  */
  1232. #else
  1233.       if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end)
  1234.         stop_func_start = sal.end;
  1235. #endif
  1236.  
  1237.       if (stop_func_start == stop_pc)
  1238.         {
  1239.           /* We are already there: stop now.  */
  1240.           stop_step = 1;
  1241.           break;
  1242.         }
  1243.       else
  1244.         /* Put the step-breakpoint there and go until there. */
  1245.         {
  1246.           struct symtab_and_line sr_sal;
  1247.  
  1248.           sr_sal.pc = stop_func_start;
  1249.           sr_sal.symtab = NULL;
  1250.           sr_sal.line = 0;
  1251.           /* Do not specify what the fp should be when we stop
  1252.          since on some machines the prologue
  1253.          is where the new fp value is established.  */
  1254.           step_resume_breakpoint =
  1255.         set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
  1256.           if (breakpoints_inserted)
  1257.         insert_breakpoints ();
  1258.  
  1259.           /* And make sure stepping stops right away then.  */
  1260.           step_range_end = step_range_start;
  1261.         }
  1262.       goto keep_going;
  1263.     }
  1264.  
  1265.       /* We've wandered out of the step range.  */
  1266.  
  1267.       sal = find_pc_line(stop_pc, 0);
  1268.  
  1269.       if (step_range_end == 1)
  1270.     {
  1271.       /* It is stepi or nexti.  We always want to stop stepping after
  1272.          one instruction.  */
  1273.       stop_step = 1;
  1274.       break;
  1275.     }
  1276.  
  1277.       if (sal.line == 0)
  1278.     {
  1279.       /* We have no line number information.  That means to stop
  1280.          stepping (does this always happen right after one instruction,
  1281.          when we do "s" in a function with no line numbers,
  1282.          or can this happen as a result of a return or longjmp?).  */
  1283.       stop_step = 1;
  1284.       break;
  1285.     }
  1286.  
  1287.       if (stop_pc == sal.pc
  1288.       && (current_line != sal.line || current_symtab != sal.symtab))
  1289.     {
  1290.       /* We are at the start of a different line.  So stop.  Note that
  1291.          we don't stop if we step into the middle of a different line.
  1292.          That is said to make things like for (;;) statements work
  1293.          better.  */
  1294.       stop_step = 1;
  1295.       break;
  1296.     }
  1297.  
  1298.       /* We aren't done stepping.
  1299.  
  1300.      Optimize by setting the stepping range to the line.
  1301.      (We might not be in the original line, but if we entered a
  1302.      new line in mid-statement, we continue stepping.  This makes 
  1303.      things like for(;;) statements work better.)  */
  1304.  
  1305.       if (stop_func_end && sal.end >= stop_func_end)
  1306.     {
  1307.       /* If this is the last line of the function, don't keep stepping
  1308.          (it would probably step us out of the function).
  1309.          This is particularly necessary for a one-line function,
  1310.          in which after skipping the prologue we better stop even though
  1311.          we will be in mid-line.  */
  1312.       stop_step = 1;
  1313.       break;
  1314.     }
  1315.       step_range_start = sal.pc;
  1316.       step_range_end = sal.end;
  1317.       goto keep_going;
  1318.  
  1319.     check_sigtramp2:
  1320.       if (trap_expected
  1321.       && IN_SIGTRAMP (stop_pc, stop_func_name)
  1322.       && !IN_SIGTRAMP (prev_pc, prev_func_name))
  1323.     {
  1324.       /* What has happened here is that we have just stepped the inferior
  1325.          with a signal (because it is a signal which shouldn't make
  1326.          us stop), thus stepping into sigtramp.
  1327.  
  1328.          So we need to set a step_resume_break_address breakpoint
  1329.          and continue until we hit it, and then step.  FIXME: This should
  1330.          be more enduring than a step_resume breakpoint; we should know
  1331.          that we will later need to keep going rather than re-hitting
  1332.          the breakpoint here (see testsuite/gdb.t06/signals.exp where
  1333.          it says "exceedingly difficult").  */
  1334.       struct symtab_and_line sr_sal;
  1335.  
  1336.       sr_sal.pc = prev_pc;
  1337.       sr_sal.symtab = NULL;
  1338.       sr_sal.line = 0;
  1339.       /* We perhaps could set the frame if we kept track of what
  1340.          the frame corresponding to prev_pc was.  But we don't,
  1341.          so don't.  */
  1342.       through_sigtramp_breakpoint =
  1343.         set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
  1344.       if (breakpoints_inserted)
  1345.         insert_breakpoints ();
  1346.  
  1347.       remove_breakpoints_on_following_step = 1;
  1348.       another_trap = 1;
  1349.     }
  1350.  
  1351.     keep_going:
  1352.       /* Come to this label when you need to resume the inferior.
  1353.      It's really much cleaner to do a goto than a maze of if-else
  1354.      conditions.  */
  1355.  
  1356.       /* Save the pc before execution, to compare with pc after stop.  */
  1357.       prev_pc = read_pc ();    /* Might have been DECR_AFTER_BREAK */
  1358.       prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
  1359.                       BREAK is defined, the
  1360.                       original pc would not have
  1361.                       been at the start of a
  1362.                       function. */
  1363.       prev_func_name = stop_func_name;
  1364.       prev_sp = stop_sp;
  1365.       prev_frame_address = stop_frame_address;
  1366.  
  1367.       /* If we did not do break;, it means we should keep
  1368.      running the inferior and not return to debugger.  */
  1369.  
  1370.       if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
  1371.     {
  1372.       /* We took a signal (which we are supposed to pass through to
  1373.          the inferior, else we'd have done a break above) and we
  1374.          haven't yet gotten our trap.  Simply continue.  */
  1375.       resume (CURRENTLY_STEPPING (), stop_signal);
  1376.     }
  1377.       else
  1378.     {
  1379.       /* Either the trap was not expected, but we are continuing
  1380.          anyway (the user asked that this signal be passed to the
  1381.          child)
  1382.            -- or --
  1383.          The signal was SIGTRAP, e.g. it was our signal, but we
  1384.          decided we should resume from it.
  1385.  
  1386.          We're going to run this baby now!
  1387.  
  1388.          Insert breakpoints now, unless we are trying
  1389.          to one-proceed past a breakpoint.  */
  1390.       /* If we've just finished a special step resume and we don't
  1391.          want to hit a breakpoint, pull em out.  */
  1392.       if (step_resume_breakpoint == NULL
  1393.           && through_sigtramp_breakpoint == NULL
  1394.           && remove_breakpoints_on_following_step)
  1395.         {
  1396.           remove_breakpoints_on_following_step = 0;
  1397.           remove_breakpoints ();
  1398.           breakpoints_inserted = 0;
  1399.         }
  1400.       else if (!breakpoints_inserted &&
  1401.            (through_sigtramp_breakpoint != NULL || !another_trap))
  1402.         {
  1403.           breakpoints_failed = insert_breakpoints ();
  1404.           if (breakpoints_failed)
  1405.         break;
  1406.           breakpoints_inserted = 1;
  1407.         }
  1408.  
  1409.       trap_expected = another_trap;
  1410.  
  1411.       if (stop_signal == TARGET_SIGNAL_TRAP)
  1412.         stop_signal = TARGET_SIGNAL_0;
  1413.  
  1414. #ifdef SHIFT_INST_REGS
  1415.       /* I'm not sure when this following segment applies.  I do know, now,
  1416.          that we shouldn't rewrite the regs when we were stopped by a
  1417.          random signal from the inferior process.  */
  1418.       /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
  1419.          (this is only used on the 88k).  */
  1420.  
  1421.           if (!bpstat_explains_signal (stop_bpstat)
  1422.           && (stop_signal != TARGET_SIGNAL_CHLD) 
  1423.               && !stopped_by_random_signal)
  1424.             SHIFT_INST_REGS();
  1425. #endif /* SHIFT_INST_REGS */
  1426.  
  1427.       resume (CURRENTLY_STEPPING (), stop_signal);
  1428.     }
  1429.     }
  1430.  
  1431.  stop_stepping:
  1432.   if (target_has_execution)
  1433.     {
  1434.       /* Assuming the inferior still exists, set these up for next
  1435.      time, just like we did above if we didn't break out of the
  1436.      loop.  */
  1437.       prev_pc = read_pc ();
  1438.       prev_func_start = stop_func_start;
  1439.       prev_func_name = stop_func_name;
  1440.       prev_sp = stop_sp;
  1441.       prev_frame_address = stop_frame_address;
  1442.     }
  1443.   do_cleanups (old_cleanups);
  1444. }
  1445.  
  1446. /* Here to return control to GDB when the inferior stops for real.
  1447.    Print appropriate messages, remove breakpoints, give terminal our modes.
  1448.  
  1449.    STOP_PRINT_FRAME nonzero means print the executing frame
  1450.    (pc, function, args, file, line number and line text).
  1451.    BREAKPOINTS_FAILED nonzero means stop was due to error
  1452.    attempting to insert breakpoints.  */
  1453.  
  1454. void
  1455. normal_stop ()
  1456. {
  1457.   /* Make sure that the current_frame's pc is correct.  This
  1458.      is a correction for setting up the frame info before doing
  1459.      DECR_PC_AFTER_BREAK */
  1460.   if (target_has_execution && get_current_frame())
  1461.     (get_current_frame ())->pc = read_pc ();
  1462.   
  1463.   if (breakpoints_failed)
  1464.     {
  1465.       target_terminal_ours_for_output ();
  1466.       print_sys_errmsg ("ptrace", breakpoints_failed);
  1467.       printf_filtered ("Stopped; cannot insert breakpoints.\n\
  1468. The same program may be running in another process.\n");
  1469.     }
  1470.  
  1471.   if (target_has_execution && breakpoints_inserted)
  1472.     if (remove_breakpoints ())
  1473.       {
  1474.     target_terminal_ours_for_output ();
  1475.     printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
  1476. It might be running in another process.\n\
  1477. Further execution is probably impossible.\n");
  1478.       }
  1479.  
  1480.   breakpoints_inserted = 0;
  1481.  
  1482.   /* Delete the breakpoint we stopped at, if it wants to be deleted.
  1483.      Delete any breakpoint that is to be deleted at the next stop.  */
  1484.  
  1485.   breakpoint_auto_delete (stop_bpstat);
  1486.  
  1487.   /* If an auto-display called a function and that got a signal,
  1488.      delete that auto-display to avoid an infinite recursion.  */
  1489.  
  1490.   if (stopped_by_random_signal)
  1491.     disable_current_display ();
  1492.  
  1493.   if (step_multi && stop_step)
  1494.     goto done;
  1495.  
  1496.   target_terminal_ours ();
  1497.  
  1498.   /* Look up the hook_stop and run it if it exists.  */
  1499.  
  1500.   if (stop_command->hook)
  1501.     {
  1502.       catch_errors (hook_stop_stub, (char *)stop_command->hook,
  1503.             "Error while running hook_stop:\n", RETURN_MASK_ALL);
  1504.     }
  1505.  
  1506.   if (!target_has_stack)
  1507.     goto done;
  1508.  
  1509.   /* Select innermost stack frame except on return from a stack dummy routine,
  1510.      or if the program has exited.  Print it without a level number if
  1511.      we have changed functions or hit a breakpoint.  Print source line
  1512.      if we have one.  */
  1513.   if (!stop_stack_dummy)
  1514.     {
  1515.       if (stop_print_frame)
  1516.     {
  1517.       int source_only;
  1518.  
  1519.       source_only = bpstat_print (stop_bpstat);
  1520.       source_only = source_only ||
  1521.             (   stop_step
  1522.          && step_frame_address == stop_frame_address
  1523.          && step_start_function == find_pc_function (stop_pc));
  1524.  
  1525.           print_stack_frame (selected_frame, -1, source_only? -1: 1);
  1526.  
  1527.       /* Display the auto-display expressions.  */
  1528.       do_displays ();
  1529.     }
  1530.     }
  1531.  
  1532.   /* Save the function value return registers, if we care.
  1533.      We might be about to restore their previous contents.  */
  1534.   if (proceed_to_finish)
  1535.     read_register_bytes (0, stop_registers, REGISTER_BYTES);
  1536.  
  1537.   if (stop_stack_dummy)
  1538.     {
  1539.       /* Pop the empty frame that contains the stack dummy.
  1540.          POP_FRAME ends with a setting of the current frame, so we
  1541.      can use that next. */
  1542.       POP_FRAME;
  1543.       /* Set stop_pc to what it was before we called the function.  Can't rely
  1544.      on restore_inferior_status because that only gets called if we don't
  1545.      stop in the called function.  */
  1546.       stop_pc = read_pc();
  1547.       select_frame (get_current_frame (), 0);
  1548.     }
  1549.  done:
  1550.   annotate_stopped ();
  1551. }
  1552.  
  1553. static int
  1554. hook_stop_stub (cmd)
  1555.      char *cmd;
  1556. {
  1557.   execute_user_command ((struct cmd_list_element *)cmd, 0);
  1558.   return (0);
  1559. }
  1560.  
  1561. int signal_stop_state (signo)
  1562.      int signo;
  1563. {
  1564.   return signal_stop[signo];
  1565. }
  1566.  
  1567. int signal_print_state (signo)
  1568.      int signo;
  1569. {
  1570.   return signal_print[signo];
  1571. }
  1572.  
  1573. int signal_pass_state (signo)
  1574.      int signo;
  1575. {
  1576.   return signal_program[signo];
  1577. }
  1578.  
  1579. static void
  1580. sig_print_header ()
  1581. {
  1582.   printf_filtered ("\
  1583. Signal        Stop\tPrint\tPass to program\tDescription\n");
  1584. }
  1585.  
  1586. static void
  1587. sig_print_info (oursig)
  1588.      enum target_signal oursig;
  1589. {
  1590.   char *name = target_signal_to_name (oursig);
  1591.   printf_filtered ("%s", name);
  1592.   printf_filtered ("%*.*s ", 13 - strlen (name), 13 - strlen (name),
  1593.            "                 ");
  1594.   printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
  1595.   printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
  1596.   printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
  1597.   printf_filtered ("%s\n", target_signal_to_string (oursig));
  1598. }
  1599.  
  1600. /* Specify how various signals in the inferior should be handled.  */
  1601.  
  1602. static void
  1603. handle_command (args, from_tty)
  1604.      char *args;
  1605.      int from_tty;
  1606. {
  1607.   char **argv;
  1608.   int digits, wordlen;
  1609.   int sigfirst, signum, siglast;
  1610.   enum target_signal oursig;
  1611.   int allsigs;
  1612.   int nsigs;
  1613.   unsigned char *sigs;
  1614.   struct cleanup *old_chain;
  1615.  
  1616.   if (args == NULL)
  1617.     {
  1618.       error_no_arg ("signal to handle");
  1619.     }
  1620.  
  1621.   /* Allocate and zero an array of flags for which signals to handle. */
  1622.  
  1623.   nsigs = (int)TARGET_SIGNAL_LAST;
  1624.   sigs = (unsigned char *) alloca (nsigs);
  1625.   memset (sigs, 0, nsigs);
  1626.  
  1627.   /* Break the command line up into args. */
  1628.  
  1629.   argv = buildargv (args);
  1630.   if (argv == NULL)
  1631.     {
  1632.       nomem (0);
  1633.     }
  1634.   old_chain = make_cleanup (freeargv, (char *) argv);
  1635.  
  1636.   /* Walk through the args, looking for signal oursigs, signal names, and
  1637.      actions.  Signal numbers and signal names may be interspersed with
  1638.      actions, with the actions being performed for all signals cumulatively
  1639.      specified.  Signal ranges can be specified as <LOW>-<HIGH>. */
  1640.  
  1641.   while (*argv != NULL)
  1642.     {
  1643.       wordlen = strlen (*argv);
  1644.       for (digits = 0; isdigit ((*argv)[digits]); digits++) {;}
  1645.       allsigs = 0;
  1646.       sigfirst = siglast = -1;
  1647.  
  1648.       if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
  1649.     {
  1650.       /* Apply action to all signals except those used by the
  1651.          debugger.  Silently skip those. */
  1652.       allsigs = 1;
  1653.       sigfirst = 0;
  1654.       siglast = nsigs - 1;
  1655.     }
  1656.       else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
  1657.     {
  1658.       SET_SIGS (nsigs, sigs, signal_stop);
  1659.       SET_SIGS (nsigs, sigs, signal_print);
  1660.     }
  1661.       else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
  1662.     {
  1663.       UNSET_SIGS (nsigs, sigs, signal_program);
  1664.     }
  1665.       else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
  1666.     {
  1667.       SET_SIGS (nsigs, sigs, signal_print);
  1668.     }
  1669.       else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
  1670.     {
  1671.       SET_SIGS (nsigs, sigs, signal_program);
  1672.     }
  1673.       else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
  1674.     {
  1675.       UNSET_SIGS (nsigs, sigs, signal_stop);
  1676.     }
  1677.       else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
  1678.     {
  1679.       SET_SIGS (nsigs, sigs, signal_program);
  1680.     }
  1681.       else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
  1682.     {
  1683.       UNSET_SIGS (nsigs, sigs, signal_print);
  1684.       UNSET_SIGS (nsigs, sigs, signal_stop);
  1685.     }
  1686.       else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
  1687.     {
  1688.       UNSET_SIGS (nsigs, sigs, signal_program);
  1689.     }
  1690.       else if (digits > 0)
  1691.     {
  1692.       /* It is numeric.  The numeric signal refers to our own internal
  1693.          signal numbering from target.h, not to host/target signal number.
  1694.          This is a feature; users really should be using symbolic names
  1695.          anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
  1696.          will work right anyway.  */
  1697.  
  1698.       sigfirst = siglast = atoi (*argv);
  1699.       if ((*argv)[digits] == '-')
  1700.         {
  1701.           siglast = atoi ((*argv) + digits + 1);
  1702.         }
  1703.       if (sigfirst > siglast)
  1704.         {
  1705.           /* Bet he didn't figure we'd think of this case... */
  1706.           signum = sigfirst;
  1707.           sigfirst = siglast;
  1708.           siglast = signum;
  1709.         }
  1710.       if (sigfirst < 0 || sigfirst >= nsigs)
  1711.         {
  1712.           error ("Signal %d not in range 0-%d", sigfirst, nsigs - 1);
  1713.         }
  1714.       if (siglast < 0 || siglast >= nsigs)
  1715.         {
  1716.           error ("Signal %d not in range 0-%d", siglast, nsigs - 1);
  1717.         }
  1718.     }
  1719.       else
  1720.     {
  1721.       oursig = target_signal_from_name (*argv);
  1722.       if (oursig != TARGET_SIGNAL_UNKNOWN)
  1723.         {
  1724.           sigfirst = siglast = (int)oursig;
  1725.         }
  1726.       else
  1727.         {
  1728.           /* Not a number and not a recognized flag word => complain.  */
  1729.           error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
  1730.         }
  1731.     }
  1732.  
  1733.       /* If any signal numbers or symbol names were found, set flags for
  1734.      which signals to apply actions to. */
  1735.  
  1736.       for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
  1737.     {
  1738.       switch ((enum target_signal)signum)
  1739.         {
  1740.           case TARGET_SIGNAL_TRAP:
  1741.           case TARGET_SIGNAL_INT:
  1742.             if (!allsigs && !sigs[signum])
  1743.           {
  1744.             if (query ("%s is used by the debugger.\n\
  1745. Are you sure you want to change it? ",
  1746.                    target_signal_to_name
  1747.                    ((enum target_signal)signum)))
  1748.               {
  1749.             sigs[signum] = 1;
  1750.               }
  1751.             else
  1752.               {
  1753.             printf_unfiltered ("Not confirmed, unchanged.\n");
  1754.             gdb_flush (gdb_stdout);
  1755.               }
  1756.           }
  1757.         break;
  1758.           default:
  1759.         sigs[signum] = 1;
  1760.         break;
  1761.         }
  1762.     }
  1763.  
  1764.       argv++;
  1765.     }
  1766.  
  1767.   target_notice_signals(inferior_pid);
  1768.  
  1769.   if (from_tty)
  1770.     {
  1771.       /* Show the results.  */
  1772.       sig_print_header ();
  1773.       for (signum = 0; signum < nsigs; signum++)
  1774.     {
  1775.       if (sigs[signum])
  1776.         {
  1777.           sig_print_info (signum);
  1778.         }
  1779.     }
  1780.     }
  1781.  
  1782.   do_cleanups (old_chain);
  1783. }
  1784.  
  1785. /* Print current contents of the tables set by the handle command.
  1786.    It is possible we should just be printing signals actually used
  1787.    by the current target (but for things to work right when switching
  1788.    targets, all signals should be in the signal tables).  */
  1789.  
  1790. static void
  1791. signals_info (signum_exp, from_tty)
  1792.      char *signum_exp;
  1793.      int from_tty;
  1794. {
  1795.   enum target_signal oursig;
  1796.   sig_print_header ();
  1797.  
  1798.   if (signum_exp)
  1799.     {
  1800.       /* First see if this is a symbol name.  */
  1801.       oursig = target_signal_from_name (signum_exp);
  1802.       if (oursig == TARGET_SIGNAL_UNKNOWN)
  1803.     {
  1804.       /* Nope, maybe it's an address which evaluates to a signal
  1805.          number.  */
  1806.       /* The numeric signal refers to our own internal
  1807.          signal numbering from target.h, not to host/target signal number.
  1808.          This is a feature; users really should be using symbolic names
  1809.          anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
  1810.          will work right anyway.  */
  1811.       int i = parse_and_eval_address (signum_exp);
  1812.       if (i >= (int)TARGET_SIGNAL_LAST
  1813.           || i < 0
  1814.           || i == (int)TARGET_SIGNAL_UNKNOWN
  1815.           || i == (int)TARGET_SIGNAL_DEFAULT)
  1816.         error ("Signal number out of bounds.");
  1817.       oursig = (enum target_signal)i;
  1818.     }
  1819.       sig_print_info (oursig);
  1820.       return;
  1821.     }
  1822.  
  1823.   printf_filtered ("\n");
  1824.   /* These ugly casts brought to you by the native VAX compiler.  */
  1825.   for (oursig = TARGET_SIGNAL_FIRST;
  1826.        (int)oursig < (int)TARGET_SIGNAL_LAST;
  1827.        oursig = (enum target_signal)((int)oursig + 1))
  1828.     {
  1829.       QUIT;
  1830.  
  1831.       if (oursig != TARGET_SIGNAL_UNKNOWN
  1832.       && oursig != TARGET_SIGNAL_DEFAULT
  1833.       && oursig != TARGET_SIGNAL_0)
  1834.     sig_print_info (oursig);
  1835.     }
  1836.  
  1837.   printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
  1838. }
  1839.  
  1840. /* Save all of the information associated with the inferior<==>gdb
  1841.    connection.  INF_STATUS is a pointer to a "struct inferior_status"
  1842.    (defined in inferior.h).  */
  1843.  
  1844. void
  1845. save_inferior_status (inf_status, restore_stack_info)
  1846.      struct inferior_status *inf_status;
  1847.      int restore_stack_info;
  1848. {
  1849.   inf_status->stop_signal = stop_signal;
  1850.   inf_status->stop_pc = stop_pc;
  1851.   inf_status->stop_frame_address = stop_frame_address;
  1852.   inf_status->stop_step = stop_step;
  1853.   inf_status->stop_stack_dummy = stop_stack_dummy;
  1854.   inf_status->stopped_by_random_signal = stopped_by_random_signal;
  1855.   inf_status->trap_expected = trap_expected;
  1856.   inf_status->step_range_start = step_range_start;
  1857.   inf_status->step_range_end = step_range_end;
  1858.   inf_status->step_frame_address = step_frame_address;
  1859.   inf_status->step_over_calls = step_over_calls;
  1860.   inf_status->stop_after_trap = stop_after_trap;
  1861.   inf_status->stop_soon_quietly = stop_soon_quietly;
  1862.   /* Save original bpstat chain here; replace it with copy of chain. 
  1863.      If caller's caller is walking the chain, they'll be happier if we
  1864.      hand them back the original chain when restore_i_s is called.  */
  1865.   inf_status->stop_bpstat = stop_bpstat;
  1866.   stop_bpstat = bpstat_copy (stop_bpstat);
  1867.   inf_status->breakpoint_proceeded = breakpoint_proceeded;
  1868.   inf_status->restore_stack_info = restore_stack_info;
  1869.   inf_status->proceed_to_finish = proceed_to_finish;
  1870.   
  1871.   memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
  1872.  
  1873.   read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
  1874.  
  1875.   record_selected_frame (&(inf_status->selected_frame_address),
  1876.              &(inf_status->selected_level));
  1877.   return;
  1878. }
  1879.  
  1880. struct restore_selected_frame_args {
  1881.   FRAME_ADDR frame_address;
  1882.   int level;
  1883. };
  1884.  
  1885. static int restore_selected_frame PARAMS ((char *));
  1886.  
  1887. /* Restore the selected frame.  args is really a struct
  1888.    restore_selected_frame_args * (declared as char * for catch_errors)
  1889.    telling us what frame to restore.  Returns 1 for success, or 0 for
  1890.    failure.  An error message will have been printed on error.  */
  1891. static int
  1892. restore_selected_frame (args)
  1893.      char *args;
  1894. {
  1895.   struct restore_selected_frame_args *fr =
  1896.     (struct restore_selected_frame_args *) args;
  1897.   FRAME fid;
  1898.   int level = fr->level;
  1899.  
  1900.   fid = find_relative_frame (get_current_frame (), &level);
  1901.  
  1902.   /* If inf_status->selected_frame_address is NULL, there was no
  1903.      previously selected frame.  */
  1904.   if (fid == 0 ||
  1905.       FRAME_FP (fid) != fr->frame_address ||
  1906.       level != 0)
  1907.     {
  1908.       warning ("Unable to restore previously selected frame.\n");
  1909.       return 0;
  1910.     }
  1911.   select_frame (fid, fr->level);
  1912.   return(1);
  1913. }
  1914.  
  1915. void
  1916. restore_inferior_status (inf_status)
  1917.      struct inferior_status *inf_status;
  1918. {
  1919.   stop_signal = inf_status->stop_signal;
  1920.   stop_pc = inf_status->stop_pc;
  1921.   stop_frame_address = inf_status->stop_frame_address;
  1922.   stop_step = inf_status->stop_step;
  1923.   stop_stack_dummy = inf_status->stop_stack_dummy;
  1924.   stopped_by_random_signal = inf_status->stopped_by_random_signal;
  1925.   trap_expected = inf_status->trap_expected;
  1926.   step_range_start = inf_status->step_range_start;
  1927.   step_range_end = inf_status->step_range_end;
  1928.   step_frame_address = inf_status->step_frame_address;
  1929.   step_over_calls = inf_status->step_over_calls;
  1930.   stop_after_trap = inf_status->stop_after_trap;
  1931.   stop_soon_quietly = inf_status->stop_soon_quietly;
  1932.   bpstat_clear (&stop_bpstat);
  1933.   stop_bpstat = inf_status->stop_bpstat;
  1934.   breakpoint_proceeded = inf_status->breakpoint_proceeded;
  1935.   proceed_to_finish = inf_status->proceed_to_finish;
  1936.  
  1937.   memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
  1938.  
  1939.   /* The inferior can be gone if the user types "print exit(0)"
  1940.      (and perhaps other times).  */
  1941.   if (target_has_execution)
  1942.     write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
  1943.  
  1944.   /* The inferior can be gone if the user types "print exit(0)"
  1945.      (and perhaps other times).  */
  1946.  
  1947.   /* FIXME: If we are being called after stopping in a function which
  1948.      is called from gdb, we should not be trying to restore the
  1949.      selected frame; it just prints a spurious error message (The
  1950.      message is useful, however, in detecting bugs in gdb (like if gdb
  1951.      clobbers the stack)).  In fact, should we be restoring the
  1952.      inferior status at all in that case?  .  */
  1953.  
  1954.   if (target_has_stack && inf_status->restore_stack_info)
  1955.     {
  1956.       struct restore_selected_frame_args fr;
  1957.       fr.level = inf_status->selected_level;
  1958.       fr.frame_address = inf_status->selected_frame_address;
  1959.       /* The point of catch_errors is that if the stack is clobbered,
  1960.      walking the stack might encounter a garbage pointer and error()
  1961.      trying to dereference it.  */
  1962.       if (catch_errors (restore_selected_frame, &fr,
  1963.             "Unable to restore previously selected frame:\n",
  1964.             RETURN_MASK_ERROR) == 0)
  1965.     /* Error in restoring the selected frame.  Select the innermost
  1966.        frame.  */
  1967.     select_frame (get_current_frame (), 0);
  1968.     }
  1969. }
  1970.  
  1971.  
  1972. void
  1973. _initialize_infrun ()
  1974. {
  1975.   register int i;
  1976.   register int numsigs;
  1977.  
  1978.   add_info ("signals", signals_info,
  1979.         "What debugger does when program gets various signals.\n\
  1980. Specify a signal number as argument to print info on that signal only.");
  1981.   add_info_alias ("handle", "signals", 0);
  1982.  
  1983.   add_com ("handle", class_run, handle_command,
  1984.        "Specify how to handle a signal.\n\
  1985. Args are signal numbers and actions to apply to those signals.\n\
  1986. Signal numbers may be numeric (ex. 11) or symbolic (ex. SIGSEGV).\n\
  1987. Numeric ranges may be specified with the form LOW-HIGH (ex. 14-21).\n\
  1988. The special arg \"all\" is recognized to mean all signals except those\n\
  1989. used by the debugger, typically SIGTRAP and SIGINT.\n\
  1990. Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
  1991. \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
  1992. Stop means reenter debugger if this signal happens (implies print).\n\
  1993. Print means print a message if this signal happens.\n\
  1994. Pass means let program see this signal; otherwise program doesn't know.\n\
  1995. Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
  1996. Pass and Stop may be combined.");
  1997.  
  1998.   stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
  1999.        "There is no `stop' command, but you can set a hook on `stop'.\n\
  2000. This allows you to set a list of commands to be run each time execution\n\
  2001. of the program stops.", &cmdlist);
  2002.  
  2003.   numsigs = (int)TARGET_SIGNAL_LAST;
  2004.   signal_stop = (unsigned char *)    
  2005.     xmalloc (sizeof (signal_stop[0]) * numsigs);
  2006.   signal_print = (unsigned char *)
  2007.     xmalloc (sizeof (signal_print[0]) * numsigs);
  2008.   signal_program = (unsigned char *)
  2009.     xmalloc (sizeof (signal_program[0]) * numsigs);
  2010.   for (i = 0; i < numsigs; i++)
  2011.     {
  2012.       signal_stop[i] = 1;
  2013.       signal_print[i] = 1;
  2014.       signal_program[i] = 1;
  2015.     }
  2016.  
  2017.   /* Signals caused by debugger's own actions
  2018.      should not be given to the program afterwards.  */
  2019.   signal_program[TARGET_SIGNAL_TRAP] = 0;
  2020.   signal_program[TARGET_SIGNAL_INT] = 0;
  2021.  
  2022.   /* Signals that are not errors should not normally enter the debugger.  */
  2023.   signal_stop[TARGET_SIGNAL_ALRM] = 0;
  2024.   signal_print[TARGET_SIGNAL_ALRM] = 0;
  2025.   signal_stop[TARGET_SIGNAL_VTALRM] = 0;
  2026.   signal_print[TARGET_SIGNAL_VTALRM] = 0;
  2027.   signal_stop[TARGET_SIGNAL_PROF] = 0;
  2028.   signal_print[TARGET_SIGNAL_PROF] = 0;
  2029.   signal_stop[TARGET_SIGNAL_CHLD] = 0;
  2030.   signal_print[TARGET_SIGNAL_CHLD] = 0;
  2031.   signal_stop[TARGET_SIGNAL_IO] = 0;
  2032.   signal_print[TARGET_SIGNAL_IO] = 0;
  2033.   signal_stop[TARGET_SIGNAL_POLL] = 0;
  2034.   signal_print[TARGET_SIGNAL_POLL] = 0;
  2035.   signal_stop[TARGET_SIGNAL_URG] = 0;
  2036.   signal_print[TARGET_SIGNAL_URG] = 0;
  2037. }
  2038.