1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
27 #include "breakpoint.h"
32 #include "gdbthread.h"
34 #include "symfile.h" /* for overlay functions */
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 ((char *));
52 static void delete_breakpoint_current_contents PARAMS ((PTR));
54 int inferior_ignoring_startup_exec_events = 0;
55 int inferior_ignoring_leading_exec_events = 0;
58 /* wait_for_inferior and normal_stop use this to notify the user
59 when the inferior stopped in a different thread than it had been
61 static int switched_from_inferior_pid;
64 /* resume and wait_for_inferior use this to ensure that when
65 stepping over a hit breakpoint in a threaded application
66 only the thread that hit the breakpoint is stepped and the
67 other threads don't continue. This prevents having another
68 thread run past the breakpoint while it is temporarily
71 This is not thread-specific, so it isn't saved as part of
74 Versions of gdb which don't use the "step == this thread steps
75 and others continue" model but instead use the "step == this
76 thread steps and others wait" shouldn't do this. */
77 static int thread_step_needed = 0;
79 void _initialize_infrun PARAMS ((void));
81 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
82 program. It needs to examine the jmp_buf argument and extract the PC
83 from it. The return value is non-zero on success, zero otherwise. */
85 #ifndef GET_LONGJMP_TARGET
86 #define GET_LONGJMP_TARGET(PC_ADDR) 0
90 /* Some machines have trampoline code that sits between function callers
91 and the actual functions themselves. If this machine doesn't have
92 such things, disable their processing. */
94 #ifndef SKIP_TRAMPOLINE_CODE
95 #define SKIP_TRAMPOLINE_CODE(pc) 0
98 /* Dynamic function trampolines are similar to solib trampolines in that they
99 are between the caller and the callee. The difference is that when you
100 enter a dynamic trampoline, you can't determine the callee's address. Some
101 (usually complex) code needs to run in the dynamic trampoline to figure out
102 the callee's address. This macro is usually called twice. First, when we
103 enter the trampoline (looks like a normal function call at that point). It
104 should return the PC of a point within the trampoline where the callee's
105 address is known. Second, when we hit the breakpoint, this routine returns
106 the callee's address. At that point, things proceed as per a step resume
109 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
110 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
113 /* On SVR4 based systems, determining the callee's address is exceedingly
114 difficult and depends on the implementation of the run time loader.
115 If we are stepping at the source level, we single step until we exit
116 the run time loader code and reach the callee's address. */
118 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
119 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
122 /* For SVR4 shared libraries, each call goes through a small piece of
123 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
124 to nonzero if we are current stopped in one of these. */
126 #ifndef IN_SOLIB_CALL_TRAMPOLINE
127 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
130 /* In some shared library schemes, the return path from a shared library
131 call may need to go through a trampoline too. */
133 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
134 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
137 /* On MIPS16, a function that returns a floating point value may call
138 a library helper function to copy the return value to a floating point
139 register. The IGNORE_HELPER_CALL macro returns non-zero if we
140 should ignore (i.e. step over) this function call. */
141 #ifndef IGNORE_HELPER_CALL
142 #define IGNORE_HELPER_CALL(pc) 0
145 /* On some systems, the PC may be left pointing at an instruction that won't
146 actually be executed. This is usually indicated by a bit in the PSW. If
147 we find ourselves in such a state, then we step the target beyond the
148 nullified instruction before returning control to the user so as to avoid
151 #ifndef INSTRUCTION_NULLIFIED
152 #define INSTRUCTION_NULLIFIED 0
155 /* Tables of how to react to signals; the user sets them. */
157 static unsigned char *signal_stop;
158 static unsigned char *signal_print;
159 static unsigned char *signal_program;
161 #define SET_SIGS(nsigs,sigs,flags) \
163 int signum = (nsigs); \
164 while (signum-- > 0) \
165 if ((sigs)[signum]) \
166 (flags)[signum] = 1; \
169 #define UNSET_SIGS(nsigs,sigs,flags) \
171 int signum = (nsigs); \
172 while (signum-- > 0) \
173 if ((sigs)[signum]) \
174 (flags)[signum] = 0; \
178 /* Command list pointer for the "stop" placeholder. */
180 static struct cmd_list_element *stop_command;
182 /* Nonzero if breakpoints are now inserted in the inferior. */
184 static int breakpoints_inserted;
186 /* Function inferior was in as of last step command. */
188 static struct symbol *step_start_function;
190 /* Nonzero if we are expecting a trace trap and should proceed from it. */
192 static int trap_expected;
195 /* Nonzero if we want to give control to the user when we're notified
196 of shared library events by the dynamic linker. */
197 static int stop_on_solib_events;
201 /* Nonzero if the next time we try to continue the inferior, it will
202 step one instruction and generate a spurious trace trap.
203 This is used to compensate for a bug in HP-UX. */
205 static int trap_expected_after_continue;
208 /* Nonzero means expecting a trace trap
209 and should stop the inferior and return silently when it happens. */
213 /* Nonzero means expecting a trap and caller will handle it themselves.
214 It is used after attach, due to attaching to a process;
215 when running in the shell before the child program has been exec'd;
216 and when running some kinds of remote stuff (FIXME?). */
218 int stop_soon_quietly;
220 /* Nonzero if proceed is being used for a "finish" command or a similar
221 situation when stop_registers should be saved. */
223 int proceed_to_finish;
225 /* Save register contents here when about to pop a stack dummy frame,
226 if-and-only-if proceed_to_finish is set.
227 Thus this contains the return value from the called function (assuming
228 values are returned in a register). */
230 char stop_registers[REGISTER_BYTES];
232 /* Nonzero if program stopped due to error trying to insert breakpoints. */
234 static int breakpoints_failed;
236 /* Nonzero after stop if current stack frame should be printed. */
238 static int stop_print_frame;
240 static struct breakpoint *step_resume_breakpoint = NULL;
241 static struct breakpoint *through_sigtramp_breakpoint = NULL;
243 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
244 interactions with an inferior that is running a kernel function
245 (aka, a system call or "syscall"). wait_for_inferior therefore
246 may have a need to know when the inferior is in a syscall. This
247 is a count of the number of inferior threads which are known to
248 currently be running in a syscall. */
249 static int number_of_threads_in_syscalls;
251 /* This is used to remember when a fork, vfork or exec event
252 was caught by a catchpoint, and thus the event is to be
253 followed at the next resume of the inferior, and not
256 enum target_waitkind kind;
264 char * execd_pathname;
267 /* Some platforms don't allow us to do anything meaningful with a
268 vforked child until it has exec'd. Vforked processes on such
269 platforms can only be followed after they've exec'd.
271 When this is set to 0, a vfork can be immediately followed,
272 and an exec can be followed merely as an exec. When this is
273 set to 1, a vfork event has been seen, but cannot be followed
274 until the exec is seen.
276 (In the latter case, inferior_pid is still the parent of the
277 vfork, and pending_follow.fork_event.child_pid is the child. The
278 appropriate process is followed, according to the setting of
279 follow-fork-mode.) */
280 static int follow_vfork_when_exec;
282 static char * follow_fork_mode_kind_names [] = {
283 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
284 kernel problem. It's also not terribly useful without a GUI to
285 help the user drive two debuggers. So for now, I'm disabling
287 "parent", "child", "both", "ask" };
289 "parent", "child", "ask" };
291 static char * follow_fork_mode_string = NULL;
294 #if defined(HPUXHPPA)
296 follow_inferior_fork (parent_pid, child_pid, has_forked, has_vforked)
302 int followed_parent = 0;
303 int followed_child = 0;
306 /* Which process did the user want us to follow? */
308 savestring (follow_fork_mode_string, strlen (follow_fork_mode_string));
310 /* Or, did the user not know, and want us to ask? */
311 if (STREQ (follow_fork_mode_string, "ask"))
313 char requested_mode[100];
316 error ("\"ask\" mode NYI");
317 follow_mode = savestring (requested_mode, strlen (requested_mode));
320 /* If we're to be following the parent, then detach from child_pid.
321 We're already following the parent, so need do nothing explicit
323 if (STREQ (follow_mode, "parent"))
327 /* We're already attached to the parent, by default. */
329 /* Before detaching from the child, remove all breakpoints from
330 it. (This won't actually modify the breakpoint list, but will
331 physically remove the breakpoints from the child.) */
332 if (! has_vforked || ! follow_vfork_when_exec)
334 detach_breakpoints (child_pid);
335 SOLIB_REMOVE_INFERIOR_HOOK (child_pid);
338 /* Detach from the child. */
341 target_require_detach (child_pid, "", 1);
344 /* If we're to be following the child, then attach to it, detach
345 from inferior_pid, and set inferior_pid to child_pid. */
346 else if (STREQ (follow_mode, "child"))
348 char child_pid_spelling [100]; /* Arbitrary length. */
352 /* Before detaching from the parent, detach all breakpoints from
353 the child. But only if we're forking, or if we follow vforks
354 as soon as they happen. (If we're following vforks only when
355 the child has exec'd, then it's very wrong to try to write
356 back the "shadow contents" of inserted breakpoints now -- they
357 belong to the child's pre-exec'd a.out.) */
358 if (! has_vforked || ! follow_vfork_when_exec)
360 detach_breakpoints (child_pid);
363 /* Before detaching from the parent, remove all breakpoints from it. */
364 remove_breakpoints ();
366 /* Also reset the solib inferior hook from the parent. */
367 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid);
369 /* Detach from the parent. */
371 target_detach (NULL, 1);
373 /* Attach to the child. */
374 inferior_pid = child_pid;
375 sprintf (child_pid_spelling, "%d", child_pid);
378 target_require_attach (child_pid_spelling, 1);
380 /* Was there a step_resume breakpoint? (There was if the user
381 did a "next" at the fork() call.) If so, explicitly reset its
384 step_resumes are a form of bp that are made to be per-thread.
385 Since we created the step_resume bp when the parent process
386 was being debugged, and now are switching to the child process,
387 from the breakpoint package's viewpoint, that's a switch of
388 "threads". We must update the bp's notion of which thread
389 it is for, or it'll be ignored when it triggers... */
390 if (step_resume_breakpoint &&
391 (! has_vforked || ! follow_vfork_when_exec))
392 breakpoint_re_set_thread (step_resume_breakpoint);
394 /* Reinsert all breakpoints in the child. (The user may've set
395 breakpoints after catching the fork, in which case those
396 actually didn't get set in the child, but only in the parent.) */
397 if (! has_vforked || ! follow_vfork_when_exec)
399 breakpoint_re_set ();
400 insert_breakpoints ();
404 /* If we're to be following both parent and child, then fork ourselves,
405 and attach the debugger clone to the child. */
406 else if (STREQ (follow_mode, "both"))
408 char pid_suffix [100]; /* Arbitrary length. */
410 /* Clone ourselves to follow the child. This is the end of our
411 involvement with child_pid; our clone will take it from here... */
413 target_clone_and_follow_inferior (child_pid, &followed_child);
414 followed_parent = !followed_child;
416 /* We continue to follow the parent. To help distinguish the two
417 debuggers, though, both we and our clone will reset our prompts. */
418 sprintf (pid_suffix, "[%d] ", inferior_pid);
419 set_prompt (strcat (get_prompt (), pid_suffix));
422 /* The parent and child of a vfork share the same address space.
423 Also, on some targets the order in which vfork and exec events
424 are received for parent in child requires some delicate handling
427 For instance, on ptrace-based HPUX we receive the child's vfork
428 event first, at which time the parent has been suspended by the
429 OS and is essentially untouchable until the child's exit or second
430 exec event arrives. At that time, the parent's vfork event is
431 delivered to us, and that's when we see and decide how to follow
432 the vfork. But to get to that point, we must continue the child
433 until it execs or exits. To do that smoothly, all breakpoints
434 must be removed from the child, in case there are any set between
435 the vfork() and exec() calls. But removing them from the child
436 also removes them from the parent, due to the shared-address-space
437 nature of a vfork'd parent and child. On HPUX, therefore, we must
438 take care to restore the bp's to the parent before we continue it.
439 Else, it's likely that we may not stop in the expected place. (The
440 worst scenario is when the user tries to step over a vfork() call;
441 the step-resume bp must be restored for the step to properly stop
442 in the parent after the call completes!)
444 Sequence of events, as reported to gdb from HPUX:
446 Parent Child Action for gdb to take
447 -------------------------------------------------------
448 1 VFORK Continue child
454 target_post_follow_vfork (parent_pid,
460 pending_follow.fork_event.saw_parent_fork = 0;
461 pending_follow.fork_event.saw_child_fork = 0;
467 follow_fork (parent_pid, child_pid)
471 follow_inferior_fork (parent_pid, child_pid, 1, 0);
475 /* Forward declaration. */
476 static void follow_exec PARAMS((int, char *));
479 follow_vfork (parent_pid, child_pid)
483 follow_inferior_fork (parent_pid, child_pid, 0, 1);
485 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
486 if (pending_follow.fork_event.saw_child_exec && (inferior_pid == child_pid))
488 pending_follow.fork_event.saw_child_exec = 0;
489 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
490 follow_exec (inferior_pid, pending_follow.execd_pathname);
491 free (pending_follow.execd_pathname);
494 #endif /* HPUXHPPA */
497 follow_exec (pid, execd_pathname)
499 char * execd_pathname;
503 extern struct target_ops child_ops;
505 /* Did this exec() follow a vfork()? If so, we must follow the
506 vfork now too. Do it before following the exec. */
507 if (follow_vfork_when_exec &&
508 (pending_follow.kind == TARGET_WAITKIND_VFORKED))
510 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
511 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
512 follow_vfork_when_exec = 0;
513 saved_pid = inferior_pid;
515 /* Did we follow the parent? If so, we're done. If we followed
516 the child then we must also follow its exec(). */
517 if (inferior_pid == pending_follow.fork_event.parent_pid)
521 /* This is an exec event that we actually wish to pay attention to.
522 Refresh our symbol table to the newly exec'd program, remove any
525 If there are breakpoints, they aren't really inserted now,
526 since the exec() transformed our inferior into a fresh set
529 We want to preserve symbolic breakpoints on the list, since
530 we have hopes that they can be reset after the new a.out's
531 symbol table is read.
533 However, any "raw" breakpoints must be removed from the list
534 (e.g., the solib bp's), since their address is probably invalid
537 And, we DON'T want to call delete_breakpoints() here, since
538 that may write the bp's "shadow contents" (the instruction
539 value that was overwritten witha TRAP instruction). Since
540 we now have a new a.out, those shadow contents aren't valid. */
541 update_breakpoints_after_exec ();
543 /* If there was one, it's gone now. We cannot truly step-to-next
544 statement through an exec(). */
545 step_resume_breakpoint = NULL;
546 step_range_start = 0;
549 /* If there was one, it's gone now. */
550 through_sigtramp_breakpoint = NULL;
552 /* What is this a.out's name? */
553 printf_unfiltered ("Executing new program: %s\n", execd_pathname);
555 /* We've followed the inferior through an exec. Therefore, the
556 inferior has essentially been killed & reborn. */
557 gdb_flush (gdb_stdout);
558 target_mourn_inferior ();
559 inferior_pid = saved_pid; /* Because mourn_inferior resets inferior_pid. */
560 push_target (&child_ops);
562 /* That a.out is now the one to use. */
563 exec_file_attach (execd_pathname, 0);
565 /* And also is where symbols can be found. */
566 symbol_file_command (execd_pathname, 0);
568 /* Reset the shared library package. This ensures that we get
569 a shlib event when the child reaches "_start", at which point
570 the dld will have had a chance to initialize the child. */
572 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid);
574 /* Reinsert all breakpoints. (Those which were symbolic have
575 been reset to the proper address in the new a.out, thanks
576 to symbol_file_command...) */
577 insert_breakpoints ();
579 /* The next resume of this inferior should bring it to the shlib
580 startup breakpoints. (If the user had also set bp's on
581 "main" from the old (parent) process, then they'll auto-
582 matically get reset there in the new process.) */
586 /* Non-zero if we just simulating a single-step. This is needed
587 because we cannot remove the breakpoints in the inferior process
588 until after the `wait' in `wait_for_inferior'. */
589 static int singlestep_breakpoints_inserted_p = 0;
592 /* Things to clean up if we QUIT out of resume (). */
595 resume_cleanups (arg)
601 static char schedlock_off[] = "off";
602 static char schedlock_on[] = "on";
603 static char schedlock_step[] = "step";
604 static char *scheduler_mode = schedlock_off;
605 static char *scheduler_enums[] = {schedlock_off, schedlock_on, schedlock_step};
608 set_schedlock_func (args, from_tty, c)
611 struct cmd_list_element *c;
613 if (c->type == set_cmd)
614 if (!target_can_lock_scheduler)
616 scheduler_mode = schedlock_off;
617 error ("Target '%s' cannot support this command.",
623 /* Resume the inferior, but allow a QUIT. This is useful if the user
624 wants to interrupt some lengthy single-stepping operation
625 (for child processes, the SIGINT goes to the inferior, and so
626 we get a SIGINT random_signal, but for remote debugging and perhaps
627 other targets, that's not true).
629 STEP nonzero if we should step (zero to continue instead).
630 SIG is the signal to give the inferior (zero for none). */
634 enum target_signal sig;
636 int should_resume = 1;
637 struct cleanup *old_cleanups = make_cleanup ((make_cleanup_func)
641 #ifdef CANNOT_STEP_BREAKPOINT
642 /* Most targets can step a breakpoint instruction, thus executing it
643 normally. But if this one cannot, just continue and we will hit
645 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
649 if (SOFTWARE_SINGLE_STEP_P && step)
651 /* Do it the hard way, w/temp breakpoints */
652 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints*/);
653 /* ...and don't ask hardware to do it. */
655 /* and do not pull these breakpoints until after a `wait' in
656 `wait_for_inferior' */
657 singlestep_breakpoints_inserted_p = 1;
660 /* Handle any optimized stores to the inferior NOW... */
661 #ifdef DO_DEFERRED_STORES
666 /* If there were any forks/vforks/execs that were caught and are
667 now to be followed, then do so. */
668 switch (pending_follow.kind)
670 case (TARGET_WAITKIND_FORKED):
671 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
672 follow_fork (inferior_pid, pending_follow.fork_event.child_pid);
675 case (TARGET_WAITKIND_VFORKED):
677 int saw_child_exec = pending_follow.fork_event.saw_child_exec;
679 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
680 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
682 /* Did we follow the child, but not yet see the child's exec event?
683 If so, then it actually ought to be waiting for us; we respond to
684 parent vfork events. We don't actually want to resume the child
685 in this situation; we want to just get its exec event. */
686 if (! saw_child_exec &&
687 (inferior_pid == pending_follow.fork_event.child_pid))
692 case (TARGET_WAITKIND_EXECD):
693 /* If we saw a vfork event but couldn't follow it until we saw
694 an exec, then now might be the time! */
695 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
696 /* follow_exec is called as soon as the exec event is seen. */
702 #endif /* HPUXHPPA */
704 /* Install inferior's terminal modes. */
705 target_terminal_inferior ();
710 if (thread_step_needed)
712 /* We stopped on a BPT instruction;
713 don't continue other threads and
714 just step this thread. */
715 thread_step_needed = 0;
717 if (!breakpoint_here_p(read_pc()))
719 /* Breakpoint deleted: ok to do regular resume
720 where all the threads either step or continue. */
721 target_resume (-1, step, sig);
727 warning ( "Internal error, changing continue to step." );
728 remove_breakpoints ();
729 breakpoints_inserted = 0;
734 target_resume (inferior_pid, step, sig);
738 #endif /* HPUXHPPA */
740 /* Vanilla resume. */
742 if ((scheduler_mode == schedlock_on) ||
743 (scheduler_mode == schedlock_step && step != 0))
744 target_resume (inferior_pid, step, sig);
746 target_resume (-1, step, sig);
750 discard_cleanups (old_cleanups);
754 /* Clear out all variables saying what to do when inferior is continued.
755 First do this, then set the ones you want, then call `proceed'. */
758 clear_proceed_status ()
761 step_range_start = 0;
763 step_frame_address = 0;
764 step_over_calls = -1;
766 stop_soon_quietly = 0;
767 proceed_to_finish = 0;
768 breakpoint_proceeded = 1; /* We're about to proceed... */
770 /* Discard any remaining commands or status from previous stop. */
771 bpstat_clear (&stop_bpstat);
774 /* Basic routine for continuing the program in various fashions.
776 ADDR is the address to resume at, or -1 for resume where stopped.
777 SIGGNAL is the signal to give it, or 0 for none,
778 or -1 for act according to how it stopped.
779 STEP is nonzero if should trap after one instruction.
780 -1 means return after that and print nothing.
781 You should probably set various step_... variables
782 before calling here, if you are stepping.
784 You should call clear_proceed_status before calling proceed. */
787 proceed (addr, siggnal, step)
789 enum target_signal siggnal;
795 step_start_function = find_pc_function (read_pc ());
799 if (addr == (CORE_ADDR)-1)
801 /* If there is a breakpoint at the address we will resume at,
802 step one instruction before inserting breakpoints
803 so that we do not stop right away (and report a second
804 hit at this breakpoint). */
806 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
809 #ifndef STEP_SKIPS_DELAY
810 #define STEP_SKIPS_DELAY(pc) (0)
811 #define STEP_SKIPS_DELAY_P (0)
813 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
814 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
815 is slow (it needs to read memory from the target). */
816 if (STEP_SKIPS_DELAY_P
817 && breakpoint_here_p (read_pc () + 4)
818 && STEP_SKIPS_DELAY (read_pc ()))
825 /* New address; we don't need to single-step a thread
826 over a breakpoint we just hit, 'cause we aren't
827 continuing from there.
829 It's not worth worrying about the case where a user
830 asks for a "jump" at the current PC--if they get the
831 hiccup of re-hiting a hit breakpoint, what else do
833 thread_step_needed = 0;
836 #ifdef PREPARE_TO_PROCEED
837 /* In a multi-threaded task we may select another thread
838 and then continue or step.
840 But if the old thread was stopped at a breakpoint, it
841 will immediately cause another breakpoint stop without
842 any execution (i.e. it will report a breakpoint hit
843 incorrectly). So we must step over it first.
845 PREPARE_TO_PROCEED checks the current thread against the thread
846 that reported the most recent event. If a step-over is required
847 it returns TRUE and sets the current thread to the old thread. */
848 if (PREPARE_TO_PROCEED() && breakpoint_here_p (read_pc()))
851 thread_step_needed = 1;
854 #endif /* PREPARE_TO_PROCEED */
857 if (trap_expected_after_continue)
859 /* If (step == 0), a trap will be automatically generated after
860 the first instruction is executed. Force step one
861 instruction to clear this condition. This should not occur
862 if step is nonzero, but it is harmless in that case. */
864 trap_expected_after_continue = 0;
866 #endif /* HP_OS_BUG */
869 /* We will get a trace trap after one instruction.
870 Continue it automatically and insert breakpoints then. */
874 int temp = insert_breakpoints ();
877 print_sys_errmsg ("ptrace", temp);
878 error ("Cannot insert breakpoints.\n\
879 The same program may be running in another process.");
882 breakpoints_inserted = 1;
885 if (siggnal != TARGET_SIGNAL_DEFAULT)
886 stop_signal = siggnal;
887 /* If this signal should not be seen by program,
888 give it zero. Used for debugging signals. */
889 else if (!signal_program[stop_signal])
890 stop_signal = TARGET_SIGNAL_0;
892 annotate_starting ();
894 /* Make sure that output from GDB appears before output from the
896 gdb_flush (gdb_stdout);
898 /* Resume inferior. */
899 resume (oneproc || step || bpstat_should_step (), stop_signal);
901 /* Wait for it to stop (if not standalone)
902 and in any case decode why it stopped, and act accordingly. */
904 wait_for_inferior ();
908 /* Record the pc and sp of the program the last time it stopped.
909 These are just used internally by wait_for_inferior, but need
910 to be preserved over calls to it and cleared when the inferior
912 static CORE_ADDR prev_pc;
913 static CORE_ADDR prev_func_start;
914 static char *prev_func_name;
917 /* Start remote-debugging of a machine over a serial link. */
923 init_wait_for_inferior ();
924 stop_soon_quietly = 1;
926 wait_for_inferior ();
930 /* Initialize static vars when a new inferior begins. */
933 init_wait_for_inferior ()
935 /* These are meaningless until the first time through wait_for_inferior. */
938 prev_func_name = NULL;
941 trap_expected_after_continue = 0;
943 breakpoints_inserted = 0;
944 breakpoint_init_inferior (inf_starting);
946 /* Don't confuse first call to proceed(). */
947 stop_signal = TARGET_SIGNAL_0;
949 /* The first resume is not following a fork/vfork/exec. */
950 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
951 pending_follow.fork_event.saw_parent_fork = 0;
952 pending_follow.fork_event.saw_child_fork = 0;
953 pending_follow.fork_event.saw_child_exec = 0;
955 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
956 number_of_threads_in_syscalls = 0;
958 clear_proceed_status ();
962 delete_breakpoint_current_contents (arg)
965 struct breakpoint **breakpointp = (struct breakpoint **)arg;
966 if (*breakpointp != NULL)
968 delete_breakpoint (*breakpointp);
973 /* Wait for control to return from inferior to debugger.
974 If inferior gets a signal, we may decide to start it up again
975 instead of returning. That is why there is a loop in this function.
976 When this function actually returns it means the inferior
977 should be left stopped and GDB should read more commands. */
982 struct cleanup *old_cleanups;
983 struct target_waitstatus w;
985 int random_signal = 0;
986 CORE_ADDR stop_func_start;
987 CORE_ADDR stop_func_end;
988 char *stop_func_name;
990 CORE_ADDR prologue_pc = 0;
993 struct symtab_and_line sal;
994 int remove_breakpoints_on_following_step = 0;
996 struct symtab *current_symtab;
997 int handling_longjmp = 0; /* FIXME */
999 int saved_inferior_pid;
1000 int update_step_sp = 0;
1001 int stepping_through_solib_after_catch = 0;
1002 bpstat stepping_through_solib_catchpoints = NULL;
1003 int enable_hw_watchpoints_after_wait = 0;
1004 int stepping_through_sigtramp = 0;
1005 int new_thread_event;
1007 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
1008 int stepped_after_stopped_by_watchpoint;
1011 old_cleanups = make_cleanup (delete_breakpoint_current_contents,
1012 &step_resume_breakpoint);
1013 make_cleanup (delete_breakpoint_current_contents,
1014 &through_sigtramp_breakpoint);
1015 sal = find_pc_line(prev_pc, 0);
1016 current_line = sal.line;
1017 current_symtab = sal.symtab;
1019 /* Are we stepping? */
1020 #define CURRENTLY_STEPPING() \
1021 ((through_sigtramp_breakpoint == NULL \
1022 && !handling_longjmp \
1023 && ((step_range_end && step_resume_breakpoint == NULL) \
1024 || trap_expected)) \
1025 || stepping_through_solib_after_catch \
1026 || bpstat_should_step ())
1028 thread_step_needed = 0;
1031 /* We'll update this if & when we switch to a new thread. */
1032 switched_from_inferior_pid = inferior_pid;
1037 extern int overlay_cache_invalid; /* declared in symfile.h */
1039 overlay_cache_invalid = 1;
1041 /* We have to invalidate the registers BEFORE calling target_wait because
1042 they can be loaded from the target while in target_wait. This makes
1043 remote debugging a bit more efficient for those targets that provide
1044 critical registers as part of their normal status mechanism. */
1046 registers_changed ();
1048 if (target_wait_hook)
1049 pid = target_wait_hook (-1, &w);
1051 pid = target_wait (-1, &w);
1053 /* Since we've done a wait, we have a new event. Don't carry
1054 over any expectations about needing to step over a
1056 thread_step_needed = 0;
1058 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event is
1059 serviced in this loop, below. */
1060 if (enable_hw_watchpoints_after_wait)
1062 TARGET_ENABLE_HW_WATCHPOINTS(inferior_pid);
1063 enable_hw_watchpoints_after_wait = 0;
1067 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
1068 stepped_after_stopped_by_watchpoint = 0;
1073 We goto this label from elsewhere in wait_for_inferior when we want
1074 to continue the main loop without calling "wait" and trashing the
1075 waitstatus contained in W. */
1078 flush_cached_frames ();
1080 /* If it's a new process, add it to the thread database */
1082 new_thread_event = ((pid != inferior_pid) && !in_thread_list (pid));
1084 if (w.kind != TARGET_WAITKIND_EXITED
1085 && w.kind != TARGET_WAITKIND_SIGNALLED
1086 && new_thread_event)
1092 fprintf_unfiltered (gdb_stderr, "[New %s]\n",
1093 target_pid_or_tid_to_str (pid));
1096 printf_filtered ("[New %s]\n", target_pid_to_str (pid));
1100 /* NOTE: This block is ONLY meant to be invoked in case of a
1101 "thread creation event"! If it is invoked for any other
1102 sort of event (such as a new thread landing on a breakpoint),
1103 the event will be discarded, which is almost certainly
1106 To avoid this, the low-level module (eg. target_wait)
1107 should call in_thread_list and add_thread, so that the
1108 new thread is known by the time we get here. */
1110 /* We may want to consider not doing a resume here in order
1111 to give the user a chance to play with the new thread.
1112 It might be good to make that a user-settable option. */
1114 /* At this point, all threads are stopped (happens
1115 automatically in either the OS or the native code).
1116 Therefore we need to continue all threads in order to
1119 target_resume (-1, 0, TARGET_SIGNAL_0);
1126 case TARGET_WAITKIND_LOADED:
1127 /* Ignore gracefully during startup of the inferior, as it
1128 might be the shell which has just loaded some objects,
1129 otherwise add the symbols for the newly loaded objects. */
1131 if (!stop_soon_quietly)
1133 extern int auto_solib_add;
1135 /* Remove breakpoints, SOLIB_ADD might adjust
1136 breakpoint addresses via breakpoint_re_set. */
1137 if (breakpoints_inserted)
1138 remove_breakpoints ();
1140 /* Check for any newly added shared libraries if we're
1141 supposed to be adding them automatically. */
1144 /* Switch terminal for any messages produced by
1145 breakpoint_re_set. */
1146 target_terminal_ours_for_output ();
1147 SOLIB_ADD (NULL, 0, NULL);
1148 target_terminal_inferior ();
1151 /* Reinsert breakpoints and continue. */
1152 if (breakpoints_inserted)
1153 insert_breakpoints ();
1156 resume (0, TARGET_SIGNAL_0);
1159 case TARGET_WAITKIND_SPURIOUS:
1160 resume (0, TARGET_SIGNAL_0);
1163 case TARGET_WAITKIND_EXITED:
1164 target_terminal_ours (); /* Must do this before mourn anyway */
1165 annotate_exited (w.value.integer);
1166 if (w.value.integer)
1167 printf_filtered ("\nProgram exited with code 0%o.\n",
1168 (unsigned int)w.value.integer);
1170 printf_filtered ("\nProgram exited normally.\n");
1172 /* Record the exit code in the convenience variable $_exitcode, so
1173 that the user can inspect this again later. */
1174 set_internalvar (lookup_internalvar ("_exitcode"),
1175 value_from_longest (builtin_type_int,
1176 (LONGEST) w.value.integer));
1177 gdb_flush (gdb_stdout);
1178 target_mourn_inferior ();
1179 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P*/
1180 stop_print_frame = 0;
1183 case TARGET_WAITKIND_SIGNALLED:
1184 stop_print_frame = 0;
1185 stop_signal = w.value.sig;
1186 target_terminal_ours (); /* Must do this before mourn anyway */
1187 annotate_signalled ();
1189 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1190 mean it is already dead? This has been here since GDB 2.8, so
1191 perhaps it means rms didn't understand unix waitstatuses?
1192 For the moment I'm just kludging around this in remote.c
1193 rather than trying to change it here --kingdon, 5 Dec 1994. */
1194 target_kill (); /* kill mourns as well */
1196 printf_filtered ("\nProgram terminated with signal ");
1197 annotate_signal_name ();
1198 printf_filtered ("%s", target_signal_to_name (stop_signal));
1199 annotate_signal_name_end ();
1200 printf_filtered (", ");
1201 annotate_signal_string ();
1202 printf_filtered ("%s", target_signal_to_string (stop_signal));
1203 annotate_signal_string_end ();
1204 printf_filtered (".\n");
1206 printf_filtered ("The program no longer exists.\n");
1207 gdb_flush (gdb_stdout);
1208 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P*/
1211 /* The following are the only cases in which we keep going;
1212 the above cases end in a continue or goto. */
1213 case TARGET_WAITKIND_FORKED:
1214 stop_signal = TARGET_SIGNAL_TRAP;
1215 pending_follow.kind = w.kind;
1217 /* Ignore fork events reported for the parent; we're only
1218 interested in reacting to forks of the child. Note that
1219 we expect the child's fork event to be available if we
1220 waited for it now. */
1221 if (inferior_pid == pid)
1223 pending_follow.fork_event.saw_parent_fork = 1;
1224 pending_follow.fork_event.parent_pid = pid;
1225 pending_follow.fork_event.child_pid = w.value.related_pid;
1230 pending_follow.fork_event.saw_child_fork = 1;
1231 pending_follow.fork_event.child_pid = pid;
1232 pending_follow.fork_event.parent_pid = w.value.related_pid;
1235 stop_pc = read_pc_pid (pid);
1236 saved_inferior_pid = inferior_pid;
1238 stop_bpstat = bpstat_stop_status
1240 #if DECR_PC_AFTER_BREAK
1241 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1242 && CURRENTLY_STEPPING ())
1243 #else /* DECR_PC_AFTER_BREAK zero */
1245 #endif /* DECR_PC_AFTER_BREAK zero */
1247 random_signal = ! bpstat_explains_signal (stop_bpstat);
1248 inferior_pid = saved_inferior_pid;
1249 goto process_event_stop_test;
1251 /* If this a platform which doesn't allow a debugger to touch a
1252 vfork'd inferior until after it exec's, then we'd best keep
1253 our fingers entirely off the inferior, other than continuing
1254 it. This has the unfortunate side-effect that catchpoints
1255 of vforks will be ignored. But since the platform doesn't
1256 allow the inferior be touched at vfork time, there's really
1258 case TARGET_WAITKIND_VFORKED:
1259 stop_signal = TARGET_SIGNAL_TRAP;
1260 pending_follow.kind = w.kind;
1262 /* Is this a vfork of the parent? If so, then give any
1263 vfork catchpoints a chance to trigger now. (It's
1264 dangerous to do so if the child canot be touched until
1265 it execs, and the child has not yet exec'd. We probably
1266 should warn the user to that effect when the catchpoint
1268 if (pid == inferior_pid)
1270 pending_follow.fork_event.saw_parent_fork = 1;
1271 pending_follow.fork_event.parent_pid = pid;
1272 pending_follow.fork_event.child_pid = w.value.related_pid;
1275 /* If we've seen the child's vfork event but cannot really touch
1276 the child until it execs, then we must continue the child now.
1277 Else, give any vfork catchpoints a chance to trigger now. */
1280 pending_follow.fork_event.saw_child_fork = 1;
1281 pending_follow.fork_event.child_pid = pid;
1282 pending_follow.fork_event.parent_pid = w.value.related_pid;
1283 target_post_startup_inferior (pending_follow.fork_event.child_pid);
1284 follow_vfork_when_exec = ! target_can_follow_vfork_prior_to_exec ();
1285 if (follow_vfork_when_exec)
1287 target_resume (pid, 0, TARGET_SIGNAL_0);
1292 stop_pc = read_pc ();
1293 stop_bpstat = bpstat_stop_status
1295 #if DECR_PC_AFTER_BREAK
1296 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1297 && CURRENTLY_STEPPING ())
1298 #else /* DECR_PC_AFTER_BREAK zero */
1300 #endif /* DECR_PC_AFTER_BREAK zero */
1302 random_signal = ! bpstat_explains_signal (stop_bpstat);
1303 goto process_event_stop_test;
1305 case TARGET_WAITKIND_EXECD:
1306 stop_signal = TARGET_SIGNAL_TRAP;
1308 /* Is this a target which reports multiple exec events per actual
1309 call to exec()? (HP-UX using ptrace does, for example.) If so,
1310 ignore all but the last one. Just resume the exec'r, and wait
1311 for the next exec event. */
1312 if (inferior_ignoring_leading_exec_events)
1314 inferior_ignoring_leading_exec_events--;
1315 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1316 ENSURE_VFORKING_PARENT_REMAINS_STOPPED(pending_follow.fork_event.parent_pid);
1317 target_resume (pid, 0, TARGET_SIGNAL_0);
1320 inferior_ignoring_leading_exec_events =
1321 target_reported_exec_events_per_exec_call () - 1;
1323 pending_follow.execd_pathname = savestring (w.value.execd_pathname,
1324 strlen (w.value.execd_pathname));
1326 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1327 child of a vfork exec?
1329 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1330 HP-UX, events associated with a vforking inferior come in
1331 threes: a vfork event for the child (always first), followed
1332 a vfork event for the parent and an exec event for the child.
1333 The latter two can come in either order.
1335 If we get the parent vfork event first, life's good: We follow
1336 either the parent or child, and then the child's exec event is
1339 But if we get the child's exec event first, then we delay
1340 responding to it until we handle the parent's vfork. Because,
1341 otherwise we can't satisfy a "catch vfork". */
1342 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1344 pending_follow.fork_event.saw_child_exec = 1;
1346 /* On some targets, the child must be resumed before
1347 the parent vfork event is delivered. A single-step
1349 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK())
1350 target_resume (pid, 1, TARGET_SIGNAL_0);
1351 /* We expect the parent vfork event to be available now. */
1355 /* This causes the eventpoints and symbol table to be reset. Must
1356 do this now, before trying to determine whether to stop. */
1357 follow_exec (inferior_pid, pending_follow.execd_pathname);
1358 free (pending_follow.execd_pathname);
1360 stop_pc = read_pc_pid (pid);
1361 saved_inferior_pid = inferior_pid;
1363 stop_bpstat = bpstat_stop_status
1365 #if DECR_PC_AFTER_BREAK
1366 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1367 && CURRENTLY_STEPPING ())
1368 #else /* DECR_PC_AFTER_BREAK zero */
1370 #endif /* DECR_PC_AFTER_BREAK zero */
1372 random_signal = ! bpstat_explains_signal (stop_bpstat);
1373 inferior_pid = saved_inferior_pid;
1374 goto process_event_stop_test;
1376 /* These syscall events are returned on HP-UX, as part of its
1377 implementation of page-protection-based "hardware" watchpoints.
1378 HP-UX has unfortunate interactions between page-protections and
1379 some system calls. Our solution is to disable hardware watches
1380 when a system call is entered, and reenable them when the syscall
1381 completes. The downside of this is that we may miss the precise
1382 point at which a watched piece of memory is modified. "Oh well."
1384 Note that we may have multiple threads running, which may each
1385 enter syscalls at roughly the same time. Since we don't have a
1386 good notion currently of whether a watched piece of memory is
1387 thread-private, we'd best not have any page-protections active
1388 when any thread is in a syscall. Thus, we only want to reenable
1389 hardware watches when no threads are in a syscall.
1391 Also, be careful not to try to gather much state about a thread
1392 that's in a syscall. It's frequently a losing proposition. */
1393 case TARGET_WAITKIND_SYSCALL_ENTRY:
1394 number_of_threads_in_syscalls++;
1395 if (number_of_threads_in_syscalls == 1)
1397 TARGET_DISABLE_HW_WATCHPOINTS(inferior_pid);
1399 resume (0, TARGET_SIGNAL_0);
1402 /* Before examining the threads further, step this thread to
1403 get it entirely out of the syscall. (We get notice of the
1404 event when the thread is just on the verge of exiting a
1405 syscall. Stepping one instruction seems to get it back
1408 Note that although the logical place to reenable h/w watches
1409 is here, we cannot. We cannot reenable them before stepping
1410 the thread (this causes the next wait on the thread to hang).
1412 Nor can we enable them after stepping until we've done a wait.
1413 Thus, we simply set the flag enable_hw_watchpoints_after_wait
1414 here, which will be serviced immediately after the target
1416 case TARGET_WAITKIND_SYSCALL_RETURN:
1417 target_resume (pid, 1, TARGET_SIGNAL_0);
1419 if (number_of_threads_in_syscalls > 0)
1421 number_of_threads_in_syscalls--;
1422 enable_hw_watchpoints_after_wait =
1423 (number_of_threads_in_syscalls == 0);
1427 case TARGET_WAITKIND_STOPPED:
1428 stop_signal = w.value.sig;
1432 /* We may want to consider not doing a resume here in order to give
1433 the user a chance to play with the new thread. It might be good
1434 to make that a user-settable option. */
1436 /* At this point, all threads are stopped (happens automatically in
1437 either the OS or the native code). Therefore we need to continue
1438 all threads in order to make progress. */
1439 if (new_thread_event)
1441 target_resume (-1, 0, TARGET_SIGNAL_0);
1445 stop_pc = read_pc_pid (pid);
1447 /* See if a thread hit a thread-specific breakpoint that was meant for
1448 another thread. If so, then step that thread past the breakpoint,
1451 if (stop_signal == TARGET_SIGNAL_TRAP)
1453 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1456 if (breakpoints_inserted
1457 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
1460 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK,
1465 /* Saw a breakpoint, but it was hit by the wrong thread.
1467 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, pid);
1469 remove_status = remove_breakpoints ();
1470 /* Did we fail to remove breakpoints? If so, try
1471 to set the PC past the bp. (There's at least
1472 one situation in which we can fail to remove
1473 the bp's: On HP-UX's that use ttrace, we can't
1474 change the address space of a vforking child
1475 process until the child exits (well, okay, not
1476 then either :-) or execs. */
1477 if (remove_status != 0)
1479 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, pid);
1483 target_resume (pid, 1, TARGET_SIGNAL_0);
1484 /* FIXME: What if a signal arrives instead of the
1485 single-step happening? */
1487 if (target_wait_hook)
1488 target_wait_hook (pid, &w);
1490 target_wait (pid, &w);
1491 insert_breakpoints ();
1494 /* We need to restart all the threads now. */
1495 target_resume (-1, 0, TARGET_SIGNAL_0);
1500 /* This breakpoint matches--either it is the right
1501 thread or it's a generic breakpoint for all threads.
1502 Remember that we'll need to step just _this_ thread
1503 on any following user continuation! */
1504 thread_step_needed = 1;
1511 /* See if something interesting happened to the non-current thread. If
1512 so, then switch to that thread, and eventually give control back to
1515 Note that if there's any kind of pending follow (i.e., of a fork,
1516 vfork or exec), we don't want to do this now. Rather, we'll let
1517 the next resume handle it. */
1518 if ((pid != inferior_pid) &&
1519 (pending_follow.kind == TARGET_WAITKIND_SPURIOUS))
1523 /* If it's a random signal for a non-current thread, notify user
1524 if he's expressed an interest. */
1526 && signal_print[stop_signal])
1528 /* ??rehrauer: I don't understand the rationale for this code. If the
1529 inferior will stop as a result of this signal, then the act of handling
1530 the stop ought to print a message that's couches the stoppage in user
1531 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1532 won't stop as a result of the signal -- i.e., if the signal is merely
1533 a side-effect of something GDB's doing "under the covers" for the
1534 user, such as stepping threads over a breakpoint they shouldn't stop
1535 for -- then the message seems to be a serious annoyance at best.
1537 For now, remove the message altogether. */
1540 target_terminal_ours_for_output ();
1541 printf_filtered ("\nProgram received signal %s, %s.\n",
1542 target_signal_to_name (stop_signal),
1543 target_signal_to_string (stop_signal));
1544 gdb_flush (gdb_stdout);
1548 /* If it's not SIGTRAP and not a signal we want to stop for, then
1549 continue the thread. */
1551 if (stop_signal != TARGET_SIGNAL_TRAP
1552 && !signal_stop[stop_signal])
1555 target_terminal_inferior ();
1557 /* Clear the signal if it should not be passed. */
1558 if (signal_program[stop_signal] == 0)
1559 stop_signal = TARGET_SIGNAL_0;
1561 target_resume (pid, 0, stop_signal);
1565 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1566 and fall into the rest of wait_for_inferior(). */
1568 /* Save infrun state for the old thread. */
1569 save_infrun_state (inferior_pid, prev_pc,
1570 prev_func_start, prev_func_name,
1571 trap_expected, step_resume_breakpoint,
1572 through_sigtramp_breakpoint,
1573 step_range_start, step_range_end,
1574 step_frame_address, handling_longjmp,
1576 stepping_through_solib_after_catch,
1577 stepping_through_solib_catchpoints,
1578 stepping_through_sigtramp);
1581 switched_from_inferior_pid = inferior_pid;
1586 /* Load infrun state for the new thread. */
1587 load_infrun_state (inferior_pid, &prev_pc,
1588 &prev_func_start, &prev_func_name,
1589 &trap_expected, &step_resume_breakpoint,
1590 &through_sigtramp_breakpoint,
1591 &step_range_start, &step_range_end,
1592 &step_frame_address, &handling_longjmp,
1594 &stepping_through_solib_after_catch,
1595 &stepping_through_solib_catchpoints,
1596 &stepping_through_sigtramp);
1599 context_hook (pid_to_thread_id (pid));
1601 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid));
1602 flush_cached_frames ();
1605 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1607 /* Pull the single step breakpoints out of the target. */
1608 SOFTWARE_SINGLE_STEP (0, 0);
1609 singlestep_breakpoints_inserted_p = 0;
1612 /* If PC is pointing at a nullified instruction, then step beyond
1613 it so that the user won't be confused when GDB appears to be ready
1616 #if 0 /* XXX DEBUG */
1617 printf ("infrun.c:1607: pc = 0x%x\n", read_pc ());
1619 /* if (INSTRUCTION_NULLIFIED && CURRENTLY_STEPPING ()) */
1620 if (INSTRUCTION_NULLIFIED)
1622 struct target_waitstatus tmpstatus;
1624 all_registers_info ((char *)0, 0);
1626 registers_changed ();
1627 target_resume (pid, 1, TARGET_SIGNAL_0);
1629 /* We may have received a signal that we want to pass to
1630 the inferior; therefore, we must not clobber the waitstatus
1631 in W. So we call wait ourselves, then continue the loop
1632 at the "have_waited" label. */
1633 if (target_wait_hook)
1634 target_wait_hook (pid, &tmpstatus);
1636 target_wait (pid, &tmpstatus);
1641 #ifdef HAVE_STEPPABLE_WATCHPOINT
1642 /* It may not be necessary to disable the watchpoint to stop over
1643 it. For example, the PA can (with some kernel cooperation)
1644 single step over a watchpoint without disabling the watchpoint. */
1645 if (STOPPED_BY_WATCHPOINT (w))
1652 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
1653 /* It is far more common to need to disable a watchpoint
1654 to step the inferior over it. FIXME. What else might
1655 a debug register or page protection watchpoint scheme need
1657 if (STOPPED_BY_WATCHPOINT (w))
1659 /* At this point, we are stopped at an instruction which has attempted to write
1660 to a piece of memory under control of a watchpoint. The instruction hasn't
1661 actually executed yet. If we were to evaluate the watchpoint expression
1662 now, we would get the old value, and therefore no change would seem to have
1665 In order to make watchpoints work `right', we really need to complete the
1666 memory write, and then evaluate the watchpoint expression. The following
1667 code does that by removing the watchpoint (actually, all watchpoints and
1668 breakpoints), single-stepping the target, re-inserting watchpoints, and then
1669 falling through to let normal single-step processing handle proceed. Since
1670 this includes evaluating watchpoints, things will come to a stop in the
1673 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
1675 remove_breakpoints ();
1676 registers_changed();
1677 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
1679 if (target_wait_hook)
1680 target_wait_hook (pid, &w);
1682 target_wait (pid, &w);
1683 insert_breakpoints ();
1685 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1686 handle things like signals arriving and other things happening
1687 in combination correctly? */
1688 stepped_after_stopped_by_watchpoint = 1;
1693 #ifdef HAVE_CONTINUABLE_WATCHPOINT
1694 /* It may be possible to simply continue after a watchpoint. */
1695 STOPPED_BY_WATCHPOINT (w);
1698 stop_func_start = 0;
1701 /* Don't care about return value; stop_func_start and stop_func_name
1702 will both be 0 if it doesn't work. */
1703 find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start,
1705 stop_func_start += FUNCTION_START_OFFSET;
1707 bpstat_clear (&stop_bpstat);
1709 stop_stack_dummy = 0;
1710 stop_print_frame = 1;
1712 stopped_by_random_signal = 0;
1713 breakpoints_failed = 0;
1715 /* Look at the cause of the stop, and decide what to do.
1716 The alternatives are:
1717 1) break; to really stop and return to the debugger,
1718 2) drop through to start up again
1719 (set another_trap to 1 to single step once)
1720 3) set random_signal to 1, and the decision between 1 and 2
1721 will be made according to the signal handling tables. */
1723 /* First, distinguish signals caused by the debugger from signals
1724 that have to do with the program's own actions.
1725 Note that breakpoint insns may cause SIGTRAP or SIGILL
1726 or SIGEMT, depending on the operating system version.
1727 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1728 and change it to SIGTRAP. */
1730 if (stop_signal == TARGET_SIGNAL_TRAP
1731 || (breakpoints_inserted &&
1732 (stop_signal == TARGET_SIGNAL_ILL
1733 || stop_signal == TARGET_SIGNAL_EMT
1735 || stop_soon_quietly)
1737 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
1739 stop_print_frame = 0;
1742 if (stop_soon_quietly)
1745 /* Don't even think about breakpoints
1746 if just proceeded over a breakpoint.
1748 However, if we are trying to proceed over a breakpoint
1749 and end up in sigtramp, then through_sigtramp_breakpoint
1750 will be set and we should check whether we've hit the
1752 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
1753 && through_sigtramp_breakpoint == NULL)
1754 bpstat_clear (&stop_bpstat);
1757 /* See if there is a breakpoint at the current PC. */
1758 stop_bpstat = bpstat_stop_status
1760 (DECR_PC_AFTER_BREAK ?
1761 /* Notice the case of stepping through a jump
1762 that lands just after a breakpoint.
1763 Don't confuse that with hitting the breakpoint.
1764 What we check for is that 1) stepping is going on
1765 and 2) the pc before the last insn does not match
1766 the address of the breakpoint before the current pc
1767 and 3) we didn't hit a breakpoint in a signal handler
1768 without an intervening stop in sigtramp, which is
1769 detected by a new stack pointer value below
1770 any usual function calling stack adjustments. */
1771 (CURRENTLY_STEPPING ()
1772 && prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1774 && INNER_THAN (read_sp (), (step_sp - 16)))) :
1777 /* Following in case break condition called a
1779 stop_print_frame = 1;
1782 if (stop_signal == TARGET_SIGNAL_TRAP)
1784 = !(bpstat_explains_signal (stop_bpstat)
1786 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1787 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
1788 FRAME_FP (get_current_frame ()))
1789 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1790 || (step_range_end && step_resume_breakpoint == NULL));
1795 = !(bpstat_explains_signal (stop_bpstat)
1796 /* End of a stack dummy. Some systems (e.g. Sony
1797 news) give another signal besides SIGTRAP,
1798 so check here as well as above. */
1799 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1800 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
1801 FRAME_FP (get_current_frame ()))
1802 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1805 stop_signal = TARGET_SIGNAL_TRAP;
1809 /* When we reach this point, we've pretty much decided
1810 that the reason for stopping must've been a random
1811 (unexpected) signal. */
1815 /* If a fork, vfork or exec event was seen, then there are two
1816 possible responses we can make:
1818 1. If a catchpoint triggers for the event (random_signal == 0),
1819 then we must stop now and issue a prompt. We will resume
1820 the inferior when the user tells us to.
1821 2. If no catchpoint triggers for the event (random_signal == 1),
1822 then we must resume the inferior now and keep checking.
1824 In either case, we must take appropriate steps to "follow" the
1825 the fork/vfork/exec when the inferior is resumed. For example,
1826 if follow-fork-mode is "child", then we must detach from the
1827 parent inferior and follow the new child inferior.
1829 In either case, setting pending_follow causes the next resume()
1830 to take the appropriate following action. */
1831 process_event_stop_test:
1832 if (w.kind == TARGET_WAITKIND_FORKED)
1834 if (random_signal) /* I.e., no catchpoint triggered for this. */
1837 stop_signal = TARGET_SIGNAL_0;
1841 else if (w.kind == TARGET_WAITKIND_VFORKED)
1843 if (random_signal) /* I.e., no catchpoint triggered for this. */
1845 stop_signal = TARGET_SIGNAL_0;
1849 else if (w.kind == TARGET_WAITKIND_EXECD)
1851 pending_follow.kind = w.kind;
1852 if (random_signal) /* I.e., no catchpoint triggered for this. */
1855 stop_signal = TARGET_SIGNAL_0;
1860 /* For the program's own signals, act according to
1861 the signal handling tables. */
1865 /* Signal not for debugging purposes. */
1868 stopped_by_random_signal = 1;
1870 if (signal_print[stop_signal])
1873 target_terminal_ours_for_output ();
1875 printf_filtered ("\nProgram received signal ");
1876 annotate_signal_name ();
1877 printf_filtered ("%s", target_signal_to_name (stop_signal));
1878 annotate_signal_name_end ();
1879 printf_filtered (", ");
1880 annotate_signal_string ();
1881 printf_filtered ("%s", target_signal_to_string (stop_signal));
1882 annotate_signal_string_end ();
1883 printf_filtered (".\n");
1884 gdb_flush (gdb_stdout);
1886 if (signal_stop[stop_signal])
1888 /* If not going to stop, give terminal back
1889 if we took it away. */
1891 target_terminal_inferior ();
1893 /* Clear the signal if it should not be passed. */
1894 if (signal_program[stop_signal] == 0)
1895 stop_signal = TARGET_SIGNAL_0;
1897 /* If we're in the middle of a "next" command, let the code for
1898 stepping over a function handle this. pai/1997-09-10
1900 A previous comment here suggested it was possible to change
1901 this to jump to keep_going in all cases. */
1903 if (step_over_calls > 0)
1904 goto step_over_function;
1906 goto check_sigtramp2;
1909 /* Handle cases caused by hitting a breakpoint. */
1911 CORE_ADDR jmp_buf_pc;
1912 struct bpstat_what what;
1914 what = bpstat_what (stop_bpstat);
1916 if (what.call_dummy)
1918 stop_stack_dummy = 1;
1920 trap_expected_after_continue = 1;
1924 switch (what.main_action)
1926 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
1927 /* If we hit the breakpoint at longjmp, disable it for the
1928 duration of this command. Then, install a temporary
1929 breakpoint at the target of the jmp_buf. */
1930 disable_longjmp_breakpoint();
1931 remove_breakpoints ();
1932 breakpoints_inserted = 0;
1933 if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
1935 /* Need to blow away step-resume breakpoint, as it
1936 interferes with us */
1937 if (step_resume_breakpoint != NULL)
1939 delete_breakpoint (step_resume_breakpoint);
1940 step_resume_breakpoint = NULL;
1942 /* Not sure whether we need to blow this away too, but probably
1943 it is like the step-resume breakpoint. */
1944 if (through_sigtramp_breakpoint != NULL)
1946 delete_breakpoint (through_sigtramp_breakpoint);
1947 through_sigtramp_breakpoint = NULL;
1951 /* FIXME - Need to implement nested temporary breakpoints */
1952 if (step_over_calls > 0)
1953 set_longjmp_resume_breakpoint(jmp_buf_pc,
1954 get_current_frame());
1957 set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
1958 handling_longjmp = 1; /* FIXME */
1961 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
1962 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
1963 remove_breakpoints ();
1964 breakpoints_inserted = 0;
1966 /* FIXME - Need to implement nested temporary breakpoints */
1968 && (INNER_THAN (FRAME_FP (get_current_frame ()),
1969 step_frame_address)))
1975 disable_longjmp_breakpoint();
1976 handling_longjmp = 0; /* FIXME */
1977 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
1979 /* else fallthrough */
1981 case BPSTAT_WHAT_SINGLE:
1982 if (breakpoints_inserted)
1984 thread_step_needed = 1;
1985 remove_breakpoints ();
1987 breakpoints_inserted = 0;
1989 /* Still need to check other stuff, at least the case
1990 where we are stepping and step out of the right range. */
1993 case BPSTAT_WHAT_STOP_NOISY:
1994 stop_print_frame = 1;
1996 /* We are about to nuke the step_resume_breakpoint and
1997 through_sigtramp_breakpoint via the cleanup chain, so
1998 no need to worry about it here. */
2002 case BPSTAT_WHAT_STOP_SILENT:
2003 stop_print_frame = 0;
2005 /* We are about to nuke the step_resume_breakpoint and
2006 through_sigtramp_breakpoint via the cleanup chain, so
2007 no need to worry about it here. */
2011 case BPSTAT_WHAT_STEP_RESUME:
2012 /* This proably demands a more elegant solution, but, yeah
2015 This function's use of the simple variable
2016 step_resume_breakpoint doesn't seem to accomodate
2017 simultaneously active step-resume bp's, although the
2018 breakpoint list certainly can.
2020 If we reach here and step_resume_breakpoint is already
2021 NULL, then apparently we have multiple active
2022 step-resume bp's. We'll just delete the breakpoint we
2023 stopped at, and carry on. */
2024 if (step_resume_breakpoint == NULL)
2026 step_resume_breakpoint =
2027 bpstat_find_step_resume_breakpoint (stop_bpstat);
2029 delete_breakpoint (step_resume_breakpoint);
2030 step_resume_breakpoint = NULL;
2033 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2034 if (through_sigtramp_breakpoint)
2035 delete_breakpoint (through_sigtramp_breakpoint);
2036 through_sigtramp_breakpoint = NULL;
2038 /* If were waiting for a trap, hitting the step_resume_break
2039 doesn't count as getting it. */
2044 case BPSTAT_WHAT_CHECK_SHLIBS:
2045 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2048 extern int auto_solib_add;
2050 /* Remove breakpoints, we eventually want to step over the
2051 shlib event breakpoint, and SOLIB_ADD might adjust
2052 breakpoint addresses via breakpoint_re_set. */
2053 if (breakpoints_inserted)
2054 remove_breakpoints ();
2055 breakpoints_inserted = 0;
2057 /* Check for any newly added shared libraries if we're
2058 supposed to be adding them automatically. */
2061 /* Switch terminal for any messages produced by
2062 breakpoint_re_set. */
2063 target_terminal_ours_for_output ();
2064 SOLIB_ADD (NULL, 0, NULL);
2065 target_terminal_inferior ();
2068 /* Try to reenable shared library breakpoints, additional
2069 code segments in shared libraries might be mapped in now. */
2070 re_enable_breakpoints_in_shlibs ();
2072 /* If requested, stop when the dynamic linker notifies
2073 gdb of events. This allows the user to get control
2074 and place breakpoints in initializer routines for
2075 dynamically loaded objects (among other things). */
2076 if (stop_on_solib_events)
2078 stop_print_frame = 0;
2082 /* If we stopped due to an explicit catchpoint, then the
2083 (see above) call to SOLIB_ADD pulled in any symbols
2084 from a newly-loaded library, if appropriate.
2086 We do want the inferior to stop, but not where it is
2087 now, which is in the dynamic linker callback. Rather,
2088 we would like it stop in the user's program, just after
2089 the call that caused this catchpoint to trigger. That
2090 gives the user a more useful vantage from which to
2091 examine their program's state. */
2092 else if (what.main_action == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2094 /* ??rehrauer: If I could figure out how to get the
2095 right return PC from here, we could just set a temp
2096 breakpoint and resume. I'm not sure we can without
2097 cracking open the dld's shared libraries and sniffing
2098 their unwind tables and text/data ranges, and that's
2099 not a terribly portable notion.
2101 Until that time, we must step the inferior out of the
2102 dld callback, and also out of the dld itself (and any
2103 code or stubs in libdld.sl, such as "shl_load" and
2104 friends) until we reach non-dld code. At that point,
2105 we can stop stepping. */
2106 bpstat_get_triggered_catchpoints (stop_bpstat,
2107 &stepping_through_solib_catchpoints);
2108 stepping_through_solib_after_catch = 1;
2110 /* Be sure to lift all breakpoints, so the inferior does
2111 actually step past this point... */
2117 /* We want to step over this breakpoint, then keep going. */
2125 case BPSTAT_WHAT_LAST:
2126 /* Not a real code, but listed here to shut up gcc -Wall. */
2128 case BPSTAT_WHAT_KEEP_CHECKING:
2133 /* We come here if we hit a breakpoint but should not
2134 stop for it. Possibly we also were stepping
2135 and should stop for that. So fall through and
2136 test for stepping. But, if not stepping,
2139 /* Are we stepping to get the inferior out of the dynamic
2140 linker's hook (and possibly the dld itself) after catching
2142 if (stepping_through_solib_after_catch)
2144 #if defined(SOLIB_ADD)
2145 /* Have we reached our destination? If not, keep going. */
2146 if (SOLIB_IN_DYNAMIC_LINKER (pid, stop_pc))
2152 /* Else, stop and report the catchpoint(s) whose triggering
2153 caused us to begin stepping. */
2154 stepping_through_solib_after_catch = 0;
2155 bpstat_clear (&stop_bpstat);
2156 stop_bpstat = bpstat_copy (stepping_through_solib_catchpoints);
2157 bpstat_clear (&stepping_through_solib_catchpoints);
2158 stop_print_frame = 1;
2162 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
2163 /* This is the old way of detecting the end of the stack dummy.
2164 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2165 handled above. As soon as we can test it on all of them, all
2166 architectures should define it. */
2168 /* If this is the breakpoint at the end of a stack dummy,
2169 just stop silently, unless the user was doing an si/ni, in which
2170 case she'd better know what she's doing. */
2172 if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (),
2173 FRAME_FP (get_current_frame ()))
2176 stop_print_frame = 0;
2177 stop_stack_dummy = 1;
2179 trap_expected_after_continue = 1;
2183 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
2185 if (step_resume_breakpoint)
2186 /* Having a step-resume breakpoint overrides anything
2187 else having to do with stepping commands until
2188 that breakpoint is reached. */
2189 /* I'm not sure whether this needs to be check_sigtramp2 or
2190 whether it could/should be keep_going. */
2191 goto check_sigtramp2;
2193 if (step_range_end == 0)
2194 /* Likewise if we aren't even stepping. */
2195 /* I'm not sure whether this needs to be check_sigtramp2 or
2196 whether it could/should be keep_going. */
2197 goto check_sigtramp2;
2199 /* If stepping through a line, keep going if still within it.
2201 Note that step_range_end is the address of the first instruction
2202 beyond the step range, and NOT the address of the last instruction
2204 if (stop_pc >= step_range_start
2205 && stop_pc < step_range_end
2207 /* I haven't a clue what might trigger this clause, and it seems wrong
2208 anyway, so I've disabled it until someone complains. -Stu 10/24/95 */
2210 /* The step range might include the start of the
2211 function, so if we are at the start of the
2212 step range and either the stack or frame pointers
2213 just changed, we've stepped outside */
2214 && !(stop_pc == step_range_start
2215 && FRAME_FP (get_current_frame ())
2216 && (INNER_THAN (read_sp (), step_sp)
2217 || FRAME_FP (get_current_frame ()) != step_frame_address))
2221 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2222 So definately need to check for sigtramp here. */
2223 goto check_sigtramp2;
2226 /* We stepped out of the stepping range. */
2228 /* If we are stepping at the source level and entered the runtime
2229 loader dynamic symbol resolution code, we keep on single stepping
2230 until we exit the run time loader code and reach the callee's
2232 if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2235 /* We can't update step_sp every time through the loop, because
2236 reading the stack pointer would slow down stepping too much.
2237 But we can update it every time we leave the step range. */
2240 /* Did we just take a signal? */
2241 if (IN_SIGTRAMP (stop_pc, stop_func_name)
2242 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2243 && INNER_THAN (read_sp (), step_sp))
2245 /* We've just taken a signal; go until we are back to
2246 the point where we took it and one more. */
2248 /* Note: The test above succeeds not only when we stepped
2249 into a signal handler, but also when we step past the last
2250 statement of a signal handler and end up in the return stub
2251 of the signal handler trampoline. To distinguish between
2252 these two cases, check that the frame is INNER_THAN the
2253 previous one below. pai/1997-09-11 */
2257 CORE_ADDR current_frame = FRAME_FP (get_current_frame());
2259 if (INNER_THAN (current_frame, step_frame_address))
2261 /* We have just taken a signal; go until we are back to
2262 the point where we took it and one more. */
2264 /* This code is needed at least in the following case:
2265 The user types "next" and then a signal arrives (before
2266 the "next" is done). */
2268 /* Note that if we are stopped at a breakpoint, then we need
2269 the step_resume breakpoint to override any breakpoints at
2270 the same location, so that we will still step over the
2271 breakpoint even though the signal happened. */
2272 struct symtab_and_line sr_sal;
2275 sr_sal.symtab = NULL;
2277 sr_sal.pc = prev_pc;
2278 /* We could probably be setting the frame to
2279 step_frame_address; I don't think anyone thought to
2281 step_resume_breakpoint =
2282 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2283 if (breakpoints_inserted)
2284 insert_breakpoints ();
2288 /* We just stepped out of a signal handler and into
2289 its calling trampoline.
2291 Normally, we'd jump to step_over_function from
2292 here, but for some reason GDB can't unwind the
2293 stack correctly to find the real PC for the point
2294 user code where the signal trampoline will return
2295 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2296 But signal trampolines are pretty small stubs of
2297 code, anyway, so it's OK instead to just
2298 single-step out. Note: assuming such trampolines
2299 don't exhibit recursion on any platform... */
2300 find_pc_partial_function (stop_pc, &stop_func_name,
2303 /* Readjust stepping range */
2304 step_range_start = stop_func_start;
2305 step_range_end = stop_func_end;
2306 stepping_through_sigtramp = 1;
2311 /* If this is stepi or nexti, make sure that the stepping range
2312 gets us past that instruction. */
2313 if (step_range_end == 1)
2314 /* FIXME: Does this run afoul of the code below which, if
2315 we step into the middle of a line, resets the stepping
2317 step_range_end = (step_range_start = prev_pc) + 1;
2319 remove_breakpoints_on_following_step = 1;
2324 /* I disabled this test because it was too complicated and slow.
2325 The SKIP_PROLOGUE was especially slow, because it caused
2326 unnecessary prologue examination on various architectures.
2327 The code in the #else clause has been tested on the Sparc,
2328 Mips, PA, and Power architectures, so it's pretty likely to
2329 be correct. -Stu 10/24/95 */
2331 /* See if we left the step range due to a subroutine call that
2332 we should proceed to the end of. */
2334 if (stop_func_start)
2338 /* Do this after the IN_SIGTRAMP check; it might give
2340 prologue_pc = stop_func_start;
2342 /* Don't skip the prologue if this is assembly source */
2343 s = find_pc_symtab (stop_pc);
2344 if (s && s->language != language_asm)
2345 SKIP_PROLOGUE (prologue_pc);
2348 if (!(INNER_THAN (step_sp, read_sp ())) /* don't mistake (sig)return
2350 && (/* Might be a non-recursive call. If the symbols are missing
2351 enough that stop_func_start == prev_func_start even though
2352 they are really two functions, we will treat some calls as
2354 stop_func_start != prev_func_start
2356 /* Might be a recursive call if either we have a prologue
2357 or the call instruction itself saves the PC on the stack. */
2358 || prologue_pc != stop_func_start
2359 || read_sp () != step_sp)
2360 && (/* PC is completely out of bounds of any known objfiles. Treat
2361 like a subroutine call. */
2364 /* If we do a call, we will be at the start of a function... */
2365 || stop_pc == stop_func_start
2367 /* ...except on the Alpha with -O (and also Irix 5 and
2368 perhaps others), in which we might call the address
2369 after the load of gp. Since prologues don't contain
2370 calls, we can't return to within one, and we don't
2371 jump back into them, so this check is OK. */
2373 || stop_pc < prologue_pc
2375 /* ...and if it is a leaf function, the prologue might
2376 consist of gp loading only, so the call transfers to
2377 the first instruction after the prologue. */
2378 || (stop_pc == prologue_pc
2380 /* Distinguish this from the case where we jump back
2381 to the first instruction after the prologue,
2382 within a function. */
2383 && stop_func_start != prev_func_start)
2385 /* If we end up in certain places, it means we did a subroutine
2386 call. I'm not completely sure this is necessary now that we
2387 have the above checks with stop_func_start (and now that
2388 find_pc_partial_function is pickier). */
2389 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
2391 /* If none of the above apply, it is a jump within a function,
2392 or a return from a subroutine. The other case is longjmp,
2393 which can no longer happen here as long as the
2394 handling_longjmp stuff is working. */
2397 /* This test is a much more streamlined, (but hopefully correct)
2398 replacement for the code above. It's been tested on the Sparc,
2399 Mips, PA, and Power architectures with good results. */
2401 if (stop_pc == stop_func_start /* Quick test */
2402 || (in_prologue (stop_pc, stop_func_start) &&
2403 ! IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, stop_func_name))
2404 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
2405 || stop_func_name == 0)
2409 /* It's a subroutine call. */
2411 if (step_over_calls == 0)
2413 /* I presume that step_over_calls is only 0 when we're
2414 supposed to be stepping at the assembly language level
2415 ("stepi"). Just stop. */
2420 if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc))
2421 /* We're doing a "next". */
2422 goto step_over_function;
2424 /* If we are in a function call trampoline (a stub between
2425 the calling routine and the real function), locate the real
2426 function. That's what tells us (a) whether we want to step
2427 into it at all, and (b) what prologue we want to run to
2428 the end of, if we do step into it. */
2429 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2431 stop_func_start = tmp;
2434 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
2437 struct symtab_and_line xxx;
2438 /* Why isn't this s_a_l called "sr_sal", like all of the
2439 other s_a_l's where this code is duplicated? */
2440 INIT_SAL (&xxx); /* initialize to zeroes */
2442 xxx.section = find_pc_overlay (xxx.pc);
2443 step_resume_breakpoint =
2444 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
2445 insert_breakpoints ();
2450 /* If we have line number information for the function we
2451 are thinking of stepping into, step into it.
2453 If there are several symtabs at that PC (e.g. with include
2454 files), just want to know whether *any* of them have line
2455 numbers. find_pc_line handles this. */
2457 struct symtab_and_line tmp_sal;
2459 tmp_sal = find_pc_line (stop_func_start, 0);
2460 if (tmp_sal.line != 0)
2461 goto step_into_function;
2465 /* A subroutine call has happened. */
2467 /* Set a special breakpoint after the return */
2468 struct symtab_and_line sr_sal;
2471 sr_sal.symtab = NULL;
2474 /* If we came here after encountering a signal in the middle of
2475 a "next", use the stashed-away previous frame pc */
2477 = stopped_by_random_signal
2479 : ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2481 step_resume_breakpoint =
2482 set_momentary_breakpoint (sr_sal,
2483 stopped_by_random_signal ?
2484 NULL : get_current_frame (),
2487 /* We've just entered a callee, and we wish to resume until
2488 it returns to the caller. Setting a step_resume bp on
2489 the return PC will catch a return from the callee.
2491 However, if the callee is recursing, we want to be
2492 careful not to catch returns of those recursive calls,
2493 but of THIS instance of the call.
2495 To do this, we set the step_resume bp's frame to our
2496 current caller's frame (step_frame_address, which is
2497 set by the "next" or "until" command, before execution
2500 But ... don't do it if we're single-stepping out of a
2501 sigtramp, because the reason we're single-stepping is
2502 precisely because unwinding is a problem (HP-UX 10.20,
2503 e.g.) and the frame address is likely to be incorrect.
2504 No danger of sigtramp recursion. */
2506 if (stepping_through_sigtramp)
2508 step_resume_breakpoint->frame = (CORE_ADDR) NULL;
2509 stepping_through_sigtramp = 0;
2511 else if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
2512 step_resume_breakpoint->frame = step_frame_address;
2514 if (breakpoints_inserted)
2515 insert_breakpoints ();
2520 /* Subroutine call with source code we should not step over.
2521 Do step to the first line of code in it. */
2525 s = find_pc_symtab (stop_pc);
2526 if (s && s->language != language_asm)
2527 SKIP_PROLOGUE (stop_func_start);
2529 sal = find_pc_line (stop_func_start, 0);
2530 /* Use the step_resume_break to step until
2531 the end of the prologue, even if that involves jumps
2532 (as it seems to on the vax under 4.2). */
2533 /* If the prologue ends in the middle of a source line,
2534 continue to the end of that source line (if it is still
2535 within the function). Otherwise, just go to end of prologue. */
2536 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2537 /* no, don't either. It skips any code that's
2538 legitimately on the first line. */
2540 if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end)
2541 stop_func_start = sal.end;
2544 if (stop_func_start == stop_pc)
2546 /* We are already there: stop now. */
2551 /* Put the step-breakpoint there and go until there. */
2553 struct symtab_and_line sr_sal;
2555 INIT_SAL (&sr_sal); /* initialize to zeroes */
2556 sr_sal.pc = stop_func_start;
2557 sr_sal.section = find_pc_overlay (stop_func_start);
2558 /* Do not specify what the fp should be when we stop
2559 since on some machines the prologue
2560 is where the new fp value is established. */
2561 step_resume_breakpoint =
2562 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2563 if (breakpoints_inserted)
2564 insert_breakpoints ();
2566 /* And make sure stepping stops right away then. */
2567 step_range_end = step_range_start;
2572 /* We've wandered out of the step range. */
2574 sal = find_pc_line(stop_pc, 0);
2576 if (step_range_end == 1)
2578 /* It is stepi or nexti. We always want to stop stepping after
2584 /* If we're in the return path from a shared library trampoline,
2585 we want to proceed through the trampoline when stepping. */
2586 if (IN_SOLIB_RETURN_TRAMPOLINE(stop_pc, stop_func_name))
2590 /* Determine where this trampoline returns. */
2591 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2593 /* Only proceed through if we know where it's going. */
2596 /* And put the step-breakpoint there and go until there. */
2597 struct symtab_and_line sr_sal;
2599 INIT_SAL (&sr_sal); /* initialize to zeroes */
2601 sr_sal.section = find_pc_overlay (sr_sal.pc);
2602 /* Do not specify what the fp should be when we stop
2603 since on some machines the prologue
2604 is where the new fp value is established. */
2605 step_resume_breakpoint =
2606 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2607 if (breakpoints_inserted)
2608 insert_breakpoints ();
2610 /* Restart without fiddling with the step ranges or
2618 /* We have no line number information. That means to stop
2619 stepping (does this always happen right after one instruction,
2620 when we do "s" in a function with no line numbers,
2621 or can this happen as a result of a return or longjmp?). */
2626 if ((stop_pc == sal.pc)
2627 && (current_line != sal.line || current_symtab != sal.symtab))
2629 /* We are at the start of a different line. So stop. Note that
2630 we don't stop if we step into the middle of a different line.
2631 That is said to make things like for (;;) statements work
2637 /* We aren't done stepping.
2639 Optimize by setting the stepping range to the line.
2640 (We might not be in the original line, but if we entered a
2641 new line in mid-statement, we continue stepping. This makes
2642 things like for(;;) statements work better.) */
2644 if (stop_func_end && sal.end >= stop_func_end)
2646 /* If this is the last line of the function, don't keep stepping
2647 (it would probably step us out of the function).
2648 This is particularly necessary for a one-line function,
2649 in which after skipping the prologue we better stop even though
2650 we will be in mid-line. */
2654 step_range_start = sal.pc;
2655 step_range_end = sal.end;
2656 step_frame_address = FRAME_FP (get_current_frame ());
2657 current_line = sal.line;
2658 current_symtab = sal.symtab;
2660 /* In the case where we just stepped out of a function into the middle
2661 of a line of the caller, continue stepping, but step_frame_address
2662 must be modified to current frame */
2664 CORE_ADDR current_frame = FRAME_FP (get_current_frame());
2665 if (!(INNER_THAN (current_frame, step_frame_address)))
2666 step_frame_address = current_frame;
2674 && IN_SIGTRAMP (stop_pc, stop_func_name)
2675 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2676 && INNER_THAN (read_sp (), step_sp))
2678 /* What has happened here is that we have just stepped the inferior
2679 with a signal (because it is a signal which shouldn't make
2680 us stop), thus stepping into sigtramp.
2682 So we need to set a step_resume_break_address breakpoint
2683 and continue until we hit it, and then step. FIXME: This should
2684 be more enduring than a step_resume breakpoint; we should know
2685 that we will later need to keep going rather than re-hitting
2686 the breakpoint here (see testsuite/gdb.t06/signals.exp where
2687 it says "exceedingly difficult"). */
2688 struct symtab_and_line sr_sal;
2690 INIT_SAL (&sr_sal); /* initialize to zeroes */
2691 sr_sal.pc = prev_pc;
2692 sr_sal.section = find_pc_overlay (sr_sal.pc);
2693 /* We perhaps could set the frame if we kept track of what
2694 the frame corresponding to prev_pc was. But we don't,
2696 through_sigtramp_breakpoint =
2697 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
2698 if (breakpoints_inserted)
2699 insert_breakpoints ();
2701 remove_breakpoints_on_following_step = 1;
2706 /* Come to this label when you need to resume the inferior.
2707 It's really much cleaner to do a goto than a maze of if-else
2710 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug
2711 a vforked child beetween its creation and subsequent exit or
2712 call to exec(). However, I had big problems in this rather
2713 creaky exec engine, getting that to work. The fundamental
2714 problem is that I'm trying to debug two processes via an
2715 engine that only understands a single process with possibly
2718 Hence, this spot is known to have problems when
2719 target_can_follow_vfork_prior_to_exec returns 1. */
2721 /* Save the pc before execution, to compare with pc after stop. */
2722 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
2723 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
2724 BREAK is defined, the
2725 original pc would not have
2726 been at the start of a
2728 prev_func_name = stop_func_name;
2731 step_sp = read_sp ();
2734 /* If we did not do break;, it means we should keep
2735 running the inferior and not return to debugger. */
2737 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
2739 /* We took a signal (which we are supposed to pass through to
2740 the inferior, else we'd have done a break above) and we
2741 haven't yet gotten our trap. Simply continue. */
2742 resume (CURRENTLY_STEPPING (), stop_signal);
2746 /* Either the trap was not expected, but we are continuing
2747 anyway (the user asked that this signal be passed to the
2750 The signal was SIGTRAP, e.g. it was our signal, but we
2751 decided we should resume from it.
2753 We're going to run this baby now!
2755 Insert breakpoints now, unless we are trying
2756 to one-proceed past a breakpoint. */
2757 /* If we've just finished a special step resume and we don't
2758 want to hit a breakpoint, pull em out. */
2759 if (step_resume_breakpoint == NULL
2760 && through_sigtramp_breakpoint == NULL
2761 && remove_breakpoints_on_following_step)
2763 remove_breakpoints_on_following_step = 0;
2764 remove_breakpoints ();
2765 breakpoints_inserted = 0;
2767 else if (!breakpoints_inserted &&
2768 (through_sigtramp_breakpoint != NULL || !another_trap))
2770 breakpoints_failed = insert_breakpoints ();
2771 if (breakpoints_failed)
2773 breakpoints_inserted = 1;
2776 trap_expected = another_trap;
2778 if (stop_signal == TARGET_SIGNAL_TRAP)
2779 stop_signal = TARGET_SIGNAL_0;
2781 #ifdef SHIFT_INST_REGS
2782 /* I'm not sure when this following segment applies. I do know,
2783 now, that we shouldn't rewrite the regs when we were stopped
2784 by a random signal from the inferior process. */
2785 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2786 (this is only used on the 88k). */
2788 if (!bpstat_explains_signal (stop_bpstat)
2789 && (stop_signal != TARGET_SIGNAL_CHLD)
2790 && !stopped_by_random_signal)
2792 #endif /* SHIFT_INST_REGS */
2794 resume (CURRENTLY_STEPPING (), stop_signal);
2799 if (target_has_execution)
2801 /* Are we stopping for a vfork event? We only stop when we see
2802 the child's event. However, we may not yet have seen the
2803 parent's event. And, inferior_pid is still set to the parent's
2804 pid, until we resume again and follow either the parent or child.
2806 To ensure that we can really touch inferior_pid (aka, the
2807 parent process) -- which calls to functions like read_pc
2808 implicitly do -- wait on the parent if necessary. */
2809 if ((pending_follow.kind == TARGET_WAITKIND_VFORKED)
2810 && ! pending_follow.fork_event.saw_parent_fork)
2815 if (target_wait_hook)
2816 parent_pid = target_wait_hook (-1, &w);
2818 parent_pid = target_wait (-1, &w);
2819 } while (parent_pid != inferior_pid);
2823 /* Assuming the inferior still exists, set these up for next
2824 time, just like we did above if we didn't break out of the
2826 prev_pc = read_pc ();
2827 prev_func_start = stop_func_start;
2828 prev_func_name = stop_func_name;
2830 do_cleanups (old_cleanups);
2833 /* This function returns TRUE if ep is an internal breakpoint
2834 set to catch generic shared library (aka dynamically-linked
2835 library) events. (This is *NOT* the same as a catchpoint for a
2836 shlib event. The latter is something a user can set; this is
2837 something gdb sets for its own use, and isn't ever shown to a
2840 is_internal_shlib_eventpoint (ep)
2841 struct breakpoint * ep;
2844 (ep->type == bp_shlib_event)
2848 /* This function returns TRUE if bs indicates that the inferior
2849 stopped due to a shared library (aka dynamically-linked library)
2852 stopped_for_internal_shlib_event (bs)
2855 /* Note that multiple eventpoints may've caused the stop. Any
2856 that are associated with shlib events will be accepted. */
2857 for (;bs != NULL; bs = bs->next)
2859 if ((bs->breakpoint_at != NULL)
2860 && is_internal_shlib_eventpoint (bs->breakpoint_at))
2864 /* If we get here, then no candidate was found. */
2868 /* This function returns TRUE if bs indicates that the inferior
2869 stopped due to a shared library (aka dynamically-linked library)
2870 event caught by a catchpoint.
2872 If TRUE, cp_p is set to point to the catchpoint.
2874 Else, the value of cp_p is undefined. */
2876 stopped_for_shlib_catchpoint (bs, cp_p)
2878 struct breakpoint ** cp_p;
2880 /* Note that multiple eventpoints may've caused the stop. Any
2881 that are associated with shlib events will be accepted. */
2884 for (;bs != NULL; bs = bs->next)
2886 if ((bs->breakpoint_at != NULL)
2887 && ep_is_shlib_catchpoint (bs->breakpoint_at))
2889 *cp_p = bs->breakpoint_at;
2894 /* If we get here, then no candidate was found. */
2899 /* Here to return control to GDB when the inferior stops for real.
2900 Print appropriate messages, remove breakpoints, give terminal our modes.
2902 STOP_PRINT_FRAME nonzero means print the executing frame
2903 (pc, function, args, file, line number and line text).
2904 BREAKPOINTS_FAILED nonzero means stop was due to error
2905 attempting to insert breakpoints. */
2912 /* As with the notification of thread events, we want to delay
2913 notifying the user that we've switched thread context until
2914 the inferior actually stops.
2916 (Note that there's no point in saying anything if the inferior
2918 if ((switched_from_inferior_pid != inferior_pid) &&
2919 target_has_execution)
2921 target_terminal_ours_for_output ();
2922 printf_filtered ("[Switched to %s]\n",
2923 target_pid_or_tid_to_str (inferior_pid));
2924 switched_from_inferior_pid = inferior_pid;
2928 /* Make sure that the current_frame's pc is correct. This
2929 is a correction for setting up the frame info before doing
2930 DECR_PC_AFTER_BREAK */
2931 if (target_has_execution && get_current_frame())
2932 (get_current_frame ())->pc = read_pc ();
2934 if (breakpoints_failed)
2936 target_terminal_ours_for_output ();
2937 print_sys_errmsg ("ptrace", breakpoints_failed);
2938 printf_filtered ("Stopped; cannot insert breakpoints.\n\
2939 The same program may be running in another process.\n");
2942 if (target_has_execution && breakpoints_inserted)
2944 if (remove_breakpoints ())
2946 target_terminal_ours_for_output ();
2947 printf_filtered ("Cannot remove breakpoints because ");
2948 printf_filtered ("program is no longer writable.\n");
2949 printf_filtered ("It might be running in another process.\n");
2950 printf_filtered ("Further execution is probably impossible.\n");
2953 breakpoints_inserted = 0;
2955 /* Delete the breakpoint we stopped at, if it wants to be deleted.
2956 Delete any breakpoint that is to be deleted at the next stop. */
2958 breakpoint_auto_delete (stop_bpstat);
2960 /* If an auto-display called a function and that got a signal,
2961 delete that auto-display to avoid an infinite recursion. */
2963 if (stopped_by_random_signal)
2964 disable_current_display ();
2966 /* Don't print a message if in the middle of doing a "step n"
2967 operation for n > 1 */
2968 if (step_multi && stop_step)
2971 target_terminal_ours ();
2973 /* Did we stop because the user set the stop_on_solib_events
2974 variable? (If so, we report this as a generic, "Stopped due
2975 to shlib event" message.) */
2976 if (stopped_for_internal_shlib_event (stop_bpstat))
2978 printf_filtered ("Stopped due to shared library event\n");
2981 /* Look up the hook_stop and run it if it exists. */
2983 if (stop_command && stop_command->hook)
2985 catch_errors (hook_stop_stub, (char *)stop_command->hook,
2986 "Error while running hook_stop:\n", RETURN_MASK_ALL);
2989 if (!target_has_stack)
2995 /* Select innermost stack frame - i.e., current frame is frame 0,
2996 and current location is based on that.
2997 Don't do this on return from a stack dummy routine,
2998 or if the program has exited. */
3000 if (!stop_stack_dummy)
3002 select_frame (get_current_frame (), 0);
3004 /* Print current location without a level number, if
3005 we have changed functions or hit a breakpoint.
3006 Print source line if we have one.
3007 bpstat_print() contains the logic deciding in detail
3008 what to print, based on the event(s) that just occurred. */
3010 if (stop_print_frame)
3015 bpstat_ret = bpstat_print (stop_bpstat);
3016 /* bpstat_print() returned one of:
3017 -1: Didn't print anything
3018 0: Printed preliminary "Breakpoint n, " message, desires
3020 1: Printed something, don't tack on location */
3022 if (bpstat_ret == -1)
3024 && step_frame_address == FRAME_FP (get_current_frame ())
3025 && step_start_function == find_pc_function (stop_pc))
3026 source_flag = -1; /* finished step, just print source line */
3028 source_flag = 1; /* print location and source line */
3029 else if (bpstat_ret == 0) /* hit bpt, desire location */
3030 source_flag = 1; /* print location and source line */
3031 else /* bpstat_ret == 1, hit bpt, do not desire location */
3032 source_flag = -1; /* just print source line */
3034 /* The behavior of this routine with respect to the source
3036 -1: Print only source line
3037 0: Print only location
3038 1: Print location and source line */
3039 show_and_print_stack_frame (selected_frame, -1, source_flag);
3041 /* Display the auto-display expressions. */
3046 /* Save the function value return registers, if we care.
3047 We might be about to restore their previous contents. */
3048 if (proceed_to_finish)
3049 read_register_bytes (0, stop_registers, REGISTER_BYTES);
3051 if (stop_stack_dummy)
3053 /* Pop the empty frame that contains the stack dummy.
3054 POP_FRAME ends with a setting of the current frame, so we
3055 can use that next. */
3057 /* Set stop_pc to what it was before we called the function.
3058 Can't rely on restore_inferior_status because that only gets
3059 called if we don't stop in the called function. */
3060 stop_pc = read_pc();
3061 select_frame (get_current_frame (), 0);
3065 TUIDO (((TuiOpaqueFuncPtr)tui_vCheckDataValues, selected_frame));
3068 annotate_stopped ();
3072 hook_stop_stub (cmd)
3075 execute_user_command ((struct cmd_list_element *)cmd, 0);
3079 int signal_stop_state (signo)
3082 return signal_stop[signo];
3085 int signal_print_state (signo)
3088 return signal_print[signo];
3091 int signal_pass_state (signo)
3094 return signal_program[signo];
3101 Signal Stop\tPrint\tPass to program\tDescription\n");
3105 sig_print_info (oursig)
3106 enum target_signal oursig;
3108 char *name = target_signal_to_name (oursig);
3109 int name_padding = 13 - strlen (name);
3110 if (name_padding <= 0)
3113 printf_filtered ("%s", name);
3114 printf_filtered ("%*.*s ", name_padding, name_padding,
3116 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3117 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3118 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3119 printf_filtered ("%s\n", target_signal_to_string (oursig));
3122 /* Specify how various signals in the inferior should be handled. */
3125 handle_command (args, from_tty)
3130 int digits, wordlen;
3131 int sigfirst, signum, siglast;
3132 enum target_signal oursig;
3135 unsigned char *sigs;
3136 struct cleanup *old_chain;
3140 error_no_arg ("signal to handle");
3143 /* Allocate and zero an array of flags for which signals to handle. */
3145 nsigs = (int)TARGET_SIGNAL_LAST;
3146 sigs = (unsigned char *) alloca (nsigs);
3147 memset (sigs, 0, nsigs);
3149 /* Break the command line up into args. */
3151 argv = buildargv (args);
3156 old_chain = make_cleanup ((make_cleanup_func) freeargv, (char *) argv);
3158 /* Walk through the args, looking for signal oursigs, signal names, and
3159 actions. Signal numbers and signal names may be interspersed with
3160 actions, with the actions being performed for all signals cumulatively
3161 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3163 while (*argv != NULL)
3165 wordlen = strlen (*argv);
3166 for (digits = 0; isdigit ((*argv)[digits]); digits++) {;}
3168 sigfirst = siglast = -1;
3170 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3172 /* Apply action to all signals except those used by the
3173 debugger. Silently skip those. */
3176 siglast = nsigs - 1;
3178 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3180 SET_SIGS (nsigs, sigs, signal_stop);
3181 SET_SIGS (nsigs, sigs, signal_print);
3183 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3185 UNSET_SIGS (nsigs, sigs, signal_program);
3187 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3189 SET_SIGS (nsigs, sigs, signal_print);
3191 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3193 SET_SIGS (nsigs, sigs, signal_program);
3195 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3197 UNSET_SIGS (nsigs, sigs, signal_stop);
3199 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3201 SET_SIGS (nsigs, sigs, signal_program);
3203 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3205 UNSET_SIGS (nsigs, sigs, signal_print);
3206 UNSET_SIGS (nsigs, sigs, signal_stop);
3208 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3210 UNSET_SIGS (nsigs, sigs, signal_program);
3212 else if (digits > 0)
3214 /* It is numeric. The numeric signal refers to our own
3215 internal signal numbering from target.h, not to host/target
3216 signal number. This is a feature; users really should be
3217 using symbolic names anyway, and the common ones like
3218 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3220 sigfirst = siglast = (int)
3221 target_signal_from_command (atoi (*argv));
3222 if ((*argv)[digits] == '-')
3225 target_signal_from_command (atoi ((*argv) + digits + 1));
3227 if (sigfirst > siglast)
3229 /* Bet he didn't figure we'd think of this case... */
3237 oursig = target_signal_from_name (*argv);
3238 if (oursig != TARGET_SIGNAL_UNKNOWN)
3240 sigfirst = siglast = (int)oursig;
3244 /* Not a number and not a recognized flag word => complain. */
3245 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3249 /* If any signal numbers or symbol names were found, set flags for
3250 which signals to apply actions to. */
3252 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3254 switch ((enum target_signal)signum)
3256 case TARGET_SIGNAL_TRAP:
3257 case TARGET_SIGNAL_INT:
3258 if (!allsigs && !sigs[signum])
3260 if (query ("%s is used by the debugger.\n\
3261 Are you sure you want to change it? ",
3262 target_signal_to_name
3263 ((enum target_signal)signum)))
3269 printf_unfiltered ("Not confirmed, unchanged.\n");
3270 gdb_flush (gdb_stdout);
3274 case TARGET_SIGNAL_0:
3275 case TARGET_SIGNAL_DEFAULT:
3276 case TARGET_SIGNAL_UNKNOWN:
3277 /* Make sure that "all" doesn't print these. */
3288 target_notice_signals(inferior_pid);
3292 /* Show the results. */
3293 sig_print_header ();
3294 for (signum = 0; signum < nsigs; signum++)
3298 sig_print_info (signum);
3303 do_cleanups (old_chain);
3307 xdb_handle_command (args, from_tty)
3312 struct cleanup *old_chain;
3314 /* Break the command line up into args. */
3316 argv = buildargv (args);
3321 old_chain = make_cleanup ((make_cleanup_func) freeargv, (char *) argv);
3322 if (argv[1] != (char *)NULL)
3327 bufLen = strlen(argv[0]) + 20;
3328 argBuf = (char *)xmalloc(bufLen);
3332 enum target_signal oursig;
3334 oursig = target_signal_from_name (argv[0]);
3335 memset(argBuf, 0, bufLen);
3336 if (strcmp(argv[1], "Q") == 0)
3337 sprintf(argBuf, "%s %s", argv[0], "noprint");
3340 if (strcmp(argv[1], "s") == 0)
3342 if (!signal_stop[oursig])
3343 sprintf(argBuf, "%s %s", argv[0], "stop");
3345 sprintf(argBuf, "%s %s", argv[0], "nostop");
3347 else if (strcmp(argv[1], "i") == 0)
3349 if (!signal_program[oursig])
3350 sprintf(argBuf, "%s %s", argv[0], "pass");
3352 sprintf(argBuf, "%s %s", argv[0], "nopass");
3354 else if (strcmp(argv[1], "r") == 0)
3356 if (!signal_print[oursig])
3357 sprintf(argBuf, "%s %s", argv[0], "print");
3359 sprintf(argBuf, "%s %s", argv[0], "noprint");
3365 handle_command(argBuf, from_tty);
3367 printf_filtered("Invalid signal handling flag.\n");
3372 do_cleanups (old_chain);
3375 /* Print current contents of the tables set by the handle command.
3376 It is possible we should just be printing signals actually used
3377 by the current target (but for things to work right when switching
3378 targets, all signals should be in the signal tables). */
3381 signals_info (signum_exp, from_tty)
3385 enum target_signal oursig;
3386 sig_print_header ();
3390 /* First see if this is a symbol name. */
3391 oursig = target_signal_from_name (signum_exp);
3392 if (oursig == TARGET_SIGNAL_UNKNOWN)
3394 /* No, try numeric. */
3396 target_signal_from_command (parse_and_eval_address (signum_exp));
3398 sig_print_info (oursig);
3402 printf_filtered ("\n");
3403 /* These ugly casts brought to you by the native VAX compiler. */
3404 for (oursig = TARGET_SIGNAL_FIRST;
3405 (int)oursig < (int)TARGET_SIGNAL_LAST;
3406 oursig = (enum target_signal)((int)oursig + 1))
3410 if (oursig != TARGET_SIGNAL_UNKNOWN
3411 && oursig != TARGET_SIGNAL_DEFAULT
3412 && oursig != TARGET_SIGNAL_0)
3413 sig_print_info (oursig);
3416 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3419 /* Save all of the information associated with the inferior<==>gdb
3420 connection. INF_STATUS is a pointer to a "struct inferior_status"
3421 (defined in inferior.h). */
3424 save_inferior_status (inf_status, restore_stack_info)
3425 struct inferior_status *inf_status;
3426 int restore_stack_info;
3428 inf_status->stop_signal = stop_signal;
3429 inf_status->stop_pc = stop_pc;
3430 inf_status->stop_step = stop_step;
3431 inf_status->stop_stack_dummy = stop_stack_dummy;
3432 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3433 inf_status->trap_expected = trap_expected;
3434 inf_status->step_range_start = step_range_start;
3435 inf_status->step_range_end = step_range_end;
3436 inf_status->step_frame_address = step_frame_address;
3437 inf_status->step_over_calls = step_over_calls;
3438 inf_status->stop_after_trap = stop_after_trap;
3439 inf_status->stop_soon_quietly = stop_soon_quietly;
3440 /* Save original bpstat chain here; replace it with copy of chain.
3441 If caller's caller is walking the chain, they'll be happier if we
3442 hand them back the original chain when restore_i_s is called. */
3443 inf_status->stop_bpstat = stop_bpstat;
3444 stop_bpstat = bpstat_copy (stop_bpstat);
3445 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3446 inf_status->restore_stack_info = restore_stack_info;
3447 inf_status->proceed_to_finish = proceed_to_finish;
3449 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
3451 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3453 record_selected_frame (&(inf_status->selected_frame_address),
3454 &(inf_status->selected_level));
3458 struct restore_selected_frame_args {
3459 CORE_ADDR frame_address;
3463 static int restore_selected_frame PARAMS ((char *));
3465 /* Restore the selected frame. args is really a struct
3466 restore_selected_frame_args * (declared as char * for catch_errors)
3467 telling us what frame to restore. Returns 1 for success, or 0 for
3468 failure. An error message will have been printed on error. */
3471 restore_selected_frame (args)
3474 struct restore_selected_frame_args *fr =
3475 (struct restore_selected_frame_args *) args;
3476 struct frame_info *frame;
3477 int level = fr->level;
3479 frame = find_relative_frame (get_current_frame (), &level);
3481 /* If inf_status->selected_frame_address is NULL, there was no
3482 previously selected frame. */
3483 if (frame == NULL ||
3484 /* FRAME_FP (frame) != fr->frame_address || */
3485 /* elz: deleted this check as a quick fix to the problem that
3486 for function called by hand gdb creates no internal frame
3487 structure and the real stack and gdb's idea of stack are
3488 different if nested calls by hands are made.
3490 mvs: this worries me. */
3493 warning ("Unable to restore previously selected frame.\n");
3497 select_frame (frame, fr->level);
3503 restore_inferior_status (inf_status)
3504 struct inferior_status *inf_status;
3506 stop_signal = inf_status->stop_signal;
3507 stop_pc = inf_status->stop_pc;
3508 stop_step = inf_status->stop_step;
3509 stop_stack_dummy = inf_status->stop_stack_dummy;
3510 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3511 trap_expected = inf_status->trap_expected;
3512 step_range_start = inf_status->step_range_start;
3513 step_range_end = inf_status->step_range_end;
3514 step_frame_address = inf_status->step_frame_address;
3515 step_over_calls = inf_status->step_over_calls;
3516 stop_after_trap = inf_status->stop_after_trap;
3517 stop_soon_quietly = inf_status->stop_soon_quietly;
3518 bpstat_clear (&stop_bpstat);
3519 stop_bpstat = inf_status->stop_bpstat;
3520 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3521 proceed_to_finish = inf_status->proceed_to_finish;
3523 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
3525 /* The inferior can be gone if the user types "print exit(0)"
3526 (and perhaps other times). */
3527 if (target_has_execution)
3528 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3530 /* The inferior can be gone if the user types "print exit(0)"
3531 (and perhaps other times). */
3533 /* FIXME: If we are being called after stopping in a function which
3534 is called from gdb, we should not be trying to restore the
3535 selected frame; it just prints a spurious error message (The
3536 message is useful, however, in detecting bugs in gdb (like if gdb
3537 clobbers the stack)). In fact, should we be restoring the
3538 inferior status at all in that case? . */
3540 if (target_has_stack && inf_status->restore_stack_info)
3542 struct restore_selected_frame_args fr;
3543 fr.level = inf_status->selected_level;
3544 fr.frame_address = inf_status->selected_frame_address;
3545 /* The point of catch_errors is that if the stack is clobbered,
3546 walking the stack might encounter a garbage pointer and error()
3547 trying to dereference it. */
3548 if (catch_errors (restore_selected_frame, &fr,
3549 "Unable to restore previously selected frame:\n",
3550 RETURN_MASK_ERROR) == 0)
3551 /* Error in restoring the selected frame. Select the innermost
3555 select_frame (get_current_frame (), 0);
3563 set_follow_fork_mode_command (arg, from_tty, c)
3566 struct cmd_list_element * c;
3568 if (! STREQ (arg, "parent") &&
3569 ! STREQ (arg, "child") &&
3570 ! STREQ (arg, "both") &&
3571 ! STREQ (arg, "ask"))
3572 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
3574 if (follow_fork_mode_string != NULL)
3575 free (follow_fork_mode_string);
3576 follow_fork_mode_string = savestring (arg, strlen (arg));
3582 _initialize_infrun ()
3585 register int numsigs;
3586 struct cmd_list_element * c;
3588 add_info ("signals", signals_info,
3589 "What debugger does when program gets various signals.\n\
3590 Specify a signal as argument to print info on that signal only.");
3591 add_info_alias ("handle", "signals", 0);
3593 add_com ("handle", class_run, handle_command,
3594 concat ("Specify how to handle a signal.\n\
3595 Args are signals and actions to apply to those signals.\n\
3596 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3597 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3598 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3599 The special arg \"all\" is recognized to mean all signals except those\n\
3600 used by the debugger, typically SIGTRAP and SIGINT.\n",
3601 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3602 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3603 Stop means reenter debugger if this signal happens (implies print).\n\
3604 Print means print a message if this signal happens.\n\
3605 Pass means let program see this signal; otherwise program doesn't know.\n\
3606 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3607 Pass and Stop may be combined.", NULL));
3610 add_com("lz", class_info, signals_info,
3611 "What debugger does when program gets various signals.\n\
3612 Specify a signal as argument to print info on that signal only.");
3613 add_com("z", class_run, xdb_handle_command,
3614 concat ("Specify how to handle a signal.\n\
3615 Args are signals and actions to apply to those signals.\n\
3616 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3617 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3618 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3619 The special arg \"all\" is recognized to mean all signals except those\n\
3620 used by the debugger, typically SIGTRAP and SIGINT.\n",
3621 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3622 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3623 nopass), \"Q\" (noprint)\n\
3624 Stop means reenter debugger if this signal happens (implies print).\n\
3625 Print means print a message if this signal happens.\n\
3626 Pass means let program see this signal; otherwise program doesn't know.\n\
3627 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3628 Pass and Stop may be combined.", NULL));
3632 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
3633 "There is no `stop' command, but you can set a hook on `stop'.\n\
3634 This allows you to set a list of commands to be run each time execution\n\
3635 of the program stops.", &cmdlist);
3637 numsigs = (int)TARGET_SIGNAL_LAST;
3638 signal_stop = (unsigned char *)
3639 xmalloc (sizeof (signal_stop[0]) * numsigs);
3640 signal_print = (unsigned char *)
3641 xmalloc (sizeof (signal_print[0]) * numsigs);
3642 signal_program = (unsigned char *)
3643 xmalloc (sizeof (signal_program[0]) * numsigs);
3644 for (i = 0; i < numsigs; i++)
3647 signal_print[i] = 1;
3648 signal_program[i] = 1;
3651 /* Signals caused by debugger's own actions
3652 should not be given to the program afterwards. */
3653 signal_program[TARGET_SIGNAL_TRAP] = 0;
3654 signal_program[TARGET_SIGNAL_INT] = 0;
3656 /* Signals that are not errors should not normally enter the debugger. */
3657 signal_stop[TARGET_SIGNAL_ALRM] = 0;
3658 signal_print[TARGET_SIGNAL_ALRM] = 0;
3659 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
3660 signal_print[TARGET_SIGNAL_VTALRM] = 0;
3661 signal_stop[TARGET_SIGNAL_PROF] = 0;
3662 signal_print[TARGET_SIGNAL_PROF] = 0;
3663 signal_stop[TARGET_SIGNAL_CHLD] = 0;
3664 signal_print[TARGET_SIGNAL_CHLD] = 0;
3665 signal_stop[TARGET_SIGNAL_IO] = 0;
3666 signal_print[TARGET_SIGNAL_IO] = 0;
3667 signal_stop[TARGET_SIGNAL_POLL] = 0;
3668 signal_print[TARGET_SIGNAL_POLL] = 0;
3669 signal_stop[TARGET_SIGNAL_URG] = 0;
3670 signal_print[TARGET_SIGNAL_URG] = 0;
3674 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
3675 (char *) &stop_on_solib_events,
3676 "Set stopping for shared library events.\n\
3677 If nonzero, gdb will give control to the user when the dynamic linker\n\
3678 notifies gdb of shared library events. The most common event of interest\n\
3679 to the user would be loading/unloading of a new library.\n",
3684 c = add_set_enum_cmd ("follow-fork-mode",
3686 follow_fork_mode_kind_names,
3687 (char *) &follow_fork_mode_string,
3688 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
3689 kernel problem. It's also not terribly useful without a GUI to
3690 help the user drive two debuggers. So for now, I'm disabling
3691 the "both" option. */
3692 /* "Set debugger response to a program call of fork \
3694 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3695 parent - the original process is debugged after a fork\n\
3696 child - the new process is debugged after a fork\n\
3697 both - both the parent and child are debugged after a fork\n\
3698 ask - the debugger will ask for one of the above choices\n\
3699 For \"both\", another copy of the debugger will be started to follow\n\
3700 the new child process. The original debugger will continue to follow\n\
3701 the original parent process. To distinguish their prompts, the\n\
3702 debugger copy's prompt will be changed.\n\
3703 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3704 By default, the debugger will follow the parent process.",
3706 "Set debugger response to a program call of fork \
3708 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3709 parent - the original process is debugged after a fork\n\
3710 child - the new process is debugged after a fork\n\
3711 ask - the debugger will ask for one of the above choices\n\
3712 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3713 By default, the debugger will follow the parent process.",
3715 /* c->function.sfunc = ;*/
3716 add_show_from_set (c, &showlist);
3718 set_follow_fork_mode_command ("parent", 0, NULL);
3720 c = add_set_enum_cmd ("scheduler-locking", class_run,
3721 scheduler_enums, /* array of string names */
3722 (char *) &scheduler_mode, /* current mode */
3723 "Set mode for locking scheduler during execution.\n\
3724 off == no locking (threads may preempt at any time)\n\
3725 on == full locking (no thread except the current thread may run)\n\
3726 step == scheduler locked during every single-step operation.\n\
3727 In this mode, no other thread may run during a step command.\n\
3728 Other threads may run while stepping over a function call ('next').",
3731 c->function.sfunc = set_schedlock_func; /* traps on target vector */
3732 add_show_from_set (c, &showlist);