1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986-1989, 1991-1999 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
27 #include "breakpoint.h"
32 #include "gdbthread.h"
34 #include "symfile.h" /* for overlay functions */
39 /* Prototypes for local functions */
41 static void signals_info (char *, int);
43 static void handle_command (char *, int);
45 static void sig_print_info (enum target_signal
);
47 static void sig_print_header (void);
49 static void resume_cleanups (int);
51 static int hook_stop_stub (void *);
53 static void delete_breakpoint_current_contents (void *);
55 static void set_follow_fork_mode_command (char *arg
, int from_tty
,
56 struct cmd_list_element
* c
);
58 static struct inferior_status
*xmalloc_inferior_status (void);
60 static void free_inferior_status (struct inferior_status
*);
62 static int restore_selected_frame (void *);
64 static void build_infrun (void);
66 static void follow_inferior_fork (int parent_pid
, int child_pid
,
67 int has_forked
, int has_vforked
);
69 static void follow_fork (int parent_pid
, int child_pid
);
71 static void follow_vfork (int parent_pid
, int child_pid
);
73 static void set_schedlock_func (char *args
, int from_tty
,
74 struct cmd_list_element
* c
);
76 static int is_internal_shlib_eventpoint (struct breakpoint
* ep
);
78 static int stopped_for_internal_shlib_event (bpstat bs
);
80 struct execution_control_state
;
82 static int currently_stepping (struct execution_control_state
*ecs
);
84 static void xdb_handle_command (char *args
, int from_tty
);
86 void _initialize_infrun (void);
88 int inferior_ignoring_startup_exec_events
= 0;
89 int inferior_ignoring_leading_exec_events
= 0;
91 /* In asynchronous mode, but simulating synchronous execution. */
93 int sync_execution
= 0;
95 /* wait_for_inferior and normal_stop use this to notify the user
96 when the inferior stopped in a different thread than it had been
99 static int switched_from_inferior_pid
;
101 /* This will be true for configurations that may actually report an
102 inferior pid different from the original. At present this is only
103 true for HP-UX native. */
105 #ifndef MAY_SWITCH_FROM_INFERIOR_PID
106 #define MAY_SWITCH_FROM_INFERIOR_PID (0)
109 static int may_switch_from_inferior_pid
= MAY_SWITCH_FROM_INFERIOR_PID
;
111 /* This is true for configurations that may follow through execl() and
112 similar functions. At present this is only true for HP-UX native. */
114 #ifndef MAY_FOLLOW_EXEC
115 #define MAY_FOLLOW_EXEC (0)
118 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
120 /* resume and wait_for_inferior use this to ensure that when
121 stepping over a hit breakpoint in a threaded application
122 only the thread that hit the breakpoint is stepped and the
123 other threads don't continue. This prevents having another
124 thread run past the breakpoint while it is temporarily
127 This is not thread-specific, so it isn't saved as part of
130 Versions of gdb which don't use the "step == this thread steps
131 and others continue" model but instead use the "step == this
132 thread steps and others wait" shouldn't do this. */
134 static int thread_step_needed
= 0;
136 /* This is true if thread_step_needed should actually be used. At
137 present this is only true for HP-UX native. */
139 #ifndef USE_THREAD_STEP_NEEDED
140 #define USE_THREAD_STEP_NEEDED (0)
143 static int use_thread_step_needed
= USE_THREAD_STEP_NEEDED
;
145 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
146 program. It needs to examine the jmp_buf argument and extract the PC
147 from it. The return value is non-zero on success, zero otherwise. */
149 #ifndef GET_LONGJMP_TARGET
150 #define GET_LONGJMP_TARGET(PC_ADDR) 0
154 /* Some machines have trampoline code that sits between function callers
155 and the actual functions themselves. If this machine doesn't have
156 such things, disable their processing. */
158 #ifndef SKIP_TRAMPOLINE_CODE
159 #define SKIP_TRAMPOLINE_CODE(pc) 0
162 /* Dynamic function trampolines are similar to solib trampolines in that they
163 are between the caller and the callee. The difference is that when you
164 enter a dynamic trampoline, you can't determine the callee's address. Some
165 (usually complex) code needs to run in the dynamic trampoline to figure out
166 the callee's address. This macro is usually called twice. First, when we
167 enter the trampoline (looks like a normal function call at that point). It
168 should return the PC of a point within the trampoline where the callee's
169 address is known. Second, when we hit the breakpoint, this routine returns
170 the callee's address. At that point, things proceed as per a step resume
173 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
174 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
177 /* If the program uses ELF-style shared libraries, then calls to
178 functions in shared libraries go through stubs, which live in a
179 table called the PLT (Procedure Linkage Table). The first time the
180 function is called, the stub sends control to the dynamic linker,
181 which looks up the function's real address, patches the stub so
182 that future calls will go directly to the function, and then passes
183 control to the function.
185 If we are stepping at the source level, we don't want to see any of
186 this --- we just want to skip over the stub and the dynamic linker.
187 The simple approach is to single-step until control leaves the
190 However, on some systems (e.g., Red Hat Linux 5.2) the dynamic
191 linker calls functions in the shared C library, so you can't tell
192 from the PC alone whether the dynamic linker is still running. In
193 this case, we use a step-resume breakpoint to get us past the
194 dynamic linker, as if we were using "next" to step over a function
197 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
198 linker code or not. Normally, this means we single-step. However,
199 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
200 address where we can place a step-resume breakpoint to get past the
201 linker's symbol resolution function.
203 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
204 pretty portable way, by comparing the PC against the address ranges
205 of the dynamic linker's sections.
207 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
208 it depends on internal details of the dynamic linker. It's usually
209 not too hard to figure out where to put a breakpoint, but it
210 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
211 sanity checking. If it can't figure things out, returning zero and
212 getting the (possibly confusing) stepping behavior is better than
213 signalling an error, which will obscure the change in the
216 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
217 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
220 #ifndef SKIP_SOLIB_RESOLVER
221 #define SKIP_SOLIB_RESOLVER(pc) 0
224 /* For SVR4 shared libraries, each call goes through a small piece of
225 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
226 to nonzero if we are current stopped in one of these. */
228 #ifndef IN_SOLIB_CALL_TRAMPOLINE
229 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
232 /* In some shared library schemes, the return path from a shared library
233 call may need to go through a trampoline too. */
235 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
236 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
239 /* This function returns TRUE if pc is the address of an instruction
240 that lies within the dynamic linker (such as the event hook, or the
243 This function must be used only when a dynamic linker event has
244 been caught, and the inferior is being stepped out of the hook, or
245 undefined results are guaranteed. */
247 #ifndef SOLIB_IN_DYNAMIC_LINKER
248 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
251 /* On MIPS16, a function that returns a floating point value may call
252 a library helper function to copy the return value to a floating point
253 register. The IGNORE_HELPER_CALL macro returns non-zero if we
254 should ignore (i.e. step over) this function call. */
255 #ifndef IGNORE_HELPER_CALL
256 #define IGNORE_HELPER_CALL(pc) 0
259 /* On some systems, the PC may be left pointing at an instruction that won't
260 actually be executed. This is usually indicated by a bit in the PSW. If
261 we find ourselves in such a state, then we step the target beyond the
262 nullified instruction before returning control to the user so as to avoid
265 #ifndef INSTRUCTION_NULLIFIED
266 #define INSTRUCTION_NULLIFIED 0
269 /* We can't step off a permanent breakpoint in the ordinary way, because we
270 can't remove it. Instead, we have to advance the PC to the next
271 instruction. This macro should expand to a pointer to a function that
272 does that, or zero if we have no such function. If we don't have a
273 definition for it, we have to report an error. */
274 #ifndef SKIP_PERMANENT_BREAKPOINT
275 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
277 default_skip_permanent_breakpoint ()
280 fprintf_filtered (gdb_stderr
, "\
281 The program is stopped at a permanent breakpoint, but GDB does not know\n\
282 how to step past a permanent breakpoint on this architecture. Try using\n\
283 a command like `return' or `jump' to continue execution.\n");
284 return_to_top_level (RETURN_ERROR
);
289 /* Convert the #defines into values. This is temporary until wfi control
290 flow is completely sorted out. */
292 #ifndef HAVE_STEPPABLE_WATCHPOINT
293 #define HAVE_STEPPABLE_WATCHPOINT 0
295 #undef HAVE_STEPPABLE_WATCHPOINT
296 #define HAVE_STEPPABLE_WATCHPOINT 1
299 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
300 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
302 #undef HAVE_NONSTEPPABLE_WATCHPOINT
303 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
306 #ifndef HAVE_CONTINUABLE_WATCHPOINT
307 #define HAVE_CONTINUABLE_WATCHPOINT 0
309 #undef HAVE_CONTINUABLE_WATCHPOINT
310 #define HAVE_CONTINUABLE_WATCHPOINT 1
313 /* Tables of how to react to signals; the user sets them. */
315 static unsigned char *signal_stop
;
316 static unsigned char *signal_print
;
317 static unsigned char *signal_program
;
319 #define SET_SIGS(nsigs,sigs,flags) \
321 int signum = (nsigs); \
322 while (signum-- > 0) \
323 if ((sigs)[signum]) \
324 (flags)[signum] = 1; \
327 #define UNSET_SIGS(nsigs,sigs,flags) \
329 int signum = (nsigs); \
330 while (signum-- > 0) \
331 if ((sigs)[signum]) \
332 (flags)[signum] = 0; \
336 /* Command list pointer for the "stop" placeholder. */
338 static struct cmd_list_element
*stop_command
;
340 /* Nonzero if breakpoints are now inserted in the inferior. */
342 static int breakpoints_inserted
;
344 /* Function inferior was in as of last step command. */
346 static struct symbol
*step_start_function
;
348 /* Nonzero if we are expecting a trace trap and should proceed from it. */
350 static int trap_expected
;
353 /* Nonzero if we want to give control to the user when we're notified
354 of shared library events by the dynamic linker. */
355 static int stop_on_solib_events
;
359 /* Nonzero if the next time we try to continue the inferior, it will
360 step one instruction and generate a spurious trace trap.
361 This is used to compensate for a bug in HP-UX. */
363 static int trap_expected_after_continue
;
366 /* Nonzero means expecting a trace trap
367 and should stop the inferior and return silently when it happens. */
371 /* Nonzero means expecting a trap and caller will handle it themselves.
372 It is used after attach, due to attaching to a process;
373 when running in the shell before the child program has been exec'd;
374 and when running some kinds of remote stuff (FIXME?). */
376 int stop_soon_quietly
;
378 /* Nonzero if proceed is being used for a "finish" command or a similar
379 situation when stop_registers should be saved. */
381 int proceed_to_finish
;
383 /* Save register contents here when about to pop a stack dummy frame,
384 if-and-only-if proceed_to_finish is set.
385 Thus this contains the return value from the called function (assuming
386 values are returned in a register). */
388 char *stop_registers
;
390 /* Nonzero if program stopped due to error trying to insert breakpoints. */
392 static int breakpoints_failed
;
394 /* Nonzero after stop if current stack frame should be printed. */
396 static int stop_print_frame
;
398 static struct breakpoint
*step_resume_breakpoint
= NULL
;
399 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
401 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
402 interactions with an inferior that is running a kernel function
403 (aka, a system call or "syscall"). wait_for_inferior therefore
404 may have a need to know when the inferior is in a syscall. This
405 is a count of the number of inferior threads which are known to
406 currently be running in a syscall. */
407 static int number_of_threads_in_syscalls
;
409 /* This is used to remember when a fork, vfork or exec event
410 was caught by a catchpoint, and thus the event is to be
411 followed at the next resume of the inferior, and not
415 enum target_waitkind kind
;
425 char *execd_pathname
;
429 /* Some platforms don't allow us to do anything meaningful with a
430 vforked child until it has exec'd. Vforked processes on such
431 platforms can only be followed after they've exec'd.
433 When this is set to 0, a vfork can be immediately followed,
434 and an exec can be followed merely as an exec. When this is
435 set to 1, a vfork event has been seen, but cannot be followed
436 until the exec is seen.
438 (In the latter case, inferior_pid is still the parent of the
439 vfork, and pending_follow.fork_event.child_pid is the child. The
440 appropriate process is followed, according to the setting of
441 follow-fork-mode.) */
442 static int follow_vfork_when_exec
;
444 static char *follow_fork_mode_kind_names
[] =
446 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
447 kernel problem. It's also not terribly useful without a GUI to
448 help the user drive two debuggers. So for now, I'm disabling
450 "parent", "child", "both", "ask" };
452 "parent", "child", "ask"};
454 static char *follow_fork_mode_string
= NULL
;
458 follow_inferior_fork (int parent_pid
, int child_pid
, int has_forked
,
461 int followed_parent
= 0;
462 int followed_child
= 0;
464 /* Which process did the user want us to follow? */
466 savestring (follow_fork_mode_string
, strlen (follow_fork_mode_string
));
468 /* Or, did the user not know, and want us to ask? */
469 if (STREQ (follow_fork_mode_string
, "ask"))
471 char requested_mode
[100];
474 error ("\"ask\" mode NYI");
475 follow_mode
= savestring (requested_mode
, strlen (requested_mode
));
478 /* If we're to be following the parent, then detach from child_pid.
479 We're already following the parent, so need do nothing explicit
481 if (STREQ (follow_mode
, "parent"))
485 /* We're already attached to the parent, by default. */
487 /* Before detaching from the child, remove all breakpoints from
488 it. (This won't actually modify the breakpoint list, but will
489 physically remove the breakpoints from the child.) */
490 if (!has_vforked
|| !follow_vfork_when_exec
)
492 detach_breakpoints (child_pid
);
493 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
494 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
498 /* Detach from the child. */
501 target_require_detach (child_pid
, "", 1);
504 /* If we're to be following the child, then attach to it, detach
505 from inferior_pid, and set inferior_pid to child_pid. */
506 else if (STREQ (follow_mode
, "child"))
508 char child_pid_spelling
[100]; /* Arbitrary length. */
512 /* Before detaching from the parent, detach all breakpoints from
513 the child. But only if we're forking, or if we follow vforks
514 as soon as they happen. (If we're following vforks only when
515 the child has exec'd, then it's very wrong to try to write
516 back the "shadow contents" of inserted breakpoints now -- they
517 belong to the child's pre-exec'd a.out.) */
518 if (!has_vforked
|| !follow_vfork_when_exec
)
520 detach_breakpoints (child_pid
);
523 /* Before detaching from the parent, remove all breakpoints from it. */
524 remove_breakpoints ();
526 /* Also reset the solib inferior hook from the parent. */
527 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
528 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid
);
531 /* Detach from the parent. */
533 target_detach (NULL
, 1);
535 /* Attach to the child. */
536 inferior_pid
= child_pid
;
537 sprintf (child_pid_spelling
, "%d", child_pid
);
540 target_require_attach (child_pid_spelling
, 1);
542 /* Was there a step_resume breakpoint? (There was if the user
543 did a "next" at the fork() call.) If so, explicitly reset its
546 step_resumes are a form of bp that are made to be per-thread.
547 Since we created the step_resume bp when the parent process
548 was being debugged, and now are switching to the child process,
549 from the breakpoint package's viewpoint, that's a switch of
550 "threads". We must update the bp's notion of which thread
551 it is for, or it'll be ignored when it triggers... */
552 if (step_resume_breakpoint
&&
553 (!has_vforked
|| !follow_vfork_when_exec
))
554 breakpoint_re_set_thread (step_resume_breakpoint
);
556 /* Reinsert all breakpoints in the child. (The user may've set
557 breakpoints after catching the fork, in which case those
558 actually didn't get set in the child, but only in the parent.) */
559 if (!has_vforked
|| !follow_vfork_when_exec
)
561 breakpoint_re_set ();
562 insert_breakpoints ();
566 /* If we're to be following both parent and child, then fork ourselves,
567 and attach the debugger clone to the child. */
568 else if (STREQ (follow_mode
, "both"))
570 char pid_suffix
[100]; /* Arbitrary length. */
572 /* Clone ourselves to follow the child. This is the end of our
573 involvement with child_pid; our clone will take it from here... */
575 target_clone_and_follow_inferior (child_pid
, &followed_child
);
576 followed_parent
= !followed_child
;
578 /* We continue to follow the parent. To help distinguish the two
579 debuggers, though, both we and our clone will reset our prompts. */
580 sprintf (pid_suffix
, "[%d] ", inferior_pid
);
581 set_prompt (strcat (get_prompt (), pid_suffix
));
584 /* The parent and child of a vfork share the same address space.
585 Also, on some targets the order in which vfork and exec events
586 are received for parent in child requires some delicate handling
589 For instance, on ptrace-based HPUX we receive the child's vfork
590 event first, at which time the parent has been suspended by the
591 OS and is essentially untouchable until the child's exit or second
592 exec event arrives. At that time, the parent's vfork event is
593 delivered to us, and that's when we see and decide how to follow
594 the vfork. But to get to that point, we must continue the child
595 until it execs or exits. To do that smoothly, all breakpoints
596 must be removed from the child, in case there are any set between
597 the vfork() and exec() calls. But removing them from the child
598 also removes them from the parent, due to the shared-address-space
599 nature of a vfork'd parent and child. On HPUX, therefore, we must
600 take care to restore the bp's to the parent before we continue it.
601 Else, it's likely that we may not stop in the expected place. (The
602 worst scenario is when the user tries to step over a vfork() call;
603 the step-resume bp must be restored for the step to properly stop
604 in the parent after the call completes!)
606 Sequence of events, as reported to gdb from HPUX:
608 Parent Child Action for gdb to take
609 -------------------------------------------------------
610 1 VFORK Continue child
616 target_post_follow_vfork (parent_pid
,
622 pending_follow
.fork_event
.saw_parent_fork
= 0;
623 pending_follow
.fork_event
.saw_child_fork
= 0;
629 follow_fork (int parent_pid
, int child_pid
)
631 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
635 /* Forward declaration. */
636 static void follow_exec (int, char *);
639 follow_vfork (int parent_pid
, int child_pid
)
641 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
643 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
644 if (pending_follow
.fork_event
.saw_child_exec
&& (inferior_pid
== child_pid
))
646 pending_follow
.fork_event
.saw_child_exec
= 0;
647 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
648 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
649 free (pending_follow
.execd_pathname
);
654 follow_exec (int pid
, char *execd_pathname
)
657 struct target_ops
*tgt
;
659 if (!may_follow_exec
)
662 /* Did this exec() follow a vfork()? If so, we must follow the
663 vfork now too. Do it before following the exec. */
664 if (follow_vfork_when_exec
&&
665 (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
))
667 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
668 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
669 follow_vfork_when_exec
= 0;
670 saved_pid
= inferior_pid
;
672 /* Did we follow the parent? If so, we're done. If we followed
673 the child then we must also follow its exec(). */
674 if (inferior_pid
== pending_follow
.fork_event
.parent_pid
)
678 /* This is an exec event that we actually wish to pay attention to.
679 Refresh our symbol table to the newly exec'd program, remove any
682 If there are breakpoints, they aren't really inserted now,
683 since the exec() transformed our inferior into a fresh set
686 We want to preserve symbolic breakpoints on the list, since
687 we have hopes that they can be reset after the new a.out's
688 symbol table is read.
690 However, any "raw" breakpoints must be removed from the list
691 (e.g., the solib bp's), since their address is probably invalid
694 And, we DON'T want to call delete_breakpoints() here, since
695 that may write the bp's "shadow contents" (the instruction
696 value that was overwritten witha TRAP instruction). Since
697 we now have a new a.out, those shadow contents aren't valid. */
698 update_breakpoints_after_exec ();
700 /* If there was one, it's gone now. We cannot truly step-to-next
701 statement through an exec(). */
702 step_resume_breakpoint
= NULL
;
703 step_range_start
= 0;
706 /* If there was one, it's gone now. */
707 through_sigtramp_breakpoint
= NULL
;
709 /* What is this a.out's name? */
710 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
712 /* We've followed the inferior through an exec. Therefore, the
713 inferior has essentially been killed & reborn. */
715 /* First collect the run target in effect. */
716 tgt
= find_run_target ();
717 /* If we can't find one, things are in a very strange state... */
719 error ("Could find run target to save before following exec");
721 gdb_flush (gdb_stdout
);
722 target_mourn_inferior ();
723 inferior_pid
= saved_pid
; /* Because mourn_inferior resets inferior_pid. */
726 /* That a.out is now the one to use. */
727 exec_file_attach (execd_pathname
, 0);
729 /* And also is where symbols can be found. */
730 symbol_file_command (execd_pathname
, 0);
732 /* Reset the shared library package. This ensures that we get
733 a shlib event when the child reaches "_start", at which point
734 the dld will have had a chance to initialize the child. */
735 #if defined(SOLIB_RESTART)
738 #ifdef SOLIB_CREATE_INFERIOR_HOOK
739 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid
);
742 /* Reinsert all breakpoints. (Those which were symbolic have
743 been reset to the proper address in the new a.out, thanks
744 to symbol_file_command...) */
745 insert_breakpoints ();
747 /* The next resume of this inferior should bring it to the shlib
748 startup breakpoints. (If the user had also set bp's on
749 "main" from the old (parent) process, then they'll auto-
750 matically get reset there in the new process.) */
753 /* Non-zero if we just simulating a single-step. This is needed
754 because we cannot remove the breakpoints in the inferior process
755 until after the `wait' in `wait_for_inferior'. */
756 static int singlestep_breakpoints_inserted_p
= 0;
759 /* Things to clean up if we QUIT out of resume (). */
762 resume_cleanups (int arg
)
767 static char schedlock_off
[] = "off";
768 static char schedlock_on
[] = "on";
769 static char schedlock_step
[] = "step";
770 static char *scheduler_mode
= schedlock_off
;
771 static char *scheduler_enums
[] =
772 {schedlock_off
, schedlock_on
, schedlock_step
};
775 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
777 if (c
->type
== set_cmd
)
778 if (!target_can_lock_scheduler
)
780 scheduler_mode
= schedlock_off
;
781 error ("Target '%s' cannot support this command.",
789 /* Resume the inferior, but allow a QUIT. This is useful if the user
790 wants to interrupt some lengthy single-stepping operation
791 (for child processes, the SIGINT goes to the inferior, and so
792 we get a SIGINT random_signal, but for remote debugging and perhaps
793 other targets, that's not true).
795 STEP nonzero if we should step (zero to continue instead).
796 SIG is the signal to give the inferior (zero for none). */
798 resume (int step
, enum target_signal sig
)
800 int should_resume
= 1;
801 struct cleanup
*old_cleanups
= make_cleanup ((make_cleanup_func
)
805 #ifdef CANNOT_STEP_BREAKPOINT
806 /* Most targets can step a breakpoint instruction, thus executing it
807 normally. But if this one cannot, just continue and we will hit
809 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
813 /* Normally, by the time we reach `resume', the breakpoints are either
814 removed or inserted, as appropriate. The exception is if we're sitting
815 at a permanent breakpoint; we need to step over it, but permanent
816 breakpoints can't be removed. So we have to test for it here. */
817 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
818 SKIP_PERMANENT_BREAKPOINT ();
820 if (SOFTWARE_SINGLE_STEP_P
&& step
)
822 /* Do it the hard way, w/temp breakpoints */
823 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
824 /* ...and don't ask hardware to do it. */
826 /* and do not pull these breakpoints until after a `wait' in
827 `wait_for_inferior' */
828 singlestep_breakpoints_inserted_p
= 1;
831 /* Handle any optimized stores to the inferior NOW... */
832 #ifdef DO_DEFERRED_STORES
836 /* If there were any forks/vforks/execs that were caught and are
837 now to be followed, then do so. */
838 switch (pending_follow
.kind
)
840 case (TARGET_WAITKIND_FORKED
):
841 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
842 follow_fork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
845 case (TARGET_WAITKIND_VFORKED
):
847 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
849 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
850 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
852 /* Did we follow the child, but not yet see the child's exec event?
853 If so, then it actually ought to be waiting for us; we respond to
854 parent vfork events. We don't actually want to resume the child
855 in this situation; we want to just get its exec event. */
856 if (!saw_child_exec
&&
857 (inferior_pid
== pending_follow
.fork_event
.child_pid
))
862 case (TARGET_WAITKIND_EXECD
):
863 /* If we saw a vfork event but couldn't follow it until we saw
864 an exec, then now might be the time! */
865 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
866 /* follow_exec is called as soon as the exec event is seen. */
873 /* Install inferior's terminal modes. */
874 target_terminal_inferior ();
878 if (use_thread_step_needed
&& thread_step_needed
)
880 /* We stopped on a BPT instruction;
881 don't continue other threads and
882 just step this thread. */
883 thread_step_needed
= 0;
885 if (!breakpoint_here_p (read_pc ()))
887 /* Breakpoint deleted: ok to do regular resume
888 where all the threads either step or continue. */
889 target_resume (-1, step
, sig
);
895 warning ("Internal error, changing continue to step.");
896 remove_breakpoints ();
897 breakpoints_inserted
= 0;
902 target_resume (inferior_pid
, step
, sig
);
907 /* Vanilla resume. */
909 if ((scheduler_mode
== schedlock_on
) ||
910 (scheduler_mode
== schedlock_step
&& step
!= 0))
911 target_resume (inferior_pid
, step
, sig
);
913 target_resume (-1, step
, sig
);
917 discard_cleanups (old_cleanups
);
921 /* Clear out all variables saying what to do when inferior is continued.
922 First do this, then set the ones you want, then call `proceed'. */
925 clear_proceed_status (void)
928 step_range_start
= 0;
930 step_frame_address
= 0;
931 step_over_calls
= -1;
933 stop_soon_quietly
= 0;
934 proceed_to_finish
= 0;
935 breakpoint_proceeded
= 1; /* We're about to proceed... */
937 /* Discard any remaining commands or status from previous stop. */
938 bpstat_clear (&stop_bpstat
);
941 /* Basic routine for continuing the program in various fashions.
943 ADDR is the address to resume at, or -1 for resume where stopped.
944 SIGGNAL is the signal to give it, or 0 for none,
945 or -1 for act according to how it stopped.
946 STEP is nonzero if should trap after one instruction.
947 -1 means return after that and print nothing.
948 You should probably set various step_... variables
949 before calling here, if you are stepping.
951 You should call clear_proceed_status before calling proceed. */
954 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
959 step_start_function
= find_pc_function (read_pc ());
963 if (addr
== (CORE_ADDR
) -1)
965 /* If there is a breakpoint at the address we will resume at,
966 step one instruction before inserting breakpoints
967 so that we do not stop right away (and report a second
968 hit at this breakpoint). */
970 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
973 #ifndef STEP_SKIPS_DELAY
974 #define STEP_SKIPS_DELAY(pc) (0)
975 #define STEP_SKIPS_DELAY_P (0)
977 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
978 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
979 is slow (it needs to read memory from the target). */
980 if (STEP_SKIPS_DELAY_P
981 && breakpoint_here_p (read_pc () + 4)
982 && STEP_SKIPS_DELAY (read_pc ()))
989 /* New address; we don't need to single-step a thread
990 over a breakpoint we just hit, 'cause we aren't
991 continuing from there.
993 It's not worth worrying about the case where a user
994 asks for a "jump" at the current PC--if they get the
995 hiccup of re-hiting a hit breakpoint, what else do
997 thread_step_needed
= 0;
1000 #ifdef PREPARE_TO_PROCEED
1001 /* In a multi-threaded task we may select another thread
1002 and then continue or step.
1004 But if the old thread was stopped at a breakpoint, it
1005 will immediately cause another breakpoint stop without
1006 any execution (i.e. it will report a breakpoint hit
1007 incorrectly). So we must step over it first.
1009 PREPARE_TO_PROCEED checks the current thread against the thread
1010 that reported the most recent event. If a step-over is required
1011 it returns TRUE and sets the current thread to the old thread. */
1012 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
1015 thread_step_needed
= 1;
1018 #endif /* PREPARE_TO_PROCEED */
1021 if (trap_expected_after_continue
)
1023 /* If (step == 0), a trap will be automatically generated after
1024 the first instruction is executed. Force step one
1025 instruction to clear this condition. This should not occur
1026 if step is nonzero, but it is harmless in that case. */
1028 trap_expected_after_continue
= 0;
1030 #endif /* HP_OS_BUG */
1033 /* We will get a trace trap after one instruction.
1034 Continue it automatically and insert breakpoints then. */
1038 int temp
= insert_breakpoints ();
1041 print_sys_errmsg ("ptrace", temp
);
1042 error ("Cannot insert breakpoints.\n\
1043 The same program may be running in another process.");
1046 breakpoints_inserted
= 1;
1049 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1050 stop_signal
= siggnal
;
1051 /* If this signal should not be seen by program,
1052 give it zero. Used for debugging signals. */
1053 else if (!signal_program
[stop_signal
])
1054 stop_signal
= TARGET_SIGNAL_0
;
1056 annotate_starting ();
1058 /* Make sure that output from GDB appears before output from the
1060 gdb_flush (gdb_stdout
);
1062 /* Resume inferior. */
1063 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1065 /* Wait for it to stop (if not standalone)
1066 and in any case decode why it stopped, and act accordingly. */
1067 /* Do this only if we are not using the event loop, or if the target
1068 does not support asynchronous execution. */
1069 if (!event_loop_p
|| !target_can_async_p ())
1071 wait_for_inferior ();
1076 /* Record the pc and sp of the program the last time it stopped.
1077 These are just used internally by wait_for_inferior, but need
1078 to be preserved over calls to it and cleared when the inferior
1080 static CORE_ADDR prev_pc
;
1081 static CORE_ADDR prev_func_start
;
1082 static char *prev_func_name
;
1085 /* Start remote-debugging of a machine over a serial link. */
1090 init_thread_list ();
1091 init_wait_for_inferior ();
1092 stop_soon_quietly
= 1;
1095 /* Always go on waiting for the target, regardless of the mode. */
1096 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1097 indicate th wait_for_inferior that a target should timeout if
1098 nothing is returned (instead of just blocking). Because of this,
1099 targets expecting an immediate response need to, internally, set
1100 things up so that the target_wait() is forced to eventually
1102 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1103 differentiate to its caller what the state of the target is after
1104 the initial open has been performed. Here we're assuming that
1105 the target has stopped. It should be possible to eventually have
1106 target_open() return to the caller an indication that the target
1107 is currently running and GDB state should be set to the same as
1108 for an async run. */
1109 wait_for_inferior ();
1113 /* Initialize static vars when a new inferior begins. */
1116 init_wait_for_inferior (void)
1118 /* These are meaningless until the first time through wait_for_inferior. */
1120 prev_func_start
= 0;
1121 prev_func_name
= NULL
;
1124 trap_expected_after_continue
= 0;
1126 breakpoints_inserted
= 0;
1127 breakpoint_init_inferior (inf_starting
);
1129 /* Don't confuse first call to proceed(). */
1130 stop_signal
= TARGET_SIGNAL_0
;
1132 /* The first resume is not following a fork/vfork/exec. */
1133 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1134 pending_follow
.fork_event
.saw_parent_fork
= 0;
1135 pending_follow
.fork_event
.saw_child_fork
= 0;
1136 pending_follow
.fork_event
.saw_child_exec
= 0;
1138 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1139 number_of_threads_in_syscalls
= 0;
1141 clear_proceed_status ();
1145 delete_breakpoint_current_contents (void *arg
)
1147 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1148 if (*breakpointp
!= NULL
)
1150 delete_breakpoint (*breakpointp
);
1151 *breakpointp
= NULL
;
1155 /* This enum encodes possible reasons for doing a target_wait, so that
1156 wfi can call target_wait in one place. (Ultimately the call will be
1157 moved out of the infinite loop entirely.) */
1161 infwait_normal_state
,
1162 infwait_thread_hop_state
,
1163 infwait_nullified_state
,
1164 infwait_nonstep_watch_state
1167 /* This structure contains what used to be local variables in
1168 wait_for_inferior. Probably many of them can return to being
1169 locals in handle_inferior_event. */
1171 struct execution_control_state
1173 struct target_waitstatus ws
;
1174 struct target_waitstatus
*wp
;
1177 CORE_ADDR stop_func_start
;
1178 CORE_ADDR stop_func_end
;
1179 char *stop_func_name
;
1180 struct symtab_and_line sal
;
1181 int remove_breakpoints_on_following_step
;
1183 struct symtab
*current_symtab
;
1184 int handling_longjmp
; /* FIXME */
1186 int saved_inferior_pid
;
1188 int stepping_through_solib_after_catch
;
1189 bpstat stepping_through_solib_catchpoints
;
1190 int enable_hw_watchpoints_after_wait
;
1191 int stepping_through_sigtramp
;
1192 int new_thread_event
;
1193 struct target_waitstatus tmpstatus
;
1194 enum infwait_states infwait_state
;
1199 void init_execution_control_state (struct execution_control_state
* ecs
);
1201 void handle_inferior_event (struct execution_control_state
* ecs
);
1203 static void check_sigtramp2 (struct execution_control_state
*ecs
);
1204 static void step_into_function (struct execution_control_state
*ecs
);
1205 static void step_over_function (struct execution_control_state
*ecs
);
1206 static void stop_stepping (struct execution_control_state
*ecs
);
1207 static void prepare_to_wait (struct execution_control_state
*ecs
);
1208 static void keep_going (struct execution_control_state
*ecs
);
1210 /* Wait for control to return from inferior to debugger.
1211 If inferior gets a signal, we may decide to start it up again
1212 instead of returning. That is why there is a loop in this function.
1213 When this function actually returns it means the inferior
1214 should be left stopped and GDB should read more commands. */
1217 wait_for_inferior (void)
1219 struct cleanup
*old_cleanups
;
1220 struct execution_control_state ecss
;
1221 struct execution_control_state
*ecs
;
1223 old_cleanups
= make_cleanup (delete_breakpoint_current_contents
,
1224 &step_resume_breakpoint
);
1225 make_cleanup (delete_breakpoint_current_contents
,
1226 &through_sigtramp_breakpoint
);
1228 /* wfi still stays in a loop, so it's OK just to take the address of
1229 a local to get the ecs pointer. */
1232 /* Fill in with reasonable starting values. */
1233 init_execution_control_state (ecs
);
1235 thread_step_needed
= 0;
1237 /* We'll update this if & when we switch to a new thread. */
1238 if (may_switch_from_inferior_pid
)
1239 switched_from_inferior_pid
= inferior_pid
;
1241 overlay_cache_invalid
= 1;
1243 /* We have to invalidate the registers BEFORE calling target_wait
1244 because they can be loaded from the target while in target_wait.
1245 This makes remote debugging a bit more efficient for those
1246 targets that provide critical registers as part of their normal
1247 status mechanism. */
1249 registers_changed ();
1253 if (target_wait_hook
)
1254 ecs
->pid
= target_wait_hook (ecs
->waiton_pid
, ecs
->wp
);
1256 ecs
->pid
= target_wait (ecs
->waiton_pid
, ecs
->wp
);
1258 /* Now figure out what to do with the result of the result. */
1259 handle_inferior_event (ecs
);
1261 if (!ecs
->wait_some_more
)
1264 do_cleanups (old_cleanups
);
1267 /* Asynchronous version of wait_for_inferior. It is called by the
1268 event loop whenever a change of state is detected on the file
1269 descriptor corresponding to the target. It can be called more than
1270 once to complete a single execution command. In such cases we need
1271 to keep the state in a global variable ASYNC_ECSS. If it is the
1272 last time that this function is called for a single execution
1273 command, then report to the user that the inferior has stopped, and
1274 do the necessary cleanups. */
1276 struct execution_control_state async_ecss
;
1277 struct execution_control_state
*async_ecs
;
1280 fetch_inferior_event (client_data
)
1283 static struct cleanup
*old_cleanups
;
1285 async_ecs
= &async_ecss
;
1287 if (!async_ecs
->wait_some_more
)
1289 old_cleanups
= make_exec_cleanup (delete_breakpoint_current_contents
,
1290 &step_resume_breakpoint
);
1291 make_exec_cleanup (delete_breakpoint_current_contents
,
1292 &through_sigtramp_breakpoint
);
1294 /* Fill in with reasonable starting values. */
1295 init_execution_control_state (async_ecs
);
1297 thread_step_needed
= 0;
1299 /* We'll update this if & when we switch to a new thread. */
1300 if (may_switch_from_inferior_pid
)
1301 switched_from_inferior_pid
= inferior_pid
;
1303 overlay_cache_invalid
= 1;
1305 /* We have to invalidate the registers BEFORE calling target_wait
1306 because they can be loaded from the target while in target_wait.
1307 This makes remote debugging a bit more efficient for those
1308 targets that provide critical registers as part of their normal
1309 status mechanism. */
1311 registers_changed ();
1314 if (target_wait_hook
)
1315 async_ecs
->pid
= target_wait_hook (async_ecs
->waiton_pid
, async_ecs
->wp
);
1317 async_ecs
->pid
= target_wait (async_ecs
->waiton_pid
, async_ecs
->wp
);
1319 /* Now figure out what to do with the result of the result. */
1320 handle_inferior_event (async_ecs
);
1322 if (!async_ecs
->wait_some_more
)
1324 /* Do only the cleanups that have been added by this
1325 function. Let the continuations for the commands do the rest,
1326 if there are any. */
1327 do_exec_cleanups (old_cleanups
);
1329 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1333 /* Prepare an execution control state for looping through a
1334 wait_for_inferior-type loop. */
1337 init_execution_control_state (struct execution_control_state
*ecs
)
1339 ecs
->random_signal
= 0;
1340 ecs
->remove_breakpoints_on_following_step
= 0;
1341 ecs
->handling_longjmp
= 0; /* FIXME */
1342 ecs
->update_step_sp
= 0;
1343 ecs
->stepping_through_solib_after_catch
= 0;
1344 ecs
->stepping_through_solib_catchpoints
= NULL
;
1345 ecs
->enable_hw_watchpoints_after_wait
= 0;
1346 ecs
->stepping_through_sigtramp
= 0;
1347 ecs
->sal
= find_pc_line (prev_pc
, 0);
1348 ecs
->current_line
= ecs
->sal
.line
;
1349 ecs
->current_symtab
= ecs
->sal
.symtab
;
1350 ecs
->infwait_state
= infwait_normal_state
;
1351 ecs
->waiton_pid
= -1;
1352 ecs
->wp
= &(ecs
->ws
);
1355 /* Call this function before setting step_resume_breakpoint, as a
1356 sanity check. There should never be more than one step-resume
1357 breakpoint per thread, so we should never be setting a new
1358 step_resume_breakpoint when one is already active. */
1360 check_for_old_step_resume_breakpoint (void)
1362 if (step_resume_breakpoint
)
1363 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1366 /* Given an execution control state that has been freshly filled in
1367 by an event from the inferior, figure out what it means and take
1368 appropriate action. */
1371 handle_inferior_event (struct execution_control_state
*ecs
)
1374 int stepped_after_stopped_by_watchpoint
;
1376 /* Keep this extra brace for now, minimizes diffs. */
1378 switch (ecs
->infwait_state
)
1380 case infwait_normal_state
:
1381 /* Since we've done a wait, we have a new event. Don't
1382 carry over any expectations about needing to step over a
1384 thread_step_needed
= 0;
1386 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1387 is serviced in this loop, below. */
1388 if (ecs
->enable_hw_watchpoints_after_wait
)
1390 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid
);
1391 ecs
->enable_hw_watchpoints_after_wait
= 0;
1393 stepped_after_stopped_by_watchpoint
= 0;
1396 case infwait_thread_hop_state
:
1397 insert_breakpoints ();
1399 /* We need to restart all the threads now,
1400 * unles we're running in scheduler-locked mode.
1401 * FIXME: shouldn't we look at currently_stepping ()?
1403 if (scheduler_mode
== schedlock_on
)
1404 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1406 target_resume (-1, 0, TARGET_SIGNAL_0
);
1407 ecs
->infwait_state
= infwait_normal_state
;
1408 prepare_to_wait (ecs
);
1411 case infwait_nullified_state
:
1414 case infwait_nonstep_watch_state
:
1415 insert_breakpoints ();
1417 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1418 handle things like signals arriving and other things happening
1419 in combination correctly? */
1420 stepped_after_stopped_by_watchpoint
= 1;
1423 ecs
->infwait_state
= infwait_normal_state
;
1425 flush_cached_frames ();
1427 /* If it's a new process, add it to the thread database */
1429 ecs
->new_thread_event
= ((ecs
->pid
!= inferior_pid
) && !in_thread_list (ecs
->pid
));
1431 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1432 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1433 && ecs
->new_thread_event
)
1435 add_thread (ecs
->pid
);
1437 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs
->pid
));
1440 /* NOTE: This block is ONLY meant to be invoked in case of a
1441 "thread creation event"! If it is invoked for any other
1442 sort of event (such as a new thread landing on a breakpoint),
1443 the event will be discarded, which is almost certainly
1446 To avoid this, the low-level module (eg. target_wait)
1447 should call in_thread_list and add_thread, so that the
1448 new thread is known by the time we get here. */
1450 /* We may want to consider not doing a resume here in order
1451 to give the user a chance to play with the new thread.
1452 It might be good to make that a user-settable option. */
1454 /* At this point, all threads are stopped (happens
1455 automatically in either the OS or the native code).
1456 Therefore we need to continue all threads in order to
1459 target_resume (-1, 0, TARGET_SIGNAL_0
);
1460 prepare_to_wait (ecs
);
1465 switch (ecs
->ws
.kind
)
1467 case TARGET_WAITKIND_LOADED
:
1468 /* Ignore gracefully during startup of the inferior, as it
1469 might be the shell which has just loaded some objects,
1470 otherwise add the symbols for the newly loaded objects. */
1472 if (!stop_soon_quietly
)
1474 /* Remove breakpoints, SOLIB_ADD might adjust
1475 breakpoint addresses via breakpoint_re_set. */
1476 if (breakpoints_inserted
)
1477 remove_breakpoints ();
1479 /* Check for any newly added shared libraries if we're
1480 supposed to be adding them automatically. */
1483 /* Switch terminal for any messages produced by
1484 breakpoint_re_set. */
1485 target_terminal_ours_for_output ();
1486 SOLIB_ADD (NULL
, 0, NULL
);
1487 target_terminal_inferior ();
1490 /* Reinsert breakpoints and continue. */
1491 if (breakpoints_inserted
)
1492 insert_breakpoints ();
1495 resume (0, TARGET_SIGNAL_0
);
1496 prepare_to_wait (ecs
);
1499 case TARGET_WAITKIND_SPURIOUS
:
1500 resume (0, TARGET_SIGNAL_0
);
1501 prepare_to_wait (ecs
);
1504 case TARGET_WAITKIND_EXITED
:
1505 target_terminal_ours (); /* Must do this before mourn anyway */
1506 annotate_exited (ecs
->ws
.value
.integer
);
1507 if (ecs
->ws
.value
.integer
)
1508 printf_filtered ("\nProgram exited with code 0%o.\n",
1509 (unsigned int) ecs
->ws
.value
.integer
);
1511 printf_filtered ("\nProgram exited normally.\n");
1513 /* Record the exit code in the convenience variable $_exitcode, so
1514 that the user can inspect this again later. */
1515 set_internalvar (lookup_internalvar ("_exitcode"),
1516 value_from_longest (builtin_type_int
,
1517 (LONGEST
) ecs
->ws
.value
.integer
));
1518 gdb_flush (gdb_stdout
);
1519 target_mourn_inferior ();
1520 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P */
1521 stop_print_frame
= 0;
1522 stop_stepping (ecs
);
1525 case TARGET_WAITKIND_SIGNALLED
:
1526 stop_print_frame
= 0;
1527 stop_signal
= ecs
->ws
.value
.sig
;
1528 target_terminal_ours (); /* Must do this before mourn anyway */
1529 annotate_signalled ();
1531 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1532 mean it is already dead? This has been here since GDB 2.8, so
1533 perhaps it means rms didn't understand unix waitstatuses?
1534 For the moment I'm just kludging around this in remote.c
1535 rather than trying to change it here --kingdon, 5 Dec 1994. */
1536 target_kill (); /* kill mourns as well */
1538 printf_filtered ("\nProgram terminated with signal ");
1539 annotate_signal_name ();
1540 printf_filtered ("%s", target_signal_to_name (stop_signal
));
1541 annotate_signal_name_end ();
1542 printf_filtered (", ");
1543 annotate_signal_string ();
1544 printf_filtered ("%s", target_signal_to_string (stop_signal
));
1545 annotate_signal_string_end ();
1546 printf_filtered (".\n");
1548 printf_filtered ("The program no longer exists.\n");
1549 gdb_flush (gdb_stdout
);
1550 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P */
1551 stop_stepping (ecs
);
1554 /* The following are the only cases in which we keep going;
1555 the above cases end in a continue or goto. */
1556 case TARGET_WAITKIND_FORKED
:
1557 stop_signal
= TARGET_SIGNAL_TRAP
;
1558 pending_follow
.kind
= ecs
->ws
.kind
;
1560 /* Ignore fork events reported for the parent; we're only
1561 interested in reacting to forks of the child. Note that
1562 we expect the child's fork event to be available if we
1563 waited for it now. */
1564 if (inferior_pid
== ecs
->pid
)
1566 pending_follow
.fork_event
.saw_parent_fork
= 1;
1567 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1568 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1569 prepare_to_wait (ecs
);
1574 pending_follow
.fork_event
.saw_child_fork
= 1;
1575 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1576 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1579 stop_pc
= read_pc_pid (ecs
->pid
);
1580 ecs
->saved_inferior_pid
= inferior_pid
;
1581 inferior_pid
= ecs
->pid
;
1582 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1583 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1584 inferior_pid
= ecs
->saved_inferior_pid
;
1585 goto process_event_stop_test
;
1587 /* If this a platform which doesn't allow a debugger to touch a
1588 vfork'd inferior until after it exec's, then we'd best keep
1589 our fingers entirely off the inferior, other than continuing
1590 it. This has the unfortunate side-effect that catchpoints
1591 of vforks will be ignored. But since the platform doesn't
1592 allow the inferior be touched at vfork time, there's really
1594 case TARGET_WAITKIND_VFORKED
:
1595 stop_signal
= TARGET_SIGNAL_TRAP
;
1596 pending_follow
.kind
= ecs
->ws
.kind
;
1598 /* Is this a vfork of the parent? If so, then give any
1599 vfork catchpoints a chance to trigger now. (It's
1600 dangerous to do so if the child canot be touched until
1601 it execs, and the child has not yet exec'd. We probably
1602 should warn the user to that effect when the catchpoint
1604 if (ecs
->pid
== inferior_pid
)
1606 pending_follow
.fork_event
.saw_parent_fork
= 1;
1607 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1608 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1611 /* If we've seen the child's vfork event but cannot really touch
1612 the child until it execs, then we must continue the child now.
1613 Else, give any vfork catchpoints a chance to trigger now. */
1616 pending_follow
.fork_event
.saw_child_fork
= 1;
1617 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1618 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1619 target_post_startup_inferior (pending_follow
.fork_event
.child_pid
);
1620 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1621 if (follow_vfork_when_exec
)
1623 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1624 prepare_to_wait (ecs
);
1629 stop_pc
= read_pc ();
1630 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1631 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1632 goto process_event_stop_test
;
1634 case TARGET_WAITKIND_EXECD
:
1635 stop_signal
= TARGET_SIGNAL_TRAP
;
1637 /* Is this a target which reports multiple exec events per actual
1638 call to exec()? (HP-UX using ptrace does, for example.) If so,
1639 ignore all but the last one. Just resume the exec'r, and wait
1640 for the next exec event. */
1641 if (inferior_ignoring_leading_exec_events
)
1643 inferior_ignoring_leading_exec_events
--;
1644 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1645 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.parent_pid
);
1646 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1647 prepare_to_wait (ecs
);
1650 inferior_ignoring_leading_exec_events
=
1651 target_reported_exec_events_per_exec_call () - 1;
1653 pending_follow
.execd_pathname
=
1654 savestring (ecs
->ws
.value
.execd_pathname
,
1655 strlen (ecs
->ws
.value
.execd_pathname
));
1657 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1658 child of a vfork exec?
1660 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1661 HP-UX, events associated with a vforking inferior come in
1662 threes: a vfork event for the child (always first), followed
1663 a vfork event for the parent and an exec event for the child.
1664 The latter two can come in either order.
1666 If we get the parent vfork event first, life's good: We follow
1667 either the parent or child, and then the child's exec event is
1670 But if we get the child's exec event first, then we delay
1671 responding to it until we handle the parent's vfork. Because,
1672 otherwise we can't satisfy a "catch vfork". */
1673 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1675 pending_follow
.fork_event
.saw_child_exec
= 1;
1677 /* On some targets, the child must be resumed before
1678 the parent vfork event is delivered. A single-step
1680 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1681 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1682 /* We expect the parent vfork event to be available now. */
1683 prepare_to_wait (ecs
);
1687 /* This causes the eventpoints and symbol table to be reset. Must
1688 do this now, before trying to determine whether to stop. */
1689 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
1690 free (pending_follow
.execd_pathname
);
1692 stop_pc
= read_pc_pid (ecs
->pid
);
1693 ecs
->saved_inferior_pid
= inferior_pid
;
1694 inferior_pid
= ecs
->pid
;
1695 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1696 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1697 inferior_pid
= ecs
->saved_inferior_pid
;
1698 goto process_event_stop_test
;
1700 /* These syscall events are returned on HP-UX, as part of its
1701 implementation of page-protection-based "hardware" watchpoints.
1702 HP-UX has unfortunate interactions between page-protections and
1703 some system calls. Our solution is to disable hardware watches
1704 when a system call is entered, and reenable them when the syscall
1705 completes. The downside of this is that we may miss the precise
1706 point at which a watched piece of memory is modified. "Oh well."
1708 Note that we may have multiple threads running, which may each
1709 enter syscalls at roughly the same time. Since we don't have a
1710 good notion currently of whether a watched piece of memory is
1711 thread-private, we'd best not have any page-protections active
1712 when any thread is in a syscall. Thus, we only want to reenable
1713 hardware watches when no threads are in a syscall.
1715 Also, be careful not to try to gather much state about a thread
1716 that's in a syscall. It's frequently a losing proposition. */
1717 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1718 number_of_threads_in_syscalls
++;
1719 if (number_of_threads_in_syscalls
== 1)
1721 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid
);
1723 resume (0, TARGET_SIGNAL_0
);
1724 prepare_to_wait (ecs
);
1727 /* Before examining the threads further, step this thread to
1728 get it entirely out of the syscall. (We get notice of the
1729 event when the thread is just on the verge of exiting a
1730 syscall. Stepping one instruction seems to get it back
1733 Note that although the logical place to reenable h/w watches
1734 is here, we cannot. We cannot reenable them before stepping
1735 the thread (this causes the next wait on the thread to hang).
1737 Nor can we enable them after stepping until we've done a wait.
1738 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1739 here, which will be serviced immediately after the target
1741 case TARGET_WAITKIND_SYSCALL_RETURN
:
1742 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1744 if (number_of_threads_in_syscalls
> 0)
1746 number_of_threads_in_syscalls
--;
1747 ecs
->enable_hw_watchpoints_after_wait
=
1748 (number_of_threads_in_syscalls
== 0);
1750 prepare_to_wait (ecs
);
1753 case TARGET_WAITKIND_STOPPED
:
1754 stop_signal
= ecs
->ws
.value
.sig
;
1758 /* We may want to consider not doing a resume here in order to give
1759 the user a chance to play with the new thread. It might be good
1760 to make that a user-settable option. */
1762 /* At this point, all threads are stopped (happens automatically in
1763 either the OS or the native code). Therefore we need to continue
1764 all threads in order to make progress. */
1765 if (ecs
->new_thread_event
)
1767 target_resume (-1, 0, TARGET_SIGNAL_0
);
1768 prepare_to_wait (ecs
);
1772 stop_pc
= read_pc_pid (ecs
->pid
);
1774 /* See if a thread hit a thread-specific breakpoint that was meant for
1775 another thread. If so, then step that thread past the breakpoint,
1778 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1780 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1781 ecs
->random_signal
= 0;
1782 else if (breakpoints_inserted
1783 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1785 ecs
->random_signal
= 0;
1786 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1791 /* Saw a breakpoint, but it was hit by the wrong thread.
1793 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->pid
);
1795 remove_status
= remove_breakpoints ();
1796 /* Did we fail to remove breakpoints? If so, try
1797 to set the PC past the bp. (There's at least
1798 one situation in which we can fail to remove
1799 the bp's: On HP-UX's that use ttrace, we can't
1800 change the address space of a vforking child
1801 process until the child exits (well, okay, not
1802 then either :-) or execs. */
1803 if (remove_status
!= 0)
1805 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->pid
);
1809 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1810 /* FIXME: What if a signal arrives instead of the
1811 single-step happening? */
1813 ecs
->waiton_pid
= ecs
->pid
;
1814 ecs
->wp
= &(ecs
->ws
);
1815 ecs
->infwait_state
= infwait_thread_hop_state
;
1816 prepare_to_wait (ecs
);
1820 /* We need to restart all the threads now,
1821 * unles we're running in scheduler-locked mode.
1822 * FIXME: shouldn't we look at currently_stepping ()?
1824 if (scheduler_mode
== schedlock_on
)
1825 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1827 target_resume (-1, 0, TARGET_SIGNAL_0
);
1828 prepare_to_wait (ecs
);
1833 /* This breakpoint matches--either it is the right
1834 thread or it's a generic breakpoint for all threads.
1835 Remember that we'll need to step just _this_ thread
1836 on any following user continuation! */
1837 thread_step_needed
= 1;
1842 ecs
->random_signal
= 1;
1844 /* See if something interesting happened to the non-current thread. If
1845 so, then switch to that thread, and eventually give control back to
1848 Note that if there's any kind of pending follow (i.e., of a fork,
1849 vfork or exec), we don't want to do this now. Rather, we'll let
1850 the next resume handle it. */
1851 if ((ecs
->pid
!= inferior_pid
) &&
1852 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1856 /* If it's a random signal for a non-current thread, notify user
1857 if he's expressed an interest. */
1858 if (ecs
->random_signal
1859 && signal_print
[stop_signal
])
1861 /* ??rehrauer: I don't understand the rationale for this code. If the
1862 inferior will stop as a result of this signal, then the act of handling
1863 the stop ought to print a message that's couches the stoppage in user
1864 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1865 won't stop as a result of the signal -- i.e., if the signal is merely
1866 a side-effect of something GDB's doing "under the covers" for the
1867 user, such as stepping threads over a breakpoint they shouldn't stop
1868 for -- then the message seems to be a serious annoyance at best.
1870 For now, remove the message altogether. */
1873 target_terminal_ours_for_output ();
1874 printf_filtered ("\nProgram received signal %s, %s.\n",
1875 target_signal_to_name (stop_signal
),
1876 target_signal_to_string (stop_signal
));
1877 gdb_flush (gdb_stdout
);
1881 /* If it's not SIGTRAP and not a signal we want to stop for, then
1882 continue the thread. */
1884 if (stop_signal
!= TARGET_SIGNAL_TRAP
1885 && !signal_stop
[stop_signal
])
1888 target_terminal_inferior ();
1890 /* Clear the signal if it should not be passed. */
1891 if (signal_program
[stop_signal
] == 0)
1892 stop_signal
= TARGET_SIGNAL_0
;
1894 target_resume (ecs
->pid
, 0, stop_signal
);
1895 prepare_to_wait (ecs
);
1899 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1900 and fall into the rest of wait_for_inferior(). */
1902 /* Save infrun state for the old thread. */
1903 save_infrun_state (inferior_pid
, prev_pc
,
1904 prev_func_start
, prev_func_name
,
1905 trap_expected
, step_resume_breakpoint
,
1906 through_sigtramp_breakpoint
,
1907 step_range_start
, step_range_end
,
1908 step_frame_address
, ecs
->handling_longjmp
,
1910 ecs
->stepping_through_solib_after_catch
,
1911 ecs
->stepping_through_solib_catchpoints
,
1912 ecs
->stepping_through_sigtramp
);
1914 if (may_switch_from_inferior_pid
)
1915 switched_from_inferior_pid
= inferior_pid
;
1917 inferior_pid
= ecs
->pid
;
1919 /* Load infrun state for the new thread. */
1920 load_infrun_state (inferior_pid
, &prev_pc
,
1921 &prev_func_start
, &prev_func_name
,
1922 &trap_expected
, &step_resume_breakpoint
,
1923 &through_sigtramp_breakpoint
,
1924 &step_range_start
, &step_range_end
,
1925 &step_frame_address
, &ecs
->handling_longjmp
,
1927 &ecs
->stepping_through_solib_after_catch
,
1928 &ecs
->stepping_through_solib_catchpoints
,
1929 &ecs
->stepping_through_sigtramp
);
1932 context_hook (pid_to_thread_id (ecs
->pid
));
1934 printf_filtered ("[Switching to %s]\n", target_pid_to_str (ecs
->pid
));
1935 flush_cached_frames ();
1938 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1940 /* Pull the single step breakpoints out of the target. */
1941 SOFTWARE_SINGLE_STEP (0, 0);
1942 singlestep_breakpoints_inserted_p
= 0;
1945 /* If PC is pointing at a nullified instruction, then step beyond
1946 it so that the user won't be confused when GDB appears to be ready
1949 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1950 if (INSTRUCTION_NULLIFIED
)
1952 registers_changed ();
1953 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1955 /* We may have received a signal that we want to pass to
1956 the inferior; therefore, we must not clobber the waitstatus
1959 ecs
->infwait_state
= infwait_nullified_state
;
1960 ecs
->waiton_pid
= ecs
->pid
;
1961 ecs
->wp
= &(ecs
->tmpstatus
);
1962 prepare_to_wait (ecs
);
1966 /* It may not be necessary to disable the watchpoint to stop over
1967 it. For example, the PA can (with some kernel cooperation)
1968 single step over a watchpoint without disabling the watchpoint. */
1969 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1972 prepare_to_wait (ecs
);
1976 /* It is far more common to need to disable a watchpoint to step
1977 the inferior over it. FIXME. What else might a debug
1978 register or page protection watchpoint scheme need here? */
1979 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1981 /* At this point, we are stopped at an instruction which has
1982 attempted to write to a piece of memory under control of
1983 a watchpoint. The instruction hasn't actually executed
1984 yet. If we were to evaluate the watchpoint expression
1985 now, we would get the old value, and therefore no change
1986 would seem to have occurred.
1988 In order to make watchpoints work `right', we really need
1989 to complete the memory write, and then evaluate the
1990 watchpoint expression. The following code does that by
1991 removing the watchpoint (actually, all watchpoints and
1992 breakpoints), single-stepping the target, re-inserting
1993 watchpoints, and then falling through to let normal
1994 single-step processing handle proceed. Since this
1995 includes evaluating watchpoints, things will come to a
1996 stop in the correct manner. */
1998 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
2000 remove_breakpoints ();
2001 registers_changed ();
2002 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
); /* Single step */
2004 ecs
->waiton_pid
= ecs
->pid
;
2005 ecs
->wp
= &(ecs
->ws
);
2006 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2007 prepare_to_wait (ecs
);
2011 /* It may be possible to simply continue after a watchpoint. */
2012 if (HAVE_CONTINUABLE_WATCHPOINT
)
2013 STOPPED_BY_WATCHPOINT (ecs
->ws
);
2015 ecs
->stop_func_start
= 0;
2016 ecs
->stop_func_end
= 0;
2017 ecs
->stop_func_name
= 0;
2018 /* Don't care about return value; stop_func_start and stop_func_name
2019 will both be 0 if it doesn't work. */
2020 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2021 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2022 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
2023 ecs
->another_trap
= 0;
2024 bpstat_clear (&stop_bpstat
);
2026 stop_stack_dummy
= 0;
2027 stop_print_frame
= 1;
2028 ecs
->random_signal
= 0;
2029 stopped_by_random_signal
= 0;
2030 breakpoints_failed
= 0;
2032 /* Look at the cause of the stop, and decide what to do.
2033 The alternatives are:
2034 1) break; to really stop and return to the debugger,
2035 2) drop through to start up again
2036 (set ecs->another_trap to 1 to single step once)
2037 3) set ecs->random_signal to 1, and the decision between 1 and 2
2038 will be made according to the signal handling tables. */
2040 /* First, distinguish signals caused by the debugger from signals
2041 that have to do with the program's own actions.
2042 Note that breakpoint insns may cause SIGTRAP or SIGILL
2043 or SIGEMT, depending on the operating system version.
2044 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2045 and change it to SIGTRAP. */
2047 if (stop_signal
== TARGET_SIGNAL_TRAP
2048 || (breakpoints_inserted
&&
2049 (stop_signal
== TARGET_SIGNAL_ILL
2050 || stop_signal
== TARGET_SIGNAL_EMT
2052 || stop_soon_quietly
)
2054 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2056 stop_print_frame
= 0;
2057 stop_stepping (ecs
);
2060 if (stop_soon_quietly
)
2062 stop_stepping (ecs
);
2066 /* Don't even think about breakpoints
2067 if just proceeded over a breakpoint.
2069 However, if we are trying to proceed over a breakpoint
2070 and end up in sigtramp, then through_sigtramp_breakpoint
2071 will be set and we should check whether we've hit the
2073 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2074 && through_sigtramp_breakpoint
== NULL
)
2075 bpstat_clear (&stop_bpstat
);
2078 /* See if there is a breakpoint at the current PC. */
2079 stop_bpstat
= bpstat_stop_status
2081 /* Pass TRUE if our reason for stopping is something other
2082 than hitting a breakpoint. We do this by checking that
2083 1) stepping is going on and 2) we didn't hit a breakpoint
2084 in a signal handler without an intervening stop in
2085 sigtramp, which is detected by a new stack pointer value
2086 below any usual function calling stack adjustments. */
2087 (currently_stepping (ecs
)
2089 && INNER_THAN (read_sp (), (step_sp
- 16))))
2091 /* Following in case break condition called a
2093 stop_print_frame
= 1;
2096 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2098 = !(bpstat_explains_signal (stop_bpstat
)
2100 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2101 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2102 FRAME_FP (get_current_frame ())))
2103 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2108 = !(bpstat_explains_signal (stop_bpstat
)
2109 /* End of a stack dummy. Some systems (e.g. Sony
2110 news) give another signal besides SIGTRAP, so
2111 check here as well as above. */
2112 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2113 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2114 FRAME_FP (get_current_frame ())))
2116 if (!ecs
->random_signal
)
2117 stop_signal
= TARGET_SIGNAL_TRAP
;
2121 /* When we reach this point, we've pretty much decided
2122 that the reason for stopping must've been a random
2123 (unexpected) signal. */
2126 ecs
->random_signal
= 1;
2127 /* If a fork, vfork or exec event was seen, then there are two
2128 possible responses we can make:
2130 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2131 then we must stop now and issue a prompt. We will resume
2132 the inferior when the user tells us to.
2133 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2134 then we must resume the inferior now and keep checking.
2136 In either case, we must take appropriate steps to "follow" the
2137 the fork/vfork/exec when the inferior is resumed. For example,
2138 if follow-fork-mode is "child", then we must detach from the
2139 parent inferior and follow the new child inferior.
2141 In either case, setting pending_follow causes the next resume()
2142 to take the appropriate following action. */
2143 process_event_stop_test
:
2144 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2146 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2149 stop_signal
= TARGET_SIGNAL_0
;
2154 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2156 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2158 stop_signal
= TARGET_SIGNAL_0
;
2163 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2165 pending_follow
.kind
= ecs
->ws
.kind
;
2166 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2169 stop_signal
= TARGET_SIGNAL_0
;
2175 /* For the program's own signals, act according to
2176 the signal handling tables. */
2178 if (ecs
->random_signal
)
2180 /* Signal not for debugging purposes. */
2183 stopped_by_random_signal
= 1;
2185 if (signal_print
[stop_signal
])
2188 target_terminal_ours_for_output ();
2190 printf_filtered ("\nProgram received signal ");
2191 annotate_signal_name ();
2192 printf_filtered ("%s", target_signal_to_name (stop_signal
));
2193 annotate_signal_name_end ();
2194 printf_filtered (", ");
2195 annotate_signal_string ();
2196 printf_filtered ("%s", target_signal_to_string (stop_signal
));
2197 annotate_signal_string_end ();
2198 printf_filtered (".\n");
2199 gdb_flush (gdb_stdout
);
2201 if (signal_stop
[stop_signal
])
2203 stop_stepping (ecs
);
2206 /* If not going to stop, give terminal back
2207 if we took it away. */
2209 target_terminal_inferior ();
2211 /* Clear the signal if it should not be passed. */
2212 if (signal_program
[stop_signal
] == 0)
2213 stop_signal
= TARGET_SIGNAL_0
;
2215 /* I'm not sure whether this needs to be check_sigtramp2 or
2216 whether it could/should be keep_going.
2218 This used to jump to step_over_function if we are stepping,
2221 Suppose the user does a `next' over a function call, and while
2222 that call is in progress, the inferior receives a signal for
2223 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2224 that case, when we reach this point, there is already a
2225 step-resume breakpoint established, right where it should be:
2226 immediately after the function call the user is "next"-ing
2227 over. If we call step_over_function now, two bad things
2230 - we'll create a new breakpoint, at wherever the current
2231 frame's return address happens to be. That could be
2232 anywhere, depending on what function call happens to be on
2233 the top of the stack at that point. Point is, it's probably
2234 not where we need it.
2236 - the existing step-resume breakpoint (which is at the correct
2237 address) will get orphaned: step_resume_breakpoint will point
2238 to the new breakpoint, and the old step-resume breakpoint
2239 will never be cleaned up.
2241 The old behavior was meant to help HP-UX single-step out of
2242 sigtramps. It would place the new breakpoint at prev_pc, which
2243 was certainly wrong. I don't know the details there, so fixing
2244 this probably breaks that. As with anything else, it's up to
2245 the HP-UX maintainer to furnish a fix that doesn't break other
2246 platforms. --JimB, 20 May 1999 */
2247 check_sigtramp2 (ecs
);
2250 /* Handle cases caused by hitting a breakpoint. */
2252 CORE_ADDR jmp_buf_pc
;
2253 struct bpstat_what what
;
2255 what
= bpstat_what (stop_bpstat
);
2257 if (what
.call_dummy
)
2259 stop_stack_dummy
= 1;
2261 trap_expected_after_continue
= 1;
2265 switch (what
.main_action
)
2267 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2268 /* If we hit the breakpoint at longjmp, disable it for the
2269 duration of this command. Then, install a temporary
2270 breakpoint at the target of the jmp_buf. */
2271 disable_longjmp_breakpoint ();
2272 remove_breakpoints ();
2273 breakpoints_inserted
= 0;
2274 if (!GET_LONGJMP_TARGET (&jmp_buf_pc
))
2280 /* Need to blow away step-resume breakpoint, as it
2281 interferes with us */
2282 if (step_resume_breakpoint
!= NULL
)
2284 delete_breakpoint (step_resume_breakpoint
);
2285 step_resume_breakpoint
= NULL
;
2287 /* Not sure whether we need to blow this away too, but probably
2288 it is like the step-resume breakpoint. */
2289 if (through_sigtramp_breakpoint
!= NULL
)
2291 delete_breakpoint (through_sigtramp_breakpoint
);
2292 through_sigtramp_breakpoint
= NULL
;
2296 /* FIXME - Need to implement nested temporary breakpoints */
2297 if (step_over_calls
> 0)
2298 set_longjmp_resume_breakpoint (jmp_buf_pc
,
2299 get_current_frame ());
2302 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2303 ecs
->handling_longjmp
= 1; /* FIXME */
2307 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2308 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2309 remove_breakpoints ();
2310 breakpoints_inserted
= 0;
2312 /* FIXME - Need to implement nested temporary breakpoints */
2314 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2315 step_frame_address
)))
2317 ecs
->another_trap
= 1;
2322 disable_longjmp_breakpoint ();
2323 ecs
->handling_longjmp
= 0; /* FIXME */
2324 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2326 /* else fallthrough */
2328 case BPSTAT_WHAT_SINGLE
:
2329 if (breakpoints_inserted
)
2331 thread_step_needed
= 1;
2332 remove_breakpoints ();
2334 breakpoints_inserted
= 0;
2335 ecs
->another_trap
= 1;
2336 /* Still need to check other stuff, at least the case
2337 where we are stepping and step out of the right range. */
2340 case BPSTAT_WHAT_STOP_NOISY
:
2341 stop_print_frame
= 1;
2343 /* We are about to nuke the step_resume_breakpoint and
2344 through_sigtramp_breakpoint via the cleanup chain, so
2345 no need to worry about it here. */
2347 stop_stepping (ecs
);
2350 case BPSTAT_WHAT_STOP_SILENT
:
2351 stop_print_frame
= 0;
2353 /* We are about to nuke the step_resume_breakpoint and
2354 through_sigtramp_breakpoint via the cleanup chain, so
2355 no need to worry about it here. */
2357 stop_stepping (ecs
);
2360 case BPSTAT_WHAT_STEP_RESUME
:
2361 /* This proably demands a more elegant solution, but, yeah
2364 This function's use of the simple variable
2365 step_resume_breakpoint doesn't seem to accomodate
2366 simultaneously active step-resume bp's, although the
2367 breakpoint list certainly can.
2369 If we reach here and step_resume_breakpoint is already
2370 NULL, then apparently we have multiple active
2371 step-resume bp's. We'll just delete the breakpoint we
2372 stopped at, and carry on.
2374 Correction: what the code currently does is delete a
2375 step-resume bp, but it makes no effort to ensure that
2376 the one deleted is the one currently stopped at. MVS */
2378 if (step_resume_breakpoint
== NULL
)
2380 step_resume_breakpoint
=
2381 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2383 delete_breakpoint (step_resume_breakpoint
);
2384 step_resume_breakpoint
= NULL
;
2387 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2388 if (through_sigtramp_breakpoint
)
2389 delete_breakpoint (through_sigtramp_breakpoint
);
2390 through_sigtramp_breakpoint
= NULL
;
2392 /* If were waiting for a trap, hitting the step_resume_break
2393 doesn't count as getting it. */
2395 ecs
->another_trap
= 1;
2398 case BPSTAT_WHAT_CHECK_SHLIBS
:
2399 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2402 /* Remove breakpoints, we eventually want to step over the
2403 shlib event breakpoint, and SOLIB_ADD might adjust
2404 breakpoint addresses via breakpoint_re_set. */
2405 if (breakpoints_inserted
)
2406 remove_breakpoints ();
2407 breakpoints_inserted
= 0;
2409 /* Check for any newly added shared libraries if we're
2410 supposed to be adding them automatically. */
2413 /* Switch terminal for any messages produced by
2414 breakpoint_re_set. */
2415 target_terminal_ours_for_output ();
2416 SOLIB_ADD (NULL
, 0, NULL
);
2417 target_terminal_inferior ();
2420 /* Try to reenable shared library breakpoints, additional
2421 code segments in shared libraries might be mapped in now. */
2422 re_enable_breakpoints_in_shlibs ();
2424 /* If requested, stop when the dynamic linker notifies
2425 gdb of events. This allows the user to get control
2426 and place breakpoints in initializer routines for
2427 dynamically loaded objects (among other things). */
2428 if (stop_on_solib_events
)
2430 stop_print_frame
= 0;
2431 stop_stepping (ecs
);
2435 /* If we stopped due to an explicit catchpoint, then the
2436 (see above) call to SOLIB_ADD pulled in any symbols
2437 from a newly-loaded library, if appropriate.
2439 We do want the inferior to stop, but not where it is
2440 now, which is in the dynamic linker callback. Rather,
2441 we would like it stop in the user's program, just after
2442 the call that caused this catchpoint to trigger. That
2443 gives the user a more useful vantage from which to
2444 examine their program's state. */
2445 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2447 /* ??rehrauer: If I could figure out how to get the
2448 right return PC from here, we could just set a temp
2449 breakpoint and resume. I'm not sure we can without
2450 cracking open the dld's shared libraries and sniffing
2451 their unwind tables and text/data ranges, and that's
2452 not a terribly portable notion.
2454 Until that time, we must step the inferior out of the
2455 dld callback, and also out of the dld itself (and any
2456 code or stubs in libdld.sl, such as "shl_load" and
2457 friends) until we reach non-dld code. At that point,
2458 we can stop stepping. */
2459 bpstat_get_triggered_catchpoints (stop_bpstat
,
2460 &ecs
->stepping_through_solib_catchpoints
);
2461 ecs
->stepping_through_solib_after_catch
= 1;
2463 /* Be sure to lift all breakpoints, so the inferior does
2464 actually step past this point... */
2465 ecs
->another_trap
= 1;
2470 /* We want to step over this breakpoint, then keep going. */
2471 ecs
->another_trap
= 1;
2478 case BPSTAT_WHAT_LAST
:
2479 /* Not a real code, but listed here to shut up gcc -Wall. */
2481 case BPSTAT_WHAT_KEEP_CHECKING
:
2486 /* We come here if we hit a breakpoint but should not
2487 stop for it. Possibly we also were stepping
2488 and should stop for that. So fall through and
2489 test for stepping. But, if not stepping,
2492 /* Are we stepping to get the inferior out of the dynamic
2493 linker's hook (and possibly the dld itself) after catching
2495 if (ecs
->stepping_through_solib_after_catch
)
2497 #if defined(SOLIB_ADD)
2498 /* Have we reached our destination? If not, keep going. */
2499 if (SOLIB_IN_DYNAMIC_LINKER (ecs
->pid
, stop_pc
))
2501 ecs
->another_trap
= 1;
2506 /* Else, stop and report the catchpoint(s) whose triggering
2507 caused us to begin stepping. */
2508 ecs
->stepping_through_solib_after_catch
= 0;
2509 bpstat_clear (&stop_bpstat
);
2510 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2511 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2512 stop_print_frame
= 1;
2513 stop_stepping (ecs
);
2517 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2519 /* This is the old way of detecting the end of the stack dummy.
2520 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2521 handled above. As soon as we can test it on all of them, all
2522 architectures should define it. */
2524 /* If this is the breakpoint at the end of a stack dummy,
2525 just stop silently, unless the user was doing an si/ni, in which
2526 case she'd better know what she's doing. */
2528 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2529 FRAME_FP (get_current_frame ()))
2532 stop_print_frame
= 0;
2533 stop_stack_dummy
= 1;
2535 trap_expected_after_continue
= 1;
2537 stop_stepping (ecs
);
2542 if (step_resume_breakpoint
)
2544 /* Having a step-resume breakpoint overrides anything
2545 else having to do with stepping commands until
2546 that breakpoint is reached. */
2547 /* I'm not sure whether this needs to be check_sigtramp2 or
2548 whether it could/should be keep_going. */
2549 check_sigtramp2 (ecs
);
2554 if (step_range_end
== 0)
2556 /* Likewise if we aren't even stepping. */
2557 /* I'm not sure whether this needs to be check_sigtramp2 or
2558 whether it could/should be keep_going. */
2559 check_sigtramp2 (ecs
);
2564 /* If stepping through a line, keep going if still within it.
2566 Note that step_range_end is the address of the first instruction
2567 beyond the step range, and NOT the address of the last instruction
2569 if (stop_pc
>= step_range_start
2570 && stop_pc
< step_range_end
)
2572 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2573 So definately need to check for sigtramp here. */
2574 check_sigtramp2 (ecs
);
2579 /* We stepped out of the stepping range. */
2581 /* If we are stepping at the source level and entered the runtime
2582 loader dynamic symbol resolution code, we keep on single stepping
2583 until we exit the run time loader code and reach the callee's
2585 if (step_over_calls
< 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2587 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2589 if (pc_after_resolver
)
2591 /* Set up a step-resume breakpoint at the address
2592 indicated by SKIP_SOLIB_RESOLVER. */
2593 struct symtab_and_line sr_sal
;
2595 sr_sal
.pc
= pc_after_resolver
;
2597 check_for_old_step_resume_breakpoint ();
2598 step_resume_breakpoint
=
2599 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2600 if (breakpoints_inserted
)
2601 insert_breakpoints ();
2608 /* We can't update step_sp every time through the loop, because
2609 reading the stack pointer would slow down stepping too much.
2610 But we can update it every time we leave the step range. */
2611 ecs
->update_step_sp
= 1;
2613 /* Did we just take a signal? */
2614 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2615 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2616 && INNER_THAN (read_sp (), step_sp
))
2618 /* We've just taken a signal; go until we are back to
2619 the point where we took it and one more. */
2621 /* Note: The test above succeeds not only when we stepped
2622 into a signal handler, but also when we step past the last
2623 statement of a signal handler and end up in the return stub
2624 of the signal handler trampoline. To distinguish between
2625 these two cases, check that the frame is INNER_THAN the
2626 previous one below. pai/1997-09-11 */
2630 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2632 if (INNER_THAN (current_frame
, step_frame_address
))
2634 /* We have just taken a signal; go until we are back to
2635 the point where we took it and one more. */
2637 /* This code is needed at least in the following case:
2638 The user types "next" and then a signal arrives (before
2639 the "next" is done). */
2641 /* Note that if we are stopped at a breakpoint, then we need
2642 the step_resume breakpoint to override any breakpoints at
2643 the same location, so that we will still step over the
2644 breakpoint even though the signal happened. */
2645 struct symtab_and_line sr_sal
;
2648 sr_sal
.symtab
= NULL
;
2650 sr_sal
.pc
= prev_pc
;
2651 /* We could probably be setting the frame to
2652 step_frame_address; I don't think anyone thought to
2654 check_for_old_step_resume_breakpoint ();
2655 step_resume_breakpoint
=
2656 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2657 if (breakpoints_inserted
)
2658 insert_breakpoints ();
2662 /* We just stepped out of a signal handler and into
2663 its calling trampoline.
2665 Normally, we'd call step_over_function from
2666 here, but for some reason GDB can't unwind the
2667 stack correctly to find the real PC for the point
2668 user code where the signal trampoline will return
2669 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2670 But signal trampolines are pretty small stubs of
2671 code, anyway, so it's OK instead to just
2672 single-step out. Note: assuming such trampolines
2673 don't exhibit recursion on any platform... */
2674 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2675 &ecs
->stop_func_start
,
2676 &ecs
->stop_func_end
);
2677 /* Readjust stepping range */
2678 step_range_start
= ecs
->stop_func_start
;
2679 step_range_end
= ecs
->stop_func_end
;
2680 ecs
->stepping_through_sigtramp
= 1;
2685 /* If this is stepi or nexti, make sure that the stepping range
2686 gets us past that instruction. */
2687 if (step_range_end
== 1)
2688 /* FIXME: Does this run afoul of the code below which, if
2689 we step into the middle of a line, resets the stepping
2691 step_range_end
= (step_range_start
= prev_pc
) + 1;
2693 ecs
->remove_breakpoints_on_following_step
= 1;
2698 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2699 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2700 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2701 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2702 || ecs
->stop_func_name
== 0)
2704 /* It's a subroutine call. */
2706 if (step_over_calls
== 0)
2708 /* I presume that step_over_calls is only 0 when we're
2709 supposed to be stepping at the assembly language level
2710 ("stepi"). Just stop. */
2712 stop_stepping (ecs
);
2716 if (step_over_calls
> 0 || IGNORE_HELPER_CALL (stop_pc
))
2718 /* We're doing a "next". */
2719 step_over_function (ecs
);
2724 /* If we are in a function call trampoline (a stub between
2725 the calling routine and the real function), locate the real
2726 function. That's what tells us (a) whether we want to step
2727 into it at all, and (b) what prologue we want to run to
2728 the end of, if we do step into it. */
2729 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2731 ecs
->stop_func_start
= tmp
;
2734 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2737 struct symtab_and_line xxx
;
2738 /* Why isn't this s_a_l called "sr_sal", like all of the
2739 other s_a_l's where this code is duplicated? */
2740 INIT_SAL (&xxx
); /* initialize to zeroes */
2742 xxx
.section
= find_pc_overlay (xxx
.pc
);
2743 check_for_old_step_resume_breakpoint ();
2744 step_resume_breakpoint
=
2745 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2746 insert_breakpoints ();
2752 /* If we have line number information for the function we
2753 are thinking of stepping into, step into it.
2755 If there are several symtabs at that PC (e.g. with include
2756 files), just want to know whether *any* of them have line
2757 numbers. find_pc_line handles this. */
2759 struct symtab_and_line tmp_sal
;
2761 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2762 if (tmp_sal
.line
!= 0)
2764 step_into_function (ecs
);
2768 step_over_function (ecs
);
2774 /* We've wandered out of the step range. */
2776 ecs
->sal
= find_pc_line (stop_pc
, 0);
2778 if (step_range_end
== 1)
2780 /* It is stepi or nexti. We always want to stop stepping after
2783 stop_stepping (ecs
);
2787 /* If we're in the return path from a shared library trampoline,
2788 we want to proceed through the trampoline when stepping. */
2789 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2793 /* Determine where this trampoline returns. */
2794 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2796 /* Only proceed through if we know where it's going. */
2799 /* And put the step-breakpoint there and go until there. */
2800 struct symtab_and_line sr_sal
;
2802 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2804 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2805 /* Do not specify what the fp should be when we stop
2806 since on some machines the prologue
2807 is where the new fp value is established. */
2808 check_for_old_step_resume_breakpoint ();
2809 step_resume_breakpoint
=
2810 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2811 if (breakpoints_inserted
)
2812 insert_breakpoints ();
2814 /* Restart without fiddling with the step ranges or
2821 if (ecs
->sal
.line
== 0)
2823 /* We have no line number information. That means to stop
2824 stepping (does this always happen right after one instruction,
2825 when we do "s" in a function with no line numbers,
2826 or can this happen as a result of a return or longjmp?). */
2828 stop_stepping (ecs
);
2832 if ((stop_pc
== ecs
->sal
.pc
)
2833 && (ecs
->current_line
!= ecs
->sal
.line
|| ecs
->current_symtab
!= ecs
->sal
.symtab
))
2835 /* We are at the start of a different line. So stop. Note that
2836 we don't stop if we step into the middle of a different line.
2837 That is said to make things like for (;;) statements work
2840 stop_stepping (ecs
);
2844 /* We aren't done stepping.
2846 Optimize by setting the stepping range to the line.
2847 (We might not be in the original line, but if we entered a
2848 new line in mid-statement, we continue stepping. This makes
2849 things like for(;;) statements work better.) */
2851 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2853 /* If this is the last line of the function, don't keep stepping
2854 (it would probably step us out of the function).
2855 This is particularly necessary for a one-line function,
2856 in which after skipping the prologue we better stop even though
2857 we will be in mid-line. */
2859 stop_stepping (ecs
);
2862 step_range_start
= ecs
->sal
.pc
;
2863 step_range_end
= ecs
->sal
.end
;
2864 step_frame_address
= FRAME_FP (get_current_frame ());
2865 ecs
->current_line
= ecs
->sal
.line
;
2866 ecs
->current_symtab
= ecs
->sal
.symtab
;
2868 /* In the case where we just stepped out of a function into the middle
2869 of a line of the caller, continue stepping, but step_frame_address
2870 must be modified to current frame */
2872 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2873 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2874 step_frame_address
= current_frame
;
2879 } /* extra brace, to preserve old indentation */
2882 /* Are we in the middle of stepping? */
2885 currently_stepping (struct execution_control_state
*ecs
)
2887 return ((through_sigtramp_breakpoint
== NULL
2888 && !ecs
->handling_longjmp
2889 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2891 || ecs
->stepping_through_solib_after_catch
2892 || bpstat_should_step ());
2896 check_sigtramp2 (struct execution_control_state
*ecs
)
2899 && IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2900 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2901 && INNER_THAN (read_sp (), step_sp
))
2903 /* What has happened here is that we have just stepped the
2904 inferior with a signal (because it is a signal which
2905 shouldn't make us stop), thus stepping into sigtramp.
2907 So we need to set a step_resume_break_address breakpoint and
2908 continue until we hit it, and then step. FIXME: This should
2909 be more enduring than a step_resume breakpoint; we should
2910 know that we will later need to keep going rather than
2911 re-hitting the breakpoint here (see the testsuite,
2912 gdb.base/signals.exp where it says "exceedingly difficult"). */
2914 struct symtab_and_line sr_sal
;
2916 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2917 sr_sal
.pc
= prev_pc
;
2918 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2919 /* We perhaps could set the frame if we kept track of what the
2920 frame corresponding to prev_pc was. But we don't, so don't. */
2921 through_sigtramp_breakpoint
=
2922 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2923 if (breakpoints_inserted
)
2924 insert_breakpoints ();
2926 ecs
->remove_breakpoints_on_following_step
= 1;
2927 ecs
->another_trap
= 1;
2931 /* Subroutine call with source code we should not step over. Do step
2932 to the first line of code in it. */
2935 step_into_function (struct execution_control_state
*ecs
)
2938 struct symtab_and_line sr_sal
;
2940 s
= find_pc_symtab (stop_pc
);
2941 if (s
&& s
->language
!= language_asm
)
2942 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2944 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2945 /* Use the step_resume_break to step until the end of the prologue,
2946 even if that involves jumps (as it seems to on the vax under
2948 /* If the prologue ends in the middle of a source line, continue to
2949 the end of that source line (if it is still within the function).
2950 Otherwise, just go to end of prologue. */
2951 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2952 /* no, don't either. It skips any code that's legitimately on the
2956 && ecs
->sal
.pc
!= ecs
->stop_func_start
2957 && ecs
->sal
.end
< ecs
->stop_func_end
)
2958 ecs
->stop_func_start
= ecs
->sal
.end
;
2961 if (ecs
->stop_func_start
== stop_pc
)
2963 /* We are already there: stop now. */
2965 stop_stepping (ecs
);
2970 /* Put the step-breakpoint there and go until there. */
2971 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2972 sr_sal
.pc
= ecs
->stop_func_start
;
2973 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
2974 /* Do not specify what the fp should be when we stop since on
2975 some machines the prologue is where the new fp value is
2977 check_for_old_step_resume_breakpoint ();
2978 step_resume_breakpoint
=
2979 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2980 if (breakpoints_inserted
)
2981 insert_breakpoints ();
2983 /* And make sure stepping stops right away then. */
2984 step_range_end
= step_range_start
;
2989 /* We've just entered a callee, and we wish to resume until it returns
2990 to the caller. Setting a step_resume breakpoint on the return
2991 address will catch a return from the callee.
2993 However, if the callee is recursing, we want to be careful not to
2994 catch returns of those recursive calls, but only of THIS instance
2997 To do this, we set the step_resume bp's frame to our current
2998 caller's frame (step_frame_address, which is set by the "next" or
2999 "until" command, before execution begins). */
3002 step_over_function (struct execution_control_state
*ecs
)
3004 struct symtab_and_line sr_sal
;
3006 INIT_SAL (&sr_sal
); /* initialize to zeros */
3007 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3008 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3010 check_for_old_step_resume_breakpoint ();
3011 step_resume_breakpoint
=
3012 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
3014 if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
3015 step_resume_breakpoint
->frame
= step_frame_address
;
3017 if (breakpoints_inserted
)
3018 insert_breakpoints ();
3022 stop_stepping (struct execution_control_state
*ecs
)
3024 if (target_has_execution
)
3026 /* Are we stopping for a vfork event? We only stop when we see
3027 the child's event. However, we may not yet have seen the
3028 parent's event. And, inferior_pid is still set to the
3029 parent's pid, until we resume again and follow either the
3032 To ensure that we can really touch inferior_pid (aka, the
3033 parent process) -- which calls to functions like read_pc
3034 implicitly do -- wait on the parent if necessary. */
3035 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3036 && !pending_follow
.fork_event
.saw_parent_fork
)
3042 if (target_wait_hook
)
3043 parent_pid
= target_wait_hook (-1, &(ecs
->ws
));
3045 parent_pid
= target_wait (-1, &(ecs
->ws
));
3047 while (parent_pid
!= inferior_pid
);
3050 /* Assuming the inferior still exists, set these up for next
3051 time, just like we did above if we didn't break out of the
3053 prev_pc
= read_pc ();
3054 prev_func_start
= ecs
->stop_func_start
;
3055 prev_func_name
= ecs
->stop_func_name
;
3058 /* Let callers know we don't want to wait for the inferior anymore. */
3059 ecs
->wait_some_more
= 0;
3062 /* This function handles various cases where we need to continue
3063 waiting for the inferior. */
3064 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3067 keep_going (struct execution_control_state
*ecs
)
3069 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3070 vforked child between its creation and subsequent exit or call to
3071 exec(). However, I had big problems in this rather creaky exec
3072 engine, getting that to work. The fundamental problem is that
3073 I'm trying to debug two processes via an engine that only
3074 understands a single process with possibly multiple threads.
3076 Hence, this spot is known to have problems when
3077 target_can_follow_vfork_prior_to_exec returns 1. */
3079 /* Save the pc before execution, to compare with pc after stop. */
3080 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3081 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3082 BREAK is defined, the
3083 original pc would not have
3084 been at the start of a
3086 prev_func_name
= ecs
->stop_func_name
;
3088 if (ecs
->update_step_sp
)
3089 step_sp
= read_sp ();
3090 ecs
->update_step_sp
= 0;
3092 /* If we did not do break;, it means we should keep running the
3093 inferior and not return to debugger. */
3095 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3097 /* We took a signal (which we are supposed to pass through to
3098 the inferior, else we'd have done a break above) and we
3099 haven't yet gotten our trap. Simply continue. */
3100 resume (currently_stepping (ecs
), stop_signal
);
3104 /* Either the trap was not expected, but we are continuing
3105 anyway (the user asked that this signal be passed to the
3108 The signal was SIGTRAP, e.g. it was our signal, but we
3109 decided we should resume from it.
3111 We're going to run this baby now!
3113 Insert breakpoints now, unless we are trying to one-proceed
3114 past a breakpoint. */
3115 /* If we've just finished a special step resume and we don't
3116 want to hit a breakpoint, pull em out. */
3117 if (step_resume_breakpoint
== NULL
3118 && through_sigtramp_breakpoint
== NULL
3119 && ecs
->remove_breakpoints_on_following_step
)
3121 ecs
->remove_breakpoints_on_following_step
= 0;
3122 remove_breakpoints ();
3123 breakpoints_inserted
= 0;
3125 else if (!breakpoints_inserted
&&
3126 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3128 breakpoints_failed
= insert_breakpoints ();
3129 if (breakpoints_failed
)
3131 stop_stepping (ecs
);
3134 breakpoints_inserted
= 1;
3137 trap_expected
= ecs
->another_trap
;
3139 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3140 specifies that such a signal should be delivered to the
3143 Typically, this would occure when a user is debugging a
3144 target monitor on a simulator: the target monitor sets a
3145 breakpoint; the simulator encounters this break-point and
3146 halts the simulation handing control to GDB; GDB, noteing
3147 that the break-point isn't valid, returns control back to the
3148 simulator; the simulator then delivers the hardware
3149 equivalent of a SIGNAL_TRAP to the program being debugged. */
3151 if (stop_signal
== TARGET_SIGNAL_TRAP
3152 && !signal_program
[stop_signal
])
3153 stop_signal
= TARGET_SIGNAL_0
;
3155 #ifdef SHIFT_INST_REGS
3156 /* I'm not sure when this following segment applies. I do know,
3157 now, that we shouldn't rewrite the regs when we were stopped
3158 by a random signal from the inferior process. */
3159 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3160 (this is only used on the 88k). */
3162 if (!bpstat_explains_signal (stop_bpstat
)
3163 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
3164 && !stopped_by_random_signal
)
3166 #endif /* SHIFT_INST_REGS */
3168 resume (currently_stepping (ecs
), stop_signal
);
3171 prepare_to_wait (ecs
);
3174 /* This function normally comes after a resume, before
3175 handle_inferior_event exits. It takes care of any last bits of
3176 housekeeping, and sets the all-important wait_some_more flag. */
3179 prepare_to_wait (struct execution_control_state
*ecs
)
3181 if (ecs
->infwait_state
== infwait_normal_state
)
3183 overlay_cache_invalid
= 1;
3185 /* We have to invalidate the registers BEFORE calling
3186 target_wait because they can be loaded from the target while
3187 in target_wait. This makes remote debugging a bit more
3188 efficient for those targets that provide critical registers
3189 as part of their normal status mechanism. */
3191 registers_changed ();
3192 ecs
->waiton_pid
= -1;
3193 ecs
->wp
= &(ecs
->ws
);
3195 /* This is the old end of the while loop. Let everybody know we
3196 want to wait for the inferior some more and get called again
3198 ecs
->wait_some_more
= 1;
3201 /* This function returns TRUE if ep is an internal breakpoint
3202 set to catch generic shared library (aka dynamically-linked
3203 library) events. (This is *NOT* the same as a catchpoint for a
3204 shlib event. The latter is something a user can set; this is
3205 something gdb sets for its own use, and isn't ever shown to a
3208 is_internal_shlib_eventpoint (struct breakpoint
*ep
)
3211 (ep
->type
== bp_shlib_event
)
3215 /* This function returns TRUE if bs indicates that the inferior
3216 stopped due to a shared library (aka dynamically-linked library)
3220 stopped_for_internal_shlib_event (bpstat bs
)
3222 /* Note that multiple eventpoints may've caused the stop. Any
3223 that are associated with shlib events will be accepted. */
3224 for (; bs
!= NULL
; bs
= bs
->next
)
3226 if ((bs
->breakpoint_at
!= NULL
)
3227 && is_internal_shlib_eventpoint (bs
->breakpoint_at
))
3231 /* If we get here, then no candidate was found. */
3236 /* Here to return control to GDB when the inferior stops for real.
3237 Print appropriate messages, remove breakpoints, give terminal our modes.
3239 STOP_PRINT_FRAME nonzero means print the executing frame
3240 (pc, function, args, file, line number and line text).
3241 BREAKPOINTS_FAILED nonzero means stop was due to error
3242 attempting to insert breakpoints. */
3247 /* As with the notification of thread events, we want to delay
3248 notifying the user that we've switched thread context until
3249 the inferior actually stops.
3251 (Note that there's no point in saying anything if the inferior
3253 if (may_switch_from_inferior_pid
3254 && (switched_from_inferior_pid
!= inferior_pid
)
3255 && target_has_execution
)
3257 target_terminal_ours_for_output ();
3258 printf_filtered ("[Switched to %s]\n",
3259 target_pid_or_tid_to_str (inferior_pid
));
3260 switched_from_inferior_pid
= inferior_pid
;
3263 /* Make sure that the current_frame's pc is correct. This
3264 is a correction for setting up the frame info before doing
3265 DECR_PC_AFTER_BREAK */
3266 if (target_has_execution
&& get_current_frame ())
3267 (get_current_frame ())->pc
= read_pc ();
3269 if (breakpoints_failed
)
3271 target_terminal_ours_for_output ();
3272 print_sys_errmsg ("ptrace", breakpoints_failed
);
3273 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3274 The same program may be running in another process.\n");
3277 if (target_has_execution
&& breakpoints_inserted
)
3279 if (remove_breakpoints ())
3281 target_terminal_ours_for_output ();
3282 printf_filtered ("Cannot remove breakpoints because ");
3283 printf_filtered ("program is no longer writable.\n");
3284 printf_filtered ("It might be running in another process.\n");
3285 printf_filtered ("Further execution is probably impossible.\n");
3288 breakpoints_inserted
= 0;
3290 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3291 Delete any breakpoint that is to be deleted at the next stop. */
3293 breakpoint_auto_delete (stop_bpstat
);
3295 /* If an auto-display called a function and that got a signal,
3296 delete that auto-display to avoid an infinite recursion. */
3298 if (stopped_by_random_signal
)
3299 disable_current_display ();
3301 /* Don't print a message if in the middle of doing a "step n"
3302 operation for n > 1 */
3303 if (step_multi
&& stop_step
)
3306 target_terminal_ours ();
3308 /* Did we stop because the user set the stop_on_solib_events
3309 variable? (If so, we report this as a generic, "Stopped due
3310 to shlib event" message.) */
3311 if (stopped_for_internal_shlib_event (stop_bpstat
))
3313 printf_filtered ("Stopped due to shared library event\n");
3316 /* Look up the hook_stop and run it if it exists. */
3318 if (stop_command
&& stop_command
->hook
)
3320 catch_errors (hook_stop_stub
, stop_command
->hook
,
3321 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3324 if (!target_has_stack
)
3330 /* Select innermost stack frame - i.e., current frame is frame 0,
3331 and current location is based on that.
3332 Don't do this on return from a stack dummy routine,
3333 or if the program has exited. */
3335 if (!stop_stack_dummy
)
3337 select_frame (get_current_frame (), 0);
3339 /* Print current location without a level number, if
3340 we have changed functions or hit a breakpoint.
3341 Print source line if we have one.
3342 bpstat_print() contains the logic deciding in detail
3343 what to print, based on the event(s) that just occurred. */
3345 if (stop_print_frame
)
3350 bpstat_ret
= bpstat_print (stop_bpstat
);
3351 /* bpstat_print() returned one of:
3352 -1: Didn't print anything
3353 0: Printed preliminary "Breakpoint n, " message, desires
3355 1: Printed something, don't tack on location */
3357 if (bpstat_ret
== -1)
3359 && step_frame_address
== FRAME_FP (get_current_frame ())
3360 && step_start_function
== find_pc_function (stop_pc
))
3361 source_flag
= -1; /* finished step, just print source line */
3363 source_flag
= 1; /* print location and source line */
3364 else if (bpstat_ret
== 0) /* hit bpt, desire location */
3365 source_flag
= 1; /* print location and source line */
3366 else /* bpstat_ret == 1, hit bpt, do not desire location */
3367 source_flag
= -1; /* just print source line */
3369 /* The behavior of this routine with respect to the source
3371 -1: Print only source line
3372 0: Print only location
3373 1: Print location and source line */
3374 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
3376 /* Display the auto-display expressions. */
3381 /* Save the function value return registers, if we care.
3382 We might be about to restore their previous contents. */
3383 if (proceed_to_finish
)
3384 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
3386 if (stop_stack_dummy
)
3388 /* Pop the empty frame that contains the stack dummy.
3389 POP_FRAME ends with a setting of the current frame, so we
3390 can use that next. */
3392 /* Set stop_pc to what it was before we called the function.
3393 Can't rely on restore_inferior_status because that only gets
3394 called if we don't stop in the called function. */
3395 stop_pc
= read_pc ();
3396 select_frame (get_current_frame (), 0);
3400 TUIDO (((TuiOpaqueFuncPtr
) tui_vCheckDataValues
, selected_frame
));
3403 annotate_stopped ();
3407 hook_stop_stub (void *cmd
)
3409 execute_user_command ((struct cmd_list_element
*) cmd
, 0);
3414 signal_stop_state (int signo
)
3416 return signal_stop
[signo
];
3420 signal_print_state (int signo
)
3422 return signal_print
[signo
];
3426 signal_pass_state (int signo
)
3428 return signal_program
[signo
];
3431 int signal_stop_update (signo
, state
)
3435 int ret
= signal_stop
[signo
];
3436 signal_stop
[signo
] = state
;
3440 int signal_print_update (signo
, state
)
3444 int ret
= signal_print
[signo
];
3445 signal_print
[signo
] = state
;
3449 int signal_pass_update (signo
, state
)
3453 int ret
= signal_program
[signo
];
3454 signal_program
[signo
] = state
;
3459 sig_print_header (void)
3462 Signal Stop\tPrint\tPass to program\tDescription\n");
3466 sig_print_info (enum target_signal oursig
)
3468 char *name
= target_signal_to_name (oursig
);
3469 int name_padding
= 13 - strlen (name
);
3471 if (name_padding
<= 0)
3474 printf_filtered ("%s", name
);
3475 printf_filtered ("%*.*s ", name_padding
, name_padding
,
3477 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3478 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3479 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3480 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3483 /* Specify how various signals in the inferior should be handled. */
3486 handle_command (char *args
, int from_tty
)
3489 int digits
, wordlen
;
3490 int sigfirst
, signum
, siglast
;
3491 enum target_signal oursig
;
3494 unsigned char *sigs
;
3495 struct cleanup
*old_chain
;
3499 error_no_arg ("signal to handle");
3502 /* Allocate and zero an array of flags for which signals to handle. */
3504 nsigs
= (int) TARGET_SIGNAL_LAST
;
3505 sigs
= (unsigned char *) alloca (nsigs
);
3506 memset (sigs
, 0, nsigs
);
3508 /* Break the command line up into args. */
3510 argv
= buildargv (args
);
3515 old_chain
= make_cleanup_freeargv (argv
);
3517 /* Walk through the args, looking for signal oursigs, signal names, and
3518 actions. Signal numbers and signal names may be interspersed with
3519 actions, with the actions being performed for all signals cumulatively
3520 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3522 while (*argv
!= NULL
)
3524 wordlen
= strlen (*argv
);
3525 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3529 sigfirst
= siglast
= -1;
3531 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3533 /* Apply action to all signals except those used by the
3534 debugger. Silently skip those. */
3537 siglast
= nsigs
- 1;
3539 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3541 SET_SIGS (nsigs
, sigs
, signal_stop
);
3542 SET_SIGS (nsigs
, sigs
, signal_print
);
3544 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3546 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3548 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3550 SET_SIGS (nsigs
, sigs
, signal_print
);
3552 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3554 SET_SIGS (nsigs
, sigs
, signal_program
);
3556 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3558 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3560 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3562 SET_SIGS (nsigs
, sigs
, signal_program
);
3564 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3566 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3567 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3569 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3571 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3573 else if (digits
> 0)
3575 /* It is numeric. The numeric signal refers to our own
3576 internal signal numbering from target.h, not to host/target
3577 signal number. This is a feature; users really should be
3578 using symbolic names anyway, and the common ones like
3579 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3581 sigfirst
= siglast
= (int)
3582 target_signal_from_command (atoi (*argv
));
3583 if ((*argv
)[digits
] == '-')
3586 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3588 if (sigfirst
> siglast
)
3590 /* Bet he didn't figure we'd think of this case... */
3598 oursig
= target_signal_from_name (*argv
);
3599 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3601 sigfirst
= siglast
= (int) oursig
;
3605 /* Not a number and not a recognized flag word => complain. */
3606 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3610 /* If any signal numbers or symbol names were found, set flags for
3611 which signals to apply actions to. */
3613 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3615 switch ((enum target_signal
) signum
)
3617 case TARGET_SIGNAL_TRAP
:
3618 case TARGET_SIGNAL_INT
:
3619 if (!allsigs
&& !sigs
[signum
])
3621 if (query ("%s is used by the debugger.\n\
3622 Are you sure you want to change it? ",
3623 target_signal_to_name
3624 ((enum target_signal
) signum
)))
3630 printf_unfiltered ("Not confirmed, unchanged.\n");
3631 gdb_flush (gdb_stdout
);
3635 case TARGET_SIGNAL_0
:
3636 case TARGET_SIGNAL_DEFAULT
:
3637 case TARGET_SIGNAL_UNKNOWN
:
3638 /* Make sure that "all" doesn't print these. */
3649 target_notice_signals (inferior_pid
);
3653 /* Show the results. */
3654 sig_print_header ();
3655 for (signum
= 0; signum
< nsigs
; signum
++)
3659 sig_print_info (signum
);
3664 do_cleanups (old_chain
);
3668 xdb_handle_command (char *args
, int from_tty
)
3671 struct cleanup
*old_chain
;
3673 /* Break the command line up into args. */
3675 argv
= buildargv (args
);
3680 old_chain
= make_cleanup_freeargv (argv
);
3681 if (argv
[1] != (char *) NULL
)
3686 bufLen
= strlen (argv
[0]) + 20;
3687 argBuf
= (char *) xmalloc (bufLen
);
3691 enum target_signal oursig
;
3693 oursig
= target_signal_from_name (argv
[0]);
3694 memset (argBuf
, 0, bufLen
);
3695 if (strcmp (argv
[1], "Q") == 0)
3696 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3699 if (strcmp (argv
[1], "s") == 0)
3701 if (!signal_stop
[oursig
])
3702 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3704 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3706 else if (strcmp (argv
[1], "i") == 0)
3708 if (!signal_program
[oursig
])
3709 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3711 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3713 else if (strcmp (argv
[1], "r") == 0)
3715 if (!signal_print
[oursig
])
3716 sprintf (argBuf
, "%s %s", argv
[0], "print");
3718 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3724 handle_command (argBuf
, from_tty
);
3726 printf_filtered ("Invalid signal handling flag.\n");
3731 do_cleanups (old_chain
);
3734 /* Print current contents of the tables set by the handle command.
3735 It is possible we should just be printing signals actually used
3736 by the current target (but for things to work right when switching
3737 targets, all signals should be in the signal tables). */
3740 signals_info (char *signum_exp
, int from_tty
)
3742 enum target_signal oursig
;
3743 sig_print_header ();
3747 /* First see if this is a symbol name. */
3748 oursig
= target_signal_from_name (signum_exp
);
3749 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3751 /* No, try numeric. */
3753 target_signal_from_command (parse_and_eval_address (signum_exp
));
3755 sig_print_info (oursig
);
3759 printf_filtered ("\n");
3760 /* These ugly casts brought to you by the native VAX compiler. */
3761 for (oursig
= TARGET_SIGNAL_FIRST
;
3762 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3763 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3767 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3768 && oursig
!= TARGET_SIGNAL_DEFAULT
3769 && oursig
!= TARGET_SIGNAL_0
)
3770 sig_print_info (oursig
);
3773 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3776 struct inferior_status
3778 enum target_signal stop_signal
;
3782 int stop_stack_dummy
;
3783 int stopped_by_random_signal
;
3785 CORE_ADDR step_range_start
;
3786 CORE_ADDR step_range_end
;
3787 CORE_ADDR step_frame_address
;
3788 int step_over_calls
;
3789 CORE_ADDR step_resume_break_address
;
3790 int stop_after_trap
;
3791 int stop_soon_quietly
;
3792 CORE_ADDR selected_frame_address
;
3793 char *stop_registers
;
3795 /* These are here because if call_function_by_hand has written some
3796 registers and then decides to call error(), we better not have changed
3801 int breakpoint_proceeded
;
3802 int restore_stack_info
;
3803 int proceed_to_finish
;
3806 static struct inferior_status
*
3807 xmalloc_inferior_status (void)
3809 struct inferior_status
*inf_status
;
3810 inf_status
= xmalloc (sizeof (struct inferior_status
));
3811 inf_status
->stop_registers
= xmalloc (REGISTER_BYTES
);
3812 inf_status
->registers
= xmalloc (REGISTER_BYTES
);
3817 free_inferior_status (struct inferior_status
*inf_status
)
3819 free (inf_status
->registers
);
3820 free (inf_status
->stop_registers
);
3825 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3828 int size
= REGISTER_RAW_SIZE (regno
);
3829 void *buf
= alloca (size
);
3830 store_signed_integer (buf
, size
, val
);
3831 memcpy (&inf_status
->registers
[REGISTER_BYTE (regno
)], buf
, size
);
3834 /* Save all of the information associated with the inferior<==>gdb
3835 connection. INF_STATUS is a pointer to a "struct inferior_status"
3836 (defined in inferior.h). */
3838 struct inferior_status
*
3839 save_inferior_status (int restore_stack_info
)
3841 struct inferior_status
*inf_status
= xmalloc_inferior_status ();
3843 inf_status
->stop_signal
= stop_signal
;
3844 inf_status
->stop_pc
= stop_pc
;
3845 inf_status
->stop_step
= stop_step
;
3846 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3847 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3848 inf_status
->trap_expected
= trap_expected
;
3849 inf_status
->step_range_start
= step_range_start
;
3850 inf_status
->step_range_end
= step_range_end
;
3851 inf_status
->step_frame_address
= step_frame_address
;
3852 inf_status
->step_over_calls
= step_over_calls
;
3853 inf_status
->stop_after_trap
= stop_after_trap
;
3854 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3855 /* Save original bpstat chain here; replace it with copy of chain.
3856 If caller's caller is walking the chain, they'll be happier if we
3857 hand them back the original chain when restore_inferior_status is
3859 inf_status
->stop_bpstat
= stop_bpstat
;
3860 stop_bpstat
= bpstat_copy (stop_bpstat
);
3861 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3862 inf_status
->restore_stack_info
= restore_stack_info
;
3863 inf_status
->proceed_to_finish
= proceed_to_finish
;
3865 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
3867 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3869 record_selected_frame (&(inf_status
->selected_frame_address
),
3870 &(inf_status
->selected_level
));
3874 struct restore_selected_frame_args
3876 CORE_ADDR frame_address
;
3881 restore_selected_frame (void *args
)
3883 struct restore_selected_frame_args
*fr
=
3884 (struct restore_selected_frame_args
*) args
;
3885 struct frame_info
*frame
;
3886 int level
= fr
->level
;
3888 frame
= find_relative_frame (get_current_frame (), &level
);
3890 /* If inf_status->selected_frame_address is NULL, there was no
3891 previously selected frame. */
3892 if (frame
== NULL
||
3893 /* FRAME_FP (frame) != fr->frame_address || */
3894 /* elz: deleted this check as a quick fix to the problem that
3895 for function called by hand gdb creates no internal frame
3896 structure and the real stack and gdb's idea of stack are
3897 different if nested calls by hands are made.
3899 mvs: this worries me. */
3902 warning ("Unable to restore previously selected frame.\n");
3906 select_frame (frame
, fr
->level
);
3912 restore_inferior_status (struct inferior_status
*inf_status
)
3914 stop_signal
= inf_status
->stop_signal
;
3915 stop_pc
= inf_status
->stop_pc
;
3916 stop_step
= inf_status
->stop_step
;
3917 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3918 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3919 trap_expected
= inf_status
->trap_expected
;
3920 step_range_start
= inf_status
->step_range_start
;
3921 step_range_end
= inf_status
->step_range_end
;
3922 step_frame_address
= inf_status
->step_frame_address
;
3923 step_over_calls
= inf_status
->step_over_calls
;
3924 stop_after_trap
= inf_status
->stop_after_trap
;
3925 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
3926 bpstat_clear (&stop_bpstat
);
3927 stop_bpstat
= inf_status
->stop_bpstat
;
3928 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3929 proceed_to_finish
= inf_status
->proceed_to_finish
;
3931 /* FIXME: Is the restore of stop_registers always needed */
3932 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
3934 /* The inferior can be gone if the user types "print exit(0)"
3935 (and perhaps other times). */
3936 if (target_has_execution
)
3937 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3939 /* FIXME: If we are being called after stopping in a function which
3940 is called from gdb, we should not be trying to restore the
3941 selected frame; it just prints a spurious error message (The
3942 message is useful, however, in detecting bugs in gdb (like if gdb
3943 clobbers the stack)). In fact, should we be restoring the
3944 inferior status at all in that case? . */
3946 if (target_has_stack
&& inf_status
->restore_stack_info
)
3948 struct restore_selected_frame_args fr
;
3949 fr
.level
= inf_status
->selected_level
;
3950 fr
.frame_address
= inf_status
->selected_frame_address
;
3951 /* The point of catch_errors is that if the stack is clobbered,
3952 walking the stack might encounter a garbage pointer and error()
3953 trying to dereference it. */
3954 if (catch_errors (restore_selected_frame
, &fr
,
3955 "Unable to restore previously selected frame:\n",
3956 RETURN_MASK_ERROR
) == 0)
3957 /* Error in restoring the selected frame. Select the innermost
3961 select_frame (get_current_frame (), 0);
3965 free_inferior_status (inf_status
);
3969 discard_inferior_status (struct inferior_status
*inf_status
)
3971 /* See save_inferior_status for info on stop_bpstat. */
3972 bpstat_clear (&inf_status
->stop_bpstat
);
3973 free_inferior_status (inf_status
);
3977 set_follow_fork_mode_command (char *arg
, int from_tty
,
3978 struct cmd_list_element
*c
)
3980 if (!STREQ (arg
, "parent") &&
3981 !STREQ (arg
, "child") &&
3982 !STREQ (arg
, "both") &&
3983 !STREQ (arg
, "ask"))
3984 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
3986 if (follow_fork_mode_string
!= NULL
)
3987 free (follow_fork_mode_string
);
3988 follow_fork_mode_string
= savestring (arg
, strlen (arg
));
3994 stop_registers
= xmalloc (REGISTER_BYTES
);
3998 _initialize_infrun (void)
4001 register int numsigs
;
4002 struct cmd_list_element
*c
;
4006 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4007 register_gdbarch_swap (NULL
, 0, build_infrun
);
4009 add_info ("signals", signals_info
,
4010 "What debugger does when program gets various signals.\n\
4011 Specify a signal as argument to print info on that signal only.");
4012 add_info_alias ("handle", "signals", 0);
4014 add_com ("handle", class_run
, handle_command
,
4015 concat ("Specify how to handle a signal.\n\
4016 Args are signals and actions to apply to those signals.\n\
4017 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4018 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4019 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4020 The special arg \"all\" is recognized to mean all signals except those\n\
4021 used by the debugger, typically SIGTRAP and SIGINT.\n",
4022 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4023 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4024 Stop means reenter debugger if this signal happens (implies print).\n\
4025 Print means print a message if this signal happens.\n\
4026 Pass means let program see this signal; otherwise program doesn't know.\n\
4027 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4028 Pass and Stop may be combined.", NULL
));
4031 add_com ("lz", class_info
, signals_info
,
4032 "What debugger does when program gets various signals.\n\
4033 Specify a signal as argument to print info on that signal only.");
4034 add_com ("z", class_run
, xdb_handle_command
,
4035 concat ("Specify how to handle a signal.\n\
4036 Args are signals and actions to apply to those signals.\n\
4037 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4038 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4039 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4040 The special arg \"all\" is recognized to mean all signals except those\n\
4041 used by the debugger, typically SIGTRAP and SIGINT.\n",
4042 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4043 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4044 nopass), \"Q\" (noprint)\n\
4045 Stop means reenter debugger if this signal happens (implies print).\n\
4046 Print means print a message if this signal happens.\n\
4047 Pass means let program see this signal; otherwise program doesn't know.\n\
4048 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4049 Pass and Stop may be combined.", NULL
));
4053 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
4054 "There is no `stop' command, but you can set a hook on `stop'.\n\
4055 This allows you to set a list of commands to be run each time execution\n\
4056 of the program stops.", &cmdlist
);
4058 numsigs
= (int) TARGET_SIGNAL_LAST
;
4059 signal_stop
= (unsigned char *)
4060 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4061 signal_print
= (unsigned char *)
4062 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4063 signal_program
= (unsigned char *)
4064 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4065 for (i
= 0; i
< numsigs
; i
++)
4068 signal_print
[i
] = 1;
4069 signal_program
[i
] = 1;
4072 /* Signals caused by debugger's own actions
4073 should not be given to the program afterwards. */
4074 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4075 signal_program
[TARGET_SIGNAL_INT
] = 0;
4077 /* Signals that are not errors should not normally enter the debugger. */
4078 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4079 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4080 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4081 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4082 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4083 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4084 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4085 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4086 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4087 signal_print
[TARGET_SIGNAL_IO
] = 0;
4088 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4089 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4090 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4091 signal_print
[TARGET_SIGNAL_URG
] = 0;
4092 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4093 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4095 /* These signals are used internally by user-level thread
4096 implementations. (See signal(5) on Solaris.) Like the above
4097 signals, a healthy program receives and handles them as part of
4098 its normal operation. */
4099 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4100 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4101 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4102 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4103 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4104 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4108 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4109 (char *) &stop_on_solib_events
,
4110 "Set stopping for shared library events.\n\
4111 If nonzero, gdb will give control to the user when the dynamic linker\n\
4112 notifies gdb of shared library events. The most common event of interest\n\
4113 to the user would be loading/unloading of a new library.\n",
4118 c
= add_set_enum_cmd ("follow-fork-mode",
4120 follow_fork_mode_kind_names
,
4121 (char *) &follow_fork_mode_string
,
4122 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4123 kernel problem. It's also not terribly useful without a GUI to
4124 help the user drive two debuggers. So for now, I'm disabling
4125 the "both" option. */
4126 /* "Set debugger response to a program call of fork \
4128 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4129 parent - the original process is debugged after a fork\n\
4130 child - the new process is debugged after a fork\n\
4131 both - both the parent and child are debugged after a fork\n\
4132 ask - the debugger will ask for one of the above choices\n\
4133 For \"both\", another copy of the debugger will be started to follow\n\
4134 the new child process. The original debugger will continue to follow\n\
4135 the original parent process. To distinguish their prompts, the\n\
4136 debugger copy's prompt will be changed.\n\
4137 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4138 By default, the debugger will follow the parent process.",
4140 "Set debugger response to a program call of fork \
4142 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4143 parent - the original process is debugged after a fork\n\
4144 child - the new process is debugged after a fork\n\
4145 ask - the debugger will ask for one of the above choices\n\
4146 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4147 By default, the debugger will follow the parent process.",
4149 /* c->function.sfunc = ; */
4150 add_show_from_set (c
, &showlist
);
4152 set_follow_fork_mode_command ("parent", 0, NULL
);
4154 c
= add_set_enum_cmd ("scheduler-locking", class_run
,
4155 scheduler_enums
, /* array of string names */
4156 (char *) &scheduler_mode
, /* current mode */
4157 "Set mode for locking scheduler during execution.\n\
4158 off == no locking (threads may preempt at any time)\n\
4159 on == full locking (no thread except the current thread may run)\n\
4160 step == scheduler locked during every single-step operation.\n\
4161 In this mode, no other thread may run during a step command.\n\
4162 Other threads may run while stepping over a function call ('next').",
4165 c
->function
.sfunc
= set_schedlock_func
; /* traps on target vector */
4166 add_show_from_set (c
, &showlist
);