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