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 */
203 extern void write_pc_pid
PARAMS ((CORE_ADDR
, int));
206 /* Things to clean up if we QUIT out of resume (). */
209 resume_cleanups (arg
)
215 /* Resume the inferior, but allow a QUIT. This is useful if the user
216 wants to interrupt some lengthy single-stepping operation
217 (for child processes, the SIGINT goes to the inferior, and so
218 we get a SIGINT random_signal, but for remote debugging and perhaps
219 other targets, that's not true).
221 STEP nonzero if we should step (zero to continue instead).
222 SIG is the signal to give the inferior (zero for none). */
226 enum target_signal sig
;
228 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
231 #ifdef CANNOT_STEP_BREAKPOINT
232 /* Most targets can step a breakpoint instruction, thus executing it
233 normally. But if this one cannot, just continue and we will hit
235 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
239 #ifdef NO_SINGLE_STEP
241 single_step(sig
); /* Do it the hard way, w/temp breakpoints */
242 step
= 0; /* ...and don't ask hardware to do it. */
246 /* Handle any optimized stores to the inferior NOW... */
247 #ifdef DO_DEFERRED_STORES
251 /* Install inferior's terminal modes. */
252 target_terminal_inferior ();
254 target_resume (-1, step
, sig
);
255 discard_cleanups (old_cleanups
);
259 /* Clear out all variables saying what to do when inferior is continued.
260 First do this, then set the ones you want, then call `proceed'. */
263 clear_proceed_status ()
266 step_range_start
= 0;
268 step_frame_address
= 0;
269 step_over_calls
= -1;
271 stop_soon_quietly
= 0;
272 proceed_to_finish
= 0;
273 breakpoint_proceeded
= 1; /* We're about to proceed... */
275 /* Discard any remaining commands or status from previous stop. */
276 bpstat_clear (&stop_bpstat
);
279 /* Basic routine for continuing the program in various fashions.
281 ADDR is the address to resume at, or -1 for resume where stopped.
282 SIGGNAL is the signal to give it, or 0 for none,
283 or -1 for act according to how it stopped.
284 STEP is nonzero if should trap after one instruction.
285 -1 means return after that and print nothing.
286 You should probably set various step_... variables
287 before calling here, if you are stepping.
289 You should call clear_proceed_status before calling proceed. */
292 proceed (addr
, siggnal
, step
)
294 enum target_signal siggnal
;
300 step_start_function
= find_pc_function (read_pc ());
304 if (addr
== (CORE_ADDR
)-1)
306 /* If there is a breakpoint at the address we will resume at,
307 step one instruction before inserting breakpoints
308 so that we do not stop right away. */
310 if (breakpoint_here_p (read_pc ()))
313 #ifdef STEP_SKIPS_DELAY
314 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
315 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
316 is slow (it needs to read memory from the target). */
317 if (breakpoint_here_p (read_pc () + 4)
318 && STEP_SKIPS_DELAY (read_pc ()))
320 #endif /* STEP_SKIPS_DELAY */
325 #ifdef PREPARE_TO_PROCEED
326 /* In a multi-threaded task we may select another thread and then continue.
328 In this case the thread that stopped at a breakpoint will immediately
329 cause another stop, if it is not stepped over first. On the other hand,
330 if (ADDR != -1) we only want to single step over the breakpoint if we did
331 switch to another thread.
333 If we are single stepping, don't do any of the above.
334 (Note that in the current implementation single stepping another
335 thread after a breakpoint and then continuing will cause the original
336 breakpoint to be hit again, but you can always continue, so it's not
339 if (! step
&& PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
341 #endif /* PREPARE_TO_PROCEED */
344 if (trap_expected_after_continue
)
346 /* If (step == 0), a trap will be automatically generated after
347 the first instruction is executed. Force step one
348 instruction to clear this condition. This should not occur
349 if step is nonzero, but it is harmless in that case. */
351 trap_expected_after_continue
= 0;
353 #endif /* HP_OS_BUG */
356 /* We will get a trace trap after one instruction.
357 Continue it automatically and insert breakpoints then. */
361 int temp
= insert_breakpoints ();
364 print_sys_errmsg ("ptrace", temp
);
365 error ("Cannot insert breakpoints.\n\
366 The same program may be running in another process.");
368 breakpoints_inserted
= 1;
371 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
372 stop_signal
= siggnal
;
373 /* If this signal should not be seen by program,
374 give it zero. Used for debugging signals. */
375 else if (!signal_program
[stop_signal
])
376 stop_signal
= TARGET_SIGNAL_0
;
378 annotate_starting ();
380 /* Make sure that output from GDB appears before output from the
382 gdb_flush (gdb_stdout
);
384 /* Resume inferior. */
385 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
387 /* Wait for it to stop (if not standalone)
388 and in any case decode why it stopped, and act accordingly. */
390 wait_for_inferior ();
394 /* Record the pc and sp of the program the last time it stopped.
395 These are just used internally by wait_for_inferior, but need
396 to be preserved over calls to it and cleared when the inferior
398 static CORE_ADDR prev_pc
;
399 static CORE_ADDR prev_func_start
;
400 static char *prev_func_name
;
403 /* Start remote-debugging of a machine over a serial link. */
409 init_wait_for_inferior ();
410 clear_proceed_status ();
411 stop_soon_quietly
= 1;
413 wait_for_inferior ();
417 /* Initialize static vars when a new inferior begins. */
420 init_wait_for_inferior ()
422 /* These are meaningless until the first time through wait_for_inferior. */
425 prev_func_name
= NULL
;
428 trap_expected_after_continue
= 0;
430 breakpoints_inserted
= 0;
431 breakpoint_init_inferior ();
433 /* Don't confuse first call to proceed(). */
434 stop_signal
= TARGET_SIGNAL_0
;
438 delete_breakpoint_current_contents (arg
)
441 struct breakpoint
**breakpointp
= (struct breakpoint
**)arg
;
442 if (*breakpointp
!= NULL
)
443 delete_breakpoint (*breakpointp
);
446 /* Wait for control to return from inferior to debugger.
447 If inferior gets a signal, we may decide to start it up again
448 instead of returning. That is why there is a loop in this function.
449 When this function actually returns it means the inferior
450 should be left stopped and GDB should read more commands. */
455 struct cleanup
*old_cleanups
;
456 struct target_waitstatus w
;
459 CORE_ADDR stop_func_start
;
460 CORE_ADDR stop_func_end
;
461 char *stop_func_name
;
463 CORE_ADDR prologue_pc
= 0;
466 struct symtab_and_line sal
;
467 int remove_breakpoints_on_following_step
= 0;
469 struct symtab
*current_symtab
;
470 int handling_longjmp
= 0; /* FIXME */
471 struct breakpoint
*step_resume_breakpoint
= NULL
;
472 struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
474 int update_step_sp
= 0;
476 old_cleanups
= make_cleanup (delete_breakpoint_current_contents
,
477 &step_resume_breakpoint
);
478 make_cleanup (delete_breakpoint_current_contents
,
479 &through_sigtramp_breakpoint
);
480 sal
= find_pc_line(prev_pc
, 0);
481 current_line
= sal
.line
;
482 current_symtab
= sal
.symtab
;
484 /* Are we stepping? */
485 #define CURRENTLY_STEPPING() \
486 ((through_sigtramp_breakpoint == NULL \
487 && !handling_longjmp \
488 && ((step_range_end && step_resume_breakpoint == NULL) \
490 || bpstat_should_step ())
494 /* We have to invalidate the registers BEFORE calling target_wait because
495 they can be loaded from the target while in target_wait. This makes
496 remote debugging a bit more efficient for those targets that provide
497 critical registers as part of their normal status mechanism. */
499 registers_changed ();
501 if (target_wait_hook
)
502 pid
= target_wait_hook (-1, &w
);
504 pid
= target_wait (-1, &w
);
508 We goto this label from elsewhere in wait_for_inferior when we want
509 to continue the main loop without calling "wait" and trashing the
510 waitstatus contained in W. */
513 flush_cached_frames ();
515 /* If it's a new process, add it to the thread database */
517 if (pid
!= inferior_pid
518 && !in_thread_list (pid
))
520 fprintf_unfiltered (gdb_stderr
, "[New %s]\n", target_pid_to_str (pid
));
523 /* We may want to consider not doing a resume here in order to give
524 the user a chance to play with the new thread. It might be good
525 to make that a user-settable option. */
527 /* At this point, all threads are stopped (happens automatically in
528 either the OS or the native code). Therefore we need to continue
529 all threads in order to make progress. */
531 target_resume (-1, 0, TARGET_SIGNAL_0
);
537 case TARGET_WAITKIND_LOADED
:
538 /* Ignore it gracefully. */
539 if (breakpoints_inserted
)
541 mark_breakpoints_out ();
542 insert_breakpoints ();
544 resume (0, TARGET_SIGNAL_0
);
547 case TARGET_WAITKIND_SPURIOUS
:
548 resume (0, TARGET_SIGNAL_0
);
551 case TARGET_WAITKIND_EXITED
:
552 target_terminal_ours (); /* Must do this before mourn anyway */
553 annotate_exited (w
.value
.integer
);
555 printf_filtered ("\nProgram exited with code 0%o.\n",
556 (unsigned int)w
.value
.integer
);
558 printf_filtered ("\nProgram exited normally.\n");
560 /* Record the exit code in the convenience variable $_exitcode, so
561 that the user can inspect this again later. */
562 set_internalvar (lookup_internalvar ("_exitcode"),
563 value_from_longest (builtin_type_int
,
564 (LONGEST
) w
.value
.integer
));
565 gdb_flush (gdb_stdout
);
566 target_mourn_inferior ();
567 #ifdef NO_SINGLE_STEP
570 stop_print_frame
= 0;
573 case TARGET_WAITKIND_SIGNALLED
:
574 stop_print_frame
= 0;
575 stop_signal
= w
.value
.sig
;
576 target_terminal_ours (); /* Must do this before mourn anyway */
577 annotate_signalled ();
579 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
580 mean it is already dead? This has been here since GDB 2.8, so
581 perhaps it means rms didn't understand unix waitstatuses?
582 For the moment I'm just kludging around this in remote.c
583 rather than trying to change it here --kingdon, 5 Dec 1994. */
584 target_kill (); /* kill mourns as well */
586 printf_filtered ("\nProgram terminated with signal ");
587 annotate_signal_name ();
588 printf_filtered ("%s", target_signal_to_name (stop_signal
));
589 annotate_signal_name_end ();
590 printf_filtered (", ");
591 annotate_signal_string ();
592 printf_filtered ("%s", target_signal_to_string (stop_signal
));
593 annotate_signal_string_end ();
594 printf_filtered (".\n");
596 printf_filtered ("The program no longer exists.\n");
597 gdb_flush (gdb_stdout
);
598 #ifdef NO_SINGLE_STEP
603 case TARGET_WAITKIND_STOPPED
:
604 /* This is the only case in which we keep going; the above cases
605 end in a continue or goto. */
609 stop_signal
= w
.value
.sig
;
611 stop_pc
= read_pc_pid (pid
);
613 /* See if a thread hit a thread-specific breakpoint that was meant for
614 another thread. If so, then step that thread past the breakpoint,
617 if (stop_signal
== TARGET_SIGNAL_TRAP
618 && breakpoints_inserted
619 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
622 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
, pid
))
624 /* Saw a breakpoint, but it was hit by the wrong thread. Just continue. */
625 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, pid
);
627 remove_breakpoints ();
628 target_resume (pid
, 1, TARGET_SIGNAL_0
); /* Single step */
629 /* FIXME: What if a signal arrives instead of the single-step
632 if (target_wait_hook
)
633 target_wait_hook (pid
, &w
);
635 target_wait (pid
, &w
);
636 insert_breakpoints ();
638 /* We need to restart all the threads now. */
639 target_resume (-1, 0, TARGET_SIGNAL_0
);
646 /* See if something interesting happened to the non-current thread. If
647 so, then switch to that thread, and eventually give control back to
650 if (pid
!= inferior_pid
)
654 /* If it's a random signal for a non-current thread, notify user
655 if he's expressed an interest. */
658 && signal_print
[stop_signal
])
661 target_terminal_ours_for_output ();
662 printf_filtered ("\nProgram received signal %s, %s.\n",
663 target_signal_to_name (stop_signal
),
664 target_signal_to_string (stop_signal
));
665 gdb_flush (gdb_stdout
);
668 /* If it's not SIGTRAP and not a signal we want to stop for, then
669 continue the thread. */
671 if (stop_signal
!= TARGET_SIGNAL_TRAP
672 && !signal_stop
[stop_signal
])
675 target_terminal_inferior ();
677 /* Clear the signal if it should not be passed. */
678 if (signal_program
[stop_signal
] == 0)
679 stop_signal
= TARGET_SIGNAL_0
;
681 target_resume (pid
, 0, stop_signal
);
685 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
686 and fall into the rest of wait_for_inferior(). */
688 /* Save infrun state for the old thread. */
689 save_infrun_state (inferior_pid
, prev_pc
,
690 prev_func_start
, prev_func_name
,
691 trap_expected
, step_resume_breakpoint
,
692 through_sigtramp_breakpoint
,
693 step_range_start
, step_range_end
,
694 step_frame_address
, handling_longjmp
,
699 /* Load infrun state for the new thread. */
700 load_infrun_state (inferior_pid
, &prev_pc
,
701 &prev_func_start
, &prev_func_name
,
702 &trap_expected
, &step_resume_breakpoint
,
703 &through_sigtramp_breakpoint
,
704 &step_range_start
, &step_range_end
,
705 &step_frame_address
, &handling_longjmp
,
707 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid
));
709 flush_cached_frames ();
712 #ifdef NO_SINGLE_STEP
714 single_step (0); /* This actually cleans up the ss */
715 #endif /* NO_SINGLE_STEP */
717 /* If PC is pointing at a nullified instruction, then step beyond
718 it so that the user won't be confused when GDB appears to be ready
721 if (INSTRUCTION_NULLIFIED
)
723 struct target_waitstatus tmpstatus
;
729 registers_changed ();
730 target_resume (pid
, 1, TARGET_SIGNAL_0
);
732 /* We may have received a signal that we want to pass to
733 the inferior; therefore, we must not clobber the waitstatus
734 in W. So we call wait ourselves, then continue the loop
735 at the "have_waited" label. */
736 if (target_wait_hook
)
737 target_wait_hook (pid
, &tmpstatus
);
739 target_wait (pid
, &tmpstatus
);
745 #ifdef HAVE_STEPPABLE_WATCHPOINT
746 /* It may not be necessary to disable the watchpoint to stop over
747 it. For example, the PA can (with some kernel cooperation)
748 single step over a watchpoint without disabling the watchpoint. */
749 if (STOPPED_BY_WATCHPOINT (w
))
756 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
757 /* It is far more common to need to disable a watchpoint
758 to step the inferior over it. FIXME. What else might
759 a debug register or page protection watchpoint scheme need
761 if (STOPPED_BY_WATCHPOINT (w
))
763 /* At this point, we are stopped at an instruction which has attempted to write
764 to a piece of memory under control of a watchpoint. The instruction hasn't
765 actually executed yet. If we were to evaluate the watchpoint expression
766 now, we would get the old value, and therefore no change would seem to have
769 In order to make watchpoints work `right', we really need to complete the
770 memory write, and then evaluate the watchpoint expression. The following
771 code does that by removing the watchpoint (actually, all watchpoints and
772 breakpoints), single-stepping the target, re-inserting watchpoints, and then
773 falling through to let normal single-step processing handle proceed. Since
774 this includes evaluating watchpoints, things will come to a stop in the
777 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
779 remove_breakpoints ();
780 target_resume (pid
, 1, TARGET_SIGNAL_0
); /* Single step */
782 if (target_wait_hook
)
783 target_wait_hook (pid
, &w
);
785 target_wait (pid
, &w
);
786 insert_breakpoints ();
787 /* FIXME-maybe: is this cleaner than setting a flag? Does it
788 handle things like signals arriving and other things happening
789 in combination correctly? */
794 #ifdef HAVE_CONTINUABLE_WATCHPOINT
795 /* It may be possible to simply continue after a watchpoint. */
796 STOPPED_BY_WATCHPOINT (w
);
801 /* Don't care about return value; stop_func_start and stop_func_name
802 will both be 0 if it doesn't work. */
803 find_pc_partial_function (stop_pc
, &stop_func_name
, &stop_func_start
,
805 stop_func_start
+= FUNCTION_START_OFFSET
;
807 bpstat_clear (&stop_bpstat
);
809 stop_stack_dummy
= 0;
810 stop_print_frame
= 1;
812 stopped_by_random_signal
= 0;
813 breakpoints_failed
= 0;
815 /* Look at the cause of the stop, and decide what to do.
816 The alternatives are:
817 1) break; to really stop and return to the debugger,
818 2) drop through to start up again
819 (set another_trap to 1 to single step once)
820 3) set random_signal to 1, and the decision between 1 and 2
821 will be made according to the signal handling tables. */
823 /* First, distinguish signals caused by the debugger from signals
824 that have to do with the program's own actions.
825 Note that breakpoint insns may cause SIGTRAP or SIGILL
826 or SIGEMT, depending on the operating system version.
827 Here we detect when a SIGILL or SIGEMT is really a breakpoint
828 and change it to SIGTRAP. */
830 if (stop_signal
== TARGET_SIGNAL_TRAP
831 || (breakpoints_inserted
&&
832 (stop_signal
== TARGET_SIGNAL_ILL
833 || stop_signal
== TARGET_SIGNAL_EMT
835 || stop_soon_quietly
)
837 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
839 stop_print_frame
= 0;
842 if (stop_soon_quietly
)
845 /* Don't even think about breakpoints
846 if just proceeded over a breakpoint.
848 However, if we are trying to proceed over a breakpoint
849 and end up in sigtramp, then through_sigtramp_breakpoint
850 will be set and we should check whether we've hit the
852 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
853 && through_sigtramp_breakpoint
== NULL
)
854 bpstat_clear (&stop_bpstat
);
857 /* See if there is a breakpoint at the current PC. */
858 stop_bpstat
= bpstat_stop_status
860 #if DECR_PC_AFTER_BREAK
861 /* Notice the case of stepping through a jump
862 that lands just after a breakpoint.
863 Don't confuse that with hitting the breakpoint.
864 What we check for is that 1) stepping is going on
865 and 2) the pc before the last insn does not match
866 the address of the breakpoint before the current pc. */
867 (prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
868 && CURRENTLY_STEPPING ())
869 #else /* DECR_PC_AFTER_BREAK zero */
871 #endif /* DECR_PC_AFTER_BREAK zero */
873 /* Following in case break condition called a
875 stop_print_frame
= 1;
878 if (stop_signal
== TARGET_SIGNAL_TRAP
)
880 = !(bpstat_explains_signal (stop_bpstat
)
882 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
883 || PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
884 FRAME_FP (get_current_frame ()))
885 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
886 || (step_range_end
&& step_resume_breakpoint
== NULL
));
890 = !(bpstat_explains_signal (stop_bpstat
)
891 /* End of a stack dummy. Some systems (e.g. Sony
892 news) give another signal besides SIGTRAP,
893 so check here as well as above. */
894 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
895 || PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
896 FRAME_FP (get_current_frame ()))
897 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
900 stop_signal
= TARGET_SIGNAL_TRAP
;
906 /* For the program's own signals, act according to
907 the signal handling tables. */
911 /* Signal not for debugging purposes. */
914 stopped_by_random_signal
= 1;
916 if (signal_print
[stop_signal
])
919 target_terminal_ours_for_output ();
921 printf_filtered ("\nProgram received signal ");
922 annotate_signal_name ();
923 printf_filtered ("%s", target_signal_to_name (stop_signal
));
924 annotate_signal_name_end ();
925 printf_filtered (", ");
926 annotate_signal_string ();
927 printf_filtered ("%s", target_signal_to_string (stop_signal
));
928 annotate_signal_string_end ();
929 printf_filtered (".\n");
930 gdb_flush (gdb_stdout
);
932 if (signal_stop
[stop_signal
])
934 /* If not going to stop, give terminal back
935 if we took it away. */
937 target_terminal_inferior ();
939 /* Clear the signal if it should not be passed. */
940 if (signal_program
[stop_signal
] == 0)
941 stop_signal
= TARGET_SIGNAL_0
;
943 /* I'm not sure whether this needs to be check_sigtramp2 or
944 whether it could/should be keep_going. */
945 goto check_sigtramp2
;
948 /* Handle cases caused by hitting a breakpoint. */
950 CORE_ADDR jmp_buf_pc
;
951 struct bpstat_what what
;
953 what
= bpstat_what (stop_bpstat
);
957 stop_stack_dummy
= 1;
959 trap_expected_after_continue
= 1;
963 switch (what
.main_action
)
965 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
966 /* If we hit the breakpoint at longjmp, disable it for the
967 duration of this command. Then, install a temporary
968 breakpoint at the target of the jmp_buf. */
969 disable_longjmp_breakpoint();
970 remove_breakpoints ();
971 breakpoints_inserted
= 0;
972 if (!GET_LONGJMP_TARGET(&jmp_buf_pc
)) goto keep_going
;
974 /* Need to blow away step-resume breakpoint, as it
975 interferes with us */
976 if (step_resume_breakpoint
!= NULL
)
978 delete_breakpoint (step_resume_breakpoint
);
979 step_resume_breakpoint
= NULL
;
981 /* Not sure whether we need to blow this away too, but probably
982 it is like the step-resume breakpoint. */
983 if (through_sigtramp_breakpoint
!= NULL
)
985 delete_breakpoint (through_sigtramp_breakpoint
);
986 through_sigtramp_breakpoint
= NULL
;
990 /* FIXME - Need to implement nested temporary breakpoints */
991 if (step_over_calls
> 0)
992 set_longjmp_resume_breakpoint(jmp_buf_pc
,
993 get_current_frame());
996 set_longjmp_resume_breakpoint(jmp_buf_pc
, NULL
);
997 handling_longjmp
= 1; /* FIXME */
1000 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
1001 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
1002 remove_breakpoints ();
1003 breakpoints_inserted
= 0;
1005 /* FIXME - Need to implement nested temporary breakpoints */
1007 && (FRAME_FP (get_current_frame ())
1008 INNER_THAN step_frame_address
))
1014 disable_longjmp_breakpoint();
1015 handling_longjmp
= 0; /* FIXME */
1016 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
1018 /* else fallthrough */
1020 case BPSTAT_WHAT_SINGLE
:
1021 if (breakpoints_inserted
)
1022 remove_breakpoints ();
1023 breakpoints_inserted
= 0;
1025 /* Still need to check other stuff, at least the case
1026 where we are stepping and step out of the right range. */
1029 case BPSTAT_WHAT_STOP_NOISY
:
1030 stop_print_frame
= 1;
1032 /* We are about to nuke the step_resume_breakpoint and
1033 through_sigtramp_breakpoint via the cleanup chain, so
1034 no need to worry about it here. */
1038 case BPSTAT_WHAT_STOP_SILENT
:
1039 stop_print_frame
= 0;
1041 /* We are about to nuke the step_resume_breakpoint and
1042 through_sigtramp_breakpoint via the cleanup chain, so
1043 no need to worry about it here. */
1047 case BPSTAT_WHAT_STEP_RESUME
:
1048 delete_breakpoint (step_resume_breakpoint
);
1049 step_resume_breakpoint
= NULL
;
1052 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
1053 if (through_sigtramp_breakpoint
)
1054 delete_breakpoint (through_sigtramp_breakpoint
);
1055 through_sigtramp_breakpoint
= NULL
;
1057 /* If were waiting for a trap, hitting the step_resume_break
1058 doesn't count as getting it. */
1064 case BPSTAT_WHAT_CHECK_SHLIBS
:
1066 extern int auto_solib_add
;
1068 /* Remove breakpoints, we eventually want to step over the
1069 shlib event breakpoint, and SOLIB_ADD might adjust
1070 breakpoint addresses via breakpoint_re_set. */
1071 if (breakpoints_inserted
)
1072 remove_breakpoints ();
1073 breakpoints_inserted
= 0;
1075 /* Check for any newly added shared libraries if we're
1076 supposed to be adding them automatically. */
1079 /* Switch terminal for any messages produced by
1080 breakpoint_re_set. */
1081 target_terminal_ours_for_output ();
1082 SOLIB_ADD (NULL
, 0, NULL
);
1083 re_enable_breakpoints_in_shlibs ();
1084 target_terminal_inferior ();
1087 /* If requested, stop when the dynamic linker notifies
1088 gdb of events. This allows the user to get control
1089 and place breakpoints in initializer routines for
1090 dynamically loaded objects (among other things). */
1091 if (stop_on_solib_events
)
1093 stop_print_frame
= 0;
1098 /* We want to step over this breakpoint, then keep going. */
1105 case BPSTAT_WHAT_LAST
:
1106 /* Not a real code, but listed here to shut up gcc -Wall. */
1108 case BPSTAT_WHAT_KEEP_CHECKING
:
1113 /* We come here if we hit a breakpoint but should not
1114 stop for it. Possibly we also were stepping
1115 and should stop for that. So fall through and
1116 test for stepping. But, if not stepping,
1119 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1120 /* This is the old way of detecting the end of the stack dummy.
1121 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
1122 handled above. As soon as we can test it on all of them, all
1123 architectures should define it. */
1125 /* If this is the breakpoint at the end of a stack dummy,
1126 just stop silently, unless the user was doing an si/ni, in which
1127 case she'd better know what she's doing. */
1129 if (PC_IN_CALL_DUMMY (stop_pc
, read_sp (), FRAME_FP (get_current_frame ()))
1132 stop_print_frame
= 0;
1133 stop_stack_dummy
= 1;
1135 trap_expected_after_continue
= 1;
1139 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1141 if (step_resume_breakpoint
)
1142 /* Having a step-resume breakpoint overrides anything
1143 else having to do with stepping commands until
1144 that breakpoint is reached. */
1145 /* I'm not sure whether this needs to be check_sigtramp2 or
1146 whether it could/should be keep_going. */
1147 goto check_sigtramp2
;
1149 if (step_range_end
== 0)
1150 /* Likewise if we aren't even stepping. */
1151 /* I'm not sure whether this needs to be check_sigtramp2 or
1152 whether it could/should be keep_going. */
1153 goto check_sigtramp2
;
1155 /* If stepping through a line, keep going if still within it. */
1156 if (stop_pc
>= step_range_start
1157 && stop_pc
< step_range_end
1159 /* I haven't a clue what might trigger this clause, and it seems wrong anyway,
1160 so I've disabled it until someone complains. -Stu 10/24/95 */
1162 /* The step range might include the start of the
1163 function, so if we are at the start of the
1164 step range and either the stack or frame pointers
1165 just changed, we've stepped outside */
1166 && !(stop_pc
== step_range_start
1167 && FRAME_FP (get_current_frame ())
1168 && (read_sp () INNER_THAN step_sp
1169 || FRAME_FP (get_current_frame ()) != step_frame_address
))
1173 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
1174 So definately need to check for sigtramp here. */
1175 goto check_sigtramp2
;
1178 /* We stepped out of the stepping range. */
1180 /* We can't update step_sp every time through the loop, because
1181 reading the stack pointer would slow down stepping too much.
1182 But we can update it every time we leave the step range. */
1185 /* Did we just take a signal? */
1186 if (IN_SIGTRAMP (stop_pc
, stop_func_name
)
1187 && !IN_SIGTRAMP (prev_pc
, prev_func_name
))
1189 /* We've just taken a signal; go until we are back to
1190 the point where we took it and one more. */
1192 /* This code is needed at least in the following case:
1193 The user types "next" and then a signal arrives (before
1194 the "next" is done). */
1196 /* Note that if we are stopped at a breakpoint, then we need
1197 the step_resume breakpoint to override any breakpoints at
1198 the same location, so that we will still step over the
1199 breakpoint even though the signal happened. */
1202 struct symtab_and_line sr_sal
;
1204 sr_sal
.pc
= prev_pc
;
1205 sr_sal
.symtab
= NULL
;
1207 /* We could probably be setting the frame to
1208 step_frame_address; I don't think anyone thought to try it. */
1209 step_resume_breakpoint
=
1210 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
1211 if (breakpoints_inserted
)
1212 insert_breakpoints ();
1215 /* If this is stepi or nexti, make sure that the stepping range
1216 gets us past that instruction. */
1217 if (step_range_end
== 1)
1218 /* FIXME: Does this run afoul of the code below which, if
1219 we step into the middle of a line, resets the stepping
1221 step_range_end
= (step_range_start
= prev_pc
) + 1;
1223 remove_breakpoints_on_following_step
= 1;
1228 /* I disabled this test because it was too complicated and slow. The
1229 SKIP_PROLOGUE was especially slow, because it caused unnecessary
1230 prologue examination on various architectures. The code in the #else
1231 clause has been tested on the Sparc, Mips, PA, and Power
1232 architectures, so it's pretty likely to be correct. -Stu 10/24/95 */
1234 /* See if we left the step range due to a subroutine call that
1235 we should proceed to the end of. */
1237 if (stop_func_start
)
1241 /* Do this after the IN_SIGTRAMP check; it might give
1243 prologue_pc
= stop_func_start
;
1245 /* Don't skip the prologue if this is assembly source */
1246 s
= find_pc_symtab (stop_pc
);
1247 if (s
&& s
->language
!= language_asm
)
1248 SKIP_PROLOGUE (prologue_pc
);
1251 if ((/* Might be a non-recursive call. If the symbols are missing
1252 enough that stop_func_start == prev_func_start even though
1253 they are really two functions, we will treat some calls as
1255 stop_func_start
!= prev_func_start
1257 /* Might be a recursive call if either we have a prologue
1258 or the call instruction itself saves the PC on the stack. */
1259 || prologue_pc
!= stop_func_start
1260 || read_sp () != step_sp
)
1261 && (/* PC is completely out of bounds of any known objfiles. Treat
1262 like a subroutine call. */
1265 /* If we do a call, we will be at the start of a function... */
1266 || stop_pc
== stop_func_start
1268 /* ...except on the Alpha with -O (and also Irix 5 and
1269 perhaps others), in which we might call the address
1270 after the load of gp. Since prologues don't contain
1271 calls, we can't return to within one, and we don't
1272 jump back into them, so this check is OK. */
1274 || stop_pc
< prologue_pc
1276 /* ...and if it is a leaf function, the prologue might
1277 consist of gp loading only, so the call transfers to
1278 the first instruction after the prologue. */
1279 || (stop_pc
== prologue_pc
1281 /* Distinguish this from the case where we jump back
1282 to the first instruction after the prologue,
1283 within a function. */
1284 && stop_func_start
!= prev_func_start
)
1286 /* If we end up in certain places, it means we did a subroutine
1287 call. I'm not completely sure this is necessary now that we
1288 have the above checks with stop_func_start (and now that
1289 find_pc_partial_function is pickier). */
1290 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, stop_func_name
)
1292 /* If none of the above apply, it is a jump within a function,
1293 or a return from a subroutine. The other case is longjmp,
1294 which can no longer happen here as long as the
1295 handling_longjmp stuff is working. */
1298 /* This test is a much more streamlined, (but hopefully correct)
1299 replacement for the code above. It's been tested on the Sparc,
1300 Mips, PA, and Power architectures with good results. */
1302 if (stop_pc
== stop_func_start
/* Quick test */
1303 || in_prologue (stop_pc
, stop_func_start
)
1304 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, stop_func_name
)
1305 || stop_func_start
== 0)
1309 /* It's a subroutine call. */
1311 if (step_over_calls
== 0)
1313 /* I presume that step_over_calls is only 0 when we're
1314 supposed to be stepping at the assembly language level
1315 ("stepi"). Just stop. */
1320 if (step_over_calls
> 0)
1321 /* We're doing a "next". */
1322 goto step_over_function
;
1324 /* If we are in a function call trampoline (a stub between
1325 the calling routine and the real function), locate the real
1326 function. That's what tells us (a) whether we want to step
1327 into it at all, and (b) what prologue we want to run to
1328 the end of, if we do step into it. */
1329 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
1331 stop_func_start
= tmp
;
1334 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
1337 struct symtab_and_line xxx
;
1342 step_resume_breakpoint
=
1343 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
1344 insert_breakpoints ();
1349 /* If we have line number information for the function we
1350 are thinking of stepping into, step into it.
1352 If there are several symtabs at that PC (e.g. with include
1353 files), just want to know whether *any* of them have line
1354 numbers. find_pc_line handles this. */
1356 struct symtab_and_line tmp_sal
;
1358 tmp_sal
= find_pc_line (stop_func_start
, 0);
1359 if (tmp_sal
.line
!= 0)
1360 goto step_into_function
;
1364 /* A subroutine call has happened. */
1366 /* Set a special breakpoint after the return */
1367 struct symtab_and_line sr_sal
;
1370 (SAVED_PC_AFTER_CALL (get_current_frame ()));
1371 sr_sal
.symtab
= NULL
;
1373 step_resume_breakpoint
=
1374 set_momentary_breakpoint (sr_sal
, get_current_frame (),
1376 step_resume_breakpoint
->frame
= step_frame_address
;
1377 if (breakpoints_inserted
)
1378 insert_breakpoints ();
1383 /* Subroutine call with source code we should not step over.
1384 Do step to the first line of code in it. */
1388 s
= find_pc_symtab (stop_pc
);
1389 if (s
&& s
->language
!= language_asm
)
1390 SKIP_PROLOGUE (stop_func_start
);
1392 sal
= find_pc_line (stop_func_start
, 0);
1393 /* Use the step_resume_break to step until
1394 the end of the prologue, even if that involves jumps
1395 (as it seems to on the vax under 4.2). */
1396 /* If the prologue ends in the middle of a source line,
1397 continue to the end of that source line (if it is still
1398 within the function). Otherwise, just go to end of prologue. */
1399 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1400 /* no, don't either. It skips any code that's
1401 legitimately on the first line. */
1403 if (sal
.end
&& sal
.pc
!= stop_func_start
&& sal
.end
< stop_func_end
)
1404 stop_func_start
= sal
.end
;
1407 if (stop_func_start
== stop_pc
)
1409 /* We are already there: stop now. */
1414 /* Put the step-breakpoint there and go until there. */
1416 struct symtab_and_line sr_sal
;
1418 sr_sal
.pc
= stop_func_start
;
1419 sr_sal
.symtab
= NULL
;
1421 /* Do not specify what the fp should be when we stop
1422 since on some machines the prologue
1423 is where the new fp value is established. */
1424 step_resume_breakpoint
=
1425 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
1426 if (breakpoints_inserted
)
1427 insert_breakpoints ();
1429 /* And make sure stepping stops right away then. */
1430 step_range_end
= step_range_start
;
1435 /* We've wandered out of the step range. */
1437 sal
= find_pc_line(stop_pc
, 0);
1439 if (step_range_end
== 1)
1441 /* It is stepi or nexti. We always want to stop stepping after
1447 /* If we're in the return path from a shared library trampoline,
1448 we want to proceed through the trampoline when stepping. */
1449 if (IN_SOLIB_RETURN_TRAMPOLINE(stop_pc
, stop_func_name
))
1453 /* Determine where this trampoline returns. */
1454 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
1456 /* Only proceed through if we know where it's going. */
1459 /* And put the step-breakpoint there and go until there. */
1460 struct symtab_and_line sr_sal
;
1463 sr_sal
.symtab
= NULL
;
1465 /* Do not specify what the fp should be when we stop
1466 since on some machines the prologue
1467 is where the new fp value is established. */
1468 step_resume_breakpoint
=
1469 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
1470 if (breakpoints_inserted
)
1471 insert_breakpoints ();
1473 /* Restart without fiddling with the step ranges or
1481 /* We have no line number information. That means to stop
1482 stepping (does this always happen right after one instruction,
1483 when we do "s" in a function with no line numbers,
1484 or can this happen as a result of a return or longjmp?). */
1489 if (stop_pc
== sal
.pc
1490 && (current_line
!= sal
.line
|| current_symtab
!= sal
.symtab
))
1492 /* We are at the start of a different line. So stop. Note that
1493 we don't stop if we step into the middle of a different line.
1494 That is said to make things like for (;;) statements work
1500 /* We aren't done stepping.
1502 Optimize by setting the stepping range to the line.
1503 (We might not be in the original line, but if we entered a
1504 new line in mid-statement, we continue stepping. This makes
1505 things like for(;;) statements work better.) */
1507 if (stop_func_end
&& sal
.end
>= stop_func_end
)
1509 /* If this is the last line of the function, don't keep stepping
1510 (it would probably step us out of the function).
1511 This is particularly necessary for a one-line function,
1512 in which after skipping the prologue we better stop even though
1513 we will be in mid-line. */
1517 step_range_start
= sal
.pc
;
1518 step_range_end
= sal
.end
;
1523 && IN_SIGTRAMP (stop_pc
, stop_func_name
)
1524 && !IN_SIGTRAMP (prev_pc
, prev_func_name
))
1526 /* What has happened here is that we have just stepped the inferior
1527 with a signal (because it is a signal which shouldn't make
1528 us stop), thus stepping into sigtramp.
1530 So we need to set a step_resume_break_address breakpoint
1531 and continue until we hit it, and then step. FIXME: This should
1532 be more enduring than a step_resume breakpoint; we should know
1533 that we will later need to keep going rather than re-hitting
1534 the breakpoint here (see testsuite/gdb.t06/signals.exp where
1535 it says "exceedingly difficult"). */
1536 struct symtab_and_line sr_sal
;
1538 sr_sal
.pc
= prev_pc
;
1539 sr_sal
.symtab
= NULL
;
1541 /* We perhaps could set the frame if we kept track of what
1542 the frame corresponding to prev_pc was. But we don't,
1544 through_sigtramp_breakpoint
=
1545 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
1546 if (breakpoints_inserted
)
1547 insert_breakpoints ();
1549 remove_breakpoints_on_following_step
= 1;
1554 /* Come to this label when you need to resume the inferior.
1555 It's really much cleaner to do a goto than a maze of if-else
1558 /* Save the pc before execution, to compare with pc after stop. */
1559 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
1560 prev_func_start
= stop_func_start
; /* Ok, since if DECR_PC_AFTER
1561 BREAK is defined, the
1562 original pc would not have
1563 been at the start of a
1565 prev_func_name
= stop_func_name
;
1568 step_sp
= read_sp ();
1571 /* If we did not do break;, it means we should keep
1572 running the inferior and not return to debugger. */
1574 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
1576 /* We took a signal (which we are supposed to pass through to
1577 the inferior, else we'd have done a break above) and we
1578 haven't yet gotten our trap. Simply continue. */
1579 resume (CURRENTLY_STEPPING (), stop_signal
);
1583 /* Either the trap was not expected, but we are continuing
1584 anyway (the user asked that this signal be passed to the
1587 The signal was SIGTRAP, e.g. it was our signal, but we
1588 decided we should resume from it.
1590 We're going to run this baby now!
1592 Insert breakpoints now, unless we are trying
1593 to one-proceed past a breakpoint. */
1594 /* If we've just finished a special step resume and we don't
1595 want to hit a breakpoint, pull em out. */
1596 if (step_resume_breakpoint
== NULL
1597 && through_sigtramp_breakpoint
== NULL
1598 && remove_breakpoints_on_following_step
)
1600 remove_breakpoints_on_following_step
= 0;
1601 remove_breakpoints ();
1602 breakpoints_inserted
= 0;
1604 else if (!breakpoints_inserted
&&
1605 (through_sigtramp_breakpoint
!= NULL
|| !another_trap
))
1607 breakpoints_failed
= insert_breakpoints ();
1608 if (breakpoints_failed
)
1610 breakpoints_inserted
= 1;
1613 trap_expected
= another_trap
;
1615 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1616 stop_signal
= TARGET_SIGNAL_0
;
1618 #ifdef SHIFT_INST_REGS
1619 /* I'm not sure when this following segment applies. I do know, now,
1620 that we shouldn't rewrite the regs when we were stopped by a
1621 random signal from the inferior process. */
1622 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
1623 (this is only used on the 88k). */
1625 if (!bpstat_explains_signal (stop_bpstat
)
1626 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
1627 && !stopped_by_random_signal
)
1629 #endif /* SHIFT_INST_REGS */
1631 resume (CURRENTLY_STEPPING (), stop_signal
);
1636 if (target_has_execution
)
1638 /* Assuming the inferior still exists, set these up for next
1639 time, just like we did above if we didn't break out of the
1641 prev_pc
= read_pc ();
1642 prev_func_start
= stop_func_start
;
1643 prev_func_name
= stop_func_name
;
1645 do_cleanups (old_cleanups
);
1648 /* Here to return control to GDB when the inferior stops for real.
1649 Print appropriate messages, remove breakpoints, give terminal our modes.
1651 STOP_PRINT_FRAME nonzero means print the executing frame
1652 (pc, function, args, file, line number and line text).
1653 BREAKPOINTS_FAILED nonzero means stop was due to error
1654 attempting to insert breakpoints. */
1659 /* Make sure that the current_frame's pc is correct. This
1660 is a correction for setting up the frame info before doing
1661 DECR_PC_AFTER_BREAK */
1662 if (target_has_execution
&& get_current_frame())
1663 (get_current_frame ())->pc
= read_pc ();
1665 if (breakpoints_failed
)
1667 target_terminal_ours_for_output ();
1668 print_sys_errmsg ("ptrace", breakpoints_failed
);
1669 printf_filtered ("Stopped; cannot insert breakpoints.\n\
1670 The same program may be running in another process.\n");
1673 if (target_has_execution
&& breakpoints_inserted
)
1674 if (remove_breakpoints ())
1676 target_terminal_ours_for_output ();
1677 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
1678 It might be running in another process.\n\
1679 Further execution is probably impossible.\n");
1682 breakpoints_inserted
= 0;
1684 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1685 Delete any breakpoint that is to be deleted at the next stop. */
1687 breakpoint_auto_delete (stop_bpstat
);
1689 /* If an auto-display called a function and that got a signal,
1690 delete that auto-display to avoid an infinite recursion. */
1692 if (stopped_by_random_signal
)
1693 disable_current_display ();
1695 if (step_multi
&& stop_step
)
1698 target_terminal_ours ();
1701 && stop_bpstat
->breakpoint_at
1702 && stop_bpstat
->breakpoint_at
->type
== bp_shlib_event
)
1703 printf_filtered ("Stopped due to shared library event\n");
1705 /* Look up the hook_stop and run it if it exists. */
1707 if (stop_command
->hook
)
1709 catch_errors (hook_stop_stub
, (char *)stop_command
->hook
,
1710 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
1713 if (!target_has_stack
)
1716 /* Select innermost stack frame except on return from a stack dummy routine,
1717 or if the program has exited. Print it without a level number if
1718 we have changed functions or hit a breakpoint. Print source line
1720 if (!stop_stack_dummy
)
1722 select_frame (get_current_frame (), 0);
1724 if (stop_print_frame
)
1728 source_only
= bpstat_print (stop_bpstat
);
1729 source_only
= source_only
||
1731 && step_frame_address
== FRAME_FP (get_current_frame ())
1732 && step_start_function
== find_pc_function (stop_pc
));
1734 print_stack_frame (selected_frame
, -1, source_only
? -1: 1);
1736 /* Display the auto-display expressions. */
1741 /* Save the function value return registers, if we care.
1742 We might be about to restore their previous contents. */
1743 if (proceed_to_finish
)
1744 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
1746 if (stop_stack_dummy
)
1748 /* Pop the empty frame that contains the stack dummy.
1749 POP_FRAME ends with a setting of the current frame, so we
1750 can use that next. */
1752 /* Set stop_pc to what it was before we called the function. Can't rely
1753 on restore_inferior_status because that only gets called if we don't
1754 stop in the called function. */
1755 stop_pc
= read_pc();
1756 select_frame (get_current_frame (), 0);
1759 annotate_stopped ();
1763 hook_stop_stub (cmd
)
1766 execute_user_command ((struct cmd_list_element
*)cmd
, 0);
1770 int signal_stop_state (signo
)
1773 return signal_stop
[signo
];
1776 int signal_print_state (signo
)
1779 return signal_print
[signo
];
1782 int signal_pass_state (signo
)
1785 return signal_program
[signo
];
1792 Signal Stop\tPrint\tPass to program\tDescription\n");
1796 sig_print_info (oursig
)
1797 enum target_signal oursig
;
1799 char *name
= target_signal_to_name (oursig
);
1800 printf_filtered ("%s", name
);
1801 printf_filtered ("%*.*s ", 13 - strlen (name
), 13 - strlen (name
),
1803 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
1804 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
1805 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
1806 printf_filtered ("%s\n", target_signal_to_string (oursig
));
1809 /* Specify how various signals in the inferior should be handled. */
1812 handle_command (args
, from_tty
)
1817 int digits
, wordlen
;
1818 int sigfirst
, signum
, siglast
;
1819 enum target_signal oursig
;
1822 unsigned char *sigs
;
1823 struct cleanup
*old_chain
;
1827 error_no_arg ("signal to handle");
1830 /* Allocate and zero an array of flags for which signals to handle. */
1832 nsigs
= (int)TARGET_SIGNAL_LAST
;
1833 sigs
= (unsigned char *) alloca (nsigs
);
1834 memset (sigs
, 0, nsigs
);
1836 /* Break the command line up into args. */
1838 argv
= buildargv (args
);
1843 old_chain
= make_cleanup (freeargv
, (char *) argv
);
1845 /* Walk through the args, looking for signal oursigs, signal names, and
1846 actions. Signal numbers and signal names may be interspersed with
1847 actions, with the actions being performed for all signals cumulatively
1848 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
1850 while (*argv
!= NULL
)
1852 wordlen
= strlen (*argv
);
1853 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++) {;}
1855 sigfirst
= siglast
= -1;
1857 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
1859 /* Apply action to all signals except those used by the
1860 debugger. Silently skip those. */
1863 siglast
= nsigs
- 1;
1865 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
1867 SET_SIGS (nsigs
, sigs
, signal_stop
);
1868 SET_SIGS (nsigs
, sigs
, signal_print
);
1870 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
1872 UNSET_SIGS (nsigs
, sigs
, signal_program
);
1874 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
1876 SET_SIGS (nsigs
, sigs
, signal_print
);
1878 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
1880 SET_SIGS (nsigs
, sigs
, signal_program
);
1882 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
1884 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
1886 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
1888 SET_SIGS (nsigs
, sigs
, signal_program
);
1890 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
1892 UNSET_SIGS (nsigs
, sigs
, signal_print
);
1893 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
1895 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
1897 UNSET_SIGS (nsigs
, sigs
, signal_program
);
1899 else if (digits
> 0)
1901 /* It is numeric. The numeric signal refers to our own internal
1902 signal numbering from target.h, not to host/target signal number.
1903 This is a feature; users really should be using symbolic names
1904 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
1905 will work right anyway. */
1907 sigfirst
= siglast
= (int) target_signal_from_command (atoi (*argv
));
1908 if ((*argv
)[digits
] == '-')
1911 (int) target_signal_from_command (atoi ((*argv
) + digits
+ 1));
1913 if (sigfirst
> siglast
)
1915 /* Bet he didn't figure we'd think of this case... */
1923 oursig
= target_signal_from_name (*argv
);
1924 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
1926 sigfirst
= siglast
= (int)oursig
;
1930 /* Not a number and not a recognized flag word => complain. */
1931 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
1935 /* If any signal numbers or symbol names were found, set flags for
1936 which signals to apply actions to. */
1938 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
1940 switch ((enum target_signal
)signum
)
1942 case TARGET_SIGNAL_TRAP
:
1943 case TARGET_SIGNAL_INT
:
1944 if (!allsigs
&& !sigs
[signum
])
1946 if (query ("%s is used by the debugger.\n\
1947 Are you sure you want to change it? ",
1948 target_signal_to_name
1949 ((enum target_signal
)signum
)))
1955 printf_unfiltered ("Not confirmed, unchanged.\n");
1956 gdb_flush (gdb_stdout
);
1960 case TARGET_SIGNAL_0
:
1961 case TARGET_SIGNAL_DEFAULT
:
1962 case TARGET_SIGNAL_UNKNOWN
:
1963 /* Make sure that "all" doesn't print these. */
1974 target_notice_signals(inferior_pid
);
1978 /* Show the results. */
1979 sig_print_header ();
1980 for (signum
= 0; signum
< nsigs
; signum
++)
1984 sig_print_info (signum
);
1989 do_cleanups (old_chain
);
1992 /* Print current contents of the tables set by the handle command.
1993 It is possible we should just be printing signals actually used
1994 by the current target (but for things to work right when switching
1995 targets, all signals should be in the signal tables). */
1998 signals_info (signum_exp
, from_tty
)
2002 enum target_signal oursig
;
2003 sig_print_header ();
2007 /* First see if this is a symbol name. */
2008 oursig
= target_signal_from_name (signum_exp
);
2009 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
2011 /* No, try numeric. */
2013 target_signal_from_command (parse_and_eval_address (signum_exp
));
2015 sig_print_info (oursig
);
2019 printf_filtered ("\n");
2020 /* These ugly casts brought to you by the native VAX compiler. */
2021 for (oursig
= TARGET_SIGNAL_FIRST
;
2022 (int)oursig
< (int)TARGET_SIGNAL_LAST
;
2023 oursig
= (enum target_signal
)((int)oursig
+ 1))
2027 if (oursig
!= TARGET_SIGNAL_UNKNOWN
2028 && oursig
!= TARGET_SIGNAL_DEFAULT
2029 && oursig
!= TARGET_SIGNAL_0
)
2030 sig_print_info (oursig
);
2033 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
2036 /* Save all of the information associated with the inferior<==>gdb
2037 connection. INF_STATUS is a pointer to a "struct inferior_status"
2038 (defined in inferior.h). */
2041 save_inferior_status (inf_status
, restore_stack_info
)
2042 struct inferior_status
*inf_status
;
2043 int restore_stack_info
;
2045 inf_status
->stop_signal
= stop_signal
;
2046 inf_status
->stop_pc
= stop_pc
;
2047 inf_status
->stop_step
= stop_step
;
2048 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
2049 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
2050 inf_status
->trap_expected
= trap_expected
;
2051 inf_status
->step_range_start
= step_range_start
;
2052 inf_status
->step_range_end
= step_range_end
;
2053 inf_status
->step_frame_address
= step_frame_address
;
2054 inf_status
->step_over_calls
= step_over_calls
;
2055 inf_status
->stop_after_trap
= stop_after_trap
;
2056 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
2057 /* Save original bpstat chain here; replace it with copy of chain.
2058 If caller's caller is walking the chain, they'll be happier if we
2059 hand them back the original chain when restore_i_s is called. */
2060 inf_status
->stop_bpstat
= stop_bpstat
;
2061 stop_bpstat
= bpstat_copy (stop_bpstat
);
2062 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
2063 inf_status
->restore_stack_info
= restore_stack_info
;
2064 inf_status
->proceed_to_finish
= proceed_to_finish
;
2066 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
2068 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
2070 record_selected_frame (&(inf_status
->selected_frame_address
),
2071 &(inf_status
->selected_level
));
2075 struct restore_selected_frame_args
{
2076 CORE_ADDR frame_address
;
2080 static int restore_selected_frame
PARAMS ((char *));
2082 /* Restore the selected frame. args is really a struct
2083 restore_selected_frame_args * (declared as char * for catch_errors)
2084 telling us what frame to restore. Returns 1 for success, or 0 for
2085 failure. An error message will have been printed on error. */
2088 restore_selected_frame (args
)
2091 struct restore_selected_frame_args
*fr
=
2092 (struct restore_selected_frame_args
*) args
;
2093 struct frame_info
*frame
;
2094 int level
= fr
->level
;
2096 frame
= find_relative_frame (get_current_frame (), &level
);
2098 /* If inf_status->selected_frame_address is NULL, there was no
2099 previously selected frame. */
2100 if (frame
== NULL
||
2101 FRAME_FP (frame
) != fr
->frame_address
||
2104 warning ("Unable to restore previously selected frame.\n");
2107 select_frame (frame
, fr
->level
);
2112 restore_inferior_status (inf_status
)
2113 struct inferior_status
*inf_status
;
2115 stop_signal
= inf_status
->stop_signal
;
2116 stop_pc
= inf_status
->stop_pc
;
2117 stop_step
= inf_status
->stop_step
;
2118 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
2119 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
2120 trap_expected
= inf_status
->trap_expected
;
2121 step_range_start
= inf_status
->step_range_start
;
2122 step_range_end
= inf_status
->step_range_end
;
2123 step_frame_address
= inf_status
->step_frame_address
;
2124 step_over_calls
= inf_status
->step_over_calls
;
2125 stop_after_trap
= inf_status
->stop_after_trap
;
2126 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
2127 bpstat_clear (&stop_bpstat
);
2128 stop_bpstat
= inf_status
->stop_bpstat
;
2129 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
2130 proceed_to_finish
= inf_status
->proceed_to_finish
;
2132 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
2134 /* The inferior can be gone if the user types "print exit(0)"
2135 (and perhaps other times). */
2136 if (target_has_execution
)
2137 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
2139 /* The inferior can be gone if the user types "print exit(0)"
2140 (and perhaps other times). */
2142 /* FIXME: If we are being called after stopping in a function which
2143 is called from gdb, we should not be trying to restore the
2144 selected frame; it just prints a spurious error message (The
2145 message is useful, however, in detecting bugs in gdb (like if gdb
2146 clobbers the stack)). In fact, should we be restoring the
2147 inferior status at all in that case? . */
2149 if (target_has_stack
&& inf_status
->restore_stack_info
)
2151 struct restore_selected_frame_args fr
;
2152 fr
.level
= inf_status
->selected_level
;
2153 fr
.frame_address
= inf_status
->selected_frame_address
;
2154 /* The point of catch_errors is that if the stack is clobbered,
2155 walking the stack might encounter a garbage pointer and error()
2156 trying to dereference it. */
2157 if (catch_errors (restore_selected_frame
, &fr
,
2158 "Unable to restore previously selected frame:\n",
2159 RETURN_MASK_ERROR
) == 0)
2160 /* Error in restoring the selected frame. Select the innermost
2162 select_frame (get_current_frame (), 0);
2168 _initialize_infrun ()
2171 register int numsigs
;
2173 add_info ("signals", signals_info
,
2174 "What debugger does when program gets various signals.\n\
2175 Specify a signal as argument to print info on that signal only.");
2176 add_info_alias ("handle", "signals", 0);
2178 add_com ("handle", class_run
, handle_command
,
2179 concat ("Specify how to handle a signal.\n\
2180 Args are signals and actions to apply to those signals.\n\
2181 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
2182 from 1-15 are allowed for compatibility with old versions of GDB.\n\
2183 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
2184 The special arg \"all\" is recognized to mean all signals except those\n\
2185 used by the debugger, typically SIGTRAP and SIGINT.\n",
2186 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
2187 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
2188 Stop means reenter debugger if this signal happens (implies print).\n\
2189 Print means print a message if this signal happens.\n\
2190 Pass means let program see this signal; otherwise program doesn't know.\n\
2191 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
2192 Pass and Stop may be combined.", NULL
));
2194 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
2195 "There is no `stop' command, but you can set a hook on `stop'.\n\
2196 This allows you to set a list of commands to be run each time execution\n\
2197 of the program stops.", &cmdlist
);
2199 numsigs
= (int)TARGET_SIGNAL_LAST
;
2200 signal_stop
= (unsigned char *)
2201 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
2202 signal_print
= (unsigned char *)
2203 xmalloc (sizeof (signal_print
[0]) * numsigs
);
2204 signal_program
= (unsigned char *)
2205 xmalloc (sizeof (signal_program
[0]) * numsigs
);
2206 for (i
= 0; i
< numsigs
; i
++)
2209 signal_print
[i
] = 1;
2210 signal_program
[i
] = 1;
2213 /* Signals caused by debugger's own actions
2214 should not be given to the program afterwards. */
2215 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
2216 signal_program
[TARGET_SIGNAL_INT
] = 0;
2218 /* Signals that are not errors should not normally enter the debugger. */
2219 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
2220 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
2221 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
2222 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
2223 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
2224 signal_print
[TARGET_SIGNAL_PROF
] = 0;
2225 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
2226 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
2227 signal_stop
[TARGET_SIGNAL_IO
] = 0;
2228 signal_print
[TARGET_SIGNAL_IO
] = 0;
2229 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
2230 signal_print
[TARGET_SIGNAL_POLL
] = 0;
2231 signal_stop
[TARGET_SIGNAL_URG
] = 0;
2232 signal_print
[TARGET_SIGNAL_URG
] = 0;
2236 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
2237 (char *) &stop_on_solib_events
,
2238 "Set stopping for shared library events.\n\
2239 If nonzero, gdb will give control to the user when the dynamic linker\n\
2240 notifies gdb of shared library events. The most common event of interest\n\
2241 to the user would be loading/unloading of a new library.\n",