1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986-1989, 1991-2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
27 #include "breakpoint.h"
32 #include "gdbthread.h"
34 #include "symfile.h" /* for overlay functions */
39 /* Prototypes for local functions */
41 static void signals_info (char *, int);
43 static void handle_command (char *, int);
45 static void sig_print_info (enum target_signal);
47 static void sig_print_header (void);
49 static void resume_cleanups (int);
51 static int hook_stop_stub (void *);
53 static void delete_breakpoint_current_contents (void *);
55 static void set_follow_fork_mode_command (char *arg, int from_tty,
56 struct cmd_list_element * c);
58 static struct inferior_status *xmalloc_inferior_status (void);
60 static void free_inferior_status (struct inferior_status *);
62 static int restore_selected_frame (void *);
64 static void build_infrun (void);
66 static void follow_inferior_fork (int parent_pid, int child_pid,
67 int has_forked, int has_vforked);
69 static void follow_fork (int parent_pid, int child_pid);
71 static void follow_vfork (int parent_pid, int child_pid);
73 static void set_schedlock_func (char *args, int from_tty,
74 struct cmd_list_element * c);
76 struct execution_control_state;
78 static int currently_stepping (struct execution_control_state *ecs);
80 static void xdb_handle_command (char *args, int from_tty);
82 void _initialize_infrun (void);
84 int inferior_ignoring_startup_exec_events = 0;
85 int inferior_ignoring_leading_exec_events = 0;
87 /* In asynchronous mode, but simulating synchronous execution. */
89 int sync_execution = 0;
91 /* wait_for_inferior and normal_stop use this to notify the user
92 when the inferior stopped in a different thread than it had been
95 static int previous_inferior_pid;
97 /* This is true for configurations that may follow through execl() and
98 similar functions. At present this is only true for HP-UX native. */
100 #ifndef MAY_FOLLOW_EXEC
101 #define MAY_FOLLOW_EXEC (0)
104 static int may_follow_exec = MAY_FOLLOW_EXEC;
106 /* resume and wait_for_inferior use this to ensure that when
107 stepping over a hit breakpoint in a threaded application
108 only the thread that hit the breakpoint is stepped and the
109 other threads don't continue. This prevents having another
110 thread run past the breakpoint while it is temporarily
113 This is not thread-specific, so it isn't saved as part of
116 Versions of gdb which don't use the "step == this thread steps
117 and others continue" model but instead use the "step == this
118 thread steps and others wait" shouldn't do this. */
120 static int thread_step_needed = 0;
122 /* This is true if thread_step_needed should actually be used. At
123 present this is only true for HP-UX native. */
125 #ifndef USE_THREAD_STEP_NEEDED
126 #define USE_THREAD_STEP_NEEDED (0)
129 static int use_thread_step_needed = USE_THREAD_STEP_NEEDED;
131 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
132 program. It needs to examine the jmp_buf argument and extract the PC
133 from it. The return value is non-zero on success, zero otherwise. */
135 #ifndef GET_LONGJMP_TARGET
136 #define GET_LONGJMP_TARGET(PC_ADDR) 0
140 /* Some machines have trampoline code that sits between function callers
141 and the actual functions themselves. If this machine doesn't have
142 such things, disable their processing. */
144 #ifndef SKIP_TRAMPOLINE_CODE
145 #define SKIP_TRAMPOLINE_CODE(pc) 0
148 /* Dynamic function trampolines are similar to solib trampolines in that they
149 are between the caller and the callee. The difference is that when you
150 enter a dynamic trampoline, you can't determine the callee's address. Some
151 (usually complex) code needs to run in the dynamic trampoline to figure out
152 the callee's address. This macro is usually called twice. First, when we
153 enter the trampoline (looks like a normal function call at that point). It
154 should return the PC of a point within the trampoline where the callee's
155 address is known. Second, when we hit the breakpoint, this routine returns
156 the callee's address. At that point, things proceed as per a step resume
159 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
160 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
163 /* If the program uses ELF-style shared libraries, then calls to
164 functions in shared libraries go through stubs, which live in a
165 table called the PLT (Procedure Linkage Table). The first time the
166 function is called, the stub sends control to the dynamic linker,
167 which looks up the function's real address, patches the stub so
168 that future calls will go directly to the function, and then passes
169 control to the function.
171 If we are stepping at the source level, we don't want to see any of
172 this --- we just want to skip over the stub and the dynamic linker.
173 The simple approach is to single-step until control leaves the
176 However, on some systems (e.g., Red Hat Linux 5.2) the dynamic
177 linker calls functions in the shared C library, so you can't tell
178 from the PC alone whether the dynamic linker is still running. In
179 this case, we use a step-resume breakpoint to get us past the
180 dynamic linker, as if we were using "next" to step over a function
183 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
184 linker code or not. Normally, this means we single-step. However,
185 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
186 address where we can place a step-resume breakpoint to get past the
187 linker's symbol resolution function.
189 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
190 pretty portable way, by comparing the PC against the address ranges
191 of the dynamic linker's sections.
193 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
194 it depends on internal details of the dynamic linker. It's usually
195 not too hard to figure out where to put a breakpoint, but it
196 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
197 sanity checking. If it can't figure things out, returning zero and
198 getting the (possibly confusing) stepping behavior is better than
199 signalling an error, which will obscure the change in the
202 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
203 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
206 #ifndef SKIP_SOLIB_RESOLVER
207 #define SKIP_SOLIB_RESOLVER(pc) 0
210 /* For SVR4 shared libraries, each call goes through a small piece of
211 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
212 to nonzero if we are current stopped in one of these. */
214 #ifndef IN_SOLIB_CALL_TRAMPOLINE
215 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
218 /* In some shared library schemes, the return path from a shared library
219 call may need to go through a trampoline too. */
221 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
222 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
225 /* This function returns TRUE if pc is the address of an instruction
226 that lies within the dynamic linker (such as the event hook, or the
229 This function must be used only when a dynamic linker event has
230 been caught, and the inferior is being stepped out of the hook, or
231 undefined results are guaranteed. */
233 #ifndef SOLIB_IN_DYNAMIC_LINKER
234 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
237 /* On MIPS16, a function that returns a floating point value may call
238 a library helper function to copy the return value to a floating point
239 register. The IGNORE_HELPER_CALL macro returns non-zero if we
240 should ignore (i.e. step over) this function call. */
241 #ifndef IGNORE_HELPER_CALL
242 #define IGNORE_HELPER_CALL(pc) 0
245 /* On some systems, the PC may be left pointing at an instruction that won't
246 actually be executed. This is usually indicated by a bit in the PSW. If
247 we find ourselves in such a state, then we step the target beyond the
248 nullified instruction before returning control to the user so as to avoid
251 #ifndef INSTRUCTION_NULLIFIED
252 #define INSTRUCTION_NULLIFIED 0
255 /* We can't step off a permanent breakpoint in the ordinary way, because we
256 can't remove it. Instead, we have to advance the PC to the next
257 instruction. This macro should expand to a pointer to a function that
258 does that, or zero if we have no such function. If we don't have a
259 definition for it, we have to report an error. */
260 #ifndef SKIP_PERMANENT_BREAKPOINT
261 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
263 default_skip_permanent_breakpoint (void)
266 fprintf_filtered (gdb_stderr, "\
267 The program is stopped at a permanent breakpoint, but GDB does not know\n\
268 how to step past a permanent breakpoint on this architecture. Try using\n\
269 a command like `return' or `jump' to continue execution.\n");
270 return_to_top_level (RETURN_ERROR);
275 /* Convert the #defines into values. This is temporary until wfi control
276 flow is completely sorted out. */
278 #ifndef HAVE_STEPPABLE_WATCHPOINT
279 #define HAVE_STEPPABLE_WATCHPOINT 0
281 #undef HAVE_STEPPABLE_WATCHPOINT
282 #define HAVE_STEPPABLE_WATCHPOINT 1
285 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
286 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
288 #undef HAVE_NONSTEPPABLE_WATCHPOINT
289 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
292 #ifndef HAVE_CONTINUABLE_WATCHPOINT
293 #define HAVE_CONTINUABLE_WATCHPOINT 0
295 #undef HAVE_CONTINUABLE_WATCHPOINT
296 #define HAVE_CONTINUABLE_WATCHPOINT 1
299 #ifndef CANNOT_STEP_HW_WATCHPOINTS
300 #define CANNOT_STEP_HW_WATCHPOINTS 0
302 #undef CANNOT_STEP_HW_WATCHPOINTS
303 #define CANNOT_STEP_HW_WATCHPOINTS 1
306 /* Tables of how to react to signals; the user sets them. */
308 static unsigned char *signal_stop;
309 static unsigned char *signal_print;
310 static unsigned char *signal_program;
312 #define SET_SIGS(nsigs,sigs,flags) \
314 int signum = (nsigs); \
315 while (signum-- > 0) \
316 if ((sigs)[signum]) \
317 (flags)[signum] = 1; \
320 #define UNSET_SIGS(nsigs,sigs,flags) \
322 int signum = (nsigs); \
323 while (signum-- > 0) \
324 if ((sigs)[signum]) \
325 (flags)[signum] = 0; \
329 /* Command list pointer for the "stop" placeholder. */
331 static struct cmd_list_element *stop_command;
333 /* Nonzero if breakpoints are now inserted in the inferior. */
335 static int breakpoints_inserted;
337 /* Function inferior was in as of last step command. */
339 static struct symbol *step_start_function;
341 /* Nonzero if we are expecting a trace trap and should proceed from it. */
343 static int trap_expected;
346 /* Nonzero if we want to give control to the user when we're notified
347 of shared library events by the dynamic linker. */
348 static int stop_on_solib_events;
352 /* Nonzero if the next time we try to continue the inferior, it will
353 step one instruction and generate a spurious trace trap.
354 This is used to compensate for a bug in HP-UX. */
356 static int trap_expected_after_continue;
359 /* Nonzero means expecting a trace trap
360 and should stop the inferior and return silently when it happens. */
364 /* Nonzero means expecting a trap and caller will handle it themselves.
365 It is used after attach, due to attaching to a process;
366 when running in the shell before the child program has been exec'd;
367 and when running some kinds of remote stuff (FIXME?). */
369 int stop_soon_quietly;
371 /* Nonzero if proceed is being used for a "finish" command or a similar
372 situation when stop_registers should be saved. */
374 int proceed_to_finish;
376 /* Save register contents here when about to pop a stack dummy frame,
377 if-and-only-if proceed_to_finish is set.
378 Thus this contains the return value from the called function (assuming
379 values are returned in a register). */
381 char *stop_registers;
383 /* Nonzero if program stopped due to error trying to insert breakpoints. */
385 static int breakpoints_failed;
387 /* Nonzero after stop if current stack frame should be printed. */
389 static int stop_print_frame;
391 static struct breakpoint *step_resume_breakpoint = NULL;
392 static struct breakpoint *through_sigtramp_breakpoint = NULL;
394 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
395 interactions with an inferior that is running a kernel function
396 (aka, a system call or "syscall"). wait_for_inferior therefore
397 may have a need to know when the inferior is in a syscall. This
398 is a count of the number of inferior threads which are known to
399 currently be running in a syscall. */
400 static int number_of_threads_in_syscalls;
402 /* This is used to remember when a fork, vfork or exec event
403 was caught by a catchpoint, and thus the event is to be
404 followed at the next resume of the inferior, and not
408 enum target_waitkind kind;
418 char *execd_pathname;
422 /* Some platforms don't allow us to do anything meaningful with a
423 vforked child until it has exec'd. Vforked processes on such
424 platforms can only be followed after they've exec'd.
426 When this is set to 0, a vfork can be immediately followed,
427 and an exec can be followed merely as an exec. When this is
428 set to 1, a vfork event has been seen, but cannot be followed
429 until the exec is seen.
431 (In the latter case, inferior_pid is still the parent of the
432 vfork, and pending_follow.fork_event.child_pid is the child. The
433 appropriate process is followed, according to the setting of
434 follow-fork-mode.) */
435 static int follow_vfork_when_exec;
437 static char *follow_fork_mode_kind_names[] =
439 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
440 kernel problem. It's also not terribly useful without a GUI to
441 help the user drive two debuggers. So for now, I'm disabling
443 "parent", "child", "both", "ask" };
445 "parent", "child", "ask"};
447 static char *follow_fork_mode_string = NULL;
451 follow_inferior_fork (int parent_pid, int child_pid, int has_forked,
454 int followed_parent = 0;
455 int followed_child = 0;
457 /* Which process did the user want us to follow? */
459 savestring (follow_fork_mode_string, strlen (follow_fork_mode_string));
461 /* Or, did the user not know, and want us to ask? */
462 if (STREQ (follow_fork_mode_string, "ask"))
464 char requested_mode[100];
467 error ("\"ask\" mode NYI");
468 follow_mode = savestring (requested_mode, strlen (requested_mode));
471 /* If we're to be following the parent, then detach from child_pid.
472 We're already following the parent, so need do nothing explicit
474 if (STREQ (follow_mode, "parent"))
478 /* We're already attached to the parent, by default. */
480 /* Before detaching from the child, remove all breakpoints from
481 it. (This won't actually modify the breakpoint list, but will
482 physically remove the breakpoints from the child.) */
483 if (!has_vforked || !follow_vfork_when_exec)
485 detach_breakpoints (child_pid);
486 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
487 SOLIB_REMOVE_INFERIOR_HOOK (child_pid);
491 /* Detach from the child. */
494 target_require_detach (child_pid, "", 1);
497 /* If we're to be following the child, then attach to it, detach
498 from inferior_pid, and set inferior_pid to child_pid. */
499 else if (STREQ (follow_mode, "child"))
501 char child_pid_spelling[100]; /* Arbitrary length. */
505 /* Before detaching from the parent, detach all breakpoints from
506 the child. But only if we're forking, or if we follow vforks
507 as soon as they happen. (If we're following vforks only when
508 the child has exec'd, then it's very wrong to try to write
509 back the "shadow contents" of inserted breakpoints now -- they
510 belong to the child's pre-exec'd a.out.) */
511 if (!has_vforked || !follow_vfork_when_exec)
513 detach_breakpoints (child_pid);
516 /* Before detaching from the parent, remove all breakpoints from it. */
517 remove_breakpoints ();
519 /* Also reset the solib inferior hook from the parent. */
520 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
521 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid);
524 /* Detach from the parent. */
526 target_detach (NULL, 1);
528 /* Attach to the child. */
529 inferior_pid = child_pid;
530 sprintf (child_pid_spelling, "%d", child_pid);
533 target_require_attach (child_pid_spelling, 1);
535 /* Was there a step_resume breakpoint? (There was if the user
536 did a "next" at the fork() call.) If so, explicitly reset its
539 step_resumes are a form of bp that are made to be per-thread.
540 Since we created the step_resume bp when the parent process
541 was being debugged, and now are switching to the child process,
542 from the breakpoint package's viewpoint, that's a switch of
543 "threads". We must update the bp's notion of which thread
544 it is for, or it'll be ignored when it triggers... */
545 if (step_resume_breakpoint &&
546 (!has_vforked || !follow_vfork_when_exec))
547 breakpoint_re_set_thread (step_resume_breakpoint);
549 /* Reinsert all breakpoints in the child. (The user may've set
550 breakpoints after catching the fork, in which case those
551 actually didn't get set in the child, but only in the parent.) */
552 if (!has_vforked || !follow_vfork_when_exec)
554 breakpoint_re_set ();
555 insert_breakpoints ();
559 /* If we're to be following both parent and child, then fork ourselves,
560 and attach the debugger clone to the child. */
561 else if (STREQ (follow_mode, "both"))
563 char pid_suffix[100]; /* Arbitrary length. */
565 /* Clone ourselves to follow the child. This is the end of our
566 involvement with child_pid; our clone will take it from here... */
568 target_clone_and_follow_inferior (child_pid, &followed_child);
569 followed_parent = !followed_child;
571 /* We continue to follow the parent. To help distinguish the two
572 debuggers, though, both we and our clone will reset our prompts. */
573 sprintf (pid_suffix, "[%d] ", inferior_pid);
574 set_prompt (strcat (get_prompt (), pid_suffix));
577 /* The parent and child of a vfork share the same address space.
578 Also, on some targets the order in which vfork and exec events
579 are received for parent in child requires some delicate handling
582 For instance, on ptrace-based HPUX we receive the child's vfork
583 event first, at which time the parent has been suspended by the
584 OS and is essentially untouchable until the child's exit or second
585 exec event arrives. At that time, the parent's vfork event is
586 delivered to us, and that's when we see and decide how to follow
587 the vfork. But to get to that point, we must continue the child
588 until it execs or exits. To do that smoothly, all breakpoints
589 must be removed from the child, in case there are any set between
590 the vfork() and exec() calls. But removing them from the child
591 also removes them from the parent, due to the shared-address-space
592 nature of a vfork'd parent and child. On HPUX, therefore, we must
593 take care to restore the bp's to the parent before we continue it.
594 Else, it's likely that we may not stop in the expected place. (The
595 worst scenario is when the user tries to step over a vfork() call;
596 the step-resume bp must be restored for the step to properly stop
597 in the parent after the call completes!)
599 Sequence of events, as reported to gdb from HPUX:
601 Parent Child Action for gdb to take
602 -------------------------------------------------------
603 1 VFORK Continue child
609 target_post_follow_vfork (parent_pid,
615 pending_follow.fork_event.saw_parent_fork = 0;
616 pending_follow.fork_event.saw_child_fork = 0;
622 follow_fork (int parent_pid, int child_pid)
624 follow_inferior_fork (parent_pid, child_pid, 1, 0);
628 /* Forward declaration. */
629 static void follow_exec (int, char *);
632 follow_vfork (int parent_pid, int child_pid)
634 follow_inferior_fork (parent_pid, child_pid, 0, 1);
636 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
637 if (pending_follow.fork_event.saw_child_exec && (inferior_pid == child_pid))
639 pending_follow.fork_event.saw_child_exec = 0;
640 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
641 follow_exec (inferior_pid, pending_follow.execd_pathname);
642 free (pending_follow.execd_pathname);
647 follow_exec (int pid, char *execd_pathname)
650 struct target_ops *tgt;
652 if (!may_follow_exec)
655 /* Did this exec() follow a vfork()? If so, we must follow the
656 vfork now too. Do it before following the exec. */
657 if (follow_vfork_when_exec &&
658 (pending_follow.kind == TARGET_WAITKIND_VFORKED))
660 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
661 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
662 follow_vfork_when_exec = 0;
663 saved_pid = inferior_pid;
665 /* Did we follow the parent? If so, we're done. If we followed
666 the child then we must also follow its exec(). */
667 if (inferior_pid == pending_follow.fork_event.parent_pid)
671 /* This is an exec event that we actually wish to pay attention to.
672 Refresh our symbol table to the newly exec'd program, remove any
675 If there are breakpoints, they aren't really inserted now,
676 since the exec() transformed our inferior into a fresh set
679 We want to preserve symbolic breakpoints on the list, since
680 we have hopes that they can be reset after the new a.out's
681 symbol table is read.
683 However, any "raw" breakpoints must be removed from the list
684 (e.g., the solib bp's), since their address is probably invalid
687 And, we DON'T want to call delete_breakpoints() here, since
688 that may write the bp's "shadow contents" (the instruction
689 value that was overwritten witha TRAP instruction). Since
690 we now have a new a.out, those shadow contents aren't valid. */
691 update_breakpoints_after_exec ();
693 /* If there was one, it's gone now. We cannot truly step-to-next
694 statement through an exec(). */
695 step_resume_breakpoint = NULL;
696 step_range_start = 0;
699 /* If there was one, it's gone now. */
700 through_sigtramp_breakpoint = NULL;
702 /* What is this a.out's name? */
703 printf_unfiltered ("Executing new program: %s\n", execd_pathname);
705 /* We've followed the inferior through an exec. Therefore, the
706 inferior has essentially been killed & reborn. */
708 /* First collect the run target in effect. */
709 tgt = find_run_target ();
710 /* If we can't find one, things are in a very strange state... */
712 error ("Could find run target to save before following exec");
714 gdb_flush (gdb_stdout);
715 target_mourn_inferior ();
716 inferior_pid = saved_pid; /* Because mourn_inferior resets inferior_pid. */
719 /* That a.out is now the one to use. */
720 exec_file_attach (execd_pathname, 0);
722 /* And also is where symbols can be found. */
723 symbol_file_command (execd_pathname, 0);
725 /* Reset the shared library package. This ensures that we get
726 a shlib event when the child reaches "_start", at which point
727 the dld will have had a chance to initialize the child. */
728 #if defined(SOLIB_RESTART)
731 #ifdef SOLIB_CREATE_INFERIOR_HOOK
732 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid);
735 /* Reinsert all breakpoints. (Those which were symbolic have
736 been reset to the proper address in the new a.out, thanks
737 to symbol_file_command...) */
738 insert_breakpoints ();
740 /* The next resume of this inferior should bring it to the shlib
741 startup breakpoints. (If the user had also set bp's on
742 "main" from the old (parent) process, then they'll auto-
743 matically get reset there in the new process.) */
746 /* Non-zero if we just simulating a single-step. This is needed
747 because we cannot remove the breakpoints in the inferior process
748 until after the `wait' in `wait_for_inferior'. */
749 static int singlestep_breakpoints_inserted_p = 0;
752 /* Things to clean up if we QUIT out of resume (). */
755 resume_cleanups (int arg)
760 static char schedlock_off[] = "off";
761 static char schedlock_on[] = "on";
762 static char schedlock_step[] = "step";
763 static char *scheduler_mode = schedlock_off;
764 static char *scheduler_enums[] =
765 {schedlock_off, schedlock_on, schedlock_step};
768 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
770 if (c->type == set_cmd)
771 if (!target_can_lock_scheduler)
773 scheduler_mode = schedlock_off;
774 error ("Target '%s' cannot support this command.",
782 /* Resume the inferior, but allow a QUIT. This is useful if the user
783 wants to interrupt some lengthy single-stepping operation
784 (for child processes, the SIGINT goes to the inferior, and so
785 we get a SIGINT random_signal, but for remote debugging and perhaps
786 other targets, that's not true).
788 STEP nonzero if we should step (zero to continue instead).
789 SIG is the signal to give the inferior (zero for none). */
791 resume (int step, enum target_signal sig)
793 int should_resume = 1;
794 struct cleanup *old_cleanups = make_cleanup ((make_cleanup_func)
798 #ifdef CANNOT_STEP_BREAKPOINT
799 /* Most targets can step a breakpoint instruction, thus executing it
800 normally. But if this one cannot, just continue and we will hit
802 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
806 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
807 over an instruction that causes a page fault without triggering
808 a hardware watchpoint. The kernel properly notices that it shouldn't
809 stop, because the hardware watchpoint is not triggered, but it forgets
810 the step request and continues the program normally.
811 Work around the problem by removing hardware watchpoints if a step is
812 requested, GDB will check for a hardware watchpoint trigger after the
814 if (CANNOT_STEP_HW_WATCHPOINTS && step && breakpoints_inserted)
815 remove_hw_watchpoints ();
818 /* Normally, by the time we reach `resume', the breakpoints are either
819 removed or inserted, as appropriate. The exception is if we're sitting
820 at a permanent breakpoint; we need to step over it, but permanent
821 breakpoints can't be removed. So we have to test for it here. */
822 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here)
823 SKIP_PERMANENT_BREAKPOINT ();
825 if (SOFTWARE_SINGLE_STEP_P && step)
827 /* Do it the hard way, w/temp breakpoints */
828 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ );
829 /* ...and don't ask hardware to do it. */
831 /* and do not pull these breakpoints until after a `wait' in
832 `wait_for_inferior' */
833 singlestep_breakpoints_inserted_p = 1;
836 /* Handle any optimized stores to the inferior NOW... */
837 #ifdef DO_DEFERRED_STORES
841 /* If there were any forks/vforks/execs that were caught and are
842 now to be followed, then do so. */
843 switch (pending_follow.kind)
845 case (TARGET_WAITKIND_FORKED):
846 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
847 follow_fork (inferior_pid, pending_follow.fork_event.child_pid);
850 case (TARGET_WAITKIND_VFORKED):
852 int saw_child_exec = pending_follow.fork_event.saw_child_exec;
854 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
855 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
857 /* Did we follow the child, but not yet see the child's exec event?
858 If so, then it actually ought to be waiting for us; we respond to
859 parent vfork events. We don't actually want to resume the child
860 in this situation; we want to just get its exec event. */
861 if (!saw_child_exec &&
862 (inferior_pid == pending_follow.fork_event.child_pid))
867 case (TARGET_WAITKIND_EXECD):
868 /* If we saw a vfork event but couldn't follow it until we saw
869 an exec, then now might be the time! */
870 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
871 /* follow_exec is called as soon as the exec event is seen. */
878 /* Install inferior's terminal modes. */
879 target_terminal_inferior ();
885 if (use_thread_step_needed && thread_step_needed)
887 /* We stopped on a BPT instruction;
888 don't continue other threads and
889 just step this thread. */
890 thread_step_needed = 0;
892 if (!breakpoint_here_p (read_pc ()))
894 /* Breakpoint deleted: ok to do regular resume
895 where all the threads either step or continue. */
902 warning ("Internal error, changing continue to step.");
903 remove_breakpoints ();
904 breakpoints_inserted = 0;
908 resume_pid = inferior_pid;
913 /* Vanilla resume. */
914 if ((scheduler_mode == schedlock_on) ||
915 (scheduler_mode == schedlock_step && step != 0))
916 resume_pid = inferior_pid;
920 target_resume (resume_pid, step, sig);
923 discard_cleanups (old_cleanups);
927 /* Clear out all variables saying what to do when inferior is continued.
928 First do this, then set the ones you want, then call `proceed'. */
931 clear_proceed_status (void)
934 step_range_start = 0;
936 step_frame_address = 0;
937 step_over_calls = -1;
939 stop_soon_quietly = 0;
940 proceed_to_finish = 0;
941 breakpoint_proceeded = 1; /* We're about to proceed... */
943 /* Discard any remaining commands or status from previous stop. */
944 bpstat_clear (&stop_bpstat);
947 /* Basic routine for continuing the program in various fashions.
949 ADDR is the address to resume at, or -1 for resume where stopped.
950 SIGGNAL is the signal to give it, or 0 for none,
951 or -1 for act according to how it stopped.
952 STEP is nonzero if should trap after one instruction.
953 -1 means return after that and print nothing.
954 You should probably set various step_... variables
955 before calling here, if you are stepping.
957 You should call clear_proceed_status before calling proceed. */
960 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
965 step_start_function = find_pc_function (read_pc ());
969 if (addr == (CORE_ADDR) -1)
971 /* If there is a breakpoint at the address we will resume at,
972 step one instruction before inserting breakpoints
973 so that we do not stop right away (and report a second
974 hit at this breakpoint). */
976 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
979 #ifndef STEP_SKIPS_DELAY
980 #define STEP_SKIPS_DELAY(pc) (0)
981 #define STEP_SKIPS_DELAY_P (0)
983 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
984 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
985 is slow (it needs to read memory from the target). */
986 if (STEP_SKIPS_DELAY_P
987 && breakpoint_here_p (read_pc () + 4)
988 && STEP_SKIPS_DELAY (read_pc ()))
995 /* New address; we don't need to single-step a thread
996 over a breakpoint we just hit, 'cause we aren't
997 continuing from there.
999 It's not worth worrying about the case where a user
1000 asks for a "jump" at the current PC--if they get the
1001 hiccup of re-hiting a hit breakpoint, what else do
1003 thread_step_needed = 0;
1006 #ifdef PREPARE_TO_PROCEED
1007 /* In a multi-threaded task we may select another thread
1008 and then continue or step.
1010 But if the old thread was stopped at a breakpoint, it
1011 will immediately cause another breakpoint stop without
1012 any execution (i.e. it will report a breakpoint hit
1013 incorrectly). So we must step over it first.
1015 PREPARE_TO_PROCEED checks the current thread against the thread
1016 that reported the most recent event. If a step-over is required
1017 it returns TRUE and sets the current thread to the old thread. */
1018 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
1021 thread_step_needed = 1;
1024 #endif /* PREPARE_TO_PROCEED */
1027 if (trap_expected_after_continue)
1029 /* If (step == 0), a trap will be automatically generated after
1030 the first instruction is executed. Force step one
1031 instruction to clear this condition. This should not occur
1032 if step is nonzero, but it is harmless in that case. */
1034 trap_expected_after_continue = 0;
1036 #endif /* HP_OS_BUG */
1039 /* We will get a trace trap after one instruction.
1040 Continue it automatically and insert breakpoints then. */
1044 int temp = insert_breakpoints ();
1047 print_sys_errmsg ("ptrace", temp);
1048 error ("Cannot insert breakpoints.\n\
1049 The same program may be running in another process.");
1052 breakpoints_inserted = 1;
1055 if (siggnal != TARGET_SIGNAL_DEFAULT)
1056 stop_signal = siggnal;
1057 /* If this signal should not be seen by program,
1058 give it zero. Used for debugging signals. */
1059 else if (!signal_program[stop_signal])
1060 stop_signal = TARGET_SIGNAL_0;
1062 annotate_starting ();
1064 /* Make sure that output from GDB appears before output from the
1066 gdb_flush (gdb_stdout);
1068 /* Resume inferior. */
1069 resume (oneproc || step || bpstat_should_step (), stop_signal);
1071 /* Wait for it to stop (if not standalone)
1072 and in any case decode why it stopped, and act accordingly. */
1073 /* Do this only if we are not using the event loop, or if the target
1074 does not support asynchronous execution. */
1075 if (!event_loop_p || !target_can_async_p ())
1077 wait_for_inferior ();
1082 /* Record the pc and sp of the program the last time it stopped.
1083 These are just used internally by wait_for_inferior, but need
1084 to be preserved over calls to it and cleared when the inferior
1086 static CORE_ADDR prev_pc;
1087 static CORE_ADDR prev_func_start;
1088 static char *prev_func_name;
1091 /* Start remote-debugging of a machine over a serial link. */
1096 init_thread_list ();
1097 init_wait_for_inferior ();
1098 stop_soon_quietly = 1;
1101 /* Always go on waiting for the target, regardless of the mode. */
1102 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1103 indicate th wait_for_inferior that a target should timeout if
1104 nothing is returned (instead of just blocking). Because of this,
1105 targets expecting an immediate response need to, internally, set
1106 things up so that the target_wait() is forced to eventually
1108 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1109 differentiate to its caller what the state of the target is after
1110 the initial open has been performed. Here we're assuming that
1111 the target has stopped. It should be possible to eventually have
1112 target_open() return to the caller an indication that the target
1113 is currently running and GDB state should be set to the same as
1114 for an async run. */
1115 wait_for_inferior ();
1119 /* Initialize static vars when a new inferior begins. */
1122 init_wait_for_inferior (void)
1124 /* These are meaningless until the first time through wait_for_inferior. */
1126 prev_func_start = 0;
1127 prev_func_name = NULL;
1130 trap_expected_after_continue = 0;
1132 breakpoints_inserted = 0;
1133 breakpoint_init_inferior (inf_starting);
1135 /* Don't confuse first call to proceed(). */
1136 stop_signal = TARGET_SIGNAL_0;
1138 /* The first resume is not following a fork/vfork/exec. */
1139 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
1140 pending_follow.fork_event.saw_parent_fork = 0;
1141 pending_follow.fork_event.saw_child_fork = 0;
1142 pending_follow.fork_event.saw_child_exec = 0;
1144 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1145 number_of_threads_in_syscalls = 0;
1147 clear_proceed_status ();
1151 delete_breakpoint_current_contents (void *arg)
1153 struct breakpoint **breakpointp = (struct breakpoint **) arg;
1154 if (*breakpointp != NULL)
1156 delete_breakpoint (*breakpointp);
1157 *breakpointp = NULL;
1161 /* This enum encodes possible reasons for doing a target_wait, so that
1162 wfi can call target_wait in one place. (Ultimately the call will be
1163 moved out of the infinite loop entirely.) */
1167 infwait_normal_state,
1168 infwait_thread_hop_state,
1169 infwait_nullified_state,
1170 infwait_nonstep_watch_state
1173 /* Why did the inferior stop? Used to print the appropriate messages
1174 to the interface from within handle_inferior_event(). */
1175 enum inferior_stop_reason
1177 /* We don't know why. */
1179 /* Step, next, nexti, stepi finished. */
1181 /* Found breakpoint. */
1183 /* Inferior terminated by signal. */
1185 /* Inferior exited. */
1187 /* Inferior received signal, and user asked to be notified. */
1191 /* This structure contains what used to be local variables in
1192 wait_for_inferior. Probably many of them can return to being
1193 locals in handle_inferior_event. */
1195 struct execution_control_state
1197 struct target_waitstatus ws;
1198 struct target_waitstatus *wp;
1201 CORE_ADDR stop_func_start;
1202 CORE_ADDR stop_func_end;
1203 char *stop_func_name;
1204 struct symtab_and_line sal;
1205 int remove_breakpoints_on_following_step;
1207 struct symtab *current_symtab;
1208 int handling_longjmp; /* FIXME */
1210 int saved_inferior_pid;
1212 int stepping_through_solib_after_catch;
1213 bpstat stepping_through_solib_catchpoints;
1214 int enable_hw_watchpoints_after_wait;
1215 int stepping_through_sigtramp;
1216 int new_thread_event;
1217 struct target_waitstatus tmpstatus;
1218 enum infwait_states infwait_state;
1223 void init_execution_control_state (struct execution_control_state * ecs);
1225 void handle_inferior_event (struct execution_control_state * ecs);
1227 static void check_sigtramp2 (struct execution_control_state *ecs);
1228 static void step_into_function (struct execution_control_state *ecs);
1229 static void step_over_function (struct execution_control_state *ecs);
1230 static void stop_stepping (struct execution_control_state *ecs);
1231 static void prepare_to_wait (struct execution_control_state *ecs);
1232 static void keep_going (struct execution_control_state *ecs);
1233 static void print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info);
1235 /* Wait for control to return from inferior to debugger.
1236 If inferior gets a signal, we may decide to start it up again
1237 instead of returning. That is why there is a loop in this function.
1238 When this function actually returns it means the inferior
1239 should be left stopped and GDB should read more commands. */
1242 wait_for_inferior (void)
1244 struct cleanup *old_cleanups;
1245 struct execution_control_state ecss;
1246 struct execution_control_state *ecs;
1248 old_cleanups = make_cleanup (delete_breakpoint_current_contents,
1249 &step_resume_breakpoint);
1250 make_cleanup (delete_breakpoint_current_contents,
1251 &through_sigtramp_breakpoint);
1253 /* wfi still stays in a loop, so it's OK just to take the address of
1254 a local to get the ecs pointer. */
1257 /* Fill in with reasonable starting values. */
1258 init_execution_control_state (ecs);
1260 thread_step_needed = 0;
1262 /* We'll update this if & when we switch to a new thread. */
1263 previous_inferior_pid = inferior_pid;
1265 overlay_cache_invalid = 1;
1267 /* We have to invalidate the registers BEFORE calling target_wait
1268 because they can be loaded from the target while in target_wait.
1269 This makes remote debugging a bit more efficient for those
1270 targets that provide critical registers as part of their normal
1271 status mechanism. */
1273 registers_changed ();
1277 if (target_wait_hook)
1278 ecs->pid = target_wait_hook (ecs->waiton_pid, ecs->wp);
1280 ecs->pid = target_wait (ecs->waiton_pid, ecs->wp);
1282 /* Now figure out what to do with the result of the result. */
1283 handle_inferior_event (ecs);
1285 if (!ecs->wait_some_more)
1288 do_cleanups (old_cleanups);
1291 /* Asynchronous version of wait_for_inferior. It is called by the
1292 event loop whenever a change of state is detected on the file
1293 descriptor corresponding to the target. It can be called more than
1294 once to complete a single execution command. In such cases we need
1295 to keep the state in a global variable ASYNC_ECSS. If it is the
1296 last time that this function is called for a single execution
1297 command, then report to the user that the inferior has stopped, and
1298 do the necessary cleanups. */
1300 struct execution_control_state async_ecss;
1301 struct execution_control_state *async_ecs;
1304 fetch_inferior_event (client_data)
1307 static struct cleanup *old_cleanups;
1309 async_ecs = &async_ecss;
1311 if (!async_ecs->wait_some_more)
1313 old_cleanups = make_exec_cleanup (delete_breakpoint_current_contents,
1314 &step_resume_breakpoint);
1315 make_exec_cleanup (delete_breakpoint_current_contents,
1316 &through_sigtramp_breakpoint);
1318 /* Fill in with reasonable starting values. */
1319 init_execution_control_state (async_ecs);
1321 thread_step_needed = 0;
1323 /* We'll update this if & when we switch to a new thread. */
1324 previous_inferior_pid = inferior_pid;
1326 overlay_cache_invalid = 1;
1328 /* We have to invalidate the registers BEFORE calling target_wait
1329 because they can be loaded from the target while in target_wait.
1330 This makes remote debugging a bit more efficient for those
1331 targets that provide critical registers as part of their normal
1332 status mechanism. */
1334 registers_changed ();
1337 if (target_wait_hook)
1338 async_ecs->pid = target_wait_hook (async_ecs->waiton_pid, async_ecs->wp);
1340 async_ecs->pid = target_wait (async_ecs->waiton_pid, async_ecs->wp);
1342 /* Now figure out what to do with the result of the result. */
1343 handle_inferior_event (async_ecs);
1345 if (!async_ecs->wait_some_more)
1347 /* Do only the cleanups that have been added by this
1348 function. Let the continuations for the commands do the rest,
1349 if there are any. */
1350 do_exec_cleanups (old_cleanups);
1352 if (step_multi && stop_step)
1353 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
1355 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1359 /* Prepare an execution control state for looping through a
1360 wait_for_inferior-type loop. */
1363 init_execution_control_state (struct execution_control_state *ecs)
1365 /* ecs->another_trap? */
1366 ecs->random_signal = 0;
1367 ecs->remove_breakpoints_on_following_step = 0;
1368 ecs->handling_longjmp = 0; /* FIXME */
1369 ecs->update_step_sp = 0;
1370 ecs->stepping_through_solib_after_catch = 0;
1371 ecs->stepping_through_solib_catchpoints = NULL;
1372 ecs->enable_hw_watchpoints_after_wait = 0;
1373 ecs->stepping_through_sigtramp = 0;
1374 ecs->sal = find_pc_line (prev_pc, 0);
1375 ecs->current_line = ecs->sal.line;
1376 ecs->current_symtab = ecs->sal.symtab;
1377 ecs->infwait_state = infwait_normal_state;
1378 ecs->waiton_pid = -1;
1379 ecs->wp = &(ecs->ws);
1382 /* Call this function before setting step_resume_breakpoint, as a
1383 sanity check. There should never be more than one step-resume
1384 breakpoint per thread, so we should never be setting a new
1385 step_resume_breakpoint when one is already active. */
1387 check_for_old_step_resume_breakpoint (void)
1389 if (step_resume_breakpoint)
1390 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1393 /* Given an execution control state that has been freshly filled in
1394 by an event from the inferior, figure out what it means and take
1395 appropriate action. */
1398 handle_inferior_event (struct execution_control_state *ecs)
1401 int stepped_after_stopped_by_watchpoint;
1403 /* Keep this extra brace for now, minimizes diffs. */
1405 switch (ecs->infwait_state)
1407 case infwait_normal_state:
1408 /* Since we've done a wait, we have a new event. Don't
1409 carry over any expectations about needing to step over a
1411 thread_step_needed = 0;
1413 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1414 is serviced in this loop, below. */
1415 if (ecs->enable_hw_watchpoints_after_wait)
1417 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid);
1418 ecs->enable_hw_watchpoints_after_wait = 0;
1420 stepped_after_stopped_by_watchpoint = 0;
1423 case infwait_thread_hop_state:
1424 insert_breakpoints ();
1426 /* We need to restart all the threads now,
1427 * unles we're running in scheduler-locked mode.
1428 * FIXME: shouldn't we look at currently_stepping ()?
1430 if (scheduler_mode == schedlock_on)
1431 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1433 target_resume (-1, 0, TARGET_SIGNAL_0);
1434 ecs->infwait_state = infwait_normal_state;
1435 prepare_to_wait (ecs);
1438 case infwait_nullified_state:
1441 case infwait_nonstep_watch_state:
1442 insert_breakpoints ();
1444 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1445 handle things like signals arriving and other things happening
1446 in combination correctly? */
1447 stepped_after_stopped_by_watchpoint = 1;
1450 ecs->infwait_state = infwait_normal_state;
1452 flush_cached_frames ();
1454 /* If it's a new process, add it to the thread database */
1456 ecs->new_thread_event = ((ecs->pid != inferior_pid) && !in_thread_list (ecs->pid));
1458 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1459 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
1460 && ecs->new_thread_event)
1462 add_thread (ecs->pid);
1465 ui_out_text (uiout, "[New ");
1466 ui_out_text (uiout, target_pid_or_tid_to_str (ecs->pid));
1467 ui_out_text (uiout, "]\n");
1469 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs->pid));
1473 /* NOTE: This block is ONLY meant to be invoked in case of a
1474 "thread creation event"! If it is invoked for any other
1475 sort of event (such as a new thread landing on a breakpoint),
1476 the event will be discarded, which is almost certainly
1479 To avoid this, the low-level module (eg. target_wait)
1480 should call in_thread_list and add_thread, so that the
1481 new thread is known by the time we get here. */
1483 /* We may want to consider not doing a resume here in order
1484 to give the user a chance to play with the new thread.
1485 It might be good to make that a user-settable option. */
1487 /* At this point, all threads are stopped (happens
1488 automatically in either the OS or the native code).
1489 Therefore we need to continue all threads in order to
1492 target_resume (-1, 0, TARGET_SIGNAL_0);
1493 prepare_to_wait (ecs);
1498 switch (ecs->ws.kind)
1500 case TARGET_WAITKIND_LOADED:
1501 /* Ignore gracefully during startup of the inferior, as it
1502 might be the shell which has just loaded some objects,
1503 otherwise add the symbols for the newly loaded objects. */
1505 if (!stop_soon_quietly)
1507 /* Remove breakpoints, SOLIB_ADD might adjust
1508 breakpoint addresses via breakpoint_re_set. */
1509 if (breakpoints_inserted)
1510 remove_breakpoints ();
1512 /* Check for any newly added shared libraries if we're
1513 supposed to be adding them automatically. */
1516 /* Switch terminal for any messages produced by
1517 breakpoint_re_set. */
1518 target_terminal_ours_for_output ();
1519 SOLIB_ADD (NULL, 0, NULL);
1520 target_terminal_inferior ();
1523 /* Reinsert breakpoints and continue. */
1524 if (breakpoints_inserted)
1525 insert_breakpoints ();
1528 resume (0, TARGET_SIGNAL_0);
1529 prepare_to_wait (ecs);
1532 case TARGET_WAITKIND_SPURIOUS:
1533 resume (0, TARGET_SIGNAL_0);
1534 prepare_to_wait (ecs);
1537 case TARGET_WAITKIND_EXITED:
1538 target_terminal_ours (); /* Must do this before mourn anyway */
1539 print_stop_reason (EXITED, ecs->ws.value.integer);
1541 /* Record the exit code in the convenience variable $_exitcode, so
1542 that the user can inspect this again later. */
1543 set_internalvar (lookup_internalvar ("_exitcode"),
1544 value_from_longest (builtin_type_int,
1545 (LONGEST) ecs->ws.value.integer));
1546 gdb_flush (gdb_stdout);
1547 target_mourn_inferior ();
1548 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P */
1549 stop_print_frame = 0;
1550 stop_stepping (ecs);
1553 case TARGET_WAITKIND_SIGNALLED:
1554 stop_print_frame = 0;
1555 stop_signal = ecs->ws.value.sig;
1556 target_terminal_ours (); /* Must do this before mourn anyway */
1558 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1559 mean it is already dead? This has been here since GDB 2.8, so
1560 perhaps it means rms didn't understand unix waitstatuses?
1561 For the moment I'm just kludging around this in remote.c
1562 rather than trying to change it here --kingdon, 5 Dec 1994. */
1563 target_kill (); /* kill mourns as well */
1565 print_stop_reason (SIGNAL_EXITED, stop_signal);
1566 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P */
1567 stop_stepping (ecs);
1570 /* The following are the only cases in which we keep going;
1571 the above cases end in a continue or goto. */
1572 case TARGET_WAITKIND_FORKED:
1573 stop_signal = TARGET_SIGNAL_TRAP;
1574 pending_follow.kind = ecs->ws.kind;
1576 /* Ignore fork events reported for the parent; we're only
1577 interested in reacting to forks of the child. Note that
1578 we expect the child's fork event to be available if we
1579 waited for it now. */
1580 if (inferior_pid == ecs->pid)
1582 pending_follow.fork_event.saw_parent_fork = 1;
1583 pending_follow.fork_event.parent_pid = ecs->pid;
1584 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1585 prepare_to_wait (ecs);
1590 pending_follow.fork_event.saw_child_fork = 1;
1591 pending_follow.fork_event.child_pid = ecs->pid;
1592 pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid;
1595 stop_pc = read_pc_pid (ecs->pid);
1596 ecs->saved_inferior_pid = inferior_pid;
1597 inferior_pid = ecs->pid;
1598 stop_bpstat = bpstat_stop_status (&stop_pc, currently_stepping (ecs));
1599 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1600 inferior_pid = ecs->saved_inferior_pid;
1601 goto process_event_stop_test;
1603 /* If this a platform which doesn't allow a debugger to touch a
1604 vfork'd inferior until after it exec's, then we'd best keep
1605 our fingers entirely off the inferior, other than continuing
1606 it. This has the unfortunate side-effect that catchpoints
1607 of vforks will be ignored. But since the platform doesn't
1608 allow the inferior be touched at vfork time, there's really
1610 case TARGET_WAITKIND_VFORKED:
1611 stop_signal = TARGET_SIGNAL_TRAP;
1612 pending_follow.kind = ecs->ws.kind;
1614 /* Is this a vfork of the parent? If so, then give any
1615 vfork catchpoints a chance to trigger now. (It's
1616 dangerous to do so if the child canot be touched until
1617 it execs, and the child has not yet exec'd. We probably
1618 should warn the user to that effect when the catchpoint
1620 if (ecs->pid == inferior_pid)
1622 pending_follow.fork_event.saw_parent_fork = 1;
1623 pending_follow.fork_event.parent_pid = ecs->pid;
1624 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1627 /* If we've seen the child's vfork event but cannot really touch
1628 the child until it execs, then we must continue the child now.
1629 Else, give any vfork catchpoints a chance to trigger now. */
1632 pending_follow.fork_event.saw_child_fork = 1;
1633 pending_follow.fork_event.child_pid = ecs->pid;
1634 pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid;
1635 target_post_startup_inferior (pending_follow.fork_event.child_pid);
1636 follow_vfork_when_exec = !target_can_follow_vfork_prior_to_exec ();
1637 if (follow_vfork_when_exec)
1639 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1640 prepare_to_wait (ecs);
1645 stop_pc = read_pc ();
1646 stop_bpstat = bpstat_stop_status (&stop_pc, currently_stepping (ecs));
1647 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1648 goto process_event_stop_test;
1650 case TARGET_WAITKIND_EXECD:
1651 stop_signal = TARGET_SIGNAL_TRAP;
1653 /* Is this a target which reports multiple exec events per actual
1654 call to exec()? (HP-UX using ptrace does, for example.) If so,
1655 ignore all but the last one. Just resume the exec'r, and wait
1656 for the next exec event. */
1657 if (inferior_ignoring_leading_exec_events)
1659 inferior_ignoring_leading_exec_events--;
1660 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1661 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.parent_pid);
1662 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1663 prepare_to_wait (ecs);
1666 inferior_ignoring_leading_exec_events =
1667 target_reported_exec_events_per_exec_call () - 1;
1669 pending_follow.execd_pathname =
1670 savestring (ecs->ws.value.execd_pathname,
1671 strlen (ecs->ws.value.execd_pathname));
1673 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1674 child of a vfork exec?
1676 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1677 HP-UX, events associated with a vforking inferior come in
1678 threes: a vfork event for the child (always first), followed
1679 a vfork event for the parent and an exec event for the child.
1680 The latter two can come in either order.
1682 If we get the parent vfork event first, life's good: We follow
1683 either the parent or child, and then the child's exec event is
1686 But if we get the child's exec event first, then we delay
1687 responding to it until we handle the parent's vfork. Because,
1688 otherwise we can't satisfy a "catch vfork". */
1689 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1691 pending_follow.fork_event.saw_child_exec = 1;
1693 /* On some targets, the child must be resumed before
1694 the parent vfork event is delivered. A single-step
1696 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1697 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1698 /* We expect the parent vfork event to be available now. */
1699 prepare_to_wait (ecs);
1703 /* This causes the eventpoints and symbol table to be reset. Must
1704 do this now, before trying to determine whether to stop. */
1705 follow_exec (inferior_pid, pending_follow.execd_pathname);
1706 free (pending_follow.execd_pathname);
1708 stop_pc = read_pc_pid (ecs->pid);
1709 ecs->saved_inferior_pid = inferior_pid;
1710 inferior_pid = ecs->pid;
1711 stop_bpstat = bpstat_stop_status (&stop_pc, currently_stepping (ecs));
1712 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1713 inferior_pid = ecs->saved_inferior_pid;
1714 goto process_event_stop_test;
1716 /* These syscall events are returned on HP-UX, as part of its
1717 implementation of page-protection-based "hardware" watchpoints.
1718 HP-UX has unfortunate interactions between page-protections and
1719 some system calls. Our solution is to disable hardware watches
1720 when a system call is entered, and reenable them when the syscall
1721 completes. The downside of this is that we may miss the precise
1722 point at which a watched piece of memory is modified. "Oh well."
1724 Note that we may have multiple threads running, which may each
1725 enter syscalls at roughly the same time. Since we don't have a
1726 good notion currently of whether a watched piece of memory is
1727 thread-private, we'd best not have any page-protections active
1728 when any thread is in a syscall. Thus, we only want to reenable
1729 hardware watches when no threads are in a syscall.
1731 Also, be careful not to try to gather much state about a thread
1732 that's in a syscall. It's frequently a losing proposition. */
1733 case TARGET_WAITKIND_SYSCALL_ENTRY:
1734 number_of_threads_in_syscalls++;
1735 if (number_of_threads_in_syscalls == 1)
1737 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid);
1739 resume (0, TARGET_SIGNAL_0);
1740 prepare_to_wait (ecs);
1743 /* Before examining the threads further, step this thread to
1744 get it entirely out of the syscall. (We get notice of the
1745 event when the thread is just on the verge of exiting a
1746 syscall. Stepping one instruction seems to get it back
1749 Note that although the logical place to reenable h/w watches
1750 is here, we cannot. We cannot reenable them before stepping
1751 the thread (this causes the next wait on the thread to hang).
1753 Nor can we enable them after stepping until we've done a wait.
1754 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1755 here, which will be serviced immediately after the target
1757 case TARGET_WAITKIND_SYSCALL_RETURN:
1758 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1760 if (number_of_threads_in_syscalls > 0)
1762 number_of_threads_in_syscalls--;
1763 ecs->enable_hw_watchpoints_after_wait =
1764 (number_of_threads_in_syscalls == 0);
1766 prepare_to_wait (ecs);
1769 case TARGET_WAITKIND_STOPPED:
1770 stop_signal = ecs->ws.value.sig;
1773 /* We had an event in the inferior, but we are not interested
1774 in handling it at this level. The lower layers have already
1775 done what needs to be done, if anything. This case can
1776 occur only when the target is async or extended-async. One
1777 of the circumstamces for this to happen is when the
1778 inferior produces output for the console. The inferior has
1779 not stopped, and we are ignoring the event. */
1780 case TARGET_WAITKIND_IGNORE:
1781 ecs->wait_some_more = 1;
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 /* Caution: it may happen that the new thread (or the old one!)
1930 is not in the thread list. In this case we must not attempt
1931 to "switch context", or we run the risk that our context may
1932 be lost. This may happen as a result of the target module
1933 mishandling thread creation. */
1935 if (in_thread_list (inferior_pid) && in_thread_list (ecs->pid))
1936 { /* Perform infrun state context switch: */
1937 /* Save infrun state for the old thread. */
1938 save_infrun_state (inferior_pid, prev_pc,
1939 prev_func_start, prev_func_name,
1940 trap_expected, step_resume_breakpoint,
1941 through_sigtramp_breakpoint,
1942 step_range_start, step_range_end,
1943 step_frame_address, ecs->handling_longjmp,
1945 ecs->stepping_through_solib_after_catch,
1946 ecs->stepping_through_solib_catchpoints,
1947 ecs->stepping_through_sigtramp);
1949 /* Load infrun state for the new thread. */
1950 load_infrun_state (ecs->pid, &prev_pc,
1951 &prev_func_start, &prev_func_name,
1952 &trap_expected, &step_resume_breakpoint,
1953 &through_sigtramp_breakpoint,
1954 &step_range_start, &step_range_end,
1955 &step_frame_address, &ecs->handling_longjmp,
1957 &ecs->stepping_through_solib_after_catch,
1958 &ecs->stepping_through_solib_catchpoints,
1959 &ecs->stepping_through_sigtramp);
1962 inferior_pid = ecs->pid;
1965 context_hook (pid_to_thread_id (ecs->pid));
1967 flush_cached_frames ();
1970 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1972 /* Pull the single step breakpoints out of the target. */
1973 SOFTWARE_SINGLE_STEP (0, 0);
1974 singlestep_breakpoints_inserted_p = 0;
1977 /* If PC is pointing at a nullified instruction, then step beyond
1978 it so that the user won't be confused when GDB appears to be ready
1981 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1982 if (INSTRUCTION_NULLIFIED)
1984 registers_changed ();
1985 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1987 /* We may have received a signal that we want to pass to
1988 the inferior; therefore, we must not clobber the waitstatus
1991 ecs->infwait_state = infwait_nullified_state;
1992 ecs->waiton_pid = ecs->pid;
1993 ecs->wp = &(ecs->tmpstatus);
1994 prepare_to_wait (ecs);
1998 /* It may not be necessary to disable the watchpoint to stop over
1999 it. For example, the PA can (with some kernel cooperation)
2000 single step over a watchpoint without disabling the watchpoint. */
2001 if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
2004 prepare_to_wait (ecs);
2008 /* It is far more common to need to disable a watchpoint to step
2009 the inferior over it. FIXME. What else might a debug
2010 register or page protection watchpoint scheme need here? */
2011 if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
2013 /* At this point, we are stopped at an instruction which has
2014 attempted to write to a piece of memory under control of
2015 a watchpoint. The instruction hasn't actually executed
2016 yet. If we were to evaluate the watchpoint expression
2017 now, we would get the old value, and therefore no change
2018 would seem to have occurred.
2020 In order to make watchpoints work `right', we really need
2021 to complete the memory write, and then evaluate the
2022 watchpoint expression. The following code does that by
2023 removing the watchpoint (actually, all watchpoints and
2024 breakpoints), single-stepping the target, re-inserting
2025 watchpoints, and then falling through to let normal
2026 single-step processing handle proceed. Since this
2027 includes evaluating watchpoints, things will come to a
2028 stop in the correct manner. */
2030 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
2032 remove_breakpoints ();
2033 registers_changed ();
2034 target_resume (ecs->pid, 1, TARGET_SIGNAL_0); /* Single step */
2036 ecs->waiton_pid = ecs->pid;
2037 ecs->wp = &(ecs->ws);
2038 ecs->infwait_state = infwait_nonstep_watch_state;
2039 prepare_to_wait (ecs);
2043 /* It may be possible to simply continue after a watchpoint. */
2044 if (HAVE_CONTINUABLE_WATCHPOINT)
2045 STOPPED_BY_WATCHPOINT (ecs->ws);
2047 ecs->stop_func_start = 0;
2048 ecs->stop_func_end = 0;
2049 ecs->stop_func_name = 0;
2050 /* Don't care about return value; stop_func_start and stop_func_name
2051 will both be 0 if it doesn't work. */
2052 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2053 &ecs->stop_func_start, &ecs->stop_func_end);
2054 ecs->stop_func_start += FUNCTION_START_OFFSET;
2055 ecs->another_trap = 0;
2056 bpstat_clear (&stop_bpstat);
2058 stop_stack_dummy = 0;
2059 stop_print_frame = 1;
2060 ecs->random_signal = 0;
2061 stopped_by_random_signal = 0;
2062 breakpoints_failed = 0;
2064 /* Look at the cause of the stop, and decide what to do.
2065 The alternatives are:
2066 1) break; to really stop and return to the debugger,
2067 2) drop through to start up again
2068 (set ecs->another_trap to 1 to single step once)
2069 3) set ecs->random_signal to 1, and the decision between 1 and 2
2070 will be made according to the signal handling tables. */
2072 /* First, distinguish signals caused by the debugger from signals
2073 that have to do with the program's own actions.
2074 Note that breakpoint insns may cause SIGTRAP or SIGILL
2075 or SIGEMT, depending on the operating system version.
2076 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2077 and change it to SIGTRAP. */
2079 if (stop_signal == TARGET_SIGNAL_TRAP
2080 || (breakpoints_inserted &&
2081 (stop_signal == TARGET_SIGNAL_ILL
2082 || stop_signal == TARGET_SIGNAL_EMT
2084 || stop_soon_quietly)
2086 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
2088 stop_print_frame = 0;
2089 stop_stepping (ecs);
2092 if (stop_soon_quietly)
2094 stop_stepping (ecs);
2098 /* Don't even think about breakpoints
2099 if just proceeded over a breakpoint.
2101 However, if we are trying to proceed over a breakpoint
2102 and end up in sigtramp, then through_sigtramp_breakpoint
2103 will be set and we should check whether we've hit the
2105 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
2106 && through_sigtramp_breakpoint == NULL)
2107 bpstat_clear (&stop_bpstat);
2110 /* See if there is a breakpoint at the current PC. */
2111 stop_bpstat = bpstat_stop_status
2113 /* Pass TRUE if our reason for stopping is something other
2114 than hitting a breakpoint. We do this by checking that
2115 1) stepping is going on and 2) we didn't hit a breakpoint
2116 in a signal handler without an intervening stop in
2117 sigtramp, which is detected by a new stack pointer value
2118 below any usual function calling stack adjustments. */
2119 (currently_stepping (ecs)
2121 && INNER_THAN (read_sp (), (step_sp - 16))))
2123 /* Following in case break condition called a
2125 stop_print_frame = 1;
2128 if (stop_signal == TARGET_SIGNAL_TRAP)
2130 = !(bpstat_explains_signal (stop_bpstat)
2132 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2133 && PC_IN_CALL_DUMMY (stop_pc, read_sp (),
2134 FRAME_FP (get_current_frame ())))
2135 || (step_range_end && step_resume_breakpoint == NULL));
2140 = !(bpstat_explains_signal (stop_bpstat)
2141 /* End of a stack dummy. Some systems (e.g. Sony
2142 news) give another signal besides SIGTRAP, so
2143 check here as well as above. */
2144 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2145 && PC_IN_CALL_DUMMY (stop_pc, read_sp (),
2146 FRAME_FP (get_current_frame ())))
2148 if (!ecs->random_signal)
2149 stop_signal = TARGET_SIGNAL_TRAP;
2153 /* When we reach this point, we've pretty much decided
2154 that the reason for stopping must've been a random
2155 (unexpected) signal. */
2158 ecs->random_signal = 1;
2159 /* If a fork, vfork or exec event was seen, then there are two
2160 possible responses we can make:
2162 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2163 then we must stop now and issue a prompt. We will resume
2164 the inferior when the user tells us to.
2165 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2166 then we must resume the inferior now and keep checking.
2168 In either case, we must take appropriate steps to "follow" the
2169 the fork/vfork/exec when the inferior is resumed. For example,
2170 if follow-fork-mode is "child", then we must detach from the
2171 parent inferior and follow the new child inferior.
2173 In either case, setting pending_follow causes the next resume()
2174 to take the appropriate following action. */
2175 process_event_stop_test:
2176 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
2178 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2181 stop_signal = TARGET_SIGNAL_0;
2186 else if (ecs->ws.kind == TARGET_WAITKIND_VFORKED)
2188 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2190 stop_signal = TARGET_SIGNAL_0;
2195 else if (ecs->ws.kind == TARGET_WAITKIND_EXECD)
2197 pending_follow.kind = ecs->ws.kind;
2198 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2201 stop_signal = TARGET_SIGNAL_0;
2207 /* For the program's own signals, act according to
2208 the signal handling tables. */
2210 if (ecs->random_signal)
2212 /* Signal not for debugging purposes. */
2215 stopped_by_random_signal = 1;
2217 if (signal_print[stop_signal])
2220 target_terminal_ours_for_output ();
2221 print_stop_reason (SIGNAL_RECEIVED, stop_signal);
2223 if (signal_stop[stop_signal])
2225 stop_stepping (ecs);
2228 /* If not going to stop, give terminal back
2229 if we took it away. */
2231 target_terminal_inferior ();
2233 /* Clear the signal if it should not be passed. */
2234 if (signal_program[stop_signal] == 0)
2235 stop_signal = TARGET_SIGNAL_0;
2237 /* I'm not sure whether this needs to be check_sigtramp2 or
2238 whether it could/should be keep_going.
2240 This used to jump to step_over_function if we are stepping,
2243 Suppose the user does a `next' over a function call, and while
2244 that call is in progress, the inferior receives a signal for
2245 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2246 that case, when we reach this point, there is already a
2247 step-resume breakpoint established, right where it should be:
2248 immediately after the function call the user is "next"-ing
2249 over. If we call step_over_function now, two bad things
2252 - we'll create a new breakpoint, at wherever the current
2253 frame's return address happens to be. That could be
2254 anywhere, depending on what function call happens to be on
2255 the top of the stack at that point. Point is, it's probably
2256 not where we need it.
2258 - the existing step-resume breakpoint (which is at the correct
2259 address) will get orphaned: step_resume_breakpoint will point
2260 to the new breakpoint, and the old step-resume breakpoint
2261 will never be cleaned up.
2263 The old behavior was meant to help HP-UX single-step out of
2264 sigtramps. It would place the new breakpoint at prev_pc, which
2265 was certainly wrong. I don't know the details there, so fixing
2266 this probably breaks that. As with anything else, it's up to
2267 the HP-UX maintainer to furnish a fix that doesn't break other
2268 platforms. --JimB, 20 May 1999 */
2269 check_sigtramp2 (ecs);
2272 /* Handle cases caused by hitting a breakpoint. */
2274 CORE_ADDR jmp_buf_pc;
2275 struct bpstat_what what;
2277 what = bpstat_what (stop_bpstat);
2279 if (what.call_dummy)
2281 stop_stack_dummy = 1;
2283 trap_expected_after_continue = 1;
2287 switch (what.main_action)
2289 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
2290 /* If we hit the breakpoint at longjmp, disable it for the
2291 duration of this command. Then, install a temporary
2292 breakpoint at the target of the jmp_buf. */
2293 disable_longjmp_breakpoint ();
2294 remove_breakpoints ();
2295 breakpoints_inserted = 0;
2296 if (!GET_LONGJMP_TARGET (&jmp_buf_pc))
2302 /* Need to blow away step-resume breakpoint, as it
2303 interferes with us */
2304 if (step_resume_breakpoint != NULL)
2306 delete_breakpoint (step_resume_breakpoint);
2307 step_resume_breakpoint = NULL;
2309 /* Not sure whether we need to blow this away too, but probably
2310 it is like the step-resume breakpoint. */
2311 if (through_sigtramp_breakpoint != NULL)
2313 delete_breakpoint (through_sigtramp_breakpoint);
2314 through_sigtramp_breakpoint = NULL;
2318 /* FIXME - Need to implement nested temporary breakpoints */
2319 if (step_over_calls > 0)
2320 set_longjmp_resume_breakpoint (jmp_buf_pc,
2321 get_current_frame ());
2324 set_longjmp_resume_breakpoint (jmp_buf_pc, NULL);
2325 ecs->handling_longjmp = 1; /* FIXME */
2329 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
2330 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
2331 remove_breakpoints ();
2332 breakpoints_inserted = 0;
2334 /* FIXME - Need to implement nested temporary breakpoints */
2336 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2337 step_frame_address)))
2339 ecs->another_trap = 1;
2344 disable_longjmp_breakpoint ();
2345 ecs->handling_longjmp = 0; /* FIXME */
2346 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
2348 /* else fallthrough */
2350 case BPSTAT_WHAT_SINGLE:
2351 if (breakpoints_inserted)
2353 thread_step_needed = 1;
2354 remove_breakpoints ();
2356 breakpoints_inserted = 0;
2357 ecs->another_trap = 1;
2358 /* Still need to check other stuff, at least the case
2359 where we are stepping and step out of the right range. */
2362 case BPSTAT_WHAT_STOP_NOISY:
2363 stop_print_frame = 1;
2365 /* We are about to nuke the step_resume_breakpoint and
2366 through_sigtramp_breakpoint via the cleanup chain, so
2367 no need to worry about it here. */
2369 stop_stepping (ecs);
2372 case BPSTAT_WHAT_STOP_SILENT:
2373 stop_print_frame = 0;
2375 /* We are about to nuke the step_resume_breakpoint and
2376 through_sigtramp_breakpoint via the cleanup chain, so
2377 no need to worry about it here. */
2379 stop_stepping (ecs);
2382 case BPSTAT_WHAT_STEP_RESUME:
2383 /* This proably demands a more elegant solution, but, yeah
2386 This function's use of the simple variable
2387 step_resume_breakpoint doesn't seem to accomodate
2388 simultaneously active step-resume bp's, although the
2389 breakpoint list certainly can.
2391 If we reach here and step_resume_breakpoint is already
2392 NULL, then apparently we have multiple active
2393 step-resume bp's. We'll just delete the breakpoint we
2394 stopped at, and carry on.
2396 Correction: what the code currently does is delete a
2397 step-resume bp, but it makes no effort to ensure that
2398 the one deleted is the one currently stopped at. MVS */
2400 if (step_resume_breakpoint == NULL)
2402 step_resume_breakpoint =
2403 bpstat_find_step_resume_breakpoint (stop_bpstat);
2405 delete_breakpoint (step_resume_breakpoint);
2406 step_resume_breakpoint = NULL;
2409 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2410 if (through_sigtramp_breakpoint)
2411 delete_breakpoint (through_sigtramp_breakpoint);
2412 through_sigtramp_breakpoint = NULL;
2414 /* If were waiting for a trap, hitting the step_resume_break
2415 doesn't count as getting it. */
2417 ecs->another_trap = 1;
2420 case BPSTAT_WHAT_CHECK_SHLIBS:
2421 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2424 /* Remove breakpoints, we eventually want to step over the
2425 shlib event breakpoint, and SOLIB_ADD might adjust
2426 breakpoint addresses via breakpoint_re_set. */
2427 if (breakpoints_inserted)
2428 remove_breakpoints ();
2429 breakpoints_inserted = 0;
2431 /* Check for any newly added shared libraries if we're
2432 supposed to be adding them automatically. */
2435 /* Switch terminal for any messages produced by
2436 breakpoint_re_set. */
2437 target_terminal_ours_for_output ();
2438 SOLIB_ADD (NULL, 0, NULL);
2439 target_terminal_inferior ();
2442 /* Try to reenable shared library breakpoints, additional
2443 code segments in shared libraries might be mapped in now. */
2444 re_enable_breakpoints_in_shlibs ();
2446 /* If requested, stop when the dynamic linker notifies
2447 gdb of events. This allows the user to get control
2448 and place breakpoints in initializer routines for
2449 dynamically loaded objects (among other things). */
2450 if (stop_on_solib_events)
2452 stop_stepping (ecs);
2456 /* If we stopped due to an explicit catchpoint, then the
2457 (see above) call to SOLIB_ADD pulled in any symbols
2458 from a newly-loaded library, if appropriate.
2460 We do want the inferior to stop, but not where it is
2461 now, which is in the dynamic linker callback. Rather,
2462 we would like it stop in the user's program, just after
2463 the call that caused this catchpoint to trigger. That
2464 gives the user a more useful vantage from which to
2465 examine their program's state. */
2466 else if (what.main_action == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2468 /* ??rehrauer: If I could figure out how to get the
2469 right return PC from here, we could just set a temp
2470 breakpoint and resume. I'm not sure we can without
2471 cracking open the dld's shared libraries and sniffing
2472 their unwind tables and text/data ranges, and that's
2473 not a terribly portable notion.
2475 Until that time, we must step the inferior out of the
2476 dld callback, and also out of the dld itself (and any
2477 code or stubs in libdld.sl, such as "shl_load" and
2478 friends) until we reach non-dld code. At that point,
2479 we can stop stepping. */
2480 bpstat_get_triggered_catchpoints (stop_bpstat,
2481 &ecs->stepping_through_solib_catchpoints);
2482 ecs->stepping_through_solib_after_catch = 1;
2484 /* Be sure to lift all breakpoints, so the inferior does
2485 actually step past this point... */
2486 ecs->another_trap = 1;
2491 /* We want to step over this breakpoint, then keep going. */
2492 ecs->another_trap = 1;
2499 case BPSTAT_WHAT_LAST:
2500 /* Not a real code, but listed here to shut up gcc -Wall. */
2502 case BPSTAT_WHAT_KEEP_CHECKING:
2507 /* We come here if we hit a breakpoint but should not
2508 stop for it. Possibly we also were stepping
2509 and should stop for that. So fall through and
2510 test for stepping. But, if not stepping,
2513 /* Are we stepping to get the inferior out of the dynamic
2514 linker's hook (and possibly the dld itself) after catching
2516 if (ecs->stepping_through_solib_after_catch)
2518 #if defined(SOLIB_ADD)
2519 /* Have we reached our destination? If not, keep going. */
2520 if (SOLIB_IN_DYNAMIC_LINKER (ecs->pid, stop_pc))
2522 ecs->another_trap = 1;
2527 /* Else, stop and report the catchpoint(s) whose triggering
2528 caused us to begin stepping. */
2529 ecs->stepping_through_solib_after_catch = 0;
2530 bpstat_clear (&stop_bpstat);
2531 stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints);
2532 bpstat_clear (&ecs->stepping_through_solib_catchpoints);
2533 stop_print_frame = 1;
2534 stop_stepping (ecs);
2538 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P)
2540 /* This is the old way of detecting the end of the stack dummy.
2541 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2542 handled above. As soon as we can test it on all of them, all
2543 architectures should define it. */
2545 /* If this is the breakpoint at the end of a stack dummy,
2546 just stop silently, unless the user was doing an si/ni, in which
2547 case she'd better know what she's doing. */
2549 if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (),
2550 FRAME_FP (get_current_frame ()))
2553 stop_print_frame = 0;
2554 stop_stack_dummy = 1;
2556 trap_expected_after_continue = 1;
2558 stop_stepping (ecs);
2563 if (step_resume_breakpoint)
2565 /* Having a step-resume breakpoint overrides anything
2566 else having to do with stepping commands until
2567 that breakpoint is reached. */
2568 /* I'm not sure whether this needs to be check_sigtramp2 or
2569 whether it could/should be keep_going. */
2570 check_sigtramp2 (ecs);
2575 if (step_range_end == 0)
2577 /* Likewise if we aren't even stepping. */
2578 /* I'm not sure whether this needs to be check_sigtramp2 or
2579 whether it could/should be keep_going. */
2580 check_sigtramp2 (ecs);
2585 /* If stepping through a line, keep going if still within it.
2587 Note that step_range_end is the address of the first instruction
2588 beyond the step range, and NOT the address of the last instruction
2590 if (stop_pc >= step_range_start
2591 && stop_pc < step_range_end)
2593 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2594 So definately need to check for sigtramp here. */
2595 check_sigtramp2 (ecs);
2600 /* We stepped out of the stepping range. */
2602 /* If we are stepping at the source level and entered the runtime
2603 loader dynamic symbol resolution code, we keep on single stepping
2604 until we exit the run time loader code and reach the callee's
2606 if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2608 CORE_ADDR pc_after_resolver = SKIP_SOLIB_RESOLVER (stop_pc);
2610 if (pc_after_resolver)
2612 /* Set up a step-resume breakpoint at the address
2613 indicated by SKIP_SOLIB_RESOLVER. */
2614 struct symtab_and_line sr_sal;
2616 sr_sal.pc = pc_after_resolver;
2618 check_for_old_step_resume_breakpoint ();
2619 step_resume_breakpoint =
2620 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2621 if (breakpoints_inserted)
2622 insert_breakpoints ();
2629 /* We can't update step_sp every time through the loop, because
2630 reading the stack pointer would slow down stepping too much.
2631 But we can update it every time we leave the step range. */
2632 ecs->update_step_sp = 1;
2634 /* Did we just take a signal? */
2635 if (IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2636 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2637 && INNER_THAN (read_sp (), step_sp))
2639 /* We've just taken a signal; go until we are back to
2640 the point where we took it and one more. */
2642 /* Note: The test above succeeds not only when we stepped
2643 into a signal handler, but also when we step past the last
2644 statement of a signal handler and end up in the return stub
2645 of the signal handler trampoline. To distinguish between
2646 these two cases, check that the frame is INNER_THAN the
2647 previous one below. pai/1997-09-11 */
2651 CORE_ADDR current_frame = FRAME_FP (get_current_frame ());
2653 if (INNER_THAN (current_frame, step_frame_address))
2655 /* We have just taken a signal; go until we are back to
2656 the point where we took it and one more. */
2658 /* This code is needed at least in the following case:
2659 The user types "next" and then a signal arrives (before
2660 the "next" is done). */
2662 /* Note that if we are stopped at a breakpoint, then we need
2663 the step_resume breakpoint to override any breakpoints at
2664 the same location, so that we will still step over the
2665 breakpoint even though the signal happened. */
2666 struct symtab_and_line sr_sal;
2669 sr_sal.symtab = NULL;
2671 sr_sal.pc = prev_pc;
2672 /* We could probably be setting the frame to
2673 step_frame_address; I don't think anyone thought to
2675 check_for_old_step_resume_breakpoint ();
2676 step_resume_breakpoint =
2677 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2678 if (breakpoints_inserted)
2679 insert_breakpoints ();
2683 /* We just stepped out of a signal handler and into
2684 its calling trampoline.
2686 Normally, we'd call step_over_function from
2687 here, but for some reason GDB can't unwind the
2688 stack correctly to find the real PC for the point
2689 user code where the signal trampoline will return
2690 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2691 But signal trampolines are pretty small stubs of
2692 code, anyway, so it's OK instead to just
2693 single-step out. Note: assuming such trampolines
2694 don't exhibit recursion on any platform... */
2695 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2696 &ecs->stop_func_start,
2697 &ecs->stop_func_end);
2698 /* Readjust stepping range */
2699 step_range_start = ecs->stop_func_start;
2700 step_range_end = ecs->stop_func_end;
2701 ecs->stepping_through_sigtramp = 1;
2706 /* If this is stepi or nexti, make sure that the stepping range
2707 gets us past that instruction. */
2708 if (step_range_end == 1)
2709 /* FIXME: Does this run afoul of the code below which, if
2710 we step into the middle of a line, resets the stepping
2712 step_range_end = (step_range_start = prev_pc) + 1;
2714 ecs->remove_breakpoints_on_following_step = 1;
2719 if (stop_pc == ecs->stop_func_start /* Quick test */
2720 || (in_prologue (stop_pc, ecs->stop_func_start) &&
2721 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2722 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name)
2723 || ecs->stop_func_name == 0)
2725 /* It's a subroutine call. */
2727 if (step_over_calls == 0)
2729 /* I presume that step_over_calls is only 0 when we're
2730 supposed to be stepping at the assembly language level
2731 ("stepi"). Just stop. */
2733 print_stop_reason (END_STEPPING_RANGE, 0);
2734 stop_stepping (ecs);
2738 if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc))
2740 /* We're doing a "next". */
2741 step_over_function (ecs);
2746 /* If we are in a function call trampoline (a stub between
2747 the calling routine and the real function), locate the real
2748 function. That's what tells us (a) whether we want to step
2749 into it at all, and (b) what prologue we want to run to
2750 the end of, if we do step into it. */
2751 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2753 ecs->stop_func_start = tmp;
2756 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
2759 struct symtab_and_line xxx;
2760 /* Why isn't this s_a_l called "sr_sal", like all of the
2761 other s_a_l's where this code is duplicated? */
2762 INIT_SAL (&xxx); /* initialize to zeroes */
2764 xxx.section = find_pc_overlay (xxx.pc);
2765 check_for_old_step_resume_breakpoint ();
2766 step_resume_breakpoint =
2767 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
2768 insert_breakpoints ();
2774 /* If we have line number information for the function we
2775 are thinking of stepping into, step into it.
2777 If there are several symtabs at that PC (e.g. with include
2778 files), just want to know whether *any* of them have line
2779 numbers. find_pc_line handles this. */
2781 struct symtab_and_line tmp_sal;
2783 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
2784 if (tmp_sal.line != 0)
2786 step_into_function (ecs);
2790 step_over_function (ecs);
2796 /* We've wandered out of the step range. */
2798 ecs->sal = find_pc_line (stop_pc, 0);
2800 if (step_range_end == 1)
2802 /* It is stepi or nexti. We always want to stop stepping after
2805 print_stop_reason (END_STEPPING_RANGE, 0);
2806 stop_stepping (ecs);
2810 /* If we're in the return path from a shared library trampoline,
2811 we want to proceed through the trampoline when stepping. */
2812 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2816 /* Determine where this trampoline returns. */
2817 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2819 /* Only proceed through if we know where it's going. */
2822 /* And put the step-breakpoint there and go until there. */
2823 struct symtab_and_line sr_sal;
2825 INIT_SAL (&sr_sal); /* initialize to zeroes */
2827 sr_sal.section = find_pc_overlay (sr_sal.pc);
2828 /* Do not specify what the fp should be when we stop
2829 since on some machines the prologue
2830 is where the new fp value is established. */
2831 check_for_old_step_resume_breakpoint ();
2832 step_resume_breakpoint =
2833 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2834 if (breakpoints_inserted)
2835 insert_breakpoints ();
2837 /* Restart without fiddling with the step ranges or
2844 if (ecs->sal.line == 0)
2846 /* We have no line number information. That means to stop
2847 stepping (does this always happen right after one instruction,
2848 when we do "s" in a function with no line numbers,
2849 or can this happen as a result of a return or longjmp?). */
2851 print_stop_reason (END_STEPPING_RANGE, 0);
2852 stop_stepping (ecs);
2856 if ((stop_pc == ecs->sal.pc)
2857 && (ecs->current_line != ecs->sal.line || ecs->current_symtab != ecs->sal.symtab))
2859 /* We are at the start of a different line. So stop. Note that
2860 we don't stop if we step into the middle of a different line.
2861 That is said to make things like for (;;) statements work
2864 print_stop_reason (END_STEPPING_RANGE, 0);
2865 stop_stepping (ecs);
2869 /* We aren't done stepping.
2871 Optimize by setting the stepping range to the line.
2872 (We might not be in the original line, but if we entered a
2873 new line in mid-statement, we continue stepping. This makes
2874 things like for(;;) statements work better.) */
2876 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
2878 /* If this is the last line of the function, don't keep stepping
2879 (it would probably step us out of the function).
2880 This is particularly necessary for a one-line function,
2881 in which after skipping the prologue we better stop even though
2882 we will be in mid-line. */
2884 print_stop_reason (END_STEPPING_RANGE, 0);
2885 stop_stepping (ecs);
2888 step_range_start = ecs->sal.pc;
2889 step_range_end = ecs->sal.end;
2890 step_frame_address = FRAME_FP (get_current_frame ());
2891 ecs->current_line = ecs->sal.line;
2892 ecs->current_symtab = ecs->sal.symtab;
2894 /* In the case where we just stepped out of a function into the middle
2895 of a line of the caller, continue stepping, but step_frame_address
2896 must be modified to current frame */
2898 CORE_ADDR current_frame = FRAME_FP (get_current_frame ());
2899 if (!(INNER_THAN (current_frame, step_frame_address)))
2900 step_frame_address = current_frame;
2905 } /* extra brace, to preserve old indentation */
2908 /* Are we in the middle of stepping? */
2911 currently_stepping (struct execution_control_state *ecs)
2913 return ((through_sigtramp_breakpoint == NULL
2914 && !ecs->handling_longjmp
2915 && ((step_range_end && step_resume_breakpoint == NULL)
2917 || ecs->stepping_through_solib_after_catch
2918 || bpstat_should_step ());
2922 check_sigtramp2 (struct execution_control_state *ecs)
2925 && IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2926 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2927 && INNER_THAN (read_sp (), step_sp))
2929 /* What has happened here is that we have just stepped the
2930 inferior with a signal (because it is a signal which
2931 shouldn't make us stop), thus stepping into sigtramp.
2933 So we need to set a step_resume_break_address breakpoint and
2934 continue until we hit it, and then step. FIXME: This should
2935 be more enduring than a step_resume breakpoint; we should
2936 know that we will later need to keep going rather than
2937 re-hitting the breakpoint here (see the testsuite,
2938 gdb.base/signals.exp where it says "exceedingly difficult"). */
2940 struct symtab_and_line sr_sal;
2942 INIT_SAL (&sr_sal); /* initialize to zeroes */
2943 sr_sal.pc = prev_pc;
2944 sr_sal.section = find_pc_overlay (sr_sal.pc);
2945 /* We perhaps could set the frame if we kept track of what the
2946 frame corresponding to prev_pc was. But we don't, so don't. */
2947 through_sigtramp_breakpoint =
2948 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
2949 if (breakpoints_inserted)
2950 insert_breakpoints ();
2952 ecs->remove_breakpoints_on_following_step = 1;
2953 ecs->another_trap = 1;
2957 /* Subroutine call with source code we should not step over. Do step
2958 to the first line of code in it. */
2961 step_into_function (struct execution_control_state *ecs)
2964 struct symtab_and_line sr_sal;
2966 s = find_pc_symtab (stop_pc);
2967 if (s && s->language != language_asm)
2968 ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start);
2970 ecs->sal = find_pc_line (ecs->stop_func_start, 0);
2971 /* Use the step_resume_break to step until the end of the prologue,
2972 even if that involves jumps (as it seems to on the vax under
2974 /* If the prologue ends in the middle of a source line, continue to
2975 the end of that source line (if it is still within the function).
2976 Otherwise, just go to end of prologue. */
2977 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2978 /* no, don't either. It skips any code that's legitimately on the
2982 && ecs->sal.pc != ecs->stop_func_start
2983 && ecs->sal.end < ecs->stop_func_end)
2984 ecs->stop_func_start = ecs->sal.end;
2987 if (ecs->stop_func_start == stop_pc)
2989 /* We are already there: stop now. */
2991 print_stop_reason (END_STEPPING_RANGE, 0);
2992 stop_stepping (ecs);
2997 /* Put the step-breakpoint there and go until there. */
2998 INIT_SAL (&sr_sal); /* initialize to zeroes */
2999 sr_sal.pc = ecs->stop_func_start;
3000 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
3001 /* Do not specify what the fp should be when we stop since on
3002 some machines the prologue is where the new fp value is
3004 check_for_old_step_resume_breakpoint ();
3005 step_resume_breakpoint =
3006 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
3007 if (breakpoints_inserted)
3008 insert_breakpoints ();
3010 /* And make sure stepping stops right away then. */
3011 step_range_end = step_range_start;
3016 /* We've just entered a callee, and we wish to resume until it returns
3017 to the caller. Setting a step_resume breakpoint on the return
3018 address will catch a return from the callee.
3020 However, if the callee is recursing, we want to be careful not to
3021 catch returns of those recursive calls, but only of THIS instance
3024 To do this, we set the step_resume bp's frame to our current
3025 caller's frame (step_frame_address, which is set by the "next" or
3026 "until" command, before execution begins). */
3029 step_over_function (struct execution_control_state *ecs)
3031 struct symtab_and_line sr_sal;
3033 INIT_SAL (&sr_sal); /* initialize to zeros */
3034 sr_sal.pc = ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3035 sr_sal.section = find_pc_overlay (sr_sal.pc);
3037 check_for_old_step_resume_breakpoint ();
3038 step_resume_breakpoint =
3039 set_momentary_breakpoint (sr_sal, get_current_frame (), bp_step_resume);
3041 if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
3042 step_resume_breakpoint->frame = step_frame_address;
3044 if (breakpoints_inserted)
3045 insert_breakpoints ();
3049 stop_stepping (struct execution_control_state *ecs)
3051 if (target_has_execution)
3053 /* Are we stopping for a vfork event? We only stop when we see
3054 the child's event. However, we may not yet have seen the
3055 parent's event. And, inferior_pid is still set to the
3056 parent's pid, until we resume again and follow either the
3059 To ensure that we can really touch inferior_pid (aka, the
3060 parent process) -- which calls to functions like read_pc
3061 implicitly do -- wait on the parent if necessary. */
3062 if ((pending_follow.kind == TARGET_WAITKIND_VFORKED)
3063 && !pending_follow.fork_event.saw_parent_fork)
3069 if (target_wait_hook)
3070 parent_pid = target_wait_hook (-1, &(ecs->ws));
3072 parent_pid = target_wait (-1, &(ecs->ws));
3074 while (parent_pid != inferior_pid);
3077 /* Assuming the inferior still exists, set these up for next
3078 time, just like we did above if we didn't break out of the
3080 prev_pc = read_pc ();
3081 prev_func_start = ecs->stop_func_start;
3082 prev_func_name = ecs->stop_func_name;
3085 /* Let callers know we don't want to wait for the inferior anymore. */
3086 ecs->wait_some_more = 0;
3089 /* This function handles various cases where we need to continue
3090 waiting for the inferior. */
3091 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3094 keep_going (struct execution_control_state *ecs)
3096 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3097 vforked child between its creation and subsequent exit or call to
3098 exec(). However, I had big problems in this rather creaky exec
3099 engine, getting that to work. The fundamental problem is that
3100 I'm trying to debug two processes via an engine that only
3101 understands a single process with possibly multiple threads.
3103 Hence, this spot is known to have problems when
3104 target_can_follow_vfork_prior_to_exec returns 1. */
3106 /* Save the pc before execution, to compare with pc after stop. */
3107 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
3108 prev_func_start = ecs->stop_func_start; /* Ok, since if DECR_PC_AFTER
3109 BREAK is defined, the
3110 original pc would not have
3111 been at the start of a
3113 prev_func_name = ecs->stop_func_name;
3115 if (ecs->update_step_sp)
3116 step_sp = read_sp ();
3117 ecs->update_step_sp = 0;
3119 /* If we did not do break;, it means we should keep running the
3120 inferior and not return to debugger. */
3122 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
3124 /* We took a signal (which we are supposed to pass through to
3125 the inferior, else we'd have done a break above) and we
3126 haven't yet gotten our trap. Simply continue. */
3127 resume (currently_stepping (ecs), stop_signal);
3131 /* Either the trap was not expected, but we are continuing
3132 anyway (the user asked that this signal be passed to the
3135 The signal was SIGTRAP, e.g. it was our signal, but we
3136 decided we should resume from it.
3138 We're going to run this baby now!
3140 Insert breakpoints now, unless we are trying to one-proceed
3141 past a breakpoint. */
3142 /* If we've just finished a special step resume and we don't
3143 want to hit a breakpoint, pull em out. */
3144 if (step_resume_breakpoint == NULL
3145 && through_sigtramp_breakpoint == NULL
3146 && ecs->remove_breakpoints_on_following_step)
3148 ecs->remove_breakpoints_on_following_step = 0;
3149 remove_breakpoints ();
3150 breakpoints_inserted = 0;
3152 else if (!breakpoints_inserted &&
3153 (through_sigtramp_breakpoint != NULL || !ecs->another_trap))
3155 breakpoints_failed = insert_breakpoints ();
3156 if (breakpoints_failed)
3158 stop_stepping (ecs);
3161 breakpoints_inserted = 1;
3164 trap_expected = ecs->another_trap;
3166 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3167 specifies that such a signal should be delivered to the
3170 Typically, this would occure when a user is debugging a
3171 target monitor on a simulator: the target monitor sets a
3172 breakpoint; the simulator encounters this break-point and
3173 halts the simulation handing control to GDB; GDB, noteing
3174 that the break-point isn't valid, returns control back to the
3175 simulator; the simulator then delivers the hardware
3176 equivalent of a SIGNAL_TRAP to the program being debugged. */
3178 if (stop_signal == TARGET_SIGNAL_TRAP
3179 && !signal_program[stop_signal])
3180 stop_signal = TARGET_SIGNAL_0;
3182 #ifdef SHIFT_INST_REGS
3183 /* I'm not sure when this following segment applies. I do know,
3184 now, that we shouldn't rewrite the regs when we were stopped
3185 by a random signal from the inferior process. */
3186 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3187 (this is only used on the 88k). */
3189 if (!bpstat_explains_signal (stop_bpstat)
3190 && (stop_signal != TARGET_SIGNAL_CHLD)
3191 && !stopped_by_random_signal)
3193 #endif /* SHIFT_INST_REGS */
3195 resume (currently_stepping (ecs), stop_signal);
3198 prepare_to_wait (ecs);
3201 /* This function normally comes after a resume, before
3202 handle_inferior_event exits. It takes care of any last bits of
3203 housekeeping, and sets the all-important wait_some_more flag. */
3206 prepare_to_wait (struct execution_control_state *ecs)
3208 if (ecs->infwait_state == infwait_normal_state)
3210 overlay_cache_invalid = 1;
3212 /* We have to invalidate the registers BEFORE calling
3213 target_wait because they can be loaded from the target while
3214 in target_wait. This makes remote debugging a bit more
3215 efficient for those targets that provide critical registers
3216 as part of their normal status mechanism. */
3218 registers_changed ();
3219 ecs->waiton_pid = -1;
3220 ecs->wp = &(ecs->ws);
3222 /* This is the old end of the while loop. Let everybody know we
3223 want to wait for the inferior some more and get called again
3225 ecs->wait_some_more = 1;
3228 /* Print why the inferior has stopped. We always print something when
3229 the inferior exits, or receives a signal. The rest of the cases are
3230 dealt with later on in normal_stop() and print_it_typical(). Ideally
3231 there should be a call to this function from handle_inferior_event()
3232 each time stop_stepping() is called.*/
3234 print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
3236 switch (stop_reason)
3239 /* We don't deal with these cases from handle_inferior_event()
3242 case END_STEPPING_RANGE:
3243 /* We are done with a step/next/si/ni command. */
3244 /* For now print nothing. */
3246 /* Print a message only if not in the middle of doing a "step n"
3247 operation for n > 1 */
3248 if (!step_multi || !stop_step)
3249 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3250 ui_out_field_string (uiout, "reason", "end-stepping-range");
3253 case BREAKPOINT_HIT:
3254 /* We found a breakpoint. */
3255 /* For now print nothing. */
3258 /* The inferior was terminated by a signal. */
3260 annotate_signalled ();
3261 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3262 ui_out_field_string (uiout, "reason", "exited-signalled");
3263 ui_out_text (uiout, "\nProgram terminated with signal ");
3264 annotate_signal_name ();
3265 ui_out_field_string (uiout, "signal-name", target_signal_to_name (stop_info));
3266 annotate_signal_name_end ();
3267 ui_out_text (uiout, ", ");
3268 annotate_signal_string ();
3269 ui_out_field_string (uiout, "signal-meaning", target_signal_to_string (stop_info));
3270 annotate_signal_string_end ();
3271 ui_out_text (uiout, ".\n");
3272 ui_out_text (uiout, "The program no longer exists.\n");
3274 annotate_signalled ();
3275 printf_filtered ("\nProgram terminated with signal ");
3276 annotate_signal_name ();
3277 printf_filtered ("%s", target_signal_to_name (stop_info));
3278 annotate_signal_name_end ();
3279 printf_filtered (", ");
3280 annotate_signal_string ();
3281 printf_filtered ("%s", target_signal_to_string (stop_info));
3282 annotate_signal_string_end ();
3283 printf_filtered (".\n");
3285 printf_filtered ("The program no longer exists.\n");
3286 gdb_flush (gdb_stdout);
3290 /* The inferior program is finished. */
3292 annotate_exited (stop_info);
3295 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3296 ui_out_field_string (uiout, "reason", "exited");
3297 ui_out_text (uiout, "\nProgram exited with code ");
3298 ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) stop_info);
3299 ui_out_text (uiout, ".\n");
3303 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3304 ui_out_field_string (uiout, "reason", "exited-normally");
3305 ui_out_text (uiout, "\nProgram exited normally.\n");
3308 annotate_exited (stop_info);
3310 printf_filtered ("\nProgram exited with code 0%o.\n",
3311 (unsigned int) stop_info);
3313 printf_filtered ("\nProgram exited normally.\n");
3316 case SIGNAL_RECEIVED:
3317 /* Signal received. The signal table tells us to print about
3321 ui_out_text (uiout, "\nProgram received signal ");
3322 annotate_signal_name ();
3323 ui_out_field_string (uiout, "signal-name", target_signal_to_name (stop_info));
3324 annotate_signal_name_end ();
3325 ui_out_text (uiout, ", ");
3326 annotate_signal_string ();
3327 ui_out_field_string (uiout, "signal-meaning", target_signal_to_string (stop_info));
3328 annotate_signal_string_end ();
3329 ui_out_text (uiout, ".\n");
3332 printf_filtered ("\nProgram received signal ");
3333 annotate_signal_name ();
3334 printf_filtered ("%s", target_signal_to_name (stop_info));
3335 annotate_signal_name_end ();
3336 printf_filtered (", ");
3337 annotate_signal_string ();
3338 printf_filtered ("%s", target_signal_to_string (stop_info));
3339 annotate_signal_string_end ();
3340 printf_filtered (".\n");
3341 gdb_flush (gdb_stdout);
3345 internal_error ("print_stop_reason: unrecognized enum value");
3351 /* Here to return control to GDB when the inferior stops for real.
3352 Print appropriate messages, remove breakpoints, give terminal our modes.
3354 STOP_PRINT_FRAME nonzero means print the executing frame
3355 (pc, function, args, file, line number and line text).
3356 BREAKPOINTS_FAILED nonzero means stop was due to error
3357 attempting to insert breakpoints. */
3362 /* As with the notification of thread events, we want to delay
3363 notifying the user that we've switched thread context until
3364 the inferior actually stops.
3366 (Note that there's no point in saying anything if the inferior
3368 if ((previous_inferior_pid != inferior_pid)
3369 && target_has_execution)
3371 target_terminal_ours_for_output ();
3372 printf_filtered ("[Switching to %s]\n",
3373 target_pid_or_tid_to_str (inferior_pid));
3374 previous_inferior_pid = inferior_pid;
3377 /* Make sure that the current_frame's pc is correct. This
3378 is a correction for setting up the frame info before doing
3379 DECR_PC_AFTER_BREAK */
3380 if (target_has_execution && get_current_frame ())
3381 (get_current_frame ())->pc = read_pc ();
3383 if (breakpoints_failed)
3385 target_terminal_ours_for_output ();
3386 print_sys_errmsg ("ptrace", breakpoints_failed);
3387 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3388 The same program may be running in another process.\n");
3391 if (target_has_execution && breakpoints_inserted)
3393 if (remove_breakpoints ())
3395 target_terminal_ours_for_output ();
3396 printf_filtered ("Cannot remove breakpoints because ");
3397 printf_filtered ("program is no longer writable.\n");
3398 printf_filtered ("It might be running in another process.\n");
3399 printf_filtered ("Further execution is probably impossible.\n");
3402 breakpoints_inserted = 0;
3404 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3405 Delete any breakpoint that is to be deleted at the next stop. */
3407 breakpoint_auto_delete (stop_bpstat);
3409 /* If an auto-display called a function and that got a signal,
3410 delete that auto-display to avoid an infinite recursion. */
3412 if (stopped_by_random_signal)
3413 disable_current_display ();
3415 /* Don't print a message if in the middle of doing a "step n"
3416 operation for n > 1 */
3417 if (step_multi && stop_step)
3420 target_terminal_ours ();
3422 /* Look up the hook_stop and run it if it exists. */
3424 if (stop_command && stop_command->hook)
3426 catch_errors (hook_stop_stub, stop_command->hook,
3427 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3430 if (!target_has_stack)
3436 /* Select innermost stack frame - i.e., current frame is frame 0,
3437 and current location is based on that.
3438 Don't do this on return from a stack dummy routine,
3439 or if the program has exited. */
3441 if (!stop_stack_dummy)
3443 select_frame (get_current_frame (), 0);
3445 /* Print current location without a level number, if
3446 we have changed functions or hit a breakpoint.
3447 Print source line if we have one.
3448 bpstat_print() contains the logic deciding in detail
3449 what to print, based on the event(s) that just occurred. */
3451 if (stop_print_frame
3456 int do_frame_printing = 1;
3458 bpstat_ret = bpstat_print (stop_bpstat);
3463 && step_frame_address == FRAME_FP (get_current_frame ())
3464 && step_start_function == find_pc_function (stop_pc))
3465 source_flag = SRC_LINE; /* finished step, just print source line */
3467 source_flag = SRC_AND_LOC; /* print location and source line */
3469 case PRINT_SRC_AND_LOC:
3470 source_flag = SRC_AND_LOC; /* print location and source line */
3472 case PRINT_SRC_ONLY:
3473 source_flag = SRC_LINE;
3476 do_frame_printing = 0;
3479 internal_error ("Unknown value.");
3482 /* For mi, have the same behavior every time we stop:
3483 print everything but the source line. */
3484 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3485 source_flag = LOC_AND_ADDRESS;
3489 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3490 ui_out_field_int (uiout, "thread-id", pid_to_thread_id (inferior_pid));
3492 /* The behavior of this routine with respect to the source
3494 SRC_LINE: Print only source line
3495 LOCATION: Print only location
3496 SRC_AND_LOC: Print location and source line */
3497 if (do_frame_printing)
3498 show_and_print_stack_frame (selected_frame, -1, source_flag);
3500 /* Display the auto-display expressions. */
3505 /* Save the function value return registers, if we care.
3506 We might be about to restore their previous contents. */
3507 if (proceed_to_finish)
3508 read_register_bytes (0, stop_registers, REGISTER_BYTES);
3510 if (stop_stack_dummy)
3512 /* Pop the empty frame that contains the stack dummy.
3513 POP_FRAME ends with a setting of the current frame, so we
3514 can use that next. */
3516 /* Set stop_pc to what it was before we called the function.
3517 Can't rely on restore_inferior_status because that only gets
3518 called if we don't stop in the called function. */
3519 stop_pc = read_pc ();
3520 select_frame (get_current_frame (), 0);
3524 TUIDO (((TuiOpaqueFuncPtr) tui_vCheckDataValues, selected_frame));
3527 annotate_stopped ();
3531 hook_stop_stub (void *cmd)
3533 execute_user_command ((struct cmd_list_element *) cmd, 0);
3538 signal_stop_state (int signo)
3540 return signal_stop[signo];
3544 signal_print_state (int signo)
3546 return signal_print[signo];
3550 signal_pass_state (int signo)
3552 return signal_program[signo];
3555 int signal_stop_update (signo, state)
3559 int ret = signal_stop[signo];
3560 signal_stop[signo] = state;
3564 int signal_print_update (signo, state)
3568 int ret = signal_print[signo];
3569 signal_print[signo] = state;
3573 int signal_pass_update (signo, state)
3577 int ret = signal_program[signo];
3578 signal_program[signo] = state;
3583 sig_print_header (void)
3586 Signal Stop\tPrint\tPass to program\tDescription\n");
3590 sig_print_info (enum target_signal oursig)
3592 char *name = target_signal_to_name (oursig);
3593 int name_padding = 13 - strlen (name);
3595 if (name_padding <= 0)
3598 printf_filtered ("%s", name);
3599 printf_filtered ("%*.*s ", name_padding, name_padding,
3601 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3602 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3603 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3604 printf_filtered ("%s\n", target_signal_to_string (oursig));
3607 /* Specify how various signals in the inferior should be handled. */
3610 handle_command (char *args, int from_tty)
3613 int digits, wordlen;
3614 int sigfirst, signum, siglast;
3615 enum target_signal oursig;
3618 unsigned char *sigs;
3619 struct cleanup *old_chain;
3623 error_no_arg ("signal to handle");
3626 /* Allocate and zero an array of flags for which signals to handle. */
3628 nsigs = (int) TARGET_SIGNAL_LAST;
3629 sigs = (unsigned char *) alloca (nsigs);
3630 memset (sigs, 0, nsigs);
3632 /* Break the command line up into args. */
3634 argv = buildargv (args);
3639 old_chain = make_cleanup_freeargv (argv);
3641 /* Walk through the args, looking for signal oursigs, signal names, and
3642 actions. Signal numbers and signal names may be interspersed with
3643 actions, with the actions being performed for all signals cumulatively
3644 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3646 while (*argv != NULL)
3648 wordlen = strlen (*argv);
3649 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3653 sigfirst = siglast = -1;
3655 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3657 /* Apply action to all signals except those used by the
3658 debugger. Silently skip those. */
3661 siglast = nsigs - 1;
3663 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3665 SET_SIGS (nsigs, sigs, signal_stop);
3666 SET_SIGS (nsigs, sigs, signal_print);
3668 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3670 UNSET_SIGS (nsigs, sigs, signal_program);
3672 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3674 SET_SIGS (nsigs, sigs, signal_print);
3676 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3678 SET_SIGS (nsigs, sigs, signal_program);
3680 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3682 UNSET_SIGS (nsigs, sigs, signal_stop);
3684 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3686 SET_SIGS (nsigs, sigs, signal_program);
3688 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3690 UNSET_SIGS (nsigs, sigs, signal_print);
3691 UNSET_SIGS (nsigs, sigs, signal_stop);
3693 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3695 UNSET_SIGS (nsigs, sigs, signal_program);
3697 else if (digits > 0)
3699 /* It is numeric. The numeric signal refers to our own
3700 internal signal numbering from target.h, not to host/target
3701 signal number. This is a feature; users really should be
3702 using symbolic names anyway, and the common ones like
3703 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3705 sigfirst = siglast = (int)
3706 target_signal_from_command (atoi (*argv));
3707 if ((*argv)[digits] == '-')
3710 target_signal_from_command (atoi ((*argv) + digits + 1));
3712 if (sigfirst > siglast)
3714 /* Bet he didn't figure we'd think of this case... */
3722 oursig = target_signal_from_name (*argv);
3723 if (oursig != TARGET_SIGNAL_UNKNOWN)
3725 sigfirst = siglast = (int) oursig;
3729 /* Not a number and not a recognized flag word => complain. */
3730 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3734 /* If any signal numbers or symbol names were found, set flags for
3735 which signals to apply actions to. */
3737 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3739 switch ((enum target_signal) signum)
3741 case TARGET_SIGNAL_TRAP:
3742 case TARGET_SIGNAL_INT:
3743 if (!allsigs && !sigs[signum])
3745 if (query ("%s is used by the debugger.\n\
3746 Are you sure you want to change it? ",
3747 target_signal_to_name
3748 ((enum target_signal) signum)))
3754 printf_unfiltered ("Not confirmed, unchanged.\n");
3755 gdb_flush (gdb_stdout);
3759 case TARGET_SIGNAL_0:
3760 case TARGET_SIGNAL_DEFAULT:
3761 case TARGET_SIGNAL_UNKNOWN:
3762 /* Make sure that "all" doesn't print these. */
3773 target_notice_signals (inferior_pid);
3777 /* Show the results. */
3778 sig_print_header ();
3779 for (signum = 0; signum < nsigs; signum++)
3783 sig_print_info (signum);
3788 do_cleanups (old_chain);
3792 xdb_handle_command (char *args, int from_tty)
3795 struct cleanup *old_chain;
3797 /* Break the command line up into args. */
3799 argv = buildargv (args);
3804 old_chain = make_cleanup_freeargv (argv);
3805 if (argv[1] != (char *) NULL)
3810 bufLen = strlen (argv[0]) + 20;
3811 argBuf = (char *) xmalloc (bufLen);
3815 enum target_signal oursig;
3817 oursig = target_signal_from_name (argv[0]);
3818 memset (argBuf, 0, bufLen);
3819 if (strcmp (argv[1], "Q") == 0)
3820 sprintf (argBuf, "%s %s", argv[0], "noprint");
3823 if (strcmp (argv[1], "s") == 0)
3825 if (!signal_stop[oursig])
3826 sprintf (argBuf, "%s %s", argv[0], "stop");
3828 sprintf (argBuf, "%s %s", argv[0], "nostop");
3830 else if (strcmp (argv[1], "i") == 0)
3832 if (!signal_program[oursig])
3833 sprintf (argBuf, "%s %s", argv[0], "pass");
3835 sprintf (argBuf, "%s %s", argv[0], "nopass");
3837 else if (strcmp (argv[1], "r") == 0)
3839 if (!signal_print[oursig])
3840 sprintf (argBuf, "%s %s", argv[0], "print");
3842 sprintf (argBuf, "%s %s", argv[0], "noprint");
3848 handle_command (argBuf, from_tty);
3850 printf_filtered ("Invalid signal handling flag.\n");
3855 do_cleanups (old_chain);
3858 /* Print current contents of the tables set by the handle command.
3859 It is possible we should just be printing signals actually used
3860 by the current target (but for things to work right when switching
3861 targets, all signals should be in the signal tables). */
3864 signals_info (char *signum_exp, int from_tty)
3866 enum target_signal oursig;
3867 sig_print_header ();
3871 /* First see if this is a symbol name. */
3872 oursig = target_signal_from_name (signum_exp);
3873 if (oursig == TARGET_SIGNAL_UNKNOWN)
3875 /* No, try numeric. */
3877 target_signal_from_command (parse_and_eval_address (signum_exp));
3879 sig_print_info (oursig);
3883 printf_filtered ("\n");
3884 /* These ugly casts brought to you by the native VAX compiler. */
3885 for (oursig = TARGET_SIGNAL_FIRST;
3886 (int) oursig < (int) TARGET_SIGNAL_LAST;
3887 oursig = (enum target_signal) ((int) oursig + 1))
3891 if (oursig != TARGET_SIGNAL_UNKNOWN
3892 && oursig != TARGET_SIGNAL_DEFAULT
3893 && oursig != TARGET_SIGNAL_0)
3894 sig_print_info (oursig);
3897 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3900 struct inferior_status
3902 enum target_signal stop_signal;
3906 int stop_stack_dummy;
3907 int stopped_by_random_signal;
3909 CORE_ADDR step_range_start;
3910 CORE_ADDR step_range_end;
3911 CORE_ADDR step_frame_address;
3912 int step_over_calls;
3913 CORE_ADDR step_resume_break_address;
3914 int stop_after_trap;
3915 int stop_soon_quietly;
3916 CORE_ADDR selected_frame_address;
3917 char *stop_registers;
3919 /* These are here because if call_function_by_hand has written some
3920 registers and then decides to call error(), we better not have changed
3925 int breakpoint_proceeded;
3926 int restore_stack_info;
3927 int proceed_to_finish;
3930 static struct inferior_status *
3931 xmalloc_inferior_status (void)
3933 struct inferior_status *inf_status;
3934 inf_status = xmalloc (sizeof (struct inferior_status));
3935 inf_status->stop_registers = xmalloc (REGISTER_BYTES);
3936 inf_status->registers = xmalloc (REGISTER_BYTES);
3941 free_inferior_status (struct inferior_status *inf_status)
3943 free (inf_status->registers);
3944 free (inf_status->stop_registers);
3949 write_inferior_status_register (struct inferior_status *inf_status, int regno,
3952 int size = REGISTER_RAW_SIZE (regno);
3953 void *buf = alloca (size);
3954 store_signed_integer (buf, size, val);
3955 memcpy (&inf_status->registers[REGISTER_BYTE (regno)], buf, size);
3958 /* Save all of the information associated with the inferior<==>gdb
3959 connection. INF_STATUS is a pointer to a "struct inferior_status"
3960 (defined in inferior.h). */
3962 struct inferior_status *
3963 save_inferior_status (int restore_stack_info)
3965 struct inferior_status *inf_status = xmalloc_inferior_status ();
3967 inf_status->stop_signal = stop_signal;
3968 inf_status->stop_pc = stop_pc;
3969 inf_status->stop_step = stop_step;
3970 inf_status->stop_stack_dummy = stop_stack_dummy;
3971 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3972 inf_status->trap_expected = trap_expected;
3973 inf_status->step_range_start = step_range_start;
3974 inf_status->step_range_end = step_range_end;
3975 inf_status->step_frame_address = step_frame_address;
3976 inf_status->step_over_calls = step_over_calls;
3977 inf_status->stop_after_trap = stop_after_trap;
3978 inf_status->stop_soon_quietly = stop_soon_quietly;
3979 /* Save original bpstat chain here; replace it with copy of chain.
3980 If caller's caller is walking the chain, they'll be happier if we
3981 hand them back the original chain when restore_inferior_status is
3983 inf_status->stop_bpstat = stop_bpstat;
3984 stop_bpstat = bpstat_copy (stop_bpstat);
3985 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3986 inf_status->restore_stack_info = restore_stack_info;
3987 inf_status->proceed_to_finish = proceed_to_finish;
3989 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
3991 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3993 record_selected_frame (&(inf_status->selected_frame_address),
3994 &(inf_status->selected_level));
3998 struct restore_selected_frame_args
4000 CORE_ADDR frame_address;
4005 restore_selected_frame (void *args)
4007 struct restore_selected_frame_args *fr =
4008 (struct restore_selected_frame_args *) args;
4009 struct frame_info *frame;
4010 int level = fr->level;
4012 frame = find_relative_frame (get_current_frame (), &level);
4014 /* If inf_status->selected_frame_address is NULL, there was no
4015 previously selected frame. */
4016 if (frame == NULL ||
4017 /* FRAME_FP (frame) != fr->frame_address || */
4018 /* elz: deleted this check as a quick fix to the problem that
4019 for function called by hand gdb creates no internal frame
4020 structure and the real stack and gdb's idea of stack are
4021 different if nested calls by hands are made.
4023 mvs: this worries me. */
4026 warning ("Unable to restore previously selected frame.\n");
4030 select_frame (frame, fr->level);
4036 restore_inferior_status (struct inferior_status *inf_status)
4038 stop_signal = inf_status->stop_signal;
4039 stop_pc = inf_status->stop_pc;
4040 stop_step = inf_status->stop_step;
4041 stop_stack_dummy = inf_status->stop_stack_dummy;
4042 stopped_by_random_signal = inf_status->stopped_by_random_signal;
4043 trap_expected = inf_status->trap_expected;
4044 step_range_start = inf_status->step_range_start;
4045 step_range_end = inf_status->step_range_end;
4046 step_frame_address = inf_status->step_frame_address;
4047 step_over_calls = inf_status->step_over_calls;
4048 stop_after_trap = inf_status->stop_after_trap;
4049 stop_soon_quietly = inf_status->stop_soon_quietly;
4050 bpstat_clear (&stop_bpstat);
4051 stop_bpstat = inf_status->stop_bpstat;
4052 breakpoint_proceeded = inf_status->breakpoint_proceeded;
4053 proceed_to_finish = inf_status->proceed_to_finish;
4055 /* FIXME: Is the restore of stop_registers always needed */
4056 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
4058 /* The inferior can be gone if the user types "print exit(0)"
4059 (and perhaps other times). */
4060 if (target_has_execution)
4061 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
4063 /* FIXME: If we are being called after stopping in a function which
4064 is called from gdb, we should not be trying to restore the
4065 selected frame; it just prints a spurious error message (The
4066 message is useful, however, in detecting bugs in gdb (like if gdb
4067 clobbers the stack)). In fact, should we be restoring the
4068 inferior status at all in that case? . */
4070 if (target_has_stack && inf_status->restore_stack_info)
4072 struct restore_selected_frame_args fr;
4073 fr.level = inf_status->selected_level;
4074 fr.frame_address = inf_status->selected_frame_address;
4075 /* The point of catch_errors is that if the stack is clobbered,
4076 walking the stack might encounter a garbage pointer and error()
4077 trying to dereference it. */
4078 if (catch_errors (restore_selected_frame, &fr,
4079 "Unable to restore previously selected frame:\n",
4080 RETURN_MASK_ERROR) == 0)
4081 /* Error in restoring the selected frame. Select the innermost
4085 select_frame (get_current_frame (), 0);
4089 free_inferior_status (inf_status);
4093 discard_inferior_status (struct inferior_status *inf_status)
4095 /* See save_inferior_status for info on stop_bpstat. */
4096 bpstat_clear (&inf_status->stop_bpstat);
4097 free_inferior_status (inf_status);
4101 set_follow_fork_mode_command (char *arg, int from_tty,
4102 struct cmd_list_element *c)
4104 if (!STREQ (arg, "parent") &&
4105 !STREQ (arg, "child") &&
4106 !STREQ (arg, "both") &&
4107 !STREQ (arg, "ask"))
4108 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
4110 if (follow_fork_mode_string != NULL)
4111 free (follow_fork_mode_string);
4112 follow_fork_mode_string = savestring (arg, strlen (arg));
4118 stop_registers = xmalloc (REGISTER_BYTES);
4122 _initialize_infrun (void)
4125 register int numsigs;
4126 struct cmd_list_element *c;
4130 register_gdbarch_swap (&stop_registers, sizeof (stop_registers), NULL);
4131 register_gdbarch_swap (NULL, 0, build_infrun);
4133 add_info ("signals", signals_info,
4134 "What debugger does when program gets various signals.\n\
4135 Specify a signal as argument to print info on that signal only.");
4136 add_info_alias ("handle", "signals", 0);
4138 add_com ("handle", class_run, handle_command,
4139 concat ("Specify how to handle a signal.\n\
4140 Args are signals and actions to apply to those signals.\n\
4141 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4142 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4143 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4144 The special arg \"all\" is recognized to mean all signals except those\n\
4145 used by the debugger, typically SIGTRAP and SIGINT.\n",
4146 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4147 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4148 Stop means reenter debugger if this signal happens (implies print).\n\
4149 Print means print a message if this signal happens.\n\
4150 Pass means let program see this signal; otherwise program doesn't know.\n\
4151 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4152 Pass and Stop may be combined.", NULL));
4155 add_com ("lz", class_info, signals_info,
4156 "What debugger does when program gets various signals.\n\
4157 Specify a signal as argument to print info on that signal only.");
4158 add_com ("z", class_run, xdb_handle_command,
4159 concat ("Specify how to handle a signal.\n\
4160 Args are signals and actions to apply to those signals.\n\
4161 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4162 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4163 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4164 The special arg \"all\" is recognized to mean all signals except those\n\
4165 used by the debugger, typically SIGTRAP and SIGINT.\n",
4166 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4167 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4168 nopass), \"Q\" (noprint)\n\
4169 Stop means reenter debugger if this signal happens (implies print).\n\
4170 Print means print a message if this signal happens.\n\
4171 Pass means let program see this signal; otherwise program doesn't know.\n\
4172 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4173 Pass and Stop may be combined.", NULL));
4177 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
4178 "There is no `stop' command, but you can set a hook on `stop'.\n\
4179 This allows you to set a list of commands to be run each time execution\n\
4180 of the program stops.", &cmdlist);
4182 numsigs = (int) TARGET_SIGNAL_LAST;
4183 signal_stop = (unsigned char *)
4184 xmalloc (sizeof (signal_stop[0]) * numsigs);
4185 signal_print = (unsigned char *)
4186 xmalloc (sizeof (signal_print[0]) * numsigs);
4187 signal_program = (unsigned char *)
4188 xmalloc (sizeof (signal_program[0]) * numsigs);
4189 for (i = 0; i < numsigs; i++)
4192 signal_print[i] = 1;
4193 signal_program[i] = 1;
4196 /* Signals caused by debugger's own actions
4197 should not be given to the program afterwards. */
4198 signal_program[TARGET_SIGNAL_TRAP] = 0;
4199 signal_program[TARGET_SIGNAL_INT] = 0;
4201 /* Signals that are not errors should not normally enter the debugger. */
4202 signal_stop[TARGET_SIGNAL_ALRM] = 0;
4203 signal_print[TARGET_SIGNAL_ALRM] = 0;
4204 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
4205 signal_print[TARGET_SIGNAL_VTALRM] = 0;
4206 signal_stop[TARGET_SIGNAL_PROF] = 0;
4207 signal_print[TARGET_SIGNAL_PROF] = 0;
4208 signal_stop[TARGET_SIGNAL_CHLD] = 0;
4209 signal_print[TARGET_SIGNAL_CHLD] = 0;
4210 signal_stop[TARGET_SIGNAL_IO] = 0;
4211 signal_print[TARGET_SIGNAL_IO] = 0;
4212 signal_stop[TARGET_SIGNAL_POLL] = 0;
4213 signal_print[TARGET_SIGNAL_POLL] = 0;
4214 signal_stop[TARGET_SIGNAL_URG] = 0;
4215 signal_print[TARGET_SIGNAL_URG] = 0;
4216 signal_stop[TARGET_SIGNAL_WINCH] = 0;
4217 signal_print[TARGET_SIGNAL_WINCH] = 0;
4219 /* These signals are used internally by user-level thread
4220 implementations. (See signal(5) on Solaris.) Like the above
4221 signals, a healthy program receives and handles them as part of
4222 its normal operation. */
4223 signal_stop[TARGET_SIGNAL_LWP] = 0;
4224 signal_print[TARGET_SIGNAL_LWP] = 0;
4225 signal_stop[TARGET_SIGNAL_WAITING] = 0;
4226 signal_print[TARGET_SIGNAL_WAITING] = 0;
4227 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
4228 signal_print[TARGET_SIGNAL_CANCEL] = 0;
4232 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
4233 (char *) &stop_on_solib_events,
4234 "Set stopping for shared library events.\n\
4235 If nonzero, gdb will give control to the user when the dynamic linker\n\
4236 notifies gdb of shared library events. The most common event of interest\n\
4237 to the user would be loading/unloading of a new library.\n",
4242 c = add_set_enum_cmd ("follow-fork-mode",
4244 follow_fork_mode_kind_names,
4245 (char *) &follow_fork_mode_string,
4246 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4247 kernel problem. It's also not terribly useful without a GUI to
4248 help the user drive two debuggers. So for now, I'm disabling
4249 the "both" option. */
4250 /* "Set debugger response to a program call of fork \
4252 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4253 parent - the original process is debugged after a fork\n\
4254 child - the new process is debugged after a fork\n\
4255 both - both the parent and child are debugged after a fork\n\
4256 ask - the debugger will ask for one of the above choices\n\
4257 For \"both\", another copy of the debugger will be started to follow\n\
4258 the new child process. The original debugger will continue to follow\n\
4259 the original parent process. To distinguish their prompts, the\n\
4260 debugger copy's prompt will be changed.\n\
4261 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4262 By default, the debugger will follow the parent process.",
4264 "Set debugger response to a program call of fork \
4266 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4267 parent - the original process is debugged after a fork\n\
4268 child - the new process is debugged after a fork\n\
4269 ask - the debugger will ask for one of the above choices\n\
4270 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4271 By default, the debugger will follow the parent process.",
4273 /* c->function.sfunc = ; */
4274 add_show_from_set (c, &showlist);
4276 set_follow_fork_mode_command ("parent", 0, NULL);
4278 c = add_set_enum_cmd ("scheduler-locking", class_run,
4279 scheduler_enums, /* array of string names */
4280 (char *) &scheduler_mode, /* current mode */
4281 "Set mode for locking scheduler during execution.\n\
4282 off == no locking (threads may preempt at any time)\n\
4283 on == full locking (no thread except the current thread may run)\n\
4284 step == scheduler locked during every single-step operation.\n\
4285 In this mode, no other thread may run during a step command.\n\
4286 Other threads may run while stepping over a function call ('next').",
4289 c->function.sfunc = set_schedlock_func; /* traps on target vector */
4290 add_show_from_set (c, &showlist);