1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986-1989, 1991-1999 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
27 #include "breakpoint.h"
32 #include "gdbthread.h"
34 #include "symfile.h" /* for overlay functions */
39 /* Prototypes for local functions */
41 static void signals_info (char *, int);
43 static void handle_command (char *, int);
45 static void sig_print_info (enum target_signal
);
47 static void sig_print_header (void);
49 static void resume_cleanups (int);
51 static int hook_stop_stub (void *);
53 static void delete_breakpoint_current_contents (void *);
55 static void set_follow_fork_mode_command (char *arg
, int from_tty
,
56 struct cmd_list_element
* c
);
58 static struct inferior_status
*xmalloc_inferior_status (void);
60 static void free_inferior_status (struct inferior_status
*);
62 static int restore_selected_frame (void *);
64 static void build_infrun (void);
66 static void follow_inferior_fork (int parent_pid
, int child_pid
,
67 int has_forked
, int has_vforked
);
69 static void follow_fork (int parent_pid
, int child_pid
);
71 static void follow_vfork (int parent_pid
, int child_pid
);
73 static void set_schedlock_func (char *args
, int from_tty
,
74 struct cmd_list_element
* c
);
76 struct execution_control_state
;
78 static int currently_stepping (struct execution_control_state
*ecs
);
80 static void xdb_handle_command (char *args
, int from_tty
);
82 void _initialize_infrun (void);
84 int inferior_ignoring_startup_exec_events
= 0;
85 int inferior_ignoring_leading_exec_events
= 0;
87 /* In asynchronous mode, but simulating synchronous execution. */
89 int sync_execution
= 0;
91 /* wait_for_inferior and normal_stop use this to notify the user
92 when the inferior stopped in a different thread than it had been
95 static int switched_from_inferior_pid
;
97 /* This will be true for configurations that may actually report an
98 inferior pid different from the original. At present this is only
99 true for HP-UX native. */
101 #ifndef MAY_SWITCH_FROM_INFERIOR_PID
102 #define MAY_SWITCH_FROM_INFERIOR_PID (0)
105 static int may_switch_from_inferior_pid
= MAY_SWITCH_FROM_INFERIOR_PID
;
107 /* This is true for configurations that may follow through execl() and
108 similar functions. At present this is only true for HP-UX native. */
110 #ifndef MAY_FOLLOW_EXEC
111 #define MAY_FOLLOW_EXEC (0)
114 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
116 /* resume and wait_for_inferior use this to ensure that when
117 stepping over a hit breakpoint in a threaded application
118 only the thread that hit the breakpoint is stepped and the
119 other threads don't continue. This prevents having another
120 thread run past the breakpoint while it is temporarily
123 This is not thread-specific, so it isn't saved as part of
126 Versions of gdb which don't use the "step == this thread steps
127 and others continue" model but instead use the "step == this
128 thread steps and others wait" shouldn't do this. */
130 static int thread_step_needed
= 0;
132 /* This is true if thread_step_needed should actually be used. At
133 present this is only true for HP-UX native. */
135 #ifndef USE_THREAD_STEP_NEEDED
136 #define USE_THREAD_STEP_NEEDED (0)
139 static int use_thread_step_needed
= USE_THREAD_STEP_NEEDED
;
141 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
142 program. It needs to examine the jmp_buf argument and extract the PC
143 from it. The return value is non-zero on success, zero otherwise. */
145 #ifndef GET_LONGJMP_TARGET
146 #define GET_LONGJMP_TARGET(PC_ADDR) 0
150 /* Some machines have trampoline code that sits between function callers
151 and the actual functions themselves. If this machine doesn't have
152 such things, disable their processing. */
154 #ifndef SKIP_TRAMPOLINE_CODE
155 #define SKIP_TRAMPOLINE_CODE(pc) 0
158 /* Dynamic function trampolines are similar to solib trampolines in that they
159 are between the caller and the callee. The difference is that when you
160 enter a dynamic trampoline, you can't determine the callee's address. Some
161 (usually complex) code needs to run in the dynamic trampoline to figure out
162 the callee's address. This macro is usually called twice. First, when we
163 enter the trampoline (looks like a normal function call at that point). It
164 should return the PC of a point within the trampoline where the callee's
165 address is known. Second, when we hit the breakpoint, this routine returns
166 the callee's address. At that point, things proceed as per a step resume
169 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
170 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
173 /* If the program uses ELF-style shared libraries, then calls to
174 functions in shared libraries go through stubs, which live in a
175 table called the PLT (Procedure Linkage Table). The first time the
176 function is called, the stub sends control to the dynamic linker,
177 which looks up the function's real address, patches the stub so
178 that future calls will go directly to the function, and then passes
179 control to the function.
181 If we are stepping at the source level, we don't want to see any of
182 this --- we just want to skip over the stub and the dynamic linker.
183 The simple approach is to single-step until control leaves the
186 However, on some systems (e.g., Red Hat Linux 5.2) the dynamic
187 linker calls functions in the shared C library, so you can't tell
188 from the PC alone whether the dynamic linker is still running. In
189 this case, we use a step-resume breakpoint to get us past the
190 dynamic linker, as if we were using "next" to step over a function
193 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
194 linker code or not. Normally, this means we single-step. However,
195 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
196 address where we can place a step-resume breakpoint to get past the
197 linker's symbol resolution function.
199 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
200 pretty portable way, by comparing the PC against the address ranges
201 of the dynamic linker's sections.
203 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
204 it depends on internal details of the dynamic linker. It's usually
205 not too hard to figure out where to put a breakpoint, but it
206 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
207 sanity checking. If it can't figure things out, returning zero and
208 getting the (possibly confusing) stepping behavior is better than
209 signalling an error, which will obscure the change in the
212 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
213 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
216 #ifndef SKIP_SOLIB_RESOLVER
217 #define SKIP_SOLIB_RESOLVER(pc) 0
220 /* For SVR4 shared libraries, each call goes through a small piece of
221 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
222 to nonzero if we are current stopped in one of these. */
224 #ifndef IN_SOLIB_CALL_TRAMPOLINE
225 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
228 /* In some shared library schemes, the return path from a shared library
229 call may need to go through a trampoline too. */
231 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
232 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
235 /* This function returns TRUE if pc is the address of an instruction
236 that lies within the dynamic linker (such as the event hook, or the
239 This function must be used only when a dynamic linker event has
240 been caught, and the inferior is being stepped out of the hook, or
241 undefined results are guaranteed. */
243 #ifndef SOLIB_IN_DYNAMIC_LINKER
244 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
247 /* On MIPS16, a function that returns a floating point value may call
248 a library helper function to copy the return value to a floating point
249 register. The IGNORE_HELPER_CALL macro returns non-zero if we
250 should ignore (i.e. step over) this function call. */
251 #ifndef IGNORE_HELPER_CALL
252 #define IGNORE_HELPER_CALL(pc) 0
255 /* On some systems, the PC may be left pointing at an instruction that won't
256 actually be executed. This is usually indicated by a bit in the PSW. If
257 we find ourselves in such a state, then we step the target beyond the
258 nullified instruction before returning control to the user so as to avoid
261 #ifndef INSTRUCTION_NULLIFIED
262 #define INSTRUCTION_NULLIFIED 0
265 /* We can't step off a permanent breakpoint in the ordinary way, because we
266 can't remove it. Instead, we have to advance the PC to the next
267 instruction. This macro should expand to a pointer to a function that
268 does that, or zero if we have no such function. If we don't have a
269 definition for it, we have to report an error. */
270 #ifndef SKIP_PERMANENT_BREAKPOINT
271 #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint)
273 default_skip_permanent_breakpoint ()
276 fprintf_filtered (gdb_stderr
, "\
277 The program is stopped at a permanent breakpoint, but GDB does not know\n\
278 how to step past a permanent breakpoint on this architecture. Try using\n\
279 a command like `return' or `jump' to continue execution.\n");
280 return_to_top_level (RETURN_ERROR
);
285 /* Convert the #defines into values. This is temporary until wfi control
286 flow is completely sorted out. */
288 #ifndef HAVE_STEPPABLE_WATCHPOINT
289 #define HAVE_STEPPABLE_WATCHPOINT 0
291 #undef HAVE_STEPPABLE_WATCHPOINT
292 #define HAVE_STEPPABLE_WATCHPOINT 1
295 #ifndef HAVE_NONSTEPPABLE_WATCHPOINT
296 #define HAVE_NONSTEPPABLE_WATCHPOINT 0
298 #undef HAVE_NONSTEPPABLE_WATCHPOINT
299 #define HAVE_NONSTEPPABLE_WATCHPOINT 1
302 #ifndef HAVE_CONTINUABLE_WATCHPOINT
303 #define HAVE_CONTINUABLE_WATCHPOINT 0
305 #undef HAVE_CONTINUABLE_WATCHPOINT
306 #define HAVE_CONTINUABLE_WATCHPOINT 1
309 /* Tables of how to react to signals; the user sets them. */
311 static unsigned char *signal_stop
;
312 static unsigned char *signal_print
;
313 static unsigned char *signal_program
;
315 #define SET_SIGS(nsigs,sigs,flags) \
317 int signum = (nsigs); \
318 while (signum-- > 0) \
319 if ((sigs)[signum]) \
320 (flags)[signum] = 1; \
323 #define UNSET_SIGS(nsigs,sigs,flags) \
325 int signum = (nsigs); \
326 while (signum-- > 0) \
327 if ((sigs)[signum]) \
328 (flags)[signum] = 0; \
332 /* Command list pointer for the "stop" placeholder. */
334 static struct cmd_list_element
*stop_command
;
336 /* Nonzero if breakpoints are now inserted in the inferior. */
338 static int breakpoints_inserted
;
340 /* Function inferior was in as of last step command. */
342 static struct symbol
*step_start_function
;
344 /* Nonzero if we are expecting a trace trap and should proceed from it. */
346 static int trap_expected
;
349 /* Nonzero if we want to give control to the user when we're notified
350 of shared library events by the dynamic linker. */
351 static int stop_on_solib_events
;
355 /* Nonzero if the next time we try to continue the inferior, it will
356 step one instruction and generate a spurious trace trap.
357 This is used to compensate for a bug in HP-UX. */
359 static int trap_expected_after_continue
;
362 /* Nonzero means expecting a trace trap
363 and should stop the inferior and return silently when it happens. */
367 /* Nonzero means expecting a trap and caller will handle it themselves.
368 It is used after attach, due to attaching to a process;
369 when running in the shell before the child program has been exec'd;
370 and when running some kinds of remote stuff (FIXME?). */
372 int stop_soon_quietly
;
374 /* Nonzero if proceed is being used for a "finish" command or a similar
375 situation when stop_registers should be saved. */
377 int proceed_to_finish
;
379 /* Save register contents here when about to pop a stack dummy frame,
380 if-and-only-if proceed_to_finish is set.
381 Thus this contains the return value from the called function (assuming
382 values are returned in a register). */
384 char *stop_registers
;
386 /* Nonzero if program stopped due to error trying to insert breakpoints. */
388 static int breakpoints_failed
;
390 /* Nonzero after stop if current stack frame should be printed. */
392 static int stop_print_frame
;
394 static struct breakpoint
*step_resume_breakpoint
= NULL
;
395 static struct breakpoint
*through_sigtramp_breakpoint
= NULL
;
397 /* On some platforms (e.g., HP-UX), hardware watchpoints have bad
398 interactions with an inferior that is running a kernel function
399 (aka, a system call or "syscall"). wait_for_inferior therefore
400 may have a need to know when the inferior is in a syscall. This
401 is a count of the number of inferior threads which are known to
402 currently be running in a syscall. */
403 static int number_of_threads_in_syscalls
;
405 /* This is used to remember when a fork, vfork or exec event
406 was caught by a catchpoint, and thus the event is to be
407 followed at the next resume of the inferior, and not
411 enum target_waitkind kind
;
421 char *execd_pathname
;
425 /* Some platforms don't allow us to do anything meaningful with a
426 vforked child until it has exec'd. Vforked processes on such
427 platforms can only be followed after they've exec'd.
429 When this is set to 0, a vfork can be immediately followed,
430 and an exec can be followed merely as an exec. When this is
431 set to 1, a vfork event has been seen, but cannot be followed
432 until the exec is seen.
434 (In the latter case, inferior_pid is still the parent of the
435 vfork, and pending_follow.fork_event.child_pid is the child. The
436 appropriate process is followed, according to the setting of
437 follow-fork-mode.) */
438 static int follow_vfork_when_exec
;
440 static char *follow_fork_mode_kind_names
[] =
442 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
443 kernel problem. It's also not terribly useful without a GUI to
444 help the user drive two debuggers. So for now, I'm disabling
446 "parent", "child", "both", "ask" };
448 "parent", "child", "ask"};
450 static char *follow_fork_mode_string
= NULL
;
454 follow_inferior_fork (int parent_pid
, int child_pid
, int has_forked
,
457 int followed_parent
= 0;
458 int followed_child
= 0;
460 /* Which process did the user want us to follow? */
462 savestring (follow_fork_mode_string
, strlen (follow_fork_mode_string
));
464 /* Or, did the user not know, and want us to ask? */
465 if (STREQ (follow_fork_mode_string
, "ask"))
467 char requested_mode
[100];
470 error ("\"ask\" mode NYI");
471 follow_mode
= savestring (requested_mode
, strlen (requested_mode
));
474 /* If we're to be following the parent, then detach from child_pid.
475 We're already following the parent, so need do nothing explicit
477 if (STREQ (follow_mode
, "parent"))
481 /* We're already attached to the parent, by default. */
483 /* Before detaching from the child, remove all breakpoints from
484 it. (This won't actually modify the breakpoint list, but will
485 physically remove the breakpoints from the child.) */
486 if (!has_vforked
|| !follow_vfork_when_exec
)
488 detach_breakpoints (child_pid
);
489 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
490 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
494 /* Detach from the child. */
497 target_require_detach (child_pid
, "", 1);
500 /* If we're to be following the child, then attach to it, detach
501 from inferior_pid, and set inferior_pid to child_pid. */
502 else if (STREQ (follow_mode
, "child"))
504 char child_pid_spelling
[100]; /* Arbitrary length. */
508 /* Before detaching from the parent, detach all breakpoints from
509 the child. But only if we're forking, or if we follow vforks
510 as soon as they happen. (If we're following vforks only when
511 the child has exec'd, then it's very wrong to try to write
512 back the "shadow contents" of inserted breakpoints now -- they
513 belong to the child's pre-exec'd a.out.) */
514 if (!has_vforked
|| !follow_vfork_when_exec
)
516 detach_breakpoints (child_pid
);
519 /* Before detaching from the parent, remove all breakpoints from it. */
520 remove_breakpoints ();
522 /* Also reset the solib inferior hook from the parent. */
523 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
524 SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid
);
527 /* Detach from the parent. */
529 target_detach (NULL
, 1);
531 /* Attach to the child. */
532 inferior_pid
= child_pid
;
533 sprintf (child_pid_spelling
, "%d", child_pid
);
536 target_require_attach (child_pid_spelling
, 1);
538 /* Was there a step_resume breakpoint? (There was if the user
539 did a "next" at the fork() call.) If so, explicitly reset its
542 step_resumes are a form of bp that are made to be per-thread.
543 Since we created the step_resume bp when the parent process
544 was being debugged, and now are switching to the child process,
545 from the breakpoint package's viewpoint, that's a switch of
546 "threads". We must update the bp's notion of which thread
547 it is for, or it'll be ignored when it triggers... */
548 if (step_resume_breakpoint
&&
549 (!has_vforked
|| !follow_vfork_when_exec
))
550 breakpoint_re_set_thread (step_resume_breakpoint
);
552 /* Reinsert all breakpoints in the child. (The user may've set
553 breakpoints after catching the fork, in which case those
554 actually didn't get set in the child, but only in the parent.) */
555 if (!has_vforked
|| !follow_vfork_when_exec
)
557 breakpoint_re_set ();
558 insert_breakpoints ();
562 /* If we're to be following both parent and child, then fork ourselves,
563 and attach the debugger clone to the child. */
564 else if (STREQ (follow_mode
, "both"))
566 char pid_suffix
[100]; /* Arbitrary length. */
568 /* Clone ourselves to follow the child. This is the end of our
569 involvement with child_pid; our clone will take it from here... */
571 target_clone_and_follow_inferior (child_pid
, &followed_child
);
572 followed_parent
= !followed_child
;
574 /* We continue to follow the parent. To help distinguish the two
575 debuggers, though, both we and our clone will reset our prompts. */
576 sprintf (pid_suffix
, "[%d] ", inferior_pid
);
577 set_prompt (strcat (get_prompt (), pid_suffix
));
580 /* The parent and child of a vfork share the same address space.
581 Also, on some targets the order in which vfork and exec events
582 are received for parent in child requires some delicate handling
585 For instance, on ptrace-based HPUX we receive the child's vfork
586 event first, at which time the parent has been suspended by the
587 OS and is essentially untouchable until the child's exit or second
588 exec event arrives. At that time, the parent's vfork event is
589 delivered to us, and that's when we see and decide how to follow
590 the vfork. But to get to that point, we must continue the child
591 until it execs or exits. To do that smoothly, all breakpoints
592 must be removed from the child, in case there are any set between
593 the vfork() and exec() calls. But removing them from the child
594 also removes them from the parent, due to the shared-address-space
595 nature of a vfork'd parent and child. On HPUX, therefore, we must
596 take care to restore the bp's to the parent before we continue it.
597 Else, it's likely that we may not stop in the expected place. (The
598 worst scenario is when the user tries to step over a vfork() call;
599 the step-resume bp must be restored for the step to properly stop
600 in the parent after the call completes!)
602 Sequence of events, as reported to gdb from HPUX:
604 Parent Child Action for gdb to take
605 -------------------------------------------------------
606 1 VFORK Continue child
612 target_post_follow_vfork (parent_pid
,
618 pending_follow
.fork_event
.saw_parent_fork
= 0;
619 pending_follow
.fork_event
.saw_child_fork
= 0;
625 follow_fork (int parent_pid
, int child_pid
)
627 follow_inferior_fork (parent_pid
, child_pid
, 1, 0);
631 /* Forward declaration. */
632 static void follow_exec (int, char *);
635 follow_vfork (int parent_pid
, int child_pid
)
637 follow_inferior_fork (parent_pid
, child_pid
, 0, 1);
639 /* Did we follow the child? Had it exec'd before we saw the parent vfork? */
640 if (pending_follow
.fork_event
.saw_child_exec
&& (inferior_pid
== child_pid
))
642 pending_follow
.fork_event
.saw_child_exec
= 0;
643 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
644 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
645 free (pending_follow
.execd_pathname
);
650 follow_exec (int pid
, char *execd_pathname
)
653 struct target_ops
*tgt
;
655 if (!may_follow_exec
)
658 /* Did this exec() follow a vfork()? If so, we must follow the
659 vfork now too. Do it before following the exec. */
660 if (follow_vfork_when_exec
&&
661 (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
))
663 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
664 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
665 follow_vfork_when_exec
= 0;
666 saved_pid
= inferior_pid
;
668 /* Did we follow the parent? If so, we're done. If we followed
669 the child then we must also follow its exec(). */
670 if (inferior_pid
== pending_follow
.fork_event
.parent_pid
)
674 /* This is an exec event that we actually wish to pay attention to.
675 Refresh our symbol table to the newly exec'd program, remove any
678 If there are breakpoints, they aren't really inserted now,
679 since the exec() transformed our inferior into a fresh set
682 We want to preserve symbolic breakpoints on the list, since
683 we have hopes that they can be reset after the new a.out's
684 symbol table is read.
686 However, any "raw" breakpoints must be removed from the list
687 (e.g., the solib bp's), since their address is probably invalid
690 And, we DON'T want to call delete_breakpoints() here, since
691 that may write the bp's "shadow contents" (the instruction
692 value that was overwritten witha TRAP instruction). Since
693 we now have a new a.out, those shadow contents aren't valid. */
694 update_breakpoints_after_exec ();
696 /* If there was one, it's gone now. We cannot truly step-to-next
697 statement through an exec(). */
698 step_resume_breakpoint
= NULL
;
699 step_range_start
= 0;
702 /* If there was one, it's gone now. */
703 through_sigtramp_breakpoint
= NULL
;
705 /* What is this a.out's name? */
706 printf_unfiltered ("Executing new program: %s\n", execd_pathname
);
708 /* We've followed the inferior through an exec. Therefore, the
709 inferior has essentially been killed & reborn. */
711 /* First collect the run target in effect. */
712 tgt
= find_run_target ();
713 /* If we can't find one, things are in a very strange state... */
715 error ("Could find run target to save before following exec");
717 gdb_flush (gdb_stdout
);
718 target_mourn_inferior ();
719 inferior_pid
= saved_pid
; /* Because mourn_inferior resets inferior_pid. */
722 /* That a.out is now the one to use. */
723 exec_file_attach (execd_pathname
, 0);
725 /* And also is where symbols can be found. */
726 symbol_file_command (execd_pathname
, 0);
728 /* Reset the shared library package. This ensures that we get
729 a shlib event when the child reaches "_start", at which point
730 the dld will have had a chance to initialize the child. */
731 #if defined(SOLIB_RESTART)
734 #ifdef SOLIB_CREATE_INFERIOR_HOOK
735 SOLIB_CREATE_INFERIOR_HOOK (inferior_pid
);
738 /* Reinsert all breakpoints. (Those which were symbolic have
739 been reset to the proper address in the new a.out, thanks
740 to symbol_file_command...) */
741 insert_breakpoints ();
743 /* The next resume of this inferior should bring it to the shlib
744 startup breakpoints. (If the user had also set bp's on
745 "main" from the old (parent) process, then they'll auto-
746 matically get reset there in the new process.) */
749 /* Non-zero if we just simulating a single-step. This is needed
750 because we cannot remove the breakpoints in the inferior process
751 until after the `wait' in `wait_for_inferior'. */
752 static int singlestep_breakpoints_inserted_p
= 0;
755 /* Things to clean up if we QUIT out of resume (). */
758 resume_cleanups (int arg
)
763 static char schedlock_off
[] = "off";
764 static char schedlock_on
[] = "on";
765 static char schedlock_step
[] = "step";
766 static char *scheduler_mode
= schedlock_off
;
767 static char *scheduler_enums
[] =
768 {schedlock_off
, schedlock_on
, schedlock_step
};
771 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
773 if (c
->type
== set_cmd
)
774 if (!target_can_lock_scheduler
)
776 scheduler_mode
= schedlock_off
;
777 error ("Target '%s' cannot support this command.",
785 /* Resume the inferior, but allow a QUIT. This is useful if the user
786 wants to interrupt some lengthy single-stepping operation
787 (for child processes, the SIGINT goes to the inferior, and so
788 we get a SIGINT random_signal, but for remote debugging and perhaps
789 other targets, that's not true).
791 STEP nonzero if we should step (zero to continue instead).
792 SIG is the signal to give the inferior (zero for none). */
794 resume (int step
, enum target_signal sig
)
796 int should_resume
= 1;
797 struct cleanup
*old_cleanups
= make_cleanup ((make_cleanup_func
)
801 #ifdef CANNOT_STEP_BREAKPOINT
802 /* Most targets can step a breakpoint instruction, thus executing it
803 normally. But if this one cannot, just continue and we will hit
805 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
809 /* Normally, by the time we reach `resume', the breakpoints are either
810 removed or inserted, as appropriate. The exception is if we're sitting
811 at a permanent breakpoint; we need to step over it, but permanent
812 breakpoints can't be removed. So we have to test for it here. */
813 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
814 SKIP_PERMANENT_BREAKPOINT ();
816 if (SOFTWARE_SINGLE_STEP_P
&& step
)
818 /* Do it the hard way, w/temp breakpoints */
819 SOFTWARE_SINGLE_STEP (sig
, 1 /*insert-breakpoints */ );
820 /* ...and don't ask hardware to do it. */
822 /* and do not pull these breakpoints until after a `wait' in
823 `wait_for_inferior' */
824 singlestep_breakpoints_inserted_p
= 1;
827 /* Handle any optimized stores to the inferior NOW... */
828 #ifdef DO_DEFERRED_STORES
832 /* If there were any forks/vforks/execs that were caught and are
833 now to be followed, then do so. */
834 switch (pending_follow
.kind
)
836 case (TARGET_WAITKIND_FORKED
):
837 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
838 follow_fork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
841 case (TARGET_WAITKIND_VFORKED
):
843 int saw_child_exec
= pending_follow
.fork_event
.saw_child_exec
;
845 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
846 follow_vfork (inferior_pid
, pending_follow
.fork_event
.child_pid
);
848 /* Did we follow the child, but not yet see the child's exec event?
849 If so, then it actually ought to be waiting for us; we respond to
850 parent vfork events. We don't actually want to resume the child
851 in this situation; we want to just get its exec event. */
852 if (!saw_child_exec
&&
853 (inferior_pid
== pending_follow
.fork_event
.child_pid
))
858 case (TARGET_WAITKIND_EXECD
):
859 /* If we saw a vfork event but couldn't follow it until we saw
860 an exec, then now might be the time! */
861 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
862 /* follow_exec is called as soon as the exec event is seen. */
869 /* Install inferior's terminal modes. */
870 target_terminal_inferior ();
874 if (use_thread_step_needed
&& thread_step_needed
)
876 /* We stopped on a BPT instruction;
877 don't continue other threads and
878 just step this thread. */
879 thread_step_needed
= 0;
881 if (!breakpoint_here_p (read_pc ()))
883 /* Breakpoint deleted: ok to do regular resume
884 where all the threads either step or continue. */
885 target_resume (-1, step
, sig
);
891 warning ("Internal error, changing continue to step.");
892 remove_breakpoints ();
893 breakpoints_inserted
= 0;
898 target_resume (inferior_pid
, step
, sig
);
903 /* Vanilla resume. */
905 if ((scheduler_mode
== schedlock_on
) ||
906 (scheduler_mode
== schedlock_step
&& step
!= 0))
907 target_resume (inferior_pid
, step
, sig
);
909 target_resume (-1, step
, sig
);
913 discard_cleanups (old_cleanups
);
917 /* Clear out all variables saying what to do when inferior is continued.
918 First do this, then set the ones you want, then call `proceed'. */
921 clear_proceed_status (void)
924 step_range_start
= 0;
926 step_frame_address
= 0;
927 step_over_calls
= -1;
929 stop_soon_quietly
= 0;
930 proceed_to_finish
= 0;
931 breakpoint_proceeded
= 1; /* We're about to proceed... */
933 /* Discard any remaining commands or status from previous stop. */
934 bpstat_clear (&stop_bpstat
);
937 /* Basic routine for continuing the program in various fashions.
939 ADDR is the address to resume at, or -1 for resume where stopped.
940 SIGGNAL is the signal to give it, or 0 for none,
941 or -1 for act according to how it stopped.
942 STEP is nonzero if should trap after one instruction.
943 -1 means return after that and print nothing.
944 You should probably set various step_... variables
945 before calling here, if you are stepping.
947 You should call clear_proceed_status before calling proceed. */
950 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
955 step_start_function
= find_pc_function (read_pc ());
959 if (addr
== (CORE_ADDR
) -1)
961 /* If there is a breakpoint at the address we will resume at,
962 step one instruction before inserting breakpoints
963 so that we do not stop right away (and report a second
964 hit at this breakpoint). */
966 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
969 #ifndef STEP_SKIPS_DELAY
970 #define STEP_SKIPS_DELAY(pc) (0)
971 #define STEP_SKIPS_DELAY_P (0)
973 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
974 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
975 is slow (it needs to read memory from the target). */
976 if (STEP_SKIPS_DELAY_P
977 && breakpoint_here_p (read_pc () + 4)
978 && STEP_SKIPS_DELAY (read_pc ()))
985 /* New address; we don't need to single-step a thread
986 over a breakpoint we just hit, 'cause we aren't
987 continuing from there.
989 It's not worth worrying about the case where a user
990 asks for a "jump" at the current PC--if they get the
991 hiccup of re-hiting a hit breakpoint, what else do
993 thread_step_needed
= 0;
996 #ifdef PREPARE_TO_PROCEED
997 /* In a multi-threaded task we may select another thread
998 and then continue or step.
1000 But if the old thread was stopped at a breakpoint, it
1001 will immediately cause another breakpoint stop without
1002 any execution (i.e. it will report a breakpoint hit
1003 incorrectly). So we must step over it first.
1005 PREPARE_TO_PROCEED checks the current thread against the thread
1006 that reported the most recent event. If a step-over is required
1007 it returns TRUE and sets the current thread to the old thread. */
1008 if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
1011 thread_step_needed
= 1;
1014 #endif /* PREPARE_TO_PROCEED */
1017 if (trap_expected_after_continue
)
1019 /* If (step == 0), a trap will be automatically generated after
1020 the first instruction is executed. Force step one
1021 instruction to clear this condition. This should not occur
1022 if step is nonzero, but it is harmless in that case. */
1024 trap_expected_after_continue
= 0;
1026 #endif /* HP_OS_BUG */
1029 /* We will get a trace trap after one instruction.
1030 Continue it automatically and insert breakpoints then. */
1034 int temp
= insert_breakpoints ();
1037 print_sys_errmsg ("ptrace", temp
);
1038 error ("Cannot insert breakpoints.\n\
1039 The same program may be running in another process.");
1042 breakpoints_inserted
= 1;
1045 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1046 stop_signal
= siggnal
;
1047 /* If this signal should not be seen by program,
1048 give it zero. Used for debugging signals. */
1049 else if (!signal_program
[stop_signal
])
1050 stop_signal
= TARGET_SIGNAL_0
;
1052 annotate_starting ();
1054 /* Make sure that output from GDB appears before output from the
1056 gdb_flush (gdb_stdout
);
1058 /* Resume inferior. */
1059 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1061 /* Wait for it to stop (if not standalone)
1062 and in any case decode why it stopped, and act accordingly. */
1063 /* Do this only if we are not using the event loop, or if the target
1064 does not support asynchronous execution. */
1065 if (!event_loop_p
|| !target_can_async_p ())
1067 wait_for_inferior ();
1072 /* Record the pc and sp of the program the last time it stopped.
1073 These are just used internally by wait_for_inferior, but need
1074 to be preserved over calls to it and cleared when the inferior
1076 static CORE_ADDR prev_pc
;
1077 static CORE_ADDR prev_func_start
;
1078 static char *prev_func_name
;
1081 /* Start remote-debugging of a machine over a serial link. */
1086 init_thread_list ();
1087 init_wait_for_inferior ();
1088 stop_soon_quietly
= 1;
1091 /* Always go on waiting for the target, regardless of the mode. */
1092 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1093 indicate th wait_for_inferior that a target should timeout if
1094 nothing is returned (instead of just blocking). Because of this,
1095 targets expecting an immediate response need to, internally, set
1096 things up so that the target_wait() is forced to eventually
1098 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1099 differentiate to its caller what the state of the target is after
1100 the initial open has been performed. Here we're assuming that
1101 the target has stopped. It should be possible to eventually have
1102 target_open() return to the caller an indication that the target
1103 is currently running and GDB state should be set to the same as
1104 for an async run. */
1105 wait_for_inferior ();
1109 /* Initialize static vars when a new inferior begins. */
1112 init_wait_for_inferior (void)
1114 /* These are meaningless until the first time through wait_for_inferior. */
1116 prev_func_start
= 0;
1117 prev_func_name
= NULL
;
1120 trap_expected_after_continue
= 0;
1122 breakpoints_inserted
= 0;
1123 breakpoint_init_inferior (inf_starting
);
1125 /* Don't confuse first call to proceed(). */
1126 stop_signal
= TARGET_SIGNAL_0
;
1128 /* The first resume is not following a fork/vfork/exec. */
1129 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1130 pending_follow
.fork_event
.saw_parent_fork
= 0;
1131 pending_follow
.fork_event
.saw_child_fork
= 0;
1132 pending_follow
.fork_event
.saw_child_exec
= 0;
1134 /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */
1135 number_of_threads_in_syscalls
= 0;
1137 clear_proceed_status ();
1141 delete_breakpoint_current_contents (void *arg
)
1143 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
1144 if (*breakpointp
!= NULL
)
1146 delete_breakpoint (*breakpointp
);
1147 *breakpointp
= NULL
;
1151 /* This enum encodes possible reasons for doing a target_wait, so that
1152 wfi can call target_wait in one place. (Ultimately the call will be
1153 moved out of the infinite loop entirely.) */
1157 infwait_normal_state
,
1158 infwait_thread_hop_state
,
1159 infwait_nullified_state
,
1160 infwait_nonstep_watch_state
1163 /* Why did the inferior stop? Used to print the appropriate messages
1164 to the interface from within handle_inferior_event(). */
1165 enum inferior_stop_reason
1167 /* We don't know why. */
1169 /* Step, next, nexti, stepi finished. */
1171 /* Found breakpoint. */
1173 /* Inferior terminated by signal. */
1175 /* Inferior exited. */
1177 /* Inferior received signal, and user asked to be notified. */
1181 /* This structure contains what used to be local variables in
1182 wait_for_inferior. Probably many of them can return to being
1183 locals in handle_inferior_event. */
1185 struct execution_control_state
1187 struct target_waitstatus ws
;
1188 struct target_waitstatus
*wp
;
1191 CORE_ADDR stop_func_start
;
1192 CORE_ADDR stop_func_end
;
1193 char *stop_func_name
;
1194 struct symtab_and_line sal
;
1195 int remove_breakpoints_on_following_step
;
1197 struct symtab
*current_symtab
;
1198 int handling_longjmp
; /* FIXME */
1200 int saved_inferior_pid
;
1202 int stepping_through_solib_after_catch
;
1203 bpstat stepping_through_solib_catchpoints
;
1204 int enable_hw_watchpoints_after_wait
;
1205 int stepping_through_sigtramp
;
1206 int new_thread_event
;
1207 struct target_waitstatus tmpstatus
;
1208 enum infwait_states infwait_state
;
1213 void init_execution_control_state (struct execution_control_state
* ecs
);
1215 void handle_inferior_event (struct execution_control_state
* ecs
);
1217 static void check_sigtramp2 (struct execution_control_state
*ecs
);
1218 static void step_into_function (struct execution_control_state
*ecs
);
1219 static void step_over_function (struct execution_control_state
*ecs
);
1220 static void stop_stepping (struct execution_control_state
*ecs
);
1221 static void prepare_to_wait (struct execution_control_state
*ecs
);
1222 static void keep_going (struct execution_control_state
*ecs
);
1223 static void print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
);
1225 /* Wait for control to return from inferior to debugger.
1226 If inferior gets a signal, we may decide to start it up again
1227 instead of returning. That is why there is a loop in this function.
1228 When this function actually returns it means the inferior
1229 should be left stopped and GDB should read more commands. */
1232 wait_for_inferior (void)
1234 struct cleanup
*old_cleanups
;
1235 struct execution_control_state ecss
;
1236 struct execution_control_state
*ecs
;
1238 old_cleanups
= make_cleanup (delete_breakpoint_current_contents
,
1239 &step_resume_breakpoint
);
1240 make_cleanup (delete_breakpoint_current_contents
,
1241 &through_sigtramp_breakpoint
);
1243 /* wfi still stays in a loop, so it's OK just to take the address of
1244 a local to get the ecs pointer. */
1247 /* Fill in with reasonable starting values. */
1248 init_execution_control_state (ecs
);
1250 thread_step_needed
= 0;
1252 /* We'll update this if & when we switch to a new thread. */
1253 if (may_switch_from_inferior_pid
)
1254 switched_from_inferior_pid
= inferior_pid
;
1256 overlay_cache_invalid
= 1;
1258 /* We have to invalidate the registers BEFORE calling target_wait
1259 because they can be loaded from the target while in target_wait.
1260 This makes remote debugging a bit more efficient for those
1261 targets that provide critical registers as part of their normal
1262 status mechanism. */
1264 registers_changed ();
1268 if (target_wait_hook
)
1269 ecs
->pid
= target_wait_hook (ecs
->waiton_pid
, ecs
->wp
);
1271 ecs
->pid
= target_wait (ecs
->waiton_pid
, ecs
->wp
);
1273 /* Now figure out what to do with the result of the result. */
1274 handle_inferior_event (ecs
);
1276 if (!ecs
->wait_some_more
)
1279 do_cleanups (old_cleanups
);
1282 /* Asynchronous version of wait_for_inferior. It is called by the
1283 event loop whenever a change of state is detected on the file
1284 descriptor corresponding to the target. It can be called more than
1285 once to complete a single execution command. In such cases we need
1286 to keep the state in a global variable ASYNC_ECSS. If it is the
1287 last time that this function is called for a single execution
1288 command, then report to the user that the inferior has stopped, and
1289 do the necessary cleanups. */
1291 struct execution_control_state async_ecss
;
1292 struct execution_control_state
*async_ecs
;
1295 fetch_inferior_event (client_data
)
1298 static struct cleanup
*old_cleanups
;
1300 async_ecs
= &async_ecss
;
1302 if (!async_ecs
->wait_some_more
)
1304 old_cleanups
= make_exec_cleanup (delete_breakpoint_current_contents
,
1305 &step_resume_breakpoint
);
1306 make_exec_cleanup (delete_breakpoint_current_contents
,
1307 &through_sigtramp_breakpoint
);
1309 /* Fill in with reasonable starting values. */
1310 init_execution_control_state (async_ecs
);
1312 thread_step_needed
= 0;
1314 /* We'll update this if & when we switch to a new thread. */
1315 if (may_switch_from_inferior_pid
)
1316 switched_from_inferior_pid
= inferior_pid
;
1318 overlay_cache_invalid
= 1;
1320 /* We have to invalidate the registers BEFORE calling target_wait
1321 because they can be loaded from the target while in target_wait.
1322 This makes remote debugging a bit more efficient for those
1323 targets that provide critical registers as part of their normal
1324 status mechanism. */
1326 registers_changed ();
1329 if (target_wait_hook
)
1330 async_ecs
->pid
= target_wait_hook (async_ecs
->waiton_pid
, async_ecs
->wp
);
1332 async_ecs
->pid
= target_wait (async_ecs
->waiton_pid
, async_ecs
->wp
);
1334 /* Now figure out what to do with the result of the result. */
1335 handle_inferior_event (async_ecs
);
1337 if (!async_ecs
->wait_some_more
)
1339 /* Do only the cleanups that have been added by this
1340 function. Let the continuations for the commands do the rest,
1341 if there are any. */
1342 do_exec_cleanups (old_cleanups
);
1344 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1348 /* Prepare an execution control state for looping through a
1349 wait_for_inferior-type loop. */
1352 init_execution_control_state (struct execution_control_state
*ecs
)
1354 ecs
->random_signal
= 0;
1355 ecs
->remove_breakpoints_on_following_step
= 0;
1356 ecs
->handling_longjmp
= 0; /* FIXME */
1357 ecs
->update_step_sp
= 0;
1358 ecs
->stepping_through_solib_after_catch
= 0;
1359 ecs
->stepping_through_solib_catchpoints
= NULL
;
1360 ecs
->enable_hw_watchpoints_after_wait
= 0;
1361 ecs
->stepping_through_sigtramp
= 0;
1362 ecs
->sal
= find_pc_line (prev_pc
, 0);
1363 ecs
->current_line
= ecs
->sal
.line
;
1364 ecs
->current_symtab
= ecs
->sal
.symtab
;
1365 ecs
->infwait_state
= infwait_normal_state
;
1366 ecs
->waiton_pid
= -1;
1367 ecs
->wp
= &(ecs
->ws
);
1370 /* Call this function before setting step_resume_breakpoint, as a
1371 sanity check. There should never be more than one step-resume
1372 breakpoint per thread, so we should never be setting a new
1373 step_resume_breakpoint when one is already active. */
1375 check_for_old_step_resume_breakpoint (void)
1377 if (step_resume_breakpoint
)
1378 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1381 /* Given an execution control state that has been freshly filled in
1382 by an event from the inferior, figure out what it means and take
1383 appropriate action. */
1386 handle_inferior_event (struct execution_control_state
*ecs
)
1389 int stepped_after_stopped_by_watchpoint
;
1391 /* Keep this extra brace for now, minimizes diffs. */
1393 switch (ecs
->infwait_state
)
1395 case infwait_normal_state
:
1396 /* Since we've done a wait, we have a new event. Don't
1397 carry over any expectations about needing to step over a
1399 thread_step_needed
= 0;
1401 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1402 is serviced in this loop, below. */
1403 if (ecs
->enable_hw_watchpoints_after_wait
)
1405 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid
);
1406 ecs
->enable_hw_watchpoints_after_wait
= 0;
1408 stepped_after_stopped_by_watchpoint
= 0;
1411 case infwait_thread_hop_state
:
1412 insert_breakpoints ();
1414 /* We need to restart all the threads now,
1415 * unles we're running in scheduler-locked mode.
1416 * FIXME: shouldn't we look at currently_stepping ()?
1418 if (scheduler_mode
== schedlock_on
)
1419 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1421 target_resume (-1, 0, TARGET_SIGNAL_0
);
1422 ecs
->infwait_state
= infwait_normal_state
;
1423 prepare_to_wait (ecs
);
1426 case infwait_nullified_state
:
1429 case infwait_nonstep_watch_state
:
1430 insert_breakpoints ();
1432 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1433 handle things like signals arriving and other things happening
1434 in combination correctly? */
1435 stepped_after_stopped_by_watchpoint
= 1;
1438 ecs
->infwait_state
= infwait_normal_state
;
1440 flush_cached_frames ();
1442 /* If it's a new process, add it to the thread database */
1444 ecs
->new_thread_event
= ((ecs
->pid
!= inferior_pid
) && !in_thread_list (ecs
->pid
));
1446 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1447 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1448 && ecs
->new_thread_event
)
1450 add_thread (ecs
->pid
);
1452 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs
->pid
));
1455 /* NOTE: This block is ONLY meant to be invoked in case of a
1456 "thread creation event"! If it is invoked for any other
1457 sort of event (such as a new thread landing on a breakpoint),
1458 the event will be discarded, which is almost certainly
1461 To avoid this, the low-level module (eg. target_wait)
1462 should call in_thread_list and add_thread, so that the
1463 new thread is known by the time we get here. */
1465 /* We may want to consider not doing a resume here in order
1466 to give the user a chance to play with the new thread.
1467 It might be good to make that a user-settable option. */
1469 /* At this point, all threads are stopped (happens
1470 automatically in either the OS or the native code).
1471 Therefore we need to continue all threads in order to
1474 target_resume (-1, 0, TARGET_SIGNAL_0
);
1475 prepare_to_wait (ecs
);
1480 switch (ecs
->ws
.kind
)
1482 case TARGET_WAITKIND_LOADED
:
1483 /* Ignore gracefully during startup of the inferior, as it
1484 might be the shell which has just loaded some objects,
1485 otherwise add the symbols for the newly loaded objects. */
1487 if (!stop_soon_quietly
)
1489 /* Remove breakpoints, SOLIB_ADD might adjust
1490 breakpoint addresses via breakpoint_re_set. */
1491 if (breakpoints_inserted
)
1492 remove_breakpoints ();
1494 /* Check for any newly added shared libraries if we're
1495 supposed to be adding them automatically. */
1498 /* Switch terminal for any messages produced by
1499 breakpoint_re_set. */
1500 target_terminal_ours_for_output ();
1501 SOLIB_ADD (NULL
, 0, NULL
);
1502 target_terminal_inferior ();
1505 /* Reinsert breakpoints and continue. */
1506 if (breakpoints_inserted
)
1507 insert_breakpoints ();
1510 resume (0, TARGET_SIGNAL_0
);
1511 prepare_to_wait (ecs
);
1514 case TARGET_WAITKIND_SPURIOUS
:
1515 resume (0, TARGET_SIGNAL_0
);
1516 prepare_to_wait (ecs
);
1519 case TARGET_WAITKIND_EXITED
:
1520 target_terminal_ours (); /* Must do this before mourn anyway */
1521 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1523 /* Record the exit code in the convenience variable $_exitcode, so
1524 that the user can inspect this again later. */
1525 set_internalvar (lookup_internalvar ("_exitcode"),
1526 value_from_longest (builtin_type_int
,
1527 (LONGEST
) ecs
->ws
.value
.integer
));
1528 gdb_flush (gdb_stdout
);
1529 target_mourn_inferior ();
1530 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P */
1531 stop_print_frame
= 0;
1532 stop_stepping (ecs
);
1535 case TARGET_WAITKIND_SIGNALLED
:
1536 stop_print_frame
= 0;
1537 stop_signal
= ecs
->ws
.value
.sig
;
1538 target_terminal_ours (); /* Must do this before mourn anyway */
1540 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1541 mean it is already dead? This has been here since GDB 2.8, so
1542 perhaps it means rms didn't understand unix waitstatuses?
1543 For the moment I'm just kludging around this in remote.c
1544 rather than trying to change it here --kingdon, 5 Dec 1994. */
1545 target_kill (); /* kill mourns as well */
1547 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1548 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P */
1549 stop_stepping (ecs
);
1552 /* The following are the only cases in which we keep going;
1553 the above cases end in a continue or goto. */
1554 case TARGET_WAITKIND_FORKED
:
1555 stop_signal
= TARGET_SIGNAL_TRAP
;
1556 pending_follow
.kind
= ecs
->ws
.kind
;
1558 /* Ignore fork events reported for the parent; we're only
1559 interested in reacting to forks of the child. Note that
1560 we expect the child's fork event to be available if we
1561 waited for it now. */
1562 if (inferior_pid
== ecs
->pid
)
1564 pending_follow
.fork_event
.saw_parent_fork
= 1;
1565 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1566 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1567 prepare_to_wait (ecs
);
1572 pending_follow
.fork_event
.saw_child_fork
= 1;
1573 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1574 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1577 stop_pc
= read_pc_pid (ecs
->pid
);
1578 ecs
->saved_inferior_pid
= inferior_pid
;
1579 inferior_pid
= ecs
->pid
;
1580 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1581 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1582 inferior_pid
= ecs
->saved_inferior_pid
;
1583 goto process_event_stop_test
;
1585 /* If this a platform which doesn't allow a debugger to touch a
1586 vfork'd inferior until after it exec's, then we'd best keep
1587 our fingers entirely off the inferior, other than continuing
1588 it. This has the unfortunate side-effect that catchpoints
1589 of vforks will be ignored. But since the platform doesn't
1590 allow the inferior be touched at vfork time, there's really
1592 case TARGET_WAITKIND_VFORKED
:
1593 stop_signal
= TARGET_SIGNAL_TRAP
;
1594 pending_follow
.kind
= ecs
->ws
.kind
;
1596 /* Is this a vfork of the parent? If so, then give any
1597 vfork catchpoints a chance to trigger now. (It's
1598 dangerous to do so if the child canot be touched until
1599 it execs, and the child has not yet exec'd. We probably
1600 should warn the user to that effect when the catchpoint
1602 if (ecs
->pid
== inferior_pid
)
1604 pending_follow
.fork_event
.saw_parent_fork
= 1;
1605 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1606 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1609 /* If we've seen the child's vfork event but cannot really touch
1610 the child until it execs, then we must continue the child now.
1611 Else, give any vfork catchpoints a chance to trigger now. */
1614 pending_follow
.fork_event
.saw_child_fork
= 1;
1615 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1616 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1617 target_post_startup_inferior (pending_follow
.fork_event
.child_pid
);
1618 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1619 if (follow_vfork_when_exec
)
1621 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1622 prepare_to_wait (ecs
);
1627 stop_pc
= read_pc ();
1628 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1629 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1630 goto process_event_stop_test
;
1632 case TARGET_WAITKIND_EXECD
:
1633 stop_signal
= TARGET_SIGNAL_TRAP
;
1635 /* Is this a target which reports multiple exec events per actual
1636 call to exec()? (HP-UX using ptrace does, for example.) If so,
1637 ignore all but the last one. Just resume the exec'r, and wait
1638 for the next exec event. */
1639 if (inferior_ignoring_leading_exec_events
)
1641 inferior_ignoring_leading_exec_events
--;
1642 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1643 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.parent_pid
);
1644 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1645 prepare_to_wait (ecs
);
1648 inferior_ignoring_leading_exec_events
=
1649 target_reported_exec_events_per_exec_call () - 1;
1651 pending_follow
.execd_pathname
=
1652 savestring (ecs
->ws
.value
.execd_pathname
,
1653 strlen (ecs
->ws
.value
.execd_pathname
));
1655 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1656 child of a vfork exec?
1658 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1659 HP-UX, events associated with a vforking inferior come in
1660 threes: a vfork event for the child (always first), followed
1661 a vfork event for the parent and an exec event for the child.
1662 The latter two can come in either order.
1664 If we get the parent vfork event first, life's good: We follow
1665 either the parent or child, and then the child's exec event is
1668 But if we get the child's exec event first, then we delay
1669 responding to it until we handle the parent's vfork. Because,
1670 otherwise we can't satisfy a "catch vfork". */
1671 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1673 pending_follow
.fork_event
.saw_child_exec
= 1;
1675 /* On some targets, the child must be resumed before
1676 the parent vfork event is delivered. A single-step
1678 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1679 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1680 /* We expect the parent vfork event to be available now. */
1681 prepare_to_wait (ecs
);
1685 /* This causes the eventpoints and symbol table to be reset. Must
1686 do this now, before trying to determine whether to stop. */
1687 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
1688 free (pending_follow
.execd_pathname
);
1690 stop_pc
= read_pc_pid (ecs
->pid
);
1691 ecs
->saved_inferior_pid
= inferior_pid
;
1692 inferior_pid
= ecs
->pid
;
1693 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1694 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1695 inferior_pid
= ecs
->saved_inferior_pid
;
1696 goto process_event_stop_test
;
1698 /* These syscall events are returned on HP-UX, as part of its
1699 implementation of page-protection-based "hardware" watchpoints.
1700 HP-UX has unfortunate interactions between page-protections and
1701 some system calls. Our solution is to disable hardware watches
1702 when a system call is entered, and reenable them when the syscall
1703 completes. The downside of this is that we may miss the precise
1704 point at which a watched piece of memory is modified. "Oh well."
1706 Note that we may have multiple threads running, which may each
1707 enter syscalls at roughly the same time. Since we don't have a
1708 good notion currently of whether a watched piece of memory is
1709 thread-private, we'd best not have any page-protections active
1710 when any thread is in a syscall. Thus, we only want to reenable
1711 hardware watches when no threads are in a syscall.
1713 Also, be careful not to try to gather much state about a thread
1714 that's in a syscall. It's frequently a losing proposition. */
1715 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1716 number_of_threads_in_syscalls
++;
1717 if (number_of_threads_in_syscalls
== 1)
1719 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid
);
1721 resume (0, TARGET_SIGNAL_0
);
1722 prepare_to_wait (ecs
);
1725 /* Before examining the threads further, step this thread to
1726 get it entirely out of the syscall. (We get notice of the
1727 event when the thread is just on the verge of exiting a
1728 syscall. Stepping one instruction seems to get it back
1731 Note that although the logical place to reenable h/w watches
1732 is here, we cannot. We cannot reenable them before stepping
1733 the thread (this causes the next wait on the thread to hang).
1735 Nor can we enable them after stepping until we've done a wait.
1736 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1737 here, which will be serviced immediately after the target
1739 case TARGET_WAITKIND_SYSCALL_RETURN
:
1740 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1742 if (number_of_threads_in_syscalls
> 0)
1744 number_of_threads_in_syscalls
--;
1745 ecs
->enable_hw_watchpoints_after_wait
=
1746 (number_of_threads_in_syscalls
== 0);
1748 prepare_to_wait (ecs
);
1751 case TARGET_WAITKIND_STOPPED
:
1752 stop_signal
= ecs
->ws
.value
.sig
;
1756 /* We may want to consider not doing a resume here in order to give
1757 the user a chance to play with the new thread. It might be good
1758 to make that a user-settable option. */
1760 /* At this point, all threads are stopped (happens automatically in
1761 either the OS or the native code). Therefore we need to continue
1762 all threads in order to make progress. */
1763 if (ecs
->new_thread_event
)
1765 target_resume (-1, 0, TARGET_SIGNAL_0
);
1766 prepare_to_wait (ecs
);
1770 stop_pc
= read_pc_pid (ecs
->pid
);
1772 /* See if a thread hit a thread-specific breakpoint that was meant for
1773 another thread. If so, then step that thread past the breakpoint,
1776 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1778 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1779 ecs
->random_signal
= 0;
1780 else if (breakpoints_inserted
1781 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1783 ecs
->random_signal
= 0;
1784 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1789 /* Saw a breakpoint, but it was hit by the wrong thread.
1791 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->pid
);
1793 remove_status
= remove_breakpoints ();
1794 /* Did we fail to remove breakpoints? If so, try
1795 to set the PC past the bp. (There's at least
1796 one situation in which we can fail to remove
1797 the bp's: On HP-UX's that use ttrace, we can't
1798 change the address space of a vforking child
1799 process until the child exits (well, okay, not
1800 then either :-) or execs. */
1801 if (remove_status
!= 0)
1803 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->pid
);
1807 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1808 /* FIXME: What if a signal arrives instead of the
1809 single-step happening? */
1811 ecs
->waiton_pid
= ecs
->pid
;
1812 ecs
->wp
= &(ecs
->ws
);
1813 ecs
->infwait_state
= infwait_thread_hop_state
;
1814 prepare_to_wait (ecs
);
1818 /* We need to restart all the threads now,
1819 * unles we're running in scheduler-locked mode.
1820 * FIXME: shouldn't we look at currently_stepping ()?
1822 if (scheduler_mode
== schedlock_on
)
1823 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1825 target_resume (-1, 0, TARGET_SIGNAL_0
);
1826 prepare_to_wait (ecs
);
1831 /* This breakpoint matches--either it is the right
1832 thread or it's a generic breakpoint for all threads.
1833 Remember that we'll need to step just _this_ thread
1834 on any following user continuation! */
1835 thread_step_needed
= 1;
1840 ecs
->random_signal
= 1;
1842 /* See if something interesting happened to the non-current thread. If
1843 so, then switch to that thread, and eventually give control back to
1846 Note that if there's any kind of pending follow (i.e., of a fork,
1847 vfork or exec), we don't want to do this now. Rather, we'll let
1848 the next resume handle it. */
1849 if ((ecs
->pid
!= inferior_pid
) &&
1850 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1854 /* If it's a random signal for a non-current thread, notify user
1855 if he's expressed an interest. */
1856 if (ecs
->random_signal
1857 && signal_print
[stop_signal
])
1859 /* ??rehrauer: I don't understand the rationale for this code. If the
1860 inferior will stop as a result of this signal, then the act of handling
1861 the stop ought to print a message that's couches the stoppage in user
1862 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1863 won't stop as a result of the signal -- i.e., if the signal is merely
1864 a side-effect of something GDB's doing "under the covers" for the
1865 user, such as stepping threads over a breakpoint they shouldn't stop
1866 for -- then the message seems to be a serious annoyance at best.
1868 For now, remove the message altogether. */
1871 target_terminal_ours_for_output ();
1872 printf_filtered ("\nProgram received signal %s, %s.\n",
1873 target_signal_to_name (stop_signal
),
1874 target_signal_to_string (stop_signal
));
1875 gdb_flush (gdb_stdout
);
1879 /* If it's not SIGTRAP and not a signal we want to stop for, then
1880 continue the thread. */
1882 if (stop_signal
!= TARGET_SIGNAL_TRAP
1883 && !signal_stop
[stop_signal
])
1886 target_terminal_inferior ();
1888 /* Clear the signal if it should not be passed. */
1889 if (signal_program
[stop_signal
] == 0)
1890 stop_signal
= TARGET_SIGNAL_0
;
1892 target_resume (ecs
->pid
, 0, stop_signal
);
1893 prepare_to_wait (ecs
);
1897 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1898 and fall into the rest of wait_for_inferior(). */
1900 /* Save infrun state for the old thread. */
1901 save_infrun_state (inferior_pid
, prev_pc
,
1902 prev_func_start
, prev_func_name
,
1903 trap_expected
, step_resume_breakpoint
,
1904 through_sigtramp_breakpoint
,
1905 step_range_start
, step_range_end
,
1906 step_frame_address
, ecs
->handling_longjmp
,
1908 ecs
->stepping_through_solib_after_catch
,
1909 ecs
->stepping_through_solib_catchpoints
,
1910 ecs
->stepping_through_sigtramp
);
1912 if (may_switch_from_inferior_pid
)
1913 switched_from_inferior_pid
= inferior_pid
;
1915 inferior_pid
= ecs
->pid
;
1917 /* Load infrun state for the new thread. */
1918 load_infrun_state (inferior_pid
, &prev_pc
,
1919 &prev_func_start
, &prev_func_name
,
1920 &trap_expected
, &step_resume_breakpoint
,
1921 &through_sigtramp_breakpoint
,
1922 &step_range_start
, &step_range_end
,
1923 &step_frame_address
, &ecs
->handling_longjmp
,
1925 &ecs
->stepping_through_solib_after_catch
,
1926 &ecs
->stepping_through_solib_catchpoints
,
1927 &ecs
->stepping_through_sigtramp
);
1930 context_hook (pid_to_thread_id (ecs
->pid
));
1932 printf_filtered ("[Switching to %s]\n", target_pid_to_str (ecs
->pid
));
1933 flush_cached_frames ();
1936 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1938 /* Pull the single step breakpoints out of the target. */
1939 SOFTWARE_SINGLE_STEP (0, 0);
1940 singlestep_breakpoints_inserted_p
= 0;
1943 /* If PC is pointing at a nullified instruction, then step beyond
1944 it so that the user won't be confused when GDB appears to be ready
1947 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1948 if (INSTRUCTION_NULLIFIED
)
1950 registers_changed ();
1951 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1953 /* We may have received a signal that we want to pass to
1954 the inferior; therefore, we must not clobber the waitstatus
1957 ecs
->infwait_state
= infwait_nullified_state
;
1958 ecs
->waiton_pid
= ecs
->pid
;
1959 ecs
->wp
= &(ecs
->tmpstatus
);
1960 prepare_to_wait (ecs
);
1964 /* It may not be necessary to disable the watchpoint to stop over
1965 it. For example, the PA can (with some kernel cooperation)
1966 single step over a watchpoint without disabling the watchpoint. */
1967 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1970 prepare_to_wait (ecs
);
1974 /* It is far more common to need to disable a watchpoint to step
1975 the inferior over it. FIXME. What else might a debug
1976 register or page protection watchpoint scheme need here? */
1977 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1979 /* At this point, we are stopped at an instruction which has
1980 attempted to write to a piece of memory under control of
1981 a watchpoint. The instruction hasn't actually executed
1982 yet. If we were to evaluate the watchpoint expression
1983 now, we would get the old value, and therefore no change
1984 would seem to have occurred.
1986 In order to make watchpoints work `right', we really need
1987 to complete the memory write, and then evaluate the
1988 watchpoint expression. The following code does that by
1989 removing the watchpoint (actually, all watchpoints and
1990 breakpoints), single-stepping the target, re-inserting
1991 watchpoints, and then falling through to let normal
1992 single-step processing handle proceed. Since this
1993 includes evaluating watchpoints, things will come to a
1994 stop in the correct manner. */
1996 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
1998 remove_breakpoints ();
1999 registers_changed ();
2000 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
); /* Single step */
2002 ecs
->waiton_pid
= ecs
->pid
;
2003 ecs
->wp
= &(ecs
->ws
);
2004 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2005 prepare_to_wait (ecs
);
2009 /* It may be possible to simply continue after a watchpoint. */
2010 if (HAVE_CONTINUABLE_WATCHPOINT
)
2011 STOPPED_BY_WATCHPOINT (ecs
->ws
);
2013 ecs
->stop_func_start
= 0;
2014 ecs
->stop_func_end
= 0;
2015 ecs
->stop_func_name
= 0;
2016 /* Don't care about return value; stop_func_start and stop_func_name
2017 will both be 0 if it doesn't work. */
2018 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2019 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2020 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
2021 ecs
->another_trap
= 0;
2022 bpstat_clear (&stop_bpstat
);
2024 stop_stack_dummy
= 0;
2025 stop_print_frame
= 1;
2026 ecs
->random_signal
= 0;
2027 stopped_by_random_signal
= 0;
2028 breakpoints_failed
= 0;
2030 /* Look at the cause of the stop, and decide what to do.
2031 The alternatives are:
2032 1) break; to really stop and return to the debugger,
2033 2) drop through to start up again
2034 (set ecs->another_trap to 1 to single step once)
2035 3) set ecs->random_signal to 1, and the decision between 1 and 2
2036 will be made according to the signal handling tables. */
2038 /* First, distinguish signals caused by the debugger from signals
2039 that have to do with the program's own actions.
2040 Note that breakpoint insns may cause SIGTRAP or SIGILL
2041 or SIGEMT, depending on the operating system version.
2042 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2043 and change it to SIGTRAP. */
2045 if (stop_signal
== TARGET_SIGNAL_TRAP
2046 || (breakpoints_inserted
&&
2047 (stop_signal
== TARGET_SIGNAL_ILL
2048 || stop_signal
== TARGET_SIGNAL_EMT
2050 || stop_soon_quietly
)
2052 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2054 stop_print_frame
= 0;
2055 stop_stepping (ecs
);
2058 if (stop_soon_quietly
)
2060 stop_stepping (ecs
);
2064 /* Don't even think about breakpoints
2065 if just proceeded over a breakpoint.
2067 However, if we are trying to proceed over a breakpoint
2068 and end up in sigtramp, then through_sigtramp_breakpoint
2069 will be set and we should check whether we've hit the
2071 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2072 && through_sigtramp_breakpoint
== NULL
)
2073 bpstat_clear (&stop_bpstat
);
2076 /* See if there is a breakpoint at the current PC. */
2077 stop_bpstat
= bpstat_stop_status
2079 /* Pass TRUE if our reason for stopping is something other
2080 than hitting a breakpoint. We do this by checking that
2081 1) stepping is going on and 2) we didn't hit a breakpoint
2082 in a signal handler without an intervening stop in
2083 sigtramp, which is detected by a new stack pointer value
2084 below any usual function calling stack adjustments. */
2085 (currently_stepping (ecs
)
2087 && INNER_THAN (read_sp (), (step_sp
- 16))))
2089 /* Following in case break condition called a
2091 stop_print_frame
= 1;
2094 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2096 = !(bpstat_explains_signal (stop_bpstat
)
2098 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2099 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2100 FRAME_FP (get_current_frame ())))
2101 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2106 = !(bpstat_explains_signal (stop_bpstat
)
2107 /* End of a stack dummy. Some systems (e.g. Sony
2108 news) give another signal besides SIGTRAP, so
2109 check here as well as above. */
2110 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2111 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2112 FRAME_FP (get_current_frame ())))
2114 if (!ecs
->random_signal
)
2115 stop_signal
= TARGET_SIGNAL_TRAP
;
2119 /* When we reach this point, we've pretty much decided
2120 that the reason for stopping must've been a random
2121 (unexpected) signal. */
2124 ecs
->random_signal
= 1;
2125 /* If a fork, vfork or exec event was seen, then there are two
2126 possible responses we can make:
2128 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2129 then we must stop now and issue a prompt. We will resume
2130 the inferior when the user tells us to.
2131 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2132 then we must resume the inferior now and keep checking.
2134 In either case, we must take appropriate steps to "follow" the
2135 the fork/vfork/exec when the inferior is resumed. For example,
2136 if follow-fork-mode is "child", then we must detach from the
2137 parent inferior and follow the new child inferior.
2139 In either case, setting pending_follow causes the next resume()
2140 to take the appropriate following action. */
2141 process_event_stop_test
:
2142 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2144 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2147 stop_signal
= TARGET_SIGNAL_0
;
2152 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2154 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2156 stop_signal
= TARGET_SIGNAL_0
;
2161 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2163 pending_follow
.kind
= ecs
->ws
.kind
;
2164 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2167 stop_signal
= TARGET_SIGNAL_0
;
2173 /* For the program's own signals, act according to
2174 the signal handling tables. */
2176 if (ecs
->random_signal
)
2178 /* Signal not for debugging purposes. */
2181 stopped_by_random_signal
= 1;
2183 if (signal_print
[stop_signal
])
2186 target_terminal_ours_for_output ();
2187 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2189 if (signal_stop
[stop_signal
])
2191 stop_stepping (ecs
);
2194 /* If not going to stop, give terminal back
2195 if we took it away. */
2197 target_terminal_inferior ();
2199 /* Clear the signal if it should not be passed. */
2200 if (signal_program
[stop_signal
] == 0)
2201 stop_signal
= TARGET_SIGNAL_0
;
2203 /* I'm not sure whether this needs to be check_sigtramp2 or
2204 whether it could/should be keep_going.
2206 This used to jump to step_over_function if we are stepping,
2209 Suppose the user does a `next' over a function call, and while
2210 that call is in progress, the inferior receives a signal for
2211 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2212 that case, when we reach this point, there is already a
2213 step-resume breakpoint established, right where it should be:
2214 immediately after the function call the user is "next"-ing
2215 over. If we call step_over_function now, two bad things
2218 - we'll create a new breakpoint, at wherever the current
2219 frame's return address happens to be. That could be
2220 anywhere, depending on what function call happens to be on
2221 the top of the stack at that point. Point is, it's probably
2222 not where we need it.
2224 - the existing step-resume breakpoint (which is at the correct
2225 address) will get orphaned: step_resume_breakpoint will point
2226 to the new breakpoint, and the old step-resume breakpoint
2227 will never be cleaned up.
2229 The old behavior was meant to help HP-UX single-step out of
2230 sigtramps. It would place the new breakpoint at prev_pc, which
2231 was certainly wrong. I don't know the details there, so fixing
2232 this probably breaks that. As with anything else, it's up to
2233 the HP-UX maintainer to furnish a fix that doesn't break other
2234 platforms. --JimB, 20 May 1999 */
2235 check_sigtramp2 (ecs
);
2238 /* Handle cases caused by hitting a breakpoint. */
2240 CORE_ADDR jmp_buf_pc
;
2241 struct bpstat_what what
;
2243 what
= bpstat_what (stop_bpstat
);
2245 if (what
.call_dummy
)
2247 stop_stack_dummy
= 1;
2249 trap_expected_after_continue
= 1;
2253 switch (what
.main_action
)
2255 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2256 /* If we hit the breakpoint at longjmp, disable it for the
2257 duration of this command. Then, install a temporary
2258 breakpoint at the target of the jmp_buf. */
2259 disable_longjmp_breakpoint ();
2260 remove_breakpoints ();
2261 breakpoints_inserted
= 0;
2262 if (!GET_LONGJMP_TARGET (&jmp_buf_pc
))
2268 /* Need to blow away step-resume breakpoint, as it
2269 interferes with us */
2270 if (step_resume_breakpoint
!= NULL
)
2272 delete_breakpoint (step_resume_breakpoint
);
2273 step_resume_breakpoint
= NULL
;
2275 /* Not sure whether we need to blow this away too, but probably
2276 it is like the step-resume breakpoint. */
2277 if (through_sigtramp_breakpoint
!= NULL
)
2279 delete_breakpoint (through_sigtramp_breakpoint
);
2280 through_sigtramp_breakpoint
= NULL
;
2284 /* FIXME - Need to implement nested temporary breakpoints */
2285 if (step_over_calls
> 0)
2286 set_longjmp_resume_breakpoint (jmp_buf_pc
,
2287 get_current_frame ());
2290 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2291 ecs
->handling_longjmp
= 1; /* FIXME */
2295 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2296 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2297 remove_breakpoints ();
2298 breakpoints_inserted
= 0;
2300 /* FIXME - Need to implement nested temporary breakpoints */
2302 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2303 step_frame_address
)))
2305 ecs
->another_trap
= 1;
2310 disable_longjmp_breakpoint ();
2311 ecs
->handling_longjmp
= 0; /* FIXME */
2312 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2314 /* else fallthrough */
2316 case BPSTAT_WHAT_SINGLE
:
2317 if (breakpoints_inserted
)
2319 thread_step_needed
= 1;
2320 remove_breakpoints ();
2322 breakpoints_inserted
= 0;
2323 ecs
->another_trap
= 1;
2324 /* Still need to check other stuff, at least the case
2325 where we are stepping and step out of the right range. */
2328 case BPSTAT_WHAT_STOP_NOISY
:
2329 stop_print_frame
= 1;
2331 /* We are about to nuke the step_resume_breakpoint and
2332 through_sigtramp_breakpoint via the cleanup chain, so
2333 no need to worry about it here. */
2335 stop_stepping (ecs
);
2338 case BPSTAT_WHAT_STOP_SILENT
:
2339 stop_print_frame
= 0;
2341 /* We are about to nuke the step_resume_breakpoint and
2342 through_sigtramp_breakpoint via the cleanup chain, so
2343 no need to worry about it here. */
2345 stop_stepping (ecs
);
2348 case BPSTAT_WHAT_STEP_RESUME
:
2349 /* This proably demands a more elegant solution, but, yeah
2352 This function's use of the simple variable
2353 step_resume_breakpoint doesn't seem to accomodate
2354 simultaneously active step-resume bp's, although the
2355 breakpoint list certainly can.
2357 If we reach here and step_resume_breakpoint is already
2358 NULL, then apparently we have multiple active
2359 step-resume bp's. We'll just delete the breakpoint we
2360 stopped at, and carry on.
2362 Correction: what the code currently does is delete a
2363 step-resume bp, but it makes no effort to ensure that
2364 the one deleted is the one currently stopped at. MVS */
2366 if (step_resume_breakpoint
== NULL
)
2368 step_resume_breakpoint
=
2369 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2371 delete_breakpoint (step_resume_breakpoint
);
2372 step_resume_breakpoint
= NULL
;
2375 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2376 if (through_sigtramp_breakpoint
)
2377 delete_breakpoint (through_sigtramp_breakpoint
);
2378 through_sigtramp_breakpoint
= NULL
;
2380 /* If were waiting for a trap, hitting the step_resume_break
2381 doesn't count as getting it. */
2383 ecs
->another_trap
= 1;
2386 case BPSTAT_WHAT_CHECK_SHLIBS
:
2387 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2390 /* Remove breakpoints, we eventually want to step over the
2391 shlib event breakpoint, and SOLIB_ADD might adjust
2392 breakpoint addresses via breakpoint_re_set. */
2393 if (breakpoints_inserted
)
2394 remove_breakpoints ();
2395 breakpoints_inserted
= 0;
2397 /* Check for any newly added shared libraries if we're
2398 supposed to be adding them automatically. */
2401 /* Switch terminal for any messages produced by
2402 breakpoint_re_set. */
2403 target_terminal_ours_for_output ();
2404 SOLIB_ADD (NULL
, 0, NULL
);
2405 target_terminal_inferior ();
2408 /* Try to reenable shared library breakpoints, additional
2409 code segments in shared libraries might be mapped in now. */
2410 re_enable_breakpoints_in_shlibs ();
2412 /* If requested, stop when the dynamic linker notifies
2413 gdb of events. This allows the user to get control
2414 and place breakpoints in initializer routines for
2415 dynamically loaded objects (among other things). */
2416 if (stop_on_solib_events
)
2418 stop_stepping (ecs
);
2422 /* If we stopped due to an explicit catchpoint, then the
2423 (see above) call to SOLIB_ADD pulled in any symbols
2424 from a newly-loaded library, if appropriate.
2426 We do want the inferior to stop, but not where it is
2427 now, which is in the dynamic linker callback. Rather,
2428 we would like it stop in the user's program, just after
2429 the call that caused this catchpoint to trigger. That
2430 gives the user a more useful vantage from which to
2431 examine their program's state. */
2432 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2434 /* ??rehrauer: If I could figure out how to get the
2435 right return PC from here, we could just set a temp
2436 breakpoint and resume. I'm not sure we can without
2437 cracking open the dld's shared libraries and sniffing
2438 their unwind tables and text/data ranges, and that's
2439 not a terribly portable notion.
2441 Until that time, we must step the inferior out of the
2442 dld callback, and also out of the dld itself (and any
2443 code or stubs in libdld.sl, such as "shl_load" and
2444 friends) until we reach non-dld code. At that point,
2445 we can stop stepping. */
2446 bpstat_get_triggered_catchpoints (stop_bpstat
,
2447 &ecs
->stepping_through_solib_catchpoints
);
2448 ecs
->stepping_through_solib_after_catch
= 1;
2450 /* Be sure to lift all breakpoints, so the inferior does
2451 actually step past this point... */
2452 ecs
->another_trap
= 1;
2457 /* We want to step over this breakpoint, then keep going. */
2458 ecs
->another_trap
= 1;
2465 case BPSTAT_WHAT_LAST
:
2466 /* Not a real code, but listed here to shut up gcc -Wall. */
2468 case BPSTAT_WHAT_KEEP_CHECKING
:
2473 /* We come here if we hit a breakpoint but should not
2474 stop for it. Possibly we also were stepping
2475 and should stop for that. So fall through and
2476 test for stepping. But, if not stepping,
2479 /* Are we stepping to get the inferior out of the dynamic
2480 linker's hook (and possibly the dld itself) after catching
2482 if (ecs
->stepping_through_solib_after_catch
)
2484 #if defined(SOLIB_ADD)
2485 /* Have we reached our destination? If not, keep going. */
2486 if (SOLIB_IN_DYNAMIC_LINKER (ecs
->pid
, stop_pc
))
2488 ecs
->another_trap
= 1;
2493 /* Else, stop and report the catchpoint(s) whose triggering
2494 caused us to begin stepping. */
2495 ecs
->stepping_through_solib_after_catch
= 0;
2496 bpstat_clear (&stop_bpstat
);
2497 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2498 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2499 stop_print_frame
= 1;
2500 stop_stepping (ecs
);
2504 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2506 /* This is the old way of detecting the end of the stack dummy.
2507 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2508 handled above. As soon as we can test it on all of them, all
2509 architectures should define it. */
2511 /* If this is the breakpoint at the end of a stack dummy,
2512 just stop silently, unless the user was doing an si/ni, in which
2513 case she'd better know what she's doing. */
2515 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2516 FRAME_FP (get_current_frame ()))
2519 stop_print_frame
= 0;
2520 stop_stack_dummy
= 1;
2522 trap_expected_after_continue
= 1;
2524 stop_stepping (ecs
);
2529 if (step_resume_breakpoint
)
2531 /* Having a step-resume breakpoint overrides anything
2532 else having to do with stepping commands until
2533 that breakpoint is reached. */
2534 /* I'm not sure whether this needs to be check_sigtramp2 or
2535 whether it could/should be keep_going. */
2536 check_sigtramp2 (ecs
);
2541 if (step_range_end
== 0)
2543 /* Likewise if we aren't even stepping. */
2544 /* I'm not sure whether this needs to be check_sigtramp2 or
2545 whether it could/should be keep_going. */
2546 check_sigtramp2 (ecs
);
2551 /* If stepping through a line, keep going if still within it.
2553 Note that step_range_end is the address of the first instruction
2554 beyond the step range, and NOT the address of the last instruction
2556 if (stop_pc
>= step_range_start
2557 && stop_pc
< step_range_end
)
2559 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2560 So definately need to check for sigtramp here. */
2561 check_sigtramp2 (ecs
);
2566 /* We stepped out of the stepping range. */
2568 /* If we are stepping at the source level and entered the runtime
2569 loader dynamic symbol resolution code, we keep on single stepping
2570 until we exit the run time loader code and reach the callee's
2572 if (step_over_calls
< 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2574 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2576 if (pc_after_resolver
)
2578 /* Set up a step-resume breakpoint at the address
2579 indicated by SKIP_SOLIB_RESOLVER. */
2580 struct symtab_and_line sr_sal
;
2582 sr_sal
.pc
= pc_after_resolver
;
2584 check_for_old_step_resume_breakpoint ();
2585 step_resume_breakpoint
=
2586 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2587 if (breakpoints_inserted
)
2588 insert_breakpoints ();
2595 /* We can't update step_sp every time through the loop, because
2596 reading the stack pointer would slow down stepping too much.
2597 But we can update it every time we leave the step range. */
2598 ecs
->update_step_sp
= 1;
2600 /* Did we just take a signal? */
2601 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2602 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2603 && INNER_THAN (read_sp (), step_sp
))
2605 /* We've just taken a signal; go until we are back to
2606 the point where we took it and one more. */
2608 /* Note: The test above succeeds not only when we stepped
2609 into a signal handler, but also when we step past the last
2610 statement of a signal handler and end up in the return stub
2611 of the signal handler trampoline. To distinguish between
2612 these two cases, check that the frame is INNER_THAN the
2613 previous one below. pai/1997-09-11 */
2617 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2619 if (INNER_THAN (current_frame
, step_frame_address
))
2621 /* We have just taken a signal; go until we are back to
2622 the point where we took it and one more. */
2624 /* This code is needed at least in the following case:
2625 The user types "next" and then a signal arrives (before
2626 the "next" is done). */
2628 /* Note that if we are stopped at a breakpoint, then we need
2629 the step_resume breakpoint to override any breakpoints at
2630 the same location, so that we will still step over the
2631 breakpoint even though the signal happened. */
2632 struct symtab_and_line sr_sal
;
2635 sr_sal
.symtab
= NULL
;
2637 sr_sal
.pc
= prev_pc
;
2638 /* We could probably be setting the frame to
2639 step_frame_address; I don't think anyone thought to
2641 check_for_old_step_resume_breakpoint ();
2642 step_resume_breakpoint
=
2643 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2644 if (breakpoints_inserted
)
2645 insert_breakpoints ();
2649 /* We just stepped out of a signal handler and into
2650 its calling trampoline.
2652 Normally, we'd call step_over_function from
2653 here, but for some reason GDB can't unwind the
2654 stack correctly to find the real PC for the point
2655 user code where the signal trampoline will return
2656 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2657 But signal trampolines are pretty small stubs of
2658 code, anyway, so it's OK instead to just
2659 single-step out. Note: assuming such trampolines
2660 don't exhibit recursion on any platform... */
2661 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2662 &ecs
->stop_func_start
,
2663 &ecs
->stop_func_end
);
2664 /* Readjust stepping range */
2665 step_range_start
= ecs
->stop_func_start
;
2666 step_range_end
= ecs
->stop_func_end
;
2667 ecs
->stepping_through_sigtramp
= 1;
2672 /* If this is stepi or nexti, make sure that the stepping range
2673 gets us past that instruction. */
2674 if (step_range_end
== 1)
2675 /* FIXME: Does this run afoul of the code below which, if
2676 we step into the middle of a line, resets the stepping
2678 step_range_end
= (step_range_start
= prev_pc
) + 1;
2680 ecs
->remove_breakpoints_on_following_step
= 1;
2685 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2686 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2687 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2688 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2689 || ecs
->stop_func_name
== 0)
2691 /* It's a subroutine call. */
2693 if (step_over_calls
== 0)
2695 /* I presume that step_over_calls is only 0 when we're
2696 supposed to be stepping at the assembly language level
2697 ("stepi"). Just stop. */
2699 print_stop_reason (END_STEPPING_RANGE
, 0);
2700 stop_stepping (ecs
);
2704 if (step_over_calls
> 0 || IGNORE_HELPER_CALL (stop_pc
))
2706 /* We're doing a "next". */
2707 step_over_function (ecs
);
2712 /* If we are in a function call trampoline (a stub between
2713 the calling routine and the real function), locate the real
2714 function. That's what tells us (a) whether we want to step
2715 into it at all, and (b) what prologue we want to run to
2716 the end of, if we do step into it. */
2717 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2719 ecs
->stop_func_start
= tmp
;
2722 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2725 struct symtab_and_line xxx
;
2726 /* Why isn't this s_a_l called "sr_sal", like all of the
2727 other s_a_l's where this code is duplicated? */
2728 INIT_SAL (&xxx
); /* initialize to zeroes */
2730 xxx
.section
= find_pc_overlay (xxx
.pc
);
2731 check_for_old_step_resume_breakpoint ();
2732 step_resume_breakpoint
=
2733 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2734 insert_breakpoints ();
2740 /* If we have line number information for the function we
2741 are thinking of stepping into, step into it.
2743 If there are several symtabs at that PC (e.g. with include
2744 files), just want to know whether *any* of them have line
2745 numbers. find_pc_line handles this. */
2747 struct symtab_and_line tmp_sal
;
2749 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2750 if (tmp_sal
.line
!= 0)
2752 step_into_function (ecs
);
2756 step_over_function (ecs
);
2762 /* We've wandered out of the step range. */
2764 ecs
->sal
= find_pc_line (stop_pc
, 0);
2766 if (step_range_end
== 1)
2768 /* It is stepi or nexti. We always want to stop stepping after
2771 print_stop_reason (END_STEPPING_RANGE
, 0);
2772 stop_stepping (ecs
);
2776 /* If we're in the return path from a shared library trampoline,
2777 we want to proceed through the trampoline when stepping. */
2778 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2782 /* Determine where this trampoline returns. */
2783 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2785 /* Only proceed through if we know where it's going. */
2788 /* And put the step-breakpoint there and go until there. */
2789 struct symtab_and_line sr_sal
;
2791 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2793 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2794 /* Do not specify what the fp should be when we stop
2795 since on some machines the prologue
2796 is where the new fp value is established. */
2797 check_for_old_step_resume_breakpoint ();
2798 step_resume_breakpoint
=
2799 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2800 if (breakpoints_inserted
)
2801 insert_breakpoints ();
2803 /* Restart without fiddling with the step ranges or
2810 if (ecs
->sal
.line
== 0)
2812 /* We have no line number information. That means to stop
2813 stepping (does this always happen right after one instruction,
2814 when we do "s" in a function with no line numbers,
2815 or can this happen as a result of a return or longjmp?). */
2817 print_stop_reason (END_STEPPING_RANGE
, 0);
2818 stop_stepping (ecs
);
2822 if ((stop_pc
== ecs
->sal
.pc
)
2823 && (ecs
->current_line
!= ecs
->sal
.line
|| ecs
->current_symtab
!= ecs
->sal
.symtab
))
2825 /* We are at the start of a different line. So stop. Note that
2826 we don't stop if we step into the middle of a different line.
2827 That is said to make things like for (;;) statements work
2830 print_stop_reason (END_STEPPING_RANGE
, 0);
2831 stop_stepping (ecs
);
2835 /* We aren't done stepping.
2837 Optimize by setting the stepping range to the line.
2838 (We might not be in the original line, but if we entered a
2839 new line in mid-statement, we continue stepping. This makes
2840 things like for(;;) statements work better.) */
2842 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2844 /* If this is the last line of the function, don't keep stepping
2845 (it would probably step us out of the function).
2846 This is particularly necessary for a one-line function,
2847 in which after skipping the prologue we better stop even though
2848 we will be in mid-line. */
2850 print_stop_reason (END_STEPPING_RANGE
, 0);
2851 stop_stepping (ecs
);
2854 step_range_start
= ecs
->sal
.pc
;
2855 step_range_end
= ecs
->sal
.end
;
2856 step_frame_address
= FRAME_FP (get_current_frame ());
2857 ecs
->current_line
= ecs
->sal
.line
;
2858 ecs
->current_symtab
= ecs
->sal
.symtab
;
2860 /* In the case where we just stepped out of a function into the middle
2861 of a line of the caller, continue stepping, but step_frame_address
2862 must be modified to current frame */
2864 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2865 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2866 step_frame_address
= current_frame
;
2871 } /* extra brace, to preserve old indentation */
2874 /* Are we in the middle of stepping? */
2877 currently_stepping (struct execution_control_state
*ecs
)
2879 return ((through_sigtramp_breakpoint
== NULL
2880 && !ecs
->handling_longjmp
2881 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2883 || ecs
->stepping_through_solib_after_catch
2884 || bpstat_should_step ());
2888 check_sigtramp2 (struct execution_control_state
*ecs
)
2891 && IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2892 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2893 && INNER_THAN (read_sp (), step_sp
))
2895 /* What has happened here is that we have just stepped the
2896 inferior with a signal (because it is a signal which
2897 shouldn't make us stop), thus stepping into sigtramp.
2899 So we need to set a step_resume_break_address breakpoint and
2900 continue until we hit it, and then step. FIXME: This should
2901 be more enduring than a step_resume breakpoint; we should
2902 know that we will later need to keep going rather than
2903 re-hitting the breakpoint here (see the testsuite,
2904 gdb.base/signals.exp where it says "exceedingly difficult"). */
2906 struct symtab_and_line sr_sal
;
2908 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2909 sr_sal
.pc
= prev_pc
;
2910 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2911 /* We perhaps could set the frame if we kept track of what the
2912 frame corresponding to prev_pc was. But we don't, so don't. */
2913 through_sigtramp_breakpoint
=
2914 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2915 if (breakpoints_inserted
)
2916 insert_breakpoints ();
2918 ecs
->remove_breakpoints_on_following_step
= 1;
2919 ecs
->another_trap
= 1;
2923 /* Subroutine call with source code we should not step over. Do step
2924 to the first line of code in it. */
2927 step_into_function (struct execution_control_state
*ecs
)
2930 struct symtab_and_line sr_sal
;
2932 s
= find_pc_symtab (stop_pc
);
2933 if (s
&& s
->language
!= language_asm
)
2934 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2936 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2937 /* Use the step_resume_break to step until the end of the prologue,
2938 even if that involves jumps (as it seems to on the vax under
2940 /* If the prologue ends in the middle of a source line, continue to
2941 the end of that source line (if it is still within the function).
2942 Otherwise, just go to end of prologue. */
2943 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2944 /* no, don't either. It skips any code that's legitimately on the
2948 && ecs
->sal
.pc
!= ecs
->stop_func_start
2949 && ecs
->sal
.end
< ecs
->stop_func_end
)
2950 ecs
->stop_func_start
= ecs
->sal
.end
;
2953 if (ecs
->stop_func_start
== stop_pc
)
2955 /* We are already there: stop now. */
2957 print_stop_reason (END_STEPPING_RANGE
, 0);
2958 stop_stepping (ecs
);
2963 /* Put the step-breakpoint there and go until there. */
2964 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2965 sr_sal
.pc
= ecs
->stop_func_start
;
2966 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
2967 /* Do not specify what the fp should be when we stop since on
2968 some machines the prologue is where the new fp value is
2970 check_for_old_step_resume_breakpoint ();
2971 step_resume_breakpoint
=
2972 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2973 if (breakpoints_inserted
)
2974 insert_breakpoints ();
2976 /* And make sure stepping stops right away then. */
2977 step_range_end
= step_range_start
;
2982 /* We've just entered a callee, and we wish to resume until it returns
2983 to the caller. Setting a step_resume breakpoint on the return
2984 address will catch a return from the callee.
2986 However, if the callee is recursing, we want to be careful not to
2987 catch returns of those recursive calls, but only of THIS instance
2990 To do this, we set the step_resume bp's frame to our current
2991 caller's frame (step_frame_address, which is set by the "next" or
2992 "until" command, before execution begins). */
2995 step_over_function (struct execution_control_state
*ecs
)
2997 struct symtab_and_line sr_sal
;
2999 INIT_SAL (&sr_sal
); /* initialize to zeros */
3000 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3001 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3003 check_for_old_step_resume_breakpoint ();
3004 step_resume_breakpoint
=
3005 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
3007 if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
3008 step_resume_breakpoint
->frame
= step_frame_address
;
3010 if (breakpoints_inserted
)
3011 insert_breakpoints ();
3015 stop_stepping (struct execution_control_state
*ecs
)
3017 if (target_has_execution
)
3019 /* Are we stopping for a vfork event? We only stop when we see
3020 the child's event. However, we may not yet have seen the
3021 parent's event. And, inferior_pid is still set to the
3022 parent's pid, until we resume again and follow either the
3025 To ensure that we can really touch inferior_pid (aka, the
3026 parent process) -- which calls to functions like read_pc
3027 implicitly do -- wait on the parent if necessary. */
3028 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3029 && !pending_follow
.fork_event
.saw_parent_fork
)
3035 if (target_wait_hook
)
3036 parent_pid
= target_wait_hook (-1, &(ecs
->ws
));
3038 parent_pid
= target_wait (-1, &(ecs
->ws
));
3040 while (parent_pid
!= inferior_pid
);
3043 /* Assuming the inferior still exists, set these up for next
3044 time, just like we did above if we didn't break out of the
3046 prev_pc
= read_pc ();
3047 prev_func_start
= ecs
->stop_func_start
;
3048 prev_func_name
= ecs
->stop_func_name
;
3051 /* Let callers know we don't want to wait for the inferior anymore. */
3052 ecs
->wait_some_more
= 0;
3055 /* This function handles various cases where we need to continue
3056 waiting for the inferior. */
3057 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3060 keep_going (struct execution_control_state
*ecs
)
3062 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3063 vforked child between its creation and subsequent exit or call to
3064 exec(). However, I had big problems in this rather creaky exec
3065 engine, getting that to work. The fundamental problem is that
3066 I'm trying to debug two processes via an engine that only
3067 understands a single process with possibly multiple threads.
3069 Hence, this spot is known to have problems when
3070 target_can_follow_vfork_prior_to_exec returns 1. */
3072 /* Save the pc before execution, to compare with pc after stop. */
3073 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3074 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3075 BREAK is defined, the
3076 original pc would not have
3077 been at the start of a
3079 prev_func_name
= ecs
->stop_func_name
;
3081 if (ecs
->update_step_sp
)
3082 step_sp
= read_sp ();
3083 ecs
->update_step_sp
= 0;
3085 /* If we did not do break;, it means we should keep running the
3086 inferior and not return to debugger. */
3088 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3090 /* We took a signal (which we are supposed to pass through to
3091 the inferior, else we'd have done a break above) and we
3092 haven't yet gotten our trap. Simply continue. */
3093 resume (currently_stepping (ecs
), stop_signal
);
3097 /* Either the trap was not expected, but we are continuing
3098 anyway (the user asked that this signal be passed to the
3101 The signal was SIGTRAP, e.g. it was our signal, but we
3102 decided we should resume from it.
3104 We're going to run this baby now!
3106 Insert breakpoints now, unless we are trying to one-proceed
3107 past a breakpoint. */
3108 /* If we've just finished a special step resume and we don't
3109 want to hit a breakpoint, pull em out. */
3110 if (step_resume_breakpoint
== NULL
3111 && through_sigtramp_breakpoint
== NULL
3112 && ecs
->remove_breakpoints_on_following_step
)
3114 ecs
->remove_breakpoints_on_following_step
= 0;
3115 remove_breakpoints ();
3116 breakpoints_inserted
= 0;
3118 else if (!breakpoints_inserted
&&
3119 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3121 breakpoints_failed
= insert_breakpoints ();
3122 if (breakpoints_failed
)
3124 stop_stepping (ecs
);
3127 breakpoints_inserted
= 1;
3130 trap_expected
= ecs
->another_trap
;
3132 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3133 specifies that such a signal should be delivered to the
3136 Typically, this would occure when a user is debugging a
3137 target monitor on a simulator: the target monitor sets a
3138 breakpoint; the simulator encounters this break-point and
3139 halts the simulation handing control to GDB; GDB, noteing
3140 that the break-point isn't valid, returns control back to the
3141 simulator; the simulator then delivers the hardware
3142 equivalent of a SIGNAL_TRAP to the program being debugged. */
3144 if (stop_signal
== TARGET_SIGNAL_TRAP
3145 && !signal_program
[stop_signal
])
3146 stop_signal
= TARGET_SIGNAL_0
;
3148 #ifdef SHIFT_INST_REGS
3149 /* I'm not sure when this following segment applies. I do know,
3150 now, that we shouldn't rewrite the regs when we were stopped
3151 by a random signal from the inferior process. */
3152 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3153 (this is only used on the 88k). */
3155 if (!bpstat_explains_signal (stop_bpstat
)
3156 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
3157 && !stopped_by_random_signal
)
3159 #endif /* SHIFT_INST_REGS */
3161 resume (currently_stepping (ecs
), stop_signal
);
3164 prepare_to_wait (ecs
);
3167 /* This function normally comes after a resume, before
3168 handle_inferior_event exits. It takes care of any last bits of
3169 housekeeping, and sets the all-important wait_some_more flag. */
3172 prepare_to_wait (struct execution_control_state
*ecs
)
3174 if (ecs
->infwait_state
== infwait_normal_state
)
3176 overlay_cache_invalid
= 1;
3178 /* We have to invalidate the registers BEFORE calling
3179 target_wait because they can be loaded from the target while
3180 in target_wait. This makes remote debugging a bit more
3181 efficient for those targets that provide critical registers
3182 as part of their normal status mechanism. */
3184 registers_changed ();
3185 ecs
->waiton_pid
= -1;
3186 ecs
->wp
= &(ecs
->ws
);
3188 /* This is the old end of the while loop. Let everybody know we
3189 want to wait for the inferior some more and get called again
3191 ecs
->wait_some_more
= 1;
3194 /* Print why the inferior has stopped. We always print something when
3195 the inferior exits, or receives a signal. The rest of the cases are
3196 dealt with later on in normal_stop() and print_it_typical(). Ideally
3197 there should be a call to this function from handle_inferior_event()
3198 each time stop_stepping() is called.*/
3200 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3202 switch (stop_reason
)
3205 /* We don't deal with these cases from handle_inferior_event()
3208 case END_STEPPING_RANGE
:
3209 /* We are done with a step/next/si/ni command. */
3210 /* For now print nothing. */
3212 case BREAKPOINT_HIT
:
3213 /* We found a breakpoint. */
3214 /* For now print nothing. */
3217 /* The inferior was terminated by a signal. */
3218 annotate_signalled ();
3219 printf_filtered ("\nProgram terminated with signal ");
3220 annotate_signal_name ();
3221 printf_filtered ("%s", target_signal_to_name (stop_info
));
3222 annotate_signal_name_end ();
3223 printf_filtered (", ");
3224 annotate_signal_string ();
3225 printf_filtered ("%s", target_signal_to_string (stop_info
));
3226 annotate_signal_string_end ();
3227 printf_filtered (".\n");
3229 printf_filtered ("The program no longer exists.\n");
3230 gdb_flush (gdb_stdout
);
3233 /* The inferior program is finished. */
3234 annotate_exited (stop_info
);
3236 printf_filtered ("\nProgram exited with code 0%o.\n",
3237 (unsigned int) stop_info
);
3239 printf_filtered ("\nProgram exited normally.\n");
3241 case SIGNAL_RECEIVED
:
3242 /* Signal received. The signal table tells us to print about
3245 printf_filtered ("\nProgram received signal ");
3246 annotate_signal_name ();
3247 printf_filtered ("%s", target_signal_to_name (stop_info
));
3248 annotate_signal_name_end ();
3249 printf_filtered (", ");
3250 annotate_signal_string ();
3251 printf_filtered ("%s", target_signal_to_string (stop_info
));
3252 annotate_signal_string_end ();
3253 printf_filtered (".\n");
3254 gdb_flush (gdb_stdout
);
3257 internal_error ("print_stop_reason: unrecognized enum value");
3263 /* Here to return control to GDB when the inferior stops for real.
3264 Print appropriate messages, remove breakpoints, give terminal our modes.
3266 STOP_PRINT_FRAME nonzero means print the executing frame
3267 (pc, function, args, file, line number and line text).
3268 BREAKPOINTS_FAILED nonzero means stop was due to error
3269 attempting to insert breakpoints. */
3274 /* As with the notification of thread events, we want to delay
3275 notifying the user that we've switched thread context until
3276 the inferior actually stops.
3278 (Note that there's no point in saying anything if the inferior
3280 if (may_switch_from_inferior_pid
3281 && (switched_from_inferior_pid
!= inferior_pid
)
3282 && target_has_execution
)
3284 target_terminal_ours_for_output ();
3285 printf_filtered ("[Switched to %s]\n",
3286 target_pid_or_tid_to_str (inferior_pid
));
3287 switched_from_inferior_pid
= inferior_pid
;
3290 /* Make sure that the current_frame's pc is correct. This
3291 is a correction for setting up the frame info before doing
3292 DECR_PC_AFTER_BREAK */
3293 if (target_has_execution
&& get_current_frame ())
3294 (get_current_frame ())->pc
= read_pc ();
3296 if (breakpoints_failed
)
3298 target_terminal_ours_for_output ();
3299 print_sys_errmsg ("ptrace", breakpoints_failed
);
3300 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3301 The same program may be running in another process.\n");
3304 if (target_has_execution
&& breakpoints_inserted
)
3306 if (remove_breakpoints ())
3308 target_terminal_ours_for_output ();
3309 printf_filtered ("Cannot remove breakpoints because ");
3310 printf_filtered ("program is no longer writable.\n");
3311 printf_filtered ("It might be running in another process.\n");
3312 printf_filtered ("Further execution is probably impossible.\n");
3315 breakpoints_inserted
= 0;
3317 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3318 Delete any breakpoint that is to be deleted at the next stop. */
3320 breakpoint_auto_delete (stop_bpstat
);
3322 /* If an auto-display called a function and that got a signal,
3323 delete that auto-display to avoid an infinite recursion. */
3325 if (stopped_by_random_signal
)
3326 disable_current_display ();
3328 /* Don't print a message if in the middle of doing a "step n"
3329 operation for n > 1 */
3330 if (step_multi
&& stop_step
)
3333 target_terminal_ours ();
3335 /* Look up the hook_stop and run it if it exists. */
3337 if (stop_command
&& stop_command
->hook
)
3339 catch_errors (hook_stop_stub
, stop_command
->hook
,
3340 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3343 if (!target_has_stack
)
3349 /* Select innermost stack frame - i.e., current frame is frame 0,
3350 and current location is based on that.
3351 Don't do this on return from a stack dummy routine,
3352 or if the program has exited. */
3354 if (!stop_stack_dummy
)
3356 select_frame (get_current_frame (), 0);
3358 /* Print current location without a level number, if
3359 we have changed functions or hit a breakpoint.
3360 Print source line if we have one.
3361 bpstat_print() contains the logic deciding in detail
3362 what to print, based on the event(s) that just occurred. */
3364 if (stop_print_frame
)
3368 int do_frame_printing
= 1;
3370 bpstat_ret
= bpstat_print (stop_bpstat
);
3375 && step_frame_address
== FRAME_FP (get_current_frame ())
3376 && step_start_function
== find_pc_function (stop_pc
))
3377 source_flag
= -1; /* finished step, just print source line */
3379 source_flag
= 1; /* print location and source line */
3381 case PRINT_SRC_AND_LOC
:
3382 source_flag
= 1; /* print location and source line */
3384 case PRINT_SRC_ONLY
:
3388 do_frame_printing
= 0;
3391 internal_error ("Unknown value.");
3394 /* The behavior of this routine with respect to the source
3396 -1: Print only source line
3397 0: Print only location
3398 1: Print location and source line */
3399 if (do_frame_printing
)
3400 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
3402 /* Display the auto-display expressions. */
3407 /* Save the function value return registers, if we care.
3408 We might be about to restore their previous contents. */
3409 if (proceed_to_finish
)
3410 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
3412 if (stop_stack_dummy
)
3414 /* Pop the empty frame that contains the stack dummy.
3415 POP_FRAME ends with a setting of the current frame, so we
3416 can use that next. */
3418 /* Set stop_pc to what it was before we called the function.
3419 Can't rely on restore_inferior_status because that only gets
3420 called if we don't stop in the called function. */
3421 stop_pc
= read_pc ();
3422 select_frame (get_current_frame (), 0);
3426 TUIDO (((TuiOpaqueFuncPtr
) tui_vCheckDataValues
, selected_frame
));
3429 annotate_stopped ();
3433 hook_stop_stub (void *cmd
)
3435 execute_user_command ((struct cmd_list_element
*) cmd
, 0);
3440 signal_stop_state (int signo
)
3442 return signal_stop
[signo
];
3446 signal_print_state (int signo
)
3448 return signal_print
[signo
];
3452 signal_pass_state (int signo
)
3454 return signal_program
[signo
];
3457 int signal_stop_update (signo
, state
)
3461 int ret
= signal_stop
[signo
];
3462 signal_stop
[signo
] = state
;
3466 int signal_print_update (signo
, state
)
3470 int ret
= signal_print
[signo
];
3471 signal_print
[signo
] = state
;
3475 int signal_pass_update (signo
, state
)
3479 int ret
= signal_program
[signo
];
3480 signal_program
[signo
] = state
;
3485 sig_print_header (void)
3488 Signal Stop\tPrint\tPass to program\tDescription\n");
3492 sig_print_info (enum target_signal oursig
)
3494 char *name
= target_signal_to_name (oursig
);
3495 int name_padding
= 13 - strlen (name
);
3497 if (name_padding
<= 0)
3500 printf_filtered ("%s", name
);
3501 printf_filtered ("%*.*s ", name_padding
, name_padding
,
3503 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3504 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3505 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3506 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3509 /* Specify how various signals in the inferior should be handled. */
3512 handle_command (char *args
, int from_tty
)
3515 int digits
, wordlen
;
3516 int sigfirst
, signum
, siglast
;
3517 enum target_signal oursig
;
3520 unsigned char *sigs
;
3521 struct cleanup
*old_chain
;
3525 error_no_arg ("signal to handle");
3528 /* Allocate and zero an array of flags for which signals to handle. */
3530 nsigs
= (int) TARGET_SIGNAL_LAST
;
3531 sigs
= (unsigned char *) alloca (nsigs
);
3532 memset (sigs
, 0, nsigs
);
3534 /* Break the command line up into args. */
3536 argv
= buildargv (args
);
3541 old_chain
= make_cleanup_freeargv (argv
);
3543 /* Walk through the args, looking for signal oursigs, signal names, and
3544 actions. Signal numbers and signal names may be interspersed with
3545 actions, with the actions being performed for all signals cumulatively
3546 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3548 while (*argv
!= NULL
)
3550 wordlen
= strlen (*argv
);
3551 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3555 sigfirst
= siglast
= -1;
3557 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3559 /* Apply action to all signals except those used by the
3560 debugger. Silently skip those. */
3563 siglast
= nsigs
- 1;
3565 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3567 SET_SIGS (nsigs
, sigs
, signal_stop
);
3568 SET_SIGS (nsigs
, sigs
, signal_print
);
3570 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3572 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3574 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3576 SET_SIGS (nsigs
, sigs
, signal_print
);
3578 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3580 SET_SIGS (nsigs
, sigs
, signal_program
);
3582 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3584 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3586 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3588 SET_SIGS (nsigs
, sigs
, signal_program
);
3590 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3592 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3593 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3595 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3597 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3599 else if (digits
> 0)
3601 /* It is numeric. The numeric signal refers to our own
3602 internal signal numbering from target.h, not to host/target
3603 signal number. This is a feature; users really should be
3604 using symbolic names anyway, and the common ones like
3605 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3607 sigfirst
= siglast
= (int)
3608 target_signal_from_command (atoi (*argv
));
3609 if ((*argv
)[digits
] == '-')
3612 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3614 if (sigfirst
> siglast
)
3616 /* Bet he didn't figure we'd think of this case... */
3624 oursig
= target_signal_from_name (*argv
);
3625 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3627 sigfirst
= siglast
= (int) oursig
;
3631 /* Not a number and not a recognized flag word => complain. */
3632 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3636 /* If any signal numbers or symbol names were found, set flags for
3637 which signals to apply actions to. */
3639 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3641 switch ((enum target_signal
) signum
)
3643 case TARGET_SIGNAL_TRAP
:
3644 case TARGET_SIGNAL_INT
:
3645 if (!allsigs
&& !sigs
[signum
])
3647 if (query ("%s is used by the debugger.\n\
3648 Are you sure you want to change it? ",
3649 target_signal_to_name
3650 ((enum target_signal
) signum
)))
3656 printf_unfiltered ("Not confirmed, unchanged.\n");
3657 gdb_flush (gdb_stdout
);
3661 case TARGET_SIGNAL_0
:
3662 case TARGET_SIGNAL_DEFAULT
:
3663 case TARGET_SIGNAL_UNKNOWN
:
3664 /* Make sure that "all" doesn't print these. */
3675 target_notice_signals (inferior_pid
);
3679 /* Show the results. */
3680 sig_print_header ();
3681 for (signum
= 0; signum
< nsigs
; signum
++)
3685 sig_print_info (signum
);
3690 do_cleanups (old_chain
);
3694 xdb_handle_command (char *args
, int from_tty
)
3697 struct cleanup
*old_chain
;
3699 /* Break the command line up into args. */
3701 argv
= buildargv (args
);
3706 old_chain
= make_cleanup_freeargv (argv
);
3707 if (argv
[1] != (char *) NULL
)
3712 bufLen
= strlen (argv
[0]) + 20;
3713 argBuf
= (char *) xmalloc (bufLen
);
3717 enum target_signal oursig
;
3719 oursig
= target_signal_from_name (argv
[0]);
3720 memset (argBuf
, 0, bufLen
);
3721 if (strcmp (argv
[1], "Q") == 0)
3722 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3725 if (strcmp (argv
[1], "s") == 0)
3727 if (!signal_stop
[oursig
])
3728 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3730 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3732 else if (strcmp (argv
[1], "i") == 0)
3734 if (!signal_program
[oursig
])
3735 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3737 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3739 else if (strcmp (argv
[1], "r") == 0)
3741 if (!signal_print
[oursig
])
3742 sprintf (argBuf
, "%s %s", argv
[0], "print");
3744 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3750 handle_command (argBuf
, from_tty
);
3752 printf_filtered ("Invalid signal handling flag.\n");
3757 do_cleanups (old_chain
);
3760 /* Print current contents of the tables set by the handle command.
3761 It is possible we should just be printing signals actually used
3762 by the current target (but for things to work right when switching
3763 targets, all signals should be in the signal tables). */
3766 signals_info (char *signum_exp
, int from_tty
)
3768 enum target_signal oursig
;
3769 sig_print_header ();
3773 /* First see if this is a symbol name. */
3774 oursig
= target_signal_from_name (signum_exp
);
3775 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3777 /* No, try numeric. */
3779 target_signal_from_command (parse_and_eval_address (signum_exp
));
3781 sig_print_info (oursig
);
3785 printf_filtered ("\n");
3786 /* These ugly casts brought to you by the native VAX compiler. */
3787 for (oursig
= TARGET_SIGNAL_FIRST
;
3788 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3789 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3793 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3794 && oursig
!= TARGET_SIGNAL_DEFAULT
3795 && oursig
!= TARGET_SIGNAL_0
)
3796 sig_print_info (oursig
);
3799 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3802 struct inferior_status
3804 enum target_signal stop_signal
;
3808 int stop_stack_dummy
;
3809 int stopped_by_random_signal
;
3811 CORE_ADDR step_range_start
;
3812 CORE_ADDR step_range_end
;
3813 CORE_ADDR step_frame_address
;
3814 int step_over_calls
;
3815 CORE_ADDR step_resume_break_address
;
3816 int stop_after_trap
;
3817 int stop_soon_quietly
;
3818 CORE_ADDR selected_frame_address
;
3819 char *stop_registers
;
3821 /* These are here because if call_function_by_hand has written some
3822 registers and then decides to call error(), we better not have changed
3827 int breakpoint_proceeded
;
3828 int restore_stack_info
;
3829 int proceed_to_finish
;
3832 static struct inferior_status
*
3833 xmalloc_inferior_status (void)
3835 struct inferior_status
*inf_status
;
3836 inf_status
= xmalloc (sizeof (struct inferior_status
));
3837 inf_status
->stop_registers
= xmalloc (REGISTER_BYTES
);
3838 inf_status
->registers
= xmalloc (REGISTER_BYTES
);
3843 free_inferior_status (struct inferior_status
*inf_status
)
3845 free (inf_status
->registers
);
3846 free (inf_status
->stop_registers
);
3851 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3854 int size
= REGISTER_RAW_SIZE (regno
);
3855 void *buf
= alloca (size
);
3856 store_signed_integer (buf
, size
, val
);
3857 memcpy (&inf_status
->registers
[REGISTER_BYTE (regno
)], buf
, size
);
3860 /* Save all of the information associated with the inferior<==>gdb
3861 connection. INF_STATUS is a pointer to a "struct inferior_status"
3862 (defined in inferior.h). */
3864 struct inferior_status
*
3865 save_inferior_status (int restore_stack_info
)
3867 struct inferior_status
*inf_status
= xmalloc_inferior_status ();
3869 inf_status
->stop_signal
= stop_signal
;
3870 inf_status
->stop_pc
= stop_pc
;
3871 inf_status
->stop_step
= stop_step
;
3872 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3873 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3874 inf_status
->trap_expected
= trap_expected
;
3875 inf_status
->step_range_start
= step_range_start
;
3876 inf_status
->step_range_end
= step_range_end
;
3877 inf_status
->step_frame_address
= step_frame_address
;
3878 inf_status
->step_over_calls
= step_over_calls
;
3879 inf_status
->stop_after_trap
= stop_after_trap
;
3880 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3881 /* Save original bpstat chain here; replace it with copy of chain.
3882 If caller's caller is walking the chain, they'll be happier if we
3883 hand them back the original chain when restore_inferior_status is
3885 inf_status
->stop_bpstat
= stop_bpstat
;
3886 stop_bpstat
= bpstat_copy (stop_bpstat
);
3887 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3888 inf_status
->restore_stack_info
= restore_stack_info
;
3889 inf_status
->proceed_to_finish
= proceed_to_finish
;
3891 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
3893 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3895 record_selected_frame (&(inf_status
->selected_frame_address
),
3896 &(inf_status
->selected_level
));
3900 struct restore_selected_frame_args
3902 CORE_ADDR frame_address
;
3907 restore_selected_frame (void *args
)
3909 struct restore_selected_frame_args
*fr
=
3910 (struct restore_selected_frame_args
*) args
;
3911 struct frame_info
*frame
;
3912 int level
= fr
->level
;
3914 frame
= find_relative_frame (get_current_frame (), &level
);
3916 /* If inf_status->selected_frame_address is NULL, there was no
3917 previously selected frame. */
3918 if (frame
== NULL
||
3919 /* FRAME_FP (frame) != fr->frame_address || */
3920 /* elz: deleted this check as a quick fix to the problem that
3921 for function called by hand gdb creates no internal frame
3922 structure and the real stack and gdb's idea of stack are
3923 different if nested calls by hands are made.
3925 mvs: this worries me. */
3928 warning ("Unable to restore previously selected frame.\n");
3932 select_frame (frame
, fr
->level
);
3938 restore_inferior_status (struct inferior_status
*inf_status
)
3940 stop_signal
= inf_status
->stop_signal
;
3941 stop_pc
= inf_status
->stop_pc
;
3942 stop_step
= inf_status
->stop_step
;
3943 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3944 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3945 trap_expected
= inf_status
->trap_expected
;
3946 step_range_start
= inf_status
->step_range_start
;
3947 step_range_end
= inf_status
->step_range_end
;
3948 step_frame_address
= inf_status
->step_frame_address
;
3949 step_over_calls
= inf_status
->step_over_calls
;
3950 stop_after_trap
= inf_status
->stop_after_trap
;
3951 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
3952 bpstat_clear (&stop_bpstat
);
3953 stop_bpstat
= inf_status
->stop_bpstat
;
3954 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3955 proceed_to_finish
= inf_status
->proceed_to_finish
;
3957 /* FIXME: Is the restore of stop_registers always needed */
3958 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
3960 /* The inferior can be gone if the user types "print exit(0)"
3961 (and perhaps other times). */
3962 if (target_has_execution
)
3963 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3965 /* FIXME: If we are being called after stopping in a function which
3966 is called from gdb, we should not be trying to restore the
3967 selected frame; it just prints a spurious error message (The
3968 message is useful, however, in detecting bugs in gdb (like if gdb
3969 clobbers the stack)). In fact, should we be restoring the
3970 inferior status at all in that case? . */
3972 if (target_has_stack
&& inf_status
->restore_stack_info
)
3974 struct restore_selected_frame_args fr
;
3975 fr
.level
= inf_status
->selected_level
;
3976 fr
.frame_address
= inf_status
->selected_frame_address
;
3977 /* The point of catch_errors is that if the stack is clobbered,
3978 walking the stack might encounter a garbage pointer and error()
3979 trying to dereference it. */
3980 if (catch_errors (restore_selected_frame
, &fr
,
3981 "Unable to restore previously selected frame:\n",
3982 RETURN_MASK_ERROR
) == 0)
3983 /* Error in restoring the selected frame. Select the innermost
3987 select_frame (get_current_frame (), 0);
3991 free_inferior_status (inf_status
);
3995 discard_inferior_status (struct inferior_status
*inf_status
)
3997 /* See save_inferior_status for info on stop_bpstat. */
3998 bpstat_clear (&inf_status
->stop_bpstat
);
3999 free_inferior_status (inf_status
);
4003 set_follow_fork_mode_command (char *arg
, int from_tty
,
4004 struct cmd_list_element
*c
)
4006 if (!STREQ (arg
, "parent") &&
4007 !STREQ (arg
, "child") &&
4008 !STREQ (arg
, "both") &&
4009 !STREQ (arg
, "ask"))
4010 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
4012 if (follow_fork_mode_string
!= NULL
)
4013 free (follow_fork_mode_string
);
4014 follow_fork_mode_string
= savestring (arg
, strlen (arg
));
4020 stop_registers
= xmalloc (REGISTER_BYTES
);
4024 _initialize_infrun (void)
4027 register int numsigs
;
4028 struct cmd_list_element
*c
;
4032 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4033 register_gdbarch_swap (NULL
, 0, build_infrun
);
4035 add_info ("signals", signals_info
,
4036 "What debugger does when program gets various signals.\n\
4037 Specify a signal as argument to print info on that signal only.");
4038 add_info_alias ("handle", "signals", 0);
4040 add_com ("handle", class_run
, handle_command
,
4041 concat ("Specify how to handle a signal.\n\
4042 Args are signals and actions to apply to those signals.\n\
4043 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4044 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4045 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4046 The special arg \"all\" is recognized to mean all signals except those\n\
4047 used by the debugger, typically SIGTRAP and SIGINT.\n",
4048 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4049 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4050 Stop means reenter debugger if this signal happens (implies print).\n\
4051 Print means print a message if this signal happens.\n\
4052 Pass means let program see this signal; otherwise program doesn't know.\n\
4053 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4054 Pass and Stop may be combined.", NULL
));
4057 add_com ("lz", class_info
, signals_info
,
4058 "What debugger does when program gets various signals.\n\
4059 Specify a signal as argument to print info on that signal only.");
4060 add_com ("z", class_run
, xdb_handle_command
,
4061 concat ("Specify how to handle a signal.\n\
4062 Args are signals and actions to apply to those signals.\n\
4063 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4064 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4065 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4066 The special arg \"all\" is recognized to mean all signals except those\n\
4067 used by the debugger, typically SIGTRAP and SIGINT.\n",
4068 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4069 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4070 nopass), \"Q\" (noprint)\n\
4071 Stop means reenter debugger if this signal happens (implies print).\n\
4072 Print means print a message if this signal happens.\n\
4073 Pass means let program see this signal; otherwise program doesn't know.\n\
4074 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4075 Pass and Stop may be combined.", NULL
));
4079 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
4080 "There is no `stop' command, but you can set a hook on `stop'.\n\
4081 This allows you to set a list of commands to be run each time execution\n\
4082 of the program stops.", &cmdlist
);
4084 numsigs
= (int) TARGET_SIGNAL_LAST
;
4085 signal_stop
= (unsigned char *)
4086 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4087 signal_print
= (unsigned char *)
4088 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4089 signal_program
= (unsigned char *)
4090 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4091 for (i
= 0; i
< numsigs
; i
++)
4094 signal_print
[i
] = 1;
4095 signal_program
[i
] = 1;
4098 /* Signals caused by debugger's own actions
4099 should not be given to the program afterwards. */
4100 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4101 signal_program
[TARGET_SIGNAL_INT
] = 0;
4103 /* Signals that are not errors should not normally enter the debugger. */
4104 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4105 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4106 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4107 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4108 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4109 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4110 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4111 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4112 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4113 signal_print
[TARGET_SIGNAL_IO
] = 0;
4114 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4115 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4116 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4117 signal_print
[TARGET_SIGNAL_URG
] = 0;
4118 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4119 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4121 /* These signals are used internally by user-level thread
4122 implementations. (See signal(5) on Solaris.) Like the above
4123 signals, a healthy program receives and handles them as part of
4124 its normal operation. */
4125 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4126 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4127 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4128 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4129 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4130 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4134 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4135 (char *) &stop_on_solib_events
,
4136 "Set stopping for shared library events.\n\
4137 If nonzero, gdb will give control to the user when the dynamic linker\n\
4138 notifies gdb of shared library events. The most common event of interest\n\
4139 to the user would be loading/unloading of a new library.\n",
4144 c
= add_set_enum_cmd ("follow-fork-mode",
4146 follow_fork_mode_kind_names
,
4147 (char *) &follow_fork_mode_string
,
4148 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4149 kernel problem. It's also not terribly useful without a GUI to
4150 help the user drive two debuggers. So for now, I'm disabling
4151 the "both" option. */
4152 /* "Set debugger response to a program call of fork \
4154 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4155 parent - the original process is debugged after a fork\n\
4156 child - the new process is debugged after a fork\n\
4157 both - both the parent and child are debugged after a fork\n\
4158 ask - the debugger will ask for one of the above choices\n\
4159 For \"both\", another copy of the debugger will be started to follow\n\
4160 the new child process. The original debugger will continue to follow\n\
4161 the original parent process. To distinguish their prompts, the\n\
4162 debugger copy's prompt will be changed.\n\
4163 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4164 By default, the debugger will follow the parent process.",
4166 "Set debugger response to a program call of fork \
4168 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4169 parent - the original process is debugged after a fork\n\
4170 child - the new process is debugged after a fork\n\
4171 ask - the debugger will ask for one of the above choices\n\
4172 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4173 By default, the debugger will follow the parent process.",
4175 /* c->function.sfunc = ; */
4176 add_show_from_set (c
, &showlist
);
4178 set_follow_fork_mode_command ("parent", 0, NULL
);
4180 c
= add_set_enum_cmd ("scheduler-locking", class_run
,
4181 scheduler_enums
, /* array of string names */
4182 (char *) &scheduler_mode
, /* current mode */
4183 "Set mode for locking scheduler during execution.\n\
4184 off == no locking (threads may preempt at any time)\n\
4185 on == full locking (no thread except the current thread may run)\n\
4186 step == scheduler locked during every single-step operation.\n\
4187 In this mode, no other thread may run during a step command.\n\
4188 Other threads may run while stepping over a function call ('next').",
4191 c
->function
.sfunc
= set_schedlock_func
; /* traps on target vector */
4192 add_show_from_set (c
, &showlist
);