1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986-1989, 1991-1999 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
27 #include "breakpoint.h"
32 #include "gdbthread.h"
34 #include "symfile.h" /* for overlay functions */
37 #include "event-loop.h"
38 #include "event-top.h"
39 #include "remote.h" /* For cleanup_sigint_signal_handler. */
41 /* Prototypes for local functions */
43 static void signals_info (char *, int);
45 static void handle_command (char *, int);
47 static void sig_print_info (enum target_signal);
49 static void sig_print_header (void);
51 static void resume_cleanups (int);
53 static int hook_stop_stub (void *);
55 static void delete_breakpoint_current_contents (void *);
57 static void set_follow_fork_mode_command (char *arg, int from_tty,
58 struct cmd_list_element * c);
60 static void complete_execution (void);
62 static struct inferior_status *xmalloc_inferior_status (void);
64 static void free_inferior_status (struct inferior_status *);
66 static int restore_selected_frame (void *);
68 static void build_infrun (void);
70 static void follow_inferior_fork (int parent_pid, int child_pid,
71 int has_forked, int has_vforked);
73 static void follow_fork (int parent_pid, int child_pid);
75 static void follow_vfork (int parent_pid, int child_pid);
77 static void set_schedlock_func (char *args, int from_tty,
78 struct cmd_list_element * c);
80 static int is_internal_shlib_eventpoint (struct breakpoint * ep);
82 static int stopped_for_internal_shlib_event (bpstat bs);
84 struct execution_control_state;
86 static int currently_stepping (struct execution_control_state *ecs);
88 static void xdb_handle_command (char *args, int from_tty);
90 void _initialize_infrun (void);
92 int inferior_ignoring_startup_exec_events = 0;
93 int inferior_ignoring_leading_exec_events = 0;
95 /* In asynchronous mode, but simulating synchronous execution. */
97 int sync_execution = 0;
99 /* wait_for_inferior and normal_stop use this to notify the user
100 when the inferior stopped in a different thread than it had been
103 static int switched_from_inferior_pid;
105 /* This will be true for configurations that may actually report an
106 inferior pid different from the original. At present this is only
107 true for HP-UX native. */
109 #ifndef MAY_SWITCH_FROM_INFERIOR_PID
110 #define MAY_SWITCH_FROM_INFERIOR_PID (0)
113 static int may_switch_from_inferior_pid = MAY_SWITCH_FROM_INFERIOR_PID;
115 /* This is true for configurations that may follow through execl() and
116 similar functions. At present this is only true for HP-UX native. */
118 #ifndef MAY_FOLLOW_EXEC
119 #define MAY_FOLLOW_EXEC (0)
122 static int may_follow_exec = MAY_FOLLOW_EXEC;
124 /* resume and wait_for_inferior use this to ensure that when
125 stepping over a hit breakpoint in a threaded application
126 only the thread that hit the breakpoint is stepped and the
127 other threads don't continue. This prevents having another
128 thread run past the breakpoint while it is temporarily
131 This is not thread-specific, so it isn't saved as part of
134 Versions of gdb which don't use the "step == this thread steps
135 and others continue" model but instead use the "step == this
136 thread steps and others wait" shouldn't do this. */
138 static int thread_step_needed = 0;
140 /* This is true if thread_step_needed should actually be used. At
141 present this is only true for HP-UX native. */
143 #ifndef USE_THREAD_STEP_NEEDED
144 #define USE_THREAD_STEP_NEEDED (0)
147 static int use_thread_step_needed = USE_THREAD_STEP_NEEDED;
149 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
150 program. It needs to examine the jmp_buf argument and extract the PC
151 from it. The return value is non-zero on success, zero otherwise. */
153 #ifndef GET_LONGJMP_TARGET
154 #define GET_LONGJMP_TARGET(PC_ADDR) 0
158 /* Some machines have trampoline code that sits between function callers
159 and the actual functions themselves. If this machine doesn't have
160 such things, disable their processing. */
162 #ifndef SKIP_TRAMPOLINE_CODE
163 #define SKIP_TRAMPOLINE_CODE(pc) 0
166 /* Dynamic function trampolines are similar to solib trampolines in that they
167 are between the caller and the callee. The difference is that when you
168 enter a dynamic trampoline, you can't determine the callee's address. Some
169 (usually complex) code needs to run in the dynamic trampoline to figure out
170 the callee's address. This macro is usually called twice. First, when we
171 enter the trampoline (looks like a normal function call at that point). It
172 should return the PC of a point within the trampoline where the callee's
173 address is known. Second, when we hit the breakpoint, this routine returns
174 the callee's address. At that point, things proceed as per a step resume
177 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
178 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
181 /* If the program uses ELF-style shared libraries, then calls to
182 functions in shared libraries go through stubs, which live in a
183 table called the PLT (Procedure Linkage Table). The first time the
184 function is called, the stub sends control to the dynamic linker,
185 which looks up the function's real address, patches the stub so
186 that future calls will go directly to the function, and then passes
187 control to the function.
189 If we are stepping at the source level, we don't want to see any of
190 this --- we just want to skip over the stub and the dynamic linker.
191 The simple approach is to single-step until control leaves the
194 However, on some systems (e.g., Red Hat Linux 5.2) the dynamic
195 linker calls functions in the shared C library, so you can't tell
196 from the PC alone whether the dynamic linker is still running. In
197 this case, we use a step-resume breakpoint to get us past the
198 dynamic linker, as if we were using "next" to step over a function
201 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
202 linker code or not. Normally, this means we single-step. However,
203 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
204 address where we can place a step-resume breakpoint to get past the
205 linker's symbol resolution function.
207 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
208 pretty portable way, by comparing the PC against the address ranges
209 of the dynamic linker's sections.
211 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
212 it depends on internal details of the dynamic linker. It's usually
213 not too hard to figure out where to put a breakpoint, but it
214 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
215 sanity checking. If it can't figure things out, returning zero and
216 getting the (possibly confusing) stepping behavior is better than
217 signalling an error, which will obscure the change in the
220 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
221 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
224 #ifndef SKIP_SOLIB_RESOLVER
225 #define SKIP_SOLIB_RESOLVER(pc) 0
228 /* For SVR4 shared libraries, each call goes through a small piece of
229 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
230 to nonzero if we are current stopped in one of these. */
232 #ifndef IN_SOLIB_CALL_TRAMPOLINE
233 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
236 /* In some shared library schemes, the return path from a shared library
237 call may need to go through a trampoline too. */
239 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
240 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
243 /* This function returns TRUE if pc is the address of an instruction
244 that lies within the dynamic linker (such as the event hook, or the
247 This function must be used only when a dynamic linker event has
248 been caught, and the inferior is being stepped out of the hook, or
249 undefined results are guaranteed. */
251 #ifndef SOLIB_IN_DYNAMIC_LINKER
252 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
255 /* On MIPS16, a function that returns a floating point value may call
256 a library helper function to copy the return value to a floating point
257 register. The IGNORE_HELPER_CALL macro returns non-zero if we
258 should ignore (i.e. step over) this function call. */
259 #ifndef IGNORE_HELPER_CALL
260 #define IGNORE_HELPER_CALL(pc) 0
263 /* On some systems, the PC may be left pointing at an instruction that won't
264 actually be executed. This is usually indicated by a bit in the PSW. If
265 we find ourselves in such a state, then we step the target beyond the
266 nullified instruction before returning control to the user so as to avoid
269 #ifndef INSTRUCTION_NULLIFIED
270 #define INSTRUCTION_NULLIFIED 0
273 /* We can't step off a permanent breakpoint in the ordinary way, because we
274 can't remove it. Instead, we have to advance the PC to the next
275 instruction. This macro should expand to a pointer to a function that
276 does that, or zero if we have no such function. If we don't have a
277 definition for it, we have to report an error. */
278 #ifndef SKIP_PERMANENT_BREAKPOINT
279 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
281 default_skip_permanent_breakpoint ()
284 fprintf_filtered (gdb_stderr, "\
285 The program is stopped at a permanent breakpoint, but GDB does not know\n\
286 how to step past a permanent breakpoint on this architecture. Try using\n\
287 a command like `return' or `jump' to continue execution.\n");
288 return_to_top_level (RETURN_ERROR);
293 /* Convert the #defines into values. This is temporary until wfi control
294 flow is completely sorted out. */
296 #ifndef HAVE_STEPPABLE_WATCHPOINT
297 #define HAVE_STEPPABLE_WATCHPOINT 0
299 #undef HAVE_STEPPABLE_WATCHPOINT
300 #define HAVE_STEPPABLE_WATCHPOINT 1
303 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
304 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
306 #undef HAVE_NONSTEPPABLE_WATCHPOINT
307 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
310 #ifndef HAVE_CONTINUABLE_WATCHPOINT
311 #define HAVE_CONTINUABLE_WATCHPOINT 0
313 #undef HAVE_CONTINUABLE_WATCHPOINT
314 #define HAVE_CONTINUABLE_WATCHPOINT 1
317 /* Tables of how to react to signals; the user sets them. */
319 static unsigned char *signal_stop;
320 static unsigned char *signal_print;
321 static unsigned char *signal_program;
323 #define SET_SIGS(nsigs,sigs,flags) \
325 int signum = (nsigs); \
326 while (signum-- > 0) \
327 if ((sigs)[signum]) \
328 (flags)[signum] = 1; \
331 #define UNSET_SIGS(nsigs,sigs,flags) \
333 int signum = (nsigs); \
334 while (signum-- > 0) \
335 if ((sigs)[signum]) \
336 (flags)[signum] = 0; \
340 /* Command list pointer for the "stop" placeholder. */
342 static struct cmd_list_element *stop_command;
344 /* Nonzero if breakpoints are now inserted in the inferior. */
346 static int breakpoints_inserted;
348 /* Function inferior was in as of last step command. */
350 static struct symbol *step_start_function;
352 /* Nonzero if we are expecting a trace trap and should proceed from it. */
354 static int trap_expected;
357 /* Nonzero if we want to give control to the user when we're notified
358 of shared library events by the dynamic linker. */
359 static int stop_on_solib_events;
363 /* Nonzero if the next time we try to continue the inferior, it will
364 step one instruction and generate a spurious trace trap.
365 This is used to compensate for a bug in HP-UX. */
367 static int trap_expected_after_continue;
370 /* Nonzero means expecting a trace trap
371 and should stop the inferior and return silently when it happens. */
375 /* Nonzero means expecting a trap and caller will handle it themselves.
376 It is used after attach, due to attaching to a process;
377 when running in the shell before the child program has been exec'd;
378 and when running some kinds of remote stuff (FIXME?). */
380 int stop_soon_quietly;
382 /* Nonzero if proceed is being used for a "finish" command or a similar
383 situation when stop_registers should be saved. */
385 int proceed_to_finish;
387 /* Save register contents here when about to pop a stack dummy frame,
388 if-and-only-if proceed_to_finish is set.
389 Thus this contains the return value from the called function (assuming
390 values are returned in a register). */
392 char *stop_registers;
394 /* Nonzero if program stopped due to error trying to insert breakpoints. */
396 static int breakpoints_failed;
398 /* Nonzero after stop if current stack frame should be printed. */
400 static int stop_print_frame;
402 static struct breakpoint *step_resume_breakpoint = NULL;
403 static struct breakpoint *through_sigtramp_breakpoint = NULL;
405 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
406 interactions with an inferior that is running a kernel function
407 (aka, a system call or "syscall"). wait_for_inferior therefore
408 may have a need to know when the inferior is in a syscall. This
409 is a count of the number of inferior threads which are known to
410 currently be running in a syscall. */
411 static int number_of_threads_in_syscalls;
413 /* This is used to remember when a fork, vfork or exec event
414 was caught by a catchpoint, and thus the event is to be
415 followed at the next resume of the inferior, and not
419 enum target_waitkind kind;
429 char *execd_pathname;
433 /* Some platforms don't allow us to do anything meaningful with a
434 vforked child until it has exec'd. Vforked processes on such
435 platforms can only be followed after they've exec'd.
437 When this is set to 0, a vfork can be immediately followed,
438 and an exec can be followed merely as an exec. When this is
439 set to 1, a vfork event has been seen, but cannot be followed
440 until the exec is seen.
442 (In the latter case, inferior_pid is still the parent of the
443 vfork, and pending_follow.fork_event.child_pid is the child. The
444 appropriate process is followed, according to the setting of
445 follow-fork-mode.) */
446 static int follow_vfork_when_exec;
448 static char *follow_fork_mode_kind_names[] =
450 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
451 kernel problem. It's also not terribly useful without a GUI to
452 help the user drive two debuggers. So for now, I'm disabling
454 "parent", "child", "both", "ask" };
456 "parent", "child", "ask"};
458 static char *follow_fork_mode_string = NULL;
462 follow_inferior_fork (int parent_pid, int child_pid, int has_forked,
465 int followed_parent = 0;
466 int followed_child = 0;
468 /* Which process did the user want us to follow? */
470 savestring (follow_fork_mode_string, strlen (follow_fork_mode_string));
472 /* Or, did the user not know, and want us to ask? */
473 if (STREQ (follow_fork_mode_string, "ask"))
475 char requested_mode[100];
478 error ("\"ask\" mode NYI");
479 follow_mode = savestring (requested_mode, strlen (requested_mode));
482 /* If we're to be following the parent, then detach from child_pid.
483 We're already following the parent, so need do nothing explicit
485 if (STREQ (follow_mode, "parent"))
489 /* We're already attached to the parent, by default. */
491 /* Before detaching from the child, remove all breakpoints from
492 it. (This won't actually modify the breakpoint list, but will
493 physically remove the breakpoints from the child.) */
494 if (!has_vforked || !follow_vfork_when_exec)
496 detach_breakpoints (child_pid);
497 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
498 SOLIB_REMOVE_INFERIOR_HOOK (child_pid);
502 /* Detach from the child. */
505 target_require_detach (child_pid, "", 1);
508 /* If we're to be following the child, then attach to it, detach
509 from inferior_pid, and set inferior_pid to child_pid. */
510 else if (STREQ (follow_mode, "child"))
512 char child_pid_spelling[100]; /* Arbitrary length. */
516 /* Before detaching from the parent, detach all breakpoints from
517 the child. But only if we're forking, or if we follow vforks
518 as soon as they happen. (If we're following vforks only when
519 the child has exec'd, then it's very wrong to try to write
520 back the "shadow contents" of inserted breakpoints now -- they
521 belong to the child's pre-exec'd a.out.) */
522 if (!has_vforked || !follow_vfork_when_exec)
524 detach_breakpoints (child_pid);
527 /* Before detaching from the parent, remove all breakpoints from it. */
528 remove_breakpoints ();
530 /* Also reset the solib inferior hook from the parent. */
531 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
532 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid);
535 /* Detach from the parent. */
537 target_detach (NULL, 1);
539 /* Attach to the child. */
540 inferior_pid = child_pid;
541 sprintf (child_pid_spelling, "%d", child_pid);
544 target_require_attach (child_pid_spelling, 1);
546 /* Was there a step_resume breakpoint? (There was if the user
547 did a "next" at the fork() call.) If so, explicitly reset its
550 step_resumes are a form of bp that are made to be per-thread.
551 Since we created the step_resume bp when the parent process
552 was being debugged, and now are switching to the child process,
553 from the breakpoint package's viewpoint, that's a switch of
554 "threads". We must update the bp's notion of which thread
555 it is for, or it'll be ignored when it triggers... */
556 if (step_resume_breakpoint &&
557 (!has_vforked || !follow_vfork_when_exec))
558 breakpoint_re_set_thread (step_resume_breakpoint);
560 /* Reinsert all breakpoints in the child. (The user may've set
561 breakpoints after catching the fork, in which case those
562 actually didn't get set in the child, but only in the parent.) */
563 if (!has_vforked || !follow_vfork_when_exec)
565 breakpoint_re_set ();
566 insert_breakpoints ();
570 /* If we're to be following both parent and child, then fork ourselves,
571 and attach the debugger clone to the child. */
572 else if (STREQ (follow_mode, "both"))
574 char pid_suffix[100]; /* Arbitrary length. */
576 /* Clone ourselves to follow the child. This is the end of our
577 involvement with child_pid; our clone will take it from here... */
579 target_clone_and_follow_inferior (child_pid, &followed_child);
580 followed_parent = !followed_child;
582 /* We continue to follow the parent. To help distinguish the two
583 debuggers, though, both we and our clone will reset our prompts. */
584 sprintf (pid_suffix, "[%d] ", inferior_pid);
585 set_prompt (strcat (get_prompt (), pid_suffix));
588 /* The parent and child of a vfork share the same address space.
589 Also, on some targets the order in which vfork and exec events
590 are received for parent in child requires some delicate handling
593 For instance, on ptrace-based HPUX we receive the child's vfork
594 event first, at which time the parent has been suspended by the
595 OS and is essentially untouchable until the child's exit or second
596 exec event arrives. At that time, the parent's vfork event is
597 delivered to us, and that's when we see and decide how to follow
598 the vfork. But to get to that point, we must continue the child
599 until it execs or exits. To do that smoothly, all breakpoints
600 must be removed from the child, in case there are any set between
601 the vfork() and exec() calls. But removing them from the child
602 also removes them from the parent, due to the shared-address-space
603 nature of a vfork'd parent and child. On HPUX, therefore, we must
604 take care to restore the bp's to the parent before we continue it.
605 Else, it's likely that we may not stop in the expected place. (The
606 worst scenario is when the user tries to step over a vfork() call;
607 the step-resume bp must be restored for the step to properly stop
608 in the parent after the call completes!)
610 Sequence of events, as reported to gdb from HPUX:
612 Parent Child Action for gdb to take
613 -------------------------------------------------------
614 1 VFORK Continue child
620 target_post_follow_vfork (parent_pid,
626 pending_follow.fork_event.saw_parent_fork = 0;
627 pending_follow.fork_event.saw_child_fork = 0;
633 follow_fork (int parent_pid, int child_pid)
635 follow_inferior_fork (parent_pid, child_pid, 1, 0);
639 /* Forward declaration. */
640 static void follow_exec (int, char *);
643 follow_vfork (int parent_pid, int child_pid)
645 follow_inferior_fork (parent_pid, child_pid, 0, 1);
647 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
648 if (pending_follow.fork_event.saw_child_exec && (inferior_pid == child_pid))
650 pending_follow.fork_event.saw_child_exec = 0;
651 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
652 follow_exec (inferior_pid, pending_follow.execd_pathname);
653 free (pending_follow.execd_pathname);
658 follow_exec (int pid, char *execd_pathname)
661 struct target_ops *tgt;
663 if (!may_follow_exec)
666 /* Did this exec() follow a vfork()? If so, we must follow the
667 vfork now too. Do it before following the exec. */
668 if (follow_vfork_when_exec &&
669 (pending_follow.kind == TARGET_WAITKIND_VFORKED))
671 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
672 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
673 follow_vfork_when_exec = 0;
674 saved_pid = inferior_pid;
676 /* Did we follow the parent? If so, we're done. If we followed
677 the child then we must also follow its exec(). */
678 if (inferior_pid == pending_follow.fork_event.parent_pid)
682 /* This is an exec event that we actually wish to pay attention to.
683 Refresh our symbol table to the newly exec'd program, remove any
686 If there are breakpoints, they aren't really inserted now,
687 since the exec() transformed our inferior into a fresh set
690 We want to preserve symbolic breakpoints on the list, since
691 we have hopes that they can be reset after the new a.out's
692 symbol table is read.
694 However, any "raw" breakpoints must be removed from the list
695 (e.g., the solib bp's), since their address is probably invalid
698 And, we DON'T want to call delete_breakpoints() here, since
699 that may write the bp's "shadow contents" (the instruction
700 value that was overwritten witha TRAP instruction). Since
701 we now have a new a.out, those shadow contents aren't valid. */
702 update_breakpoints_after_exec ();
704 /* If there was one, it's gone now. We cannot truly step-to-next
705 statement through an exec(). */
706 step_resume_breakpoint = NULL;
707 step_range_start = 0;
710 /* If there was one, it's gone now. */
711 through_sigtramp_breakpoint = NULL;
713 /* What is this a.out's name? */
714 printf_unfiltered ("Executing new program: %s\n", execd_pathname);
716 /* We've followed the inferior through an exec. Therefore, the
717 inferior has essentially been killed & reborn. */
719 /* First collect the run target in effect. */
720 tgt = find_run_target ();
721 /* If we can't find one, things are in a very strange state... */
723 error ("Could find run target to save before following exec");
725 gdb_flush (gdb_stdout);
726 target_mourn_inferior ();
727 inferior_pid = saved_pid; /* Because mourn_inferior resets inferior_pid. */
730 /* That a.out is now the one to use. */
731 exec_file_attach (execd_pathname, 0);
733 /* And also is where symbols can be found. */
734 symbol_file_command (execd_pathname, 0);
736 /* Reset the shared library package. This ensures that we get
737 a shlib event when the child reaches "_start", at which point
738 the dld will have had a chance to initialize the child. */
739 #if defined(SOLIB_RESTART)
742 #ifdef SOLIB_CREATE_INFERIOR_HOOK
743 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid);
746 /* Reinsert all breakpoints. (Those which were symbolic have
747 been reset to the proper address in the new a.out, thanks
748 to symbol_file_command...) */
749 insert_breakpoints ();
751 /* The next resume of this inferior should bring it to the shlib
752 startup breakpoints. (If the user had also set bp's on
753 "main" from the old (parent) process, then they'll auto-
754 matically get reset there in the new process.) */
757 /* Non-zero if we just simulating a single-step. This is needed
758 because we cannot remove the breakpoints in the inferior process
759 until after the `wait' in `wait_for_inferior'. */
760 static int singlestep_breakpoints_inserted_p = 0;
763 /* Things to clean up if we QUIT out of resume (). */
766 resume_cleanups (int arg)
771 static char schedlock_off[] = "off";
772 static char schedlock_on[] = "on";
773 static char schedlock_step[] = "step";
774 static char *scheduler_mode = schedlock_off;
775 static char *scheduler_enums[] =
776 {schedlock_off, schedlock_on, schedlock_step};
779 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
781 if (c->type == set_cmd)
782 if (!target_can_lock_scheduler)
784 scheduler_mode = schedlock_off;
785 error ("Target '%s' cannot support this command.",
793 /* Resume the inferior, but allow a QUIT. This is useful if the user
794 wants to interrupt some lengthy single-stepping operation
795 (for child processes, the SIGINT goes to the inferior, and so
796 we get a SIGINT random_signal, but for remote debugging and perhaps
797 other targets, that's not true).
799 STEP nonzero if we should step (zero to continue instead).
800 SIG is the signal to give the inferior (zero for none). */
802 resume (int step, enum target_signal sig)
804 int should_resume = 1;
805 struct cleanup *old_cleanups = make_cleanup ((make_cleanup_func)
809 #ifdef CANNOT_STEP_BREAKPOINT
810 /* Most targets can step a breakpoint instruction, thus executing it
811 normally. But if this one cannot, just continue and we will hit
813 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
817 /* Normally, by the time we reach `resume', the breakpoints are either
818 removed or inserted, as appropriate. The exception is if we're sitting
819 at a permanent breakpoint; we need to step over it, but permanent
820 breakpoints can't be removed. So we have to test for it here. */
821 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here)
822 SKIP_PERMANENT_BREAKPOINT ();
824 if (SOFTWARE_SINGLE_STEP_P && step)
826 /* Do it the hard way, w/temp breakpoints */
827 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ );
828 /* ...and don't ask hardware to do it. */
830 /* and do not pull these breakpoints until after a `wait' in
831 `wait_for_inferior' */
832 singlestep_breakpoints_inserted_p = 1;
835 /* Handle any optimized stores to the inferior NOW... */
836 #ifdef DO_DEFERRED_STORES
840 /* If there were any forks/vforks/execs that were caught and are
841 now to be followed, then do so. */
842 switch (pending_follow.kind)
844 case (TARGET_WAITKIND_FORKED):
845 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
846 follow_fork (inferior_pid, pending_follow.fork_event.child_pid);
849 case (TARGET_WAITKIND_VFORKED):
851 int saw_child_exec = pending_follow.fork_event.saw_child_exec;
853 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
854 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
856 /* Did we follow the child, but not yet see the child's exec event?
857 If so, then it actually ought to be waiting for us; we respond to
858 parent vfork events. We don't actually want to resume the child
859 in this situation; we want to just get its exec event. */
860 if (!saw_child_exec &&
861 (inferior_pid == pending_follow.fork_event.child_pid))
866 case (TARGET_WAITKIND_EXECD):
867 /* If we saw a vfork event but couldn't follow it until we saw
868 an exec, then now might be the time! */
869 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
870 /* follow_exec is called as soon as the exec event is seen. */
877 /* Install inferior's terminal modes. */
878 target_terminal_inferior ();
882 if (use_thread_step_needed && thread_step_needed)
884 /* We stopped on a BPT instruction;
885 don't continue other threads and
886 just step this thread. */
887 thread_step_needed = 0;
889 if (!breakpoint_here_p (read_pc ()))
891 /* Breakpoint deleted: ok to do regular resume
892 where all the threads either step or continue. */
893 target_resume (-1, step, sig);
899 warning ("Internal error, changing continue to step.");
900 remove_breakpoints ();
901 breakpoints_inserted = 0;
906 target_resume (inferior_pid, step, sig);
911 /* Vanilla resume. */
913 if ((scheduler_mode == schedlock_on) ||
914 (scheduler_mode == schedlock_step && step != 0))
915 target_resume (inferior_pid, step, sig);
917 target_resume (-1, step, sig);
921 discard_cleanups (old_cleanups);
925 /* Clear out all variables saying what to do when inferior is continued.
926 First do this, then set the ones you want, then call `proceed'. */
929 clear_proceed_status (void)
932 step_range_start = 0;
934 step_frame_address = 0;
935 step_over_calls = -1;
937 stop_soon_quietly = 0;
938 proceed_to_finish = 0;
939 breakpoint_proceeded = 1; /* We're about to proceed... */
941 /* Discard any remaining commands or status from previous stop. */
942 bpstat_clear (&stop_bpstat);
945 /* Basic routine for continuing the program in various fashions.
947 ADDR is the address to resume at, or -1 for resume where stopped.
948 SIGGNAL is the signal to give it, or 0 for none,
949 or -1 for act according to how it stopped.
950 STEP is nonzero if should trap after one instruction.
951 -1 means return after that and print nothing.
952 You should probably set various step_... variables
953 before calling here, if you are stepping.
955 You should call clear_proceed_status before calling proceed. */
958 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
963 step_start_function = find_pc_function (read_pc ());
967 if (addr == (CORE_ADDR) - 1)
969 /* If there is a breakpoint at the address we will resume at,
970 step one instruction before inserting breakpoints
971 so that we do not stop right away (and report a second
972 hit at this breakpoint). */
974 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
977 #ifndef STEP_SKIPS_DELAY
978 #define STEP_SKIPS_DELAY(pc) (0)
979 #define STEP_SKIPS_DELAY_P (0)
981 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
982 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
983 is slow (it needs to read memory from the target). */
984 if (STEP_SKIPS_DELAY_P
985 && breakpoint_here_p (read_pc () + 4)
986 && STEP_SKIPS_DELAY (read_pc ()))
993 /* New address; we don't need to single-step a thread
994 over a breakpoint we just hit, 'cause we aren't
995 continuing from there.
997 It's not worth worrying about the case where a user
998 asks for a "jump" at the current PC--if they get the
999 hiccup of re-hiting a hit breakpoint, what else do
1001 thread_step_needed = 0;
1004 #ifdef PREPARE_TO_PROCEED
1005 /* In a multi-threaded task we may select another thread
1006 and then continue or step.
1008 But if the old thread was stopped at a breakpoint, it
1009 will immediately cause another breakpoint stop without
1010 any execution (i.e. it will report a breakpoint hit
1011 incorrectly). So we must step over it first.
1013 PREPARE_TO_PROCEED checks the current thread against the thread
1014 that reported the most recent event. If a step-over is required
1015 it returns TRUE and sets the current thread to the old thread. */
1016 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
1019 thread_step_needed = 1;
1022 #endif /* PREPARE_TO_PROCEED */
1025 if (trap_expected_after_continue)
1027 /* If (step == 0), a trap will be automatically generated after
1028 the first instruction is executed. Force step one
1029 instruction to clear this condition. This should not occur
1030 if step is nonzero, but it is harmless in that case. */
1032 trap_expected_after_continue = 0;
1034 #endif /* HP_OS_BUG */
1037 /* We will get a trace trap after one instruction.
1038 Continue it automatically and insert breakpoints then. */
1042 int temp = insert_breakpoints ();
1045 print_sys_errmsg ("ptrace", temp);
1046 error ("Cannot insert breakpoints.\n\
1047 The same program may be running in another process.");
1050 breakpoints_inserted = 1;
1053 if (siggnal != TARGET_SIGNAL_DEFAULT)
1054 stop_signal = siggnal;
1055 /* If this signal should not be seen by program,
1056 give it zero. Used for debugging signals. */
1057 else if (!signal_program[stop_signal])
1058 stop_signal = TARGET_SIGNAL_0;
1060 annotate_starting ();
1062 /* Make sure that output from GDB appears before output from the
1064 gdb_flush (gdb_stdout);
1066 /* Resume inferior. */
1067 resume (oneproc || step || bpstat_should_step (), stop_signal);
1069 /* Wait for it to stop (if not standalone)
1070 and in any case decode why it stopped, and act accordingly. */
1071 /* Do this only if we are not using the event loop, or if the target
1072 does not support asynchronous execution. */
1073 if (!async_p || !target_has_async)
1075 wait_for_inferior ();
1080 /* Record the pc and sp of the program the last time it stopped.
1081 These are just used internally by wait_for_inferior, but need
1082 to be preserved over calls to it and cleared when the inferior
1084 static CORE_ADDR prev_pc;
1085 static CORE_ADDR prev_func_start;
1086 static char *prev_func_name;
1089 /* Start remote-debugging of a machine over a serial link. */
1094 init_thread_list ();
1095 init_wait_for_inferior ();
1096 stop_soon_quietly = 1;
1099 /* Go on waiting only in case gdb is not started in async mode, or
1100 in case the target doesn't support async execution. */
1101 if (!async_p || !target_has_async)
1103 wait_for_inferior ();
1108 /* The 'tar rem' command should always look synchronous,
1109 i.e. display the prompt only once it has connected and
1110 started the target. */
1112 push_prompt ("", "", "");
1113 delete_file_handler (input_fd);
1114 target_executing = 1;
1118 /* Initialize static vars when a new inferior begins. */
1121 init_wait_for_inferior (void)
1123 /* These are meaningless until the first time through wait_for_inferior. */
1125 prev_func_start = 0;
1126 prev_func_name = NULL;
1129 trap_expected_after_continue = 0;
1131 breakpoints_inserted = 0;
1132 breakpoint_init_inferior (inf_starting);
1134 /* Don't confuse first call to proceed(). */
1135 stop_signal = TARGET_SIGNAL_0;
1137 /* The first resume is not following a fork/vfork/exec. */
1138 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
1139 pending_follow.fork_event.saw_parent_fork = 0;
1140 pending_follow.fork_event.saw_child_fork = 0;
1141 pending_follow.fork_event.saw_child_exec = 0;
1143 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1144 number_of_threads_in_syscalls = 0;
1146 clear_proceed_status ();
1150 delete_breakpoint_current_contents (void *arg)
1152 struct breakpoint **breakpointp = (struct breakpoint **) arg;
1153 if (*breakpointp != NULL)
1155 delete_breakpoint (*breakpointp);
1156 *breakpointp = NULL;
1160 /* This enum encodes possible reasons for doing a target_wait, so that
1161 wfi can call target_wait in one place. (Ultimately the call will be
1162 moved out of the infinite loop entirely.) */
1166 infwait_normal_state,
1167 infwait_thread_hop_state,
1168 infwait_nullified_state,
1169 infwait_nonstep_watch_state
1172 /* This structure contains what used to be local variables in
1173 wait_for_inferior. Probably many of them can return to being
1174 locals in handle_inferior_event. */
1176 struct execution_control_state
1178 struct target_waitstatus ws;
1179 struct target_waitstatus *wp;
1182 CORE_ADDR stop_func_start;
1183 CORE_ADDR stop_func_end;
1184 char *stop_func_name;
1185 struct symtab_and_line sal;
1186 int remove_breakpoints_on_following_step;
1188 struct symtab *current_symtab;
1189 int handling_longjmp; /* FIXME */
1191 int saved_inferior_pid;
1193 int stepping_through_solib_after_catch;
1194 bpstat stepping_through_solib_catchpoints;
1195 int enable_hw_watchpoints_after_wait;
1196 int stepping_through_sigtramp;
1197 int new_thread_event;
1198 struct target_waitstatus tmpstatus;
1199 enum infwait_states infwait_state;
1204 void init_execution_control_state (struct execution_control_state * ecs);
1206 void handle_inferior_event (struct execution_control_state * ecs);
1208 static void check_sigtramp2 (struct execution_control_state *ecs);
1209 static void step_into_function (struct execution_control_state *ecs);
1210 static void step_over_function (struct execution_control_state *ecs);
1211 static void stop_stepping (struct execution_control_state *ecs);
1212 static void prepare_to_wait (struct execution_control_state *ecs);
1213 static void keep_going (struct execution_control_state *ecs);
1215 /* Wait for control to return from inferior to debugger.
1216 If inferior gets a signal, we may decide to start it up again
1217 instead of returning. That is why there is a loop in this function.
1218 When this function actually returns it means the inferior
1219 should be left stopped and GDB should read more commands. */
1222 wait_for_inferior (void)
1224 struct cleanup *old_cleanups;
1225 struct execution_control_state ecss;
1226 struct execution_control_state *ecs;
1228 old_cleanups = make_cleanup (delete_breakpoint_current_contents,
1229 &step_resume_breakpoint);
1230 make_cleanup (delete_breakpoint_current_contents,
1231 &through_sigtramp_breakpoint);
1233 /* wfi still stays in a loop, so it's OK just to take the address of
1234 a local to get the ecs pointer. */
1237 /* Fill in with reasonable starting values. */
1238 init_execution_control_state (ecs);
1240 thread_step_needed = 0;
1242 /* We'll update this if & when we switch to a new thread. */
1243 if (may_switch_from_inferior_pid)
1244 switched_from_inferior_pid = inferior_pid;
1246 overlay_cache_invalid = 1;
1248 /* We have to invalidate the registers BEFORE calling target_wait
1249 because they can be loaded from the target while in target_wait.
1250 This makes remote debugging a bit more efficient for those
1251 targets that provide critical registers as part of their normal
1252 status mechanism. */
1254 registers_changed ();
1258 if (target_wait_hook)
1259 ecs->pid = target_wait_hook (ecs->waiton_pid, ecs->wp);
1261 ecs->pid = target_wait (ecs->waiton_pid, ecs->wp);
1263 /* Now figure out what to do with the result of the result. */
1264 handle_inferior_event (ecs);
1266 if (!ecs->wait_some_more)
1269 do_cleanups (old_cleanups);
1272 /* Asynchronous version of wait_for_inferior. It is called by the
1273 event loop whenever a change of state is detected on the file
1274 descriptor corresponding to the target. It can be called more than
1275 once to complete a single execution command. In such cases we need
1276 to keep the state in a global variable ASYNC_ECSS. If it is the
1277 last time that this function is called for a single execution
1278 command, then report to the user that the inferior has stopped, and
1279 do the necessary cleanups. */
1281 struct execution_control_state async_ecss;
1282 struct execution_control_state *async_ecs;
1285 fetch_inferior_event (client_data)
1286 gdb_client_data client_data;
1288 static struct cleanup *old_cleanups;
1290 async_ecs = &async_ecss;
1292 if (!async_ecs->wait_some_more)
1294 old_cleanups = make_exec_cleanup (delete_breakpoint_current_contents,
1295 &step_resume_breakpoint);
1296 make_exec_cleanup (delete_breakpoint_current_contents,
1297 &through_sigtramp_breakpoint);
1299 /* Fill in with reasonable starting values. */
1300 init_execution_control_state (async_ecs);
1302 thread_step_needed = 0;
1304 /* We'll update this if & when we switch to a new thread. */
1305 if (may_switch_from_inferior_pid)
1306 switched_from_inferior_pid = inferior_pid;
1308 overlay_cache_invalid = 1;
1310 /* We have to invalidate the registers BEFORE calling target_wait
1311 because they can be loaded from the target while in target_wait.
1312 This makes remote debugging a bit more efficient for those
1313 targets that provide critical registers as part of their normal
1314 status mechanism. */
1316 registers_changed ();
1319 if (target_wait_hook)
1320 async_ecs->pid = target_wait_hook (async_ecs->waiton_pid, async_ecs->wp);
1322 async_ecs->pid = target_wait (async_ecs->waiton_pid, async_ecs->wp);
1324 /* Now figure out what to do with the result of the result. */
1325 handle_inferior_event (async_ecs);
1327 if (!async_ecs->wait_some_more)
1329 /* Do only the cleanups that have been added by this
1330 function. Let the continuations for the commands do the rest,
1331 if there are any. */
1332 do_exec_cleanups (old_cleanups);
1334 /* Is there anything left to do for the command issued to
1336 do_all_continuations ();
1337 /* Reset things after target has stopped for the async commands. */
1338 complete_execution ();
1342 /* Prepare an execution control state for looping through a
1343 wait_for_inferior-type loop. */
1346 init_execution_control_state (struct execution_control_state *ecs)
1348 ecs->random_signal = 0;
1349 ecs->remove_breakpoints_on_following_step = 0;
1350 ecs->handling_longjmp = 0; /* FIXME */
1351 ecs->update_step_sp = 0;
1352 ecs->stepping_through_solib_after_catch = 0;
1353 ecs->stepping_through_solib_catchpoints = NULL;
1354 ecs->enable_hw_watchpoints_after_wait = 0;
1355 ecs->stepping_through_sigtramp = 0;
1356 ecs->sal = find_pc_line (prev_pc, 0);
1357 ecs->current_line = ecs->sal.line;
1358 ecs->current_symtab = ecs->sal.symtab;
1359 ecs->infwait_state = infwait_normal_state;
1360 ecs->waiton_pid = -1;
1361 ecs->wp = &(ecs->ws);
1364 /* Call this function before setting step_resume_breakpoint, as a
1365 sanity check. There should never be more than one step-resume
1366 breakpoint per thread, so we should never be setting a new
1367 step_resume_breakpoint when one is already active. */
1369 check_for_old_step_resume_breakpoint (void)
1371 if (step_resume_breakpoint)
1372 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1375 /* Given an execution control state that has been freshly filled in
1376 by an event from the inferior, figure out what it means and take
1377 appropriate action. */
1380 handle_inferior_event (struct execution_control_state *ecs)
1383 int stepped_after_stopped_by_watchpoint;
1385 /* Keep this extra brace for now, minimizes diffs. */
1387 switch (ecs->infwait_state)
1389 case infwait_normal_state:
1390 /* Since we've done a wait, we have a new event. Don't
1391 carry over any expectations about needing to step over a
1393 thread_step_needed = 0;
1395 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1396 is serviced in this loop, below. */
1397 if (ecs->enable_hw_watchpoints_after_wait)
1399 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid);
1400 ecs->enable_hw_watchpoints_after_wait = 0;
1402 stepped_after_stopped_by_watchpoint = 0;
1405 case infwait_thread_hop_state:
1406 insert_breakpoints ();
1408 /* We need to restart all the threads now,
1409 * unles we're running in scheduler-locked mode.
1410 * FIXME: shouldn't we look at currently_stepping ()?
1412 if (scheduler_mode == schedlock_on)
1413 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1415 target_resume (-1, 0, TARGET_SIGNAL_0);
1416 ecs->infwait_state = infwait_normal_state;
1417 prepare_to_wait (ecs);
1420 case infwait_nullified_state:
1423 case infwait_nonstep_watch_state:
1424 insert_breakpoints ();
1426 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1427 handle things like signals arriving and other things happening
1428 in combination correctly? */
1429 stepped_after_stopped_by_watchpoint = 1;
1432 ecs->infwait_state = infwait_normal_state;
1434 flush_cached_frames ();
1436 /* If it's a new process, add it to the thread database */
1438 ecs->new_thread_event = ((ecs->pid != inferior_pid) && !in_thread_list (ecs->pid));
1440 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1441 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
1442 && ecs->new_thread_event)
1444 add_thread (ecs->pid);
1446 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs->pid));
1449 /* NOTE: This block is ONLY meant to be invoked in case of a
1450 "thread creation event"! If it is invoked for any other
1451 sort of event (such as a new thread landing on a breakpoint),
1452 the event will be discarded, which is almost certainly
1455 To avoid this, the low-level module (eg. target_wait)
1456 should call in_thread_list and add_thread, so that the
1457 new thread is known by the time we get here. */
1459 /* We may want to consider not doing a resume here in order
1460 to give the user a chance to play with the new thread.
1461 It might be good to make that a user-settable option. */
1463 /* At this point, all threads are stopped (happens
1464 automatically in either the OS or the native code).
1465 Therefore we need to continue all threads in order to
1468 target_resume (-1, 0, TARGET_SIGNAL_0);
1469 prepare_to_wait (ecs);
1474 switch (ecs->ws.kind)
1476 case TARGET_WAITKIND_LOADED:
1477 /* Ignore gracefully during startup of the inferior, as it
1478 might be the shell which has just loaded some objects,
1479 otherwise add the symbols for the newly loaded objects. */
1481 if (!stop_soon_quietly)
1483 /* Remove breakpoints, SOLIB_ADD might adjust
1484 breakpoint addresses via breakpoint_re_set. */
1485 if (breakpoints_inserted)
1486 remove_breakpoints ();
1488 /* Check for any newly added shared libraries if we're
1489 supposed to be adding them automatically. */
1492 /* Switch terminal for any messages produced by
1493 breakpoint_re_set. */
1494 target_terminal_ours_for_output ();
1495 SOLIB_ADD (NULL, 0, NULL);
1496 target_terminal_inferior ();
1499 /* Reinsert breakpoints and continue. */
1500 if (breakpoints_inserted)
1501 insert_breakpoints ();
1504 resume (0, TARGET_SIGNAL_0);
1505 prepare_to_wait (ecs);
1508 case TARGET_WAITKIND_SPURIOUS:
1509 resume (0, TARGET_SIGNAL_0);
1510 prepare_to_wait (ecs);
1513 case TARGET_WAITKIND_EXITED:
1514 target_terminal_ours (); /* Must do this before mourn anyway */
1515 annotate_exited (ecs->ws.value.integer);
1516 if (ecs->ws.value.integer)
1517 printf_filtered ("\nProgram exited with code 0%o.\n",
1518 (unsigned int) ecs->ws.value.integer);
1520 printf_filtered ("\nProgram exited normally.\n");
1522 /* Record the exit code in the convenience variable $_exitcode, so
1523 that the user can inspect this again later. */
1524 set_internalvar (lookup_internalvar ("_exitcode"),
1525 value_from_longest (builtin_type_int,
1526 (LONGEST) ecs->ws.value.integer));
1527 gdb_flush (gdb_stdout);
1528 target_mourn_inferior ();
1529 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P */
1530 stop_print_frame = 0;
1531 stop_stepping (ecs);
1534 case TARGET_WAITKIND_SIGNALLED:
1535 stop_print_frame = 0;
1536 stop_signal = ecs->ws.value.sig;
1537 target_terminal_ours (); /* Must do this before mourn anyway */
1538 annotate_signalled ();
1540 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1541 mean it is already dead? This has been here since GDB 2.8, so
1542 perhaps it means rms didn't understand unix waitstatuses?
1543 For the moment I'm just kludging around this in remote.c
1544 rather than trying to change it here --kingdon, 5 Dec 1994. */
1545 target_kill (); /* kill mourns as well */
1547 printf_filtered ("\nProgram terminated with signal ");
1548 annotate_signal_name ();
1549 printf_filtered ("%s", target_signal_to_name (stop_signal));
1550 annotate_signal_name_end ();
1551 printf_filtered (", ");
1552 annotate_signal_string ();
1553 printf_filtered ("%s", target_signal_to_string (stop_signal));
1554 annotate_signal_string_end ();
1555 printf_filtered (".\n");
1557 printf_filtered ("The program no longer exists.\n");
1558 gdb_flush (gdb_stdout);
1559 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P */
1560 stop_stepping (ecs);
1563 /* The following are the only cases in which we keep going;
1564 the above cases end in a continue or goto. */
1565 case TARGET_WAITKIND_FORKED:
1566 stop_signal = TARGET_SIGNAL_TRAP;
1567 pending_follow.kind = ecs->ws.kind;
1569 /* Ignore fork events reported for the parent; we're only
1570 interested in reacting to forks of the child. Note that
1571 we expect the child's fork event to be available if we
1572 waited for it now. */
1573 if (inferior_pid == ecs->pid)
1575 pending_follow.fork_event.saw_parent_fork = 1;
1576 pending_follow.fork_event.parent_pid = ecs->pid;
1577 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1578 prepare_to_wait (ecs);
1583 pending_follow.fork_event.saw_child_fork = 1;
1584 pending_follow.fork_event.child_pid = ecs->pid;
1585 pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid;
1588 stop_pc = read_pc_pid (ecs->pid);
1589 ecs->saved_inferior_pid = inferior_pid;
1590 inferior_pid = ecs->pid;
1591 stop_bpstat = bpstat_stop_status
1593 (DECR_PC_AFTER_BREAK ?
1594 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1595 && currently_stepping (ecs))
1598 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1599 inferior_pid = ecs->saved_inferior_pid;
1600 goto process_event_stop_test;
1602 /* If this a platform which doesn't allow a debugger to touch a
1603 vfork'd inferior until after it exec's, then we'd best keep
1604 our fingers entirely off the inferior, other than continuing
1605 it. This has the unfortunate side-effect that catchpoints
1606 of vforks will be ignored. But since the platform doesn't
1607 allow the inferior be touched at vfork time, there's really
1609 case TARGET_WAITKIND_VFORKED:
1610 stop_signal = TARGET_SIGNAL_TRAP;
1611 pending_follow.kind = ecs->ws.kind;
1613 /* Is this a vfork of the parent? If so, then give any
1614 vfork catchpoints a chance to trigger now. (It's
1615 dangerous to do so if the child canot be touched until
1616 it execs, and the child has not yet exec'd. We probably
1617 should warn the user to that effect when the catchpoint
1619 if (ecs->pid == inferior_pid)
1621 pending_follow.fork_event.saw_parent_fork = 1;
1622 pending_follow.fork_event.parent_pid = ecs->pid;
1623 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1626 /* If we've seen the child's vfork event but cannot really touch
1627 the child until it execs, then we must continue the child now.
1628 Else, give any vfork catchpoints a chance to trigger now. */
1631 pending_follow.fork_event.saw_child_fork = 1;
1632 pending_follow.fork_event.child_pid = ecs->pid;
1633 pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid;
1634 target_post_startup_inferior (pending_follow.fork_event.child_pid);
1635 follow_vfork_when_exec = !target_can_follow_vfork_prior_to_exec ();
1636 if (follow_vfork_when_exec)
1638 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1639 prepare_to_wait (ecs);
1644 stop_pc = read_pc ();
1645 stop_bpstat = bpstat_stop_status
1647 (DECR_PC_AFTER_BREAK ?
1648 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1649 && currently_stepping (ecs))
1652 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1653 goto process_event_stop_test;
1655 case TARGET_WAITKIND_EXECD:
1656 stop_signal = TARGET_SIGNAL_TRAP;
1658 /* Is this a target which reports multiple exec events per actual
1659 call to exec()? (HP-UX using ptrace does, for example.) If so,
1660 ignore all but the last one. Just resume the exec'r, and wait
1661 for the next exec event. */
1662 if (inferior_ignoring_leading_exec_events)
1664 inferior_ignoring_leading_exec_events--;
1665 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1666 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.parent_pid);
1667 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1668 prepare_to_wait (ecs);
1671 inferior_ignoring_leading_exec_events =
1672 target_reported_exec_events_per_exec_call () - 1;
1674 pending_follow.execd_pathname =
1675 savestring (ecs->ws.value.execd_pathname,
1676 strlen (ecs->ws.value.execd_pathname));
1678 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1679 child of a vfork exec?
1681 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1682 HP-UX, events associated with a vforking inferior come in
1683 threes: a vfork event for the child (always first), followed
1684 a vfork event for the parent and an exec event for the child.
1685 The latter two can come in either order.
1687 If we get the parent vfork event first, life's good: We follow
1688 either the parent or child, and then the child's exec event is
1691 But if we get the child's exec event first, then we delay
1692 responding to it until we handle the parent's vfork. Because,
1693 otherwise we can't satisfy a "catch vfork". */
1694 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1696 pending_follow.fork_event.saw_child_exec = 1;
1698 /* On some targets, the child must be resumed before
1699 the parent vfork event is delivered. A single-step
1701 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1702 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1703 /* We expect the parent vfork event to be available now. */
1704 prepare_to_wait (ecs);
1708 /* This causes the eventpoints and symbol table to be reset. Must
1709 do this now, before trying to determine whether to stop. */
1710 follow_exec (inferior_pid, pending_follow.execd_pathname);
1711 free (pending_follow.execd_pathname);
1713 stop_pc = read_pc_pid (ecs->pid);
1714 ecs->saved_inferior_pid = inferior_pid;
1715 inferior_pid = ecs->pid;
1716 stop_bpstat = bpstat_stop_status
1718 (DECR_PC_AFTER_BREAK ?
1719 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1720 && currently_stepping (ecs))
1723 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1724 inferior_pid = ecs->saved_inferior_pid;
1725 goto process_event_stop_test;
1727 /* These syscall events are returned on HP-UX, as part of its
1728 implementation of page-protection-based "hardware" watchpoints.
1729 HP-UX has unfortunate interactions between page-protections and
1730 some system calls. Our solution is to disable hardware watches
1731 when a system call is entered, and reenable them when the syscall
1732 completes. The downside of this is that we may miss the precise
1733 point at which a watched piece of memory is modified. "Oh well."
1735 Note that we may have multiple threads running, which may each
1736 enter syscalls at roughly the same time. Since we don't have a
1737 good notion currently of whether a watched piece of memory is
1738 thread-private, we'd best not have any page-protections active
1739 when any thread is in a syscall. Thus, we only want to reenable
1740 hardware watches when no threads are in a syscall.
1742 Also, be careful not to try to gather much state about a thread
1743 that's in a syscall. It's frequently a losing proposition. */
1744 case TARGET_WAITKIND_SYSCALL_ENTRY:
1745 number_of_threads_in_syscalls++;
1746 if (number_of_threads_in_syscalls == 1)
1748 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid);
1750 resume (0, TARGET_SIGNAL_0);
1751 prepare_to_wait (ecs);
1754 /* Before examining the threads further, step this thread to
1755 get it entirely out of the syscall. (We get notice of the
1756 event when the thread is just on the verge of exiting a
1757 syscall. Stepping one instruction seems to get it back
1760 Note that although the logical place to reenable h/w watches
1761 is here, we cannot. We cannot reenable them before stepping
1762 the thread (this causes the next wait on the thread to hang).
1764 Nor can we enable them after stepping until we've done a wait.
1765 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1766 here, which will be serviced immediately after the target
1768 case TARGET_WAITKIND_SYSCALL_RETURN:
1769 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1771 if (number_of_threads_in_syscalls > 0)
1773 number_of_threads_in_syscalls--;
1774 ecs->enable_hw_watchpoints_after_wait =
1775 (number_of_threads_in_syscalls == 0);
1777 prepare_to_wait (ecs);
1780 case TARGET_WAITKIND_STOPPED:
1781 stop_signal = ecs->ws.value.sig;
1785 /* We may want to consider not doing a resume here in order to give
1786 the user a chance to play with the new thread. It might be good
1787 to make that a user-settable option. */
1789 /* At this point, all threads are stopped (happens automatically in
1790 either the OS or the native code). Therefore we need to continue
1791 all threads in order to make progress. */
1792 if (ecs->new_thread_event)
1794 target_resume (-1, 0, TARGET_SIGNAL_0);
1795 prepare_to_wait (ecs);
1799 stop_pc = read_pc_pid (ecs->pid);
1801 /* See if a thread hit a thread-specific breakpoint that was meant for
1802 another thread. If so, then step that thread past the breakpoint,
1805 if (stop_signal == TARGET_SIGNAL_TRAP)
1807 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1808 ecs->random_signal = 0;
1809 else if (breakpoints_inserted
1810 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
1812 ecs->random_signal = 0;
1813 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK,
1818 /* Saw a breakpoint, but it was hit by the wrong thread.
1820 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, ecs->pid);
1822 remove_status = remove_breakpoints ();
1823 /* Did we fail to remove breakpoints? If so, try
1824 to set the PC past the bp. (There's at least
1825 one situation in which we can fail to remove
1826 the bp's: On HP-UX's that use ttrace, we can't
1827 change the address space of a vforking child
1828 process until the child exits (well, okay, not
1829 then either :-) or execs. */
1830 if (remove_status != 0)
1832 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, ecs->pid);
1836 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1837 /* FIXME: What if a signal arrives instead of the
1838 single-step happening? */
1840 ecs->waiton_pid = ecs->pid;
1841 ecs->wp = &(ecs->ws);
1842 ecs->infwait_state = infwait_thread_hop_state;
1843 prepare_to_wait (ecs);
1847 /* We need to restart all the threads now,
1848 * unles we're running in scheduler-locked mode.
1849 * FIXME: shouldn't we look at currently_stepping ()?
1851 if (scheduler_mode == schedlock_on)
1852 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1854 target_resume (-1, 0, TARGET_SIGNAL_0);
1855 prepare_to_wait (ecs);
1860 /* This breakpoint matches--either it is the right
1861 thread or it's a generic breakpoint for all threads.
1862 Remember that we'll need to step just _this_ thread
1863 on any following user continuation! */
1864 thread_step_needed = 1;
1869 ecs->random_signal = 1;
1871 /* See if something interesting happened to the non-current thread. If
1872 so, then switch to that thread, and eventually give control back to
1875 Note that if there's any kind of pending follow (i.e., of a fork,
1876 vfork or exec), we don't want to do this now. Rather, we'll let
1877 the next resume handle it. */
1878 if ((ecs->pid != inferior_pid) &&
1879 (pending_follow.kind == TARGET_WAITKIND_SPURIOUS))
1883 /* If it's a random signal for a non-current thread, notify user
1884 if he's expressed an interest. */
1885 if (ecs->random_signal
1886 && signal_print[stop_signal])
1888 /* ??rehrauer: I don't understand the rationale for this code. If the
1889 inferior will stop as a result of this signal, then the act of handling
1890 the stop ought to print a message that's couches the stoppage in user
1891 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1892 won't stop as a result of the signal -- i.e., if the signal is merely
1893 a side-effect of something GDB's doing "under the covers" for the
1894 user, such as stepping threads over a breakpoint they shouldn't stop
1895 for -- then the message seems to be a serious annoyance at best.
1897 For now, remove the message altogether. */
1900 target_terminal_ours_for_output ();
1901 printf_filtered ("\nProgram received signal %s, %s.\n",
1902 target_signal_to_name (stop_signal),
1903 target_signal_to_string (stop_signal));
1904 gdb_flush (gdb_stdout);
1908 /* If it's not SIGTRAP and not a signal we want to stop for, then
1909 continue the thread. */
1911 if (stop_signal != TARGET_SIGNAL_TRAP
1912 && !signal_stop[stop_signal])
1915 target_terminal_inferior ();
1917 /* Clear the signal if it should not be passed. */
1918 if (signal_program[stop_signal] == 0)
1919 stop_signal = TARGET_SIGNAL_0;
1921 target_resume (ecs->pid, 0, stop_signal);
1922 prepare_to_wait (ecs);
1926 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1927 and fall into the rest of wait_for_inferior(). */
1929 /* Save infrun state for the old thread. */
1930 save_infrun_state (inferior_pid, prev_pc,
1931 prev_func_start, prev_func_name,
1932 trap_expected, step_resume_breakpoint,
1933 through_sigtramp_breakpoint,
1934 step_range_start, step_range_end,
1935 step_frame_address, ecs->handling_longjmp,
1937 ecs->stepping_through_solib_after_catch,
1938 ecs->stepping_through_solib_catchpoints,
1939 ecs->stepping_through_sigtramp);
1941 if (may_switch_from_inferior_pid)
1942 switched_from_inferior_pid = inferior_pid;
1944 inferior_pid = ecs->pid;
1946 /* Load infrun state for the new thread. */
1947 load_infrun_state (inferior_pid, &prev_pc,
1948 &prev_func_start, &prev_func_name,
1949 &trap_expected, &step_resume_breakpoint,
1950 &through_sigtramp_breakpoint,
1951 &step_range_start, &step_range_end,
1952 &step_frame_address, &ecs->handling_longjmp,
1954 &ecs->stepping_through_solib_after_catch,
1955 &ecs->stepping_through_solib_catchpoints,
1956 &ecs->stepping_through_sigtramp);
1959 context_hook (pid_to_thread_id (ecs->pid));
1961 printf_filtered ("[Switching to %s]\n", target_pid_to_str (ecs->pid));
1962 flush_cached_frames ();
1965 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1967 /* Pull the single step breakpoints out of the target. */
1968 SOFTWARE_SINGLE_STEP (0, 0);
1969 singlestep_breakpoints_inserted_p = 0;
1972 /* If PC is pointing at a nullified instruction, then step beyond
1973 it so that the user won't be confused when GDB appears to be ready
1976 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1977 if (INSTRUCTION_NULLIFIED)
1979 registers_changed ();
1980 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1982 /* We may have received a signal that we want to pass to
1983 the inferior; therefore, we must not clobber the waitstatus
1986 ecs->infwait_state = infwait_nullified_state;
1987 ecs->waiton_pid = ecs->pid;
1988 ecs->wp = &(ecs->tmpstatus);
1989 prepare_to_wait (ecs);
1993 /* It may not be necessary to disable the watchpoint to stop over
1994 it. For example, the PA can (with some kernel cooperation)
1995 single step over a watchpoint without disabling the watchpoint. */
1996 if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1999 prepare_to_wait (ecs);
2003 /* It is far more common to need to disable a watchpoint to step
2004 the inferior over it. FIXME. What else might a debug
2005 register or page protection watchpoint scheme need here? */
2006 if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
2008 /* At this point, we are stopped at an instruction which has
2009 attempted to write to a piece of memory under control of
2010 a watchpoint. The instruction hasn't actually executed
2011 yet. If we were to evaluate the watchpoint expression
2012 now, we would get the old value, and therefore no change
2013 would seem to have occurred.
2015 In order to make watchpoints work `right', we really need
2016 to complete the memory write, and then evaluate the
2017 watchpoint expression. The following code does that by
2018 removing the watchpoint (actually, all watchpoints and
2019 breakpoints), single-stepping the target, re-inserting
2020 watchpoints, and then falling through to let normal
2021 single-step processing handle proceed. Since this
2022 includes evaluating watchpoints, things will come to a
2023 stop in the correct manner. */
2025 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
2027 remove_breakpoints ();
2028 registers_changed ();
2029 target_resume (ecs->pid, 1, TARGET_SIGNAL_0); /* Single step */
2031 ecs->waiton_pid = ecs->pid;
2032 ecs->wp = &(ecs->ws);
2033 ecs->infwait_state = infwait_nonstep_watch_state;
2034 prepare_to_wait (ecs);
2038 /* It may be possible to simply continue after a watchpoint. */
2039 if (HAVE_CONTINUABLE_WATCHPOINT)
2040 STOPPED_BY_WATCHPOINT (ecs->ws);
2042 ecs->stop_func_start = 0;
2043 ecs->stop_func_end = 0;
2044 ecs->stop_func_name = 0;
2045 /* Don't care about return value; stop_func_start and stop_func_name
2046 will both be 0 if it doesn't work. */
2047 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2048 &ecs->stop_func_start, &ecs->stop_func_end);
2049 ecs->stop_func_start += FUNCTION_START_OFFSET;
2050 ecs->another_trap = 0;
2051 bpstat_clear (&stop_bpstat);
2053 stop_stack_dummy = 0;
2054 stop_print_frame = 1;
2055 ecs->random_signal = 0;
2056 stopped_by_random_signal = 0;
2057 breakpoints_failed = 0;
2059 /* Look at the cause of the stop, and decide what to do.
2060 The alternatives are:
2061 1) break; to really stop and return to the debugger,
2062 2) drop through to start up again
2063 (set ecs->another_trap to 1 to single step once)
2064 3) set ecs->random_signal to 1, and the decision between 1 and 2
2065 will be made according to the signal handling tables. */
2067 /* First, distinguish signals caused by the debugger from signals
2068 that have to do with the program's own actions.
2069 Note that breakpoint insns may cause SIGTRAP or SIGILL
2070 or SIGEMT, depending on the operating system version.
2071 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2072 and change it to SIGTRAP. */
2074 if (stop_signal == TARGET_SIGNAL_TRAP
2075 || (breakpoints_inserted &&
2076 (stop_signal == TARGET_SIGNAL_ILL
2077 || stop_signal == TARGET_SIGNAL_EMT
2079 || stop_soon_quietly)
2081 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
2083 stop_print_frame = 0;
2084 stop_stepping (ecs);
2087 if (stop_soon_quietly)
2089 stop_stepping (ecs);
2093 /* Don't even think about breakpoints
2094 if just proceeded over a breakpoint.
2096 However, if we are trying to proceed over a breakpoint
2097 and end up in sigtramp, then through_sigtramp_breakpoint
2098 will be set and we should check whether we've hit the
2100 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
2101 && through_sigtramp_breakpoint == NULL)
2102 bpstat_clear (&stop_bpstat);
2105 /* See if there is a breakpoint at the current PC. */
2106 stop_bpstat = bpstat_stop_status
2108 (DECR_PC_AFTER_BREAK ?
2109 /* Notice the case of stepping through a jump
2110 that lands just after a breakpoint.
2111 Don't confuse that with hitting the breakpoint.
2112 What we check for is that 1) stepping is going on
2113 and 2) the pc before the last insn does not match
2114 the address of the breakpoint before the current pc
2115 and 3) we didn't hit a breakpoint in a signal handler
2116 without an intervening stop in sigtramp, which is
2117 detected by a new stack pointer value below
2118 any usual function calling stack adjustments. */
2119 (currently_stepping (ecs)
2120 && prev_pc != stop_pc - DECR_PC_AFTER_BREAK
2122 && INNER_THAN (read_sp (), (step_sp - 16)))) :
2125 /* Following in case break condition called a
2127 stop_print_frame = 1;
2130 if (stop_signal == TARGET_SIGNAL_TRAP)
2132 = !(bpstat_explains_signal (stop_bpstat)
2134 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2135 && PC_IN_CALL_DUMMY (stop_pc, read_sp (),
2136 FRAME_FP (get_current_frame ())))
2137 || (step_range_end && step_resume_breakpoint == NULL));
2142 = !(bpstat_explains_signal (stop_bpstat)
2143 /* End of a stack dummy. Some systems (e.g. Sony
2144 news) give another signal besides SIGTRAP, so
2145 check here as well as above. */
2146 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2147 && PC_IN_CALL_DUMMY (stop_pc, read_sp (),
2148 FRAME_FP (get_current_frame ())))
2150 if (!ecs->random_signal)
2151 stop_signal = TARGET_SIGNAL_TRAP;
2155 /* When we reach this point, we've pretty much decided
2156 that the reason for stopping must've been a random
2157 (unexpected) signal. */
2160 ecs->random_signal = 1;
2161 /* If a fork, vfork or exec event was seen, then there are two
2162 possible responses we can make:
2164 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2165 then we must stop now and issue a prompt. We will resume
2166 the inferior when the user tells us to.
2167 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2168 then we must resume the inferior now and keep checking.
2170 In either case, we must take appropriate steps to "follow" the
2171 the fork/vfork/exec when the inferior is resumed. For example,
2172 if follow-fork-mode is "child", then we must detach from the
2173 parent inferior and follow the new child inferior.
2175 In either case, setting pending_follow causes the next resume()
2176 to take the appropriate following action. */
2177 process_event_stop_test:
2178 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
2180 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2183 stop_signal = TARGET_SIGNAL_0;
2188 else if (ecs->ws.kind == TARGET_WAITKIND_VFORKED)
2190 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2192 stop_signal = TARGET_SIGNAL_0;
2197 else if (ecs->ws.kind == TARGET_WAITKIND_EXECD)
2199 pending_follow.kind = ecs->ws.kind;
2200 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2203 stop_signal = TARGET_SIGNAL_0;
2209 /* For the program's own signals, act according to
2210 the signal handling tables. */
2212 if (ecs->random_signal)
2214 /* Signal not for debugging purposes. */
2217 stopped_by_random_signal = 1;
2219 if (signal_print[stop_signal])
2222 target_terminal_ours_for_output ();
2224 printf_filtered ("\nProgram received signal ");
2225 annotate_signal_name ();
2226 printf_filtered ("%s", target_signal_to_name (stop_signal));
2227 annotate_signal_name_end ();
2228 printf_filtered (", ");
2229 annotate_signal_string ();
2230 printf_filtered ("%s", target_signal_to_string (stop_signal));
2231 annotate_signal_string_end ();
2232 printf_filtered (".\n");
2233 gdb_flush (gdb_stdout);
2235 if (signal_stop[stop_signal])
2237 stop_stepping (ecs);
2240 /* If not going to stop, give terminal back
2241 if we took it away. */
2243 target_terminal_inferior ();
2245 /* Clear the signal if it should not be passed. */
2246 if (signal_program[stop_signal] == 0)
2247 stop_signal = TARGET_SIGNAL_0;
2249 /* I'm not sure whether this needs to be check_sigtramp2 or
2250 whether it could/should be keep_going.
2252 This used to jump to step_over_function if we are stepping,
2255 Suppose the user does a `next' over a function call, and while
2256 that call is in progress, the inferior receives a signal for
2257 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2258 that case, when we reach this point, there is already a
2259 step-resume breakpoint established, right where it should be:
2260 immediately after the function call the user is "next"-ing
2261 over. If we call step_over_function now, two bad things
2264 - we'll create a new breakpoint, at wherever the current
2265 frame's return address happens to be. That could be
2266 anywhere, depending on what function call happens to be on
2267 the top of the stack at that point. Point is, it's probably
2268 not where we need it.
2270 - the existing step-resume breakpoint (which is at the correct
2271 address) will get orphaned: step_resume_breakpoint will point
2272 to the new breakpoint, and the old step-resume breakpoint
2273 will never be cleaned up.
2275 The old behavior was meant to help HP-UX single-step out of
2276 sigtramps. It would place the new breakpoint at prev_pc, which
2277 was certainly wrong. I don't know the details there, so fixing
2278 this probably breaks that. As with anything else, it's up to
2279 the HP-UX maintainer to furnish a fix that doesn't break other
2280 platforms. --JimB, 20 May 1999 */
2281 check_sigtramp2 (ecs);
2284 /* Handle cases caused by hitting a breakpoint. */
2286 CORE_ADDR jmp_buf_pc;
2287 struct bpstat_what what;
2289 what = bpstat_what (stop_bpstat);
2291 if (what.call_dummy)
2293 stop_stack_dummy = 1;
2295 trap_expected_after_continue = 1;
2299 switch (what.main_action)
2301 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
2302 /* If we hit the breakpoint at longjmp, disable it for the
2303 duration of this command. Then, install a temporary
2304 breakpoint at the target of the jmp_buf. */
2305 disable_longjmp_breakpoint ();
2306 remove_breakpoints ();
2307 breakpoints_inserted = 0;
2308 if (!GET_LONGJMP_TARGET (&jmp_buf_pc))
2314 /* Need to blow away step-resume breakpoint, as it
2315 interferes with us */
2316 if (step_resume_breakpoint != NULL)
2318 delete_breakpoint (step_resume_breakpoint);
2319 step_resume_breakpoint = NULL;
2321 /* Not sure whether we need to blow this away too, but probably
2322 it is like the step-resume breakpoint. */
2323 if (through_sigtramp_breakpoint != NULL)
2325 delete_breakpoint (through_sigtramp_breakpoint);
2326 through_sigtramp_breakpoint = NULL;
2330 /* FIXME - Need to implement nested temporary breakpoints */
2331 if (step_over_calls > 0)
2332 set_longjmp_resume_breakpoint (jmp_buf_pc,
2333 get_current_frame ());
2336 set_longjmp_resume_breakpoint (jmp_buf_pc, NULL);
2337 ecs->handling_longjmp = 1; /* FIXME */
2341 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
2342 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
2343 remove_breakpoints ();
2344 breakpoints_inserted = 0;
2346 /* FIXME - Need to implement nested temporary breakpoints */
2348 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2349 step_frame_address)))
2351 ecs->another_trap = 1;
2356 disable_longjmp_breakpoint ();
2357 ecs->handling_longjmp = 0; /* FIXME */
2358 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
2360 /* else fallthrough */
2362 case BPSTAT_WHAT_SINGLE:
2363 if (breakpoints_inserted)
2365 thread_step_needed = 1;
2366 remove_breakpoints ();
2368 breakpoints_inserted = 0;
2369 ecs->another_trap = 1;
2370 /* Still need to check other stuff, at least the case
2371 where we are stepping and step out of the right range. */
2374 case BPSTAT_WHAT_STOP_NOISY:
2375 stop_print_frame = 1;
2377 /* We are about to nuke the step_resume_breakpoint and
2378 through_sigtramp_breakpoint via the cleanup chain, so
2379 no need to worry about it here. */
2381 stop_stepping (ecs);
2384 case BPSTAT_WHAT_STOP_SILENT:
2385 stop_print_frame = 0;
2387 /* We are about to nuke the step_resume_breakpoint and
2388 through_sigtramp_breakpoint via the cleanup chain, so
2389 no need to worry about it here. */
2391 stop_stepping (ecs);
2394 case BPSTAT_WHAT_STEP_RESUME:
2395 /* This proably demands a more elegant solution, but, yeah
2398 This function's use of the simple variable
2399 step_resume_breakpoint doesn't seem to accomodate
2400 simultaneously active step-resume bp's, although the
2401 breakpoint list certainly can.
2403 If we reach here and step_resume_breakpoint is already
2404 NULL, then apparently we have multiple active
2405 step-resume bp's. We'll just delete the breakpoint we
2406 stopped at, and carry on.
2408 Correction: what the code currently does is delete a
2409 step-resume bp, but it makes no effort to ensure that
2410 the one deleted is the one currently stopped at. MVS */
2412 if (step_resume_breakpoint == NULL)
2414 step_resume_breakpoint =
2415 bpstat_find_step_resume_breakpoint (stop_bpstat);
2417 delete_breakpoint (step_resume_breakpoint);
2418 step_resume_breakpoint = NULL;
2421 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2422 if (through_sigtramp_breakpoint)
2423 delete_breakpoint (through_sigtramp_breakpoint);
2424 through_sigtramp_breakpoint = NULL;
2426 /* If were waiting for a trap, hitting the step_resume_break
2427 doesn't count as getting it. */
2429 ecs->another_trap = 1;
2432 case BPSTAT_WHAT_CHECK_SHLIBS:
2433 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2436 /* Remove breakpoints, we eventually want to step over the
2437 shlib event breakpoint, and SOLIB_ADD might adjust
2438 breakpoint addresses via breakpoint_re_set. */
2439 if (breakpoints_inserted)
2440 remove_breakpoints ();
2441 breakpoints_inserted = 0;
2443 /* Check for any newly added shared libraries if we're
2444 supposed to be adding them automatically. */
2447 /* Switch terminal for any messages produced by
2448 breakpoint_re_set. */
2449 target_terminal_ours_for_output ();
2450 SOLIB_ADD (NULL, 0, NULL);
2451 target_terminal_inferior ();
2454 /* Try to reenable shared library breakpoints, additional
2455 code segments in shared libraries might be mapped in now. */
2456 re_enable_breakpoints_in_shlibs ();
2458 /* If requested, stop when the dynamic linker notifies
2459 gdb of events. This allows the user to get control
2460 and place breakpoints in initializer routines for
2461 dynamically loaded objects (among other things). */
2462 if (stop_on_solib_events)
2464 stop_print_frame = 0;
2465 stop_stepping (ecs);
2469 /* If we stopped due to an explicit catchpoint, then the
2470 (see above) call to SOLIB_ADD pulled in any symbols
2471 from a newly-loaded library, if appropriate.
2473 We do want the inferior to stop, but not where it is
2474 now, which is in the dynamic linker callback. Rather,
2475 we would like it stop in the user's program, just after
2476 the call that caused this catchpoint to trigger. That
2477 gives the user a more useful vantage from which to
2478 examine their program's state. */
2479 else if (what.main_action == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2481 /* ??rehrauer: If I could figure out how to get the
2482 right return PC from here, we could just set a temp
2483 breakpoint and resume. I'm not sure we can without
2484 cracking open the dld's shared libraries and sniffing
2485 their unwind tables and text/data ranges, and that's
2486 not a terribly portable notion.
2488 Until that time, we must step the inferior out of the
2489 dld callback, and also out of the dld itself (and any
2490 code or stubs in libdld.sl, such as "shl_load" and
2491 friends) until we reach non-dld code. At that point,
2492 we can stop stepping. */
2493 bpstat_get_triggered_catchpoints (stop_bpstat,
2494 &ecs->stepping_through_solib_catchpoints);
2495 ecs->stepping_through_solib_after_catch = 1;
2497 /* Be sure to lift all breakpoints, so the inferior does
2498 actually step past this point... */
2499 ecs->another_trap = 1;
2504 /* We want to step over this breakpoint, then keep going. */
2505 ecs->another_trap = 1;
2512 case BPSTAT_WHAT_LAST:
2513 /* Not a real code, but listed here to shut up gcc -Wall. */
2515 case BPSTAT_WHAT_KEEP_CHECKING:
2520 /* We come here if we hit a breakpoint but should not
2521 stop for it. Possibly we also were stepping
2522 and should stop for that. So fall through and
2523 test for stepping. But, if not stepping,
2526 /* Are we stepping to get the inferior out of the dynamic
2527 linker's hook (and possibly the dld itself) after catching
2529 if (ecs->stepping_through_solib_after_catch)
2531 #if defined(SOLIB_ADD)
2532 /* Have we reached our destination? If not, keep going. */
2533 if (SOLIB_IN_DYNAMIC_LINKER (ecs->pid, stop_pc))
2535 ecs->another_trap = 1;
2540 /* Else, stop and report the catchpoint(s) whose triggering
2541 caused us to begin stepping. */
2542 ecs->stepping_through_solib_after_catch = 0;
2543 bpstat_clear (&stop_bpstat);
2544 stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints);
2545 bpstat_clear (&ecs->stepping_through_solib_catchpoints);
2546 stop_print_frame = 1;
2547 stop_stepping (ecs);
2551 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P)
2553 /* This is the old way of detecting the end of the stack dummy.
2554 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2555 handled above. As soon as we can test it on all of them, all
2556 architectures should define it. */
2558 /* If this is the breakpoint at the end of a stack dummy,
2559 just stop silently, unless the user was doing an si/ni, in which
2560 case she'd better know what she's doing. */
2562 if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (),
2563 FRAME_FP (get_current_frame ()))
2566 stop_print_frame = 0;
2567 stop_stack_dummy = 1;
2569 trap_expected_after_continue = 1;
2571 stop_stepping (ecs);
2576 if (step_resume_breakpoint)
2578 /* Having a step-resume breakpoint overrides anything
2579 else having to do with stepping commands until
2580 that breakpoint is reached. */
2581 /* I'm not sure whether this needs to be check_sigtramp2 or
2582 whether it could/should be keep_going. */
2583 check_sigtramp2 (ecs);
2588 if (step_range_end == 0)
2590 /* Likewise if we aren't even stepping. */
2591 /* I'm not sure whether this needs to be check_sigtramp2 or
2592 whether it could/should be keep_going. */
2593 check_sigtramp2 (ecs);
2598 /* If stepping through a line, keep going if still within it.
2600 Note that step_range_end is the address of the first instruction
2601 beyond the step range, and NOT the address of the last instruction
2603 if (stop_pc >= step_range_start
2604 && stop_pc < step_range_end)
2606 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2607 So definately need to check for sigtramp here. */
2608 check_sigtramp2 (ecs);
2613 /* We stepped out of the stepping range. */
2615 /* If we are stepping at the source level and entered the runtime
2616 loader dynamic symbol resolution code, we keep on single stepping
2617 until we exit the run time loader code and reach the callee's
2619 if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2621 CORE_ADDR pc_after_resolver = SKIP_SOLIB_RESOLVER (stop_pc);
2623 if (pc_after_resolver)
2625 /* Set up a step-resume breakpoint at the address
2626 indicated by SKIP_SOLIB_RESOLVER. */
2627 struct symtab_and_line sr_sal;
2629 sr_sal.pc = pc_after_resolver;
2631 check_for_old_step_resume_breakpoint ();
2632 step_resume_breakpoint =
2633 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2634 if (breakpoints_inserted)
2635 insert_breakpoints ();
2642 /* We can't update step_sp every time through the loop, because
2643 reading the stack pointer would slow down stepping too much.
2644 But we can update it every time we leave the step range. */
2645 ecs->update_step_sp = 1;
2647 /* Did we just take a signal? */
2648 if (IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2649 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2650 && INNER_THAN (read_sp (), step_sp))
2652 /* We've just taken a signal; go until we are back to
2653 the point where we took it and one more. */
2655 /* Note: The test above succeeds not only when we stepped
2656 into a signal handler, but also when we step past the last
2657 statement of a signal handler and end up in the return stub
2658 of the signal handler trampoline. To distinguish between
2659 these two cases, check that the frame is INNER_THAN the
2660 previous one below. pai/1997-09-11 */
2664 CORE_ADDR current_frame = FRAME_FP (get_current_frame ());
2666 if (INNER_THAN (current_frame, step_frame_address))
2668 /* We have just taken a signal; go until we are back to
2669 the point where we took it and one more. */
2671 /* This code is needed at least in the following case:
2672 The user types "next" and then a signal arrives (before
2673 the "next" is done). */
2675 /* Note that if we are stopped at a breakpoint, then we need
2676 the step_resume breakpoint to override any breakpoints at
2677 the same location, so that we will still step over the
2678 breakpoint even though the signal happened. */
2679 struct symtab_and_line sr_sal;
2682 sr_sal.symtab = NULL;
2684 sr_sal.pc = prev_pc;
2685 /* We could probably be setting the frame to
2686 step_frame_address; I don't think anyone thought to
2688 check_for_old_step_resume_breakpoint ();
2689 step_resume_breakpoint =
2690 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2691 if (breakpoints_inserted)
2692 insert_breakpoints ();
2696 /* We just stepped out of a signal handler and into
2697 its calling trampoline.
2699 Normally, we'd call step_over_function from
2700 here, but for some reason GDB can't unwind the
2701 stack correctly to find the real PC for the point
2702 user code where the signal trampoline will return
2703 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2704 But signal trampolines are pretty small stubs of
2705 code, anyway, so it's OK instead to just
2706 single-step out. Note: assuming such trampolines
2707 don't exhibit recursion on any platform... */
2708 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2709 &ecs->stop_func_start,
2710 &ecs->stop_func_end);
2711 /* Readjust stepping range */
2712 step_range_start = ecs->stop_func_start;
2713 step_range_end = ecs->stop_func_end;
2714 ecs->stepping_through_sigtramp = 1;
2719 /* If this is stepi or nexti, make sure that the stepping range
2720 gets us past that instruction. */
2721 if (step_range_end == 1)
2722 /* FIXME: Does this run afoul of the code below which, if
2723 we step into the middle of a line, resets the stepping
2725 step_range_end = (step_range_start = prev_pc) + 1;
2727 ecs->remove_breakpoints_on_following_step = 1;
2732 if (stop_pc == ecs->stop_func_start /* Quick test */
2733 || (in_prologue (stop_pc, ecs->stop_func_start) &&
2734 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2735 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name)
2736 || ecs->stop_func_name == 0)
2738 /* It's a subroutine call. */
2740 if (step_over_calls == 0)
2742 /* I presume that step_over_calls is only 0 when we're
2743 supposed to be stepping at the assembly language level
2744 ("stepi"). Just stop. */
2746 stop_stepping (ecs);
2750 if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc))
2752 /* We're doing a "next". */
2753 step_over_function (ecs);
2758 /* If we are in a function call trampoline (a stub between
2759 the calling routine and the real function), locate the real
2760 function. That's what tells us (a) whether we want to step
2761 into it at all, and (b) what prologue we want to run to
2762 the end of, if we do step into it. */
2763 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2765 ecs->stop_func_start = tmp;
2768 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
2771 struct symtab_and_line xxx;
2772 /* Why isn't this s_a_l called "sr_sal", like all of the
2773 other s_a_l's where this code is duplicated? */
2774 INIT_SAL (&xxx); /* initialize to zeroes */
2776 xxx.section = find_pc_overlay (xxx.pc);
2777 check_for_old_step_resume_breakpoint ();
2778 step_resume_breakpoint =
2779 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
2780 insert_breakpoints ();
2786 /* If we have line number information for the function we
2787 are thinking of stepping into, step into it.
2789 If there are several symtabs at that PC (e.g. with include
2790 files), just want to know whether *any* of them have line
2791 numbers. find_pc_line handles this. */
2793 struct symtab_and_line tmp_sal;
2795 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
2796 if (tmp_sal.line != 0)
2798 step_into_function (ecs);
2802 step_over_function (ecs);
2808 /* We've wandered out of the step range. */
2810 ecs->sal = find_pc_line (stop_pc, 0);
2812 if (step_range_end == 1)
2814 /* It is stepi or nexti. We always want to stop stepping after
2817 stop_stepping (ecs);
2821 /* If we're in the return path from a shared library trampoline,
2822 we want to proceed through the trampoline when stepping. */
2823 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2827 /* Determine where this trampoline returns. */
2828 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2830 /* Only proceed through if we know where it's going. */
2833 /* And put the step-breakpoint there and go until there. */
2834 struct symtab_and_line sr_sal;
2836 INIT_SAL (&sr_sal); /* initialize to zeroes */
2838 sr_sal.section = find_pc_overlay (sr_sal.pc);
2839 /* Do not specify what the fp should be when we stop
2840 since on some machines the prologue
2841 is where the new fp value is established. */
2842 check_for_old_step_resume_breakpoint ();
2843 step_resume_breakpoint =
2844 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2845 if (breakpoints_inserted)
2846 insert_breakpoints ();
2848 /* Restart without fiddling with the step ranges or
2855 if (ecs->sal.line == 0)
2857 /* We have no line number information. That means to stop
2858 stepping (does this always happen right after one instruction,
2859 when we do "s" in a function with no line numbers,
2860 or can this happen as a result of a return or longjmp?). */
2862 stop_stepping (ecs);
2866 if ((stop_pc == ecs->sal.pc)
2867 && (ecs->current_line != ecs->sal.line || ecs->current_symtab != ecs->sal.symtab))
2869 /* We are at the start of a different line. So stop. Note that
2870 we don't stop if we step into the middle of a different line.
2871 That is said to make things like for (;;) statements work
2874 stop_stepping (ecs);
2878 /* We aren't done stepping.
2880 Optimize by setting the stepping range to the line.
2881 (We might not be in the original line, but if we entered a
2882 new line in mid-statement, we continue stepping. This makes
2883 things like for(;;) statements work better.) */
2885 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
2887 /* If this is the last line of the function, don't keep stepping
2888 (it would probably step us out of the function).
2889 This is particularly necessary for a one-line function,
2890 in which after skipping the prologue we better stop even though
2891 we will be in mid-line. */
2893 stop_stepping (ecs);
2896 step_range_start = ecs->sal.pc;
2897 step_range_end = ecs->sal.end;
2898 step_frame_address = FRAME_FP (get_current_frame ());
2899 ecs->current_line = ecs->sal.line;
2900 ecs->current_symtab = ecs->sal.symtab;
2902 /* In the case where we just stepped out of a function into the middle
2903 of a line of the caller, continue stepping, but step_frame_address
2904 must be modified to current frame */
2906 CORE_ADDR current_frame = FRAME_FP (get_current_frame ());
2907 if (!(INNER_THAN (current_frame, step_frame_address)))
2908 step_frame_address = current_frame;
2913 } /* extra brace, to preserve old indentation */
2916 /* Are we in the middle of stepping? */
2919 currently_stepping (struct execution_control_state *ecs)
2921 return ((through_sigtramp_breakpoint == NULL
2922 && !ecs->handling_longjmp
2923 && ((step_range_end && step_resume_breakpoint == NULL)
2925 || ecs->stepping_through_solib_after_catch
2926 || bpstat_should_step ());
2930 check_sigtramp2 (struct execution_control_state *ecs)
2933 && IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2934 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2935 && INNER_THAN (read_sp (), step_sp))
2937 /* What has happened here is that we have just stepped the
2938 inferior with a signal (because it is a signal which
2939 shouldn't make us stop), thus stepping into sigtramp.
2941 So we need to set a step_resume_break_address breakpoint and
2942 continue until we hit it, and then step. FIXME: This should
2943 be more enduring than a step_resume breakpoint; we should
2944 know that we will later need to keep going rather than
2945 re-hitting the breakpoint here (see the testsuite,
2946 gdb.base/signals.exp where it says "exceedingly difficult"). */
2948 struct symtab_and_line sr_sal;
2950 INIT_SAL (&sr_sal); /* initialize to zeroes */
2951 sr_sal.pc = prev_pc;
2952 sr_sal.section = find_pc_overlay (sr_sal.pc);
2953 /* We perhaps could set the frame if we kept track of what the
2954 frame corresponding to prev_pc was. But we don't, so don't. */
2955 through_sigtramp_breakpoint =
2956 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
2957 if (breakpoints_inserted)
2958 insert_breakpoints ();
2960 ecs->remove_breakpoints_on_following_step = 1;
2961 ecs->another_trap = 1;
2965 /* Subroutine call with source code we should not step over. Do step
2966 to the first line of code in it. */
2969 step_into_function (struct execution_control_state *ecs)
2972 struct symtab_and_line sr_sal;
2974 s = find_pc_symtab (stop_pc);
2975 if (s && s->language != language_asm)
2976 ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start);
2978 ecs->sal = find_pc_line (ecs->stop_func_start, 0);
2979 /* Use the step_resume_break to step until the end of the prologue,
2980 even if that involves jumps (as it seems to on the vax under
2982 /* If the prologue ends in the middle of a source line, continue to
2983 the end of that source line (if it is still within the function).
2984 Otherwise, just go to end of prologue. */
2985 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2986 /* no, don't either. It skips any code that's legitimately on the
2990 && ecs->sal.pc != ecs->stop_func_start
2991 && ecs->sal.end < ecs->stop_func_end)
2992 ecs->stop_func_start = ecs->sal.end;
2995 if (ecs->stop_func_start == stop_pc)
2997 /* We are already there: stop now. */
2999 stop_stepping (ecs);
3004 /* Put the step-breakpoint there and go until there. */
3005 INIT_SAL (&sr_sal); /* initialize to zeroes */
3006 sr_sal.pc = ecs->stop_func_start;
3007 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
3008 /* Do not specify what the fp should be when we stop since on
3009 some machines the prologue is where the new fp value is
3011 check_for_old_step_resume_breakpoint ();
3012 step_resume_breakpoint =
3013 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
3014 if (breakpoints_inserted)
3015 insert_breakpoints ();
3017 /* And make sure stepping stops right away then. */
3018 step_range_end = step_range_start;
3023 /* We've just entered a callee, and we wish to resume until it returns
3024 to the caller. Setting a step_resume breakpoint on the return
3025 address will catch a return from the callee.
3027 However, if the callee is recursing, we want to be careful not to
3028 catch returns of those recursive calls, but only of THIS instance
3031 To do this, we set the step_resume bp's frame to our current
3032 caller's frame (step_frame_address, which is set by the "next" or
3033 "until" command, before execution begins). */
3036 step_over_function (struct execution_control_state *ecs)
3038 struct symtab_and_line sr_sal;
3040 INIT_SAL (&sr_sal); /* initialize to zeros */
3041 sr_sal.pc = ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3042 sr_sal.section = find_pc_overlay (sr_sal.pc);
3044 check_for_old_step_resume_breakpoint ();
3045 step_resume_breakpoint =
3046 set_momentary_breakpoint (sr_sal, get_current_frame (), bp_step_resume);
3048 if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
3049 step_resume_breakpoint->frame = step_frame_address;
3051 if (breakpoints_inserted)
3052 insert_breakpoints ();
3056 stop_stepping (struct execution_control_state *ecs)
3058 if (target_has_execution)
3060 /* Are we stopping for a vfork event? We only stop when we see
3061 the child's event. However, we may not yet have seen the
3062 parent's event. And, inferior_pid is still set to the
3063 parent's pid, until we resume again and follow either the
3066 To ensure that we can really touch inferior_pid (aka, the
3067 parent process) -- which calls to functions like read_pc
3068 implicitly do -- wait on the parent if necessary. */
3069 if ((pending_follow.kind == TARGET_WAITKIND_VFORKED)
3070 && !pending_follow.fork_event.saw_parent_fork)
3076 if (target_wait_hook)
3077 parent_pid = target_wait_hook (-1, &(ecs->ws));
3079 parent_pid = target_wait (-1, &(ecs->ws));
3081 while (parent_pid != inferior_pid);
3084 /* Assuming the inferior still exists, set these up for next
3085 time, just like we did above if we didn't break out of the
3087 prev_pc = read_pc ();
3088 prev_func_start = ecs->stop_func_start;
3089 prev_func_name = ecs->stop_func_name;
3092 /* Let callers know we don't want to wait for the inferior anymore. */
3093 ecs->wait_some_more = 0;
3096 /* This function handles various cases where we need to continue
3097 waiting for the inferior. */
3098 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3101 keep_going (struct execution_control_state *ecs)
3103 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3104 vforked child between its creation and subsequent exit or call to
3105 exec(). However, I had big problems in this rather creaky exec
3106 engine, getting that to work. The fundamental problem is that
3107 I'm trying to debug two processes via an engine that only
3108 understands a single process with possibly multiple threads.
3110 Hence, this spot is known to have problems when
3111 target_can_follow_vfork_prior_to_exec returns 1. */
3113 /* Save the pc before execution, to compare with pc after stop. */
3114 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
3115 prev_func_start = ecs->stop_func_start; /* Ok, since if DECR_PC_AFTER
3116 BREAK is defined, the
3117 original pc would not have
3118 been at the start of a
3120 prev_func_name = ecs->stop_func_name;
3122 if (ecs->update_step_sp)
3123 step_sp = read_sp ();
3124 ecs->update_step_sp = 0;
3126 /* If we did not do break;, it means we should keep running the
3127 inferior and not return to debugger. */
3129 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
3131 /* We took a signal (which we are supposed to pass through to
3132 the inferior, else we'd have done a break above) and we
3133 haven't yet gotten our trap. Simply continue. */
3134 resume (currently_stepping (ecs), stop_signal);
3138 /* Either the trap was not expected, but we are continuing
3139 anyway (the user asked that this signal be passed to the
3142 The signal was SIGTRAP, e.g. it was our signal, but we
3143 decided we should resume from it.
3145 We're going to run this baby now!
3147 Insert breakpoints now, unless we are trying to one-proceed
3148 past a breakpoint. */
3149 /* If we've just finished a special step resume and we don't
3150 want to hit a breakpoint, pull em out. */
3151 if (step_resume_breakpoint == NULL
3152 && through_sigtramp_breakpoint == NULL
3153 && ecs->remove_breakpoints_on_following_step)
3155 ecs->remove_breakpoints_on_following_step = 0;
3156 remove_breakpoints ();
3157 breakpoints_inserted = 0;
3159 else if (!breakpoints_inserted &&
3160 (through_sigtramp_breakpoint != NULL || !ecs->another_trap))
3162 breakpoints_failed = insert_breakpoints ();
3163 if (breakpoints_failed)
3165 stop_stepping (ecs);
3168 breakpoints_inserted = 1;
3171 trap_expected = ecs->another_trap;
3173 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3174 specifies that such a signal should be delivered to the
3177 Typically, this would occure when a user is debugging a
3178 target monitor on a simulator: the target monitor sets a
3179 breakpoint; the simulator encounters this break-point and
3180 halts the simulation handing control to GDB; GDB, noteing
3181 that the break-point isn't valid, returns control back to the
3182 simulator; the simulator then delivers the hardware
3183 equivalent of a SIGNAL_TRAP to the program being debugged. */
3185 if (stop_signal == TARGET_SIGNAL_TRAP
3186 && !signal_program[stop_signal])
3187 stop_signal = TARGET_SIGNAL_0;
3189 #ifdef SHIFT_INST_REGS
3190 /* I'm not sure when this following segment applies. I do know,
3191 now, that we shouldn't rewrite the regs when we were stopped
3192 by a random signal from the inferior process. */
3193 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3194 (this is only used on the 88k). */
3196 if (!bpstat_explains_signal (stop_bpstat)
3197 && (stop_signal != TARGET_SIGNAL_CHLD)
3198 && !stopped_by_random_signal)
3200 #endif /* SHIFT_INST_REGS */
3202 resume (currently_stepping (ecs), stop_signal);
3205 prepare_to_wait (ecs);
3208 /* This function normally comes after a resume, before
3209 handle_inferior_event exits. It takes care of any last bits of
3210 housekeeping, and sets the all-important wait_some_more flag. */
3213 prepare_to_wait (struct execution_control_state *ecs)
3215 if (ecs->infwait_state == infwait_normal_state)
3217 overlay_cache_invalid = 1;
3219 /* We have to invalidate the registers BEFORE calling
3220 target_wait because they can be loaded from the target while
3221 in target_wait. This makes remote debugging a bit more
3222 efficient for those targets that provide critical registers
3223 as part of their normal status mechanism. */
3225 registers_changed ();
3226 ecs->waiton_pid = -1;
3227 ecs->wp = &(ecs->ws);
3229 /* This is the old end of the while loop. Let everybody know we
3230 want to wait for the inferior some more and get called again
3232 ecs->wait_some_more = 1;
3235 /* This function returns TRUE if ep is an internal breakpoint
3236 set to catch generic shared library (aka dynamically-linked
3237 library) events. (This is *NOT* the same as a catchpoint for a
3238 shlib event. The latter is something a user can set; this is
3239 something gdb sets for its own use, and isn't ever shown to a
3242 is_internal_shlib_eventpoint (struct breakpoint *ep)
3245 (ep->type == bp_shlib_event)
3249 /* This function returns TRUE if bs indicates that the inferior
3250 stopped due to a shared library (aka dynamically-linked library)
3254 stopped_for_internal_shlib_event (bpstat bs)
3256 /* Note that multiple eventpoints may've caused the stop. Any
3257 that are associated with shlib events will be accepted. */
3258 for (; bs != NULL; bs = bs->next)
3260 if ((bs->breakpoint_at != NULL)
3261 && is_internal_shlib_eventpoint (bs->breakpoint_at))
3265 /* If we get here, then no candidate was found. */
3269 /* Reset proper settings after an asynchronous command has finished.
3270 If the execution command was in synchronous mode, register stdin
3271 with the event loop, and reset the prompt. */
3274 complete_execution (void)
3276 target_executing = 0;
3279 add_file_handler (input_fd, stdin_event_handler, 0);
3282 cleanup_sigint_signal_handler ();
3283 display_gdb_prompt (0);
3287 if (exec_done_display_p)
3288 printf_unfiltered ("completed.\n");
3292 /* Here to return control to GDB when the inferior stops for real.
3293 Print appropriate messages, remove breakpoints, give terminal our modes.
3295 STOP_PRINT_FRAME nonzero means print the executing frame
3296 (pc, function, args, file, line number and line text).
3297 BREAKPOINTS_FAILED nonzero means stop was due to error
3298 attempting to insert breakpoints. */
3303 /* As with the notification of thread events, we want to delay
3304 notifying the user that we've switched thread context until
3305 the inferior actually stops.
3307 (Note that there's no point in saying anything if the inferior
3309 if (may_switch_from_inferior_pid
3310 && (switched_from_inferior_pid != inferior_pid)
3311 && target_has_execution)
3313 target_terminal_ours_for_output ();
3314 printf_filtered ("[Switched to %s]\n",
3315 target_pid_or_tid_to_str (inferior_pid));
3316 switched_from_inferior_pid = inferior_pid;
3319 /* Make sure that the current_frame's pc is correct. This
3320 is a correction for setting up the frame info before doing
3321 DECR_PC_AFTER_BREAK */
3322 if (target_has_execution && get_current_frame ())
3323 (get_current_frame ())->pc = read_pc ();
3325 if (breakpoints_failed)
3327 target_terminal_ours_for_output ();
3328 print_sys_errmsg ("ptrace", breakpoints_failed);
3329 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3330 The same program may be running in another process.\n");
3333 if (target_has_execution && breakpoints_inserted)
3335 if (remove_breakpoints ())
3337 target_terminal_ours_for_output ();
3338 printf_filtered ("Cannot remove breakpoints because ");
3339 printf_filtered ("program is no longer writable.\n");
3340 printf_filtered ("It might be running in another process.\n");
3341 printf_filtered ("Further execution is probably impossible.\n");
3344 breakpoints_inserted = 0;
3346 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3347 Delete any breakpoint that is to be deleted at the next stop. */
3349 breakpoint_auto_delete (stop_bpstat);
3351 /* If an auto-display called a function and that got a signal,
3352 delete that auto-display to avoid an infinite recursion. */
3354 if (stopped_by_random_signal)
3355 disable_current_display ();
3357 /* Don't print a message if in the middle of doing a "step n"
3358 operation for n > 1 */
3359 if (step_multi && stop_step)
3362 target_terminal_ours ();
3364 /* Did we stop because the user set the stop_on_solib_events
3365 variable? (If so, we report this as a generic, "Stopped due
3366 to shlib event" message.) */
3367 if (stopped_for_internal_shlib_event (stop_bpstat))
3369 printf_filtered ("Stopped due to shared library event\n");
3372 /* Look up the hook_stop and run it if it exists. */
3374 if (stop_command && stop_command->hook)
3376 catch_errors (hook_stop_stub, stop_command->hook,
3377 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3380 if (!target_has_stack)
3386 /* Select innermost stack frame - i.e., current frame is frame 0,
3387 and current location is based on that.
3388 Don't do this on return from a stack dummy routine,
3389 or if the program has exited. */
3391 if (!stop_stack_dummy)
3393 select_frame (get_current_frame (), 0);
3395 /* Print current location without a level number, if
3396 we have changed functions or hit a breakpoint.
3397 Print source line if we have one.
3398 bpstat_print() contains the logic deciding in detail
3399 what to print, based on the event(s) that just occurred. */
3401 if (stop_print_frame)
3406 bpstat_ret = bpstat_print (stop_bpstat);
3407 /* bpstat_print() returned one of:
3408 -1: Didn't print anything
3409 0: Printed preliminary "Breakpoint n, " message, desires
3411 1: Printed something, don't tack on location */
3413 if (bpstat_ret == -1)
3415 && step_frame_address == FRAME_FP (get_current_frame ())
3416 && step_start_function == find_pc_function (stop_pc))
3417 source_flag = -1; /* finished step, just print source line */
3419 source_flag = 1; /* print location and source line */
3420 else if (bpstat_ret == 0) /* hit bpt, desire location */
3421 source_flag = 1; /* print location and source line */
3422 else /* bpstat_ret == 1, hit bpt, do not desire location */
3423 source_flag = -1; /* just print source line */
3425 /* The behavior of this routine with respect to the source
3427 -1: Print only source line
3428 0: Print only location
3429 1: Print location and source line */
3430 show_and_print_stack_frame (selected_frame, -1, source_flag);
3432 /* Display the auto-display expressions. */
3437 /* Save the function value return registers, if we care.
3438 We might be about to restore their previous contents. */
3439 if (proceed_to_finish)
3440 read_register_bytes (0, stop_registers, REGISTER_BYTES);
3442 if (stop_stack_dummy)
3444 /* Pop the empty frame that contains the stack dummy.
3445 POP_FRAME ends with a setting of the current frame, so we
3446 can use that next. */
3448 /* Set stop_pc to what it was before we called the function.
3449 Can't rely on restore_inferior_status because that only gets
3450 called if we don't stop in the called function. */
3451 stop_pc = read_pc ();
3452 select_frame (get_current_frame (), 0);
3456 TUIDO (((TuiOpaqueFuncPtr) tui_vCheckDataValues, selected_frame));
3459 annotate_stopped ();
3463 hook_stop_stub (void *cmd)
3465 execute_user_command ((struct cmd_list_element *) cmd, 0);
3470 signal_stop_state (int signo)
3472 return signal_stop[signo];
3476 signal_print_state (int signo)
3478 return signal_print[signo];
3482 signal_pass_state (int signo)
3484 return signal_program[signo];
3487 int signal_stop_update (signo, state)
3491 int ret = signal_stop[signo];
3492 signal_stop[signo] = state;
3496 int signal_print_update (signo, state)
3500 int ret = signal_print[signo];
3501 signal_print[signo] = state;
3505 int signal_pass_update (signo, state)
3509 int ret = signal_program[signo];
3510 signal_program[signo] = state;
3515 sig_print_header (void)
3518 Signal Stop\tPrint\tPass to program\tDescription\n");
3522 sig_print_info (enum target_signal oursig)
3524 char *name = target_signal_to_name (oursig);
3525 int name_padding = 13 - strlen (name);
3527 if (name_padding <= 0)
3530 printf_filtered ("%s", name);
3531 printf_filtered ("%*.*s ", name_padding, name_padding,
3533 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3534 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3535 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3536 printf_filtered ("%s\n", target_signal_to_string (oursig));
3539 /* Specify how various signals in the inferior should be handled. */
3542 handle_command (char *args, int from_tty)
3545 int digits, wordlen;
3546 int sigfirst, signum, siglast;
3547 enum target_signal oursig;
3550 unsigned char *sigs;
3551 struct cleanup *old_chain;
3555 error_no_arg ("signal to handle");
3558 /* Allocate and zero an array of flags for which signals to handle. */
3560 nsigs = (int) TARGET_SIGNAL_LAST;
3561 sigs = (unsigned char *) alloca (nsigs);
3562 memset (sigs, 0, nsigs);
3564 /* Break the command line up into args. */
3566 argv = buildargv (args);
3571 old_chain = make_cleanup_freeargv (argv);
3573 /* Walk through the args, looking for signal oursigs, signal names, and
3574 actions. Signal numbers and signal names may be interspersed with
3575 actions, with the actions being performed for all signals cumulatively
3576 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3578 while (*argv != NULL)
3580 wordlen = strlen (*argv);
3581 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3585 sigfirst = siglast = -1;
3587 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3589 /* Apply action to all signals except those used by the
3590 debugger. Silently skip those. */
3593 siglast = nsigs - 1;
3595 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3597 SET_SIGS (nsigs, sigs, signal_stop);
3598 SET_SIGS (nsigs, sigs, signal_print);
3600 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3602 UNSET_SIGS (nsigs, sigs, signal_program);
3604 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3606 SET_SIGS (nsigs, sigs, signal_print);
3608 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3610 SET_SIGS (nsigs, sigs, signal_program);
3612 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3614 UNSET_SIGS (nsigs, sigs, signal_stop);
3616 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3618 SET_SIGS (nsigs, sigs, signal_program);
3620 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3622 UNSET_SIGS (nsigs, sigs, signal_print);
3623 UNSET_SIGS (nsigs, sigs, signal_stop);
3625 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3627 UNSET_SIGS (nsigs, sigs, signal_program);
3629 else if (digits > 0)
3631 /* It is numeric. The numeric signal refers to our own
3632 internal signal numbering from target.h, not to host/target
3633 signal number. This is a feature; users really should be
3634 using symbolic names anyway, and the common ones like
3635 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3637 sigfirst = siglast = (int)
3638 target_signal_from_command (atoi (*argv));
3639 if ((*argv)[digits] == '-')
3642 target_signal_from_command (atoi ((*argv) + digits + 1));
3644 if (sigfirst > siglast)
3646 /* Bet he didn't figure we'd think of this case... */
3654 oursig = target_signal_from_name (*argv);
3655 if (oursig != TARGET_SIGNAL_UNKNOWN)
3657 sigfirst = siglast = (int) oursig;
3661 /* Not a number and not a recognized flag word => complain. */
3662 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3666 /* If any signal numbers or symbol names were found, set flags for
3667 which signals to apply actions to. */
3669 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3671 switch ((enum target_signal) signum)
3673 case TARGET_SIGNAL_TRAP:
3674 case TARGET_SIGNAL_INT:
3675 if (!allsigs && !sigs[signum])
3677 if (query ("%s is used by the debugger.\n\
3678 Are you sure you want to change it? ",
3679 target_signal_to_name
3680 ((enum target_signal) signum)))
3686 printf_unfiltered ("Not confirmed, unchanged.\n");
3687 gdb_flush (gdb_stdout);
3691 case TARGET_SIGNAL_0:
3692 case TARGET_SIGNAL_DEFAULT:
3693 case TARGET_SIGNAL_UNKNOWN:
3694 /* Make sure that "all" doesn't print these. */
3705 target_notice_signals (inferior_pid);
3709 /* Show the results. */
3710 sig_print_header ();
3711 for (signum = 0; signum < nsigs; signum++)
3715 sig_print_info (signum);
3720 do_cleanups (old_chain);
3724 xdb_handle_command (char *args, int from_tty)
3727 struct cleanup *old_chain;
3729 /* Break the command line up into args. */
3731 argv = buildargv (args);
3736 old_chain = make_cleanup_freeargv (argv);
3737 if (argv[1] != (char *) NULL)
3742 bufLen = strlen (argv[0]) + 20;
3743 argBuf = (char *) xmalloc (bufLen);
3747 enum target_signal oursig;
3749 oursig = target_signal_from_name (argv[0]);
3750 memset (argBuf, 0, bufLen);
3751 if (strcmp (argv[1], "Q") == 0)
3752 sprintf (argBuf, "%s %s", argv[0], "noprint");
3755 if (strcmp (argv[1], "s") == 0)
3757 if (!signal_stop[oursig])
3758 sprintf (argBuf, "%s %s", argv[0], "stop");
3760 sprintf (argBuf, "%s %s", argv[0], "nostop");
3762 else if (strcmp (argv[1], "i") == 0)
3764 if (!signal_program[oursig])
3765 sprintf (argBuf, "%s %s", argv[0], "pass");
3767 sprintf (argBuf, "%s %s", argv[0], "nopass");
3769 else if (strcmp (argv[1], "r") == 0)
3771 if (!signal_print[oursig])
3772 sprintf (argBuf, "%s %s", argv[0], "print");
3774 sprintf (argBuf, "%s %s", argv[0], "noprint");
3780 handle_command (argBuf, from_tty);
3782 printf_filtered ("Invalid signal handling flag.\n");
3787 do_cleanups (old_chain);
3790 /* Print current contents of the tables set by the handle command.
3791 It is possible we should just be printing signals actually used
3792 by the current target (but for things to work right when switching
3793 targets, all signals should be in the signal tables). */
3796 signals_info (char *signum_exp, int from_tty)
3798 enum target_signal oursig;
3799 sig_print_header ();
3803 /* First see if this is a symbol name. */
3804 oursig = target_signal_from_name (signum_exp);
3805 if (oursig == TARGET_SIGNAL_UNKNOWN)
3807 /* No, try numeric. */
3809 target_signal_from_command (parse_and_eval_address (signum_exp));
3811 sig_print_info (oursig);
3815 printf_filtered ("\n");
3816 /* These ugly casts brought to you by the native VAX compiler. */
3817 for (oursig = TARGET_SIGNAL_FIRST;
3818 (int) oursig < (int) TARGET_SIGNAL_LAST;
3819 oursig = (enum target_signal) ((int) oursig + 1))
3823 if (oursig != TARGET_SIGNAL_UNKNOWN
3824 && oursig != TARGET_SIGNAL_DEFAULT
3825 && oursig != TARGET_SIGNAL_0)
3826 sig_print_info (oursig);
3829 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3832 struct inferior_status
3834 enum target_signal stop_signal;
3838 int stop_stack_dummy;
3839 int stopped_by_random_signal;
3841 CORE_ADDR step_range_start;
3842 CORE_ADDR step_range_end;
3843 CORE_ADDR step_frame_address;
3844 int step_over_calls;
3845 CORE_ADDR step_resume_break_address;
3846 int stop_after_trap;
3847 int stop_soon_quietly;
3848 CORE_ADDR selected_frame_address;
3849 char *stop_registers;
3851 /* These are here because if call_function_by_hand has written some
3852 registers and then decides to call error(), we better not have changed
3857 int breakpoint_proceeded;
3858 int restore_stack_info;
3859 int proceed_to_finish;
3862 static struct inferior_status *
3863 xmalloc_inferior_status (void)
3865 struct inferior_status *inf_status;
3866 inf_status = xmalloc (sizeof (struct inferior_status));
3867 inf_status->stop_registers = xmalloc (REGISTER_BYTES);
3868 inf_status->registers = xmalloc (REGISTER_BYTES);
3873 free_inferior_status (struct inferior_status *inf_status)
3875 free (inf_status->registers);
3876 free (inf_status->stop_registers);
3881 write_inferior_status_register (struct inferior_status *inf_status, int regno,
3884 int size = REGISTER_RAW_SIZE (regno);
3885 void *buf = alloca (size);
3886 store_signed_integer (buf, size, val);
3887 memcpy (&inf_status->registers[REGISTER_BYTE (regno)], buf, size);
3890 /* Save all of the information associated with the inferior<==>gdb
3891 connection. INF_STATUS is a pointer to a "struct inferior_status"
3892 (defined in inferior.h). */
3894 struct inferior_status *
3895 save_inferior_status (int restore_stack_info)
3897 struct inferior_status *inf_status = xmalloc_inferior_status ();
3899 inf_status->stop_signal = stop_signal;
3900 inf_status->stop_pc = stop_pc;
3901 inf_status->stop_step = stop_step;
3902 inf_status->stop_stack_dummy = stop_stack_dummy;
3903 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3904 inf_status->trap_expected = trap_expected;
3905 inf_status->step_range_start = step_range_start;
3906 inf_status->step_range_end = step_range_end;
3907 inf_status->step_frame_address = step_frame_address;
3908 inf_status->step_over_calls = step_over_calls;
3909 inf_status->stop_after_trap = stop_after_trap;
3910 inf_status->stop_soon_quietly = stop_soon_quietly;
3911 /* Save original bpstat chain here; replace it with copy of chain.
3912 If caller's caller is walking the chain, they'll be happier if we
3913 hand them back the original chain when restore_inferior_status is
3915 inf_status->stop_bpstat = stop_bpstat;
3916 stop_bpstat = bpstat_copy (stop_bpstat);
3917 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3918 inf_status->restore_stack_info = restore_stack_info;
3919 inf_status->proceed_to_finish = proceed_to_finish;
3921 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
3923 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3925 record_selected_frame (&(inf_status->selected_frame_address),
3926 &(inf_status->selected_level));
3930 struct restore_selected_frame_args
3932 CORE_ADDR frame_address;
3937 restore_selected_frame (void *args)
3939 struct restore_selected_frame_args *fr =
3940 (struct restore_selected_frame_args *) args;
3941 struct frame_info *frame;
3942 int level = fr->level;
3944 frame = find_relative_frame (get_current_frame (), &level);
3946 /* If inf_status->selected_frame_address is NULL, there was no
3947 previously selected frame. */
3948 if (frame == NULL ||
3949 /* FRAME_FP (frame) != fr->frame_address || */
3950 /* elz: deleted this check as a quick fix to the problem that
3951 for function called by hand gdb creates no internal frame
3952 structure and the real stack and gdb's idea of stack are
3953 different if nested calls by hands are made.
3955 mvs: this worries me. */
3958 warning ("Unable to restore previously selected frame.\n");
3962 select_frame (frame, fr->level);
3968 restore_inferior_status (struct inferior_status *inf_status)
3970 stop_signal = inf_status->stop_signal;
3971 stop_pc = inf_status->stop_pc;
3972 stop_step = inf_status->stop_step;
3973 stop_stack_dummy = inf_status->stop_stack_dummy;
3974 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3975 trap_expected = inf_status->trap_expected;
3976 step_range_start = inf_status->step_range_start;
3977 step_range_end = inf_status->step_range_end;
3978 step_frame_address = inf_status->step_frame_address;
3979 step_over_calls = inf_status->step_over_calls;
3980 stop_after_trap = inf_status->stop_after_trap;
3981 stop_soon_quietly = inf_status->stop_soon_quietly;
3982 bpstat_clear (&stop_bpstat);
3983 stop_bpstat = inf_status->stop_bpstat;
3984 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3985 proceed_to_finish = inf_status->proceed_to_finish;
3987 /* FIXME: Is the restore of stop_registers always needed */
3988 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
3990 /* The inferior can be gone if the user types "print exit(0)"
3991 (and perhaps other times). */
3992 if (target_has_execution)
3993 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3995 /* FIXME: If we are being called after stopping in a function which
3996 is called from gdb, we should not be trying to restore the
3997 selected frame; it just prints a spurious error message (The
3998 message is useful, however, in detecting bugs in gdb (like if gdb
3999 clobbers the stack)). In fact, should we be restoring the
4000 inferior status at all in that case? . */
4002 if (target_has_stack && inf_status->restore_stack_info)
4004 struct restore_selected_frame_args fr;
4005 fr.level = inf_status->selected_level;
4006 fr.frame_address = inf_status->selected_frame_address;
4007 /* The point of catch_errors is that if the stack is clobbered,
4008 walking the stack might encounter a garbage pointer and error()
4009 trying to dereference it. */
4010 if (catch_errors (restore_selected_frame, &fr,
4011 "Unable to restore previously selected frame:\n",
4012 RETURN_MASK_ERROR) == 0)
4013 /* Error in restoring the selected frame. Select the innermost
4017 select_frame (get_current_frame (), 0);
4021 free_inferior_status (inf_status);
4025 discard_inferior_status (struct inferior_status *inf_status)
4027 /* See save_inferior_status for info on stop_bpstat. */
4028 bpstat_clear (&inf_status->stop_bpstat);
4029 free_inferior_status (inf_status);
4033 set_follow_fork_mode_command (char *arg, int from_tty,
4034 struct cmd_list_element *c)
4036 if (!STREQ (arg, "parent") &&
4037 !STREQ (arg, "child") &&
4038 !STREQ (arg, "both") &&
4039 !STREQ (arg, "ask"))
4040 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
4042 if (follow_fork_mode_string != NULL)
4043 free (follow_fork_mode_string);
4044 follow_fork_mode_string = savestring (arg, strlen (arg));
4050 stop_registers = xmalloc (REGISTER_BYTES);
4054 _initialize_infrun (void)
4057 register int numsigs;
4058 struct cmd_list_element *c;
4062 register_gdbarch_swap (&stop_registers, sizeof (stop_registers), NULL);
4063 register_gdbarch_swap (NULL, 0, build_infrun);
4065 add_info ("signals", signals_info,
4066 "What debugger does when program gets various signals.\n\
4067 Specify a signal as argument to print info on that signal only.");
4068 add_info_alias ("handle", "signals", 0);
4070 add_com ("handle", class_run, handle_command,
4071 concat ("Specify how to handle a signal.\n\
4072 Args are signals and actions to apply to those signals.\n\
4073 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4074 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4075 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4076 The special arg \"all\" is recognized to mean all signals except those\n\
4077 used by the debugger, typically SIGTRAP and SIGINT.\n",
4078 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4079 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4080 Stop means reenter debugger if this signal happens (implies print).\n\
4081 Print means print a message if this signal happens.\n\
4082 Pass means let program see this signal; otherwise program doesn't know.\n\
4083 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4084 Pass and Stop may be combined.", NULL));
4087 add_com ("lz", class_info, signals_info,
4088 "What debugger does when program gets various signals.\n\
4089 Specify a signal as argument to print info on that signal only.");
4090 add_com ("z", class_run, xdb_handle_command,
4091 concat ("Specify how to handle a signal.\n\
4092 Args are signals and actions to apply to those signals.\n\
4093 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4094 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4095 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4096 The special arg \"all\" is recognized to mean all signals except those\n\
4097 used by the debugger, typically SIGTRAP and SIGINT.\n",
4098 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4099 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4100 nopass), \"Q\" (noprint)\n\
4101 Stop means reenter debugger if this signal happens (implies print).\n\
4102 Print means print a message if this signal happens.\n\
4103 Pass means let program see this signal; otherwise program doesn't know.\n\
4104 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4105 Pass and Stop may be combined.", NULL));
4109 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
4110 "There is no `stop' command, but you can set a hook on `stop'.\n\
4111 This allows you to set a list of commands to be run each time execution\n\
4112 of the program stops.", &cmdlist);
4114 numsigs = (int) TARGET_SIGNAL_LAST;
4115 signal_stop = (unsigned char *)
4116 xmalloc (sizeof (signal_stop[0]) * numsigs);
4117 signal_print = (unsigned char *)
4118 xmalloc (sizeof (signal_print[0]) * numsigs);
4119 signal_program = (unsigned char *)
4120 xmalloc (sizeof (signal_program[0]) * numsigs);
4121 for (i = 0; i < numsigs; i++)
4124 signal_print[i] = 1;
4125 signal_program[i] = 1;
4128 /* Signals caused by debugger's own actions
4129 should not be given to the program afterwards. */
4130 signal_program[TARGET_SIGNAL_TRAP] = 0;
4131 signal_program[TARGET_SIGNAL_INT] = 0;
4133 /* Signals that are not errors should not normally enter the debugger. */
4134 signal_stop[TARGET_SIGNAL_ALRM] = 0;
4135 signal_print[TARGET_SIGNAL_ALRM] = 0;
4136 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
4137 signal_print[TARGET_SIGNAL_VTALRM] = 0;
4138 signal_stop[TARGET_SIGNAL_PROF] = 0;
4139 signal_print[TARGET_SIGNAL_PROF] = 0;
4140 signal_stop[TARGET_SIGNAL_CHLD] = 0;
4141 signal_print[TARGET_SIGNAL_CHLD] = 0;
4142 signal_stop[TARGET_SIGNAL_IO] = 0;
4143 signal_print[TARGET_SIGNAL_IO] = 0;
4144 signal_stop[TARGET_SIGNAL_POLL] = 0;
4145 signal_print[TARGET_SIGNAL_POLL] = 0;
4146 signal_stop[TARGET_SIGNAL_URG] = 0;
4147 signal_print[TARGET_SIGNAL_URG] = 0;
4148 signal_stop[TARGET_SIGNAL_WINCH] = 0;
4149 signal_print[TARGET_SIGNAL_WINCH] = 0;
4151 /* These signals are used internally by user-level thread
4152 implementations. (See signal(5) on Solaris.) Like the above
4153 signals, a healthy program receives and handles them as part of
4154 its normal operation. */
4155 signal_stop[TARGET_SIGNAL_LWP] = 0;
4156 signal_print[TARGET_SIGNAL_LWP] = 0;
4157 signal_stop[TARGET_SIGNAL_WAITING] = 0;
4158 signal_print[TARGET_SIGNAL_WAITING] = 0;
4159 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
4160 signal_print[TARGET_SIGNAL_CANCEL] = 0;
4164 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
4165 (char *) &stop_on_solib_events,
4166 "Set stopping for shared library events.\n\
4167 If nonzero, gdb will give control to the user when the dynamic linker\n\
4168 notifies gdb of shared library events. The most common event of interest\n\
4169 to the user would be loading/unloading of a new library.\n",
4174 c = add_set_enum_cmd ("follow-fork-mode",
4176 follow_fork_mode_kind_names,
4177 (char *) &follow_fork_mode_string,
4178 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4179 kernel problem. It's also not terribly useful without a GUI to
4180 help the user drive two debuggers. So for now, I'm disabling
4181 the "both" option. */
4182 /* "Set debugger response to a program call of fork \
4184 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4185 parent - the original process is debugged after a fork\n\
4186 child - the new process is debugged after a fork\n\
4187 both - both the parent and child are debugged after a fork\n\
4188 ask - the debugger will ask for one of the above choices\n\
4189 For \"both\", another copy of the debugger will be started to follow\n\
4190 the new child process. The original debugger will continue to follow\n\
4191 the original parent process. To distinguish their prompts, the\n\
4192 debugger copy's prompt will be changed.\n\
4193 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4194 By default, the debugger will follow the parent process.",
4196 "Set debugger response to a program call of fork \
4198 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4199 parent - the original process is debugged after a fork\n\
4200 child - the new process is debugged after a fork\n\
4201 ask - the debugger will ask for one of the above choices\n\
4202 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4203 By default, the debugger will follow the parent process.",
4205 /* c->function.sfunc = ; */
4206 add_show_from_set (c, &showlist);
4208 set_follow_fork_mode_command ("parent", 0, NULL);
4210 c = add_set_enum_cmd ("scheduler-locking", class_run,
4211 scheduler_enums, /* array of string names */
4212 (char *) &scheduler_mode, /* current mode */
4213 "Set mode for locking scheduler during execution.\n\
4214 off == no locking (threads may preempt at any time)\n\
4215 on == full locking (no thread except the current thread may run)\n\
4216 step == scheduler locked during every single-step operation.\n\
4217 In this mode, no other thread may run during a step command.\n\
4218 Other threads may run while stepping over a function call ('next').",
4221 c->function.sfunc = set_schedlock_func; /* traps on target vector */
4222 add_show_from_set (c, &showlist);