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 ((PTR));
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 /* This function returns TRUE if pc is the address of an instruction
138 that lies within the dynamic linker (such as the event hook, or the
141 This function must be used only when a dynamic linker event has
142 been caught, and the inferior is being stepped out of the hook, or
143 undefined results are guaranteed. */
145 #ifndef SOLIB_IN_DYNAMIC_LINKER
146 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
149 /* On MIPS16, a function that returns a floating point value may call
150 a library helper function to copy the return value to a floating point
151 register. The IGNORE_HELPER_CALL macro returns non-zero if we
152 should ignore (i.e. step over) this function call. */
153 #ifndef IGNORE_HELPER_CALL
154 #define IGNORE_HELPER_CALL(pc) 0
157 /* On some systems, the PC may be left pointing at an instruction that won't
158 actually be executed. This is usually indicated by a bit in the PSW. If
159 we find ourselves in such a state, then we step the target beyond the
160 nullified instruction before returning control to the user so as to avoid
163 #ifndef INSTRUCTION_NULLIFIED
164 #define INSTRUCTION_NULLIFIED 0
167 /* Tables of how to react to signals; the user sets them. */
169 static unsigned char *signal_stop;
170 static unsigned char *signal_print;
171 static unsigned char *signal_program;
173 #define SET_SIGS(nsigs,sigs,flags) \
175 int signum = (nsigs); \
176 while (signum-- > 0) \
177 if ((sigs)[signum]) \
178 (flags)[signum] = 1; \
181 #define UNSET_SIGS(nsigs,sigs,flags) \
183 int signum = (nsigs); \
184 while (signum-- > 0) \
185 if ((sigs)[signum]) \
186 (flags)[signum] = 0; \
190 /* Command list pointer for the "stop" placeholder. */
192 static struct cmd_list_element *stop_command;
194 /* Nonzero if breakpoints are now inserted in the inferior. */
196 static int breakpoints_inserted;
198 /* Function inferior was in as of last step command. */
200 static struct symbol *step_start_function;
202 /* Nonzero if we are expecting a trace trap and should proceed from it. */
204 static int trap_expected;
207 /* Nonzero if we want to give control to the user when we're notified
208 of shared library events by the dynamic linker. */
209 static int stop_on_solib_events;
213 /* Nonzero if the next time we try to continue the inferior, it will
214 step one instruction and generate a spurious trace trap.
215 This is used to compensate for a bug in HP-UX. */
217 static int trap_expected_after_continue;
220 /* Nonzero means expecting a trace trap
221 and should stop the inferior and return silently when it happens. */
225 /* Nonzero means expecting a trap and caller will handle it themselves.
226 It is used after attach, due to attaching to a process;
227 when running in the shell before the child program has been exec'd;
228 and when running some kinds of remote stuff (FIXME?). */
230 int stop_soon_quietly;
232 /* Nonzero if proceed is being used for a "finish" command or a similar
233 situation when stop_registers should be saved. */
235 int proceed_to_finish;
237 /* Save register contents here when about to pop a stack dummy frame,
238 if-and-only-if proceed_to_finish is set.
239 Thus this contains the return value from the called function (assuming
240 values are returned in a register). */
242 char stop_registers[REGISTER_BYTES];
244 /* Nonzero if program stopped due to error trying to insert breakpoints. */
246 static int breakpoints_failed;
248 /* Nonzero after stop if current stack frame should be printed. */
250 static int stop_print_frame;
252 static struct breakpoint *step_resume_breakpoint = NULL;
253 static struct breakpoint *through_sigtramp_breakpoint = NULL;
255 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
256 interactions with an inferior that is running a kernel function
257 (aka, a system call or "syscall"). wait_for_inferior therefore
258 may have a need to know when the inferior is in a syscall. This
259 is a count of the number of inferior threads which are known to
260 currently be running in a syscall. */
261 static int number_of_threads_in_syscalls;
263 /* This is used to remember when a fork, vfork or exec event
264 was caught by a catchpoint, and thus the event is to be
265 followed at the next resume of the inferior, and not
269 enum target_waitkind kind;
279 char *execd_pathname;
283 /* Some platforms don't allow us to do anything meaningful with a
284 vforked child until it has exec'd. Vforked processes on such
285 platforms can only be followed after they've exec'd.
287 When this is set to 0, a vfork can be immediately followed,
288 and an exec can be followed merely as an exec. When this is
289 set to 1, a vfork event has been seen, but cannot be followed
290 until the exec is seen.
292 (In the latter case, inferior_pid is still the parent of the
293 vfork, and pending_follow.fork_event.child_pid is the child. The
294 appropriate process is followed, according to the setting of
295 follow-fork-mode.) */
296 static int follow_vfork_when_exec;
298 static char *follow_fork_mode_kind_names[] =
300 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
301 kernel problem. It's also not terribly useful without a GUI to
302 help the user drive two debuggers. So for now, I'm disabling
304 "parent", "child", "both", "ask" };
306 "parent", "child", "ask"};
308 static char *follow_fork_mode_string = NULL;
311 #if defined(HPUXHPPA)
313 follow_inferior_fork (parent_pid, child_pid, has_forked, has_vforked)
319 int followed_parent = 0;
320 int followed_child = 0;
323 /* Which process did the user want us to follow? */
325 savestring (follow_fork_mode_string, strlen (follow_fork_mode_string));
327 /* Or, did the user not know, and want us to ask? */
328 if (STREQ (follow_fork_mode_string, "ask"))
330 char requested_mode[100];
333 error ("\"ask\" mode NYI");
334 follow_mode = savestring (requested_mode, strlen (requested_mode));
337 /* If we're to be following the parent, then detach from child_pid.
338 We're already following the parent, so need do nothing explicit
340 if (STREQ (follow_mode, "parent"))
344 /* We're already attached to the parent, by default. */
346 /* Before detaching from the child, remove all breakpoints from
347 it. (This won't actually modify the breakpoint list, but will
348 physically remove the breakpoints from the child.) */
349 if (!has_vforked || !follow_vfork_when_exec)
351 detach_breakpoints (child_pid);
352 SOLIB_REMOVE_INFERIOR_HOOK (child_pid);
355 /* Detach from the child. */
358 target_require_detach (child_pid, "", 1);
361 /* If we're to be following the child, then attach to it, detach
362 from inferior_pid, and set inferior_pid to child_pid. */
363 else if (STREQ (follow_mode, "child"))
365 char child_pid_spelling[100]; /* Arbitrary length. */
369 /* Before detaching from the parent, detach all breakpoints from
370 the child. But only if we're forking, or if we follow vforks
371 as soon as they happen. (If we're following vforks only when
372 the child has exec'd, then it's very wrong to try to write
373 back the "shadow contents" of inserted breakpoints now -- they
374 belong to the child's pre-exec'd a.out.) */
375 if (!has_vforked || !follow_vfork_when_exec)
377 detach_breakpoints (child_pid);
380 /* Before detaching from the parent, remove all breakpoints from it. */
381 remove_breakpoints ();
383 /* Also reset the solib inferior hook from the parent. */
384 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid);
386 /* Detach from the parent. */
388 target_detach (NULL, 1);
390 /* Attach to the child. */
391 inferior_pid = child_pid;
392 sprintf (child_pid_spelling, "%d", child_pid);
395 target_require_attach (child_pid_spelling, 1);
397 /* Was there a step_resume breakpoint? (There was if the user
398 did a "next" at the fork() call.) If so, explicitly reset its
401 step_resumes are a form of bp that are made to be per-thread.
402 Since we created the step_resume bp when the parent process
403 was being debugged, and now are switching to the child process,
404 from the breakpoint package's viewpoint, that's a switch of
405 "threads". We must update the bp's notion of which thread
406 it is for, or it'll be ignored when it triggers... */
407 if (step_resume_breakpoint &&
408 (!has_vforked || !follow_vfork_when_exec))
409 breakpoint_re_set_thread (step_resume_breakpoint);
411 /* Reinsert all breakpoints in the child. (The user may've set
412 breakpoints after catching the fork, in which case those
413 actually didn't get set in the child, but only in the parent.) */
414 if (!has_vforked || !follow_vfork_when_exec)
416 breakpoint_re_set ();
417 insert_breakpoints ();
421 /* If we're to be following both parent and child, then fork ourselves,
422 and attach the debugger clone to the child. */
423 else if (STREQ (follow_mode, "both"))
425 char pid_suffix[100]; /* Arbitrary length. */
427 /* Clone ourselves to follow the child. This is the end of our
428 involvement with child_pid; our clone will take it from here... */
430 target_clone_and_follow_inferior (child_pid, &followed_child);
431 followed_parent = !followed_child;
433 /* We continue to follow the parent. To help distinguish the two
434 debuggers, though, both we and our clone will reset our prompts. */
435 sprintf (pid_suffix, "[%d] ", inferior_pid);
436 set_prompt (strcat (get_prompt (), pid_suffix));
439 /* The parent and child of a vfork share the same address space.
440 Also, on some targets the order in which vfork and exec events
441 are received for parent in child requires some delicate handling
444 For instance, on ptrace-based HPUX we receive the child's vfork
445 event first, at which time the parent has been suspended by the
446 OS and is essentially untouchable until the child's exit or second
447 exec event arrives. At that time, the parent's vfork event is
448 delivered to us, and that's when we see and decide how to follow
449 the vfork. But to get to that point, we must continue the child
450 until it execs or exits. To do that smoothly, all breakpoints
451 must be removed from the child, in case there are any set between
452 the vfork() and exec() calls. But removing them from the child
453 also removes them from the parent, due to the shared-address-space
454 nature of a vfork'd parent and child. On HPUX, therefore, we must
455 take care to restore the bp's to the parent before we continue it.
456 Else, it's likely that we may not stop in the expected place. (The
457 worst scenario is when the user tries to step over a vfork() call;
458 the step-resume bp must be restored for the step to properly stop
459 in the parent after the call completes!)
461 Sequence of events, as reported to gdb from HPUX:
463 Parent Child Action for gdb to take
464 -------------------------------------------------------
465 1 VFORK Continue child
471 target_post_follow_vfork (parent_pid,
477 pending_follow.fork_event.saw_parent_fork = 0;
478 pending_follow.fork_event.saw_child_fork = 0;
484 follow_fork (parent_pid, child_pid)
488 follow_inferior_fork (parent_pid, child_pid, 1, 0);
492 /* Forward declaration. */
493 static void follow_exec PARAMS ((int, char *));
496 follow_vfork (parent_pid, child_pid)
500 follow_inferior_fork (parent_pid, child_pid, 0, 1);
502 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
503 if (pending_follow.fork_event.saw_child_exec && (inferior_pid == child_pid))
505 pending_follow.fork_event.saw_child_exec = 0;
506 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
507 follow_exec (inferior_pid, pending_follow.execd_pathname);
508 free (pending_follow.execd_pathname);
511 #endif /* HPUXHPPA */
514 follow_exec (pid, execd_pathname)
516 char *execd_pathname;
520 extern struct target_ops child_ops;
522 /* Did this exec() follow a vfork()? If so, we must follow the
523 vfork now too. Do it before following the exec. */
524 if (follow_vfork_when_exec &&
525 (pending_follow.kind == TARGET_WAITKIND_VFORKED))
527 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
528 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
529 follow_vfork_when_exec = 0;
530 saved_pid = inferior_pid;
532 /* Did we follow the parent? If so, we're done. If we followed
533 the child then we must also follow its exec(). */
534 if (inferior_pid == pending_follow.fork_event.parent_pid)
538 /* This is an exec event that we actually wish to pay attention to.
539 Refresh our symbol table to the newly exec'd program, remove any
542 If there are breakpoints, they aren't really inserted now,
543 since the exec() transformed our inferior into a fresh set
546 We want to preserve symbolic breakpoints on the list, since
547 we have hopes that they can be reset after the new a.out's
548 symbol table is read.
550 However, any "raw" breakpoints must be removed from the list
551 (e.g., the solib bp's), since their address is probably invalid
554 And, we DON'T want to call delete_breakpoints() here, since
555 that may write the bp's "shadow contents" (the instruction
556 value that was overwritten witha TRAP instruction). Since
557 we now have a new a.out, those shadow contents aren't valid. */
558 update_breakpoints_after_exec ();
560 /* If there was one, it's gone now. We cannot truly step-to-next
561 statement through an exec(). */
562 step_resume_breakpoint = NULL;
563 step_range_start = 0;
566 /* If there was one, it's gone now. */
567 through_sigtramp_breakpoint = NULL;
569 /* What is this a.out's name? */
570 printf_unfiltered ("Executing new program: %s\n", execd_pathname);
572 /* We've followed the inferior through an exec. Therefore, the
573 inferior has essentially been killed & reborn. */
574 gdb_flush (gdb_stdout);
575 target_mourn_inferior ();
576 inferior_pid = saved_pid; /* Because mourn_inferior resets inferior_pid. */
577 push_target (&child_ops);
579 /* That a.out is now the one to use. */
580 exec_file_attach (execd_pathname, 0);
582 /* And also is where symbols can be found. */
583 symbol_file_command (execd_pathname, 0);
585 /* Reset the shared library package. This ensures that we get
586 a shlib event when the child reaches "_start", at which point
587 the dld will have had a chance to initialize the child. */
589 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid);
591 /* Reinsert all breakpoints. (Those which were symbolic have
592 been reset to the proper address in the new a.out, thanks
593 to symbol_file_command...) */
594 insert_breakpoints ();
596 /* The next resume of this inferior should bring it to the shlib
597 startup breakpoints. (If the user had also set bp's on
598 "main" from the old (parent) process, then they'll auto-
599 matically get reset there in the new process.) */
603 /* Non-zero if we just simulating a single-step. This is needed
604 because we cannot remove the breakpoints in the inferior process
605 until after the `wait' in `wait_for_inferior'. */
606 static int singlestep_breakpoints_inserted_p = 0;
609 /* Things to clean up if we QUIT out of resume (). */
612 resume_cleanups (arg)
618 static char schedlock_off[] = "off";
619 static char schedlock_on[] = "on";
620 static char schedlock_step[] = "step";
621 static char *scheduler_mode = schedlock_off;
622 static char *scheduler_enums[] =
623 {schedlock_off, schedlock_on, schedlock_step};
626 set_schedlock_func (args, from_tty, c)
629 struct cmd_list_element *c;
631 if (c->type == set_cmd)
632 if (!target_can_lock_scheduler)
634 scheduler_mode = schedlock_off;
635 error ("Target '%s' cannot support this command.",
641 /* Resume the inferior, but allow a QUIT. This is useful if the user
642 wants to interrupt some lengthy single-stepping operation
643 (for child processes, the SIGINT goes to the inferior, and so
644 we get a SIGINT random_signal, but for remote debugging and perhaps
645 other targets, that's not true).
647 STEP nonzero if we should step (zero to continue instead).
648 SIG is the signal to give the inferior (zero for none). */
652 enum target_signal sig;
654 int should_resume = 1;
655 struct cleanup *old_cleanups = make_cleanup ((make_cleanup_func)
659 #ifdef CANNOT_STEP_BREAKPOINT
660 /* Most targets can step a breakpoint instruction, thus executing it
661 normally. But if this one cannot, just continue and we will hit
663 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
667 if (SOFTWARE_SINGLE_STEP_P && step)
669 /* Do it the hard way, w/temp breakpoints */
670 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints*/ );
671 /* ...and don't ask hardware to do it. */
673 /* and do not pull these breakpoints until after a `wait' in
674 `wait_for_inferior' */
675 singlestep_breakpoints_inserted_p = 1;
678 /* Handle any optimized stores to the inferior NOW... */
679 #ifdef DO_DEFERRED_STORES
684 /* If there were any forks/vforks/execs that were caught and are
685 now to be followed, then do so. */
686 switch (pending_follow.kind)
688 case (TARGET_WAITKIND_FORKED):
689 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
690 follow_fork (inferior_pid, pending_follow.fork_event.child_pid);
693 case (TARGET_WAITKIND_VFORKED):
695 int saw_child_exec = pending_follow.fork_event.saw_child_exec;
697 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
698 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
700 /* Did we follow the child, but not yet see the child's exec event?
701 If so, then it actually ought to be waiting for us; we respond to
702 parent vfork events. We don't actually want to resume the child
703 in this situation; we want to just get its exec event. */
704 if (!saw_child_exec &&
705 (inferior_pid == pending_follow.fork_event.child_pid))
710 case (TARGET_WAITKIND_EXECD):
711 /* If we saw a vfork event but couldn't follow it until we saw
712 an exec, then now might be the time! */
713 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
714 /* follow_exec is called as soon as the exec event is seen. */
720 #endif /* HPUXHPPA */
722 /* Install inferior's terminal modes. */
723 target_terminal_inferior ();
728 if (thread_step_needed)
730 /* We stopped on a BPT instruction;
731 don't continue other threads and
732 just step this thread. */
733 thread_step_needed = 0;
735 if (!breakpoint_here_p (read_pc ()))
737 /* Breakpoint deleted: ok to do regular resume
738 where all the threads either step or continue. */
739 target_resume (-1, step, sig);
745 warning ("Internal error, changing continue to step.");
746 remove_breakpoints ();
747 breakpoints_inserted = 0;
752 target_resume (inferior_pid, step, sig);
756 #endif /* HPUXHPPA */
758 /* Vanilla resume. */
760 if ((scheduler_mode == schedlock_on) ||
761 (scheduler_mode == schedlock_step && step != 0))
762 target_resume (inferior_pid, step, sig);
764 target_resume (-1, step, sig);
768 discard_cleanups (old_cleanups);
772 /* Clear out all variables saying what to do when inferior is continued.
773 First do this, then set the ones you want, then call `proceed'. */
776 clear_proceed_status ()
779 step_range_start = 0;
781 step_frame_address = 0;
782 step_over_calls = -1;
784 stop_soon_quietly = 0;
785 proceed_to_finish = 0;
786 breakpoint_proceeded = 1; /* We're about to proceed... */
788 /* Discard any remaining commands or status from previous stop. */
789 bpstat_clear (&stop_bpstat);
792 /* Basic routine for continuing the program in various fashions.
794 ADDR is the address to resume at, or -1 for resume where stopped.
795 SIGGNAL is the signal to give it, or 0 for none,
796 or -1 for act according to how it stopped.
797 STEP is nonzero if should trap after one instruction.
798 -1 means return after that and print nothing.
799 You should probably set various step_... variables
800 before calling here, if you are stepping.
802 You should call clear_proceed_status before calling proceed. */
805 proceed (addr, siggnal, step)
807 enum target_signal siggnal;
813 step_start_function = find_pc_function (read_pc ());
817 if (addr == (CORE_ADDR) - 1)
819 /* If there is a breakpoint at the address we will resume at,
820 step one instruction before inserting breakpoints
821 so that we do not stop right away (and report a second
822 hit at this breakpoint). */
824 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
827 #ifndef STEP_SKIPS_DELAY
828 #define STEP_SKIPS_DELAY(pc) (0)
829 #define STEP_SKIPS_DELAY_P (0)
831 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
832 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
833 is slow (it needs to read memory from the target). */
834 if (STEP_SKIPS_DELAY_P
835 && breakpoint_here_p (read_pc () + 4)
836 && STEP_SKIPS_DELAY (read_pc ()))
843 /* New address; we don't need to single-step a thread
844 over a breakpoint we just hit, 'cause we aren't
845 continuing from there.
847 It's not worth worrying about the case where a user
848 asks for a "jump" at the current PC--if they get the
849 hiccup of re-hiting a hit breakpoint, what else do
851 thread_step_needed = 0;
854 #ifdef PREPARE_TO_PROCEED
855 /* In a multi-threaded task we may select another thread
856 and then continue or step.
858 But if the old thread was stopped at a breakpoint, it
859 will immediately cause another breakpoint stop without
860 any execution (i.e. it will report a breakpoint hit
861 incorrectly). So we must step over it first.
863 PREPARE_TO_PROCEED checks the current thread against the thread
864 that reported the most recent event. If a step-over is required
865 it returns TRUE and sets the current thread to the old thread. */
866 if (PREPARE_TO_PROCEED () && breakpoint_here_p (read_pc ()))
869 thread_step_needed = 1;
872 #endif /* PREPARE_TO_PROCEED */
875 if (trap_expected_after_continue)
877 /* If (step == 0), a trap will be automatically generated after
878 the first instruction is executed. Force step one
879 instruction to clear this condition. This should not occur
880 if step is nonzero, but it is harmless in that case. */
882 trap_expected_after_continue = 0;
884 #endif /* HP_OS_BUG */
887 /* We will get a trace trap after one instruction.
888 Continue it automatically and insert breakpoints then. */
892 int temp = insert_breakpoints ();
895 print_sys_errmsg ("ptrace", temp);
896 error ("Cannot insert breakpoints.\n\
897 The same program may be running in another process.");
900 breakpoints_inserted = 1;
903 if (siggnal != TARGET_SIGNAL_DEFAULT)
904 stop_signal = siggnal;
905 /* If this signal should not be seen by program,
906 give it zero. Used for debugging signals. */
907 else if (!signal_program[stop_signal])
908 stop_signal = TARGET_SIGNAL_0;
910 annotate_starting ();
912 /* Make sure that output from GDB appears before output from the
914 gdb_flush (gdb_stdout);
916 /* Resume inferior. */
917 resume (oneproc || step || bpstat_should_step (), stop_signal);
919 /* Wait for it to stop (if not standalone)
920 and in any case decode why it stopped, and act accordingly. */
922 wait_for_inferior ();
926 /* Record the pc and sp of the program the last time it stopped.
927 These are just used internally by wait_for_inferior, but need
928 to be preserved over calls to it and cleared when the inferior
930 static CORE_ADDR prev_pc;
931 static CORE_ADDR prev_func_start;
932 static char *prev_func_name;
935 /* Start remote-debugging of a machine over a serial link. */
941 init_wait_for_inferior ();
942 stop_soon_quietly = 1;
944 wait_for_inferior ();
948 /* Initialize static vars when a new inferior begins. */
951 init_wait_for_inferior ()
953 /* These are meaningless until the first time through wait_for_inferior. */
956 prev_func_name = NULL;
959 trap_expected_after_continue = 0;
961 breakpoints_inserted = 0;
962 breakpoint_init_inferior (inf_starting);
964 /* Don't confuse first call to proceed(). */
965 stop_signal = TARGET_SIGNAL_0;
967 /* The first resume is not following a fork/vfork/exec. */
968 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
969 pending_follow.fork_event.saw_parent_fork = 0;
970 pending_follow.fork_event.saw_child_fork = 0;
971 pending_follow.fork_event.saw_child_exec = 0;
973 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
974 number_of_threads_in_syscalls = 0;
976 clear_proceed_status ();
980 delete_breakpoint_current_contents (arg)
983 struct breakpoint **breakpointp = (struct breakpoint **) arg;
984 if (*breakpointp != NULL)
986 delete_breakpoint (*breakpointp);
991 /* Wait for control to return from inferior to debugger.
992 If inferior gets a signal, we may decide to start it up again
993 instead of returning. That is why there is a loop in this function.
994 When this function actually returns it means the inferior
995 should be left stopped and GDB should read more commands. */
1000 struct cleanup *old_cleanups;
1001 struct target_waitstatus w;
1003 int random_signal = 0;
1004 CORE_ADDR stop_func_start;
1005 CORE_ADDR stop_func_end;
1006 char *stop_func_name;
1008 CORE_ADDR prologue_pc = 0;
1011 struct symtab_and_line sal;
1012 int remove_breakpoints_on_following_step = 0;
1014 struct symtab *current_symtab;
1015 int handling_longjmp = 0; /* FIXME */
1017 int saved_inferior_pid;
1018 int update_step_sp = 0;
1019 int stepping_through_solib_after_catch = 0;
1020 bpstat stepping_through_solib_catchpoints = NULL;
1021 int enable_hw_watchpoints_after_wait = 0;
1022 int stepping_through_sigtramp = 0;
1023 int new_thread_event;
1025 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
1026 int stepped_after_stopped_by_watchpoint;
1029 old_cleanups = make_cleanup (delete_breakpoint_current_contents,
1030 &step_resume_breakpoint);
1031 make_cleanup (delete_breakpoint_current_contents,
1032 &through_sigtramp_breakpoint);
1033 sal = find_pc_line (prev_pc, 0);
1034 current_line = sal.line;
1035 current_symtab = sal.symtab;
1037 /* Are we stepping? */
1038 #define CURRENTLY_STEPPING() \
1039 ((through_sigtramp_breakpoint == NULL \
1040 && !handling_longjmp \
1041 && ((step_range_end && step_resume_breakpoint == NULL) \
1042 || trap_expected)) \
1043 || stepping_through_solib_after_catch \
1044 || bpstat_should_step ())
1046 thread_step_needed = 0;
1049 /* We'll update this if & when we switch to a new thread. */
1050 switched_from_inferior_pid = inferior_pid;
1055 extern int overlay_cache_invalid; /* declared in symfile.h */
1057 overlay_cache_invalid = 1;
1059 /* We have to invalidate the registers BEFORE calling target_wait because
1060 they can be loaded from the target while in target_wait. This makes
1061 remote debugging a bit more efficient for those targets that provide
1062 critical registers as part of their normal status mechanism. */
1064 registers_changed ();
1066 if (target_wait_hook)
1067 pid = target_wait_hook (-1, &w);
1069 pid = target_wait (-1, &w);
1071 /* Since we've done a wait, we have a new event. Don't carry
1072 over any expectations about needing to step over a
1074 thread_step_needed = 0;
1076 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event is
1077 serviced in this loop, below. */
1078 if (enable_hw_watchpoints_after_wait)
1080 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid);
1081 enable_hw_watchpoints_after_wait = 0;
1085 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
1086 stepped_after_stopped_by_watchpoint = 0;
1091 We goto this label from elsewhere in wait_for_inferior when we want
1092 to continue the main loop without calling "wait" and trashing the
1093 waitstatus contained in W. */
1096 flush_cached_frames ();
1098 /* If it's a new process, add it to the thread database */
1100 new_thread_event = ((pid != inferior_pid) && !in_thread_list (pid));
1102 if (w.kind != TARGET_WAITKIND_EXITED
1103 && w.kind != TARGET_WAITKIND_SIGNALLED
1104 && new_thread_event)
1110 fprintf_unfiltered (gdb_stderr, "[New %s]\n",
1111 target_pid_or_tid_to_str (pid));
1114 printf_filtered ("[New %s]\n", target_pid_to_str (pid));
1118 /* NOTE: This block is ONLY meant to be invoked in case of a
1119 "thread creation event"! If it is invoked for any other
1120 sort of event (such as a new thread landing on a breakpoint),
1121 the event will be discarded, which is almost certainly
1124 To avoid this, the low-level module (eg. target_wait)
1125 should call in_thread_list and add_thread, so that the
1126 new thread is known by the time we get here. */
1128 /* We may want to consider not doing a resume here in order
1129 to give the user a chance to play with the new thread.
1130 It might be good to make that a user-settable option. */
1132 /* At this point, all threads are stopped (happens
1133 automatically in either the OS or the native code).
1134 Therefore we need to continue all threads in order to
1137 target_resume (-1, 0, TARGET_SIGNAL_0);
1144 case TARGET_WAITKIND_LOADED:
1145 /* Ignore gracefully during startup of the inferior, as it
1146 might be the shell which has just loaded some objects,
1147 otherwise add the symbols for the newly loaded objects. */
1149 if (!stop_soon_quietly)
1151 extern int auto_solib_add;
1153 /* Remove breakpoints, SOLIB_ADD might adjust
1154 breakpoint addresses via breakpoint_re_set. */
1155 if (breakpoints_inserted)
1156 remove_breakpoints ();
1158 /* Check for any newly added shared libraries if we're
1159 supposed to be adding them automatically. */
1162 /* Switch terminal for any messages produced by
1163 breakpoint_re_set. */
1164 target_terminal_ours_for_output ();
1165 SOLIB_ADD (NULL, 0, NULL);
1166 target_terminal_inferior ();
1169 /* Reinsert breakpoints and continue. */
1170 if (breakpoints_inserted)
1171 insert_breakpoints ();
1174 resume (0, TARGET_SIGNAL_0);
1177 case TARGET_WAITKIND_SPURIOUS:
1178 resume (0, TARGET_SIGNAL_0);
1181 case TARGET_WAITKIND_EXITED:
1182 target_terminal_ours (); /* Must do this before mourn anyway */
1183 annotate_exited (w.value.integer);
1184 if (w.value.integer)
1185 printf_filtered ("\nProgram exited with code 0%o.\n",
1186 (unsigned int) w.value.integer);
1188 printf_filtered ("\nProgram exited normally.\n");
1190 /* Record the exit code in the convenience variable $_exitcode, so
1191 that the user can inspect this again later. */
1192 set_internalvar (lookup_internalvar ("_exitcode"),
1193 value_from_longest (builtin_type_int,
1194 (LONGEST) w.value.integer));
1195 gdb_flush (gdb_stdout);
1196 target_mourn_inferior ();
1197 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P*/
1198 stop_print_frame = 0;
1201 case TARGET_WAITKIND_SIGNALLED:
1202 stop_print_frame = 0;
1203 stop_signal = w.value.sig;
1204 target_terminal_ours (); /* Must do this before mourn anyway */
1205 annotate_signalled ();
1207 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1208 mean it is already dead? This has been here since GDB 2.8, so
1209 perhaps it means rms didn't understand unix waitstatuses?
1210 For the moment I'm just kludging around this in remote.c
1211 rather than trying to change it here --kingdon, 5 Dec 1994. */
1212 target_kill (); /* kill mourns as well */
1214 printf_filtered ("\nProgram terminated with signal ");
1215 annotate_signal_name ();
1216 printf_filtered ("%s", target_signal_to_name (stop_signal));
1217 annotate_signal_name_end ();
1218 printf_filtered (", ");
1219 annotate_signal_string ();
1220 printf_filtered ("%s", target_signal_to_string (stop_signal));
1221 annotate_signal_string_end ();
1222 printf_filtered (".\n");
1224 printf_filtered ("The program no longer exists.\n");
1225 gdb_flush (gdb_stdout);
1226 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P*/
1229 /* The following are the only cases in which we keep going;
1230 the above cases end in a continue or goto. */
1231 case TARGET_WAITKIND_FORKED:
1232 stop_signal = TARGET_SIGNAL_TRAP;
1233 pending_follow.kind = w.kind;
1235 /* Ignore fork events reported for the parent; we're only
1236 interested in reacting to forks of the child. Note that
1237 we expect the child's fork event to be available if we
1238 waited for it now. */
1239 if (inferior_pid == pid)
1241 pending_follow.fork_event.saw_parent_fork = 1;
1242 pending_follow.fork_event.parent_pid = pid;
1243 pending_follow.fork_event.child_pid = w.value.related_pid;
1248 pending_follow.fork_event.saw_child_fork = 1;
1249 pending_follow.fork_event.child_pid = pid;
1250 pending_follow.fork_event.parent_pid = w.value.related_pid;
1253 stop_pc = read_pc_pid (pid);
1254 saved_inferior_pid = inferior_pid;
1256 stop_bpstat = bpstat_stop_status
1258 #if DECR_PC_AFTER_BREAK
1259 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1260 && CURRENTLY_STEPPING ())
1261 #else /* DECR_PC_AFTER_BREAK zero */
1263 #endif /* DECR_PC_AFTER_BREAK zero */
1265 random_signal = !bpstat_explains_signal (stop_bpstat);
1266 inferior_pid = saved_inferior_pid;
1267 goto process_event_stop_test;
1269 /* If this a platform which doesn't allow a debugger to touch a
1270 vfork'd inferior until after it exec's, then we'd best keep
1271 our fingers entirely off the inferior, other than continuing
1272 it. This has the unfortunate side-effect that catchpoints
1273 of vforks will be ignored. But since the platform doesn't
1274 allow the inferior be touched at vfork time, there's really
1276 case TARGET_WAITKIND_VFORKED:
1277 stop_signal = TARGET_SIGNAL_TRAP;
1278 pending_follow.kind = w.kind;
1280 /* Is this a vfork of the parent? If so, then give any
1281 vfork catchpoints a chance to trigger now. (It's
1282 dangerous to do so if the child canot be touched until
1283 it execs, and the child has not yet exec'd. We probably
1284 should warn the user to that effect when the catchpoint
1286 if (pid == inferior_pid)
1288 pending_follow.fork_event.saw_parent_fork = 1;
1289 pending_follow.fork_event.parent_pid = pid;
1290 pending_follow.fork_event.child_pid = w.value.related_pid;
1293 /* If we've seen the child's vfork event but cannot really touch
1294 the child until it execs, then we must continue the child now.
1295 Else, give any vfork catchpoints a chance to trigger now. */
1298 pending_follow.fork_event.saw_child_fork = 1;
1299 pending_follow.fork_event.child_pid = pid;
1300 pending_follow.fork_event.parent_pid = w.value.related_pid;
1301 target_post_startup_inferior (pending_follow.fork_event.child_pid);
1302 follow_vfork_when_exec = !target_can_follow_vfork_prior_to_exec ();
1303 if (follow_vfork_when_exec)
1305 target_resume (pid, 0, TARGET_SIGNAL_0);
1310 stop_pc = read_pc ();
1311 stop_bpstat = bpstat_stop_status
1313 #if DECR_PC_AFTER_BREAK
1314 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1315 && CURRENTLY_STEPPING ())
1316 #else /* DECR_PC_AFTER_BREAK zero */
1318 #endif /* DECR_PC_AFTER_BREAK zero */
1320 random_signal = !bpstat_explains_signal (stop_bpstat);
1321 goto process_event_stop_test;
1323 case TARGET_WAITKIND_EXECD:
1324 stop_signal = TARGET_SIGNAL_TRAP;
1326 /* Is this a target which reports multiple exec events per actual
1327 call to exec()? (HP-UX using ptrace does, for example.) If so,
1328 ignore all but the last one. Just resume the exec'r, and wait
1329 for the next exec event. */
1330 if (inferior_ignoring_leading_exec_events)
1332 inferior_ignoring_leading_exec_events--;
1333 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1334 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.parent_pid);
1335 target_resume (pid, 0, TARGET_SIGNAL_0);
1338 inferior_ignoring_leading_exec_events =
1339 target_reported_exec_events_per_exec_call () - 1;
1341 pending_follow.execd_pathname = savestring (w.value.execd_pathname,
1342 strlen (w.value.execd_pathname));
1344 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1345 child of a vfork exec?
1347 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1348 HP-UX, events associated with a vforking inferior come in
1349 threes: a vfork event for the child (always first), followed
1350 a vfork event for the parent and an exec event for the child.
1351 The latter two can come in either order.
1353 If we get the parent vfork event first, life's good: We follow
1354 either the parent or child, and then the child's exec event is
1357 But if we get the child's exec event first, then we delay
1358 responding to it until we handle the parent's vfork. Because,
1359 otherwise we can't satisfy a "catch vfork". */
1360 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1362 pending_follow.fork_event.saw_child_exec = 1;
1364 /* On some targets, the child must be resumed before
1365 the parent vfork event is delivered. A single-step
1367 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1368 target_resume (pid, 1, TARGET_SIGNAL_0);
1369 /* We expect the parent vfork event to be available now. */
1373 /* This causes the eventpoints and symbol table to be reset. Must
1374 do this now, before trying to determine whether to stop. */
1375 follow_exec (inferior_pid, pending_follow.execd_pathname);
1376 free (pending_follow.execd_pathname);
1378 stop_pc = read_pc_pid (pid);
1379 saved_inferior_pid = inferior_pid;
1381 stop_bpstat = bpstat_stop_status
1383 #if DECR_PC_AFTER_BREAK
1384 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1385 && CURRENTLY_STEPPING ())
1386 #else /* DECR_PC_AFTER_BREAK zero */
1388 #endif /* DECR_PC_AFTER_BREAK zero */
1390 random_signal = !bpstat_explains_signal (stop_bpstat);
1391 inferior_pid = saved_inferior_pid;
1392 goto process_event_stop_test;
1394 /* These syscall events are returned on HP-UX, as part of its
1395 implementation of page-protection-based "hardware" watchpoints.
1396 HP-UX has unfortunate interactions between page-protections and
1397 some system calls. Our solution is to disable hardware watches
1398 when a system call is entered, and reenable them when the syscall
1399 completes. The downside of this is that we may miss the precise
1400 point at which a watched piece of memory is modified. "Oh well."
1402 Note that we may have multiple threads running, which may each
1403 enter syscalls at roughly the same time. Since we don't have a
1404 good notion currently of whether a watched piece of memory is
1405 thread-private, we'd best not have any page-protections active
1406 when any thread is in a syscall. Thus, we only want to reenable
1407 hardware watches when no threads are in a syscall.
1409 Also, be careful not to try to gather much state about a thread
1410 that's in a syscall. It's frequently a losing proposition. */
1411 case TARGET_WAITKIND_SYSCALL_ENTRY:
1412 number_of_threads_in_syscalls++;
1413 if (number_of_threads_in_syscalls == 1)
1415 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid);
1417 resume (0, TARGET_SIGNAL_0);
1420 /* Before examining the threads further, step this thread to
1421 get it entirely out of the syscall. (We get notice of the
1422 event when the thread is just on the verge of exiting a
1423 syscall. Stepping one instruction seems to get it back
1426 Note that although the logical place to reenable h/w watches
1427 is here, we cannot. We cannot reenable them before stepping
1428 the thread (this causes the next wait on the thread to hang).
1430 Nor can we enable them after stepping until we've done a wait.
1431 Thus, we simply set the flag enable_hw_watchpoints_after_wait
1432 here, which will be serviced immediately after the target
1434 case TARGET_WAITKIND_SYSCALL_RETURN:
1435 target_resume (pid, 1, TARGET_SIGNAL_0);
1437 if (number_of_threads_in_syscalls > 0)
1439 number_of_threads_in_syscalls--;
1440 enable_hw_watchpoints_after_wait =
1441 (number_of_threads_in_syscalls == 0);
1445 case TARGET_WAITKIND_STOPPED:
1446 stop_signal = w.value.sig;
1450 /* We may want to consider not doing a resume here in order to give
1451 the user a chance to play with the new thread. It might be good
1452 to make that a user-settable option. */
1454 /* At this point, all threads are stopped (happens automatically in
1455 either the OS or the native code). Therefore we need to continue
1456 all threads in order to make progress. */
1457 if (new_thread_event)
1459 target_resume (-1, 0, TARGET_SIGNAL_0);
1463 stop_pc = read_pc_pid (pid);
1465 /* See if a thread hit a thread-specific breakpoint that was meant for
1466 another thread. If so, then step that thread past the breakpoint,
1469 if (stop_signal == TARGET_SIGNAL_TRAP)
1471 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1473 else if (breakpoints_inserted
1474 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
1477 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK,
1482 /* Saw a breakpoint, but it was hit by the wrong thread.
1484 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, pid);
1486 remove_status = remove_breakpoints ();
1487 /* Did we fail to remove breakpoints? If so, try
1488 to set the PC past the bp. (There's at least
1489 one situation in which we can fail to remove
1490 the bp's: On HP-UX's that use ttrace, we can't
1491 change the address space of a vforking child
1492 process until the child exits (well, okay, not
1493 then either :-) or execs. */
1494 if (remove_status != 0)
1496 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, pid);
1500 target_resume (pid, 1, TARGET_SIGNAL_0);
1501 /* FIXME: What if a signal arrives instead of the
1502 single-step happening? */
1504 if (target_wait_hook)
1505 target_wait_hook (pid, &w);
1507 target_wait (pid, &w);
1508 insert_breakpoints ();
1511 /* We need to restart all the threads now. */
1512 target_resume (-1, 0, TARGET_SIGNAL_0);
1517 /* This breakpoint matches--either it is the right
1518 thread or it's a generic breakpoint for all threads.
1519 Remember that we'll need to step just _this_ thread
1520 on any following user continuation! */
1521 thread_step_needed = 1;
1528 /* See if something interesting happened to the non-current thread. If
1529 so, then switch to that thread, and eventually give control back to
1532 Note that if there's any kind of pending follow (i.e., of a fork,
1533 vfork or exec), we don't want to do this now. Rather, we'll let
1534 the next resume handle it. */
1535 if ((pid != inferior_pid) &&
1536 (pending_follow.kind == TARGET_WAITKIND_SPURIOUS))
1540 /* If it's a random signal for a non-current thread, notify user
1541 if he's expressed an interest. */
1543 && signal_print[stop_signal])
1545 /* ??rehrauer: I don't understand the rationale for this code. If the
1546 inferior will stop as a result of this signal, then the act of handling
1547 the stop ought to print a message that's couches the stoppage in user
1548 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1549 won't stop as a result of the signal -- i.e., if the signal is merely
1550 a side-effect of something GDB's doing "under the covers" for the
1551 user, such as stepping threads over a breakpoint they shouldn't stop
1552 for -- then the message seems to be a serious annoyance at best.
1554 For now, remove the message altogether. */
1557 target_terminal_ours_for_output ();
1558 printf_filtered ("\nProgram received signal %s, %s.\n",
1559 target_signal_to_name (stop_signal),
1560 target_signal_to_string (stop_signal));
1561 gdb_flush (gdb_stdout);
1565 /* If it's not SIGTRAP and not a signal we want to stop for, then
1566 continue the thread. */
1568 if (stop_signal != TARGET_SIGNAL_TRAP
1569 && !signal_stop[stop_signal])
1572 target_terminal_inferior ();
1574 /* Clear the signal if it should not be passed. */
1575 if (signal_program[stop_signal] == 0)
1576 stop_signal = TARGET_SIGNAL_0;
1578 target_resume (pid, 0, stop_signal);
1582 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1583 and fall into the rest of wait_for_inferior(). */
1585 /* Save infrun state for the old thread. */
1586 save_infrun_state (inferior_pid, prev_pc,
1587 prev_func_start, prev_func_name,
1588 trap_expected, step_resume_breakpoint,
1589 through_sigtramp_breakpoint,
1590 step_range_start, step_range_end,
1591 step_frame_address, handling_longjmp,
1593 stepping_through_solib_after_catch,
1594 stepping_through_solib_catchpoints,
1595 stepping_through_sigtramp);
1598 switched_from_inferior_pid = inferior_pid;
1603 /* Load infrun state for the new thread. */
1604 load_infrun_state (inferior_pid, &prev_pc,
1605 &prev_func_start, &prev_func_name,
1606 &trap_expected, &step_resume_breakpoint,
1607 &through_sigtramp_breakpoint,
1608 &step_range_start, &step_range_end,
1609 &step_frame_address, &handling_longjmp,
1611 &stepping_through_solib_after_catch,
1612 &stepping_through_solib_catchpoints,
1613 &stepping_through_sigtramp);
1616 context_hook (pid_to_thread_id (pid));
1618 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid));
1619 flush_cached_frames ();
1622 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1624 /* Pull the single step breakpoints out of the target. */
1625 SOFTWARE_SINGLE_STEP (0, 0);
1626 singlestep_breakpoints_inserted_p = 0;
1629 /* If PC is pointing at a nullified instruction, then step beyond
1630 it so that the user won't be confused when GDB appears to be ready
1633 #if 0 /* XXX DEBUG */
1634 printf ("infrun.c:1607: pc = 0x%x\n", read_pc ());
1636 /* if (INSTRUCTION_NULLIFIED && CURRENTLY_STEPPING ()) */
1637 if (INSTRUCTION_NULLIFIED)
1639 struct target_waitstatus tmpstatus;
1641 all_registers_info ((char *) 0, 0);
1643 registers_changed ();
1644 target_resume (pid, 1, TARGET_SIGNAL_0);
1646 /* We may have received a signal that we want to pass to
1647 the inferior; therefore, we must not clobber the waitstatus
1648 in W. So we call wait ourselves, then continue the loop
1649 at the "have_waited" label. */
1650 if (target_wait_hook)
1651 target_wait_hook (pid, &tmpstatus);
1653 target_wait (pid, &tmpstatus);
1658 #ifdef HAVE_STEPPABLE_WATCHPOINT
1659 /* It may not be necessary to disable the watchpoint to stop over
1660 it. For example, the PA can (with some kernel cooperation)
1661 single step over a watchpoint without disabling the watchpoint. */
1662 if (STOPPED_BY_WATCHPOINT (w))
1669 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
1670 /* It is far more common to need to disable a watchpoint
1671 to step the inferior over it. FIXME. What else might
1672 a debug register or page protection watchpoint scheme need
1674 if (STOPPED_BY_WATCHPOINT (w))
1676 /* At this point, we are stopped at an instruction which has attempted to write
1677 to a piece of memory under control of a watchpoint. The instruction hasn't
1678 actually executed yet. If we were to evaluate the watchpoint expression
1679 now, we would get the old value, and therefore no change would seem to have
1682 In order to make watchpoints work `right', we really need to complete the
1683 memory write, and then evaluate the watchpoint expression. The following
1684 code does that by removing the watchpoint (actually, all watchpoints and
1685 breakpoints), single-stepping the target, re-inserting watchpoints, and then
1686 falling through to let normal single-step processing handle proceed. Since
1687 this includes evaluating watchpoints, things will come to a stop in the
1690 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
1692 remove_breakpoints ();
1693 registers_changed ();
1694 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
1696 if (target_wait_hook)
1697 target_wait_hook (pid, &w);
1699 target_wait (pid, &w);
1700 insert_breakpoints ();
1702 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1703 handle things like signals arriving and other things happening
1704 in combination correctly? */
1705 stepped_after_stopped_by_watchpoint = 1;
1710 #ifdef HAVE_CONTINUABLE_WATCHPOINT
1711 /* It may be possible to simply continue after a watchpoint. */
1712 STOPPED_BY_WATCHPOINT (w);
1715 stop_func_start = 0;
1718 /* Don't care about return value; stop_func_start and stop_func_name
1719 will both be 0 if it doesn't work. */
1720 find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start,
1722 stop_func_start += FUNCTION_START_OFFSET;
1724 bpstat_clear (&stop_bpstat);
1726 stop_stack_dummy = 0;
1727 stop_print_frame = 1;
1729 stopped_by_random_signal = 0;
1730 breakpoints_failed = 0;
1732 /* Look at the cause of the stop, and decide what to do.
1733 The alternatives are:
1734 1) break; to really stop and return to the debugger,
1735 2) drop through to start up again
1736 (set another_trap to 1 to single step once)
1737 3) set random_signal to 1, and the decision between 1 and 2
1738 will be made according to the signal handling tables. */
1740 /* First, distinguish signals caused by the debugger from signals
1741 that have to do with the program's own actions.
1742 Note that breakpoint insns may cause SIGTRAP or SIGILL
1743 or SIGEMT, depending on the operating system version.
1744 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1745 and change it to SIGTRAP. */
1747 if (stop_signal == TARGET_SIGNAL_TRAP
1748 || (breakpoints_inserted &&
1749 (stop_signal == TARGET_SIGNAL_ILL
1750 || stop_signal == TARGET_SIGNAL_EMT
1752 || stop_soon_quietly)
1754 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
1756 stop_print_frame = 0;
1759 if (stop_soon_quietly)
1762 /* Don't even think about breakpoints
1763 if just proceeded over a breakpoint.
1765 However, if we are trying to proceed over a breakpoint
1766 and end up in sigtramp, then through_sigtramp_breakpoint
1767 will be set and we should check whether we've hit the
1769 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
1770 && through_sigtramp_breakpoint == NULL)
1771 bpstat_clear (&stop_bpstat);
1774 /* See if there is a breakpoint at the current PC. */
1775 stop_bpstat = bpstat_stop_status
1777 (DECR_PC_AFTER_BREAK ?
1778 /* Notice the case of stepping through a jump
1779 that lands just after a breakpoint.
1780 Don't confuse that with hitting the breakpoint.
1781 What we check for is that 1) stepping is going on
1782 and 2) the pc before the last insn does not match
1783 the address of the breakpoint before the current pc
1784 and 3) we didn't hit a breakpoint in a signal handler
1785 without an intervening stop in sigtramp, which is
1786 detected by a new stack pointer value below
1787 any usual function calling stack adjustments. */
1788 (CURRENTLY_STEPPING ()
1789 && prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1791 && INNER_THAN (read_sp (), (step_sp - 16)))) :
1794 /* Following in case break condition called a
1796 stop_print_frame = 1;
1799 if (stop_signal == TARGET_SIGNAL_TRAP)
1801 = !(bpstat_explains_signal (stop_bpstat)
1803 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1804 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
1805 FRAME_FP (get_current_frame ()))
1806 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1807 || (step_range_end && step_resume_breakpoint == NULL));
1812 = !(bpstat_explains_signal (stop_bpstat)
1813 /* End of a stack dummy. Some systems (e.g. Sony
1814 news) give another signal besides SIGTRAP,
1815 so check here as well as above. */
1816 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1817 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
1818 FRAME_FP (get_current_frame ()))
1819 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1822 stop_signal = TARGET_SIGNAL_TRAP;
1826 /* When we reach this point, we've pretty much decided
1827 that the reason for stopping must've been a random
1828 (unexpected) signal. */
1832 /* If a fork, vfork or exec event was seen, then there are two
1833 possible responses we can make:
1835 1. If a catchpoint triggers for the event (random_signal == 0),
1836 then we must stop now and issue a prompt. We will resume
1837 the inferior when the user tells us to.
1838 2. If no catchpoint triggers for the event (random_signal == 1),
1839 then we must resume the inferior now and keep checking.
1841 In either case, we must take appropriate steps to "follow" the
1842 the fork/vfork/exec when the inferior is resumed. For example,
1843 if follow-fork-mode is "child", then we must detach from the
1844 parent inferior and follow the new child inferior.
1846 In either case, setting pending_follow causes the next resume()
1847 to take the appropriate following action. */
1848 process_event_stop_test:
1849 if (w.kind == TARGET_WAITKIND_FORKED)
1851 if (random_signal) /* I.e., no catchpoint triggered for this. */
1854 stop_signal = TARGET_SIGNAL_0;
1858 else if (w.kind == TARGET_WAITKIND_VFORKED)
1860 if (random_signal) /* I.e., no catchpoint triggered for this. */
1862 stop_signal = TARGET_SIGNAL_0;
1866 else if (w.kind == TARGET_WAITKIND_EXECD)
1868 pending_follow.kind = w.kind;
1869 if (random_signal) /* I.e., no catchpoint triggered for this. */
1872 stop_signal = TARGET_SIGNAL_0;
1877 /* For the program's own signals, act according to
1878 the signal handling tables. */
1882 /* Signal not for debugging purposes. */
1885 stopped_by_random_signal = 1;
1887 if (signal_print[stop_signal])
1890 target_terminal_ours_for_output ();
1892 printf_filtered ("\nProgram received signal ");
1893 annotate_signal_name ();
1894 printf_filtered ("%s", target_signal_to_name (stop_signal));
1895 annotate_signal_name_end ();
1896 printf_filtered (", ");
1897 annotate_signal_string ();
1898 printf_filtered ("%s", target_signal_to_string (stop_signal));
1899 annotate_signal_string_end ();
1900 printf_filtered (".\n");
1901 gdb_flush (gdb_stdout);
1903 if (signal_stop[stop_signal])
1905 /* If not going to stop, give terminal back
1906 if we took it away. */
1908 target_terminal_inferior ();
1910 /* Clear the signal if it should not be passed. */
1911 if (signal_program[stop_signal] == 0)
1912 stop_signal = TARGET_SIGNAL_0;
1914 /* If we're in the middle of a "next" command, let the code for
1915 stepping over a function handle this. pai/1997-09-10
1917 A previous comment here suggested it was possible to change
1918 this to jump to keep_going in all cases. */
1920 if (step_over_calls > 0)
1921 goto step_over_function;
1923 goto check_sigtramp2;
1926 /* Handle cases caused by hitting a breakpoint. */
1928 CORE_ADDR jmp_buf_pc;
1929 struct bpstat_what what;
1931 what = bpstat_what (stop_bpstat);
1933 if (what.call_dummy)
1935 stop_stack_dummy = 1;
1937 trap_expected_after_continue = 1;
1941 switch (what.main_action)
1943 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
1944 /* If we hit the breakpoint at longjmp, disable it for the
1945 duration of this command. Then, install a temporary
1946 breakpoint at the target of the jmp_buf. */
1947 disable_longjmp_breakpoint ();
1948 remove_breakpoints ();
1949 breakpoints_inserted = 0;
1950 if (!GET_LONGJMP_TARGET (&jmp_buf_pc))
1953 /* Need to blow away step-resume breakpoint, as it
1954 interferes with us */
1955 if (step_resume_breakpoint != NULL)
1957 delete_breakpoint (step_resume_breakpoint);
1958 step_resume_breakpoint = NULL;
1960 /* Not sure whether we need to blow this away too, but probably
1961 it is like the step-resume breakpoint. */
1962 if (through_sigtramp_breakpoint != NULL)
1964 delete_breakpoint (through_sigtramp_breakpoint);
1965 through_sigtramp_breakpoint = NULL;
1969 /* FIXME - Need to implement nested temporary breakpoints */
1970 if (step_over_calls > 0)
1971 set_longjmp_resume_breakpoint (jmp_buf_pc,
1972 get_current_frame ());
1975 set_longjmp_resume_breakpoint (jmp_buf_pc, NULL);
1976 handling_longjmp = 1; /* FIXME */
1979 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
1980 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
1981 remove_breakpoints ();
1982 breakpoints_inserted = 0;
1984 /* FIXME - Need to implement nested temporary breakpoints */
1986 && (INNER_THAN (FRAME_FP (get_current_frame ()),
1987 step_frame_address)))
1993 disable_longjmp_breakpoint ();
1994 handling_longjmp = 0; /* FIXME */
1995 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
1997 /* else fallthrough */
1999 case BPSTAT_WHAT_SINGLE:
2000 if (breakpoints_inserted)
2002 thread_step_needed = 1;
2003 remove_breakpoints ();
2005 breakpoints_inserted = 0;
2007 /* Still need to check other stuff, at least the case
2008 where we are stepping and step out of the right range. */
2011 case BPSTAT_WHAT_STOP_NOISY:
2012 stop_print_frame = 1;
2014 /* We are about to nuke the step_resume_breakpoint and
2015 through_sigtramp_breakpoint via the cleanup chain, so
2016 no need to worry about it here. */
2020 case BPSTAT_WHAT_STOP_SILENT:
2021 stop_print_frame = 0;
2023 /* We are about to nuke the step_resume_breakpoint and
2024 through_sigtramp_breakpoint via the cleanup chain, so
2025 no need to worry about it here. */
2029 case BPSTAT_WHAT_STEP_RESUME:
2030 /* This proably demands a more elegant solution, but, yeah
2033 This function's use of the simple variable
2034 step_resume_breakpoint doesn't seem to accomodate
2035 simultaneously active step-resume bp's, although the
2036 breakpoint list certainly can.
2038 If we reach here and step_resume_breakpoint is already
2039 NULL, then apparently we have multiple active
2040 step-resume bp's. We'll just delete the breakpoint we
2041 stopped at, and carry on. */
2042 if (step_resume_breakpoint == NULL)
2044 step_resume_breakpoint =
2045 bpstat_find_step_resume_breakpoint (stop_bpstat);
2047 delete_breakpoint (step_resume_breakpoint);
2048 step_resume_breakpoint = NULL;
2051 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2052 if (through_sigtramp_breakpoint)
2053 delete_breakpoint (through_sigtramp_breakpoint);
2054 through_sigtramp_breakpoint = NULL;
2056 /* If were waiting for a trap, hitting the step_resume_break
2057 doesn't count as getting it. */
2062 case BPSTAT_WHAT_CHECK_SHLIBS:
2063 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2066 extern int auto_solib_add;
2068 /* Remove breakpoints, we eventually want to step over the
2069 shlib event breakpoint, and SOLIB_ADD might adjust
2070 breakpoint addresses via breakpoint_re_set. */
2071 if (breakpoints_inserted)
2072 remove_breakpoints ();
2073 breakpoints_inserted = 0;
2075 /* Check for any newly added shared libraries if we're
2076 supposed to be adding them automatically. */
2079 /* Switch terminal for any messages produced by
2080 breakpoint_re_set. */
2081 target_terminal_ours_for_output ();
2082 SOLIB_ADD (NULL, 0, NULL);
2083 target_terminal_inferior ();
2086 /* Try to reenable shared library breakpoints, additional
2087 code segments in shared libraries might be mapped in now. */
2088 re_enable_breakpoints_in_shlibs ();
2090 /* If requested, stop when the dynamic linker notifies
2091 gdb of events. This allows the user to get control
2092 and place breakpoints in initializer routines for
2093 dynamically loaded objects (among other things). */
2094 if (stop_on_solib_events)
2096 stop_print_frame = 0;
2100 /* If we stopped due to an explicit catchpoint, then the
2101 (see above) call to SOLIB_ADD pulled in any symbols
2102 from a newly-loaded library, if appropriate.
2104 We do want the inferior to stop, but not where it is
2105 now, which is in the dynamic linker callback. Rather,
2106 we would like it stop in the user's program, just after
2107 the call that caused this catchpoint to trigger. That
2108 gives the user a more useful vantage from which to
2109 examine their program's state. */
2110 else if (what.main_action == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2112 /* ??rehrauer: If I could figure out how to get the
2113 right return PC from here, we could just set a temp
2114 breakpoint and resume. I'm not sure we can without
2115 cracking open the dld's shared libraries and sniffing
2116 their unwind tables and text/data ranges, and that's
2117 not a terribly portable notion.
2119 Until that time, we must step the inferior out of the
2120 dld callback, and also out of the dld itself (and any
2121 code or stubs in libdld.sl, such as "shl_load" and
2122 friends) until we reach non-dld code. At that point,
2123 we can stop stepping. */
2124 bpstat_get_triggered_catchpoints (stop_bpstat,
2125 &stepping_through_solib_catchpoints);
2126 stepping_through_solib_after_catch = 1;
2128 /* Be sure to lift all breakpoints, so the inferior does
2129 actually step past this point... */
2135 /* We want to step over this breakpoint, then keep going. */
2143 case BPSTAT_WHAT_LAST:
2144 /* Not a real code, but listed here to shut up gcc -Wall. */
2146 case BPSTAT_WHAT_KEEP_CHECKING:
2151 /* We come here if we hit a breakpoint but should not
2152 stop for it. Possibly we also were stepping
2153 and should stop for that. So fall through and
2154 test for stepping. But, if not stepping,
2157 /* Are we stepping to get the inferior out of the dynamic
2158 linker's hook (and possibly the dld itself) after catching
2160 if (stepping_through_solib_after_catch)
2162 #if defined(SOLIB_ADD)
2163 /* Have we reached our destination? If not, keep going. */
2164 if (SOLIB_IN_DYNAMIC_LINKER (pid, stop_pc))
2170 /* Else, stop and report the catchpoint(s) whose triggering
2171 caused us to begin stepping. */
2172 stepping_through_solib_after_catch = 0;
2173 bpstat_clear (&stop_bpstat);
2174 stop_bpstat = bpstat_copy (stepping_through_solib_catchpoints);
2175 bpstat_clear (&stepping_through_solib_catchpoints);
2176 stop_print_frame = 1;
2180 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
2181 /* This is the old way of detecting the end of the stack dummy.
2182 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2183 handled above. As soon as we can test it on all of them, all
2184 architectures should define it. */
2186 /* If this is the breakpoint at the end of a stack dummy,
2187 just stop silently, unless the user was doing an si/ni, in which
2188 case she'd better know what she's doing. */
2190 if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (),
2191 FRAME_FP (get_current_frame ()))
2194 stop_print_frame = 0;
2195 stop_stack_dummy = 1;
2197 trap_expected_after_continue = 1;
2201 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
2203 if (step_resume_breakpoint)
2204 /* Having a step-resume breakpoint overrides anything
2205 else having to do with stepping commands until
2206 that breakpoint is reached. */
2207 /* I'm not sure whether this needs to be check_sigtramp2 or
2208 whether it could/should be keep_going. */
2209 goto check_sigtramp2;
2211 if (step_range_end == 0)
2212 /* Likewise if we aren't even stepping. */
2213 /* I'm not sure whether this needs to be check_sigtramp2 or
2214 whether it could/should be keep_going. */
2215 goto check_sigtramp2;
2217 /* If stepping through a line, keep going if still within it.
2219 Note that step_range_end is the address of the first instruction
2220 beyond the step range, and NOT the address of the last instruction
2222 if (stop_pc >= step_range_start
2223 && stop_pc < step_range_end
2225 /* I haven't a clue what might trigger this clause, and it seems wrong
2226 anyway, so I've disabled it until someone complains. -Stu 10/24/95 */
2228 /* The step range might include the start of the
2229 function, so if we are at the start of the
2230 step range and either the stack or frame pointers
2231 just changed, we've stepped outside */
2232 && !(stop_pc == step_range_start
2233 && FRAME_FP (get_current_frame ())
2234 && (INNER_THAN (read_sp (), step_sp)
2235 || FRAME_FP (get_current_frame ()) != step_frame_address))
2239 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2240 So definately need to check for sigtramp here. */
2241 goto check_sigtramp2;
2244 /* We stepped out of the stepping range. */
2246 /* If we are stepping at the source level and entered the runtime
2247 loader dynamic symbol resolution code, we keep on single stepping
2248 until we exit the run time loader code and reach the callee's
2250 if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2253 /* We can't update step_sp every time through the loop, because
2254 reading the stack pointer would slow down stepping too much.
2255 But we can update it every time we leave the step range. */
2258 /* Did we just take a signal? */
2259 if (IN_SIGTRAMP (stop_pc, stop_func_name)
2260 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2261 && INNER_THAN (read_sp (), step_sp))
2263 /* We've just taken a signal; go until we are back to
2264 the point where we took it and one more. */
2266 /* Note: The test above succeeds not only when we stepped
2267 into a signal handler, but also when we step past the last
2268 statement of a signal handler and end up in the return stub
2269 of the signal handler trampoline. To distinguish between
2270 these two cases, check that the frame is INNER_THAN the
2271 previous one below. pai/1997-09-11 */
2275 CORE_ADDR current_frame = FRAME_FP (get_current_frame ());
2277 if (INNER_THAN (current_frame, step_frame_address))
2279 /* We have just taken a signal; go until we are back to
2280 the point where we took it and one more. */
2282 /* This code is needed at least in the following case:
2283 The user types "next" and then a signal arrives (before
2284 the "next" is done). */
2286 /* Note that if we are stopped at a breakpoint, then we need
2287 the step_resume breakpoint to override any breakpoints at
2288 the same location, so that we will still step over the
2289 breakpoint even though the signal happened. */
2290 struct symtab_and_line sr_sal;
2293 sr_sal.symtab = NULL;
2295 sr_sal.pc = prev_pc;
2296 /* We could probably be setting the frame to
2297 step_frame_address; I don't think anyone thought to
2299 step_resume_breakpoint =
2300 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2301 if (breakpoints_inserted)
2302 insert_breakpoints ();
2306 /* We just stepped out of a signal handler and into
2307 its calling trampoline.
2309 Normally, we'd jump to step_over_function from
2310 here, but for some reason GDB can't unwind the
2311 stack correctly to find the real PC for the point
2312 user code where the signal trampoline will return
2313 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2314 But signal trampolines are pretty small stubs of
2315 code, anyway, so it's OK instead to just
2316 single-step out. Note: assuming such trampolines
2317 don't exhibit recursion on any platform... */
2318 find_pc_partial_function (stop_pc, &stop_func_name,
2321 /* Readjust stepping range */
2322 step_range_start = stop_func_start;
2323 step_range_end = stop_func_end;
2324 stepping_through_sigtramp = 1;
2329 /* If this is stepi or nexti, make sure that the stepping range
2330 gets us past that instruction. */
2331 if (step_range_end == 1)
2332 /* FIXME: Does this run afoul of the code below which, if
2333 we step into the middle of a line, resets the stepping
2335 step_range_end = (step_range_start = prev_pc) + 1;
2337 remove_breakpoints_on_following_step = 1;
2342 /* I disabled this test because it was too complicated and slow.
2343 The SKIP_PROLOGUE was especially slow, because it caused
2344 unnecessary prologue examination on various architectures.
2345 The code in the #else clause has been tested on the Sparc,
2346 Mips, PA, and Power architectures, so it's pretty likely to
2347 be correct. -Stu 10/24/95 */
2349 /* See if we left the step range due to a subroutine call that
2350 we should proceed to the end of. */
2352 if (stop_func_start)
2356 /* Do this after the IN_SIGTRAMP check; it might give
2358 prologue_pc = stop_func_start;
2360 /* Don't skip the prologue if this is assembly source */
2361 s = find_pc_symtab (stop_pc);
2362 if (s && s->language != language_asm)
2363 SKIP_PROLOGUE (prologue_pc);
2366 if (!(INNER_THAN (step_sp, read_sp ())) /* don't mistake (sig)return
2368 && ( /* Might be a non-recursive call. If the symbols are missing
2369 enough that stop_func_start == prev_func_start even though
2370 they are really two functions, we will treat some calls as
2372 stop_func_start != prev_func_start
2374 /* Might be a recursive call if either we have a prologue
2375 or the call instruction itself saves the PC on the stack. */
2376 || prologue_pc != stop_func_start
2377 || read_sp () != step_sp)
2378 && ( /* PC is completely out of bounds of any known objfiles. Treat
2379 like a subroutine call. */
2382 /* If we do a call, we will be at the start of a function... */
2383 || stop_pc == stop_func_start
2385 /* ...except on the Alpha with -O (and also Irix 5 and
2386 perhaps others), in which we might call the address
2387 after the load of gp. Since prologues don't contain
2388 calls, we can't return to within one, and we don't
2389 jump back into them, so this check is OK. */
2391 || stop_pc < prologue_pc
2393 /* ...and if it is a leaf function, the prologue might
2394 consist of gp loading only, so the call transfers to
2395 the first instruction after the prologue. */
2396 || (stop_pc == prologue_pc
2398 /* Distinguish this from the case where we jump back
2399 to the first instruction after the prologue,
2400 within a function. */
2401 && stop_func_start != prev_func_start)
2403 /* If we end up in certain places, it means we did a subroutine
2404 call. I'm not completely sure this is necessary now that we
2405 have the above checks with stop_func_start (and now that
2406 find_pc_partial_function is pickier). */
2407 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
2409 /* If none of the above apply, it is a jump within a function,
2410 or a return from a subroutine. The other case is longjmp,
2411 which can no longer happen here as long as the
2412 handling_longjmp stuff is working. */
2415 /* This test is a much more streamlined, (but hopefully correct)
2416 replacement for the code above. It's been tested on the Sparc,
2417 Mips, PA, and Power architectures with good results. */
2419 if (stop_pc == stop_func_start /* Quick test */
2420 || (in_prologue (stop_pc, stop_func_start) &&
2421 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, stop_func_name))
2422 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
2423 || stop_func_name == 0)
2427 /* It's a subroutine call. */
2429 if (step_over_calls == 0)
2431 /* I presume that step_over_calls is only 0 when we're
2432 supposed to be stepping at the assembly language level
2433 ("stepi"). Just stop. */
2438 if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc))
2439 /* We're doing a "next". */
2440 goto step_over_function;
2442 /* If we are in a function call trampoline (a stub between
2443 the calling routine and the real function), locate the real
2444 function. That's what tells us (a) whether we want to step
2445 into it at all, and (b) what prologue we want to run to
2446 the end of, if we do step into it. */
2447 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2449 stop_func_start = tmp;
2452 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
2455 struct symtab_and_line xxx;
2456 /* Why isn't this s_a_l called "sr_sal", like all of the
2457 other s_a_l's where this code is duplicated? */
2458 INIT_SAL (&xxx); /* initialize to zeroes */
2460 xxx.section = find_pc_overlay (xxx.pc);
2461 step_resume_breakpoint =
2462 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
2463 insert_breakpoints ();
2468 /* If we have line number information for the function we
2469 are thinking of stepping into, step into it.
2471 If there are several symtabs at that PC (e.g. with include
2472 files), just want to know whether *any* of them have line
2473 numbers. find_pc_line handles this. */
2475 struct symtab_and_line tmp_sal;
2477 tmp_sal = find_pc_line (stop_func_start, 0);
2478 if (tmp_sal.line != 0)
2479 goto step_into_function;
2483 /* A subroutine call has happened. */
2485 /* Set a special breakpoint after the return */
2486 struct symtab_and_line sr_sal;
2489 sr_sal.symtab = NULL;
2492 /* If we came here after encountering a signal in the middle of
2493 a "next", use the stashed-away previous frame pc */
2495 = stopped_by_random_signal
2497 : ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2499 step_resume_breakpoint =
2500 set_momentary_breakpoint (sr_sal,
2501 stopped_by_random_signal ?
2502 NULL : get_current_frame (),
2505 /* We've just entered a callee, and we wish to resume until
2506 it returns to the caller. Setting a step_resume bp on
2507 the return PC will catch a return from the callee.
2509 However, if the callee is recursing, we want to be
2510 careful not to catch returns of those recursive calls,
2511 but of THIS instance of the call.
2513 To do this, we set the step_resume bp's frame to our
2514 current caller's frame (step_frame_address, which is
2515 set by the "next" or "until" command, before execution
2518 But ... don't do it if we're single-stepping out of a
2519 sigtramp, because the reason we're single-stepping is
2520 precisely because unwinding is a problem (HP-UX 10.20,
2521 e.g.) and the frame address is likely to be incorrect.
2522 No danger of sigtramp recursion. */
2524 if (stepping_through_sigtramp)
2526 step_resume_breakpoint->frame = (CORE_ADDR) NULL;
2527 stepping_through_sigtramp = 0;
2529 else if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
2530 step_resume_breakpoint->frame = step_frame_address;
2532 if (breakpoints_inserted)
2533 insert_breakpoints ();
2538 /* Subroutine call with source code we should not step over.
2539 Do step to the first line of code in it. */
2543 s = find_pc_symtab (stop_pc);
2544 if (s && s->language != language_asm)
2545 SKIP_PROLOGUE (stop_func_start);
2547 sal = find_pc_line (stop_func_start, 0);
2548 /* Use the step_resume_break to step until
2549 the end of the prologue, even if that involves jumps
2550 (as it seems to on the vax under 4.2). */
2551 /* If the prologue ends in the middle of a source line,
2552 continue to the end of that source line (if it is still
2553 within the function). Otherwise, just go to end of prologue. */
2554 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2555 /* no, don't either. It skips any code that's
2556 legitimately on the first line. */
2558 if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end)
2559 stop_func_start = sal.end;
2562 if (stop_func_start == stop_pc)
2564 /* We are already there: stop now. */
2569 /* Put the step-breakpoint there and go until there. */
2571 struct symtab_and_line sr_sal;
2573 INIT_SAL (&sr_sal); /* initialize to zeroes */
2574 sr_sal.pc = stop_func_start;
2575 sr_sal.section = find_pc_overlay (stop_func_start);
2576 /* Do not specify what the fp should be when we stop
2577 since on some machines the prologue
2578 is where the new fp value is established. */
2579 step_resume_breakpoint =
2580 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2581 if (breakpoints_inserted)
2582 insert_breakpoints ();
2584 /* And make sure stepping stops right away then. */
2585 step_range_end = step_range_start;
2590 /* We've wandered out of the step range. */
2592 sal = find_pc_line (stop_pc, 0);
2594 if (step_range_end == 1)
2596 /* It is stepi or nexti. We always want to stop stepping after
2602 /* If we're in the return path from a shared library trampoline,
2603 we want to proceed through the trampoline when stepping. */
2604 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, stop_func_name))
2608 /* Determine where this trampoline returns. */
2609 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2611 /* Only proceed through if we know where it's going. */
2614 /* And put the step-breakpoint there and go until there. */
2615 struct symtab_and_line sr_sal;
2617 INIT_SAL (&sr_sal); /* initialize to zeroes */
2619 sr_sal.section = find_pc_overlay (sr_sal.pc);
2620 /* Do not specify what the fp should be when we stop
2621 since on some machines the prologue
2622 is where the new fp value is established. */
2623 step_resume_breakpoint =
2624 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2625 if (breakpoints_inserted)
2626 insert_breakpoints ();
2628 /* Restart without fiddling with the step ranges or
2636 /* We have no line number information. That means to stop
2637 stepping (does this always happen right after one instruction,
2638 when we do "s" in a function with no line numbers,
2639 or can this happen as a result of a return or longjmp?). */
2644 if ((stop_pc == sal.pc)
2645 && (current_line != sal.line || current_symtab != sal.symtab))
2647 /* We are at the start of a different line. So stop. Note that
2648 we don't stop if we step into the middle of a different line.
2649 That is said to make things like for (;;) statements work
2655 /* We aren't done stepping.
2657 Optimize by setting the stepping range to the line.
2658 (We might not be in the original line, but if we entered a
2659 new line in mid-statement, we continue stepping. This makes
2660 things like for(;;) statements work better.) */
2662 if (stop_func_end && sal.end >= stop_func_end)
2664 /* If this is the last line of the function, don't keep stepping
2665 (it would probably step us out of the function).
2666 This is particularly necessary for a one-line function,
2667 in which after skipping the prologue we better stop even though
2668 we will be in mid-line. */
2672 step_range_start = sal.pc;
2673 step_range_end = sal.end;
2674 step_frame_address = FRAME_FP (get_current_frame ());
2675 current_line = sal.line;
2676 current_symtab = sal.symtab;
2678 /* In the case where we just stepped out of a function into the middle
2679 of a line of the caller, continue stepping, but step_frame_address
2680 must be modified to current frame */
2682 CORE_ADDR current_frame = FRAME_FP (get_current_frame ());
2683 if (!(INNER_THAN (current_frame, step_frame_address)))
2684 step_frame_address = current_frame;
2692 && IN_SIGTRAMP (stop_pc, stop_func_name)
2693 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2694 && INNER_THAN (read_sp (), step_sp))
2696 /* What has happened here is that we have just stepped the inferior
2697 with a signal (because it is a signal which shouldn't make
2698 us stop), thus stepping into sigtramp.
2700 So we need to set a step_resume_break_address breakpoint
2701 and continue until we hit it, and then step. FIXME: This should
2702 be more enduring than a step_resume breakpoint; we should know
2703 that we will later need to keep going rather than re-hitting
2704 the breakpoint here (see testsuite/gdb.t06/signals.exp where
2705 it says "exceedingly difficult"). */
2706 struct symtab_and_line sr_sal;
2708 INIT_SAL (&sr_sal); /* initialize to zeroes */
2709 sr_sal.pc = prev_pc;
2710 sr_sal.section = find_pc_overlay (sr_sal.pc);
2711 /* We perhaps could set the frame if we kept track of what
2712 the frame corresponding to prev_pc was. But we don't,
2714 through_sigtramp_breakpoint =
2715 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
2716 if (breakpoints_inserted)
2717 insert_breakpoints ();
2719 remove_breakpoints_on_following_step = 1;
2724 /* Come to this label when you need to resume the inferior.
2725 It's really much cleaner to do a goto than a maze of if-else
2728 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug
2729 a vforked child beetween its creation and subsequent exit or
2730 call to exec(). However, I had big problems in this rather
2731 creaky exec engine, getting that to work. The fundamental
2732 problem is that I'm trying to debug two processes via an
2733 engine that only understands a single process with possibly
2736 Hence, this spot is known to have problems when
2737 target_can_follow_vfork_prior_to_exec returns 1. */
2739 /* Save the pc before execution, to compare with pc after stop. */
2740 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
2741 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
2742 BREAK is defined, the
2743 original pc would not have
2744 been at the start of a
2746 prev_func_name = stop_func_name;
2749 step_sp = read_sp ();
2752 /* If we did not do break;, it means we should keep
2753 running the inferior and not return to debugger. */
2755 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
2757 /* We took a signal (which we are supposed to pass through to
2758 the inferior, else we'd have done a break above) and we
2759 haven't yet gotten our trap. Simply continue. */
2760 resume (CURRENTLY_STEPPING (), stop_signal);
2764 /* Either the trap was not expected, but we are continuing
2765 anyway (the user asked that this signal be passed to the
2768 The signal was SIGTRAP, e.g. it was our signal, but we
2769 decided we should resume from it.
2771 We're going to run this baby now!
2773 Insert breakpoints now, unless we are trying
2774 to one-proceed past a breakpoint. */
2775 /* If we've just finished a special step resume and we don't
2776 want to hit a breakpoint, pull em out. */
2777 if (step_resume_breakpoint == NULL
2778 && through_sigtramp_breakpoint == NULL
2779 && remove_breakpoints_on_following_step)
2781 remove_breakpoints_on_following_step = 0;
2782 remove_breakpoints ();
2783 breakpoints_inserted = 0;
2785 else if (!breakpoints_inserted &&
2786 (through_sigtramp_breakpoint != NULL || !another_trap))
2788 breakpoints_failed = insert_breakpoints ();
2789 if (breakpoints_failed)
2791 breakpoints_inserted = 1;
2794 trap_expected = another_trap;
2796 /* Do not deliver SIGNAL_TRAP (except when the user
2797 explicitly specifies that such a signal should be
2798 delivered to the target program).
2800 Typically, this would occure when a user is debugging a
2801 target monitor on a simulator: the target monitor sets a
2802 breakpoint; the simulator encounters this break-point and
2803 halts the simulation handing control to GDB; GDB, noteing
2804 that the break-point isn't valid, returns control back to
2805 the simulator; the simulator then delivers the hardware
2806 equivalent of a SIGNAL_TRAP to the program being
2809 if (stop_signal == TARGET_SIGNAL_TRAP
2810 && !signal_program[stop_signal])
2811 stop_signal = TARGET_SIGNAL_0;
2813 #ifdef SHIFT_INST_REGS
2814 /* I'm not sure when this following segment applies. I do know,
2815 now, that we shouldn't rewrite the regs when we were stopped
2816 by a random signal from the inferior process. */
2817 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2818 (this is only used on the 88k). */
2820 if (!bpstat_explains_signal (stop_bpstat)
2821 && (stop_signal != TARGET_SIGNAL_CHLD)
2822 && !stopped_by_random_signal)
2824 #endif /* SHIFT_INST_REGS */
2826 resume (CURRENTLY_STEPPING (), stop_signal);
2831 if (target_has_execution)
2833 /* Are we stopping for a vfork event? We only stop when we see
2834 the child's event. However, we may not yet have seen the
2835 parent's event. And, inferior_pid is still set to the parent's
2836 pid, until we resume again and follow either the parent or child.
2838 To ensure that we can really touch inferior_pid (aka, the
2839 parent process) -- which calls to functions like read_pc
2840 implicitly do -- wait on the parent if necessary. */
2841 if ((pending_follow.kind == TARGET_WAITKIND_VFORKED)
2842 && !pending_follow.fork_event.saw_parent_fork)
2848 if (target_wait_hook)
2849 parent_pid = target_wait_hook (-1, &w);
2851 parent_pid = target_wait (-1, &w);
2853 while (parent_pid != inferior_pid);
2857 /* Assuming the inferior still exists, set these up for next
2858 time, just like we did above if we didn't break out of the
2860 prev_pc = read_pc ();
2861 prev_func_start = stop_func_start;
2862 prev_func_name = stop_func_name;
2864 do_cleanups (old_cleanups);
2867 /* This function returns TRUE if ep is an internal breakpoint
2868 set to catch generic shared library (aka dynamically-linked
2869 library) events. (This is *NOT* the same as a catchpoint for a
2870 shlib event. The latter is something a user can set; this is
2871 something gdb sets for its own use, and isn't ever shown to a
2874 is_internal_shlib_eventpoint (ep)
2875 struct breakpoint *ep;
2878 (ep->type == bp_shlib_event)
2882 /* This function returns TRUE if bs indicates that the inferior
2883 stopped due to a shared library (aka dynamically-linked library)
2886 stopped_for_internal_shlib_event (bs)
2889 /* Note that multiple eventpoints may've caused the stop. Any
2890 that are associated with shlib events will be accepted. */
2891 for (; bs != NULL; bs = bs->next)
2893 if ((bs->breakpoint_at != NULL)
2894 && is_internal_shlib_eventpoint (bs->breakpoint_at))
2898 /* If we get here, then no candidate was found. */
2902 /* This function returns TRUE if bs indicates that the inferior
2903 stopped due to a shared library (aka dynamically-linked library)
2904 event caught by a catchpoint.
2906 If TRUE, cp_p is set to point to the catchpoint.
2908 Else, the value of cp_p is undefined. */
2910 stopped_for_shlib_catchpoint (bs, cp_p)
2912 struct breakpoint **cp_p;
2914 /* Note that multiple eventpoints may've caused the stop. Any
2915 that are associated with shlib events will be accepted. */
2918 for (; bs != NULL; bs = bs->next)
2920 if ((bs->breakpoint_at != NULL)
2921 && ep_is_shlib_catchpoint (bs->breakpoint_at))
2923 *cp_p = bs->breakpoint_at;
2928 /* If we get here, then no candidate was found. */
2933 /* Here to return control to GDB when the inferior stops for real.
2934 Print appropriate messages, remove breakpoints, give terminal our modes.
2936 STOP_PRINT_FRAME nonzero means print the executing frame
2937 (pc, function, args, file, line number and line text).
2938 BREAKPOINTS_FAILED nonzero means stop was due to error
2939 attempting to insert breakpoints. */
2946 /* As with the notification of thread events, we want to delay
2947 notifying the user that we've switched thread context until
2948 the inferior actually stops.
2950 (Note that there's no point in saying anything if the inferior
2952 if ((switched_from_inferior_pid != inferior_pid) &&
2953 target_has_execution)
2955 target_terminal_ours_for_output ();
2956 printf_filtered ("[Switched to %s]\n",
2957 target_pid_or_tid_to_str (inferior_pid));
2958 switched_from_inferior_pid = inferior_pid;
2962 /* Make sure that the current_frame's pc is correct. This
2963 is a correction for setting up the frame info before doing
2964 DECR_PC_AFTER_BREAK */
2965 if (target_has_execution && get_current_frame ())
2966 (get_current_frame ())->pc = read_pc ();
2968 if (breakpoints_failed)
2970 target_terminal_ours_for_output ();
2971 print_sys_errmsg ("ptrace", breakpoints_failed);
2972 printf_filtered ("Stopped; cannot insert breakpoints.\n\
2973 The same program may be running in another process.\n");
2976 if (target_has_execution && breakpoints_inserted)
2978 if (remove_breakpoints ())
2980 target_terminal_ours_for_output ();
2981 printf_filtered ("Cannot remove breakpoints because ");
2982 printf_filtered ("program is no longer writable.\n");
2983 printf_filtered ("It might be running in another process.\n");
2984 printf_filtered ("Further execution is probably impossible.\n");
2987 breakpoints_inserted = 0;
2989 /* Delete the breakpoint we stopped at, if it wants to be deleted.
2990 Delete any breakpoint that is to be deleted at the next stop. */
2992 breakpoint_auto_delete (stop_bpstat);
2994 /* If an auto-display called a function and that got a signal,
2995 delete that auto-display to avoid an infinite recursion. */
2997 if (stopped_by_random_signal)
2998 disable_current_display ();
3000 /* Don't print a message if in the middle of doing a "step n"
3001 operation for n > 1 */
3002 if (step_multi && stop_step)
3005 target_terminal_ours ();
3007 /* Did we stop because the user set the stop_on_solib_events
3008 variable? (If so, we report this as a generic, "Stopped due
3009 to shlib event" message.) */
3010 if (stopped_for_internal_shlib_event (stop_bpstat))
3012 printf_filtered ("Stopped due to shared library event\n");
3015 /* Look up the hook_stop and run it if it exists. */
3017 if (stop_command && stop_command->hook)
3019 catch_errors (hook_stop_stub, stop_command->hook,
3020 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3023 if (!target_has_stack)
3029 /* Select innermost stack frame - i.e., current frame is frame 0,
3030 and current location is based on that.
3031 Don't do this on return from a stack dummy routine,
3032 or if the program has exited. */
3034 if (!stop_stack_dummy)
3036 select_frame (get_current_frame (), 0);
3038 /* Print current location without a level number, if
3039 we have changed functions or hit a breakpoint.
3040 Print source line if we have one.
3041 bpstat_print() contains the logic deciding in detail
3042 what to print, based on the event(s) that just occurred. */
3044 if (stop_print_frame)
3049 bpstat_ret = bpstat_print (stop_bpstat);
3050 /* bpstat_print() returned one of:
3051 -1: Didn't print anything
3052 0: Printed preliminary "Breakpoint n, " message, desires
3054 1: Printed something, don't tack on location */
3056 if (bpstat_ret == -1)
3058 && step_frame_address == FRAME_FP (get_current_frame ())
3059 && step_start_function == find_pc_function (stop_pc))
3060 source_flag = -1; /* finished step, just print source line */
3062 source_flag = 1; /* print location and source line */
3063 else if (bpstat_ret == 0) /* hit bpt, desire location */
3064 source_flag = 1; /* print location and source line */
3065 else /* bpstat_ret == 1, hit bpt, do not desire location */
3066 source_flag = -1; /* just print source line */
3068 /* The behavior of this routine with respect to the source
3070 -1: Print only source line
3071 0: Print only location
3072 1: Print location and source line */
3073 show_and_print_stack_frame (selected_frame, -1, source_flag);
3075 /* Display the auto-display expressions. */
3080 /* Save the function value return registers, if we care.
3081 We might be about to restore their previous contents. */
3082 if (proceed_to_finish)
3083 read_register_bytes (0, stop_registers, REGISTER_BYTES);
3085 if (stop_stack_dummy)
3087 /* Pop the empty frame that contains the stack dummy.
3088 POP_FRAME ends with a setting of the current frame, so we
3089 can use that next. */
3091 /* Set stop_pc to what it was before we called the function.
3092 Can't rely on restore_inferior_status because that only gets
3093 called if we don't stop in the called function. */
3094 stop_pc = read_pc ();
3095 select_frame (get_current_frame (), 0);
3099 TUIDO (((TuiOpaqueFuncPtr) tui_vCheckDataValues, selected_frame));
3102 annotate_stopped ();
3106 hook_stop_stub (cmd)
3109 execute_user_command ((struct cmd_list_element *) cmd, 0);
3114 signal_stop_state (signo)
3117 return signal_stop[signo];
3121 signal_print_state (signo)
3124 return signal_print[signo];
3128 signal_pass_state (signo)
3131 return signal_program[signo];
3138 Signal Stop\tPrint\tPass to program\tDescription\n");
3142 sig_print_info (oursig)
3143 enum target_signal oursig;
3145 char *name = target_signal_to_name (oursig);
3146 int name_padding = 13 - strlen (name);
3147 if (name_padding <= 0)
3150 printf_filtered ("%s", name);
3151 printf_filtered ("%*.*s ", name_padding, name_padding,
3153 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3154 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3155 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3156 printf_filtered ("%s\n", target_signal_to_string (oursig));
3159 /* Specify how various signals in the inferior should be handled. */
3162 handle_command (args, from_tty)
3167 int digits, wordlen;
3168 int sigfirst, signum, siglast;
3169 enum target_signal oursig;
3172 unsigned char *sigs;
3173 struct cleanup *old_chain;
3177 error_no_arg ("signal to handle");
3180 /* Allocate and zero an array of flags for which signals to handle. */
3182 nsigs = (int) TARGET_SIGNAL_LAST;
3183 sigs = (unsigned char *) alloca (nsigs);
3184 memset (sigs, 0, nsigs);
3186 /* Break the command line up into args. */
3188 argv = buildargv (args);
3193 old_chain = make_cleanup ((make_cleanup_func) freeargv, (char *) argv);
3195 /* Walk through the args, looking for signal oursigs, signal names, and
3196 actions. Signal numbers and signal names may be interspersed with
3197 actions, with the actions being performed for all signals cumulatively
3198 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3200 while (*argv != NULL)
3202 wordlen = strlen (*argv);
3203 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3207 sigfirst = siglast = -1;
3209 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3211 /* Apply action to all signals except those used by the
3212 debugger. Silently skip those. */
3215 siglast = nsigs - 1;
3217 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3219 SET_SIGS (nsigs, sigs, signal_stop);
3220 SET_SIGS (nsigs, sigs, signal_print);
3222 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3224 UNSET_SIGS (nsigs, sigs, signal_program);
3226 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3228 SET_SIGS (nsigs, sigs, signal_print);
3230 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3232 SET_SIGS (nsigs, sigs, signal_program);
3234 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3236 UNSET_SIGS (nsigs, sigs, signal_stop);
3238 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3240 SET_SIGS (nsigs, sigs, signal_program);
3242 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3244 UNSET_SIGS (nsigs, sigs, signal_print);
3245 UNSET_SIGS (nsigs, sigs, signal_stop);
3247 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3249 UNSET_SIGS (nsigs, sigs, signal_program);
3251 else if (digits > 0)
3253 /* It is numeric. The numeric signal refers to our own
3254 internal signal numbering from target.h, not to host/target
3255 signal number. This is a feature; users really should be
3256 using symbolic names anyway, and the common ones like
3257 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3259 sigfirst = siglast = (int)
3260 target_signal_from_command (atoi (*argv));
3261 if ((*argv)[digits] == '-')
3264 target_signal_from_command (atoi ((*argv) + digits + 1));
3266 if (sigfirst > siglast)
3268 /* Bet he didn't figure we'd think of this case... */
3276 oursig = target_signal_from_name (*argv);
3277 if (oursig != TARGET_SIGNAL_UNKNOWN)
3279 sigfirst = siglast = (int) oursig;
3283 /* Not a number and not a recognized flag word => complain. */
3284 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3288 /* If any signal numbers or symbol names were found, set flags for
3289 which signals to apply actions to. */
3291 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3293 switch ((enum target_signal) signum)
3295 case TARGET_SIGNAL_TRAP:
3296 case TARGET_SIGNAL_INT:
3297 if (!allsigs && !sigs[signum])
3299 if (query ("%s is used by the debugger.\n\
3300 Are you sure you want to change it? ",
3301 target_signal_to_name
3302 ((enum target_signal) signum)))
3308 printf_unfiltered ("Not confirmed, unchanged.\n");
3309 gdb_flush (gdb_stdout);
3313 case TARGET_SIGNAL_0:
3314 case TARGET_SIGNAL_DEFAULT:
3315 case TARGET_SIGNAL_UNKNOWN:
3316 /* Make sure that "all" doesn't print these. */
3327 target_notice_signals (inferior_pid);
3331 /* Show the results. */
3332 sig_print_header ();
3333 for (signum = 0; signum < nsigs; signum++)
3337 sig_print_info (signum);
3342 do_cleanups (old_chain);
3346 xdb_handle_command (args, from_tty)
3351 struct cleanup *old_chain;
3353 /* Break the command line up into args. */
3355 argv = buildargv (args);
3360 old_chain = make_cleanup ((make_cleanup_func) freeargv, (char *) argv);
3361 if (argv[1] != (char *) NULL)
3366 bufLen = strlen (argv[0]) + 20;
3367 argBuf = (char *) xmalloc (bufLen);
3371 enum target_signal oursig;
3373 oursig = target_signal_from_name (argv[0]);
3374 memset (argBuf, 0, bufLen);
3375 if (strcmp (argv[1], "Q") == 0)
3376 sprintf (argBuf, "%s %s", argv[0], "noprint");
3379 if (strcmp (argv[1], "s") == 0)
3381 if (!signal_stop[oursig])
3382 sprintf (argBuf, "%s %s", argv[0], "stop");
3384 sprintf (argBuf, "%s %s", argv[0], "nostop");
3386 else if (strcmp (argv[1], "i") == 0)
3388 if (!signal_program[oursig])
3389 sprintf (argBuf, "%s %s", argv[0], "pass");
3391 sprintf (argBuf, "%s %s", argv[0], "nopass");
3393 else if (strcmp (argv[1], "r") == 0)
3395 if (!signal_print[oursig])
3396 sprintf (argBuf, "%s %s", argv[0], "print");
3398 sprintf (argBuf, "%s %s", argv[0], "noprint");
3404 handle_command (argBuf, from_tty);
3406 printf_filtered ("Invalid signal handling flag.\n");
3411 do_cleanups (old_chain);
3414 /* Print current contents of the tables set by the handle command.
3415 It is possible we should just be printing signals actually used
3416 by the current target (but for things to work right when switching
3417 targets, all signals should be in the signal tables). */
3420 signals_info (signum_exp, from_tty)
3424 enum target_signal oursig;
3425 sig_print_header ();
3429 /* First see if this is a symbol name. */
3430 oursig = target_signal_from_name (signum_exp);
3431 if (oursig == TARGET_SIGNAL_UNKNOWN)
3433 /* No, try numeric. */
3435 target_signal_from_command (parse_and_eval_address (signum_exp));
3437 sig_print_info (oursig);
3441 printf_filtered ("\n");
3442 /* These ugly casts brought to you by the native VAX compiler. */
3443 for (oursig = TARGET_SIGNAL_FIRST;
3444 (int) oursig < (int) TARGET_SIGNAL_LAST;
3445 oursig = (enum target_signal) ((int) oursig + 1))
3449 if (oursig != TARGET_SIGNAL_UNKNOWN
3450 && oursig != TARGET_SIGNAL_DEFAULT
3451 && oursig != TARGET_SIGNAL_0)
3452 sig_print_info (oursig);
3455 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3458 /* Save all of the information associated with the inferior<==>gdb
3459 connection. INF_STATUS is a pointer to a "struct inferior_status"
3460 (defined in inferior.h). */
3463 save_inferior_status (inf_status, restore_stack_info)
3464 struct inferior_status *inf_status;
3465 int restore_stack_info;
3467 inf_status->stop_signal = stop_signal;
3468 inf_status->stop_pc = stop_pc;
3469 inf_status->stop_step = stop_step;
3470 inf_status->stop_stack_dummy = stop_stack_dummy;
3471 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3472 inf_status->trap_expected = trap_expected;
3473 inf_status->step_range_start = step_range_start;
3474 inf_status->step_range_end = step_range_end;
3475 inf_status->step_frame_address = step_frame_address;
3476 inf_status->step_over_calls = step_over_calls;
3477 inf_status->stop_after_trap = stop_after_trap;
3478 inf_status->stop_soon_quietly = stop_soon_quietly;
3479 /* Save original bpstat chain here; replace it with copy of chain.
3480 If caller's caller is walking the chain, they'll be happier if we
3481 hand them back the original chain when restore_i_s is called. */
3482 inf_status->stop_bpstat = stop_bpstat;
3483 stop_bpstat = bpstat_copy (stop_bpstat);
3484 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3485 inf_status->restore_stack_info = restore_stack_info;
3486 inf_status->proceed_to_finish = proceed_to_finish;
3488 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
3490 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3492 record_selected_frame (&(inf_status->selected_frame_address),
3493 &(inf_status->selected_level));
3497 struct restore_selected_frame_args
3499 CORE_ADDR frame_address;
3503 static int restore_selected_frame PARAMS ((PTR));
3505 /* Restore the selected frame. args is really a struct
3506 restore_selected_frame_args * (declared as char * for catch_errors)
3507 telling us what frame to restore. Returns 1 for success, or 0 for
3508 failure. An error message will have been printed on error. */
3511 restore_selected_frame (args)
3514 struct restore_selected_frame_args *fr =
3515 (struct restore_selected_frame_args *) args;
3516 struct frame_info *frame;
3517 int level = fr->level;
3519 frame = find_relative_frame (get_current_frame (), &level);
3521 /* If inf_status->selected_frame_address is NULL, there was no
3522 previously selected frame. */
3523 if (frame == NULL ||
3524 /* FRAME_FP (frame) != fr->frame_address || */
3525 /* elz: deleted this check as a quick fix to the problem that
3526 for function called by hand gdb creates no internal frame
3527 structure and the real stack and gdb's idea of stack are
3528 different if nested calls by hands are made.
3530 mvs: this worries me. */
3533 warning ("Unable to restore previously selected frame.\n");
3537 select_frame (frame, fr->level);
3543 restore_inferior_status (inf_status)
3544 struct inferior_status *inf_status;
3546 stop_signal = inf_status->stop_signal;
3547 stop_pc = inf_status->stop_pc;
3548 stop_step = inf_status->stop_step;
3549 stop_stack_dummy = inf_status->stop_stack_dummy;
3550 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3551 trap_expected = inf_status->trap_expected;
3552 step_range_start = inf_status->step_range_start;
3553 step_range_end = inf_status->step_range_end;
3554 step_frame_address = inf_status->step_frame_address;
3555 step_over_calls = inf_status->step_over_calls;
3556 stop_after_trap = inf_status->stop_after_trap;
3557 stop_soon_quietly = inf_status->stop_soon_quietly;
3558 bpstat_clear (&stop_bpstat);
3559 stop_bpstat = inf_status->stop_bpstat;
3560 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3561 proceed_to_finish = inf_status->proceed_to_finish;
3563 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
3565 /* The inferior can be gone if the user types "print exit(0)"
3566 (and perhaps other times). */
3567 if (target_has_execution)
3568 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3570 /* The inferior can be gone if the user types "print exit(0)"
3571 (and perhaps other times). */
3573 /* FIXME: If we are being called after stopping in a function which
3574 is called from gdb, we should not be trying to restore the
3575 selected frame; it just prints a spurious error message (The
3576 message is useful, however, in detecting bugs in gdb (like if gdb
3577 clobbers the stack)). In fact, should we be restoring the
3578 inferior status at all in that case? . */
3580 if (target_has_stack && inf_status->restore_stack_info)
3582 struct restore_selected_frame_args fr;
3583 fr.level = inf_status->selected_level;
3584 fr.frame_address = inf_status->selected_frame_address;
3585 /* The point of catch_errors is that if the stack is clobbered,
3586 walking the stack might encounter a garbage pointer and error()
3587 trying to dereference it. */
3588 if (catch_errors (restore_selected_frame, &fr,
3589 "Unable to restore previously selected frame:\n",
3590 RETURN_MASK_ERROR) == 0)
3591 /* Error in restoring the selected frame. Select the innermost
3595 select_frame (get_current_frame (), 0);
3603 set_follow_fork_mode_command (arg, from_tty, c)
3606 struct cmd_list_element *c;
3608 if (!STREQ (arg, "parent") &&
3609 !STREQ (arg, "child") &&
3610 !STREQ (arg, "both") &&
3611 !STREQ (arg, "ask"))
3612 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
3614 if (follow_fork_mode_string != NULL)
3615 free (follow_fork_mode_string);
3616 follow_fork_mode_string = savestring (arg, strlen (arg));
3622 _initialize_infrun ()
3625 register int numsigs;
3626 struct cmd_list_element *c;
3628 add_info ("signals", signals_info,
3629 "What debugger does when program gets various signals.\n\
3630 Specify a signal as argument to print info on that signal only.");
3631 add_info_alias ("handle", "signals", 0);
3633 add_com ("handle", class_run, handle_command,
3634 concat ("Specify how to handle a signal.\n\
3635 Args are signals and actions to apply to those signals.\n\
3636 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3637 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3638 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3639 The special arg \"all\" is recognized to mean all signals except those\n\
3640 used by the debugger, typically SIGTRAP and SIGINT.\n",
3641 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3642 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3643 Stop means reenter debugger if this signal happens (implies print).\n\
3644 Print means print a message if this signal happens.\n\
3645 Pass means let program see this signal; otherwise program doesn't know.\n\
3646 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3647 Pass and Stop may be combined.", NULL));
3650 add_com ("lz", class_info, signals_info,
3651 "What debugger does when program gets various signals.\n\
3652 Specify a signal as argument to print info on that signal only.");
3653 add_com ("z", class_run, xdb_handle_command,
3654 concat ("Specify how to handle a signal.\n\
3655 Args are signals and actions to apply to those signals.\n\
3656 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3657 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3658 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3659 The special arg \"all\" is recognized to mean all signals except those\n\
3660 used by the debugger, typically SIGTRAP and SIGINT.\n",
3661 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3662 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3663 nopass), \"Q\" (noprint)\n\
3664 Stop means reenter debugger if this signal happens (implies print).\n\
3665 Print means print a message if this signal happens.\n\
3666 Pass means let program see this signal; otherwise program doesn't know.\n\
3667 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3668 Pass and Stop may be combined.", NULL));
3672 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
3673 "There is no `stop' command, but you can set a hook on `stop'.\n\
3674 This allows you to set a list of commands to be run each time execution\n\
3675 of the program stops.", &cmdlist);
3677 numsigs = (int) TARGET_SIGNAL_LAST;
3678 signal_stop = (unsigned char *)
3679 xmalloc (sizeof (signal_stop[0]) * numsigs);
3680 signal_print = (unsigned char *)
3681 xmalloc (sizeof (signal_print[0]) * numsigs);
3682 signal_program = (unsigned char *)
3683 xmalloc (sizeof (signal_program[0]) * numsigs);
3684 for (i = 0; i < numsigs; i++)
3687 signal_print[i] = 1;
3688 signal_program[i] = 1;
3691 /* Signals caused by debugger's own actions
3692 should not be given to the program afterwards. */
3693 signal_program[TARGET_SIGNAL_TRAP] = 0;
3694 signal_program[TARGET_SIGNAL_INT] = 0;
3696 /* Signals that are not errors should not normally enter the debugger. */
3697 signal_stop[TARGET_SIGNAL_ALRM] = 0;
3698 signal_print[TARGET_SIGNAL_ALRM] = 0;
3699 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
3700 signal_print[TARGET_SIGNAL_VTALRM] = 0;
3701 signal_stop[TARGET_SIGNAL_PROF] = 0;
3702 signal_print[TARGET_SIGNAL_PROF] = 0;
3703 signal_stop[TARGET_SIGNAL_CHLD] = 0;
3704 signal_print[TARGET_SIGNAL_CHLD] = 0;
3705 signal_stop[TARGET_SIGNAL_IO] = 0;
3706 signal_print[TARGET_SIGNAL_IO] = 0;
3707 signal_stop[TARGET_SIGNAL_POLL] = 0;
3708 signal_print[TARGET_SIGNAL_POLL] = 0;
3709 signal_stop[TARGET_SIGNAL_URG] = 0;
3710 signal_print[TARGET_SIGNAL_URG] = 0;
3711 signal_stop[TARGET_SIGNAL_WINCH] = 0;
3712 signal_print[TARGET_SIGNAL_WINCH] = 0;
3716 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
3717 (char *) &stop_on_solib_events,
3718 "Set stopping for shared library events.\n\
3719 If nonzero, gdb will give control to the user when the dynamic linker\n\
3720 notifies gdb of shared library events. The most common event of interest\n\
3721 to the user would be loading/unloading of a new library.\n",
3726 c = add_set_enum_cmd ("follow-fork-mode",
3728 follow_fork_mode_kind_names,
3729 (char *) &follow_fork_mode_string,
3730 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
3731 kernel problem. It's also not terribly useful without a GUI to
3732 help the user drive two debuggers. So for now, I'm disabling
3733 the "both" option. */
3734 /* "Set debugger response to a program call of fork \
3736 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3737 parent - the original process is debugged after a fork\n\
3738 child - the new process is debugged after a fork\n\
3739 both - both the parent and child are debugged after a fork\n\
3740 ask - the debugger will ask for one of the above choices\n\
3741 For \"both\", another copy of the debugger will be started to follow\n\
3742 the new child process. The original debugger will continue to follow\n\
3743 the original parent process. To distinguish their prompts, the\n\
3744 debugger copy's prompt will be changed.\n\
3745 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3746 By default, the debugger will follow the parent process.",
3748 "Set debugger response to a program call of fork \
3750 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3751 parent - the original process is debugged after a fork\n\
3752 child - the new process is debugged after a fork\n\
3753 ask - the debugger will ask for one of the above choices\n\
3754 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3755 By default, the debugger will follow the parent process.",
3757 /* c->function.sfunc = ;*/
3758 add_show_from_set (c, &showlist);
3760 set_follow_fork_mode_command ("parent", 0, NULL);
3762 c = add_set_enum_cmd ("scheduler-locking", class_run,
3763 scheduler_enums, /* array of string names */
3764 (char *) &scheduler_mode, /* current mode */
3765 "Set mode for locking scheduler during execution.\n\
3766 off == no locking (threads may preempt at any time)\n\
3767 on == full locking (no thread except the current thread may run)\n\
3768 step == scheduler locked during every single-step operation.\n\
3769 In this mode, no other thread may run during a step command.\n\
3770 Other threads may run while stepping over a function call ('next').",
3773 c->function.sfunc = set_schedlock_func; /* traps on target vector */
3774 add_show_from_set (c, &showlist);