1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
5 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
6 Free Software Foundation, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
29 #include "exceptions.h"
30 #include "breakpoint.h"
34 #include "cli/cli-script.h"
36 #include "gdbthread.h"
49 #include "gdb_assert.h"
50 #include "mi/mi-common.h"
52 /* Prototypes for local functions */
54 static void signals_info (char *, int);
56 static void handle_command (char *, int);
58 static void sig_print_info (enum target_signal
);
60 static void sig_print_header (void);
62 static void resume_cleanups (void *);
64 static int hook_stop_stub (void *);
66 static int restore_selected_frame (void *);
68 static void build_infrun (void);
70 static int follow_fork (void);
72 static void set_schedlock_func (char *args
, int from_tty
,
73 struct cmd_list_element
*c
);
75 struct execution_control_state
;
77 static int currently_stepping (struct execution_control_state
*ecs
);
79 static void xdb_handle_command (char *args
, int from_tty
);
81 static int prepare_to_proceed (int);
83 void _initialize_infrun (void);
85 int inferior_ignoring_leading_exec_events
= 0;
87 /* When set, stop the 'step' command if we enter a function which has
88 no line number information. The normal behavior is that we step
89 over such function. */
90 int step_stop_if_no_debug
= 0;
92 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
93 struct cmd_list_element
*c
, const char *value
)
95 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
98 /* In asynchronous mode, but simulating synchronous execution. */
100 int sync_execution
= 0;
102 /* wait_for_inferior and normal_stop use this to notify the user
103 when the inferior stopped in a different thread than it had been
106 static ptid_t previous_inferior_ptid
;
108 /* This is true for configurations that may follow through execl() and
109 similar functions. At present this is only true for HP-UX native. */
111 #ifndef MAY_FOLLOW_EXEC
112 #define MAY_FOLLOW_EXEC (0)
115 static int may_follow_exec
= MAY_FOLLOW_EXEC
;
117 static int debug_infrun
= 0;
119 show_debug_infrun (struct ui_file
*file
, int from_tty
,
120 struct cmd_list_element
*c
, const char *value
)
122 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
125 /* If the program uses ELF-style shared libraries, then calls to
126 functions in shared libraries go through stubs, which live in a
127 table called the PLT (Procedure Linkage Table). The first time the
128 function is called, the stub sends control to the dynamic linker,
129 which looks up the function's real address, patches the stub so
130 that future calls will go directly to the function, and then passes
131 control to the function.
133 If we are stepping at the source level, we don't want to see any of
134 this --- we just want to skip over the stub and the dynamic linker.
135 The simple approach is to single-step until control leaves the
138 However, on some systems (e.g., Red Hat's 5.2 distribution) the
139 dynamic linker calls functions in the shared C library, so you
140 can't tell from the PC alone whether the dynamic linker is still
141 running. In this case, we use a step-resume breakpoint to get us
142 past the dynamic linker, as if we were using "next" to step over a
145 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
146 linker code or not. Normally, this means we single-step. However,
147 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
148 address where we can place a step-resume breakpoint to get past the
149 linker's symbol resolution function.
151 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
152 pretty portable way, by comparing the PC against the address ranges
153 of the dynamic linker's sections.
155 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
156 it depends on internal details of the dynamic linker. It's usually
157 not too hard to figure out where to put a breakpoint, but it
158 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
159 sanity checking. If it can't figure things out, returning zero and
160 getting the (possibly confusing) stepping behavior is better than
161 signalling an error, which will obscure the change in the
164 /* This function returns TRUE if pc is the address of an instruction
165 that lies within the dynamic linker (such as the event hook, or the
168 This function must be used only when a dynamic linker event has
169 been caught, and the inferior is being stepped out of the hook, or
170 undefined results are guaranteed. */
172 #ifndef SOLIB_IN_DYNAMIC_LINKER
173 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
177 /* Convert the #defines into values. This is temporary until wfi control
178 flow is completely sorted out. */
180 #ifndef CANNOT_STEP_HW_WATCHPOINTS
181 #define CANNOT_STEP_HW_WATCHPOINTS 0
183 #undef CANNOT_STEP_HW_WATCHPOINTS
184 #define CANNOT_STEP_HW_WATCHPOINTS 1
187 /* Tables of how to react to signals; the user sets them. */
189 static unsigned char *signal_stop
;
190 static unsigned char *signal_print
;
191 static unsigned char *signal_program
;
193 #define SET_SIGS(nsigs,sigs,flags) \
195 int signum = (nsigs); \
196 while (signum-- > 0) \
197 if ((sigs)[signum]) \
198 (flags)[signum] = 1; \
201 #define UNSET_SIGS(nsigs,sigs,flags) \
203 int signum = (nsigs); \
204 while (signum-- > 0) \
205 if ((sigs)[signum]) \
206 (flags)[signum] = 0; \
209 /* Value to pass to target_resume() to cause all threads to resume */
211 #define RESUME_ALL (pid_to_ptid (-1))
213 /* Command list pointer for the "stop" placeholder. */
215 static struct cmd_list_element
*stop_command
;
217 /* Nonzero if breakpoints are now inserted in the inferior. */
219 static int breakpoints_inserted
;
221 /* Function inferior was in as of last step command. */
223 static struct symbol
*step_start_function
;
225 /* Nonzero if we are expecting a trace trap and should proceed from it. */
227 static int trap_expected
;
229 /* Nonzero if we want to give control to the user when we're notified
230 of shared library events by the dynamic linker. */
231 static int stop_on_solib_events
;
233 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
234 struct cmd_list_element
*c
, const char *value
)
236 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
240 /* Nonzero means expecting a trace trap
241 and should stop the inferior and return silently when it happens. */
245 /* Nonzero means expecting a trap and caller will handle it themselves.
246 It is used after attach, due to attaching to a process;
247 when running in the shell before the child program has been exec'd;
248 and when running some kinds of remote stuff (FIXME?). */
250 enum stop_kind stop_soon
;
252 /* Nonzero if proceed is being used for a "finish" command or a similar
253 situation when stop_registers should be saved. */
255 int proceed_to_finish
;
257 /* Save register contents here when about to pop a stack dummy frame,
258 if-and-only-if proceed_to_finish is set.
259 Thus this contains the return value from the called function (assuming
260 values are returned in a register). */
262 struct regcache
*stop_registers
;
264 /* Nonzero after stop if current stack frame should be printed. */
266 static int stop_print_frame
;
268 static struct breakpoint
*step_resume_breakpoint
= NULL
;
270 /* This is a cached copy of the pid/waitstatus of the last event
271 returned by target_wait()/deprecated_target_wait_hook(). This
272 information is returned by get_last_target_status(). */
273 static ptid_t target_last_wait_ptid
;
274 static struct target_waitstatus target_last_waitstatus
;
276 /* This is used to remember when a fork, vfork or exec event
277 was caught by a catchpoint, and thus the event is to be
278 followed at the next resume of the inferior, and not
282 enum target_waitkind kind
;
289 char *execd_pathname
;
293 static const char follow_fork_mode_child
[] = "child";
294 static const char follow_fork_mode_parent
[] = "parent";
296 static const char *follow_fork_mode_kind_names
[] = {
297 follow_fork_mode_child
,
298 follow_fork_mode_parent
,
302 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
304 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
305 struct cmd_list_element
*c
, const char *value
)
307 fprintf_filtered (file
, _("\
308 Debugger response to a program call of fork or vfork is \"%s\".\n"),
316 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
318 return target_follow_fork (follow_child
);
322 follow_inferior_reset_breakpoints (void)
324 /* Was there a step_resume breakpoint? (There was if the user
325 did a "next" at the fork() call.) If so, explicitly reset its
328 step_resumes are a form of bp that are made to be per-thread.
329 Since we created the step_resume bp when the parent process
330 was being debugged, and now are switching to the child process,
331 from the breakpoint package's viewpoint, that's a switch of
332 "threads". We must update the bp's notion of which thread
333 it is for, or it'll be ignored when it triggers. */
335 if (step_resume_breakpoint
)
336 breakpoint_re_set_thread (step_resume_breakpoint
);
338 /* Reinsert all breakpoints in the child. The user may have set
339 breakpoints after catching the fork, in which case those
340 were never set in the child, but only in the parent. This makes
341 sure the inserted breakpoints match the breakpoint list. */
343 breakpoint_re_set ();
344 insert_breakpoints ();
347 /* EXECD_PATHNAME is assumed to be non-NULL. */
350 follow_exec (int pid
, char *execd_pathname
)
353 struct target_ops
*tgt
;
355 if (!may_follow_exec
)
358 /* This is an exec event that we actually wish to pay attention to.
359 Refresh our symbol table to the newly exec'd program, remove any
362 If there are breakpoints, they aren't really inserted now,
363 since the exec() transformed our inferior into a fresh set
366 We want to preserve symbolic breakpoints on the list, since
367 we have hopes that they can be reset after the new a.out's
368 symbol table is read.
370 However, any "raw" breakpoints must be removed from the list
371 (e.g., the solib bp's), since their address is probably invalid
374 And, we DON'T want to call delete_breakpoints() here, since
375 that may write the bp's "shadow contents" (the instruction
376 value that was overwritten witha TRAP instruction). Since
377 we now have a new a.out, those shadow contents aren't valid. */
378 update_breakpoints_after_exec ();
380 /* If there was one, it's gone now. We cannot truly step-to-next
381 statement through an exec(). */
382 step_resume_breakpoint
= NULL
;
383 step_range_start
= 0;
386 /* What is this a.out's name? */
387 printf_unfiltered (_("Executing new program: %s\n"), execd_pathname
);
389 /* We've followed the inferior through an exec. Therefore, the
390 inferior has essentially been killed & reborn. */
392 /* First collect the run target in effect. */
393 tgt
= find_run_target ();
394 /* If we can't find one, things are in a very strange state... */
396 error (_("Could find run target to save before following exec"));
398 gdb_flush (gdb_stdout
);
399 target_mourn_inferior ();
400 inferior_ptid
= pid_to_ptid (saved_pid
);
401 /* Because mourn_inferior resets inferior_ptid. */
404 /* That a.out is now the one to use. */
405 exec_file_attach (execd_pathname
, 0);
407 /* And also is where symbols can be found. */
408 symbol_file_add_main (execd_pathname
, 0);
410 /* Reset the shared library package. This ensures that we get
411 a shlib event when the child reaches "_start", at which point
412 the dld will have had a chance to initialize the child. */
413 #if defined(SOLIB_RESTART)
416 #ifdef SOLIB_CREATE_INFERIOR_HOOK
417 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
419 solib_create_inferior_hook ();
422 /* Reinsert all breakpoints. (Those which were symbolic have
423 been reset to the proper address in the new a.out, thanks
424 to symbol_file_command...) */
425 insert_breakpoints ();
427 /* The next resume of this inferior should bring it to the shlib
428 startup breakpoints. (If the user had also set bp's on
429 "main" from the old (parent) process, then they'll auto-
430 matically get reset there in the new process.) */
433 /* Non-zero if we just simulating a single-step. This is needed
434 because we cannot remove the breakpoints in the inferior process
435 until after the `wait' in `wait_for_inferior'. */
436 static int singlestep_breakpoints_inserted_p
= 0;
438 /* The thread we inserted single-step breakpoints for. */
439 static ptid_t singlestep_ptid
;
441 /* PC when we started this single-step. */
442 static CORE_ADDR singlestep_pc
;
444 /* If another thread hit the singlestep breakpoint, we save the original
445 thread here so that we can resume single-stepping it later. */
446 static ptid_t saved_singlestep_ptid
;
447 static int stepping_past_singlestep_breakpoint
;
449 /* Similarly, if we are stepping another thread past a breakpoint,
450 save the original thread here so that we can resume stepping it later. */
451 static ptid_t stepping_past_breakpoint_ptid
;
452 static int stepping_past_breakpoint
;
455 /* Things to clean up if we QUIT out of resume (). */
457 resume_cleanups (void *ignore
)
462 static const char schedlock_off
[] = "off";
463 static const char schedlock_on
[] = "on";
464 static const char schedlock_step
[] = "step";
465 static const char *scheduler_enums
[] = {
471 static const char *scheduler_mode
= schedlock_off
;
473 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
474 struct cmd_list_element
*c
, const char *value
)
476 fprintf_filtered (file
, _("\
477 Mode for locking scheduler during execution is \"%s\".\n"),
482 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
484 if (!target_can_lock_scheduler
)
486 scheduler_mode
= schedlock_off
;
487 error (_("Target '%s' cannot support this command."), target_shortname
);
492 /* Resume the inferior, but allow a QUIT. This is useful if the user
493 wants to interrupt some lengthy single-stepping operation
494 (for child processes, the SIGINT goes to the inferior, and so
495 we get a SIGINT random_signal, but for remote debugging and perhaps
496 other targets, that's not true).
498 STEP nonzero if we should step (zero to continue instead).
499 SIG is the signal to give the inferior (zero for none). */
501 resume (int step
, enum target_signal sig
)
503 int should_resume
= 1;
504 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
508 fprintf_unfiltered (gdb_stdlog
, "infrun: resume (step=%d, signal=%d)\n",
511 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
514 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
515 over an instruction that causes a page fault without triggering
516 a hardware watchpoint. The kernel properly notices that it shouldn't
517 stop, because the hardware watchpoint is not triggered, but it forgets
518 the step request and continues the program normally.
519 Work around the problem by removing hardware watchpoints if a step is
520 requested, GDB will check for a hardware watchpoint trigger after the
522 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
&& breakpoints_inserted
)
523 remove_hw_watchpoints ();
526 /* Normally, by the time we reach `resume', the breakpoints are either
527 removed or inserted, as appropriate. The exception is if we're sitting
528 at a permanent breakpoint; we need to step over it, but permanent
529 breakpoints can't be removed. So we have to test for it here. */
530 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here
)
532 if (gdbarch_skip_permanent_breakpoint_p (current_gdbarch
))
533 gdbarch_skip_permanent_breakpoint (current_gdbarch
,
534 get_current_regcache ());
537 The program is stopped at a permanent breakpoint, but GDB does not know\n\
538 how to step past a permanent breakpoint on this architecture. Try using\n\
539 a command like `return' or `jump' to continue execution."));
542 if (step
&& gdbarch_software_single_step_p (current_gdbarch
))
544 /* Do it the hard way, w/temp breakpoints */
545 if (gdbarch_software_single_step (current_gdbarch
, get_current_frame ()))
547 /* ...and don't ask hardware to do it. */
549 /* and do not pull these breakpoints until after a `wait' in
550 `wait_for_inferior' */
551 singlestep_breakpoints_inserted_p
= 1;
552 singlestep_ptid
= inferior_ptid
;
553 singlestep_pc
= read_pc ();
557 /* If there were any forks/vforks/execs that were caught and are
558 now to be followed, then do so. */
559 switch (pending_follow
.kind
)
561 case TARGET_WAITKIND_FORKED
:
562 case TARGET_WAITKIND_VFORKED
:
563 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
568 case TARGET_WAITKIND_EXECD
:
569 /* follow_exec is called as soon as the exec event is seen. */
570 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
577 /* Install inferior's terminal modes. */
578 target_terminal_inferior ();
584 resume_ptid
= RESUME_ALL
; /* Default */
586 /* If STEP is set, it's a request to use hardware stepping
587 facilities. But in that case, we should never
588 use singlestep breakpoint. */
589 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
591 if (singlestep_breakpoints_inserted_p
592 && stepping_past_singlestep_breakpoint
)
594 /* The situation here is as follows. In thread T1 we wanted to
595 single-step. Lacking hardware single-stepping we've
596 set breakpoint at the PC of the next instruction -- call it
597 P. After resuming, we've hit that breakpoint in thread T2.
598 Now we've removed original breakpoint, inserted breakpoint
599 at P+1, and try to step to advance T2 past breakpoint.
600 We need to step only T2, as if T1 is allowed to freely run,
601 it can run past P, and if other threads are allowed to run,
602 they can hit breakpoint at P+1, and nested hits of single-step
603 breakpoints is not something we'd want -- that's complicated
604 to support, and has no value. */
605 resume_ptid
= inferior_ptid
;
608 if ((step
|| singlestep_breakpoints_inserted_p
)
609 && breakpoint_here_p (read_pc ())
610 && !breakpoint_inserted_here_p (read_pc ()))
612 /* We're stepping, have breakpoint at PC, and it's
613 not inserted. Most likely, proceed has noticed that
614 we have breakpoint and tries to single-step over it,
615 so that it's not hit. In which case, we need to
616 single-step only this thread, and keep others stopped,
617 as they can miss this breakpoint if allowed to run.
619 The current code either has all breakpoints inserted,
620 or all removed, so if we let other threads run,
621 we can actually miss any breakpoint, not the one at PC. */
622 resume_ptid
= inferior_ptid
;
625 if ((scheduler_mode
== schedlock_on
)
626 || (scheduler_mode
== schedlock_step
627 && (step
|| singlestep_breakpoints_inserted_p
)))
629 /* User-settable 'scheduler' mode requires solo thread resume. */
630 resume_ptid
= inferior_ptid
;
633 if (gdbarch_cannot_step_breakpoint (current_gdbarch
))
635 /* Most targets can step a breakpoint instruction, thus
636 executing it normally. But if this one cannot, just
637 continue and we will hit it anyway. */
638 if (step
&& breakpoints_inserted
&& breakpoint_here_p (read_pc ()))
641 target_resume (resume_ptid
, step
, sig
);
644 discard_cleanups (old_cleanups
);
648 /* Clear out all variables saying what to do when inferior is continued.
649 First do this, then set the ones you want, then call `proceed'. */
652 clear_proceed_status (void)
655 step_range_start
= 0;
657 step_frame_id
= null_frame_id
;
658 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
660 stop_soon
= NO_STOP_QUIETLY
;
661 proceed_to_finish
= 0;
662 breakpoint_proceeded
= 1; /* We're about to proceed... */
666 regcache_xfree (stop_registers
);
667 stop_registers
= NULL
;
670 /* Discard any remaining commands or status from previous stop. */
671 bpstat_clear (&stop_bpstat
);
674 /* This should be suitable for any targets that support threads. */
677 prepare_to_proceed (int step
)
680 struct target_waitstatus wait_status
;
682 /* Get the last target status returned by target_wait(). */
683 get_last_target_status (&wait_ptid
, &wait_status
);
685 /* Make sure we were stopped at a breakpoint. */
686 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
687 || wait_status
.value
.sig
!= TARGET_SIGNAL_TRAP
)
692 /* Switched over from WAIT_PID. */
693 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
694 && !ptid_equal (inferior_ptid
, wait_ptid
)
695 && breakpoint_here_p (read_pc_pid (wait_ptid
)))
697 /* If stepping, remember current thread to switch back to. */
700 stepping_past_breakpoint
= 1;
701 stepping_past_breakpoint_ptid
= inferior_ptid
;
704 /* Switch back to WAIT_PID thread. */
705 switch_to_thread (wait_ptid
);
707 /* We return 1 to indicate that there is a breakpoint here,
708 so we need to step over it before continuing to avoid
709 hitting it straight away. */
716 /* Record the pc of the program the last time it stopped. This is
717 just used internally by wait_for_inferior, but need to be preserved
718 over calls to it and cleared when the inferior is started. */
719 static CORE_ADDR prev_pc
;
721 /* Basic routine for continuing the program in various fashions.
723 ADDR is the address to resume at, or -1 for resume where stopped.
724 SIGGNAL is the signal to give it, or 0 for none,
725 or -1 for act according to how it stopped.
726 STEP is nonzero if should trap after one instruction.
727 -1 means return after that and print nothing.
728 You should probably set various step_... variables
729 before calling here, if you are stepping.
731 You should call clear_proceed_status before calling proceed. */
734 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
739 step_start_function
= find_pc_function (read_pc ());
743 if (addr
== (CORE_ADDR
) -1)
745 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
746 /* There is a breakpoint at the address we will resume at,
747 step one instruction before inserting breakpoints so that
748 we do not stop right away (and report a second hit at this
751 else if (gdbarch_single_step_through_delay_p (current_gdbarch
)
752 && gdbarch_single_step_through_delay (current_gdbarch
,
753 get_current_frame ()))
754 /* We stepped onto an instruction that needs to be stepped
755 again before re-inserting the breakpoint, do so. */
764 fprintf_unfiltered (gdb_stdlog
,
765 "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n",
766 paddr_nz (addr
), siggnal
, step
);
768 /* In a multi-threaded task we may select another thread
769 and then continue or step.
771 But if the old thread was stopped at a breakpoint, it
772 will immediately cause another breakpoint stop without
773 any execution (i.e. it will report a breakpoint hit
774 incorrectly). So we must step over it first.
776 prepare_to_proceed checks the current thread against the thread
777 that reported the most recent event. If a step-over is required
778 it returns TRUE and sets the current thread to the old thread. */
779 if (prepare_to_proceed (step
))
783 /* We will get a trace trap after one instruction.
784 Continue it automatically and insert breakpoints then. */
788 insert_breakpoints ();
789 /* If we get here there was no call to error() in
790 insert breakpoints -- so they were inserted. */
791 breakpoints_inserted
= 1;
794 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
795 stop_signal
= siggnal
;
796 /* If this signal should not be seen by program,
797 give it zero. Used for debugging signals. */
798 else if (!signal_program
[stop_signal
])
799 stop_signal
= TARGET_SIGNAL_0
;
801 annotate_starting ();
803 /* Make sure that output from GDB appears before output from the
805 gdb_flush (gdb_stdout
);
807 /* Refresh prev_pc value just prior to resuming. This used to be
808 done in stop_stepping, however, setting prev_pc there did not handle
809 scenarios such as inferior function calls or returning from
810 a function via the return command. In those cases, the prev_pc
811 value was not set properly for subsequent commands. The prev_pc value
812 is used to initialize the starting line number in the ecs. With an
813 invalid value, the gdb next command ends up stopping at the position
814 represented by the next line table entry past our start position.
815 On platforms that generate one line table entry per line, this
816 is not a problem. However, on the ia64, the compiler generates
817 extraneous line table entries that do not increase the line number.
818 When we issue the gdb next command on the ia64 after an inferior call
819 or a return command, we often end up a few instructions forward, still
820 within the original line we started.
822 An attempt was made to have init_execution_control_state () refresh
823 the prev_pc value before calculating the line number. This approach
824 did not work because on platforms that use ptrace, the pc register
825 cannot be read unless the inferior is stopped. At that point, we
826 are not guaranteed the inferior is stopped and so the read_pc ()
827 call can fail. Setting the prev_pc value here ensures the value is
828 updated correctly when the inferior is stopped. */
829 prev_pc
= read_pc ();
831 /* Resume inferior. */
832 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
834 /* Wait for it to stop (if not standalone)
835 and in any case decode why it stopped, and act accordingly. */
836 /* Do this only if we are not using the event loop, or if the target
837 does not support asynchronous execution. */
838 if (!target_can_async_p ())
840 wait_for_inferior ();
846 /* Start remote-debugging of a machine over a serial link. */
849 start_remote (int from_tty
)
852 init_wait_for_inferior ();
853 stop_soon
= STOP_QUIETLY_REMOTE
;
856 /* Always go on waiting for the target, regardless of the mode. */
857 /* FIXME: cagney/1999-09-23: At present it isn't possible to
858 indicate to wait_for_inferior that a target should timeout if
859 nothing is returned (instead of just blocking). Because of this,
860 targets expecting an immediate response need to, internally, set
861 things up so that the target_wait() is forced to eventually
863 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
864 differentiate to its caller what the state of the target is after
865 the initial open has been performed. Here we're assuming that
866 the target has stopped. It should be possible to eventually have
867 target_open() return to the caller an indication that the target
868 is currently running and GDB state should be set to the same as
870 wait_for_inferior ();
872 /* Now that the inferior has stopped, do any bookkeeping like
873 loading shared libraries. We want to do this before normal_stop,
874 so that the displayed frame is up to date. */
875 post_create_inferior (¤t_target
, from_tty
);
880 /* Initialize static vars when a new inferior begins. */
883 init_wait_for_inferior (void)
885 /* These are meaningless until the first time through wait_for_inferior. */
888 breakpoints_inserted
= 0;
889 breakpoint_init_inferior (inf_starting
);
891 /* Don't confuse first call to proceed(). */
892 stop_signal
= TARGET_SIGNAL_0
;
894 /* The first resume is not following a fork/vfork/exec. */
895 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
897 clear_proceed_status ();
899 stepping_past_singlestep_breakpoint
= 0;
900 stepping_past_breakpoint
= 0;
903 /* This enum encodes possible reasons for doing a target_wait, so that
904 wfi can call target_wait in one place. (Ultimately the call will be
905 moved out of the infinite loop entirely.) */
909 infwait_normal_state
,
910 infwait_thread_hop_state
,
911 infwait_step_watch_state
,
912 infwait_nonstep_watch_state
915 /* Why did the inferior stop? Used to print the appropriate messages
916 to the interface from within handle_inferior_event(). */
917 enum inferior_stop_reason
919 /* Step, next, nexti, stepi finished. */
921 /* Inferior terminated by signal. */
923 /* Inferior exited. */
925 /* Inferior received signal, and user asked to be notified. */
929 /* This structure contains what used to be local variables in
930 wait_for_inferior. Probably many of them can return to being
931 locals in handle_inferior_event. */
933 struct execution_control_state
935 struct target_waitstatus ws
;
936 struct target_waitstatus
*wp
;
939 CORE_ADDR stop_func_start
;
940 CORE_ADDR stop_func_end
;
941 char *stop_func_name
;
942 struct symtab_and_line sal
;
944 struct symtab
*current_symtab
;
945 int handling_longjmp
; /* FIXME */
947 ptid_t saved_inferior_ptid
;
948 int step_after_step_resume_breakpoint
;
949 int stepping_through_solib_after_catch
;
950 bpstat stepping_through_solib_catchpoints
;
951 int new_thread_event
;
952 struct target_waitstatus tmpstatus
;
953 enum infwait_states infwait_state
;
958 void init_execution_control_state (struct execution_control_state
*ecs
);
960 void handle_inferior_event (struct execution_control_state
*ecs
);
962 static void step_into_function (struct execution_control_state
*ecs
);
963 static void insert_step_resume_breakpoint_at_frame (struct frame_info
*step_frame
);
964 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
965 static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
966 struct frame_id sr_id
);
967 static void stop_stepping (struct execution_control_state
*ecs
);
968 static void prepare_to_wait (struct execution_control_state
*ecs
);
969 static void keep_going (struct execution_control_state
*ecs
);
970 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
973 /* Wait for control to return from inferior to debugger.
974 If inferior gets a signal, we may decide to start it up again
975 instead of returning. That is why there is a loop in this function.
976 When this function actually returns it means the inferior
977 should be left stopped and GDB should read more commands. */
980 wait_for_inferior (void)
982 struct cleanup
*old_cleanups
;
983 struct execution_control_state ecss
;
984 struct execution_control_state
*ecs
;
987 fprintf_unfiltered (gdb_stdlog
, "infrun: wait_for_inferior\n");
989 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
990 &step_resume_breakpoint
);
992 /* wfi still stays in a loop, so it's OK just to take the address of
993 a local to get the ecs pointer. */
996 /* Fill in with reasonable starting values. */
997 init_execution_control_state (ecs
);
999 /* We'll update this if & when we switch to a new thread. */
1000 previous_inferior_ptid
= inferior_ptid
;
1002 overlay_cache_invalid
= 1;
1004 /* We have to invalidate the registers BEFORE calling target_wait
1005 because they can be loaded from the target while in target_wait.
1006 This makes remote debugging a bit more efficient for those
1007 targets that provide critical registers as part of their normal
1008 status mechanism. */
1010 registers_changed ();
1014 if (deprecated_target_wait_hook
)
1015 ecs
->ptid
= deprecated_target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
1017 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
1019 /* Now figure out what to do with the result of the result. */
1020 handle_inferior_event (ecs
);
1022 if (!ecs
->wait_some_more
)
1025 do_cleanups (old_cleanups
);
1028 /* Asynchronous version of wait_for_inferior. It is called by the
1029 event loop whenever a change of state is detected on the file
1030 descriptor corresponding to the target. It can be called more than
1031 once to complete a single execution command. In such cases we need
1032 to keep the state in a global variable ASYNC_ECSS. If it is the
1033 last time that this function is called for a single execution
1034 command, then report to the user that the inferior has stopped, and
1035 do the necessary cleanups. */
1037 struct execution_control_state async_ecss
;
1038 struct execution_control_state
*async_ecs
;
1041 fetch_inferior_event (void *client_data
)
1043 static struct cleanup
*old_cleanups
;
1045 async_ecs
= &async_ecss
;
1047 if (!async_ecs
->wait_some_more
)
1049 old_cleanups
= make_exec_cleanup (delete_step_resume_breakpoint
,
1050 &step_resume_breakpoint
);
1052 /* Fill in with reasonable starting values. */
1053 init_execution_control_state (async_ecs
);
1055 /* We'll update this if & when we switch to a new thread. */
1056 previous_inferior_ptid
= inferior_ptid
;
1058 overlay_cache_invalid
= 1;
1060 /* We have to invalidate the registers BEFORE calling target_wait
1061 because they can be loaded from the target while in target_wait.
1062 This makes remote debugging a bit more efficient for those
1063 targets that provide critical registers as part of their normal
1064 status mechanism. */
1066 registers_changed ();
1069 if (deprecated_target_wait_hook
)
1071 deprecated_target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1073 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1075 /* Now figure out what to do with the result of the result. */
1076 handle_inferior_event (async_ecs
);
1078 if (!async_ecs
->wait_some_more
)
1080 /* Do only the cleanups that have been added by this
1081 function. Let the continuations for the commands do the rest,
1082 if there are any. */
1083 do_exec_cleanups (old_cleanups
);
1085 if (step_multi
&& stop_step
)
1086 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1088 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1092 /* Prepare an execution control state for looping through a
1093 wait_for_inferior-type loop. */
1096 init_execution_control_state (struct execution_control_state
*ecs
)
1098 ecs
->another_trap
= 0;
1099 ecs
->random_signal
= 0;
1100 ecs
->step_after_step_resume_breakpoint
= 0;
1101 ecs
->handling_longjmp
= 0; /* FIXME */
1102 ecs
->stepping_through_solib_after_catch
= 0;
1103 ecs
->stepping_through_solib_catchpoints
= NULL
;
1104 ecs
->sal
= find_pc_line (prev_pc
, 0);
1105 ecs
->current_line
= ecs
->sal
.line
;
1106 ecs
->current_symtab
= ecs
->sal
.symtab
;
1107 ecs
->infwait_state
= infwait_normal_state
;
1108 ecs
->waiton_ptid
= pid_to_ptid (-1);
1109 ecs
->wp
= &(ecs
->ws
);
1112 /* Return the cached copy of the last pid/waitstatus returned by
1113 target_wait()/deprecated_target_wait_hook(). The data is actually
1114 cached by handle_inferior_event(), which gets called immediately
1115 after target_wait()/deprecated_target_wait_hook(). */
1118 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
1120 *ptidp
= target_last_wait_ptid
;
1121 *status
= target_last_waitstatus
;
1125 nullify_last_target_wait_ptid (void)
1127 target_last_wait_ptid
= minus_one_ptid
;
1130 /* Switch thread contexts, maintaining "infrun state". */
1133 context_switch (struct execution_control_state
*ecs
)
1135 /* Caution: it may happen that the new thread (or the old one!)
1136 is not in the thread list. In this case we must not attempt
1137 to "switch context", or we run the risk that our context may
1138 be lost. This may happen as a result of the target module
1139 mishandling thread creation. */
1143 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
1144 target_pid_to_str (inferior_ptid
));
1145 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
1146 target_pid_to_str (ecs
->ptid
));
1149 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1150 { /* Perform infrun state context switch: */
1151 /* Save infrun state for the old thread. */
1152 save_infrun_state (inferior_ptid
, prev_pc
,
1153 trap_expected
, step_resume_breakpoint
,
1155 step_range_end
, &step_frame_id
,
1156 ecs
->handling_longjmp
, ecs
->another_trap
,
1157 ecs
->stepping_through_solib_after_catch
,
1158 ecs
->stepping_through_solib_catchpoints
,
1159 ecs
->current_line
, ecs
->current_symtab
);
1161 /* Load infrun state for the new thread. */
1162 load_infrun_state (ecs
->ptid
, &prev_pc
,
1163 &trap_expected
, &step_resume_breakpoint
,
1165 &step_range_end
, &step_frame_id
,
1166 &ecs
->handling_longjmp
, &ecs
->another_trap
,
1167 &ecs
->stepping_through_solib_after_catch
,
1168 &ecs
->stepping_through_solib_catchpoints
,
1169 &ecs
->current_line
, &ecs
->current_symtab
);
1172 switch_to_thread (ecs
->ptid
);
1176 adjust_pc_after_break (struct execution_control_state
*ecs
)
1178 CORE_ADDR breakpoint_pc
;
1180 /* If this target does not decrement the PC after breakpoints, then
1181 we have nothing to do. */
1182 if (gdbarch_decr_pc_after_break (current_gdbarch
) == 0)
1185 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
1186 we aren't, just return.
1188 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
1189 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
1190 implemented by software breakpoints should be handled through the normal
1193 NOTE drow/2004-01-31: On some targets, breakpoints may generate
1194 different signals (SIGILL or SIGEMT for instance), but it is less
1195 clear where the PC is pointing afterwards. It may not match
1196 gdbarch_decr_pc_after_break. I don't know any specific target that
1197 generates these signals at breakpoints (the code has been in GDB since at
1198 least 1992) so I can not guess how to handle them here.
1200 In earlier versions of GDB, a target with
1201 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
1202 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
1203 target with both of these set in GDB history, and it seems unlikely to be
1204 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
1206 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
1209 if (ecs
->ws
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1212 /* Find the location where (if we've hit a breakpoint) the
1213 breakpoint would be. */
1214 breakpoint_pc
= read_pc_pid (ecs
->ptid
) - gdbarch_decr_pc_after_break
1217 /* Check whether there actually is a software breakpoint inserted
1218 at that location. */
1219 if (software_breakpoint_inserted_here_p (breakpoint_pc
))
1221 /* When using hardware single-step, a SIGTRAP is reported for both
1222 a completed single-step and a software breakpoint. Need to
1223 differentiate between the two, as the latter needs adjusting
1224 but the former does not.
1226 The SIGTRAP can be due to a completed hardware single-step only if
1227 - we didn't insert software single-step breakpoints
1228 - the thread to be examined is still the current thread
1229 - this thread is currently being stepped
1231 If any of these events did not occur, we must have stopped due
1232 to hitting a software breakpoint, and have to back up to the
1235 As a special case, we could have hardware single-stepped a
1236 software breakpoint. In this case (prev_pc == breakpoint_pc),
1237 we also need to back up to the breakpoint address. */
1239 if (singlestep_breakpoints_inserted_p
1240 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
1241 || !currently_stepping (ecs
)
1242 || prev_pc
== breakpoint_pc
)
1243 write_pc_pid (breakpoint_pc
, ecs
->ptid
);
1247 /* Given an execution control state that has been freshly filled in
1248 by an event from the inferior, figure out what it means and take
1249 appropriate action. */
1252 handle_inferior_event (struct execution_control_state
*ecs
)
1254 int sw_single_step_trap_p
= 0;
1255 int stopped_by_watchpoint
;
1256 int stepped_after_stopped_by_watchpoint
= 0;
1258 /* Cache the last pid/waitstatus. */
1259 target_last_wait_ptid
= ecs
->ptid
;
1260 target_last_waitstatus
= *ecs
->wp
;
1262 adjust_pc_after_break (ecs
);
1264 switch (ecs
->infwait_state
)
1266 case infwait_thread_hop_state
:
1268 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
1269 /* Cancel the waiton_ptid. */
1270 ecs
->waiton_ptid
= pid_to_ptid (-1);
1273 case infwait_normal_state
:
1275 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
1278 case infwait_step_watch_state
:
1280 fprintf_unfiltered (gdb_stdlog
,
1281 "infrun: infwait_step_watch_state\n");
1283 stepped_after_stopped_by_watchpoint
= 1;
1286 case infwait_nonstep_watch_state
:
1288 fprintf_unfiltered (gdb_stdlog
,
1289 "infrun: infwait_nonstep_watch_state\n");
1290 insert_breakpoints ();
1292 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1293 handle things like signals arriving and other things happening
1294 in combination correctly? */
1295 stepped_after_stopped_by_watchpoint
= 1;
1299 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1301 ecs
->infwait_state
= infwait_normal_state
;
1303 reinit_frame_cache ();
1305 /* If it's a new process, add it to the thread database */
1307 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
1308 && !ptid_equal (ecs
->ptid
, minus_one_ptid
)
1309 && !in_thread_list (ecs
->ptid
));
1311 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1312 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
1314 add_thread (ecs
->ptid
);
1316 ui_out_text (uiout
, "[New ");
1317 ui_out_text (uiout
, target_pid_or_tid_to_str (ecs
->ptid
));
1318 ui_out_text (uiout
, "]\n");
1321 switch (ecs
->ws
.kind
)
1323 case TARGET_WAITKIND_LOADED
:
1325 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
1326 /* Ignore gracefully during startup of the inferior, as it might
1327 be the shell which has just loaded some objects, otherwise
1328 add the symbols for the newly loaded objects. Also ignore at
1329 the beginning of an attach or remote session; we will query
1330 the full list of libraries once the connection is
1332 if (stop_soon
== NO_STOP_QUIETLY
)
1334 int breakpoints_were_inserted
;
1336 /* Remove breakpoints, SOLIB_ADD might adjust
1337 breakpoint addresses via breakpoint_re_set. */
1338 breakpoints_were_inserted
= breakpoints_inserted
;
1339 if (breakpoints_inserted
)
1340 remove_breakpoints ();
1341 breakpoints_inserted
= 0;
1343 /* Check for any newly added shared libraries if we're
1344 supposed to be adding them automatically. Switch
1345 terminal for any messages produced by
1346 breakpoint_re_set. */
1347 target_terminal_ours_for_output ();
1348 /* NOTE: cagney/2003-11-25: Make certain that the target
1349 stack's section table is kept up-to-date. Architectures,
1350 (e.g., PPC64), use the section table to perform
1351 operations such as address => section name and hence
1352 require the table to contain all sections (including
1353 those found in shared libraries). */
1354 /* NOTE: cagney/2003-11-25: Pass current_target and not
1355 exec_ops to SOLIB_ADD. This is because current GDB is
1356 only tooled to propagate section_table changes out from
1357 the "current_target" (see target_resize_to_sections), and
1358 not up from the exec stratum. This, of course, isn't
1359 right. "infrun.c" should only interact with the
1360 exec/process stratum, instead relying on the target stack
1361 to propagate relevant changes (stop, section table
1362 changed, ...) up to other layers. */
1364 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
1366 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
1368 target_terminal_inferior ();
1370 /* If requested, stop when the dynamic linker notifies
1371 gdb of events. This allows the user to get control
1372 and place breakpoints in initializer routines for
1373 dynamically loaded objects (among other things). */
1374 if (stop_on_solib_events
)
1376 stop_stepping (ecs
);
1380 /* NOTE drow/2007-05-11: This might be a good place to check
1381 for "catch load". */
1383 /* Reinsert breakpoints and continue. */
1384 if (breakpoints_were_inserted
)
1386 insert_breakpoints ();
1387 breakpoints_inserted
= 1;
1391 /* If we are skipping through a shell, or through shared library
1392 loading that we aren't interested in, resume the program. If
1393 we're running the program normally, also resume. But stop if
1394 we're attaching or setting up a remote connection. */
1395 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
1397 resume (0, TARGET_SIGNAL_0
);
1398 prepare_to_wait (ecs
);
1404 case TARGET_WAITKIND_SPURIOUS
:
1406 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
1407 resume (0, TARGET_SIGNAL_0
);
1408 prepare_to_wait (ecs
);
1411 case TARGET_WAITKIND_EXITED
:
1413 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXITED\n");
1414 target_terminal_ours (); /* Must do this before mourn anyway */
1415 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1417 /* Record the exit code in the convenience variable $_exitcode, so
1418 that the user can inspect this again later. */
1419 set_internalvar (lookup_internalvar ("_exitcode"),
1420 value_from_longest (builtin_type_int
,
1421 (LONGEST
) ecs
->ws
.value
.integer
));
1422 gdb_flush (gdb_stdout
);
1423 target_mourn_inferior ();
1424 singlestep_breakpoints_inserted_p
= 0;
1425 stop_print_frame
= 0;
1426 stop_stepping (ecs
);
1429 case TARGET_WAITKIND_SIGNALLED
:
1431 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SIGNALLED\n");
1432 stop_print_frame
= 0;
1433 stop_signal
= ecs
->ws
.value
.sig
;
1434 target_terminal_ours (); /* Must do this before mourn anyway */
1436 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1437 reach here unless the inferior is dead. However, for years
1438 target_kill() was called here, which hints that fatal signals aren't
1439 really fatal on some systems. If that's true, then some changes
1441 target_mourn_inferior ();
1443 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1444 singlestep_breakpoints_inserted_p
= 0;
1445 stop_stepping (ecs
);
1448 /* The following are the only cases in which we keep going;
1449 the above cases end in a continue or goto. */
1450 case TARGET_WAITKIND_FORKED
:
1451 case TARGET_WAITKIND_VFORKED
:
1453 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
1454 stop_signal
= TARGET_SIGNAL_TRAP
;
1455 pending_follow
.kind
= ecs
->ws
.kind
;
1457 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1458 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1460 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
1462 context_switch (ecs
);
1463 reinit_frame_cache ();
1466 stop_pc
= read_pc ();
1468 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
1470 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1472 /* If no catchpoint triggered for this, then keep going. */
1473 if (ecs
->random_signal
)
1475 stop_signal
= TARGET_SIGNAL_0
;
1479 goto process_event_stop_test
;
1481 case TARGET_WAITKIND_EXECD
:
1483 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
1484 stop_signal
= TARGET_SIGNAL_TRAP
;
1486 /* NOTE drow/2002-12-05: This code should be pushed down into the
1487 target_wait function. Until then following vfork on HP/UX 10.20
1488 is probably broken by this. Of course, it's broken anyway. */
1489 /* Is this a target which reports multiple exec events per actual
1490 call to exec()? (HP-UX using ptrace does, for example.) If so,
1491 ignore all but the last one. Just resume the exec'r, and wait
1492 for the next exec event. */
1493 if (inferior_ignoring_leading_exec_events
)
1495 inferior_ignoring_leading_exec_events
--;
1496 target_resume (ecs
->ptid
, 0, TARGET_SIGNAL_0
);
1497 prepare_to_wait (ecs
);
1500 inferior_ignoring_leading_exec_events
=
1501 target_reported_exec_events_per_exec_call () - 1;
1503 pending_follow
.execd_pathname
=
1504 savestring (ecs
->ws
.value
.execd_pathname
,
1505 strlen (ecs
->ws
.value
.execd_pathname
));
1507 /* This causes the eventpoints and symbol table to be reset. Must
1508 do this now, before trying to determine whether to stop. */
1509 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1510 xfree (pending_follow
.execd_pathname
);
1512 stop_pc
= read_pc_pid (ecs
->ptid
);
1513 ecs
->saved_inferior_ptid
= inferior_ptid
;
1514 inferior_ptid
= ecs
->ptid
;
1516 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
1518 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1519 inferior_ptid
= ecs
->saved_inferior_ptid
;
1521 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
1523 context_switch (ecs
);
1524 reinit_frame_cache ();
1527 /* If no catchpoint triggered for this, then keep going. */
1528 if (ecs
->random_signal
)
1530 stop_signal
= TARGET_SIGNAL_0
;
1534 goto process_event_stop_test
;
1536 /* Be careful not to try to gather much state about a thread
1537 that's in a syscall. It's frequently a losing proposition. */
1538 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1540 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
1541 resume (0, TARGET_SIGNAL_0
);
1542 prepare_to_wait (ecs
);
1545 /* Before examining the threads further, step this thread to
1546 get it entirely out of the syscall. (We get notice of the
1547 event when the thread is just on the verge of exiting a
1548 syscall. Stepping one instruction seems to get it back
1550 case TARGET_WAITKIND_SYSCALL_RETURN
:
1552 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
1553 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1554 prepare_to_wait (ecs
);
1557 case TARGET_WAITKIND_STOPPED
:
1559 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
1560 stop_signal
= ecs
->ws
.value
.sig
;
1563 /* We had an event in the inferior, but we are not interested
1564 in handling it at this level. The lower layers have already
1565 done what needs to be done, if anything.
1567 One of the possible circumstances for this is when the
1568 inferior produces output for the console. The inferior has
1569 not stopped, and we are ignoring the event. Another possible
1570 circumstance is any event which the lower level knows will be
1571 reported multiple times without an intervening resume. */
1572 case TARGET_WAITKIND_IGNORE
:
1574 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
1575 prepare_to_wait (ecs
);
1579 /* We may want to consider not doing a resume here in order to give
1580 the user a chance to play with the new thread. It might be good
1581 to make that a user-settable option. */
1583 /* At this point, all threads are stopped (happens automatically in
1584 either the OS or the native code). Therefore we need to continue
1585 all threads in order to make progress. */
1586 if (ecs
->new_thread_event
)
1588 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1589 prepare_to_wait (ecs
);
1593 stop_pc
= read_pc_pid (ecs
->ptid
);
1596 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = 0x%s\n", paddr_nz (stop_pc
));
1598 if (stepping_past_singlestep_breakpoint
)
1600 gdb_assert (singlestep_breakpoints_inserted_p
);
1601 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
1602 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
1604 stepping_past_singlestep_breakpoint
= 0;
1606 /* We've either finished single-stepping past the single-step
1607 breakpoint, or stopped for some other reason. It would be nice if
1608 we could tell, but we can't reliably. */
1609 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1612 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping_past_singlestep_breakpoint\n");
1613 /* Pull the single step breakpoints out of the target. */
1614 remove_single_step_breakpoints ();
1615 singlestep_breakpoints_inserted_p
= 0;
1617 ecs
->random_signal
= 0;
1619 ecs
->ptid
= saved_singlestep_ptid
;
1620 context_switch (ecs
);
1621 if (deprecated_context_hook
)
1622 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
1624 resume (1, TARGET_SIGNAL_0
);
1625 prepare_to_wait (ecs
);
1630 stepping_past_singlestep_breakpoint
= 0;
1632 if (stepping_past_breakpoint
)
1634 stepping_past_breakpoint
= 0;
1636 /* If we stopped for some other reason than single-stepping, ignore
1637 the fact that we were supposed to switch back. */
1638 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1641 fprintf_unfiltered (gdb_stdlog
,
1642 "infrun: stepping_past_breakpoint\n");
1644 /* Pull the single step breakpoints out of the target. */
1645 if (singlestep_breakpoints_inserted_p
)
1647 remove_single_step_breakpoints ();
1648 singlestep_breakpoints_inserted_p
= 0;
1651 /* Note: We do not call context_switch at this point, as the
1652 context is already set up for stepping the original thread. */
1653 switch_to_thread (stepping_past_breakpoint_ptid
);
1654 /* Suppress spurious "Switching to ..." message. */
1655 previous_inferior_ptid
= inferior_ptid
;
1657 resume (1, TARGET_SIGNAL_0
);
1658 prepare_to_wait (ecs
);
1663 /* See if a thread hit a thread-specific breakpoint that was meant for
1664 another thread. If so, then step that thread past the breakpoint,
1667 if (stop_signal
== TARGET_SIGNAL_TRAP
)
1669 int thread_hop_needed
= 0;
1671 /* Check if a regular breakpoint has been hit before checking
1672 for a potential single step breakpoint. Otherwise, GDB will
1673 not see this breakpoint hit when stepping onto breakpoints. */
1674 if (breakpoints_inserted
&& breakpoint_here_p (stop_pc
))
1676 ecs
->random_signal
= 0;
1677 if (!breakpoint_thread_match (stop_pc
, ecs
->ptid
))
1678 thread_hop_needed
= 1;
1680 else if (singlestep_breakpoints_inserted_p
)
1682 /* We have not context switched yet, so this should be true
1683 no matter which thread hit the singlestep breakpoint. */
1684 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
1686 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
1688 target_pid_to_str (ecs
->ptid
));
1690 ecs
->random_signal
= 0;
1691 /* The call to in_thread_list is necessary because PTIDs sometimes
1692 change when we go from single-threaded to multi-threaded. If
1693 the singlestep_ptid is still in the list, assume that it is
1694 really different from ecs->ptid. */
1695 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
1696 && in_thread_list (singlestep_ptid
))
1698 /* If the PC of the thread we were trying to single-step
1699 has changed, discard this event (which we were going
1700 to ignore anyway), and pretend we saw that thread
1701 trap. This prevents us continuously moving the
1702 single-step breakpoint forward, one instruction at a
1703 time. If the PC has changed, then the thread we were
1704 trying to single-step has trapped or been signalled,
1705 but the event has not been reported to GDB yet.
1707 There might be some cases where this loses signal
1708 information, if a signal has arrived at exactly the
1709 same time that the PC changed, but this is the best
1710 we can do with the information available. Perhaps we
1711 should arrange to report all events for all threads
1712 when they stop, or to re-poll the remote looking for
1713 this particular thread (i.e. temporarily enable
1715 if (read_pc_pid (singlestep_ptid
) != singlestep_pc
)
1718 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
1719 " but expected thread advanced also\n");
1721 /* The current context still belongs to
1722 singlestep_ptid. Don't swap here, since that's
1723 the context we want to use. Just fudge our
1724 state and continue. */
1725 ecs
->ptid
= singlestep_ptid
;
1726 stop_pc
= read_pc_pid (ecs
->ptid
);
1731 fprintf_unfiltered (gdb_stdlog
,
1732 "infrun: unexpected thread\n");
1734 thread_hop_needed
= 1;
1735 stepping_past_singlestep_breakpoint
= 1;
1736 saved_singlestep_ptid
= singlestep_ptid
;
1741 if (thread_hop_needed
)
1746 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
1748 /* Saw a breakpoint, but it was hit by the wrong thread.
1751 if (singlestep_breakpoints_inserted_p
)
1753 /* Pull the single step breakpoints out of the target. */
1754 remove_single_step_breakpoints ();
1755 singlestep_breakpoints_inserted_p
= 0;
1758 remove_status
= remove_breakpoints ();
1759 /* Did we fail to remove breakpoints? If so, try
1760 to set the PC past the bp. (There's at least
1761 one situation in which we can fail to remove
1762 the bp's: On HP-UX's that use ttrace, we can't
1763 change the address space of a vforking child
1764 process until the child exits (well, okay, not
1765 then either :-) or execs. */
1766 if (remove_status
!= 0)
1768 /* FIXME! This is obviously non-portable! */
1769 write_pc_pid (stop_pc
+ 4, ecs
->ptid
);
1770 /* We need to restart all the threads now,
1771 * unles we're running in scheduler-locked mode.
1772 * Use currently_stepping to determine whether to
1775 /* FIXME MVS: is there any reason not to call resume()? */
1776 if (scheduler_mode
== schedlock_on
)
1777 target_resume (ecs
->ptid
,
1778 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1780 target_resume (RESUME_ALL
,
1781 currently_stepping (ecs
), TARGET_SIGNAL_0
);
1782 prepare_to_wait (ecs
);
1787 breakpoints_inserted
= 0;
1788 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
1789 context_switch (ecs
);
1790 ecs
->waiton_ptid
= ecs
->ptid
;
1791 ecs
->wp
= &(ecs
->ws
);
1792 ecs
->another_trap
= 1;
1794 ecs
->infwait_state
= infwait_thread_hop_state
;
1796 registers_changed ();
1800 else if (singlestep_breakpoints_inserted_p
)
1802 sw_single_step_trap_p
= 1;
1803 ecs
->random_signal
= 0;
1807 ecs
->random_signal
= 1;
1809 /* See if something interesting happened to the non-current thread. If
1810 so, then switch to that thread. */
1811 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
1814 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
1816 context_switch (ecs
);
1818 if (deprecated_context_hook
)
1819 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
1822 if (singlestep_breakpoints_inserted_p
)
1824 /* Pull the single step breakpoints out of the target. */
1825 remove_single_step_breakpoints ();
1826 singlestep_breakpoints_inserted_p
= 0;
1829 if (stepped_after_stopped_by_watchpoint
)
1830 stopped_by_watchpoint
= 0;
1832 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
1834 /* If necessary, step over this watchpoint. We'll be back to display
1836 if (stopped_by_watchpoint
1837 && (HAVE_STEPPABLE_WATCHPOINT
1838 || gdbarch_have_nonsteppable_watchpoint (current_gdbarch
)))
1841 fprintf_unfiltered (gdb_stdlog
, "infrun: STOPPED_BY_WATCHPOINT\n");
1843 /* At this point, we are stopped at an instruction which has
1844 attempted to write to a piece of memory under control of
1845 a watchpoint. The instruction hasn't actually executed
1846 yet. If we were to evaluate the watchpoint expression
1847 now, we would get the old value, and therefore no change
1848 would seem to have occurred.
1850 In order to make watchpoints work `right', we really need
1851 to complete the memory write, and then evaluate the
1852 watchpoint expression. We do this by single-stepping the
1855 It may not be necessary to disable the watchpoint to stop over
1856 it. For example, the PA can (with some kernel cooperation)
1857 single step over a watchpoint without disabling the watchpoint.
1859 It is far more common to need to disable a watchpoint to step
1860 the inferior over it. If we have non-steppable watchpoints,
1861 we must disable the current watchpoint; it's simplest to
1862 disable all watchpoints and breakpoints. */
1864 if (!HAVE_STEPPABLE_WATCHPOINT
)
1865 remove_breakpoints ();
1866 registers_changed ();
1867 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
1868 ecs
->waiton_ptid
= ecs
->ptid
;
1869 if (HAVE_STEPPABLE_WATCHPOINT
)
1870 ecs
->infwait_state
= infwait_step_watch_state
;
1872 ecs
->infwait_state
= infwait_nonstep_watch_state
;
1873 prepare_to_wait (ecs
);
1877 ecs
->stop_func_start
= 0;
1878 ecs
->stop_func_end
= 0;
1879 ecs
->stop_func_name
= 0;
1880 /* Don't care about return value; stop_func_start and stop_func_name
1881 will both be 0 if it doesn't work. */
1882 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
1883 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
1884 ecs
->stop_func_start
1885 += gdbarch_deprecated_function_start_offset (current_gdbarch
);
1886 ecs
->another_trap
= 0;
1887 bpstat_clear (&stop_bpstat
);
1889 stop_stack_dummy
= 0;
1890 stop_print_frame
= 1;
1891 ecs
->random_signal
= 0;
1892 stopped_by_random_signal
= 0;
1894 if (stop_signal
== TARGET_SIGNAL_TRAP
1896 && gdbarch_single_step_through_delay_p (current_gdbarch
)
1897 && currently_stepping (ecs
))
1899 /* We're trying to step of a breakpoint. Turns out that we're
1900 also on an instruction that needs to be stepped multiple
1901 times before it's been fully executing. E.g., architectures
1902 with a delay slot. It needs to be stepped twice, once for
1903 the instruction and once for the delay slot. */
1904 int step_through_delay
1905 = gdbarch_single_step_through_delay (current_gdbarch
,
1906 get_current_frame ());
1907 if (debug_infrun
&& step_through_delay
)
1908 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
1909 if (step_range_end
== 0 && step_through_delay
)
1911 /* The user issued a continue when stopped at a breakpoint.
1912 Set up for another trap and get out of here. */
1913 ecs
->another_trap
= 1;
1917 else if (step_through_delay
)
1919 /* The user issued a step when stopped at a breakpoint.
1920 Maybe we should stop, maybe we should not - the delay
1921 slot *might* correspond to a line of source. In any
1922 case, don't decide that here, just set ecs->another_trap,
1923 making sure we single-step again before breakpoints are
1925 ecs
->another_trap
= 1;
1929 /* Look at the cause of the stop, and decide what to do.
1930 The alternatives are:
1931 1) break; to really stop and return to the debugger,
1932 2) drop through to start up again
1933 (set ecs->another_trap to 1 to single step once)
1934 3) set ecs->random_signal to 1, and the decision between 1 and 2
1935 will be made according to the signal handling tables. */
1937 /* First, distinguish signals caused by the debugger from signals
1938 that have to do with the program's own actions. Note that
1939 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
1940 on the operating system version. Here we detect when a SIGILL or
1941 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
1942 something similar for SIGSEGV, since a SIGSEGV will be generated
1943 when we're trying to execute a breakpoint instruction on a
1944 non-executable stack. This happens for call dummy breakpoints
1945 for architectures like SPARC that place call dummies on the
1948 if (stop_signal
== TARGET_SIGNAL_TRAP
1949 || (breakpoints_inserted
1950 && (stop_signal
== TARGET_SIGNAL_ILL
1951 || stop_signal
== TARGET_SIGNAL_SEGV
1952 || stop_signal
== TARGET_SIGNAL_EMT
))
1953 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
1954 || stop_soon
== STOP_QUIETLY_REMOTE
)
1956 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
1959 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
1960 stop_print_frame
= 0;
1961 stop_stepping (ecs
);
1965 /* This is originated from start_remote(), start_inferior() and
1966 shared libraries hook functions. */
1967 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
1970 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
1971 stop_stepping (ecs
);
1975 /* This originates from attach_command(). We need to overwrite
1976 the stop_signal here, because some kernels don't ignore a
1977 SIGSTOP in a subsequent ptrace(PTRACE_SONT,SOGSTOP) call.
1978 See more comments in inferior.h. */
1979 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
)
1981 stop_stepping (ecs
);
1982 if (stop_signal
== TARGET_SIGNAL_STOP
)
1983 stop_signal
= TARGET_SIGNAL_0
;
1987 /* Don't even think about breakpoints if just proceeded over a
1989 if (stop_signal
== TARGET_SIGNAL_TRAP
&& trap_expected
)
1992 fprintf_unfiltered (gdb_stdlog
, "infrun: trap expected\n");
1993 bpstat_clear (&stop_bpstat
);
1997 /* See if there is a breakpoint at the current PC. */
1998 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2000 /* Following in case break condition called a
2002 stop_print_frame
= 1;
2005 /* NOTE: cagney/2003-03-29: These two checks for a random signal
2006 at one stage in the past included checks for an inferior
2007 function call's call dummy's return breakpoint. The original
2008 comment, that went with the test, read:
2010 ``End of a stack dummy. Some systems (e.g. Sony news) give
2011 another signal besides SIGTRAP, so check here as well as
2014 If someone ever tries to get get call dummys on a
2015 non-executable stack to work (where the target would stop
2016 with something like a SIGSEGV), then those tests might need
2017 to be re-instated. Given, however, that the tests were only
2018 enabled when momentary breakpoints were not being used, I
2019 suspect that it won't be the case.
2021 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
2022 be necessary for call dummies on a non-executable stack on
2025 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2027 = !(bpstat_explains_signal (stop_bpstat
)
2029 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2032 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
2033 if (!ecs
->random_signal
)
2034 stop_signal
= TARGET_SIGNAL_TRAP
;
2038 /* When we reach this point, we've pretty much decided
2039 that the reason for stopping must've been a random
2040 (unexpected) signal. */
2043 ecs
->random_signal
= 1;
2045 process_event_stop_test
:
2046 /* For the program's own signals, act according to
2047 the signal handling tables. */
2049 if (ecs
->random_signal
)
2051 /* Signal not for debugging purposes. */
2055 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n", stop_signal
);
2057 stopped_by_random_signal
= 1;
2059 if (signal_print
[stop_signal
])
2062 target_terminal_ours_for_output ();
2063 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2065 if (signal_stop
[stop_signal
])
2067 stop_stepping (ecs
);
2070 /* If not going to stop, give terminal back
2071 if we took it away. */
2073 target_terminal_inferior ();
2075 /* Clear the signal if it should not be passed. */
2076 if (signal_program
[stop_signal
] == 0)
2077 stop_signal
= TARGET_SIGNAL_0
;
2079 if (prev_pc
== read_pc ()
2080 && !breakpoints_inserted
2081 && breakpoint_here_p (read_pc ())
2082 && step_resume_breakpoint
== NULL
)
2084 /* We were just starting a new sequence, attempting to
2085 single-step off of a breakpoint and expecting a SIGTRAP.
2086 Intead this signal arrives. This signal will take us out
2087 of the stepping range so GDB needs to remember to, when
2088 the signal handler returns, resume stepping off that
2090 /* To simplify things, "continue" is forced to use the same
2091 code paths as single-step - set a breakpoint at the
2092 signal return address and then, once hit, step off that
2095 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2096 ecs
->step_after_step_resume_breakpoint
= 1;
2101 if (step_range_end
!= 0
2102 && stop_signal
!= TARGET_SIGNAL_0
2103 && stop_pc
>= step_range_start
&& stop_pc
< step_range_end
2104 && frame_id_eq (get_frame_id (get_current_frame ()),
2106 && step_resume_breakpoint
== NULL
)
2108 /* The inferior is about to take a signal that will take it
2109 out of the single step range. Set a breakpoint at the
2110 current PC (which is presumably where the signal handler
2111 will eventually return) and then allow the inferior to
2114 Note that this is only needed for a signal delivered
2115 while in the single-step range. Nested signals aren't a
2116 problem as they eventually all return. */
2117 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2122 /* Note: step_resume_breakpoint may be non-NULL. This occures
2123 when either there's a nested signal, or when there's a
2124 pending signal enabled just as the signal handler returns
2125 (leaving the inferior at the step-resume-breakpoint without
2126 actually executing it). Either way continue until the
2127 breakpoint is really hit. */
2132 /* Handle cases caused by hitting a breakpoint. */
2134 CORE_ADDR jmp_buf_pc
;
2135 struct bpstat_what what
;
2137 what
= bpstat_what (stop_bpstat
);
2139 if (what
.call_dummy
)
2141 stop_stack_dummy
= 1;
2144 switch (what
.main_action
)
2146 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2147 /* If we hit the breakpoint at longjmp, disable it for the
2148 duration of this command. Then, install a temporary
2149 breakpoint at the target of the jmp_buf. */
2151 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
2152 disable_longjmp_breakpoint ();
2153 remove_breakpoints ();
2154 breakpoints_inserted
= 0;
2155 if (!gdbarch_get_longjmp_target_p (current_gdbarch
)
2156 || !gdbarch_get_longjmp_target (current_gdbarch
,
2157 get_current_frame (), &jmp_buf_pc
))
2163 /* Need to blow away step-resume breakpoint, as it
2164 interferes with us */
2165 if (step_resume_breakpoint
!= NULL
)
2167 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2170 set_longjmp_resume_breakpoint (jmp_buf_pc
, null_frame_id
);
2171 ecs
->handling_longjmp
= 1; /* FIXME */
2175 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2176 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
:
2178 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
2179 remove_breakpoints ();
2180 breakpoints_inserted
= 0;
2181 disable_longjmp_breakpoint ();
2182 ecs
->handling_longjmp
= 0; /* FIXME */
2183 if (what
.main_action
== BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
)
2185 /* else fallthrough */
2187 case BPSTAT_WHAT_SINGLE
:
2189 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
2190 if (breakpoints_inserted
)
2191 remove_breakpoints ();
2192 breakpoints_inserted
= 0;
2193 ecs
->another_trap
= 1;
2194 /* Still need to check other stuff, at least the case
2195 where we are stepping and step out of the right range. */
2198 case BPSTAT_WHAT_STOP_NOISY
:
2200 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
2201 stop_print_frame
= 1;
2203 /* We are about to nuke the step_resume_breakpointt via the
2204 cleanup chain, so no need to worry about it here. */
2206 stop_stepping (ecs
);
2209 case BPSTAT_WHAT_STOP_SILENT
:
2211 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
2212 stop_print_frame
= 0;
2214 /* We are about to nuke the step_resume_breakpoin via the
2215 cleanup chain, so no need to worry about it here. */
2217 stop_stepping (ecs
);
2220 case BPSTAT_WHAT_STEP_RESUME
:
2221 /* This proably demands a more elegant solution, but, yeah
2224 This function's use of the simple variable
2225 step_resume_breakpoint doesn't seem to accomodate
2226 simultaneously active step-resume bp's, although the
2227 breakpoint list certainly can.
2229 If we reach here and step_resume_breakpoint is already
2230 NULL, then apparently we have multiple active
2231 step-resume bp's. We'll just delete the breakpoint we
2232 stopped at, and carry on.
2234 Correction: what the code currently does is delete a
2235 step-resume bp, but it makes no effort to ensure that
2236 the one deleted is the one currently stopped at. MVS */
2239 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
2241 if (step_resume_breakpoint
== NULL
)
2243 step_resume_breakpoint
=
2244 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2246 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2247 if (ecs
->step_after_step_resume_breakpoint
)
2249 /* Back when the step-resume breakpoint was inserted, we
2250 were trying to single-step off a breakpoint. Go back
2252 ecs
->step_after_step_resume_breakpoint
= 0;
2253 remove_breakpoints ();
2254 breakpoints_inserted
= 0;
2255 ecs
->another_trap
= 1;
2261 case BPSTAT_WHAT_CHECK_SHLIBS
:
2262 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2265 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
2266 /* Remove breakpoints, we eventually want to step over the
2267 shlib event breakpoint, and SOLIB_ADD might adjust
2268 breakpoint addresses via breakpoint_re_set. */
2269 if (breakpoints_inserted
)
2270 remove_breakpoints ();
2271 breakpoints_inserted
= 0;
2273 /* Check for any newly added shared libraries if we're
2274 supposed to be adding them automatically. Switch
2275 terminal for any messages produced by
2276 breakpoint_re_set. */
2277 target_terminal_ours_for_output ();
2278 /* NOTE: cagney/2003-11-25: Make certain that the target
2279 stack's section table is kept up-to-date. Architectures,
2280 (e.g., PPC64), use the section table to perform
2281 operations such as address => section name and hence
2282 require the table to contain all sections (including
2283 those found in shared libraries). */
2284 /* NOTE: cagney/2003-11-25: Pass current_target and not
2285 exec_ops to SOLIB_ADD. This is because current GDB is
2286 only tooled to propagate section_table changes out from
2287 the "current_target" (see target_resize_to_sections), and
2288 not up from the exec stratum. This, of course, isn't
2289 right. "infrun.c" should only interact with the
2290 exec/process stratum, instead relying on the target stack
2291 to propagate relevant changes (stop, section table
2292 changed, ...) up to other layers. */
2294 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
2296 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
2298 target_terminal_inferior ();
2300 /* If requested, stop when the dynamic linker notifies
2301 gdb of events. This allows the user to get control
2302 and place breakpoints in initializer routines for
2303 dynamically loaded objects (among other things). */
2304 if (stop_on_solib_events
|| stop_stack_dummy
)
2306 stop_stepping (ecs
);
2310 /* If we stopped due to an explicit catchpoint, then the
2311 (see above) call to SOLIB_ADD pulled in any symbols
2312 from a newly-loaded library, if appropriate.
2314 We do want the inferior to stop, but not where it is
2315 now, which is in the dynamic linker callback. Rather,
2316 we would like it stop in the user's program, just after
2317 the call that caused this catchpoint to trigger. That
2318 gives the user a more useful vantage from which to
2319 examine their program's state. */
2320 else if (what
.main_action
2321 == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2323 /* ??rehrauer: If I could figure out how to get the
2324 right return PC from here, we could just set a temp
2325 breakpoint and resume. I'm not sure we can without
2326 cracking open the dld's shared libraries and sniffing
2327 their unwind tables and text/data ranges, and that's
2328 not a terribly portable notion.
2330 Until that time, we must step the inferior out of the
2331 dld callback, and also out of the dld itself (and any
2332 code or stubs in libdld.sl, such as "shl_load" and
2333 friends) until we reach non-dld code. At that point,
2334 we can stop stepping. */
2335 bpstat_get_triggered_catchpoints (stop_bpstat
,
2337 stepping_through_solib_catchpoints
);
2338 ecs
->stepping_through_solib_after_catch
= 1;
2340 /* Be sure to lift all breakpoints, so the inferior does
2341 actually step past this point... */
2342 ecs
->another_trap
= 1;
2347 /* We want to step over this breakpoint, then keep going. */
2348 ecs
->another_trap
= 1;
2354 case BPSTAT_WHAT_LAST
:
2355 /* Not a real code, but listed here to shut up gcc -Wall. */
2357 case BPSTAT_WHAT_KEEP_CHECKING
:
2362 /* We come here if we hit a breakpoint but should not
2363 stop for it. Possibly we also were stepping
2364 and should stop for that. So fall through and
2365 test for stepping. But, if not stepping,
2368 /* Are we stepping to get the inferior out of the dynamic linker's
2369 hook (and possibly the dld itself) after catching a shlib
2371 if (ecs
->stepping_through_solib_after_catch
)
2373 #if defined(SOLIB_ADD)
2374 /* Have we reached our destination? If not, keep going. */
2375 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2378 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping in dynamic linker\n");
2379 ecs
->another_trap
= 1;
2385 fprintf_unfiltered (gdb_stdlog
, "infrun: step past dynamic linker\n");
2386 /* Else, stop and report the catchpoint(s) whose triggering
2387 caused us to begin stepping. */
2388 ecs
->stepping_through_solib_after_catch
= 0;
2389 bpstat_clear (&stop_bpstat
);
2390 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2391 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2392 stop_print_frame
= 1;
2393 stop_stepping (ecs
);
2397 if (step_resume_breakpoint
)
2400 fprintf_unfiltered (gdb_stdlog
,
2401 "infrun: step-resume breakpoint is inserted\n");
2403 /* Having a step-resume breakpoint overrides anything
2404 else having to do with stepping commands until
2405 that breakpoint is reached. */
2410 if (step_range_end
== 0)
2413 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
2414 /* Likewise if we aren't even stepping. */
2419 /* If stepping through a line, keep going if still within it.
2421 Note that step_range_end is the address of the first instruction
2422 beyond the step range, and NOT the address of the last instruction
2424 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
2427 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping inside range [0x%s-0x%s]\n",
2428 paddr_nz (step_range_start
),
2429 paddr_nz (step_range_end
));
2434 /* We stepped out of the stepping range. */
2436 /* If we are stepping at the source level and entered the runtime
2437 loader dynamic symbol resolution code, we keep on single stepping
2438 until we exit the run time loader code and reach the callee's
2440 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2441 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
2442 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
)
2444 && in_solib_dynsym_resolve_code (stop_pc
)
2448 CORE_ADDR pc_after_resolver
=
2449 gdbarch_skip_solib_resolver (current_gdbarch
, stop_pc
);
2452 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into dynsym resolve code\n");
2454 if (pc_after_resolver
)
2456 /* Set up a step-resume breakpoint at the address
2457 indicated by SKIP_SOLIB_RESOLVER. */
2458 struct symtab_and_line sr_sal
;
2460 sr_sal
.pc
= pc_after_resolver
;
2462 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
2469 if (step_range_end
!= 1
2470 && (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2471 || step_over_calls
== STEP_OVER_ALL
)
2472 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME
)
2475 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into signal trampoline\n");
2476 /* The inferior, while doing a "step" or "next", has ended up in
2477 a signal trampoline (either by a signal being delivered or by
2478 the signal handler returning). Just single-step until the
2479 inferior leaves the trampoline (either by calling the handler
2485 /* Check for subroutine calls. The check for the current frame
2486 equalling the step ID is not necessary - the check of the
2487 previous frame's ID is sufficient - but it is a common case and
2488 cheaper than checking the previous frame's ID.
2490 NOTE: frame_id_eq will never report two invalid frame IDs as
2491 being equal, so to get into this block, both the current and
2492 previous frame must have valid frame IDs. */
2493 if (!frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id
)
2494 && frame_id_eq (frame_unwind_id (get_current_frame ()), step_frame_id
))
2496 CORE_ADDR real_stop_pc
;
2499 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
2501 if ((step_over_calls
== STEP_OVER_NONE
)
2502 || ((step_range_end
== 1)
2503 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2505 /* I presume that step_over_calls is only 0 when we're
2506 supposed to be stepping at the assembly language level
2507 ("stepi"). Just stop. */
2508 /* Also, maybe we just did a "nexti" inside a prolog, so we
2509 thought it was a subroutine call but it was not. Stop as
2512 print_stop_reason (END_STEPPING_RANGE
, 0);
2513 stop_stepping (ecs
);
2517 if (step_over_calls
== STEP_OVER_ALL
)
2519 /* We're doing a "next", set a breakpoint at callee's return
2520 address (the address at which the caller will
2522 insert_step_resume_breakpoint_at_caller (get_current_frame ());
2527 /* If we are in a function call trampoline (a stub between the
2528 calling routine and the real function), locate the real
2529 function. That's what tells us (a) whether we want to step
2530 into it at all, and (b) what prologue we want to run to the
2531 end of, if we do step into it. */
2532 real_stop_pc
= skip_language_trampoline (get_current_frame (), stop_pc
);
2533 if (real_stop_pc
== 0)
2534 real_stop_pc
= gdbarch_skip_trampoline_code
2535 (current_gdbarch
, get_current_frame (), stop_pc
);
2536 if (real_stop_pc
!= 0)
2537 ecs
->stop_func_start
= real_stop_pc
;
2540 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
2541 IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs
->stop_func_start
)
2543 in_solib_dynsym_resolve_code (ecs
->stop_func_start
)
2547 struct symtab_and_line sr_sal
;
2549 sr_sal
.pc
= ecs
->stop_func_start
;
2551 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
2556 /* If we have line number information for the function we are
2557 thinking of stepping into, step into it.
2559 If there are several symtabs at that PC (e.g. with include
2560 files), just want to know whether *any* of them have line
2561 numbers. find_pc_line handles this. */
2563 struct symtab_and_line tmp_sal
;
2565 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2566 if (tmp_sal
.line
!= 0)
2568 step_into_function (ecs
);
2573 /* If we have no line number and the step-stop-if-no-debug is
2574 set, we stop the step so that the user has a chance to switch
2575 in assembly mode. */
2576 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2579 print_stop_reason (END_STEPPING_RANGE
, 0);
2580 stop_stepping (ecs
);
2584 /* Set a breakpoint at callee's return address (the address at
2585 which the caller will resume). */
2586 insert_step_resume_breakpoint_at_caller (get_current_frame ());
2591 /* If we're in the return path from a shared library trampoline,
2592 we want to proceed through the trampoline when stepping. */
2593 if (gdbarch_in_solib_return_trampoline (current_gdbarch
,
2594 stop_pc
, ecs
->stop_func_name
))
2596 /* Determine where this trampoline returns. */
2597 CORE_ADDR real_stop_pc
;
2598 real_stop_pc
= gdbarch_skip_trampoline_code
2599 (current_gdbarch
, get_current_frame (), stop_pc
);
2602 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into solib return tramp\n");
2604 /* Only proceed through if we know where it's going. */
2607 /* And put the step-breakpoint there and go until there. */
2608 struct symtab_and_line sr_sal
;
2610 init_sal (&sr_sal
); /* initialize to zeroes */
2611 sr_sal
.pc
= real_stop_pc
;
2612 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2614 /* Do not specify what the fp should be when we stop since
2615 on some machines the prologue is where the new fp value
2617 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
2619 /* Restart without fiddling with the step ranges or
2626 ecs
->sal
= find_pc_line (stop_pc
, 0);
2628 /* NOTE: tausq/2004-05-24: This if block used to be done before all
2629 the trampoline processing logic, however, there are some trampolines
2630 that have no names, so we should do trampoline handling first. */
2631 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2632 && ecs
->stop_func_name
== NULL
2633 && ecs
->sal
.line
== 0)
2636 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into undebuggable function\n");
2638 /* The inferior just stepped into, or returned to, an
2639 undebuggable function (where there is no debugging information
2640 and no line number corresponding to the address where the
2641 inferior stopped). Since we want to skip this kind of code,
2642 we keep going until the inferior returns from this
2643 function - unless the user has asked us not to (via
2644 set step-mode) or we no longer know how to get back
2645 to the call site. */
2646 if (step_stop_if_no_debug
2647 || !frame_id_p (frame_unwind_id (get_current_frame ())))
2649 /* If we have no line number and the step-stop-if-no-debug
2650 is set, we stop the step so that the user has a chance to
2651 switch in assembly mode. */
2653 print_stop_reason (END_STEPPING_RANGE
, 0);
2654 stop_stepping (ecs
);
2659 /* Set a breakpoint at callee's return address (the address
2660 at which the caller will resume). */
2661 insert_step_resume_breakpoint_at_caller (get_current_frame ());
2667 if (step_range_end
== 1)
2669 /* It is stepi or nexti. We always want to stop stepping after
2672 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
2674 print_stop_reason (END_STEPPING_RANGE
, 0);
2675 stop_stepping (ecs
);
2679 if (ecs
->sal
.line
== 0)
2681 /* We have no line number information. That means to stop
2682 stepping (does this always happen right after one instruction,
2683 when we do "s" in a function with no line numbers,
2684 or can this happen as a result of a return or longjmp?). */
2686 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
2688 print_stop_reason (END_STEPPING_RANGE
, 0);
2689 stop_stepping (ecs
);
2693 if ((stop_pc
== ecs
->sal
.pc
)
2694 && (ecs
->current_line
!= ecs
->sal
.line
2695 || ecs
->current_symtab
!= ecs
->sal
.symtab
))
2697 /* We are at the start of a different line. So stop. Note that
2698 we don't stop if we step into the middle of a different line.
2699 That is said to make things like for (;;) statements work
2702 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped to a different line\n");
2704 print_stop_reason (END_STEPPING_RANGE
, 0);
2705 stop_stepping (ecs
);
2709 /* We aren't done stepping.
2711 Optimize by setting the stepping range to the line.
2712 (We might not be in the original line, but if we entered a
2713 new line in mid-statement, we continue stepping. This makes
2714 things like for(;;) statements work better.) */
2716 if (ecs
->stop_func_end
&& ecs
->sal
.end
>= ecs
->stop_func_end
)
2718 /* If this is the last line of the function, don't keep stepping
2719 (it would probably step us out of the function).
2720 This is particularly necessary for a one-line function,
2721 in which after skipping the prologue we better stop even though
2722 we will be in mid-line. */
2724 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped to a different function\n");
2726 print_stop_reason (END_STEPPING_RANGE
, 0);
2727 stop_stepping (ecs
);
2730 step_range_start
= ecs
->sal
.pc
;
2731 step_range_end
= ecs
->sal
.end
;
2732 step_frame_id
= get_frame_id (get_current_frame ());
2733 ecs
->current_line
= ecs
->sal
.line
;
2734 ecs
->current_symtab
= ecs
->sal
.symtab
;
2736 /* In the case where we just stepped out of a function into the
2737 middle of a line of the caller, continue stepping, but
2738 step_frame_id must be modified to current frame */
2740 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too
2741 generous. It will trigger on things like a step into a frameless
2742 stackless leaf function. I think the logic should instead look
2743 at the unwound frame ID has that should give a more robust
2744 indication of what happened. */
2745 if (step
- ID
== current
- ID
)
2746 still stepping in same function
;
2747 else if (step
- ID
== unwind (current
- ID
))
2748 stepped into a function
;
2750 stepped out of a function
;
2751 /* Of course this assumes that the frame ID unwind code is robust
2752 and we're willing to introduce frame unwind logic into this
2753 function. Fortunately, those days are nearly upon us. */
2756 struct frame_info
*frame
= get_current_frame ();
2757 struct frame_id current_frame
= get_frame_id (frame
);
2758 if (!(frame_id_inner (get_frame_arch (frame
), current_frame
,
2760 step_frame_id
= current_frame
;
2764 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
2768 /* Are we in the middle of stepping? */
2771 currently_stepping (struct execution_control_state
*ecs
)
2773 return ((!ecs
->handling_longjmp
2774 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
2776 || ecs
->stepping_through_solib_after_catch
2777 || bpstat_should_step ());
2780 /* Subroutine call with source code we should not step over. Do step
2781 to the first line of code in it. */
2784 step_into_function (struct execution_control_state
*ecs
)
2787 struct symtab_and_line sr_sal
;
2789 s
= find_pc_symtab (stop_pc
);
2790 if (s
&& s
->language
!= language_asm
)
2791 ecs
->stop_func_start
= gdbarch_skip_prologue
2792 (current_gdbarch
, ecs
->stop_func_start
);
2794 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
2795 /* Use the step_resume_break to step until the end of the prologue,
2796 even if that involves jumps (as it seems to on the vax under
2798 /* If the prologue ends in the middle of a source line, continue to
2799 the end of that source line (if it is still within the function).
2800 Otherwise, just go to end of prologue. */
2802 && ecs
->sal
.pc
!= ecs
->stop_func_start
2803 && ecs
->sal
.end
< ecs
->stop_func_end
)
2804 ecs
->stop_func_start
= ecs
->sal
.end
;
2806 /* Architectures which require breakpoint adjustment might not be able
2807 to place a breakpoint at the computed address. If so, the test
2808 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
2809 ecs->stop_func_start to an address at which a breakpoint may be
2810 legitimately placed.
2812 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
2813 made, GDB will enter an infinite loop when stepping through
2814 optimized code consisting of VLIW instructions which contain
2815 subinstructions corresponding to different source lines. On
2816 FR-V, it's not permitted to place a breakpoint on any but the
2817 first subinstruction of a VLIW instruction. When a breakpoint is
2818 set, GDB will adjust the breakpoint address to the beginning of
2819 the VLIW instruction. Thus, we need to make the corresponding
2820 adjustment here when computing the stop address. */
2822 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
2824 ecs
->stop_func_start
2825 = gdbarch_adjust_breakpoint_address (current_gdbarch
,
2826 ecs
->stop_func_start
);
2829 if (ecs
->stop_func_start
== stop_pc
)
2831 /* We are already there: stop now. */
2833 print_stop_reason (END_STEPPING_RANGE
, 0);
2834 stop_stepping (ecs
);
2839 /* Put the step-breakpoint there and go until there. */
2840 init_sal (&sr_sal
); /* initialize to zeroes */
2841 sr_sal
.pc
= ecs
->stop_func_start
;
2842 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
2844 /* Do not specify what the fp should be when we stop since on
2845 some machines the prologue is where the new fp value is
2847 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
2849 /* And make sure stepping stops right away then. */
2850 step_range_end
= step_range_start
;
2855 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
2856 This is used to both functions and to skip over code. */
2859 insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
2860 struct frame_id sr_id
)
2862 /* There should never be more than one step-resume breakpoint per
2863 thread, so we should never be setting a new
2864 step_resume_breakpoint when one is already active. */
2865 gdb_assert (step_resume_breakpoint
== NULL
);
2868 fprintf_unfiltered (gdb_stdlog
,
2869 "infrun: inserting step-resume breakpoint at 0x%s\n",
2870 paddr_nz (sr_sal
.pc
));
2872 step_resume_breakpoint
= set_momentary_breakpoint (sr_sal
, sr_id
,
2874 if (breakpoints_inserted
)
2875 insert_breakpoints ();
2878 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
2879 to skip a potential signal handler.
2881 This is called with the interrupted function's frame. The signal
2882 handler, when it returns, will resume the interrupted function at
2886 insert_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
2888 struct symtab_and_line sr_sal
;
2890 gdb_assert (return_frame
!= NULL
);
2891 init_sal (&sr_sal
); /* initialize to zeros */
2893 sr_sal
.pc
= gdbarch_addr_bits_remove
2894 (current_gdbarch
, get_frame_pc (return_frame
));
2895 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2897 insert_step_resume_breakpoint_at_sal (sr_sal
, get_frame_id (return_frame
));
2900 /* Similar to insert_step_resume_breakpoint_at_frame, except
2901 but a breakpoint at the previous frame's PC. This is used to
2902 skip a function after stepping into it (for "next" or if the called
2903 function has no debugging information).
2905 The current function has almost always been reached by single
2906 stepping a call or return instruction. NEXT_FRAME belongs to the
2907 current function, and the breakpoint will be set at the caller's
2910 This is a separate function rather than reusing
2911 insert_step_resume_breakpoint_at_frame in order to avoid
2912 get_prev_frame, which may stop prematurely (see the implementation
2913 of frame_unwind_id for an example). */
2916 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
2918 struct symtab_and_line sr_sal
;
2920 /* We shouldn't have gotten here if we don't know where the call site
2922 gdb_assert (frame_id_p (frame_unwind_id (next_frame
)));
2924 init_sal (&sr_sal
); /* initialize to zeros */
2926 sr_sal
.pc
= gdbarch_addr_bits_remove
2927 (current_gdbarch
, frame_pc_unwind (next_frame
));
2928 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
2930 insert_step_resume_breakpoint_at_sal (sr_sal
, frame_unwind_id (next_frame
));
2934 stop_stepping (struct execution_control_state
*ecs
)
2937 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
2939 /* Let callers know we don't want to wait for the inferior anymore. */
2940 ecs
->wait_some_more
= 0;
2943 /* This function handles various cases where we need to continue
2944 waiting for the inferior. */
2945 /* (Used to be the keep_going: label in the old wait_for_inferior) */
2948 keep_going (struct execution_control_state
*ecs
)
2950 /* Save the pc before execution, to compare with pc after stop. */
2951 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
2953 /* If we did not do break;, it means we should keep running the
2954 inferior and not return to debugger. */
2956 if (trap_expected
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
2958 /* We took a signal (which we are supposed to pass through to
2959 the inferior, else we'd have done a break above) and we
2960 haven't yet gotten our trap. Simply continue. */
2961 resume (currently_stepping (ecs
), stop_signal
);
2965 /* Either the trap was not expected, but we are continuing
2966 anyway (the user asked that this signal be passed to the
2969 The signal was SIGTRAP, e.g. it was our signal, but we
2970 decided we should resume from it.
2972 We're going to run this baby now! */
2974 if (!breakpoints_inserted
&& !ecs
->another_trap
)
2976 /* Stop stepping when inserting breakpoints
2978 if (insert_breakpoints () != 0)
2980 stop_stepping (ecs
);
2983 breakpoints_inserted
= 1;
2986 trap_expected
= ecs
->another_trap
;
2988 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
2989 specifies that such a signal should be delivered to the
2992 Typically, this would occure when a user is debugging a
2993 target monitor on a simulator: the target monitor sets a
2994 breakpoint; the simulator encounters this break-point and
2995 halts the simulation handing control to GDB; GDB, noteing
2996 that the break-point isn't valid, returns control back to the
2997 simulator; the simulator then delivers the hardware
2998 equivalent of a SIGNAL_TRAP to the program being debugged. */
3000 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !signal_program
[stop_signal
])
3001 stop_signal
= TARGET_SIGNAL_0
;
3004 resume (currently_stepping (ecs
), stop_signal
);
3007 prepare_to_wait (ecs
);
3010 /* This function normally comes after a resume, before
3011 handle_inferior_event exits. It takes care of any last bits of
3012 housekeeping, and sets the all-important wait_some_more flag. */
3015 prepare_to_wait (struct execution_control_state
*ecs
)
3018 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
3019 if (ecs
->infwait_state
== infwait_normal_state
)
3021 overlay_cache_invalid
= 1;
3023 /* We have to invalidate the registers BEFORE calling
3024 target_wait because they can be loaded from the target while
3025 in target_wait. This makes remote debugging a bit more
3026 efficient for those targets that provide critical registers
3027 as part of their normal status mechanism. */
3029 registers_changed ();
3030 ecs
->waiton_ptid
= pid_to_ptid (-1);
3031 ecs
->wp
= &(ecs
->ws
);
3033 /* This is the old end of the while loop. Let everybody know we
3034 want to wait for the inferior some more and get called again
3036 ecs
->wait_some_more
= 1;
3039 /* Print why the inferior has stopped. We always print something when
3040 the inferior exits, or receives a signal. The rest of the cases are
3041 dealt with later on in normal_stop() and print_it_typical(). Ideally
3042 there should be a call to this function from handle_inferior_event()
3043 each time stop_stepping() is called.*/
3045 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3047 switch (stop_reason
)
3049 case END_STEPPING_RANGE
:
3050 /* We are done with a step/next/si/ni command. */
3051 /* For now print nothing. */
3052 /* Print a message only if not in the middle of doing a "step n"
3053 operation for n > 1 */
3054 if (!step_multi
|| !stop_step
)
3055 if (ui_out_is_mi_like_p (uiout
))
3058 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
3061 /* The inferior was terminated by a signal. */
3062 annotate_signalled ();
3063 if (ui_out_is_mi_like_p (uiout
))
3066 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
3067 ui_out_text (uiout
, "\nProgram terminated with signal ");
3068 annotate_signal_name ();
3069 ui_out_field_string (uiout
, "signal-name",
3070 target_signal_to_name (stop_info
));
3071 annotate_signal_name_end ();
3072 ui_out_text (uiout
, ", ");
3073 annotate_signal_string ();
3074 ui_out_field_string (uiout
, "signal-meaning",
3075 target_signal_to_string (stop_info
));
3076 annotate_signal_string_end ();
3077 ui_out_text (uiout
, ".\n");
3078 ui_out_text (uiout
, "The program no longer exists.\n");
3081 /* The inferior program is finished. */
3082 annotate_exited (stop_info
);
3085 if (ui_out_is_mi_like_p (uiout
))
3086 ui_out_field_string (uiout
, "reason",
3087 async_reason_lookup (EXEC_ASYNC_EXITED
));
3088 ui_out_text (uiout
, "\nProgram exited with code ");
3089 ui_out_field_fmt (uiout
, "exit-code", "0%o",
3090 (unsigned int) stop_info
);
3091 ui_out_text (uiout
, ".\n");
3095 if (ui_out_is_mi_like_p (uiout
))
3098 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
3099 ui_out_text (uiout
, "\nProgram exited normally.\n");
3101 /* Support the --return-child-result option. */
3102 return_child_result_value
= stop_info
;
3104 case SIGNAL_RECEIVED
:
3105 /* Signal received. The signal table tells us to print about
3108 ui_out_text (uiout
, "\nProgram received signal ");
3109 annotate_signal_name ();
3110 if (ui_out_is_mi_like_p (uiout
))
3112 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
3113 ui_out_field_string (uiout
, "signal-name",
3114 target_signal_to_name (stop_info
));
3115 annotate_signal_name_end ();
3116 ui_out_text (uiout
, ", ");
3117 annotate_signal_string ();
3118 ui_out_field_string (uiout
, "signal-meaning",
3119 target_signal_to_string (stop_info
));
3120 annotate_signal_string_end ();
3121 ui_out_text (uiout
, ".\n");
3124 internal_error (__FILE__
, __LINE__
,
3125 _("print_stop_reason: unrecognized enum value"));
3131 /* Here to return control to GDB when the inferior stops for real.
3132 Print appropriate messages, remove breakpoints, give terminal our modes.
3134 STOP_PRINT_FRAME nonzero means print the executing frame
3135 (pc, function, args, file, line number and line text).
3136 BREAKPOINTS_FAILED nonzero means stop was due to error
3137 attempting to insert breakpoints. */
3142 struct target_waitstatus last
;
3145 get_last_target_status (&last_ptid
, &last
);
3147 /* As with the notification of thread events, we want to delay
3148 notifying the user that we've switched thread context until
3149 the inferior actually stops.
3151 There's no point in saying anything if the inferior has exited.
3152 Note that SIGNALLED here means "exited with a signal", not
3153 "received a signal". */
3154 if (!ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3155 && target_has_execution
3156 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
3157 && last
.kind
!= TARGET_WAITKIND_EXITED
)
3159 target_terminal_ours_for_output ();
3160 printf_filtered (_("[Switching to %s]\n"),
3161 target_pid_or_tid_to_str (inferior_ptid
));
3162 previous_inferior_ptid
= inferior_ptid
;
3165 /* NOTE drow/2004-01-17: Is this still necessary? */
3166 /* Make sure that the current_frame's pc is correct. This
3167 is a correction for setting up the frame info before doing
3168 gdbarch_decr_pc_after_break */
3169 if (target_has_execution
)
3170 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3171 gdbarch_decr_pc_after_break, the program counter can change. Ask the
3172 frame code to check for this and sort out any resultant mess.
3173 gdbarch_decr_pc_after_break needs to just go away. */
3174 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3176 if (target_has_execution
&& breakpoints_inserted
)
3178 if (remove_breakpoints ())
3180 target_terminal_ours_for_output ();
3181 printf_filtered (_("\
3182 Cannot remove breakpoints because program is no longer writable.\n\
3183 It might be running in another process.\n\
3184 Further execution is probably impossible.\n"));
3187 breakpoints_inserted
= 0;
3189 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3190 Delete any breakpoint that is to be deleted at the next stop. */
3192 breakpoint_auto_delete (stop_bpstat
);
3194 /* If an auto-display called a function and that got a signal,
3195 delete that auto-display to avoid an infinite recursion. */
3197 if (stopped_by_random_signal
)
3198 disable_current_display ();
3200 /* Don't print a message if in the middle of doing a "step n"
3201 operation for n > 1 */
3202 if (step_multi
&& stop_step
)
3205 target_terminal_ours ();
3207 /* Set the current source location. This will also happen if we
3208 display the frame below, but the current SAL will be incorrect
3209 during a user hook-stop function. */
3210 if (target_has_stack
&& !stop_stack_dummy
)
3211 set_current_sal_from_frame (get_current_frame (), 1);
3213 /* Look up the hook_stop and run it (CLI internally handles problem
3214 of stop_command's pre-hook not existing). */
3216 catch_errors (hook_stop_stub
, stop_command
,
3217 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3219 if (!target_has_stack
)
3225 /* Select innermost stack frame - i.e., current frame is frame 0,
3226 and current location is based on that.
3227 Don't do this on return from a stack dummy routine,
3228 or if the program has exited. */
3230 if (!stop_stack_dummy
)
3232 select_frame (get_current_frame ());
3234 /* Print current location without a level number, if
3235 we have changed functions or hit a breakpoint.
3236 Print source line if we have one.
3237 bpstat_print() contains the logic deciding in detail
3238 what to print, based on the event(s) that just occurred. */
3240 if (stop_print_frame
)
3244 int do_frame_printing
= 1;
3246 bpstat_ret
= bpstat_print (stop_bpstat
);
3250 /* If we had hit a shared library event breakpoint,
3251 bpstat_print would print out this message. If we hit
3252 an OS-level shared library event, do the same
3254 if (last
.kind
== TARGET_WAITKIND_LOADED
)
3256 printf_filtered (_("Stopped due to shared library event\n"));
3257 source_flag
= SRC_LINE
; /* something bogus */
3258 do_frame_printing
= 0;
3262 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3263 (or should) carry around the function and does (or
3264 should) use that when doing a frame comparison. */
3266 && frame_id_eq (step_frame_id
,
3267 get_frame_id (get_current_frame ()))
3268 && step_start_function
== find_pc_function (stop_pc
))
3269 source_flag
= SRC_LINE
; /* finished step, just print source line */
3271 source_flag
= SRC_AND_LOC
; /* print location and source line */
3273 case PRINT_SRC_AND_LOC
:
3274 source_flag
= SRC_AND_LOC
; /* print location and source line */
3276 case PRINT_SRC_ONLY
:
3277 source_flag
= SRC_LINE
;
3280 source_flag
= SRC_LINE
; /* something bogus */
3281 do_frame_printing
= 0;
3284 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
3287 if (ui_out_is_mi_like_p (uiout
))
3288 ui_out_field_int (uiout
, "thread-id",
3289 pid_to_thread_id (inferior_ptid
));
3290 /* The behavior of this routine with respect to the source
3292 SRC_LINE: Print only source line
3293 LOCATION: Print only location
3294 SRC_AND_LOC: Print location and source line */
3295 if (do_frame_printing
)
3296 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
3298 /* Display the auto-display expressions. */
3303 /* Save the function value return registers, if we care.
3304 We might be about to restore their previous contents. */
3305 if (proceed_to_finish
)
3307 /* This should not be necessary. */
3309 regcache_xfree (stop_registers
);
3311 /* NB: The copy goes through to the target picking up the value of
3312 all the registers. */
3313 stop_registers
= regcache_dup (get_current_regcache ());
3316 if (stop_stack_dummy
)
3318 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3319 ends with a setting of the current frame, so we can use that
3321 frame_pop (get_current_frame ());
3322 /* Set stop_pc to what it was before we called the function.
3323 Can't rely on restore_inferior_status because that only gets
3324 called if we don't stop in the called function. */
3325 stop_pc
= read_pc ();
3326 select_frame (get_current_frame ());
3330 annotate_stopped ();
3331 observer_notify_normal_stop (stop_bpstat
);
3335 hook_stop_stub (void *cmd
)
3337 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3342 signal_stop_state (int signo
)
3344 return signal_stop
[signo
];
3348 signal_print_state (int signo
)
3350 return signal_print
[signo
];
3354 signal_pass_state (int signo
)
3356 return signal_program
[signo
];
3360 signal_stop_update (int signo
, int state
)
3362 int ret
= signal_stop
[signo
];
3363 signal_stop
[signo
] = state
;
3368 signal_print_update (int signo
, int state
)
3370 int ret
= signal_print
[signo
];
3371 signal_print
[signo
] = state
;
3376 signal_pass_update (int signo
, int state
)
3378 int ret
= signal_program
[signo
];
3379 signal_program
[signo
] = state
;
3384 sig_print_header (void)
3386 printf_filtered (_("\
3387 Signal Stop\tPrint\tPass to program\tDescription\n"));
3391 sig_print_info (enum target_signal oursig
)
3393 char *name
= target_signal_to_name (oursig
);
3394 int name_padding
= 13 - strlen (name
);
3396 if (name_padding
<= 0)
3399 printf_filtered ("%s", name
);
3400 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
3401 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3402 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3403 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3404 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3407 /* Specify how various signals in the inferior should be handled. */
3410 handle_command (char *args
, int from_tty
)
3413 int digits
, wordlen
;
3414 int sigfirst
, signum
, siglast
;
3415 enum target_signal oursig
;
3418 unsigned char *sigs
;
3419 struct cleanup
*old_chain
;
3423 error_no_arg (_("signal to handle"));
3426 /* Allocate and zero an array of flags for which signals to handle. */
3428 nsigs
= (int) TARGET_SIGNAL_LAST
;
3429 sigs
= (unsigned char *) alloca (nsigs
);
3430 memset (sigs
, 0, nsigs
);
3432 /* Break the command line up into args. */
3434 argv
= buildargv (args
);
3439 old_chain
= make_cleanup_freeargv (argv
);
3441 /* Walk through the args, looking for signal oursigs, signal names, and
3442 actions. Signal numbers and signal names may be interspersed with
3443 actions, with the actions being performed for all signals cumulatively
3444 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3446 while (*argv
!= NULL
)
3448 wordlen
= strlen (*argv
);
3449 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3453 sigfirst
= siglast
= -1;
3455 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3457 /* Apply action to all signals except those used by the
3458 debugger. Silently skip those. */
3461 siglast
= nsigs
- 1;
3463 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3465 SET_SIGS (nsigs
, sigs
, signal_stop
);
3466 SET_SIGS (nsigs
, sigs
, signal_print
);
3468 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3470 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3472 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3474 SET_SIGS (nsigs
, sigs
, signal_print
);
3476 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3478 SET_SIGS (nsigs
, sigs
, signal_program
);
3480 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3482 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3484 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3486 SET_SIGS (nsigs
, sigs
, signal_program
);
3488 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3490 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3491 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3493 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3495 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3497 else if (digits
> 0)
3499 /* It is numeric. The numeric signal refers to our own
3500 internal signal numbering from target.h, not to host/target
3501 signal number. This is a feature; users really should be
3502 using symbolic names anyway, and the common ones like
3503 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3505 sigfirst
= siglast
= (int)
3506 target_signal_from_command (atoi (*argv
));
3507 if ((*argv
)[digits
] == '-')
3510 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3512 if (sigfirst
> siglast
)
3514 /* Bet he didn't figure we'd think of this case... */
3522 oursig
= target_signal_from_name (*argv
);
3523 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3525 sigfirst
= siglast
= (int) oursig
;
3529 /* Not a number and not a recognized flag word => complain. */
3530 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
3534 /* If any signal numbers or symbol names were found, set flags for
3535 which signals to apply actions to. */
3537 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3539 switch ((enum target_signal
) signum
)
3541 case TARGET_SIGNAL_TRAP
:
3542 case TARGET_SIGNAL_INT
:
3543 if (!allsigs
&& !sigs
[signum
])
3545 if (query ("%s is used by the debugger.\n\
3546 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
3552 printf_unfiltered (_("Not confirmed, unchanged.\n"));
3553 gdb_flush (gdb_stdout
);
3557 case TARGET_SIGNAL_0
:
3558 case TARGET_SIGNAL_DEFAULT
:
3559 case TARGET_SIGNAL_UNKNOWN
:
3560 /* Make sure that "all" doesn't print these. */
3571 target_notice_signals (inferior_ptid
);
3575 /* Show the results. */
3576 sig_print_header ();
3577 for (signum
= 0; signum
< nsigs
; signum
++)
3581 sig_print_info (signum
);
3586 do_cleanups (old_chain
);
3590 xdb_handle_command (char *args
, int from_tty
)
3593 struct cleanup
*old_chain
;
3595 /* Break the command line up into args. */
3597 argv
= buildargv (args
);
3602 old_chain
= make_cleanup_freeargv (argv
);
3603 if (argv
[1] != (char *) NULL
)
3608 bufLen
= strlen (argv
[0]) + 20;
3609 argBuf
= (char *) xmalloc (bufLen
);
3613 enum target_signal oursig
;
3615 oursig
= target_signal_from_name (argv
[0]);
3616 memset (argBuf
, 0, bufLen
);
3617 if (strcmp (argv
[1], "Q") == 0)
3618 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3621 if (strcmp (argv
[1], "s") == 0)
3623 if (!signal_stop
[oursig
])
3624 sprintf (argBuf
, "%s %s", argv
[0], "stop");
3626 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
3628 else if (strcmp (argv
[1], "i") == 0)
3630 if (!signal_program
[oursig
])
3631 sprintf (argBuf
, "%s %s", argv
[0], "pass");
3633 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
3635 else if (strcmp (argv
[1], "r") == 0)
3637 if (!signal_print
[oursig
])
3638 sprintf (argBuf
, "%s %s", argv
[0], "print");
3640 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
3646 handle_command (argBuf
, from_tty
);
3648 printf_filtered (_("Invalid signal handling flag.\n"));
3653 do_cleanups (old_chain
);
3656 /* Print current contents of the tables set by the handle command.
3657 It is possible we should just be printing signals actually used
3658 by the current target (but for things to work right when switching
3659 targets, all signals should be in the signal tables). */
3662 signals_info (char *signum_exp
, int from_tty
)
3664 enum target_signal oursig
;
3665 sig_print_header ();
3669 /* First see if this is a symbol name. */
3670 oursig
= target_signal_from_name (signum_exp
);
3671 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
3673 /* No, try numeric. */
3675 target_signal_from_command (parse_and_eval_long (signum_exp
));
3677 sig_print_info (oursig
);
3681 printf_filtered ("\n");
3682 /* These ugly casts brought to you by the native VAX compiler. */
3683 for (oursig
= TARGET_SIGNAL_FIRST
;
3684 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
3685 oursig
= (enum target_signal
) ((int) oursig
+ 1))
3689 if (oursig
!= TARGET_SIGNAL_UNKNOWN
3690 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
3691 sig_print_info (oursig
);
3694 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
3697 struct inferior_status
3699 enum target_signal stop_signal
;
3703 int stop_stack_dummy
;
3704 int stopped_by_random_signal
;
3706 CORE_ADDR step_range_start
;
3707 CORE_ADDR step_range_end
;
3708 struct frame_id step_frame_id
;
3709 enum step_over_calls_kind step_over_calls
;
3710 CORE_ADDR step_resume_break_address
;
3711 int stop_after_trap
;
3714 /* These are here because if call_function_by_hand has written some
3715 registers and then decides to call error(), we better not have changed
3717 struct regcache
*registers
;
3719 /* A frame unique identifier. */
3720 struct frame_id selected_frame_id
;
3722 int breakpoint_proceeded
;
3723 int restore_stack_info
;
3724 int proceed_to_finish
;
3728 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
3731 int size
= register_size (current_gdbarch
, regno
);
3732 void *buf
= alloca (size
);
3733 store_signed_integer (buf
, size
, val
);
3734 regcache_raw_write (inf_status
->registers
, regno
, buf
);
3737 /* Save all of the information associated with the inferior<==>gdb
3738 connection. INF_STATUS is a pointer to a "struct inferior_status"
3739 (defined in inferior.h). */
3741 struct inferior_status
*
3742 save_inferior_status (int restore_stack_info
)
3744 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
3746 inf_status
->stop_signal
= stop_signal
;
3747 inf_status
->stop_pc
= stop_pc
;
3748 inf_status
->stop_step
= stop_step
;
3749 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
3750 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
3751 inf_status
->trap_expected
= trap_expected
;
3752 inf_status
->step_range_start
= step_range_start
;
3753 inf_status
->step_range_end
= step_range_end
;
3754 inf_status
->step_frame_id
= step_frame_id
;
3755 inf_status
->step_over_calls
= step_over_calls
;
3756 inf_status
->stop_after_trap
= stop_after_trap
;
3757 inf_status
->stop_soon
= stop_soon
;
3758 /* Save original bpstat chain here; replace it with copy of chain.
3759 If caller's caller is walking the chain, they'll be happier if we
3760 hand them back the original chain when restore_inferior_status is
3762 inf_status
->stop_bpstat
= stop_bpstat
;
3763 stop_bpstat
= bpstat_copy (stop_bpstat
);
3764 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
3765 inf_status
->restore_stack_info
= restore_stack_info
;
3766 inf_status
->proceed_to_finish
= proceed_to_finish
;
3768 inf_status
->registers
= regcache_dup (get_current_regcache ());
3770 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
3775 restore_selected_frame (void *args
)
3777 struct frame_id
*fid
= (struct frame_id
*) args
;
3778 struct frame_info
*frame
;
3780 frame
= frame_find_by_id (*fid
);
3782 /* If inf_status->selected_frame_id is NULL, there was no previously
3786 warning (_("Unable to restore previously selected frame."));
3790 select_frame (frame
);
3796 restore_inferior_status (struct inferior_status
*inf_status
)
3798 stop_signal
= inf_status
->stop_signal
;
3799 stop_pc
= inf_status
->stop_pc
;
3800 stop_step
= inf_status
->stop_step
;
3801 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
3802 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
3803 trap_expected
= inf_status
->trap_expected
;
3804 step_range_start
= inf_status
->step_range_start
;
3805 step_range_end
= inf_status
->step_range_end
;
3806 step_frame_id
= inf_status
->step_frame_id
;
3807 step_over_calls
= inf_status
->step_over_calls
;
3808 stop_after_trap
= inf_status
->stop_after_trap
;
3809 stop_soon
= inf_status
->stop_soon
;
3810 bpstat_clear (&stop_bpstat
);
3811 stop_bpstat
= inf_status
->stop_bpstat
;
3812 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
3813 proceed_to_finish
= inf_status
->proceed_to_finish
;
3815 /* The inferior can be gone if the user types "print exit(0)"
3816 (and perhaps other times). */
3817 if (target_has_execution
)
3818 /* NB: The register write goes through to the target. */
3819 regcache_cpy (get_current_regcache (), inf_status
->registers
);
3820 regcache_xfree (inf_status
->registers
);
3822 /* FIXME: If we are being called after stopping in a function which
3823 is called from gdb, we should not be trying to restore the
3824 selected frame; it just prints a spurious error message (The
3825 message is useful, however, in detecting bugs in gdb (like if gdb
3826 clobbers the stack)). In fact, should we be restoring the
3827 inferior status at all in that case? . */
3829 if (target_has_stack
&& inf_status
->restore_stack_info
)
3831 /* The point of catch_errors is that if the stack is clobbered,
3832 walking the stack might encounter a garbage pointer and
3833 error() trying to dereference it. */
3835 (restore_selected_frame
, &inf_status
->selected_frame_id
,
3836 "Unable to restore previously selected frame:\n",
3837 RETURN_MASK_ERROR
) == 0)
3838 /* Error in restoring the selected frame. Select the innermost
3840 select_frame (get_current_frame ());
3848 do_restore_inferior_status_cleanup (void *sts
)
3850 restore_inferior_status (sts
);
3854 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
3856 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
3860 discard_inferior_status (struct inferior_status
*inf_status
)
3862 /* See save_inferior_status for info on stop_bpstat. */
3863 bpstat_clear (&inf_status
->stop_bpstat
);
3864 regcache_xfree (inf_status
->registers
);
3869 inferior_has_forked (int pid
, int *child_pid
)
3871 struct target_waitstatus last
;
3874 get_last_target_status (&last_ptid
, &last
);
3876 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
3879 if (ptid_get_pid (last_ptid
) != pid
)
3882 *child_pid
= last
.value
.related_pid
;
3887 inferior_has_vforked (int pid
, int *child_pid
)
3889 struct target_waitstatus last
;
3892 get_last_target_status (&last_ptid
, &last
);
3894 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
3897 if (ptid_get_pid (last_ptid
) != pid
)
3900 *child_pid
= last
.value
.related_pid
;
3905 inferior_has_execd (int pid
, char **execd_pathname
)
3907 struct target_waitstatus last
;
3910 get_last_target_status (&last_ptid
, &last
);
3912 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
3915 if (ptid_get_pid (last_ptid
) != pid
)
3918 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
3922 /* Oft used ptids */
3924 ptid_t minus_one_ptid
;
3926 /* Create a ptid given the necessary PID, LWP, and TID components. */
3929 ptid_build (int pid
, long lwp
, long tid
)
3939 /* Create a ptid from just a pid. */
3942 pid_to_ptid (int pid
)
3944 return ptid_build (pid
, 0, 0);
3947 /* Fetch the pid (process id) component from a ptid. */
3950 ptid_get_pid (ptid_t ptid
)
3955 /* Fetch the lwp (lightweight process) component from a ptid. */
3958 ptid_get_lwp (ptid_t ptid
)
3963 /* Fetch the tid (thread id) component from a ptid. */
3966 ptid_get_tid (ptid_t ptid
)
3971 /* ptid_equal() is used to test equality of two ptids. */
3974 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
3976 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
3977 && ptid1
.tid
== ptid2
.tid
);
3980 /* restore_inferior_ptid() will be used by the cleanup machinery
3981 to restore the inferior_ptid value saved in a call to
3982 save_inferior_ptid(). */
3985 restore_inferior_ptid (void *arg
)
3987 ptid_t
*saved_ptid_ptr
= arg
;
3988 inferior_ptid
= *saved_ptid_ptr
;
3992 /* Save the value of inferior_ptid so that it may be restored by a
3993 later call to do_cleanups(). Returns the struct cleanup pointer
3994 needed for later doing the cleanup. */
3997 save_inferior_ptid (void)
3999 ptid_t
*saved_ptid_ptr
;
4001 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4002 *saved_ptid_ptr
= inferior_ptid
;
4003 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4008 _initialize_infrun (void)
4012 struct cmd_list_element
*c
;
4014 add_info ("signals", signals_info
, _("\
4015 What debugger does when program gets various signals.\n\
4016 Specify a signal as argument to print info on that signal only."));
4017 add_info_alias ("handle", "signals", 0);
4019 add_com ("handle", class_run
, handle_command
, _("\
4020 Specify how to handle a signal.\n\
4021 Args are signals and actions to apply to those signals.\n\
4022 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4023 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4024 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4025 The special arg \"all\" is recognized to mean all signals except those\n\
4026 used by the debugger, typically SIGTRAP and SIGINT.\n\
4027 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4028 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4029 Stop means reenter debugger if this signal happens (implies print).\n\
4030 Print means print a message if this signal happens.\n\
4031 Pass means let program see this signal; otherwise program doesn't know.\n\
4032 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4033 Pass and Stop may be combined."));
4036 add_com ("lz", class_info
, signals_info
, _("\
4037 What debugger does when program gets various signals.\n\
4038 Specify a signal as argument to print info on that signal only."));
4039 add_com ("z", class_run
, xdb_handle_command
, _("\
4040 Specify how to handle a signal.\n\
4041 Args are signals and actions to apply to those signals.\n\
4042 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4043 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4044 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4045 The special arg \"all\" is recognized to mean all signals except those\n\
4046 used by the debugger, typically SIGTRAP and SIGINT.\n\
4047 Recognized actions include \"s\" (toggles between stop and nostop), \n\
4048 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4049 nopass), \"Q\" (noprint)\n\
4050 Stop means reenter debugger if this signal happens (implies print).\n\
4051 Print means print a message if this signal happens.\n\
4052 Pass means let program see this signal; otherwise program doesn't know.\n\
4053 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4054 Pass and Stop may be combined."));
4058 stop_command
= add_cmd ("stop", class_obscure
,
4059 not_just_help_class_command
, _("\
4060 There is no `stop' command, but you can set a hook on `stop'.\n\
4061 This allows you to set a list of commands to be run each time execution\n\
4062 of the program stops."), &cmdlist
);
4064 add_setshow_zinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
4065 Set inferior debugging."), _("\
4066 Show inferior debugging."), _("\
4067 When non-zero, inferior specific debugging is enabled."),
4070 &setdebuglist
, &showdebuglist
);
4072 numsigs
= (int) TARGET_SIGNAL_LAST
;
4073 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4074 signal_print
= (unsigned char *)
4075 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4076 signal_program
= (unsigned char *)
4077 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4078 for (i
= 0; i
< numsigs
; i
++)
4081 signal_print
[i
] = 1;
4082 signal_program
[i
] = 1;
4085 /* Signals caused by debugger's own actions
4086 should not be given to the program afterwards. */
4087 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4088 signal_program
[TARGET_SIGNAL_INT
] = 0;
4090 /* Signals that are not errors should not normally enter the debugger. */
4091 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4092 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4093 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4094 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4095 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4096 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4097 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4098 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4099 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4100 signal_print
[TARGET_SIGNAL_IO
] = 0;
4101 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4102 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4103 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4104 signal_print
[TARGET_SIGNAL_URG
] = 0;
4105 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4106 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4108 /* These signals are used internally by user-level thread
4109 implementations. (See signal(5) on Solaris.) Like the above
4110 signals, a healthy program receives and handles them as part of
4111 its normal operation. */
4112 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4113 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4114 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4115 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4116 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4117 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4119 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
4120 &stop_on_solib_events
, _("\
4121 Set stopping for shared library events."), _("\
4122 Show stopping for shared library events."), _("\
4123 If nonzero, gdb will give control to the user when the dynamic linker\n\
4124 notifies gdb of shared library events. The most common event of interest\n\
4125 to the user would be loading/unloading of a new library."),
4127 show_stop_on_solib_events
,
4128 &setlist
, &showlist
);
4130 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
4131 follow_fork_mode_kind_names
,
4132 &follow_fork_mode_string
, _("\
4133 Set debugger response to a program call of fork or vfork."), _("\
4134 Show debugger response to a program call of fork or vfork."), _("\
4135 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4136 parent - the original process is debugged after a fork\n\
4137 child - the new process is debugged after a fork\n\
4138 The unfollowed process will continue to run.\n\
4139 By default, the debugger will follow the parent process."),
4141 show_follow_fork_mode_string
,
4142 &setlist
, &showlist
);
4144 add_setshow_enum_cmd ("scheduler-locking", class_run
,
4145 scheduler_enums
, &scheduler_mode
, _("\
4146 Set mode for locking scheduler during execution."), _("\
4147 Show mode for locking scheduler during execution."), _("\
4148 off == no locking (threads may preempt at any time)\n\
4149 on == full locking (no thread except the current thread may run)\n\
4150 step == scheduler locked during every single-step operation.\n\
4151 In this mode, no other thread may run during a step command.\n\
4152 Other threads may run while stepping over a function call ('next')."),
4153 set_schedlock_func
, /* traps on target vector */
4154 show_scheduler_mode
,
4155 &setlist
, &showlist
);
4157 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
4158 Set mode of the step operation."), _("\
4159 Show mode of the step operation."), _("\
4160 When set, doing a step over a function without debug line information\n\
4161 will stop at the first instruction of that function. Otherwise, the\n\
4162 function is skipped and the step command stops at a different source line."),
4164 show_step_stop_if_no_debug
,
4165 &setlist
, &showlist
);
4167 /* ptid initializations */
4168 null_ptid
= ptid_build (0, 0, 0);
4169 minus_one_ptid
= ptid_build (-1, 0, 0);
4170 inferior_ptid
= null_ptid
;
4171 target_last_wait_ptid
= minus_one_ptid
;