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, Boston, MA 02111-1307, USA. */
21 #include "gdb_string.h"
26 #include "breakpoint.h"
31 #include "gdbthread.h"
33 #include "symfile.h" /* for overlay functions */
38 /* Prototypes for local functions */
40 static void signals_info PARAMS ((char *, int));
42 static void handle_command PARAMS ((char *, int));
44 static void sig_print_info PARAMS ((enum target_signal));
46 static void sig_print_header PARAMS ((void));
48 static void resume_cleanups PARAMS ((int));
50 static int hook_stop_stub PARAMS ((PTR));
52 static void delete_breakpoint_current_contents PARAMS ((PTR));
54 static void set_follow_fork_mode_command PARAMS ((char *arg, int from_tty, struct cmd_list_element *c));
56 int inferior_ignoring_startup_exec_events = 0;
57 int inferior_ignoring_leading_exec_events = 0;
59 /* wait_for_inferior and normal_stop use this to notify the user
60 when the inferior stopped in a different thread than it had been
62 static int switched_from_inferior_pid;
64 /* This will be true for configurations that may actually report an
65 inferior pid different from the original. At present this is only
66 true for HP-UX native. */
68 #ifndef MAY_SWITCH_FROM_INFERIOR_PID
69 #define MAY_SWITCH_FROM_INFERIOR_PID (0)
72 static int may_switch_from_inferior_pid = MAY_SWITCH_FROM_INFERIOR_PID;
74 /* This is true for configurations that may follow through execl() and
75 similar functions. At present this is only true for HP-UX native. */
77 #ifndef MAY_FOLLOW_EXEC
78 #define MAY_FOLLOW_EXEC (0)
81 static int may_follow_exec = MAY_FOLLOW_EXEC;
83 /* resume and wait_for_inferior use this to ensure that when
84 stepping over a hit breakpoint in a threaded application
85 only the thread that hit the breakpoint is stepped and the
86 other threads don't continue. This prevents having another
87 thread run past the breakpoint while it is temporarily
90 This is not thread-specific, so it isn't saved as part of
93 Versions of gdb which don't use the "step == this thread steps
94 and others continue" model but instead use the "step == this
95 thread steps and others wait" shouldn't do this. */
96 static int thread_step_needed = 0;
98 /* This is true if thread_step_needed should actually be used. At
99 present this is only true for HP-UX native. */
101 #ifndef USE_THREAD_STEP_NEEDED
102 #define USE_THREAD_STEP_NEEDED (0)
105 static int use_thread_step_needed = USE_THREAD_STEP_NEEDED;
107 static void follow_inferior_fork PARAMS ((int parent_pid,
112 static void follow_fork PARAMS ((int parent_pid, int child_pid));
114 static void follow_vfork PARAMS ((int parent_pid, int child_pid));
116 static void set_schedlock_func PARAMS ((char *args, int from_tty,
117 struct cmd_list_element *c));
119 static int is_internal_shlib_eventpoint PARAMS ((struct breakpoint *ep));
121 static int stopped_for_internal_shlib_event PARAMS ((bpstat bs));
123 static int stopped_for_shlib_catchpoint PARAMS ((bpstat bs,
124 struct breakpoint **cp_p));
127 struct execution_control_state;
129 static int currently_stepping PARAMS ((struct execution_control_state *ecs));
131 static void xdb_handle_command PARAMS ((char *args, int from_tty));
133 void _initialize_infrun PARAMS ((void));
135 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
136 program. It needs to examine the jmp_buf argument and extract the PC
137 from it. The return value is non-zero on success, zero otherwise. */
139 #ifndef GET_LONGJMP_TARGET
140 #define GET_LONGJMP_TARGET(PC_ADDR) 0
144 /* Some machines have trampoline code that sits between function callers
145 and the actual functions themselves. If this machine doesn't have
146 such things, disable their processing. */
148 #ifndef SKIP_TRAMPOLINE_CODE
149 #define SKIP_TRAMPOLINE_CODE(pc) 0
152 /* Dynamic function trampolines are similar to solib trampolines in that they
153 are between the caller and the callee. The difference is that when you
154 enter a dynamic trampoline, you can't determine the callee's address. Some
155 (usually complex) code needs to run in the dynamic trampoline to figure out
156 the callee's address. This macro is usually called twice. First, when we
157 enter the trampoline (looks like a normal function call at that point). It
158 should return the PC of a point within the trampoline where the callee's
159 address is known. Second, when we hit the breakpoint, this routine returns
160 the callee's address. At that point, things proceed as per a step resume
163 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
164 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
167 /* On SVR4 based systems, determining the callee's address is exceedingly
168 difficult and depends on the implementation of the run time loader.
169 If we are stepping at the source level, we single step until we exit
170 the run time loader code and reach the callee's address. */
172 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
173 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
176 /* For SVR4 shared libraries, each call goes through a small piece of
177 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
178 to nonzero if we are current stopped in one of these. */
180 #ifndef IN_SOLIB_CALL_TRAMPOLINE
181 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
184 /* In some shared library schemes, the return path from a shared library
185 call may need to go through a trampoline too. */
187 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
188 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
191 /* This function returns TRUE if pc is the address of an instruction
192 that lies within the dynamic linker (such as the event hook, or the
195 This function must be used only when a dynamic linker event has
196 been caught, and the inferior is being stepped out of the hook, or
197 undefined results are guaranteed. */
199 #ifndef SOLIB_IN_DYNAMIC_LINKER
200 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
203 /* On MIPS16, a function that returns a floating point value may call
204 a library helper function to copy the return value to a floating point
205 register. The IGNORE_HELPER_CALL macro returns non-zero if we
206 should ignore (i.e. step over) this function call. */
207 #ifndef IGNORE_HELPER_CALL
208 #define IGNORE_HELPER_CALL(pc) 0
211 /* On some systems, the PC may be left pointing at an instruction that won't
212 actually be executed. This is usually indicated by a bit in the PSW. If
213 we find ourselves in such a state, then we step the target beyond the
214 nullified instruction before returning control to the user so as to avoid
217 #ifndef INSTRUCTION_NULLIFIED
218 #define INSTRUCTION_NULLIFIED 0
221 /* Convert the #defines into values. This is temporary until wfi control
222 flow is completely sorted out. */
224 #ifndef HAVE_STEPPABLE_WATCHPOINT
225 #define HAVE_STEPPABLE_WATCHPOINT 0
227 #undef HAVE_STEPPABLE_WATCHPOINT
228 #define HAVE_STEPPABLE_WATCHPOINT 1
231 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
232 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
234 #undef HAVE_NONSTEPPABLE_WATCHPOINT
235 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
238 #ifndef HAVE_CONTINUABLE_WATCHPOINT
239 #define HAVE_CONTINUABLE_WATCHPOINT 0
241 #undef HAVE_CONTINUABLE_WATCHPOINT
242 #define HAVE_CONTINUABLE_WATCHPOINT 1
245 /* Tables of how to react to signals; the user sets them. */
247 static unsigned char *signal_stop;
248 static unsigned char *signal_print;
249 static unsigned char *signal_program;
251 #define SET_SIGS(nsigs,sigs,flags) \
253 int signum = (nsigs); \
254 while (signum-- > 0) \
255 if ((sigs)[signum]) \
256 (flags)[signum] = 1; \
259 #define UNSET_SIGS(nsigs,sigs,flags) \
261 int signum = (nsigs); \
262 while (signum-- > 0) \
263 if ((sigs)[signum]) \
264 (flags)[signum] = 0; \
268 /* Command list pointer for the "stop" placeholder. */
270 static struct cmd_list_element *stop_command;
272 /* Nonzero if breakpoints are now inserted in the inferior. */
274 static int breakpoints_inserted;
276 /* Function inferior was in as of last step command. */
278 static struct symbol *step_start_function;
280 /* Nonzero if we are expecting a trace trap and should proceed from it. */
282 static int trap_expected;
285 /* Nonzero if we want to give control to the user when we're notified
286 of shared library events by the dynamic linker. */
287 static int stop_on_solib_events;
291 /* Nonzero if the next time we try to continue the inferior, it will
292 step one instruction and generate a spurious trace trap.
293 This is used to compensate for a bug in HP-UX. */
295 static int trap_expected_after_continue;
298 /* Nonzero means expecting a trace trap
299 and should stop the inferior and return silently when it happens. */
303 /* Nonzero means expecting a trap and caller will handle it themselves.
304 It is used after attach, due to attaching to a process;
305 when running in the shell before the child program has been exec'd;
306 and when running some kinds of remote stuff (FIXME?). */
308 int stop_soon_quietly;
310 /* Nonzero if proceed is being used for a "finish" command or a similar
311 situation when stop_registers should be saved. */
313 int proceed_to_finish;
315 /* Save register contents here when about to pop a stack dummy frame,
316 if-and-only-if proceed_to_finish is set.
317 Thus this contains the return value from the called function (assuming
318 values are returned in a register). */
320 char *stop_registers;
322 /* Nonzero if program stopped due to error trying to insert breakpoints. */
324 static int breakpoints_failed;
326 /* Nonzero after stop if current stack frame should be printed. */
328 static int stop_print_frame;
330 static struct breakpoint *step_resume_breakpoint = NULL;
331 static struct breakpoint *through_sigtramp_breakpoint = NULL;
333 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
334 interactions with an inferior that is running a kernel function
335 (aka, a system call or "syscall"). wait_for_inferior therefore
336 may have a need to know when the inferior is in a syscall. This
337 is a count of the number of inferior threads which are known to
338 currently be running in a syscall. */
339 static int number_of_threads_in_syscalls;
341 /* This is used to remember when a fork, vfork or exec event
342 was caught by a catchpoint, and thus the event is to be
343 followed at the next resume of the inferior, and not
347 enum target_waitkind kind;
357 char *execd_pathname;
361 /* Some platforms don't allow us to do anything meaningful with a
362 vforked child until it has exec'd. Vforked processes on such
363 platforms can only be followed after they've exec'd.
365 When this is set to 0, a vfork can be immediately followed,
366 and an exec can be followed merely as an exec. When this is
367 set to 1, a vfork event has been seen, but cannot be followed
368 until the exec is seen.
370 (In the latter case, inferior_pid is still the parent of the
371 vfork, and pending_follow.fork_event.child_pid is the child. The
372 appropriate process is followed, according to the setting of
373 follow-fork-mode.) */
374 static int follow_vfork_when_exec;
376 static char *follow_fork_mode_kind_names[] =
378 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
379 kernel problem. It's also not terribly useful without a GUI to
380 help the user drive two debuggers. So for now, I'm disabling
382 "parent", "child", "both", "ask" };
384 "parent", "child", "ask"};
386 static char *follow_fork_mode_string = NULL;
390 follow_inferior_fork (parent_pid, child_pid, has_forked, has_vforked)
396 int followed_parent = 0;
397 int followed_child = 0;
400 /* Which process did the user want us to follow? */
402 savestring (follow_fork_mode_string, strlen (follow_fork_mode_string));
404 /* Or, did the user not know, and want us to ask? */
405 if (STREQ (follow_fork_mode_string, "ask"))
407 char requested_mode[100];
410 error ("\"ask\" mode NYI");
411 follow_mode = savestring (requested_mode, strlen (requested_mode));
414 /* If we're to be following the parent, then detach from child_pid.
415 We're already following the parent, so need do nothing explicit
417 if (STREQ (follow_mode, "parent"))
421 /* We're already attached to the parent, by default. */
423 /* Before detaching from the child, remove all breakpoints from
424 it. (This won't actually modify the breakpoint list, but will
425 physically remove the breakpoints from the child.) */
426 if (!has_vforked || !follow_vfork_when_exec)
428 detach_breakpoints (child_pid);
429 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
430 SOLIB_REMOVE_INFERIOR_HOOK (child_pid);
434 /* Detach from the child. */
437 target_require_detach (child_pid, "", 1);
440 /* If we're to be following the child, then attach to it, detach
441 from inferior_pid, and set inferior_pid to child_pid. */
442 else if (STREQ (follow_mode, "child"))
444 char child_pid_spelling[100]; /* Arbitrary length. */
448 /* Before detaching from the parent, detach all breakpoints from
449 the child. But only if we're forking, or if we follow vforks
450 as soon as they happen. (If we're following vforks only when
451 the child has exec'd, then it's very wrong to try to write
452 back the "shadow contents" of inserted breakpoints now -- they
453 belong to the child's pre-exec'd a.out.) */
454 if (!has_vforked || !follow_vfork_when_exec)
456 detach_breakpoints (child_pid);
459 /* Before detaching from the parent, remove all breakpoints from it. */
460 remove_breakpoints ();
462 /* Also reset the solib inferior hook from the parent. */
463 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
464 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid);
467 /* Detach from the parent. */
469 target_detach (NULL, 1);
471 /* Attach to the child. */
472 inferior_pid = child_pid;
473 sprintf (child_pid_spelling, "%d", child_pid);
476 target_require_attach (child_pid_spelling, 1);
478 /* Was there a step_resume breakpoint? (There was if the user
479 did a "next" at the fork() call.) If so, explicitly reset its
482 step_resumes are a form of bp that are made to be per-thread.
483 Since we created the step_resume bp when the parent process
484 was being debugged, and now are switching to the child process,
485 from the breakpoint package's viewpoint, that's a switch of
486 "threads". We must update the bp's notion of which thread
487 it is for, or it'll be ignored when it triggers... */
488 if (step_resume_breakpoint &&
489 (!has_vforked || !follow_vfork_when_exec))
490 breakpoint_re_set_thread (step_resume_breakpoint);
492 /* Reinsert all breakpoints in the child. (The user may've set
493 breakpoints after catching the fork, in which case those
494 actually didn't get set in the child, but only in the parent.) */
495 if (!has_vforked || !follow_vfork_when_exec)
497 breakpoint_re_set ();
498 insert_breakpoints ();
502 /* If we're to be following both parent and child, then fork ourselves,
503 and attach the debugger clone to the child. */
504 else if (STREQ (follow_mode, "both"))
506 char pid_suffix[100]; /* Arbitrary length. */
508 /* Clone ourselves to follow the child. This is the end of our
509 involvement with child_pid; our clone will take it from here... */
511 target_clone_and_follow_inferior (child_pid, &followed_child);
512 followed_parent = !followed_child;
514 /* We continue to follow the parent. To help distinguish the two
515 debuggers, though, both we and our clone will reset our prompts. */
516 sprintf (pid_suffix, "[%d] ", inferior_pid);
517 set_prompt (strcat (get_prompt (), pid_suffix));
520 /* The parent and child of a vfork share the same address space.
521 Also, on some targets the order in which vfork and exec events
522 are received for parent in child requires some delicate handling
525 For instance, on ptrace-based HPUX we receive the child's vfork
526 event first, at which time the parent has been suspended by the
527 OS and is essentially untouchable until the child's exit or second
528 exec event arrives. At that time, the parent's vfork event is
529 delivered to us, and that's when we see and decide how to follow
530 the vfork. But to get to that point, we must continue the child
531 until it execs or exits. To do that smoothly, all breakpoints
532 must be removed from the child, in case there are any set between
533 the vfork() and exec() calls. But removing them from the child
534 also removes them from the parent, due to the shared-address-space
535 nature of a vfork'd parent and child. On HPUX, therefore, we must
536 take care to restore the bp's to the parent before we continue it.
537 Else, it's likely that we may not stop in the expected place. (The
538 worst scenario is when the user tries to step over a vfork() call;
539 the step-resume bp must be restored for the step to properly stop
540 in the parent after the call completes!)
542 Sequence of events, as reported to gdb from HPUX:
544 Parent Child Action for gdb to take
545 -------------------------------------------------------
546 1 VFORK Continue child
552 target_post_follow_vfork (parent_pid,
558 pending_follow.fork_event.saw_parent_fork = 0;
559 pending_follow.fork_event.saw_child_fork = 0;
565 follow_fork (parent_pid, child_pid)
569 follow_inferior_fork (parent_pid, child_pid, 1, 0);
573 /* Forward declaration. */
574 static void follow_exec PARAMS ((int, char *));
577 follow_vfork (parent_pid, child_pid)
581 follow_inferior_fork (parent_pid, child_pid, 0, 1);
583 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
584 if (pending_follow.fork_event.saw_child_exec && (inferior_pid == child_pid))
586 pending_follow.fork_event.saw_child_exec = 0;
587 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
588 follow_exec (inferior_pid, pending_follow.execd_pathname);
589 free (pending_follow.execd_pathname);
594 follow_exec (pid, execd_pathname)
596 char *execd_pathname;
599 struct target_ops *tgt;
601 if (!may_follow_exec)
604 /* Did this exec() follow a vfork()? If so, we must follow the
605 vfork now too. Do it before following the exec. */
606 if (follow_vfork_when_exec &&
607 (pending_follow.kind == TARGET_WAITKIND_VFORKED))
609 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
610 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
611 follow_vfork_when_exec = 0;
612 saved_pid = inferior_pid;
614 /* Did we follow the parent? If so, we're done. If we followed
615 the child then we must also follow its exec(). */
616 if (inferior_pid == pending_follow.fork_event.parent_pid)
620 /* This is an exec event that we actually wish to pay attention to.
621 Refresh our symbol table to the newly exec'd program, remove any
624 If there are breakpoints, they aren't really inserted now,
625 since the exec() transformed our inferior into a fresh set
628 We want to preserve symbolic breakpoints on the list, since
629 we have hopes that they can be reset after the new a.out's
630 symbol table is read.
632 However, any "raw" breakpoints must be removed from the list
633 (e.g., the solib bp's), since their address is probably invalid
636 And, we DON'T want to call delete_breakpoints() here, since
637 that may write the bp's "shadow contents" (the instruction
638 value that was overwritten witha TRAP instruction). Since
639 we now have a new a.out, those shadow contents aren't valid. */
640 update_breakpoints_after_exec ();
642 /* If there was one, it's gone now. We cannot truly step-to-next
643 statement through an exec(). */
644 step_resume_breakpoint = NULL;
645 step_range_start = 0;
648 /* If there was one, it's gone now. */
649 through_sigtramp_breakpoint = NULL;
651 /* What is this a.out's name? */
652 printf_unfiltered ("Executing new program: %s\n", execd_pathname);
654 /* We've followed the inferior through an exec. Therefore, the
655 inferior has essentially been killed & reborn. */
657 /* First collect the run target in effect. */
658 tgt = find_run_target ();
659 /* If we can't find one, things are in a very strange state... */
661 error ("Could find run target to save before following exec");
663 gdb_flush (gdb_stdout);
664 target_mourn_inferior ();
665 inferior_pid = saved_pid; /* Because mourn_inferior resets inferior_pid. */
668 /* That a.out is now the one to use. */
669 exec_file_attach (execd_pathname, 0);
671 /* And also is where symbols can be found. */
672 symbol_file_command (execd_pathname, 0);
674 /* Reset the shared library package. This ensures that we get
675 a shlib event when the child reaches "_start", at which point
676 the dld will have had a chance to initialize the child. */
677 #if defined(SOLIB_RESTART)
680 #ifdef SOLIB_CREATE_INFERIOR_HOOK
681 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid);
684 /* Reinsert all breakpoints. (Those which were symbolic have
685 been reset to the proper address in the new a.out, thanks
686 to symbol_file_command...) */
687 insert_breakpoints ();
689 /* The next resume of this inferior should bring it to the shlib
690 startup breakpoints. (If the user had also set bp's on
691 "main" from the old (parent) process, then they'll auto-
692 matically get reset there in the new process.) */
695 /* Non-zero if we just simulating a single-step. This is needed
696 because we cannot remove the breakpoints in the inferior process
697 until after the `wait' in `wait_for_inferior'. */
698 static int singlestep_breakpoints_inserted_p = 0;
701 /* Things to clean up if we QUIT out of resume (). */
704 resume_cleanups (arg)
710 static char schedlock_off[] = "off";
711 static char schedlock_on[] = "on";
712 static char schedlock_step[] = "step";
713 static char *scheduler_mode = schedlock_off;
714 static char *scheduler_enums[] =
715 {schedlock_off, schedlock_on, schedlock_step};
718 set_schedlock_func (args, from_tty, c)
721 struct cmd_list_element *c;
723 if (c->type == set_cmd)
724 if (!target_can_lock_scheduler)
726 scheduler_mode = schedlock_off;
727 error ("Target '%s' cannot support this command.",
733 /* Resume the inferior, but allow a QUIT. This is useful if the user
734 wants to interrupt some lengthy single-stepping operation
735 (for child processes, the SIGINT goes to the inferior, and so
736 we get a SIGINT random_signal, but for remote debugging and perhaps
737 other targets, that's not true).
739 STEP nonzero if we should step (zero to continue instead).
740 SIG is the signal to give the inferior (zero for none). */
744 enum target_signal sig;
746 int should_resume = 1;
747 struct cleanup *old_cleanups = make_cleanup ((make_cleanup_func)
751 #ifdef CANNOT_STEP_BREAKPOINT
752 /* Most targets can step a breakpoint instruction, thus executing it
753 normally. But if this one cannot, just continue and we will hit
755 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
759 if (SOFTWARE_SINGLE_STEP_P && step)
761 /* Do it the hard way, w/temp breakpoints */
762 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints*/ );
763 /* ...and don't ask hardware to do it. */
765 /* and do not pull these breakpoints until after a `wait' in
766 `wait_for_inferior' */
767 singlestep_breakpoints_inserted_p = 1;
770 /* Handle any optimized stores to the inferior NOW... */
771 #ifdef DO_DEFERRED_STORES
775 /* If there were any forks/vforks/execs that were caught and are
776 now to be followed, then do so. */
777 switch (pending_follow.kind)
779 case (TARGET_WAITKIND_FORKED):
780 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
781 follow_fork (inferior_pid, pending_follow.fork_event.child_pid);
784 case (TARGET_WAITKIND_VFORKED):
786 int saw_child_exec = pending_follow.fork_event.saw_child_exec;
788 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
789 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
791 /* Did we follow the child, but not yet see the child's exec event?
792 If so, then it actually ought to be waiting for us; we respond to
793 parent vfork events. We don't actually want to resume the child
794 in this situation; we want to just get its exec event. */
795 if (!saw_child_exec &&
796 (inferior_pid == pending_follow.fork_event.child_pid))
801 case (TARGET_WAITKIND_EXECD):
802 /* If we saw a vfork event but couldn't follow it until we saw
803 an exec, then now might be the time! */
804 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
805 /* follow_exec is called as soon as the exec event is seen. */
812 /* Install inferior's terminal modes. */
813 target_terminal_inferior ();
817 if (use_thread_step_needed && thread_step_needed)
819 /* We stopped on a BPT instruction;
820 don't continue other threads and
821 just step this thread. */
822 thread_step_needed = 0;
824 if (!breakpoint_here_p (read_pc ()))
826 /* Breakpoint deleted: ok to do regular resume
827 where all the threads either step or continue. */
828 target_resume (-1, step, sig);
834 warning ("Internal error, changing continue to step.");
835 remove_breakpoints ();
836 breakpoints_inserted = 0;
841 target_resume (inferior_pid, step, sig);
846 /* Vanilla resume. */
848 if ((scheduler_mode == schedlock_on) ||
849 (scheduler_mode == schedlock_step && step != 0))
850 target_resume (inferior_pid, step, sig);
852 target_resume (-1, step, sig);
856 discard_cleanups (old_cleanups);
860 /* Clear out all variables saying what to do when inferior is continued.
861 First do this, then set the ones you want, then call `proceed'. */
864 clear_proceed_status ()
867 step_range_start = 0;
869 step_frame_address = 0;
870 step_over_calls = -1;
872 stop_soon_quietly = 0;
873 proceed_to_finish = 0;
874 breakpoint_proceeded = 1; /* We're about to proceed... */
876 /* Discard any remaining commands or status from previous stop. */
877 bpstat_clear (&stop_bpstat);
880 /* Basic routine for continuing the program in various fashions.
882 ADDR is the address to resume at, or -1 for resume where stopped.
883 SIGGNAL is the signal to give it, or 0 for none,
884 or -1 for act according to how it stopped.
885 STEP is nonzero if should trap after one instruction.
886 -1 means return after that and print nothing.
887 You should probably set various step_... variables
888 before calling here, if you are stepping.
890 You should call clear_proceed_status before calling proceed. */
893 proceed (addr, siggnal, step)
895 enum target_signal siggnal;
901 step_start_function = find_pc_function (read_pc ());
905 if (addr == (CORE_ADDR) - 1)
907 /* If there is a breakpoint at the address we will resume at,
908 step one instruction before inserting breakpoints
909 so that we do not stop right away (and report a second
910 hit at this breakpoint). */
912 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
915 #ifndef STEP_SKIPS_DELAY
916 #define STEP_SKIPS_DELAY(pc) (0)
917 #define STEP_SKIPS_DELAY_P (0)
919 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
920 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
921 is slow (it needs to read memory from the target). */
922 if (STEP_SKIPS_DELAY_P
923 && breakpoint_here_p (read_pc () + 4)
924 && STEP_SKIPS_DELAY (read_pc ()))
931 /* New address; we don't need to single-step a thread
932 over a breakpoint we just hit, 'cause we aren't
933 continuing from there.
935 It's not worth worrying about the case where a user
936 asks for a "jump" at the current PC--if they get the
937 hiccup of re-hiting a hit breakpoint, what else do
939 thread_step_needed = 0;
942 #ifdef PREPARE_TO_PROCEED
943 /* In a multi-threaded task we may select another thread
944 and then continue or step.
946 But if the old thread was stopped at a breakpoint, it
947 will immediately cause another breakpoint stop without
948 any execution (i.e. it will report a breakpoint hit
949 incorrectly). So we must step over it first.
951 PREPARE_TO_PROCEED checks the current thread against the thread
952 that reported the most recent event. If a step-over is required
953 it returns TRUE and sets the current thread to the old thread. */
954 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
957 thread_step_needed = 1;
960 #endif /* PREPARE_TO_PROCEED */
963 if (trap_expected_after_continue)
965 /* If (step == 0), a trap will be automatically generated after
966 the first instruction is executed. Force step one
967 instruction to clear this condition. This should not occur
968 if step is nonzero, but it is harmless in that case. */
970 trap_expected_after_continue = 0;
972 #endif /* HP_OS_BUG */
975 /* We will get a trace trap after one instruction.
976 Continue it automatically and insert breakpoints then. */
980 int temp = insert_breakpoints ();
983 print_sys_errmsg ("ptrace", temp);
984 error ("Cannot insert breakpoints.\n\
985 The same program may be running in another process.");
988 breakpoints_inserted = 1;
991 if (siggnal != TARGET_SIGNAL_DEFAULT)
992 stop_signal = siggnal;
993 /* If this signal should not be seen by program,
994 give it zero. Used for debugging signals. */
995 else if (!signal_program[stop_signal])
996 stop_signal = TARGET_SIGNAL_0;
998 annotate_starting ();
1000 /* Make sure that output from GDB appears before output from the
1002 gdb_flush (gdb_stdout);
1004 /* Resume inferior. */
1005 resume (oneproc || step || bpstat_should_step (), stop_signal);
1007 /* Wait for it to stop (if not standalone)
1008 and in any case decode why it stopped, and act accordingly. */
1010 wait_for_inferior ();
1014 /* Record the pc and sp of the program the last time it stopped.
1015 These are just used internally by wait_for_inferior, but need
1016 to be preserved over calls to it and cleared when the inferior
1018 static CORE_ADDR prev_pc;
1019 static CORE_ADDR prev_func_start;
1020 static char *prev_func_name;
1023 /* Start remote-debugging of a machine over a serial link. */
1028 init_thread_list ();
1029 init_wait_for_inferior ();
1030 stop_soon_quietly = 1;
1032 wait_for_inferior ();
1036 /* Initialize static vars when a new inferior begins. */
1039 init_wait_for_inferior ()
1041 /* These are meaningless until the first time through wait_for_inferior. */
1043 prev_func_start = 0;
1044 prev_func_name = NULL;
1047 trap_expected_after_continue = 0;
1049 breakpoints_inserted = 0;
1050 breakpoint_init_inferior (inf_starting);
1052 /* Don't confuse first call to proceed(). */
1053 stop_signal = TARGET_SIGNAL_0;
1055 /* The first resume is not following a fork/vfork/exec. */
1056 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
1057 pending_follow.fork_event.saw_parent_fork = 0;
1058 pending_follow.fork_event.saw_child_fork = 0;
1059 pending_follow.fork_event.saw_child_exec = 0;
1061 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1062 number_of_threads_in_syscalls = 0;
1064 clear_proceed_status ();
1068 delete_breakpoint_current_contents (arg)
1071 struct breakpoint **breakpointp = (struct breakpoint **) arg;
1072 if (*breakpointp != NULL)
1074 delete_breakpoint (*breakpointp);
1075 *breakpointp = NULL;
1079 /* This enum encodes possible reasons for doing a target_wait, so that
1080 wfi can call target_wait in one place. (Ultimately the call will be
1081 moved out of the infinite loop entirely.) */
1083 enum infwait_states {
1084 infwait_normal_state,
1085 infwait_thread_hop_state,
1086 infwait_nullified_state,
1087 infwait_nonstep_watch_state
1090 /* This structure contains what used to be local variables in
1091 wait_for_inferior. Probably many of them can return to being
1092 locals in handle_inferior_event. */
1094 struct execution_control_state {
1095 struct target_waitstatus ws;
1096 struct target_waitstatus *wp;
1099 CORE_ADDR stop_func_start;
1100 CORE_ADDR stop_func_end;
1101 char *stop_func_name;
1102 struct symtab_and_line sal;
1103 int remove_breakpoints_on_following_step;
1105 struct symtab *current_symtab;
1106 int handling_longjmp; /* FIXME */
1108 int saved_inferior_pid;
1110 int stepping_through_solib_after_catch;
1111 bpstat stepping_through_solib_catchpoints;
1112 int enable_hw_watchpoints_after_wait;
1113 int stepping_through_sigtramp;
1114 int new_thread_event;
1115 struct target_waitstatus tmpstatus;
1116 enum infwait_states infwait_state;
1121 void init_execution_control_state PARAMS ((struct execution_control_state *ecs));
1123 void handle_inferior_event PARAMS ((struct execution_control_state *ecs));
1125 /* Wait for control to return from inferior to debugger.
1126 If inferior gets a signal, we may decide to start it up again
1127 instead of returning. That is why there is a loop in this function.
1128 When this function actually returns it means the inferior
1129 should be left stopped and GDB should read more commands. */
1132 wait_for_inferior ()
1134 struct cleanup *old_cleanups;
1135 struct execution_control_state ecss;
1136 struct execution_control_state *ecs;
1138 old_cleanups = make_cleanup (delete_breakpoint_current_contents,
1139 &step_resume_breakpoint);
1140 make_cleanup (delete_breakpoint_current_contents,
1141 &through_sigtramp_breakpoint);
1143 /* wfi still stays in a loop, so it's OK just to take the address of
1144 a local to get the ecs pointer. */
1147 /* Fill in with reasonable starting values. */
1148 init_execution_control_state (ecs);
1150 thread_step_needed = 0;
1152 /* We'll update this if & when we switch to a new thread. */
1153 if (may_switch_from_inferior_pid)
1154 switched_from_inferior_pid = inferior_pid;
1156 overlay_cache_invalid = 1;
1158 /* We have to invalidate the registers BEFORE calling target_wait
1159 because they can be loaded from the target while in target_wait.
1160 This makes remote debugging a bit more efficient for those
1161 targets that provide critical registers as part of their normal
1162 status mechanism. */
1164 registers_changed ();
1168 if (target_wait_hook)
1169 ecs->pid = target_wait_hook (ecs->waiton_pid, ecs->wp);
1171 ecs->pid = target_wait (ecs->waiton_pid, ecs->wp);
1173 /* Now figure out what to do with the result of the result. */
1174 handle_inferior_event (ecs);
1176 if (!ecs->wait_some_more)
1179 do_cleanups (old_cleanups);
1182 /* Prepare an execution control state for looping through a
1183 wait_for_inferior-type loop. */
1186 init_execution_control_state (ecs)
1187 struct execution_control_state *ecs;
1189 ecs->random_signal = 0;
1190 ecs->remove_breakpoints_on_following_step = 0;
1191 ecs->handling_longjmp = 0; /* FIXME */
1192 ecs->update_step_sp = 0;
1193 ecs->stepping_through_solib_after_catch = 0;
1194 ecs->stepping_through_solib_catchpoints = NULL;
1195 ecs->enable_hw_watchpoints_after_wait = 0;
1196 ecs->stepping_through_sigtramp = 0;
1197 ecs->sal = find_pc_line (prev_pc, 0);
1198 ecs->current_line = ecs->sal.line;
1199 ecs->current_symtab = ecs->sal.symtab;
1200 ecs->infwait_state = infwait_normal_state;
1201 ecs->waiton_pid = -1;
1202 ecs->wp = &(ecs->ws);
1205 /* Given an execution control state that has been freshly filled in
1206 by an event from the inferior, figure out what it means and take
1207 appropriate action. */
1210 handle_inferior_event (ecs)
1211 struct execution_control_state *ecs;
1214 int stepped_after_stopped_by_watchpoint;
1216 /* Keep this extra brace for now, minimizes diffs. */
1218 switch (ecs->infwait_state)
1220 case infwait_normal_state:
1221 /* Since we've done a wait, we have a new event. Don't
1222 carry over any expectations about needing to step over a
1224 thread_step_needed = 0;
1226 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1227 is serviced in this loop, below. */
1228 if (ecs->enable_hw_watchpoints_after_wait)
1230 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid);
1231 ecs->enable_hw_watchpoints_after_wait = 0;
1233 stepped_after_stopped_by_watchpoint = 0;
1236 case infwait_thread_hop_state:
1237 insert_breakpoints ();
1239 /* We need to restart all the threads now,
1240 * unles we're running in scheduler-locked mode.
1241 * FIXME: shouldn't we look at currently_stepping ()?
1243 if (scheduler_mode == schedlock_on)
1244 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1246 target_resume (-1, 0, TARGET_SIGNAL_0);
1247 ecs->infwait_state = infwait_normal_state;
1250 case infwait_nullified_state:
1253 case infwait_nonstep_watch_state:
1254 insert_breakpoints ();
1256 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1257 handle things like signals arriving and other things happening
1258 in combination correctly? */
1259 stepped_after_stopped_by_watchpoint = 1;
1262 ecs->infwait_state = infwait_normal_state;
1264 flush_cached_frames ();
1266 /* If it's a new process, add it to the thread database */
1268 ecs->new_thread_event = ((ecs->pid != inferior_pid) && !in_thread_list (ecs->pid));
1270 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1271 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
1272 && ecs->new_thread_event)
1274 add_thread (ecs->pid);
1276 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs->pid));
1279 /* NOTE: This block is ONLY meant to be invoked in case of a
1280 "thread creation event"! If it is invoked for any other
1281 sort of event (such as a new thread landing on a breakpoint),
1282 the event will be discarded, which is almost certainly
1285 To avoid this, the low-level module (eg. target_wait)
1286 should call in_thread_list and add_thread, so that the
1287 new thread is known by the time we get here. */
1289 /* We may want to consider not doing a resume here in order
1290 to give the user a chance to play with the new thread.
1291 It might be good to make that a user-settable option. */
1293 /* At this point, all threads are stopped (happens
1294 automatically in either the OS or the native code).
1295 Therefore we need to continue all threads in order to
1298 target_resume (-1, 0, TARGET_SIGNAL_0);
1303 switch (ecs->ws.kind)
1305 case TARGET_WAITKIND_LOADED:
1306 /* Ignore gracefully during startup of the inferior, as it
1307 might be the shell which has just loaded some objects,
1308 otherwise add the symbols for the newly loaded objects. */
1310 if (!stop_soon_quietly)
1312 /* Remove breakpoints, SOLIB_ADD might adjust
1313 breakpoint addresses via breakpoint_re_set. */
1314 if (breakpoints_inserted)
1315 remove_breakpoints ();
1317 /* Check for any newly added shared libraries if we're
1318 supposed to be adding them automatically. */
1321 /* Switch terminal for any messages produced by
1322 breakpoint_re_set. */
1323 target_terminal_ours_for_output ();
1324 SOLIB_ADD (NULL, 0, NULL);
1325 target_terminal_inferior ();
1328 /* Reinsert breakpoints and continue. */
1329 if (breakpoints_inserted)
1330 insert_breakpoints ();
1333 resume (0, TARGET_SIGNAL_0);
1336 case TARGET_WAITKIND_SPURIOUS:
1337 resume (0, TARGET_SIGNAL_0);
1340 case TARGET_WAITKIND_EXITED:
1341 target_terminal_ours (); /* Must do this before mourn anyway */
1342 annotate_exited (ecs->ws.value.integer);
1343 if (ecs->ws.value.integer)
1344 printf_filtered ("\nProgram exited with code 0%o.\n",
1345 (unsigned int) ecs->ws.value.integer);
1347 printf_filtered ("\nProgram exited normally.\n");
1349 /* Record the exit code in the convenience variable $_exitcode, so
1350 that the user can inspect this again later. */
1351 set_internalvar (lookup_internalvar ("_exitcode"),
1352 value_from_longest (builtin_type_int,
1353 (LONGEST) ecs->ws.value.integer));
1354 gdb_flush (gdb_stdout);
1355 target_mourn_inferior ();
1356 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P*/
1357 stop_print_frame = 0;
1360 case TARGET_WAITKIND_SIGNALLED:
1361 stop_print_frame = 0;
1362 stop_signal = ecs->ws.value.sig;
1363 target_terminal_ours (); /* Must do this before mourn anyway */
1364 annotate_signalled ();
1366 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1367 mean it is already dead? This has been here since GDB 2.8, so
1368 perhaps it means rms didn't understand unix waitstatuses?
1369 For the moment I'm just kludging around this in remote.c
1370 rather than trying to change it here --kingdon, 5 Dec 1994. */
1371 target_kill (); /* kill mourns as well */
1373 printf_filtered ("\nProgram terminated with signal ");
1374 annotate_signal_name ();
1375 printf_filtered ("%s", target_signal_to_name (stop_signal));
1376 annotate_signal_name_end ();
1377 printf_filtered (", ");
1378 annotate_signal_string ();
1379 printf_filtered ("%s", target_signal_to_string (stop_signal));
1380 annotate_signal_string_end ();
1381 printf_filtered (".\n");
1383 printf_filtered ("The program no longer exists.\n");
1384 gdb_flush (gdb_stdout);
1385 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P*/
1388 /* The following are the only cases in which we keep going;
1389 the above cases end in a continue or goto. */
1390 case TARGET_WAITKIND_FORKED:
1391 stop_signal = TARGET_SIGNAL_TRAP;
1392 pending_follow.kind = ecs->ws.kind;
1394 /* Ignore fork events reported for the parent; we're only
1395 interested in reacting to forks of the child. Note that
1396 we expect the child's fork event to be available if we
1397 waited for it now. */
1398 if (inferior_pid == ecs->pid)
1400 pending_follow.fork_event.saw_parent_fork = 1;
1401 pending_follow.fork_event.parent_pid = ecs->pid;
1402 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1407 pending_follow.fork_event.saw_child_fork = 1;
1408 pending_follow.fork_event.child_pid = ecs->pid;
1409 pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid;
1412 stop_pc = read_pc_pid (ecs->pid);
1413 ecs->saved_inferior_pid = inferior_pid;
1414 inferior_pid = ecs->pid;
1415 stop_bpstat = bpstat_stop_status
1417 (DECR_PC_AFTER_BREAK ?
1418 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1419 && currently_stepping (ecs))
1422 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1423 inferior_pid = ecs->saved_inferior_pid;
1424 goto process_event_stop_test;
1426 /* If this a platform which doesn't allow a debugger to touch a
1427 vfork'd inferior until after it exec's, then we'd best keep
1428 our fingers entirely off the inferior, other than continuing
1429 it. This has the unfortunate side-effect that catchpoints
1430 of vforks will be ignored. But since the platform doesn't
1431 allow the inferior be touched at vfork time, there's really
1433 case TARGET_WAITKIND_VFORKED:
1434 stop_signal = TARGET_SIGNAL_TRAP;
1435 pending_follow.kind = ecs->ws.kind;
1437 /* Is this a vfork of the parent? If so, then give any
1438 vfork catchpoints a chance to trigger now. (It's
1439 dangerous to do so if the child canot be touched until
1440 it execs, and the child has not yet exec'd. We probably
1441 should warn the user to that effect when the catchpoint
1443 if (ecs->pid == inferior_pid)
1445 pending_follow.fork_event.saw_parent_fork = 1;
1446 pending_follow.fork_event.parent_pid = ecs->pid;
1447 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1450 /* If we've seen the child's vfork event but cannot really touch
1451 the child until it execs, then we must continue the child now.
1452 Else, give any vfork catchpoints a chance to trigger now. */
1455 pending_follow.fork_event.saw_child_fork = 1;
1456 pending_follow.fork_event.child_pid = ecs->pid;
1457 pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid;
1458 target_post_startup_inferior (pending_follow.fork_event.child_pid);
1459 follow_vfork_when_exec = !target_can_follow_vfork_prior_to_exec ();
1460 if (follow_vfork_when_exec)
1462 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1467 stop_pc = read_pc ();
1468 stop_bpstat = bpstat_stop_status
1470 (DECR_PC_AFTER_BREAK ?
1471 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1472 && currently_stepping (ecs))
1475 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1476 goto process_event_stop_test;
1478 case TARGET_WAITKIND_EXECD:
1479 stop_signal = TARGET_SIGNAL_TRAP;
1481 /* Is this a target which reports multiple exec events per actual
1482 call to exec()? (HP-UX using ptrace does, for example.) If so,
1483 ignore all but the last one. Just resume the exec'r, and wait
1484 for the next exec event. */
1485 if (inferior_ignoring_leading_exec_events)
1487 inferior_ignoring_leading_exec_events--;
1488 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1489 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.parent_pid);
1490 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1493 inferior_ignoring_leading_exec_events =
1494 target_reported_exec_events_per_exec_call () - 1;
1496 pending_follow.execd_pathname = savestring (ecs->ws.value.execd_pathname,
1497 strlen (ecs->ws.value.execd_pathname));
1499 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1500 child of a vfork exec?
1502 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1503 HP-UX, events associated with a vforking inferior come in
1504 threes: a vfork event for the child (always first), followed
1505 a vfork event for the parent and an exec event for the child.
1506 The latter two can come in either order.
1508 If we get the parent vfork event first, life's good: We follow
1509 either the parent or child, and then the child's exec event is
1512 But if we get the child's exec event first, then we delay
1513 responding to it until we handle the parent's vfork. Because,
1514 otherwise we can't satisfy a "catch vfork". */
1515 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1517 pending_follow.fork_event.saw_child_exec = 1;
1519 /* On some targets, the child must be resumed before
1520 the parent vfork event is delivered. A single-step
1522 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1523 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1524 /* We expect the parent vfork event to be available now. */
1528 /* This causes the eventpoints and symbol table to be reset. Must
1529 do this now, before trying to determine whether to stop. */
1530 follow_exec (inferior_pid, pending_follow.execd_pathname);
1531 free (pending_follow.execd_pathname);
1533 stop_pc = read_pc_pid (ecs->pid);
1534 ecs->saved_inferior_pid = inferior_pid;
1535 inferior_pid = ecs->pid;
1536 stop_bpstat = bpstat_stop_status
1538 (DECR_PC_AFTER_BREAK ?
1539 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1540 && currently_stepping (ecs))
1543 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1544 inferior_pid = ecs->saved_inferior_pid;
1545 goto process_event_stop_test;
1547 /* These syscall events are returned on HP-UX, as part of its
1548 implementation of page-protection-based "hardware" watchpoints.
1549 HP-UX has unfortunate interactions between page-protections and
1550 some system calls. Our solution is to disable hardware watches
1551 when a system call is entered, and reenable them when the syscall
1552 completes. The downside of this is that we may miss the precise
1553 point at which a watched piece of memory is modified. "Oh well."
1555 Note that we may have multiple threads running, which may each
1556 enter syscalls at roughly the same time. Since we don't have a
1557 good notion currently of whether a watched piece of memory is
1558 thread-private, we'd best not have any page-protections active
1559 when any thread is in a syscall. Thus, we only want to reenable
1560 hardware watches when no threads are in a syscall.
1562 Also, be careful not to try to gather much state about a thread
1563 that's in a syscall. It's frequently a losing proposition. */
1564 case TARGET_WAITKIND_SYSCALL_ENTRY:
1565 number_of_threads_in_syscalls++;
1566 if (number_of_threads_in_syscalls == 1)
1568 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid);
1570 resume (0, TARGET_SIGNAL_0);
1573 /* Before examining the threads further, step this thread to
1574 get it entirely out of the syscall. (We get notice of the
1575 event when the thread is just on the verge of exiting a
1576 syscall. Stepping one instruction seems to get it back
1579 Note that although the logical place to reenable h/w watches
1580 is here, we cannot. We cannot reenable them before stepping
1581 the thread (this causes the next wait on the thread to hang).
1583 Nor can we enable them after stepping until we've done a wait.
1584 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1585 here, which will be serviced immediately after the target
1587 case TARGET_WAITKIND_SYSCALL_RETURN:
1588 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1590 if (number_of_threads_in_syscalls > 0)
1592 number_of_threads_in_syscalls--;
1593 ecs->enable_hw_watchpoints_after_wait =
1594 (number_of_threads_in_syscalls == 0);
1598 case TARGET_WAITKIND_STOPPED:
1599 stop_signal = ecs->ws.value.sig;
1603 /* We may want to consider not doing a resume here in order to give
1604 the user a chance to play with the new thread. It might be good
1605 to make that a user-settable option. */
1607 /* At this point, all threads are stopped (happens automatically in
1608 either the OS or the native code). Therefore we need to continue
1609 all threads in order to make progress. */
1610 if (ecs->new_thread_event)
1612 target_resume (-1, 0, TARGET_SIGNAL_0);
1616 stop_pc = read_pc_pid (ecs->pid);
1618 /* See if a thread hit a thread-specific breakpoint that was meant for
1619 another thread. If so, then step that thread past the breakpoint,
1622 if (stop_signal == TARGET_SIGNAL_TRAP)
1624 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1625 ecs->random_signal = 0;
1626 else if (breakpoints_inserted
1627 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
1629 ecs->random_signal = 0;
1630 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK,
1635 /* Saw a breakpoint, but it was hit by the wrong thread.
1637 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, ecs->pid);
1639 remove_status = remove_breakpoints ();
1640 /* Did we fail to remove breakpoints? If so, try
1641 to set the PC past the bp. (There's at least
1642 one situation in which we can fail to remove
1643 the bp's: On HP-UX's that use ttrace, we can't
1644 change the address space of a vforking child
1645 process until the child exits (well, okay, not
1646 then either :-) or execs. */
1647 if (remove_status != 0)
1649 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, ecs->pid);
1653 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1654 /* FIXME: What if a signal arrives instead of the
1655 single-step happening? */
1657 ecs->waiton_pid = ecs->pid;
1658 ecs->wp = &(ecs->ws);
1659 ecs->infwait_state = infwait_thread_hop_state;
1663 /* We need to restart all the threads now,
1664 * unles we're running in scheduler-locked mode.
1665 * FIXME: shouldn't we look at currently_stepping ()?
1667 if (scheduler_mode == schedlock_on)
1668 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1670 target_resume (-1, 0, TARGET_SIGNAL_0);
1675 /* This breakpoint matches--either it is the right
1676 thread or it's a generic breakpoint for all threads.
1677 Remember that we'll need to step just _this_ thread
1678 on any following user continuation! */
1679 thread_step_needed = 1;
1684 ecs->random_signal = 1;
1686 /* See if something interesting happened to the non-current thread. If
1687 so, then switch to that thread, and eventually give control back to
1690 Note that if there's any kind of pending follow (i.e., of a fork,
1691 vfork or exec), we don't want to do this now. Rather, we'll let
1692 the next resume handle it. */
1693 if ((ecs->pid != inferior_pid) &&
1694 (pending_follow.kind == TARGET_WAITKIND_SPURIOUS))
1698 /* If it's a random signal for a non-current thread, notify user
1699 if he's expressed an interest. */
1700 if (ecs->random_signal
1701 && signal_print[stop_signal])
1703 /* ??rehrauer: I don't understand the rationale for this code. If the
1704 inferior will stop as a result of this signal, then the act of handling
1705 the stop ought to print a message that's couches the stoppage in user
1706 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1707 won't stop as a result of the signal -- i.e., if the signal is merely
1708 a side-effect of something GDB's doing "under the covers" for the
1709 user, such as stepping threads over a breakpoint they shouldn't stop
1710 for -- then the message seems to be a serious annoyance at best.
1712 For now, remove the message altogether. */
1715 target_terminal_ours_for_output ();
1716 printf_filtered ("\nProgram received signal %s, %s.\n",
1717 target_signal_to_name (stop_signal),
1718 target_signal_to_string (stop_signal));
1719 gdb_flush (gdb_stdout);
1723 /* If it's not SIGTRAP and not a signal we want to stop for, then
1724 continue the thread. */
1726 if (stop_signal != TARGET_SIGNAL_TRAP
1727 && !signal_stop[stop_signal])
1730 target_terminal_inferior ();
1732 /* Clear the signal if it should not be passed. */
1733 if (signal_program[stop_signal] == 0)
1734 stop_signal = TARGET_SIGNAL_0;
1736 target_resume (ecs->pid, 0, stop_signal);
1740 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1741 and fall into the rest of wait_for_inferior(). */
1743 /* Save infrun state for the old thread. */
1744 save_infrun_state (inferior_pid, prev_pc,
1745 prev_func_start, prev_func_name,
1746 trap_expected, step_resume_breakpoint,
1747 through_sigtramp_breakpoint,
1748 step_range_start, step_range_end,
1749 step_frame_address, ecs->handling_longjmp,
1751 ecs->stepping_through_solib_after_catch,
1752 ecs->stepping_through_solib_catchpoints,
1753 ecs->stepping_through_sigtramp);
1755 if (may_switch_from_inferior_pid)
1756 switched_from_inferior_pid = inferior_pid;
1758 inferior_pid = ecs->pid;
1760 /* Load infrun state for the new thread. */
1761 load_infrun_state (inferior_pid, &prev_pc,
1762 &prev_func_start, &prev_func_name,
1763 &trap_expected, &step_resume_breakpoint,
1764 &through_sigtramp_breakpoint,
1765 &step_range_start, &step_range_end,
1766 &step_frame_address, &ecs->handling_longjmp,
1768 &ecs->stepping_through_solib_after_catch,
1769 &ecs->stepping_through_solib_catchpoints,
1770 &ecs->stepping_through_sigtramp);
1773 context_hook (pid_to_thread_id (ecs->pid));
1775 printf_filtered ("[Switching to %s]\n", target_pid_to_str (ecs->pid));
1776 flush_cached_frames ();
1779 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1781 /* Pull the single step breakpoints out of the target. */
1782 SOFTWARE_SINGLE_STEP (0, 0);
1783 singlestep_breakpoints_inserted_p = 0;
1786 /* If PC is pointing at a nullified instruction, then step beyond
1787 it so that the user won't be confused when GDB appears to be ready
1790 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1791 if (INSTRUCTION_NULLIFIED)
1793 registers_changed ();
1794 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1796 /* We may have received a signal that we want to pass to
1797 the inferior; therefore, we must not clobber the waitstatus
1800 ecs->infwait_state = infwait_nullified_state;
1801 ecs->waiton_pid = ecs->pid;
1802 ecs->wp = &(ecs->tmpstatus);
1806 /* It may not be necessary to disable the watchpoint to stop over
1807 it. For example, the PA can (with some kernel cooperation)
1808 single step over a watchpoint without disabling the watchpoint. */
1809 if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1815 /* It is far more common to need to disable a watchpoint to step
1816 the inferior over it. FIXME. What else might a debug
1817 register or page protection watchpoint scheme need here? */
1818 if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1820 /* At this point, we are stopped at an instruction which has
1821 attempted to write to a piece of memory under control of
1822 a watchpoint. The instruction hasn't actually executed
1823 yet. If we were to evaluate the watchpoint expression
1824 now, we would get the old value, and therefore no change
1825 would seem to have occurred.
1827 In order to make watchpoints work `right', we really need
1828 to complete the memory write, and then evaluate the
1829 watchpoint expression. The following code does that by
1830 removing the watchpoint (actually, all watchpoints and
1831 breakpoints), single-stepping the target, re-inserting
1832 watchpoints, and then falling through to let normal
1833 single-step processing handle proceed. Since this
1834 includes evaluating watchpoints, things will come to a
1835 stop in the correct manner. */
1837 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
1839 remove_breakpoints ();
1840 registers_changed ();
1841 target_resume (ecs->pid, 1, TARGET_SIGNAL_0); /* Single step */
1843 ecs->waiton_pid = ecs->pid;
1844 ecs->wp = &(ecs->ws);
1845 ecs->infwait_state = infwait_nonstep_watch_state;
1849 /* It may be possible to simply continue after a watchpoint. */
1850 if (HAVE_CONTINUABLE_WATCHPOINT)
1851 STOPPED_BY_WATCHPOINT (ecs->ws);
1853 ecs->stop_func_start = 0;
1854 ecs->stop_func_end = 0;
1855 ecs->stop_func_name = 0;
1856 /* Don't care about return value; stop_func_start and stop_func_name
1857 will both be 0 if it doesn't work. */
1858 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
1859 &ecs->stop_func_start, &ecs->stop_func_end);
1860 ecs->stop_func_start += FUNCTION_START_OFFSET;
1861 ecs->another_trap = 0;
1862 bpstat_clear (&stop_bpstat);
1864 stop_stack_dummy = 0;
1865 stop_print_frame = 1;
1866 ecs->random_signal = 0;
1867 stopped_by_random_signal = 0;
1868 breakpoints_failed = 0;
1870 /* Look at the cause of the stop, and decide what to do.
1871 The alternatives are:
1872 1) break; to really stop and return to the debugger,
1873 2) drop through to start up again
1874 (set ecs->another_trap to 1 to single step once)
1875 3) set ecs->random_signal to 1, and the decision between 1 and 2
1876 will be made according to the signal handling tables. */
1878 /* First, distinguish signals caused by the debugger from signals
1879 that have to do with the program's own actions.
1880 Note that breakpoint insns may cause SIGTRAP or SIGILL
1881 or SIGEMT, depending on the operating system version.
1882 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1883 and change it to SIGTRAP. */
1885 if (stop_signal == TARGET_SIGNAL_TRAP
1886 || (breakpoints_inserted &&
1887 (stop_signal == TARGET_SIGNAL_ILL
1888 || stop_signal == TARGET_SIGNAL_EMT
1890 || stop_soon_quietly)
1892 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
1894 stop_print_frame = 0;
1897 if (stop_soon_quietly)
1900 /* Don't even think about breakpoints
1901 if just proceeded over a breakpoint.
1903 However, if we are trying to proceed over a breakpoint
1904 and end up in sigtramp, then through_sigtramp_breakpoint
1905 will be set and we should check whether we've hit the
1907 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
1908 && through_sigtramp_breakpoint == NULL)
1909 bpstat_clear (&stop_bpstat);
1912 /* See if there is a breakpoint at the current PC. */
1913 stop_bpstat = bpstat_stop_status
1915 (DECR_PC_AFTER_BREAK ?
1916 /* Notice the case of stepping through a jump
1917 that lands just after a breakpoint.
1918 Don't confuse that with hitting the breakpoint.
1919 What we check for is that 1) stepping is going on
1920 and 2) the pc before the last insn does not match
1921 the address of the breakpoint before the current pc
1922 and 3) we didn't hit a breakpoint in a signal handler
1923 without an intervening stop in sigtramp, which is
1924 detected by a new stack pointer value below
1925 any usual function calling stack adjustments. */
1926 (currently_stepping (ecs)
1927 && prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1929 && INNER_THAN (read_sp (), (step_sp - 16)))) :
1932 /* Following in case break condition called a
1934 stop_print_frame = 1;
1937 if (stop_signal == TARGET_SIGNAL_TRAP)
1939 = !(bpstat_explains_signal (stop_bpstat)
1941 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
1942 && PC_IN_CALL_DUMMY (stop_pc, read_sp (),
1943 FRAME_FP (get_current_frame ())))
1944 || (step_range_end && step_resume_breakpoint == NULL));
1949 = !(bpstat_explains_signal (stop_bpstat)
1950 /* End of a stack dummy. Some systems (e.g. Sony
1951 news) give another signal besides SIGTRAP, so
1952 check here as well as above. */
1953 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
1954 && PC_IN_CALL_DUMMY (stop_pc, read_sp (),
1955 FRAME_FP (get_current_frame ())))
1957 if (!ecs->random_signal)
1958 stop_signal = TARGET_SIGNAL_TRAP;
1962 /* When we reach this point, we've pretty much decided
1963 that the reason for stopping must've been a random
1964 (unexpected) signal. */
1967 ecs->random_signal = 1;
1968 /* If a fork, vfork or exec event was seen, then there are two
1969 possible responses we can make:
1971 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
1972 then we must stop now and issue a prompt. We will resume
1973 the inferior when the user tells us to.
1974 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
1975 then we must resume the inferior now and keep checking.
1977 In either case, we must take appropriate steps to "follow" the
1978 the fork/vfork/exec when the inferior is resumed. For example,
1979 if follow-fork-mode is "child", then we must detach from the
1980 parent inferior and follow the new child inferior.
1982 In either case, setting pending_follow causes the next resume()
1983 to take the appropriate following action. */
1984 process_event_stop_test:
1985 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
1987 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
1990 stop_signal = TARGET_SIGNAL_0;
1994 else if (ecs->ws.kind == TARGET_WAITKIND_VFORKED)
1996 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
1998 stop_signal = TARGET_SIGNAL_0;
2002 else if (ecs->ws.kind == TARGET_WAITKIND_EXECD)
2004 pending_follow.kind = ecs->ws.kind;
2005 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2008 stop_signal = TARGET_SIGNAL_0;
2013 /* For the program's own signals, act according to
2014 the signal handling tables. */
2016 if (ecs->random_signal)
2018 /* Signal not for debugging purposes. */
2021 stopped_by_random_signal = 1;
2023 if (signal_print[stop_signal])
2026 target_terminal_ours_for_output ();
2028 printf_filtered ("\nProgram received signal ");
2029 annotate_signal_name ();
2030 printf_filtered ("%s", target_signal_to_name (stop_signal));
2031 annotate_signal_name_end ();
2032 printf_filtered (", ");
2033 annotate_signal_string ();
2034 printf_filtered ("%s", target_signal_to_string (stop_signal));
2035 annotate_signal_string_end ();
2036 printf_filtered (".\n");
2037 gdb_flush (gdb_stdout);
2039 if (signal_stop[stop_signal])
2041 /* If not going to stop, give terminal back
2042 if we took it away. */
2044 target_terminal_inferior ();
2046 /* Clear the signal if it should not be passed. */
2047 if (signal_program[stop_signal] == 0)
2048 stop_signal = TARGET_SIGNAL_0;
2050 /* If we're in the middle of a "next" command, let the code for
2051 stepping over a function handle this. pai/1997-09-10
2053 A previous comment here suggested it was possible to change
2054 this to jump to keep_going in all cases. */
2056 if (step_over_calls > 0)
2057 goto step_over_function;
2059 goto check_sigtramp2;
2062 /* Handle cases caused by hitting a breakpoint. */
2064 CORE_ADDR jmp_buf_pc;
2065 struct bpstat_what what;
2067 what = bpstat_what (stop_bpstat);
2069 if (what.call_dummy)
2071 stop_stack_dummy = 1;
2073 trap_expected_after_continue = 1;
2077 switch (what.main_action)
2079 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
2080 /* If we hit the breakpoint at longjmp, disable it for the
2081 duration of this command. Then, install a temporary
2082 breakpoint at the target of the jmp_buf. */
2083 disable_longjmp_breakpoint ();
2084 remove_breakpoints ();
2085 breakpoints_inserted = 0;
2086 if (!GET_LONGJMP_TARGET (&jmp_buf_pc))
2089 /* Need to blow away step-resume breakpoint, as it
2090 interferes with us */
2091 if (step_resume_breakpoint != NULL)
2093 delete_breakpoint (step_resume_breakpoint);
2094 step_resume_breakpoint = NULL;
2096 /* Not sure whether we need to blow this away too, but probably
2097 it is like the step-resume breakpoint. */
2098 if (through_sigtramp_breakpoint != NULL)
2100 delete_breakpoint (through_sigtramp_breakpoint);
2101 through_sigtramp_breakpoint = NULL;
2105 /* FIXME - Need to implement nested temporary breakpoints */
2106 if (step_over_calls > 0)
2107 set_longjmp_resume_breakpoint (jmp_buf_pc,
2108 get_current_frame ());
2111 set_longjmp_resume_breakpoint (jmp_buf_pc, NULL);
2112 ecs->handling_longjmp = 1; /* FIXME */
2115 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
2116 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
2117 remove_breakpoints ();
2118 breakpoints_inserted = 0;
2120 /* FIXME - Need to implement nested temporary breakpoints */
2122 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2123 step_frame_address)))
2125 ecs->another_trap = 1;
2129 disable_longjmp_breakpoint ();
2130 ecs->handling_longjmp = 0; /* FIXME */
2131 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
2133 /* else fallthrough */
2135 case BPSTAT_WHAT_SINGLE:
2136 if (breakpoints_inserted)
2138 thread_step_needed = 1;
2139 remove_breakpoints ();
2141 breakpoints_inserted = 0;
2142 ecs->another_trap = 1;
2143 /* Still need to check other stuff, at least the case
2144 where we are stepping and step out of the right range. */
2147 case BPSTAT_WHAT_STOP_NOISY:
2148 stop_print_frame = 1;
2150 /* We are about to nuke the step_resume_breakpoint and
2151 through_sigtramp_breakpoint via the cleanup chain, so
2152 no need to worry about it here. */
2156 case BPSTAT_WHAT_STOP_SILENT:
2157 stop_print_frame = 0;
2159 /* We are about to nuke the step_resume_breakpoint and
2160 through_sigtramp_breakpoint via the cleanup chain, so
2161 no need to worry about it here. */
2165 case BPSTAT_WHAT_STEP_RESUME:
2166 /* This proably demands a more elegant solution, but, yeah
2169 This function's use of the simple variable
2170 step_resume_breakpoint doesn't seem to accomodate
2171 simultaneously active step-resume bp's, although the
2172 breakpoint list certainly can.
2174 If we reach here and step_resume_breakpoint is already
2175 NULL, then apparently we have multiple active
2176 step-resume bp's. We'll just delete the breakpoint we
2177 stopped at, and carry on. */
2178 if (step_resume_breakpoint == NULL)
2180 step_resume_breakpoint =
2181 bpstat_find_step_resume_breakpoint (stop_bpstat);
2183 delete_breakpoint (step_resume_breakpoint);
2184 step_resume_breakpoint = NULL;
2187 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2188 if (through_sigtramp_breakpoint)
2189 delete_breakpoint (through_sigtramp_breakpoint);
2190 through_sigtramp_breakpoint = NULL;
2192 /* If were waiting for a trap, hitting the step_resume_break
2193 doesn't count as getting it. */
2195 ecs->another_trap = 1;
2198 case BPSTAT_WHAT_CHECK_SHLIBS:
2199 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2202 /* Remove breakpoints, we eventually want to step over the
2203 shlib event breakpoint, and SOLIB_ADD might adjust
2204 breakpoint addresses via breakpoint_re_set. */
2205 if (breakpoints_inserted)
2206 remove_breakpoints ();
2207 breakpoints_inserted = 0;
2209 /* Check for any newly added shared libraries if we're
2210 supposed to be adding them automatically. */
2213 /* Switch terminal for any messages produced by
2214 breakpoint_re_set. */
2215 target_terminal_ours_for_output ();
2216 SOLIB_ADD (NULL, 0, NULL);
2217 target_terminal_inferior ();
2220 /* Try to reenable shared library breakpoints, additional
2221 code segments in shared libraries might be mapped in now. */
2222 re_enable_breakpoints_in_shlibs ();
2224 /* If requested, stop when the dynamic linker notifies
2225 gdb of events. This allows the user to get control
2226 and place breakpoints in initializer routines for
2227 dynamically loaded objects (among other things). */
2228 if (stop_on_solib_events)
2230 stop_print_frame = 0;
2234 /* If we stopped due to an explicit catchpoint, then the
2235 (see above) call to SOLIB_ADD pulled in any symbols
2236 from a newly-loaded library, if appropriate.
2238 We do want the inferior to stop, but not where it is
2239 now, which is in the dynamic linker callback. Rather,
2240 we would like it stop in the user's program, just after
2241 the call that caused this catchpoint to trigger. That
2242 gives the user a more useful vantage from which to
2243 examine their program's state. */
2244 else if (what.main_action == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2246 /* ??rehrauer: If I could figure out how to get the
2247 right return PC from here, we could just set a temp
2248 breakpoint and resume. I'm not sure we can without
2249 cracking open the dld's shared libraries and sniffing
2250 their unwind tables and text/data ranges, and that's
2251 not a terribly portable notion.
2253 Until that time, we must step the inferior out of the
2254 dld callback, and also out of the dld itself (and any
2255 code or stubs in libdld.sl, such as "shl_load" and
2256 friends) until we reach non-dld code. At that point,
2257 we can stop stepping. */
2258 bpstat_get_triggered_catchpoints (stop_bpstat,
2259 &ecs->stepping_through_solib_catchpoints);
2260 ecs->stepping_through_solib_after_catch = 1;
2262 /* Be sure to lift all breakpoints, so the inferior does
2263 actually step past this point... */
2264 ecs->another_trap = 1;
2269 /* We want to step over this breakpoint, then keep going. */
2270 ecs->another_trap = 1;
2277 case BPSTAT_WHAT_LAST:
2278 /* Not a real code, but listed here to shut up gcc -Wall. */
2280 case BPSTAT_WHAT_KEEP_CHECKING:
2285 /* We come here if we hit a breakpoint but should not
2286 stop for it. Possibly we also were stepping
2287 and should stop for that. So fall through and
2288 test for stepping. But, if not stepping,
2291 /* Are we stepping to get the inferior out of the dynamic
2292 linker's hook (and possibly the dld itself) after catching
2294 if (ecs->stepping_through_solib_after_catch)
2296 #if defined(SOLIB_ADD)
2297 /* Have we reached our destination? If not, keep going. */
2298 if (SOLIB_IN_DYNAMIC_LINKER (ecs->pid, stop_pc))
2300 ecs->another_trap = 1;
2304 /* Else, stop and report the catchpoint(s) whose triggering
2305 caused us to begin stepping. */
2306 ecs->stepping_through_solib_after_catch = 0;
2307 bpstat_clear (&stop_bpstat);
2308 stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints);
2309 bpstat_clear (&ecs->stepping_through_solib_catchpoints);
2310 stop_print_frame = 1;
2314 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P)
2316 /* This is the old way of detecting the end of the stack dummy.
2317 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2318 handled above. As soon as we can test it on all of them, all
2319 architectures should define it. */
2321 /* If this is the breakpoint at the end of a stack dummy,
2322 just stop silently, unless the user was doing an si/ni, in which
2323 case she'd better know what she's doing. */
2325 if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (),
2326 FRAME_FP (get_current_frame ()))
2329 stop_print_frame = 0;
2330 stop_stack_dummy = 1;
2332 trap_expected_after_continue = 1;
2338 if (step_resume_breakpoint)
2339 /* Having a step-resume breakpoint overrides anything
2340 else having to do with stepping commands until
2341 that breakpoint is reached. */
2342 /* I'm not sure whether this needs to be check_sigtramp2 or
2343 whether it could/should be keep_going. */
2344 goto check_sigtramp2;
2346 if (step_range_end == 0)
2347 /* Likewise if we aren't even stepping. */
2348 /* I'm not sure whether this needs to be check_sigtramp2 or
2349 whether it could/should be keep_going. */
2350 goto check_sigtramp2;
2352 /* If stepping through a line, keep going if still within it.
2354 Note that step_range_end is the address of the first instruction
2355 beyond the step range, and NOT the address of the last instruction
2357 if (stop_pc >= step_range_start
2358 && stop_pc < step_range_end)
2360 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2361 So definately need to check for sigtramp here. */
2362 goto check_sigtramp2;
2365 /* We stepped out of the stepping range. */
2367 /* If we are stepping at the source level and entered the runtime
2368 loader dynamic symbol resolution code, we keep on single stepping
2369 until we exit the run time loader code and reach the callee's
2371 if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2374 /* We can't update step_sp every time through the loop, because
2375 reading the stack pointer would slow down stepping too much.
2376 But we can update it every time we leave the step range. */
2377 ecs->update_step_sp = 1;
2379 /* Did we just take a signal? */
2380 if (IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2381 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2382 && INNER_THAN (read_sp (), step_sp))
2384 /* We've just taken a signal; go until we are back to
2385 the point where we took it and one more. */
2387 /* Note: The test above succeeds not only when we stepped
2388 into a signal handler, but also when we step past the last
2389 statement of a signal handler and end up in the return stub
2390 of the signal handler trampoline. To distinguish between
2391 these two cases, check that the frame is INNER_THAN the
2392 previous one below. pai/1997-09-11 */
2396 CORE_ADDR current_frame = FRAME_FP (get_current_frame ());
2398 if (INNER_THAN (current_frame, step_frame_address))
2400 /* We have just taken a signal; go until we are back to
2401 the point where we took it and one more. */
2403 /* This code is needed at least in the following case:
2404 The user types "next" and then a signal arrives (before
2405 the "next" is done). */
2407 /* Note that if we are stopped at a breakpoint, then we need
2408 the step_resume breakpoint to override any breakpoints at
2409 the same location, so that we will still step over the
2410 breakpoint even though the signal happened. */
2411 struct symtab_and_line sr_sal;
2414 sr_sal.symtab = NULL;
2416 sr_sal.pc = prev_pc;
2417 /* We could probably be setting the frame to
2418 step_frame_address; I don't think anyone thought to
2420 step_resume_breakpoint =
2421 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2422 if (breakpoints_inserted)
2423 insert_breakpoints ();
2427 /* We just stepped out of a signal handler and into
2428 its calling trampoline.
2430 Normally, we'd jump to step_over_function from
2431 here, but for some reason GDB can't unwind the
2432 stack correctly to find the real PC for the point
2433 user code where the signal trampoline will return
2434 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2435 But signal trampolines are pretty small stubs of
2436 code, anyway, so it's OK instead to just
2437 single-step out. Note: assuming such trampolines
2438 don't exhibit recursion on any platform... */
2439 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2440 &ecs->stop_func_start,
2441 &ecs->stop_func_end);
2442 /* Readjust stepping range */
2443 step_range_start = ecs->stop_func_start;
2444 step_range_end = ecs->stop_func_end;
2445 ecs->stepping_through_sigtramp = 1;
2450 /* If this is stepi or nexti, make sure that the stepping range
2451 gets us past that instruction. */
2452 if (step_range_end == 1)
2453 /* FIXME: Does this run afoul of the code below which, if
2454 we step into the middle of a line, resets the stepping
2456 step_range_end = (step_range_start = prev_pc) + 1;
2458 ecs->remove_breakpoints_on_following_step = 1;
2462 if (stop_pc == ecs->stop_func_start /* Quick test */
2463 || (in_prologue (stop_pc, ecs->stop_func_start) &&
2464 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2465 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name)
2466 || ecs->stop_func_name == 0)
2468 /* It's a subroutine call. */
2470 if (step_over_calls == 0)
2472 /* I presume that step_over_calls is only 0 when we're
2473 supposed to be stepping at the assembly language level
2474 ("stepi"). Just stop. */
2479 if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc))
2480 /* We're doing a "next". */
2481 goto step_over_function;
2483 /* If we are in a function call trampoline (a stub between
2484 the calling routine and the real function), locate the real
2485 function. That's what tells us (a) whether we want to step
2486 into it at all, and (b) what prologue we want to run to
2487 the end of, if we do step into it. */
2488 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2490 ecs->stop_func_start = tmp;
2493 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
2496 struct symtab_and_line xxx;
2497 /* Why isn't this s_a_l called "sr_sal", like all of the
2498 other s_a_l's where this code is duplicated? */
2499 INIT_SAL (&xxx); /* initialize to zeroes */
2501 xxx.section = find_pc_overlay (xxx.pc);
2502 step_resume_breakpoint =
2503 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
2504 insert_breakpoints ();
2509 /* If we have line number information for the function we
2510 are thinking of stepping into, step into it.
2512 If there are several symtabs at that PC (e.g. with include
2513 files), just want to know whether *any* of them have line
2514 numbers. find_pc_line handles this. */
2516 struct symtab_and_line tmp_sal;
2518 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
2519 if (tmp_sal.line != 0)
2520 goto step_into_function;
2524 /* A subroutine call has happened. */
2526 /* Set a special breakpoint after the return */
2527 struct symtab_and_line sr_sal;
2530 sr_sal.symtab = NULL;
2533 /* If we came here after encountering a signal in the middle of
2534 a "next", use the stashed-away previous frame pc */
2536 = stopped_by_random_signal
2538 : ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2540 step_resume_breakpoint =
2541 set_momentary_breakpoint (sr_sal,
2542 stopped_by_random_signal ?
2543 NULL : get_current_frame (),
2546 /* We've just entered a callee, and we wish to resume until
2547 it returns to the caller. Setting a step_resume bp on
2548 the return PC will catch a return from the callee.
2550 However, if the callee is recursing, we want to be
2551 careful not to catch returns of those recursive calls,
2552 but of THIS instance of the call.
2554 To do this, we set the step_resume bp's frame to our
2555 current caller's frame (step_frame_address, which is
2556 set by the "next" or "until" command, before execution
2559 But ... don't do it if we're single-stepping out of a
2560 sigtramp, because the reason we're single-stepping is
2561 precisely because unwinding is a problem (HP-UX 10.20,
2562 e.g.) and the frame address is likely to be incorrect.
2563 No danger of sigtramp recursion. */
2565 if (ecs->stepping_through_sigtramp)
2567 step_resume_breakpoint->frame = (CORE_ADDR) NULL;
2568 ecs->stepping_through_sigtramp = 0;
2570 else if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
2571 step_resume_breakpoint->frame = step_frame_address;
2573 if (breakpoints_inserted)
2574 insert_breakpoints ();
2579 /* Subroutine call with source code we should not step over.
2580 Do step to the first line of code in it. */
2584 s = find_pc_symtab (stop_pc);
2585 if (s && s->language != language_asm)
2586 ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start);
2588 ecs->sal = find_pc_line (ecs->stop_func_start, 0);
2589 /* Use the step_resume_break to step until
2590 the end of the prologue, even if that involves jumps
2591 (as it seems to on the vax under 4.2). */
2592 /* If the prologue ends in the middle of a source line,
2593 continue to the end of that source line (if it is still
2594 within the function). Otherwise, just go to end of prologue. */
2595 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2596 /* no, don't either. It skips any code that's
2597 legitimately on the first line. */
2599 if (ecs->sal.end && ecs->sal.pc != ecs->stop_func_start && ecs->sal.end < ecs->stop_func_end)
2600 ecs->stop_func_start = ecs->sal.end;
2603 if (ecs->stop_func_start == stop_pc)
2605 /* We are already there: stop now. */
2610 /* Put the step-breakpoint there and go until there. */
2612 struct symtab_and_line sr_sal;
2614 INIT_SAL (&sr_sal); /* initialize to zeroes */
2615 sr_sal.pc = ecs->stop_func_start;
2616 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
2617 /* Do not specify what the fp should be when we stop
2618 since on some machines the prologue
2619 is where the new fp value is established. */
2620 step_resume_breakpoint =
2621 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2622 if (breakpoints_inserted)
2623 insert_breakpoints ();
2625 /* And make sure stepping stops right away then. */
2626 step_range_end = step_range_start;
2631 /* We've wandered out of the step range. */
2633 ecs->sal = find_pc_line (stop_pc, 0);
2635 if (step_range_end == 1)
2637 /* It is stepi or nexti. We always want to stop stepping after
2643 /* If we're in the return path from a shared library trampoline,
2644 we want to proceed through the trampoline when stepping. */
2645 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2649 /* Determine where this trampoline returns. */
2650 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2652 /* Only proceed through if we know where it's going. */
2655 /* And put the step-breakpoint there and go until there. */
2656 struct symtab_and_line sr_sal;
2658 INIT_SAL (&sr_sal); /* initialize to zeroes */
2660 sr_sal.section = find_pc_overlay (sr_sal.pc);
2661 /* Do not specify what the fp should be when we stop
2662 since on some machines the prologue
2663 is where the new fp value is established. */
2664 step_resume_breakpoint =
2665 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2666 if (breakpoints_inserted)
2667 insert_breakpoints ();
2669 /* Restart without fiddling with the step ranges or
2675 if (ecs->sal.line == 0)
2677 /* We have no line number information. That means to stop
2678 stepping (does this always happen right after one instruction,
2679 when we do "s" in a function with no line numbers,
2680 or can this happen as a result of a return or longjmp?). */
2685 if ((stop_pc == ecs->sal.pc)
2686 && (ecs->current_line != ecs->sal.line || ecs->current_symtab != ecs->sal.symtab))
2688 /* We are at the start of a different line. So stop. Note that
2689 we don't stop if we step into the middle of a different line.
2690 That is said to make things like for (;;) statements work
2696 /* We aren't done stepping.
2698 Optimize by setting the stepping range to the line.
2699 (We might not be in the original line, but if we entered a
2700 new line in mid-statement, we continue stepping. This makes
2701 things like for(;;) statements work better.) */
2703 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
2705 /* If this is the last line of the function, don't keep stepping
2706 (it would probably step us out of the function).
2707 This is particularly necessary for a one-line function,
2708 in which after skipping the prologue we better stop even though
2709 we will be in mid-line. */
2713 step_range_start = ecs->sal.pc;
2714 step_range_end = ecs->sal.end;
2715 step_frame_address = FRAME_FP (get_current_frame ());
2716 ecs->current_line = ecs->sal.line;
2717 ecs->current_symtab = ecs->sal.symtab;
2719 /* In the case where we just stepped out of a function into the middle
2720 of a line of the caller, continue stepping, but step_frame_address
2721 must be modified to current frame */
2723 CORE_ADDR current_frame = FRAME_FP (get_current_frame ());
2724 if (!(INNER_THAN (current_frame, step_frame_address)))
2725 step_frame_address = current_frame;
2733 && IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2734 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2735 && INNER_THAN (read_sp (), step_sp))
2737 /* What has happened here is that we have just stepped the inferior
2738 with a signal (because it is a signal which shouldn't make
2739 us stop), thus stepping into sigtramp.
2741 So we need to set a step_resume_break_address breakpoint
2742 and continue until we hit it, and then step. FIXME: This should
2743 be more enduring than a step_resume breakpoint; we should know
2744 that we will later need to keep going rather than re-hitting
2745 the breakpoint here (see testsuite/gdb.t06/signals.exp where
2746 it says "exceedingly difficult"). */
2747 struct symtab_and_line sr_sal;
2749 INIT_SAL (&sr_sal); /* initialize to zeroes */
2750 sr_sal.pc = prev_pc;
2751 sr_sal.section = find_pc_overlay (sr_sal.pc);
2752 /* We perhaps could set the frame if we kept track of what
2753 the frame corresponding to prev_pc was. But we don't,
2755 through_sigtramp_breakpoint =
2756 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
2757 if (breakpoints_inserted)
2758 insert_breakpoints ();
2760 ecs->remove_breakpoints_on_following_step = 1;
2761 ecs->another_trap = 1;
2765 /* Come to this label when you need to resume the inferior.
2766 It's really much cleaner to do a goto than a maze of if-else
2769 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug
2770 a vforked child beetween its creation and subsequent exit or
2771 call to exec(). However, I had big problems in this rather
2772 creaky exec engine, getting that to work. The fundamental
2773 problem is that I'm trying to debug two processes via an
2774 engine that only understands a single process with possibly
2777 Hence, this spot is known to have problems when
2778 target_can_follow_vfork_prior_to_exec returns 1. */
2780 /* Save the pc before execution, to compare with pc after stop. */
2781 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
2782 prev_func_start = ecs->stop_func_start; /* Ok, since if DECR_PC_AFTER
2783 BREAK is defined, the
2784 original pc would not have
2785 been at the start of a
2787 prev_func_name = ecs->stop_func_name;
2789 if (ecs->update_step_sp)
2790 step_sp = read_sp ();
2791 ecs->update_step_sp = 0;
2793 /* If we did not do break;, it means we should keep
2794 running the inferior and not return to debugger. */
2796 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
2798 /* We took a signal (which we are supposed to pass through to
2799 the inferior, else we'd have done a break above) and we
2800 haven't yet gotten our trap. Simply continue. */
2801 resume (currently_stepping (ecs), stop_signal);
2805 /* Either the trap was not expected, but we are continuing
2806 anyway (the user asked that this signal be passed to the
2809 The signal was SIGTRAP, e.g. it was our signal, but we
2810 decided we should resume from it.
2812 We're going to run this baby now!
2814 Insert breakpoints now, unless we are trying
2815 to one-proceed past a breakpoint. */
2816 /* If we've just finished a special step resume and we don't
2817 want to hit a breakpoint, pull em out. */
2818 if (step_resume_breakpoint == NULL
2819 && through_sigtramp_breakpoint == NULL
2820 && ecs->remove_breakpoints_on_following_step)
2822 ecs->remove_breakpoints_on_following_step = 0;
2823 remove_breakpoints ();
2824 breakpoints_inserted = 0;
2826 else if (!breakpoints_inserted &&
2827 (through_sigtramp_breakpoint != NULL || !ecs->another_trap))
2829 breakpoints_failed = insert_breakpoints ();
2830 if (breakpoints_failed)
2832 breakpoints_inserted = 1;
2835 trap_expected = ecs->another_trap;
2837 /* Do not deliver SIGNAL_TRAP (except when the user
2838 explicitly specifies that such a signal should be
2839 delivered to the target program).
2841 Typically, this would occure when a user is debugging a
2842 target monitor on a simulator: the target monitor sets a
2843 breakpoint; the simulator encounters this break-point and
2844 halts the simulation handing control to GDB; GDB, noteing
2845 that the break-point isn't valid, returns control back to
2846 the simulator; the simulator then delivers the hardware
2847 equivalent of a SIGNAL_TRAP to the program being
2850 if (stop_signal == TARGET_SIGNAL_TRAP
2851 && !signal_program[stop_signal])
2852 stop_signal = TARGET_SIGNAL_0;
2854 #ifdef SHIFT_INST_REGS
2855 /* I'm not sure when this following segment applies. I do know,
2856 now, that we shouldn't rewrite the regs when we were stopped
2857 by a random signal from the inferior process. */
2858 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2859 (this is only used on the 88k). */
2861 if (!bpstat_explains_signal (stop_bpstat)
2862 && (stop_signal != TARGET_SIGNAL_CHLD)
2863 && !stopped_by_random_signal)
2865 #endif /* SHIFT_INST_REGS */
2867 resume (currently_stepping (ecs), stop_signal);
2870 /* Former continues in the main loop goto here. */
2872 /* This used to be at the top of the loop. */
2873 if (ecs->infwait_state == infwait_normal_state)
2875 overlay_cache_invalid = 1;
2877 /* We have to invalidate the registers BEFORE calling
2878 target_wait because they can be loaded from the target
2879 while in target_wait. This makes remote debugging a bit
2880 more efficient for those targets that provide critical
2881 registers as part of their normal status mechanism. */
2883 registers_changed ();
2884 ecs->waiton_pid = -1;
2885 ecs->wp = &(ecs->ws);
2887 /* This is the old end of the while loop. Let everybody know
2888 we want to wait for the inferior some more and get called
2890 ecs->wait_some_more = 1;
2894 /* Former breaks in the main loop goto here. */
2898 if (target_has_execution)
2900 /* Are we stopping for a vfork event? We only stop when we see
2901 the child's event. However, we may not yet have seen the
2902 parent's event. And, inferior_pid is still set to the parent's
2903 pid, until we resume again and follow either the parent or child.
2905 To ensure that we can really touch inferior_pid (aka, the
2906 parent process) -- which calls to functions like read_pc
2907 implicitly do -- wait on the parent if necessary. */
2908 if ((pending_follow.kind == TARGET_WAITKIND_VFORKED)
2909 && !pending_follow.fork_event.saw_parent_fork)
2915 if (target_wait_hook)
2916 parent_pid = target_wait_hook (-1, &(ecs->ws));
2918 parent_pid = target_wait (-1, &(ecs->ws));
2920 while (parent_pid != inferior_pid);
2923 /* Assuming the inferior still exists, set these up for next
2924 time, just like we did above if we didn't break out of the
2926 prev_pc = read_pc ();
2927 prev_func_start = ecs->stop_func_start;
2928 prev_func_name = ecs->stop_func_name;
2930 /* Let callers know we don't want to wait for the inferior anymore. */
2931 ecs->wait_some_more = 0;
2934 /* Are we in the middle of stepping? */
2937 currently_stepping (ecs)
2938 struct execution_control_state *ecs;
2940 return ((through_sigtramp_breakpoint == NULL
2941 && !ecs->handling_longjmp
2942 && ((step_range_end && step_resume_breakpoint == NULL)
2944 || ecs->stepping_through_solib_after_catch
2945 || bpstat_should_step ());
2948 /* This function returns TRUE if ep is an internal breakpoint
2949 set to catch generic shared library (aka dynamically-linked
2950 library) events. (This is *NOT* the same as a catchpoint for a
2951 shlib event. The latter is something a user can set; this is
2952 something gdb sets for its own use, and isn't ever shown to a
2955 is_internal_shlib_eventpoint (ep)
2956 struct breakpoint *ep;
2959 (ep->type == bp_shlib_event)
2963 /* This function returns TRUE if bs indicates that the inferior
2964 stopped due to a shared library (aka dynamically-linked library)
2967 stopped_for_internal_shlib_event (bs)
2970 /* Note that multiple eventpoints may've caused the stop. Any
2971 that are associated with shlib events will be accepted. */
2972 for (; bs != NULL; bs = bs->next)
2974 if ((bs->breakpoint_at != NULL)
2975 && is_internal_shlib_eventpoint (bs->breakpoint_at))
2979 /* If we get here, then no candidate was found. */
2983 /* This function returns TRUE if bs indicates that the inferior
2984 stopped due to a shared library (aka dynamically-linked library)
2985 event caught by a catchpoint.
2987 If TRUE, cp_p is set to point to the catchpoint.
2989 Else, the value of cp_p is undefined. */
2991 stopped_for_shlib_catchpoint (bs, cp_p)
2993 struct breakpoint **cp_p;
2995 /* Note that multiple eventpoints may've caused the stop. Any
2996 that are associated with shlib events will be accepted. */
2999 for (; bs != NULL; bs = bs->next)
3001 if ((bs->breakpoint_at != NULL)
3002 && ep_is_shlib_catchpoint (bs->breakpoint_at))
3004 *cp_p = bs->breakpoint_at;
3009 /* If we get here, then no candidate was found. */
3014 /* Here to return control to GDB when the inferior stops for real.
3015 Print appropriate messages, remove breakpoints, give terminal our modes.
3017 STOP_PRINT_FRAME nonzero means print the executing frame
3018 (pc, function, args, file, line number and line text).
3019 BREAKPOINTS_FAILED nonzero means stop was due to error
3020 attempting to insert breakpoints. */
3025 /* As with the notification of thread events, we want to delay
3026 notifying the user that we've switched thread context until
3027 the inferior actually stops.
3029 (Note that there's no point in saying anything if the inferior
3031 if (may_switch_from_inferior_pid
3032 && (switched_from_inferior_pid != inferior_pid)
3033 && target_has_execution)
3035 target_terminal_ours_for_output ();
3036 printf_filtered ("[Switched to %s]\n",
3037 target_pid_or_tid_to_str (inferior_pid));
3038 switched_from_inferior_pid = inferior_pid;
3041 /* Make sure that the current_frame's pc is correct. This
3042 is a correction for setting up the frame info before doing
3043 DECR_PC_AFTER_BREAK */
3044 if (target_has_execution && get_current_frame ())
3045 (get_current_frame ())->pc = read_pc ();
3047 if (breakpoints_failed)
3049 target_terminal_ours_for_output ();
3050 print_sys_errmsg ("ptrace", breakpoints_failed);
3051 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3052 The same program may be running in another process.\n");
3055 if (target_has_execution && breakpoints_inserted)
3057 if (remove_breakpoints ())
3059 target_terminal_ours_for_output ();
3060 printf_filtered ("Cannot remove breakpoints because ");
3061 printf_filtered ("program is no longer writable.\n");
3062 printf_filtered ("It might be running in another process.\n");
3063 printf_filtered ("Further execution is probably impossible.\n");
3066 breakpoints_inserted = 0;
3068 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3069 Delete any breakpoint that is to be deleted at the next stop. */
3071 breakpoint_auto_delete (stop_bpstat);
3073 /* If an auto-display called a function and that got a signal,
3074 delete that auto-display to avoid an infinite recursion. */
3076 if (stopped_by_random_signal)
3077 disable_current_display ();
3079 /* Don't print a message if in the middle of doing a "step n"
3080 operation for n > 1 */
3081 if (step_multi && stop_step)
3084 target_terminal_ours ();
3086 /* Did we stop because the user set the stop_on_solib_events
3087 variable? (If so, we report this as a generic, "Stopped due
3088 to shlib event" message.) */
3089 if (stopped_for_internal_shlib_event (stop_bpstat))
3091 printf_filtered ("Stopped due to shared library event\n");
3094 /* Look up the hook_stop and run it if it exists. */
3096 if (stop_command && stop_command->hook)
3098 catch_errors (hook_stop_stub, stop_command->hook,
3099 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3102 if (!target_has_stack)
3108 /* Select innermost stack frame - i.e., current frame is frame 0,
3109 and current location is based on that.
3110 Don't do this on return from a stack dummy routine,
3111 or if the program has exited. */
3113 if (!stop_stack_dummy)
3115 select_frame (get_current_frame (), 0);
3117 /* Print current location without a level number, if
3118 we have changed functions or hit a breakpoint.
3119 Print source line if we have one.
3120 bpstat_print() contains the logic deciding in detail
3121 what to print, based on the event(s) that just occurred. */
3123 if (stop_print_frame)
3128 bpstat_ret = bpstat_print (stop_bpstat);
3129 /* bpstat_print() returned one of:
3130 -1: Didn't print anything
3131 0: Printed preliminary "Breakpoint n, " message, desires
3133 1: Printed something, don't tack on location */
3135 if (bpstat_ret == -1)
3137 && step_frame_address == FRAME_FP (get_current_frame ())
3138 && step_start_function == find_pc_function (stop_pc))
3139 source_flag = -1; /* finished step, just print source line */
3141 source_flag = 1; /* print location and source line */
3142 else if (bpstat_ret == 0) /* hit bpt, desire location */
3143 source_flag = 1; /* print location and source line */
3144 else /* bpstat_ret == 1, hit bpt, do not desire location */
3145 source_flag = -1; /* just print source line */
3147 /* The behavior of this routine with respect to the source
3149 -1: Print only source line
3150 0: Print only location
3151 1: Print location and source line */
3152 show_and_print_stack_frame (selected_frame, -1, source_flag);
3154 /* Display the auto-display expressions. */
3159 /* Save the function value return registers, if we care.
3160 We might be about to restore their previous contents. */
3161 if (proceed_to_finish)
3162 read_register_bytes (0, stop_registers, REGISTER_BYTES);
3164 if (stop_stack_dummy)
3166 /* Pop the empty frame that contains the stack dummy.
3167 POP_FRAME ends with a setting of the current frame, so we
3168 can use that next. */
3170 /* Set stop_pc to what it was before we called the function.
3171 Can't rely on restore_inferior_status because that only gets
3172 called if we don't stop in the called function. */
3173 stop_pc = read_pc ();
3174 select_frame (get_current_frame (), 0);
3178 TUIDO (((TuiOpaqueFuncPtr) tui_vCheckDataValues, selected_frame));
3181 annotate_stopped ();
3185 hook_stop_stub (cmd)
3188 execute_user_command ((struct cmd_list_element *) cmd, 0);
3193 signal_stop_state (signo)
3196 return signal_stop[signo];
3200 signal_print_state (signo)
3203 return signal_print[signo];
3207 signal_pass_state (signo)
3210 return signal_program[signo];
3217 Signal Stop\tPrint\tPass to program\tDescription\n");
3221 sig_print_info (oursig)
3222 enum target_signal oursig;
3224 char *name = target_signal_to_name (oursig);
3225 int name_padding = 13 - strlen (name);
3226 if (name_padding <= 0)
3229 printf_filtered ("%s", name);
3230 printf_filtered ("%*.*s ", name_padding, name_padding,
3232 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3233 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3234 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3235 printf_filtered ("%s\n", target_signal_to_string (oursig));
3238 /* Specify how various signals in the inferior should be handled. */
3241 handle_command (args, from_tty)
3246 int digits, wordlen;
3247 int sigfirst, signum, siglast;
3248 enum target_signal oursig;
3251 unsigned char *sigs;
3252 struct cleanup *old_chain;
3256 error_no_arg ("signal to handle");
3259 /* Allocate and zero an array of flags for which signals to handle. */
3261 nsigs = (int) TARGET_SIGNAL_LAST;
3262 sigs = (unsigned char *) alloca (nsigs);
3263 memset (sigs, 0, nsigs);
3265 /* Break the command line up into args. */
3267 argv = buildargv (args);
3272 old_chain = make_cleanup_freeargv (argv);
3274 /* Walk through the args, looking for signal oursigs, signal names, and
3275 actions. Signal numbers and signal names may be interspersed with
3276 actions, with the actions being performed for all signals cumulatively
3277 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3279 while (*argv != NULL)
3281 wordlen = strlen (*argv);
3282 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3286 sigfirst = siglast = -1;
3288 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3290 /* Apply action to all signals except those used by the
3291 debugger. Silently skip those. */
3294 siglast = nsigs - 1;
3296 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3298 SET_SIGS (nsigs, sigs, signal_stop);
3299 SET_SIGS (nsigs, sigs, signal_print);
3301 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3303 UNSET_SIGS (nsigs, sigs, signal_program);
3305 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3307 SET_SIGS (nsigs, sigs, signal_print);
3309 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3311 SET_SIGS (nsigs, sigs, signal_program);
3313 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3315 UNSET_SIGS (nsigs, sigs, signal_stop);
3317 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3319 SET_SIGS (nsigs, sigs, signal_program);
3321 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3323 UNSET_SIGS (nsigs, sigs, signal_print);
3324 UNSET_SIGS (nsigs, sigs, signal_stop);
3326 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3328 UNSET_SIGS (nsigs, sigs, signal_program);
3330 else if (digits > 0)
3332 /* It is numeric. The numeric signal refers to our own
3333 internal signal numbering from target.h, not to host/target
3334 signal number. This is a feature; users really should be
3335 using symbolic names anyway, and the common ones like
3336 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3338 sigfirst = siglast = (int)
3339 target_signal_from_command (atoi (*argv));
3340 if ((*argv)[digits] == '-')
3343 target_signal_from_command (atoi ((*argv) + digits + 1));
3345 if (sigfirst > siglast)
3347 /* Bet he didn't figure we'd think of this case... */
3355 oursig = target_signal_from_name (*argv);
3356 if (oursig != TARGET_SIGNAL_UNKNOWN)
3358 sigfirst = siglast = (int) oursig;
3362 /* Not a number and not a recognized flag word => complain. */
3363 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3367 /* If any signal numbers or symbol names were found, set flags for
3368 which signals to apply actions to. */
3370 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3372 switch ((enum target_signal) signum)
3374 case TARGET_SIGNAL_TRAP:
3375 case TARGET_SIGNAL_INT:
3376 if (!allsigs && !sigs[signum])
3378 if (query ("%s is used by the debugger.\n\
3379 Are you sure you want to change it? ",
3380 target_signal_to_name
3381 ((enum target_signal) signum)))
3387 printf_unfiltered ("Not confirmed, unchanged.\n");
3388 gdb_flush (gdb_stdout);
3392 case TARGET_SIGNAL_0:
3393 case TARGET_SIGNAL_DEFAULT:
3394 case TARGET_SIGNAL_UNKNOWN:
3395 /* Make sure that "all" doesn't print these. */
3406 target_notice_signals (inferior_pid);
3410 /* Show the results. */
3411 sig_print_header ();
3412 for (signum = 0; signum < nsigs; signum++)
3416 sig_print_info (signum);
3421 do_cleanups (old_chain);
3425 xdb_handle_command (args, from_tty)
3430 struct cleanup *old_chain;
3432 /* Break the command line up into args. */
3434 argv = buildargv (args);
3439 old_chain = make_cleanup_freeargv (argv);
3440 if (argv[1] != (char *) NULL)
3445 bufLen = strlen (argv[0]) + 20;
3446 argBuf = (char *) xmalloc (bufLen);
3450 enum target_signal oursig;
3452 oursig = target_signal_from_name (argv[0]);
3453 memset (argBuf, 0, bufLen);
3454 if (strcmp (argv[1], "Q") == 0)
3455 sprintf (argBuf, "%s %s", argv[0], "noprint");
3458 if (strcmp (argv[1], "s") == 0)
3460 if (!signal_stop[oursig])
3461 sprintf (argBuf, "%s %s", argv[0], "stop");
3463 sprintf (argBuf, "%s %s", argv[0], "nostop");
3465 else if (strcmp (argv[1], "i") == 0)
3467 if (!signal_program[oursig])
3468 sprintf (argBuf, "%s %s", argv[0], "pass");
3470 sprintf (argBuf, "%s %s", argv[0], "nopass");
3472 else if (strcmp (argv[1], "r") == 0)
3474 if (!signal_print[oursig])
3475 sprintf (argBuf, "%s %s", argv[0], "print");
3477 sprintf (argBuf, "%s %s", argv[0], "noprint");
3483 handle_command (argBuf, from_tty);
3485 printf_filtered ("Invalid signal handling flag.\n");
3490 do_cleanups (old_chain);
3493 /* Print current contents of the tables set by the handle command.
3494 It is possible we should just be printing signals actually used
3495 by the current target (but for things to work right when switching
3496 targets, all signals should be in the signal tables). */
3499 signals_info (signum_exp, from_tty)
3503 enum target_signal oursig;
3504 sig_print_header ();
3508 /* First see if this is a symbol name. */
3509 oursig = target_signal_from_name (signum_exp);
3510 if (oursig == TARGET_SIGNAL_UNKNOWN)
3512 /* No, try numeric. */
3514 target_signal_from_command (parse_and_eval_address (signum_exp));
3516 sig_print_info (oursig);
3520 printf_filtered ("\n");
3521 /* These ugly casts brought to you by the native VAX compiler. */
3522 for (oursig = TARGET_SIGNAL_FIRST;
3523 (int) oursig < (int) TARGET_SIGNAL_LAST;
3524 oursig = (enum target_signal) ((int) oursig + 1))
3528 if (oursig != TARGET_SIGNAL_UNKNOWN
3529 && oursig != TARGET_SIGNAL_DEFAULT
3530 && oursig != TARGET_SIGNAL_0)
3531 sig_print_info (oursig);
3534 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3537 struct inferior_status
3539 enum target_signal stop_signal;
3543 int stop_stack_dummy;
3544 int stopped_by_random_signal;
3546 CORE_ADDR step_range_start;
3547 CORE_ADDR step_range_end;
3548 CORE_ADDR step_frame_address;
3549 int step_over_calls;
3550 CORE_ADDR step_resume_break_address;
3551 int stop_after_trap;
3552 int stop_soon_quietly;
3553 CORE_ADDR selected_frame_address;
3554 char *stop_registers;
3556 /* These are here because if call_function_by_hand has written some
3557 registers and then decides to call error(), we better not have changed
3562 int breakpoint_proceeded;
3563 int restore_stack_info;
3564 int proceed_to_finish;
3568 static struct inferior_status *xmalloc_inferior_status PARAMS ((void));
3569 static struct inferior_status *
3570 xmalloc_inferior_status ()
3572 struct inferior_status *inf_status;
3573 inf_status = xmalloc (sizeof (struct inferior_status));
3574 inf_status->stop_registers = xmalloc (REGISTER_BYTES);
3575 inf_status->registers = xmalloc (REGISTER_BYTES);
3579 static void free_inferior_status PARAMS ((struct inferior_status *));
3581 free_inferior_status (inf_status)
3582 struct inferior_status *inf_status;
3584 free (inf_status->registers);
3585 free (inf_status->stop_registers);
3590 write_inferior_status_register (inf_status, regno, val)
3591 struct inferior_status *inf_status;
3595 int size = REGISTER_RAW_SIZE(regno);
3596 void *buf = alloca (size);
3597 store_signed_integer (buf, size, val);
3598 memcpy (&inf_status->registers[REGISTER_BYTE (regno)], buf, size);
3603 /* Save all of the information associated with the inferior<==>gdb
3604 connection. INF_STATUS is a pointer to a "struct inferior_status"
3605 (defined in inferior.h). */
3607 struct inferior_status *
3608 save_inferior_status (restore_stack_info)
3609 int restore_stack_info;
3611 struct inferior_status *inf_status = xmalloc_inferior_status ();
3613 inf_status->stop_signal = stop_signal;
3614 inf_status->stop_pc = stop_pc;
3615 inf_status->stop_step = stop_step;
3616 inf_status->stop_stack_dummy = stop_stack_dummy;
3617 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3618 inf_status->trap_expected = trap_expected;
3619 inf_status->step_range_start = step_range_start;
3620 inf_status->step_range_end = step_range_end;
3621 inf_status->step_frame_address = step_frame_address;
3622 inf_status->step_over_calls = step_over_calls;
3623 inf_status->stop_after_trap = stop_after_trap;
3624 inf_status->stop_soon_quietly = stop_soon_quietly;
3625 /* Save original bpstat chain here; replace it with copy of chain.
3626 If caller's caller is walking the chain, they'll be happier if we
3627 hand them back the original chain when restore_inferior_status is
3629 inf_status->stop_bpstat = stop_bpstat;
3630 stop_bpstat = bpstat_copy (stop_bpstat);
3631 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3632 inf_status->restore_stack_info = restore_stack_info;
3633 inf_status->proceed_to_finish = proceed_to_finish;
3635 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
3637 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3639 record_selected_frame (&(inf_status->selected_frame_address),
3640 &(inf_status->selected_level));
3644 struct restore_selected_frame_args
3646 CORE_ADDR frame_address;
3650 static int restore_selected_frame PARAMS ((PTR));
3653 restore_selected_frame (args)
3656 struct restore_selected_frame_args *fr =
3657 (struct restore_selected_frame_args *) args;
3658 struct frame_info *frame;
3659 int level = fr->level;
3661 frame = find_relative_frame (get_current_frame (), &level);
3663 /* If inf_status->selected_frame_address is NULL, there was no
3664 previously selected frame. */
3665 if (frame == NULL ||
3666 /* FRAME_FP (frame) != fr->frame_address || */
3667 /* elz: deleted this check as a quick fix to the problem that
3668 for function called by hand gdb creates no internal frame
3669 structure and the real stack and gdb's idea of stack are
3670 different if nested calls by hands are made.
3672 mvs: this worries me. */
3675 warning ("Unable to restore previously selected frame.\n");
3679 select_frame (frame, fr->level);
3685 restore_inferior_status (inf_status)
3686 struct inferior_status *inf_status;
3688 stop_signal = inf_status->stop_signal;
3689 stop_pc = inf_status->stop_pc;
3690 stop_step = inf_status->stop_step;
3691 stop_stack_dummy = inf_status->stop_stack_dummy;
3692 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3693 trap_expected = inf_status->trap_expected;
3694 step_range_start = inf_status->step_range_start;
3695 step_range_end = inf_status->step_range_end;
3696 step_frame_address = inf_status->step_frame_address;
3697 step_over_calls = inf_status->step_over_calls;
3698 stop_after_trap = inf_status->stop_after_trap;
3699 stop_soon_quietly = inf_status->stop_soon_quietly;
3700 bpstat_clear (&stop_bpstat);
3701 stop_bpstat = inf_status->stop_bpstat;
3702 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3703 proceed_to_finish = inf_status->proceed_to_finish;
3705 /* FIXME: Is the restore of stop_registers always needed */
3706 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
3708 /* The inferior can be gone if the user types "print exit(0)"
3709 (and perhaps other times). */
3710 if (target_has_execution)
3711 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3713 /* FIXME: If we are being called after stopping in a function which
3714 is called from gdb, we should not be trying to restore the
3715 selected frame; it just prints a spurious error message (The
3716 message is useful, however, in detecting bugs in gdb (like if gdb
3717 clobbers the stack)). In fact, should we be restoring the
3718 inferior status at all in that case? . */
3720 if (target_has_stack && inf_status->restore_stack_info)
3722 struct restore_selected_frame_args fr;
3723 fr.level = inf_status->selected_level;
3724 fr.frame_address = inf_status->selected_frame_address;
3725 /* The point of catch_errors is that if the stack is clobbered,
3726 walking the stack might encounter a garbage pointer and error()
3727 trying to dereference it. */
3728 if (catch_errors (restore_selected_frame, &fr,
3729 "Unable to restore previously selected frame:\n",
3730 RETURN_MASK_ERROR) == 0)
3731 /* Error in restoring the selected frame. Select the innermost
3735 select_frame (get_current_frame (), 0);
3739 free_inferior_status (inf_status);
3743 discard_inferior_status (inf_status)
3744 struct inferior_status *inf_status;
3746 /* See save_inferior_status for info on stop_bpstat. */
3747 bpstat_clear (&inf_status->stop_bpstat);
3748 free_inferior_status (inf_status);
3752 set_follow_fork_mode_command (arg, from_tty, c)
3755 struct cmd_list_element *c;
3757 if (!STREQ (arg, "parent") &&
3758 !STREQ (arg, "child") &&
3759 !STREQ (arg, "both") &&
3760 !STREQ (arg, "ask"))
3761 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
3763 if (follow_fork_mode_string != NULL)
3764 free (follow_fork_mode_string);
3765 follow_fork_mode_string = savestring (arg, strlen (arg));
3770 static void build_infrun PARAMS ((void));
3774 stop_registers = xmalloc (REGISTER_BYTES);
3779 _initialize_infrun ()
3782 register int numsigs;
3783 struct cmd_list_element *c;
3787 add_info ("signals", signals_info,
3788 "What debugger does when program gets various signals.\n\
3789 Specify a signal as argument to print info on that signal only.");
3790 add_info_alias ("handle", "signals", 0);
3792 add_com ("handle", class_run, handle_command,
3793 concat ("Specify how to handle a signal.\n\
3794 Args are signals and actions to apply to those signals.\n\
3795 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3796 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3797 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3798 The special arg \"all\" is recognized to mean all signals except those\n\
3799 used by the debugger, typically SIGTRAP and SIGINT.\n",
3800 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3801 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3802 Stop means reenter debugger if this signal happens (implies print).\n\
3803 Print means print a message if this signal happens.\n\
3804 Pass means let program see this signal; otherwise program doesn't know.\n\
3805 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3806 Pass and Stop may be combined.", NULL));
3809 add_com ("lz", class_info, signals_info,
3810 "What debugger does when program gets various signals.\n\
3811 Specify a signal as argument to print info on that signal only.");
3812 add_com ("z", class_run, xdb_handle_command,
3813 concat ("Specify how to handle a signal.\n\
3814 Args are signals and actions to apply to those signals.\n\
3815 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3816 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3817 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3818 The special arg \"all\" is recognized to mean all signals except those\n\
3819 used by the debugger, typically SIGTRAP and SIGINT.\n",
3820 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3821 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3822 nopass), \"Q\" (noprint)\n\
3823 Stop means reenter debugger if this signal happens (implies print).\n\
3824 Print means print a message if this signal happens.\n\
3825 Pass means let program see this signal; otherwise program doesn't know.\n\
3826 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3827 Pass and Stop may be combined.", NULL));
3831 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
3832 "There is no `stop' command, but you can set a hook on `stop'.\n\
3833 This allows you to set a list of commands to be run each time execution\n\
3834 of the program stops.", &cmdlist);
3836 numsigs = (int) TARGET_SIGNAL_LAST;
3837 signal_stop = (unsigned char *)
3838 xmalloc (sizeof (signal_stop[0]) * numsigs);
3839 signal_print = (unsigned char *)
3840 xmalloc (sizeof (signal_print[0]) * numsigs);
3841 signal_program = (unsigned char *)
3842 xmalloc (sizeof (signal_program[0]) * numsigs);
3843 for (i = 0; i < numsigs; i++)
3846 signal_print[i] = 1;
3847 signal_program[i] = 1;
3850 /* Signals caused by debugger's own actions
3851 should not be given to the program afterwards. */
3852 signal_program[TARGET_SIGNAL_TRAP] = 0;
3853 signal_program[TARGET_SIGNAL_INT] = 0;
3855 /* Signals that are not errors should not normally enter the debugger. */
3856 signal_stop[TARGET_SIGNAL_ALRM] = 0;
3857 signal_print[TARGET_SIGNAL_ALRM] = 0;
3858 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
3859 signal_print[TARGET_SIGNAL_VTALRM] = 0;
3860 signal_stop[TARGET_SIGNAL_PROF] = 0;
3861 signal_print[TARGET_SIGNAL_PROF] = 0;
3862 signal_stop[TARGET_SIGNAL_CHLD] = 0;
3863 signal_print[TARGET_SIGNAL_CHLD] = 0;
3864 signal_stop[TARGET_SIGNAL_IO] = 0;
3865 signal_print[TARGET_SIGNAL_IO] = 0;
3866 signal_stop[TARGET_SIGNAL_POLL] = 0;
3867 signal_print[TARGET_SIGNAL_POLL] = 0;
3868 signal_stop[TARGET_SIGNAL_URG] = 0;
3869 signal_print[TARGET_SIGNAL_URG] = 0;
3870 signal_stop[TARGET_SIGNAL_WINCH] = 0;
3871 signal_print[TARGET_SIGNAL_WINCH] = 0;
3873 /* These signals are used internally by user-level thread
3874 implementations. (See signal(5) on Solaris.) Like the above
3875 signals, a healthy program receives and handles them as part of
3876 its normal operation. */
3877 signal_stop[TARGET_SIGNAL_LWP] = 0;
3878 signal_print[TARGET_SIGNAL_LWP] = 0;
3879 signal_stop[TARGET_SIGNAL_WAITING] = 0;
3880 signal_print[TARGET_SIGNAL_WAITING] = 0;
3881 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
3882 signal_print[TARGET_SIGNAL_CANCEL] = 0;
3886 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
3887 (char *) &stop_on_solib_events,
3888 "Set stopping for shared library events.\n\
3889 If nonzero, gdb will give control to the user when the dynamic linker\n\
3890 notifies gdb of shared library events. The most common event of interest\n\
3891 to the user would be loading/unloading of a new library.\n",
3896 c = add_set_enum_cmd ("follow-fork-mode",
3898 follow_fork_mode_kind_names,
3899 (char *) &follow_fork_mode_string,
3900 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
3901 kernel problem. It's also not terribly useful without a GUI to
3902 help the user drive two debuggers. So for now, I'm disabling
3903 the "both" option. */
3904 /* "Set debugger response to a program call of fork \
3906 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3907 parent - the original process is debugged after a fork\n\
3908 child - the new process is debugged after a fork\n\
3909 both - both the parent and child are debugged after a fork\n\
3910 ask - the debugger will ask for one of the above choices\n\
3911 For \"both\", another copy of the debugger will be started to follow\n\
3912 the new child process. The original debugger will continue to follow\n\
3913 the original parent process. To distinguish their prompts, the\n\
3914 debugger copy's prompt will be changed.\n\
3915 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3916 By default, the debugger will follow the parent process.",
3918 "Set debugger response to a program call of fork \
3920 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3921 parent - the original process is debugged after a fork\n\
3922 child - the new process is debugged after a fork\n\
3923 ask - the debugger will ask for one of the above choices\n\
3924 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3925 By default, the debugger will follow the parent process.",
3927 /* c->function.sfunc = ;*/
3928 add_show_from_set (c, &showlist);
3930 set_follow_fork_mode_command ("parent", 0, NULL);
3932 c = add_set_enum_cmd ("scheduler-locking", class_run,
3933 scheduler_enums, /* array of string names */
3934 (char *) &scheduler_mode, /* current mode */
3935 "Set mode for locking scheduler during execution.\n\
3936 off == no locking (threads may preempt at any time)\n\
3937 on == full locking (no thread except the current thread may run)\n\
3938 step == scheduler locked during every single-step operation.\n\
3939 In this mode, no other thread may run during a step command.\n\
3940 Other threads may run while stepping over a function call ('next').",
3943 c->function.sfunc = set_schedlock_func; /* traps on target vector */
3944 add_show_from_set (c, &showlist);