1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986-1989, 1991-2000 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 (void *);
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 struct execution_control_state
;
78 static int currently_stepping (struct execution_control_state
*ecs
);
80 static void xdb_handle_command (char *args
, int from_tty
);
82 void _initialize_infrun (void);
84 int inferior_ignoring_startup_exec_events
= 0;
85 int inferior_ignoring_leading_exec_events
= 0;
87 /* In asynchronous mode, but simulating synchronous execution. */
89 int sync_execution
= 0;
91 /* wait_for_inferior and normal_stop use this to notify the user
92 when the inferior stopped in a different thread than it had been
95 static int previous_inferior_pid
;
97 /* This is true for configurations that may follow through execl() and
98 similar functions. At present this is only true for HP-UX native. */
100 #ifndef MAY_FOLLOW_EXEC
101 #define MAY_FOLLOW_EXEC (0)
104 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
106 /* resume and wait_for_inferior use this to ensure that when
107 stepping over a hit breakpoint in a threaded application
108 only the thread that hit the breakpoint is stepped and the
109 other threads don't continue. This prevents having another
110 thread run past the breakpoint while it is temporarily
113 This is not thread-specific, so it isn't saved as part of
116 Versions of gdb which don't use the "step == this thread steps
117 and others continue" model but instead use the "step == this
118 thread steps and others wait" shouldn't do this. */
120 static int thread_step_needed
= 0;
122 /* This is true if thread_step_needed should actually be used. At
123 present this is only true for HP-UX native. */
125 #ifndef USE_THREAD_STEP_NEEDED
126 #define USE_THREAD_STEP_NEEDED (0)
129 static int use_thread_step_needed
= USE_THREAD_STEP_NEEDED
;
131 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
132 program. It needs to examine the jmp_buf argument and extract the PC
133 from it. The return value is non-zero on success, zero otherwise. */
135 #ifndef GET_LONGJMP_TARGET
136 #define GET_LONGJMP_TARGET(PC_ADDR) 0
140 /* Some machines have trampoline code that sits between function callers
141 and the actual functions themselves. If this machine doesn't have
142 such things, disable their processing. */
144 #ifndef SKIP_TRAMPOLINE_CODE
145 #define SKIP_TRAMPOLINE_CODE(pc) 0
148 /* Dynamic function trampolines are similar to solib trampolines in that they
149 are between the caller and the callee. The difference is that when you
150 enter a dynamic trampoline, you can't determine the callee's address. Some
151 (usually complex) code needs to run in the dynamic trampoline to figure out
152 the callee's address. This macro is usually called twice. First, when we
153 enter the trampoline (looks like a normal function call at that point). It
154 should return the PC of a point within the trampoline where the callee's
155 address is known. Second, when we hit the breakpoint, this routine returns
156 the callee's address. At that point, things proceed as per a step resume
159 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
160 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
163 /* If the program uses ELF-style shared libraries, then calls to
164 functions in shared libraries go through stubs, which live in a
165 table called the PLT (Procedure Linkage Table). The first time the
166 function is called, the stub sends control to the dynamic linker,
167 which looks up the function's real address, patches the stub so
168 that future calls will go directly to the function, and then passes
169 control to the function.
171 If we are stepping at the source level, we don't want to see any of
172 this --- we just want to skip over the stub and the dynamic linker.
173 The simple approach is to single-step until control leaves the
176 However, on some systems (e.g., Red Hat Linux 5.2) the dynamic
177 linker calls functions in the shared C library, so you can't tell
178 from the PC alone whether the dynamic linker is still running. In
179 this case, we use a step-resume breakpoint to get us past the
180 dynamic linker, as if we were using "next" to step over a function
183 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
184 linker code or not. Normally, this means we single-step. However,
185 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
186 address where we can place a step-resume breakpoint to get past the
187 linker's symbol resolution function.
189 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
190 pretty portable way, by comparing the PC against the address ranges
191 of the dynamic linker's sections.
193 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
194 it depends on internal details of the dynamic linker. It's usually
195 not too hard to figure out where to put a breakpoint, but it
196 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
197 sanity checking. If it can't figure things out, returning zero and
198 getting the (possibly confusing) stepping behavior is better than
199 signalling an error, which will obscure the change in the
202 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
203 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
206 #ifndef SKIP_SOLIB_RESOLVER
207 #define SKIP_SOLIB_RESOLVER(pc) 0
210 /* For SVR4 shared libraries, each call goes through a small piece of
211 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
212 to nonzero if we are current stopped in one of these. */
214 #ifndef IN_SOLIB_CALL_TRAMPOLINE
215 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
218 /* In some shared library schemes, the return path from a shared library
219 call may need to go through a trampoline too. */
221 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
222 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
225 /* This function returns TRUE if pc is the address of an instruction
226 that lies within the dynamic linker (such as the event hook, or the
229 This function must be used only when a dynamic linker event has
230 been caught, and the inferior is being stepped out of the hook, or
231 undefined results are guaranteed. */
233 #ifndef SOLIB_IN_DYNAMIC_LINKER
234 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
237 /* On MIPS16, a function that returns a floating point value may call
238 a library helper function to copy the return value to a floating point
239 register. The IGNORE_HELPER_CALL macro returns non-zero if we
240 should ignore (i.e. step over) this function call. */
241 #ifndef IGNORE_HELPER_CALL
242 #define IGNORE_HELPER_CALL(pc) 0
245 /* On some systems, the PC may be left pointing at an instruction that won't
246 actually be executed. This is usually indicated by a bit in the PSW. If
247 we find ourselves in such a state, then we step the target beyond the
248 nullified instruction before returning control to the user so as to avoid
251 #ifndef INSTRUCTION_NULLIFIED
252 #define INSTRUCTION_NULLIFIED 0
255 /* We can't step off a permanent breakpoint in the ordinary way, because we
256 can't remove it. Instead, we have to advance the PC to the next
257 instruction. This macro should expand to a pointer to a function that
258 does that, or zero if we have no such function. If we don't have a
259 definition for it, we have to report an error. */
260 #ifndef SKIP_PERMANENT_BREAKPOINT
261 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
263 default_skip_permanent_breakpoint (void)
266 fprintf_filtered (gdb_stderr
, "\
267 The program is stopped at a permanent breakpoint, but GDB does not know\n\
268 how to step past a permanent breakpoint on this architecture. Try using\n\
269 a command like `return' or `jump' to continue execution.\n");
270 return_to_top_level (RETURN_ERROR
);
275 /* Convert the #defines into values. This is temporary until wfi control
276 flow is completely sorted out. */
278 #ifndef HAVE_STEPPABLE_WATCHPOINT
279 #define HAVE_STEPPABLE_WATCHPOINT 0
281 #undef HAVE_STEPPABLE_WATCHPOINT
282 #define HAVE_STEPPABLE_WATCHPOINT 1
285 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
286 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
288 #undef HAVE_NONSTEPPABLE_WATCHPOINT
289 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
292 #ifndef HAVE_CONTINUABLE_WATCHPOINT
293 #define HAVE_CONTINUABLE_WATCHPOINT 0
295 #undef HAVE_CONTINUABLE_WATCHPOINT
296 #define HAVE_CONTINUABLE_WATCHPOINT 1
299 #ifndef CANNOT_STEP_HW_WATCHPOINTS
300 #define CANNOT_STEP_HW_WATCHPOINTS 0
302 #undef CANNOT_STEP_HW_WATCHPOINTS
303 #define CANNOT_STEP_HW_WATCHPOINTS 1
306 /* Tables of how to react to signals; the user sets them. */
308 static unsigned char *signal_stop
;
309 static unsigned char *signal_print
;
310 static unsigned char *signal_program
;
312 #define SET_SIGS(nsigs,sigs,flags) \
314 int signum = (nsigs); \
315 while (signum-- > 0) \
316 if ((sigs)[signum]) \
317 (flags)[signum] = 1; \
320 #define UNSET_SIGS(nsigs,sigs,flags) \
322 int signum = (nsigs); \
323 while (signum-- > 0) \
324 if ((sigs)[signum]) \
325 (flags)[signum] = 0; \
329 /* Command list pointer for the "stop" placeholder. */
331 static struct cmd_list_element
*stop_command
;
333 /* Nonzero if breakpoints are now inserted in the inferior. */
335 static int breakpoints_inserted
;
337 /* Function inferior was in as of last step command. */
339 static struct symbol
*step_start_function
;
341 /* Nonzero if we are expecting a trace trap and should proceed from it. */
343 static int trap_expected
;
346 /* Nonzero if we want to give control to the user when we're notified
347 of shared library events by the dynamic linker. */
348 static int stop_on_solib_events
;
352 /* Nonzero if the next time we try to continue the inferior, it will
353 step one instruction and generate a spurious trace trap.
354 This is used to compensate for a bug in HP-UX. */
356 static int trap_expected_after_continue
;
359 /* Nonzero means expecting a trace trap
360 and should stop the inferior and return silently when it happens. */
364 /* Nonzero means expecting a trap and caller will handle it themselves.
365 It is used after attach, due to attaching to a process;
366 when running in the shell before the child program has been exec'd;
367 and when running some kinds of remote stuff (FIXME?). */
369 int stop_soon_quietly
;
371 /* Nonzero if proceed is being used for a "finish" command or a similar
372 situation when stop_registers should be saved. */
374 int proceed_to_finish
;
376 /* Save register contents here when about to pop a stack dummy frame,
377 if-and-only-if proceed_to_finish is set.
378 Thus this contains the return value from the called function (assuming
379 values are returned in a register). */
381 char *stop_registers
;
383 /* Nonzero if program stopped due to error trying to insert breakpoints. */
385 static int breakpoints_failed
;
387 /* Nonzero after stop if current stack frame should be printed. */
389 static int stop_print_frame
;
391 static struct breakpoint
*step_resume_breakpoint
= NULL
;
392 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
394 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
395 interactions with an inferior that is running a kernel function
396 (aka, a system call or "syscall"). wait_for_inferior therefore
397 may have a need to know when the inferior is in a syscall. This
398 is a count of the number of inferior threads which are known to
399 currently be running in a syscall. */
400 static int number_of_threads_in_syscalls
;
402 /* This is used to remember when a fork, vfork or exec event
403 was caught by a catchpoint, and thus the event is to be
404 followed at the next resume of the inferior, and not
408 enum target_waitkind kind
;
418 char *execd_pathname
;
422 /* Some platforms don't allow us to do anything meaningful with a
423 vforked child until it has exec'd. Vforked processes on such
424 platforms can only be followed after they've exec'd.
426 When this is set to 0, a vfork can be immediately followed,
427 and an exec can be followed merely as an exec. When this is
428 set to 1, a vfork event has been seen, but cannot be followed
429 until the exec is seen.
431 (In the latter case, inferior_pid is still the parent of the
432 vfork, and pending_follow.fork_event.child_pid is the child. The
433 appropriate process is followed, according to the setting of
434 follow-fork-mode.) */
435 static int follow_vfork_when_exec
;
437 static const char follow_fork_mode_ask
[] = "ask";
438 static const char follow_fork_mode_both
[] = "both";
439 static const char follow_fork_mode_child
[] = "child";
440 static const char follow_fork_mode_parent
[] = "parent";
442 static const char *follow_fork_mode_kind_names
[] =
444 follow_fork_mode_ask
,
445 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
446 kernel problem. It's also not terribly useful without a GUI to
447 help the user drive two debuggers. So for now, I'm disabling the
449 /* follow_fork_mode_both, */
450 follow_fork_mode_child
,
451 follow_fork_mode_parent
,
455 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
459 follow_inferior_fork (int parent_pid
, int child_pid
, int has_forked
,
462 int followed_parent
= 0;
463 int followed_child
= 0;
465 /* Which process did the user want us to follow? */
466 const char *follow_mode
= follow_fork_mode_string
;
468 /* Or, did the user not know, and want us to ask? */
469 if (follow_fork_mode_string
== follow_fork_mode_ask
)
471 internal_error ("follow_inferior_fork: \"ask\" mode not implemented");
472 /* follow_mode = follow_fork_mode_...; */
475 /* If we're to be following the parent, then detach from child_pid.
476 We're already following the parent, so need do nothing explicit
478 if (follow_mode
== follow_fork_mode_parent
)
482 /* We're already attached to the parent, by default. */
484 /* Before detaching from the child, remove all breakpoints from
485 it. (This won't actually modify the breakpoint list, but will
486 physically remove the breakpoints from the child.) */
487 if (!has_vforked
|| !follow_vfork_when_exec
)
489 detach_breakpoints (child_pid
);
490 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
491 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
495 /* Detach from the child. */
498 target_require_detach (child_pid
, "", 1);
501 /* If we're to be following the child, then attach to it, detach
502 from inferior_pid, and set inferior_pid to child_pid. */
503 else if (follow_mode
== follow_fork_mode_child
)
505 char child_pid_spelling
[100]; /* Arbitrary length. */
509 /* Before detaching from the parent, detach all breakpoints from
510 the child. But only if we're forking, or if we follow vforks
511 as soon as they happen. (If we're following vforks only when
512 the child has exec'd, then it's very wrong to try to write
513 back the "shadow contents" of inserted breakpoints now -- they
514 belong to the child's pre-exec'd a.out.) */
515 if (!has_vforked
|| !follow_vfork_when_exec
)
517 detach_breakpoints (child_pid
);
520 /* Before detaching from the parent, remove all breakpoints from it. */
521 remove_breakpoints ();
523 /* Also reset the solib inferior hook from the parent. */
524 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
525 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid
);
528 /* Detach from the parent. */
530 target_detach (NULL
, 1);
532 /* Attach to the child. */
533 inferior_pid
= child_pid
;
534 sprintf (child_pid_spelling
, "%d", child_pid
);
537 target_require_attach (child_pid_spelling
, 1);
539 /* Was there a step_resume breakpoint? (There was if the user
540 did a "next" at the fork() call.) If so, explicitly reset its
543 step_resumes are a form of bp that are made to be per-thread.
544 Since we created the step_resume bp when the parent process
545 was being debugged, and now are switching to the child process,
546 from the breakpoint package's viewpoint, that's a switch of
547 "threads". We must update the bp's notion of which thread
548 it is for, or it'll be ignored when it triggers... */
549 if (step_resume_breakpoint
&&
550 (!has_vforked
|| !follow_vfork_when_exec
))
551 breakpoint_re_set_thread (step_resume_breakpoint
);
553 /* Reinsert all breakpoints in the child. (The user may've set
554 breakpoints after catching the fork, in which case those
555 actually didn't get set in the child, but only in the parent.) */
556 if (!has_vforked
|| !follow_vfork_when_exec
)
558 breakpoint_re_set ();
559 insert_breakpoints ();
563 /* If we're to be following both parent and child, then fork ourselves,
564 and attach the debugger clone to the child. */
565 else if (follow_mode
== follow_fork_mode_both
)
567 char pid_suffix
[100]; /* Arbitrary length. */
569 /* Clone ourselves to follow the child. This is the end of our
570 involvement with child_pid; our clone will take it from here... */
572 target_clone_and_follow_inferior (child_pid
, &followed_child
);
573 followed_parent
= !followed_child
;
575 /* We continue to follow the parent. To help distinguish the two
576 debuggers, though, both we and our clone will reset our prompts. */
577 sprintf (pid_suffix
, "[%d] ", inferior_pid
);
578 set_prompt (strcat (get_prompt (), pid_suffix
));
581 /* The parent and child of a vfork share the same address space.
582 Also, on some targets the order in which vfork and exec events
583 are received for parent in child requires some delicate handling
586 For instance, on ptrace-based HPUX we receive the child's vfork
587 event first, at which time the parent has been suspended by the
588 OS and is essentially untouchable until the child's exit or second
589 exec event arrives. At that time, the parent's vfork event is
590 delivered to us, and that's when we see and decide how to follow
591 the vfork. But to get to that point, we must continue the child
592 until it execs or exits. To do that smoothly, all breakpoints
593 must be removed from the child, in case there are any set between
594 the vfork() and exec() calls. But removing them from the child
595 also removes them from the parent, due to the shared-address-space
596 nature of a vfork'd parent and child. On HPUX, therefore, we must
597 take care to restore the bp's to the parent before we continue it.
598 Else, it's likely that we may not stop in the expected place. (The
599 worst scenario is when the user tries to step over a vfork() call;
600 the step-resume bp must be restored for the step to properly stop
601 in the parent after the call completes!)
603 Sequence of events, as reported to gdb from HPUX:
605 Parent Child Action for gdb to take
606 -------------------------------------------------------
607 1 VFORK Continue child
613 target_post_follow_vfork (parent_pid
,
619 pending_follow
.fork_event
.saw_parent_fork
= 0;
620 pending_follow
.fork_event
.saw_child_fork
= 0;
624 follow_fork (int parent_pid
, int child_pid
)
626 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
630 /* Forward declaration. */
631 static void follow_exec (int, char *);
634 follow_vfork (int parent_pid
, int child_pid
)
636 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
638 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
639 if (pending_follow
.fork_event
.saw_child_exec
&& (inferior_pid
== child_pid
))
641 pending_follow
.fork_event
.saw_child_exec
= 0;
642 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
643 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
644 free (pending_follow
.execd_pathname
);
649 follow_exec (int pid
, char *execd_pathname
)
652 struct target_ops
*tgt
;
654 if (!may_follow_exec
)
657 /* Did this exec() follow a vfork()? If so, we must follow the
658 vfork now too. Do it before following the exec. */
659 if (follow_vfork_when_exec
&&
660 (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
))
662 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
663 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
664 follow_vfork_when_exec
= 0;
665 saved_pid
= inferior_pid
;
667 /* Did we follow the parent? If so, we're done. If we followed
668 the child then we must also follow its exec(). */
669 if (inferior_pid
== pending_follow
.fork_event
.parent_pid
)
673 /* This is an exec event that we actually wish to pay attention to.
674 Refresh our symbol table to the newly exec'd program, remove any
677 If there are breakpoints, they aren't really inserted now,
678 since the exec() transformed our inferior into a fresh set
681 We want to preserve symbolic breakpoints on the list, since
682 we have hopes that they can be reset after the new a.out's
683 symbol table is read.
685 However, any "raw" breakpoints must be removed from the list
686 (e.g., the solib bp's), since their address is probably invalid
689 And, we DON'T want to call delete_breakpoints() here, since
690 that may write the bp's "shadow contents" (the instruction
691 value that was overwritten witha TRAP instruction). Since
692 we now have a new a.out, those shadow contents aren't valid. */
693 update_breakpoints_after_exec ();
695 /* If there was one, it's gone now. We cannot truly step-to-next
696 statement through an exec(). */
697 step_resume_breakpoint
= NULL
;
698 step_range_start
= 0;
701 /* If there was one, it's gone now. */
702 through_sigtramp_breakpoint
= NULL
;
704 /* What is this a.out's name? */
705 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
707 /* We've followed the inferior through an exec. Therefore, the
708 inferior has essentially been killed & reborn. */
710 /* First collect the run target in effect. */
711 tgt
= find_run_target ();
712 /* If we can't find one, things are in a very strange state... */
714 error ("Could find run target to save before following exec");
716 gdb_flush (gdb_stdout
);
717 target_mourn_inferior ();
718 inferior_pid
= saved_pid
; /* Because mourn_inferior resets inferior_pid. */
721 /* That a.out is now the one to use. */
722 exec_file_attach (execd_pathname
, 0);
724 /* And also is where symbols can be found. */
725 symbol_file_command (execd_pathname
, 0);
727 /* Reset the shared library package. This ensures that we get
728 a shlib event when the child reaches "_start", at which point
729 the dld will have had a chance to initialize the child. */
730 #if defined(SOLIB_RESTART)
733 #ifdef SOLIB_CREATE_INFERIOR_HOOK
734 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid
);
737 /* Reinsert all breakpoints. (Those which were symbolic have
738 been reset to the proper address in the new a.out, thanks
739 to symbol_file_command...) */
740 insert_breakpoints ();
742 /* The next resume of this inferior should bring it to the shlib
743 startup breakpoints. (If the user had also set bp's on
744 "main" from the old (parent) process, then they'll auto-
745 matically get reset there in the new process.) */
748 /* Non-zero if we just simulating a single-step. This is needed
749 because we cannot remove the breakpoints in the inferior process
750 until after the `wait' in `wait_for_inferior'. */
751 static int singlestep_breakpoints_inserted_p
= 0;
754 /* Things to clean up if we QUIT out of resume (). */
757 resume_cleanups (void *ignore
)
762 static const char schedlock_off
[] = "off";
763 static const char schedlock_on
[] = "on";
764 static const char schedlock_step
[] = "step";
765 static const char *scheduler_mode
= schedlock_off
;
766 static const char *scheduler_enums
[] =
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 (resume_cleanups
, 0);
804 #ifdef CANNOT_STEP_BREAKPOINT
805 /* Most targets can step a breakpoint instruction, thus executing it
806 normally. But if this one cannot, just continue and we will hit
808 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
812 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
813 over an instruction that causes a page fault without triggering
814 a hardware watchpoint. The kernel properly notices that it shouldn't
815 stop, because the hardware watchpoint is not triggered, but it forgets
816 the step request and continues the program normally.
817 Work around the problem by removing hardware watchpoints if a step is
818 requested, GDB will check for a hardware watchpoint trigger after the
820 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
821 remove_hw_watchpoints ();
824 /* Normally, by the time we reach `resume', the breakpoints are either
825 removed or inserted, as appropriate. The exception is if we're sitting
826 at a permanent breakpoint; we need to step over it, but permanent
827 breakpoints can't be removed. So we have to test for it here. */
828 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
829 SKIP_PERMANENT_BREAKPOINT ();
831 if (SOFTWARE_SINGLE_STEP_P
&& step
)
833 /* Do it the hard way, w/temp breakpoints */
834 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
835 /* ...and don't ask hardware to do it. */
837 /* and do not pull these breakpoints until after a `wait' in
838 `wait_for_inferior' */
839 singlestep_breakpoints_inserted_p
= 1;
842 /* Handle any optimized stores to the inferior NOW... */
843 #ifdef DO_DEFERRED_STORES
847 /* If there were any forks/vforks/execs that were caught and are
848 now to be followed, then do so. */
849 switch (pending_follow
.kind
)
851 case (TARGET_WAITKIND_FORKED
):
852 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
853 follow_fork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
856 case (TARGET_WAITKIND_VFORKED
):
858 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
860 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
861 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
863 /* Did we follow the child, but not yet see the child's exec event?
864 If so, then it actually ought to be waiting for us; we respond to
865 parent vfork events. We don't actually want to resume the child
866 in this situation; we want to just get its exec event. */
867 if (!saw_child_exec
&&
868 (inferior_pid
== pending_follow
.fork_event
.child_pid
))
873 case (TARGET_WAITKIND_EXECD
):
874 /* If we saw a vfork event but couldn't follow it until we saw
875 an exec, then now might be the time! */
876 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
877 /* follow_exec is called as soon as the exec event is seen. */
884 /* Install inferior's terminal modes. */
885 target_terminal_inferior ();
891 if (use_thread_step_needed
&& thread_step_needed
)
893 /* We stopped on a BPT instruction;
894 don't continue other threads and
895 just step this thread. */
896 thread_step_needed
= 0;
898 if (!breakpoint_here_p (read_pc ()))
900 /* Breakpoint deleted: ok to do regular resume
901 where all the threads either step or continue. */
908 warning ("Internal error, changing continue to step.");
909 remove_breakpoints ();
910 breakpoints_inserted
= 0;
914 resume_pid
= inferior_pid
;
919 /* Vanilla resume. */
920 if ((scheduler_mode
== schedlock_on
) ||
921 (scheduler_mode
== schedlock_step
&& step
!= 0))
922 resume_pid
= inferior_pid
;
926 target_resume (resume_pid
, step
, sig
);
929 discard_cleanups (old_cleanups
);
933 /* Clear out all variables saying what to do when inferior is continued.
934 First do this, then set the ones you want, then call `proceed'. */
937 clear_proceed_status (void)
940 step_range_start
= 0;
942 step_frame_address
= 0;
943 step_over_calls
= -1;
945 stop_soon_quietly
= 0;
946 proceed_to_finish
= 0;
947 breakpoint_proceeded
= 1; /* We're about to proceed... */
949 /* Discard any remaining commands or status from previous stop. */
950 bpstat_clear (&stop_bpstat
);
953 /* Basic routine for continuing the program in various fashions.
955 ADDR is the address to resume at, or -1 for resume where stopped.
956 SIGGNAL is the signal to give it, or 0 for none,
957 or -1 for act according to how it stopped.
958 STEP is nonzero if should trap after one instruction.
959 -1 means return after that and print nothing.
960 You should probably set various step_... variables
961 before calling here, if you are stepping.
963 You should call clear_proceed_status before calling proceed. */
966 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
971 step_start_function
= find_pc_function (read_pc ());
975 if (addr
== (CORE_ADDR
) -1)
977 /* If there is a breakpoint at the address we will resume at,
978 step one instruction before inserting breakpoints
979 so that we do not stop right away (and report a second
980 hit at this breakpoint). */
982 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
985 #ifndef STEP_SKIPS_DELAY
986 #define STEP_SKIPS_DELAY(pc) (0)
987 #define STEP_SKIPS_DELAY_P (0)
989 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
990 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
991 is slow (it needs to read memory from the target). */
992 if (STEP_SKIPS_DELAY_P
993 && breakpoint_here_p (read_pc () + 4)
994 && STEP_SKIPS_DELAY (read_pc ()))
1001 /* New address; we don't need to single-step a thread
1002 over a breakpoint we just hit, 'cause we aren't
1003 continuing from there.
1005 It's not worth worrying about the case where a user
1006 asks for a "jump" at the current PC--if they get the
1007 hiccup of re-hiting a hit breakpoint, what else do
1009 thread_step_needed
= 0;
1012 #ifdef PREPARE_TO_PROCEED
1013 /* In a multi-threaded task we may select another thread
1014 and then continue or step.
1016 But if the old thread was stopped at a breakpoint, it
1017 will immediately cause another breakpoint stop without
1018 any execution (i.e. it will report a breakpoint hit
1019 incorrectly). So we must step over it first.
1021 PREPARE_TO_PROCEED checks the current thread against the thread
1022 that reported the most recent event. If a step-over is required
1023 it returns TRUE and sets the current thread to the old thread. */
1024 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
1027 thread_step_needed
= 1;
1030 #endif /* PREPARE_TO_PROCEED */
1033 if (trap_expected_after_continue
)
1035 /* If (step == 0), a trap will be automatically generated after
1036 the first instruction is executed. Force step one
1037 instruction to clear this condition. This should not occur
1038 if step is nonzero, but it is harmless in that case. */
1040 trap_expected_after_continue
= 0;
1042 #endif /* HP_OS_BUG */
1045 /* We will get a trace trap after one instruction.
1046 Continue it automatically and insert breakpoints then. */
1050 int temp
= insert_breakpoints ();
1053 print_sys_errmsg ("insert_breakpoints", temp
);
1054 error ("Cannot insert breakpoints.\n\
1055 The same program may be running in another process,\n\
1056 or you may have requested too many hardware\n\
1057 breakpoints and/or watchpoints.\n");
1060 breakpoints_inserted
= 1;
1063 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1064 stop_signal
= siggnal
;
1065 /* If this signal should not be seen by program,
1066 give it zero. Used for debugging signals. */
1067 else if (!signal_program
[stop_signal
])
1068 stop_signal
= TARGET_SIGNAL_0
;
1070 annotate_starting ();
1072 /* Make sure that output from GDB appears before output from the
1074 gdb_flush (gdb_stdout
);
1076 /* Resume inferior. */
1077 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1079 /* Wait for it to stop (if not standalone)
1080 and in any case decode why it stopped, and act accordingly. */
1081 /* Do this only if we are not using the event loop, or if the target
1082 does not support asynchronous execution. */
1083 if (!event_loop_p
|| !target_can_async_p ())
1085 wait_for_inferior ();
1090 /* Record the pc and sp of the program the last time it stopped.
1091 These are just used internally by wait_for_inferior, but need
1092 to be preserved over calls to it and cleared when the inferior
1094 static CORE_ADDR prev_pc
;
1095 static CORE_ADDR prev_func_start
;
1096 static char *prev_func_name
;
1099 /* Start remote-debugging of a machine over a serial link. */
1104 init_thread_list ();
1105 init_wait_for_inferior ();
1106 stop_soon_quietly
= 1;
1109 /* Always go on waiting for the target, regardless of the mode. */
1110 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1111 indicate th wait_for_inferior that a target should timeout if
1112 nothing is returned (instead of just blocking). Because of this,
1113 targets expecting an immediate response need to, internally, set
1114 things up so that the target_wait() is forced to eventually
1116 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1117 differentiate to its caller what the state of the target is after
1118 the initial open has been performed. Here we're assuming that
1119 the target has stopped. It should be possible to eventually have
1120 target_open() return to the caller an indication that the target
1121 is currently running and GDB state should be set to the same as
1122 for an async run. */
1123 wait_for_inferior ();
1127 /* Initialize static vars when a new inferior begins. */
1130 init_wait_for_inferior (void)
1132 /* These are meaningless until the first time through wait_for_inferior. */
1134 prev_func_start
= 0;
1135 prev_func_name
= NULL
;
1138 trap_expected_after_continue
= 0;
1140 breakpoints_inserted
= 0;
1141 breakpoint_init_inferior (inf_starting
);
1143 /* Don't confuse first call to proceed(). */
1144 stop_signal
= TARGET_SIGNAL_0
;
1146 /* The first resume is not following a fork/vfork/exec. */
1147 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1148 pending_follow
.fork_event
.saw_parent_fork
= 0;
1149 pending_follow
.fork_event
.saw_child_fork
= 0;
1150 pending_follow
.fork_event
.saw_child_exec
= 0;
1152 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1153 number_of_threads_in_syscalls
= 0;
1155 clear_proceed_status ();
1159 delete_breakpoint_current_contents (void *arg
)
1161 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1162 if (*breakpointp
!= NULL
)
1164 delete_breakpoint (*breakpointp
);
1165 *breakpointp
= NULL
;
1169 /* This enum encodes possible reasons for doing a target_wait, so that
1170 wfi can call target_wait in one place. (Ultimately the call will be
1171 moved out of the infinite loop entirely.) */
1175 infwait_normal_state
,
1176 infwait_thread_hop_state
,
1177 infwait_nullified_state
,
1178 infwait_nonstep_watch_state
1181 /* Why did the inferior stop? Used to print the appropriate messages
1182 to the interface from within handle_inferior_event(). */
1183 enum inferior_stop_reason
1185 /* We don't know why. */
1187 /* Step, next, nexti, stepi finished. */
1189 /* Found breakpoint. */
1191 /* Inferior terminated by signal. */
1193 /* Inferior exited. */
1195 /* Inferior received signal, and user asked to be notified. */
1199 /* This structure contains what used to be local variables in
1200 wait_for_inferior. Probably many of them can return to being
1201 locals in handle_inferior_event. */
1203 struct execution_control_state
1205 struct target_waitstatus ws
;
1206 struct target_waitstatus
*wp
;
1209 CORE_ADDR stop_func_start
;
1210 CORE_ADDR stop_func_end
;
1211 char *stop_func_name
;
1212 struct symtab_and_line sal
;
1213 int remove_breakpoints_on_following_step
;
1215 struct symtab
*current_symtab
;
1216 int handling_longjmp
; /* FIXME */
1218 int saved_inferior_pid
;
1220 int stepping_through_solib_after_catch
;
1221 bpstat stepping_through_solib_catchpoints
;
1222 int enable_hw_watchpoints_after_wait
;
1223 int stepping_through_sigtramp
;
1224 int new_thread_event
;
1225 struct target_waitstatus tmpstatus
;
1226 enum infwait_states infwait_state
;
1231 void init_execution_control_state (struct execution_control_state
* ecs
);
1233 void handle_inferior_event (struct execution_control_state
* ecs
);
1235 static void check_sigtramp2 (struct execution_control_state
*ecs
);
1236 static void step_into_function (struct execution_control_state
*ecs
);
1237 static void step_over_function (struct execution_control_state
*ecs
);
1238 static void stop_stepping (struct execution_control_state
*ecs
);
1239 static void prepare_to_wait (struct execution_control_state
*ecs
);
1240 static void keep_going (struct execution_control_state
*ecs
);
1241 static void print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
);
1243 /* Wait for control to return from inferior to debugger.
1244 If inferior gets a signal, we may decide to start it up again
1245 instead of returning. That is why there is a loop in this function.
1246 When this function actually returns it means the inferior
1247 should be left stopped and GDB should read more commands. */
1250 wait_for_inferior (void)
1252 struct cleanup
*old_cleanups
;
1253 struct execution_control_state ecss
;
1254 struct execution_control_state
*ecs
;
1256 old_cleanups
= make_cleanup (delete_breakpoint_current_contents
,
1257 &step_resume_breakpoint
);
1258 make_cleanup (delete_breakpoint_current_contents
,
1259 &through_sigtramp_breakpoint
);
1261 /* wfi still stays in a loop, so it's OK just to take the address of
1262 a local to get the ecs pointer. */
1265 /* Fill in with reasonable starting values. */
1266 init_execution_control_state (ecs
);
1268 thread_step_needed
= 0;
1270 /* We'll update this if & when we switch to a new thread. */
1271 previous_inferior_pid
= inferior_pid
;
1273 overlay_cache_invalid
= 1;
1275 /* We have to invalidate the registers BEFORE calling target_wait
1276 because they can be loaded from the target while in target_wait.
1277 This makes remote debugging a bit more efficient for those
1278 targets that provide critical registers as part of their normal
1279 status mechanism. */
1281 registers_changed ();
1285 if (target_wait_hook
)
1286 ecs
->pid
= target_wait_hook (ecs
->waiton_pid
, ecs
->wp
);
1288 ecs
->pid
= target_wait (ecs
->waiton_pid
, ecs
->wp
);
1290 /* Now figure out what to do with the result of the result. */
1291 handle_inferior_event (ecs
);
1293 if (!ecs
->wait_some_more
)
1296 do_cleanups (old_cleanups
);
1299 /* Asynchronous version of wait_for_inferior. It is called by the
1300 event loop whenever a change of state is detected on the file
1301 descriptor corresponding to the target. It can be called more than
1302 once to complete a single execution command. In such cases we need
1303 to keep the state in a global variable ASYNC_ECSS. If it is the
1304 last time that this function is called for a single execution
1305 command, then report to the user that the inferior has stopped, and
1306 do the necessary cleanups. */
1308 struct execution_control_state async_ecss
;
1309 struct execution_control_state
*async_ecs
;
1312 fetch_inferior_event (client_data
)
1315 static struct cleanup
*old_cleanups
;
1317 async_ecs
= &async_ecss
;
1319 if (!async_ecs
->wait_some_more
)
1321 old_cleanups
= make_exec_cleanup (delete_breakpoint_current_contents
,
1322 &step_resume_breakpoint
);
1323 make_exec_cleanup (delete_breakpoint_current_contents
,
1324 &through_sigtramp_breakpoint
);
1326 /* Fill in with reasonable starting values. */
1327 init_execution_control_state (async_ecs
);
1329 thread_step_needed
= 0;
1331 /* We'll update this if & when we switch to a new thread. */
1332 previous_inferior_pid
= inferior_pid
;
1334 overlay_cache_invalid
= 1;
1336 /* We have to invalidate the registers BEFORE calling target_wait
1337 because they can be loaded from the target while in target_wait.
1338 This makes remote debugging a bit more efficient for those
1339 targets that provide critical registers as part of their normal
1340 status mechanism. */
1342 registers_changed ();
1345 if (target_wait_hook
)
1346 async_ecs
->pid
= target_wait_hook (async_ecs
->waiton_pid
, async_ecs
->wp
);
1348 async_ecs
->pid
= target_wait (async_ecs
->waiton_pid
, async_ecs
->wp
);
1350 /* Now figure out what to do with the result of the result. */
1351 handle_inferior_event (async_ecs
);
1353 if (!async_ecs
->wait_some_more
)
1355 /* Do only the cleanups that have been added by this
1356 function. Let the continuations for the commands do the rest,
1357 if there are any. */
1358 do_exec_cleanups (old_cleanups
);
1360 if (step_multi
&& stop_step
)
1361 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1363 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1367 /* Prepare an execution control state for looping through a
1368 wait_for_inferior-type loop. */
1371 init_execution_control_state (struct execution_control_state
*ecs
)
1373 /* ecs->another_trap? */
1374 ecs
->random_signal
= 0;
1375 ecs
->remove_breakpoints_on_following_step
= 0;
1376 ecs
->handling_longjmp
= 0; /* FIXME */
1377 ecs
->update_step_sp
= 0;
1378 ecs
->stepping_through_solib_after_catch
= 0;
1379 ecs
->stepping_through_solib_catchpoints
= NULL
;
1380 ecs
->enable_hw_watchpoints_after_wait
= 0;
1381 ecs
->stepping_through_sigtramp
= 0;
1382 ecs
->sal
= find_pc_line (prev_pc
, 0);
1383 ecs
->current_line
= ecs
->sal
.line
;
1384 ecs
->current_symtab
= ecs
->sal
.symtab
;
1385 ecs
->infwait_state
= infwait_normal_state
;
1386 ecs
->waiton_pid
= -1;
1387 ecs
->wp
= &(ecs
->ws
);
1390 /* Call this function before setting step_resume_breakpoint, as a
1391 sanity check. There should never be more than one step-resume
1392 breakpoint per thread, so we should never be setting a new
1393 step_resume_breakpoint when one is already active. */
1395 check_for_old_step_resume_breakpoint (void)
1397 if (step_resume_breakpoint
)
1398 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1401 /* Given an execution control state that has been freshly filled in
1402 by an event from the inferior, figure out what it means and take
1403 appropriate action. */
1406 handle_inferior_event (struct execution_control_state
*ecs
)
1409 int stepped_after_stopped_by_watchpoint
;
1411 /* Keep this extra brace for now, minimizes diffs. */
1413 switch (ecs
->infwait_state
)
1415 case infwait_normal_state
:
1416 /* Since we've done a wait, we have a new event. Don't
1417 carry over any expectations about needing to step over a
1419 thread_step_needed
= 0;
1421 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1422 is serviced in this loop, below. */
1423 if (ecs
->enable_hw_watchpoints_after_wait
)
1425 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid
);
1426 ecs
->enable_hw_watchpoints_after_wait
= 0;
1428 stepped_after_stopped_by_watchpoint
= 0;
1431 case infwait_thread_hop_state
:
1432 insert_breakpoints ();
1434 /* We need to restart all the threads now,
1435 * unles we're running in scheduler-locked mode.
1436 * FIXME: shouldn't we look at currently_stepping ()?
1438 if (scheduler_mode
== schedlock_on
)
1439 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1441 target_resume (-1, 0, TARGET_SIGNAL_0
);
1442 ecs
->infwait_state
= infwait_normal_state
;
1443 prepare_to_wait (ecs
);
1446 case infwait_nullified_state
:
1449 case infwait_nonstep_watch_state
:
1450 insert_breakpoints ();
1452 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1453 handle things like signals arriving and other things happening
1454 in combination correctly? */
1455 stepped_after_stopped_by_watchpoint
= 1;
1458 ecs
->infwait_state
= infwait_normal_state
;
1460 flush_cached_frames ();
1462 /* If it's a new process, add it to the thread database */
1464 ecs
->new_thread_event
= ((ecs
->pid
!= inferior_pid
) && !in_thread_list (ecs
->pid
));
1466 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1467 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1468 && ecs
->new_thread_event
)
1470 add_thread (ecs
->pid
);
1473 ui_out_text (uiout
, "[New ");
1474 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->pid
));
1475 ui_out_text (uiout
, "]\n");
1477 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs
->pid
));
1481 /* NOTE: This block is ONLY meant to be invoked in case of a
1482 "thread creation event"! If it is invoked for any other
1483 sort of event (such as a new thread landing on a breakpoint),
1484 the event will be discarded, which is almost certainly
1487 To avoid this, the low-level module (eg. target_wait)
1488 should call in_thread_list and add_thread, so that the
1489 new thread is known by the time we get here. */
1491 /* We may want to consider not doing a resume here in order
1492 to give the user a chance to play with the new thread.
1493 It might be good to make that a user-settable option. */
1495 /* At this point, all threads are stopped (happens
1496 automatically in either the OS or the native code).
1497 Therefore we need to continue all threads in order to
1500 target_resume (-1, 0, TARGET_SIGNAL_0
);
1501 prepare_to_wait (ecs
);
1506 switch (ecs
->ws
.kind
)
1508 case TARGET_WAITKIND_LOADED
:
1509 /* Ignore gracefully during startup of the inferior, as it
1510 might be the shell which has just loaded some objects,
1511 otherwise add the symbols for the newly loaded objects. */
1513 if (!stop_soon_quietly
)
1515 /* Remove breakpoints, SOLIB_ADD might adjust
1516 breakpoint addresses via breakpoint_re_set. */
1517 if (breakpoints_inserted
)
1518 remove_breakpoints ();
1520 /* Check for any newly added shared libraries if we're
1521 supposed to be adding them automatically. */
1524 /* Switch terminal for any messages produced by
1525 breakpoint_re_set. */
1526 target_terminal_ours_for_output ();
1527 SOLIB_ADD (NULL
, 0, NULL
);
1528 target_terminal_inferior ();
1531 /* Reinsert breakpoints and continue. */
1532 if (breakpoints_inserted
)
1533 insert_breakpoints ();
1536 resume (0, TARGET_SIGNAL_0
);
1537 prepare_to_wait (ecs
);
1540 case TARGET_WAITKIND_SPURIOUS
:
1541 resume (0, TARGET_SIGNAL_0
);
1542 prepare_to_wait (ecs
);
1545 case TARGET_WAITKIND_EXITED
:
1546 target_terminal_ours (); /* Must do this before mourn anyway */
1547 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1549 /* Record the exit code in the convenience variable $_exitcode, so
1550 that the user can inspect this again later. */
1551 set_internalvar (lookup_internalvar ("_exitcode"),
1552 value_from_longest (builtin_type_int
,
1553 (LONGEST
) ecs
->ws
.value
.integer
));
1554 gdb_flush (gdb_stdout
);
1555 target_mourn_inferior ();
1556 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P */
1557 stop_print_frame
= 0;
1558 stop_stepping (ecs
);
1561 case TARGET_WAITKIND_SIGNALLED
:
1562 stop_print_frame
= 0;
1563 stop_signal
= ecs
->ws
.value
.sig
;
1564 target_terminal_ours (); /* Must do this before mourn anyway */
1566 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1567 reach here unless the inferior is dead. However, for years
1568 target_kill() was called here, which hints that fatal signals aren't
1569 really fatal on some systems. If that's true, then some changes
1571 target_mourn_inferior ();
1573 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1574 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P */
1575 stop_stepping (ecs
);
1578 /* The following are the only cases in which we keep going;
1579 the above cases end in a continue or goto. */
1580 case TARGET_WAITKIND_FORKED
:
1581 stop_signal
= TARGET_SIGNAL_TRAP
;
1582 pending_follow
.kind
= ecs
->ws
.kind
;
1584 /* Ignore fork events reported for the parent; we're only
1585 interested in reacting to forks of the child. Note that
1586 we expect the child's fork event to be available if we
1587 waited for it now. */
1588 if (inferior_pid
== ecs
->pid
)
1590 pending_follow
.fork_event
.saw_parent_fork
= 1;
1591 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1592 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1593 prepare_to_wait (ecs
);
1598 pending_follow
.fork_event
.saw_child_fork
= 1;
1599 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1600 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1603 stop_pc
= read_pc_pid (ecs
->pid
);
1604 ecs
->saved_inferior_pid
= inferior_pid
;
1605 inferior_pid
= ecs
->pid
;
1606 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1607 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1608 inferior_pid
= ecs
->saved_inferior_pid
;
1609 goto process_event_stop_test
;
1611 /* If this a platform which doesn't allow a debugger to touch a
1612 vfork'd inferior until after it exec's, then we'd best keep
1613 our fingers entirely off the inferior, other than continuing
1614 it. This has the unfortunate side-effect that catchpoints
1615 of vforks will be ignored. But since the platform doesn't
1616 allow the inferior be touched at vfork time, there's really
1618 case TARGET_WAITKIND_VFORKED
:
1619 stop_signal
= TARGET_SIGNAL_TRAP
;
1620 pending_follow
.kind
= ecs
->ws
.kind
;
1622 /* Is this a vfork of the parent? If so, then give any
1623 vfork catchpoints a chance to trigger now. (It's
1624 dangerous to do so if the child canot be touched until
1625 it execs, and the child has not yet exec'd. We probably
1626 should warn the user to that effect when the catchpoint
1628 if (ecs
->pid
== inferior_pid
)
1630 pending_follow
.fork_event
.saw_parent_fork
= 1;
1631 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1632 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1635 /* If we've seen the child's vfork event but cannot really touch
1636 the child until it execs, then we must continue the child now.
1637 Else, give any vfork catchpoints a chance to trigger now. */
1640 pending_follow
.fork_event
.saw_child_fork
= 1;
1641 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1642 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1643 target_post_startup_inferior (pending_follow
.fork_event
.child_pid
);
1644 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1645 if (follow_vfork_when_exec
)
1647 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1648 prepare_to_wait (ecs
);
1653 stop_pc
= read_pc ();
1654 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1655 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1656 goto process_event_stop_test
;
1658 case TARGET_WAITKIND_EXECD
:
1659 stop_signal
= TARGET_SIGNAL_TRAP
;
1661 /* Is this a target which reports multiple exec events per actual
1662 call to exec()? (HP-UX using ptrace does, for example.) If so,
1663 ignore all but the last one. Just resume the exec'r, and wait
1664 for the next exec event. */
1665 if (inferior_ignoring_leading_exec_events
)
1667 inferior_ignoring_leading_exec_events
--;
1668 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1669 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.parent_pid
);
1670 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1671 prepare_to_wait (ecs
);
1674 inferior_ignoring_leading_exec_events
=
1675 target_reported_exec_events_per_exec_call () - 1;
1677 pending_follow
.execd_pathname
=
1678 savestring (ecs
->ws
.value
.execd_pathname
,
1679 strlen (ecs
->ws
.value
.execd_pathname
));
1681 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1682 child of a vfork exec?
1684 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1685 HP-UX, events associated with a vforking inferior come in
1686 threes: a vfork event for the child (always first), followed
1687 a vfork event for the parent and an exec event for the child.
1688 The latter two can come in either order.
1690 If we get the parent vfork event first, life's good: We follow
1691 either the parent or child, and then the child's exec event is
1694 But if we get the child's exec event first, then we delay
1695 responding to it until we handle the parent's vfork. Because,
1696 otherwise we can't satisfy a "catch vfork". */
1697 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1699 pending_follow
.fork_event
.saw_child_exec
= 1;
1701 /* On some targets, the child must be resumed before
1702 the parent vfork event is delivered. A single-step
1704 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1705 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1706 /* We expect the parent vfork event to be available now. */
1707 prepare_to_wait (ecs
);
1711 /* This causes the eventpoints and symbol table to be reset. Must
1712 do this now, before trying to determine whether to stop. */
1713 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
1714 free (pending_follow
.execd_pathname
);
1716 stop_pc
= read_pc_pid (ecs
->pid
);
1717 ecs
->saved_inferior_pid
= inferior_pid
;
1718 inferior_pid
= ecs
->pid
;
1719 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1720 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1721 inferior_pid
= ecs
->saved_inferior_pid
;
1722 goto process_event_stop_test
;
1724 /* These syscall events are returned on HP-UX, as part of its
1725 implementation of page-protection-based "hardware" watchpoints.
1726 HP-UX has unfortunate interactions between page-protections and
1727 some system calls. Our solution is to disable hardware watches
1728 when a system call is entered, and reenable them when the syscall
1729 completes. The downside of this is that we may miss the precise
1730 point at which a watched piece of memory is modified. "Oh well."
1732 Note that we may have multiple threads running, which may each
1733 enter syscalls at roughly the same time. Since we don't have a
1734 good notion currently of whether a watched piece of memory is
1735 thread-private, we'd best not have any page-protections active
1736 when any thread is in a syscall. Thus, we only want to reenable
1737 hardware watches when no threads are in a syscall.
1739 Also, be careful not to try to gather much state about a thread
1740 that's in a syscall. It's frequently a losing proposition. */
1741 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1742 number_of_threads_in_syscalls
++;
1743 if (number_of_threads_in_syscalls
== 1)
1745 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid
);
1747 resume (0, TARGET_SIGNAL_0
);
1748 prepare_to_wait (ecs
);
1751 /* Before examining the threads further, step this thread to
1752 get it entirely out of the syscall. (We get notice of the
1753 event when the thread is just on the verge of exiting a
1754 syscall. Stepping one instruction seems to get it back
1757 Note that although the logical place to reenable h/w watches
1758 is here, we cannot. We cannot reenable them before stepping
1759 the thread (this causes the next wait on the thread to hang).
1761 Nor can we enable them after stepping until we've done a wait.
1762 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1763 here, which will be serviced immediately after the target
1765 case TARGET_WAITKIND_SYSCALL_RETURN
:
1766 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1768 if (number_of_threads_in_syscalls
> 0)
1770 number_of_threads_in_syscalls
--;
1771 ecs
->enable_hw_watchpoints_after_wait
=
1772 (number_of_threads_in_syscalls
== 0);
1774 prepare_to_wait (ecs
);
1777 case TARGET_WAITKIND_STOPPED
:
1778 stop_signal
= ecs
->ws
.value
.sig
;
1781 /* We had an event in the inferior, but we are not interested
1782 in handling it at this level. The lower layers have already
1783 done what needs to be done, if anything. This case can
1784 occur only when the target is async or extended-async. One
1785 of the circumstamces for this to happen is when the
1786 inferior produces output for the console. The inferior has
1787 not stopped, and we are ignoring the event. */
1788 case TARGET_WAITKIND_IGNORE
:
1789 ecs
->wait_some_more
= 1;
1793 /* We may want to consider not doing a resume here in order to give
1794 the user a chance to play with the new thread. It might be good
1795 to make that a user-settable option. */
1797 /* At this point, all threads are stopped (happens automatically in
1798 either the OS or the native code). Therefore we need to continue
1799 all threads in order to make progress. */
1800 if (ecs
->new_thread_event
)
1802 target_resume (-1, 0, TARGET_SIGNAL_0
);
1803 prepare_to_wait (ecs
);
1807 stop_pc
= read_pc_pid (ecs
->pid
);
1809 /* See if a thread hit a thread-specific breakpoint that was meant for
1810 another thread. If so, then step that thread past the breakpoint,
1813 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1815 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1816 ecs
->random_signal
= 0;
1817 else if (breakpoints_inserted
1818 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1820 ecs
->random_signal
= 0;
1821 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1826 /* Saw a breakpoint, but it was hit by the wrong thread.
1828 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->pid
);
1830 remove_status
= remove_breakpoints ();
1831 /* Did we fail to remove breakpoints? If so, try
1832 to set the PC past the bp. (There's at least
1833 one situation in which we can fail to remove
1834 the bp's: On HP-UX's that use ttrace, we can't
1835 change the address space of a vforking child
1836 process until the child exits (well, okay, not
1837 then either :-) or execs. */
1838 if (remove_status
!= 0)
1840 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->pid
);
1844 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1845 /* FIXME: What if a signal arrives instead of the
1846 single-step happening? */
1848 ecs
->waiton_pid
= ecs
->pid
;
1849 ecs
->wp
= &(ecs
->ws
);
1850 ecs
->infwait_state
= infwait_thread_hop_state
;
1851 prepare_to_wait (ecs
);
1855 /* We need to restart all the threads now,
1856 * unles we're running in scheduler-locked mode.
1857 * FIXME: shouldn't we look at currently_stepping ()?
1859 if (scheduler_mode
== schedlock_on
)
1860 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1862 target_resume (-1, 0, TARGET_SIGNAL_0
);
1863 prepare_to_wait (ecs
);
1868 /* This breakpoint matches--either it is the right
1869 thread or it's a generic breakpoint for all threads.
1870 Remember that we'll need to step just _this_ thread
1871 on any following user continuation! */
1872 thread_step_needed
= 1;
1877 ecs
->random_signal
= 1;
1879 /* See if something interesting happened to the non-current thread. If
1880 so, then switch to that thread, and eventually give control back to
1883 Note that if there's any kind of pending follow (i.e., of a fork,
1884 vfork or exec), we don't want to do this now. Rather, we'll let
1885 the next resume handle it. */
1886 if ((ecs
->pid
!= inferior_pid
) &&
1887 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1891 /* If it's a random signal for a non-current thread, notify user
1892 if he's expressed an interest. */
1893 if (ecs
->random_signal
1894 && signal_print
[stop_signal
])
1896 /* ??rehrauer: I don't understand the rationale for this code. If the
1897 inferior will stop as a result of this signal, then the act of handling
1898 the stop ought to print a message that's couches the stoppage in user
1899 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1900 won't stop as a result of the signal -- i.e., if the signal is merely
1901 a side-effect of something GDB's doing "under the covers" for the
1902 user, such as stepping threads over a breakpoint they shouldn't stop
1903 for -- then the message seems to be a serious annoyance at best.
1905 For now, remove the message altogether. */
1908 target_terminal_ours_for_output ();
1909 printf_filtered ("\nProgram received signal %s, %s.\n",
1910 target_signal_to_name (stop_signal
),
1911 target_signal_to_string (stop_signal
));
1912 gdb_flush (gdb_stdout
);
1916 /* If it's not SIGTRAP and not a signal we want to stop for, then
1917 continue the thread. */
1919 if (stop_signal
!= TARGET_SIGNAL_TRAP
1920 && !signal_stop
[stop_signal
])
1923 target_terminal_inferior ();
1925 /* Clear the signal if it should not be passed. */
1926 if (signal_program
[stop_signal
] == 0)
1927 stop_signal
= TARGET_SIGNAL_0
;
1929 target_resume (ecs
->pid
, 0, stop_signal
);
1930 prepare_to_wait (ecs
);
1934 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1935 and fall into the rest of wait_for_inferior(). */
1937 /* Caution: it may happen that the new thread (or the old one!)
1938 is not in the thread list. In this case we must not attempt
1939 to "switch context", or we run the risk that our context may
1940 be lost. This may happen as a result of the target module
1941 mishandling thread creation. */
1943 if (in_thread_list (inferior_pid
) && in_thread_list (ecs
->pid
))
1944 { /* Perform infrun state context switch: */
1945 /* Save infrun state for the old thread. */
1946 save_infrun_state (inferior_pid
, prev_pc
,
1947 prev_func_start
, prev_func_name
,
1948 trap_expected
, step_resume_breakpoint
,
1949 through_sigtramp_breakpoint
,
1950 step_range_start
, step_range_end
,
1951 step_frame_address
, ecs
->handling_longjmp
,
1953 ecs
->stepping_through_solib_after_catch
,
1954 ecs
->stepping_through_solib_catchpoints
,
1955 ecs
->stepping_through_sigtramp
);
1957 /* Load infrun state for the new thread. */
1958 load_infrun_state (ecs
->pid
, &prev_pc
,
1959 &prev_func_start
, &prev_func_name
,
1960 &trap_expected
, &step_resume_breakpoint
,
1961 &through_sigtramp_breakpoint
,
1962 &step_range_start
, &step_range_end
,
1963 &step_frame_address
, &ecs
->handling_longjmp
,
1965 &ecs
->stepping_through_solib_after_catch
,
1966 &ecs
->stepping_through_solib_catchpoints
,
1967 &ecs
->stepping_through_sigtramp
);
1970 inferior_pid
= ecs
->pid
;
1973 context_hook (pid_to_thread_id (ecs
->pid
));
1975 flush_cached_frames ();
1978 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1980 /* Pull the single step breakpoints out of the target. */
1981 SOFTWARE_SINGLE_STEP (0, 0);
1982 singlestep_breakpoints_inserted_p
= 0;
1985 /* If PC is pointing at a nullified instruction, then step beyond
1986 it so that the user won't be confused when GDB appears to be ready
1989 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1990 if (INSTRUCTION_NULLIFIED
)
1992 registers_changed ();
1993 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1995 /* We may have received a signal that we want to pass to
1996 the inferior; therefore, we must not clobber the waitstatus
1999 ecs
->infwait_state
= infwait_nullified_state
;
2000 ecs
->waiton_pid
= ecs
->pid
;
2001 ecs
->wp
= &(ecs
->tmpstatus
);
2002 prepare_to_wait (ecs
);
2006 /* It may not be necessary to disable the watchpoint to stop over
2007 it. For example, the PA can (with some kernel cooperation)
2008 single step over a watchpoint without disabling the watchpoint. */
2009 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2012 prepare_to_wait (ecs
);
2016 /* It is far more common to need to disable a watchpoint to step
2017 the inferior over it. FIXME. What else might a debug
2018 register or page protection watchpoint scheme need here? */
2019 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
2021 /* At this point, we are stopped at an instruction which has
2022 attempted to write to a piece of memory under control of
2023 a watchpoint. The instruction hasn't actually executed
2024 yet. If we were to evaluate the watchpoint expression
2025 now, we would get the old value, and therefore no change
2026 would seem to have occurred.
2028 In order to make watchpoints work `right', we really need
2029 to complete the memory write, and then evaluate the
2030 watchpoint expression. The following code does that by
2031 removing the watchpoint (actually, all watchpoints and
2032 breakpoints), single-stepping the target, re-inserting
2033 watchpoints, and then falling through to let normal
2034 single-step processing handle proceed. Since this
2035 includes evaluating watchpoints, things will come to a
2036 stop in the correct manner. */
2038 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
2040 remove_breakpoints ();
2041 registers_changed ();
2042 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
); /* Single step */
2044 ecs
->waiton_pid
= ecs
->pid
;
2045 ecs
->wp
= &(ecs
->ws
);
2046 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2047 prepare_to_wait (ecs
);
2051 /* It may be possible to simply continue after a watchpoint. */
2052 if (HAVE_CONTINUABLE_WATCHPOINT
)
2053 STOPPED_BY_WATCHPOINT (ecs
->ws
);
2055 ecs
->stop_func_start
= 0;
2056 ecs
->stop_func_end
= 0;
2057 ecs
->stop_func_name
= 0;
2058 /* Don't care about return value; stop_func_start and stop_func_name
2059 will both be 0 if it doesn't work. */
2060 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2061 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2062 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
2063 ecs
->another_trap
= 0;
2064 bpstat_clear (&stop_bpstat
);
2066 stop_stack_dummy
= 0;
2067 stop_print_frame
= 1;
2068 ecs
->random_signal
= 0;
2069 stopped_by_random_signal
= 0;
2070 breakpoints_failed
= 0;
2072 /* Look at the cause of the stop, and decide what to do.
2073 The alternatives are:
2074 1) break; to really stop and return to the debugger,
2075 2) drop through to start up again
2076 (set ecs->another_trap to 1 to single step once)
2077 3) set ecs->random_signal to 1, and the decision between 1 and 2
2078 will be made according to the signal handling tables. */
2080 /* First, distinguish signals caused by the debugger from signals
2081 that have to do with the program's own actions.
2082 Note that breakpoint insns may cause SIGTRAP or SIGILL
2083 or SIGEMT, depending on the operating system version.
2084 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2085 and change it to SIGTRAP. */
2087 if (stop_signal
== TARGET_SIGNAL_TRAP
2088 || (breakpoints_inserted
&&
2089 (stop_signal
== TARGET_SIGNAL_ILL
2090 || stop_signal
== TARGET_SIGNAL_EMT
2092 || stop_soon_quietly
)
2094 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2096 stop_print_frame
= 0;
2097 stop_stepping (ecs
);
2100 if (stop_soon_quietly
)
2102 stop_stepping (ecs
);
2106 /* Don't even think about breakpoints
2107 if just proceeded over a breakpoint.
2109 However, if we are trying to proceed over a breakpoint
2110 and end up in sigtramp, then through_sigtramp_breakpoint
2111 will be set and we should check whether we've hit the
2113 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2114 && through_sigtramp_breakpoint
== NULL
)
2115 bpstat_clear (&stop_bpstat
);
2118 /* See if there is a breakpoint at the current PC. */
2119 stop_bpstat
= bpstat_stop_status
2121 /* Pass TRUE if our reason for stopping is something other
2122 than hitting a breakpoint. We do this by checking that
2123 1) stepping is going on and 2) we didn't hit a breakpoint
2124 in a signal handler without an intervening stop in
2125 sigtramp, which is detected by a new stack pointer value
2126 below any usual function calling stack adjustments. */
2127 (currently_stepping (ecs
)
2129 && INNER_THAN (read_sp (), (step_sp
- 16))))
2131 /* Following in case break condition called a
2133 stop_print_frame
= 1;
2136 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2138 = !(bpstat_explains_signal (stop_bpstat
)
2140 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2141 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2142 FRAME_FP (get_current_frame ())))
2143 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2148 = !(bpstat_explains_signal (stop_bpstat
)
2149 /* End of a stack dummy. Some systems (e.g. Sony
2150 news) give another signal besides SIGTRAP, so
2151 check here as well as above. */
2152 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2153 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2154 FRAME_FP (get_current_frame ())))
2156 if (!ecs
->random_signal
)
2157 stop_signal
= TARGET_SIGNAL_TRAP
;
2161 /* When we reach this point, we've pretty much decided
2162 that the reason for stopping must've been a random
2163 (unexpected) signal. */
2166 ecs
->random_signal
= 1;
2167 /* If a fork, vfork or exec event was seen, then there are two
2168 possible responses we can make:
2170 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2171 then we must stop now and issue a prompt. We will resume
2172 the inferior when the user tells us to.
2173 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2174 then we must resume the inferior now and keep checking.
2176 In either case, we must take appropriate steps to "follow" the
2177 the fork/vfork/exec when the inferior is resumed. For example,
2178 if follow-fork-mode is "child", then we must detach from the
2179 parent inferior and follow the new child inferior.
2181 In either case, setting pending_follow causes the next resume()
2182 to take the appropriate following action. */
2183 process_event_stop_test
:
2184 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2186 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2189 stop_signal
= TARGET_SIGNAL_0
;
2194 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2196 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2198 stop_signal
= TARGET_SIGNAL_0
;
2203 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2205 pending_follow
.kind
= ecs
->ws
.kind
;
2206 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2209 stop_signal
= TARGET_SIGNAL_0
;
2215 /* For the program's own signals, act according to
2216 the signal handling tables. */
2218 if (ecs
->random_signal
)
2220 /* Signal not for debugging purposes. */
2223 stopped_by_random_signal
= 1;
2225 if (signal_print
[stop_signal
])
2228 target_terminal_ours_for_output ();
2229 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2231 if (signal_stop
[stop_signal
])
2233 stop_stepping (ecs
);
2236 /* If not going to stop, give terminal back
2237 if we took it away. */
2239 target_terminal_inferior ();
2241 /* Clear the signal if it should not be passed. */
2242 if (signal_program
[stop_signal
] == 0)
2243 stop_signal
= TARGET_SIGNAL_0
;
2245 /* I'm not sure whether this needs to be check_sigtramp2 or
2246 whether it could/should be keep_going.
2248 This used to jump to step_over_function if we are stepping,
2251 Suppose the user does a `next' over a function call, and while
2252 that call is in progress, the inferior receives a signal for
2253 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2254 that case, when we reach this point, there is already a
2255 step-resume breakpoint established, right where it should be:
2256 immediately after the function call the user is "next"-ing
2257 over. If we call step_over_function now, two bad things
2260 - we'll create a new breakpoint, at wherever the current
2261 frame's return address happens to be. That could be
2262 anywhere, depending on what function call happens to be on
2263 the top of the stack at that point. Point is, it's probably
2264 not where we need it.
2266 - the existing step-resume breakpoint (which is at the correct
2267 address) will get orphaned: step_resume_breakpoint will point
2268 to the new breakpoint, and the old step-resume breakpoint
2269 will never be cleaned up.
2271 The old behavior was meant to help HP-UX single-step out of
2272 sigtramps. It would place the new breakpoint at prev_pc, which
2273 was certainly wrong. I don't know the details there, so fixing
2274 this probably breaks that. As with anything else, it's up to
2275 the HP-UX maintainer to furnish a fix that doesn't break other
2276 platforms. --JimB, 20 May 1999 */
2277 check_sigtramp2 (ecs
);
2282 /* Handle cases caused by hitting a breakpoint. */
2284 CORE_ADDR jmp_buf_pc
;
2285 struct bpstat_what what
;
2287 what
= bpstat_what (stop_bpstat
);
2289 if (what
.call_dummy
)
2291 stop_stack_dummy
= 1;
2293 trap_expected_after_continue
= 1;
2297 switch (what
.main_action
)
2299 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2300 /* If we hit the breakpoint at longjmp, disable it for the
2301 duration of this command. Then, install a temporary
2302 breakpoint at the target of the jmp_buf. */
2303 disable_longjmp_breakpoint ();
2304 remove_breakpoints ();
2305 breakpoints_inserted
= 0;
2306 if (!GET_LONGJMP_TARGET (&jmp_buf_pc
))
2312 /* Need to blow away step-resume breakpoint, as it
2313 interferes with us */
2314 if (step_resume_breakpoint
!= NULL
)
2316 delete_breakpoint (step_resume_breakpoint
);
2317 step_resume_breakpoint
= NULL
;
2319 /* Not sure whether we need to blow this away too, but probably
2320 it is like the step-resume breakpoint. */
2321 if (through_sigtramp_breakpoint
!= NULL
)
2323 delete_breakpoint (through_sigtramp_breakpoint
);
2324 through_sigtramp_breakpoint
= NULL
;
2328 /* FIXME - Need to implement nested temporary breakpoints */
2329 if (step_over_calls
> 0)
2330 set_longjmp_resume_breakpoint (jmp_buf_pc
,
2331 get_current_frame ());
2334 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2335 ecs
->handling_longjmp
= 1; /* FIXME */
2339 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2340 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2341 remove_breakpoints ();
2342 breakpoints_inserted
= 0;
2344 /* FIXME - Need to implement nested temporary breakpoints */
2346 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2347 step_frame_address
)))
2349 ecs
->another_trap
= 1;
2354 disable_longjmp_breakpoint ();
2355 ecs
->handling_longjmp
= 0; /* FIXME */
2356 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2358 /* else fallthrough */
2360 case BPSTAT_WHAT_SINGLE
:
2361 if (breakpoints_inserted
)
2363 thread_step_needed
= 1;
2364 remove_breakpoints ();
2366 breakpoints_inserted
= 0;
2367 ecs
->another_trap
= 1;
2368 /* Still need to check other stuff, at least the case
2369 where we are stepping and step out of the right range. */
2372 case BPSTAT_WHAT_STOP_NOISY
:
2373 stop_print_frame
= 1;
2375 /* We are about to nuke the step_resume_breakpoint and
2376 through_sigtramp_breakpoint via the cleanup chain, so
2377 no need to worry about it here. */
2379 stop_stepping (ecs
);
2382 case BPSTAT_WHAT_STOP_SILENT
:
2383 stop_print_frame
= 0;
2385 /* We are about to nuke the step_resume_breakpoint and
2386 through_sigtramp_breakpoint via the cleanup chain, so
2387 no need to worry about it here. */
2389 stop_stepping (ecs
);
2392 case BPSTAT_WHAT_STEP_RESUME
:
2393 /* This proably demands a more elegant solution, but, yeah
2396 This function's use of the simple variable
2397 step_resume_breakpoint doesn't seem to accomodate
2398 simultaneously active step-resume bp's, although the
2399 breakpoint list certainly can.
2401 If we reach here and step_resume_breakpoint is already
2402 NULL, then apparently we have multiple active
2403 step-resume bp's. We'll just delete the breakpoint we
2404 stopped at, and carry on.
2406 Correction: what the code currently does is delete a
2407 step-resume bp, but it makes no effort to ensure that
2408 the one deleted is the one currently stopped at. MVS */
2410 if (step_resume_breakpoint
== NULL
)
2412 step_resume_breakpoint
=
2413 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2415 delete_breakpoint (step_resume_breakpoint
);
2416 step_resume_breakpoint
= NULL
;
2419 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2420 if (through_sigtramp_breakpoint
)
2421 delete_breakpoint (through_sigtramp_breakpoint
);
2422 through_sigtramp_breakpoint
= NULL
;
2424 /* If were waiting for a trap, hitting the step_resume_break
2425 doesn't count as getting it. */
2427 ecs
->another_trap
= 1;
2430 case BPSTAT_WHAT_CHECK_SHLIBS
:
2431 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2434 /* Remove breakpoints, we eventually want to step over the
2435 shlib event breakpoint, and SOLIB_ADD might adjust
2436 breakpoint addresses via breakpoint_re_set. */
2437 if (breakpoints_inserted
)
2438 remove_breakpoints ();
2439 breakpoints_inserted
= 0;
2441 /* Check for any newly added shared libraries if we're
2442 supposed to be adding them automatically. */
2445 /* Switch terminal for any messages produced by
2446 breakpoint_re_set. */
2447 target_terminal_ours_for_output ();
2448 SOLIB_ADD (NULL
, 0, NULL
);
2449 target_terminal_inferior ();
2452 /* Try to reenable shared library breakpoints, additional
2453 code segments in shared libraries might be mapped in now. */
2454 re_enable_breakpoints_in_shlibs ();
2456 /* If requested, stop when the dynamic linker notifies
2457 gdb of events. This allows the user to get control
2458 and place breakpoints in initializer routines for
2459 dynamically loaded objects (among other things). */
2460 if (stop_on_solib_events
)
2462 stop_stepping (ecs
);
2466 /* If we stopped due to an explicit catchpoint, then the
2467 (see above) call to SOLIB_ADD pulled in any symbols
2468 from a newly-loaded library, if appropriate.
2470 We do want the inferior to stop, but not where it is
2471 now, which is in the dynamic linker callback. Rather,
2472 we would like it stop in the user's program, just after
2473 the call that caused this catchpoint to trigger. That
2474 gives the user a more useful vantage from which to
2475 examine their program's state. */
2476 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2478 /* ??rehrauer: If I could figure out how to get the
2479 right return PC from here, we could just set a temp
2480 breakpoint and resume. I'm not sure we can without
2481 cracking open the dld's shared libraries and sniffing
2482 their unwind tables and text/data ranges, and that's
2483 not a terribly portable notion.
2485 Until that time, we must step the inferior out of the
2486 dld callback, and also out of the dld itself (and any
2487 code or stubs in libdld.sl, such as "shl_load" and
2488 friends) until we reach non-dld code. At that point,
2489 we can stop stepping. */
2490 bpstat_get_triggered_catchpoints (stop_bpstat
,
2491 &ecs
->stepping_through_solib_catchpoints
);
2492 ecs
->stepping_through_solib_after_catch
= 1;
2494 /* Be sure to lift all breakpoints, so the inferior does
2495 actually step past this point... */
2496 ecs
->another_trap
= 1;
2501 /* We want to step over this breakpoint, then keep going. */
2502 ecs
->another_trap
= 1;
2509 case BPSTAT_WHAT_LAST
:
2510 /* Not a real code, but listed here to shut up gcc -Wall. */
2512 case BPSTAT_WHAT_KEEP_CHECKING
:
2517 /* We come here if we hit a breakpoint but should not
2518 stop for it. Possibly we also were stepping
2519 and should stop for that. So fall through and
2520 test for stepping. But, if not stepping,
2523 /* Are we stepping to get the inferior out of the dynamic
2524 linker's hook (and possibly the dld itself) after catching
2526 if (ecs
->stepping_through_solib_after_catch
)
2528 #if defined(SOLIB_ADD)
2529 /* Have we reached our destination? If not, keep going. */
2530 if (SOLIB_IN_DYNAMIC_LINKER (ecs
->pid
, stop_pc
))
2532 ecs
->another_trap
= 1;
2537 /* Else, stop and report the catchpoint(s) whose triggering
2538 caused us to begin stepping. */
2539 ecs
->stepping_through_solib_after_catch
= 0;
2540 bpstat_clear (&stop_bpstat
);
2541 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2542 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2543 stop_print_frame
= 1;
2544 stop_stepping (ecs
);
2548 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2550 /* This is the old way of detecting the end of the stack dummy.
2551 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2552 handled above. As soon as we can test it on all of them, all
2553 architectures should define it. */
2555 /* If this is the breakpoint at the end of a stack dummy,
2556 just stop silently, unless the user was doing an si/ni, in which
2557 case she'd better know what she's doing. */
2559 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2560 FRAME_FP (get_current_frame ()))
2563 stop_print_frame
= 0;
2564 stop_stack_dummy
= 1;
2566 trap_expected_after_continue
= 1;
2568 stop_stepping (ecs
);
2573 if (step_resume_breakpoint
)
2575 /* Having a step-resume breakpoint overrides anything
2576 else having to do with stepping commands until
2577 that breakpoint is reached. */
2578 /* I'm not sure whether this needs to be check_sigtramp2 or
2579 whether it could/should be keep_going. */
2580 check_sigtramp2 (ecs
);
2585 if (step_range_end
== 0)
2587 /* Likewise if we aren't even stepping. */
2588 /* I'm not sure whether this needs to be check_sigtramp2 or
2589 whether it could/should be keep_going. */
2590 check_sigtramp2 (ecs
);
2595 /* If stepping through a line, keep going if still within it.
2597 Note that step_range_end is the address of the first instruction
2598 beyond the step range, and NOT the address of the last instruction
2600 if (stop_pc
>= step_range_start
2601 && stop_pc
< step_range_end
)
2603 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2604 So definately need to check for sigtramp here. */
2605 check_sigtramp2 (ecs
);
2610 /* We stepped out of the stepping range. */
2612 /* If we are stepping at the source level and entered the runtime
2613 loader dynamic symbol resolution code, we keep on single stepping
2614 until we exit the run time loader code and reach the callee's
2616 if (step_over_calls
< 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2618 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2620 if (pc_after_resolver
)
2622 /* Set up a step-resume breakpoint at the address
2623 indicated by SKIP_SOLIB_RESOLVER. */
2624 struct symtab_and_line sr_sal
;
2626 sr_sal
.pc
= pc_after_resolver
;
2628 check_for_old_step_resume_breakpoint ();
2629 step_resume_breakpoint
=
2630 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2631 if (breakpoints_inserted
)
2632 insert_breakpoints ();
2639 /* We can't update step_sp every time through the loop, because
2640 reading the stack pointer would slow down stepping too much.
2641 But we can update it every time we leave the step range. */
2642 ecs
->update_step_sp
= 1;
2644 /* Did we just take a signal? */
2645 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2646 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2647 && INNER_THAN (read_sp (), step_sp
))
2649 /* We've just taken a signal; go until we are back to
2650 the point where we took it and one more. */
2652 /* Note: The test above succeeds not only when we stepped
2653 into a signal handler, but also when we step past the last
2654 statement of a signal handler and end up in the return stub
2655 of the signal handler trampoline. To distinguish between
2656 these two cases, check that the frame is INNER_THAN the
2657 previous one below. pai/1997-09-11 */
2661 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2663 if (INNER_THAN (current_frame
, step_frame_address
))
2665 /* We have just taken a signal; go until we are back to
2666 the point where we took it and one more. */
2668 /* This code is needed at least in the following case:
2669 The user types "next" and then a signal arrives (before
2670 the "next" is done). */
2672 /* Note that if we are stopped at a breakpoint, then we need
2673 the step_resume breakpoint to override any breakpoints at
2674 the same location, so that we will still step over the
2675 breakpoint even though the signal happened. */
2676 struct symtab_and_line sr_sal
;
2679 sr_sal
.symtab
= NULL
;
2681 sr_sal
.pc
= prev_pc
;
2682 /* We could probably be setting the frame to
2683 step_frame_address; I don't think anyone thought to
2685 check_for_old_step_resume_breakpoint ();
2686 step_resume_breakpoint
=
2687 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2688 if (breakpoints_inserted
)
2689 insert_breakpoints ();
2693 /* We just stepped out of a signal handler and into
2694 its calling trampoline.
2696 Normally, we'd call step_over_function from
2697 here, but for some reason GDB can't unwind the
2698 stack correctly to find the real PC for the point
2699 user code where the signal trampoline will return
2700 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2701 But signal trampolines are pretty small stubs of
2702 code, anyway, so it's OK instead to just
2703 single-step out. Note: assuming such trampolines
2704 don't exhibit recursion on any platform... */
2705 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2706 &ecs
->stop_func_start
,
2707 &ecs
->stop_func_end
);
2708 /* Readjust stepping range */
2709 step_range_start
= ecs
->stop_func_start
;
2710 step_range_end
= ecs
->stop_func_end
;
2711 ecs
->stepping_through_sigtramp
= 1;
2716 /* If this is stepi or nexti, make sure that the stepping range
2717 gets us past that instruction. */
2718 if (step_range_end
== 1)
2719 /* FIXME: Does this run afoul of the code below which, if
2720 we step into the middle of a line, resets the stepping
2722 step_range_end
= (step_range_start
= prev_pc
) + 1;
2724 ecs
->remove_breakpoints_on_following_step
= 1;
2729 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2730 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2731 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2732 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2733 || ecs
->stop_func_name
== 0)
2735 /* It's a subroutine call. */
2737 if (step_over_calls
== 0)
2739 /* I presume that step_over_calls is only 0 when we're
2740 supposed to be stepping at the assembly language level
2741 ("stepi"). Just stop. */
2743 print_stop_reason (END_STEPPING_RANGE
, 0);
2744 stop_stepping (ecs
);
2748 if (step_over_calls
> 0 || IGNORE_HELPER_CALL (stop_pc
))
2750 /* We're doing a "next". */
2752 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2753 && INNER_THAN (step_frame_address
, read_sp()))
2754 /* We stepped out of a signal handler, and into its
2755 calling trampoline. This is misdetected as a
2756 subroutine call, but stepping over the signal
2757 trampoline isn't such a bad idea. In order to do
2758 that, we have to ignore the value in
2759 step_frame_address, since that doesn't represent the
2760 frame that'll reach when we return from the signal
2761 trampoline. Otherwise we'll probably continue to the
2762 end of the program. */
2763 step_frame_address
= 0;
2765 step_over_function (ecs
);
2770 /* If we are in a function call trampoline (a stub between
2771 the calling routine and the real function), locate the real
2772 function. That's what tells us (a) whether we want to step
2773 into it at all, and (b) what prologue we want to run to
2774 the end of, if we do step into it. */
2775 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2777 ecs
->stop_func_start
= tmp
;
2780 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2783 struct symtab_and_line xxx
;
2784 /* Why isn't this s_a_l called "sr_sal", like all of the
2785 other s_a_l's where this code is duplicated? */
2786 INIT_SAL (&xxx
); /* initialize to zeroes */
2788 xxx
.section
= find_pc_overlay (xxx
.pc
);
2789 check_for_old_step_resume_breakpoint ();
2790 step_resume_breakpoint
=
2791 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2792 insert_breakpoints ();
2798 /* If we have line number information for the function we
2799 are thinking of stepping into, step into it.
2801 If there are several symtabs at that PC (e.g. with include
2802 files), just want to know whether *any* of them have line
2803 numbers. find_pc_line handles this. */
2805 struct symtab_and_line tmp_sal
;
2807 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2808 if (tmp_sal
.line
!= 0)
2810 step_into_function (ecs
);
2814 step_over_function (ecs
);
2820 /* We've wandered out of the step range. */
2822 ecs
->sal
= find_pc_line (stop_pc
, 0);
2824 if (step_range_end
== 1)
2826 /* It is stepi or nexti. We always want to stop stepping after
2829 print_stop_reason (END_STEPPING_RANGE
, 0);
2830 stop_stepping (ecs
);
2834 /* If we're in the return path from a shared library trampoline,
2835 we want to proceed through the trampoline when stepping. */
2836 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2840 /* Determine where this trampoline returns. */
2841 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2843 /* Only proceed through if we know where it's going. */
2846 /* And put the step-breakpoint there and go until there. */
2847 struct symtab_and_line sr_sal
;
2849 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2851 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2852 /* Do not specify what the fp should be when we stop
2853 since on some machines the prologue
2854 is where the new fp value is established. */
2855 check_for_old_step_resume_breakpoint ();
2856 step_resume_breakpoint
=
2857 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2858 if (breakpoints_inserted
)
2859 insert_breakpoints ();
2861 /* Restart without fiddling with the step ranges or
2868 if (ecs
->sal
.line
== 0)
2870 /* We have no line number information. That means to stop
2871 stepping (does this always happen right after one instruction,
2872 when we do "s" in a function with no line numbers,
2873 or can this happen as a result of a return or longjmp?). */
2875 print_stop_reason (END_STEPPING_RANGE
, 0);
2876 stop_stepping (ecs
);
2880 if ((stop_pc
== ecs
->sal
.pc
)
2881 && (ecs
->current_line
!= ecs
->sal
.line
|| ecs
->current_symtab
!= ecs
->sal
.symtab
))
2883 /* We are at the start of a different line. So stop. Note that
2884 we don't stop if we step into the middle of a different line.
2885 That is said to make things like for (;;) statements work
2888 print_stop_reason (END_STEPPING_RANGE
, 0);
2889 stop_stepping (ecs
);
2893 /* We aren't done stepping.
2895 Optimize by setting the stepping range to the line.
2896 (We might not be in the original line, but if we entered a
2897 new line in mid-statement, we continue stepping. This makes
2898 things like for(;;) statements work better.) */
2900 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2902 /* If this is the last line of the function, don't keep stepping
2903 (it would probably step us out of the function).
2904 This is particularly necessary for a one-line function,
2905 in which after skipping the prologue we better stop even though
2906 we will be in mid-line. */
2908 print_stop_reason (END_STEPPING_RANGE
, 0);
2909 stop_stepping (ecs
);
2912 step_range_start
= ecs
->sal
.pc
;
2913 step_range_end
= ecs
->sal
.end
;
2914 step_frame_address
= FRAME_FP (get_current_frame ());
2915 ecs
->current_line
= ecs
->sal
.line
;
2916 ecs
->current_symtab
= ecs
->sal
.symtab
;
2918 /* In the case where we just stepped out of a function into the middle
2919 of a line of the caller, continue stepping, but step_frame_address
2920 must be modified to current frame */
2922 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2923 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2924 step_frame_address
= current_frame
;
2929 } /* extra brace, to preserve old indentation */
2932 /* Are we in the middle of stepping? */
2935 currently_stepping (struct execution_control_state
*ecs
)
2937 return ((through_sigtramp_breakpoint
== NULL
2938 && !ecs
->handling_longjmp
2939 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2941 || ecs
->stepping_through_solib_after_catch
2942 || bpstat_should_step ());
2946 check_sigtramp2 (struct execution_control_state
*ecs
)
2949 && IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2950 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2951 && INNER_THAN (read_sp (), step_sp
))
2953 /* What has happened here is that we have just stepped the
2954 inferior with a signal (because it is a signal which
2955 shouldn't make us stop), thus stepping into sigtramp.
2957 So we need to set a step_resume_break_address breakpoint and
2958 continue until we hit it, and then step. FIXME: This should
2959 be more enduring than a step_resume breakpoint; we should
2960 know that we will later need to keep going rather than
2961 re-hitting the breakpoint here (see the testsuite,
2962 gdb.base/signals.exp where it says "exceedingly difficult"). */
2964 struct symtab_and_line sr_sal
;
2966 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2967 sr_sal
.pc
= prev_pc
;
2968 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2969 /* We perhaps could set the frame if we kept track of what the
2970 frame corresponding to prev_pc was. But we don't, so don't. */
2971 through_sigtramp_breakpoint
=
2972 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2973 if (breakpoints_inserted
)
2974 insert_breakpoints ();
2976 ecs
->remove_breakpoints_on_following_step
= 1;
2977 ecs
->another_trap
= 1;
2981 /* Subroutine call with source code we should not step over. Do step
2982 to the first line of code in it. */
2985 step_into_function (struct execution_control_state
*ecs
)
2988 struct symtab_and_line sr_sal
;
2990 s
= find_pc_symtab (stop_pc
);
2991 if (s
&& s
->language
!= language_asm
)
2992 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2994 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2995 /* Use the step_resume_break to step until the end of the prologue,
2996 even if that involves jumps (as it seems to on the vax under
2998 /* If the prologue ends in the middle of a source line, continue to
2999 the end of that source line (if it is still within the function).
3000 Otherwise, just go to end of prologue. */
3001 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
3002 /* no, don't either. It skips any code that's legitimately on the
3006 && ecs
->sal
.pc
!= ecs
->stop_func_start
3007 && ecs
->sal
.end
< ecs
->stop_func_end
)
3008 ecs
->stop_func_start
= ecs
->sal
.end
;
3011 if (ecs
->stop_func_start
== stop_pc
)
3013 /* We are already there: stop now. */
3015 print_stop_reason (END_STEPPING_RANGE
, 0);
3016 stop_stepping (ecs
);
3021 /* Put the step-breakpoint there and go until there. */
3022 INIT_SAL (&sr_sal
); /* initialize to zeroes */
3023 sr_sal
.pc
= ecs
->stop_func_start
;
3024 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3025 /* Do not specify what the fp should be when we stop since on
3026 some machines the prologue is where the new fp value is
3028 check_for_old_step_resume_breakpoint ();
3029 step_resume_breakpoint
=
3030 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
3031 if (breakpoints_inserted
)
3032 insert_breakpoints ();
3034 /* And make sure stepping stops right away then. */
3035 step_range_end
= step_range_start
;
3040 /* We've just entered a callee, and we wish to resume until it returns
3041 to the caller. Setting a step_resume breakpoint on the return
3042 address will catch a return from the callee.
3044 However, if the callee is recursing, we want to be careful not to
3045 catch returns of those recursive calls, but only of THIS instance
3048 To do this, we set the step_resume bp's frame to our current
3049 caller's frame (step_frame_address, which is set by the "next" or
3050 "until" command, before execution begins). */
3053 step_over_function (struct execution_control_state
*ecs
)
3055 struct symtab_and_line sr_sal
;
3057 INIT_SAL (&sr_sal
); /* initialize to zeros */
3058 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3059 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3061 check_for_old_step_resume_breakpoint ();
3062 step_resume_breakpoint
=
3063 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
3065 if (step_frame_address
&& !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
3066 step_resume_breakpoint
->frame
= step_frame_address
;
3068 if (breakpoints_inserted
)
3069 insert_breakpoints ();
3073 stop_stepping (struct execution_control_state
*ecs
)
3075 if (target_has_execution
)
3077 /* Are we stopping for a vfork event? We only stop when we see
3078 the child's event. However, we may not yet have seen the
3079 parent's event. And, inferior_pid is still set to the
3080 parent's pid, until we resume again and follow either the
3083 To ensure that we can really touch inferior_pid (aka, the
3084 parent process) -- which calls to functions like read_pc
3085 implicitly do -- wait on the parent if necessary. */
3086 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3087 && !pending_follow
.fork_event
.saw_parent_fork
)
3093 if (target_wait_hook
)
3094 parent_pid
= target_wait_hook (-1, &(ecs
->ws
));
3096 parent_pid
= target_wait (-1, &(ecs
->ws
));
3098 while (parent_pid
!= inferior_pid
);
3101 /* Assuming the inferior still exists, set these up for next
3102 time, just like we did above if we didn't break out of the
3104 prev_pc
= read_pc ();
3105 prev_func_start
= ecs
->stop_func_start
;
3106 prev_func_name
= ecs
->stop_func_name
;
3109 /* Let callers know we don't want to wait for the inferior anymore. */
3110 ecs
->wait_some_more
= 0;
3113 /* This function handles various cases where we need to continue
3114 waiting for the inferior. */
3115 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3118 keep_going (struct execution_control_state
*ecs
)
3120 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3121 vforked child between its creation and subsequent exit or call to
3122 exec(). However, I had big problems in this rather creaky exec
3123 engine, getting that to work. The fundamental problem is that
3124 I'm trying to debug two processes via an engine that only
3125 understands a single process with possibly multiple threads.
3127 Hence, this spot is known to have problems when
3128 target_can_follow_vfork_prior_to_exec returns 1. */
3130 /* Save the pc before execution, to compare with pc after stop. */
3131 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3132 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3133 BREAK is defined, the
3134 original pc would not have
3135 been at the start of a
3137 prev_func_name
= ecs
->stop_func_name
;
3139 if (ecs
->update_step_sp
)
3140 step_sp
= read_sp ();
3141 ecs
->update_step_sp
= 0;
3143 /* If we did not do break;, it means we should keep running the
3144 inferior and not return to debugger. */
3146 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3148 /* We took a signal (which we are supposed to pass through to
3149 the inferior, else we'd have done a break above) and we
3150 haven't yet gotten our trap. Simply continue. */
3151 resume (currently_stepping (ecs
), stop_signal
);
3155 /* Either the trap was not expected, but we are continuing
3156 anyway (the user asked that this signal be passed to the
3159 The signal was SIGTRAP, e.g. it was our signal, but we
3160 decided we should resume from it.
3162 We're going to run this baby now!
3164 Insert breakpoints now, unless we are trying to one-proceed
3165 past a breakpoint. */
3166 /* If we've just finished a special step resume and we don't
3167 want to hit a breakpoint, pull em out. */
3168 if (step_resume_breakpoint
== NULL
3169 && through_sigtramp_breakpoint
== NULL
3170 && ecs
->remove_breakpoints_on_following_step
)
3172 ecs
->remove_breakpoints_on_following_step
= 0;
3173 remove_breakpoints ();
3174 breakpoints_inserted
= 0;
3176 else if (!breakpoints_inserted
&&
3177 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3179 breakpoints_failed
= insert_breakpoints ();
3180 if (breakpoints_failed
)
3182 stop_stepping (ecs
);
3185 breakpoints_inserted
= 1;
3188 trap_expected
= ecs
->another_trap
;
3190 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3191 specifies that such a signal should be delivered to the
3194 Typically, this would occure when a user is debugging a
3195 target monitor on a simulator: the target monitor sets a
3196 breakpoint; the simulator encounters this break-point and
3197 halts the simulation handing control to GDB; GDB, noteing
3198 that the break-point isn't valid, returns control back to the
3199 simulator; the simulator then delivers the hardware
3200 equivalent of a SIGNAL_TRAP to the program being debugged. */
3202 if (stop_signal
== TARGET_SIGNAL_TRAP
3203 && !signal_program
[stop_signal
])
3204 stop_signal
= TARGET_SIGNAL_0
;
3206 #ifdef SHIFT_INST_REGS
3207 /* I'm not sure when this following segment applies. I do know,
3208 now, that we shouldn't rewrite the regs when we were stopped
3209 by a random signal from the inferior process. */
3210 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3211 (this is only used on the 88k). */
3213 if (!bpstat_explains_signal (stop_bpstat
)
3214 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
3215 && !stopped_by_random_signal
)
3217 #endif /* SHIFT_INST_REGS */
3219 resume (currently_stepping (ecs
), stop_signal
);
3222 prepare_to_wait (ecs
);
3225 /* This function normally comes after a resume, before
3226 handle_inferior_event exits. It takes care of any last bits of
3227 housekeeping, and sets the all-important wait_some_more flag. */
3230 prepare_to_wait (struct execution_control_state
*ecs
)
3232 if (ecs
->infwait_state
== infwait_normal_state
)
3234 overlay_cache_invalid
= 1;
3236 /* We have to invalidate the registers BEFORE calling
3237 target_wait because they can be loaded from the target while
3238 in target_wait. This makes remote debugging a bit more
3239 efficient for those targets that provide critical registers
3240 as part of their normal status mechanism. */
3242 registers_changed ();
3243 ecs
->waiton_pid
= -1;
3244 ecs
->wp
= &(ecs
->ws
);
3246 /* This is the old end of the while loop. Let everybody know we
3247 want to wait for the inferior some more and get called again
3249 ecs
->wait_some_more
= 1;
3252 /* Print why the inferior has stopped. We always print something when
3253 the inferior exits, or receives a signal. The rest of the cases are
3254 dealt with later on in normal_stop() and print_it_typical(). Ideally
3255 there should be a call to this function from handle_inferior_event()
3256 each time stop_stepping() is called.*/
3258 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3260 switch (stop_reason
)
3263 /* We don't deal with these cases from handle_inferior_event()
3266 case END_STEPPING_RANGE
:
3267 /* We are done with a step/next/si/ni command. */
3268 /* For now print nothing. */
3270 /* Print a message only if not in the middle of doing a "step n"
3271 operation for n > 1 */
3272 if (!step_multi
|| !stop_step
)
3273 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3274 ui_out_field_string (uiout
, "reason", "end-stepping-range");
3277 case BREAKPOINT_HIT
:
3278 /* We found a breakpoint. */
3279 /* For now print nothing. */
3282 /* The inferior was terminated by a signal. */
3284 annotate_signalled ();
3285 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3286 ui_out_field_string (uiout
, "reason", "exited-signalled");
3287 ui_out_text (uiout
, "\nProgram terminated with signal ");
3288 annotate_signal_name ();
3289 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3290 annotate_signal_name_end ();
3291 ui_out_text (uiout
, ", ");
3292 annotate_signal_string ();
3293 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3294 annotate_signal_string_end ();
3295 ui_out_text (uiout
, ".\n");
3296 ui_out_text (uiout
, "The program no longer exists.\n");
3298 annotate_signalled ();
3299 printf_filtered ("\nProgram terminated with signal ");
3300 annotate_signal_name ();
3301 printf_filtered ("%s", target_signal_to_name (stop_info
));
3302 annotate_signal_name_end ();
3303 printf_filtered (", ");
3304 annotate_signal_string ();
3305 printf_filtered ("%s", target_signal_to_string (stop_info
));
3306 annotate_signal_string_end ();
3307 printf_filtered (".\n");
3309 printf_filtered ("The program no longer exists.\n");
3310 gdb_flush (gdb_stdout
);
3314 /* The inferior program is finished. */
3316 annotate_exited (stop_info
);
3319 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3320 ui_out_field_string (uiout
, "reason", "exited");
3321 ui_out_text (uiout
, "\nProgram exited with code ");
3322 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) stop_info
);
3323 ui_out_text (uiout
, ".\n");
3327 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3328 ui_out_field_string (uiout
, "reason", "exited-normally");
3329 ui_out_text (uiout
, "\nProgram exited normally.\n");
3332 annotate_exited (stop_info
);
3334 printf_filtered ("\nProgram exited with code 0%o.\n",
3335 (unsigned int) stop_info
);
3337 printf_filtered ("\nProgram exited normally.\n");
3340 case SIGNAL_RECEIVED
:
3341 /* Signal received. The signal table tells us to print about
3345 ui_out_text (uiout
, "\nProgram received signal ");
3346 annotate_signal_name ();
3347 ui_out_field_string (uiout
, "signal-name", target_signal_to_name (stop_info
));
3348 annotate_signal_name_end ();
3349 ui_out_text (uiout
, ", ");
3350 annotate_signal_string ();
3351 ui_out_field_string (uiout
, "signal-meaning", target_signal_to_string (stop_info
));
3352 annotate_signal_string_end ();
3353 ui_out_text (uiout
, ".\n");
3356 printf_filtered ("\nProgram received signal ");
3357 annotate_signal_name ();
3358 printf_filtered ("%s", target_signal_to_name (stop_info
));
3359 annotate_signal_name_end ();
3360 printf_filtered (", ");
3361 annotate_signal_string ();
3362 printf_filtered ("%s", target_signal_to_string (stop_info
));
3363 annotate_signal_string_end ();
3364 printf_filtered (".\n");
3365 gdb_flush (gdb_stdout
);
3369 internal_error ("print_stop_reason: unrecognized enum value");
3375 /* Here to return control to GDB when the inferior stops for real.
3376 Print appropriate messages, remove breakpoints, give terminal our modes.
3378 STOP_PRINT_FRAME nonzero means print the executing frame
3379 (pc, function, args, file, line number and line text).
3380 BREAKPOINTS_FAILED nonzero means stop was due to error
3381 attempting to insert breakpoints. */
3386 /* As with the notification of thread events, we want to delay
3387 notifying the user that we've switched thread context until
3388 the inferior actually stops.
3390 (Note that there's no point in saying anything if the inferior
3392 if ((previous_inferior_pid
!= inferior_pid
)
3393 && target_has_execution
)
3395 target_terminal_ours_for_output ();
3396 printf_filtered ("[Switching to %s]\n",
3397 target_pid_or_tid_to_str (inferior_pid
));
3398 previous_inferior_pid
= inferior_pid
;
3401 /* Make sure that the current_frame's pc is correct. This
3402 is a correction for setting up the frame info before doing
3403 DECR_PC_AFTER_BREAK */
3404 if (target_has_execution
&& get_current_frame ())
3405 (get_current_frame ())->pc
= read_pc ();
3407 if (breakpoints_failed
)
3409 target_terminal_ours_for_output ();
3410 print_sys_errmsg ("While inserting breakpoints", breakpoints_failed
);
3411 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3412 The same program may be running in another process,\n\
3413 or you may have requested too many hardware breakpoints\n\
3414 and/or watchpoints.\n");
3417 if (target_has_execution
&& breakpoints_inserted
)
3419 if (remove_breakpoints ())
3421 target_terminal_ours_for_output ();
3422 printf_filtered ("Cannot remove breakpoints because ");
3423 printf_filtered ("program is no longer writable.\n");
3424 printf_filtered ("It might be running in another process.\n");
3425 printf_filtered ("Further execution is probably impossible.\n");
3428 breakpoints_inserted
= 0;
3430 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3431 Delete any breakpoint that is to be deleted at the next stop. */
3433 breakpoint_auto_delete (stop_bpstat
);
3435 /* If an auto-display called a function and that got a signal,
3436 delete that auto-display to avoid an infinite recursion. */
3438 if (stopped_by_random_signal
)
3439 disable_current_display ();
3441 /* Don't print a message if in the middle of doing a "step n"
3442 operation for n > 1 */
3443 if (step_multi
&& stop_step
)
3446 target_terminal_ours ();
3448 /* Look up the hook_stop and run it if it exists. */
3450 if (stop_command
&& stop_command
->hook
)
3452 catch_errors (hook_stop_stub
, stop_command
->hook
,
3453 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3456 if (!target_has_stack
)
3462 /* Select innermost stack frame - i.e., current frame is frame 0,
3463 and current location is based on that.
3464 Don't do this on return from a stack dummy routine,
3465 or if the program has exited. */
3467 if (!stop_stack_dummy
)
3469 select_frame (get_current_frame (), 0);
3471 /* Print current location without a level number, if
3472 we have changed functions or hit a breakpoint.
3473 Print source line if we have one.
3474 bpstat_print() contains the logic deciding in detail
3475 what to print, based on the event(s) that just occurred. */
3477 if (stop_print_frame
3482 int do_frame_printing
= 1;
3484 bpstat_ret
= bpstat_print (stop_bpstat
);
3489 && step_frame_address
== FRAME_FP (get_current_frame ())
3490 && step_start_function
== find_pc_function (stop_pc
))
3491 source_flag
= SRC_LINE
; /* finished step, just print source line */
3493 source_flag
= SRC_AND_LOC
; /* print location and source line */
3495 case PRINT_SRC_AND_LOC
:
3496 source_flag
= SRC_AND_LOC
; /* print location and source line */
3498 case PRINT_SRC_ONLY
:
3499 source_flag
= SRC_LINE
;
3502 do_frame_printing
= 0;
3505 internal_error ("Unknown value.");
3508 /* For mi, have the same behavior every time we stop:
3509 print everything but the source line. */
3510 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3511 source_flag
= LOC_AND_ADDRESS
;
3515 if (interpreter_p
&& strcmp (interpreter_p
, "mi") == 0)
3516 ui_out_field_int (uiout
, "thread-id", pid_to_thread_id (inferior_pid
));
3518 /* The behavior of this routine with respect to the source
3520 SRC_LINE: Print only source line
3521 LOCATION: Print only location
3522 SRC_AND_LOC: Print location and source line */
3523 if (do_frame_printing
)
3524 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
3526 /* Display the auto-display expressions. */
3531 /* Save the function value return registers, if we care.
3532 We might be about to restore their previous contents. */
3533 if (proceed_to_finish
)
3534 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
3536 if (stop_stack_dummy
)
3538 /* Pop the empty frame that contains the stack dummy.
3539 POP_FRAME ends with a setting of the current frame, so we
3540 can use that next. */
3542 /* Set stop_pc to what it was before we called the function.
3543 Can't rely on restore_inferior_status because that only gets
3544 called if we don't stop in the called function. */
3545 stop_pc
= read_pc ();
3546 select_frame (get_current_frame (), 0);
3550 TUIDO (((TuiOpaqueFuncPtr
) tui_vCheckDataValues
, selected_frame
));
3553 annotate_stopped ();
3557 hook_stop_stub (void *cmd
)
3559 execute_user_command ((struct cmd_list_element
*) cmd
, 0);
3564 signal_stop_state (int signo
)
3566 return signal_stop
[signo
];
3570 signal_print_state (int signo
)
3572 return signal_print
[signo
];
3576 signal_pass_state (int signo
)
3578 return signal_program
[signo
];
3581 int signal_stop_update (signo
, state
)
3585 int ret
= signal_stop
[signo
];
3586 signal_stop
[signo
] = state
;
3590 int signal_print_update (signo
, state
)
3594 int ret
= signal_print
[signo
];
3595 signal_print
[signo
] = state
;
3599 int signal_pass_update (signo
, state
)
3603 int ret
= signal_program
[signo
];
3604 signal_program
[signo
] = state
;
3609 sig_print_header (void)
3612 Signal Stop\tPrint\tPass to program\tDescription\n");
3616 sig_print_info (enum target_signal oursig
)
3618 char *name
= target_signal_to_name (oursig
);
3619 int name_padding
= 13 - strlen (name
);
3621 if (name_padding
<= 0)
3624 printf_filtered ("%s", name
);
3625 printf_filtered ("%*.*s ", name_padding
, name_padding
,
3627 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3628 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3629 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3630 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3633 /* Specify how various signals in the inferior should be handled. */
3636 handle_command (char *args
, int from_tty
)
3639 int digits
, wordlen
;
3640 int sigfirst
, signum
, siglast
;
3641 enum target_signal oursig
;
3644 unsigned char *sigs
;
3645 struct cleanup
*old_chain
;
3649 error_no_arg ("signal to handle");
3652 /* Allocate and zero an array of flags for which signals to handle. */
3654 nsigs
= (int) TARGET_SIGNAL_LAST
;
3655 sigs
= (unsigned char *) alloca (nsigs
);
3656 memset (sigs
, 0, nsigs
);
3658 /* Break the command line up into args. */
3660 argv
= buildargv (args
);
3665 old_chain
= make_cleanup_freeargv (argv
);
3667 /* Walk through the args, looking for signal oursigs, signal names, and
3668 actions. Signal numbers and signal names may be interspersed with
3669 actions, with the actions being performed for all signals cumulatively
3670 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3672 while (*argv
!= NULL
)
3674 wordlen
= strlen (*argv
);
3675 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3679 sigfirst
= siglast
= -1;
3681 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3683 /* Apply action to all signals except those used by the
3684 debugger. Silently skip those. */
3687 siglast
= nsigs
- 1;
3689 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3691 SET_SIGS (nsigs
, sigs
, signal_stop
);
3692 SET_SIGS (nsigs
, sigs
, signal_print
);
3694 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3696 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3698 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3700 SET_SIGS (nsigs
, sigs
, signal_print
);
3702 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3704 SET_SIGS (nsigs
, sigs
, signal_program
);
3706 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3708 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3710 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3712 SET_SIGS (nsigs
, sigs
, signal_program
);
3714 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3716 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3717 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3719 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3721 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3723 else if (digits
> 0)
3725 /* It is numeric. The numeric signal refers to our own
3726 internal signal numbering from target.h, not to host/target
3727 signal number. This is a feature; users really should be
3728 using symbolic names anyway, and the common ones like
3729 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3731 sigfirst
= siglast
= (int)
3732 target_signal_from_command (atoi (*argv
));
3733 if ((*argv
)[digits
] == '-')
3736 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3738 if (sigfirst
> siglast
)
3740 /* Bet he didn't figure we'd think of this case... */
3748 oursig
= target_signal_from_name (*argv
);
3749 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3751 sigfirst
= siglast
= (int) oursig
;
3755 /* Not a number and not a recognized flag word => complain. */
3756 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3760 /* If any signal numbers or symbol names were found, set flags for
3761 which signals to apply actions to. */
3763 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3765 switch ((enum target_signal
) signum
)
3767 case TARGET_SIGNAL_TRAP
:
3768 case TARGET_SIGNAL_INT
:
3769 if (!allsigs
&& !sigs
[signum
])
3771 if (query ("%s is used by the debugger.\n\
3772 Are you sure you want to change it? ",
3773 target_signal_to_name
3774 ((enum target_signal
) signum
)))
3780 printf_unfiltered ("Not confirmed, unchanged.\n");
3781 gdb_flush (gdb_stdout
);
3785 case TARGET_SIGNAL_0
:
3786 case TARGET_SIGNAL_DEFAULT
:
3787 case TARGET_SIGNAL_UNKNOWN
:
3788 /* Make sure that "all" doesn't print these. */
3799 target_notice_signals (inferior_pid
);
3803 /* Show the results. */
3804 sig_print_header ();
3805 for (signum
= 0; signum
< nsigs
; signum
++)
3809 sig_print_info (signum
);
3814 do_cleanups (old_chain
);
3818 xdb_handle_command (char *args
, int from_tty
)
3821 struct cleanup
*old_chain
;
3823 /* Break the command line up into args. */
3825 argv
= buildargv (args
);
3830 old_chain
= make_cleanup_freeargv (argv
);
3831 if (argv
[1] != (char *) NULL
)
3836 bufLen
= strlen (argv
[0]) + 20;
3837 argBuf
= (char *) xmalloc (bufLen
);
3841 enum target_signal oursig
;
3843 oursig
= target_signal_from_name (argv
[0]);
3844 memset (argBuf
, 0, bufLen
);
3845 if (strcmp (argv
[1], "Q") == 0)
3846 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3849 if (strcmp (argv
[1], "s") == 0)
3851 if (!signal_stop
[oursig
])
3852 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3854 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3856 else if (strcmp (argv
[1], "i") == 0)
3858 if (!signal_program
[oursig
])
3859 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3861 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3863 else if (strcmp (argv
[1], "r") == 0)
3865 if (!signal_print
[oursig
])
3866 sprintf (argBuf
, "%s %s", argv
[0], "print");
3868 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3874 handle_command (argBuf
, from_tty
);
3876 printf_filtered ("Invalid signal handling flag.\n");
3881 do_cleanups (old_chain
);
3884 /* Print current contents of the tables set by the handle command.
3885 It is possible we should just be printing signals actually used
3886 by the current target (but for things to work right when switching
3887 targets, all signals should be in the signal tables). */
3890 signals_info (char *signum_exp
, int from_tty
)
3892 enum target_signal oursig
;
3893 sig_print_header ();
3897 /* First see if this is a symbol name. */
3898 oursig
= target_signal_from_name (signum_exp
);
3899 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3901 /* No, try numeric. */
3903 target_signal_from_command (parse_and_eval_address (signum_exp
));
3905 sig_print_info (oursig
);
3909 printf_filtered ("\n");
3910 /* These ugly casts brought to you by the native VAX compiler. */
3911 for (oursig
= TARGET_SIGNAL_FIRST
;
3912 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3913 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3917 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3918 && oursig
!= TARGET_SIGNAL_DEFAULT
3919 && oursig
!= TARGET_SIGNAL_0
)
3920 sig_print_info (oursig
);
3923 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3926 struct inferior_status
3928 enum target_signal stop_signal
;
3932 int stop_stack_dummy
;
3933 int stopped_by_random_signal
;
3935 CORE_ADDR step_range_start
;
3936 CORE_ADDR step_range_end
;
3937 CORE_ADDR step_frame_address
;
3938 int step_over_calls
;
3939 CORE_ADDR step_resume_break_address
;
3940 int stop_after_trap
;
3941 int stop_soon_quietly
;
3942 CORE_ADDR selected_frame_address
;
3943 char *stop_registers
;
3945 /* These are here because if call_function_by_hand has written some
3946 registers and then decides to call error(), we better not have changed
3951 int breakpoint_proceeded
;
3952 int restore_stack_info
;
3953 int proceed_to_finish
;
3956 static struct inferior_status
*
3957 xmalloc_inferior_status (void)
3959 struct inferior_status
*inf_status
;
3960 inf_status
= xmalloc (sizeof (struct inferior_status
));
3961 inf_status
->stop_registers
= xmalloc (REGISTER_BYTES
);
3962 inf_status
->registers
= xmalloc (REGISTER_BYTES
);
3967 free_inferior_status (struct inferior_status
*inf_status
)
3969 free (inf_status
->registers
);
3970 free (inf_status
->stop_registers
);
3975 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3978 int size
= REGISTER_RAW_SIZE (regno
);
3979 void *buf
= alloca (size
);
3980 store_signed_integer (buf
, size
, val
);
3981 memcpy (&inf_status
->registers
[REGISTER_BYTE (regno
)], buf
, size
);
3984 /* Save all of the information associated with the inferior<==>gdb
3985 connection. INF_STATUS is a pointer to a "struct inferior_status"
3986 (defined in inferior.h). */
3988 struct inferior_status
*
3989 save_inferior_status (int restore_stack_info
)
3991 struct inferior_status
*inf_status
= xmalloc_inferior_status ();
3993 inf_status
->stop_signal
= stop_signal
;
3994 inf_status
->stop_pc
= stop_pc
;
3995 inf_status
->stop_step
= stop_step
;
3996 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3997 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3998 inf_status
->trap_expected
= trap_expected
;
3999 inf_status
->step_range_start
= step_range_start
;
4000 inf_status
->step_range_end
= step_range_end
;
4001 inf_status
->step_frame_address
= step_frame_address
;
4002 inf_status
->step_over_calls
= step_over_calls
;
4003 inf_status
->stop_after_trap
= stop_after_trap
;
4004 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
4005 /* Save original bpstat chain here; replace it with copy of chain.
4006 If caller's caller is walking the chain, they'll be happier if we
4007 hand them back the original chain when restore_inferior_status is
4009 inf_status
->stop_bpstat
= stop_bpstat
;
4010 stop_bpstat
= bpstat_copy (stop_bpstat
);
4011 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
4012 inf_status
->restore_stack_info
= restore_stack_info
;
4013 inf_status
->proceed_to_finish
= proceed_to_finish
;
4015 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
4017 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
4019 record_selected_frame (&(inf_status
->selected_frame_address
),
4020 &(inf_status
->selected_level
));
4024 struct restore_selected_frame_args
4026 CORE_ADDR frame_address
;
4031 restore_selected_frame (void *args
)
4033 struct restore_selected_frame_args
*fr
=
4034 (struct restore_selected_frame_args
*) args
;
4035 struct frame_info
*frame
;
4036 int level
= fr
->level
;
4038 frame
= find_relative_frame (get_current_frame (), &level
);
4040 /* If inf_status->selected_frame_address is NULL, there was no
4041 previously selected frame. */
4042 if (frame
== NULL
||
4043 /* FRAME_FP (frame) != fr->frame_address || */
4044 /* elz: deleted this check as a quick fix to the problem that
4045 for function called by hand gdb creates no internal frame
4046 structure and the real stack and gdb's idea of stack are
4047 different if nested calls by hands are made.
4049 mvs: this worries me. */
4052 warning ("Unable to restore previously selected frame.\n");
4056 select_frame (frame
, fr
->level
);
4062 restore_inferior_status (struct inferior_status
*inf_status
)
4064 stop_signal
= inf_status
->stop_signal
;
4065 stop_pc
= inf_status
->stop_pc
;
4066 stop_step
= inf_status
->stop_step
;
4067 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4068 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4069 trap_expected
= inf_status
->trap_expected
;
4070 step_range_start
= inf_status
->step_range_start
;
4071 step_range_end
= inf_status
->step_range_end
;
4072 step_frame_address
= inf_status
->step_frame_address
;
4073 step_over_calls
= inf_status
->step_over_calls
;
4074 stop_after_trap
= inf_status
->stop_after_trap
;
4075 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
4076 bpstat_clear (&stop_bpstat
);
4077 stop_bpstat
= inf_status
->stop_bpstat
;
4078 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4079 proceed_to_finish
= inf_status
->proceed_to_finish
;
4081 /* FIXME: Is the restore of stop_registers always needed */
4082 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
4084 /* The inferior can be gone if the user types "print exit(0)"
4085 (and perhaps other times). */
4086 if (target_has_execution
)
4087 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
4089 /* FIXME: If we are being called after stopping in a function which
4090 is called from gdb, we should not be trying to restore the
4091 selected frame; it just prints a spurious error message (The
4092 message is useful, however, in detecting bugs in gdb (like if gdb
4093 clobbers the stack)). In fact, should we be restoring the
4094 inferior status at all in that case? . */
4096 if (target_has_stack
&& inf_status
->restore_stack_info
)
4098 struct restore_selected_frame_args fr
;
4099 fr
.level
= inf_status
->selected_level
;
4100 fr
.frame_address
= inf_status
->selected_frame_address
;
4101 /* The point of catch_errors is that if the stack is clobbered,
4102 walking the stack might encounter a garbage pointer and error()
4103 trying to dereference it. */
4104 if (catch_errors (restore_selected_frame
, &fr
,
4105 "Unable to restore previously selected frame:\n",
4106 RETURN_MASK_ERROR
) == 0)
4107 /* Error in restoring the selected frame. Select the innermost
4111 select_frame (get_current_frame (), 0);
4115 free_inferior_status (inf_status
);
4119 do_restore_inferior_status_cleanup (void *sts
)
4121 restore_inferior_status (sts
);
4125 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4127 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4131 discard_inferior_status (struct inferior_status
*inf_status
)
4133 /* See save_inferior_status for info on stop_bpstat. */
4134 bpstat_clear (&inf_status
->stop_bpstat
);
4135 free_inferior_status (inf_status
);
4142 stop_registers
= xmalloc (REGISTER_BYTES
);
4146 _initialize_infrun (void)
4149 register int numsigs
;
4150 struct cmd_list_element
*c
;
4154 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4155 register_gdbarch_swap (NULL
, 0, build_infrun
);
4157 add_info ("signals", signals_info
,
4158 "What debugger does when program gets various signals.\n\
4159 Specify a signal as argument to print info on that signal only.");
4160 add_info_alias ("handle", "signals", 0);
4162 add_com ("handle", class_run
, handle_command
,
4163 concat ("Specify how to handle a signal.\n\
4164 Args are signals and actions to apply to those signals.\n\
4165 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4166 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4167 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4168 The special arg \"all\" is recognized to mean all signals except those\n\
4169 used by the debugger, typically SIGTRAP and SIGINT.\n",
4170 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4171 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4172 Stop means reenter debugger if this signal happens (implies print).\n\
4173 Print means print a message if this signal happens.\n\
4174 Pass means let program see this signal; otherwise program doesn't know.\n\
4175 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4176 Pass and Stop may be combined.", NULL
));
4179 add_com ("lz", class_info
, signals_info
,
4180 "What debugger does when program gets various signals.\n\
4181 Specify a signal as argument to print info on that signal only.");
4182 add_com ("z", class_run
, xdb_handle_command
,
4183 concat ("Specify how to handle a signal.\n\
4184 Args are signals and actions to apply to those signals.\n\
4185 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4186 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4187 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4188 The special arg \"all\" is recognized to mean all signals except those\n\
4189 used by the debugger, typically SIGTRAP and SIGINT.\n",
4190 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4191 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4192 nopass), \"Q\" (noprint)\n\
4193 Stop means reenter debugger if this signal happens (implies print).\n\
4194 Print means print a message if this signal happens.\n\
4195 Pass means let program see this signal; otherwise program doesn't know.\n\
4196 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4197 Pass and Stop may be combined.", NULL
));
4201 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
4202 "There is no `stop' command, but you can set a hook on `stop'.\n\
4203 This allows you to set a list of commands to be run each time execution\n\
4204 of the program stops.", &cmdlist
);
4206 numsigs
= (int) TARGET_SIGNAL_LAST
;
4207 signal_stop
= (unsigned char *)
4208 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4209 signal_print
= (unsigned char *)
4210 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4211 signal_program
= (unsigned char *)
4212 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4213 for (i
= 0; i
< numsigs
; i
++)
4216 signal_print
[i
] = 1;
4217 signal_program
[i
] = 1;
4220 /* Signals caused by debugger's own actions
4221 should not be given to the program afterwards. */
4222 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4223 signal_program
[TARGET_SIGNAL_INT
] = 0;
4225 /* Signals that are not errors should not normally enter the debugger. */
4226 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4227 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4228 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4229 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4230 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4231 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4232 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4233 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4234 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4235 signal_print
[TARGET_SIGNAL_IO
] = 0;
4236 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4237 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4238 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4239 signal_print
[TARGET_SIGNAL_URG
] = 0;
4240 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4241 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4243 /* These signals are used internally by user-level thread
4244 implementations. (See signal(5) on Solaris.) Like the above
4245 signals, a healthy program receives and handles them as part of
4246 its normal operation. */
4247 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4248 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4249 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4250 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4251 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4252 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4256 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4257 (char *) &stop_on_solib_events
,
4258 "Set stopping for shared library events.\n\
4259 If nonzero, gdb will give control to the user when the dynamic linker\n\
4260 notifies gdb of shared library events. The most common event of interest\n\
4261 to the user would be loading/unloading of a new library.\n",
4266 c
= add_set_enum_cmd ("follow-fork-mode",
4268 follow_fork_mode_kind_names
,
4269 &follow_fork_mode_string
,
4270 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4271 kernel problem. It's also not terribly useful without a GUI to
4272 help the user drive two debuggers. So for now, I'm disabling
4273 the "both" option. */
4274 /* "Set debugger response to a program call of fork \
4276 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4277 parent - the original process is debugged after a fork\n\
4278 child - the new process is debugged after a fork\n\
4279 both - both the parent and child are debugged after a fork\n\
4280 ask - the debugger will ask for one of the above choices\n\
4281 For \"both\", another copy of the debugger will be started to follow\n\
4282 the new child process. The original debugger will continue to follow\n\
4283 the original parent process. To distinguish their prompts, the\n\
4284 debugger copy's prompt will be changed.\n\
4285 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4286 By default, the debugger will follow the parent process.",
4288 "Set debugger response to a program call of fork \
4290 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4291 parent - the original process is debugged after a fork\n\
4292 child - the new process is debugged after a fork\n\
4293 ask - the debugger will ask for one of the above choices\n\
4294 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4295 By default, the debugger will follow the parent process.",
4297 /* c->function.sfunc = ; */
4298 add_show_from_set (c
, &showlist
);
4300 c
= add_set_enum_cmd ("scheduler-locking", class_run
,
4301 scheduler_enums
, /* array of string names */
4302 &scheduler_mode
, /* current mode */
4303 "Set mode for locking scheduler during execution.\n\
4304 off == no locking (threads may preempt at any time)\n\
4305 on == full locking (no thread except the current thread may run)\n\
4306 step == scheduler locked during every single-step operation.\n\
4307 In this mode, no other thread may run during a step command.\n\
4308 Other threads may run while stepping over a function call ('next').",
4311 c
->function
.sfunc
= set_schedlock_func
; /* traps on target vector */
4312 add_show_from_set (c
, &showlist
);