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