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