1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986-1989, 1991-1999 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
27 #include "breakpoint.h"
32 #include "gdbthread.h"
34 #include "symfile.h" /* for overlay functions */
39 /* Prototypes for local functions */
41 static void signals_info (char *, int);
43 static void handle_command (char *, int);
45 static void sig_print_info (enum target_signal);
47 static void sig_print_header (void);
49 static void resume_cleanups (int);
51 static int hook_stop_stub (void *);
53 static void delete_breakpoint_current_contents (void *);
55 static void set_follow_fork_mode_command (char *arg, int from_tty,
56 struct cmd_list_element * c);
58 static struct inferior_status *xmalloc_inferior_status (void);
60 static void free_inferior_status (struct inferior_status *);
62 static int restore_selected_frame (void *);
64 static void build_infrun (void);
66 static void follow_inferior_fork (int parent_pid, int child_pid,
67 int has_forked, int has_vforked);
69 static void follow_fork (int parent_pid, int child_pid);
71 static void follow_vfork (int parent_pid, int child_pid);
73 static void set_schedlock_func (char *args, int from_tty,
74 struct cmd_list_element * c);
76 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 switched_from_inferior_pid;
97 /* This will be true for configurations that may actually report an
98 inferior pid different from the original. At present this is only
99 true for HP-UX native. */
101 #ifndef MAY_SWITCH_FROM_INFERIOR_PID
102 #define MAY_SWITCH_FROM_INFERIOR_PID (0)
105 static int may_switch_from_inferior_pid = MAY_SWITCH_FROM_INFERIOR_PID;
107 /* This is true for configurations that may follow through execl() and
108 similar functions. At present this is only true for HP-UX native. */
110 #ifndef MAY_FOLLOW_EXEC
111 #define MAY_FOLLOW_EXEC (0)
114 static int may_follow_exec = MAY_FOLLOW_EXEC;
116 /* resume and wait_for_inferior use this to ensure that when
117 stepping over a hit breakpoint in a threaded application
118 only the thread that hit the breakpoint is stepped and the
119 other threads don't continue. This prevents having another
120 thread run past the breakpoint while it is temporarily
123 This is not thread-specific, so it isn't saved as part of
126 Versions of gdb which don't use the "step == this thread steps
127 and others continue" model but instead use the "step == this
128 thread steps and others wait" shouldn't do this. */
130 static int thread_step_needed = 0;
132 /* This is true if thread_step_needed should actually be used. At
133 present this is only true for HP-UX native. */
135 #ifndef USE_THREAD_STEP_NEEDED
136 #define USE_THREAD_STEP_NEEDED (0)
139 static int use_thread_step_needed = USE_THREAD_STEP_NEEDED;
141 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
142 program. It needs to examine the jmp_buf argument and extract the PC
143 from it. The return value is non-zero on success, zero otherwise. */
145 #ifndef GET_LONGJMP_TARGET
146 #define GET_LONGJMP_TARGET(PC_ADDR) 0
150 /* Some machines have trampoline code that sits between function callers
151 and the actual functions themselves. If this machine doesn't have
152 such things, disable their processing. */
154 #ifndef SKIP_TRAMPOLINE_CODE
155 #define SKIP_TRAMPOLINE_CODE(pc) 0
158 /* Dynamic function trampolines are similar to solib trampolines in that they
159 are between the caller and the callee. The difference is that when you
160 enter a dynamic trampoline, you can't determine the callee's address. Some
161 (usually complex) code needs to run in the dynamic trampoline to figure out
162 the callee's address. This macro is usually called twice. First, when we
163 enter the trampoline (looks like a normal function call at that point). It
164 should return the PC of a point within the trampoline where the callee's
165 address is known. Second, when we hit the breakpoint, this routine returns
166 the callee's address. At that point, things proceed as per a step resume
169 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
170 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
173 /* If the program uses ELF-style shared libraries, then calls to
174 functions in shared libraries go through stubs, which live in a
175 table called the PLT (Procedure Linkage Table). The first time the
176 function is called, the stub sends control to the dynamic linker,
177 which looks up the function's real address, patches the stub so
178 that future calls will go directly to the function, and then passes
179 control to the function.
181 If we are stepping at the source level, we don't want to see any of
182 this --- we just want to skip over the stub and the dynamic linker.
183 The simple approach is to single-step until control leaves the
186 However, on some systems (e.g., Red Hat Linux 5.2) the dynamic
187 linker calls functions in the shared C library, so you can't tell
188 from the PC alone whether the dynamic linker is still running. In
189 this case, we use a step-resume breakpoint to get us past the
190 dynamic linker, as if we were using "next" to step over a function
193 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
194 linker code or not. Normally, this means we single-step. However,
195 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
196 address where we can place a step-resume breakpoint to get past the
197 linker's symbol resolution function.
199 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
200 pretty portable way, by comparing the PC against the address ranges
201 of the dynamic linker's sections.
203 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
204 it depends on internal details of the dynamic linker. It's usually
205 not too hard to figure out where to put a breakpoint, but it
206 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
207 sanity checking. If it can't figure things out, returning zero and
208 getting the (possibly confusing) stepping behavior is better than
209 signalling an error, which will obscure the change in the
212 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
213 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
216 #ifndef SKIP_SOLIB_RESOLVER
217 #define SKIP_SOLIB_RESOLVER(pc) 0
220 /* For SVR4 shared libraries, each call goes through a small piece of
221 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
222 to nonzero if we are current stopped in one of these. */
224 #ifndef IN_SOLIB_CALL_TRAMPOLINE
225 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
228 /* In some shared library schemes, the return path from a shared library
229 call may need to go through a trampoline too. */
231 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
232 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
235 /* This function returns TRUE if pc is the address of an instruction
236 that lies within the dynamic linker (such as the event hook, or the
239 This function must be used only when a dynamic linker event has
240 been caught, and the inferior is being stepped out of the hook, or
241 undefined results are guaranteed. */
243 #ifndef SOLIB_IN_DYNAMIC_LINKER
244 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
247 /* On MIPS16, a function that returns a floating point value may call
248 a library helper function to copy the return value to a floating point
249 register. The IGNORE_HELPER_CALL macro returns non-zero if we
250 should ignore (i.e. step over) this function call. */
251 #ifndef IGNORE_HELPER_CALL
252 #define IGNORE_HELPER_CALL(pc) 0
255 /* On some systems, the PC may be left pointing at an instruction that won't
256 actually be executed. This is usually indicated by a bit in the PSW. If
257 we find ourselves in such a state, then we step the target beyond the
258 nullified instruction before returning control to the user so as to avoid
261 #ifndef INSTRUCTION_NULLIFIED
262 #define INSTRUCTION_NULLIFIED 0
265 /* We can't step off a permanent breakpoint in the ordinary way, because we
266 can't remove it. Instead, we have to advance the PC to the next
267 instruction. This macro should expand to a pointer to a function that
268 does that, or zero if we have no such function. If we don't have a
269 definition for it, we have to report an error. */
270 #ifndef SKIP_PERMANENT_BREAKPOINT
271 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
273 default_skip_permanent_breakpoint ()
276 fprintf_filtered (gdb_stderr, "\
277 The program is stopped at a permanent breakpoint, but GDB does not know\n\
278 how to step past a permanent breakpoint on this architecture. Try using\n\
279 a command like `return' or `jump' to continue execution.\n");
280 return_to_top_level (RETURN_ERROR);
285 /* Convert the #defines into values. This is temporary until wfi control
286 flow is completely sorted out. */
288 #ifndef HAVE_STEPPABLE_WATCHPOINT
289 #define HAVE_STEPPABLE_WATCHPOINT 0
291 #undef HAVE_STEPPABLE_WATCHPOINT
292 #define HAVE_STEPPABLE_WATCHPOINT 1
295 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
296 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
298 #undef HAVE_NONSTEPPABLE_WATCHPOINT
299 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
302 #ifndef HAVE_CONTINUABLE_WATCHPOINT
303 #define HAVE_CONTINUABLE_WATCHPOINT 0
305 #undef HAVE_CONTINUABLE_WATCHPOINT
306 #define HAVE_CONTINUABLE_WATCHPOINT 1
309 /* Tables of how to react to signals; the user sets them. */
311 static unsigned char *signal_stop;
312 static unsigned char *signal_print;
313 static unsigned char *signal_program;
315 #define SET_SIGS(nsigs,sigs,flags) \
317 int signum = (nsigs); \
318 while (signum-- > 0) \
319 if ((sigs)[signum]) \
320 (flags)[signum] = 1; \
323 #define UNSET_SIGS(nsigs,sigs,flags) \
325 int signum = (nsigs); \
326 while (signum-- > 0) \
327 if ((sigs)[signum]) \
328 (flags)[signum] = 0; \
332 /* Command list pointer for the "stop" placeholder. */
334 static struct cmd_list_element *stop_command;
336 /* Nonzero if breakpoints are now inserted in the inferior. */
338 static int breakpoints_inserted;
340 /* Function inferior was in as of last step command. */
342 static struct symbol *step_start_function;
344 /* Nonzero if we are expecting a trace trap and should proceed from it. */
346 static int trap_expected;
349 /* Nonzero if we want to give control to the user when we're notified
350 of shared library events by the dynamic linker. */
351 static int stop_on_solib_events;
355 /* Nonzero if the next time we try to continue the inferior, it will
356 step one instruction and generate a spurious trace trap.
357 This is used to compensate for a bug in HP-UX. */
359 static int trap_expected_after_continue;
362 /* Nonzero means expecting a trace trap
363 and should stop the inferior and return silently when it happens. */
367 /* Nonzero means expecting a trap and caller will handle it themselves.
368 It is used after attach, due to attaching to a process;
369 when running in the shell before the child program has been exec'd;
370 and when running some kinds of remote stuff (FIXME?). */
372 int stop_soon_quietly;
374 /* Nonzero if proceed is being used for a "finish" command or a similar
375 situation when stop_registers should be saved. */
377 int proceed_to_finish;
379 /* Save register contents here when about to pop a stack dummy frame,
380 if-and-only-if proceed_to_finish is set.
381 Thus this contains the return value from the called function (assuming
382 values are returned in a register). */
384 char *stop_registers;
386 /* Nonzero if program stopped due to error trying to insert breakpoints. */
388 static int breakpoints_failed;
390 /* Nonzero after stop if current stack frame should be printed. */
392 static int stop_print_frame;
394 static struct breakpoint *step_resume_breakpoint = NULL;
395 static struct breakpoint *through_sigtramp_breakpoint = NULL;
397 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
398 interactions with an inferior that is running a kernel function
399 (aka, a system call or "syscall"). wait_for_inferior therefore
400 may have a need to know when the inferior is in a syscall. This
401 is a count of the number of inferior threads which are known to
402 currently be running in a syscall. */
403 static int number_of_threads_in_syscalls;
405 /* This is used to remember when a fork, vfork or exec event
406 was caught by a catchpoint, and thus the event is to be
407 followed at the next resume of the inferior, and not
411 enum target_waitkind kind;
421 char *execd_pathname;
425 /* Some platforms don't allow us to do anything meaningful with a
426 vforked child until it has exec'd. Vforked processes on such
427 platforms can only be followed after they've exec'd.
429 When this is set to 0, a vfork can be immediately followed,
430 and an exec can be followed merely as an exec. When this is
431 set to 1, a vfork event has been seen, but cannot be followed
432 until the exec is seen.
434 (In the latter case, inferior_pid is still the parent of the
435 vfork, and pending_follow.fork_event.child_pid is the child. The
436 appropriate process is followed, according to the setting of
437 follow-fork-mode.) */
438 static int follow_vfork_when_exec;
440 static char *follow_fork_mode_kind_names[] =
442 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
443 kernel problem. It's also not terribly useful without a GUI to
444 help the user drive two debuggers. So for now, I'm disabling
446 "parent", "child", "both", "ask" };
448 "parent", "child", "ask"};
450 static char *follow_fork_mode_string = NULL;
454 follow_inferior_fork (int parent_pid, int child_pid, int has_forked,
457 int followed_parent = 0;
458 int followed_child = 0;
460 /* Which process did the user want us to follow? */
462 savestring (follow_fork_mode_string, strlen (follow_fork_mode_string));
464 /* Or, did the user not know, and want us to ask? */
465 if (STREQ (follow_fork_mode_string, "ask"))
467 char requested_mode[100];
470 error ("\"ask\" mode NYI");
471 follow_mode = savestring (requested_mode, strlen (requested_mode));
474 /* If we're to be following the parent, then detach from child_pid.
475 We're already following the parent, so need do nothing explicit
477 if (STREQ (follow_mode, "parent"))
481 /* We're already attached to the parent, by default. */
483 /* Before detaching from the child, remove all breakpoints from
484 it. (This won't actually modify the breakpoint list, but will
485 physically remove the breakpoints from the child.) */
486 if (!has_vforked || !follow_vfork_when_exec)
488 detach_breakpoints (child_pid);
489 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
490 SOLIB_REMOVE_INFERIOR_HOOK (child_pid);
494 /* Detach from the child. */
497 target_require_detach (child_pid, "", 1);
500 /* If we're to be following the child, then attach to it, detach
501 from inferior_pid, and set inferior_pid to child_pid. */
502 else if (STREQ (follow_mode, "child"))
504 char child_pid_spelling[100]; /* Arbitrary length. */
508 /* Before detaching from the parent, detach all breakpoints from
509 the child. But only if we're forking, or if we follow vforks
510 as soon as they happen. (If we're following vforks only when
511 the child has exec'd, then it's very wrong to try to write
512 back the "shadow contents" of inserted breakpoints now -- they
513 belong to the child's pre-exec'd a.out.) */
514 if (!has_vforked || !follow_vfork_when_exec)
516 detach_breakpoints (child_pid);
519 /* Before detaching from the parent, remove all breakpoints from it. */
520 remove_breakpoints ();
522 /* Also reset the solib inferior hook from the parent. */
523 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
524 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid);
527 /* Detach from the parent. */
529 target_detach (NULL, 1);
531 /* Attach to the child. */
532 inferior_pid = child_pid;
533 sprintf (child_pid_spelling, "%d", child_pid);
536 target_require_attach (child_pid_spelling, 1);
538 /* Was there a step_resume breakpoint? (There was if the user
539 did a "next" at the fork() call.) If so, explicitly reset its
542 step_resumes are a form of bp that are made to be per-thread.
543 Since we created the step_resume bp when the parent process
544 was being debugged, and now are switching to the child process,
545 from the breakpoint package's viewpoint, that's a switch of
546 "threads". We must update the bp's notion of which thread
547 it is for, or it'll be ignored when it triggers... */
548 if (step_resume_breakpoint &&
549 (!has_vforked || !follow_vfork_when_exec))
550 breakpoint_re_set_thread (step_resume_breakpoint);
552 /* Reinsert all breakpoints in the child. (The user may've set
553 breakpoints after catching the fork, in which case those
554 actually didn't get set in the child, but only in the parent.) */
555 if (!has_vforked || !follow_vfork_when_exec)
557 breakpoint_re_set ();
558 insert_breakpoints ();
562 /* If we're to be following both parent and child, then fork ourselves,
563 and attach the debugger clone to the child. */
564 else if (STREQ (follow_mode, "both"))
566 char pid_suffix[100]; /* Arbitrary length. */
568 /* Clone ourselves to follow the child. This is the end of our
569 involvement with child_pid; our clone will take it from here... */
571 target_clone_and_follow_inferior (child_pid, &followed_child);
572 followed_parent = !followed_child;
574 /* We continue to follow the parent. To help distinguish the two
575 debuggers, though, both we and our clone will reset our prompts. */
576 sprintf (pid_suffix, "[%d] ", inferior_pid);
577 set_prompt (strcat (get_prompt (), pid_suffix));
580 /* The parent and child of a vfork share the same address space.
581 Also, on some targets the order in which vfork and exec events
582 are received for parent in child requires some delicate handling
585 For instance, on ptrace-based HPUX we receive the child's vfork
586 event first, at which time the parent has been suspended by the
587 OS and is essentially untouchable until the child's exit or second
588 exec event arrives. At that time, the parent's vfork event is
589 delivered to us, and that's when we see and decide how to follow
590 the vfork. But to get to that point, we must continue the child
591 until it execs or exits. To do that smoothly, all breakpoints
592 must be removed from the child, in case there are any set between
593 the vfork() and exec() calls. But removing them from the child
594 also removes them from the parent, due to the shared-address-space
595 nature of a vfork'd parent and child. On HPUX, therefore, we must
596 take care to restore the bp's to the parent before we continue it.
597 Else, it's likely that we may not stop in the expected place. (The
598 worst scenario is when the user tries to step over a vfork() call;
599 the step-resume bp must be restored for the step to properly stop
600 in the parent after the call completes!)
602 Sequence of events, as reported to gdb from HPUX:
604 Parent Child Action for gdb to take
605 -------------------------------------------------------
606 1 VFORK Continue child
612 target_post_follow_vfork (parent_pid,
618 pending_follow.fork_event.saw_parent_fork = 0;
619 pending_follow.fork_event.saw_child_fork = 0;
625 follow_fork (int parent_pid, int child_pid)
627 follow_inferior_fork (parent_pid, child_pid, 1, 0);
631 /* Forward declaration. */
632 static void follow_exec (int, char *);
635 follow_vfork (int parent_pid, int child_pid)
637 follow_inferior_fork (parent_pid, child_pid, 0, 1);
639 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
640 if (pending_follow.fork_event.saw_child_exec && (inferior_pid == child_pid))
642 pending_follow.fork_event.saw_child_exec = 0;
643 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
644 follow_exec (inferior_pid, pending_follow.execd_pathname);
645 free (pending_follow.execd_pathname);
650 follow_exec (int pid, char *execd_pathname)
653 struct target_ops *tgt;
655 if (!may_follow_exec)
658 /* Did this exec() follow a vfork()? If so, we must follow the
659 vfork now too. Do it before following the exec. */
660 if (follow_vfork_when_exec &&
661 (pending_follow.kind == TARGET_WAITKIND_VFORKED))
663 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
664 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
665 follow_vfork_when_exec = 0;
666 saved_pid = inferior_pid;
668 /* Did we follow the parent? If so, we're done. If we followed
669 the child then we must also follow its exec(). */
670 if (inferior_pid == pending_follow.fork_event.parent_pid)
674 /* This is an exec event that we actually wish to pay attention to.
675 Refresh our symbol table to the newly exec'd program, remove any
678 If there are breakpoints, they aren't really inserted now,
679 since the exec() transformed our inferior into a fresh set
682 We want to preserve symbolic breakpoints on the list, since
683 we have hopes that they can be reset after the new a.out's
684 symbol table is read.
686 However, any "raw" breakpoints must be removed from the list
687 (e.g., the solib bp's), since their address is probably invalid
690 And, we DON'T want to call delete_breakpoints() here, since
691 that may write the bp's "shadow contents" (the instruction
692 value that was overwritten witha TRAP instruction). Since
693 we now have a new a.out, those shadow contents aren't valid. */
694 update_breakpoints_after_exec ();
696 /* If there was one, it's gone now. We cannot truly step-to-next
697 statement through an exec(). */
698 step_resume_breakpoint = NULL;
699 step_range_start = 0;
702 /* If there was one, it's gone now. */
703 through_sigtramp_breakpoint = NULL;
705 /* What is this a.out's name? */
706 printf_unfiltered ("Executing new program: %s\n", execd_pathname);
708 /* We've followed the inferior through an exec. Therefore, the
709 inferior has essentially been killed & reborn. */
711 /* First collect the run target in effect. */
712 tgt = find_run_target ();
713 /* If we can't find one, things are in a very strange state... */
715 error ("Could find run target to save before following exec");
717 gdb_flush (gdb_stdout);
718 target_mourn_inferior ();
719 inferior_pid = saved_pid; /* Because mourn_inferior resets inferior_pid. */
722 /* That a.out is now the one to use. */
723 exec_file_attach (execd_pathname, 0);
725 /* And also is where symbols can be found. */
726 symbol_file_command (execd_pathname, 0);
728 /* Reset the shared library package. This ensures that we get
729 a shlib event when the child reaches "_start", at which point
730 the dld will have had a chance to initialize the child. */
731 #if defined(SOLIB_RESTART)
734 #ifdef SOLIB_CREATE_INFERIOR_HOOK
735 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid);
738 /* Reinsert all breakpoints. (Those which were symbolic have
739 been reset to the proper address in the new a.out, thanks
740 to symbol_file_command...) */
741 insert_breakpoints ();
743 /* The next resume of this inferior should bring it to the shlib
744 startup breakpoints. (If the user had also set bp's on
745 "main" from the old (parent) process, then they'll auto-
746 matically get reset there in the new process.) */
749 /* Non-zero if we just simulating a single-step. This is needed
750 because we cannot remove the breakpoints in the inferior process
751 until after the `wait' in `wait_for_inferior'. */
752 static int singlestep_breakpoints_inserted_p = 0;
755 /* Things to clean up if we QUIT out of resume (). */
758 resume_cleanups (int arg)
763 static char schedlock_off[] = "off";
764 static char schedlock_on[] = "on";
765 static char schedlock_step[] = "step";
766 static char *scheduler_mode = schedlock_off;
767 static char *scheduler_enums[] =
768 {schedlock_off, schedlock_on, schedlock_step};
771 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
773 if (c->type == set_cmd)
774 if (!target_can_lock_scheduler)
776 scheduler_mode = schedlock_off;
777 error ("Target '%s' cannot support this command.",
785 /* Resume the inferior, but allow a QUIT. This is useful if the user
786 wants to interrupt some lengthy single-stepping operation
787 (for child processes, the SIGINT goes to the inferior, and so
788 we get a SIGINT random_signal, but for remote debugging and perhaps
789 other targets, that's not true).
791 STEP nonzero if we should step (zero to continue instead).
792 SIG is the signal to give the inferior (zero for none). */
794 resume (int step, enum target_signal sig)
796 int should_resume = 1;
797 struct cleanup *old_cleanups = make_cleanup ((make_cleanup_func)
801 #ifdef CANNOT_STEP_BREAKPOINT
802 /* Most targets can step a breakpoint instruction, thus executing it
803 normally. But if this one cannot, just continue and we will hit
805 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
809 /* Normally, by the time we reach `resume', the breakpoints are either
810 removed or inserted, as appropriate. The exception is if we're sitting
811 at a permanent breakpoint; we need to step over it, but permanent
812 breakpoints can't be removed. So we have to test for it here. */
813 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here)
814 SKIP_PERMANENT_BREAKPOINT ();
816 if (SOFTWARE_SINGLE_STEP_P && step)
818 /* Do it the hard way, w/temp breakpoints */
819 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ );
820 /* ...and don't ask hardware to do it. */
822 /* and do not pull these breakpoints until after a `wait' in
823 `wait_for_inferior' */
824 singlestep_breakpoints_inserted_p = 1;
827 /* Handle any optimized stores to the inferior NOW... */
828 #ifdef DO_DEFERRED_STORES
832 /* If there were any forks/vforks/execs that were caught and are
833 now to be followed, then do so. */
834 switch (pending_follow.kind)
836 case (TARGET_WAITKIND_FORKED):
837 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
838 follow_fork (inferior_pid, pending_follow.fork_event.child_pid);
841 case (TARGET_WAITKIND_VFORKED):
843 int saw_child_exec = pending_follow.fork_event.saw_child_exec;
845 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
846 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
848 /* Did we follow the child, but not yet see the child's exec event?
849 If so, then it actually ought to be waiting for us; we respond to
850 parent vfork events. We don't actually want to resume the child
851 in this situation; we want to just get its exec event. */
852 if (!saw_child_exec &&
853 (inferior_pid == pending_follow.fork_event.child_pid))
858 case (TARGET_WAITKIND_EXECD):
859 /* If we saw a vfork event but couldn't follow it until we saw
860 an exec, then now might be the time! */
861 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
862 /* follow_exec is called as soon as the exec event is seen. */
869 /* Install inferior's terminal modes. */
870 target_terminal_inferior ();
874 if (use_thread_step_needed && thread_step_needed)
876 /* We stopped on a BPT instruction;
877 don't continue other threads and
878 just step this thread. */
879 thread_step_needed = 0;
881 if (!breakpoint_here_p (read_pc ()))
883 /* Breakpoint deleted: ok to do regular resume
884 where all the threads either step or continue. */
885 target_resume (-1, step, sig);
891 warning ("Internal error, changing continue to step.");
892 remove_breakpoints ();
893 breakpoints_inserted = 0;
898 target_resume (inferior_pid, step, sig);
903 /* Vanilla resume. */
905 if ((scheduler_mode == schedlock_on) ||
906 (scheduler_mode == schedlock_step && step != 0))
907 target_resume (inferior_pid, step, sig);
909 target_resume (-1, step, sig);
913 discard_cleanups (old_cleanups);
917 /* Clear out all variables saying what to do when inferior is continued.
918 First do this, then set the ones you want, then call `proceed'. */
921 clear_proceed_status (void)
924 step_range_start = 0;
926 step_frame_address = 0;
927 step_over_calls = -1;
929 stop_soon_quietly = 0;
930 proceed_to_finish = 0;
931 breakpoint_proceeded = 1; /* We're about to proceed... */
933 /* Discard any remaining commands or status from previous stop. */
934 bpstat_clear (&stop_bpstat);
937 /* Basic routine for continuing the program in various fashions.
939 ADDR is the address to resume at, or -1 for resume where stopped.
940 SIGGNAL is the signal to give it, or 0 for none,
941 or -1 for act according to how it stopped.
942 STEP is nonzero if should trap after one instruction.
943 -1 means return after that and print nothing.
944 You should probably set various step_... variables
945 before calling here, if you are stepping.
947 You should call clear_proceed_status before calling proceed. */
950 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
955 step_start_function = find_pc_function (read_pc ());
959 if (addr == (CORE_ADDR) -1)
961 /* If there is a breakpoint at the address we will resume at,
962 step one instruction before inserting breakpoints
963 so that we do not stop right away (and report a second
964 hit at this breakpoint). */
966 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
969 #ifndef STEP_SKIPS_DELAY
970 #define STEP_SKIPS_DELAY(pc) (0)
971 #define STEP_SKIPS_DELAY_P (0)
973 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
974 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
975 is slow (it needs to read memory from the target). */
976 if (STEP_SKIPS_DELAY_P
977 && breakpoint_here_p (read_pc () + 4)
978 && STEP_SKIPS_DELAY (read_pc ()))
985 /* New address; we don't need to single-step a thread
986 over a breakpoint we just hit, 'cause we aren't
987 continuing from there.
989 It's not worth worrying about the case where a user
990 asks for a "jump" at the current PC--if they get the
991 hiccup of re-hiting a hit breakpoint, what else do
993 thread_step_needed = 0;
996 #ifdef PREPARE_TO_PROCEED
997 /* In a multi-threaded task we may select another thread
998 and then continue or step.
1000 But if the old thread was stopped at a breakpoint, it
1001 will immediately cause another breakpoint stop without
1002 any execution (i.e. it will report a breakpoint hit
1003 incorrectly). So we must step over it first.
1005 PREPARE_TO_PROCEED checks the current thread against the thread
1006 that reported the most recent event. If a step-over is required
1007 it returns TRUE and sets the current thread to the old thread. */
1008 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
1011 thread_step_needed = 1;
1014 #endif /* PREPARE_TO_PROCEED */
1017 if (trap_expected_after_continue)
1019 /* If (step == 0), a trap will be automatically generated after
1020 the first instruction is executed. Force step one
1021 instruction to clear this condition. This should not occur
1022 if step is nonzero, but it is harmless in that case. */
1024 trap_expected_after_continue = 0;
1026 #endif /* HP_OS_BUG */
1029 /* We will get a trace trap after one instruction.
1030 Continue it automatically and insert breakpoints then. */
1034 int temp = insert_breakpoints ();
1037 print_sys_errmsg ("ptrace", temp);
1038 error ("Cannot insert breakpoints.\n\
1039 The same program may be running in another process.");
1042 breakpoints_inserted = 1;
1045 if (siggnal != TARGET_SIGNAL_DEFAULT)
1046 stop_signal = siggnal;
1047 /* If this signal should not be seen by program,
1048 give it zero. Used for debugging signals. */
1049 else if (!signal_program[stop_signal])
1050 stop_signal = TARGET_SIGNAL_0;
1052 annotate_starting ();
1054 /* Make sure that output from GDB appears before output from the
1056 gdb_flush (gdb_stdout);
1058 /* Resume inferior. */
1059 resume (oneproc || step || bpstat_should_step (), stop_signal);
1061 /* Wait for it to stop (if not standalone)
1062 and in any case decode why it stopped, and act accordingly. */
1063 /* Do this only if we are not using the event loop, or if the target
1064 does not support asynchronous execution. */
1065 if (!event_loop_p || !target_can_async_p ())
1067 wait_for_inferior ();
1072 /* Record the pc and sp of the program the last time it stopped.
1073 These are just used internally by wait_for_inferior, but need
1074 to be preserved over calls to it and cleared when the inferior
1076 static CORE_ADDR prev_pc;
1077 static CORE_ADDR prev_func_start;
1078 static char *prev_func_name;
1081 /* Start remote-debugging of a machine over a serial link. */
1086 init_thread_list ();
1087 init_wait_for_inferior ();
1088 stop_soon_quietly = 1;
1091 /* Always go on waiting for the target, regardless of the mode. */
1092 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1093 indicate th wait_for_inferior that a target should timeout if
1094 nothing is returned (instead of just blocking). Because of this,
1095 targets expecting an immediate response need to, internally, set
1096 things up so that the target_wait() is forced to eventually
1098 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1099 differentiate to its caller what the state of the target is after
1100 the initial open has been performed. Here we're assuming that
1101 the target has stopped. It should be possible to eventually have
1102 target_open() return to the caller an indication that the target
1103 is currently running and GDB state should be set to the same as
1104 for an async run. */
1105 wait_for_inferior ();
1109 /* Initialize static vars when a new inferior begins. */
1112 init_wait_for_inferior (void)
1114 /* These are meaningless until the first time through wait_for_inferior. */
1116 prev_func_start = 0;
1117 prev_func_name = NULL;
1120 trap_expected_after_continue = 0;
1122 breakpoints_inserted = 0;
1123 breakpoint_init_inferior (inf_starting);
1125 /* Don't confuse first call to proceed(). */
1126 stop_signal = TARGET_SIGNAL_0;
1128 /* The first resume is not following a fork/vfork/exec. */
1129 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
1130 pending_follow.fork_event.saw_parent_fork = 0;
1131 pending_follow.fork_event.saw_child_fork = 0;
1132 pending_follow.fork_event.saw_child_exec = 0;
1134 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1135 number_of_threads_in_syscalls = 0;
1137 clear_proceed_status ();
1141 delete_breakpoint_current_contents (void *arg)
1143 struct breakpoint **breakpointp = (struct breakpoint **) arg;
1144 if (*breakpointp != NULL)
1146 delete_breakpoint (*breakpointp);
1147 *breakpointp = NULL;
1151 /* This enum encodes possible reasons for doing a target_wait, so that
1152 wfi can call target_wait in one place. (Ultimately the call will be
1153 moved out of the infinite loop entirely.) */
1157 infwait_normal_state,
1158 infwait_thread_hop_state,
1159 infwait_nullified_state,
1160 infwait_nonstep_watch_state
1163 /* This structure contains what used to be local variables in
1164 wait_for_inferior. Probably many of them can return to being
1165 locals in handle_inferior_event. */
1167 struct execution_control_state
1169 struct target_waitstatus ws;
1170 struct target_waitstatus *wp;
1173 CORE_ADDR stop_func_start;
1174 CORE_ADDR stop_func_end;
1175 char *stop_func_name;
1176 struct symtab_and_line sal;
1177 int remove_breakpoints_on_following_step;
1179 struct symtab *current_symtab;
1180 int handling_longjmp; /* FIXME */
1182 int saved_inferior_pid;
1184 int stepping_through_solib_after_catch;
1185 bpstat stepping_through_solib_catchpoints;
1186 int enable_hw_watchpoints_after_wait;
1187 int stepping_through_sigtramp;
1188 int new_thread_event;
1189 struct target_waitstatus tmpstatus;
1190 enum infwait_states infwait_state;
1195 void init_execution_control_state (struct execution_control_state * ecs);
1197 void handle_inferior_event (struct execution_control_state * ecs);
1199 static void check_sigtramp2 (struct execution_control_state *ecs);
1200 static void step_into_function (struct execution_control_state *ecs);
1201 static void step_over_function (struct execution_control_state *ecs);
1202 static void stop_stepping (struct execution_control_state *ecs);
1203 static void prepare_to_wait (struct execution_control_state *ecs);
1204 static void keep_going (struct execution_control_state *ecs);
1206 /* Wait for control to return from inferior to debugger.
1207 If inferior gets a signal, we may decide to start it up again
1208 instead of returning. That is why there is a loop in this function.
1209 When this function actually returns it means the inferior
1210 should be left stopped and GDB should read more commands. */
1213 wait_for_inferior (void)
1215 struct cleanup *old_cleanups;
1216 struct execution_control_state ecss;
1217 struct execution_control_state *ecs;
1219 old_cleanups = make_cleanup (delete_breakpoint_current_contents,
1220 &step_resume_breakpoint);
1221 make_cleanup (delete_breakpoint_current_contents,
1222 &through_sigtramp_breakpoint);
1224 /* wfi still stays in a loop, so it's OK just to take the address of
1225 a local to get the ecs pointer. */
1228 /* Fill in with reasonable starting values. */
1229 init_execution_control_state (ecs);
1231 thread_step_needed = 0;
1233 /* We'll update this if & when we switch to a new thread. */
1234 if (may_switch_from_inferior_pid)
1235 switched_from_inferior_pid = inferior_pid;
1237 overlay_cache_invalid = 1;
1239 /* We have to invalidate the registers BEFORE calling target_wait
1240 because they can be loaded from the target while in target_wait.
1241 This makes remote debugging a bit more efficient for those
1242 targets that provide critical registers as part of their normal
1243 status mechanism. */
1245 registers_changed ();
1249 if (target_wait_hook)
1250 ecs->pid = target_wait_hook (ecs->waiton_pid, ecs->wp);
1252 ecs->pid = target_wait (ecs->waiton_pid, ecs->wp);
1254 /* Now figure out what to do with the result of the result. */
1255 handle_inferior_event (ecs);
1257 if (!ecs->wait_some_more)
1260 do_cleanups (old_cleanups);
1263 /* Asynchronous version of wait_for_inferior. It is called by the
1264 event loop whenever a change of state is detected on the file
1265 descriptor corresponding to the target. It can be called more than
1266 once to complete a single execution command. In such cases we need
1267 to keep the state in a global variable ASYNC_ECSS. If it is the
1268 last time that this function is called for a single execution
1269 command, then report to the user that the inferior has stopped, and
1270 do the necessary cleanups. */
1272 struct execution_control_state async_ecss;
1273 struct execution_control_state *async_ecs;
1276 fetch_inferior_event (client_data)
1279 static struct cleanup *old_cleanups;
1281 async_ecs = &async_ecss;
1283 if (!async_ecs->wait_some_more)
1285 old_cleanups = make_exec_cleanup (delete_breakpoint_current_contents,
1286 &step_resume_breakpoint);
1287 make_exec_cleanup (delete_breakpoint_current_contents,
1288 &through_sigtramp_breakpoint);
1290 /* Fill in with reasonable starting values. */
1291 init_execution_control_state (async_ecs);
1293 thread_step_needed = 0;
1295 /* We'll update this if & when we switch to a new thread. */
1296 if (may_switch_from_inferior_pid)
1297 switched_from_inferior_pid = inferior_pid;
1299 overlay_cache_invalid = 1;
1301 /* We have to invalidate the registers BEFORE calling target_wait
1302 because they can be loaded from the target while in target_wait.
1303 This makes remote debugging a bit more efficient for those
1304 targets that provide critical registers as part of their normal
1305 status mechanism. */
1307 registers_changed ();
1310 if (target_wait_hook)
1311 async_ecs->pid = target_wait_hook (async_ecs->waiton_pid, async_ecs->wp);
1313 async_ecs->pid = target_wait (async_ecs->waiton_pid, async_ecs->wp);
1315 /* Now figure out what to do with the result of the result. */
1316 handle_inferior_event (async_ecs);
1318 if (!async_ecs->wait_some_more)
1320 /* Do only the cleanups that have been added by this
1321 function. Let the continuations for the commands do the rest,
1322 if there are any. */
1323 do_exec_cleanups (old_cleanups);
1325 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1329 /* Prepare an execution control state for looping through a
1330 wait_for_inferior-type loop. */
1333 init_execution_control_state (struct execution_control_state *ecs)
1335 ecs->random_signal = 0;
1336 ecs->remove_breakpoints_on_following_step = 0;
1337 ecs->handling_longjmp = 0; /* FIXME */
1338 ecs->update_step_sp = 0;
1339 ecs->stepping_through_solib_after_catch = 0;
1340 ecs->stepping_through_solib_catchpoints = NULL;
1341 ecs->enable_hw_watchpoints_after_wait = 0;
1342 ecs->stepping_through_sigtramp = 0;
1343 ecs->sal = find_pc_line (prev_pc, 0);
1344 ecs->current_line = ecs->sal.line;
1345 ecs->current_symtab = ecs->sal.symtab;
1346 ecs->infwait_state = infwait_normal_state;
1347 ecs->waiton_pid = -1;
1348 ecs->wp = &(ecs->ws);
1351 /* Call this function before setting step_resume_breakpoint, as a
1352 sanity check. There should never be more than one step-resume
1353 breakpoint per thread, so we should never be setting a new
1354 step_resume_breakpoint when one is already active. */
1356 check_for_old_step_resume_breakpoint (void)
1358 if (step_resume_breakpoint)
1359 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1362 /* Given an execution control state that has been freshly filled in
1363 by an event from the inferior, figure out what it means and take
1364 appropriate action. */
1367 handle_inferior_event (struct execution_control_state *ecs)
1370 int stepped_after_stopped_by_watchpoint;
1372 /* Keep this extra brace for now, minimizes diffs. */
1374 switch (ecs->infwait_state)
1376 case infwait_normal_state:
1377 /* Since we've done a wait, we have a new event. Don't
1378 carry over any expectations about needing to step over a
1380 thread_step_needed = 0;
1382 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1383 is serviced in this loop, below. */
1384 if (ecs->enable_hw_watchpoints_after_wait)
1386 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid);
1387 ecs->enable_hw_watchpoints_after_wait = 0;
1389 stepped_after_stopped_by_watchpoint = 0;
1392 case infwait_thread_hop_state:
1393 insert_breakpoints ();
1395 /* We need to restart all the threads now,
1396 * unles we're running in scheduler-locked mode.
1397 * FIXME: shouldn't we look at currently_stepping ()?
1399 if (scheduler_mode == schedlock_on)
1400 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1402 target_resume (-1, 0, TARGET_SIGNAL_0);
1403 ecs->infwait_state = infwait_normal_state;
1404 prepare_to_wait (ecs);
1407 case infwait_nullified_state:
1410 case infwait_nonstep_watch_state:
1411 insert_breakpoints ();
1413 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1414 handle things like signals arriving and other things happening
1415 in combination correctly? */
1416 stepped_after_stopped_by_watchpoint = 1;
1419 ecs->infwait_state = infwait_normal_state;
1421 flush_cached_frames ();
1423 /* If it's a new process, add it to the thread database */
1425 ecs->new_thread_event = ((ecs->pid != inferior_pid) && !in_thread_list (ecs->pid));
1427 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1428 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
1429 && ecs->new_thread_event)
1431 add_thread (ecs->pid);
1433 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs->pid));
1436 /* NOTE: This block is ONLY meant to be invoked in case of a
1437 "thread creation event"! If it is invoked for any other
1438 sort of event (such as a new thread landing on a breakpoint),
1439 the event will be discarded, which is almost certainly
1442 To avoid this, the low-level module (eg. target_wait)
1443 should call in_thread_list and add_thread, so that the
1444 new thread is known by the time we get here. */
1446 /* We may want to consider not doing a resume here in order
1447 to give the user a chance to play with the new thread.
1448 It might be good to make that a user-settable option. */
1450 /* At this point, all threads are stopped (happens
1451 automatically in either the OS or the native code).
1452 Therefore we need to continue all threads in order to
1455 target_resume (-1, 0, TARGET_SIGNAL_0);
1456 prepare_to_wait (ecs);
1461 switch (ecs->ws.kind)
1463 case TARGET_WAITKIND_LOADED:
1464 /* Ignore gracefully during startup of the inferior, as it
1465 might be the shell which has just loaded some objects,
1466 otherwise add the symbols for the newly loaded objects. */
1468 if (!stop_soon_quietly)
1470 /* Remove breakpoints, SOLIB_ADD might adjust
1471 breakpoint addresses via breakpoint_re_set. */
1472 if (breakpoints_inserted)
1473 remove_breakpoints ();
1475 /* Check for any newly added shared libraries if we're
1476 supposed to be adding them automatically. */
1479 /* Switch terminal for any messages produced by
1480 breakpoint_re_set. */
1481 target_terminal_ours_for_output ();
1482 SOLIB_ADD (NULL, 0, NULL);
1483 target_terminal_inferior ();
1486 /* Reinsert breakpoints and continue. */
1487 if (breakpoints_inserted)
1488 insert_breakpoints ();
1491 resume (0, TARGET_SIGNAL_0);
1492 prepare_to_wait (ecs);
1495 case TARGET_WAITKIND_SPURIOUS:
1496 resume (0, TARGET_SIGNAL_0);
1497 prepare_to_wait (ecs);
1500 case TARGET_WAITKIND_EXITED:
1501 target_terminal_ours (); /* Must do this before mourn anyway */
1502 annotate_exited (ecs->ws.value.integer);
1503 if (ecs->ws.value.integer)
1504 printf_filtered ("\nProgram exited with code 0%o.\n",
1505 (unsigned int) ecs->ws.value.integer);
1507 printf_filtered ("\nProgram exited normally.\n");
1509 /* Record the exit code in the convenience variable $_exitcode, so
1510 that the user can inspect this again later. */
1511 set_internalvar (lookup_internalvar ("_exitcode"),
1512 value_from_longest (builtin_type_int,
1513 (LONGEST) ecs->ws.value.integer));
1514 gdb_flush (gdb_stdout);
1515 target_mourn_inferior ();
1516 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P */
1517 stop_print_frame = 0;
1518 stop_stepping (ecs);
1521 case TARGET_WAITKIND_SIGNALLED:
1522 stop_print_frame = 0;
1523 stop_signal = ecs->ws.value.sig;
1524 target_terminal_ours (); /* Must do this before mourn anyway */
1525 annotate_signalled ();
1527 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1528 mean it is already dead? This has been here since GDB 2.8, so
1529 perhaps it means rms didn't understand unix waitstatuses?
1530 For the moment I'm just kludging around this in remote.c
1531 rather than trying to change it here --kingdon, 5 Dec 1994. */
1532 target_kill (); /* kill mourns as well */
1534 printf_filtered ("\nProgram terminated with signal ");
1535 annotate_signal_name ();
1536 printf_filtered ("%s", target_signal_to_name (stop_signal));
1537 annotate_signal_name_end ();
1538 printf_filtered (", ");
1539 annotate_signal_string ();
1540 printf_filtered ("%s", target_signal_to_string (stop_signal));
1541 annotate_signal_string_end ();
1542 printf_filtered (".\n");
1544 printf_filtered ("The program no longer exists.\n");
1545 gdb_flush (gdb_stdout);
1546 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P */
1547 stop_stepping (ecs);
1550 /* The following are the only cases in which we keep going;
1551 the above cases end in a continue or goto. */
1552 case TARGET_WAITKIND_FORKED:
1553 stop_signal = TARGET_SIGNAL_TRAP;
1554 pending_follow.kind = ecs->ws.kind;
1556 /* Ignore fork events reported for the parent; we're only
1557 interested in reacting to forks of the child. Note that
1558 we expect the child's fork event to be available if we
1559 waited for it now. */
1560 if (inferior_pid == ecs->pid)
1562 pending_follow.fork_event.saw_parent_fork = 1;
1563 pending_follow.fork_event.parent_pid = ecs->pid;
1564 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1565 prepare_to_wait (ecs);
1570 pending_follow.fork_event.saw_child_fork = 1;
1571 pending_follow.fork_event.child_pid = ecs->pid;
1572 pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid;
1575 stop_pc = read_pc_pid (ecs->pid);
1576 ecs->saved_inferior_pid = inferior_pid;
1577 inferior_pid = ecs->pid;
1578 stop_bpstat = bpstat_stop_status (&stop_pc, currently_stepping (ecs));
1579 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1580 inferior_pid = ecs->saved_inferior_pid;
1581 goto process_event_stop_test;
1583 /* If this a platform which doesn't allow a debugger to touch a
1584 vfork'd inferior until after it exec's, then we'd best keep
1585 our fingers entirely off the inferior, other than continuing
1586 it. This has the unfortunate side-effect that catchpoints
1587 of vforks will be ignored. But since the platform doesn't
1588 allow the inferior be touched at vfork time, there's really
1590 case TARGET_WAITKIND_VFORKED:
1591 stop_signal = TARGET_SIGNAL_TRAP;
1592 pending_follow.kind = ecs->ws.kind;
1594 /* Is this a vfork of the parent? If so, then give any
1595 vfork catchpoints a chance to trigger now. (It's
1596 dangerous to do so if the child canot be touched until
1597 it execs, and the child has not yet exec'd. We probably
1598 should warn the user to that effect when the catchpoint
1600 if (ecs->pid == inferior_pid)
1602 pending_follow.fork_event.saw_parent_fork = 1;
1603 pending_follow.fork_event.parent_pid = ecs->pid;
1604 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1607 /* If we've seen the child's vfork event but cannot really touch
1608 the child until it execs, then we must continue the child now.
1609 Else, give any vfork catchpoints a chance to trigger now. */
1612 pending_follow.fork_event.saw_child_fork = 1;
1613 pending_follow.fork_event.child_pid = ecs->pid;
1614 pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid;
1615 target_post_startup_inferior (pending_follow.fork_event.child_pid);
1616 follow_vfork_when_exec = !target_can_follow_vfork_prior_to_exec ();
1617 if (follow_vfork_when_exec)
1619 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1620 prepare_to_wait (ecs);
1625 stop_pc = read_pc ();
1626 stop_bpstat = bpstat_stop_status (&stop_pc, currently_stepping (ecs));
1627 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1628 goto process_event_stop_test;
1630 case TARGET_WAITKIND_EXECD:
1631 stop_signal = TARGET_SIGNAL_TRAP;
1633 /* Is this a target which reports multiple exec events per actual
1634 call to exec()? (HP-UX using ptrace does, for example.) If so,
1635 ignore all but the last one. Just resume the exec'r, and wait
1636 for the next exec event. */
1637 if (inferior_ignoring_leading_exec_events)
1639 inferior_ignoring_leading_exec_events--;
1640 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1641 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.parent_pid);
1642 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1643 prepare_to_wait (ecs);
1646 inferior_ignoring_leading_exec_events =
1647 target_reported_exec_events_per_exec_call () - 1;
1649 pending_follow.execd_pathname =
1650 savestring (ecs->ws.value.execd_pathname,
1651 strlen (ecs->ws.value.execd_pathname));
1653 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1654 child of a vfork exec?
1656 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1657 HP-UX, events associated with a vforking inferior come in
1658 threes: a vfork event for the child (always first), followed
1659 a vfork event for the parent and an exec event for the child.
1660 The latter two can come in either order.
1662 If we get the parent vfork event first, life's good: We follow
1663 either the parent or child, and then the child's exec event is
1666 But if we get the child's exec event first, then we delay
1667 responding to it until we handle the parent's vfork. Because,
1668 otherwise we can't satisfy a "catch vfork". */
1669 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1671 pending_follow.fork_event.saw_child_exec = 1;
1673 /* On some targets, the child must be resumed before
1674 the parent vfork event is delivered. A single-step
1676 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1677 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1678 /* We expect the parent vfork event to be available now. */
1679 prepare_to_wait (ecs);
1683 /* This causes the eventpoints and symbol table to be reset. Must
1684 do this now, before trying to determine whether to stop. */
1685 follow_exec (inferior_pid, pending_follow.execd_pathname);
1686 free (pending_follow.execd_pathname);
1688 stop_pc = read_pc_pid (ecs->pid);
1689 ecs->saved_inferior_pid = inferior_pid;
1690 inferior_pid = ecs->pid;
1691 stop_bpstat = bpstat_stop_status (&stop_pc, currently_stepping (ecs));
1692 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1693 inferior_pid = ecs->saved_inferior_pid;
1694 goto process_event_stop_test;
1696 /* These syscall events are returned on HP-UX, as part of its
1697 implementation of page-protection-based "hardware" watchpoints.
1698 HP-UX has unfortunate interactions between page-protections and
1699 some system calls. Our solution is to disable hardware watches
1700 when a system call is entered, and reenable them when the syscall
1701 completes. The downside of this is that we may miss the precise
1702 point at which a watched piece of memory is modified. "Oh well."
1704 Note that we may have multiple threads running, which may each
1705 enter syscalls at roughly the same time. Since we don't have a
1706 good notion currently of whether a watched piece of memory is
1707 thread-private, we'd best not have any page-protections active
1708 when any thread is in a syscall. Thus, we only want to reenable
1709 hardware watches when no threads are in a syscall.
1711 Also, be careful not to try to gather much state about a thread
1712 that's in a syscall. It's frequently a losing proposition. */
1713 case TARGET_WAITKIND_SYSCALL_ENTRY:
1714 number_of_threads_in_syscalls++;
1715 if (number_of_threads_in_syscalls == 1)
1717 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid);
1719 resume (0, TARGET_SIGNAL_0);
1720 prepare_to_wait (ecs);
1723 /* Before examining the threads further, step this thread to
1724 get it entirely out of the syscall. (We get notice of the
1725 event when the thread is just on the verge of exiting a
1726 syscall. Stepping one instruction seems to get it back
1729 Note that although the logical place to reenable h/w watches
1730 is here, we cannot. We cannot reenable them before stepping
1731 the thread (this causes the next wait on the thread to hang).
1733 Nor can we enable them after stepping until we've done a wait.
1734 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1735 here, which will be serviced immediately after the target
1737 case TARGET_WAITKIND_SYSCALL_RETURN:
1738 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1740 if (number_of_threads_in_syscalls > 0)
1742 number_of_threads_in_syscalls--;
1743 ecs->enable_hw_watchpoints_after_wait =
1744 (number_of_threads_in_syscalls == 0);
1746 prepare_to_wait (ecs);
1749 case TARGET_WAITKIND_STOPPED:
1750 stop_signal = ecs->ws.value.sig;
1754 /* We may want to consider not doing a resume here in order to give
1755 the user a chance to play with the new thread. It might be good
1756 to make that a user-settable option. */
1758 /* At this point, all threads are stopped (happens automatically in
1759 either the OS or the native code). Therefore we need to continue
1760 all threads in order to make progress. */
1761 if (ecs->new_thread_event)
1763 target_resume (-1, 0, TARGET_SIGNAL_0);
1764 prepare_to_wait (ecs);
1768 stop_pc = read_pc_pid (ecs->pid);
1770 /* See if a thread hit a thread-specific breakpoint that was meant for
1771 another thread. If so, then step that thread past the breakpoint,
1774 if (stop_signal == TARGET_SIGNAL_TRAP)
1776 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1777 ecs->random_signal = 0;
1778 else if (breakpoints_inserted
1779 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
1781 ecs->random_signal = 0;
1782 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK,
1787 /* Saw a breakpoint, but it was hit by the wrong thread.
1789 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, ecs->pid);
1791 remove_status = remove_breakpoints ();
1792 /* Did we fail to remove breakpoints? If so, try
1793 to set the PC past the bp. (There's at least
1794 one situation in which we can fail to remove
1795 the bp's: On HP-UX's that use ttrace, we can't
1796 change the address space of a vforking child
1797 process until the child exits (well, okay, not
1798 then either :-) or execs. */
1799 if (remove_status != 0)
1801 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, ecs->pid);
1805 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1806 /* FIXME: What if a signal arrives instead of the
1807 single-step happening? */
1809 ecs->waiton_pid = ecs->pid;
1810 ecs->wp = &(ecs->ws);
1811 ecs->infwait_state = infwait_thread_hop_state;
1812 prepare_to_wait (ecs);
1816 /* We need to restart all the threads now,
1817 * unles we're running in scheduler-locked mode.
1818 * FIXME: shouldn't we look at currently_stepping ()?
1820 if (scheduler_mode == schedlock_on)
1821 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1823 target_resume (-1, 0, TARGET_SIGNAL_0);
1824 prepare_to_wait (ecs);
1829 /* This breakpoint matches--either it is the right
1830 thread or it's a generic breakpoint for all threads.
1831 Remember that we'll need to step just _this_ thread
1832 on any following user continuation! */
1833 thread_step_needed = 1;
1838 ecs->random_signal = 1;
1840 /* See if something interesting happened to the non-current thread. If
1841 so, then switch to that thread, and eventually give control back to
1844 Note that if there's any kind of pending follow (i.e., of a fork,
1845 vfork or exec), we don't want to do this now. Rather, we'll let
1846 the next resume handle it. */
1847 if ((ecs->pid != inferior_pid) &&
1848 (pending_follow.kind == TARGET_WAITKIND_SPURIOUS))
1852 /* If it's a random signal for a non-current thread, notify user
1853 if he's expressed an interest. */
1854 if (ecs->random_signal
1855 && signal_print[stop_signal])
1857 /* ??rehrauer: I don't understand the rationale for this code. If the
1858 inferior will stop as a result of this signal, then the act of handling
1859 the stop ought to print a message that's couches the stoppage in user
1860 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1861 won't stop as a result of the signal -- i.e., if the signal is merely
1862 a side-effect of something GDB's doing "under the covers" for the
1863 user, such as stepping threads over a breakpoint they shouldn't stop
1864 for -- then the message seems to be a serious annoyance at best.
1866 For now, remove the message altogether. */
1869 target_terminal_ours_for_output ();
1870 printf_filtered ("\nProgram received signal %s, %s.\n",
1871 target_signal_to_name (stop_signal),
1872 target_signal_to_string (stop_signal));
1873 gdb_flush (gdb_stdout);
1877 /* If it's not SIGTRAP and not a signal we want to stop for, then
1878 continue the thread. */
1880 if (stop_signal != TARGET_SIGNAL_TRAP
1881 && !signal_stop[stop_signal])
1884 target_terminal_inferior ();
1886 /* Clear the signal if it should not be passed. */
1887 if (signal_program[stop_signal] == 0)
1888 stop_signal = TARGET_SIGNAL_0;
1890 target_resume (ecs->pid, 0, stop_signal);
1891 prepare_to_wait (ecs);
1895 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1896 and fall into the rest of wait_for_inferior(). */
1898 /* Save infrun state for the old thread. */
1899 save_infrun_state (inferior_pid, prev_pc,
1900 prev_func_start, prev_func_name,
1901 trap_expected, step_resume_breakpoint,
1902 through_sigtramp_breakpoint,
1903 step_range_start, step_range_end,
1904 step_frame_address, ecs->handling_longjmp,
1906 ecs->stepping_through_solib_after_catch,
1907 ecs->stepping_through_solib_catchpoints,
1908 ecs->stepping_through_sigtramp);
1910 if (may_switch_from_inferior_pid)
1911 switched_from_inferior_pid = inferior_pid;
1913 inferior_pid = ecs->pid;
1915 /* Load infrun state for the new thread. */
1916 load_infrun_state (inferior_pid, &prev_pc,
1917 &prev_func_start, &prev_func_name,
1918 &trap_expected, &step_resume_breakpoint,
1919 &through_sigtramp_breakpoint,
1920 &step_range_start, &step_range_end,
1921 &step_frame_address, &ecs->handling_longjmp,
1923 &ecs->stepping_through_solib_after_catch,
1924 &ecs->stepping_through_solib_catchpoints,
1925 &ecs->stepping_through_sigtramp);
1928 context_hook (pid_to_thread_id (ecs->pid));
1930 printf_filtered ("[Switching to %s]\n", target_pid_to_str (ecs->pid));
1931 flush_cached_frames ();
1934 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1936 /* Pull the single step breakpoints out of the target. */
1937 SOFTWARE_SINGLE_STEP (0, 0);
1938 singlestep_breakpoints_inserted_p = 0;
1941 /* If PC is pointing at a nullified instruction, then step beyond
1942 it so that the user won't be confused when GDB appears to be ready
1945 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1946 if (INSTRUCTION_NULLIFIED)
1948 registers_changed ();
1949 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1951 /* We may have received a signal that we want to pass to
1952 the inferior; therefore, we must not clobber the waitstatus
1955 ecs->infwait_state = infwait_nullified_state;
1956 ecs->waiton_pid = ecs->pid;
1957 ecs->wp = &(ecs->tmpstatus);
1958 prepare_to_wait (ecs);
1962 /* It may not be necessary to disable the watchpoint to stop over
1963 it. For example, the PA can (with some kernel cooperation)
1964 single step over a watchpoint without disabling the watchpoint. */
1965 if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1968 prepare_to_wait (ecs);
1972 /* It is far more common to need to disable a watchpoint to step
1973 the inferior over it. FIXME. What else might a debug
1974 register or page protection watchpoint scheme need here? */
1975 if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1977 /* At this point, we are stopped at an instruction which has
1978 attempted to write to a piece of memory under control of
1979 a watchpoint. The instruction hasn't actually executed
1980 yet. If we were to evaluate the watchpoint expression
1981 now, we would get the old value, and therefore no change
1982 would seem to have occurred.
1984 In order to make watchpoints work `right', we really need
1985 to complete the memory write, and then evaluate the
1986 watchpoint expression. The following code does that by
1987 removing the watchpoint (actually, all watchpoints and
1988 breakpoints), single-stepping the target, re-inserting
1989 watchpoints, and then falling through to let normal
1990 single-step processing handle proceed. Since this
1991 includes evaluating watchpoints, things will come to a
1992 stop in the correct manner. */
1994 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
1996 remove_breakpoints ();
1997 registers_changed ();
1998 target_resume (ecs->pid, 1, TARGET_SIGNAL_0); /* Single step */
2000 ecs->waiton_pid = ecs->pid;
2001 ecs->wp = &(ecs->ws);
2002 ecs->infwait_state = infwait_nonstep_watch_state;
2003 prepare_to_wait (ecs);
2007 /* It may be possible to simply continue after a watchpoint. */
2008 if (HAVE_CONTINUABLE_WATCHPOINT)
2009 STOPPED_BY_WATCHPOINT (ecs->ws);
2011 ecs->stop_func_start = 0;
2012 ecs->stop_func_end = 0;
2013 ecs->stop_func_name = 0;
2014 /* Don't care about return value; stop_func_start and stop_func_name
2015 will both be 0 if it doesn't work. */
2016 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2017 &ecs->stop_func_start, &ecs->stop_func_end);
2018 ecs->stop_func_start += FUNCTION_START_OFFSET;
2019 ecs->another_trap = 0;
2020 bpstat_clear (&stop_bpstat);
2022 stop_stack_dummy = 0;
2023 stop_print_frame = 1;
2024 ecs->random_signal = 0;
2025 stopped_by_random_signal = 0;
2026 breakpoints_failed = 0;
2028 /* Look at the cause of the stop, and decide what to do.
2029 The alternatives are:
2030 1) break; to really stop and return to the debugger,
2031 2) drop through to start up again
2032 (set ecs->another_trap to 1 to single step once)
2033 3) set ecs->random_signal to 1, and the decision between 1 and 2
2034 will be made according to the signal handling tables. */
2036 /* First, distinguish signals caused by the debugger from signals
2037 that have to do with the program's own actions.
2038 Note that breakpoint insns may cause SIGTRAP or SIGILL
2039 or SIGEMT, depending on the operating system version.
2040 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2041 and change it to SIGTRAP. */
2043 if (stop_signal == TARGET_SIGNAL_TRAP
2044 || (breakpoints_inserted &&
2045 (stop_signal == TARGET_SIGNAL_ILL
2046 || stop_signal == TARGET_SIGNAL_EMT
2048 || stop_soon_quietly)
2050 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
2052 stop_print_frame = 0;
2053 stop_stepping (ecs);
2056 if (stop_soon_quietly)
2058 stop_stepping (ecs);
2062 /* Don't even think about breakpoints
2063 if just proceeded over a breakpoint.
2065 However, if we are trying to proceed over a breakpoint
2066 and end up in sigtramp, then through_sigtramp_breakpoint
2067 will be set and we should check whether we've hit the
2069 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
2070 && through_sigtramp_breakpoint == NULL)
2071 bpstat_clear (&stop_bpstat);
2074 /* See if there is a breakpoint at the current PC. */
2075 stop_bpstat = bpstat_stop_status
2077 /* Pass TRUE if our reason for stopping is something other
2078 than hitting a breakpoint. We do this by checking that
2079 1) stepping is going on and 2) we didn't hit a breakpoint
2080 in a signal handler without an intervening stop in
2081 sigtramp, which is detected by a new stack pointer value
2082 below any usual function calling stack adjustments. */
2083 (currently_stepping (ecs)
2085 && INNER_THAN (read_sp (), (step_sp - 16))))
2087 /* Following in case break condition called a
2089 stop_print_frame = 1;
2092 if (stop_signal == TARGET_SIGNAL_TRAP)
2094 = !(bpstat_explains_signal (stop_bpstat)
2096 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2097 && PC_IN_CALL_DUMMY (stop_pc, read_sp (),
2098 FRAME_FP (get_current_frame ())))
2099 || (step_range_end && step_resume_breakpoint == NULL));
2104 = !(bpstat_explains_signal (stop_bpstat)
2105 /* End of a stack dummy. Some systems (e.g. Sony
2106 news) give another signal besides SIGTRAP, so
2107 check here as well as above. */
2108 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2109 && PC_IN_CALL_DUMMY (stop_pc, read_sp (),
2110 FRAME_FP (get_current_frame ())))
2112 if (!ecs->random_signal)
2113 stop_signal = TARGET_SIGNAL_TRAP;
2117 /* When we reach this point, we've pretty much decided
2118 that the reason for stopping must've been a random
2119 (unexpected) signal. */
2122 ecs->random_signal = 1;
2123 /* If a fork, vfork or exec event was seen, then there are two
2124 possible responses we can make:
2126 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2127 then we must stop now and issue a prompt. We will resume
2128 the inferior when the user tells us to.
2129 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2130 then we must resume the inferior now and keep checking.
2132 In either case, we must take appropriate steps to "follow" the
2133 the fork/vfork/exec when the inferior is resumed. For example,
2134 if follow-fork-mode is "child", then we must detach from the
2135 parent inferior and follow the new child inferior.
2137 In either case, setting pending_follow causes the next resume()
2138 to take the appropriate following action. */
2139 process_event_stop_test:
2140 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
2142 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2145 stop_signal = TARGET_SIGNAL_0;
2150 else if (ecs->ws.kind == TARGET_WAITKIND_VFORKED)
2152 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2154 stop_signal = TARGET_SIGNAL_0;
2159 else if (ecs->ws.kind == TARGET_WAITKIND_EXECD)
2161 pending_follow.kind = ecs->ws.kind;
2162 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2165 stop_signal = TARGET_SIGNAL_0;
2171 /* For the program's own signals, act according to
2172 the signal handling tables. */
2174 if (ecs->random_signal)
2176 /* Signal not for debugging purposes. */
2179 stopped_by_random_signal = 1;
2181 if (signal_print[stop_signal])
2184 target_terminal_ours_for_output ();
2186 printf_filtered ("\nProgram received signal ");
2187 annotate_signal_name ();
2188 printf_filtered ("%s", target_signal_to_name (stop_signal));
2189 annotate_signal_name_end ();
2190 printf_filtered (", ");
2191 annotate_signal_string ();
2192 printf_filtered ("%s", target_signal_to_string (stop_signal));
2193 annotate_signal_string_end ();
2194 printf_filtered (".\n");
2195 gdb_flush (gdb_stdout);
2197 if (signal_stop[stop_signal])
2199 stop_stepping (ecs);
2202 /* If not going to stop, give terminal back
2203 if we took it away. */
2205 target_terminal_inferior ();
2207 /* Clear the signal if it should not be passed. */
2208 if (signal_program[stop_signal] == 0)
2209 stop_signal = TARGET_SIGNAL_0;
2211 /* I'm not sure whether this needs to be check_sigtramp2 or
2212 whether it could/should be keep_going.
2214 This used to jump to step_over_function if we are stepping,
2217 Suppose the user does a `next' over a function call, and while
2218 that call is in progress, the inferior receives a signal for
2219 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2220 that case, when we reach this point, there is already a
2221 step-resume breakpoint established, right where it should be:
2222 immediately after the function call the user is "next"-ing
2223 over. If we call step_over_function now, two bad things
2226 - we'll create a new breakpoint, at wherever the current
2227 frame's return address happens to be. That could be
2228 anywhere, depending on what function call happens to be on
2229 the top of the stack at that point. Point is, it's probably
2230 not where we need it.
2232 - the existing step-resume breakpoint (which is at the correct
2233 address) will get orphaned: step_resume_breakpoint will point
2234 to the new breakpoint, and the old step-resume breakpoint
2235 will never be cleaned up.
2237 The old behavior was meant to help HP-UX single-step out of
2238 sigtramps. It would place the new breakpoint at prev_pc, which
2239 was certainly wrong. I don't know the details there, so fixing
2240 this probably breaks that. As with anything else, it's up to
2241 the HP-UX maintainer to furnish a fix that doesn't break other
2242 platforms. --JimB, 20 May 1999 */
2243 check_sigtramp2 (ecs);
2246 /* Handle cases caused by hitting a breakpoint. */
2248 CORE_ADDR jmp_buf_pc;
2249 struct bpstat_what what;
2251 what = bpstat_what (stop_bpstat);
2253 if (what.call_dummy)
2255 stop_stack_dummy = 1;
2257 trap_expected_after_continue = 1;
2261 switch (what.main_action)
2263 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
2264 /* If we hit the breakpoint at longjmp, disable it for the
2265 duration of this command. Then, install a temporary
2266 breakpoint at the target of the jmp_buf. */
2267 disable_longjmp_breakpoint ();
2268 remove_breakpoints ();
2269 breakpoints_inserted = 0;
2270 if (!GET_LONGJMP_TARGET (&jmp_buf_pc))
2276 /* Need to blow away step-resume breakpoint, as it
2277 interferes with us */
2278 if (step_resume_breakpoint != NULL)
2280 delete_breakpoint (step_resume_breakpoint);
2281 step_resume_breakpoint = NULL;
2283 /* Not sure whether we need to blow this away too, but probably
2284 it is like the step-resume breakpoint. */
2285 if (through_sigtramp_breakpoint != NULL)
2287 delete_breakpoint (through_sigtramp_breakpoint);
2288 through_sigtramp_breakpoint = NULL;
2292 /* FIXME - Need to implement nested temporary breakpoints */
2293 if (step_over_calls > 0)
2294 set_longjmp_resume_breakpoint (jmp_buf_pc,
2295 get_current_frame ());
2298 set_longjmp_resume_breakpoint (jmp_buf_pc, NULL);
2299 ecs->handling_longjmp = 1; /* FIXME */
2303 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
2304 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
2305 remove_breakpoints ();
2306 breakpoints_inserted = 0;
2308 /* FIXME - Need to implement nested temporary breakpoints */
2310 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2311 step_frame_address)))
2313 ecs->another_trap = 1;
2318 disable_longjmp_breakpoint ();
2319 ecs->handling_longjmp = 0; /* FIXME */
2320 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
2322 /* else fallthrough */
2324 case BPSTAT_WHAT_SINGLE:
2325 if (breakpoints_inserted)
2327 thread_step_needed = 1;
2328 remove_breakpoints ();
2330 breakpoints_inserted = 0;
2331 ecs->another_trap = 1;
2332 /* Still need to check other stuff, at least the case
2333 where we are stepping and step out of the right range. */
2336 case BPSTAT_WHAT_STOP_NOISY:
2337 stop_print_frame = 1;
2339 /* We are about to nuke the step_resume_breakpoint and
2340 through_sigtramp_breakpoint via the cleanup chain, so
2341 no need to worry about it here. */
2343 stop_stepping (ecs);
2346 case BPSTAT_WHAT_STOP_SILENT:
2347 stop_print_frame = 0;
2349 /* We are about to nuke the step_resume_breakpoint and
2350 through_sigtramp_breakpoint via the cleanup chain, so
2351 no need to worry about it here. */
2353 stop_stepping (ecs);
2356 case BPSTAT_WHAT_STEP_RESUME:
2357 /* This proably demands a more elegant solution, but, yeah
2360 This function's use of the simple variable
2361 step_resume_breakpoint doesn't seem to accomodate
2362 simultaneously active step-resume bp's, although the
2363 breakpoint list certainly can.
2365 If we reach here and step_resume_breakpoint is already
2366 NULL, then apparently we have multiple active
2367 step-resume bp's. We'll just delete the breakpoint we
2368 stopped at, and carry on.
2370 Correction: what the code currently does is delete a
2371 step-resume bp, but it makes no effort to ensure that
2372 the one deleted is the one currently stopped at. MVS */
2374 if (step_resume_breakpoint == NULL)
2376 step_resume_breakpoint =
2377 bpstat_find_step_resume_breakpoint (stop_bpstat);
2379 delete_breakpoint (step_resume_breakpoint);
2380 step_resume_breakpoint = NULL;
2383 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2384 if (through_sigtramp_breakpoint)
2385 delete_breakpoint (through_sigtramp_breakpoint);
2386 through_sigtramp_breakpoint = NULL;
2388 /* If were waiting for a trap, hitting the step_resume_break
2389 doesn't count as getting it. */
2391 ecs->another_trap = 1;
2394 case BPSTAT_WHAT_CHECK_SHLIBS:
2395 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2398 /* Remove breakpoints, we eventually want to step over the
2399 shlib event breakpoint, and SOLIB_ADD might adjust
2400 breakpoint addresses via breakpoint_re_set. */
2401 if (breakpoints_inserted)
2402 remove_breakpoints ();
2403 breakpoints_inserted = 0;
2405 /* Check for any newly added shared libraries if we're
2406 supposed to be adding them automatically. */
2409 /* Switch terminal for any messages produced by
2410 breakpoint_re_set. */
2411 target_terminal_ours_for_output ();
2412 SOLIB_ADD (NULL, 0, NULL);
2413 target_terminal_inferior ();
2416 /* Try to reenable shared library breakpoints, additional
2417 code segments in shared libraries might be mapped in now. */
2418 re_enable_breakpoints_in_shlibs ();
2420 /* If requested, stop when the dynamic linker notifies
2421 gdb of events. This allows the user to get control
2422 and place breakpoints in initializer routines for
2423 dynamically loaded objects (among other things). */
2424 if (stop_on_solib_events)
2426 stop_stepping (ecs);
2430 /* If we stopped due to an explicit catchpoint, then the
2431 (see above) call to SOLIB_ADD pulled in any symbols
2432 from a newly-loaded library, if appropriate.
2434 We do want the inferior to stop, but not where it is
2435 now, which is in the dynamic linker callback. Rather,
2436 we would like it stop in the user's program, just after
2437 the call that caused this catchpoint to trigger. That
2438 gives the user a more useful vantage from which to
2439 examine their program's state. */
2440 else if (what.main_action == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2442 /* ??rehrauer: If I could figure out how to get the
2443 right return PC from here, we could just set a temp
2444 breakpoint and resume. I'm not sure we can without
2445 cracking open the dld's shared libraries and sniffing
2446 their unwind tables and text/data ranges, and that's
2447 not a terribly portable notion.
2449 Until that time, we must step the inferior out of the
2450 dld callback, and also out of the dld itself (and any
2451 code or stubs in libdld.sl, such as "shl_load" and
2452 friends) until we reach non-dld code. At that point,
2453 we can stop stepping. */
2454 bpstat_get_triggered_catchpoints (stop_bpstat,
2455 &ecs->stepping_through_solib_catchpoints);
2456 ecs->stepping_through_solib_after_catch = 1;
2458 /* Be sure to lift all breakpoints, so the inferior does
2459 actually step past this point... */
2460 ecs->another_trap = 1;
2465 /* We want to step over this breakpoint, then keep going. */
2466 ecs->another_trap = 1;
2473 case BPSTAT_WHAT_LAST:
2474 /* Not a real code, but listed here to shut up gcc -Wall. */
2476 case BPSTAT_WHAT_KEEP_CHECKING:
2481 /* We come here if we hit a breakpoint but should not
2482 stop for it. Possibly we also were stepping
2483 and should stop for that. So fall through and
2484 test for stepping. But, if not stepping,
2487 /* Are we stepping to get the inferior out of the dynamic
2488 linker's hook (and possibly the dld itself) after catching
2490 if (ecs->stepping_through_solib_after_catch)
2492 #if defined(SOLIB_ADD)
2493 /* Have we reached our destination? If not, keep going. */
2494 if (SOLIB_IN_DYNAMIC_LINKER (ecs->pid, stop_pc))
2496 ecs->another_trap = 1;
2501 /* Else, stop and report the catchpoint(s) whose triggering
2502 caused us to begin stepping. */
2503 ecs->stepping_through_solib_after_catch = 0;
2504 bpstat_clear (&stop_bpstat);
2505 stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints);
2506 bpstat_clear (&ecs->stepping_through_solib_catchpoints);
2507 stop_print_frame = 1;
2508 stop_stepping (ecs);
2512 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P)
2514 /* This is the old way of detecting the end of the stack dummy.
2515 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2516 handled above. As soon as we can test it on all of them, all
2517 architectures should define it. */
2519 /* If this is the breakpoint at the end of a stack dummy,
2520 just stop silently, unless the user was doing an si/ni, in which
2521 case she'd better know what she's doing. */
2523 if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (),
2524 FRAME_FP (get_current_frame ()))
2527 stop_print_frame = 0;
2528 stop_stack_dummy = 1;
2530 trap_expected_after_continue = 1;
2532 stop_stepping (ecs);
2537 if (step_resume_breakpoint)
2539 /* Having a step-resume breakpoint overrides anything
2540 else having to do with stepping commands until
2541 that breakpoint is reached. */
2542 /* I'm not sure whether this needs to be check_sigtramp2 or
2543 whether it could/should be keep_going. */
2544 check_sigtramp2 (ecs);
2549 if (step_range_end == 0)
2551 /* Likewise if we aren't even stepping. */
2552 /* I'm not sure whether this needs to be check_sigtramp2 or
2553 whether it could/should be keep_going. */
2554 check_sigtramp2 (ecs);
2559 /* If stepping through a line, keep going if still within it.
2561 Note that step_range_end is the address of the first instruction
2562 beyond the step range, and NOT the address of the last instruction
2564 if (stop_pc >= step_range_start
2565 && stop_pc < step_range_end)
2567 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2568 So definately need to check for sigtramp here. */
2569 check_sigtramp2 (ecs);
2574 /* We stepped out of the stepping range. */
2576 /* If we are stepping at the source level and entered the runtime
2577 loader dynamic symbol resolution code, we keep on single stepping
2578 until we exit the run time loader code and reach the callee's
2580 if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2582 CORE_ADDR pc_after_resolver = SKIP_SOLIB_RESOLVER (stop_pc);
2584 if (pc_after_resolver)
2586 /* Set up a step-resume breakpoint at the address
2587 indicated by SKIP_SOLIB_RESOLVER. */
2588 struct symtab_and_line sr_sal;
2590 sr_sal.pc = pc_after_resolver;
2592 check_for_old_step_resume_breakpoint ();
2593 step_resume_breakpoint =
2594 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2595 if (breakpoints_inserted)
2596 insert_breakpoints ();
2603 /* We can't update step_sp every time through the loop, because
2604 reading the stack pointer would slow down stepping too much.
2605 But we can update it every time we leave the step range. */
2606 ecs->update_step_sp = 1;
2608 /* Did we just take a signal? */
2609 if (IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2610 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2611 && INNER_THAN (read_sp (), step_sp))
2613 /* We've just taken a signal; go until we are back to
2614 the point where we took it and one more. */
2616 /* Note: The test above succeeds not only when we stepped
2617 into a signal handler, but also when we step past the last
2618 statement of a signal handler and end up in the return stub
2619 of the signal handler trampoline. To distinguish between
2620 these two cases, check that the frame is INNER_THAN the
2621 previous one below. pai/1997-09-11 */
2625 CORE_ADDR current_frame = FRAME_FP (get_current_frame ());
2627 if (INNER_THAN (current_frame, step_frame_address))
2629 /* We have just taken a signal; go until we are back to
2630 the point where we took it and one more. */
2632 /* This code is needed at least in the following case:
2633 The user types "next" and then a signal arrives (before
2634 the "next" is done). */
2636 /* Note that if we are stopped at a breakpoint, then we need
2637 the step_resume breakpoint to override any breakpoints at
2638 the same location, so that we will still step over the
2639 breakpoint even though the signal happened. */
2640 struct symtab_and_line sr_sal;
2643 sr_sal.symtab = NULL;
2645 sr_sal.pc = prev_pc;
2646 /* We could probably be setting the frame to
2647 step_frame_address; I don't think anyone thought to
2649 check_for_old_step_resume_breakpoint ();
2650 step_resume_breakpoint =
2651 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2652 if (breakpoints_inserted)
2653 insert_breakpoints ();
2657 /* We just stepped out of a signal handler and into
2658 its calling trampoline.
2660 Normally, we'd call step_over_function from
2661 here, but for some reason GDB can't unwind the
2662 stack correctly to find the real PC for the point
2663 user code where the signal trampoline will return
2664 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2665 But signal trampolines are pretty small stubs of
2666 code, anyway, so it's OK instead to just
2667 single-step out. Note: assuming such trampolines
2668 don't exhibit recursion on any platform... */
2669 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2670 &ecs->stop_func_start,
2671 &ecs->stop_func_end);
2672 /* Readjust stepping range */
2673 step_range_start = ecs->stop_func_start;
2674 step_range_end = ecs->stop_func_end;
2675 ecs->stepping_through_sigtramp = 1;
2680 /* If this is stepi or nexti, make sure that the stepping range
2681 gets us past that instruction. */
2682 if (step_range_end == 1)
2683 /* FIXME: Does this run afoul of the code below which, if
2684 we step into the middle of a line, resets the stepping
2686 step_range_end = (step_range_start = prev_pc) + 1;
2688 ecs->remove_breakpoints_on_following_step = 1;
2693 if (stop_pc == ecs->stop_func_start /* Quick test */
2694 || (in_prologue (stop_pc, ecs->stop_func_start) &&
2695 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2696 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name)
2697 || ecs->stop_func_name == 0)
2699 /* It's a subroutine call. */
2701 if (step_over_calls == 0)
2703 /* I presume that step_over_calls is only 0 when we're
2704 supposed to be stepping at the assembly language level
2705 ("stepi"). Just stop. */
2707 stop_stepping (ecs);
2711 if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc))
2713 /* We're doing a "next". */
2714 step_over_function (ecs);
2719 /* If we are in a function call trampoline (a stub between
2720 the calling routine and the real function), locate the real
2721 function. That's what tells us (a) whether we want to step
2722 into it at all, and (b) what prologue we want to run to
2723 the end of, if we do step into it. */
2724 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2726 ecs->stop_func_start = tmp;
2729 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
2732 struct symtab_and_line xxx;
2733 /* Why isn't this s_a_l called "sr_sal", like all of the
2734 other s_a_l's where this code is duplicated? */
2735 INIT_SAL (&xxx); /* initialize to zeroes */
2737 xxx.section = find_pc_overlay (xxx.pc);
2738 check_for_old_step_resume_breakpoint ();
2739 step_resume_breakpoint =
2740 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
2741 insert_breakpoints ();
2747 /* If we have line number information for the function we
2748 are thinking of stepping into, step into it.
2750 If there are several symtabs at that PC (e.g. with include
2751 files), just want to know whether *any* of them have line
2752 numbers. find_pc_line handles this. */
2754 struct symtab_and_line tmp_sal;
2756 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
2757 if (tmp_sal.line != 0)
2759 step_into_function (ecs);
2763 step_over_function (ecs);
2769 /* We've wandered out of the step range. */
2771 ecs->sal = find_pc_line (stop_pc, 0);
2773 if (step_range_end == 1)
2775 /* It is stepi or nexti. We always want to stop stepping after
2778 stop_stepping (ecs);
2782 /* If we're in the return path from a shared library trampoline,
2783 we want to proceed through the trampoline when stepping. */
2784 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2788 /* Determine where this trampoline returns. */
2789 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2791 /* Only proceed through if we know where it's going. */
2794 /* And put the step-breakpoint there and go until there. */
2795 struct symtab_and_line sr_sal;
2797 INIT_SAL (&sr_sal); /* initialize to zeroes */
2799 sr_sal.section = find_pc_overlay (sr_sal.pc);
2800 /* Do not specify what the fp should be when we stop
2801 since on some machines the prologue
2802 is where the new fp value is established. */
2803 check_for_old_step_resume_breakpoint ();
2804 step_resume_breakpoint =
2805 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2806 if (breakpoints_inserted)
2807 insert_breakpoints ();
2809 /* Restart without fiddling with the step ranges or
2816 if (ecs->sal.line == 0)
2818 /* We have no line number information. That means to stop
2819 stepping (does this always happen right after one instruction,
2820 when we do "s" in a function with no line numbers,
2821 or can this happen as a result of a return or longjmp?). */
2823 stop_stepping (ecs);
2827 if ((stop_pc == ecs->sal.pc)
2828 && (ecs->current_line != ecs->sal.line || ecs->current_symtab != ecs->sal.symtab))
2830 /* We are at the start of a different line. So stop. Note that
2831 we don't stop if we step into the middle of a different line.
2832 That is said to make things like for (;;) statements work
2835 stop_stepping (ecs);
2839 /* We aren't done stepping.
2841 Optimize by setting the stepping range to the line.
2842 (We might not be in the original line, but if we entered a
2843 new line in mid-statement, we continue stepping. This makes
2844 things like for(;;) statements work better.) */
2846 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
2848 /* If this is the last line of the function, don't keep stepping
2849 (it would probably step us out of the function).
2850 This is particularly necessary for a one-line function,
2851 in which after skipping the prologue we better stop even though
2852 we will be in mid-line. */
2854 stop_stepping (ecs);
2857 step_range_start = ecs->sal.pc;
2858 step_range_end = ecs->sal.end;
2859 step_frame_address = FRAME_FP (get_current_frame ());
2860 ecs->current_line = ecs->sal.line;
2861 ecs->current_symtab = ecs->sal.symtab;
2863 /* In the case where we just stepped out of a function into the middle
2864 of a line of the caller, continue stepping, but step_frame_address
2865 must be modified to current frame */
2867 CORE_ADDR current_frame = FRAME_FP (get_current_frame ());
2868 if (!(INNER_THAN (current_frame, step_frame_address)))
2869 step_frame_address = current_frame;
2874 } /* extra brace, to preserve old indentation */
2877 /* Are we in the middle of stepping? */
2880 currently_stepping (struct execution_control_state *ecs)
2882 return ((through_sigtramp_breakpoint == NULL
2883 && !ecs->handling_longjmp
2884 && ((step_range_end && step_resume_breakpoint == NULL)
2886 || ecs->stepping_through_solib_after_catch
2887 || bpstat_should_step ());
2891 check_sigtramp2 (struct execution_control_state *ecs)
2894 && IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2895 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2896 && INNER_THAN (read_sp (), step_sp))
2898 /* What has happened here is that we have just stepped the
2899 inferior with a signal (because it is a signal which
2900 shouldn't make us stop), thus stepping into sigtramp.
2902 So we need to set a step_resume_break_address breakpoint and
2903 continue until we hit it, and then step. FIXME: This should
2904 be more enduring than a step_resume breakpoint; we should
2905 know that we will later need to keep going rather than
2906 re-hitting the breakpoint here (see the testsuite,
2907 gdb.base/signals.exp where it says "exceedingly difficult"). */
2909 struct symtab_and_line sr_sal;
2911 INIT_SAL (&sr_sal); /* initialize to zeroes */
2912 sr_sal.pc = prev_pc;
2913 sr_sal.section = find_pc_overlay (sr_sal.pc);
2914 /* We perhaps could set the frame if we kept track of what the
2915 frame corresponding to prev_pc was. But we don't, so don't. */
2916 through_sigtramp_breakpoint =
2917 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
2918 if (breakpoints_inserted)
2919 insert_breakpoints ();
2921 ecs->remove_breakpoints_on_following_step = 1;
2922 ecs->another_trap = 1;
2926 /* Subroutine call with source code we should not step over. Do step
2927 to the first line of code in it. */
2930 step_into_function (struct execution_control_state *ecs)
2933 struct symtab_and_line sr_sal;
2935 s = find_pc_symtab (stop_pc);
2936 if (s && s->language != language_asm)
2937 ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start);
2939 ecs->sal = find_pc_line (ecs->stop_func_start, 0);
2940 /* Use the step_resume_break to step until the end of the prologue,
2941 even if that involves jumps (as it seems to on the vax under
2943 /* If the prologue ends in the middle of a source line, continue to
2944 the end of that source line (if it is still within the function).
2945 Otherwise, just go to end of prologue. */
2946 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2947 /* no, don't either. It skips any code that's legitimately on the
2951 && ecs->sal.pc != ecs->stop_func_start
2952 && ecs->sal.end < ecs->stop_func_end)
2953 ecs->stop_func_start = ecs->sal.end;
2956 if (ecs->stop_func_start == stop_pc)
2958 /* We are already there: stop now. */
2960 stop_stepping (ecs);
2965 /* Put the step-breakpoint there and go until there. */
2966 INIT_SAL (&sr_sal); /* initialize to zeroes */
2967 sr_sal.pc = ecs->stop_func_start;
2968 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
2969 /* Do not specify what the fp should be when we stop since on
2970 some machines the prologue is where the new fp value is
2972 check_for_old_step_resume_breakpoint ();
2973 step_resume_breakpoint =
2974 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2975 if (breakpoints_inserted)
2976 insert_breakpoints ();
2978 /* And make sure stepping stops right away then. */
2979 step_range_end = step_range_start;
2984 /* We've just entered a callee, and we wish to resume until it returns
2985 to the caller. Setting a step_resume breakpoint on the return
2986 address will catch a return from the callee.
2988 However, if the callee is recursing, we want to be careful not to
2989 catch returns of those recursive calls, but only of THIS instance
2992 To do this, we set the step_resume bp's frame to our current
2993 caller's frame (step_frame_address, which is set by the "next" or
2994 "until" command, before execution begins). */
2997 step_over_function (struct execution_control_state *ecs)
2999 struct symtab_and_line sr_sal;
3001 INIT_SAL (&sr_sal); /* initialize to zeros */
3002 sr_sal.pc = ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3003 sr_sal.section = find_pc_overlay (sr_sal.pc);
3005 check_for_old_step_resume_breakpoint ();
3006 step_resume_breakpoint =
3007 set_momentary_breakpoint (sr_sal, get_current_frame (), bp_step_resume);
3009 if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
3010 step_resume_breakpoint->frame = step_frame_address;
3012 if (breakpoints_inserted)
3013 insert_breakpoints ();
3017 stop_stepping (struct execution_control_state *ecs)
3019 if (target_has_execution)
3021 /* Are we stopping for a vfork event? We only stop when we see
3022 the child's event. However, we may not yet have seen the
3023 parent's event. And, inferior_pid is still set to the
3024 parent's pid, until we resume again and follow either the
3027 To ensure that we can really touch inferior_pid (aka, the
3028 parent process) -- which calls to functions like read_pc
3029 implicitly do -- wait on the parent if necessary. */
3030 if ((pending_follow.kind == TARGET_WAITKIND_VFORKED)
3031 && !pending_follow.fork_event.saw_parent_fork)
3037 if (target_wait_hook)
3038 parent_pid = target_wait_hook (-1, &(ecs->ws));
3040 parent_pid = target_wait (-1, &(ecs->ws));
3042 while (parent_pid != inferior_pid);
3045 /* Assuming the inferior still exists, set these up for next
3046 time, just like we did above if we didn't break out of the
3048 prev_pc = read_pc ();
3049 prev_func_start = ecs->stop_func_start;
3050 prev_func_name = ecs->stop_func_name;
3053 /* Let callers know we don't want to wait for the inferior anymore. */
3054 ecs->wait_some_more = 0;
3057 /* This function handles various cases where we need to continue
3058 waiting for the inferior. */
3059 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3062 keep_going (struct execution_control_state *ecs)
3064 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3065 vforked child between its creation and subsequent exit or call to
3066 exec(). However, I had big problems in this rather creaky exec
3067 engine, getting that to work. The fundamental problem is that
3068 I'm trying to debug two processes via an engine that only
3069 understands a single process with possibly multiple threads.
3071 Hence, this spot is known to have problems when
3072 target_can_follow_vfork_prior_to_exec returns 1. */
3074 /* Save the pc before execution, to compare with pc after stop. */
3075 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
3076 prev_func_start = ecs->stop_func_start; /* Ok, since if DECR_PC_AFTER
3077 BREAK is defined, the
3078 original pc would not have
3079 been at the start of a
3081 prev_func_name = ecs->stop_func_name;
3083 if (ecs->update_step_sp)
3084 step_sp = read_sp ();
3085 ecs->update_step_sp = 0;
3087 /* If we did not do break;, it means we should keep running the
3088 inferior and not return to debugger. */
3090 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
3092 /* We took a signal (which we are supposed to pass through to
3093 the inferior, else we'd have done a break above) and we
3094 haven't yet gotten our trap. Simply continue. */
3095 resume (currently_stepping (ecs), stop_signal);
3099 /* Either the trap was not expected, but we are continuing
3100 anyway (the user asked that this signal be passed to the
3103 The signal was SIGTRAP, e.g. it was our signal, but we
3104 decided we should resume from it.
3106 We're going to run this baby now!
3108 Insert breakpoints now, unless we are trying to one-proceed
3109 past a breakpoint. */
3110 /* If we've just finished a special step resume and we don't
3111 want to hit a breakpoint, pull em out. */
3112 if (step_resume_breakpoint == NULL
3113 && through_sigtramp_breakpoint == NULL
3114 && ecs->remove_breakpoints_on_following_step)
3116 ecs->remove_breakpoints_on_following_step = 0;
3117 remove_breakpoints ();
3118 breakpoints_inserted = 0;
3120 else if (!breakpoints_inserted &&
3121 (through_sigtramp_breakpoint != NULL || !ecs->another_trap))
3123 breakpoints_failed = insert_breakpoints ();
3124 if (breakpoints_failed)
3126 stop_stepping (ecs);
3129 breakpoints_inserted = 1;
3132 trap_expected = ecs->another_trap;
3134 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3135 specifies that such a signal should be delivered to the
3138 Typically, this would occure when a user is debugging a
3139 target monitor on a simulator: the target monitor sets a
3140 breakpoint; the simulator encounters this break-point and
3141 halts the simulation handing control to GDB; GDB, noteing
3142 that the break-point isn't valid, returns control back to the
3143 simulator; the simulator then delivers the hardware
3144 equivalent of a SIGNAL_TRAP to the program being debugged. */
3146 if (stop_signal == TARGET_SIGNAL_TRAP
3147 && !signal_program[stop_signal])
3148 stop_signal = TARGET_SIGNAL_0;
3150 #ifdef SHIFT_INST_REGS
3151 /* I'm not sure when this following segment applies. I do know,
3152 now, that we shouldn't rewrite the regs when we were stopped
3153 by a random signal from the inferior process. */
3154 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3155 (this is only used on the 88k). */
3157 if (!bpstat_explains_signal (stop_bpstat)
3158 && (stop_signal != TARGET_SIGNAL_CHLD)
3159 && !stopped_by_random_signal)
3161 #endif /* SHIFT_INST_REGS */
3163 resume (currently_stepping (ecs), stop_signal);
3166 prepare_to_wait (ecs);
3169 /* This function normally comes after a resume, before
3170 handle_inferior_event exits. It takes care of any last bits of
3171 housekeeping, and sets the all-important wait_some_more flag. */
3174 prepare_to_wait (struct execution_control_state *ecs)
3176 if (ecs->infwait_state == infwait_normal_state)
3178 overlay_cache_invalid = 1;
3180 /* We have to invalidate the registers BEFORE calling
3181 target_wait because they can be loaded from the target while
3182 in target_wait. This makes remote debugging a bit more
3183 efficient for those targets that provide critical registers
3184 as part of their normal status mechanism. */
3186 registers_changed ();
3187 ecs->waiton_pid = -1;
3188 ecs->wp = &(ecs->ws);
3190 /* This is the old end of the while loop. Let everybody know we
3191 want to wait for the inferior some more and get called again
3193 ecs->wait_some_more = 1;
3197 /* Here to return control to GDB when the inferior stops for real.
3198 Print appropriate messages, remove breakpoints, give terminal our modes.
3200 STOP_PRINT_FRAME nonzero means print the executing frame
3201 (pc, function, args, file, line number and line text).
3202 BREAKPOINTS_FAILED nonzero means stop was due to error
3203 attempting to insert breakpoints. */
3208 /* As with the notification of thread events, we want to delay
3209 notifying the user that we've switched thread context until
3210 the inferior actually stops.
3212 (Note that there's no point in saying anything if the inferior
3214 if (may_switch_from_inferior_pid
3215 && (switched_from_inferior_pid != inferior_pid)
3216 && target_has_execution)
3218 target_terminal_ours_for_output ();
3219 printf_filtered ("[Switched to %s]\n",
3220 target_pid_or_tid_to_str (inferior_pid));
3221 switched_from_inferior_pid = inferior_pid;
3224 /* Make sure that the current_frame's pc is correct. This
3225 is a correction for setting up the frame info before doing
3226 DECR_PC_AFTER_BREAK */
3227 if (target_has_execution && get_current_frame ())
3228 (get_current_frame ())->pc = read_pc ();
3230 if (breakpoints_failed)
3232 target_terminal_ours_for_output ();
3233 print_sys_errmsg ("ptrace", breakpoints_failed);
3234 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3235 The same program may be running in another process.\n");
3238 if (target_has_execution && breakpoints_inserted)
3240 if (remove_breakpoints ())
3242 target_terminal_ours_for_output ();
3243 printf_filtered ("Cannot remove breakpoints because ");
3244 printf_filtered ("program is no longer writable.\n");
3245 printf_filtered ("It might be running in another process.\n");
3246 printf_filtered ("Further execution is probably impossible.\n");
3249 breakpoints_inserted = 0;
3251 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3252 Delete any breakpoint that is to be deleted at the next stop. */
3254 breakpoint_auto_delete (stop_bpstat);
3256 /* If an auto-display called a function and that got a signal,
3257 delete that auto-display to avoid an infinite recursion. */
3259 if (stopped_by_random_signal)
3260 disable_current_display ();
3262 /* Don't print a message if in the middle of doing a "step n"
3263 operation for n > 1 */
3264 if (step_multi && stop_step)
3267 target_terminal_ours ();
3269 /* Look up the hook_stop and run it if it exists. */
3271 if (stop_command && stop_command->hook)
3273 catch_errors (hook_stop_stub, stop_command->hook,
3274 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3277 if (!target_has_stack)
3283 /* Select innermost stack frame - i.e., current frame is frame 0,
3284 and current location is based on that.
3285 Don't do this on return from a stack dummy routine,
3286 or if the program has exited. */
3288 if (!stop_stack_dummy)
3290 select_frame (get_current_frame (), 0);
3292 /* Print current location without a level number, if
3293 we have changed functions or hit a breakpoint.
3294 Print source line if we have one.
3295 bpstat_print() contains the logic deciding in detail
3296 what to print, based on the event(s) that just occurred. */
3298 if (stop_print_frame)
3302 int do_frame_printing = 1;
3304 bpstat_ret = bpstat_print (stop_bpstat);
3309 && step_frame_address == FRAME_FP (get_current_frame ())
3310 && step_start_function == find_pc_function (stop_pc))
3311 source_flag = -1; /* finished step, just print source line */
3313 source_flag = 1; /* print location and source line */
3315 case PRINT_SRC_AND_LOC:
3316 source_flag = 1; /* print location and source line */
3318 case PRINT_SRC_ONLY:
3322 do_frame_printing = 0;
3325 internal_error ("Unknown value.");
3328 /* The behavior of this routine with respect to the source
3330 -1: Print only source line
3331 0: Print only location
3332 1: Print location and source line */
3333 if (do_frame_printing)
3334 show_and_print_stack_frame (selected_frame, -1, source_flag);
3336 /* Display the auto-display expressions. */
3341 /* Save the function value return registers, if we care.
3342 We might be about to restore their previous contents. */
3343 if (proceed_to_finish)
3344 read_register_bytes (0, stop_registers, REGISTER_BYTES);
3346 if (stop_stack_dummy)
3348 /* Pop the empty frame that contains the stack dummy.
3349 POP_FRAME ends with a setting of the current frame, so we
3350 can use that next. */
3352 /* Set stop_pc to what it was before we called the function.
3353 Can't rely on restore_inferior_status because that only gets
3354 called if we don't stop in the called function. */
3355 stop_pc = read_pc ();
3356 select_frame (get_current_frame (), 0);
3360 TUIDO (((TuiOpaqueFuncPtr) tui_vCheckDataValues, selected_frame));
3363 annotate_stopped ();
3367 hook_stop_stub (void *cmd)
3369 execute_user_command ((struct cmd_list_element *) cmd, 0);
3374 signal_stop_state (int signo)
3376 return signal_stop[signo];
3380 signal_print_state (int signo)
3382 return signal_print[signo];
3386 signal_pass_state (int signo)
3388 return signal_program[signo];
3391 int signal_stop_update (signo, state)
3395 int ret = signal_stop[signo];
3396 signal_stop[signo] = state;
3400 int signal_print_update (signo, state)
3404 int ret = signal_print[signo];
3405 signal_print[signo] = state;
3409 int signal_pass_update (signo, state)
3413 int ret = signal_program[signo];
3414 signal_program[signo] = state;
3419 sig_print_header (void)
3422 Signal Stop\tPrint\tPass to program\tDescription\n");
3426 sig_print_info (enum target_signal oursig)
3428 char *name = target_signal_to_name (oursig);
3429 int name_padding = 13 - strlen (name);
3431 if (name_padding <= 0)
3434 printf_filtered ("%s", name);
3435 printf_filtered ("%*.*s ", name_padding, name_padding,
3437 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3438 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3439 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3440 printf_filtered ("%s\n", target_signal_to_string (oursig));
3443 /* Specify how various signals in the inferior should be handled. */
3446 handle_command (char *args, int from_tty)
3449 int digits, wordlen;
3450 int sigfirst, signum, siglast;
3451 enum target_signal oursig;
3454 unsigned char *sigs;
3455 struct cleanup *old_chain;
3459 error_no_arg ("signal to handle");
3462 /* Allocate and zero an array of flags for which signals to handle. */
3464 nsigs = (int) TARGET_SIGNAL_LAST;
3465 sigs = (unsigned char *) alloca (nsigs);
3466 memset (sigs, 0, nsigs);
3468 /* Break the command line up into args. */
3470 argv = buildargv (args);
3475 old_chain = make_cleanup_freeargv (argv);
3477 /* Walk through the args, looking for signal oursigs, signal names, and
3478 actions. Signal numbers and signal names may be interspersed with
3479 actions, with the actions being performed for all signals cumulatively
3480 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3482 while (*argv != NULL)
3484 wordlen = strlen (*argv);
3485 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3489 sigfirst = siglast = -1;
3491 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3493 /* Apply action to all signals except those used by the
3494 debugger. Silently skip those. */
3497 siglast = nsigs - 1;
3499 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3501 SET_SIGS (nsigs, sigs, signal_stop);
3502 SET_SIGS (nsigs, sigs, signal_print);
3504 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3506 UNSET_SIGS (nsigs, sigs, signal_program);
3508 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3510 SET_SIGS (nsigs, sigs, signal_print);
3512 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3514 SET_SIGS (nsigs, sigs, signal_program);
3516 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3518 UNSET_SIGS (nsigs, sigs, signal_stop);
3520 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3522 SET_SIGS (nsigs, sigs, signal_program);
3524 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3526 UNSET_SIGS (nsigs, sigs, signal_print);
3527 UNSET_SIGS (nsigs, sigs, signal_stop);
3529 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3531 UNSET_SIGS (nsigs, sigs, signal_program);
3533 else if (digits > 0)
3535 /* It is numeric. The numeric signal refers to our own
3536 internal signal numbering from target.h, not to host/target
3537 signal number. This is a feature; users really should be
3538 using symbolic names anyway, and the common ones like
3539 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3541 sigfirst = siglast = (int)
3542 target_signal_from_command (atoi (*argv));
3543 if ((*argv)[digits] == '-')
3546 target_signal_from_command (atoi ((*argv) + digits + 1));
3548 if (sigfirst > siglast)
3550 /* Bet he didn't figure we'd think of this case... */
3558 oursig = target_signal_from_name (*argv);
3559 if (oursig != TARGET_SIGNAL_UNKNOWN)
3561 sigfirst = siglast = (int) oursig;
3565 /* Not a number and not a recognized flag word => complain. */
3566 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3570 /* If any signal numbers or symbol names were found, set flags for
3571 which signals to apply actions to. */
3573 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3575 switch ((enum target_signal) signum)
3577 case TARGET_SIGNAL_TRAP:
3578 case TARGET_SIGNAL_INT:
3579 if (!allsigs && !sigs[signum])
3581 if (query ("%s is used by the debugger.\n\
3582 Are you sure you want to change it? ",
3583 target_signal_to_name
3584 ((enum target_signal) signum)))
3590 printf_unfiltered ("Not confirmed, unchanged.\n");
3591 gdb_flush (gdb_stdout);
3595 case TARGET_SIGNAL_0:
3596 case TARGET_SIGNAL_DEFAULT:
3597 case TARGET_SIGNAL_UNKNOWN:
3598 /* Make sure that "all" doesn't print these. */
3609 target_notice_signals (inferior_pid);
3613 /* Show the results. */
3614 sig_print_header ();
3615 for (signum = 0; signum < nsigs; signum++)
3619 sig_print_info (signum);
3624 do_cleanups (old_chain);
3628 xdb_handle_command (char *args, int from_tty)
3631 struct cleanup *old_chain;
3633 /* Break the command line up into args. */
3635 argv = buildargv (args);
3640 old_chain = make_cleanup_freeargv (argv);
3641 if (argv[1] != (char *) NULL)
3646 bufLen = strlen (argv[0]) + 20;
3647 argBuf = (char *) xmalloc (bufLen);
3651 enum target_signal oursig;
3653 oursig = target_signal_from_name (argv[0]);
3654 memset (argBuf, 0, bufLen);
3655 if (strcmp (argv[1], "Q") == 0)
3656 sprintf (argBuf, "%s %s", argv[0], "noprint");
3659 if (strcmp (argv[1], "s") == 0)
3661 if (!signal_stop[oursig])
3662 sprintf (argBuf, "%s %s", argv[0], "stop");
3664 sprintf (argBuf, "%s %s", argv[0], "nostop");
3666 else if (strcmp (argv[1], "i") == 0)
3668 if (!signal_program[oursig])
3669 sprintf (argBuf, "%s %s", argv[0], "pass");
3671 sprintf (argBuf, "%s %s", argv[0], "nopass");
3673 else if (strcmp (argv[1], "r") == 0)
3675 if (!signal_print[oursig])
3676 sprintf (argBuf, "%s %s", argv[0], "print");
3678 sprintf (argBuf, "%s %s", argv[0], "noprint");
3684 handle_command (argBuf, from_tty);
3686 printf_filtered ("Invalid signal handling flag.\n");
3691 do_cleanups (old_chain);
3694 /* Print current contents of the tables set by the handle command.
3695 It is possible we should just be printing signals actually used
3696 by the current target (but for things to work right when switching
3697 targets, all signals should be in the signal tables). */
3700 signals_info (char *signum_exp, int from_tty)
3702 enum target_signal oursig;
3703 sig_print_header ();
3707 /* First see if this is a symbol name. */
3708 oursig = target_signal_from_name (signum_exp);
3709 if (oursig == TARGET_SIGNAL_UNKNOWN)
3711 /* No, try numeric. */
3713 target_signal_from_command (parse_and_eval_address (signum_exp));
3715 sig_print_info (oursig);
3719 printf_filtered ("\n");
3720 /* These ugly casts brought to you by the native VAX compiler. */
3721 for (oursig = TARGET_SIGNAL_FIRST;
3722 (int) oursig < (int) TARGET_SIGNAL_LAST;
3723 oursig = (enum target_signal) ((int) oursig + 1))
3727 if (oursig != TARGET_SIGNAL_UNKNOWN
3728 && oursig != TARGET_SIGNAL_DEFAULT
3729 && oursig != TARGET_SIGNAL_0)
3730 sig_print_info (oursig);
3733 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3736 struct inferior_status
3738 enum target_signal stop_signal;
3742 int stop_stack_dummy;
3743 int stopped_by_random_signal;
3745 CORE_ADDR step_range_start;
3746 CORE_ADDR step_range_end;
3747 CORE_ADDR step_frame_address;
3748 int step_over_calls;
3749 CORE_ADDR step_resume_break_address;
3750 int stop_after_trap;
3751 int stop_soon_quietly;
3752 CORE_ADDR selected_frame_address;
3753 char *stop_registers;
3755 /* These are here because if call_function_by_hand has written some
3756 registers and then decides to call error(), we better not have changed
3761 int breakpoint_proceeded;
3762 int restore_stack_info;
3763 int proceed_to_finish;
3766 static struct inferior_status *
3767 xmalloc_inferior_status (void)
3769 struct inferior_status *inf_status;
3770 inf_status = xmalloc (sizeof (struct inferior_status));
3771 inf_status->stop_registers = xmalloc (REGISTER_BYTES);
3772 inf_status->registers = xmalloc (REGISTER_BYTES);
3777 free_inferior_status (struct inferior_status *inf_status)
3779 free (inf_status->registers);
3780 free (inf_status->stop_registers);
3785 write_inferior_status_register (struct inferior_status *inf_status, int regno,
3788 int size = REGISTER_RAW_SIZE (regno);
3789 void *buf = alloca (size);
3790 store_signed_integer (buf, size, val);
3791 memcpy (&inf_status->registers[REGISTER_BYTE (regno)], buf, size);
3794 /* Save all of the information associated with the inferior<==>gdb
3795 connection. INF_STATUS is a pointer to a "struct inferior_status"
3796 (defined in inferior.h). */
3798 struct inferior_status *
3799 save_inferior_status (int restore_stack_info)
3801 struct inferior_status *inf_status = xmalloc_inferior_status ();
3803 inf_status->stop_signal = stop_signal;
3804 inf_status->stop_pc = stop_pc;
3805 inf_status->stop_step = stop_step;
3806 inf_status->stop_stack_dummy = stop_stack_dummy;
3807 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3808 inf_status->trap_expected = trap_expected;
3809 inf_status->step_range_start = step_range_start;
3810 inf_status->step_range_end = step_range_end;
3811 inf_status->step_frame_address = step_frame_address;
3812 inf_status->step_over_calls = step_over_calls;
3813 inf_status->stop_after_trap = stop_after_trap;
3814 inf_status->stop_soon_quietly = stop_soon_quietly;
3815 /* Save original bpstat chain here; replace it with copy of chain.
3816 If caller's caller is walking the chain, they'll be happier if we
3817 hand them back the original chain when restore_inferior_status is
3819 inf_status->stop_bpstat = stop_bpstat;
3820 stop_bpstat = bpstat_copy (stop_bpstat);
3821 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3822 inf_status->restore_stack_info = restore_stack_info;
3823 inf_status->proceed_to_finish = proceed_to_finish;
3825 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
3827 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3829 record_selected_frame (&(inf_status->selected_frame_address),
3830 &(inf_status->selected_level));
3834 struct restore_selected_frame_args
3836 CORE_ADDR frame_address;
3841 restore_selected_frame (void *args)
3843 struct restore_selected_frame_args *fr =
3844 (struct restore_selected_frame_args *) args;
3845 struct frame_info *frame;
3846 int level = fr->level;
3848 frame = find_relative_frame (get_current_frame (), &level);
3850 /* If inf_status->selected_frame_address is NULL, there was no
3851 previously selected frame. */
3852 if (frame == NULL ||
3853 /* FRAME_FP (frame) != fr->frame_address || */
3854 /* elz: deleted this check as a quick fix to the problem that
3855 for function called by hand gdb creates no internal frame
3856 structure and the real stack and gdb's idea of stack are
3857 different if nested calls by hands are made.
3859 mvs: this worries me. */
3862 warning ("Unable to restore previously selected frame.\n");
3866 select_frame (frame, fr->level);
3872 restore_inferior_status (struct inferior_status *inf_status)
3874 stop_signal = inf_status->stop_signal;
3875 stop_pc = inf_status->stop_pc;
3876 stop_step = inf_status->stop_step;
3877 stop_stack_dummy = inf_status->stop_stack_dummy;
3878 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3879 trap_expected = inf_status->trap_expected;
3880 step_range_start = inf_status->step_range_start;
3881 step_range_end = inf_status->step_range_end;
3882 step_frame_address = inf_status->step_frame_address;
3883 step_over_calls = inf_status->step_over_calls;
3884 stop_after_trap = inf_status->stop_after_trap;
3885 stop_soon_quietly = inf_status->stop_soon_quietly;
3886 bpstat_clear (&stop_bpstat);
3887 stop_bpstat = inf_status->stop_bpstat;
3888 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3889 proceed_to_finish = inf_status->proceed_to_finish;
3891 /* FIXME: Is the restore of stop_registers always needed */
3892 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
3894 /* The inferior can be gone if the user types "print exit(0)"
3895 (and perhaps other times). */
3896 if (target_has_execution)
3897 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3899 /* FIXME: If we are being called after stopping in a function which
3900 is called from gdb, we should not be trying to restore the
3901 selected frame; it just prints a spurious error message (The
3902 message is useful, however, in detecting bugs in gdb (like if gdb
3903 clobbers the stack)). In fact, should we be restoring the
3904 inferior status at all in that case? . */
3906 if (target_has_stack && inf_status->restore_stack_info)
3908 struct restore_selected_frame_args fr;
3909 fr.level = inf_status->selected_level;
3910 fr.frame_address = inf_status->selected_frame_address;
3911 /* The point of catch_errors is that if the stack is clobbered,
3912 walking the stack might encounter a garbage pointer and error()
3913 trying to dereference it. */
3914 if (catch_errors (restore_selected_frame, &fr,
3915 "Unable to restore previously selected frame:\n",
3916 RETURN_MASK_ERROR) == 0)
3917 /* Error in restoring the selected frame. Select the innermost
3921 select_frame (get_current_frame (), 0);
3925 free_inferior_status (inf_status);
3929 discard_inferior_status (struct inferior_status *inf_status)
3931 /* See save_inferior_status for info on stop_bpstat. */
3932 bpstat_clear (&inf_status->stop_bpstat);
3933 free_inferior_status (inf_status);
3937 set_follow_fork_mode_command (char *arg, int from_tty,
3938 struct cmd_list_element *c)
3940 if (!STREQ (arg, "parent") &&
3941 !STREQ (arg, "child") &&
3942 !STREQ (arg, "both") &&
3943 !STREQ (arg, "ask"))
3944 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
3946 if (follow_fork_mode_string != NULL)
3947 free (follow_fork_mode_string);
3948 follow_fork_mode_string = savestring (arg, strlen (arg));
3954 stop_registers = xmalloc (REGISTER_BYTES);
3958 _initialize_infrun (void)
3961 register int numsigs;
3962 struct cmd_list_element *c;
3966 register_gdbarch_swap (&stop_registers, sizeof (stop_registers), NULL);
3967 register_gdbarch_swap (NULL, 0, build_infrun);
3969 add_info ("signals", signals_info,
3970 "What debugger does when program gets various signals.\n\
3971 Specify a signal as argument to print info on that signal only.");
3972 add_info_alias ("handle", "signals", 0);
3974 add_com ("handle", class_run, handle_command,
3975 concat ("Specify how to handle a signal.\n\
3976 Args are signals and actions to apply to those signals.\n\
3977 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3978 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3979 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3980 The special arg \"all\" is recognized to mean all signals except those\n\
3981 used by the debugger, typically SIGTRAP and SIGINT.\n",
3982 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3983 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3984 Stop means reenter debugger if this signal happens (implies print).\n\
3985 Print means print a message if this signal happens.\n\
3986 Pass means let program see this signal; otherwise program doesn't know.\n\
3987 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3988 Pass and Stop may be combined.", NULL));
3991 add_com ("lz", class_info, signals_info,
3992 "What debugger does when program gets various signals.\n\
3993 Specify a signal as argument to print info on that signal only.");
3994 add_com ("z", class_run, xdb_handle_command,
3995 concat ("Specify how to handle a signal.\n\
3996 Args are signals and actions to apply to those signals.\n\
3997 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3998 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3999 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4000 The special arg \"all\" is recognized to mean all signals except those\n\
4001 used by the debugger, typically SIGTRAP and SIGINT.\n",
4002 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4003 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4004 nopass), \"Q\" (noprint)\n\
4005 Stop means reenter debugger if this signal happens (implies print).\n\
4006 Print means print a message if this signal happens.\n\
4007 Pass means let program see this signal; otherwise program doesn't know.\n\
4008 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4009 Pass and Stop may be combined.", NULL));
4013 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
4014 "There is no `stop' command, but you can set a hook on `stop'.\n\
4015 This allows you to set a list of commands to be run each time execution\n\
4016 of the program stops.", &cmdlist);
4018 numsigs = (int) TARGET_SIGNAL_LAST;
4019 signal_stop = (unsigned char *)
4020 xmalloc (sizeof (signal_stop[0]) * numsigs);
4021 signal_print = (unsigned char *)
4022 xmalloc (sizeof (signal_print[0]) * numsigs);
4023 signal_program = (unsigned char *)
4024 xmalloc (sizeof (signal_program[0]) * numsigs);
4025 for (i = 0; i < numsigs; i++)
4028 signal_print[i] = 1;
4029 signal_program[i] = 1;
4032 /* Signals caused by debugger's own actions
4033 should not be given to the program afterwards. */
4034 signal_program[TARGET_SIGNAL_TRAP] = 0;
4035 signal_program[TARGET_SIGNAL_INT] = 0;
4037 /* Signals that are not errors should not normally enter the debugger. */
4038 signal_stop[TARGET_SIGNAL_ALRM] = 0;
4039 signal_print[TARGET_SIGNAL_ALRM] = 0;
4040 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
4041 signal_print[TARGET_SIGNAL_VTALRM] = 0;
4042 signal_stop[TARGET_SIGNAL_PROF] = 0;
4043 signal_print[TARGET_SIGNAL_PROF] = 0;
4044 signal_stop[TARGET_SIGNAL_CHLD] = 0;
4045 signal_print[TARGET_SIGNAL_CHLD] = 0;
4046 signal_stop[TARGET_SIGNAL_IO] = 0;
4047 signal_print[TARGET_SIGNAL_IO] = 0;
4048 signal_stop[TARGET_SIGNAL_POLL] = 0;
4049 signal_print[TARGET_SIGNAL_POLL] = 0;
4050 signal_stop[TARGET_SIGNAL_URG] = 0;
4051 signal_print[TARGET_SIGNAL_URG] = 0;
4052 signal_stop[TARGET_SIGNAL_WINCH] = 0;
4053 signal_print[TARGET_SIGNAL_WINCH] = 0;
4055 /* These signals are used internally by user-level thread
4056 implementations. (See signal(5) on Solaris.) Like the above
4057 signals, a healthy program receives and handles them as part of
4058 its normal operation. */
4059 signal_stop[TARGET_SIGNAL_LWP] = 0;
4060 signal_print[TARGET_SIGNAL_LWP] = 0;
4061 signal_stop[TARGET_SIGNAL_WAITING] = 0;
4062 signal_print[TARGET_SIGNAL_WAITING] = 0;
4063 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
4064 signal_print[TARGET_SIGNAL_CANCEL] = 0;
4068 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
4069 (char *) &stop_on_solib_events,
4070 "Set stopping for shared library events.\n\
4071 If nonzero, gdb will give control to the user when the dynamic linker\n\
4072 notifies gdb of shared library events. The most common event of interest\n\
4073 to the user would be loading/unloading of a new library.\n",
4078 c = add_set_enum_cmd ("follow-fork-mode",
4080 follow_fork_mode_kind_names,
4081 (char *) &follow_fork_mode_string,
4082 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4083 kernel problem. It's also not terribly useful without a GUI to
4084 help the user drive two debuggers. So for now, I'm disabling
4085 the "both" option. */
4086 /* "Set debugger response to a program call of fork \
4088 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4089 parent - the original process is debugged after a fork\n\
4090 child - the new process is debugged after a fork\n\
4091 both - both the parent and child are debugged after a fork\n\
4092 ask - the debugger will ask for one of the above choices\n\
4093 For \"both\", another copy of the debugger will be started to follow\n\
4094 the new child process. The original debugger will continue to follow\n\
4095 the original parent process. To distinguish their prompts, the\n\
4096 debugger copy's prompt will be changed.\n\
4097 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4098 By default, the debugger will follow the parent process.",
4100 "Set debugger response to a program call of fork \
4102 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4103 parent - the original process is debugged after a fork\n\
4104 child - the new process is debugged after a fork\n\
4105 ask - the debugger will ask for one of the above choices\n\
4106 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4107 By default, the debugger will follow the parent process.",
4109 /* c->function.sfunc = ; */
4110 add_show_from_set (c, &showlist);
4112 set_follow_fork_mode_command ("parent", 0, NULL);
4114 c = add_set_enum_cmd ("scheduler-locking", class_run,
4115 scheduler_enums, /* array of string names */
4116 (char *) &scheduler_mode, /* current mode */
4117 "Set mode for locking scheduler during execution.\n\
4118 off == no locking (threads may preempt at any time)\n\
4119 on == full locking (no thread except the current thread may run)\n\
4120 step == scheduler locked during every single-step operation.\n\
4121 In this mode, no other thread may run during a step command.\n\
4122 Other threads may run while stepping over a function call ('next').",
4125 c->function.sfunc = set_schedlock_func; /* traps on target vector */
4126 add_show_from_set (c, &showlist);