1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
27 #include "breakpoint.h"
32 #include "gdbthread.h"
34 #include "symfile.h" /* for overlay functions */
38 /* Prototypes for local functions */
40 static void signals_info PARAMS ((char *, int));
42 static void handle_command PARAMS ((char *, int));
44 static void sig_print_info PARAMS ((enum target_signal));
46 static void sig_print_header PARAMS ((void));
48 static void resume_cleanups PARAMS ((int));
50 static int hook_stop_stub PARAMS ((char *));
52 static void delete_breakpoint_current_contents PARAMS ((PTR));
54 int inferior_ignoring_startup_exec_events = 0;
55 int inferior_ignoring_leading_exec_events = 0;
58 /* wait_for_inferior and normal_stop use this to notify the user
59 when the inferior stopped in a different thread than it had been
61 static int switched_from_inferior_pid;
64 /* resume and wait_for_inferior use this to ensure that when
65 stepping over a hit breakpoint in a threaded application
66 only the thread that hit the breakpoint is stepped and the
67 other threads don't continue. This prevents having another
68 thread run past the breakpoint while it is temporarily
71 This is not thread-specific, so it isn't saved as part of
74 Versions of gdb which don't use the "step == this thread steps
75 and others continue" model but instead use the "step == this
76 thread steps and others wait" shouldn't do this. */
77 static int thread_step_needed = 0;
79 void _initialize_infrun PARAMS ((void));
81 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
82 program. It needs to examine the jmp_buf argument and extract the PC
83 from it. The return value is non-zero on success, zero otherwise. */
85 #ifndef GET_LONGJMP_TARGET
86 #define GET_LONGJMP_TARGET(PC_ADDR) 0
90 /* Some machines have trampoline code that sits between function callers
91 and the actual functions themselves. If this machine doesn't have
92 such things, disable their processing. */
94 #ifndef SKIP_TRAMPOLINE_CODE
95 #define SKIP_TRAMPOLINE_CODE(pc) 0
98 /* Dynamic function trampolines are similar to solib trampolines in that they
99 are between the caller and the callee. The difference is that when you
100 enter a dynamic trampoline, you can't determine the callee's address. Some
101 (usually complex) code needs to run in the dynamic trampoline to figure out
102 the callee's address. This macro is usually called twice. First, when we
103 enter the trampoline (looks like a normal function call at that point). It
104 should return the PC of a point within the trampoline where the callee's
105 address is known. Second, when we hit the breakpoint, this routine returns
106 the callee's address. At that point, things proceed as per a step resume
109 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
110 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
113 /* On SVR4 based systems, determining the callee's address is exceedingly
114 difficult and depends on the implementation of the run time loader.
115 If we are stepping at the source level, we single step until we exit
116 the run time loader code and reach the callee's address. */
118 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
119 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
122 /* For SVR4 shared libraries, each call goes through a small piece of
123 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
124 to nonzero if we are current stopped in one of these. */
126 #ifndef IN_SOLIB_CALL_TRAMPOLINE
127 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
130 /* In some shared library schemes, the return path from a shared library
131 call may need to go through a trampoline too. */
133 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
134 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
137 /* On MIPS16, a function that returns a floating point value may call
138 a library helper function to copy the return value to a floating point
139 register. The IGNORE_HELPER_CALL macro returns non-zero if we
140 should ignore (i.e. step over) this function call. */
141 #ifndef IGNORE_HELPER_CALL
142 #define IGNORE_HELPER_CALL(pc) 0
145 /* On some systems, the PC may be left pointing at an instruction that won't
146 actually be executed. This is usually indicated by a bit in the PSW. If
147 we find ourselves in such a state, then we step the target beyond the
148 nullified instruction before returning control to the user so as to avoid
151 #ifndef INSTRUCTION_NULLIFIED
152 #define INSTRUCTION_NULLIFIED 0
155 /* Tables of how to react to signals; the user sets them. */
157 static unsigned char *signal_stop;
158 static unsigned char *signal_print;
159 static unsigned char *signal_program;
161 #define SET_SIGS(nsigs,sigs,flags) \
163 int signum = (nsigs); \
164 while (signum-- > 0) \
165 if ((sigs)[signum]) \
166 (flags)[signum] = 1; \
169 #define UNSET_SIGS(nsigs,sigs,flags) \
171 int signum = (nsigs); \
172 while (signum-- > 0) \
173 if ((sigs)[signum]) \
174 (flags)[signum] = 0; \
178 /* Command list pointer for the "stop" placeholder. */
180 static struct cmd_list_element *stop_command;
182 /* Nonzero if breakpoints are now inserted in the inferior. */
184 static int breakpoints_inserted;
186 /* Function inferior was in as of last step command. */
188 static struct symbol *step_start_function;
190 /* Nonzero if we are expecting a trace trap and should proceed from it. */
192 static int trap_expected;
195 /* Nonzero if we want to give control to the user when we're notified
196 of shared library events by the dynamic linker. */
197 static int stop_on_solib_events;
201 /* Nonzero if the next time we try to continue the inferior, it will
202 step one instruction and generate a spurious trace trap.
203 This is used to compensate for a bug in HP-UX. */
205 static int trap_expected_after_continue;
208 /* Nonzero means expecting a trace trap
209 and should stop the inferior and return silently when it happens. */
213 /* Nonzero means expecting a trap and caller will handle it themselves.
214 It is used after attach, due to attaching to a process;
215 when running in the shell before the child program has been exec'd;
216 and when running some kinds of remote stuff (FIXME?). */
218 int stop_soon_quietly;
220 /* Nonzero if proceed is being used for a "finish" command or a similar
221 situation when stop_registers should be saved. */
223 int proceed_to_finish;
225 /* Save register contents here when about to pop a stack dummy frame,
226 if-and-only-if proceed_to_finish is set.
227 Thus this contains the return value from the called function (assuming
228 values are returned in a register). */
230 char stop_registers[REGISTER_BYTES];
232 /* Nonzero if program stopped due to error trying to insert breakpoints. */
234 static int breakpoints_failed;
236 /* Nonzero after stop if current stack frame should be printed. */
238 static int stop_print_frame;
240 static struct breakpoint *step_resume_breakpoint = NULL;
241 static struct breakpoint *through_sigtramp_breakpoint = NULL;
243 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
244 interactions with an inferior that is running a kernel function
245 (aka, a system call or "syscall"). wait_for_inferior therefore
246 may have a need to know when the inferior is in a syscall. This
247 is a count of the number of inferior threads which are known to
248 currently be running in a syscall. */
249 static int number_of_threads_in_syscalls;
251 /* This is used to remember when a fork, vfork or exec event
252 was caught by a catchpoint, and thus the event is to be
253 followed at the next resume of the inferior, and not
256 enum target_waitkind kind;
264 char * execd_pathname;
267 /* Some platforms don't allow us to do anything meaningful with a
268 vforked child until it has exec'd. Vforked processes on such
269 platforms can only be followed after they've exec'd.
271 When this is set to 0, a vfork can be immediately followed,
272 and an exec can be followed merely as an exec. When this is
273 set to 1, a vfork event has been seen, but cannot be followed
274 until the exec is seen.
276 (In the latter case, inferior_pid is still the parent of the
277 vfork, and pending_follow.fork_event.child_pid is the child. The
278 appropriate process is followed, according to the setting of
279 follow-fork-mode.) */
280 static int follow_vfork_when_exec;
282 static char * follow_fork_mode_kind_names [] = {
283 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
284 kernel problem. It's also not terribly useful without a GUI to
285 help the user drive two debuggers. So for now, I'm disabling
287 "parent", "child", "both", "ask" };
289 "parent", "child", "ask" };
291 static char * follow_fork_mode_string = NULL;
294 #if defined(HPUXHPPA)
296 follow_inferior_fork (parent_pid, child_pid, has_forked, has_vforked)
302 int followed_parent = 0;
303 int followed_child = 0;
306 /* Which process did the user want us to follow? */
308 savestring (follow_fork_mode_string, strlen (follow_fork_mode_string));
310 /* Or, did the user not know, and want us to ask? */
311 if (STREQ (follow_fork_mode_string, "ask"))
313 char requested_mode[100];
316 error ("\"ask\" mode NYI");
317 follow_mode = savestring (requested_mode, strlen (requested_mode));
320 /* If we're to be following the parent, then detach from child_pid.
321 We're already following the parent, so need do nothing explicit
323 if (STREQ (follow_mode, "parent"))
327 /* We're already attached to the parent, by default. */
329 /* Before detaching from the child, remove all breakpoints from
330 it. (This won't actually modify the breakpoint list, but will
331 physically remove the breakpoints from the child.) */
332 if (! has_vforked || ! follow_vfork_when_exec)
334 detach_breakpoints (child_pid);
335 SOLIB_REMOVE_INFERIOR_HOOK (child_pid);
338 /* Detach from the child. */
341 target_require_detach (child_pid, "", 1);
344 /* If we're to be following the child, then attach to it, detach
345 from inferior_pid, and set inferior_pid to child_pid. */
346 else if (STREQ (follow_mode, "child"))
348 char child_pid_spelling [100]; /* Arbitrary length. */
352 /* Before detaching from the parent, detach all breakpoints from
353 the child. But only if we're forking, or if we follow vforks
354 as soon as they happen. (If we're following vforks only when
355 the child has exec'd, then it's very wrong to try to write
356 back the "shadow contents" of inserted breakpoints now -- they
357 belong to the child's pre-exec'd a.out.) */
358 if (! has_vforked || ! follow_vfork_when_exec)
360 detach_breakpoints (child_pid);
363 /* Before detaching from the parent, remove all breakpoints from it. */
364 remove_breakpoints ();
366 /* Also reset the solib inferior hook from the parent. */
367 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid);
369 /* Detach from the parent. */
371 target_detach (NULL, 1);
373 /* Attach to the child. */
374 inferior_pid = child_pid;
375 sprintf (child_pid_spelling, "%d", child_pid);
378 target_require_attach (child_pid_spelling, 1);
380 /* Was there a step_resume breakpoint? (There was if the user
381 did a "next" at the fork() call.) If so, explicitly reset its
384 step_resumes are a form of bp that are made to be per-thread.
385 Since we created the step_resume bp when the parent process
386 was being debugged, and now are switching to the child process,
387 from the breakpoint package's viewpoint, that's a switch of
388 "threads". We must update the bp's notion of which thread
389 it is for, or it'll be ignored when it triggers... */
390 if (step_resume_breakpoint &&
391 (! has_vforked || ! follow_vfork_when_exec))
392 breakpoint_re_set_thread (step_resume_breakpoint);
394 /* Reinsert all breakpoints in the child. (The user may've set
395 breakpoints after catching the fork, in which case those
396 actually didn't get set in the child, but only in the parent.) */
397 if (! has_vforked || ! follow_vfork_when_exec)
399 breakpoint_re_set ();
400 insert_breakpoints ();
404 /* If we're to be following both parent and child, then fork ourselves,
405 and attach the debugger clone to the child. */
406 else if (STREQ (follow_mode, "both"))
408 char pid_suffix [100]; /* Arbitrary length. */
410 /* Clone ourselves to follow the child. This is the end of our
411 involvement with child_pid; our clone will take it from here... */
413 target_clone_and_follow_inferior (child_pid, &followed_child);
414 followed_parent = !followed_child;
416 /* We continue to follow the parent. To help distinguish the two
417 debuggers, though, both we and our clone will reset our prompts. */
418 sprintf (pid_suffix, "[%d] ", inferior_pid);
419 set_prompt (strcat (get_prompt (), pid_suffix));
422 /* The parent and child of a vfork share the same address space.
423 Also, on some targets the order in which vfork and exec events
424 are received for parent in child requires some delicate handling
427 For instance, on ptrace-based HPUX we receive the child's vfork
428 event first, at which time the parent has been suspended by the
429 OS and is essentially untouchable until the child's exit or second
430 exec event arrives. At that time, the parent's vfork event is
431 delivered to us, and that's when we see and decide how to follow
432 the vfork. But to get to that point, we must continue the child
433 until it execs or exits. To do that smoothly, all breakpoints
434 must be removed from the child, in case there are any set between
435 the vfork() and exec() calls. But removing them from the child
436 also removes them from the parent, due to the shared-address-space
437 nature of a vfork'd parent and child. On HPUX, therefore, we must
438 take care to restore the bp's to the parent before we continue it.
439 Else, it's likely that we may not stop in the expected place. (The
440 worst scenario is when the user tries to step over a vfork() call;
441 the step-resume bp must be restored for the step to properly stop
442 in the parent after the call completes!)
444 Sequence of events, as reported to gdb from HPUX:
446 Parent Child Action for gdb to take
447 -------------------------------------------------------
448 1 VFORK Continue child
454 target_post_follow_vfork (parent_pid,
460 pending_follow.fork_event.saw_parent_fork = 0;
461 pending_follow.fork_event.saw_child_fork = 0;
467 follow_fork (parent_pid, child_pid)
471 follow_inferior_fork (parent_pid, child_pid, 1, 0);
475 /* Forward declaration. */
476 static void follow_exec PARAMS((int, char *));
479 follow_vfork (parent_pid, child_pid)
483 follow_inferior_fork (parent_pid, child_pid, 0, 1);
485 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
486 if (pending_follow.fork_event.saw_child_exec && (inferior_pid == child_pid))
488 pending_follow.fork_event.saw_child_exec = 0;
489 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
490 follow_exec (inferior_pid, pending_follow.execd_pathname);
491 free (pending_follow.execd_pathname);
494 #endif /* HPUXHPPA */
497 follow_exec (pid, execd_pathname)
499 char * execd_pathname;
503 extern struct target_ops child_ops;
505 /* Did this exec() follow a vfork()? If so, we must follow the
506 vfork now too. Do it before following the exec. */
507 if (follow_vfork_when_exec &&
508 (pending_follow.kind == TARGET_WAITKIND_VFORKED))
510 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
511 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
512 follow_vfork_when_exec = 0;
513 saved_pid = inferior_pid;
515 /* Did we follow the parent? If so, we're done. If we followed
516 the child then we must also follow its exec(). */
517 if (inferior_pid == pending_follow.fork_event.parent_pid)
521 /* This is an exec event that we actually wish to pay attention to.
522 Refresh our symbol table to the newly exec'd program, remove any
525 If there are breakpoints, they aren't really inserted now,
526 since the exec() transformed our inferior into a fresh set
529 We want to preserve symbolic breakpoints on the list, since
530 we have hopes that they can be reset after the new a.out's
531 symbol table is read.
533 However, any "raw" breakpoints must be removed from the list
534 (e.g., the solib bp's), since their address is probably invalid
537 And, we DON'T want to call delete_breakpoints() here, since
538 that may write the bp's "shadow contents" (the instruction
539 value that was overwritten witha TRAP instruction). Since
540 we now have a new a.out, those shadow contents aren't valid. */
541 update_breakpoints_after_exec ();
543 /* If there was one, it's gone now. We cannot truly step-to-next
544 statement through an exec(). */
545 step_resume_breakpoint = NULL;
546 step_range_start = 0;
549 /* If there was one, it's gone now. */
550 through_sigtramp_breakpoint = NULL;
552 /* What is this a.out's name? */
553 printf_unfiltered ("Executing new program: %s\n", execd_pathname);
555 /* We've followed the inferior through an exec. Therefore, the
556 inferior has essentially been killed & reborn. */
557 gdb_flush (gdb_stdout);
558 target_mourn_inferior ();
559 inferior_pid = saved_pid; /* Because mourn_inferior resets inferior_pid. */
560 push_target (&child_ops);
562 /* That a.out is now the one to use. */
563 exec_file_attach (execd_pathname, 0);
565 /* And also is where symbols can be found. */
566 symbol_file_command (execd_pathname, 0);
568 /* Reset the shared library package. This ensures that we get
569 a shlib event when the child reaches "_start", at which point
570 the dld will have had a chance to initialize the child. */
572 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid);
574 /* Reinsert all breakpoints. (Those which were symbolic have
575 been reset to the proper address in the new a.out, thanks
576 to symbol_file_command...) */
577 insert_breakpoints ();
579 /* The next resume of this inferior should bring it to the shlib
580 startup breakpoints. (If the user had also set bp's on
581 "main" from the old (parent) process, then they'll auto-
582 matically get reset there in the new process.) */
586 /* Non-zero if we just simulating a single-step. This is needed
587 because we cannot remove the breakpoints in the inferior process
588 until after the `wait' in `wait_for_inferior'. */
589 static int singlestep_breakpoints_inserted_p = 0;
592 /* Things to clean up if we QUIT out of resume (). */
595 resume_cleanups (arg)
601 /* Resume the inferior, but allow a QUIT. This is useful if the user
602 wants to interrupt some lengthy single-stepping operation
603 (for child processes, the SIGINT goes to the inferior, and so
604 we get a SIGINT random_signal, but for remote debugging and perhaps
605 other targets, that's not true).
607 STEP nonzero if we should step (zero to continue instead).
608 SIG is the signal to give the inferior (zero for none). */
612 enum target_signal sig;
614 int should_resume = 1;
615 struct cleanup *old_cleanups = make_cleanup ((make_cleanup_func)
619 #ifdef CANNOT_STEP_BREAKPOINT
620 /* Most targets can step a breakpoint instruction, thus executing it
621 normally. But if this one cannot, just continue and we will hit
623 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
627 if (SOFTWARE_SINGLE_STEP_P && step)
629 /* Do it the hard way, w/temp breakpoints */
630 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints*/);
631 /* ...and don't ask hardware to do it. */
633 /* and do not pull these breakpoints until after a `wait' in
634 `wait_for_inferior' */
635 singlestep_breakpoints_inserted_p = 1;
638 /* Handle any optimized stores to the inferior NOW... */
639 #ifdef DO_DEFERRED_STORES
644 /* If there were any forks/vforks/execs that were caught and are
645 now to be followed, then do so. */
646 switch (pending_follow.kind)
648 case (TARGET_WAITKIND_FORKED):
649 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
650 follow_fork (inferior_pid, pending_follow.fork_event.child_pid);
653 case (TARGET_WAITKIND_VFORKED):
655 int saw_child_exec = pending_follow.fork_event.saw_child_exec;
657 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
658 follow_vfork (inferior_pid, pending_follow.fork_event.child_pid);
660 /* Did we follow the child, but not yet see the child's exec event?
661 If so, then it actually ought to be waiting for us; we respond to
662 parent vfork events. We don't actually want to resume the child
663 in this situation; we want to just get its exec event. */
664 if (! saw_child_exec &&
665 (inferior_pid == pending_follow.fork_event.child_pid))
670 case (TARGET_WAITKIND_EXECD):
671 /* If we saw a vfork event but couldn't follow it until we saw
672 an exec, then now might be the time! */
673 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
674 /* follow_exec is called as soon as the exec event is seen. */
680 #endif /* HPUXHPPA */
682 /* Install inferior's terminal modes. */
683 target_terminal_inferior ();
688 if (thread_step_needed)
690 /* We stopped on a BPT instruction;
691 don't continue other threads and
692 just step this thread. */
693 thread_step_needed = 0;
695 if (!breakpoint_here_p(read_pc()))
697 /* Breakpoint deleted: ok to do regular resume
698 where all the threads either step or continue. */
699 target_resume (-1, step, sig);
705 warning ( "Internal error, changing continue to step." );
706 remove_breakpoints ();
707 breakpoints_inserted = 0;
712 target_resume (inferior_pid, step, sig);
716 #endif /* HPUXHPPA */
718 /* Vanilla resume. */
719 target_resume (-1, step, sig);
722 discard_cleanups (old_cleanups);
726 /* Clear out all variables saying what to do when inferior is continued.
727 First do this, then set the ones you want, then call `proceed'. */
730 clear_proceed_status ()
733 step_range_start = 0;
735 step_frame_address = 0;
736 step_over_calls = -1;
738 stop_soon_quietly = 0;
739 proceed_to_finish = 0;
740 breakpoint_proceeded = 1; /* We're about to proceed... */
742 /* Discard any remaining commands or status from previous stop. */
743 bpstat_clear (&stop_bpstat);
746 /* Basic routine for continuing the program in various fashions.
748 ADDR is the address to resume at, or -1 for resume where stopped.
749 SIGGNAL is the signal to give it, or 0 for none,
750 or -1 for act according to how it stopped.
751 STEP is nonzero if should trap after one instruction.
752 -1 means return after that and print nothing.
753 You should probably set various step_... variables
754 before calling here, if you are stepping.
756 You should call clear_proceed_status before calling proceed. */
759 proceed (addr, siggnal, step)
761 enum target_signal siggnal;
767 step_start_function = find_pc_function (read_pc ());
771 if (addr == (CORE_ADDR)-1)
773 /* If there is a breakpoint at the address we will resume at,
774 step one instruction before inserting breakpoints
775 so that we do not stop right away (and report a second
776 hit at this breakpoint). */
778 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
781 #ifndef STEP_SKIPS_DELAY
782 #define STEP_SKIPS_DELAY(pc) (0)
783 #define STEP_SKIPS_DELAY_P (0)
785 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
786 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
787 is slow (it needs to read memory from the target). */
788 if (STEP_SKIPS_DELAY_P
789 && breakpoint_here_p (read_pc () + 4)
790 && STEP_SKIPS_DELAY (read_pc ()))
797 /* New address; we don't need to single-step a thread
798 over a breakpoint we just hit, 'cause we aren't
799 continuing from there.
801 It's not worth worrying about the case where a user
802 asks for a "jump" at the current PC--if they get the
803 hiccup of re-hiting a hit breakpoint, what else do
805 thread_step_needed = 0;
808 #ifdef PREPARE_TO_PROCEED
809 /* In a multi-threaded task we may select another thread
810 and then continue or step.
812 But if the old thread was stopped at a breakpoint, it
813 will immediately cause another breakpoint stop without
814 any execution (i.e. it will report a breakpoint hit
815 incorrectly). So we must step over it first.
817 PREPARE_TO_PROCEED checks the current thread against the thread
818 that reported the most recent event. If a step-over is required
819 it returns TRUE and sets the current thread to the old thread. */
820 if (PREPARE_TO_PROCEED() && breakpoint_here_p (read_pc()))
823 thread_step_needed = 1;
826 #endif /* PREPARE_TO_PROCEED */
829 if (trap_expected_after_continue)
831 /* If (step == 0), a trap will be automatically generated after
832 the first instruction is executed. Force step one
833 instruction to clear this condition. This should not occur
834 if step is nonzero, but it is harmless in that case. */
836 trap_expected_after_continue = 0;
838 #endif /* HP_OS_BUG */
841 /* We will get a trace trap after one instruction.
842 Continue it automatically and insert breakpoints then. */
846 int temp = insert_breakpoints ();
849 print_sys_errmsg ("ptrace", temp);
850 error ("Cannot insert breakpoints.\n\
851 The same program may be running in another process.");
854 breakpoints_inserted = 1;
857 if (siggnal != TARGET_SIGNAL_DEFAULT)
858 stop_signal = siggnal;
859 /* If this signal should not be seen by program,
860 give it zero. Used for debugging signals. */
861 else if (!signal_program[stop_signal])
862 stop_signal = TARGET_SIGNAL_0;
864 annotate_starting ();
866 /* Make sure that output from GDB appears before output from the
868 gdb_flush (gdb_stdout);
870 /* Resume inferior. */
871 resume (oneproc || step || bpstat_should_step (), stop_signal);
873 /* Wait for it to stop (if not standalone)
874 and in any case decode why it stopped, and act accordingly. */
876 wait_for_inferior ();
880 /* Record the pc and sp of the program the last time it stopped.
881 These are just used internally by wait_for_inferior, but need
882 to be preserved over calls to it and cleared when the inferior
884 static CORE_ADDR prev_pc;
885 static CORE_ADDR prev_func_start;
886 static char *prev_func_name;
889 /* Start remote-debugging of a machine over a serial link. */
895 init_wait_for_inferior ();
896 stop_soon_quietly = 1;
898 wait_for_inferior ();
902 /* Initialize static vars when a new inferior begins. */
905 init_wait_for_inferior ()
907 /* These are meaningless until the first time through wait_for_inferior. */
910 prev_func_name = NULL;
913 trap_expected_after_continue = 0;
915 breakpoints_inserted = 0;
916 breakpoint_init_inferior (inf_starting);
918 /* Don't confuse first call to proceed(). */
919 stop_signal = TARGET_SIGNAL_0;
921 /* The first resume is not following a fork/vfork/exec. */
922 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
923 pending_follow.fork_event.saw_parent_fork = 0;
924 pending_follow.fork_event.saw_child_fork = 0;
925 pending_follow.fork_event.saw_child_exec = 0;
927 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
928 number_of_threads_in_syscalls = 0;
930 clear_proceed_status ();
934 delete_breakpoint_current_contents (arg)
937 struct breakpoint **breakpointp = (struct breakpoint **)arg;
938 if (*breakpointp != NULL)
940 delete_breakpoint (*breakpointp);
945 /* Wait for control to return from inferior to debugger.
946 If inferior gets a signal, we may decide to start it up again
947 instead of returning. That is why there is a loop in this function.
948 When this function actually returns it means the inferior
949 should be left stopped and GDB should read more commands. */
954 struct cleanup *old_cleanups;
955 struct target_waitstatus w;
957 int random_signal = 0;
958 CORE_ADDR stop_func_start;
959 CORE_ADDR stop_func_end;
960 char *stop_func_name;
962 CORE_ADDR prologue_pc = 0;
965 struct symtab_and_line sal;
966 int remove_breakpoints_on_following_step = 0;
968 struct symtab *current_symtab;
969 int handling_longjmp = 0; /* FIXME */
971 int saved_inferior_pid;
972 int update_step_sp = 0;
973 int stepping_through_solib_after_catch = 0;
974 bpstat stepping_through_solib_catchpoints = NULL;
975 int enable_hw_watchpoints_after_wait = 0;
976 int stepping_through_sigtramp = 0;
977 int new_thread_event;
979 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
980 int stepped_after_stopped_by_watchpoint;
983 old_cleanups = make_cleanup (delete_breakpoint_current_contents,
984 &step_resume_breakpoint);
985 make_cleanup (delete_breakpoint_current_contents,
986 &through_sigtramp_breakpoint);
987 sal = find_pc_line(prev_pc, 0);
988 current_line = sal.line;
989 current_symtab = sal.symtab;
991 /* Are we stepping? */
992 #define CURRENTLY_STEPPING() \
993 ((through_sigtramp_breakpoint == NULL \
994 && !handling_longjmp \
995 && ((step_range_end && step_resume_breakpoint == NULL) \
997 || stepping_through_solib_after_catch \
998 || bpstat_should_step ())
1000 thread_step_needed = 0;
1003 /* We'll update this if & when we switch to a new thread. */
1004 switched_from_inferior_pid = inferior_pid;
1009 extern int overlay_cache_invalid; /* declared in symfile.h */
1011 overlay_cache_invalid = 1;
1013 /* We have to invalidate the registers BEFORE calling target_wait because
1014 they can be loaded from the target while in target_wait. This makes
1015 remote debugging a bit more efficient for those targets that provide
1016 critical registers as part of their normal status mechanism. */
1018 registers_changed ();
1020 if (target_wait_hook)
1021 pid = target_wait_hook (-1, &w);
1023 pid = target_wait (-1, &w);
1025 /* Since we've done a wait, we have a new event. Don't carry
1026 over any expectations about needing to step over a
1028 thread_step_needed = 0;
1030 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event is
1031 serviced in this loop, below. */
1032 if (enable_hw_watchpoints_after_wait)
1034 TARGET_ENABLE_HW_WATCHPOINTS(inferior_pid);
1035 enable_hw_watchpoints_after_wait = 0;
1039 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
1040 stepped_after_stopped_by_watchpoint = 0;
1045 We goto this label from elsewhere in wait_for_inferior when we want
1046 to continue the main loop without calling "wait" and trashing the
1047 waitstatus contained in W. */
1050 flush_cached_frames ();
1052 /* If it's a new process, add it to the thread database */
1054 new_thread_event = ((pid != inferior_pid) && !in_thread_list (pid));
1056 if (w.kind != TARGET_WAITKIND_EXITED
1057 && w.kind != TARGET_WAITKIND_SIGNALLED
1058 && new_thread_event)
1064 fprintf_unfiltered (gdb_stderr, "[New %s]\n",
1065 target_pid_or_tid_to_str (pid));
1068 printf_filtered ("[New %s]\n", target_pid_to_str (pid));
1072 /* NOTE: This block is ONLY meant to be invoked in case of a
1073 "thread creation event"! If it is invoked for any other
1074 sort of event (such as a new thread landing on a breakpoint),
1075 the event will be discarded, which is almost certainly
1078 To avoid this, the low-level module (eg. target_wait)
1079 should call in_thread_list and add_thread, so that the
1080 new thread is known by the time we get here. */
1082 /* We may want to consider not doing a resume here in order
1083 to give the user a chance to play with the new thread.
1084 It might be good to make that a user-settable option. */
1086 /* At this point, all threads are stopped (happens
1087 automatically in either the OS or the native code).
1088 Therefore we need to continue all threads in order to
1091 target_resume (-1, 0, TARGET_SIGNAL_0);
1098 case TARGET_WAITKIND_LOADED:
1099 /* Ignore gracefully during startup of the inferior, as it
1100 might be the shell which has just loaded some objects,
1101 otherwise add the symbols for the newly loaded objects. */
1103 if (!stop_soon_quietly)
1105 extern int auto_solib_add;
1107 /* Remove breakpoints, SOLIB_ADD might adjust
1108 breakpoint addresses via breakpoint_re_set. */
1109 if (breakpoints_inserted)
1110 remove_breakpoints ();
1112 /* Check for any newly added shared libraries if we're
1113 supposed to be adding them automatically. */
1116 /* Switch terminal for any messages produced by
1117 breakpoint_re_set. */
1118 target_terminal_ours_for_output ();
1119 SOLIB_ADD (NULL, 0, NULL);
1120 target_terminal_inferior ();
1123 /* Reinsert breakpoints and continue. */
1124 if (breakpoints_inserted)
1125 insert_breakpoints ();
1128 resume (0, TARGET_SIGNAL_0);
1131 case TARGET_WAITKIND_SPURIOUS:
1132 resume (0, TARGET_SIGNAL_0);
1135 case TARGET_WAITKIND_EXITED:
1136 target_terminal_ours (); /* Must do this before mourn anyway */
1137 annotate_exited (w.value.integer);
1138 if (w.value.integer)
1139 printf_filtered ("\nProgram exited with code 0%o.\n",
1140 (unsigned int)w.value.integer);
1142 printf_filtered ("\nProgram exited normally.\n");
1144 /* Record the exit code in the convenience variable $_exitcode, so
1145 that the user can inspect this again later. */
1146 set_internalvar (lookup_internalvar ("_exitcode"),
1147 value_from_longest (builtin_type_int,
1148 (LONGEST) w.value.integer));
1149 gdb_flush (gdb_stdout);
1150 target_mourn_inferior ();
1151 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P*/
1152 stop_print_frame = 0;
1155 case TARGET_WAITKIND_SIGNALLED:
1156 stop_print_frame = 0;
1157 stop_signal = w.value.sig;
1158 target_terminal_ours (); /* Must do this before mourn anyway */
1159 annotate_signalled ();
1161 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1162 mean it is already dead? This has been here since GDB 2.8, so
1163 perhaps it means rms didn't understand unix waitstatuses?
1164 For the moment I'm just kludging around this in remote.c
1165 rather than trying to change it here --kingdon, 5 Dec 1994. */
1166 target_kill (); /* kill mourns as well */
1168 printf_filtered ("\nProgram terminated with signal ");
1169 annotate_signal_name ();
1170 printf_filtered ("%s", target_signal_to_name (stop_signal));
1171 annotate_signal_name_end ();
1172 printf_filtered (", ");
1173 annotate_signal_string ();
1174 printf_filtered ("%s", target_signal_to_string (stop_signal));
1175 annotate_signal_string_end ();
1176 printf_filtered (".\n");
1178 printf_filtered ("The program no longer exists.\n");
1179 gdb_flush (gdb_stdout);
1180 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P*/
1183 /* The following are the only cases in which we keep going;
1184 the above cases end in a continue or goto. */
1185 case TARGET_WAITKIND_FORKED:
1186 stop_signal = TARGET_SIGNAL_TRAP;
1187 pending_follow.kind = w.kind;
1189 /* Ignore fork events reported for the parent; we're only
1190 interested in reacting to forks of the child. Note that
1191 we expect the child's fork event to be available if we
1192 waited for it now. */
1193 if (inferior_pid == pid)
1195 pending_follow.fork_event.saw_parent_fork = 1;
1196 pending_follow.fork_event.parent_pid = pid;
1197 pending_follow.fork_event.child_pid = w.value.related_pid;
1202 pending_follow.fork_event.saw_child_fork = 1;
1203 pending_follow.fork_event.child_pid = pid;
1204 pending_follow.fork_event.parent_pid = w.value.related_pid;
1207 stop_pc = read_pc_pid (pid);
1208 saved_inferior_pid = inferior_pid;
1210 stop_bpstat = bpstat_stop_status
1212 #if DECR_PC_AFTER_BREAK
1213 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1214 && CURRENTLY_STEPPING ())
1215 #else /* DECR_PC_AFTER_BREAK zero */
1217 #endif /* DECR_PC_AFTER_BREAK zero */
1219 random_signal = ! bpstat_explains_signal (stop_bpstat);
1220 inferior_pid = saved_inferior_pid;
1221 goto process_event_stop_test;
1223 /* If this a platform which doesn't allow a debugger to touch a
1224 vfork'd inferior until after it exec's, then we'd best keep
1225 our fingers entirely off the inferior, other than continuing
1226 it. This has the unfortunate side-effect that catchpoints
1227 of vforks will be ignored. But since the platform doesn't
1228 allow the inferior be touched at vfork time, there's really
1230 case TARGET_WAITKIND_VFORKED:
1231 stop_signal = TARGET_SIGNAL_TRAP;
1232 pending_follow.kind = w.kind;
1234 /* Is this a vfork of the parent? If so, then give any
1235 vfork catchpoints a chance to trigger now. (It's
1236 dangerous to do so if the child canot be touched until
1237 it execs, and the child has not yet exec'd. We probably
1238 should warn the user to that effect when the catchpoint
1240 if (pid == inferior_pid)
1242 pending_follow.fork_event.saw_parent_fork = 1;
1243 pending_follow.fork_event.parent_pid = pid;
1244 pending_follow.fork_event.child_pid = w.value.related_pid;
1247 /* If we've seen the child's vfork event but cannot really touch
1248 the child until it execs, then we must continue the child now.
1249 Else, give any vfork catchpoints a chance to trigger now. */
1252 pending_follow.fork_event.saw_child_fork = 1;
1253 pending_follow.fork_event.child_pid = pid;
1254 pending_follow.fork_event.parent_pid = w.value.related_pid;
1255 target_post_startup_inferior (pending_follow.fork_event.child_pid);
1256 follow_vfork_when_exec = ! target_can_follow_vfork_prior_to_exec ();
1257 if (follow_vfork_when_exec)
1259 target_resume (pid, 0, TARGET_SIGNAL_0);
1264 stop_pc = read_pc ();
1265 stop_bpstat = bpstat_stop_status
1267 #if DECR_PC_AFTER_BREAK
1268 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1269 && CURRENTLY_STEPPING ())
1270 #else /* DECR_PC_AFTER_BREAK zero */
1272 #endif /* DECR_PC_AFTER_BREAK zero */
1274 random_signal = ! bpstat_explains_signal (stop_bpstat);
1275 goto process_event_stop_test;
1277 case TARGET_WAITKIND_EXECD:
1278 stop_signal = TARGET_SIGNAL_TRAP;
1280 /* Is this a target which reports multiple exec events per actual
1281 call to exec()? (HP-UX using ptrace does, for example.) If so,
1282 ignore all but the last one. Just resume the exec'r, and wait
1283 for the next exec event. */
1284 if (inferior_ignoring_leading_exec_events)
1286 inferior_ignoring_leading_exec_events--;
1287 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1288 ENSURE_VFORKING_PARENT_REMAINS_STOPPED(pending_follow.fork_event.parent_pid);
1289 target_resume (pid, 0, TARGET_SIGNAL_0);
1292 inferior_ignoring_leading_exec_events =
1293 target_reported_exec_events_per_exec_call () - 1;
1295 pending_follow.execd_pathname = savestring (w.value.execd_pathname,
1296 strlen (w.value.execd_pathname));
1298 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1299 child of a vfork exec?
1301 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1302 HP-UX, events associated with a vforking inferior come in
1303 threes: a vfork event for the child (always first), followed
1304 a vfork event for the parent and an exec event for the child.
1305 The latter two can come in either order.
1307 If we get the parent vfork event first, life's good: We follow
1308 either the parent or child, and then the child's exec event is
1311 But if we get the child's exec event first, then we delay
1312 responding to it until we handle the parent's vfork. Because,
1313 otherwise we can't satisfy a "catch vfork". */
1314 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1316 pending_follow.fork_event.saw_child_exec = 1;
1318 /* On some targets, the child must be resumed before
1319 the parent vfork event is delivered. A single-step
1321 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK())
1322 target_resume (pid, 1, TARGET_SIGNAL_0);
1323 /* We expect the parent vfork event to be available now. */
1327 /* This causes the eventpoints and symbol table to be reset. Must
1328 do this now, before trying to determine whether to stop. */
1329 follow_exec (inferior_pid, pending_follow.execd_pathname);
1330 free (pending_follow.execd_pathname);
1332 stop_pc = read_pc_pid (pid);
1333 saved_inferior_pid = inferior_pid;
1335 stop_bpstat = bpstat_stop_status
1337 #if DECR_PC_AFTER_BREAK
1338 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1339 && CURRENTLY_STEPPING ())
1340 #else /* DECR_PC_AFTER_BREAK zero */
1342 #endif /* DECR_PC_AFTER_BREAK zero */
1344 random_signal = ! bpstat_explains_signal (stop_bpstat);
1345 inferior_pid = saved_inferior_pid;
1346 goto process_event_stop_test;
1348 /* These syscall events are returned on HP-UX, as part of its
1349 implementation of page-protection-based "hardware" watchpoints.
1350 HP-UX has unfortunate interactions between page-protections and
1351 some system calls. Our solution is to disable hardware watches
1352 when a system call is entered, and reenable them when the syscall
1353 completes. The downside of this is that we may miss the precise
1354 point at which a watched piece of memory is modified. "Oh well."
1356 Note that we may have multiple threads running, which may each
1357 enter syscalls at roughly the same time. Since we don't have a
1358 good notion currently of whether a watched piece of memory is
1359 thread-private, we'd best not have any page-protections active
1360 when any thread is in a syscall. Thus, we only want to reenable
1361 hardware watches when no threads are in a syscall.
1363 Also, be careful not to try to gather much state about a thread
1364 that's in a syscall. It's frequently a losing proposition. */
1365 case TARGET_WAITKIND_SYSCALL_ENTRY:
1366 number_of_threads_in_syscalls++;
1367 if (number_of_threads_in_syscalls == 1)
1369 TARGET_DISABLE_HW_WATCHPOINTS(inferior_pid);
1371 resume (0, TARGET_SIGNAL_0);
1374 /* Before examining the threads further, step this thread to
1375 get it entirely out of the syscall. (We get notice of the
1376 event when the thread is just on the verge of exiting a
1377 syscall. Stepping one instruction seems to get it back
1380 Note that although the logical place to reenable h/w watches
1381 is here, we cannot. We cannot reenable them before stepping
1382 the thread (this causes the next wait on the thread to hang).
1384 Nor can we enable them after stepping until we've done a wait.
1385 Thus, we simply set the flag enable_hw_watchpoints_after_wait
1386 here, which will be serviced immediately after the target
1388 case TARGET_WAITKIND_SYSCALL_RETURN:
1389 target_resume (pid, 1, TARGET_SIGNAL_0);
1391 if (number_of_threads_in_syscalls > 0)
1393 number_of_threads_in_syscalls--;
1394 enable_hw_watchpoints_after_wait =
1395 (number_of_threads_in_syscalls == 0);
1399 case TARGET_WAITKIND_STOPPED:
1400 stop_signal = w.value.sig;
1404 /* We may want to consider not doing a resume here in order to give
1405 the user a chance to play with the new thread. It might be good
1406 to make that a user-settable option. */
1408 /* At this point, all threads are stopped (happens automatically in
1409 either the OS or the native code). Therefore we need to continue
1410 all threads in order to make progress. */
1411 if (new_thread_event)
1413 target_resume (-1, 0, TARGET_SIGNAL_0);
1417 stop_pc = read_pc_pid (pid);
1419 /* See if a thread hit a thread-specific breakpoint that was meant for
1420 another thread. If so, then step that thread past the breakpoint,
1423 if (stop_signal == TARGET_SIGNAL_TRAP)
1425 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1428 if (breakpoints_inserted
1429 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
1432 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK,
1437 /* Saw a breakpoint, but it was hit by the wrong thread.
1439 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, pid);
1441 remove_status = remove_breakpoints ();
1442 /* Did we fail to remove breakpoints? If so, try
1443 to set the PC past the bp. (There's at least
1444 one situation in which we can fail to remove
1445 the bp's: On HP-UX's that use ttrace, we can't
1446 change the address space of a vforking child
1447 process until the child exits (well, okay, not
1448 then either :-) or execs. */
1449 if (remove_status != 0)
1451 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, pid);
1455 target_resume (pid, 1, TARGET_SIGNAL_0);
1456 /* FIXME: What if a signal arrives instead of the
1457 single-step happening? */
1459 if (target_wait_hook)
1460 target_wait_hook (pid, &w);
1462 target_wait (pid, &w);
1463 insert_breakpoints ();
1466 /* We need to restart all the threads now. */
1467 target_resume (-1, 0, TARGET_SIGNAL_0);
1472 /* This breakpoint matches--either it is the right
1473 thread or it's a generic breakpoint for all threads.
1474 Remember that we'll need to step just _this_ thread
1475 on any following user continuation! */
1476 thread_step_needed = 1;
1483 /* See if something interesting happened to the non-current thread. If
1484 so, then switch to that thread, and eventually give control back to
1487 Note that if there's any kind of pending follow (i.e., of a fork,
1488 vfork or exec), we don't want to do this now. Rather, we'll let
1489 the next resume handle it. */
1490 if ((pid != inferior_pid) &&
1491 (pending_follow.kind == TARGET_WAITKIND_SPURIOUS))
1495 /* If it's a random signal for a non-current thread, notify user
1496 if he's expressed an interest. */
1498 && signal_print[stop_signal])
1500 /* ??rehrauer: I don't understand the rationale for this code. If the
1501 inferior will stop as a result of this signal, then the act of handling
1502 the stop ought to print a message that's couches the stoppage in user
1503 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1504 won't stop as a result of the signal -- i.e., if the signal is merely
1505 a side-effect of something GDB's doing "under the covers" for the
1506 user, such as stepping threads over a breakpoint they shouldn't stop
1507 for -- then the message seems to be a serious annoyance at best.
1509 For now, remove the message altogether. */
1512 target_terminal_ours_for_output ();
1513 printf_filtered ("\nProgram received signal %s, %s.\n",
1514 target_signal_to_name (stop_signal),
1515 target_signal_to_string (stop_signal));
1516 gdb_flush (gdb_stdout);
1520 /* If it's not SIGTRAP and not a signal we want to stop for, then
1521 continue the thread. */
1523 if (stop_signal != TARGET_SIGNAL_TRAP
1524 && !signal_stop[stop_signal])
1527 target_terminal_inferior ();
1529 /* Clear the signal if it should not be passed. */
1530 if (signal_program[stop_signal] == 0)
1531 stop_signal = TARGET_SIGNAL_0;
1533 target_resume (pid, 0, stop_signal);
1537 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1538 and fall into the rest of wait_for_inferior(). */
1540 /* Save infrun state for the old thread. */
1541 save_infrun_state (inferior_pid, prev_pc,
1542 prev_func_start, prev_func_name,
1543 trap_expected, step_resume_breakpoint,
1544 through_sigtramp_breakpoint,
1545 step_range_start, step_range_end,
1546 step_frame_address, handling_longjmp,
1548 stepping_through_solib_after_catch,
1549 stepping_through_solib_catchpoints,
1550 stepping_through_sigtramp);
1553 switched_from_inferior_pid = inferior_pid;
1558 /* Load infrun state for the new thread. */
1559 load_infrun_state (inferior_pid, &prev_pc,
1560 &prev_func_start, &prev_func_name,
1561 &trap_expected, &step_resume_breakpoint,
1562 &through_sigtramp_breakpoint,
1563 &step_range_start, &step_range_end,
1564 &step_frame_address, &handling_longjmp,
1566 &stepping_through_solib_after_catch,
1567 &stepping_through_solib_catchpoints,
1568 &stepping_through_sigtramp);
1571 context_hook (pid_to_thread_id (pid));
1573 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid));
1574 flush_cached_frames ();
1577 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1579 /* Pull the single step breakpoints out of the target. */
1580 SOFTWARE_SINGLE_STEP (0, 0);
1581 singlestep_breakpoints_inserted_p = 0;
1584 /* If PC is pointing at a nullified instruction, then step beyond
1585 it so that the user won't be confused when GDB appears to be ready
1588 #if 0 /* XXX DEBUG */
1589 printf ("infrun.c:1607: pc = 0x%x\n", read_pc ());
1591 /* if (INSTRUCTION_NULLIFIED && CURRENTLY_STEPPING ()) */
1592 if (INSTRUCTION_NULLIFIED)
1594 struct target_waitstatus tmpstatus;
1596 all_registers_info ((char *)0, 0);
1598 registers_changed ();
1599 target_resume (pid, 1, TARGET_SIGNAL_0);
1601 /* We may have received a signal that we want to pass to
1602 the inferior; therefore, we must not clobber the waitstatus
1603 in W. So we call wait ourselves, then continue the loop
1604 at the "have_waited" label. */
1605 if (target_wait_hook)
1606 target_wait_hook (pid, &tmpstatus);
1608 target_wait (pid, &tmpstatus);
1613 #ifdef HAVE_STEPPABLE_WATCHPOINT
1614 /* It may not be necessary to disable the watchpoint to stop over
1615 it. For example, the PA can (with some kernel cooperation)
1616 single step over a watchpoint without disabling the watchpoint. */
1617 if (STOPPED_BY_WATCHPOINT (w))
1624 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
1625 /* It is far more common to need to disable a watchpoint
1626 to step the inferior over it. FIXME. What else might
1627 a debug register or page protection watchpoint scheme need
1629 if (STOPPED_BY_WATCHPOINT (w))
1631 /* At this point, we are stopped at an instruction which has attempted to write
1632 to a piece of memory under control of a watchpoint. The instruction hasn't
1633 actually executed yet. If we were to evaluate the watchpoint expression
1634 now, we would get the old value, and therefore no change would seem to have
1637 In order to make watchpoints work `right', we really need to complete the
1638 memory write, and then evaluate the watchpoint expression. The following
1639 code does that by removing the watchpoint (actually, all watchpoints and
1640 breakpoints), single-stepping the target, re-inserting watchpoints, and then
1641 falling through to let normal single-step processing handle proceed. Since
1642 this includes evaluating watchpoints, things will come to a stop in the
1645 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
1647 remove_breakpoints ();
1648 registers_changed();
1649 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
1651 if (target_wait_hook)
1652 target_wait_hook (pid, &w);
1654 target_wait (pid, &w);
1655 insert_breakpoints ();
1657 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1658 handle things like signals arriving and other things happening
1659 in combination correctly? */
1660 stepped_after_stopped_by_watchpoint = 1;
1665 #ifdef HAVE_CONTINUABLE_WATCHPOINT
1666 /* It may be possible to simply continue after a watchpoint. */
1667 STOPPED_BY_WATCHPOINT (w);
1670 stop_func_start = 0;
1673 /* Don't care about return value; stop_func_start and stop_func_name
1674 will both be 0 if it doesn't work. */
1675 find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start,
1677 stop_func_start += FUNCTION_START_OFFSET;
1679 bpstat_clear (&stop_bpstat);
1681 stop_stack_dummy = 0;
1682 stop_print_frame = 1;
1684 stopped_by_random_signal = 0;
1685 breakpoints_failed = 0;
1687 /* Look at the cause of the stop, and decide what to do.
1688 The alternatives are:
1689 1) break; to really stop and return to the debugger,
1690 2) drop through to start up again
1691 (set another_trap to 1 to single step once)
1692 3) set random_signal to 1, and the decision between 1 and 2
1693 will be made according to the signal handling tables. */
1695 /* First, distinguish signals caused by the debugger from signals
1696 that have to do with the program's own actions.
1697 Note that breakpoint insns may cause SIGTRAP or SIGILL
1698 or SIGEMT, depending on the operating system version.
1699 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1700 and change it to SIGTRAP. */
1702 if (stop_signal == TARGET_SIGNAL_TRAP
1703 || (breakpoints_inserted &&
1704 (stop_signal == TARGET_SIGNAL_ILL
1705 || stop_signal == TARGET_SIGNAL_EMT
1707 || stop_soon_quietly)
1709 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
1711 stop_print_frame = 0;
1714 if (stop_soon_quietly)
1717 /* Don't even think about breakpoints
1718 if just proceeded over a breakpoint.
1720 However, if we are trying to proceed over a breakpoint
1721 and end up in sigtramp, then through_sigtramp_breakpoint
1722 will be set and we should check whether we've hit the
1724 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
1725 && through_sigtramp_breakpoint == NULL)
1726 bpstat_clear (&stop_bpstat);
1729 /* See if there is a breakpoint at the current PC. */
1730 stop_bpstat = bpstat_stop_status
1732 (DECR_PC_AFTER_BREAK ?
1733 /* Notice the case of stepping through a jump
1734 that lands just after a breakpoint.
1735 Don't confuse that with hitting the breakpoint.
1736 What we check for is that 1) stepping is going on
1737 and 2) the pc before the last insn does not match
1738 the address of the breakpoint before the current pc
1739 and 3) we didn't hit a breakpoint in a signal handler
1740 without an intervening stop in sigtramp, which is
1741 detected by a new stack pointer value below
1742 any usual function calling stack adjustments. */
1743 (CURRENTLY_STEPPING ()
1744 && prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1746 && INNER_THAN (read_sp (), (step_sp - 16)))) :
1749 /* Following in case break condition called a
1751 stop_print_frame = 1;
1754 if (stop_signal == TARGET_SIGNAL_TRAP)
1756 = !(bpstat_explains_signal (stop_bpstat)
1758 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1759 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
1760 FRAME_FP (get_current_frame ()))
1761 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1762 || (step_range_end && step_resume_breakpoint == NULL));
1767 = !(bpstat_explains_signal (stop_bpstat)
1768 /* End of a stack dummy. Some systems (e.g. Sony
1769 news) give another signal besides SIGTRAP,
1770 so check here as well as above. */
1771 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1772 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
1773 FRAME_FP (get_current_frame ()))
1774 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1777 stop_signal = TARGET_SIGNAL_TRAP;
1781 /* When we reach this point, we've pretty much decided
1782 that the reason for stopping must've been a random
1783 (unexpected) signal. */
1787 /* If a fork, vfork or exec event was seen, then there are two
1788 possible responses we can make:
1790 1. If a catchpoint triggers for the event (random_signal == 0),
1791 then we must stop now and issue a prompt. We will resume
1792 the inferior when the user tells us to.
1793 2. If no catchpoint triggers for the event (random_signal == 1),
1794 then we must resume the inferior now and keep checking.
1796 In either case, we must take appropriate steps to "follow" the
1797 the fork/vfork/exec when the inferior is resumed. For example,
1798 if follow-fork-mode is "child", then we must detach from the
1799 parent inferior and follow the new child inferior.
1801 In either case, setting pending_follow causes the next resume()
1802 to take the appropriate following action. */
1803 process_event_stop_test:
1804 if (w.kind == TARGET_WAITKIND_FORKED)
1806 if (random_signal) /* I.e., no catchpoint triggered for this. */
1809 stop_signal = TARGET_SIGNAL_0;
1813 else if (w.kind == TARGET_WAITKIND_VFORKED)
1815 if (random_signal) /* I.e., no catchpoint triggered for this. */
1817 stop_signal = TARGET_SIGNAL_0;
1821 else if (w.kind == TARGET_WAITKIND_EXECD)
1823 pending_follow.kind = w.kind;
1824 if (random_signal) /* I.e., no catchpoint triggered for this. */
1827 stop_signal = TARGET_SIGNAL_0;
1832 /* For the program's own signals, act according to
1833 the signal handling tables. */
1837 /* Signal not for debugging purposes. */
1840 stopped_by_random_signal = 1;
1842 if (signal_print[stop_signal])
1845 target_terminal_ours_for_output ();
1847 printf_filtered ("\nProgram received signal ");
1848 annotate_signal_name ();
1849 printf_filtered ("%s", target_signal_to_name (stop_signal));
1850 annotate_signal_name_end ();
1851 printf_filtered (", ");
1852 annotate_signal_string ();
1853 printf_filtered ("%s", target_signal_to_string (stop_signal));
1854 annotate_signal_string_end ();
1855 printf_filtered (".\n");
1856 gdb_flush (gdb_stdout);
1858 if (signal_stop[stop_signal])
1860 /* If not going to stop, give terminal back
1861 if we took it away. */
1863 target_terminal_inferior ();
1865 /* Clear the signal if it should not be passed. */
1866 if (signal_program[stop_signal] == 0)
1867 stop_signal = TARGET_SIGNAL_0;
1869 /* If we're in the middle of a "next" command, let the code for
1870 stepping over a function handle this. pai/1997-09-10
1872 A previous comment here suggested it was possible to change
1873 this to jump to keep_going in all cases. */
1875 if (step_over_calls > 0)
1876 goto step_over_function;
1878 goto check_sigtramp2;
1881 /* Handle cases caused by hitting a breakpoint. */
1883 CORE_ADDR jmp_buf_pc;
1884 struct bpstat_what what;
1886 what = bpstat_what (stop_bpstat);
1888 if (what.call_dummy)
1890 stop_stack_dummy = 1;
1892 trap_expected_after_continue = 1;
1896 switch (what.main_action)
1898 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
1899 /* If we hit the breakpoint at longjmp, disable it for the
1900 duration of this command. Then, install a temporary
1901 breakpoint at the target of the jmp_buf. */
1902 disable_longjmp_breakpoint();
1903 remove_breakpoints ();
1904 breakpoints_inserted = 0;
1905 if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
1907 /* Need to blow away step-resume breakpoint, as it
1908 interferes with us */
1909 if (step_resume_breakpoint != NULL)
1911 delete_breakpoint (step_resume_breakpoint);
1912 step_resume_breakpoint = NULL;
1914 /* Not sure whether we need to blow this away too, but probably
1915 it is like the step-resume breakpoint. */
1916 if (through_sigtramp_breakpoint != NULL)
1918 delete_breakpoint (through_sigtramp_breakpoint);
1919 through_sigtramp_breakpoint = NULL;
1923 /* FIXME - Need to implement nested temporary breakpoints */
1924 if (step_over_calls > 0)
1925 set_longjmp_resume_breakpoint(jmp_buf_pc,
1926 get_current_frame());
1929 set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
1930 handling_longjmp = 1; /* FIXME */
1933 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
1934 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
1935 remove_breakpoints ();
1936 breakpoints_inserted = 0;
1938 /* FIXME - Need to implement nested temporary breakpoints */
1940 && (INNER_THAN (FRAME_FP (get_current_frame ()),
1941 step_frame_address)))
1947 disable_longjmp_breakpoint();
1948 handling_longjmp = 0; /* FIXME */
1949 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
1951 /* else fallthrough */
1953 case BPSTAT_WHAT_SINGLE:
1954 if (breakpoints_inserted)
1956 thread_step_needed = 1;
1957 remove_breakpoints ();
1959 breakpoints_inserted = 0;
1961 /* Still need to check other stuff, at least the case
1962 where we are stepping and step out of the right range. */
1965 case BPSTAT_WHAT_STOP_NOISY:
1966 stop_print_frame = 1;
1968 /* We are about to nuke the step_resume_breakpoint and
1969 through_sigtramp_breakpoint via the cleanup chain, so
1970 no need to worry about it here. */
1974 case BPSTAT_WHAT_STOP_SILENT:
1975 stop_print_frame = 0;
1977 /* We are about to nuke the step_resume_breakpoint and
1978 through_sigtramp_breakpoint via the cleanup chain, so
1979 no need to worry about it here. */
1983 case BPSTAT_WHAT_STEP_RESUME:
1984 /* This proably demands a more elegant solution, but, yeah
1987 This function's use of the simple variable
1988 step_resume_breakpoint doesn't seem to accomodate
1989 simultaneously active step-resume bp's, although the
1990 breakpoint list certainly can.
1992 If we reach here and step_resume_breakpoint is already
1993 NULL, then apparently we have multiple active
1994 step-resume bp's. We'll just delete the breakpoint we
1995 stopped at, and carry on. */
1996 if (step_resume_breakpoint == NULL)
1998 step_resume_breakpoint =
1999 bpstat_find_step_resume_breakpoint (stop_bpstat);
2001 delete_breakpoint (step_resume_breakpoint);
2002 step_resume_breakpoint = NULL;
2005 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2006 if (through_sigtramp_breakpoint)
2007 delete_breakpoint (through_sigtramp_breakpoint);
2008 through_sigtramp_breakpoint = NULL;
2010 /* If were waiting for a trap, hitting the step_resume_break
2011 doesn't count as getting it. */
2016 case BPSTAT_WHAT_CHECK_SHLIBS:
2017 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2020 extern int auto_solib_add;
2022 /* Remove breakpoints, we eventually want to step over the
2023 shlib event breakpoint, and SOLIB_ADD might adjust
2024 breakpoint addresses via breakpoint_re_set. */
2025 if (breakpoints_inserted)
2026 remove_breakpoints ();
2027 breakpoints_inserted = 0;
2029 /* Check for any newly added shared libraries if we're
2030 supposed to be adding them automatically. */
2033 /* Switch terminal for any messages produced by
2034 breakpoint_re_set. */
2035 target_terminal_ours_for_output ();
2036 SOLIB_ADD (NULL, 0, NULL);
2037 target_terminal_inferior ();
2040 /* Try to reenable shared library breakpoints, additional
2041 code segments in shared libraries might be mapped in now. */
2042 re_enable_breakpoints_in_shlibs ();
2044 /* If requested, stop when the dynamic linker notifies
2045 gdb of events. This allows the user to get control
2046 and place breakpoints in initializer routines for
2047 dynamically loaded objects (among other things). */
2048 if (stop_on_solib_events)
2050 stop_print_frame = 0;
2054 /* If we stopped due to an explicit catchpoint, then the
2055 (see above) call to SOLIB_ADD pulled in any symbols
2056 from a newly-loaded library, if appropriate.
2058 We do want the inferior to stop, but not where it is
2059 now, which is in the dynamic linker callback. Rather,
2060 we would like it stop in the user's program, just after
2061 the call that caused this catchpoint to trigger. That
2062 gives the user a more useful vantage from which to
2063 examine their program's state. */
2064 else if (what.main_action == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2066 /* ??rehrauer: If I could figure out how to get the
2067 right return PC from here, we could just set a temp
2068 breakpoint and resume. I'm not sure we can without
2069 cracking open the dld's shared libraries and sniffing
2070 their unwind tables and text/data ranges, and that's
2071 not a terribly portable notion.
2073 Until that time, we must step the inferior out of the
2074 dld callback, and also out of the dld itself (and any
2075 code or stubs in libdld.sl, such as "shl_load" and
2076 friends) until we reach non-dld code. At that point,
2077 we can stop stepping. */
2078 bpstat_get_triggered_catchpoints (stop_bpstat,
2079 &stepping_through_solib_catchpoints);
2080 stepping_through_solib_after_catch = 1;
2082 /* Be sure to lift all breakpoints, so the inferior does
2083 actually step past this point... */
2089 /* We want to step over this breakpoint, then keep going. */
2097 case BPSTAT_WHAT_LAST:
2098 /* Not a real code, but listed here to shut up gcc -Wall. */
2100 case BPSTAT_WHAT_KEEP_CHECKING:
2105 /* We come here if we hit a breakpoint but should not
2106 stop for it. Possibly we also were stepping
2107 and should stop for that. So fall through and
2108 test for stepping. But, if not stepping,
2111 /* Are we stepping to get the inferior out of the dynamic
2112 linker's hook (and possibly the dld itself) after catching
2114 if (stepping_through_solib_after_catch)
2116 #if defined(SOLIB_ADD)
2117 /* Have we reached our destination? If not, keep going. */
2118 if (SOLIB_IN_DYNAMIC_LINKER (pid, stop_pc))
2124 /* Else, stop and report the catchpoint(s) whose triggering
2125 caused us to begin stepping. */
2126 stepping_through_solib_after_catch = 0;
2127 bpstat_clear (&stop_bpstat);
2128 stop_bpstat = bpstat_copy (stepping_through_solib_catchpoints);
2129 bpstat_clear (&stepping_through_solib_catchpoints);
2130 stop_print_frame = 1;
2134 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
2135 /* This is the old way of detecting the end of the stack dummy.
2136 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2137 handled above. As soon as we can test it on all of them, all
2138 architectures should define it. */
2140 /* If this is the breakpoint at the end of a stack dummy,
2141 just stop silently, unless the user was doing an si/ni, in which
2142 case she'd better know what she's doing. */
2144 if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (),
2145 FRAME_FP (get_current_frame ()))
2148 stop_print_frame = 0;
2149 stop_stack_dummy = 1;
2151 trap_expected_after_continue = 1;
2155 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
2157 if (step_resume_breakpoint)
2158 /* Having a step-resume breakpoint overrides anything
2159 else having to do with stepping commands until
2160 that breakpoint is reached. */
2161 /* I'm not sure whether this needs to be check_sigtramp2 or
2162 whether it could/should be keep_going. */
2163 goto check_sigtramp2;
2165 if (step_range_end == 0)
2166 /* Likewise if we aren't even stepping. */
2167 /* I'm not sure whether this needs to be check_sigtramp2 or
2168 whether it could/should be keep_going. */
2169 goto check_sigtramp2;
2171 /* If stepping through a line, keep going if still within it.
2173 Note that step_range_end is the address of the first instruction
2174 beyond the step range, and NOT the address of the last instruction
2176 if (stop_pc >= step_range_start
2177 && stop_pc < step_range_end
2179 /* I haven't a clue what might trigger this clause, and it seems wrong
2180 anyway, so I've disabled it until someone complains. -Stu 10/24/95 */
2182 /* The step range might include the start of the
2183 function, so if we are at the start of the
2184 step range and either the stack or frame pointers
2185 just changed, we've stepped outside */
2186 && !(stop_pc == step_range_start
2187 && FRAME_FP (get_current_frame ())
2188 && (INNER_THAN (read_sp (), step_sp)
2189 || FRAME_FP (get_current_frame ()) != step_frame_address))
2193 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2194 So definately need to check for sigtramp here. */
2195 goto check_sigtramp2;
2198 /* We stepped out of the stepping range. */
2200 /* If we are stepping at the source level and entered the runtime
2201 loader dynamic symbol resolution code, we keep on single stepping
2202 until we exit the run time loader code and reach the callee's
2204 if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2207 /* We can't update step_sp every time through the loop, because
2208 reading the stack pointer would slow down stepping too much.
2209 But we can update it every time we leave the step range. */
2212 /* Did we just take a signal? */
2213 if (IN_SIGTRAMP (stop_pc, stop_func_name)
2214 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2215 && INNER_THAN (read_sp (), step_sp))
2217 /* We've just taken a signal; go until we are back to
2218 the point where we took it and one more. */
2220 /* Note: The test above succeeds not only when we stepped
2221 into a signal handler, but also when we step past the last
2222 statement of a signal handler and end up in the return stub
2223 of the signal handler trampoline. To distinguish between
2224 these two cases, check that the frame is INNER_THAN the
2225 previous one below. pai/1997-09-11 */
2229 CORE_ADDR current_frame = FRAME_FP (get_current_frame());
2231 if (INNER_THAN (current_frame, step_frame_address))
2233 /* We have just taken a signal; go until we are back to
2234 the point where we took it and one more. */
2236 /* This code is needed at least in the following case:
2237 The user types "next" and then a signal arrives (before
2238 the "next" is done). */
2240 /* Note that if we are stopped at a breakpoint, then we need
2241 the step_resume breakpoint to override any breakpoints at
2242 the same location, so that we will still step over the
2243 breakpoint even though the signal happened. */
2244 struct symtab_and_line sr_sal;
2247 sr_sal.symtab = NULL;
2249 sr_sal.pc = prev_pc;
2250 /* We could probably be setting the frame to
2251 step_frame_address; I don't think anyone thought to
2253 step_resume_breakpoint =
2254 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2255 if (breakpoints_inserted)
2256 insert_breakpoints ();
2260 /* We just stepped out of a signal handler and into
2261 its calling trampoline.
2263 Normally, we'd jump to step_over_function from
2264 here, but for some reason GDB can't unwind the
2265 stack correctly to find the real PC for the point
2266 user code where the signal trampoline will return
2267 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2268 But signal trampolines are pretty small stubs of
2269 code, anyway, so it's OK instead to just
2270 single-step out. Note: assuming such trampolines
2271 don't exhibit recursion on any platform... */
2272 find_pc_partial_function (stop_pc, &stop_func_name,
2275 /* Readjust stepping range */
2276 step_range_start = stop_func_start;
2277 step_range_end = stop_func_end;
2278 stepping_through_sigtramp = 1;
2283 /* If this is stepi or nexti, make sure that the stepping range
2284 gets us past that instruction. */
2285 if (step_range_end == 1)
2286 /* FIXME: Does this run afoul of the code below which, if
2287 we step into the middle of a line, resets the stepping
2289 step_range_end = (step_range_start = prev_pc) + 1;
2291 remove_breakpoints_on_following_step = 1;
2296 /* I disabled this test because it was too complicated and slow.
2297 The SKIP_PROLOGUE was especially slow, because it caused
2298 unnecessary prologue examination on various architectures.
2299 The code in the #else clause has been tested on the Sparc,
2300 Mips, PA, and Power architectures, so it's pretty likely to
2301 be correct. -Stu 10/24/95 */
2303 /* See if we left the step range due to a subroutine call that
2304 we should proceed to the end of. */
2306 if (stop_func_start)
2310 /* Do this after the IN_SIGTRAMP check; it might give
2312 prologue_pc = stop_func_start;
2314 /* Don't skip the prologue if this is assembly source */
2315 s = find_pc_symtab (stop_pc);
2316 if (s && s->language != language_asm)
2317 SKIP_PROLOGUE (prologue_pc);
2320 if (!(INNER_THAN (step_sp, read_sp ())) /* don't mistake (sig)return
2322 && (/* Might be a non-recursive call. If the symbols are missing
2323 enough that stop_func_start == prev_func_start even though
2324 they are really two functions, we will treat some calls as
2326 stop_func_start != prev_func_start
2328 /* Might be a recursive call if either we have a prologue
2329 or the call instruction itself saves the PC on the stack. */
2330 || prologue_pc != stop_func_start
2331 || read_sp () != step_sp)
2332 && (/* PC is completely out of bounds of any known objfiles. Treat
2333 like a subroutine call. */
2336 /* If we do a call, we will be at the start of a function... */
2337 || stop_pc == stop_func_start
2339 /* ...except on the Alpha with -O (and also Irix 5 and
2340 perhaps others), in which we might call the address
2341 after the load of gp. Since prologues don't contain
2342 calls, we can't return to within one, and we don't
2343 jump back into them, so this check is OK. */
2345 || stop_pc < prologue_pc
2347 /* ...and if it is a leaf function, the prologue might
2348 consist of gp loading only, so the call transfers to
2349 the first instruction after the prologue. */
2350 || (stop_pc == prologue_pc
2352 /* Distinguish this from the case where we jump back
2353 to the first instruction after the prologue,
2354 within a function. */
2355 && stop_func_start != prev_func_start)
2357 /* If we end up in certain places, it means we did a subroutine
2358 call. I'm not completely sure this is necessary now that we
2359 have the above checks with stop_func_start (and now that
2360 find_pc_partial_function is pickier). */
2361 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
2363 /* If none of the above apply, it is a jump within a function,
2364 or a return from a subroutine. The other case is longjmp,
2365 which can no longer happen here as long as the
2366 handling_longjmp stuff is working. */
2369 /* This test is a much more streamlined, (but hopefully correct)
2370 replacement for the code above. It's been tested on the Sparc,
2371 Mips, PA, and Power architectures with good results. */
2373 if (stop_pc == stop_func_start /* Quick test */
2374 || (in_prologue (stop_pc, stop_func_start) &&
2375 ! IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, stop_func_name))
2376 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
2377 || stop_func_name == 0)
2381 /* It's a subroutine call. */
2383 if (step_over_calls == 0)
2385 /* I presume that step_over_calls is only 0 when we're
2386 supposed to be stepping at the assembly language level
2387 ("stepi"). Just stop. */
2392 if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc))
2393 /* We're doing a "next". */
2394 goto step_over_function;
2396 /* If we are in a function call trampoline (a stub between
2397 the calling routine and the real function), locate the real
2398 function. That's what tells us (a) whether we want to step
2399 into it at all, and (b) what prologue we want to run to
2400 the end of, if we do step into it. */
2401 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2403 stop_func_start = tmp;
2406 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
2409 struct symtab_and_line xxx;
2410 /* Why isn't this s_a_l called "sr_sal", like all of the
2411 other s_a_l's where this code is duplicated? */
2412 INIT_SAL (&xxx); /* initialize to zeroes */
2414 xxx.section = find_pc_overlay (xxx.pc);
2415 step_resume_breakpoint =
2416 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
2417 insert_breakpoints ();
2422 /* If we have line number information for the function we
2423 are thinking of stepping into, step into it.
2425 If there are several symtabs at that PC (e.g. with include
2426 files), just want to know whether *any* of them have line
2427 numbers. find_pc_line handles this. */
2429 struct symtab_and_line tmp_sal;
2431 tmp_sal = find_pc_line (stop_func_start, 0);
2432 if (tmp_sal.line != 0)
2433 goto step_into_function;
2437 /* A subroutine call has happened. */
2439 /* Set a special breakpoint after the return */
2440 struct symtab_and_line sr_sal;
2443 sr_sal.symtab = NULL;
2446 /* If we came here after encountering a signal in the middle of
2447 a "next", use the stashed-away previous frame pc */
2449 = stopped_by_random_signal
2451 : ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2453 step_resume_breakpoint =
2454 set_momentary_breakpoint (sr_sal,
2455 stopped_by_random_signal ?
2456 NULL : get_current_frame (),
2459 /* We've just entered a callee, and we wish to resume until
2460 it returns to the caller. Setting a step_resume bp on
2461 the return PC will catch a return from the callee.
2463 However, if the callee is recursing, we want to be
2464 careful not to catch returns of those recursive calls,
2465 but of THIS instance of the call.
2467 To do this, we set the step_resume bp's frame to our
2468 current caller's frame (step_frame_address, which is
2469 set by the "next" or "until" command, before execution
2472 But ... don't do it if we're single-stepping out of a
2473 sigtramp, because the reason we're single-stepping is
2474 precisely because unwinding is a problem (HP-UX 10.20,
2475 e.g.) and the frame address is likely to be incorrect.
2476 No danger of sigtramp recursion. */
2478 if (stepping_through_sigtramp)
2480 step_resume_breakpoint->frame = (CORE_ADDR) NULL;
2481 stepping_through_sigtramp = 0;
2483 else if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
2484 step_resume_breakpoint->frame = step_frame_address;
2486 if (breakpoints_inserted)
2487 insert_breakpoints ();
2492 /* Subroutine call with source code we should not step over.
2493 Do step to the first line of code in it. */
2497 s = find_pc_symtab (stop_pc);
2498 if (s && s->language != language_asm)
2499 SKIP_PROLOGUE (stop_func_start);
2501 sal = find_pc_line (stop_func_start, 0);
2502 /* Use the step_resume_break to step until
2503 the end of the prologue, even if that involves jumps
2504 (as it seems to on the vax under 4.2). */
2505 /* If the prologue ends in the middle of a source line,
2506 continue to the end of that source line (if it is still
2507 within the function). Otherwise, just go to end of prologue. */
2508 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2509 /* no, don't either. It skips any code that's
2510 legitimately on the first line. */
2512 if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end)
2513 stop_func_start = sal.end;
2516 if (stop_func_start == stop_pc)
2518 /* We are already there: stop now. */
2523 /* Put the step-breakpoint there and go until there. */
2525 struct symtab_and_line sr_sal;
2527 INIT_SAL (&sr_sal); /* initialize to zeroes */
2528 sr_sal.pc = stop_func_start;
2529 sr_sal.section = find_pc_overlay (stop_func_start);
2530 /* Do not specify what the fp should be when we stop
2531 since on some machines the prologue
2532 is where the new fp value is established. */
2533 step_resume_breakpoint =
2534 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2535 if (breakpoints_inserted)
2536 insert_breakpoints ();
2538 /* And make sure stepping stops right away then. */
2539 step_range_end = step_range_start;
2544 /* We've wandered out of the step range. */
2546 sal = find_pc_line(stop_pc, 0);
2548 if (step_range_end == 1)
2550 /* It is stepi or nexti. We always want to stop stepping after
2556 /* If we're in the return path from a shared library trampoline,
2557 we want to proceed through the trampoline when stepping. */
2558 if (IN_SOLIB_RETURN_TRAMPOLINE(stop_pc, stop_func_name))
2562 /* Determine where this trampoline returns. */
2563 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2565 /* Only proceed through if we know where it's going. */
2568 /* And put the step-breakpoint there and go until there. */
2569 struct symtab_and_line sr_sal;
2571 INIT_SAL (&sr_sal); /* initialize to zeroes */
2573 sr_sal.section = find_pc_overlay (sr_sal.pc);
2574 /* Do not specify what the fp should be when we stop
2575 since on some machines the prologue
2576 is where the new fp value is established. */
2577 step_resume_breakpoint =
2578 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2579 if (breakpoints_inserted)
2580 insert_breakpoints ();
2582 /* Restart without fiddling with the step ranges or
2590 /* We have no line number information. That means to stop
2591 stepping (does this always happen right after one instruction,
2592 when we do "s" in a function with no line numbers,
2593 or can this happen as a result of a return or longjmp?). */
2598 if ((stop_pc == sal.pc)
2599 && (current_line != sal.line || current_symtab != sal.symtab))
2601 /* We are at the start of a different line. So stop. Note that
2602 we don't stop if we step into the middle of a different line.
2603 That is said to make things like for (;;) statements work
2609 /* We aren't done stepping.
2611 Optimize by setting the stepping range to the line.
2612 (We might not be in the original line, but if we entered a
2613 new line in mid-statement, we continue stepping. This makes
2614 things like for(;;) statements work better.) */
2616 if (stop_func_end && sal.end >= stop_func_end)
2618 /* If this is the last line of the function, don't keep stepping
2619 (it would probably step us out of the function).
2620 This is particularly necessary for a one-line function,
2621 in which after skipping the prologue we better stop even though
2622 we will be in mid-line. */
2626 step_range_start = sal.pc;
2627 step_range_end = sal.end;
2628 step_frame_address = FRAME_FP (get_current_frame ());
2629 current_line = sal.line;
2630 current_symtab = sal.symtab;
2632 /* In the case where we just stepped out of a function into the middle
2633 of a line of the caller, continue stepping, but step_frame_address
2634 must be modified to current frame */
2636 CORE_ADDR current_frame = FRAME_FP (get_current_frame());
2637 if (!(INNER_THAN (current_frame, step_frame_address)))
2638 step_frame_address = current_frame;
2646 && IN_SIGTRAMP (stop_pc, stop_func_name)
2647 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2648 && INNER_THAN (read_sp (), step_sp))
2650 /* What has happened here is that we have just stepped the inferior
2651 with a signal (because it is a signal which shouldn't make
2652 us stop), thus stepping into sigtramp.
2654 So we need to set a step_resume_break_address breakpoint
2655 and continue until we hit it, and then step. FIXME: This should
2656 be more enduring than a step_resume breakpoint; we should know
2657 that we will later need to keep going rather than re-hitting
2658 the breakpoint here (see testsuite/gdb.t06/signals.exp where
2659 it says "exceedingly difficult"). */
2660 struct symtab_and_line sr_sal;
2662 INIT_SAL (&sr_sal); /* initialize to zeroes */
2663 sr_sal.pc = prev_pc;
2664 sr_sal.section = find_pc_overlay (sr_sal.pc);
2665 /* We perhaps could set the frame if we kept track of what
2666 the frame corresponding to prev_pc was. But we don't,
2668 through_sigtramp_breakpoint =
2669 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
2670 if (breakpoints_inserted)
2671 insert_breakpoints ();
2673 remove_breakpoints_on_following_step = 1;
2678 /* Come to this label when you need to resume the inferior.
2679 It's really much cleaner to do a goto than a maze of if-else
2682 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug
2683 a vforked child beetween its creation and subsequent exit or
2684 call to exec(). However, I had big problems in this rather
2685 creaky exec engine, getting that to work. The fundamental
2686 problem is that I'm trying to debug two processes via an
2687 engine that only understands a single process with possibly
2690 Hence, this spot is known to have problems when
2691 target_can_follow_vfork_prior_to_exec returns 1. */
2693 /* Save the pc before execution, to compare with pc after stop. */
2694 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
2695 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
2696 BREAK is defined, the
2697 original pc would not have
2698 been at the start of a
2700 prev_func_name = stop_func_name;
2703 step_sp = read_sp ();
2706 /* If we did not do break;, it means we should keep
2707 running the inferior and not return to debugger. */
2709 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
2711 /* We took a signal (which we are supposed to pass through to
2712 the inferior, else we'd have done a break above) and we
2713 haven't yet gotten our trap. Simply continue. */
2714 resume (CURRENTLY_STEPPING (), stop_signal);
2718 /* Either the trap was not expected, but we are continuing
2719 anyway (the user asked that this signal be passed to the
2722 The signal was SIGTRAP, e.g. it was our signal, but we
2723 decided we should resume from it.
2725 We're going to run this baby now!
2727 Insert breakpoints now, unless we are trying
2728 to one-proceed past a breakpoint. */
2729 /* If we've just finished a special step resume and we don't
2730 want to hit a breakpoint, pull em out. */
2731 if (step_resume_breakpoint == NULL
2732 && through_sigtramp_breakpoint == NULL
2733 && remove_breakpoints_on_following_step)
2735 remove_breakpoints_on_following_step = 0;
2736 remove_breakpoints ();
2737 breakpoints_inserted = 0;
2739 else if (!breakpoints_inserted &&
2740 (through_sigtramp_breakpoint != NULL || !another_trap))
2742 breakpoints_failed = insert_breakpoints ();
2743 if (breakpoints_failed)
2745 breakpoints_inserted = 1;
2748 trap_expected = another_trap;
2750 if (stop_signal == TARGET_SIGNAL_TRAP)
2751 stop_signal = TARGET_SIGNAL_0;
2753 #ifdef SHIFT_INST_REGS
2754 /* I'm not sure when this following segment applies. I do know,
2755 now, that we shouldn't rewrite the regs when we were stopped
2756 by a random signal from the inferior process. */
2757 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2758 (this is only used on the 88k). */
2760 if (!bpstat_explains_signal (stop_bpstat)
2761 && (stop_signal != TARGET_SIGNAL_CHLD)
2762 && !stopped_by_random_signal)
2764 #endif /* SHIFT_INST_REGS */
2766 resume (CURRENTLY_STEPPING (), stop_signal);
2771 if (target_has_execution)
2773 /* Are we stopping for a vfork event? We only stop when we see
2774 the child's event. However, we may not yet have seen the
2775 parent's event. And, inferior_pid is still set to the parent's
2776 pid, until we resume again and follow either the parent or child.
2778 To ensure that we can really touch inferior_pid (aka, the
2779 parent process) -- which calls to functions like read_pc
2780 implicitly do -- wait on the parent if necessary. */
2781 if ((pending_follow.kind == TARGET_WAITKIND_VFORKED)
2782 && ! pending_follow.fork_event.saw_parent_fork)
2787 if (target_wait_hook)
2788 parent_pid = target_wait_hook (-1, &w);
2790 parent_pid = target_wait (-1, &w);
2791 } while (parent_pid != inferior_pid);
2795 /* Assuming the inferior still exists, set these up for next
2796 time, just like we did above if we didn't break out of the
2798 prev_pc = read_pc ();
2799 prev_func_start = stop_func_start;
2800 prev_func_name = stop_func_name;
2802 do_cleanups (old_cleanups);
2805 /* This function returns TRUE if ep is an internal breakpoint
2806 set to catch generic shared library (aka dynamically-linked
2807 library) events. (This is *NOT* the same as a catchpoint for a
2808 shlib event. The latter is something a user can set; this is
2809 something gdb sets for its own use, and isn't ever shown to a
2812 is_internal_shlib_eventpoint (ep)
2813 struct breakpoint * ep;
2816 (ep->type == bp_shlib_event)
2820 /* This function returns TRUE if bs indicates that the inferior
2821 stopped due to a shared library (aka dynamically-linked library)
2824 stopped_for_internal_shlib_event (bs)
2827 /* Note that multiple eventpoints may've caused the stop. Any
2828 that are associated with shlib events will be accepted. */
2829 for (;bs != NULL; bs = bs->next)
2831 if ((bs->breakpoint_at != NULL)
2832 && is_internal_shlib_eventpoint (bs->breakpoint_at))
2836 /* If we get here, then no candidate was found. */
2840 /* This function returns TRUE if bs indicates that the inferior
2841 stopped due to a shared library (aka dynamically-linked library)
2842 event caught by a catchpoint.
2844 If TRUE, cp_p is set to point to the catchpoint.
2846 Else, the value of cp_p is undefined. */
2848 stopped_for_shlib_catchpoint (bs, cp_p)
2850 struct breakpoint ** cp_p;
2852 /* Note that multiple eventpoints may've caused the stop. Any
2853 that are associated with shlib events will be accepted. */
2856 for (;bs != NULL; bs = bs->next)
2858 if ((bs->breakpoint_at != NULL)
2859 && ep_is_shlib_catchpoint (bs->breakpoint_at))
2861 *cp_p = bs->breakpoint_at;
2866 /* If we get here, then no candidate was found. */
2871 /* Here to return control to GDB when the inferior stops for real.
2872 Print appropriate messages, remove breakpoints, give terminal our modes.
2874 STOP_PRINT_FRAME nonzero means print the executing frame
2875 (pc, function, args, file, line number and line text).
2876 BREAKPOINTS_FAILED nonzero means stop was due to error
2877 attempting to insert breakpoints. */
2884 /* As with the notification of thread events, we want to delay
2885 notifying the user that we've switched thread context until
2886 the inferior actually stops.
2888 (Note that there's no point in saying anything if the inferior
2890 if ((switched_from_inferior_pid != inferior_pid) &&
2891 target_has_execution)
2893 target_terminal_ours_for_output ();
2894 printf_filtered ("[Switched to %s]\n",
2895 target_pid_or_tid_to_str (inferior_pid));
2896 switched_from_inferior_pid = inferior_pid;
2900 /* Make sure that the current_frame's pc is correct. This
2901 is a correction for setting up the frame info before doing
2902 DECR_PC_AFTER_BREAK */
2903 if (target_has_execution && get_current_frame())
2904 (get_current_frame ())->pc = read_pc ();
2906 if (breakpoints_failed)
2908 target_terminal_ours_for_output ();
2909 print_sys_errmsg ("ptrace", breakpoints_failed);
2910 printf_filtered ("Stopped; cannot insert breakpoints.\n\
2911 The same program may be running in another process.\n");
2914 if (target_has_execution && breakpoints_inserted)
2916 if (remove_breakpoints ())
2918 target_terminal_ours_for_output ();
2919 printf_filtered ("Cannot remove breakpoints because ");
2920 printf_filtered ("program is no longer writable.\n");
2921 printf_filtered ("It might be running in another process.\n");
2922 printf_filtered ("Further execution is probably impossible.\n");
2925 breakpoints_inserted = 0;
2927 /* Delete the breakpoint we stopped at, if it wants to be deleted.
2928 Delete any breakpoint that is to be deleted at the next stop. */
2930 breakpoint_auto_delete (stop_bpstat);
2932 /* If an auto-display called a function and that got a signal,
2933 delete that auto-display to avoid an infinite recursion. */
2935 if (stopped_by_random_signal)
2936 disable_current_display ();
2938 /* Don't print a message if in the middle of doing a "step n"
2939 operation for n > 1 */
2940 if (step_multi && stop_step)
2943 target_terminal_ours ();
2945 /* Did we stop because the user set the stop_on_solib_events
2946 variable? (If so, we report this as a generic, "Stopped due
2947 to shlib event" message.) */
2948 if (stopped_for_internal_shlib_event (stop_bpstat))
2950 printf_filtered ("Stopped due to shared library event\n");
2953 /* Look up the hook_stop and run it if it exists. */
2955 if (stop_command && stop_command->hook)
2957 catch_errors (hook_stop_stub, (char *)stop_command->hook,
2958 "Error while running hook_stop:\n", RETURN_MASK_ALL);
2961 if (!target_has_stack)
2967 /* Select innermost stack frame - i.e., current frame is frame 0,
2968 and current location is based on that.
2969 Don't do this on return from a stack dummy routine,
2970 or if the program has exited. */
2972 if (!stop_stack_dummy)
2974 select_frame (get_current_frame (), 0);
2976 /* Print current location without a level number, if
2977 we have changed functions or hit a breakpoint.
2978 Print source line if we have one.
2979 bpstat_print() contains the logic deciding in detail
2980 what to print, based on the event(s) that just occurred. */
2982 if (stop_print_frame)
2987 bpstat_ret = bpstat_print (stop_bpstat);
2988 /* bpstat_print() returned one of:
2989 -1: Didn't print anything
2990 0: Printed preliminary "Breakpoint n, " message, desires
2992 1: Printed something, don't tack on location */
2994 if (bpstat_ret == -1)
2996 && step_frame_address == FRAME_FP (get_current_frame ())
2997 && step_start_function == find_pc_function (stop_pc))
2998 source_flag = -1; /* finished step, just print source line */
3000 source_flag = 1; /* print location and source line */
3001 else if (bpstat_ret == 0) /* hit bpt, desire location */
3002 source_flag = 1; /* print location and source line */
3003 else /* bpstat_ret == 1, hit bpt, do not desire location */
3004 source_flag = -1; /* just print source line */
3006 /* The behavior of this routine with respect to the source
3008 -1: Print only source line
3009 0: Print only location
3010 1: Print location and source line */
3011 show_and_print_stack_frame (selected_frame, -1, source_flag);
3013 /* Display the auto-display expressions. */
3018 /* Save the function value return registers, if we care.
3019 We might be about to restore their previous contents. */
3020 if (proceed_to_finish)
3021 read_register_bytes (0, stop_registers, REGISTER_BYTES);
3023 if (stop_stack_dummy)
3025 /* Pop the empty frame that contains the stack dummy.
3026 POP_FRAME ends with a setting of the current frame, so we
3027 can use that next. */
3029 /* Set stop_pc to what it was before we called the function.
3030 Can't rely on restore_inferior_status because that only gets
3031 called if we don't stop in the called function. */
3032 stop_pc = read_pc();
3033 select_frame (get_current_frame (), 0);
3037 TUIDO (((TuiOpaqueFuncPtr)tui_vCheckDataValues, selected_frame));
3040 annotate_stopped ();
3044 hook_stop_stub (cmd)
3047 execute_user_command ((struct cmd_list_element *)cmd, 0);
3051 int signal_stop_state (signo)
3054 return signal_stop[signo];
3057 int signal_print_state (signo)
3060 return signal_print[signo];
3063 int signal_pass_state (signo)
3066 return signal_program[signo];
3073 Signal Stop\tPrint\tPass to program\tDescription\n");
3077 sig_print_info (oursig)
3078 enum target_signal oursig;
3080 char *name = target_signal_to_name (oursig);
3081 int name_padding = 13 - strlen (name);
3082 if (name_padding <= 0)
3085 printf_filtered ("%s", name);
3086 printf_filtered ("%*.*s ", name_padding, name_padding,
3088 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3089 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3090 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3091 printf_filtered ("%s\n", target_signal_to_string (oursig));
3094 /* Specify how various signals in the inferior should be handled. */
3097 handle_command (args, from_tty)
3102 int digits, wordlen;
3103 int sigfirst, signum, siglast;
3104 enum target_signal oursig;
3107 unsigned char *sigs;
3108 struct cleanup *old_chain;
3112 error_no_arg ("signal to handle");
3115 /* Allocate and zero an array of flags for which signals to handle. */
3117 nsigs = (int)TARGET_SIGNAL_LAST;
3118 sigs = (unsigned char *) alloca (nsigs);
3119 memset (sigs, 0, nsigs);
3121 /* Break the command line up into args. */
3123 argv = buildargv (args);
3128 old_chain = make_cleanup ((make_cleanup_func) freeargv, (char *) argv);
3130 /* Walk through the args, looking for signal oursigs, signal names, and
3131 actions. Signal numbers and signal names may be interspersed with
3132 actions, with the actions being performed for all signals cumulatively
3133 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3135 while (*argv != NULL)
3137 wordlen = strlen (*argv);
3138 for (digits = 0; isdigit ((*argv)[digits]); digits++) {;}
3140 sigfirst = siglast = -1;
3142 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3144 /* Apply action to all signals except those used by the
3145 debugger. Silently skip those. */
3148 siglast = nsigs - 1;
3150 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3152 SET_SIGS (nsigs, sigs, signal_stop);
3153 SET_SIGS (nsigs, sigs, signal_print);
3155 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3157 UNSET_SIGS (nsigs, sigs, signal_program);
3159 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3161 SET_SIGS (nsigs, sigs, signal_print);
3163 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3165 SET_SIGS (nsigs, sigs, signal_program);
3167 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3169 UNSET_SIGS (nsigs, sigs, signal_stop);
3171 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3173 SET_SIGS (nsigs, sigs, signal_program);
3175 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3177 UNSET_SIGS (nsigs, sigs, signal_print);
3178 UNSET_SIGS (nsigs, sigs, signal_stop);
3180 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3182 UNSET_SIGS (nsigs, sigs, signal_program);
3184 else if (digits > 0)
3186 /* It is numeric. The numeric signal refers to our own
3187 internal signal numbering from target.h, not to host/target
3188 signal number. This is a feature; users really should be
3189 using symbolic names anyway, and the common ones like
3190 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3192 sigfirst = siglast = (int)
3193 target_signal_from_command (atoi (*argv));
3194 if ((*argv)[digits] == '-')
3197 target_signal_from_command (atoi ((*argv) + digits + 1));
3199 if (sigfirst > siglast)
3201 /* Bet he didn't figure we'd think of this case... */
3209 oursig = target_signal_from_name (*argv);
3210 if (oursig != TARGET_SIGNAL_UNKNOWN)
3212 sigfirst = siglast = (int)oursig;
3216 /* Not a number and not a recognized flag word => complain. */
3217 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3221 /* If any signal numbers or symbol names were found, set flags for
3222 which signals to apply actions to. */
3224 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3226 switch ((enum target_signal)signum)
3228 case TARGET_SIGNAL_TRAP:
3229 case TARGET_SIGNAL_INT:
3230 if (!allsigs && !sigs[signum])
3232 if (query ("%s is used by the debugger.\n\
3233 Are you sure you want to change it? ",
3234 target_signal_to_name
3235 ((enum target_signal)signum)))
3241 printf_unfiltered ("Not confirmed, unchanged.\n");
3242 gdb_flush (gdb_stdout);
3246 case TARGET_SIGNAL_0:
3247 case TARGET_SIGNAL_DEFAULT:
3248 case TARGET_SIGNAL_UNKNOWN:
3249 /* Make sure that "all" doesn't print these. */
3260 target_notice_signals(inferior_pid);
3264 /* Show the results. */
3265 sig_print_header ();
3266 for (signum = 0; signum < nsigs; signum++)
3270 sig_print_info (signum);
3275 do_cleanups (old_chain);
3279 xdb_handle_command (args, from_tty)
3284 struct cleanup *old_chain;
3286 /* Break the command line up into args. */
3288 argv = buildargv (args);
3293 old_chain = make_cleanup ((make_cleanup_func) freeargv, (char *) argv);
3294 if (argv[1] != (char *)NULL)
3299 bufLen = strlen(argv[0]) + 20;
3300 argBuf = (char *)xmalloc(bufLen);
3304 enum target_signal oursig;
3306 oursig = target_signal_from_name (argv[0]);
3307 memset(argBuf, 0, bufLen);
3308 if (strcmp(argv[1], "Q") == 0)
3309 sprintf(argBuf, "%s %s", argv[0], "noprint");
3312 if (strcmp(argv[1], "s") == 0)
3314 if (!signal_stop[oursig])
3315 sprintf(argBuf, "%s %s", argv[0], "stop");
3317 sprintf(argBuf, "%s %s", argv[0], "nostop");
3319 else if (strcmp(argv[1], "i") == 0)
3321 if (!signal_program[oursig])
3322 sprintf(argBuf, "%s %s", argv[0], "pass");
3324 sprintf(argBuf, "%s %s", argv[0], "nopass");
3326 else if (strcmp(argv[1], "r") == 0)
3328 if (!signal_print[oursig])
3329 sprintf(argBuf, "%s %s", argv[0], "print");
3331 sprintf(argBuf, "%s %s", argv[0], "noprint");
3337 handle_command(argBuf, from_tty);
3339 printf_filtered("Invalid signal handling flag.\n");
3344 do_cleanups (old_chain);
3347 /* Print current contents of the tables set by the handle command.
3348 It is possible we should just be printing signals actually used
3349 by the current target (but for things to work right when switching
3350 targets, all signals should be in the signal tables). */
3353 signals_info (signum_exp, from_tty)
3357 enum target_signal oursig;
3358 sig_print_header ();
3362 /* First see if this is a symbol name. */
3363 oursig = target_signal_from_name (signum_exp);
3364 if (oursig == TARGET_SIGNAL_UNKNOWN)
3366 /* No, try numeric. */
3368 target_signal_from_command (parse_and_eval_address (signum_exp));
3370 sig_print_info (oursig);
3374 printf_filtered ("\n");
3375 /* These ugly casts brought to you by the native VAX compiler. */
3376 for (oursig = TARGET_SIGNAL_FIRST;
3377 (int)oursig < (int)TARGET_SIGNAL_LAST;
3378 oursig = (enum target_signal)((int)oursig + 1))
3382 if (oursig != TARGET_SIGNAL_UNKNOWN
3383 && oursig != TARGET_SIGNAL_DEFAULT
3384 && oursig != TARGET_SIGNAL_0)
3385 sig_print_info (oursig);
3388 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3391 /* Save all of the information associated with the inferior<==>gdb
3392 connection. INF_STATUS is a pointer to a "struct inferior_status"
3393 (defined in inferior.h). */
3396 save_inferior_status (inf_status, restore_stack_info)
3397 struct inferior_status *inf_status;
3398 int restore_stack_info;
3400 inf_status->stop_signal = stop_signal;
3401 inf_status->stop_pc = stop_pc;
3402 inf_status->stop_step = stop_step;
3403 inf_status->stop_stack_dummy = stop_stack_dummy;
3404 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3405 inf_status->trap_expected = trap_expected;
3406 inf_status->step_range_start = step_range_start;
3407 inf_status->step_range_end = step_range_end;
3408 inf_status->step_frame_address = step_frame_address;
3409 inf_status->step_over_calls = step_over_calls;
3410 inf_status->stop_after_trap = stop_after_trap;
3411 inf_status->stop_soon_quietly = stop_soon_quietly;
3412 /* Save original bpstat chain here; replace it with copy of chain.
3413 If caller's caller is walking the chain, they'll be happier if we
3414 hand them back the original chain when restore_i_s is called. */
3415 inf_status->stop_bpstat = stop_bpstat;
3416 stop_bpstat = bpstat_copy (stop_bpstat);
3417 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3418 inf_status->restore_stack_info = restore_stack_info;
3419 inf_status->proceed_to_finish = proceed_to_finish;
3421 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
3423 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3425 record_selected_frame (&(inf_status->selected_frame_address),
3426 &(inf_status->selected_level));
3430 struct restore_selected_frame_args {
3431 CORE_ADDR frame_address;
3435 static int restore_selected_frame PARAMS ((char *));
3437 /* Restore the selected frame. args is really a struct
3438 restore_selected_frame_args * (declared as char * for catch_errors)
3439 telling us what frame to restore. Returns 1 for success, or 0 for
3440 failure. An error message will have been printed on error. */
3443 restore_selected_frame (args)
3446 struct restore_selected_frame_args *fr =
3447 (struct restore_selected_frame_args *) args;
3448 struct frame_info *frame;
3449 int level = fr->level;
3451 frame = find_relative_frame (get_current_frame (), &level);
3453 /* If inf_status->selected_frame_address is NULL, there was no
3454 previously selected frame. */
3455 if (frame == NULL ||
3456 /* FRAME_FP (frame) != fr->frame_address || */
3457 /* elz: deleted this check as a quick fix to the problem that
3458 for function called by hand gdb creates no internal frame
3459 structure and the real stack and gdb's idea of stack are
3460 different if nested calls by hands are made.
3462 mvs: this worries me. */
3465 warning ("Unable to restore previously selected frame.\n");
3469 select_frame (frame, fr->level);
3475 restore_inferior_status (inf_status)
3476 struct inferior_status *inf_status;
3478 stop_signal = inf_status->stop_signal;
3479 stop_pc = inf_status->stop_pc;
3480 stop_step = inf_status->stop_step;
3481 stop_stack_dummy = inf_status->stop_stack_dummy;
3482 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3483 trap_expected = inf_status->trap_expected;
3484 step_range_start = inf_status->step_range_start;
3485 step_range_end = inf_status->step_range_end;
3486 step_frame_address = inf_status->step_frame_address;
3487 step_over_calls = inf_status->step_over_calls;
3488 stop_after_trap = inf_status->stop_after_trap;
3489 stop_soon_quietly = inf_status->stop_soon_quietly;
3490 bpstat_clear (&stop_bpstat);
3491 stop_bpstat = inf_status->stop_bpstat;
3492 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3493 proceed_to_finish = inf_status->proceed_to_finish;
3495 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
3497 /* The inferior can be gone if the user types "print exit(0)"
3498 (and perhaps other times). */
3499 if (target_has_execution)
3500 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3502 /* The inferior can be gone if the user types "print exit(0)"
3503 (and perhaps other times). */
3505 /* FIXME: If we are being called after stopping in a function which
3506 is called from gdb, we should not be trying to restore the
3507 selected frame; it just prints a spurious error message (The
3508 message is useful, however, in detecting bugs in gdb (like if gdb
3509 clobbers the stack)). In fact, should we be restoring the
3510 inferior status at all in that case? . */
3512 if (target_has_stack && inf_status->restore_stack_info)
3514 struct restore_selected_frame_args fr;
3515 fr.level = inf_status->selected_level;
3516 fr.frame_address = inf_status->selected_frame_address;
3517 /* The point of catch_errors is that if the stack is clobbered,
3518 walking the stack might encounter a garbage pointer and error()
3519 trying to dereference it. */
3520 if (catch_errors (restore_selected_frame, &fr,
3521 "Unable to restore previously selected frame:\n",
3522 RETURN_MASK_ERROR) == 0)
3523 /* Error in restoring the selected frame. Select the innermost
3527 select_frame (get_current_frame (), 0);
3535 set_follow_fork_mode_command (arg, from_tty, c)
3538 struct cmd_list_element * c;
3540 if (! STREQ (arg, "parent") &&
3541 ! STREQ (arg, "child") &&
3542 ! STREQ (arg, "both") &&
3543 ! STREQ (arg, "ask"))
3544 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
3546 if (follow_fork_mode_string != NULL)
3547 free (follow_fork_mode_string);
3548 follow_fork_mode_string = savestring (arg, strlen (arg));
3554 _initialize_infrun ()
3557 register int numsigs;
3558 struct cmd_list_element * c;
3560 add_info ("signals", signals_info,
3561 "What debugger does when program gets various signals.\n\
3562 Specify a signal as argument to print info on that signal only.");
3563 add_info_alias ("handle", "signals", 0);
3565 add_com ("handle", class_run, handle_command,
3566 concat ("Specify how to handle a signal.\n\
3567 Args are signals and actions to apply to those signals.\n\
3568 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3569 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3570 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3571 The special arg \"all\" is recognized to mean all signals except those\n\
3572 used by the debugger, typically SIGTRAP and SIGINT.\n",
3573 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3574 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3575 Stop means reenter debugger if this signal happens (implies print).\n\
3576 Print means print a message if this signal happens.\n\
3577 Pass means let program see this signal; otherwise program doesn't know.\n\
3578 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3579 Pass and Stop may be combined.", NULL));
3582 add_com("lz", class_info, signals_info,
3583 "What debugger does when program gets various signals.\n\
3584 Specify a signal as argument to print info on that signal only.");
3585 add_com("z", class_run, xdb_handle_command,
3586 concat ("Specify how to handle a signal.\n\
3587 Args are signals and actions to apply to those signals.\n\
3588 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3589 from 1-15 are allowed for compatibility with old versions of GDB.\n\
3590 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3591 The special arg \"all\" is recognized to mean all signals except those\n\
3592 used by the debugger, typically SIGTRAP and SIGINT.\n",
3593 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3594 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3595 nopass), \"Q\" (noprint)\n\
3596 Stop means reenter debugger if this signal happens (implies print).\n\
3597 Print means print a message if this signal happens.\n\
3598 Pass means let program see this signal; otherwise program doesn't know.\n\
3599 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3600 Pass and Stop may be combined.", NULL));
3604 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
3605 "There is no `stop' command, but you can set a hook on `stop'.\n\
3606 This allows you to set a list of commands to be run each time execution\n\
3607 of the program stops.", &cmdlist);
3609 numsigs = (int)TARGET_SIGNAL_LAST;
3610 signal_stop = (unsigned char *)
3611 xmalloc (sizeof (signal_stop[0]) * numsigs);
3612 signal_print = (unsigned char *)
3613 xmalloc (sizeof (signal_print[0]) * numsigs);
3614 signal_program = (unsigned char *)
3615 xmalloc (sizeof (signal_program[0]) * numsigs);
3616 for (i = 0; i < numsigs; i++)
3619 signal_print[i] = 1;
3620 signal_program[i] = 1;
3623 /* Signals caused by debugger's own actions
3624 should not be given to the program afterwards. */
3625 signal_program[TARGET_SIGNAL_TRAP] = 0;
3626 signal_program[TARGET_SIGNAL_INT] = 0;
3628 /* Signals that are not errors should not normally enter the debugger. */
3629 signal_stop[TARGET_SIGNAL_ALRM] = 0;
3630 signal_print[TARGET_SIGNAL_ALRM] = 0;
3631 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
3632 signal_print[TARGET_SIGNAL_VTALRM] = 0;
3633 signal_stop[TARGET_SIGNAL_PROF] = 0;
3634 signal_print[TARGET_SIGNAL_PROF] = 0;
3635 signal_stop[TARGET_SIGNAL_CHLD] = 0;
3636 signal_print[TARGET_SIGNAL_CHLD] = 0;
3637 signal_stop[TARGET_SIGNAL_IO] = 0;
3638 signal_print[TARGET_SIGNAL_IO] = 0;
3639 signal_stop[TARGET_SIGNAL_POLL] = 0;
3640 signal_print[TARGET_SIGNAL_POLL] = 0;
3641 signal_stop[TARGET_SIGNAL_URG] = 0;
3642 signal_print[TARGET_SIGNAL_URG] = 0;
3646 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
3647 (char *) &stop_on_solib_events,
3648 "Set stopping for shared library events.\n\
3649 If nonzero, gdb will give control to the user when the dynamic linker\n\
3650 notifies gdb of shared library events. The most common event of interest\n\
3651 to the user would be loading/unloading of a new library.\n",
3656 c = add_set_enum_cmd ("follow-fork-mode",
3658 follow_fork_mode_kind_names,
3659 (char *) &follow_fork_mode_string,
3660 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
3661 kernel problem. It's also not terribly useful without a GUI to
3662 help the user drive two debuggers. So for now, I'm disabling
3663 the "both" option. */
3664 /* "Set debugger response to a program call of fork \
3666 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3667 parent - the original process is debugged after a fork\n\
3668 child - the new process is debugged after a fork\n\
3669 both - both the parent and child are debugged after a fork\n\
3670 ask - the debugger will ask for one of the above choices\n\
3671 For \"both\", another copy of the debugger will be started to follow\n\
3672 the new child process. The original debugger will continue to follow\n\
3673 the original parent process. To distinguish their prompts, the\n\
3674 debugger copy's prompt will be changed.\n\
3675 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3676 By default, the debugger will follow the parent process.",
3678 "Set debugger response to a program call of fork \
3680 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3681 parent - the original process is debugged after a fork\n\
3682 child - the new process is debugged after a fork\n\
3683 ask - the debugger will ask for one of the above choices\n\
3684 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3685 By default, the debugger will follow the parent process.",
3687 /* c->function.sfunc = ;*/
3688 add_show_from_set (c, &showlist);
3690 set_follow_fork_mode_command ("parent", 0, NULL);