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 (void)
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 if (step_multi
&& stop_step
)
1345 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1347 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1351 /* Prepare an execution control state for looping through a
1352 wait_for_inferior-type loop. */
1355 init_execution_control_state (struct execution_control_state
*ecs
)
1357 /* ecs->another_trap? */
1358 ecs
->random_signal
= 0;
1359 ecs
->remove_breakpoints_on_following_step
= 0;
1360 ecs
->handling_longjmp
= 0; /* FIXME */
1361 ecs
->update_step_sp
= 0;
1362 ecs
->stepping_through_solib_after_catch
= 0;
1363 ecs
->stepping_through_solib_catchpoints
= NULL
;
1364 ecs
->enable_hw_watchpoints_after_wait
= 0;
1365 ecs
->stepping_through_sigtramp
= 0;
1366 ecs
->sal
= find_pc_line (prev_pc
, 0);
1367 ecs
->current_line
= ecs
->sal
.line
;
1368 ecs
->current_symtab
= ecs
->sal
.symtab
;
1369 ecs
->infwait_state
= infwait_normal_state
;
1370 ecs
->waiton_pid
= -1;
1371 ecs
->wp
= &(ecs
->ws
);
1374 /* Call this function before setting step_resume_breakpoint, as a
1375 sanity check. There should never be more than one step-resume
1376 breakpoint per thread, so we should never be setting a new
1377 step_resume_breakpoint when one is already active. */
1379 check_for_old_step_resume_breakpoint (void)
1381 if (step_resume_breakpoint
)
1382 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1385 /* Given an execution control state that has been freshly filled in
1386 by an event from the inferior, figure out what it means and take
1387 appropriate action. */
1390 handle_inferior_event (struct execution_control_state
*ecs
)
1393 int stepped_after_stopped_by_watchpoint
;
1395 /* Keep this extra brace for now, minimizes diffs. */
1397 switch (ecs
->infwait_state
)
1399 case infwait_normal_state
:
1400 /* Since we've done a wait, we have a new event. Don't
1401 carry over any expectations about needing to step over a
1403 thread_step_needed
= 0;
1405 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1406 is serviced in this loop, below. */
1407 if (ecs
->enable_hw_watchpoints_after_wait
)
1409 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid
);
1410 ecs
->enable_hw_watchpoints_after_wait
= 0;
1412 stepped_after_stopped_by_watchpoint
= 0;
1415 case infwait_thread_hop_state
:
1416 insert_breakpoints ();
1418 /* We need to restart all the threads now,
1419 * unles we're running in scheduler-locked mode.
1420 * FIXME: shouldn't we look at currently_stepping ()?
1422 if (scheduler_mode
== schedlock_on
)
1423 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1425 target_resume (-1, 0, TARGET_SIGNAL_0
);
1426 ecs
->infwait_state
= infwait_normal_state
;
1427 prepare_to_wait (ecs
);
1430 case infwait_nullified_state
:
1433 case infwait_nonstep_watch_state
:
1434 insert_breakpoints ();
1436 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1437 handle things like signals arriving and other things happening
1438 in combination correctly? */
1439 stepped_after_stopped_by_watchpoint
= 1;
1442 ecs
->infwait_state
= infwait_normal_state
;
1444 flush_cached_frames ();
1446 /* If it's a new process, add it to the thread database */
1448 ecs
->new_thread_event
= ((ecs
->pid
!= inferior_pid
) && !in_thread_list (ecs
->pid
));
1450 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1451 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1452 && ecs
->new_thread_event
)
1454 add_thread (ecs
->pid
);
1456 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs
->pid
));
1459 /* NOTE: This block is ONLY meant to be invoked in case of a
1460 "thread creation event"! If it is invoked for any other
1461 sort of event (such as a new thread landing on a breakpoint),
1462 the event will be discarded, which is almost certainly
1465 To avoid this, the low-level module (eg. target_wait)
1466 should call in_thread_list and add_thread, so that the
1467 new thread is known by the time we get here. */
1469 /* We may want to consider not doing a resume here in order
1470 to give the user a chance to play with the new thread.
1471 It might be good to make that a user-settable option. */
1473 /* At this point, all threads are stopped (happens
1474 automatically in either the OS or the native code).
1475 Therefore we need to continue all threads in order to
1478 target_resume (-1, 0, TARGET_SIGNAL_0
);
1479 prepare_to_wait (ecs
);
1484 switch (ecs
->ws
.kind
)
1486 case TARGET_WAITKIND_LOADED
:
1487 /* Ignore gracefully during startup of the inferior, as it
1488 might be the shell which has just loaded some objects,
1489 otherwise add the symbols for the newly loaded objects. */
1491 if (!stop_soon_quietly
)
1493 /* Remove breakpoints, SOLIB_ADD might adjust
1494 breakpoint addresses via breakpoint_re_set. */
1495 if (breakpoints_inserted
)
1496 remove_breakpoints ();
1498 /* Check for any newly added shared libraries if we're
1499 supposed to be adding them automatically. */
1502 /* Switch terminal for any messages produced by
1503 breakpoint_re_set. */
1504 target_terminal_ours_for_output ();
1505 SOLIB_ADD (NULL
, 0, NULL
);
1506 target_terminal_inferior ();
1509 /* Reinsert breakpoints and continue. */
1510 if (breakpoints_inserted
)
1511 insert_breakpoints ();
1514 resume (0, TARGET_SIGNAL_0
);
1515 prepare_to_wait (ecs
);
1518 case TARGET_WAITKIND_SPURIOUS
:
1519 resume (0, TARGET_SIGNAL_0
);
1520 prepare_to_wait (ecs
);
1523 case TARGET_WAITKIND_EXITED
:
1524 target_terminal_ours (); /* Must do this before mourn anyway */
1525 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1527 /* Record the exit code in the convenience variable $_exitcode, so
1528 that the user can inspect this again later. */
1529 set_internalvar (lookup_internalvar ("_exitcode"),
1530 value_from_longest (builtin_type_int
,
1531 (LONGEST
) ecs
->ws
.value
.integer
));
1532 gdb_flush (gdb_stdout
);
1533 target_mourn_inferior ();
1534 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P */
1535 stop_print_frame
= 0;
1536 stop_stepping (ecs
);
1539 case TARGET_WAITKIND_SIGNALLED
:
1540 stop_print_frame
= 0;
1541 stop_signal
= ecs
->ws
.value
.sig
;
1542 target_terminal_ours (); /* Must do this before mourn anyway */
1544 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1545 mean it is already dead? This has been here since GDB 2.8, so
1546 perhaps it means rms didn't understand unix waitstatuses?
1547 For the moment I'm just kludging around this in remote.c
1548 rather than trying to change it here --kingdon, 5 Dec 1994. */
1549 target_kill (); /* kill mourns as well */
1551 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1552 singlestep_breakpoints_inserted_p
= 0; /*SOFTWARE_SINGLE_STEP_P */
1553 stop_stepping (ecs
);
1556 /* The following are the only cases in which we keep going;
1557 the above cases end in a continue or goto. */
1558 case TARGET_WAITKIND_FORKED
:
1559 stop_signal
= TARGET_SIGNAL_TRAP
;
1560 pending_follow
.kind
= ecs
->ws
.kind
;
1562 /* Ignore fork events reported for the parent; we're only
1563 interested in reacting to forks of the child. Note that
1564 we expect the child's fork event to be available if we
1565 waited for it now. */
1566 if (inferior_pid
== ecs
->pid
)
1568 pending_follow
.fork_event
.saw_parent_fork
= 1;
1569 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1570 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1571 prepare_to_wait (ecs
);
1576 pending_follow
.fork_event
.saw_child_fork
= 1;
1577 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1578 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1581 stop_pc
= read_pc_pid (ecs
->pid
);
1582 ecs
->saved_inferior_pid
= inferior_pid
;
1583 inferior_pid
= ecs
->pid
;
1584 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1585 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1586 inferior_pid
= ecs
->saved_inferior_pid
;
1587 goto process_event_stop_test
;
1589 /* If this a platform which doesn't allow a debugger to touch a
1590 vfork'd inferior until after it exec's, then we'd best keep
1591 our fingers entirely off the inferior, other than continuing
1592 it. This has the unfortunate side-effect that catchpoints
1593 of vforks will be ignored. But since the platform doesn't
1594 allow the inferior be touched at vfork time, there's really
1596 case TARGET_WAITKIND_VFORKED
:
1597 stop_signal
= TARGET_SIGNAL_TRAP
;
1598 pending_follow
.kind
= ecs
->ws
.kind
;
1600 /* Is this a vfork of the parent? If so, then give any
1601 vfork catchpoints a chance to trigger now. (It's
1602 dangerous to do so if the child canot be touched until
1603 it execs, and the child has not yet exec'd. We probably
1604 should warn the user to that effect when the catchpoint
1606 if (ecs
->pid
== inferior_pid
)
1608 pending_follow
.fork_event
.saw_parent_fork
= 1;
1609 pending_follow
.fork_event
.parent_pid
= ecs
->pid
;
1610 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1613 /* If we've seen the child's vfork event but cannot really touch
1614 the child until it execs, then we must continue the child now.
1615 Else, give any vfork catchpoints a chance to trigger now. */
1618 pending_follow
.fork_event
.saw_child_fork
= 1;
1619 pending_follow
.fork_event
.child_pid
= ecs
->pid
;
1620 pending_follow
.fork_event
.parent_pid
= ecs
->ws
.value
.related_pid
;
1621 target_post_startup_inferior (pending_follow
.fork_event
.child_pid
);
1622 follow_vfork_when_exec
= !target_can_follow_vfork_prior_to_exec ();
1623 if (follow_vfork_when_exec
)
1625 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1626 prepare_to_wait (ecs
);
1631 stop_pc
= read_pc ();
1632 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1633 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1634 goto process_event_stop_test
;
1636 case TARGET_WAITKIND_EXECD
:
1637 stop_signal
= TARGET_SIGNAL_TRAP
;
1639 /* Is this a target which reports multiple exec events per actual
1640 call to exec()? (HP-UX using ptrace does, for example.) If so,
1641 ignore all but the last one. Just resume the exec'r, and wait
1642 for the next exec event. */
1643 if (inferior_ignoring_leading_exec_events
)
1645 inferior_ignoring_leading_exec_events
--;
1646 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1647 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow
.fork_event
.parent_pid
);
1648 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1649 prepare_to_wait (ecs
);
1652 inferior_ignoring_leading_exec_events
=
1653 target_reported_exec_events_per_exec_call () - 1;
1655 pending_follow
.execd_pathname
=
1656 savestring (ecs
->ws
.value
.execd_pathname
,
1657 strlen (ecs
->ws
.value
.execd_pathname
));
1659 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1660 child of a vfork exec?
1662 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1663 HP-UX, events associated with a vforking inferior come in
1664 threes: a vfork event for the child (always first), followed
1665 a vfork event for the parent and an exec event for the child.
1666 The latter two can come in either order.
1668 If we get the parent vfork event first, life's good: We follow
1669 either the parent or child, and then the child's exec event is
1672 But if we get the child's exec event first, then we delay
1673 responding to it until we handle the parent's vfork. Because,
1674 otherwise we can't satisfy a "catch vfork". */
1675 if (pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
1677 pending_follow
.fork_event
.saw_child_exec
= 1;
1679 /* On some targets, the child must be resumed before
1680 the parent vfork event is delivered. A single-step
1682 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1683 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1684 /* We expect the parent vfork event to be available now. */
1685 prepare_to_wait (ecs
);
1689 /* This causes the eventpoints and symbol table to be reset. Must
1690 do this now, before trying to determine whether to stop. */
1691 follow_exec (inferior_pid
, pending_follow
.execd_pathname
);
1692 free (pending_follow
.execd_pathname
);
1694 stop_pc
= read_pc_pid (ecs
->pid
);
1695 ecs
->saved_inferior_pid
= inferior_pid
;
1696 inferior_pid
= ecs
->pid
;
1697 stop_bpstat
= bpstat_stop_status (&stop_pc
, currently_stepping (ecs
));
1698 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1699 inferior_pid
= ecs
->saved_inferior_pid
;
1700 goto process_event_stop_test
;
1702 /* These syscall events are returned on HP-UX, as part of its
1703 implementation of page-protection-based "hardware" watchpoints.
1704 HP-UX has unfortunate interactions between page-protections and
1705 some system calls. Our solution is to disable hardware watches
1706 when a system call is entered, and reenable them when the syscall
1707 completes. The downside of this is that we may miss the precise
1708 point at which a watched piece of memory is modified. "Oh well."
1710 Note that we may have multiple threads running, which may each
1711 enter syscalls at roughly the same time. Since we don't have a
1712 good notion currently of whether a watched piece of memory is
1713 thread-private, we'd best not have any page-protections active
1714 when any thread is in a syscall. Thus, we only want to reenable
1715 hardware watches when no threads are in a syscall.
1717 Also, be careful not to try to gather much state about a thread
1718 that's in a syscall. It's frequently a losing proposition. */
1719 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1720 number_of_threads_in_syscalls
++;
1721 if (number_of_threads_in_syscalls
== 1)
1723 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid
);
1725 resume (0, TARGET_SIGNAL_0
);
1726 prepare_to_wait (ecs
);
1729 /* Before examining the threads further, step this thread to
1730 get it entirely out of the syscall. (We get notice of the
1731 event when the thread is just on the verge of exiting a
1732 syscall. Stepping one instruction seems to get it back
1735 Note that although the logical place to reenable h/w watches
1736 is here, we cannot. We cannot reenable them before stepping
1737 the thread (this causes the next wait on the thread to hang).
1739 Nor can we enable them after stepping until we've done a wait.
1740 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
1741 here, which will be serviced immediately after the target
1743 case TARGET_WAITKIND_SYSCALL_RETURN
:
1744 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1746 if (number_of_threads_in_syscalls
> 0)
1748 number_of_threads_in_syscalls
--;
1749 ecs
->enable_hw_watchpoints_after_wait
=
1750 (number_of_threads_in_syscalls
== 0);
1752 prepare_to_wait (ecs
);
1755 case TARGET_WAITKIND_STOPPED
:
1756 stop_signal
= ecs
->ws
.value
.sig
;
1760 /* We may want to consider not doing a resume here in order to give
1761 the user a chance to play with the new thread. It might be good
1762 to make that a user-settable option. */
1764 /* At this point, all threads are stopped (happens automatically in
1765 either the OS or the native code). Therefore we need to continue
1766 all threads in order to make progress. */
1767 if (ecs
->new_thread_event
)
1769 target_resume (-1, 0, TARGET_SIGNAL_0
);
1770 prepare_to_wait (ecs
);
1774 stop_pc
= read_pc_pid (ecs
->pid
);
1776 /* See if a thread hit a thread-specific breakpoint that was meant for
1777 another thread. If so, then step that thread past the breakpoint,
1780 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1782 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1783 ecs
->random_signal
= 0;
1784 else if (breakpoints_inserted
1785 && breakpoint_here_p (stop_pc
- DECR_PC_AFTER_BREAK
))
1787 ecs
->random_signal
= 0;
1788 if (!breakpoint_thread_match (stop_pc
- DECR_PC_AFTER_BREAK
,
1793 /* Saw a breakpoint, but it was hit by the wrong thread.
1795 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
, ecs
->pid
);
1797 remove_status
= remove_breakpoints ();
1798 /* Did we fail to remove breakpoints? If so, try
1799 to set the PC past the bp. (There's at least
1800 one situation in which we can fail to remove
1801 the bp's: On HP-UX's that use ttrace, we can't
1802 change the address space of a vforking child
1803 process until the child exits (well, okay, not
1804 then either :-) or execs. */
1805 if (remove_status
!= 0)
1807 write_pc_pid (stop_pc
- DECR_PC_AFTER_BREAK
+ 4, ecs
->pid
);
1811 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1812 /* FIXME: What if a signal arrives instead of the
1813 single-step happening? */
1815 ecs
->waiton_pid
= ecs
->pid
;
1816 ecs
->wp
= &(ecs
->ws
);
1817 ecs
->infwait_state
= infwait_thread_hop_state
;
1818 prepare_to_wait (ecs
);
1822 /* We need to restart all the threads now,
1823 * unles we're running in scheduler-locked mode.
1824 * FIXME: shouldn't we look at currently_stepping ()?
1826 if (scheduler_mode
== schedlock_on
)
1827 target_resume (ecs
->pid
, 0, TARGET_SIGNAL_0
);
1829 target_resume (-1, 0, TARGET_SIGNAL_0
);
1830 prepare_to_wait (ecs
);
1835 /* This breakpoint matches--either it is the right
1836 thread or it's a generic breakpoint for all threads.
1837 Remember that we'll need to step just _this_ thread
1838 on any following user continuation! */
1839 thread_step_needed
= 1;
1844 ecs
->random_signal
= 1;
1846 /* See if something interesting happened to the non-current thread. If
1847 so, then switch to that thread, and eventually give control back to
1850 Note that if there's any kind of pending follow (i.e., of a fork,
1851 vfork or exec), we don't want to do this now. Rather, we'll let
1852 the next resume handle it. */
1853 if ((ecs
->pid
!= inferior_pid
) &&
1854 (pending_follow
.kind
== TARGET_WAITKIND_SPURIOUS
))
1858 /* If it's a random signal for a non-current thread, notify user
1859 if he's expressed an interest. */
1860 if (ecs
->random_signal
1861 && signal_print
[stop_signal
])
1863 /* ??rehrauer: I don't understand the rationale for this code. If the
1864 inferior will stop as a result of this signal, then the act of handling
1865 the stop ought to print a message that's couches the stoppage in user
1866 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1867 won't stop as a result of the signal -- i.e., if the signal is merely
1868 a side-effect of something GDB's doing "under the covers" for the
1869 user, such as stepping threads over a breakpoint they shouldn't stop
1870 for -- then the message seems to be a serious annoyance at best.
1872 For now, remove the message altogether. */
1875 target_terminal_ours_for_output ();
1876 printf_filtered ("\nProgram received signal %s, %s.\n",
1877 target_signal_to_name (stop_signal
),
1878 target_signal_to_string (stop_signal
));
1879 gdb_flush (gdb_stdout
);
1883 /* If it's not SIGTRAP and not a signal we want to stop for, then
1884 continue the thread. */
1886 if (stop_signal
!= TARGET_SIGNAL_TRAP
1887 && !signal_stop
[stop_signal
])
1890 target_terminal_inferior ();
1892 /* Clear the signal if it should not be passed. */
1893 if (signal_program
[stop_signal
] == 0)
1894 stop_signal
= TARGET_SIGNAL_0
;
1896 target_resume (ecs
->pid
, 0, stop_signal
);
1897 prepare_to_wait (ecs
);
1901 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1902 and fall into the rest of wait_for_inferior(). */
1904 /* Caution: it may happen that the new thread (or the old one!)
1905 is not in the thread list. In this case we must not attempt
1906 to "switch context", or we run the risk that our context may
1907 be lost. This may happen as a result of the target module
1908 mishandling thread creation. */
1910 if (in_thread_list (inferior_pid
) && in_thread_list (ecs
->pid
))
1911 { /* Perform infrun state context switch: */
1912 /* Save infrun state for the old thread. */
1913 save_infrun_state (inferior_pid
, prev_pc
,
1914 prev_func_start
, prev_func_name
,
1915 trap_expected
, step_resume_breakpoint
,
1916 through_sigtramp_breakpoint
,
1917 step_range_start
, step_range_end
,
1918 step_frame_address
, ecs
->handling_longjmp
,
1920 ecs
->stepping_through_solib_after_catch
,
1921 ecs
->stepping_through_solib_catchpoints
,
1922 ecs
->stepping_through_sigtramp
);
1924 /* Load infrun state for the new thread. */
1925 load_infrun_state (ecs
->pid
, &prev_pc
,
1926 &prev_func_start
, &prev_func_name
,
1927 &trap_expected
, &step_resume_breakpoint
,
1928 &through_sigtramp_breakpoint
,
1929 &step_range_start
, &step_range_end
,
1930 &step_frame_address
, &ecs
->handling_longjmp
,
1932 &ecs
->stepping_through_solib_after_catch
,
1933 &ecs
->stepping_through_solib_catchpoints
,
1934 &ecs
->stepping_through_sigtramp
);
1936 if (may_switch_from_inferior_pid
)
1937 switched_from_inferior_pid
= inferior_pid
;
1939 inferior_pid
= ecs
->pid
;
1942 context_hook (pid_to_thread_id (ecs
->pid
));
1944 printf_filtered ("[Switching to %s]\n", target_pid_to_str (ecs
->pid
));
1945 flush_cached_frames ();
1948 if (SOFTWARE_SINGLE_STEP_P
&& singlestep_breakpoints_inserted_p
)
1950 /* Pull the single step breakpoints out of the target. */
1951 SOFTWARE_SINGLE_STEP (0, 0);
1952 singlestep_breakpoints_inserted_p
= 0;
1955 /* If PC is pointing at a nullified instruction, then step beyond
1956 it so that the user won't be confused when GDB appears to be ready
1959 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1960 if (INSTRUCTION_NULLIFIED
)
1962 registers_changed ();
1963 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
);
1965 /* We may have received a signal that we want to pass to
1966 the inferior; therefore, we must not clobber the waitstatus
1969 ecs
->infwait_state
= infwait_nullified_state
;
1970 ecs
->waiton_pid
= ecs
->pid
;
1971 ecs
->wp
= &(ecs
->tmpstatus
);
1972 prepare_to_wait (ecs
);
1976 /* It may not be necessary to disable the watchpoint to stop over
1977 it. For example, the PA can (with some kernel cooperation)
1978 single step over a watchpoint without disabling the watchpoint. */
1979 if (HAVE_STEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1982 prepare_to_wait (ecs
);
1986 /* It is far more common to need to disable a watchpoint to step
1987 the inferior over it. FIXME. What else might a debug
1988 register or page protection watchpoint scheme need here? */
1989 if (HAVE_NONSTEPPABLE_WATCHPOINT
&& STOPPED_BY_WATCHPOINT (ecs
->ws
))
1991 /* At this point, we are stopped at an instruction which has
1992 attempted to write to a piece of memory under control of
1993 a watchpoint. The instruction hasn't actually executed
1994 yet. If we were to evaluate the watchpoint expression
1995 now, we would get the old value, and therefore no change
1996 would seem to have occurred.
1998 In order to make watchpoints work `right', we really need
1999 to complete the memory write, and then evaluate the
2000 watchpoint expression. The following code does that by
2001 removing the watchpoint (actually, all watchpoints and
2002 breakpoints), single-stepping the target, re-inserting
2003 watchpoints, and then falling through to let normal
2004 single-step processing handle proceed. Since this
2005 includes evaluating watchpoints, things will come to a
2006 stop in the correct manner. */
2008 write_pc (stop_pc
- DECR_PC_AFTER_BREAK
);
2010 remove_breakpoints ();
2011 registers_changed ();
2012 target_resume (ecs
->pid
, 1, TARGET_SIGNAL_0
); /* Single step */
2014 ecs
->waiton_pid
= ecs
->pid
;
2015 ecs
->wp
= &(ecs
->ws
);
2016 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2017 prepare_to_wait (ecs
);
2021 /* It may be possible to simply continue after a watchpoint. */
2022 if (HAVE_CONTINUABLE_WATCHPOINT
)
2023 STOPPED_BY_WATCHPOINT (ecs
->ws
);
2025 ecs
->stop_func_start
= 0;
2026 ecs
->stop_func_end
= 0;
2027 ecs
->stop_func_name
= 0;
2028 /* Don't care about return value; stop_func_start and stop_func_name
2029 will both be 0 if it doesn't work. */
2030 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2031 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2032 ecs
->stop_func_start
+= FUNCTION_START_OFFSET
;
2033 ecs
->another_trap
= 0;
2034 bpstat_clear (&stop_bpstat
);
2036 stop_stack_dummy
= 0;
2037 stop_print_frame
= 1;
2038 ecs
->random_signal
= 0;
2039 stopped_by_random_signal
= 0;
2040 breakpoints_failed
= 0;
2042 /* Look at the cause of the stop, and decide what to do.
2043 The alternatives are:
2044 1) break; to really stop and return to the debugger,
2045 2) drop through to start up again
2046 (set ecs->another_trap to 1 to single step once)
2047 3) set ecs->random_signal to 1, and the decision between 1 and 2
2048 will be made according to the signal handling tables. */
2050 /* First, distinguish signals caused by the debugger from signals
2051 that have to do with the program's own actions.
2052 Note that breakpoint insns may cause SIGTRAP or SIGILL
2053 or SIGEMT, depending on the operating system version.
2054 Here we detect when a SIGILL or SIGEMT is really a breakpoint
2055 and change it to SIGTRAP. */
2057 if (stop_signal
== TARGET_SIGNAL_TRAP
2058 || (breakpoints_inserted
&&
2059 (stop_signal
== TARGET_SIGNAL_ILL
2060 || stop_signal
== TARGET_SIGNAL_EMT
2062 || stop_soon_quietly
)
2064 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2066 stop_print_frame
= 0;
2067 stop_stepping (ecs
);
2070 if (stop_soon_quietly
)
2072 stop_stepping (ecs
);
2076 /* Don't even think about breakpoints
2077 if just proceeded over a breakpoint.
2079 However, if we are trying to proceed over a breakpoint
2080 and end up in sigtramp, then through_sigtramp_breakpoint
2081 will be set and we should check whether we've hit the
2083 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
2084 && through_sigtramp_breakpoint
== NULL
)
2085 bpstat_clear (&stop_bpstat
);
2088 /* See if there is a breakpoint at the current PC. */
2089 stop_bpstat
= bpstat_stop_status
2091 /* Pass TRUE if our reason for stopping is something other
2092 than hitting a breakpoint. We do this by checking that
2093 1) stepping is going on and 2) we didn't hit a breakpoint
2094 in a signal handler without an intervening stop in
2095 sigtramp, which is detected by a new stack pointer value
2096 below any usual function calling stack adjustments. */
2097 (currently_stepping (ecs
)
2099 && INNER_THAN (read_sp (), (step_sp
- 16))))
2101 /* Following in case break condition called a
2103 stop_print_frame
= 1;
2106 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2108 = !(bpstat_explains_signal (stop_bpstat
)
2110 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2111 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2112 FRAME_FP (get_current_frame ())))
2113 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2118 = !(bpstat_explains_signal (stop_bpstat
)
2119 /* End of a stack dummy. Some systems (e.g. Sony
2120 news) give another signal besides SIGTRAP, so
2121 check here as well as above. */
2122 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2123 && PC_IN_CALL_DUMMY (stop_pc
, read_sp (),
2124 FRAME_FP (get_current_frame ())))
2126 if (!ecs
->random_signal
)
2127 stop_signal
= TARGET_SIGNAL_TRAP
;
2131 /* When we reach this point, we've pretty much decided
2132 that the reason for stopping must've been a random
2133 (unexpected) signal. */
2136 ecs
->random_signal
= 1;
2137 /* If a fork, vfork or exec event was seen, then there are two
2138 possible responses we can make:
2140 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2141 then we must stop now and issue a prompt. We will resume
2142 the inferior when the user tells us to.
2143 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2144 then we must resume the inferior now and keep checking.
2146 In either case, we must take appropriate steps to "follow" the
2147 the fork/vfork/exec when the inferior is resumed. For example,
2148 if follow-fork-mode is "child", then we must detach from the
2149 parent inferior and follow the new child inferior.
2151 In either case, setting pending_follow causes the next resume()
2152 to take the appropriate following action. */
2153 process_event_stop_test
:
2154 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
2156 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2159 stop_signal
= TARGET_SIGNAL_0
;
2164 else if (ecs
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
2166 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2168 stop_signal
= TARGET_SIGNAL_0
;
2173 else if (ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2175 pending_follow
.kind
= ecs
->ws
.kind
;
2176 if (ecs
->random_signal
) /* I.e., no catchpoint triggered for this. */
2179 stop_signal
= TARGET_SIGNAL_0
;
2185 /* For the program's own signals, act according to
2186 the signal handling tables. */
2188 if (ecs
->random_signal
)
2190 /* Signal not for debugging purposes. */
2193 stopped_by_random_signal
= 1;
2195 if (signal_print
[stop_signal
])
2198 target_terminal_ours_for_output ();
2199 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2201 if (signal_stop
[stop_signal
])
2203 stop_stepping (ecs
);
2206 /* If not going to stop, give terminal back
2207 if we took it away. */
2209 target_terminal_inferior ();
2211 /* Clear the signal if it should not be passed. */
2212 if (signal_program
[stop_signal
] == 0)
2213 stop_signal
= TARGET_SIGNAL_0
;
2215 /* I'm not sure whether this needs to be check_sigtramp2 or
2216 whether it could/should be keep_going.
2218 This used to jump to step_over_function if we are stepping,
2221 Suppose the user does a `next' over a function call, and while
2222 that call is in progress, the inferior receives a signal for
2223 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2224 that case, when we reach this point, there is already a
2225 step-resume breakpoint established, right where it should be:
2226 immediately after the function call the user is "next"-ing
2227 over. If we call step_over_function now, two bad things
2230 - we'll create a new breakpoint, at wherever the current
2231 frame's return address happens to be. That could be
2232 anywhere, depending on what function call happens to be on
2233 the top of the stack at that point. Point is, it's probably
2234 not where we need it.
2236 - the existing step-resume breakpoint (which is at the correct
2237 address) will get orphaned: step_resume_breakpoint will point
2238 to the new breakpoint, and the old step-resume breakpoint
2239 will never be cleaned up.
2241 The old behavior was meant to help HP-UX single-step out of
2242 sigtramps. It would place the new breakpoint at prev_pc, which
2243 was certainly wrong. I don't know the details there, so fixing
2244 this probably breaks that. As with anything else, it's up to
2245 the HP-UX maintainer to furnish a fix that doesn't break other
2246 platforms. --JimB, 20 May 1999 */
2247 check_sigtramp2 (ecs
);
2250 /* Handle cases caused by hitting a breakpoint. */
2252 CORE_ADDR jmp_buf_pc
;
2253 struct bpstat_what what
;
2255 what
= bpstat_what (stop_bpstat
);
2257 if (what
.call_dummy
)
2259 stop_stack_dummy
= 1;
2261 trap_expected_after_continue
= 1;
2265 switch (what
.main_action
)
2267 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2268 /* If we hit the breakpoint at longjmp, disable it for the
2269 duration of this command. Then, install a temporary
2270 breakpoint at the target of the jmp_buf. */
2271 disable_longjmp_breakpoint ();
2272 remove_breakpoints ();
2273 breakpoints_inserted
= 0;
2274 if (!GET_LONGJMP_TARGET (&jmp_buf_pc
))
2280 /* Need to blow away step-resume breakpoint, as it
2281 interferes with us */
2282 if (step_resume_breakpoint
!= NULL
)
2284 delete_breakpoint (step_resume_breakpoint
);
2285 step_resume_breakpoint
= NULL
;
2287 /* Not sure whether we need to blow this away too, but probably
2288 it is like the step-resume breakpoint. */
2289 if (through_sigtramp_breakpoint
!= NULL
)
2291 delete_breakpoint (through_sigtramp_breakpoint
);
2292 through_sigtramp_breakpoint
= NULL
;
2296 /* FIXME - Need to implement nested temporary breakpoints */
2297 if (step_over_calls
> 0)
2298 set_longjmp_resume_breakpoint (jmp_buf_pc
,
2299 get_current_frame ());
2302 set_longjmp_resume_breakpoint (jmp_buf_pc
, NULL
);
2303 ecs
->handling_longjmp
= 1; /* FIXME */
2307 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2308 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2309 remove_breakpoints ();
2310 breakpoints_inserted
= 0;
2312 /* FIXME - Need to implement nested temporary breakpoints */
2314 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2315 step_frame_address
)))
2317 ecs
->another_trap
= 1;
2322 disable_longjmp_breakpoint ();
2323 ecs
->handling_longjmp
= 0; /* FIXME */
2324 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2326 /* else fallthrough */
2328 case BPSTAT_WHAT_SINGLE
:
2329 if (breakpoints_inserted
)
2331 thread_step_needed
= 1;
2332 remove_breakpoints ();
2334 breakpoints_inserted
= 0;
2335 ecs
->another_trap
= 1;
2336 /* Still need to check other stuff, at least the case
2337 where we are stepping and step out of the right range. */
2340 case BPSTAT_WHAT_STOP_NOISY
:
2341 stop_print_frame
= 1;
2343 /* We are about to nuke the step_resume_breakpoint and
2344 through_sigtramp_breakpoint via the cleanup chain, so
2345 no need to worry about it here. */
2347 stop_stepping (ecs
);
2350 case BPSTAT_WHAT_STOP_SILENT
:
2351 stop_print_frame
= 0;
2353 /* We are about to nuke the step_resume_breakpoint and
2354 through_sigtramp_breakpoint via the cleanup chain, so
2355 no need to worry about it here. */
2357 stop_stepping (ecs
);
2360 case BPSTAT_WHAT_STEP_RESUME
:
2361 /* This proably demands a more elegant solution, but, yeah
2364 This function's use of the simple variable
2365 step_resume_breakpoint doesn't seem to accomodate
2366 simultaneously active step-resume bp's, although the
2367 breakpoint list certainly can.
2369 If we reach here and step_resume_breakpoint is already
2370 NULL, then apparently we have multiple active
2371 step-resume bp's. We'll just delete the breakpoint we
2372 stopped at, and carry on.
2374 Correction: what the code currently does is delete a
2375 step-resume bp, but it makes no effort to ensure that
2376 the one deleted is the one currently stopped at. MVS */
2378 if (step_resume_breakpoint
== NULL
)
2380 step_resume_breakpoint
=
2381 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2383 delete_breakpoint (step_resume_breakpoint
);
2384 step_resume_breakpoint
= NULL
;
2387 case BPSTAT_WHAT_THROUGH_SIGTRAMP
:
2388 if (through_sigtramp_breakpoint
)
2389 delete_breakpoint (through_sigtramp_breakpoint
);
2390 through_sigtramp_breakpoint
= NULL
;
2392 /* If were waiting for a trap, hitting the step_resume_break
2393 doesn't count as getting it. */
2395 ecs
->another_trap
= 1;
2398 case BPSTAT_WHAT_CHECK_SHLIBS
:
2399 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2402 /* Remove breakpoints, we eventually want to step over the
2403 shlib event breakpoint, and SOLIB_ADD might adjust
2404 breakpoint addresses via breakpoint_re_set. */
2405 if (breakpoints_inserted
)
2406 remove_breakpoints ();
2407 breakpoints_inserted
= 0;
2409 /* Check for any newly added shared libraries if we're
2410 supposed to be adding them automatically. */
2413 /* Switch terminal for any messages produced by
2414 breakpoint_re_set. */
2415 target_terminal_ours_for_output ();
2416 SOLIB_ADD (NULL
, 0, NULL
);
2417 target_terminal_inferior ();
2420 /* Try to reenable shared library breakpoints, additional
2421 code segments in shared libraries might be mapped in now. */
2422 re_enable_breakpoints_in_shlibs ();
2424 /* If requested, stop when the dynamic linker notifies
2425 gdb of events. This allows the user to get control
2426 and place breakpoints in initializer routines for
2427 dynamically loaded objects (among other things). */
2428 if (stop_on_solib_events
)
2430 stop_stepping (ecs
);
2434 /* If we stopped due to an explicit catchpoint, then the
2435 (see above) call to SOLIB_ADD pulled in any symbols
2436 from a newly-loaded library, if appropriate.
2438 We do want the inferior to stop, but not where it is
2439 now, which is in the dynamic linker callback. Rather,
2440 we would like it stop in the user's program, just after
2441 the call that caused this catchpoint to trigger. That
2442 gives the user a more useful vantage from which to
2443 examine their program's state. */
2444 else if (what
.main_action
== BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2446 /* ??rehrauer: If I could figure out how to get the
2447 right return PC from here, we could just set a temp
2448 breakpoint and resume. I'm not sure we can without
2449 cracking open the dld's shared libraries and sniffing
2450 their unwind tables and text/data ranges, and that's
2451 not a terribly portable notion.
2453 Until that time, we must step the inferior out of the
2454 dld callback, and also out of the dld itself (and any
2455 code or stubs in libdld.sl, such as "shl_load" and
2456 friends) until we reach non-dld code. At that point,
2457 we can stop stepping. */
2458 bpstat_get_triggered_catchpoints (stop_bpstat
,
2459 &ecs
->stepping_through_solib_catchpoints
);
2460 ecs
->stepping_through_solib_after_catch
= 1;
2462 /* Be sure to lift all breakpoints, so the inferior does
2463 actually step past this point... */
2464 ecs
->another_trap
= 1;
2469 /* We want to step over this breakpoint, then keep going. */
2470 ecs
->another_trap
= 1;
2477 case BPSTAT_WHAT_LAST
:
2478 /* Not a real code, but listed here to shut up gcc -Wall. */
2480 case BPSTAT_WHAT_KEEP_CHECKING
:
2485 /* We come here if we hit a breakpoint but should not
2486 stop for it. Possibly we also were stepping
2487 and should stop for that. So fall through and
2488 test for stepping. But, if not stepping,
2491 /* Are we stepping to get the inferior out of the dynamic
2492 linker's hook (and possibly the dld itself) after catching
2494 if (ecs
->stepping_through_solib_after_catch
)
2496 #if defined(SOLIB_ADD)
2497 /* Have we reached our destination? If not, keep going. */
2498 if (SOLIB_IN_DYNAMIC_LINKER (ecs
->pid
, stop_pc
))
2500 ecs
->another_trap
= 1;
2505 /* Else, stop and report the catchpoint(s) whose triggering
2506 caused us to begin stepping. */
2507 ecs
->stepping_through_solib_after_catch
= 0;
2508 bpstat_clear (&stop_bpstat
);
2509 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2510 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2511 stop_print_frame
= 1;
2512 stop_stepping (ecs
);
2516 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P
)
2518 /* This is the old way of detecting the end of the stack dummy.
2519 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2520 handled above. As soon as we can test it on all of them, all
2521 architectures should define it. */
2523 /* If this is the breakpoint at the end of a stack dummy,
2524 just stop silently, unless the user was doing an si/ni, in which
2525 case she'd better know what she's doing. */
2527 if (CALL_DUMMY_HAS_COMPLETED (stop_pc
, read_sp (),
2528 FRAME_FP (get_current_frame ()))
2531 stop_print_frame
= 0;
2532 stop_stack_dummy
= 1;
2534 trap_expected_after_continue
= 1;
2536 stop_stepping (ecs
);
2541 if (step_resume_breakpoint
)
2543 /* Having a step-resume breakpoint overrides anything
2544 else having to do with stepping commands until
2545 that breakpoint is reached. */
2546 /* I'm not sure whether this needs to be check_sigtramp2 or
2547 whether it could/should be keep_going. */
2548 check_sigtramp2 (ecs
);
2553 if (step_range_end
== 0)
2555 /* Likewise if we aren't even stepping. */
2556 /* I'm not sure whether this needs to be check_sigtramp2 or
2557 whether it could/should be keep_going. */
2558 check_sigtramp2 (ecs
);
2563 /* If stepping through a line, keep going if still within it.
2565 Note that step_range_end is the address of the first instruction
2566 beyond the step range, and NOT the address of the last instruction
2568 if (stop_pc
>= step_range_start
2569 && stop_pc
< step_range_end
)
2571 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2572 So definately need to check for sigtramp here. */
2573 check_sigtramp2 (ecs
);
2578 /* We stepped out of the stepping range. */
2580 /* If we are stepping at the source level and entered the runtime
2581 loader dynamic symbol resolution code, we keep on single stepping
2582 until we exit the run time loader code and reach the callee's
2584 if (step_over_calls
< 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
))
2586 CORE_ADDR pc_after_resolver
= SKIP_SOLIB_RESOLVER (stop_pc
);
2588 if (pc_after_resolver
)
2590 /* Set up a step-resume breakpoint at the address
2591 indicated by SKIP_SOLIB_RESOLVER. */
2592 struct symtab_and_line sr_sal
;
2594 sr_sal
.pc
= pc_after_resolver
;
2596 check_for_old_step_resume_breakpoint ();
2597 step_resume_breakpoint
=
2598 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2599 if (breakpoints_inserted
)
2600 insert_breakpoints ();
2607 /* We can't update step_sp every time through the loop, because
2608 reading the stack pointer would slow down stepping too much.
2609 But we can update it every time we leave the step range. */
2610 ecs
->update_step_sp
= 1;
2612 /* Did we just take a signal? */
2613 if (IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2614 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2615 && INNER_THAN (read_sp (), step_sp
))
2617 /* We've just taken a signal; go until we are back to
2618 the point where we took it and one more. */
2620 /* Note: The test above succeeds not only when we stepped
2621 into a signal handler, but also when we step past the last
2622 statement of a signal handler and end up in the return stub
2623 of the signal handler trampoline. To distinguish between
2624 these two cases, check that the frame is INNER_THAN the
2625 previous one below. pai/1997-09-11 */
2629 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2631 if (INNER_THAN (current_frame
, step_frame_address
))
2633 /* We have just taken a signal; go until we are back to
2634 the point where we took it and one more. */
2636 /* This code is needed at least in the following case:
2637 The user types "next" and then a signal arrives (before
2638 the "next" is done). */
2640 /* Note that if we are stopped at a breakpoint, then we need
2641 the step_resume breakpoint to override any breakpoints at
2642 the same location, so that we will still step over the
2643 breakpoint even though the signal happened. */
2644 struct symtab_and_line sr_sal
;
2647 sr_sal
.symtab
= NULL
;
2649 sr_sal
.pc
= prev_pc
;
2650 /* We could probably be setting the frame to
2651 step_frame_address; I don't think anyone thought to
2653 check_for_old_step_resume_breakpoint ();
2654 step_resume_breakpoint
=
2655 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2656 if (breakpoints_inserted
)
2657 insert_breakpoints ();
2661 /* We just stepped out of a signal handler and into
2662 its calling trampoline.
2664 Normally, we'd call step_over_function from
2665 here, but for some reason GDB can't unwind the
2666 stack correctly to find the real PC for the point
2667 user code where the signal trampoline will return
2668 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2669 But signal trampolines are pretty small stubs of
2670 code, anyway, so it's OK instead to just
2671 single-step out. Note: assuming such trampolines
2672 don't exhibit recursion on any platform... */
2673 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2674 &ecs
->stop_func_start
,
2675 &ecs
->stop_func_end
);
2676 /* Readjust stepping range */
2677 step_range_start
= ecs
->stop_func_start
;
2678 step_range_end
= ecs
->stop_func_end
;
2679 ecs
->stepping_through_sigtramp
= 1;
2684 /* If this is stepi or nexti, make sure that the stepping range
2685 gets us past that instruction. */
2686 if (step_range_end
== 1)
2687 /* FIXME: Does this run afoul of the code below which, if
2688 we step into the middle of a line, resets the stepping
2690 step_range_end
= (step_range_start
= prev_pc
) + 1;
2692 ecs
->remove_breakpoints_on_following_step
= 1;
2697 if (stop_pc
== ecs
->stop_func_start
/* Quick test */
2698 || (in_prologue (stop_pc
, ecs
->stop_func_start
) &&
2699 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2700 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
)
2701 || ecs
->stop_func_name
== 0)
2703 /* It's a subroutine call. */
2705 if (step_over_calls
== 0)
2707 /* I presume that step_over_calls is only 0 when we're
2708 supposed to be stepping at the assembly language level
2709 ("stepi"). Just stop. */
2711 print_stop_reason (END_STEPPING_RANGE
, 0);
2712 stop_stepping (ecs
);
2716 if (step_over_calls
> 0 || IGNORE_HELPER_CALL (stop_pc
))
2718 /* We're doing a "next". */
2719 step_over_function (ecs
);
2724 /* If we are in a function call trampoline (a stub between
2725 the calling routine and the real function), locate the real
2726 function. That's what tells us (a) whether we want to step
2727 into it at all, and (b) what prologue we want to run to
2728 the end of, if we do step into it. */
2729 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2731 ecs
->stop_func_start
= tmp
;
2734 tmp
= DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc
);
2737 struct symtab_and_line xxx
;
2738 /* Why isn't this s_a_l called "sr_sal", like all of the
2739 other s_a_l's where this code is duplicated? */
2740 INIT_SAL (&xxx
); /* initialize to zeroes */
2742 xxx
.section
= find_pc_overlay (xxx
.pc
);
2743 check_for_old_step_resume_breakpoint ();
2744 step_resume_breakpoint
=
2745 set_momentary_breakpoint (xxx
, NULL
, bp_step_resume
);
2746 insert_breakpoints ();
2752 /* If we have line number information for the function we
2753 are thinking of stepping into, step into it.
2755 If there are several symtabs at that PC (e.g. with include
2756 files), just want to know whether *any* of them have line
2757 numbers. find_pc_line handles this. */
2759 struct symtab_and_line tmp_sal
;
2761 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2762 if (tmp_sal
.line
!= 0)
2764 step_into_function (ecs
);
2768 step_over_function (ecs
);
2774 /* We've wandered out of the step range. */
2776 ecs
->sal
= find_pc_line (stop_pc
, 0);
2778 if (step_range_end
== 1)
2780 /* It is stepi or nexti. We always want to stop stepping after
2783 print_stop_reason (END_STEPPING_RANGE
, 0);
2784 stop_stepping (ecs
);
2788 /* If we're in the return path from a shared library trampoline,
2789 we want to proceed through the trampoline when stepping. */
2790 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc
, ecs
->stop_func_name
))
2794 /* Determine where this trampoline returns. */
2795 tmp
= SKIP_TRAMPOLINE_CODE (stop_pc
);
2797 /* Only proceed through if we know where it's going. */
2800 /* And put the step-breakpoint there and go until there. */
2801 struct symtab_and_line sr_sal
;
2803 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2805 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2806 /* Do not specify what the fp should be when we stop
2807 since on some machines the prologue
2808 is where the new fp value is established. */
2809 check_for_old_step_resume_breakpoint ();
2810 step_resume_breakpoint
=
2811 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2812 if (breakpoints_inserted
)
2813 insert_breakpoints ();
2815 /* Restart without fiddling with the step ranges or
2822 if (ecs
->sal
.line
== 0)
2824 /* We have no line number information. That means to stop
2825 stepping (does this always happen right after one instruction,
2826 when we do "s" in a function with no line numbers,
2827 or can this happen as a result of a return or longjmp?). */
2829 print_stop_reason (END_STEPPING_RANGE
, 0);
2830 stop_stepping (ecs
);
2834 if ((stop_pc
== ecs
->sal
.pc
)
2835 && (ecs
->current_line
!= ecs
->sal
.line
|| ecs
->current_symtab
!= ecs
->sal
.symtab
))
2837 /* We are at the start of a different line. So stop. Note that
2838 we don't stop if we step into the middle of a different line.
2839 That is said to make things like for (;;) statements work
2842 print_stop_reason (END_STEPPING_RANGE
, 0);
2843 stop_stepping (ecs
);
2847 /* We aren't done stepping.
2849 Optimize by setting the stepping range to the line.
2850 (We might not be in the original line, but if we entered a
2851 new line in mid-statement, we continue stepping. This makes
2852 things like for(;;) statements work better.) */
2854 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2856 /* If this is the last line of the function, don't keep stepping
2857 (it would probably step us out of the function).
2858 This is particularly necessary for a one-line function,
2859 in which after skipping the prologue we better stop even though
2860 we will be in mid-line. */
2862 print_stop_reason (END_STEPPING_RANGE
, 0);
2863 stop_stepping (ecs
);
2866 step_range_start
= ecs
->sal
.pc
;
2867 step_range_end
= ecs
->sal
.end
;
2868 step_frame_address
= FRAME_FP (get_current_frame ());
2869 ecs
->current_line
= ecs
->sal
.line
;
2870 ecs
->current_symtab
= ecs
->sal
.symtab
;
2872 /* In the case where we just stepped out of a function into the middle
2873 of a line of the caller, continue stepping, but step_frame_address
2874 must be modified to current frame */
2876 CORE_ADDR current_frame
= FRAME_FP (get_current_frame ());
2877 if (!(INNER_THAN (current_frame
, step_frame_address
)))
2878 step_frame_address
= current_frame
;
2883 } /* extra brace, to preserve old indentation */
2886 /* Are we in the middle of stepping? */
2889 currently_stepping (struct execution_control_state
*ecs
)
2891 return ((through_sigtramp_breakpoint
== NULL
2892 && !ecs
->handling_longjmp
2893 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2895 || ecs
->stepping_through_solib_after_catch
2896 || bpstat_should_step ());
2900 check_sigtramp2 (struct execution_control_state
*ecs
)
2903 && IN_SIGTRAMP (stop_pc
, ecs
->stop_func_name
)
2904 && !IN_SIGTRAMP (prev_pc
, prev_func_name
)
2905 && INNER_THAN (read_sp (), step_sp
))
2907 /* What has happened here is that we have just stepped the
2908 inferior with a signal (because it is a signal which
2909 shouldn't make us stop), thus stepping into sigtramp.
2911 So we need to set a step_resume_break_address breakpoint and
2912 continue until we hit it, and then step. FIXME: This should
2913 be more enduring than a step_resume breakpoint; we should
2914 know that we will later need to keep going rather than
2915 re-hitting the breakpoint here (see the testsuite,
2916 gdb.base/signals.exp where it says "exceedingly difficult"). */
2918 struct symtab_and_line sr_sal
;
2920 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2921 sr_sal
.pc
= prev_pc
;
2922 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2923 /* We perhaps could set the frame if we kept track of what the
2924 frame corresponding to prev_pc was. But we don't, so don't. */
2925 through_sigtramp_breakpoint
=
2926 set_momentary_breakpoint (sr_sal
, NULL
, bp_through_sigtramp
);
2927 if (breakpoints_inserted
)
2928 insert_breakpoints ();
2930 ecs
->remove_breakpoints_on_following_step
= 1;
2931 ecs
->another_trap
= 1;
2935 /* Subroutine call with source code we should not step over. Do step
2936 to the first line of code in it. */
2939 step_into_function (struct execution_control_state
*ecs
)
2942 struct symtab_and_line sr_sal
;
2944 s
= find_pc_symtab (stop_pc
);
2945 if (s
&& s
->language
!= language_asm
)
2946 ecs
->stop_func_start
= SKIP_PROLOGUE (ecs
->stop_func_start
);
2948 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2949 /* Use the step_resume_break to step until the end of the prologue,
2950 even if that involves jumps (as it seems to on the vax under
2952 /* If the prologue ends in the middle of a source line, continue to
2953 the end of that source line (if it is still within the function).
2954 Otherwise, just go to end of prologue. */
2955 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2956 /* no, don't either. It skips any code that's legitimately on the
2960 && ecs
->sal
.pc
!= ecs
->stop_func_start
2961 && ecs
->sal
.end
< ecs
->stop_func_end
)
2962 ecs
->stop_func_start
= ecs
->sal
.end
;
2965 if (ecs
->stop_func_start
== stop_pc
)
2967 /* We are already there: stop now. */
2969 print_stop_reason (END_STEPPING_RANGE
, 0);
2970 stop_stepping (ecs
);
2975 /* Put the step-breakpoint there and go until there. */
2976 INIT_SAL (&sr_sal
); /* initialize to zeroes */
2977 sr_sal
.pc
= ecs
->stop_func_start
;
2978 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
2979 /* Do not specify what the fp should be when we stop since on
2980 some machines the prologue is where the new fp value is
2982 check_for_old_step_resume_breakpoint ();
2983 step_resume_breakpoint
=
2984 set_momentary_breakpoint (sr_sal
, NULL
, bp_step_resume
);
2985 if (breakpoints_inserted
)
2986 insert_breakpoints ();
2988 /* And make sure stepping stops right away then. */
2989 step_range_end
= step_range_start
;
2994 /* We've just entered a callee, and we wish to resume until it returns
2995 to the caller. Setting a step_resume breakpoint on the return
2996 address will catch a return from the callee.
2998 However, if the callee is recursing, we want to be careful not to
2999 catch returns of those recursive calls, but only of THIS instance
3002 To do this, we set the step_resume bp's frame to our current
3003 caller's frame (step_frame_address, which is set by the "next" or
3004 "until" command, before execution begins). */
3007 step_over_function (struct execution_control_state
*ecs
)
3009 struct symtab_and_line sr_sal
;
3011 INIT_SAL (&sr_sal
); /* initialize to zeros */
3012 sr_sal
.pc
= ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
3013 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3015 check_for_old_step_resume_breakpoint ();
3016 step_resume_breakpoint
=
3017 set_momentary_breakpoint (sr_sal
, get_current_frame (), bp_step_resume
);
3019 if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal
.pc
))
3020 step_resume_breakpoint
->frame
= step_frame_address
;
3022 if (breakpoints_inserted
)
3023 insert_breakpoints ();
3027 stop_stepping (struct execution_control_state
*ecs
)
3029 if (target_has_execution
)
3031 /* Are we stopping for a vfork event? We only stop when we see
3032 the child's event. However, we may not yet have seen the
3033 parent's event. And, inferior_pid is still set to the
3034 parent's pid, until we resume again and follow either the
3037 To ensure that we can really touch inferior_pid (aka, the
3038 parent process) -- which calls to functions like read_pc
3039 implicitly do -- wait on the parent if necessary. */
3040 if ((pending_follow
.kind
== TARGET_WAITKIND_VFORKED
)
3041 && !pending_follow
.fork_event
.saw_parent_fork
)
3047 if (target_wait_hook
)
3048 parent_pid
= target_wait_hook (-1, &(ecs
->ws
));
3050 parent_pid
= target_wait (-1, &(ecs
->ws
));
3052 while (parent_pid
!= inferior_pid
);
3055 /* Assuming the inferior still exists, set these up for next
3056 time, just like we did above if we didn't break out of the
3058 prev_pc
= read_pc ();
3059 prev_func_start
= ecs
->stop_func_start
;
3060 prev_func_name
= ecs
->stop_func_name
;
3063 /* Let callers know we don't want to wait for the inferior anymore. */
3064 ecs
->wait_some_more
= 0;
3067 /* This function handles various cases where we need to continue
3068 waiting for the inferior. */
3069 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3072 keep_going (struct execution_control_state
*ecs
)
3074 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a
3075 vforked child between its creation and subsequent exit or call to
3076 exec(). However, I had big problems in this rather creaky exec
3077 engine, getting that to work. The fundamental problem is that
3078 I'm trying to debug two processes via an engine that only
3079 understands a single process with possibly multiple threads.
3081 Hence, this spot is known to have problems when
3082 target_can_follow_vfork_prior_to_exec returns 1. */
3084 /* Save the pc before execution, to compare with pc after stop. */
3085 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3086 prev_func_start
= ecs
->stop_func_start
; /* Ok, since if DECR_PC_AFTER
3087 BREAK is defined, the
3088 original pc would not have
3089 been at the start of a
3091 prev_func_name
= ecs
->stop_func_name
;
3093 if (ecs
->update_step_sp
)
3094 step_sp
= read_sp ();
3095 ecs
->update_step_sp
= 0;
3097 /* If we did not do break;, it means we should keep running the
3098 inferior and not return to debugger. */
3100 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3102 /* We took a signal (which we are supposed to pass through to
3103 the inferior, else we'd have done a break above) and we
3104 haven't yet gotten our trap. Simply continue. */
3105 resume (currently_stepping (ecs
), stop_signal
);
3109 /* Either the trap was not expected, but we are continuing
3110 anyway (the user asked that this signal be passed to the
3113 The signal was SIGTRAP, e.g. it was our signal, but we
3114 decided we should resume from it.
3116 We're going to run this baby now!
3118 Insert breakpoints now, unless we are trying to one-proceed
3119 past a breakpoint. */
3120 /* If we've just finished a special step resume and we don't
3121 want to hit a breakpoint, pull em out. */
3122 if (step_resume_breakpoint
== NULL
3123 && through_sigtramp_breakpoint
== NULL
3124 && ecs
->remove_breakpoints_on_following_step
)
3126 ecs
->remove_breakpoints_on_following_step
= 0;
3127 remove_breakpoints ();
3128 breakpoints_inserted
= 0;
3130 else if (!breakpoints_inserted
&&
3131 (through_sigtramp_breakpoint
!= NULL
|| !ecs
->another_trap
))
3133 breakpoints_failed
= insert_breakpoints ();
3134 if (breakpoints_failed
)
3136 stop_stepping (ecs
);
3139 breakpoints_inserted
= 1;
3142 trap_expected
= ecs
->another_trap
;
3144 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3145 specifies that such a signal should be delivered to the
3148 Typically, this would occure when a user is debugging a
3149 target monitor on a simulator: the target monitor sets a
3150 breakpoint; the simulator encounters this break-point and
3151 halts the simulation handing control to GDB; GDB, noteing
3152 that the break-point isn't valid, returns control back to the
3153 simulator; the simulator then delivers the hardware
3154 equivalent of a SIGNAL_TRAP to the program being debugged. */
3156 if (stop_signal
== TARGET_SIGNAL_TRAP
3157 && !signal_program
[stop_signal
])
3158 stop_signal
= TARGET_SIGNAL_0
;
3160 #ifdef SHIFT_INST_REGS
3161 /* I'm not sure when this following segment applies. I do know,
3162 now, that we shouldn't rewrite the regs when we were stopped
3163 by a random signal from the inferior process. */
3164 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
3165 (this is only used on the 88k). */
3167 if (!bpstat_explains_signal (stop_bpstat
)
3168 && (stop_signal
!= TARGET_SIGNAL_CHLD
)
3169 && !stopped_by_random_signal
)
3171 #endif /* SHIFT_INST_REGS */
3173 resume (currently_stepping (ecs
), stop_signal
);
3176 prepare_to_wait (ecs
);
3179 /* This function normally comes after a resume, before
3180 handle_inferior_event exits. It takes care of any last bits of
3181 housekeeping, and sets the all-important wait_some_more flag. */
3184 prepare_to_wait (struct execution_control_state
*ecs
)
3186 if (ecs
->infwait_state
== infwait_normal_state
)
3188 overlay_cache_invalid
= 1;
3190 /* We have to invalidate the registers BEFORE calling
3191 target_wait because they can be loaded from the target while
3192 in target_wait. This makes remote debugging a bit more
3193 efficient for those targets that provide critical registers
3194 as part of their normal status mechanism. */
3196 registers_changed ();
3197 ecs
->waiton_pid
= -1;
3198 ecs
->wp
= &(ecs
->ws
);
3200 /* This is the old end of the while loop. Let everybody know we
3201 want to wait for the inferior some more and get called again
3203 ecs
->wait_some_more
= 1;
3206 /* Print why the inferior has stopped. We always print something when
3207 the inferior exits, or receives a signal. The rest of the cases are
3208 dealt with later on in normal_stop() and print_it_typical(). Ideally
3209 there should be a call to this function from handle_inferior_event()
3210 each time stop_stepping() is called.*/
3212 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3214 switch (stop_reason
)
3217 /* We don't deal with these cases from handle_inferior_event()
3220 case END_STEPPING_RANGE
:
3221 /* We are done with a step/next/si/ni command. */
3222 /* For now print nothing. */
3224 case BREAKPOINT_HIT
:
3225 /* We found a breakpoint. */
3226 /* For now print nothing. */
3229 /* The inferior was terminated by a signal. */
3230 annotate_signalled ();
3231 printf_filtered ("\nProgram terminated with signal ");
3232 annotate_signal_name ();
3233 printf_filtered ("%s", target_signal_to_name (stop_info
));
3234 annotate_signal_name_end ();
3235 printf_filtered (", ");
3236 annotate_signal_string ();
3237 printf_filtered ("%s", target_signal_to_string (stop_info
));
3238 annotate_signal_string_end ();
3239 printf_filtered (".\n");
3241 printf_filtered ("The program no longer exists.\n");
3242 gdb_flush (gdb_stdout
);
3245 /* The inferior program is finished. */
3246 annotate_exited (stop_info
);
3248 printf_filtered ("\nProgram exited with code 0%o.\n",
3249 (unsigned int) stop_info
);
3251 printf_filtered ("\nProgram exited normally.\n");
3253 case SIGNAL_RECEIVED
:
3254 /* Signal received. The signal table tells us to print about
3257 printf_filtered ("\nProgram received signal ");
3258 annotate_signal_name ();
3259 printf_filtered ("%s", target_signal_to_name (stop_info
));
3260 annotate_signal_name_end ();
3261 printf_filtered (", ");
3262 annotate_signal_string ();
3263 printf_filtered ("%s", target_signal_to_string (stop_info
));
3264 annotate_signal_string_end ();
3265 printf_filtered (".\n");
3266 gdb_flush (gdb_stdout
);
3269 internal_error ("print_stop_reason: unrecognized enum value");
3275 /* Here to return control to GDB when the inferior stops for real.
3276 Print appropriate messages, remove breakpoints, give terminal our modes.
3278 STOP_PRINT_FRAME nonzero means print the executing frame
3279 (pc, function, args, file, line number and line text).
3280 BREAKPOINTS_FAILED nonzero means stop was due to error
3281 attempting to insert breakpoints. */
3286 /* As with the notification of thread events, we want to delay
3287 notifying the user that we've switched thread context until
3288 the inferior actually stops.
3290 (Note that there's no point in saying anything if the inferior
3292 if (may_switch_from_inferior_pid
3293 && (switched_from_inferior_pid
!= inferior_pid
)
3294 && target_has_execution
)
3296 target_terminal_ours_for_output ();
3297 printf_filtered ("[Switched to %s]\n",
3298 target_pid_or_tid_to_str (inferior_pid
));
3299 switched_from_inferior_pid
= inferior_pid
;
3302 /* Make sure that the current_frame's pc is correct. This
3303 is a correction for setting up the frame info before doing
3304 DECR_PC_AFTER_BREAK */
3305 if (target_has_execution
&& get_current_frame ())
3306 (get_current_frame ())->pc
= read_pc ();
3308 if (breakpoints_failed
)
3310 target_terminal_ours_for_output ();
3311 print_sys_errmsg ("ptrace", breakpoints_failed
);
3312 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3313 The same program may be running in another process.\n");
3316 if (target_has_execution
&& breakpoints_inserted
)
3318 if (remove_breakpoints ())
3320 target_terminal_ours_for_output ();
3321 printf_filtered ("Cannot remove breakpoints because ");
3322 printf_filtered ("program is no longer writable.\n");
3323 printf_filtered ("It might be running in another process.\n");
3324 printf_filtered ("Further execution is probably impossible.\n");
3327 breakpoints_inserted
= 0;
3329 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3330 Delete any breakpoint that is to be deleted at the next stop. */
3332 breakpoint_auto_delete (stop_bpstat
);
3334 /* If an auto-display called a function and that got a signal,
3335 delete that auto-display to avoid an infinite recursion. */
3337 if (stopped_by_random_signal
)
3338 disable_current_display ();
3340 /* Don't print a message if in the middle of doing a "step n"
3341 operation for n > 1 */
3342 if (step_multi
&& stop_step
)
3345 target_terminal_ours ();
3347 /* Look up the hook_stop and run it if it exists. */
3349 if (stop_command
&& stop_command
->hook
)
3351 catch_errors (hook_stop_stub
, stop_command
->hook
,
3352 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3355 if (!target_has_stack
)
3361 /* Select innermost stack frame - i.e., current frame is frame 0,
3362 and current location is based on that.
3363 Don't do this on return from a stack dummy routine,
3364 or if the program has exited. */
3366 if (!stop_stack_dummy
)
3368 select_frame (get_current_frame (), 0);
3370 /* Print current location without a level number, if
3371 we have changed functions or hit a breakpoint.
3372 Print source line if we have one.
3373 bpstat_print() contains the logic deciding in detail
3374 what to print, based on the event(s) that just occurred. */
3376 if (stop_print_frame
)
3380 int do_frame_printing
= 1;
3382 bpstat_ret
= bpstat_print (stop_bpstat
);
3387 && step_frame_address
== FRAME_FP (get_current_frame ())
3388 && step_start_function
== find_pc_function (stop_pc
))
3389 source_flag
= -1; /* finished step, just print source line */
3391 source_flag
= 1; /* print location and source line */
3393 case PRINT_SRC_AND_LOC
:
3394 source_flag
= 1; /* print location and source line */
3396 case PRINT_SRC_ONLY
:
3400 do_frame_printing
= 0;
3403 internal_error ("Unknown value.");
3406 /* The behavior of this routine with respect to the source
3408 -1: Print only source line
3409 0: Print only location
3410 1: Print location and source line */
3411 if (do_frame_printing
)
3412 show_and_print_stack_frame (selected_frame
, -1, source_flag
);
3414 /* Display the auto-display expressions. */
3419 /* Save the function value return registers, if we care.
3420 We might be about to restore their previous contents. */
3421 if (proceed_to_finish
)
3422 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
3424 if (stop_stack_dummy
)
3426 /* Pop the empty frame that contains the stack dummy.
3427 POP_FRAME ends with a setting of the current frame, so we
3428 can use that next. */
3430 /* Set stop_pc to what it was before we called the function.
3431 Can't rely on restore_inferior_status because that only gets
3432 called if we don't stop in the called function. */
3433 stop_pc
= read_pc ();
3434 select_frame (get_current_frame (), 0);
3438 TUIDO (((TuiOpaqueFuncPtr
) tui_vCheckDataValues
, selected_frame
));
3441 annotate_stopped ();
3445 hook_stop_stub (void *cmd
)
3447 execute_user_command ((struct cmd_list_element
*) cmd
, 0);
3452 signal_stop_state (int signo
)
3454 return signal_stop
[signo
];
3458 signal_print_state (int signo
)
3460 return signal_print
[signo
];
3464 signal_pass_state (int signo
)
3466 return signal_program
[signo
];
3469 int signal_stop_update (signo
, state
)
3473 int ret
= signal_stop
[signo
];
3474 signal_stop
[signo
] = state
;
3478 int signal_print_update (signo
, state
)
3482 int ret
= signal_print
[signo
];
3483 signal_print
[signo
] = state
;
3487 int signal_pass_update (signo
, state
)
3491 int ret
= signal_program
[signo
];
3492 signal_program
[signo
] = state
;
3497 sig_print_header (void)
3500 Signal Stop\tPrint\tPass to program\tDescription\n");
3504 sig_print_info (enum target_signal oursig
)
3506 char *name
= target_signal_to_name (oursig
);
3507 int name_padding
= 13 - strlen (name
);
3509 if (name_padding
<= 0)
3512 printf_filtered ("%s", name
);
3513 printf_filtered ("%*.*s ", name_padding
, name_padding
,
3515 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3516 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3517 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3518 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3521 /* Specify how various signals in the inferior should be handled. */
3524 handle_command (char *args
, int from_tty
)
3527 int digits
, wordlen
;
3528 int sigfirst
, signum
, siglast
;
3529 enum target_signal oursig
;
3532 unsigned char *sigs
;
3533 struct cleanup
*old_chain
;
3537 error_no_arg ("signal to handle");
3540 /* Allocate and zero an array of flags for which signals to handle. */
3542 nsigs
= (int) TARGET_SIGNAL_LAST
;
3543 sigs
= (unsigned char *) alloca (nsigs
);
3544 memset (sigs
, 0, nsigs
);
3546 /* Break the command line up into args. */
3548 argv
= buildargv (args
);
3553 old_chain
= make_cleanup_freeargv (argv
);
3555 /* Walk through the args, looking for signal oursigs, signal names, and
3556 actions. Signal numbers and signal names may be interspersed with
3557 actions, with the actions being performed for all signals cumulatively
3558 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3560 while (*argv
!= NULL
)
3562 wordlen
= strlen (*argv
);
3563 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3567 sigfirst
= siglast
= -1;
3569 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3571 /* Apply action to all signals except those used by the
3572 debugger. Silently skip those. */
3575 siglast
= nsigs
- 1;
3577 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3579 SET_SIGS (nsigs
, sigs
, signal_stop
);
3580 SET_SIGS (nsigs
, sigs
, signal_print
);
3582 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3584 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3586 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3588 SET_SIGS (nsigs
, sigs
, signal_print
);
3590 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3592 SET_SIGS (nsigs
, sigs
, signal_program
);
3594 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3596 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3598 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3600 SET_SIGS (nsigs
, sigs
, signal_program
);
3602 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3604 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3605 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3607 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3609 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3611 else if (digits
> 0)
3613 /* It is numeric. The numeric signal refers to our own
3614 internal signal numbering from target.h, not to host/target
3615 signal number. This is a feature; users really should be
3616 using symbolic names anyway, and the common ones like
3617 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3619 sigfirst
= siglast
= (int)
3620 target_signal_from_command (atoi (*argv
));
3621 if ((*argv
)[digits
] == '-')
3624 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3626 if (sigfirst
> siglast
)
3628 /* Bet he didn't figure we'd think of this case... */
3636 oursig
= target_signal_from_name (*argv
);
3637 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3639 sigfirst
= siglast
= (int) oursig
;
3643 /* Not a number and not a recognized flag word => complain. */
3644 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv
);
3648 /* If any signal numbers or symbol names were found, set flags for
3649 which signals to apply actions to. */
3651 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3653 switch ((enum target_signal
) signum
)
3655 case TARGET_SIGNAL_TRAP
:
3656 case TARGET_SIGNAL_INT
:
3657 if (!allsigs
&& !sigs
[signum
])
3659 if (query ("%s is used by the debugger.\n\
3660 Are you sure you want to change it? ",
3661 target_signal_to_name
3662 ((enum target_signal
) signum
)))
3668 printf_unfiltered ("Not confirmed, unchanged.\n");
3669 gdb_flush (gdb_stdout
);
3673 case TARGET_SIGNAL_0
:
3674 case TARGET_SIGNAL_DEFAULT
:
3675 case TARGET_SIGNAL_UNKNOWN
:
3676 /* Make sure that "all" doesn't print these. */
3687 target_notice_signals (inferior_pid
);
3691 /* Show the results. */
3692 sig_print_header ();
3693 for (signum
= 0; signum
< nsigs
; signum
++)
3697 sig_print_info (signum
);
3702 do_cleanups (old_chain
);
3706 xdb_handle_command (char *args
, int from_tty
)
3709 struct cleanup
*old_chain
;
3711 /* Break the command line up into args. */
3713 argv
= buildargv (args
);
3718 old_chain
= make_cleanup_freeargv (argv
);
3719 if (argv
[1] != (char *) NULL
)
3724 bufLen
= strlen (argv
[0]) + 20;
3725 argBuf
= (char *) xmalloc (bufLen
);
3729 enum target_signal oursig
;
3731 oursig
= target_signal_from_name (argv
[0]);
3732 memset (argBuf
, 0, bufLen
);
3733 if (strcmp (argv
[1], "Q") == 0)
3734 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3737 if (strcmp (argv
[1], "s") == 0)
3739 if (!signal_stop
[oursig
])
3740 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3742 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3744 else if (strcmp (argv
[1], "i") == 0)
3746 if (!signal_program
[oursig
])
3747 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3749 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3751 else if (strcmp (argv
[1], "r") == 0)
3753 if (!signal_print
[oursig
])
3754 sprintf (argBuf
, "%s %s", argv
[0], "print");
3756 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3762 handle_command (argBuf
, from_tty
);
3764 printf_filtered ("Invalid signal handling flag.\n");
3769 do_cleanups (old_chain
);
3772 /* Print current contents of the tables set by the handle command.
3773 It is possible we should just be printing signals actually used
3774 by the current target (but for things to work right when switching
3775 targets, all signals should be in the signal tables). */
3778 signals_info (char *signum_exp
, int from_tty
)
3780 enum target_signal oursig
;
3781 sig_print_header ();
3785 /* First see if this is a symbol name. */
3786 oursig
= target_signal_from_name (signum_exp
);
3787 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3789 /* No, try numeric. */
3791 target_signal_from_command (parse_and_eval_address (signum_exp
));
3793 sig_print_info (oursig
);
3797 printf_filtered ("\n");
3798 /* These ugly casts brought to you by the native VAX compiler. */
3799 for (oursig
= TARGET_SIGNAL_FIRST
;
3800 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3801 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3805 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3806 && oursig
!= TARGET_SIGNAL_DEFAULT
3807 && oursig
!= TARGET_SIGNAL_0
)
3808 sig_print_info (oursig
);
3811 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3814 struct inferior_status
3816 enum target_signal stop_signal
;
3820 int stop_stack_dummy
;
3821 int stopped_by_random_signal
;
3823 CORE_ADDR step_range_start
;
3824 CORE_ADDR step_range_end
;
3825 CORE_ADDR step_frame_address
;
3826 int step_over_calls
;
3827 CORE_ADDR step_resume_break_address
;
3828 int stop_after_trap
;
3829 int stop_soon_quietly
;
3830 CORE_ADDR selected_frame_address
;
3831 char *stop_registers
;
3833 /* These are here because if call_function_by_hand has written some
3834 registers and then decides to call error(), we better not have changed
3839 int breakpoint_proceeded
;
3840 int restore_stack_info
;
3841 int proceed_to_finish
;
3844 static struct inferior_status
*
3845 xmalloc_inferior_status (void)
3847 struct inferior_status
*inf_status
;
3848 inf_status
= xmalloc (sizeof (struct inferior_status
));
3849 inf_status
->stop_registers
= xmalloc (REGISTER_BYTES
);
3850 inf_status
->registers
= xmalloc (REGISTER_BYTES
);
3855 free_inferior_status (struct inferior_status
*inf_status
)
3857 free (inf_status
->registers
);
3858 free (inf_status
->stop_registers
);
3863 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3866 int size
= REGISTER_RAW_SIZE (regno
);
3867 void *buf
= alloca (size
);
3868 store_signed_integer (buf
, size
, val
);
3869 memcpy (&inf_status
->registers
[REGISTER_BYTE (regno
)], buf
, size
);
3872 /* Save all of the information associated with the inferior<==>gdb
3873 connection. INF_STATUS is a pointer to a "struct inferior_status"
3874 (defined in inferior.h). */
3876 struct inferior_status
*
3877 save_inferior_status (int restore_stack_info
)
3879 struct inferior_status
*inf_status
= xmalloc_inferior_status ();
3881 inf_status
->stop_signal
= stop_signal
;
3882 inf_status
->stop_pc
= stop_pc
;
3883 inf_status
->stop_step
= stop_step
;
3884 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3885 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3886 inf_status
->trap_expected
= trap_expected
;
3887 inf_status
->step_range_start
= step_range_start
;
3888 inf_status
->step_range_end
= step_range_end
;
3889 inf_status
->step_frame_address
= step_frame_address
;
3890 inf_status
->step_over_calls
= step_over_calls
;
3891 inf_status
->stop_after_trap
= stop_after_trap
;
3892 inf_status
->stop_soon_quietly
= stop_soon_quietly
;
3893 /* Save original bpstat chain here; replace it with copy of chain.
3894 If caller's caller is walking the chain, they'll be happier if we
3895 hand them back the original chain when restore_inferior_status is
3897 inf_status
->stop_bpstat
= stop_bpstat
;
3898 stop_bpstat
= bpstat_copy (stop_bpstat
);
3899 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3900 inf_status
->restore_stack_info
= restore_stack_info
;
3901 inf_status
->proceed_to_finish
= proceed_to_finish
;
3903 memcpy (inf_status
->stop_registers
, stop_registers
, REGISTER_BYTES
);
3905 read_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3907 record_selected_frame (&(inf_status
->selected_frame_address
),
3908 &(inf_status
->selected_level
));
3912 struct restore_selected_frame_args
3914 CORE_ADDR frame_address
;
3919 restore_selected_frame (void *args
)
3921 struct restore_selected_frame_args
*fr
=
3922 (struct restore_selected_frame_args
*) args
;
3923 struct frame_info
*frame
;
3924 int level
= fr
->level
;
3926 frame
= find_relative_frame (get_current_frame (), &level
);
3928 /* If inf_status->selected_frame_address is NULL, there was no
3929 previously selected frame. */
3930 if (frame
== NULL
||
3931 /* FRAME_FP (frame) != fr->frame_address || */
3932 /* elz: deleted this check as a quick fix to the problem that
3933 for function called by hand gdb creates no internal frame
3934 structure and the real stack and gdb's idea of stack are
3935 different if nested calls by hands are made.
3937 mvs: this worries me. */
3940 warning ("Unable to restore previously selected frame.\n");
3944 select_frame (frame
, fr
->level
);
3950 restore_inferior_status (struct inferior_status
*inf_status
)
3952 stop_signal
= inf_status
->stop_signal
;
3953 stop_pc
= inf_status
->stop_pc
;
3954 stop_step
= inf_status
->stop_step
;
3955 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3956 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3957 trap_expected
= inf_status
->trap_expected
;
3958 step_range_start
= inf_status
->step_range_start
;
3959 step_range_end
= inf_status
->step_range_end
;
3960 step_frame_address
= inf_status
->step_frame_address
;
3961 step_over_calls
= inf_status
->step_over_calls
;
3962 stop_after_trap
= inf_status
->stop_after_trap
;
3963 stop_soon_quietly
= inf_status
->stop_soon_quietly
;
3964 bpstat_clear (&stop_bpstat
);
3965 stop_bpstat
= inf_status
->stop_bpstat
;
3966 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3967 proceed_to_finish
= inf_status
->proceed_to_finish
;
3969 /* FIXME: Is the restore of stop_registers always needed */
3970 memcpy (stop_registers
, inf_status
->stop_registers
, REGISTER_BYTES
);
3972 /* The inferior can be gone if the user types "print exit(0)"
3973 (and perhaps other times). */
3974 if (target_has_execution
)
3975 write_register_bytes (0, inf_status
->registers
, REGISTER_BYTES
);
3977 /* FIXME: If we are being called after stopping in a function which
3978 is called from gdb, we should not be trying to restore the
3979 selected frame; it just prints a spurious error message (The
3980 message is useful, however, in detecting bugs in gdb (like if gdb
3981 clobbers the stack)). In fact, should we be restoring the
3982 inferior status at all in that case? . */
3984 if (target_has_stack
&& inf_status
->restore_stack_info
)
3986 struct restore_selected_frame_args fr
;
3987 fr
.level
= inf_status
->selected_level
;
3988 fr
.frame_address
= inf_status
->selected_frame_address
;
3989 /* The point of catch_errors is that if the stack is clobbered,
3990 walking the stack might encounter a garbage pointer and error()
3991 trying to dereference it. */
3992 if (catch_errors (restore_selected_frame
, &fr
,
3993 "Unable to restore previously selected frame:\n",
3994 RETURN_MASK_ERROR
) == 0)
3995 /* Error in restoring the selected frame. Select the innermost
3999 select_frame (get_current_frame (), 0);
4003 free_inferior_status (inf_status
);
4007 discard_inferior_status (struct inferior_status
*inf_status
)
4009 /* See save_inferior_status for info on stop_bpstat. */
4010 bpstat_clear (&inf_status
->stop_bpstat
);
4011 free_inferior_status (inf_status
);
4015 set_follow_fork_mode_command (char *arg
, int from_tty
,
4016 struct cmd_list_element
*c
)
4018 if (!STREQ (arg
, "parent") &&
4019 !STREQ (arg
, "child") &&
4020 !STREQ (arg
, "both") &&
4021 !STREQ (arg
, "ask"))
4022 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
4024 if (follow_fork_mode_string
!= NULL
)
4025 free (follow_fork_mode_string
);
4026 follow_fork_mode_string
= savestring (arg
, strlen (arg
));
4032 stop_registers
= xmalloc (REGISTER_BYTES
);
4036 _initialize_infrun (void)
4039 register int numsigs
;
4040 struct cmd_list_element
*c
;
4044 register_gdbarch_swap (&stop_registers
, sizeof (stop_registers
), NULL
);
4045 register_gdbarch_swap (NULL
, 0, build_infrun
);
4047 add_info ("signals", signals_info
,
4048 "What debugger does when program gets various signals.\n\
4049 Specify a signal as argument to print info on that signal only.");
4050 add_info_alias ("handle", "signals", 0);
4052 add_com ("handle", class_run
, handle_command
,
4053 concat ("Specify how to handle a signal.\n\
4054 Args are signals and actions to apply to those signals.\n\
4055 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4056 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4057 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4058 The special arg \"all\" is recognized to mean all signals except those\n\
4059 used by the debugger, typically SIGTRAP and SIGINT.\n",
4060 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4061 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4062 Stop means reenter debugger if this signal happens (implies print).\n\
4063 Print means print a message if this signal happens.\n\
4064 Pass means let program see this signal; otherwise program doesn't know.\n\
4065 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4066 Pass and Stop may be combined.", NULL
));
4069 add_com ("lz", class_info
, signals_info
,
4070 "What debugger does when program gets various signals.\n\
4071 Specify a signal as argument to print info on that signal only.");
4072 add_com ("z", class_run
, xdb_handle_command
,
4073 concat ("Specify how to handle a signal.\n\
4074 Args are signals and actions to apply to those signals.\n\
4075 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4076 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4077 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4078 The special arg \"all\" is recognized to mean all signals except those\n\
4079 used by the debugger, typically SIGTRAP and SIGINT.\n",
4080 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
4081 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4082 nopass), \"Q\" (noprint)\n\
4083 Stop means reenter debugger if this signal happens (implies print).\n\
4084 Print means print a message if this signal happens.\n\
4085 Pass means let program see this signal; otherwise program doesn't know.\n\
4086 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4087 Pass and Stop may be combined.", NULL
));
4091 stop_command
= add_cmd ("stop", class_obscure
, not_just_help_class_command
,
4092 "There is no `stop' command, but you can set a hook on `stop'.\n\
4093 This allows you to set a list of commands to be run each time execution\n\
4094 of the program stops.", &cmdlist
);
4096 numsigs
= (int) TARGET_SIGNAL_LAST
;
4097 signal_stop
= (unsigned char *)
4098 xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4099 signal_print
= (unsigned char *)
4100 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4101 signal_program
= (unsigned char *)
4102 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4103 for (i
= 0; i
< numsigs
; i
++)
4106 signal_print
[i
] = 1;
4107 signal_program
[i
] = 1;
4110 /* Signals caused by debugger's own actions
4111 should not be given to the program afterwards. */
4112 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4113 signal_program
[TARGET_SIGNAL_INT
] = 0;
4115 /* Signals that are not errors should not normally enter the debugger. */
4116 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4117 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4118 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4119 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4120 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4121 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4122 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4123 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4124 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4125 signal_print
[TARGET_SIGNAL_IO
] = 0;
4126 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4127 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4128 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4129 signal_print
[TARGET_SIGNAL_URG
] = 0;
4130 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4131 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4133 /* These signals are used internally by user-level thread
4134 implementations. (See signal(5) on Solaris.) Like the above
4135 signals, a healthy program receives and handles them as part of
4136 its normal operation. */
4137 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4138 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4139 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4140 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4141 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4142 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4146 (add_set_cmd ("stop-on-solib-events", class_support
, var_zinteger
,
4147 (char *) &stop_on_solib_events
,
4148 "Set stopping for shared library events.\n\
4149 If nonzero, gdb will give control to the user when the dynamic linker\n\
4150 notifies gdb of shared library events. The most common event of interest\n\
4151 to the user would be loading/unloading of a new library.\n",
4156 c
= add_set_enum_cmd ("follow-fork-mode",
4158 follow_fork_mode_kind_names
,
4159 (char *) &follow_fork_mode_string
,
4160 /* ??rehrauer: The "both" option is broken, by what may be a 10.20
4161 kernel problem. It's also not terribly useful without a GUI to
4162 help the user drive two debuggers. So for now, I'm disabling
4163 the "both" option. */
4164 /* "Set debugger response to a program call of fork \
4166 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4167 parent - the original process is debugged after a fork\n\
4168 child - the new process is debugged after a fork\n\
4169 both - both the parent and child are debugged after a fork\n\
4170 ask - the debugger will ask for one of the above choices\n\
4171 For \"both\", another copy of the debugger will be started to follow\n\
4172 the new child process. The original debugger will continue to follow\n\
4173 the original parent process. To distinguish their prompts, the\n\
4174 debugger copy's prompt will be changed.\n\
4175 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4176 By default, the debugger will follow the parent process.",
4178 "Set debugger response to a program call of fork \
4180 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4181 parent - the original process is debugged after a fork\n\
4182 child - the new process is debugged after a fork\n\
4183 ask - the debugger will ask for one of the above choices\n\
4184 For \"parent\" or \"child\", the unfollowed process will run free.\n\
4185 By default, the debugger will follow the parent process.",
4187 /* c->function.sfunc = ; */
4188 add_show_from_set (c
, &showlist
);
4190 set_follow_fork_mode_command ("parent", 0, NULL
);
4192 c
= add_set_enum_cmd ("scheduler-locking", class_run
,
4193 scheduler_enums
, /* array of string names */
4194 (char *) &scheduler_mode
, /* current mode */
4195 "Set mode for locking scheduler during execution.\n\
4196 off == no locking (threads may preempt at any time)\n\
4197 on == full locking (no thread except the current thread may run)\n\
4198 step == scheduler locked during every single-step operation.\n\
4199 In this mode, no other thread may run during a step command.\n\
4200 Other threads may run while stepping over a function call ('next').",
4203 c
->function
.sfunc
= set_schedlock_func
; /* traps on target vector */
4204 add_show_from_set (c
, &showlist
);