1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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. */
22 #include "gdb_string.h"
27 #include "breakpoint.h"
32 #include "gdbthread.h"
34 #include "symfile.h" /* for overlay functions */
38 /* Prototypes for local functions */
40 static void signals_info PARAMS ((char *, int));
42 static void handle_command PARAMS ((char *, int));
44 static void sig_print_info PARAMS ((enum target_signal));
46 static void sig_print_header PARAMS ((void));
48 static void resume_cleanups PARAMS ((int));
50 static int hook_stop_stub PARAMS ((char *));
52 static void delete_breakpoint_current_contents PARAMS ((PTR));
54 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
55 program. It needs to examine the jmp_buf argument and extract the PC
56 from it. The return value is non-zero on success, zero otherwise. */
58 #ifndef GET_LONGJMP_TARGET
59 #define GET_LONGJMP_TARGET(PC_ADDR) 0
63 /* Some machines have trampoline code that sits between function callers
64 and the actual functions themselves. If this machine doesn't have
65 such things, disable their processing. */
67 #ifndef SKIP_TRAMPOLINE_CODE
68 #define SKIP_TRAMPOLINE_CODE(pc) 0
71 /* Dynamic function trampolines are similar to solib trampolines in that they
72 are between the caller and the callee. The difference is that when you
73 enter a dynamic trampoline, you can't determine the callee's address. Some
74 (usually complex) code needs to run in the dynamic trampoline to figure out
75 the callee's address. This macro is usually called twice. First, when we
76 enter the trampoline (looks like a normal function call at that point). It
77 should return the PC of a point within the trampoline where the callee's
78 address is known. Second, when we hit the breakpoint, this routine returns
79 the callee's address. At that point, things proceed as per a step resume
82 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
83 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
86 /* On SVR4 based systems, determining the callee's address is exceedingly
87 difficult and depends on the implementation of the run time loader.
88 If we are stepping at the source level, we single step until we exit
89 the run time loader code and reach the callee's address. */
91 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
92 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
95 /* For SVR4 shared libraries, each call goes through a small piece of
96 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
97 to nonzero if we are current stopped in one of these. */
99 #ifndef IN_SOLIB_CALL_TRAMPOLINE
100 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
103 /* In some shared library schemes, the return path from a shared library
104 call may need to go through a trampoline too. */
106 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
107 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
110 /* On MIPS16, a function that returns a floating point value may call
111 a library helper function to copy the return value to a floating point
112 register. The IGNORE_HELPER_CALL macro returns non-zero if we
113 should ignore (i.e. step over) this function call. */
114 #ifndef IGNORE_HELPER_CALL
115 #define IGNORE_HELPER_CALL(pc) 0
118 /* On some systems, the PC may be left pointing at an instruction that won't
119 actually be executed. This is usually indicated by a bit in the PSW. If
120 we find ourselves in such a state, then we step the target beyond the
121 nullified instruction before returning control to the user so as to avoid
124 #ifndef INSTRUCTION_NULLIFIED
125 #define INSTRUCTION_NULLIFIED 0
128 /* Tables of how to react to signals; the user sets them. */
130 static unsigned char *signal_stop;
131 static unsigned char *signal_print;
132 static unsigned char *signal_program;
134 #define SET_SIGS(nsigs,sigs,flags) \
136 int signum = (nsigs); \
137 while (signum-- > 0) \
138 if ((sigs)[signum]) \
139 (flags)[signum] = 1; \
142 #define UNSET_SIGS(nsigs,sigs,flags) \
144 int signum = (nsigs); \
145 while (signum-- > 0) \
146 if ((sigs)[signum]) \
147 (flags)[signum] = 0; \
151 /* Command list pointer for the "stop" placeholder. */
153 static struct cmd_list_element *stop_command;
155 /* Nonzero if breakpoints are now inserted in the inferior. */
157 static int breakpoints_inserted;
159 /* Function inferior was in as of last step command. */
161 static struct symbol *step_start_function;
163 /* Nonzero if we are expecting a trace trap and should proceed from it. */
165 static int trap_expected;
168 /* Nonzero if we want to give control to the user when we're notified
169 of shared library events by the dynamic linker. */
170 static int stop_on_solib_events;
174 /* Nonzero if the next time we try to continue the inferior, it will
175 step one instruction and generate a spurious trace trap.
176 This is used to compensate for a bug in HP-UX. */
178 static int trap_expected_after_continue;
181 /* Nonzero means expecting a trace trap
182 and should stop the inferior and return silently when it happens. */
186 /* Nonzero means expecting a trap and caller will handle it themselves.
187 It is used after attach, due to attaching to a process;
188 when running in the shell before the child program has been exec'd;
189 and when running some kinds of remote stuff (FIXME?). */
191 int stop_soon_quietly;
193 /* Nonzero if proceed is being used for a "finish" command or a similar
194 situation when stop_registers should be saved. */
196 int proceed_to_finish;
198 /* Save register contents here when about to pop a stack dummy frame,
199 if-and-only-if proceed_to_finish is set.
200 Thus this contains the return value from the called function (assuming
201 values are returned in a register). */
203 char stop_registers[REGISTER_BYTES];
205 /* Nonzero if program stopped due to error trying to insert breakpoints. */
207 static int breakpoints_failed;
209 /* Nonzero after stop if current stack frame should be printed. */
211 static int stop_print_frame;
214 /* Things to clean up if we QUIT out of resume (). */
217 resume_cleanups (arg)
223 /* Resume the inferior, but allow a QUIT. This is useful if the user
224 wants to interrupt some lengthy single-stepping operation
225 (for child processes, the SIGINT goes to the inferior, and so
226 we get a SIGINT random_signal, but for remote debugging and perhaps
227 other targets, that's not true).
229 STEP nonzero if we should step (zero to continue instead).
230 SIG is the signal to give the inferior (zero for none). */
234 enum target_signal sig;
236 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
239 #ifdef CANNOT_STEP_BREAKPOINT
240 /* Most targets can step a breakpoint instruction, thus executing it
241 normally. But if this one cannot, just continue and we will hit
243 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
247 #ifdef NO_SINGLE_STEP
249 single_step(sig); /* Do it the hard way, w/temp breakpoints */
250 step = 0; /* ...and don't ask hardware to do it. */
254 /* Handle any optimized stores to the inferior NOW... */
255 #ifdef DO_DEFERRED_STORES
259 /* Install inferior's terminal modes. */
260 target_terminal_inferior ();
262 target_resume (-1, step, sig);
263 discard_cleanups (old_cleanups);
267 /* Clear out all variables saying what to do when inferior is continued.
268 First do this, then set the ones you want, then call `proceed'. */
271 clear_proceed_status ()
274 step_range_start = 0;
276 step_frame_address = 0;
277 step_over_calls = -1;
279 stop_soon_quietly = 0;
280 proceed_to_finish = 0;
281 breakpoint_proceeded = 1; /* We're about to proceed... */
283 /* Discard any remaining commands or status from previous stop. */
284 bpstat_clear (&stop_bpstat);
287 /* Basic routine for continuing the program in various fashions.
289 ADDR is the address to resume at, or -1 for resume where stopped.
290 SIGGNAL is the signal to give it, or 0 for none,
291 or -1 for act according to how it stopped.
292 STEP is nonzero if should trap after one instruction.
293 -1 means return after that and print nothing.
294 You should probably set various step_... variables
295 before calling here, if you are stepping.
297 You should call clear_proceed_status before calling proceed. */
300 proceed (addr, siggnal, step)
302 enum target_signal siggnal;
308 step_start_function = find_pc_function (read_pc ());
312 if (addr == (CORE_ADDR)-1)
314 /* If there is a breakpoint at the address we will resume at,
315 step one instruction before inserting breakpoints
316 so that we do not stop right away. */
318 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
321 #ifdef STEP_SKIPS_DELAY
322 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
323 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
324 is slow (it needs to read memory from the target). */
325 if (breakpoint_here_p (read_pc () + 4)
326 && STEP_SKIPS_DELAY (read_pc ()))
328 #endif /* STEP_SKIPS_DELAY */
333 #ifdef PREPARE_TO_PROCEED
334 /* In a multi-threaded task we may select another thread and then continue.
336 In this case the thread that stopped at a breakpoint will immediately
337 cause another stop, if it is not stepped over first. On the other hand,
338 if (ADDR != -1) we only want to single step over the breakpoint if we did
339 switch to another thread.
341 If we are single stepping, don't do any of the above.
342 (Note that in the current implementation single stepping another
343 thread after a breakpoint and then continuing will cause the original
344 breakpoint to be hit again, but you can always continue, so it's not
347 if (! step && PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
349 #endif /* PREPARE_TO_PROCEED */
352 if (trap_expected_after_continue)
354 /* If (step == 0), a trap will be automatically generated after
355 the first instruction is executed. Force step one
356 instruction to clear this condition. This should not occur
357 if step is nonzero, but it is harmless in that case. */
359 trap_expected_after_continue = 0;
361 #endif /* HP_OS_BUG */
364 /* We will get a trace trap after one instruction.
365 Continue it automatically and insert breakpoints then. */
369 int temp = insert_breakpoints ();
372 print_sys_errmsg ("ptrace", temp);
373 error ("Cannot insert breakpoints.\n\
374 The same program may be running in another process.");
376 breakpoints_inserted = 1;
379 if (siggnal != TARGET_SIGNAL_DEFAULT)
380 stop_signal = siggnal;
381 /* If this signal should not be seen by program,
382 give it zero. Used for debugging signals. */
383 else if (!signal_program[stop_signal])
384 stop_signal = TARGET_SIGNAL_0;
386 annotate_starting ();
388 /* Make sure that output from GDB appears before output from the
390 gdb_flush (gdb_stdout);
392 /* Resume inferior. */
393 resume (oneproc || step || bpstat_should_step (), stop_signal);
395 /* Wait for it to stop (if not standalone)
396 and in any case decode why it stopped, and act accordingly. */
398 wait_for_inferior ();
402 /* Record the pc and sp of the program the last time it stopped.
403 These are just used internally by wait_for_inferior, but need
404 to be preserved over calls to it and cleared when the inferior
406 static CORE_ADDR prev_pc;
407 static CORE_ADDR prev_func_start;
408 static char *prev_func_name;
411 /* Start remote-debugging of a machine over a serial link. */
417 init_wait_for_inferior ();
418 clear_proceed_status ();
419 stop_soon_quietly = 1;
421 wait_for_inferior ();
425 /* Initialize static vars when a new inferior begins. */
428 init_wait_for_inferior ()
430 /* These are meaningless until the first time through wait_for_inferior. */
433 prev_func_name = NULL;
436 trap_expected_after_continue = 0;
438 breakpoints_inserted = 0;
439 breakpoint_init_inferior ();
441 /* Don't confuse first call to proceed(). */
442 stop_signal = TARGET_SIGNAL_0;
446 delete_breakpoint_current_contents (arg)
449 struct breakpoint **breakpointp = (struct breakpoint **)arg;
450 if (*breakpointp != NULL)
451 delete_breakpoint (*breakpointp);
454 /* Wait for control to return from inferior to debugger.
455 If inferior gets a signal, we may decide to start it up again
456 instead of returning. That is why there is a loop in this function.
457 When this function actually returns it means the inferior
458 should be left stopped and GDB should read more commands. */
463 struct cleanup *old_cleanups;
464 struct target_waitstatus w;
466 int random_signal = 0;
467 CORE_ADDR stop_func_start;
468 CORE_ADDR stop_func_end;
469 char *stop_func_name;
471 CORE_ADDR prologue_pc = 0;
474 struct symtab_and_line sal;
475 int remove_breakpoints_on_following_step = 0;
477 struct symtab *current_symtab;
478 int handling_longjmp = 0; /* FIXME */
479 struct breakpoint *step_resume_breakpoint = NULL;
480 struct breakpoint *through_sigtramp_breakpoint = NULL;
482 int update_step_sp = 0;
484 old_cleanups = make_cleanup (delete_breakpoint_current_contents,
485 &step_resume_breakpoint);
486 make_cleanup (delete_breakpoint_current_contents,
487 &through_sigtramp_breakpoint);
488 sal = find_pc_line(prev_pc, 0);
489 current_line = sal.line;
490 current_symtab = sal.symtab;
492 /* Are we stepping? */
493 #define CURRENTLY_STEPPING() \
494 ((through_sigtramp_breakpoint == NULL \
495 && !handling_longjmp \
496 && ((step_range_end && step_resume_breakpoint == NULL) \
498 || bpstat_should_step ())
502 extern int overlay_cache_invalid; /* declared in symfile.h */
504 overlay_cache_invalid = 1;
506 /* We have to invalidate the registers BEFORE calling target_wait because
507 they can be loaded from the target while in target_wait. This makes
508 remote debugging a bit more efficient for those targets that provide
509 critical registers as part of their normal status mechanism. */
511 registers_changed ();
513 if (target_wait_hook)
514 pid = target_wait_hook (-1, &w);
516 pid = target_wait (-1, &w);
520 We goto this label from elsewhere in wait_for_inferior when we want
521 to continue the main loop without calling "wait" and trashing the
522 waitstatus contained in W. */
525 flush_cached_frames ();
527 /* If it's a new process, add it to the thread database */
529 if (w.kind != TARGET_WAITKIND_EXITED
530 && pid != inferior_pid
531 && !in_thread_list (pid))
534 printf_filtered ("[New %s]\n", target_pid_to_str (pid));
536 /* We may want to consider not doing a resume here in order to give
537 the user a chance to play with the new thread. It might be good
538 to make that a user-settable option. */
540 /* At this point, all threads are stopped (happens automatically in
541 either the OS or the native code). Therefore we need to continue
542 all threads in order to make progress. */
544 target_resume (-1, 0, TARGET_SIGNAL_0);
550 case TARGET_WAITKIND_LOADED:
551 /* Ignore gracefully during startup of the inferior, as it
552 might be the shell which has just loaded some objects,
553 otherwise add the symbols for the newly loaded objects. */
555 if (!stop_soon_quietly)
557 extern int auto_solib_add;
559 /* Remove breakpoints, SOLIB_ADD might adjust
560 breakpoint addresses via breakpoint_re_set. */
561 if (breakpoints_inserted)
562 remove_breakpoints ();
564 /* Check for any newly added shared libraries if we're
565 supposed to be adding them automatically. */
568 /* Switch terminal for any messages produced by
569 breakpoint_re_set. */
570 target_terminal_ours_for_output ();
571 SOLIB_ADD (NULL, 0, NULL);
572 target_terminal_inferior ();
575 /* Reinsert breakpoints and continue. */
576 if (breakpoints_inserted)
577 insert_breakpoints ();
580 resume (0, TARGET_SIGNAL_0);
583 case TARGET_WAITKIND_SPURIOUS:
584 resume (0, TARGET_SIGNAL_0);
587 case TARGET_WAITKIND_EXITED:
588 target_terminal_ours (); /* Must do this before mourn anyway */
589 annotate_exited (w.value.integer);
591 printf_filtered ("\nProgram exited with code 0%o.\n",
592 (unsigned int)w.value.integer);
594 printf_filtered ("\nProgram exited normally.\n");
596 /* Record the exit code in the convenience variable $_exitcode, so
597 that the user can inspect this again later. */
598 set_internalvar (lookup_internalvar ("_exitcode"),
599 value_from_longest (builtin_type_int,
600 (LONGEST) w.value.integer));
601 gdb_flush (gdb_stdout);
602 target_mourn_inferior ();
603 #ifdef NO_SINGLE_STEP
606 stop_print_frame = 0;
609 case TARGET_WAITKIND_SIGNALLED:
610 stop_print_frame = 0;
611 stop_signal = w.value.sig;
612 target_terminal_ours (); /* Must do this before mourn anyway */
613 annotate_signalled ();
615 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
616 mean it is already dead? This has been here since GDB 2.8, so
617 perhaps it means rms didn't understand unix waitstatuses?
618 For the moment I'm just kludging around this in remote.c
619 rather than trying to change it here --kingdon, 5 Dec 1994. */
620 target_kill (); /* kill mourns as well */
622 printf_filtered ("\nProgram terminated with signal ");
623 annotate_signal_name ();
624 printf_filtered ("%s", target_signal_to_name (stop_signal));
625 annotate_signal_name_end ();
626 printf_filtered (", ");
627 annotate_signal_string ();
628 printf_filtered ("%s", target_signal_to_string (stop_signal));
629 annotate_signal_string_end ();
630 printf_filtered (".\n");
632 printf_filtered ("The program no longer exists.\n");
633 gdb_flush (gdb_stdout);
634 #ifdef NO_SINGLE_STEP
639 case TARGET_WAITKIND_STOPPED:
640 /* This is the only case in which we keep going; the above cases
641 end in a continue or goto. */
645 stop_signal = w.value.sig;
647 stop_pc = read_pc_pid (pid);
649 /* See if a thread hit a thread-specific breakpoint that was meant for
650 another thread. If so, then step that thread past the breakpoint,
653 if (stop_signal == TARGET_SIGNAL_TRAP)
655 #ifdef NO_SINGLE_STEP
660 if (breakpoints_inserted
661 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
664 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, pid))
666 /* Saw a breakpoint, but it was hit by the wrong thread. Just continue. */
667 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, pid);
669 remove_breakpoints ();
670 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
671 /* FIXME: What if a signal arrives instead of the single-step
674 if (target_wait_hook)
675 target_wait_hook (pid, &w);
677 target_wait (pid, &w);
678 insert_breakpoints ();
680 /* We need to restart all the threads now. */
681 target_resume (-1, 0, TARGET_SIGNAL_0);
689 /* See if something interesting happened to the non-current thread. If
690 so, then switch to that thread, and eventually give control back to
693 if (pid != inferior_pid)
697 /* If it's a random signal for a non-current thread, notify user
698 if he's expressed an interest. */
701 && signal_print[stop_signal])
704 target_terminal_ours_for_output ();
705 printf_filtered ("\nProgram received signal %s, %s.\n",
706 target_signal_to_name (stop_signal),
707 target_signal_to_string (stop_signal));
708 gdb_flush (gdb_stdout);
711 /* If it's not SIGTRAP and not a signal we want to stop for, then
712 continue the thread. */
714 if (stop_signal != TARGET_SIGNAL_TRAP
715 && !signal_stop[stop_signal])
718 target_terminal_inferior ();
720 /* Clear the signal if it should not be passed. */
721 if (signal_program[stop_signal] == 0)
722 stop_signal = TARGET_SIGNAL_0;
724 target_resume (pid, 0, stop_signal);
728 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
729 and fall into the rest of wait_for_inferior(). */
731 /* Save infrun state for the old thread. */
732 save_infrun_state (inferior_pid, prev_pc,
733 prev_func_start, prev_func_name,
734 trap_expected, step_resume_breakpoint,
735 through_sigtramp_breakpoint,
736 step_range_start, step_range_end,
737 step_frame_address, handling_longjmp,
742 /* Load infrun state for the new thread. */
743 load_infrun_state (inferior_pid, &prev_pc,
744 &prev_func_start, &prev_func_name,
745 &trap_expected, &step_resume_breakpoint,
746 &through_sigtramp_breakpoint,
747 &step_range_start, &step_range_end,
748 &step_frame_address, &handling_longjmp,
750 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid));
751 flush_cached_frames ();
754 #ifdef NO_SINGLE_STEP
756 single_step (0); /* This actually cleans up the ss */
757 #endif /* NO_SINGLE_STEP */
759 /* If PC is pointing at a nullified instruction, then step beyond
760 it so that the user won't be confused when GDB appears to be ready
763 if (INSTRUCTION_NULLIFIED)
765 struct target_waitstatus tmpstatus;
767 registers_changed ();
768 target_resume (pid, 1, TARGET_SIGNAL_0);
770 /* We may have received a signal that we want to pass to
771 the inferior; therefore, we must not clobber the waitstatus
772 in W. So we call wait ourselves, then continue the loop
773 at the "have_waited" label. */
774 if (target_wait_hook)
775 target_wait_hook (pid, &tmpstatus);
777 target_wait (pid, &tmpstatus);
783 #ifdef HAVE_STEPPABLE_WATCHPOINT
784 /* It may not be necessary to disable the watchpoint to stop over
785 it. For example, the PA can (with some kernel cooperation)
786 single step over a watchpoint without disabling the watchpoint. */
787 if (STOPPED_BY_WATCHPOINT (w))
794 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
795 /* It is far more common to need to disable a watchpoint
796 to step the inferior over it. FIXME. What else might
797 a debug register or page protection watchpoint scheme need
799 if (STOPPED_BY_WATCHPOINT (w))
801 /* At this point, we are stopped at an instruction which has attempted to write
802 to a piece of memory under control of a watchpoint. The instruction hasn't
803 actually executed yet. If we were to evaluate the watchpoint expression
804 now, we would get the old value, and therefore no change would seem to have
807 In order to make watchpoints work `right', we really need to complete the
808 memory write, and then evaluate the watchpoint expression. The following
809 code does that by removing the watchpoint (actually, all watchpoints and
810 breakpoints), single-stepping the target, re-inserting watchpoints, and then
811 falling through to let normal single-step processing handle proceed. Since
812 this includes evaluating watchpoints, things will come to a stop in the
815 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
817 remove_breakpoints ();
819 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
821 if (target_wait_hook)
822 target_wait_hook (pid, &w);
824 target_wait (pid, &w);
825 insert_breakpoints ();
826 /* FIXME-maybe: is this cleaner than setting a flag? Does it
827 handle things like signals arriving and other things happening
828 in combination correctly? */
833 #ifdef HAVE_CONTINUABLE_WATCHPOINT
834 /* It may be possible to simply continue after a watchpoint. */
835 STOPPED_BY_WATCHPOINT (w);
841 /* Don't care about return value; stop_func_start and stop_func_name
842 will both be 0 if it doesn't work. */
843 find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start,
845 stop_func_start += FUNCTION_START_OFFSET;
847 bpstat_clear (&stop_bpstat);
849 stop_stack_dummy = 0;
850 stop_print_frame = 1;
852 stopped_by_random_signal = 0;
853 breakpoints_failed = 0;
855 /* Look at the cause of the stop, and decide what to do.
856 The alternatives are:
857 1) break; to really stop and return to the debugger,
858 2) drop through to start up again
859 (set another_trap to 1 to single step once)
860 3) set random_signal to 1, and the decision between 1 and 2
861 will be made according to the signal handling tables. */
863 /* First, distinguish signals caused by the debugger from signals
864 that have to do with the program's own actions.
865 Note that breakpoint insns may cause SIGTRAP or SIGILL
866 or SIGEMT, depending on the operating system version.
867 Here we detect when a SIGILL or SIGEMT is really a breakpoint
868 and change it to SIGTRAP. */
870 if (stop_signal == TARGET_SIGNAL_TRAP
871 || (breakpoints_inserted &&
872 (stop_signal == TARGET_SIGNAL_ILL
873 || stop_signal == TARGET_SIGNAL_EMT
875 || stop_soon_quietly)
877 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
879 stop_print_frame = 0;
882 if (stop_soon_quietly)
885 /* Don't even think about breakpoints
886 if just proceeded over a breakpoint.
888 However, if we are trying to proceed over a breakpoint
889 and end up in sigtramp, then through_sigtramp_breakpoint
890 will be set and we should check whether we've hit the
892 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
893 && through_sigtramp_breakpoint == NULL)
894 bpstat_clear (&stop_bpstat);
897 /* See if there is a breakpoint at the current PC. */
898 stop_bpstat = bpstat_stop_status
900 (DECR_PC_AFTER_BREAK ?
901 /* Notice the case of stepping through a jump
902 that lands just after a breakpoint.
903 Don't confuse that with hitting the breakpoint.
904 What we check for is that 1) stepping is going on
905 and 2) the pc before the last insn does not match
906 the address of the breakpoint before the current pc. */
907 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
908 && CURRENTLY_STEPPING ()) :
911 /* Following in case break condition called a
913 stop_print_frame = 1;
916 if (stop_signal == TARGET_SIGNAL_TRAP)
918 = !(bpstat_explains_signal (stop_bpstat)
920 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
921 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
922 FRAME_FP (get_current_frame ()))
923 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
924 || (step_range_end && step_resume_breakpoint == NULL));
928 = !(bpstat_explains_signal (stop_bpstat)
929 /* End of a stack dummy. Some systems (e.g. Sony
930 news) give another signal besides SIGTRAP,
931 so check here as well as above. */
932 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
933 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
934 FRAME_FP (get_current_frame ()))
935 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
938 stop_signal = TARGET_SIGNAL_TRAP;
944 /* For the program's own signals, act according to
945 the signal handling tables. */
949 /* Signal not for debugging purposes. */
952 stopped_by_random_signal = 1;
954 if (signal_print[stop_signal])
957 target_terminal_ours_for_output ();
959 printf_filtered ("\nProgram received signal ");
960 annotate_signal_name ();
961 printf_filtered ("%s", target_signal_to_name (stop_signal));
962 annotate_signal_name_end ();
963 printf_filtered (", ");
964 annotate_signal_string ();
965 printf_filtered ("%s", target_signal_to_string (stop_signal));
966 annotate_signal_string_end ();
967 printf_filtered (".\n");
968 gdb_flush (gdb_stdout);
970 if (signal_stop[stop_signal])
972 /* If not going to stop, give terminal back
973 if we took it away. */
975 target_terminal_inferior ();
977 /* Clear the signal if it should not be passed. */
978 if (signal_program[stop_signal] == 0)
979 stop_signal = TARGET_SIGNAL_0;
981 /* I'm not sure whether this needs to be check_sigtramp2 or
982 whether it could/should be keep_going. */
983 goto check_sigtramp2;
986 /* Handle cases caused by hitting a breakpoint. */
988 CORE_ADDR jmp_buf_pc;
989 struct bpstat_what what;
991 what = bpstat_what (stop_bpstat);
995 stop_stack_dummy = 1;
997 trap_expected_after_continue = 1;
1001 switch (what.main_action)
1003 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
1004 /* If we hit the breakpoint at longjmp, disable it for the
1005 duration of this command. Then, install a temporary
1006 breakpoint at the target of the jmp_buf. */
1007 disable_longjmp_breakpoint();
1008 remove_breakpoints ();
1009 breakpoints_inserted = 0;
1010 if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
1012 /* Need to blow away step-resume breakpoint, as it
1013 interferes with us */
1014 if (step_resume_breakpoint != NULL)
1016 delete_breakpoint (step_resume_breakpoint);
1017 step_resume_breakpoint = NULL;
1019 /* Not sure whether we need to blow this away too, but probably
1020 it is like the step-resume breakpoint. */
1021 if (through_sigtramp_breakpoint != NULL)
1023 delete_breakpoint (through_sigtramp_breakpoint);
1024 through_sigtramp_breakpoint = NULL;
1028 /* FIXME - Need to implement nested temporary breakpoints */
1029 if (step_over_calls > 0)
1030 set_longjmp_resume_breakpoint(jmp_buf_pc,
1031 get_current_frame());
1034 set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
1035 handling_longjmp = 1; /* FIXME */
1038 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
1039 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
1040 remove_breakpoints ();
1041 breakpoints_inserted = 0;
1043 /* FIXME - Need to implement nested temporary breakpoints */
1045 && (FRAME_FP (get_current_frame ())
1046 INNER_THAN step_frame_address))
1052 disable_longjmp_breakpoint();
1053 handling_longjmp = 0; /* FIXME */
1054 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
1056 /* else fallthrough */
1058 case BPSTAT_WHAT_SINGLE:
1059 if (breakpoints_inserted)
1060 remove_breakpoints ();
1061 breakpoints_inserted = 0;
1063 /* Still need to check other stuff, at least the case
1064 where we are stepping and step out of the right range. */
1067 case BPSTAT_WHAT_STOP_NOISY:
1068 stop_print_frame = 1;
1070 /* We are about to nuke the step_resume_breakpoint and
1071 through_sigtramp_breakpoint via the cleanup chain, so
1072 no need to worry about it here. */
1076 case BPSTAT_WHAT_STOP_SILENT:
1077 stop_print_frame = 0;
1079 /* We are about to nuke the step_resume_breakpoint and
1080 through_sigtramp_breakpoint via the cleanup chain, so
1081 no need to worry about it here. */
1085 case BPSTAT_WHAT_STEP_RESUME:
1086 delete_breakpoint (step_resume_breakpoint);
1087 step_resume_breakpoint = NULL;
1090 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
1091 if (through_sigtramp_breakpoint)
1092 delete_breakpoint (through_sigtramp_breakpoint);
1093 through_sigtramp_breakpoint = NULL;
1095 /* If were waiting for a trap, hitting the step_resume_break
1096 doesn't count as getting it. */
1101 case BPSTAT_WHAT_CHECK_SHLIBS:
1104 extern int auto_solib_add;
1106 /* Remove breakpoints, we eventually want to step over the
1107 shlib event breakpoint, and SOLIB_ADD might adjust
1108 breakpoint addresses via breakpoint_re_set. */
1109 if (breakpoints_inserted)
1110 remove_breakpoints ();
1111 breakpoints_inserted = 0;
1113 /* Check for any newly added shared libraries if we're
1114 supposed to be adding them automatically. */
1117 /* Switch terminal for any messages produced by
1118 breakpoint_re_set. */
1119 target_terminal_ours_for_output ();
1120 SOLIB_ADD (NULL, 0, NULL);
1121 target_terminal_inferior ();
1124 /* Try to reenable shared library breakpoints, additional
1125 code segments in shared libraries might be mapped in now. */
1126 re_enable_breakpoints_in_shlibs ();
1128 /* If requested, stop when the dynamic linker notifies
1129 gdb of events. This allows the user to get control
1130 and place breakpoints in initializer routines for
1131 dynamically loaded objects (among other things). */
1132 if (stop_on_solib_events)
1134 stop_print_frame = 0;
1139 /* We want to step over this breakpoint, then keep going. */
1147 case BPSTAT_WHAT_LAST:
1148 /* Not a real code, but listed here to shut up gcc -Wall. */
1150 case BPSTAT_WHAT_KEEP_CHECKING:
1155 /* We come here if we hit a breakpoint but should not
1156 stop for it. Possibly we also were stepping
1157 and should stop for that. So fall through and
1158 test for stepping. But, if not stepping,
1161 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1162 /* This is the old way of detecting the end of the stack dummy.
1163 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
1164 handled above. As soon as we can test it on all of them, all
1165 architectures should define it. */
1167 /* If this is the breakpoint at the end of a stack dummy,
1168 just stop silently, unless the user was doing an si/ni, in which
1169 case she'd better know what she's doing. */
1171 if (PC_IN_CALL_DUMMY (stop_pc, read_sp (), FRAME_FP (get_current_frame ()))
1174 stop_print_frame = 0;
1175 stop_stack_dummy = 1;
1177 trap_expected_after_continue = 1;
1181 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1183 if (step_resume_breakpoint)
1184 /* Having a step-resume breakpoint overrides anything
1185 else having to do with stepping commands until
1186 that breakpoint is reached. */
1187 /* I'm not sure whether this needs to be check_sigtramp2 or
1188 whether it could/should be keep_going. */
1189 goto check_sigtramp2;
1191 if (step_range_end == 0)
1192 /* Likewise if we aren't even stepping. */
1193 /* I'm not sure whether this needs to be check_sigtramp2 or
1194 whether it could/should be keep_going. */
1195 goto check_sigtramp2;
1197 /* If stepping through a line, keep going if still within it. */
1198 if (stop_pc >= step_range_start
1199 && stop_pc < step_range_end
1201 /* I haven't a clue what might trigger this clause, and it seems wrong anyway,
1202 so I've disabled it until someone complains. -Stu 10/24/95 */
1204 /* The step range might include the start of the
1205 function, so if we are at the start of the
1206 step range and either the stack or frame pointers
1207 just changed, we've stepped outside */
1208 && !(stop_pc == step_range_start
1209 && FRAME_FP (get_current_frame ())
1210 && (read_sp () INNER_THAN step_sp
1211 || FRAME_FP (get_current_frame ()) != step_frame_address))
1215 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
1216 So definately need to check for sigtramp here. */
1217 goto check_sigtramp2;
1220 /* We stepped out of the stepping range. */
1222 /* If we are stepping at the source level and entered the runtime
1223 loader dynamic symbol resolution code, we keep on single stepping
1224 until we exit the run time loader code and reach the callee's
1226 if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
1229 /* We can't update step_sp every time through the loop, because
1230 reading the stack pointer would slow down stepping too much.
1231 But we can update it every time we leave the step range. */
1234 /* Did we just take a signal? */
1235 if (IN_SIGTRAMP (stop_pc, stop_func_name)
1236 && !IN_SIGTRAMP (prev_pc, prev_func_name)
1237 && read_sp () INNER_THAN step_sp)
1239 /* We've just taken a signal; go until we are back to
1240 the point where we took it and one more. */
1242 /* This code is needed at least in the following case:
1243 The user types "next" and then a signal arrives (before
1244 the "next" is done). */
1246 /* Note that if we are stopped at a breakpoint, then we need
1247 the step_resume breakpoint to override any breakpoints at
1248 the same location, so that we will still step over the
1249 breakpoint even though the signal happened. */
1252 struct symtab_and_line sr_sal;
1254 INIT_SAL (&sr_sal); /* initialize to zeroes */
1255 sr_sal.pc = prev_pc;
1256 sr_sal.section = find_pc_overlay (sr_sal.pc);
1257 /* We could probably be setting the frame to
1258 step_frame_address; I don't think anyone thought to try it. */
1259 step_resume_breakpoint =
1260 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1261 if (breakpoints_inserted)
1262 insert_breakpoints ();
1265 /* If this is stepi or nexti, make sure that the stepping range
1266 gets us past that instruction. */
1267 if (step_range_end == 1)
1268 /* FIXME: Does this run afoul of the code below which, if
1269 we step into the middle of a line, resets the stepping
1271 step_range_end = (step_range_start = prev_pc) + 1;
1273 remove_breakpoints_on_following_step = 1;
1278 /* I disabled this test because it was too complicated and slow. The
1279 SKIP_PROLOGUE was especially slow, because it caused unnecessary
1280 prologue examination on various architectures. The code in the #else
1281 clause has been tested on the Sparc, Mips, PA, and Power
1282 architectures, so it's pretty likely to be correct. -Stu 10/24/95 */
1284 /* See if we left the step range due to a subroutine call that
1285 we should proceed to the end of. */
1287 if (stop_func_start)
1291 /* Do this after the IN_SIGTRAMP check; it might give
1293 prologue_pc = stop_func_start;
1295 /* Don't skip the prologue if this is assembly source */
1296 s = find_pc_symtab (stop_pc);
1297 if (s && s->language != language_asm)
1298 SKIP_PROLOGUE (prologue_pc);
1301 if (!(step_sp INNER_THAN read_sp ()) /* don't mistake (sig)return as a call */
1302 && (/* Might be a non-recursive call. If the symbols are missing
1303 enough that stop_func_start == prev_func_start even though
1304 they are really two functions, we will treat some calls as
1306 stop_func_start != prev_func_start
1308 /* Might be a recursive call if either we have a prologue
1309 or the call instruction itself saves the PC on the stack. */
1310 || prologue_pc != stop_func_start
1311 || read_sp () != step_sp)
1312 && (/* PC is completely out of bounds of any known objfiles. Treat
1313 like a subroutine call. */
1316 /* If we do a call, we will be at the start of a function... */
1317 || stop_pc == stop_func_start
1319 /* ...except on the Alpha with -O (and also Irix 5 and
1320 perhaps others), in which we might call the address
1321 after the load of gp. Since prologues don't contain
1322 calls, we can't return to within one, and we don't
1323 jump back into them, so this check is OK. */
1325 || stop_pc < prologue_pc
1327 /* ...and if it is a leaf function, the prologue might
1328 consist of gp loading only, so the call transfers to
1329 the first instruction after the prologue. */
1330 || (stop_pc == prologue_pc
1332 /* Distinguish this from the case where we jump back
1333 to the first instruction after the prologue,
1334 within a function. */
1335 && stop_func_start != prev_func_start)
1337 /* If we end up in certain places, it means we did a subroutine
1338 call. I'm not completely sure this is necessary now that we
1339 have the above checks with stop_func_start (and now that
1340 find_pc_partial_function is pickier). */
1341 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
1343 /* If none of the above apply, it is a jump within a function,
1344 or a return from a subroutine. The other case is longjmp,
1345 which can no longer happen here as long as the
1346 handling_longjmp stuff is working. */
1349 /* This test is a much more streamlined, (but hopefully correct)
1350 replacement for the code above. It's been tested on the Sparc,
1351 Mips, PA, and Power architectures with good results. */
1353 if (stop_pc == stop_func_start /* Quick test */
1354 || in_prologue (stop_pc, stop_func_start)
1355 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
1356 || stop_func_start == 0)
1360 /* It's a subroutine call. */
1362 if (step_over_calls == 0)
1364 /* I presume that step_over_calls is only 0 when we're
1365 supposed to be stepping at the assembly language level
1366 ("stepi"). Just stop. */
1371 if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc))
1372 /* We're doing a "next". */
1373 goto step_over_function;
1375 /* If we are in a function call trampoline (a stub between
1376 the calling routine and the real function), locate the real
1377 function. That's what tells us (a) whether we want to step
1378 into it at all, and (b) what prologue we want to run to
1379 the end of, if we do step into it. */
1380 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1382 stop_func_start = tmp;
1385 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
1388 struct symtab_and_line xxx;
1389 /* Why isn't this s_a_l called "sr_sal", like all of the
1390 other s_a_l's where this code is duplicated? */
1391 INIT_SAL (&xxx); /* initialize to zeroes */
1393 xxx.section = find_pc_overlay (xxx.pc);
1394 step_resume_breakpoint =
1395 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
1396 insert_breakpoints ();
1401 /* If we have line number information for the function we
1402 are thinking of stepping into, step into it.
1404 If there are several symtabs at that PC (e.g. with include
1405 files), just want to know whether *any* of them have line
1406 numbers. find_pc_line handles this. */
1408 struct symtab_and_line tmp_sal;
1410 tmp_sal = find_pc_line (stop_func_start, 0);
1411 if (tmp_sal.line != 0)
1412 goto step_into_function;
1416 /* A subroutine call has happened. */
1418 /* Set a special breakpoint after the return */
1419 struct symtab_and_line sr_sal;
1421 INIT_SAL (&sr_sal); /* initialize to zeroes */
1423 ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
1424 sr_sal.section = find_pc_overlay (sr_sal.pc);
1425 step_resume_breakpoint =
1426 set_momentary_breakpoint (sr_sal, get_current_frame (),
1428 if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
1429 step_resume_breakpoint->frame = step_frame_address;
1430 if (breakpoints_inserted)
1431 insert_breakpoints ();
1436 /* Subroutine call with source code we should not step over.
1437 Do step to the first line of code in it. */
1441 s = find_pc_symtab (stop_pc);
1442 if (s && s->language != language_asm)
1443 SKIP_PROLOGUE (stop_func_start);
1445 sal = find_pc_line (stop_func_start, 0);
1446 /* Use the step_resume_break to step until
1447 the end of the prologue, even if that involves jumps
1448 (as it seems to on the vax under 4.2). */
1449 /* If the prologue ends in the middle of a source line,
1450 continue to the end of that source line (if it is still
1451 within the function). Otherwise, just go to end of prologue. */
1452 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1453 /* no, don't either. It skips any code that's
1454 legitimately on the first line. */
1456 if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end)
1457 stop_func_start = sal.end;
1460 if (stop_func_start == stop_pc)
1462 /* We are already there: stop now. */
1467 /* Put the step-breakpoint there and go until there. */
1469 struct symtab_and_line sr_sal;
1471 INIT_SAL (&sr_sal); /* initialize to zeroes */
1472 sr_sal.pc = stop_func_start;
1473 sr_sal.section = find_pc_overlay (stop_func_start);
1474 /* Do not specify what the fp should be when we stop
1475 since on some machines the prologue
1476 is where the new fp value is established. */
1477 step_resume_breakpoint =
1478 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1479 if (breakpoints_inserted)
1480 insert_breakpoints ();
1482 /* And make sure stepping stops right away then. */
1483 step_range_end = step_range_start;
1488 /* We've wandered out of the step range. */
1490 sal = find_pc_line(stop_pc, 0);
1492 if (step_range_end == 1)
1494 /* It is stepi or nexti. We always want to stop stepping after
1500 /* If we're in the return path from a shared library trampoline,
1501 we want to proceed through the trampoline when stepping. */
1502 if (IN_SOLIB_RETURN_TRAMPOLINE(stop_pc, stop_func_name))
1506 /* Determine where this trampoline returns. */
1507 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1509 /* Only proceed through if we know where it's going. */
1512 /* And put the step-breakpoint there and go until there. */
1513 struct symtab_and_line sr_sal;
1515 INIT_SAL (&sr_sal); /* initialize to zeroes */
1517 sr_sal.section = find_pc_overlay (sr_sal.pc);
1518 /* Do not specify what the fp should be when we stop
1519 since on some machines the prologue
1520 is where the new fp value is established. */
1521 step_resume_breakpoint =
1522 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1523 if (breakpoints_inserted)
1524 insert_breakpoints ();
1526 /* Restart without fiddling with the step ranges or
1534 /* We have no line number information. That means to stop
1535 stepping (does this always happen right after one instruction,
1536 when we do "s" in a function with no line numbers,
1537 or can this happen as a result of a return or longjmp?). */
1542 if (stop_pc == sal.pc
1543 && (current_line != sal.line || current_symtab != sal.symtab))
1545 /* We are at the start of a different line. So stop. Note that
1546 we don't stop if we step into the middle of a different line.
1547 That is said to make things like for (;;) statements work
1553 /* We aren't done stepping.
1555 Optimize by setting the stepping range to the line.
1556 (We might not be in the original line, but if we entered a
1557 new line in mid-statement, we continue stepping. This makes
1558 things like for(;;) statements work better.) */
1560 if (stop_func_end && sal.end >= stop_func_end)
1562 /* If this is the last line of the function, don't keep stepping
1563 (it would probably step us out of the function).
1564 This is particularly necessary for a one-line function,
1565 in which after skipping the prologue we better stop even though
1566 we will be in mid-line. */
1570 step_range_start = sal.pc;
1571 step_range_end = sal.end;
1572 step_frame_address = FRAME_FP (get_current_frame ());
1573 current_line = sal.line;
1574 current_symtab = sal.symtab;
1579 && IN_SIGTRAMP (stop_pc, stop_func_name)
1580 && !IN_SIGTRAMP (prev_pc, prev_func_name)
1581 && read_sp () INNER_THAN step_sp)
1583 /* What has happened here is that we have just stepped the inferior
1584 with a signal (because it is a signal which shouldn't make
1585 us stop), thus stepping into sigtramp.
1587 So we need to set a step_resume_break_address breakpoint
1588 and continue until we hit it, and then step. FIXME: This should
1589 be more enduring than a step_resume breakpoint; we should know
1590 that we will later need to keep going rather than re-hitting
1591 the breakpoint here (see testsuite/gdb.t06/signals.exp where
1592 it says "exceedingly difficult"). */
1593 struct symtab_and_line sr_sal;
1595 INIT_SAL (&sr_sal); /* initialize to zeroes */
1596 sr_sal.pc = prev_pc;
1597 sr_sal.section = find_pc_overlay (sr_sal.pc);
1598 /* We perhaps could set the frame if we kept track of what
1599 the frame corresponding to prev_pc was. But we don't,
1601 through_sigtramp_breakpoint =
1602 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
1603 if (breakpoints_inserted)
1604 insert_breakpoints ();
1606 remove_breakpoints_on_following_step = 1;
1611 /* Come to this label when you need to resume the inferior.
1612 It's really much cleaner to do a goto than a maze of if-else
1615 /* Save the pc before execution, to compare with pc after stop. */
1616 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
1617 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
1618 BREAK is defined, the
1619 original pc would not have
1620 been at the start of a
1622 prev_func_name = stop_func_name;
1625 step_sp = read_sp ();
1628 /* If we did not do break;, it means we should keep
1629 running the inferior and not return to debugger. */
1631 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
1633 /* We took a signal (which we are supposed to pass through to
1634 the inferior, else we'd have done a break above) and we
1635 haven't yet gotten our trap. Simply continue. */
1636 resume (CURRENTLY_STEPPING (), stop_signal);
1640 /* Either the trap was not expected, but we are continuing
1641 anyway (the user asked that this signal be passed to the
1644 The signal was SIGTRAP, e.g. it was our signal, but we
1645 decided we should resume from it.
1647 We're going to run this baby now!
1649 Insert breakpoints now, unless we are trying
1650 to one-proceed past a breakpoint. */
1651 /* If we've just finished a special step resume and we don't
1652 want to hit a breakpoint, pull em out. */
1653 if (step_resume_breakpoint == NULL
1654 && through_sigtramp_breakpoint == NULL
1655 && remove_breakpoints_on_following_step)
1657 remove_breakpoints_on_following_step = 0;
1658 remove_breakpoints ();
1659 breakpoints_inserted = 0;
1661 else if (!breakpoints_inserted &&
1662 (through_sigtramp_breakpoint != NULL || !another_trap))
1664 breakpoints_failed = insert_breakpoints ();
1665 if (breakpoints_failed)
1667 breakpoints_inserted = 1;
1670 trap_expected = another_trap;
1672 if (stop_signal == TARGET_SIGNAL_TRAP)
1673 stop_signal = TARGET_SIGNAL_0;
1675 #ifdef SHIFT_INST_REGS
1676 /* I'm not sure when this following segment applies. I do know, now,
1677 that we shouldn't rewrite the regs when we were stopped by a
1678 random signal from the inferior process. */
1679 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
1680 (this is only used on the 88k). */
1682 if (!bpstat_explains_signal (stop_bpstat)
1683 && (stop_signal != TARGET_SIGNAL_CHLD)
1684 && !stopped_by_random_signal)
1686 #endif /* SHIFT_INST_REGS */
1688 resume (CURRENTLY_STEPPING (), stop_signal);
1693 if (target_has_execution)
1695 /* Assuming the inferior still exists, set these up for next
1696 time, just like we did above if we didn't break out of the
1698 prev_pc = read_pc ();
1699 prev_func_start = stop_func_start;
1700 prev_func_name = stop_func_name;
1702 do_cleanups (old_cleanups);
1705 /* Here to return control to GDB when the inferior stops for real.
1706 Print appropriate messages, remove breakpoints, give terminal our modes.
1708 STOP_PRINT_FRAME nonzero means print the executing frame
1709 (pc, function, args, file, line number and line text).
1710 BREAKPOINTS_FAILED nonzero means stop was due to error
1711 attempting to insert breakpoints. */
1716 /* Make sure that the current_frame's pc is correct. This
1717 is a correction for setting up the frame info before doing
1718 DECR_PC_AFTER_BREAK */
1719 if (target_has_execution && get_current_frame())
1720 (get_current_frame ())->pc = read_pc ();
1722 if (breakpoints_failed)
1724 target_terminal_ours_for_output ();
1725 print_sys_errmsg ("ptrace", breakpoints_failed);
1726 printf_filtered ("Stopped; cannot insert breakpoints.\n\
1727 The same program may be running in another process.\n");
1730 if (target_has_execution && breakpoints_inserted)
1731 if (remove_breakpoints ())
1733 target_terminal_ours_for_output ();
1734 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
1735 It might be running in another process.\n\
1736 Further execution is probably impossible.\n");
1739 breakpoints_inserted = 0;
1741 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1742 Delete any breakpoint that is to be deleted at the next stop. */
1744 breakpoint_auto_delete (stop_bpstat);
1746 /* If an auto-display called a function and that got a signal,
1747 delete that auto-display to avoid an infinite recursion. */
1749 if (stopped_by_random_signal)
1750 disable_current_display ();
1752 if (step_multi && stop_step)
1755 target_terminal_ours ();
1758 && stop_bpstat->breakpoint_at
1759 && stop_bpstat->breakpoint_at->type == bp_shlib_event)
1760 printf_filtered ("Stopped due to shared library event\n");
1762 /* Look up the hook_stop and run it if it exists. */
1764 if (stop_command->hook)
1766 catch_errors (hook_stop_stub, (char *)stop_command->hook,
1767 "Error while running hook_stop:\n", RETURN_MASK_ALL);
1770 if (!target_has_stack)
1773 /* Select innermost stack frame except on return from a stack dummy routine,
1774 or if the program has exited. Print it without a level number if
1775 we have changed functions or hit a breakpoint. Print source line
1777 if (!stop_stack_dummy)
1779 select_frame (get_current_frame (), 0);
1781 if (stop_print_frame)
1785 source_only = bpstat_print (stop_bpstat);
1786 source_only = source_only ||
1788 && step_frame_address == FRAME_FP (get_current_frame ())
1789 && step_start_function == find_pc_function (stop_pc));
1791 print_stack_frame (selected_frame, -1, source_only? -1: 1);
1793 /* Display the auto-display expressions. */
1798 /* Save the function value return registers, if we care.
1799 We might be about to restore their previous contents. */
1800 if (proceed_to_finish)
1801 read_register_bytes (0, stop_registers, REGISTER_BYTES);
1803 if (stop_stack_dummy)
1805 /* Pop the empty frame that contains the stack dummy.
1806 POP_FRAME ends with a setting of the current frame, so we
1807 can use that next. */
1809 /* Set stop_pc to what it was before we called the function. Can't rely
1810 on restore_inferior_status because that only gets called if we don't
1811 stop in the called function. */
1812 stop_pc = read_pc();
1813 select_frame (get_current_frame (), 0);
1816 annotate_stopped ();
1820 hook_stop_stub (cmd)
1823 execute_user_command ((struct cmd_list_element *)cmd, 0);
1827 int signal_stop_state (signo)
1830 return signal_stop[signo];
1833 int signal_print_state (signo)
1836 return signal_print[signo];
1839 int signal_pass_state (signo)
1842 return signal_program[signo];
1849 Signal Stop\tPrint\tPass to program\tDescription\n");
1853 sig_print_info (oursig)
1854 enum target_signal oursig;
1856 char *name = target_signal_to_name (oursig);
1857 int name_padding = 13 - strlen (name);
1858 if (name_padding <= 0)
1861 printf_filtered ("%s", name);
1862 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
1863 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
1864 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
1865 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
1866 printf_filtered ("%s\n", target_signal_to_string (oursig));
1869 /* Specify how various signals in the inferior should be handled. */
1872 handle_command (args, from_tty)
1877 int digits, wordlen;
1878 int sigfirst, signum, siglast;
1879 enum target_signal oursig;
1882 unsigned char *sigs;
1883 struct cleanup *old_chain;
1887 error_no_arg ("signal to handle");
1890 /* Allocate and zero an array of flags for which signals to handle. */
1892 nsigs = (int)TARGET_SIGNAL_LAST;
1893 sigs = (unsigned char *) alloca (nsigs);
1894 memset (sigs, 0, nsigs);
1896 /* Break the command line up into args. */
1898 argv = buildargv (args);
1903 old_chain = make_cleanup (freeargv, (char *) argv);
1905 /* Walk through the args, looking for signal oursigs, signal names, and
1906 actions. Signal numbers and signal names may be interspersed with
1907 actions, with the actions being performed for all signals cumulatively
1908 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
1910 while (*argv != NULL)
1912 wordlen = strlen (*argv);
1913 for (digits = 0; isdigit ((*argv)[digits]); digits++) {;}
1915 sigfirst = siglast = -1;
1917 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
1919 /* Apply action to all signals except those used by the
1920 debugger. Silently skip those. */
1923 siglast = nsigs - 1;
1925 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
1927 SET_SIGS (nsigs, sigs, signal_stop);
1928 SET_SIGS (nsigs, sigs, signal_print);
1930 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
1932 UNSET_SIGS (nsigs, sigs, signal_program);
1934 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
1936 SET_SIGS (nsigs, sigs, signal_print);
1938 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
1940 SET_SIGS (nsigs, sigs, signal_program);
1942 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
1944 UNSET_SIGS (nsigs, sigs, signal_stop);
1946 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
1948 SET_SIGS (nsigs, sigs, signal_program);
1950 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
1952 UNSET_SIGS (nsigs, sigs, signal_print);
1953 UNSET_SIGS (nsigs, sigs, signal_stop);
1955 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
1957 UNSET_SIGS (nsigs, sigs, signal_program);
1959 else if (digits > 0)
1961 /* It is numeric. The numeric signal refers to our own internal
1962 signal numbering from target.h, not to host/target signal number.
1963 This is a feature; users really should be using symbolic names
1964 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
1965 will work right anyway. */
1967 sigfirst = siglast = (int) target_signal_from_command (atoi (*argv));
1968 if ((*argv)[digits] == '-')
1971 (int) target_signal_from_command (atoi ((*argv) + digits + 1));
1973 if (sigfirst > siglast)
1975 /* Bet he didn't figure we'd think of this case... */
1983 oursig = target_signal_from_name (*argv);
1984 if (oursig != TARGET_SIGNAL_UNKNOWN)
1986 sigfirst = siglast = (int)oursig;
1990 /* Not a number and not a recognized flag word => complain. */
1991 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
1995 /* If any signal numbers or symbol names were found, set flags for
1996 which signals to apply actions to. */
1998 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
2000 switch ((enum target_signal)signum)
2002 case TARGET_SIGNAL_TRAP:
2003 case TARGET_SIGNAL_INT:
2004 if (!allsigs && !sigs[signum])
2006 if (query ("%s is used by the debugger.\n\
2007 Are you sure you want to change it? ",
2008 target_signal_to_name
2009 ((enum target_signal)signum)))
2015 printf_unfiltered ("Not confirmed, unchanged.\n");
2016 gdb_flush (gdb_stdout);
2020 case TARGET_SIGNAL_0:
2021 case TARGET_SIGNAL_DEFAULT:
2022 case TARGET_SIGNAL_UNKNOWN:
2023 /* Make sure that "all" doesn't print these. */
2034 target_notice_signals(inferior_pid);
2038 /* Show the results. */
2039 sig_print_header ();
2040 for (signum = 0; signum < nsigs; signum++)
2044 sig_print_info (signum);
2049 do_cleanups (old_chain);
2052 /* Print current contents of the tables set by the handle command.
2053 It is possible we should just be printing signals actually used
2054 by the current target (but for things to work right when switching
2055 targets, all signals should be in the signal tables). */
2058 signals_info (signum_exp, from_tty)
2062 enum target_signal oursig;
2063 sig_print_header ();
2067 /* First see if this is a symbol name. */
2068 oursig = target_signal_from_name (signum_exp);
2069 if (oursig == TARGET_SIGNAL_UNKNOWN)
2071 /* No, try numeric. */
2073 target_signal_from_command (parse_and_eval_address (signum_exp));
2075 sig_print_info (oursig);
2079 printf_filtered ("\n");
2080 /* These ugly casts brought to you by the native VAX compiler. */
2081 for (oursig = TARGET_SIGNAL_FIRST;
2082 (int)oursig < (int)TARGET_SIGNAL_LAST;
2083 oursig = (enum target_signal)((int)oursig + 1))
2087 if (oursig != TARGET_SIGNAL_UNKNOWN
2088 && oursig != TARGET_SIGNAL_DEFAULT
2089 && oursig != TARGET_SIGNAL_0)
2090 sig_print_info (oursig);
2093 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
2096 /* Save all of the information associated with the inferior<==>gdb
2097 connection. INF_STATUS is a pointer to a "struct inferior_status"
2098 (defined in inferior.h). */
2101 save_inferior_status (inf_status, restore_stack_info)
2102 struct inferior_status *inf_status;
2103 int restore_stack_info;
2105 inf_status->stop_signal = stop_signal;
2106 inf_status->stop_pc = stop_pc;
2107 inf_status->stop_step = stop_step;
2108 inf_status->stop_stack_dummy = stop_stack_dummy;
2109 inf_status->stopped_by_random_signal = stopped_by_random_signal;
2110 inf_status->trap_expected = trap_expected;
2111 inf_status->step_range_start = step_range_start;
2112 inf_status->step_range_end = step_range_end;
2113 inf_status->step_frame_address = step_frame_address;
2114 inf_status->step_over_calls = step_over_calls;
2115 inf_status->stop_after_trap = stop_after_trap;
2116 inf_status->stop_soon_quietly = stop_soon_quietly;
2117 /* Save original bpstat chain here; replace it with copy of chain.
2118 If caller's caller is walking the chain, they'll be happier if we
2119 hand them back the original chain when restore_i_s is called. */
2120 inf_status->stop_bpstat = stop_bpstat;
2121 stop_bpstat = bpstat_copy (stop_bpstat);
2122 inf_status->breakpoint_proceeded = breakpoint_proceeded;
2123 inf_status->restore_stack_info = restore_stack_info;
2124 inf_status->proceed_to_finish = proceed_to_finish;
2126 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
2128 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
2130 record_selected_frame (&(inf_status->selected_frame_address),
2131 &(inf_status->selected_level));
2135 struct restore_selected_frame_args {
2136 CORE_ADDR frame_address;
2140 static int restore_selected_frame PARAMS ((char *));
2142 /* Restore the selected frame. args is really a struct
2143 restore_selected_frame_args * (declared as char * for catch_errors)
2144 telling us what frame to restore. Returns 1 for success, or 0 for
2145 failure. An error message will have been printed on error. */
2148 restore_selected_frame (args)
2151 struct restore_selected_frame_args *fr =
2152 (struct restore_selected_frame_args *) args;
2153 struct frame_info *frame;
2154 int level = fr->level;
2156 frame = find_relative_frame (get_current_frame (), &level);
2158 /* If inf_status->selected_frame_address is NULL, there was no
2159 previously selected frame. */
2160 if (frame == NULL ||
2161 FRAME_FP (frame) != fr->frame_address ||
2164 warning ("Unable to restore previously selected frame.\n");
2167 select_frame (frame, fr->level);
2172 restore_inferior_status (inf_status)
2173 struct inferior_status *inf_status;
2175 stop_signal = inf_status->stop_signal;
2176 stop_pc = inf_status->stop_pc;
2177 stop_step = inf_status->stop_step;
2178 stop_stack_dummy = inf_status->stop_stack_dummy;
2179 stopped_by_random_signal = inf_status->stopped_by_random_signal;
2180 trap_expected = inf_status->trap_expected;
2181 step_range_start = inf_status->step_range_start;
2182 step_range_end = inf_status->step_range_end;
2183 step_frame_address = inf_status->step_frame_address;
2184 step_over_calls = inf_status->step_over_calls;
2185 stop_after_trap = inf_status->stop_after_trap;
2186 stop_soon_quietly = inf_status->stop_soon_quietly;
2187 bpstat_clear (&stop_bpstat);
2188 stop_bpstat = inf_status->stop_bpstat;
2189 breakpoint_proceeded = inf_status->breakpoint_proceeded;
2190 proceed_to_finish = inf_status->proceed_to_finish;
2192 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
2194 /* The inferior can be gone if the user types "print exit(0)"
2195 (and perhaps other times). */
2196 if (target_has_execution)
2197 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
2199 /* The inferior can be gone if the user types "print exit(0)"
2200 (and perhaps other times). */
2202 /* FIXME: If we are being called after stopping in a function which
2203 is called from gdb, we should not be trying to restore the
2204 selected frame; it just prints a spurious error message (The
2205 message is useful, however, in detecting bugs in gdb (like if gdb
2206 clobbers the stack)). In fact, should we be restoring the
2207 inferior status at all in that case? . */
2209 if (target_has_stack && inf_status->restore_stack_info)
2211 struct restore_selected_frame_args fr;
2212 fr.level = inf_status->selected_level;
2213 fr.frame_address = inf_status->selected_frame_address;
2214 /* The point of catch_errors is that if the stack is clobbered,
2215 walking the stack might encounter a garbage pointer and error()
2216 trying to dereference it. */
2217 if (catch_errors (restore_selected_frame, &fr,
2218 "Unable to restore previously selected frame:\n",
2219 RETURN_MASK_ERROR) == 0)
2220 /* Error in restoring the selected frame. Select the innermost
2222 select_frame (get_current_frame (), 0);
2228 _initialize_infrun ()
2231 register int numsigs;
2233 add_info ("signals", signals_info,
2234 "What debugger does when program gets various signals.\n\
2235 Specify a signal as argument to print info on that signal only.");
2236 add_info_alias ("handle", "signals", 0);
2238 add_com ("handle", class_run, handle_command,
2239 concat ("Specify how to handle a signal.\n\
2240 Args are signals and actions to apply to those signals.\n\
2241 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
2242 from 1-15 are allowed for compatibility with old versions of GDB.\n\
2243 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
2244 The special arg \"all\" is recognized to mean all signals except those\n\
2245 used by the debugger, typically SIGTRAP and SIGINT.\n",
2246 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
2247 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
2248 Stop means reenter debugger if this signal happens (implies print).\n\
2249 Print means print a message if this signal happens.\n\
2250 Pass means let program see this signal; otherwise program doesn't know.\n\
2251 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
2252 Pass and Stop may be combined.", NULL));
2254 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
2255 "There is no `stop' command, but you can set a hook on `stop'.\n\
2256 This allows you to set a list of commands to be run each time execution\n\
2257 of the program stops.", &cmdlist);
2259 numsigs = (int)TARGET_SIGNAL_LAST;
2260 signal_stop = (unsigned char *)
2261 xmalloc (sizeof (signal_stop[0]) * numsigs);
2262 signal_print = (unsigned char *)
2263 xmalloc (sizeof (signal_print[0]) * numsigs);
2264 signal_program = (unsigned char *)
2265 xmalloc (sizeof (signal_program[0]) * numsigs);
2266 for (i = 0; i < numsigs; i++)
2269 signal_print[i] = 1;
2270 signal_program[i] = 1;
2273 /* Signals caused by debugger's own actions
2274 should not be given to the program afterwards. */
2275 signal_program[TARGET_SIGNAL_TRAP] = 0;
2276 signal_program[TARGET_SIGNAL_INT] = 0;
2278 /* Signals that are not errors should not normally enter the debugger. */
2279 signal_stop[TARGET_SIGNAL_ALRM] = 0;
2280 signal_print[TARGET_SIGNAL_ALRM] = 0;
2281 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
2282 signal_print[TARGET_SIGNAL_VTALRM] = 0;
2283 signal_stop[TARGET_SIGNAL_PROF] = 0;
2284 signal_print[TARGET_SIGNAL_PROF] = 0;
2285 signal_stop[TARGET_SIGNAL_CHLD] = 0;
2286 signal_print[TARGET_SIGNAL_CHLD] = 0;
2287 signal_stop[TARGET_SIGNAL_IO] = 0;
2288 signal_print[TARGET_SIGNAL_IO] = 0;
2289 signal_stop[TARGET_SIGNAL_POLL] = 0;
2290 signal_print[TARGET_SIGNAL_POLL] = 0;
2291 signal_stop[TARGET_SIGNAL_URG] = 0;
2292 signal_print[TARGET_SIGNAL_URG] = 0;
2296 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
2297 (char *) &stop_on_solib_events,
2298 "Set stopping for shared library events.\n\
2299 If nonzero, gdb will give control to the user when the dynamic linker\n\
2300 notifies gdb of shared library events. The most common event of interest\n\
2301 to the user would be loading/unloading of a new library.\n",