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 and 3) we didn't hit a breakpoint in a signal handler
908 without an intervening stop in sigtramp, which is
909 detected by a new stack pointer value below
910 any usual function calling stack adjustments. */
911 (CURRENTLY_STEPPING ()
912 && prev_pc != stop_pc - DECR_PC_AFTER_BREAK
914 && read_sp () INNER_THAN (step_sp - 16))) :
917 /* Following in case break condition called a
919 stop_print_frame = 1;
922 if (stop_signal == TARGET_SIGNAL_TRAP)
924 = !(bpstat_explains_signal (stop_bpstat)
926 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
927 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
928 FRAME_FP (get_current_frame ()))
929 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
930 || (step_range_end && step_resume_breakpoint == NULL));
934 = !(bpstat_explains_signal (stop_bpstat)
935 /* End of a stack dummy. Some systems (e.g. Sony
936 news) give another signal besides SIGTRAP,
937 so check here as well as above. */
938 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
939 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
940 FRAME_FP (get_current_frame ()))
941 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
944 stop_signal = TARGET_SIGNAL_TRAP;
950 /* For the program's own signals, act according to
951 the signal handling tables. */
955 /* Signal not for debugging purposes. */
958 stopped_by_random_signal = 1;
960 if (signal_print[stop_signal])
963 target_terminal_ours_for_output ();
965 printf_filtered ("\nProgram received signal ");
966 annotate_signal_name ();
967 printf_filtered ("%s", target_signal_to_name (stop_signal));
968 annotate_signal_name_end ();
969 printf_filtered (", ");
970 annotate_signal_string ();
971 printf_filtered ("%s", target_signal_to_string (stop_signal));
972 annotate_signal_string_end ();
973 printf_filtered (".\n");
974 gdb_flush (gdb_stdout);
976 if (signal_stop[stop_signal])
978 /* If not going to stop, give terminal back
979 if we took it away. */
981 target_terminal_inferior ();
983 /* Clear the signal if it should not be passed. */
984 if (signal_program[stop_signal] == 0)
985 stop_signal = TARGET_SIGNAL_0;
987 /* I'm not sure whether this needs to be check_sigtramp2 or
988 whether it could/should be keep_going. */
989 goto check_sigtramp2;
992 /* Handle cases caused by hitting a breakpoint. */
994 CORE_ADDR jmp_buf_pc;
995 struct bpstat_what what;
997 what = bpstat_what (stop_bpstat);
1001 stop_stack_dummy = 1;
1003 trap_expected_after_continue = 1;
1007 switch (what.main_action)
1009 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
1010 /* If we hit the breakpoint at longjmp, disable it for the
1011 duration of this command. Then, install a temporary
1012 breakpoint at the target of the jmp_buf. */
1013 disable_longjmp_breakpoint();
1014 remove_breakpoints ();
1015 breakpoints_inserted = 0;
1016 if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
1018 /* Need to blow away step-resume breakpoint, as it
1019 interferes with us */
1020 if (step_resume_breakpoint != NULL)
1022 delete_breakpoint (step_resume_breakpoint);
1023 step_resume_breakpoint = NULL;
1025 /* Not sure whether we need to blow this away too, but probably
1026 it is like the step-resume breakpoint. */
1027 if (through_sigtramp_breakpoint != NULL)
1029 delete_breakpoint (through_sigtramp_breakpoint);
1030 through_sigtramp_breakpoint = NULL;
1034 /* FIXME - Need to implement nested temporary breakpoints */
1035 if (step_over_calls > 0)
1036 set_longjmp_resume_breakpoint(jmp_buf_pc,
1037 get_current_frame());
1040 set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
1041 handling_longjmp = 1; /* FIXME */
1044 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
1045 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
1046 remove_breakpoints ();
1047 breakpoints_inserted = 0;
1049 /* FIXME - Need to implement nested temporary breakpoints */
1051 && (FRAME_FP (get_current_frame ())
1052 INNER_THAN step_frame_address))
1058 disable_longjmp_breakpoint();
1059 handling_longjmp = 0; /* FIXME */
1060 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
1062 /* else fallthrough */
1064 case BPSTAT_WHAT_SINGLE:
1065 if (breakpoints_inserted)
1066 remove_breakpoints ();
1067 breakpoints_inserted = 0;
1069 /* Still need to check other stuff, at least the case
1070 where we are stepping and step out of the right range. */
1073 case BPSTAT_WHAT_STOP_NOISY:
1074 stop_print_frame = 1;
1076 /* We are about to nuke the step_resume_breakpoint and
1077 through_sigtramp_breakpoint via the cleanup chain, so
1078 no need to worry about it here. */
1082 case BPSTAT_WHAT_STOP_SILENT:
1083 stop_print_frame = 0;
1085 /* We are about to nuke the step_resume_breakpoint and
1086 through_sigtramp_breakpoint via the cleanup chain, so
1087 no need to worry about it here. */
1091 case BPSTAT_WHAT_STEP_RESUME:
1092 delete_breakpoint (step_resume_breakpoint);
1093 step_resume_breakpoint = NULL;
1096 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
1097 if (through_sigtramp_breakpoint)
1098 delete_breakpoint (through_sigtramp_breakpoint);
1099 through_sigtramp_breakpoint = NULL;
1101 /* If were waiting for a trap, hitting the step_resume_break
1102 doesn't count as getting it. */
1107 case BPSTAT_WHAT_CHECK_SHLIBS:
1110 extern int auto_solib_add;
1112 /* Remove breakpoints, we eventually want to step over the
1113 shlib event breakpoint, and SOLIB_ADD might adjust
1114 breakpoint addresses via breakpoint_re_set. */
1115 if (breakpoints_inserted)
1116 remove_breakpoints ();
1117 breakpoints_inserted = 0;
1119 /* Check for any newly added shared libraries if we're
1120 supposed to be adding them automatically. */
1123 /* Switch terminal for any messages produced by
1124 breakpoint_re_set. */
1125 target_terminal_ours_for_output ();
1126 SOLIB_ADD (NULL, 0, NULL);
1127 target_terminal_inferior ();
1130 /* Try to reenable shared library breakpoints, additional
1131 code segments in shared libraries might be mapped in now. */
1132 re_enable_breakpoints_in_shlibs ();
1134 /* If requested, stop when the dynamic linker notifies
1135 gdb of events. This allows the user to get control
1136 and place breakpoints in initializer routines for
1137 dynamically loaded objects (among other things). */
1138 if (stop_on_solib_events)
1140 stop_print_frame = 0;
1145 /* We want to step over this breakpoint, then keep going. */
1153 case BPSTAT_WHAT_LAST:
1154 /* Not a real code, but listed here to shut up gcc -Wall. */
1156 case BPSTAT_WHAT_KEEP_CHECKING:
1161 /* We come here if we hit a breakpoint but should not
1162 stop for it. Possibly we also were stepping
1163 and should stop for that. So fall through and
1164 test for stepping. But, if not stepping,
1167 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1168 /* This is the old way of detecting the end of the stack dummy.
1169 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
1170 handled above. As soon as we can test it on all of them, all
1171 architectures should define it. */
1173 /* If this is the breakpoint at the end of a stack dummy,
1174 just stop silently, unless the user was doing an si/ni, in which
1175 case she'd better know what she's doing. */
1177 if (PC_IN_CALL_DUMMY (stop_pc, read_sp (), FRAME_FP (get_current_frame ()))
1180 stop_print_frame = 0;
1181 stop_stack_dummy = 1;
1183 trap_expected_after_continue = 1;
1187 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1189 if (step_resume_breakpoint)
1190 /* Having a step-resume breakpoint overrides anything
1191 else having to do with stepping commands until
1192 that breakpoint is reached. */
1193 /* I'm not sure whether this needs to be check_sigtramp2 or
1194 whether it could/should be keep_going. */
1195 goto check_sigtramp2;
1197 if (step_range_end == 0)
1198 /* Likewise if we aren't even stepping. */
1199 /* I'm not sure whether this needs to be check_sigtramp2 or
1200 whether it could/should be keep_going. */
1201 goto check_sigtramp2;
1203 /* If stepping through a line, keep going if still within it. */
1204 if (stop_pc >= step_range_start
1205 && stop_pc < step_range_end
1207 /* I haven't a clue what might trigger this clause, and it seems wrong anyway,
1208 so I've disabled it until someone complains. -Stu 10/24/95 */
1210 /* The step range might include the start of the
1211 function, so if we are at the start of the
1212 step range and either the stack or frame pointers
1213 just changed, we've stepped outside */
1214 && !(stop_pc == step_range_start
1215 && FRAME_FP (get_current_frame ())
1216 && (read_sp () INNER_THAN step_sp
1217 || FRAME_FP (get_current_frame ()) != step_frame_address))
1221 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
1222 So definately need to check for sigtramp here. */
1223 goto check_sigtramp2;
1226 /* We stepped out of the stepping range. */
1228 /* If we are stepping at the source level and entered the runtime
1229 loader dynamic symbol resolution code, we keep on single stepping
1230 until we exit the run time loader code and reach the callee's
1232 if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
1235 /* We can't update step_sp every time through the loop, because
1236 reading the stack pointer would slow down stepping too much.
1237 But we can update it every time we leave the step range. */
1240 /* Did we just take a signal? */
1241 if (IN_SIGTRAMP (stop_pc, stop_func_name)
1242 && !IN_SIGTRAMP (prev_pc, prev_func_name)
1243 && read_sp () INNER_THAN step_sp)
1245 /* We've just taken a signal; go until we are back to
1246 the point where we took it and one more. */
1248 /* This code is needed at least in the following case:
1249 The user types "next" and then a signal arrives (before
1250 the "next" is done). */
1252 /* Note that if we are stopped at a breakpoint, then we need
1253 the step_resume breakpoint to override any breakpoints at
1254 the same location, so that we will still step over the
1255 breakpoint even though the signal happened. */
1258 struct symtab_and_line sr_sal;
1260 INIT_SAL (&sr_sal); /* initialize to zeroes */
1261 sr_sal.pc = prev_pc;
1262 sr_sal.section = find_pc_overlay (sr_sal.pc);
1263 /* We could probably be setting the frame to
1264 step_frame_address; I don't think anyone thought to try it. */
1265 step_resume_breakpoint =
1266 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1267 if (breakpoints_inserted)
1268 insert_breakpoints ();
1271 /* If this is stepi or nexti, make sure that the stepping range
1272 gets us past that instruction. */
1273 if (step_range_end == 1)
1274 /* FIXME: Does this run afoul of the code below which, if
1275 we step into the middle of a line, resets the stepping
1277 step_range_end = (step_range_start = prev_pc) + 1;
1279 remove_breakpoints_on_following_step = 1;
1284 /* I disabled this test because it was too complicated and slow. The
1285 SKIP_PROLOGUE was especially slow, because it caused unnecessary
1286 prologue examination on various architectures. The code in the #else
1287 clause has been tested on the Sparc, Mips, PA, and Power
1288 architectures, so it's pretty likely to be correct. -Stu 10/24/95 */
1290 /* See if we left the step range due to a subroutine call that
1291 we should proceed to the end of. */
1293 if (stop_func_start)
1297 /* Do this after the IN_SIGTRAMP check; it might give
1299 prologue_pc = stop_func_start;
1301 /* Don't skip the prologue if this is assembly source */
1302 s = find_pc_symtab (stop_pc);
1303 if (s && s->language != language_asm)
1304 SKIP_PROLOGUE (prologue_pc);
1307 if (!(step_sp INNER_THAN read_sp ()) /* don't mistake (sig)return as a call */
1308 && (/* Might be a non-recursive call. If the symbols are missing
1309 enough that stop_func_start == prev_func_start even though
1310 they are really two functions, we will treat some calls as
1312 stop_func_start != prev_func_start
1314 /* Might be a recursive call if either we have a prologue
1315 or the call instruction itself saves the PC on the stack. */
1316 || prologue_pc != stop_func_start
1317 || read_sp () != step_sp)
1318 && (/* PC is completely out of bounds of any known objfiles. Treat
1319 like a subroutine call. */
1322 /* If we do a call, we will be at the start of a function... */
1323 || stop_pc == stop_func_start
1325 /* ...except on the Alpha with -O (and also Irix 5 and
1326 perhaps others), in which we might call the address
1327 after the load of gp. Since prologues don't contain
1328 calls, we can't return to within one, and we don't
1329 jump back into them, so this check is OK. */
1331 || stop_pc < prologue_pc
1333 /* ...and if it is a leaf function, the prologue might
1334 consist of gp loading only, so the call transfers to
1335 the first instruction after the prologue. */
1336 || (stop_pc == prologue_pc
1338 /* Distinguish this from the case where we jump back
1339 to the first instruction after the prologue,
1340 within a function. */
1341 && stop_func_start != prev_func_start)
1343 /* If we end up in certain places, it means we did a subroutine
1344 call. I'm not completely sure this is necessary now that we
1345 have the above checks with stop_func_start (and now that
1346 find_pc_partial_function is pickier). */
1347 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
1349 /* If none of the above apply, it is a jump within a function,
1350 or a return from a subroutine. The other case is longjmp,
1351 which can no longer happen here as long as the
1352 handling_longjmp stuff is working. */
1355 /* This test is a much more streamlined, (but hopefully correct)
1356 replacement for the code above. It's been tested on the Sparc,
1357 Mips, PA, and Power architectures with good results. */
1359 if (stop_pc == stop_func_start /* Quick test */
1360 || in_prologue (stop_pc, stop_func_start)
1361 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
1362 || stop_func_start == 0)
1366 /* It's a subroutine call. */
1368 if (step_over_calls == 0)
1370 /* I presume that step_over_calls is only 0 when we're
1371 supposed to be stepping at the assembly language level
1372 ("stepi"). Just stop. */
1377 if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc))
1378 /* We're doing a "next". */
1379 goto step_over_function;
1381 /* If we are in a function call trampoline (a stub between
1382 the calling routine and the real function), locate the real
1383 function. That's what tells us (a) whether we want to step
1384 into it at all, and (b) what prologue we want to run to
1385 the end of, if we do step into it. */
1386 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1388 stop_func_start = tmp;
1391 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
1394 struct symtab_and_line xxx;
1395 /* Why isn't this s_a_l called "sr_sal", like all of the
1396 other s_a_l's where this code is duplicated? */
1397 INIT_SAL (&xxx); /* initialize to zeroes */
1399 xxx.section = find_pc_overlay (xxx.pc);
1400 step_resume_breakpoint =
1401 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
1402 insert_breakpoints ();
1407 /* If we have line number information for the function we
1408 are thinking of stepping into, step into it.
1410 If there are several symtabs at that PC (e.g. with include
1411 files), just want to know whether *any* of them have line
1412 numbers. find_pc_line handles this. */
1414 struct symtab_and_line tmp_sal;
1416 tmp_sal = find_pc_line (stop_func_start, 0);
1417 if (tmp_sal.line != 0)
1418 goto step_into_function;
1422 /* A subroutine call has happened. */
1424 /* Set a special breakpoint after the return */
1425 struct symtab_and_line sr_sal;
1427 INIT_SAL (&sr_sal); /* initialize to zeroes */
1429 ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
1430 sr_sal.section = find_pc_overlay (sr_sal.pc);
1431 step_resume_breakpoint =
1432 set_momentary_breakpoint (sr_sal, get_current_frame (),
1434 if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
1435 step_resume_breakpoint->frame = step_frame_address;
1436 if (breakpoints_inserted)
1437 insert_breakpoints ();
1442 /* Subroutine call with source code we should not step over.
1443 Do step to the first line of code in it. */
1447 s = find_pc_symtab (stop_pc);
1448 if (s && s->language != language_asm)
1449 SKIP_PROLOGUE (stop_func_start);
1451 sal = find_pc_line (stop_func_start, 0);
1452 /* Use the step_resume_break to step until
1453 the end of the prologue, even if that involves jumps
1454 (as it seems to on the vax under 4.2). */
1455 /* If the prologue ends in the middle of a source line,
1456 continue to the end of that source line (if it is still
1457 within the function). Otherwise, just go to end of prologue. */
1458 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1459 /* no, don't either. It skips any code that's
1460 legitimately on the first line. */
1462 if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end)
1463 stop_func_start = sal.end;
1466 if (stop_func_start == stop_pc)
1468 /* We are already there: stop now. */
1473 /* Put the step-breakpoint there and go until there. */
1475 struct symtab_and_line sr_sal;
1477 INIT_SAL (&sr_sal); /* initialize to zeroes */
1478 sr_sal.pc = stop_func_start;
1479 sr_sal.section = find_pc_overlay (stop_func_start);
1480 /* Do not specify what the fp should be when we stop
1481 since on some machines the prologue
1482 is where the new fp value is established. */
1483 step_resume_breakpoint =
1484 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1485 if (breakpoints_inserted)
1486 insert_breakpoints ();
1488 /* And make sure stepping stops right away then. */
1489 step_range_end = step_range_start;
1494 /* We've wandered out of the step range. */
1496 sal = find_pc_line(stop_pc, 0);
1498 if (step_range_end == 1)
1500 /* It is stepi or nexti. We always want to stop stepping after
1506 /* If we're in the return path from a shared library trampoline,
1507 we want to proceed through the trampoline when stepping. */
1508 if (IN_SOLIB_RETURN_TRAMPOLINE(stop_pc, stop_func_name))
1512 /* Determine where this trampoline returns. */
1513 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1515 /* Only proceed through if we know where it's going. */
1518 /* And put the step-breakpoint there and go until there. */
1519 struct symtab_and_line sr_sal;
1521 INIT_SAL (&sr_sal); /* initialize to zeroes */
1523 sr_sal.section = find_pc_overlay (sr_sal.pc);
1524 /* Do not specify what the fp should be when we stop
1525 since on some machines the prologue
1526 is where the new fp value is established. */
1527 step_resume_breakpoint =
1528 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1529 if (breakpoints_inserted)
1530 insert_breakpoints ();
1532 /* Restart without fiddling with the step ranges or
1540 /* We have no line number information. That means to stop
1541 stepping (does this always happen right after one instruction,
1542 when we do "s" in a function with no line numbers,
1543 or can this happen as a result of a return or longjmp?). */
1548 if (stop_pc == sal.pc
1549 && (current_line != sal.line || current_symtab != sal.symtab))
1551 /* We are at the start of a different line. So stop. Note that
1552 we don't stop if we step into the middle of a different line.
1553 That is said to make things like for (;;) statements work
1559 /* We aren't done stepping.
1561 Optimize by setting the stepping range to the line.
1562 (We might not be in the original line, but if we entered a
1563 new line in mid-statement, we continue stepping. This makes
1564 things like for(;;) statements work better.) */
1566 if (stop_func_end && sal.end >= stop_func_end)
1568 /* If this is the last line of the function, don't keep stepping
1569 (it would probably step us out of the function).
1570 This is particularly necessary for a one-line function,
1571 in which after skipping the prologue we better stop even though
1572 we will be in mid-line. */
1576 step_range_start = sal.pc;
1577 step_range_end = sal.end;
1578 step_frame_address = FRAME_FP (get_current_frame ());
1579 current_line = sal.line;
1580 current_symtab = sal.symtab;
1585 && IN_SIGTRAMP (stop_pc, stop_func_name)
1586 && !IN_SIGTRAMP (prev_pc, prev_func_name)
1587 && read_sp () INNER_THAN step_sp)
1589 /* What has happened here is that we have just stepped the inferior
1590 with a signal (because it is a signal which shouldn't make
1591 us stop), thus stepping into sigtramp.
1593 So we need to set a step_resume_break_address breakpoint
1594 and continue until we hit it, and then step. FIXME: This should
1595 be more enduring than a step_resume breakpoint; we should know
1596 that we will later need to keep going rather than re-hitting
1597 the breakpoint here (see testsuite/gdb.t06/signals.exp where
1598 it says "exceedingly difficult"). */
1599 struct symtab_and_line sr_sal;
1601 INIT_SAL (&sr_sal); /* initialize to zeroes */
1602 sr_sal.pc = prev_pc;
1603 sr_sal.section = find_pc_overlay (sr_sal.pc);
1604 /* We perhaps could set the frame if we kept track of what
1605 the frame corresponding to prev_pc was. But we don't,
1607 through_sigtramp_breakpoint =
1608 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
1609 if (breakpoints_inserted)
1610 insert_breakpoints ();
1612 remove_breakpoints_on_following_step = 1;
1617 /* Come to this label when you need to resume the inferior.
1618 It's really much cleaner to do a goto than a maze of if-else
1621 /* Save the pc before execution, to compare with pc after stop. */
1622 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
1623 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
1624 BREAK is defined, the
1625 original pc would not have
1626 been at the start of a
1628 prev_func_name = stop_func_name;
1631 step_sp = read_sp ();
1634 /* If we did not do break;, it means we should keep
1635 running the inferior and not return to debugger. */
1637 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
1639 /* We took a signal (which we are supposed to pass through to
1640 the inferior, else we'd have done a break above) and we
1641 haven't yet gotten our trap. Simply continue. */
1642 resume (CURRENTLY_STEPPING (), stop_signal);
1646 /* Either the trap was not expected, but we are continuing
1647 anyway (the user asked that this signal be passed to the
1650 The signal was SIGTRAP, e.g. it was our signal, but we
1651 decided we should resume from it.
1653 We're going to run this baby now!
1655 Insert breakpoints now, unless we are trying
1656 to one-proceed past a breakpoint. */
1657 /* If we've just finished a special step resume and we don't
1658 want to hit a breakpoint, pull em out. */
1659 if (step_resume_breakpoint == NULL
1660 && through_sigtramp_breakpoint == NULL
1661 && remove_breakpoints_on_following_step)
1663 remove_breakpoints_on_following_step = 0;
1664 remove_breakpoints ();
1665 breakpoints_inserted = 0;
1667 else if (!breakpoints_inserted &&
1668 (through_sigtramp_breakpoint != NULL || !another_trap))
1670 breakpoints_failed = insert_breakpoints ();
1671 if (breakpoints_failed)
1673 breakpoints_inserted = 1;
1676 trap_expected = another_trap;
1678 if (stop_signal == TARGET_SIGNAL_TRAP)
1679 stop_signal = TARGET_SIGNAL_0;
1681 #ifdef SHIFT_INST_REGS
1682 /* I'm not sure when this following segment applies. I do know, now,
1683 that we shouldn't rewrite the regs when we were stopped by a
1684 random signal from the inferior process. */
1685 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
1686 (this is only used on the 88k). */
1688 if (!bpstat_explains_signal (stop_bpstat)
1689 && (stop_signal != TARGET_SIGNAL_CHLD)
1690 && !stopped_by_random_signal)
1692 #endif /* SHIFT_INST_REGS */
1694 resume (CURRENTLY_STEPPING (), stop_signal);
1699 if (target_has_execution)
1701 /* Assuming the inferior still exists, set these up for next
1702 time, just like we did above if we didn't break out of the
1704 prev_pc = read_pc ();
1705 prev_func_start = stop_func_start;
1706 prev_func_name = stop_func_name;
1708 do_cleanups (old_cleanups);
1711 /* Here to return control to GDB when the inferior stops for real.
1712 Print appropriate messages, remove breakpoints, give terminal our modes.
1714 STOP_PRINT_FRAME nonzero means print the executing frame
1715 (pc, function, args, file, line number and line text).
1716 BREAKPOINTS_FAILED nonzero means stop was due to error
1717 attempting to insert breakpoints. */
1722 /* Make sure that the current_frame's pc is correct. This
1723 is a correction for setting up the frame info before doing
1724 DECR_PC_AFTER_BREAK */
1725 if (target_has_execution && get_current_frame())
1726 (get_current_frame ())->pc = read_pc ();
1728 if (breakpoints_failed)
1730 target_terminal_ours_for_output ();
1731 print_sys_errmsg ("ptrace", breakpoints_failed);
1732 printf_filtered ("Stopped; cannot insert breakpoints.\n\
1733 The same program may be running in another process.\n");
1736 if (target_has_execution && breakpoints_inserted)
1737 if (remove_breakpoints ())
1739 target_terminal_ours_for_output ();
1740 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
1741 It might be running in another process.\n\
1742 Further execution is probably impossible.\n");
1745 breakpoints_inserted = 0;
1747 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1748 Delete any breakpoint that is to be deleted at the next stop. */
1750 breakpoint_auto_delete (stop_bpstat);
1752 /* If an auto-display called a function and that got a signal,
1753 delete that auto-display to avoid an infinite recursion. */
1755 if (stopped_by_random_signal)
1756 disable_current_display ();
1758 if (step_multi && stop_step)
1761 target_terminal_ours ();
1764 && stop_bpstat->breakpoint_at
1765 && stop_bpstat->breakpoint_at->type == bp_shlib_event)
1766 printf_filtered ("Stopped due to shared library event\n");
1768 /* Look up the hook_stop and run it if it exists. */
1770 if (stop_command->hook)
1772 catch_errors (hook_stop_stub, (char *)stop_command->hook,
1773 "Error while running hook_stop:\n", RETURN_MASK_ALL);
1776 if (!target_has_stack)
1779 /* Select innermost stack frame except on return from a stack dummy routine,
1780 or if the program has exited. Print it without a level number if
1781 we have changed functions or hit a breakpoint. Print source line
1783 if (!stop_stack_dummy)
1785 select_frame (get_current_frame (), 0);
1787 if (stop_print_frame)
1791 source_only = bpstat_print (stop_bpstat);
1792 source_only = source_only ||
1794 && step_frame_address == FRAME_FP (get_current_frame ())
1795 && step_start_function == find_pc_function (stop_pc));
1797 print_stack_frame (selected_frame, -1, source_only? -1: 1);
1799 /* Display the auto-display expressions. */
1804 /* Save the function value return registers, if we care.
1805 We might be about to restore their previous contents. */
1806 if (proceed_to_finish)
1807 read_register_bytes (0, stop_registers, REGISTER_BYTES);
1809 if (stop_stack_dummy)
1811 /* Pop the empty frame that contains the stack dummy.
1812 POP_FRAME ends with a setting of the current frame, so we
1813 can use that next. */
1815 /* Set stop_pc to what it was before we called the function. Can't rely
1816 on restore_inferior_status because that only gets called if we don't
1817 stop in the called function. */
1818 stop_pc = read_pc();
1819 select_frame (get_current_frame (), 0);
1822 annotate_stopped ();
1826 hook_stop_stub (cmd)
1829 execute_user_command ((struct cmd_list_element *)cmd, 0);
1833 int signal_stop_state (signo)
1836 return signal_stop[signo];
1839 int signal_print_state (signo)
1842 return signal_print[signo];
1845 int signal_pass_state (signo)
1848 return signal_program[signo];
1855 Signal Stop\tPrint\tPass to program\tDescription\n");
1859 sig_print_info (oursig)
1860 enum target_signal oursig;
1862 char *name = target_signal_to_name (oursig);
1863 int name_padding = 13 - strlen (name);
1864 if (name_padding <= 0)
1867 printf_filtered ("%s", name);
1868 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
1869 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
1870 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
1871 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
1872 printf_filtered ("%s\n", target_signal_to_string (oursig));
1875 /* Specify how various signals in the inferior should be handled. */
1878 handle_command (args, from_tty)
1883 int digits, wordlen;
1884 int sigfirst, signum, siglast;
1885 enum target_signal oursig;
1888 unsigned char *sigs;
1889 struct cleanup *old_chain;
1893 error_no_arg ("signal to handle");
1896 /* Allocate and zero an array of flags for which signals to handle. */
1898 nsigs = (int)TARGET_SIGNAL_LAST;
1899 sigs = (unsigned char *) alloca (nsigs);
1900 memset (sigs, 0, nsigs);
1902 /* Break the command line up into args. */
1904 argv = buildargv (args);
1909 old_chain = make_cleanup (freeargv, (char *) argv);
1911 /* Walk through the args, looking for signal oursigs, signal names, and
1912 actions. Signal numbers and signal names may be interspersed with
1913 actions, with the actions being performed for all signals cumulatively
1914 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
1916 while (*argv != NULL)
1918 wordlen = strlen (*argv);
1919 for (digits = 0; isdigit ((*argv)[digits]); digits++) {;}
1921 sigfirst = siglast = -1;
1923 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
1925 /* Apply action to all signals except those used by the
1926 debugger. Silently skip those. */
1929 siglast = nsigs - 1;
1931 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
1933 SET_SIGS (nsigs, sigs, signal_stop);
1934 SET_SIGS (nsigs, sigs, signal_print);
1936 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
1938 UNSET_SIGS (nsigs, sigs, signal_program);
1940 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
1942 SET_SIGS (nsigs, sigs, signal_print);
1944 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
1946 SET_SIGS (nsigs, sigs, signal_program);
1948 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
1950 UNSET_SIGS (nsigs, sigs, signal_stop);
1952 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
1954 SET_SIGS (nsigs, sigs, signal_program);
1956 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
1958 UNSET_SIGS (nsigs, sigs, signal_print);
1959 UNSET_SIGS (nsigs, sigs, signal_stop);
1961 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
1963 UNSET_SIGS (nsigs, sigs, signal_program);
1965 else if (digits > 0)
1967 /* It is numeric. The numeric signal refers to our own internal
1968 signal numbering from target.h, not to host/target signal number.
1969 This is a feature; users really should be using symbolic names
1970 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
1971 will work right anyway. */
1973 sigfirst = siglast = (int) target_signal_from_command (atoi (*argv));
1974 if ((*argv)[digits] == '-')
1977 (int) target_signal_from_command (atoi ((*argv) + digits + 1));
1979 if (sigfirst > siglast)
1981 /* Bet he didn't figure we'd think of this case... */
1989 oursig = target_signal_from_name (*argv);
1990 if (oursig != TARGET_SIGNAL_UNKNOWN)
1992 sigfirst = siglast = (int)oursig;
1996 /* Not a number and not a recognized flag word => complain. */
1997 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
2001 /* If any signal numbers or symbol names were found, set flags for
2002 which signals to apply actions to. */
2004 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
2006 switch ((enum target_signal)signum)
2008 case TARGET_SIGNAL_TRAP:
2009 case TARGET_SIGNAL_INT:
2010 if (!allsigs && !sigs[signum])
2012 if (query ("%s is used by the debugger.\n\
2013 Are you sure you want to change it? ",
2014 target_signal_to_name
2015 ((enum target_signal)signum)))
2021 printf_unfiltered ("Not confirmed, unchanged.\n");
2022 gdb_flush (gdb_stdout);
2026 case TARGET_SIGNAL_0:
2027 case TARGET_SIGNAL_DEFAULT:
2028 case TARGET_SIGNAL_UNKNOWN:
2029 /* Make sure that "all" doesn't print these. */
2040 target_notice_signals(inferior_pid);
2044 /* Show the results. */
2045 sig_print_header ();
2046 for (signum = 0; signum < nsigs; signum++)
2050 sig_print_info (signum);
2055 do_cleanups (old_chain);
2058 /* Print current contents of the tables set by the handle command.
2059 It is possible we should just be printing signals actually used
2060 by the current target (but for things to work right when switching
2061 targets, all signals should be in the signal tables). */
2064 signals_info (signum_exp, from_tty)
2068 enum target_signal oursig;
2069 sig_print_header ();
2073 /* First see if this is a symbol name. */
2074 oursig = target_signal_from_name (signum_exp);
2075 if (oursig == TARGET_SIGNAL_UNKNOWN)
2077 /* No, try numeric. */
2079 target_signal_from_command (parse_and_eval_address (signum_exp));
2081 sig_print_info (oursig);
2085 printf_filtered ("\n");
2086 /* These ugly casts brought to you by the native VAX compiler. */
2087 for (oursig = TARGET_SIGNAL_FIRST;
2088 (int)oursig < (int)TARGET_SIGNAL_LAST;
2089 oursig = (enum target_signal)((int)oursig + 1))
2093 if (oursig != TARGET_SIGNAL_UNKNOWN
2094 && oursig != TARGET_SIGNAL_DEFAULT
2095 && oursig != TARGET_SIGNAL_0)
2096 sig_print_info (oursig);
2099 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
2102 /* Save all of the information associated with the inferior<==>gdb
2103 connection. INF_STATUS is a pointer to a "struct inferior_status"
2104 (defined in inferior.h). */
2107 save_inferior_status (inf_status, restore_stack_info)
2108 struct inferior_status *inf_status;
2109 int restore_stack_info;
2111 inf_status->stop_signal = stop_signal;
2112 inf_status->stop_pc = stop_pc;
2113 inf_status->stop_step = stop_step;
2114 inf_status->stop_stack_dummy = stop_stack_dummy;
2115 inf_status->stopped_by_random_signal = stopped_by_random_signal;
2116 inf_status->trap_expected = trap_expected;
2117 inf_status->step_range_start = step_range_start;
2118 inf_status->step_range_end = step_range_end;
2119 inf_status->step_frame_address = step_frame_address;
2120 inf_status->step_over_calls = step_over_calls;
2121 inf_status->stop_after_trap = stop_after_trap;
2122 inf_status->stop_soon_quietly = stop_soon_quietly;
2123 /* Save original bpstat chain here; replace it with copy of chain.
2124 If caller's caller is walking the chain, they'll be happier if we
2125 hand them back the original chain when restore_i_s is called. */
2126 inf_status->stop_bpstat = stop_bpstat;
2127 stop_bpstat = bpstat_copy (stop_bpstat);
2128 inf_status->breakpoint_proceeded = breakpoint_proceeded;
2129 inf_status->restore_stack_info = restore_stack_info;
2130 inf_status->proceed_to_finish = proceed_to_finish;
2132 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
2134 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
2136 record_selected_frame (&(inf_status->selected_frame_address),
2137 &(inf_status->selected_level));
2141 struct restore_selected_frame_args {
2142 CORE_ADDR frame_address;
2146 static int restore_selected_frame PARAMS ((char *));
2148 /* Restore the selected frame. args is really a struct
2149 restore_selected_frame_args * (declared as char * for catch_errors)
2150 telling us what frame to restore. Returns 1 for success, or 0 for
2151 failure. An error message will have been printed on error. */
2154 restore_selected_frame (args)
2157 struct restore_selected_frame_args *fr =
2158 (struct restore_selected_frame_args *) args;
2159 struct frame_info *frame;
2160 int level = fr->level;
2162 frame = find_relative_frame (get_current_frame (), &level);
2164 /* If inf_status->selected_frame_address is NULL, there was no
2165 previously selected frame. */
2166 if (frame == NULL ||
2167 FRAME_FP (frame) != fr->frame_address ||
2170 warning ("Unable to restore previously selected frame.\n");
2173 select_frame (frame, fr->level);
2178 restore_inferior_status (inf_status)
2179 struct inferior_status *inf_status;
2181 stop_signal = inf_status->stop_signal;
2182 stop_pc = inf_status->stop_pc;
2183 stop_step = inf_status->stop_step;
2184 stop_stack_dummy = inf_status->stop_stack_dummy;
2185 stopped_by_random_signal = inf_status->stopped_by_random_signal;
2186 trap_expected = inf_status->trap_expected;
2187 step_range_start = inf_status->step_range_start;
2188 step_range_end = inf_status->step_range_end;
2189 step_frame_address = inf_status->step_frame_address;
2190 step_over_calls = inf_status->step_over_calls;
2191 stop_after_trap = inf_status->stop_after_trap;
2192 stop_soon_quietly = inf_status->stop_soon_quietly;
2193 bpstat_clear (&stop_bpstat);
2194 stop_bpstat = inf_status->stop_bpstat;
2195 breakpoint_proceeded = inf_status->breakpoint_proceeded;
2196 proceed_to_finish = inf_status->proceed_to_finish;
2198 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
2200 /* The inferior can be gone if the user types "print exit(0)"
2201 (and perhaps other times). */
2202 if (target_has_execution)
2203 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
2205 /* The inferior can be gone if the user types "print exit(0)"
2206 (and perhaps other times). */
2208 /* FIXME: If we are being called after stopping in a function which
2209 is called from gdb, we should not be trying to restore the
2210 selected frame; it just prints a spurious error message (The
2211 message is useful, however, in detecting bugs in gdb (like if gdb
2212 clobbers the stack)). In fact, should we be restoring the
2213 inferior status at all in that case? . */
2215 if (target_has_stack && inf_status->restore_stack_info)
2217 struct restore_selected_frame_args fr;
2218 fr.level = inf_status->selected_level;
2219 fr.frame_address = inf_status->selected_frame_address;
2220 /* The point of catch_errors is that if the stack is clobbered,
2221 walking the stack might encounter a garbage pointer and error()
2222 trying to dereference it. */
2223 if (catch_errors (restore_selected_frame, &fr,
2224 "Unable to restore previously selected frame:\n",
2225 RETURN_MASK_ERROR) == 0)
2226 /* Error in restoring the selected frame. Select the innermost
2228 select_frame (get_current_frame (), 0);
2234 _initialize_infrun ()
2237 register int numsigs;
2239 add_info ("signals", signals_info,
2240 "What debugger does when program gets various signals.\n\
2241 Specify a signal as argument to print info on that signal only.");
2242 add_info_alias ("handle", "signals", 0);
2244 add_com ("handle", class_run, handle_command,
2245 concat ("Specify how to handle a signal.\n\
2246 Args are signals and actions to apply to those signals.\n\
2247 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
2248 from 1-15 are allowed for compatibility with old versions of GDB.\n\
2249 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
2250 The special arg \"all\" is recognized to mean all signals except those\n\
2251 used by the debugger, typically SIGTRAP and SIGINT.\n",
2252 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
2253 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
2254 Stop means reenter debugger if this signal happens (implies print).\n\
2255 Print means print a message if this signal happens.\n\
2256 Pass means let program see this signal; otherwise program doesn't know.\n\
2257 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
2258 Pass and Stop may be combined.", NULL));
2260 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
2261 "There is no `stop' command, but you can set a hook on `stop'.\n\
2262 This allows you to set a list of commands to be run each time execution\n\
2263 of the program stops.", &cmdlist);
2265 numsigs = (int)TARGET_SIGNAL_LAST;
2266 signal_stop = (unsigned char *)
2267 xmalloc (sizeof (signal_stop[0]) * numsigs);
2268 signal_print = (unsigned char *)
2269 xmalloc (sizeof (signal_print[0]) * numsigs);
2270 signal_program = (unsigned char *)
2271 xmalloc (sizeof (signal_program[0]) * numsigs);
2272 for (i = 0; i < numsigs; i++)
2275 signal_print[i] = 1;
2276 signal_program[i] = 1;
2279 /* Signals caused by debugger's own actions
2280 should not be given to the program afterwards. */
2281 signal_program[TARGET_SIGNAL_TRAP] = 0;
2282 signal_program[TARGET_SIGNAL_INT] = 0;
2284 /* Signals that are not errors should not normally enter the debugger. */
2285 signal_stop[TARGET_SIGNAL_ALRM] = 0;
2286 signal_print[TARGET_SIGNAL_ALRM] = 0;
2287 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
2288 signal_print[TARGET_SIGNAL_VTALRM] = 0;
2289 signal_stop[TARGET_SIGNAL_PROF] = 0;
2290 signal_print[TARGET_SIGNAL_PROF] = 0;
2291 signal_stop[TARGET_SIGNAL_CHLD] = 0;
2292 signal_print[TARGET_SIGNAL_CHLD] = 0;
2293 signal_stop[TARGET_SIGNAL_IO] = 0;
2294 signal_print[TARGET_SIGNAL_IO] = 0;
2295 signal_stop[TARGET_SIGNAL_POLL] = 0;
2296 signal_print[TARGET_SIGNAL_POLL] = 0;
2297 signal_stop[TARGET_SIGNAL_URG] = 0;
2298 signal_print[TARGET_SIGNAL_URG] = 0;
2302 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
2303 (char *) &stop_on_solib_events,
2304 "Set stopping for shared library events.\n\
2305 If nonzero, gdb will give control to the user when the dynamic linker\n\
2306 notifies gdb of shared library events. The most common event of interest\n\
2307 to the user would be loading/unloading of a new library.\n",