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