1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996
3 Free Software Foundation, Inc.
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"
37 /* unistd.h is needed to #define X_OK */
44 /* Prototypes for local functions */
46 static void signals_info PARAMS ((char *, int));
48 static void handle_command PARAMS ((char *, int));
50 static void sig_print_info PARAMS ((enum target_signal));
52 static void sig_print_header PARAMS ((void));
54 static void resume_cleanups PARAMS ((int));
56 static int hook_stop_stub PARAMS ((char *));
58 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
59 program. It needs to examine the jmp_buf argument and extract the PC
60 from it. The return value is non-zero on success, zero otherwise. */
62 #ifndef GET_LONGJMP_TARGET
63 #define GET_LONGJMP_TARGET(PC_ADDR) 0
67 /* Some machines have trampoline code that sits between function callers
68 and the actual functions themselves. If this machine doesn't have
69 such things, disable their processing. */
71 #ifndef SKIP_TRAMPOLINE_CODE
72 #define SKIP_TRAMPOLINE_CODE(pc) 0
75 /* Dynamic function trampolines are similar to solib trampolines in that they
76 are between the caller and the callee. The difference is that when you
77 enter a dynamic trampoline, you can't determine the callee's address. Some
78 (usually complex) code needs to run in the dynamic trampoline to figure out
79 the callee's address. This macro is usually called twice. First, when we
80 enter the trampoline (looks like a normal function call at that point). It
81 should return the PC of a point within the trampoline where the callee's
82 address is known. Second, when we hit the breakpoint, this routine returns
83 the callee's address. At that point, things proceed as per a step resume
86 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
87 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
90 /* For SVR4 shared libraries, each call goes through a small piece of
91 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
92 to nonzero if we are current stopped in one of these. */
94 #ifndef IN_SOLIB_CALL_TRAMPOLINE
95 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
98 /* In some shared library schemes, the return path from a shared library
99 call may need to go through a trampoline too. */
101 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
102 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
105 /* On some systems, the PC may be left pointing at an instruction that won't
106 actually be executed. This is usually indicated by a bit in the PSW. If
107 we find ourselves in such a state, then we step the target beyond the
108 nullified instruction before returning control to the user so as to avoid
111 #ifndef INSTRUCTION_NULLIFIED
112 #define INSTRUCTION_NULLIFIED 0
115 /* Tables of how to react to signals; the user sets them. */
117 static unsigned char *signal_stop;
118 static unsigned char *signal_print;
119 static unsigned char *signal_program;
121 #define SET_SIGS(nsigs,sigs,flags) \
123 int signum = (nsigs); \
124 while (signum-- > 0) \
125 if ((sigs)[signum]) \
126 (flags)[signum] = 1; \
129 #define UNSET_SIGS(nsigs,sigs,flags) \
131 int signum = (nsigs); \
132 while (signum-- > 0) \
133 if ((sigs)[signum]) \
134 (flags)[signum] = 0; \
138 /* Command list pointer for the "stop" placeholder. */
140 static struct cmd_list_element *stop_command;
142 /* Nonzero if breakpoints are now inserted in the inferior. */
144 static int breakpoints_inserted;
146 /* Function inferior was in as of last step command. */
148 static struct symbol *step_start_function;
150 /* Nonzero if we are expecting a trace trap and should proceed from it. */
152 static int trap_expected;
154 /* Nonzero if we want to give control to the user when we're notified
155 of shared library events by the dynamic linker. */
156 static int stop_on_solib_events;
159 /* Nonzero if the next time we try to continue the inferior, it will
160 step one instruction and generate a spurious trace trap.
161 This is used to compensate for a bug in HP-UX. */
163 static int trap_expected_after_continue;
166 /* Nonzero means expecting a trace trap
167 and should stop the inferior and return silently when it happens. */
171 /* Nonzero means expecting a trap and caller will handle it themselves.
172 It is used after attach, due to attaching to a process;
173 when running in the shell before the child program has been exec'd;
174 and when running some kinds of remote stuff (FIXME?). */
176 int stop_soon_quietly;
178 /* Nonzero if proceed is being used for a "finish" command or a similar
179 situation when stop_registers should be saved. */
181 int proceed_to_finish;
183 /* Save register contents here when about to pop a stack dummy frame,
184 if-and-only-if proceed_to_finish is set.
185 Thus this contains the return value from the called function (assuming
186 values are returned in a register). */
188 char stop_registers[REGISTER_BYTES];
190 /* Nonzero if program stopped due to error trying to insert breakpoints. */
192 static int breakpoints_failed;
194 /* Nonzero after stop if current stack frame should be printed. */
196 static int stop_print_frame;
198 #ifdef NO_SINGLE_STEP
199 extern int one_stepped; /* From machine dependent code */
200 extern void single_step (); /* Same. */
201 #endif /* NO_SINGLE_STEP */
204 /* Things to clean up if we QUIT out of resume (). */
207 resume_cleanups (arg)
213 /* Resume the inferior, but allow a QUIT. This is useful if the user
214 wants to interrupt some lengthy single-stepping operation
215 (for child processes, the SIGINT goes to the inferior, and so
216 we get a SIGINT random_signal, but for remote debugging and perhaps
217 other targets, that's not true).
219 STEP nonzero if we should step (zero to continue instead).
220 SIG is the signal to give the inferior (zero for none). */
224 enum target_signal sig;
226 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
229 #ifdef CANNOT_STEP_BREAKPOINT
230 /* Most targets can step a breakpoint instruction, thus executing it
231 normally. But if this one cannot, just continue and we will hit
233 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
237 #ifdef NO_SINGLE_STEP
239 single_step(sig); /* Do it the hard way, w/temp breakpoints */
240 step = 0; /* ...and don't ask hardware to do it. */
244 /* Handle any optimized stores to the inferior NOW... */
245 #ifdef DO_DEFERRED_STORES
249 /* Install inferior's terminal modes. */
250 target_terminal_inferior ();
252 target_resume (-1, step, sig);
253 discard_cleanups (old_cleanups);
257 /* Clear out all variables saying what to do when inferior is continued.
258 First do this, then set the ones you want, then call `proceed'. */
261 clear_proceed_status ()
264 step_range_start = 0;
266 step_frame_address = 0;
267 step_over_calls = -1;
269 stop_soon_quietly = 0;
270 proceed_to_finish = 0;
271 breakpoint_proceeded = 1; /* We're about to proceed... */
273 /* Discard any remaining commands or status from previous stop. */
274 bpstat_clear (&stop_bpstat);
277 /* Basic routine for continuing the program in various fashions.
279 ADDR is the address to resume at, or -1 for resume where stopped.
280 SIGGNAL is the signal to give it, or 0 for none,
281 or -1 for act according to how it stopped.
282 STEP is nonzero if should trap after one instruction.
283 -1 means return after that and print nothing.
284 You should probably set various step_... variables
285 before calling here, if you are stepping.
287 You should call clear_proceed_status before calling proceed. */
290 proceed (addr, siggnal, step)
292 enum target_signal siggnal;
298 step_start_function = find_pc_function (read_pc ());
302 if (addr == (CORE_ADDR)-1)
304 /* If there is a breakpoint at the address we will resume at,
305 step one instruction before inserting breakpoints
306 so that we do not stop right away. */
308 if (breakpoint_here_p (read_pc ()))
311 #ifdef STEP_SKIPS_DELAY
312 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
313 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
314 is slow (it needs to read memory from the target). */
315 if (breakpoint_here_p (read_pc () + 4)
316 && STEP_SKIPS_DELAY (read_pc ()))
318 #endif /* STEP_SKIPS_DELAY */
323 #ifdef PREPARE_TO_PROCEED
324 /* In a multi-threaded task we may select another thread and then continue.
326 In this case the thread that stopped at a breakpoint will immediately
327 cause another stop, if it is not stepped over first. On the other hand,
328 if (ADDR != -1) we only want to single step over the breakpoint if we did
329 switch to another thread.
331 If we are single stepping, don't do any of the above.
332 (Note that in the current implementation single stepping another
333 thread after a breakpoint and then continuing will cause the original
334 breakpoint to be hit again, but you can always continue, so it's not
337 if (! step && PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
339 #endif /* PREPARE_TO_PROCEED */
342 if (trap_expected_after_continue)
344 /* If (step == 0), a trap will be automatically generated after
345 the first instruction is executed. Force step one
346 instruction to clear this condition. This should not occur
347 if step is nonzero, but it is harmless in that case. */
349 trap_expected_after_continue = 0;
351 #endif /* HP_OS_BUG */
354 /* We will get a trace trap after one instruction.
355 Continue it automatically and insert breakpoints then. */
359 int temp = insert_breakpoints ();
362 print_sys_errmsg ("ptrace", temp);
363 error ("Cannot insert breakpoints.\n\
364 The same program may be running in another process.");
366 breakpoints_inserted = 1;
369 if (siggnal != TARGET_SIGNAL_DEFAULT)
370 stop_signal = siggnal;
371 /* If this signal should not be seen by program,
372 give it zero. Used for debugging signals. */
373 else if (!signal_program[stop_signal])
374 stop_signal = TARGET_SIGNAL_0;
376 annotate_starting ();
378 /* Make sure that output from GDB appears before output from the
380 gdb_flush (gdb_stdout);
382 /* Resume inferior. */
383 resume (oneproc || step || bpstat_should_step (), stop_signal);
385 /* Wait for it to stop (if not standalone)
386 and in any case decode why it stopped, and act accordingly. */
388 wait_for_inferior ();
392 /* Record the pc and sp of the program the last time it stopped.
393 These are just used internally by wait_for_inferior, but need
394 to be preserved over calls to it and cleared when the inferior
396 static CORE_ADDR prev_pc;
397 static CORE_ADDR prev_func_start;
398 static char *prev_func_name;
401 /* Start remote-debugging of a machine over a serial link. */
407 init_wait_for_inferior ();
408 clear_proceed_status ();
409 stop_soon_quietly = 1;
411 wait_for_inferior ();
415 /* Initialize static vars when a new inferior begins. */
418 init_wait_for_inferior ()
420 /* These are meaningless until the first time through wait_for_inferior. */
423 prev_func_name = NULL;
426 trap_expected_after_continue = 0;
428 breakpoints_inserted = 0;
429 breakpoint_init_inferior ();
431 /* Don't confuse first call to proceed(). */
432 stop_signal = TARGET_SIGNAL_0;
436 delete_breakpoint_current_contents (arg)
439 struct breakpoint **breakpointp = (struct breakpoint **)arg;
440 if (*breakpointp != NULL)
441 delete_breakpoint (*breakpointp);
444 /* Wait for control to return from inferior to debugger.
445 If inferior gets a signal, we may decide to start it up again
446 instead of returning. That is why there is a loop in this function.
447 When this function actually returns it means the inferior
448 should be left stopped and GDB should read more commands. */
453 struct cleanup *old_cleanups;
454 struct target_waitstatus w;
457 CORE_ADDR stop_func_start;
458 CORE_ADDR stop_func_end;
459 char *stop_func_name;
460 CORE_ADDR prologue_pc = 0, tmp;
461 struct symtab_and_line sal;
462 int remove_breakpoints_on_following_step = 0;
464 struct symtab *current_symtab;
465 int handling_longjmp = 0; /* FIXME */
466 struct breakpoint *step_resume_breakpoint = NULL;
467 struct breakpoint *through_sigtramp_breakpoint = NULL;
469 int update_step_sp = 0;
471 old_cleanups = make_cleanup (delete_breakpoint_current_contents,
472 &step_resume_breakpoint);
473 make_cleanup (delete_breakpoint_current_contents,
474 &through_sigtramp_breakpoint);
475 sal = find_pc_line(prev_pc, 0);
476 current_line = sal.line;
477 current_symtab = sal.symtab;
479 /* Are we stepping? */
480 #define CURRENTLY_STEPPING() \
481 ((through_sigtramp_breakpoint == NULL \
482 && !handling_longjmp \
483 && ((step_range_end && step_resume_breakpoint == NULL) \
485 || bpstat_should_step ())
489 /* We have to invalidate the registers BEFORE calling target_wait because
490 they can be loaded from the target while in target_wait. This makes
491 remote debugging a bit more efficient for those targets that provide
492 critical registers as part of their normal status mechanism. */
494 registers_changed ();
496 if (target_wait_hook)
497 pid = target_wait_hook (-1, &w);
499 pid = target_wait (-1, &w);
501 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
505 flush_cached_frames ();
507 /* If it's a new process, add it to the thread database */
509 if (pid != inferior_pid
510 && !in_thread_list (pid))
512 fprintf_unfiltered (gdb_stderr, "[New %s]\n", target_pid_to_str (pid));
515 /* We may want to consider not doing a resume here in order to give
516 the user a chance to play with the new thread. It might be good
517 to make that a user-settable option. */
519 /* At this point, all threads are stopped (happens automatically in
520 either the OS or the native code). Therefore we need to continue
521 all threads in order to make progress. */
523 target_resume (-1, 0, TARGET_SIGNAL_0);
529 case TARGET_WAITKIND_LOADED:
530 /* Ignore it gracefully. */
531 if (breakpoints_inserted)
533 mark_breakpoints_out ();
534 insert_breakpoints ();
536 resume (0, TARGET_SIGNAL_0);
539 case TARGET_WAITKIND_SPURIOUS:
540 resume (0, TARGET_SIGNAL_0);
543 case TARGET_WAITKIND_EXITED:
544 target_terminal_ours (); /* Must do this before mourn anyway */
545 annotate_exited (w.value.integer);
547 printf_filtered ("\nProgram exited with code 0%o.\n",
548 (unsigned int)w.value.integer);
550 printf_filtered ("\nProgram exited normally.\n");
552 /* Record the exit code in the convenience variable $_exitcode, so
553 that the user can inspect this again later. */
554 set_internalvar (lookup_internalvar ("_exitcode"),
555 value_from_longest (builtin_type_int,
556 (LONGEST) w.value.integer));
557 gdb_flush (gdb_stdout);
558 target_mourn_inferior ();
559 #ifdef NO_SINGLE_STEP
562 stop_print_frame = 0;
565 case TARGET_WAITKIND_SIGNALLED:
566 stop_print_frame = 0;
567 stop_signal = w.value.sig;
568 target_terminal_ours (); /* Must do this before mourn anyway */
569 annotate_signalled ();
571 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
572 mean it is already dead? This has been here since GDB 2.8, so
573 perhaps it means rms didn't understand unix waitstatuses?
574 For the moment I'm just kludging around this in remote.c
575 rather than trying to change it here --kingdon, 5 Dec 1994. */
576 target_kill (); /* kill mourns as well */
578 printf_filtered ("\nProgram terminated with signal ");
579 annotate_signal_name ();
580 printf_filtered ("%s", target_signal_to_name (stop_signal));
581 annotate_signal_name_end ();
582 printf_filtered (", ");
583 annotate_signal_string ();
584 printf_filtered ("%s", target_signal_to_string (stop_signal));
585 annotate_signal_string_end ();
586 printf_filtered (".\n");
588 printf_filtered ("The program no longer exists.\n");
589 gdb_flush (gdb_stdout);
590 #ifdef NO_SINGLE_STEP
595 case TARGET_WAITKIND_STOPPED:
596 /* This is the only case in which we keep going; the above cases
597 end in a continue or goto. */
601 stop_signal = w.value.sig;
603 stop_pc = read_pc_pid (pid);
605 /* See if a thread hit a thread-specific breakpoint that was meant for
606 another thread. If so, then step that thread past the breakpoint,
609 if (stop_signal == TARGET_SIGNAL_TRAP
610 && breakpoints_inserted
611 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
614 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, pid))
616 /* Saw a breakpoint, but it was hit by the wrong thread. Just continue. */
617 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, pid);
619 remove_breakpoints ();
620 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
621 /* FIXME: What if a signal arrives instead of the single-step
624 if (target_wait_hook)
625 target_wait_hook (pid, &w);
627 target_wait (pid, &w);
628 insert_breakpoints ();
630 /* We need to restart all the threads now. */
631 target_resume (-1, 0, TARGET_SIGNAL_0);
638 /* See if something interesting happened to the non-current thread. If
639 so, then switch to that thread, and eventually give control back to
642 if (pid != inferior_pid)
646 /* If it's a random signal for a non-current thread, notify user
647 if he's expressed an interest. */
650 && signal_print[stop_signal])
653 target_terminal_ours_for_output ();
654 printf_filtered ("\nProgram received signal %s, %s.\n",
655 target_signal_to_name (stop_signal),
656 target_signal_to_string (stop_signal));
657 gdb_flush (gdb_stdout);
660 /* If it's not SIGTRAP and not a signal we want to stop for, then
661 continue the thread. */
663 if (stop_signal != TARGET_SIGNAL_TRAP
664 && !signal_stop[stop_signal])
667 target_terminal_inferior ();
669 /* Clear the signal if it should not be passed. */
670 if (signal_program[stop_signal] == 0)
671 stop_signal = TARGET_SIGNAL_0;
673 target_resume (pid, 0, stop_signal);
677 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
678 and fall into the rest of wait_for_inferior(). */
680 /* Save infrun state for the old thread. */
681 save_infrun_state (inferior_pid, prev_pc,
682 prev_func_start, prev_func_name,
683 trap_expected, step_resume_breakpoint,
684 through_sigtramp_breakpoint,
685 step_range_start, step_range_end,
686 step_frame_address, handling_longjmp,
691 /* Load infrun state for the new thread. */
692 load_infrun_state (inferior_pid, &prev_pc,
693 &prev_func_start, &prev_func_name,
694 &trap_expected, &step_resume_breakpoint,
695 &through_sigtramp_breakpoint,
696 &step_range_start, &step_range_end,
697 &step_frame_address, &handling_longjmp,
699 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid));
701 flush_cached_frames ();
704 #ifdef NO_SINGLE_STEP
706 single_step (0); /* This actually cleans up the ss */
707 #endif /* NO_SINGLE_STEP */
709 /* If PC is pointing at a nullified instruction, then step beyond
710 it so that the user won't be confused when GDB appears to be ready
713 if (INSTRUCTION_NULLIFIED)
719 #ifdef HAVE_STEPPABLE_WATCHPOINT
720 /* It may not be necessary to disable the watchpoint to stop over
721 it. For example, the PA can (with some kernel cooperation)
722 single step over a watchpoint without disabling the watchpoint. */
723 if (STOPPED_BY_WATCHPOINT (w))
730 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
731 /* It is far more common to need to disable a watchpoint
732 to step the inferior over it. FIXME. What else might
733 a debug register or page protection watchpoint scheme need
735 if (STOPPED_BY_WATCHPOINT (w))
737 /* At this point, we are stopped at an instruction which has attempted to write
738 to a piece of memory under control of a watchpoint. The instruction hasn't
739 actually executed yet. If we were to evaluate the watchpoint expression
740 now, we would get the old value, and therefore no change would seem to have
743 In order to make watchpoints work `right', we really need to complete the
744 memory write, and then evaluate the watchpoint expression. The following
745 code does that by removing the watchpoint (actually, all watchpoints and
746 breakpoints), single-stepping the target, re-inserting watchpoints, and then
747 falling through to let normal single-step processing handle proceed. Since
748 this includes evaluating watchpoints, things will come to a stop in the
751 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
753 remove_breakpoints ();
754 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
756 if (target_wait_hook)
757 target_wait_hook (pid, &w);
759 target_wait (pid, &w);
760 insert_breakpoints ();
761 /* FIXME-maybe: is this cleaner than setting a flag? Does it
762 handle things like signals arriving and other things happening
763 in combination correctly? */
768 #ifdef HAVE_CONTINUABLE_WATCHPOINT
769 /* It may be possible to simply continue after a watchpoint. */
770 STOPPED_BY_WATCHPOINT (w);
775 /* Don't care about return value; stop_func_start and stop_func_name
776 will both be 0 if it doesn't work. */
777 find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start,
779 stop_func_start += FUNCTION_START_OFFSET;
781 bpstat_clear (&stop_bpstat);
783 stop_stack_dummy = 0;
784 stop_print_frame = 1;
786 stopped_by_random_signal = 0;
787 breakpoints_failed = 0;
789 /* Look at the cause of the stop, and decide what to do.
790 The alternatives are:
791 1) break; to really stop and return to the debugger,
792 2) drop through to start up again
793 (set another_trap to 1 to single step once)
794 3) set random_signal to 1, and the decision between 1 and 2
795 will be made according to the signal handling tables. */
797 /* First, distinguish signals caused by the debugger from signals
798 that have to do with the program's own actions.
799 Note that breakpoint insns may cause SIGTRAP or SIGILL
800 or SIGEMT, depending on the operating system version.
801 Here we detect when a SIGILL or SIGEMT is really a breakpoint
802 and change it to SIGTRAP. */
804 if (stop_signal == TARGET_SIGNAL_TRAP
805 || (breakpoints_inserted &&
806 (stop_signal == TARGET_SIGNAL_ILL
807 || stop_signal == TARGET_SIGNAL_EMT
809 || stop_soon_quietly)
811 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
813 stop_print_frame = 0;
816 if (stop_soon_quietly)
819 /* Don't even think about breakpoints
820 if just proceeded over a breakpoint.
822 However, if we are trying to proceed over a breakpoint
823 and end up in sigtramp, then through_sigtramp_breakpoint
824 will be set and we should check whether we've hit the
826 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
827 && through_sigtramp_breakpoint == NULL)
828 bpstat_clear (&stop_bpstat);
831 /* See if there is a breakpoint at the current PC. */
832 stop_bpstat = bpstat_stop_status
834 #if DECR_PC_AFTER_BREAK
835 /* Notice the case of stepping through a jump
836 that lands just after a breakpoint.
837 Don't confuse that with hitting the breakpoint.
838 What we check for is that 1) stepping is going on
839 and 2) the pc before the last insn does not match
840 the address of the breakpoint before the current pc. */
841 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
842 && CURRENTLY_STEPPING ())
843 #else /* DECR_PC_AFTER_BREAK zero */
845 #endif /* DECR_PC_AFTER_BREAK zero */
847 /* Following in case break condition called a
849 stop_print_frame = 1;
852 if (stop_signal == TARGET_SIGNAL_TRAP)
854 = !(bpstat_explains_signal (stop_bpstat)
856 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
857 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
858 FRAME_FP (get_current_frame ()))
859 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
860 || (step_range_end && step_resume_breakpoint == NULL));
864 = !(bpstat_explains_signal (stop_bpstat)
865 /* End of a stack dummy. Some systems (e.g. Sony
866 news) give another signal besides SIGTRAP,
867 so check here as well as above. */
868 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
869 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
870 FRAME_FP (get_current_frame ()))
871 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
874 stop_signal = TARGET_SIGNAL_TRAP;
880 /* For the program's own signals, act according to
881 the signal handling tables. */
885 /* Signal not for debugging purposes. */
888 stopped_by_random_signal = 1;
890 if (signal_print[stop_signal])
893 target_terminal_ours_for_output ();
895 printf_filtered ("\nProgram received signal ");
896 annotate_signal_name ();
897 printf_filtered ("%s", target_signal_to_name (stop_signal));
898 annotate_signal_name_end ();
899 printf_filtered (", ");
900 annotate_signal_string ();
901 printf_filtered ("%s", target_signal_to_string (stop_signal));
902 annotate_signal_string_end ();
903 printf_filtered (".\n");
904 gdb_flush (gdb_stdout);
906 if (signal_stop[stop_signal])
908 /* If not going to stop, give terminal back
909 if we took it away. */
911 target_terminal_inferior ();
913 /* Clear the signal if it should not be passed. */
914 if (signal_program[stop_signal] == 0)
915 stop_signal = TARGET_SIGNAL_0;
917 /* I'm not sure whether this needs to be check_sigtramp2 or
918 whether it could/should be keep_going. */
919 goto check_sigtramp2;
922 /* Handle cases caused by hitting a breakpoint. */
924 CORE_ADDR jmp_buf_pc;
925 struct bpstat_what what;
927 what = bpstat_what (stop_bpstat);
931 stop_stack_dummy = 1;
933 trap_expected_after_continue = 1;
937 switch (what.main_action)
939 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
940 /* If we hit the breakpoint at longjmp, disable it for the
941 duration of this command. Then, install a temporary
942 breakpoint at the target of the jmp_buf. */
943 disable_longjmp_breakpoint();
944 remove_breakpoints ();
945 breakpoints_inserted = 0;
946 if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
948 /* Need to blow away step-resume breakpoint, as it
949 interferes with us */
950 if (step_resume_breakpoint != NULL)
952 delete_breakpoint (step_resume_breakpoint);
953 step_resume_breakpoint = NULL;
955 /* Not sure whether we need to blow this away too, but probably
956 it is like the step-resume breakpoint. */
957 if (through_sigtramp_breakpoint != NULL)
959 delete_breakpoint (through_sigtramp_breakpoint);
960 through_sigtramp_breakpoint = NULL;
964 /* FIXME - Need to implement nested temporary breakpoints */
965 if (step_over_calls > 0)
966 set_longjmp_resume_breakpoint(jmp_buf_pc,
967 get_current_frame());
970 set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
971 handling_longjmp = 1; /* FIXME */
974 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
975 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
976 remove_breakpoints ();
977 breakpoints_inserted = 0;
979 /* FIXME - Need to implement nested temporary breakpoints */
981 && (FRAME_FP (get_current_frame ())
982 INNER_THAN step_frame_address))
988 disable_longjmp_breakpoint();
989 handling_longjmp = 0; /* FIXME */
990 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
992 /* else fallthrough */
994 case BPSTAT_WHAT_SINGLE:
995 if (breakpoints_inserted)
996 remove_breakpoints ();
997 breakpoints_inserted = 0;
999 /* Still need to check other stuff, at least the case
1000 where we are stepping and step out of the right range. */
1003 case BPSTAT_WHAT_STOP_NOISY:
1004 stop_print_frame = 1;
1006 /* We are about to nuke the step_resume_breakpoint and
1007 through_sigtramp_breakpoint via the cleanup chain, so
1008 no need to worry about it here. */
1012 case BPSTAT_WHAT_STOP_SILENT:
1013 stop_print_frame = 0;
1015 /* We are about to nuke the step_resume_breakpoint and
1016 through_sigtramp_breakpoint via the cleanup chain, so
1017 no need to worry about it here. */
1021 case BPSTAT_WHAT_STEP_RESUME:
1022 delete_breakpoint (step_resume_breakpoint);
1023 step_resume_breakpoint = NULL;
1026 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
1027 if (through_sigtramp_breakpoint)
1028 delete_breakpoint (through_sigtramp_breakpoint);
1029 through_sigtramp_breakpoint = NULL;
1031 /* If were waiting for a trap, hitting the step_resume_break
1032 doesn't count as getting it. */
1038 case BPSTAT_WHAT_CHECK_SHLIBS:
1040 extern int auto_solib_add;
1042 /* Check for any newly added shared libraries if we're
1043 supposed to be adding them automatically. */
1046 /* Remove breakpoints, SOLIB_ADD might adjust breakpoint
1047 addresses via breakpoint_re_set. */
1048 if (breakpoints_inserted)
1049 remove_breakpoints ();
1050 breakpoints_inserted = 0;
1052 /* Switch terminal for any messages produced by
1053 breakpoint_re_set. */
1054 target_terminal_ours_for_output ();
1055 SOLIB_ADD (NULL, 0, NULL);
1056 target_terminal_inferior ();
1059 /* If requested, stop when the dynamic linker notifies
1060 gdb of events. This allows the user to get control
1061 and place breakpoints in initializer routines for
1062 dynamically loaded objects (among other things). */
1063 if (stop_on_solib_events)
1065 stop_print_frame = 0;
1070 /* We want to step over this breakpoint, then keep going. */
1072 remove_breakpoints_on_following_step = 1;
1078 case BPSTAT_WHAT_LAST:
1079 /* Not a real code, but listed here to shut up gcc -Wall. */
1081 case BPSTAT_WHAT_KEEP_CHECKING:
1086 /* We come here if we hit a breakpoint but should not
1087 stop for it. Possibly we also were stepping
1088 and should stop for that. So fall through and
1089 test for stepping. But, if not stepping,
1092 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1093 /* This is the old way of detecting the end of the stack dummy.
1094 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
1095 handled above. As soon as we can test it on all of them, all
1096 architectures should define it. */
1098 /* If this is the breakpoint at the end of a stack dummy,
1099 just stop silently, unless the user was doing an si/ni, in which
1100 case she'd better know what she's doing. */
1102 if (PC_IN_CALL_DUMMY (stop_pc, read_sp (), FRAME_FP (get_current_frame ()))
1105 stop_print_frame = 0;
1106 stop_stack_dummy = 1;
1108 trap_expected_after_continue = 1;
1112 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1114 if (step_resume_breakpoint)
1115 /* Having a step-resume breakpoint overrides anything
1116 else having to do with stepping commands until
1117 that breakpoint is reached. */
1118 /* I'm not sure whether this needs to be check_sigtramp2 or
1119 whether it could/should be keep_going. */
1120 goto check_sigtramp2;
1122 if (step_range_end == 0)
1123 /* Likewise if we aren't even stepping. */
1124 /* I'm not sure whether this needs to be check_sigtramp2 or
1125 whether it could/should be keep_going. */
1126 goto check_sigtramp2;
1128 /* If stepping through a line, keep going if still within it. */
1129 if (stop_pc >= step_range_start
1130 && stop_pc < step_range_end
1132 /* I haven't a clue what might trigger this clause, and it seems wrong anyway,
1133 so I've disabled it until someone complains. -Stu 10/24/95 */
1135 /* The step range might include the start of the
1136 function, so if we are at the start of the
1137 step range and either the stack or frame pointers
1138 just changed, we've stepped outside */
1139 && !(stop_pc == step_range_start
1140 && FRAME_FP (get_current_frame ())
1141 && (read_sp () INNER_THAN step_sp
1142 || FRAME_FP (get_current_frame ()) != step_frame_address))
1146 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
1147 So definately need to check for sigtramp here. */
1148 goto check_sigtramp2;
1151 /* We stepped out of the stepping range. */
1153 /* We can't update step_sp every time through the loop, because
1154 reading the stack pointer would slow down stepping too much.
1155 But we can update it every time we leave the step range. */
1158 /* Did we just take a signal? */
1159 if (IN_SIGTRAMP (stop_pc, stop_func_name)
1160 && !IN_SIGTRAMP (prev_pc, prev_func_name))
1162 /* We've just taken a signal; go until we are back to
1163 the point where we took it and one more. */
1165 /* This code is needed at least in the following case:
1166 The user types "next" and then a signal arrives (before
1167 the "next" is done). */
1169 /* Note that if we are stopped at a breakpoint, then we need
1170 the step_resume breakpoint to override any breakpoints at
1171 the same location, so that we will still step over the
1172 breakpoint even though the signal happened. */
1175 struct symtab_and_line sr_sal;
1177 sr_sal.pc = prev_pc;
1178 sr_sal.symtab = NULL;
1180 /* We could probably be setting the frame to
1181 step_frame_address; I don't think anyone thought to try it. */
1182 step_resume_breakpoint =
1183 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1184 if (breakpoints_inserted)
1185 insert_breakpoints ();
1188 /* If this is stepi or nexti, make sure that the stepping range
1189 gets us past that instruction. */
1190 if (step_range_end == 1)
1191 /* FIXME: Does this run afoul of the code below which, if
1192 we step into the middle of a line, resets the stepping
1194 step_range_end = (step_range_start = prev_pc) + 1;
1196 remove_breakpoints_on_following_step = 1;
1201 /* I disabled this test because it was too complicated and slow. The
1202 SKIP_PROLOGUE was especially slow, because it caused unnecessary
1203 prologue examination on various architectures. The code in the #else
1204 clause has been tested on the Sparc, Mips, PA, and Power
1205 architectures, so it's pretty likely to be correct. -Stu 10/24/95 */
1207 /* See if we left the step range due to a subroutine call that
1208 we should proceed to the end of. */
1210 if (stop_func_start)
1214 /* Do this after the IN_SIGTRAMP check; it might give
1216 prologue_pc = stop_func_start;
1218 /* Don't skip the prologue if this is assembly source */
1219 s = find_pc_symtab (stop_pc);
1220 if (s && s->language != language_asm)
1221 SKIP_PROLOGUE (prologue_pc);
1224 if ((/* Might be a non-recursive call. If the symbols are missing
1225 enough that stop_func_start == prev_func_start even though
1226 they are really two functions, we will treat some calls as
1228 stop_func_start != prev_func_start
1230 /* Might be a recursive call if either we have a prologue
1231 or the call instruction itself saves the PC on the stack. */
1232 || prologue_pc != stop_func_start
1233 || read_sp () != step_sp)
1234 && (/* PC is completely out of bounds of any known objfiles. Treat
1235 like a subroutine call. */
1238 /* If we do a call, we will be at the start of a function... */
1239 || stop_pc == stop_func_start
1241 /* ...except on the Alpha with -O (and also Irix 5 and
1242 perhaps others), in which we might call the address
1243 after the load of gp. Since prologues don't contain
1244 calls, we can't return to within one, and we don't
1245 jump back into them, so this check is OK. */
1247 || stop_pc < prologue_pc
1249 /* ...and if it is a leaf function, the prologue might
1250 consist of gp loading only, so the call transfers to
1251 the first instruction after the prologue. */
1252 || (stop_pc == prologue_pc
1254 /* Distinguish this from the case where we jump back
1255 to the first instruction after the prologue,
1256 within a function. */
1257 && stop_func_start != prev_func_start)
1259 /* If we end up in certain places, it means we did a subroutine
1260 call. I'm not completely sure this is necessary now that we
1261 have the above checks with stop_func_start (and now that
1262 find_pc_partial_function is pickier). */
1263 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
1265 /* If none of the above apply, it is a jump within a function,
1266 or a return from a subroutine. The other case is longjmp,
1267 which can no longer happen here as long as the
1268 handling_longjmp stuff is working. */
1271 /* This test is a much more streamlined, (but hopefully correct)
1272 replacement for the code above. It's been tested on the Sparc,
1273 Mips, PA, and Power architectures with good results. */
1275 if (stop_pc == stop_func_start /* Quick test */
1276 || in_prologue (stop_pc, stop_func_start)
1277 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
1278 || stop_func_start == 0)
1282 /* It's a subroutine call. */
1284 if (step_over_calls == 0)
1286 /* I presume that step_over_calls is only 0 when we're
1287 supposed to be stepping at the assembly language level
1288 ("stepi"). Just stop. */
1293 if (step_over_calls > 0)
1294 /* We're doing a "next". */
1295 goto step_over_function;
1297 /* If we are in a function call trampoline (a stub between
1298 the calling routine and the real function), locate the real
1299 function. That's what tells us (a) whether we want to step
1300 into it at all, and (b) what prologue we want to run to
1301 the end of, if we do step into it. */
1302 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1304 stop_func_start = tmp;
1307 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
1310 struct symtab_and_line xxx;
1315 step_resume_breakpoint =
1316 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
1317 insert_breakpoints ();
1322 /* If we have line number information for the function we
1323 are thinking of stepping into, step into it.
1325 If there are several symtabs at that PC (e.g. with include
1326 files), just want to know whether *any* of them have line
1327 numbers. find_pc_line handles this. */
1329 struct symtab_and_line tmp_sal;
1331 tmp_sal = find_pc_line (stop_func_start, 0);
1332 if (tmp_sal.line != 0)
1333 goto step_into_function;
1337 /* A subroutine call has happened. */
1339 /* Set a special breakpoint after the return */
1340 struct symtab_and_line sr_sal;
1343 (SAVED_PC_AFTER_CALL (get_current_frame ()));
1344 sr_sal.symtab = NULL;
1346 step_resume_breakpoint =
1347 set_momentary_breakpoint (sr_sal, get_current_frame (),
1349 step_resume_breakpoint->frame = step_frame_address;
1350 if (breakpoints_inserted)
1351 insert_breakpoints ();
1356 /* Subroutine call with source code we should not step over.
1357 Do step to the first line of code in it. */
1361 s = find_pc_symtab (stop_pc);
1362 if (s && s->language != language_asm)
1363 SKIP_PROLOGUE (stop_func_start);
1365 sal = find_pc_line (stop_func_start, 0);
1366 /* Use the step_resume_break to step until
1367 the end of the prologue, even if that involves jumps
1368 (as it seems to on the vax under 4.2). */
1369 /* If the prologue ends in the middle of a source line,
1370 continue to the end of that source line (if it is still
1371 within the function). Otherwise, just go to end of prologue. */
1372 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1373 /* no, don't either. It skips any code that's
1374 legitimately on the first line. */
1376 if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end)
1377 stop_func_start = sal.end;
1380 if (stop_func_start == stop_pc)
1382 /* We are already there: stop now. */
1387 /* Put the step-breakpoint there and go until there. */
1389 struct symtab_and_line sr_sal;
1391 sr_sal.pc = stop_func_start;
1392 sr_sal.symtab = NULL;
1394 /* Do not specify what the fp should be when we stop
1395 since on some machines the prologue
1396 is where the new fp value is established. */
1397 step_resume_breakpoint =
1398 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1399 if (breakpoints_inserted)
1400 insert_breakpoints ();
1402 /* And make sure stepping stops right away then. */
1403 step_range_end = step_range_start;
1408 /* We've wandered out of the step range. */
1410 sal = find_pc_line(stop_pc, 0);
1412 if (step_range_end == 1)
1414 /* It is stepi or nexti. We always want to stop stepping after
1420 /* If we're in the return path from a shared library trampoline,
1421 we want to proceed through the trampoline when stepping. */
1422 if (IN_SOLIB_RETURN_TRAMPOLINE(stop_pc, stop_func_name))
1426 /* Determine where this trampoline returns. */
1427 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1429 /* Only proceed through if we know where it's going. */
1432 /* And put the step-breakpoint there and go until there. */
1433 struct symtab_and_line sr_sal;
1436 sr_sal.symtab = NULL;
1438 /* Do not specify what the fp should be when we stop
1439 since on some machines the prologue
1440 is where the new fp value is established. */
1441 step_resume_breakpoint =
1442 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1443 if (breakpoints_inserted)
1444 insert_breakpoints ();
1446 /* Restart without fiddling with the step ranges or
1454 /* We have no line number information. That means to stop
1455 stepping (does this always happen right after one instruction,
1456 when we do "s" in a function with no line numbers,
1457 or can this happen as a result of a return or longjmp?). */
1462 if (stop_pc == sal.pc
1463 && (current_line != sal.line || current_symtab != sal.symtab))
1465 /* We are at the start of a different line. So stop. Note that
1466 we don't stop if we step into the middle of a different line.
1467 That is said to make things like for (;;) statements work
1473 /* We aren't done stepping.
1475 Optimize by setting the stepping range to the line.
1476 (We might not be in the original line, but if we entered a
1477 new line in mid-statement, we continue stepping. This makes
1478 things like for(;;) statements work better.) */
1480 if (stop_func_end && sal.end >= stop_func_end)
1482 /* If this is the last line of the function, don't keep stepping
1483 (it would probably step us out of the function).
1484 This is particularly necessary for a one-line function,
1485 in which after skipping the prologue we better stop even though
1486 we will be in mid-line. */
1490 step_range_start = sal.pc;
1491 step_range_end = sal.end;
1496 && IN_SIGTRAMP (stop_pc, stop_func_name)
1497 && !IN_SIGTRAMP (prev_pc, prev_func_name))
1499 /* What has happened here is that we have just stepped the inferior
1500 with a signal (because it is a signal which shouldn't make
1501 us stop), thus stepping into sigtramp.
1503 So we need to set a step_resume_break_address breakpoint
1504 and continue until we hit it, and then step. FIXME: This should
1505 be more enduring than a step_resume breakpoint; we should know
1506 that we will later need to keep going rather than re-hitting
1507 the breakpoint here (see testsuite/gdb.t06/signals.exp where
1508 it says "exceedingly difficult"). */
1509 struct symtab_and_line sr_sal;
1511 sr_sal.pc = prev_pc;
1512 sr_sal.symtab = NULL;
1514 /* We perhaps could set the frame if we kept track of what
1515 the frame corresponding to prev_pc was. But we don't,
1517 through_sigtramp_breakpoint =
1518 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
1519 if (breakpoints_inserted)
1520 insert_breakpoints ();
1522 remove_breakpoints_on_following_step = 1;
1527 /* Come to this label when you need to resume the inferior.
1528 It's really much cleaner to do a goto than a maze of if-else
1531 /* Save the pc before execution, to compare with pc after stop. */
1532 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
1533 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
1534 BREAK is defined, the
1535 original pc would not have
1536 been at the start of a
1538 prev_func_name = stop_func_name;
1541 step_sp = read_sp ();
1544 /* If we did not do break;, it means we should keep
1545 running the inferior and not return to debugger. */
1547 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
1549 /* We took a signal (which we are supposed to pass through to
1550 the inferior, else we'd have done a break above) and we
1551 haven't yet gotten our trap. Simply continue. */
1552 resume (CURRENTLY_STEPPING (), stop_signal);
1556 /* Either the trap was not expected, but we are continuing
1557 anyway (the user asked that this signal be passed to the
1560 The signal was SIGTRAP, e.g. it was our signal, but we
1561 decided we should resume from it.
1563 We're going to run this baby now!
1565 Insert breakpoints now, unless we are trying
1566 to one-proceed past a breakpoint. */
1567 /* If we've just finished a special step resume and we don't
1568 want to hit a breakpoint, pull em out. */
1569 if (step_resume_breakpoint == NULL
1570 && through_sigtramp_breakpoint == NULL
1571 && remove_breakpoints_on_following_step)
1573 remove_breakpoints_on_following_step = 0;
1574 remove_breakpoints ();
1575 breakpoints_inserted = 0;
1577 else if (!breakpoints_inserted &&
1578 (through_sigtramp_breakpoint != NULL || !another_trap))
1580 breakpoints_failed = insert_breakpoints ();
1581 if (breakpoints_failed)
1583 breakpoints_inserted = 1;
1586 trap_expected = another_trap;
1588 if (stop_signal == TARGET_SIGNAL_TRAP)
1589 stop_signal = TARGET_SIGNAL_0;
1591 #ifdef SHIFT_INST_REGS
1592 /* I'm not sure when this following segment applies. I do know, now,
1593 that we shouldn't rewrite the regs when we were stopped by a
1594 random signal from the inferior process. */
1595 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
1596 (this is only used on the 88k). */
1598 if (!bpstat_explains_signal (stop_bpstat)
1599 && (stop_signal != TARGET_SIGNAL_CHLD)
1600 && !stopped_by_random_signal)
1602 #endif /* SHIFT_INST_REGS */
1604 resume (CURRENTLY_STEPPING (), stop_signal);
1609 if (target_has_execution)
1611 /* Assuming the inferior still exists, set these up for next
1612 time, just like we did above if we didn't break out of the
1614 prev_pc = read_pc ();
1615 prev_func_start = stop_func_start;
1616 prev_func_name = stop_func_name;
1618 do_cleanups (old_cleanups);
1621 /* Here to return control to GDB when the inferior stops for real.
1622 Print appropriate messages, remove breakpoints, give terminal our modes.
1624 STOP_PRINT_FRAME nonzero means print the executing frame
1625 (pc, function, args, file, line number and line text).
1626 BREAKPOINTS_FAILED nonzero means stop was due to error
1627 attempting to insert breakpoints. */
1632 /* Make sure that the current_frame's pc is correct. This
1633 is a correction for setting up the frame info before doing
1634 DECR_PC_AFTER_BREAK */
1635 if (target_has_execution && get_current_frame())
1636 (get_current_frame ())->pc = read_pc ();
1638 if (breakpoints_failed)
1640 target_terminal_ours_for_output ();
1641 print_sys_errmsg ("ptrace", breakpoints_failed);
1642 printf_filtered ("Stopped; cannot insert breakpoints.\n\
1643 The same program may be running in another process.\n");
1646 if (target_has_execution && breakpoints_inserted)
1647 if (remove_breakpoints ())
1649 target_terminal_ours_for_output ();
1650 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
1651 It might be running in another process.\n\
1652 Further execution is probably impossible.\n");
1655 breakpoints_inserted = 0;
1657 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1658 Delete any breakpoint that is to be deleted at the next stop. */
1660 breakpoint_auto_delete (stop_bpstat);
1662 /* If an auto-display called a function and that got a signal,
1663 delete that auto-display to avoid an infinite recursion. */
1665 if (stopped_by_random_signal)
1666 disable_current_display ();
1668 if (step_multi && stop_step)
1671 target_terminal_ours ();
1674 && stop_bpstat->breakpoint_at
1675 && stop_bpstat->breakpoint_at->type == bp_shlib_event)
1676 printf_filtered ("Stopped due to shared library event\n");
1678 /* Look up the hook_stop and run it if it exists. */
1680 if (stop_command->hook)
1682 catch_errors (hook_stop_stub, (char *)stop_command->hook,
1683 "Error while running hook_stop:\n", RETURN_MASK_ALL);
1686 if (!target_has_stack)
1689 /* Select innermost stack frame except on return from a stack dummy routine,
1690 or if the program has exited. Print it without a level number if
1691 we have changed functions or hit a breakpoint. Print source line
1693 if (!stop_stack_dummy)
1695 select_frame (get_current_frame (), 0);
1697 if (stop_print_frame)
1701 source_only = bpstat_print (stop_bpstat);
1702 source_only = source_only ||
1704 && step_frame_address == FRAME_FP (get_current_frame ())
1705 && step_start_function == find_pc_function (stop_pc));
1707 print_stack_frame (selected_frame, -1, source_only? -1: 1);
1709 /* Display the auto-display expressions. */
1714 /* Save the function value return registers, if we care.
1715 We might be about to restore their previous contents. */
1716 if (proceed_to_finish)
1717 read_register_bytes (0, stop_registers, REGISTER_BYTES);
1719 if (stop_stack_dummy)
1721 /* Pop the empty frame that contains the stack dummy.
1722 POP_FRAME ends with a setting of the current frame, so we
1723 can use that next. */
1725 /* Set stop_pc to what it was before we called the function. Can't rely
1726 on restore_inferior_status because that only gets called if we don't
1727 stop in the called function. */
1728 stop_pc = read_pc();
1729 select_frame (get_current_frame (), 0);
1732 annotate_stopped ();
1736 hook_stop_stub (cmd)
1739 execute_user_command ((struct cmd_list_element *)cmd, 0);
1743 int signal_stop_state (signo)
1746 return signal_stop[signo];
1749 int signal_print_state (signo)
1752 return signal_print[signo];
1755 int signal_pass_state (signo)
1758 return signal_program[signo];
1765 Signal Stop\tPrint\tPass to program\tDescription\n");
1769 sig_print_info (oursig)
1770 enum target_signal oursig;
1772 char *name = target_signal_to_name (oursig);
1773 printf_filtered ("%s", name);
1774 printf_filtered ("%*.*s ", 13 - strlen (name), 13 - strlen (name),
1776 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
1777 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
1778 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
1779 printf_filtered ("%s\n", target_signal_to_string (oursig));
1782 /* Specify how various signals in the inferior should be handled. */
1785 handle_command (args, from_tty)
1790 int digits, wordlen;
1791 int sigfirst, signum, siglast;
1792 enum target_signal oursig;
1795 unsigned char *sigs;
1796 struct cleanup *old_chain;
1800 error_no_arg ("signal to handle");
1803 /* Allocate and zero an array of flags for which signals to handle. */
1805 nsigs = (int)TARGET_SIGNAL_LAST;
1806 sigs = (unsigned char *) alloca (nsigs);
1807 memset (sigs, 0, nsigs);
1809 /* Break the command line up into args. */
1811 argv = buildargv (args);
1816 old_chain = make_cleanup (freeargv, (char *) argv);
1818 /* Walk through the args, looking for signal oursigs, signal names, and
1819 actions. Signal numbers and signal names may be interspersed with
1820 actions, with the actions being performed for all signals cumulatively
1821 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
1823 while (*argv != NULL)
1825 wordlen = strlen (*argv);
1826 for (digits = 0; isdigit ((*argv)[digits]); digits++) {;}
1828 sigfirst = siglast = -1;
1830 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
1832 /* Apply action to all signals except those used by the
1833 debugger. Silently skip those. */
1836 siglast = nsigs - 1;
1838 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
1840 SET_SIGS (nsigs, sigs, signal_stop);
1841 SET_SIGS (nsigs, sigs, signal_print);
1843 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
1845 UNSET_SIGS (nsigs, sigs, signal_program);
1847 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
1849 SET_SIGS (nsigs, sigs, signal_print);
1851 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
1853 SET_SIGS (nsigs, sigs, signal_program);
1855 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
1857 UNSET_SIGS (nsigs, sigs, signal_stop);
1859 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
1861 SET_SIGS (nsigs, sigs, signal_program);
1863 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
1865 UNSET_SIGS (nsigs, sigs, signal_print);
1866 UNSET_SIGS (nsigs, sigs, signal_stop);
1868 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
1870 UNSET_SIGS (nsigs, sigs, signal_program);
1872 else if (digits > 0)
1874 /* It is numeric. The numeric signal refers to our own internal
1875 signal numbering from target.h, not to host/target signal number.
1876 This is a feature; users really should be using symbolic names
1877 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
1878 will work right anyway. */
1880 sigfirst = siglast = (int) target_signal_from_command (atoi (*argv));
1881 if ((*argv)[digits] == '-')
1884 (int) target_signal_from_command (atoi ((*argv) + digits + 1));
1886 if (sigfirst > siglast)
1888 /* Bet he didn't figure we'd think of this case... */
1896 oursig = target_signal_from_name (*argv);
1897 if (oursig != TARGET_SIGNAL_UNKNOWN)
1899 sigfirst = siglast = (int)oursig;
1903 /* Not a number and not a recognized flag word => complain. */
1904 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
1908 /* If any signal numbers or symbol names were found, set flags for
1909 which signals to apply actions to. */
1911 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
1913 switch ((enum target_signal)signum)
1915 case TARGET_SIGNAL_TRAP:
1916 case TARGET_SIGNAL_INT:
1917 if (!allsigs && !sigs[signum])
1919 if (query ("%s is used by the debugger.\n\
1920 Are you sure you want to change it? ",
1921 target_signal_to_name
1922 ((enum target_signal)signum)))
1928 printf_unfiltered ("Not confirmed, unchanged.\n");
1929 gdb_flush (gdb_stdout);
1933 case TARGET_SIGNAL_0:
1934 case TARGET_SIGNAL_DEFAULT:
1935 case TARGET_SIGNAL_UNKNOWN:
1936 /* Make sure that "all" doesn't print these. */
1947 target_notice_signals(inferior_pid);
1951 /* Show the results. */
1952 sig_print_header ();
1953 for (signum = 0; signum < nsigs; signum++)
1957 sig_print_info (signum);
1962 do_cleanups (old_chain);
1965 /* Print current contents of the tables set by the handle command.
1966 It is possible we should just be printing signals actually used
1967 by the current target (but for things to work right when switching
1968 targets, all signals should be in the signal tables). */
1971 signals_info (signum_exp, from_tty)
1975 enum target_signal oursig;
1976 sig_print_header ();
1980 /* First see if this is a symbol name. */
1981 oursig = target_signal_from_name (signum_exp);
1982 if (oursig == TARGET_SIGNAL_UNKNOWN)
1984 /* No, try numeric. */
1986 target_signal_from_command (parse_and_eval_address (signum_exp));
1988 sig_print_info (oursig);
1992 printf_filtered ("\n");
1993 /* These ugly casts brought to you by the native VAX compiler. */
1994 for (oursig = TARGET_SIGNAL_FIRST;
1995 (int)oursig < (int)TARGET_SIGNAL_LAST;
1996 oursig = (enum target_signal)((int)oursig + 1))
2000 if (oursig != TARGET_SIGNAL_UNKNOWN
2001 && oursig != TARGET_SIGNAL_DEFAULT
2002 && oursig != TARGET_SIGNAL_0)
2003 sig_print_info (oursig);
2006 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
2009 /* Save all of the information associated with the inferior<==>gdb
2010 connection. INF_STATUS is a pointer to a "struct inferior_status"
2011 (defined in inferior.h). */
2014 save_inferior_status (inf_status, restore_stack_info)
2015 struct inferior_status *inf_status;
2016 int restore_stack_info;
2018 inf_status->stop_signal = stop_signal;
2019 inf_status->stop_pc = stop_pc;
2020 inf_status->stop_step = stop_step;
2021 inf_status->stop_stack_dummy = stop_stack_dummy;
2022 inf_status->stopped_by_random_signal = stopped_by_random_signal;
2023 inf_status->trap_expected = trap_expected;
2024 inf_status->step_range_start = step_range_start;
2025 inf_status->step_range_end = step_range_end;
2026 inf_status->step_frame_address = step_frame_address;
2027 inf_status->step_over_calls = step_over_calls;
2028 inf_status->stop_after_trap = stop_after_trap;
2029 inf_status->stop_soon_quietly = stop_soon_quietly;
2030 /* Save original bpstat chain here; replace it with copy of chain.
2031 If caller's caller is walking the chain, they'll be happier if we
2032 hand them back the original chain when restore_i_s is called. */
2033 inf_status->stop_bpstat = stop_bpstat;
2034 stop_bpstat = bpstat_copy (stop_bpstat);
2035 inf_status->breakpoint_proceeded = breakpoint_proceeded;
2036 inf_status->restore_stack_info = restore_stack_info;
2037 inf_status->proceed_to_finish = proceed_to_finish;
2039 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
2041 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
2043 record_selected_frame (&(inf_status->selected_frame_address),
2044 &(inf_status->selected_level));
2048 struct restore_selected_frame_args {
2049 CORE_ADDR frame_address;
2053 static int restore_selected_frame PARAMS ((char *));
2055 /* Restore the selected frame. args is really a struct
2056 restore_selected_frame_args * (declared as char * for catch_errors)
2057 telling us what frame to restore. Returns 1 for success, or 0 for
2058 failure. An error message will have been printed on error. */
2061 restore_selected_frame (args)
2064 struct restore_selected_frame_args *fr =
2065 (struct restore_selected_frame_args *) args;
2066 struct frame_info *frame;
2067 int level = fr->level;
2069 frame = find_relative_frame (get_current_frame (), &level);
2071 /* If inf_status->selected_frame_address is NULL, there was no
2072 previously selected frame. */
2073 if (frame == NULL ||
2074 FRAME_FP (frame) != fr->frame_address ||
2077 warning ("Unable to restore previously selected frame.\n");
2080 select_frame (frame, fr->level);
2085 restore_inferior_status (inf_status)
2086 struct inferior_status *inf_status;
2088 stop_signal = inf_status->stop_signal;
2089 stop_pc = inf_status->stop_pc;
2090 stop_step = inf_status->stop_step;
2091 stop_stack_dummy = inf_status->stop_stack_dummy;
2092 stopped_by_random_signal = inf_status->stopped_by_random_signal;
2093 trap_expected = inf_status->trap_expected;
2094 step_range_start = inf_status->step_range_start;
2095 step_range_end = inf_status->step_range_end;
2096 step_frame_address = inf_status->step_frame_address;
2097 step_over_calls = inf_status->step_over_calls;
2098 stop_after_trap = inf_status->stop_after_trap;
2099 stop_soon_quietly = inf_status->stop_soon_quietly;
2100 bpstat_clear (&stop_bpstat);
2101 stop_bpstat = inf_status->stop_bpstat;
2102 breakpoint_proceeded = inf_status->breakpoint_proceeded;
2103 proceed_to_finish = inf_status->proceed_to_finish;
2105 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
2107 /* The inferior can be gone if the user types "print exit(0)"
2108 (and perhaps other times). */
2109 if (target_has_execution)
2110 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
2112 /* The inferior can be gone if the user types "print exit(0)"
2113 (and perhaps other times). */
2115 /* FIXME: If we are being called after stopping in a function which
2116 is called from gdb, we should not be trying to restore the
2117 selected frame; it just prints a spurious error message (The
2118 message is useful, however, in detecting bugs in gdb (like if gdb
2119 clobbers the stack)). In fact, should we be restoring the
2120 inferior status at all in that case? . */
2122 if (target_has_stack && inf_status->restore_stack_info)
2124 struct restore_selected_frame_args fr;
2125 fr.level = inf_status->selected_level;
2126 fr.frame_address = inf_status->selected_frame_address;
2127 /* The point of catch_errors is that if the stack is clobbered,
2128 walking the stack might encounter a garbage pointer and error()
2129 trying to dereference it. */
2130 if (catch_errors (restore_selected_frame, &fr,
2131 "Unable to restore previously selected frame:\n",
2132 RETURN_MASK_ERROR) == 0)
2133 /* Error in restoring the selected frame. Select the innermost
2135 select_frame (get_current_frame (), 0);
2141 _initialize_infrun ()
2144 register int numsigs;
2146 add_info ("signals", signals_info,
2147 "What debugger does when program gets various signals.\n\
2148 Specify a signal as argument to print info on that signal only.");
2149 add_info_alias ("handle", "signals", 0);
2151 add_com ("handle", class_run, handle_command,
2152 concat ("Specify how to handle a signal.\n\
2153 Args are signals and actions to apply to those signals.\n\
2154 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
2155 from 1-15 are allowed for compatibility with old versions of GDB.\n\
2156 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
2157 The special arg \"all\" is recognized to mean all signals except those\n\
2158 used by the debugger, typically SIGTRAP and SIGINT.\n",
2159 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
2160 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
2161 Stop means reenter debugger if this signal happens (implies print).\n\
2162 Print means print a message if this signal happens.\n\
2163 Pass means let program see this signal; otherwise program doesn't know.\n\
2164 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
2165 Pass and Stop may be combined.", NULL));
2167 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
2168 "There is no `stop' command, but you can set a hook on `stop'.\n\
2169 This allows you to set a list of commands to be run each time execution\n\
2170 of the program stops.", &cmdlist);
2172 numsigs = (int)TARGET_SIGNAL_LAST;
2173 signal_stop = (unsigned char *)
2174 xmalloc (sizeof (signal_stop[0]) * numsigs);
2175 signal_print = (unsigned char *)
2176 xmalloc (sizeof (signal_print[0]) * numsigs);
2177 signal_program = (unsigned char *)
2178 xmalloc (sizeof (signal_program[0]) * numsigs);
2179 for (i = 0; i < numsigs; i++)
2182 signal_print[i] = 1;
2183 signal_program[i] = 1;
2186 /* Signals caused by debugger's own actions
2187 should not be given to the program afterwards. */
2188 signal_program[TARGET_SIGNAL_TRAP] = 0;
2189 signal_program[TARGET_SIGNAL_INT] = 0;
2191 /* Signals that are not errors should not normally enter the debugger. */
2192 signal_stop[TARGET_SIGNAL_ALRM] = 0;
2193 signal_print[TARGET_SIGNAL_ALRM] = 0;
2194 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
2195 signal_print[TARGET_SIGNAL_VTALRM] = 0;
2196 signal_stop[TARGET_SIGNAL_PROF] = 0;
2197 signal_print[TARGET_SIGNAL_PROF] = 0;
2198 signal_stop[TARGET_SIGNAL_CHLD] = 0;
2199 signal_print[TARGET_SIGNAL_CHLD] = 0;
2200 signal_stop[TARGET_SIGNAL_IO] = 0;
2201 signal_print[TARGET_SIGNAL_IO] = 0;
2202 signal_stop[TARGET_SIGNAL_POLL] = 0;
2203 signal_print[TARGET_SIGNAL_POLL] = 0;
2204 signal_stop[TARGET_SIGNAL_URG] = 0;
2205 signal_print[TARGET_SIGNAL_URG] = 0;
2209 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
2210 (char *) &stop_on_solib_events,
2211 "Set stopping for shared library events.\n\
2212 If nonzero, gdb will give control to the user when the dynamic linker\n\
2213 notifies gdb of shared library events. The most common event of interest\n\
2214 to the user would be loading/unloading of a new library.\n",