1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2013 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "gdb_string.h"
27 #include "exceptions.h"
28 #include "breakpoint.h"
32 #include "cli/cli-script.h"
34 #include "gdbthread.h"
46 #include "dictionary.h"
48 #include "gdb_assert.h"
49 #include "mi/mi-common.h"
50 #include "event-top.h"
52 #include "record-full.h"
53 #include "inline-frame.h"
55 #include "tracepoint.h"
56 #include "continuations.h"
61 #include "completer.h"
62 #include "target-descriptions.h"
64 /* Prototypes for local functions */
66 static void signals_info (char *, int);
68 static void handle_command (char *, int);
70 static void sig_print_info (enum gdb_signal
);
72 static void sig_print_header (void);
74 static void resume_cleanups (void *);
76 static int hook_stop_stub (void *);
78 static int restore_selected_frame (void *);
80 static int follow_fork (void);
82 static void set_schedlock_func (char *args
, int from_tty
,
83 struct cmd_list_element
*c
);
85 static int currently_stepping (struct thread_info
*tp
);
87 static int currently_stepping_or_nexting_callback (struct thread_info
*tp
,
90 static void xdb_handle_command (char *args
, int from_tty
);
92 static int prepare_to_proceed (int);
94 static void print_exited_reason (int exitstatus
);
96 static void print_signal_exited_reason (enum gdb_signal siggnal
);
98 static void print_no_history_reason (void);
100 static void print_signal_received_reason (enum gdb_signal siggnal
);
102 static void print_end_stepping_range_reason (void);
104 void _initialize_infrun (void);
106 void nullify_last_target_wait_ptid (void);
108 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
110 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
112 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
114 /* When set, stop the 'step' command if we enter a function which has
115 no line number information. The normal behavior is that we step
116 over such function. */
117 int step_stop_if_no_debug
= 0;
119 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
120 struct cmd_list_element
*c
, const char *value
)
122 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
125 /* In asynchronous mode, but simulating synchronous execution. */
127 int sync_execution
= 0;
129 /* wait_for_inferior and normal_stop use this to notify the user
130 when the inferior stopped in a different thread than it had been
133 static ptid_t previous_inferior_ptid
;
135 /* Default behavior is to detach newly forked processes (legacy). */
138 int debug_displaced
= 0;
140 show_debug_displaced (struct ui_file
*file
, int from_tty
,
141 struct cmd_list_element
*c
, const char *value
)
143 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
146 unsigned int debug_infrun
= 0;
148 show_debug_infrun (struct ui_file
*file
, int from_tty
,
149 struct cmd_list_element
*c
, const char *value
)
151 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
155 /* Support for disabling address space randomization. */
157 int disable_randomization
= 1;
160 show_disable_randomization (struct ui_file
*file
, int from_tty
,
161 struct cmd_list_element
*c
, const char *value
)
163 if (target_supports_disable_randomization ())
164 fprintf_filtered (file
,
165 _("Disabling randomization of debuggee's "
166 "virtual address space is %s.\n"),
169 fputs_filtered (_("Disabling randomization of debuggee's "
170 "virtual address space is unsupported on\n"
171 "this platform.\n"), file
);
175 set_disable_randomization (char *args
, int from_tty
,
176 struct cmd_list_element
*c
)
178 if (!target_supports_disable_randomization ())
179 error (_("Disabling randomization of debuggee's "
180 "virtual address space is unsupported on\n"
185 /* If the program uses ELF-style shared libraries, then calls to
186 functions in shared libraries go through stubs, which live in a
187 table called the PLT (Procedure Linkage Table). The first time the
188 function is called, the stub sends control to the dynamic linker,
189 which looks up the function's real address, patches the stub so
190 that future calls will go directly to the function, and then passes
191 control to the function.
193 If we are stepping at the source level, we don't want to see any of
194 this --- we just want to skip over the stub and the dynamic linker.
195 The simple approach is to single-step until control leaves the
198 However, on some systems (e.g., Red Hat's 5.2 distribution) the
199 dynamic linker calls functions in the shared C library, so you
200 can't tell from the PC alone whether the dynamic linker is still
201 running. In this case, we use a step-resume breakpoint to get us
202 past the dynamic linker, as if we were using "next" to step over a
205 in_solib_dynsym_resolve_code() says whether we're in the dynamic
206 linker code or not. Normally, this means we single-step. However,
207 if gdbarch_skip_solib_resolver then returns non-zero, then its
208 value is an address where we can place a step-resume breakpoint to
209 get past the linker's symbol resolution function.
211 The in_dynsym_resolve_code hook of the target_so_ops vector can
212 generally be implemented in a pretty portable way, by comparing the
213 PC against the address ranges of the dynamic linker's sections.
215 The gdbarch_skip_solib_resolver implementation is generally going
216 to be system-specific, since it depends on internal details of the
217 dynamic linker. It's usually not too hard to figure out where to
218 put a breakpoint, but it certainly isn't portable.
219 gdbarch_skip_solib_resolver should do plenty of sanity checking.
220 If it can't figure things out, returning zero and getting the
221 (possibly confusing) stepping behavior is better than signaling an
222 error, which will obscure the change in the inferior's state. */
224 /* "Observer mode" is somewhat like a more extreme version of
225 non-stop, in which all GDB operations that might affect the
226 target's execution have been disabled. */
228 static int non_stop_1
= 0;
230 int observer_mode
= 0;
231 static int observer_mode_1
= 0;
234 set_observer_mode (char *args
, int from_tty
,
235 struct cmd_list_element
*c
)
237 extern int pagination_enabled
;
239 if (target_has_execution
)
241 observer_mode_1
= observer_mode
;
242 error (_("Cannot change this setting while the inferior is running."));
245 observer_mode
= observer_mode_1
;
247 may_write_registers
= !observer_mode
;
248 may_write_memory
= !observer_mode
;
249 may_insert_breakpoints
= !observer_mode
;
250 may_insert_tracepoints
= !observer_mode
;
251 /* We can insert fast tracepoints in or out of observer mode,
252 but enable them if we're going into this mode. */
254 may_insert_fast_tracepoints
= 1;
255 may_stop
= !observer_mode
;
256 update_target_permissions ();
258 /* Going *into* observer mode we must force non-stop, then
259 going out we leave it that way. */
262 target_async_permitted
= 1;
263 pagination_enabled
= 0;
264 non_stop
= non_stop_1
= 1;
268 printf_filtered (_("Observer mode is now %s.\n"),
269 (observer_mode
? "on" : "off"));
273 show_observer_mode (struct ui_file
*file
, int from_tty
,
274 struct cmd_list_element
*c
, const char *value
)
276 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
279 /* This updates the value of observer mode based on changes in
280 permissions. Note that we are deliberately ignoring the values of
281 may-write-registers and may-write-memory, since the user may have
282 reason to enable these during a session, for instance to turn on a
283 debugging-related global. */
286 update_observer_mode (void)
290 newval
= (!may_insert_breakpoints
291 && !may_insert_tracepoints
292 && may_insert_fast_tracepoints
296 /* Let the user know if things change. */
297 if (newval
!= observer_mode
)
298 printf_filtered (_("Observer mode is now %s.\n"),
299 (newval
? "on" : "off"));
301 observer_mode
= observer_mode_1
= newval
;
304 /* Tables of how to react to signals; the user sets them. */
306 static unsigned char *signal_stop
;
307 static unsigned char *signal_print
;
308 static unsigned char *signal_program
;
310 /* Table of signals that are registered with "catch signal". A
311 non-zero entry indicates that the signal is caught by some "catch
312 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
314 static unsigned char *signal_catch
;
316 /* Table of signals that the target may silently handle.
317 This is automatically determined from the flags above,
318 and simply cached here. */
319 static unsigned char *signal_pass
;
321 #define SET_SIGS(nsigs,sigs,flags) \
323 int signum = (nsigs); \
324 while (signum-- > 0) \
325 if ((sigs)[signum]) \
326 (flags)[signum] = 1; \
329 #define UNSET_SIGS(nsigs,sigs,flags) \
331 int signum = (nsigs); \
332 while (signum-- > 0) \
333 if ((sigs)[signum]) \
334 (flags)[signum] = 0; \
337 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
338 this function is to avoid exporting `signal_program'. */
341 update_signals_program_target (void)
343 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
346 /* Value to pass to target_resume() to cause all threads to resume. */
348 #define RESUME_ALL minus_one_ptid
350 /* Command list pointer for the "stop" placeholder. */
352 static struct cmd_list_element
*stop_command
;
354 /* Function inferior was in as of last step command. */
356 static struct symbol
*step_start_function
;
358 /* Nonzero if we want to give control to the user when we're notified
359 of shared library events by the dynamic linker. */
360 int stop_on_solib_events
;
362 /* Enable or disable optional shared library event breakpoints
363 as appropriate when the above flag is changed. */
366 set_stop_on_solib_events (char *args
, int from_tty
, struct cmd_list_element
*c
)
368 update_solib_breakpoints ();
372 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
373 struct cmd_list_element
*c
, const char *value
)
375 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
379 /* Nonzero means expecting a trace trap
380 and should stop the inferior and return silently when it happens. */
384 /* Save register contents here when executing a "finish" command or are
385 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
386 Thus this contains the return value from the called function (assuming
387 values are returned in a register). */
389 struct regcache
*stop_registers
;
391 /* Nonzero after stop if current stack frame should be printed. */
393 static int stop_print_frame
;
395 /* This is a cached copy of the pid/waitstatus of the last event
396 returned by target_wait()/deprecated_target_wait_hook(). This
397 information is returned by get_last_target_status(). */
398 static ptid_t target_last_wait_ptid
;
399 static struct target_waitstatus target_last_waitstatus
;
401 static void context_switch (ptid_t ptid
);
403 void init_thread_stepping_state (struct thread_info
*tss
);
405 static void init_infwait_state (void);
407 static const char follow_fork_mode_child
[] = "child";
408 static const char follow_fork_mode_parent
[] = "parent";
410 static const char *const follow_fork_mode_kind_names
[] = {
411 follow_fork_mode_child
,
412 follow_fork_mode_parent
,
416 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
418 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
419 struct cmd_list_element
*c
, const char *value
)
421 fprintf_filtered (file
,
422 _("Debugger response to a program "
423 "call of fork or vfork is \"%s\".\n"),
428 /* Tell the target to follow the fork we're stopped at. Returns true
429 if the inferior should be resumed; false, if the target for some
430 reason decided it's best not to resume. */
435 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
436 int should_resume
= 1;
437 struct thread_info
*tp
;
439 /* Copy user stepping state to the new inferior thread. FIXME: the
440 followed fork child thread should have a copy of most of the
441 parent thread structure's run control related fields, not just these.
442 Initialized to avoid "may be used uninitialized" warnings from gcc. */
443 struct breakpoint
*step_resume_breakpoint
= NULL
;
444 struct breakpoint
*exception_resume_breakpoint
= NULL
;
445 CORE_ADDR step_range_start
= 0;
446 CORE_ADDR step_range_end
= 0;
447 struct frame_id step_frame_id
= { 0 };
452 struct target_waitstatus wait_status
;
454 /* Get the last target status returned by target_wait(). */
455 get_last_target_status (&wait_ptid
, &wait_status
);
457 /* If not stopped at a fork event, then there's nothing else to
459 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
460 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
463 /* Check if we switched over from WAIT_PTID, since the event was
465 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
466 && !ptid_equal (inferior_ptid
, wait_ptid
))
468 /* We did. Switch back to WAIT_PTID thread, to tell the
469 target to follow it (in either direction). We'll
470 afterwards refuse to resume, and inform the user what
472 switch_to_thread (wait_ptid
);
477 tp
= inferior_thread ();
479 /* If there were any forks/vforks that were caught and are now to be
480 followed, then do so now. */
481 switch (tp
->pending_follow
.kind
)
483 case TARGET_WAITKIND_FORKED
:
484 case TARGET_WAITKIND_VFORKED
:
486 ptid_t parent
, child
;
488 /* If the user did a next/step, etc, over a fork call,
489 preserve the stepping state in the fork child. */
490 if (follow_child
&& should_resume
)
492 step_resume_breakpoint
= clone_momentary_breakpoint
493 (tp
->control
.step_resume_breakpoint
);
494 step_range_start
= tp
->control
.step_range_start
;
495 step_range_end
= tp
->control
.step_range_end
;
496 step_frame_id
= tp
->control
.step_frame_id
;
497 exception_resume_breakpoint
498 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
500 /* For now, delete the parent's sr breakpoint, otherwise,
501 parent/child sr breakpoints are considered duplicates,
502 and the child version will not be installed. Remove
503 this when the breakpoints module becomes aware of
504 inferiors and address spaces. */
505 delete_step_resume_breakpoint (tp
);
506 tp
->control
.step_range_start
= 0;
507 tp
->control
.step_range_end
= 0;
508 tp
->control
.step_frame_id
= null_frame_id
;
509 delete_exception_resume_breakpoint (tp
);
512 parent
= inferior_ptid
;
513 child
= tp
->pending_follow
.value
.related_pid
;
515 /* Tell the target to do whatever is necessary to follow
516 either parent or child. */
517 if (target_follow_fork (follow_child
))
519 /* Target refused to follow, or there's some other reason
520 we shouldn't resume. */
525 /* This pending follow fork event is now handled, one way
526 or another. The previous selected thread may be gone
527 from the lists by now, but if it is still around, need
528 to clear the pending follow request. */
529 tp
= find_thread_ptid (parent
);
531 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
533 /* This makes sure we don't try to apply the "Switched
534 over from WAIT_PID" logic above. */
535 nullify_last_target_wait_ptid ();
537 /* If we followed the child, switch to it... */
540 switch_to_thread (child
);
542 /* ... and preserve the stepping state, in case the
543 user was stepping over the fork call. */
546 tp
= inferior_thread ();
547 tp
->control
.step_resume_breakpoint
548 = step_resume_breakpoint
;
549 tp
->control
.step_range_start
= step_range_start
;
550 tp
->control
.step_range_end
= step_range_end
;
551 tp
->control
.step_frame_id
= step_frame_id
;
552 tp
->control
.exception_resume_breakpoint
553 = exception_resume_breakpoint
;
557 /* If we get here, it was because we're trying to
558 resume from a fork catchpoint, but, the user
559 has switched threads away from the thread that
560 forked. In that case, the resume command
561 issued is most likely not applicable to the
562 child, so just warn, and refuse to resume. */
563 warning (_("Not resuming: switched threads "
564 "before following fork child.\n"));
567 /* Reset breakpoints in the child as appropriate. */
568 follow_inferior_reset_breakpoints ();
571 switch_to_thread (parent
);
575 case TARGET_WAITKIND_SPURIOUS
:
576 /* Nothing to follow. */
579 internal_error (__FILE__
, __LINE__
,
580 "Unexpected pending_follow.kind %d\n",
581 tp
->pending_follow
.kind
);
585 return should_resume
;
589 follow_inferior_reset_breakpoints (void)
591 struct thread_info
*tp
= inferior_thread ();
593 /* Was there a step_resume breakpoint? (There was if the user
594 did a "next" at the fork() call.) If so, explicitly reset its
597 step_resumes are a form of bp that are made to be per-thread.
598 Since we created the step_resume bp when the parent process
599 was being debugged, and now are switching to the child process,
600 from the breakpoint package's viewpoint, that's a switch of
601 "threads". We must update the bp's notion of which thread
602 it is for, or it'll be ignored when it triggers. */
604 if (tp
->control
.step_resume_breakpoint
)
605 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
607 if (tp
->control
.exception_resume_breakpoint
)
608 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
610 /* Reinsert all breakpoints in the child. The user may have set
611 breakpoints after catching the fork, in which case those
612 were never set in the child, but only in the parent. This makes
613 sure the inserted breakpoints match the breakpoint list. */
615 breakpoint_re_set ();
616 insert_breakpoints ();
619 /* The child has exited or execed: resume threads of the parent the
620 user wanted to be executing. */
623 proceed_after_vfork_done (struct thread_info
*thread
,
626 int pid
= * (int *) arg
;
628 if (ptid_get_pid (thread
->ptid
) == pid
629 && is_running (thread
->ptid
)
630 && !is_executing (thread
->ptid
)
631 && !thread
->stop_requested
632 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
635 fprintf_unfiltered (gdb_stdlog
,
636 "infrun: resuming vfork parent thread %s\n",
637 target_pid_to_str (thread
->ptid
));
639 switch_to_thread (thread
->ptid
);
640 clear_proceed_status ();
641 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
647 /* Called whenever we notice an exec or exit event, to handle
648 detaching or resuming a vfork parent. */
651 handle_vfork_child_exec_or_exit (int exec
)
653 struct inferior
*inf
= current_inferior ();
655 if (inf
->vfork_parent
)
657 int resume_parent
= -1;
659 /* This exec or exit marks the end of the shared memory region
660 between the parent and the child. If the user wanted to
661 detach from the parent, now is the time. */
663 if (inf
->vfork_parent
->pending_detach
)
665 struct thread_info
*tp
;
666 struct cleanup
*old_chain
;
667 struct program_space
*pspace
;
668 struct address_space
*aspace
;
670 /* follow-fork child, detach-on-fork on. */
672 inf
->vfork_parent
->pending_detach
= 0;
676 /* If we're handling a child exit, then inferior_ptid
677 points at the inferior's pid, not to a thread. */
678 old_chain
= save_inferior_ptid ();
679 save_current_program_space ();
680 save_current_inferior ();
683 old_chain
= save_current_space_and_thread ();
685 /* We're letting loose of the parent. */
686 tp
= any_live_thread_of_process (inf
->vfork_parent
->pid
);
687 switch_to_thread (tp
->ptid
);
689 /* We're about to detach from the parent, which implicitly
690 removes breakpoints from its address space. There's a
691 catch here: we want to reuse the spaces for the child,
692 but, parent/child are still sharing the pspace at this
693 point, although the exec in reality makes the kernel give
694 the child a fresh set of new pages. The problem here is
695 that the breakpoints module being unaware of this, would
696 likely chose the child process to write to the parent
697 address space. Swapping the child temporarily away from
698 the spaces has the desired effect. Yes, this is "sort
701 pspace
= inf
->pspace
;
702 aspace
= inf
->aspace
;
706 if (debug_infrun
|| info_verbose
)
708 target_terminal_ours ();
711 fprintf_filtered (gdb_stdlog
,
712 "Detaching vfork parent process "
713 "%d after child exec.\n",
714 inf
->vfork_parent
->pid
);
716 fprintf_filtered (gdb_stdlog
,
717 "Detaching vfork parent process "
718 "%d after child exit.\n",
719 inf
->vfork_parent
->pid
);
722 target_detach (NULL
, 0);
725 inf
->pspace
= pspace
;
726 inf
->aspace
= aspace
;
728 do_cleanups (old_chain
);
732 /* We're staying attached to the parent, so, really give the
733 child a new address space. */
734 inf
->pspace
= add_program_space (maybe_new_address_space ());
735 inf
->aspace
= inf
->pspace
->aspace
;
737 set_current_program_space (inf
->pspace
);
739 resume_parent
= inf
->vfork_parent
->pid
;
741 /* Break the bonds. */
742 inf
->vfork_parent
->vfork_child
= NULL
;
746 struct cleanup
*old_chain
;
747 struct program_space
*pspace
;
749 /* If this is a vfork child exiting, then the pspace and
750 aspaces were shared with the parent. Since we're
751 reporting the process exit, we'll be mourning all that is
752 found in the address space, and switching to null_ptid,
753 preparing to start a new inferior. But, since we don't
754 want to clobber the parent's address/program spaces, we
755 go ahead and create a new one for this exiting
758 /* Switch to null_ptid, so that clone_program_space doesn't want
759 to read the selected frame of a dead process. */
760 old_chain
= save_inferior_ptid ();
761 inferior_ptid
= null_ptid
;
763 /* This inferior is dead, so avoid giving the breakpoints
764 module the option to write through to it (cloning a
765 program space resets breakpoints). */
768 pspace
= add_program_space (maybe_new_address_space ());
769 set_current_program_space (pspace
);
771 inf
->symfile_flags
= SYMFILE_NO_READ
;
772 clone_program_space (pspace
, inf
->vfork_parent
->pspace
);
773 inf
->pspace
= pspace
;
774 inf
->aspace
= pspace
->aspace
;
776 /* Put back inferior_ptid. We'll continue mourning this
778 do_cleanups (old_chain
);
780 resume_parent
= inf
->vfork_parent
->pid
;
781 /* Break the bonds. */
782 inf
->vfork_parent
->vfork_child
= NULL
;
785 inf
->vfork_parent
= NULL
;
787 gdb_assert (current_program_space
== inf
->pspace
);
789 if (non_stop
&& resume_parent
!= -1)
791 /* If the user wanted the parent to be running, let it go
793 struct cleanup
*old_chain
= make_cleanup_restore_current_thread ();
796 fprintf_unfiltered (gdb_stdlog
,
797 "infrun: resuming vfork parent process %d\n",
800 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
802 do_cleanups (old_chain
);
807 /* Enum strings for "set|show follow-exec-mode". */
809 static const char follow_exec_mode_new
[] = "new";
810 static const char follow_exec_mode_same
[] = "same";
811 static const char *const follow_exec_mode_names
[] =
813 follow_exec_mode_new
,
814 follow_exec_mode_same
,
818 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
820 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
821 struct cmd_list_element
*c
, const char *value
)
823 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
826 /* EXECD_PATHNAME is assumed to be non-NULL. */
829 follow_exec (ptid_t pid
, char *execd_pathname
)
831 struct thread_info
*th
= inferior_thread ();
832 struct inferior
*inf
= current_inferior ();
834 /* This is an exec event that we actually wish to pay attention to.
835 Refresh our symbol table to the newly exec'd program, remove any
838 If there are breakpoints, they aren't really inserted now,
839 since the exec() transformed our inferior into a fresh set
842 We want to preserve symbolic breakpoints on the list, since
843 we have hopes that they can be reset after the new a.out's
844 symbol table is read.
846 However, any "raw" breakpoints must be removed from the list
847 (e.g., the solib bp's), since their address is probably invalid
850 And, we DON'T want to call delete_breakpoints() here, since
851 that may write the bp's "shadow contents" (the instruction
852 value that was overwritten witha TRAP instruction). Since
853 we now have a new a.out, those shadow contents aren't valid. */
855 mark_breakpoints_out ();
857 update_breakpoints_after_exec ();
859 /* If there was one, it's gone now. We cannot truly step-to-next
860 statement through an exec(). */
861 th
->control
.step_resume_breakpoint
= NULL
;
862 th
->control
.exception_resume_breakpoint
= NULL
;
863 th
->control
.step_range_start
= 0;
864 th
->control
.step_range_end
= 0;
866 /* The target reports the exec event to the main thread, even if
867 some other thread does the exec, and even if the main thread was
868 already stopped --- if debugging in non-stop mode, it's possible
869 the user had the main thread held stopped in the previous image
870 --- release it now. This is the same behavior as step-over-exec
871 with scheduler-locking on in all-stop mode. */
872 th
->stop_requested
= 0;
874 /* What is this a.out's name? */
875 printf_unfiltered (_("%s is executing new program: %s\n"),
876 target_pid_to_str (inferior_ptid
),
879 /* We've followed the inferior through an exec. Therefore, the
880 inferior has essentially been killed & reborn. */
882 gdb_flush (gdb_stdout
);
884 breakpoint_init_inferior (inf_execd
);
886 if (gdb_sysroot
&& *gdb_sysroot
)
888 char *name
= alloca (strlen (gdb_sysroot
)
889 + strlen (execd_pathname
)
892 strcpy (name
, gdb_sysroot
);
893 strcat (name
, execd_pathname
);
894 execd_pathname
= name
;
897 /* Reset the shared library package. This ensures that we get a
898 shlib event when the child reaches "_start", at which point the
899 dld will have had a chance to initialize the child. */
900 /* Also, loading a symbol file below may trigger symbol lookups, and
901 we don't want those to be satisfied by the libraries of the
902 previous incarnation of this process. */
903 no_shared_libraries (NULL
, 0);
905 if (follow_exec_mode_string
== follow_exec_mode_new
)
907 struct program_space
*pspace
;
909 /* The user wants to keep the old inferior and program spaces
910 around. Create a new fresh one, and switch to it. */
912 inf
= add_inferior (current_inferior ()->pid
);
913 pspace
= add_program_space (maybe_new_address_space ());
914 inf
->pspace
= pspace
;
915 inf
->aspace
= pspace
->aspace
;
917 exit_inferior_num_silent (current_inferior ()->num
);
919 set_current_inferior (inf
);
920 set_current_program_space (pspace
);
924 /* The old description may no longer be fit for the new image.
925 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
926 old description; we'll read a new one below. No need to do
927 this on "follow-exec-mode new", as the old inferior stays
928 around (its description is later cleared/refetched on
930 target_clear_description ();
933 gdb_assert (current_program_space
== inf
->pspace
);
935 /* That a.out is now the one to use. */
936 exec_file_attach (execd_pathname
, 0);
938 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
939 (Position Independent Executable) main symbol file will get applied by
940 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
941 the breakpoints with the zero displacement. */
943 symbol_file_add (execd_pathname
,
945 | SYMFILE_MAINLINE
| SYMFILE_DEFER_BP_RESET
),
948 if ((inf
->symfile_flags
& SYMFILE_NO_READ
) == 0)
949 set_initial_language ();
951 /* If the target can specify a description, read it. Must do this
952 after flipping to the new executable (because the target supplied
953 description must be compatible with the executable's
954 architecture, and the old executable may e.g., be 32-bit, while
955 the new one 64-bit), and before anything involving memory or
957 target_find_description ();
959 solib_create_inferior_hook (0);
961 jit_inferior_created_hook ();
963 breakpoint_re_set ();
965 /* Reinsert all breakpoints. (Those which were symbolic have
966 been reset to the proper address in the new a.out, thanks
967 to symbol_file_command...). */
968 insert_breakpoints ();
970 /* The next resume of this inferior should bring it to the shlib
971 startup breakpoints. (If the user had also set bp's on
972 "main" from the old (parent) process, then they'll auto-
973 matically get reset there in the new process.). */
976 /* Non-zero if we just simulating a single-step. This is needed
977 because we cannot remove the breakpoints in the inferior process
978 until after the `wait' in `wait_for_inferior'. */
979 static int singlestep_breakpoints_inserted_p
= 0;
981 /* The thread we inserted single-step breakpoints for. */
982 static ptid_t singlestep_ptid
;
984 /* PC when we started this single-step. */
985 static CORE_ADDR singlestep_pc
;
987 /* If another thread hit the singlestep breakpoint, we save the original
988 thread here so that we can resume single-stepping it later. */
989 static ptid_t saved_singlestep_ptid
;
990 static int stepping_past_singlestep_breakpoint
;
992 /* If not equal to null_ptid, this means that after stepping over breakpoint
993 is finished, we need to switch to deferred_step_ptid, and step it.
995 The use case is when one thread has hit a breakpoint, and then the user
996 has switched to another thread and issued 'step'. We need to step over
997 breakpoint in the thread which hit the breakpoint, but then continue
998 stepping the thread user has selected. */
999 static ptid_t deferred_step_ptid
;
1001 /* Displaced stepping. */
1003 /* In non-stop debugging mode, we must take special care to manage
1004 breakpoints properly; in particular, the traditional strategy for
1005 stepping a thread past a breakpoint it has hit is unsuitable.
1006 'Displaced stepping' is a tactic for stepping one thread past a
1007 breakpoint it has hit while ensuring that other threads running
1008 concurrently will hit the breakpoint as they should.
1010 The traditional way to step a thread T off a breakpoint in a
1011 multi-threaded program in all-stop mode is as follows:
1013 a0) Initially, all threads are stopped, and breakpoints are not
1015 a1) We single-step T, leaving breakpoints uninserted.
1016 a2) We insert breakpoints, and resume all threads.
1018 In non-stop debugging, however, this strategy is unsuitable: we
1019 don't want to have to stop all threads in the system in order to
1020 continue or step T past a breakpoint. Instead, we use displaced
1023 n0) Initially, T is stopped, other threads are running, and
1024 breakpoints are inserted.
1025 n1) We copy the instruction "under" the breakpoint to a separate
1026 location, outside the main code stream, making any adjustments
1027 to the instruction, register, and memory state as directed by
1029 n2) We single-step T over the instruction at its new location.
1030 n3) We adjust the resulting register and memory state as directed
1031 by T's architecture. This includes resetting T's PC to point
1032 back into the main instruction stream.
1035 This approach depends on the following gdbarch methods:
1037 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1038 indicate where to copy the instruction, and how much space must
1039 be reserved there. We use these in step n1.
1041 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1042 address, and makes any necessary adjustments to the instruction,
1043 register contents, and memory. We use this in step n1.
1045 - gdbarch_displaced_step_fixup adjusts registers and memory after
1046 we have successfuly single-stepped the instruction, to yield the
1047 same effect the instruction would have had if we had executed it
1048 at its original address. We use this in step n3.
1050 - gdbarch_displaced_step_free_closure provides cleanup.
1052 The gdbarch_displaced_step_copy_insn and
1053 gdbarch_displaced_step_fixup functions must be written so that
1054 copying an instruction with gdbarch_displaced_step_copy_insn,
1055 single-stepping across the copied instruction, and then applying
1056 gdbarch_displaced_insn_fixup should have the same effects on the
1057 thread's memory and registers as stepping the instruction in place
1058 would have. Exactly which responsibilities fall to the copy and
1059 which fall to the fixup is up to the author of those functions.
1061 See the comments in gdbarch.sh for details.
1063 Note that displaced stepping and software single-step cannot
1064 currently be used in combination, although with some care I think
1065 they could be made to. Software single-step works by placing
1066 breakpoints on all possible subsequent instructions; if the
1067 displaced instruction is a PC-relative jump, those breakpoints
1068 could fall in very strange places --- on pages that aren't
1069 executable, or at addresses that are not proper instruction
1070 boundaries. (We do generally let other threads run while we wait
1071 to hit the software single-step breakpoint, and they might
1072 encounter such a corrupted instruction.) One way to work around
1073 this would be to have gdbarch_displaced_step_copy_insn fully
1074 simulate the effect of PC-relative instructions (and return NULL)
1075 on architectures that use software single-stepping.
1077 In non-stop mode, we can have independent and simultaneous step
1078 requests, so more than one thread may need to simultaneously step
1079 over a breakpoint. The current implementation assumes there is
1080 only one scratch space per process. In this case, we have to
1081 serialize access to the scratch space. If thread A wants to step
1082 over a breakpoint, but we are currently waiting for some other
1083 thread to complete a displaced step, we leave thread A stopped and
1084 place it in the displaced_step_request_queue. Whenever a displaced
1085 step finishes, we pick the next thread in the queue and start a new
1086 displaced step operation on it. See displaced_step_prepare and
1087 displaced_step_fixup for details. */
1089 struct displaced_step_request
1092 struct displaced_step_request
*next
;
1095 /* Per-inferior displaced stepping state. */
1096 struct displaced_step_inferior_state
1098 /* Pointer to next in linked list. */
1099 struct displaced_step_inferior_state
*next
;
1101 /* The process this displaced step state refers to. */
1104 /* A queue of pending displaced stepping requests. One entry per
1105 thread that needs to do a displaced step. */
1106 struct displaced_step_request
*step_request_queue
;
1108 /* If this is not null_ptid, this is the thread carrying out a
1109 displaced single-step in process PID. This thread's state will
1110 require fixing up once it has completed its step. */
1113 /* The architecture the thread had when we stepped it. */
1114 struct gdbarch
*step_gdbarch
;
1116 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1117 for post-step cleanup. */
1118 struct displaced_step_closure
*step_closure
;
1120 /* The address of the original instruction, and the copy we
1122 CORE_ADDR step_original
, step_copy
;
1124 /* Saved contents of copy area. */
1125 gdb_byte
*step_saved_copy
;
1128 /* The list of states of processes involved in displaced stepping
1130 static struct displaced_step_inferior_state
*displaced_step_inferior_states
;
1132 /* Get the displaced stepping state of process PID. */
1134 static struct displaced_step_inferior_state
*
1135 get_displaced_stepping_state (int pid
)
1137 struct displaced_step_inferior_state
*state
;
1139 for (state
= displaced_step_inferior_states
;
1141 state
= state
->next
)
1142 if (state
->pid
== pid
)
1148 /* Add a new displaced stepping state for process PID to the displaced
1149 stepping state list, or return a pointer to an already existing
1150 entry, if it already exists. Never returns NULL. */
1152 static struct displaced_step_inferior_state
*
1153 add_displaced_stepping_state (int pid
)
1155 struct displaced_step_inferior_state
*state
;
1157 for (state
= displaced_step_inferior_states
;
1159 state
= state
->next
)
1160 if (state
->pid
== pid
)
1163 state
= xcalloc (1, sizeof (*state
));
1165 state
->next
= displaced_step_inferior_states
;
1166 displaced_step_inferior_states
= state
;
1171 /* If inferior is in displaced stepping, and ADDR equals to starting address
1172 of copy area, return corresponding displaced_step_closure. Otherwise,
1175 struct displaced_step_closure
*
1176 get_displaced_step_closure_by_addr (CORE_ADDR addr
)
1178 struct displaced_step_inferior_state
*displaced
1179 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1181 /* If checking the mode of displaced instruction in copy area. */
1182 if (displaced
&& !ptid_equal (displaced
->step_ptid
, null_ptid
)
1183 && (displaced
->step_copy
== addr
))
1184 return displaced
->step_closure
;
1189 /* Remove the displaced stepping state of process PID. */
1192 remove_displaced_stepping_state (int pid
)
1194 struct displaced_step_inferior_state
*it
, **prev_next_p
;
1196 gdb_assert (pid
!= 0);
1198 it
= displaced_step_inferior_states
;
1199 prev_next_p
= &displaced_step_inferior_states
;
1204 *prev_next_p
= it
->next
;
1209 prev_next_p
= &it
->next
;
1215 infrun_inferior_exit (struct inferior
*inf
)
1217 remove_displaced_stepping_state (inf
->pid
);
1220 /* If ON, and the architecture supports it, GDB will use displaced
1221 stepping to step over breakpoints. If OFF, or if the architecture
1222 doesn't support it, GDB will instead use the traditional
1223 hold-and-step approach. If AUTO (which is the default), GDB will
1224 decide which technique to use to step over breakpoints depending on
1225 which of all-stop or non-stop mode is active --- displaced stepping
1226 in non-stop mode; hold-and-step in all-stop mode. */
1228 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1231 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1232 struct cmd_list_element
*c
,
1235 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1236 fprintf_filtered (file
,
1237 _("Debugger's willingness to use displaced stepping "
1238 "to step over breakpoints is %s (currently %s).\n"),
1239 value
, non_stop
? "on" : "off");
1241 fprintf_filtered (file
,
1242 _("Debugger's willingness to use displaced stepping "
1243 "to step over breakpoints is %s.\n"), value
);
1246 /* Return non-zero if displaced stepping can/should be used to step
1247 over breakpoints. */
1250 use_displaced_stepping (struct gdbarch
*gdbarch
)
1252 return (((can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
&& non_stop
)
1253 || can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1254 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
1255 && !RECORD_IS_USED
);
1258 /* Clean out any stray displaced stepping state. */
1260 displaced_step_clear (struct displaced_step_inferior_state
*displaced
)
1262 /* Indicate that there is no cleanup pending. */
1263 displaced
->step_ptid
= null_ptid
;
1265 if (displaced
->step_closure
)
1267 gdbarch_displaced_step_free_closure (displaced
->step_gdbarch
,
1268 displaced
->step_closure
);
1269 displaced
->step_closure
= NULL
;
1274 displaced_step_clear_cleanup (void *arg
)
1276 struct displaced_step_inferior_state
*state
= arg
;
1278 displaced_step_clear (state
);
1281 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1283 displaced_step_dump_bytes (struct ui_file
*file
,
1284 const gdb_byte
*buf
,
1289 for (i
= 0; i
< len
; i
++)
1290 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1291 fputs_unfiltered ("\n", file
);
1294 /* Prepare to single-step, using displaced stepping.
1296 Note that we cannot use displaced stepping when we have a signal to
1297 deliver. If we have a signal to deliver and an instruction to step
1298 over, then after the step, there will be no indication from the
1299 target whether the thread entered a signal handler or ignored the
1300 signal and stepped over the instruction successfully --- both cases
1301 result in a simple SIGTRAP. In the first case we mustn't do a
1302 fixup, and in the second case we must --- but we can't tell which.
1303 Comments in the code for 'random signals' in handle_inferior_event
1304 explain how we handle this case instead.
1306 Returns 1 if preparing was successful -- this thread is going to be
1307 stepped now; or 0 if displaced stepping this thread got queued. */
1309 displaced_step_prepare (ptid_t ptid
)
1311 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1312 struct thread_info
*tp
= find_thread_ptid (ptid
);
1313 struct regcache
*regcache
= get_thread_regcache (ptid
);
1314 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1315 CORE_ADDR original
, copy
;
1317 struct displaced_step_closure
*closure
;
1318 struct displaced_step_inferior_state
*displaced
;
1321 /* We should never reach this function if the architecture does not
1322 support displaced stepping. */
1323 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1325 /* Disable range stepping while executing in the scratch pad. We
1326 want a single-step even if executing the displaced instruction in
1327 the scratch buffer lands within the stepping range (e.g., a
1329 tp
->control
.may_range_step
= 0;
1331 /* We have to displaced step one thread at a time, as we only have
1332 access to a single scratch space per inferior. */
1334 displaced
= add_displaced_stepping_state (ptid_get_pid (ptid
));
1336 if (!ptid_equal (displaced
->step_ptid
, null_ptid
))
1338 /* Already waiting for a displaced step to finish. Defer this
1339 request and place in queue. */
1340 struct displaced_step_request
*req
, *new_req
;
1342 if (debug_displaced
)
1343 fprintf_unfiltered (gdb_stdlog
,
1344 "displaced: defering step of %s\n",
1345 target_pid_to_str (ptid
));
1347 new_req
= xmalloc (sizeof (*new_req
));
1348 new_req
->ptid
= ptid
;
1349 new_req
->next
= NULL
;
1351 if (displaced
->step_request_queue
)
1353 for (req
= displaced
->step_request_queue
;
1357 req
->next
= new_req
;
1360 displaced
->step_request_queue
= new_req
;
1366 if (debug_displaced
)
1367 fprintf_unfiltered (gdb_stdlog
,
1368 "displaced: stepping %s now\n",
1369 target_pid_to_str (ptid
));
1372 displaced_step_clear (displaced
);
1374 old_cleanups
= save_inferior_ptid ();
1375 inferior_ptid
= ptid
;
1377 original
= regcache_read_pc (regcache
);
1379 copy
= gdbarch_displaced_step_location (gdbarch
);
1380 len
= gdbarch_max_insn_length (gdbarch
);
1382 /* Save the original contents of the copy area. */
1383 displaced
->step_saved_copy
= xmalloc (len
);
1384 ignore_cleanups
= make_cleanup (free_current_contents
,
1385 &displaced
->step_saved_copy
);
1386 status
= target_read_memory (copy
, displaced
->step_saved_copy
, len
);
1388 throw_error (MEMORY_ERROR
,
1389 _("Error accessing memory address %s (%s) for "
1390 "displaced-stepping scratch space."),
1391 paddress (gdbarch
, copy
), safe_strerror (status
));
1392 if (debug_displaced
)
1394 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1395 paddress (gdbarch
, copy
));
1396 displaced_step_dump_bytes (gdb_stdlog
,
1397 displaced
->step_saved_copy
,
1401 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1402 original
, copy
, regcache
);
1404 /* We don't support the fully-simulated case at present. */
1405 gdb_assert (closure
);
1407 /* Save the information we need to fix things up if the step
1409 displaced
->step_ptid
= ptid
;
1410 displaced
->step_gdbarch
= gdbarch
;
1411 displaced
->step_closure
= closure
;
1412 displaced
->step_original
= original
;
1413 displaced
->step_copy
= copy
;
1415 make_cleanup (displaced_step_clear_cleanup
, displaced
);
1417 /* Resume execution at the copy. */
1418 regcache_write_pc (regcache
, copy
);
1420 discard_cleanups (ignore_cleanups
);
1422 do_cleanups (old_cleanups
);
1424 if (debug_displaced
)
1425 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1426 paddress (gdbarch
, copy
));
1432 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
,
1433 const gdb_byte
*myaddr
, int len
)
1435 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1437 inferior_ptid
= ptid
;
1438 write_memory (memaddr
, myaddr
, len
);
1439 do_cleanups (ptid_cleanup
);
1442 /* Restore the contents of the copy area for thread PTID. */
1445 displaced_step_restore (struct displaced_step_inferior_state
*displaced
,
1448 ULONGEST len
= gdbarch_max_insn_length (displaced
->step_gdbarch
);
1450 write_memory_ptid (ptid
, displaced
->step_copy
,
1451 displaced
->step_saved_copy
, len
);
1452 if (debug_displaced
)
1453 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s %s\n",
1454 target_pid_to_str (ptid
),
1455 paddress (displaced
->step_gdbarch
,
1456 displaced
->step_copy
));
1460 displaced_step_fixup (ptid_t event_ptid
, enum gdb_signal signal
)
1462 struct cleanup
*old_cleanups
;
1463 struct displaced_step_inferior_state
*displaced
1464 = get_displaced_stepping_state (ptid_get_pid (event_ptid
));
1466 /* Was any thread of this process doing a displaced step? */
1467 if (displaced
== NULL
)
1470 /* Was this event for the pid we displaced? */
1471 if (ptid_equal (displaced
->step_ptid
, null_ptid
)
1472 || ! ptid_equal (displaced
->step_ptid
, event_ptid
))
1475 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, displaced
);
1477 displaced_step_restore (displaced
, displaced
->step_ptid
);
1479 /* Did the instruction complete successfully? */
1480 if (signal
== GDB_SIGNAL_TRAP
)
1482 /* Fix up the resulting state. */
1483 gdbarch_displaced_step_fixup (displaced
->step_gdbarch
,
1484 displaced
->step_closure
,
1485 displaced
->step_original
,
1486 displaced
->step_copy
,
1487 get_thread_regcache (displaced
->step_ptid
));
1491 /* Since the instruction didn't complete, all we can do is
1493 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1494 CORE_ADDR pc
= regcache_read_pc (regcache
);
1496 pc
= displaced
->step_original
+ (pc
- displaced
->step_copy
);
1497 regcache_write_pc (regcache
, pc
);
1500 do_cleanups (old_cleanups
);
1502 displaced
->step_ptid
= null_ptid
;
1504 /* Are there any pending displaced stepping requests? If so, run
1505 one now. Leave the state object around, since we're likely to
1506 need it again soon. */
1507 while (displaced
->step_request_queue
)
1509 struct displaced_step_request
*head
;
1511 struct regcache
*regcache
;
1512 struct gdbarch
*gdbarch
;
1513 CORE_ADDR actual_pc
;
1514 struct address_space
*aspace
;
1516 head
= displaced
->step_request_queue
;
1518 displaced
->step_request_queue
= head
->next
;
1521 context_switch (ptid
);
1523 regcache
= get_thread_regcache (ptid
);
1524 actual_pc
= regcache_read_pc (regcache
);
1525 aspace
= get_regcache_aspace (regcache
);
1527 if (breakpoint_here_p (aspace
, actual_pc
))
1529 if (debug_displaced
)
1530 fprintf_unfiltered (gdb_stdlog
,
1531 "displaced: stepping queued %s now\n",
1532 target_pid_to_str (ptid
));
1534 displaced_step_prepare (ptid
);
1536 gdbarch
= get_regcache_arch (regcache
);
1538 if (debug_displaced
)
1540 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1543 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1544 paddress (gdbarch
, actual_pc
));
1545 read_memory (actual_pc
, buf
, sizeof (buf
));
1546 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1549 if (gdbarch_displaced_step_hw_singlestep (gdbarch
,
1550 displaced
->step_closure
))
1551 target_resume (ptid
, 1, GDB_SIGNAL_0
);
1553 target_resume (ptid
, 0, GDB_SIGNAL_0
);
1555 /* Done, we're stepping a thread. */
1561 struct thread_info
*tp
= inferior_thread ();
1563 /* The breakpoint we were sitting under has since been
1565 tp
->control
.trap_expected
= 0;
1567 /* Go back to what we were trying to do. */
1568 step
= currently_stepping (tp
);
1570 if (debug_displaced
)
1571 fprintf_unfiltered (gdb_stdlog
,
1572 "displaced: breakpoint is gone: %s, step(%d)\n",
1573 target_pid_to_str (tp
->ptid
), step
);
1575 target_resume (ptid
, step
, GDB_SIGNAL_0
);
1576 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1578 /* This request was discarded. See if there's any other
1579 thread waiting for its turn. */
1584 /* Update global variables holding ptids to hold NEW_PTID if they were
1585 holding OLD_PTID. */
1587 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1589 struct displaced_step_request
*it
;
1590 struct displaced_step_inferior_state
*displaced
;
1592 if (ptid_equal (inferior_ptid
, old_ptid
))
1593 inferior_ptid
= new_ptid
;
1595 if (ptid_equal (singlestep_ptid
, old_ptid
))
1596 singlestep_ptid
= new_ptid
;
1598 if (ptid_equal (deferred_step_ptid
, old_ptid
))
1599 deferred_step_ptid
= new_ptid
;
1601 for (displaced
= displaced_step_inferior_states
;
1603 displaced
= displaced
->next
)
1605 if (ptid_equal (displaced
->step_ptid
, old_ptid
))
1606 displaced
->step_ptid
= new_ptid
;
1608 for (it
= displaced
->step_request_queue
; it
; it
= it
->next
)
1609 if (ptid_equal (it
->ptid
, old_ptid
))
1610 it
->ptid
= new_ptid
;
1617 /* Things to clean up if we QUIT out of resume (). */
1619 resume_cleanups (void *ignore
)
1624 static const char schedlock_off
[] = "off";
1625 static const char schedlock_on
[] = "on";
1626 static const char schedlock_step
[] = "step";
1627 static const char *const scheduler_enums
[] = {
1633 static const char *scheduler_mode
= schedlock_off
;
1635 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1636 struct cmd_list_element
*c
, const char *value
)
1638 fprintf_filtered (file
,
1639 _("Mode for locking scheduler "
1640 "during execution is \"%s\".\n"),
1645 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1647 if (!target_can_lock_scheduler
)
1649 scheduler_mode
= schedlock_off
;
1650 error (_("Target '%s' cannot support this command."), target_shortname
);
1654 /* True if execution commands resume all threads of all processes by
1655 default; otherwise, resume only threads of the current inferior
1657 int sched_multi
= 0;
1659 /* Try to setup for software single stepping over the specified location.
1660 Return 1 if target_resume() should use hardware single step.
1662 GDBARCH the current gdbarch.
1663 PC the location to step over. */
1666 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1670 if (execution_direction
== EXEC_FORWARD
1671 && gdbarch_software_single_step_p (gdbarch
)
1672 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1675 /* Do not pull these breakpoints until after a `wait' in
1676 `wait_for_inferior'. */
1677 singlestep_breakpoints_inserted_p
= 1;
1678 singlestep_ptid
= inferior_ptid
;
1684 /* Return a ptid representing the set of threads that we will proceed,
1685 in the perspective of the user/frontend. We may actually resume
1686 fewer threads at first, e.g., if a thread is stopped at a
1687 breakpoint that needs stepping-off, but that should not be visible
1688 to the user/frontend, and neither should the frontend/user be
1689 allowed to proceed any of the threads that happen to be stopped for
1690 internal run control handling, if a previous command wanted them
1694 user_visible_resume_ptid (int step
)
1696 /* By default, resume all threads of all processes. */
1697 ptid_t resume_ptid
= RESUME_ALL
;
1699 /* Maybe resume only all threads of the current process. */
1700 if (!sched_multi
&& target_supports_multi_process ())
1702 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
1705 /* Maybe resume a single thread after all. */
1708 /* With non-stop mode on, threads are always handled
1710 resume_ptid
= inferior_ptid
;
1712 else if ((scheduler_mode
== schedlock_on
)
1713 || (scheduler_mode
== schedlock_step
1714 && (step
|| singlestep_breakpoints_inserted_p
)))
1716 /* User-settable 'scheduler' mode requires solo thread resume. */
1717 resume_ptid
= inferior_ptid
;
1723 /* Resume the inferior, but allow a QUIT. This is useful if the user
1724 wants to interrupt some lengthy single-stepping operation
1725 (for child processes, the SIGINT goes to the inferior, and so
1726 we get a SIGINT random_signal, but for remote debugging and perhaps
1727 other targets, that's not true).
1729 STEP nonzero if we should step (zero to continue instead).
1730 SIG is the signal to give the inferior (zero for none). */
1732 resume (int step
, enum gdb_signal sig
)
1734 int should_resume
= 1;
1735 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
1736 struct regcache
*regcache
= get_current_regcache ();
1737 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1738 struct thread_info
*tp
= inferior_thread ();
1739 CORE_ADDR pc
= regcache_read_pc (regcache
);
1740 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1744 if (current_inferior ()->waiting_for_vfork_done
)
1746 /* Don't try to single-step a vfork parent that is waiting for
1747 the child to get out of the shared memory region (by exec'ing
1748 or exiting). This is particularly important on software
1749 single-step archs, as the child process would trip on the
1750 software single step breakpoint inserted for the parent
1751 process. Since the parent will not actually execute any
1752 instruction until the child is out of the shared region (such
1753 are vfork's semantics), it is safe to simply continue it.
1754 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1755 the parent, and tell it to `keep_going', which automatically
1756 re-sets it stepping. */
1758 fprintf_unfiltered (gdb_stdlog
,
1759 "infrun: resume : clear step\n");
1764 fprintf_unfiltered (gdb_stdlog
,
1765 "infrun: resume (step=%d, signal=%d), "
1766 "trap_expected=%d, current thread [%s] at %s\n",
1767 step
, sig
, tp
->control
.trap_expected
,
1768 target_pid_to_str (inferior_ptid
),
1769 paddress (gdbarch
, pc
));
1771 /* Normally, by the time we reach `resume', the breakpoints are either
1772 removed or inserted, as appropriate. The exception is if we're sitting
1773 at a permanent breakpoint; we need to step over it, but permanent
1774 breakpoints can't be removed. So we have to test for it here. */
1775 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
1777 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1778 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1781 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1782 how to step past a permanent breakpoint on this architecture. Try using\n\
1783 a command like `return' or `jump' to continue execution."));
1786 /* If we have a breakpoint to step over, make sure to do a single
1787 step only. Same if we have software watchpoints. */
1788 if (tp
->control
.trap_expected
|| bpstat_should_step ())
1789 tp
->control
.may_range_step
= 0;
1791 /* If enabled, step over breakpoints by executing a copy of the
1792 instruction at a different address.
1794 We can't use displaced stepping when we have a signal to deliver;
1795 the comments for displaced_step_prepare explain why. The
1796 comments in the handle_inferior event for dealing with 'random
1797 signals' explain what we do instead.
1799 We can't use displaced stepping when we are waiting for vfork_done
1800 event, displaced stepping breaks the vfork child similarly as single
1801 step software breakpoint. */
1802 if (use_displaced_stepping (gdbarch
)
1803 && (tp
->control
.trap_expected
1804 || (step
&& gdbarch_software_single_step_p (gdbarch
)))
1805 && sig
== GDB_SIGNAL_0
1806 && !current_inferior ()->waiting_for_vfork_done
)
1808 struct displaced_step_inferior_state
*displaced
;
1810 if (!displaced_step_prepare (inferior_ptid
))
1812 /* Got placed in displaced stepping queue. Will be resumed
1813 later when all the currently queued displaced stepping
1814 requests finish. The thread is not executing at this point,
1815 and the call to set_executing will be made later. But we
1816 need to call set_running here, since from frontend point of view,
1817 the thread is running. */
1818 set_running (inferior_ptid
, 1);
1819 discard_cleanups (old_cleanups
);
1823 /* Update pc to reflect the new address from which we will execute
1824 instructions due to displaced stepping. */
1825 pc
= regcache_read_pc (get_thread_regcache (inferior_ptid
));
1827 displaced
= get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1828 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
,
1829 displaced
->step_closure
);
1832 /* Do we need to do it the hard way, w/temp breakpoints? */
1834 step
= maybe_software_singlestep (gdbarch
, pc
);
1836 /* Currently, our software single-step implementation leads to different
1837 results than hardware single-stepping in one situation: when stepping
1838 into delivering a signal which has an associated signal handler,
1839 hardware single-step will stop at the first instruction of the handler,
1840 while software single-step will simply skip execution of the handler.
1842 For now, this difference in behavior is accepted since there is no
1843 easy way to actually implement single-stepping into a signal handler
1844 without kernel support.
1846 However, there is one scenario where this difference leads to follow-on
1847 problems: if we're stepping off a breakpoint by removing all breakpoints
1848 and then single-stepping. In this case, the software single-step
1849 behavior means that even if there is a *breakpoint* in the signal
1850 handler, GDB still would not stop.
1852 Fortunately, we can at least fix this particular issue. We detect
1853 here the case where we are about to deliver a signal while software
1854 single-stepping with breakpoints removed. In this situation, we
1855 revert the decisions to remove all breakpoints and insert single-
1856 step breakpoints, and instead we install a step-resume breakpoint
1857 at the current address, deliver the signal without stepping, and
1858 once we arrive back at the step-resume breakpoint, actually step
1859 over the breakpoint we originally wanted to step over. */
1860 if (singlestep_breakpoints_inserted_p
1861 && tp
->control
.trap_expected
&& sig
!= GDB_SIGNAL_0
)
1863 /* If we have nested signals or a pending signal is delivered
1864 immediately after a handler returns, might might already have
1865 a step-resume breakpoint set on the earlier handler. We cannot
1866 set another step-resume breakpoint; just continue on until the
1867 original breakpoint is hit. */
1868 if (tp
->control
.step_resume_breakpoint
== NULL
)
1870 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
1871 tp
->step_after_step_resume_breakpoint
= 1;
1874 remove_single_step_breakpoints ();
1875 singlestep_breakpoints_inserted_p
= 0;
1877 insert_breakpoints ();
1878 tp
->control
.trap_expected
= 0;
1885 /* If STEP is set, it's a request to use hardware stepping
1886 facilities. But in that case, we should never
1887 use singlestep breakpoint. */
1888 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1890 /* Decide the set of threads to ask the target to resume. Start
1891 by assuming everything will be resumed, than narrow the set
1892 by applying increasingly restricting conditions. */
1893 resume_ptid
= user_visible_resume_ptid (step
);
1895 /* Maybe resume a single thread after all. */
1896 if (singlestep_breakpoints_inserted_p
1897 && stepping_past_singlestep_breakpoint
)
1899 /* The situation here is as follows. In thread T1 we wanted to
1900 single-step. Lacking hardware single-stepping we've
1901 set breakpoint at the PC of the next instruction -- call it
1902 P. After resuming, we've hit that breakpoint in thread T2.
1903 Now we've removed original breakpoint, inserted breakpoint
1904 at P+1, and try to step to advance T2 past breakpoint.
1905 We need to step only T2, as if T1 is allowed to freely run,
1906 it can run past P, and if other threads are allowed to run,
1907 they can hit breakpoint at P+1, and nested hits of single-step
1908 breakpoints is not something we'd want -- that's complicated
1909 to support, and has no value. */
1910 resume_ptid
= inferior_ptid
;
1912 else if ((step
|| singlestep_breakpoints_inserted_p
)
1913 && tp
->control
.trap_expected
)
1915 /* We're allowing a thread to run past a breakpoint it has
1916 hit, by single-stepping the thread with the breakpoint
1917 removed. In which case, we need to single-step only this
1918 thread, and keep others stopped, as they can miss this
1919 breakpoint if allowed to run.
1921 The current code actually removes all breakpoints when
1922 doing this, not just the one being stepped over, so if we
1923 let other threads run, we can actually miss any
1924 breakpoint, not just the one at PC. */
1925 resume_ptid
= inferior_ptid
;
1928 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1930 /* Most targets can step a breakpoint instruction, thus
1931 executing it normally. But if this one cannot, just
1932 continue and we will hit it anyway. */
1933 if (step
&& breakpoint_inserted_here_p (aspace
, pc
))
1938 && use_displaced_stepping (gdbarch
)
1939 && tp
->control
.trap_expected
)
1941 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1942 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
1943 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1946 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1947 paddress (resume_gdbarch
, actual_pc
));
1948 read_memory (actual_pc
, buf
, sizeof (buf
));
1949 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1952 if (tp
->control
.may_range_step
)
1954 /* If we're resuming a thread with the PC out of the step
1955 range, then we're doing some nested/finer run control
1956 operation, like stepping the thread out of the dynamic
1957 linker or the displaced stepping scratch pad. We
1958 shouldn't have allowed a range step then. */
1959 gdb_assert (pc_in_thread_step_range (pc
, tp
));
1962 /* Install inferior's terminal modes. */
1963 target_terminal_inferior ();
1965 /* Avoid confusing the next resume, if the next stop/resume
1966 happens to apply to another thread. */
1967 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1969 /* Advise target which signals may be handled silently. If we have
1970 removed breakpoints because we are stepping over one (which can
1971 happen only if we are not using displaced stepping), we need to
1972 receive all signals to avoid accidentally skipping a breakpoint
1973 during execution of a signal handler. */
1974 if ((step
|| singlestep_breakpoints_inserted_p
)
1975 && tp
->control
.trap_expected
1976 && !use_displaced_stepping (gdbarch
))
1977 target_pass_signals (0, NULL
);
1979 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
1981 target_resume (resume_ptid
, step
, sig
);
1984 discard_cleanups (old_cleanups
);
1989 /* Clear out all variables saying what to do when inferior is continued.
1990 First do this, then set the ones you want, then call `proceed'. */
1993 clear_proceed_status_thread (struct thread_info
*tp
)
1996 fprintf_unfiltered (gdb_stdlog
,
1997 "infrun: clear_proceed_status_thread (%s)\n",
1998 target_pid_to_str (tp
->ptid
));
2000 tp
->control
.trap_expected
= 0;
2001 tp
->control
.step_range_start
= 0;
2002 tp
->control
.step_range_end
= 0;
2003 tp
->control
.may_range_step
= 0;
2004 tp
->control
.step_frame_id
= null_frame_id
;
2005 tp
->control
.step_stack_frame_id
= null_frame_id
;
2006 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2007 tp
->stop_requested
= 0;
2009 tp
->control
.stop_step
= 0;
2011 tp
->control
.proceed_to_finish
= 0;
2013 /* Discard any remaining commands or status from previous stop. */
2014 bpstat_clear (&tp
->control
.stop_bpstat
);
2018 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
2020 if (is_exited (tp
->ptid
))
2023 clear_proceed_status_thread (tp
);
2028 clear_proceed_status (void)
2032 /* In all-stop mode, delete the per-thread status of all
2033 threads, even if inferior_ptid is null_ptid, there may be
2034 threads on the list. E.g., we may be launching a new
2035 process, while selecting the executable. */
2036 iterate_over_threads (clear_proceed_status_callback
, NULL
);
2039 if (!ptid_equal (inferior_ptid
, null_ptid
))
2041 struct inferior
*inferior
;
2045 /* If in non-stop mode, only delete the per-thread status of
2046 the current thread. */
2047 clear_proceed_status_thread (inferior_thread ());
2050 inferior
= current_inferior ();
2051 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2054 stop_after_trap
= 0;
2056 observer_notify_about_to_proceed ();
2060 regcache_xfree (stop_registers
);
2061 stop_registers
= NULL
;
2065 /* Check the current thread against the thread that reported the most recent
2066 event. If a step-over is required return TRUE and set the current thread
2067 to the old thread. Otherwise return FALSE.
2069 This should be suitable for any targets that support threads. */
2072 prepare_to_proceed (int step
)
2075 struct target_waitstatus wait_status
;
2076 int schedlock_enabled
;
2078 /* With non-stop mode on, threads are always handled individually. */
2079 gdb_assert (! non_stop
);
2081 /* Get the last target status returned by target_wait(). */
2082 get_last_target_status (&wait_ptid
, &wait_status
);
2084 /* Make sure we were stopped at a breakpoint. */
2085 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
2086 || (wait_status
.value
.sig
!= GDB_SIGNAL_TRAP
2087 && wait_status
.value
.sig
!= GDB_SIGNAL_ILL
2088 && wait_status
.value
.sig
!= GDB_SIGNAL_SEGV
2089 && wait_status
.value
.sig
!= GDB_SIGNAL_EMT
))
2094 schedlock_enabled
= (scheduler_mode
== schedlock_on
2095 || (scheduler_mode
== schedlock_step
2098 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
2099 if (schedlock_enabled
)
2102 /* Don't switch over if we're about to resume some other process
2103 other than WAIT_PTID's, and schedule-multiple is off. */
2105 && ptid_get_pid (wait_ptid
) != ptid_get_pid (inferior_ptid
))
2108 /* Switched over from WAIT_PID. */
2109 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
2110 && !ptid_equal (inferior_ptid
, wait_ptid
))
2112 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
2114 if (breakpoint_here_p (get_regcache_aspace (regcache
),
2115 regcache_read_pc (regcache
)))
2117 /* If stepping, remember current thread to switch back to. */
2119 deferred_step_ptid
= inferior_ptid
;
2121 /* Switch back to WAIT_PID thread. */
2122 switch_to_thread (wait_ptid
);
2125 fprintf_unfiltered (gdb_stdlog
,
2126 "infrun: prepare_to_proceed (step=%d), "
2127 "switched to [%s]\n",
2128 step
, target_pid_to_str (inferior_ptid
));
2130 /* We return 1 to indicate that there is a breakpoint here,
2131 so we need to step over it before continuing to avoid
2132 hitting it straight away. */
2140 /* Basic routine for continuing the program in various fashions.
2142 ADDR is the address to resume at, or -1 for resume where stopped.
2143 SIGGNAL is the signal to give it, or 0 for none,
2144 or -1 for act according to how it stopped.
2145 STEP is nonzero if should trap after one instruction.
2146 -1 means return after that and print nothing.
2147 You should probably set various step_... variables
2148 before calling here, if you are stepping.
2150 You should call clear_proceed_status before calling proceed. */
2153 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
, int step
)
2155 struct regcache
*regcache
;
2156 struct gdbarch
*gdbarch
;
2157 struct thread_info
*tp
;
2159 struct address_space
*aspace
;
2160 /* GDB may force the inferior to step due to various reasons. */
2163 /* If we're stopped at a fork/vfork, follow the branch set by the
2164 "set follow-fork-mode" command; otherwise, we'll just proceed
2165 resuming the current thread. */
2166 if (!follow_fork ())
2168 /* The target for some reason decided not to resume. */
2170 if (target_can_async_p ())
2171 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2175 /* We'll update this if & when we switch to a new thread. */
2176 previous_inferior_ptid
= inferior_ptid
;
2178 regcache
= get_current_regcache ();
2179 gdbarch
= get_regcache_arch (regcache
);
2180 aspace
= get_regcache_aspace (regcache
);
2181 pc
= regcache_read_pc (regcache
);
2184 step_start_function
= find_pc_function (pc
);
2186 stop_after_trap
= 1;
2188 if (addr
== (CORE_ADDR
) -1)
2190 if (pc
== stop_pc
&& breakpoint_here_p (aspace
, pc
)
2191 && execution_direction
!= EXEC_REVERSE
)
2192 /* There is a breakpoint at the address we will resume at,
2193 step one instruction before inserting breakpoints so that
2194 we do not stop right away (and report a second hit at this
2197 Note, we don't do this in reverse, because we won't
2198 actually be executing the breakpoint insn anyway.
2199 We'll be (un-)executing the previous instruction. */
2202 else if (gdbarch_single_step_through_delay_p (gdbarch
)
2203 && gdbarch_single_step_through_delay (gdbarch
,
2204 get_current_frame ()))
2205 /* We stepped onto an instruction that needs to be stepped
2206 again before re-inserting the breakpoint, do so. */
2211 regcache_write_pc (regcache
, addr
);
2215 fprintf_unfiltered (gdb_stdlog
,
2216 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
2217 paddress (gdbarch
, addr
), siggnal
, step
);
2220 /* In non-stop, each thread is handled individually. The context
2221 must already be set to the right thread here. */
2225 /* In a multi-threaded task we may select another thread and
2226 then continue or step.
2228 But if the old thread was stopped at a breakpoint, it will
2229 immediately cause another breakpoint stop without any
2230 execution (i.e. it will report a breakpoint hit incorrectly).
2231 So we must step over it first.
2233 prepare_to_proceed checks the current thread against the
2234 thread that reported the most recent event. If a step-over
2235 is required it returns TRUE and sets the current thread to
2237 if (prepare_to_proceed (step
))
2241 /* prepare_to_proceed may change the current thread. */
2242 tp
= inferior_thread ();
2246 tp
->control
.trap_expected
= 1;
2247 /* If displaced stepping is enabled, we can step over the
2248 breakpoint without hitting it, so leave all breakpoints
2249 inserted. Otherwise we need to disable all breakpoints, step
2250 one instruction, and then re-add them when that step is
2252 if (!use_displaced_stepping (gdbarch
))
2253 remove_breakpoints ();
2256 /* We can insert breakpoints if we're not trying to step over one,
2257 or if we are stepping over one but we're using displaced stepping
2259 if (! tp
->control
.trap_expected
|| use_displaced_stepping (gdbarch
))
2260 insert_breakpoints ();
2264 /* Pass the last stop signal to the thread we're resuming,
2265 irrespective of whether the current thread is the thread that
2266 got the last event or not. This was historically GDB's
2267 behaviour before keeping a stop_signal per thread. */
2269 struct thread_info
*last_thread
;
2271 struct target_waitstatus last_status
;
2273 get_last_target_status (&last_ptid
, &last_status
);
2274 if (!ptid_equal (inferior_ptid
, last_ptid
)
2275 && !ptid_equal (last_ptid
, null_ptid
)
2276 && !ptid_equal (last_ptid
, minus_one_ptid
))
2278 last_thread
= find_thread_ptid (last_ptid
);
2281 tp
->suspend
.stop_signal
= last_thread
->suspend
.stop_signal
;
2282 last_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2287 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
2288 tp
->suspend
.stop_signal
= siggnal
;
2289 /* If this signal should not be seen by program,
2290 give it zero. Used for debugging signals. */
2291 else if (!signal_program
[tp
->suspend
.stop_signal
])
2292 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2294 annotate_starting ();
2296 /* Make sure that output from GDB appears before output from the
2298 gdb_flush (gdb_stdout
);
2300 /* Refresh prev_pc value just prior to resuming. This used to be
2301 done in stop_stepping, however, setting prev_pc there did not handle
2302 scenarios such as inferior function calls or returning from
2303 a function via the return command. In those cases, the prev_pc
2304 value was not set properly for subsequent commands. The prev_pc value
2305 is used to initialize the starting line number in the ecs. With an
2306 invalid value, the gdb next command ends up stopping at the position
2307 represented by the next line table entry past our start position.
2308 On platforms that generate one line table entry per line, this
2309 is not a problem. However, on the ia64, the compiler generates
2310 extraneous line table entries that do not increase the line number.
2311 When we issue the gdb next command on the ia64 after an inferior call
2312 or a return command, we often end up a few instructions forward, still
2313 within the original line we started.
2315 An attempt was made to refresh the prev_pc at the same time the
2316 execution_control_state is initialized (for instance, just before
2317 waiting for an inferior event). But this approach did not work
2318 because of platforms that use ptrace, where the pc register cannot
2319 be read unless the inferior is stopped. At that point, we are not
2320 guaranteed the inferior is stopped and so the regcache_read_pc() call
2321 can fail. Setting the prev_pc value here ensures the value is updated
2322 correctly when the inferior is stopped. */
2323 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2325 /* Fill in with reasonable starting values. */
2326 init_thread_stepping_state (tp
);
2328 /* Reset to normal state. */
2329 init_infwait_state ();
2331 /* Resume inferior. */
2332 resume (force_step
|| step
|| bpstat_should_step (),
2333 tp
->suspend
.stop_signal
);
2335 /* Wait for it to stop (if not standalone)
2336 and in any case decode why it stopped, and act accordingly. */
2337 /* Do this only if we are not using the event loop, or if the target
2338 does not support asynchronous execution. */
2339 if (!target_can_async_p ())
2341 wait_for_inferior ();
2347 /* Start remote-debugging of a machine over a serial link. */
2350 start_remote (int from_tty
)
2352 struct inferior
*inferior
;
2354 inferior
= current_inferior ();
2355 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2357 /* Always go on waiting for the target, regardless of the mode. */
2358 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2359 indicate to wait_for_inferior that a target should timeout if
2360 nothing is returned (instead of just blocking). Because of this,
2361 targets expecting an immediate response need to, internally, set
2362 things up so that the target_wait() is forced to eventually
2364 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2365 differentiate to its caller what the state of the target is after
2366 the initial open has been performed. Here we're assuming that
2367 the target has stopped. It should be possible to eventually have
2368 target_open() return to the caller an indication that the target
2369 is currently running and GDB state should be set to the same as
2370 for an async run. */
2371 wait_for_inferior ();
2373 /* Now that the inferior has stopped, do any bookkeeping like
2374 loading shared libraries. We want to do this before normal_stop,
2375 so that the displayed frame is up to date. */
2376 post_create_inferior (¤t_target
, from_tty
);
2381 /* Initialize static vars when a new inferior begins. */
2384 init_wait_for_inferior (void)
2386 /* These are meaningless until the first time through wait_for_inferior. */
2388 breakpoint_init_inferior (inf_starting
);
2390 clear_proceed_status ();
2392 stepping_past_singlestep_breakpoint
= 0;
2393 deferred_step_ptid
= null_ptid
;
2395 target_last_wait_ptid
= minus_one_ptid
;
2397 previous_inferior_ptid
= inferior_ptid
;
2398 init_infwait_state ();
2400 /* Discard any skipped inlined frames. */
2401 clear_inline_frame_state (minus_one_ptid
);
2405 /* This enum encodes possible reasons for doing a target_wait, so that
2406 wfi can call target_wait in one place. (Ultimately the call will be
2407 moved out of the infinite loop entirely.) */
2411 infwait_normal_state
,
2412 infwait_thread_hop_state
,
2413 infwait_step_watch_state
,
2414 infwait_nonstep_watch_state
2417 /* The PTID we'll do a target_wait on.*/
2420 /* Current inferior wait state. */
2421 static enum infwait_states infwait_state
;
2423 /* Data to be passed around while handling an event. This data is
2424 discarded between events. */
2425 struct execution_control_state
2428 /* The thread that got the event, if this was a thread event; NULL
2430 struct thread_info
*event_thread
;
2432 struct target_waitstatus ws
;
2434 int stop_func_filled_in
;
2435 CORE_ADDR stop_func_start
;
2436 CORE_ADDR stop_func_end
;
2437 const char *stop_func_name
;
2441 static void handle_inferior_event (struct execution_control_state
*ecs
);
2443 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2444 struct execution_control_state
*ecs
);
2445 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2446 struct execution_control_state
*ecs
);
2447 static void check_exception_resume (struct execution_control_state
*,
2448 struct frame_info
*);
2450 static void stop_stepping (struct execution_control_state
*ecs
);
2451 static void prepare_to_wait (struct execution_control_state
*ecs
);
2452 static void keep_going (struct execution_control_state
*ecs
);
2454 /* Callback for iterate over threads. If the thread is stopped, but
2455 the user/frontend doesn't know about that yet, go through
2456 normal_stop, as if the thread had just stopped now. ARG points at
2457 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2458 ptid_is_pid(PTID) is true, applies to all threads of the process
2459 pointed at by PTID. Otherwise, apply only to the thread pointed by
2463 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2465 ptid_t ptid
= * (ptid_t
*) arg
;
2467 if ((ptid_equal (info
->ptid
, ptid
)
2468 || ptid_equal (minus_one_ptid
, ptid
)
2469 || (ptid_is_pid (ptid
)
2470 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2471 && is_running (info
->ptid
)
2472 && !is_executing (info
->ptid
))
2474 struct cleanup
*old_chain
;
2475 struct execution_control_state ecss
;
2476 struct execution_control_state
*ecs
= &ecss
;
2478 memset (ecs
, 0, sizeof (*ecs
));
2480 old_chain
= make_cleanup_restore_current_thread ();
2482 /* Go through handle_inferior_event/normal_stop, so we always
2483 have consistent output as if the stop event had been
2485 ecs
->ptid
= info
->ptid
;
2486 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2487 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2488 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
2490 handle_inferior_event (ecs
);
2492 if (!ecs
->wait_some_more
)
2494 struct thread_info
*tp
;
2498 /* Finish off the continuations. */
2499 tp
= inferior_thread ();
2500 do_all_intermediate_continuations_thread (tp
, 1);
2501 do_all_continuations_thread (tp
, 1);
2504 do_cleanups (old_chain
);
2510 /* This function is attached as a "thread_stop_requested" observer.
2511 Cleanup local state that assumed the PTID was to be resumed, and
2512 report the stop to the frontend. */
2515 infrun_thread_stop_requested (ptid_t ptid
)
2517 struct displaced_step_inferior_state
*displaced
;
2519 /* PTID was requested to stop. Remove it from the displaced
2520 stepping queue, so we don't try to resume it automatically. */
2522 for (displaced
= displaced_step_inferior_states
;
2524 displaced
= displaced
->next
)
2526 struct displaced_step_request
*it
, **prev_next_p
;
2528 it
= displaced
->step_request_queue
;
2529 prev_next_p
= &displaced
->step_request_queue
;
2532 if (ptid_match (it
->ptid
, ptid
))
2534 *prev_next_p
= it
->next
;
2540 prev_next_p
= &it
->next
;
2547 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2551 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2553 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2554 nullify_last_target_wait_ptid ();
2557 /* Callback for iterate_over_threads. */
2560 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
2562 if (is_exited (info
->ptid
))
2565 delete_step_resume_breakpoint (info
);
2566 delete_exception_resume_breakpoint (info
);
2570 /* In all-stop, delete the step resume breakpoint of any thread that
2571 had one. In non-stop, delete the step resume breakpoint of the
2572 thread that just stopped. */
2575 delete_step_thread_step_resume_breakpoint (void)
2577 if (!target_has_execution
2578 || ptid_equal (inferior_ptid
, null_ptid
))
2579 /* If the inferior has exited, we have already deleted the step
2580 resume breakpoints out of GDB's lists. */
2585 /* If in non-stop mode, only delete the step-resume or
2586 longjmp-resume breakpoint of the thread that just stopped
2588 struct thread_info
*tp
= inferior_thread ();
2590 delete_step_resume_breakpoint (tp
);
2591 delete_exception_resume_breakpoint (tp
);
2594 /* In all-stop mode, delete all step-resume and longjmp-resume
2595 breakpoints of any thread that had them. */
2596 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
2599 /* A cleanup wrapper. */
2602 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
2604 delete_step_thread_step_resume_breakpoint ();
2607 /* Pretty print the results of target_wait, for debugging purposes. */
2610 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
2611 const struct target_waitstatus
*ws
)
2613 char *status_string
= target_waitstatus_to_string (ws
);
2614 struct ui_file
*tmp_stream
= mem_fileopen ();
2617 /* The text is split over several lines because it was getting too long.
2618 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2619 output as a unit; we want only one timestamp printed if debug_timestamp
2622 fprintf_unfiltered (tmp_stream
,
2623 "infrun: target_wait (%d", PIDGET (waiton_ptid
));
2624 if (PIDGET (waiton_ptid
) != -1)
2625 fprintf_unfiltered (tmp_stream
,
2626 " [%s]", target_pid_to_str (waiton_ptid
));
2627 fprintf_unfiltered (tmp_stream
, ", status) =\n");
2628 fprintf_unfiltered (tmp_stream
,
2629 "infrun: %d [%s],\n",
2630 PIDGET (result_ptid
), target_pid_to_str (result_ptid
));
2631 fprintf_unfiltered (tmp_stream
,
2635 text
= ui_file_xstrdup (tmp_stream
, NULL
);
2637 /* This uses %s in part to handle %'s in the text, but also to avoid
2638 a gcc error: the format attribute requires a string literal. */
2639 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
2641 xfree (status_string
);
2643 ui_file_delete (tmp_stream
);
2646 /* Prepare and stabilize the inferior for detaching it. E.g.,
2647 detaching while a thread is displaced stepping is a recipe for
2648 crashing it, as nothing would readjust the PC out of the scratch
2652 prepare_for_detach (void)
2654 struct inferior
*inf
= current_inferior ();
2655 ptid_t pid_ptid
= pid_to_ptid (inf
->pid
);
2656 struct cleanup
*old_chain_1
;
2657 struct displaced_step_inferior_state
*displaced
;
2659 displaced
= get_displaced_stepping_state (inf
->pid
);
2661 /* Is any thread of this process displaced stepping? If not,
2662 there's nothing else to do. */
2663 if (displaced
== NULL
|| ptid_equal (displaced
->step_ptid
, null_ptid
))
2667 fprintf_unfiltered (gdb_stdlog
,
2668 "displaced-stepping in-process while detaching");
2670 old_chain_1
= make_cleanup_restore_integer (&inf
->detaching
);
2673 while (!ptid_equal (displaced
->step_ptid
, null_ptid
))
2675 struct cleanup
*old_chain_2
;
2676 struct execution_control_state ecss
;
2677 struct execution_control_state
*ecs
;
2680 memset (ecs
, 0, sizeof (*ecs
));
2682 overlay_cache_invalid
= 1;
2684 if (deprecated_target_wait_hook
)
2685 ecs
->ptid
= deprecated_target_wait_hook (pid_ptid
, &ecs
->ws
, 0);
2687 ecs
->ptid
= target_wait (pid_ptid
, &ecs
->ws
, 0);
2690 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
2692 /* If an error happens while handling the event, propagate GDB's
2693 knowledge of the executing state to the frontend/user running
2695 old_chain_2
= make_cleanup (finish_thread_state_cleanup
,
2698 /* Now figure out what to do with the result of the result. */
2699 handle_inferior_event (ecs
);
2701 /* No error, don't finish the state yet. */
2702 discard_cleanups (old_chain_2
);
2704 /* Breakpoints and watchpoints are not installed on the target
2705 at this point, and signals are passed directly to the
2706 inferior, so this must mean the process is gone. */
2707 if (!ecs
->wait_some_more
)
2709 discard_cleanups (old_chain_1
);
2710 error (_("Program exited while detaching"));
2714 discard_cleanups (old_chain_1
);
2717 /* Wait for control to return from inferior to debugger.
2719 If inferior gets a signal, we may decide to start it up again
2720 instead of returning. That is why there is a loop in this function.
2721 When this function actually returns it means the inferior
2722 should be left stopped and GDB should read more commands. */
2725 wait_for_inferior (void)
2727 struct cleanup
*old_cleanups
;
2731 (gdb_stdlog
, "infrun: wait_for_inferior ()\n");
2734 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
2738 struct execution_control_state ecss
;
2739 struct execution_control_state
*ecs
= &ecss
;
2740 struct cleanup
*old_chain
;
2742 memset (ecs
, 0, sizeof (*ecs
));
2744 overlay_cache_invalid
= 1;
2746 if (deprecated_target_wait_hook
)
2747 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
2749 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
2752 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2754 /* If an error happens while handling the event, propagate GDB's
2755 knowledge of the executing state to the frontend/user running
2757 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2759 /* Now figure out what to do with the result of the result. */
2760 handle_inferior_event (ecs
);
2762 /* No error, don't finish the state yet. */
2763 discard_cleanups (old_chain
);
2765 if (!ecs
->wait_some_more
)
2769 do_cleanups (old_cleanups
);
2772 /* Asynchronous version of wait_for_inferior. It is called by the
2773 event loop whenever a change of state is detected on the file
2774 descriptor corresponding to the target. It can be called more than
2775 once to complete a single execution command. In such cases we need
2776 to keep the state in a global variable ECSS. If it is the last time
2777 that this function is called for a single execution command, then
2778 report to the user that the inferior has stopped, and do the
2779 necessary cleanups. */
2782 fetch_inferior_event (void *client_data
)
2784 struct execution_control_state ecss
;
2785 struct execution_control_state
*ecs
= &ecss
;
2786 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
2787 struct cleanup
*ts_old_chain
;
2788 int was_sync
= sync_execution
;
2791 memset (ecs
, 0, sizeof (*ecs
));
2793 /* We're handling a live event, so make sure we're doing live
2794 debugging. If we're looking at traceframes while the target is
2795 running, we're going to need to get back to that mode after
2796 handling the event. */
2799 make_cleanup_restore_current_traceframe ();
2800 set_current_traceframe (-1);
2804 /* In non-stop mode, the user/frontend should not notice a thread
2805 switch due to internal events. Make sure we reverse to the
2806 user selected thread and frame after handling the event and
2807 running any breakpoint commands. */
2808 make_cleanup_restore_current_thread ();
2810 overlay_cache_invalid
= 1;
2812 make_cleanup_restore_integer (&execution_direction
);
2813 execution_direction
= target_execution_direction ();
2815 if (deprecated_target_wait_hook
)
2817 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2819 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2822 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2824 /* If an error happens while handling the event, propagate GDB's
2825 knowledge of the executing state to the frontend/user running
2828 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2830 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
2832 /* Get executed before make_cleanup_restore_current_thread above to apply
2833 still for the thread which has thrown the exception. */
2834 make_bpstat_clear_actions_cleanup ();
2836 /* Now figure out what to do with the result of the result. */
2837 handle_inferior_event (ecs
);
2839 if (!ecs
->wait_some_more
)
2841 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2843 delete_step_thread_step_resume_breakpoint ();
2845 /* We may not find an inferior if this was a process exit. */
2846 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
2849 if (target_has_execution
2850 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
2851 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2852 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2853 && ecs
->event_thread
->step_multi
2854 && ecs
->event_thread
->control
.stop_step
)
2855 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
2858 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2863 /* No error, don't finish the thread states yet. */
2864 discard_cleanups (ts_old_chain
);
2866 /* Revert thread and frame. */
2867 do_cleanups (old_chain
);
2869 /* If the inferior was in sync execution mode, and now isn't,
2870 restore the prompt (a synchronous execution command has finished,
2871 and we're ready for input). */
2872 if (interpreter_async
&& was_sync
&& !sync_execution
)
2873 display_gdb_prompt (0);
2877 && exec_done_display_p
2878 && (ptid_equal (inferior_ptid
, null_ptid
)
2879 || !is_running (inferior_ptid
)))
2880 printf_unfiltered (_("completed.\n"));
2883 /* Record the frame and location we're currently stepping through. */
2885 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
2887 struct thread_info
*tp
= inferior_thread ();
2889 tp
->control
.step_frame_id
= get_frame_id (frame
);
2890 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
2892 tp
->current_symtab
= sal
.symtab
;
2893 tp
->current_line
= sal
.line
;
2896 /* Clear context switchable stepping state. */
2899 init_thread_stepping_state (struct thread_info
*tss
)
2901 tss
->stepping_over_breakpoint
= 0;
2902 tss
->step_after_step_resume_breakpoint
= 0;
2905 /* Return the cached copy of the last pid/waitstatus returned by
2906 target_wait()/deprecated_target_wait_hook(). The data is actually
2907 cached by handle_inferior_event(), which gets called immediately
2908 after target_wait()/deprecated_target_wait_hook(). */
2911 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
2913 *ptidp
= target_last_wait_ptid
;
2914 *status
= target_last_waitstatus
;
2918 nullify_last_target_wait_ptid (void)
2920 target_last_wait_ptid
= minus_one_ptid
;
2923 /* Switch thread contexts. */
2926 context_switch (ptid_t ptid
)
2928 if (debug_infrun
&& !ptid_equal (ptid
, inferior_ptid
))
2930 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
2931 target_pid_to_str (inferior_ptid
));
2932 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
2933 target_pid_to_str (ptid
));
2936 switch_to_thread (ptid
);
2940 adjust_pc_after_break (struct execution_control_state
*ecs
)
2942 struct regcache
*regcache
;
2943 struct gdbarch
*gdbarch
;
2944 struct address_space
*aspace
;
2945 CORE_ADDR breakpoint_pc
;
2947 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2948 we aren't, just return.
2950 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2951 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2952 implemented by software breakpoints should be handled through the normal
2955 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2956 different signals (SIGILL or SIGEMT for instance), but it is less
2957 clear where the PC is pointing afterwards. It may not match
2958 gdbarch_decr_pc_after_break. I don't know any specific target that
2959 generates these signals at breakpoints (the code has been in GDB since at
2960 least 1992) so I can not guess how to handle them here.
2962 In earlier versions of GDB, a target with
2963 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2964 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2965 target with both of these set in GDB history, and it seems unlikely to be
2966 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2968 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
2971 if (ecs
->ws
.value
.sig
!= GDB_SIGNAL_TRAP
)
2974 /* In reverse execution, when a breakpoint is hit, the instruction
2975 under it has already been de-executed. The reported PC always
2976 points at the breakpoint address, so adjusting it further would
2977 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2980 B1 0x08000000 : INSN1
2981 B2 0x08000001 : INSN2
2983 PC -> 0x08000003 : INSN4
2985 Say you're stopped at 0x08000003 as above. Reverse continuing
2986 from that point should hit B2 as below. Reading the PC when the
2987 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2988 been de-executed already.
2990 B1 0x08000000 : INSN1
2991 B2 PC -> 0x08000001 : INSN2
2995 We can't apply the same logic as for forward execution, because
2996 we would wrongly adjust the PC to 0x08000000, since there's a
2997 breakpoint at PC - 1. We'd then report a hit on B1, although
2998 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3000 if (execution_direction
== EXEC_REVERSE
)
3003 /* If this target does not decrement the PC after breakpoints, then
3004 we have nothing to do. */
3005 regcache
= get_thread_regcache (ecs
->ptid
);
3006 gdbarch
= get_regcache_arch (regcache
);
3007 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
3010 aspace
= get_regcache_aspace (regcache
);
3012 /* Find the location where (if we've hit a breakpoint) the
3013 breakpoint would be. */
3014 breakpoint_pc
= regcache_read_pc (regcache
)
3015 - gdbarch_decr_pc_after_break (gdbarch
);
3017 /* Check whether there actually is a software breakpoint inserted at
3020 If in non-stop mode, a race condition is possible where we've
3021 removed a breakpoint, but stop events for that breakpoint were
3022 already queued and arrive later. To suppress those spurious
3023 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3024 and retire them after a number of stop events are reported. */
3025 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
3026 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
3028 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, NULL
);
3031 record_full_gdb_operation_disable_set ();
3033 /* When using hardware single-step, a SIGTRAP is reported for both
3034 a completed single-step and a software breakpoint. Need to
3035 differentiate between the two, as the latter needs adjusting
3036 but the former does not.
3038 The SIGTRAP can be due to a completed hardware single-step only if
3039 - we didn't insert software single-step breakpoints
3040 - the thread to be examined is still the current thread
3041 - this thread is currently being stepped
3043 If any of these events did not occur, we must have stopped due
3044 to hitting a software breakpoint, and have to back up to the
3047 As a special case, we could have hardware single-stepped a
3048 software breakpoint. In this case (prev_pc == breakpoint_pc),
3049 we also need to back up to the breakpoint address. */
3051 if (singlestep_breakpoints_inserted_p
3052 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
3053 || !currently_stepping (ecs
->event_thread
)
3054 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
3055 regcache_write_pc (regcache
, breakpoint_pc
);
3057 do_cleanups (old_cleanups
);
3062 init_infwait_state (void)
3064 waiton_ptid
= pid_to_ptid (-1);
3065 infwait_state
= infwait_normal_state
;
3069 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
3071 for (frame
= get_prev_frame (frame
);
3073 frame
= get_prev_frame (frame
))
3075 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
3077 if (get_frame_type (frame
) != INLINE_FRAME
)
3084 /* Auxiliary function that handles syscall entry/return events.
3085 It returns 1 if the inferior should keep going (and GDB
3086 should ignore the event), or 0 if the event deserves to be
3090 handle_syscall_event (struct execution_control_state
*ecs
)
3092 struct regcache
*regcache
;
3095 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3096 context_switch (ecs
->ptid
);
3098 regcache
= get_thread_regcache (ecs
->ptid
);
3099 syscall_number
= ecs
->ws
.value
.syscall_number
;
3100 stop_pc
= regcache_read_pc (regcache
);
3102 if (catch_syscall_enabled () > 0
3103 && catching_syscall_number (syscall_number
) > 0)
3105 enum bpstat_signal_value sval
;
3108 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
3111 ecs
->event_thread
->control
.stop_bpstat
3112 = bpstat_stop_status (get_regcache_aspace (regcache
),
3113 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3115 sval
= bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
3117 ecs
->random_signal
= sval
== BPSTAT_SIGNAL_NO
;
3119 if (!ecs
->random_signal
)
3121 /* Catchpoint hit. */
3122 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3127 /* If no catchpoint triggered for this, then keep going. */
3128 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3133 /* Clear the supplied execution_control_state's stop_func_* fields. */
3136 clear_stop_func (struct execution_control_state
*ecs
)
3138 ecs
->stop_func_filled_in
= 0;
3139 ecs
->stop_func_start
= 0;
3140 ecs
->stop_func_end
= 0;
3141 ecs
->stop_func_name
= NULL
;
3144 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3147 fill_in_stop_func (struct gdbarch
*gdbarch
,
3148 struct execution_control_state
*ecs
)
3150 if (!ecs
->stop_func_filled_in
)
3152 /* Don't care about return value; stop_func_start and stop_func_name
3153 will both be 0 if it doesn't work. */
3154 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3155 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3156 ecs
->stop_func_start
3157 += gdbarch_deprecated_function_start_offset (gdbarch
);
3159 ecs
->stop_func_filled_in
= 1;
3163 /* Given an execution control state that has been freshly filled in
3164 by an event from the inferior, figure out what it means and take
3165 appropriate action. */
3168 handle_inferior_event (struct execution_control_state
*ecs
)
3170 struct frame_info
*frame
;
3171 struct gdbarch
*gdbarch
;
3172 int stopped_by_watchpoint
;
3173 int stepped_after_stopped_by_watchpoint
= 0;
3174 struct symtab_and_line stop_pc_sal
;
3175 enum stop_kind stop_soon
;
3177 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
3179 /* We had an event in the inferior, but we are not interested in
3180 handling it at this level. The lower layers have already
3181 done what needs to be done, if anything.
3183 One of the possible circumstances for this is when the
3184 inferior produces output for the console. The inferior has
3185 not stopped, and we are ignoring the event. Another possible
3186 circumstance is any event which the lower level knows will be
3187 reported multiple times without an intervening resume. */
3189 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
3190 prepare_to_wait (ecs
);
3194 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
3195 && target_can_async_p () && !sync_execution
)
3197 /* There were no unwaited-for children left in the target, but,
3198 we're not synchronously waiting for events either. Just
3199 ignore. Otherwise, if we were running a synchronous
3200 execution command, we need to cancel it and give the user
3201 back the terminal. */
3203 fprintf_unfiltered (gdb_stdlog
,
3204 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3205 prepare_to_wait (ecs
);
3209 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3210 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3211 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
3213 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3216 stop_soon
= inf
->control
.stop_soon
;
3219 stop_soon
= NO_STOP_QUIETLY
;
3221 /* Cache the last pid/waitstatus. */
3222 target_last_wait_ptid
= ecs
->ptid
;
3223 target_last_waitstatus
= ecs
->ws
;
3225 /* Always clear state belonging to the previous time we stopped. */
3226 stop_stack_dummy
= STOP_NONE
;
3228 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3230 /* No unwaited-for children left. IOW, all resumed children
3233 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3235 stop_print_frame
= 0;
3236 stop_stepping (ecs
);
3240 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3241 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
3243 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3244 /* If it's a new thread, add it to the thread database. */
3245 if (ecs
->event_thread
== NULL
)
3246 ecs
->event_thread
= add_thread (ecs
->ptid
);
3248 /* Disable range stepping. If the next step request could use a
3249 range, this will be end up re-enabled then. */
3250 ecs
->event_thread
->control
.may_range_step
= 0;
3253 /* Dependent on valid ECS->EVENT_THREAD. */
3254 adjust_pc_after_break (ecs
);
3256 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3257 reinit_frame_cache ();
3259 breakpoint_retire_moribund ();
3261 /* First, distinguish signals caused by the debugger from signals
3262 that have to do with the program's own actions. Note that
3263 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3264 on the operating system version. Here we detect when a SIGILL or
3265 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3266 something similar for SIGSEGV, since a SIGSEGV will be generated
3267 when we're trying to execute a breakpoint instruction on a
3268 non-executable stack. This happens for call dummy breakpoints
3269 for architectures like SPARC that place call dummies on the
3271 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
3272 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
3273 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
3274 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
3276 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3278 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
3279 regcache_read_pc (regcache
)))
3282 fprintf_unfiltered (gdb_stdlog
,
3283 "infrun: Treating signal as SIGTRAP\n");
3284 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
3288 /* Mark the non-executing threads accordingly. In all-stop, all
3289 threads of all processes are stopped when we get any event
3290 reported. In non-stop mode, only the event thread stops. If
3291 we're handling a process exit in non-stop mode, there's nothing
3292 to do, as threads of the dead process are gone, and threads of
3293 any other process were left running. */
3295 set_executing (minus_one_ptid
, 0);
3296 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3297 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
3298 set_executing (ecs
->ptid
, 0);
3300 switch (infwait_state
)
3302 case infwait_thread_hop_state
:
3304 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
3307 case infwait_normal_state
:
3309 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
3312 case infwait_step_watch_state
:
3314 fprintf_unfiltered (gdb_stdlog
,
3315 "infrun: infwait_step_watch_state\n");
3317 stepped_after_stopped_by_watchpoint
= 1;
3320 case infwait_nonstep_watch_state
:
3322 fprintf_unfiltered (gdb_stdlog
,
3323 "infrun: infwait_nonstep_watch_state\n");
3324 insert_breakpoints ();
3326 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3327 handle things like signals arriving and other things happening
3328 in combination correctly? */
3329 stepped_after_stopped_by_watchpoint
= 1;
3333 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3336 infwait_state
= infwait_normal_state
;
3337 waiton_ptid
= pid_to_ptid (-1);
3339 switch (ecs
->ws
.kind
)
3341 case TARGET_WAITKIND_LOADED
:
3343 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
3344 /* Ignore gracefully during startup of the inferior, as it might
3345 be the shell which has just loaded some objects, otherwise
3346 add the symbols for the newly loaded objects. Also ignore at
3347 the beginning of an attach or remote session; we will query
3348 the full list of libraries once the connection is
3350 if (stop_soon
== NO_STOP_QUIETLY
)
3352 struct regcache
*regcache
;
3353 enum bpstat_signal_value sval
;
3355 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3356 context_switch (ecs
->ptid
);
3357 regcache
= get_thread_regcache (ecs
->ptid
);
3359 handle_solib_event ();
3361 ecs
->event_thread
->control
.stop_bpstat
3362 = bpstat_stop_status (get_regcache_aspace (regcache
),
3363 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3366 = bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
3368 ecs
->random_signal
= sval
== BPSTAT_SIGNAL_NO
;
3370 if (!ecs
->random_signal
)
3372 /* A catchpoint triggered. */
3373 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3374 goto process_event_stop_test
;
3377 /* If requested, stop when the dynamic linker notifies
3378 gdb of events. This allows the user to get control
3379 and place breakpoints in initializer routines for
3380 dynamically loaded objects (among other things). */
3381 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3382 if (stop_on_solib_events
)
3384 /* Make sure we print "Stopped due to solib-event" in
3386 stop_print_frame
= 1;
3388 stop_stepping (ecs
);
3393 /* If we are skipping through a shell, or through shared library
3394 loading that we aren't interested in, resume the program. If
3395 we're running the program normally, also resume. But stop if
3396 we're attaching or setting up a remote connection. */
3397 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
3399 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3400 context_switch (ecs
->ptid
);
3402 /* Loading of shared libraries might have changed breakpoint
3403 addresses. Make sure new breakpoints are inserted. */
3404 if (stop_soon
== NO_STOP_QUIETLY
3405 && !breakpoints_always_inserted_mode ())
3406 insert_breakpoints ();
3407 resume (0, GDB_SIGNAL_0
);
3408 prepare_to_wait (ecs
);
3414 case TARGET_WAITKIND_SPURIOUS
:
3416 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3417 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3418 context_switch (ecs
->ptid
);
3419 resume (0, GDB_SIGNAL_0
);
3420 prepare_to_wait (ecs
);
3423 case TARGET_WAITKIND_EXITED
:
3424 case TARGET_WAITKIND_SIGNALLED
:
3427 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3428 fprintf_unfiltered (gdb_stdlog
,
3429 "infrun: TARGET_WAITKIND_EXITED\n");
3431 fprintf_unfiltered (gdb_stdlog
,
3432 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3435 inferior_ptid
= ecs
->ptid
;
3436 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
3437 set_current_program_space (current_inferior ()->pspace
);
3438 handle_vfork_child_exec_or_exit (0);
3439 target_terminal_ours (); /* Must do this before mourn anyway. */
3441 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3443 /* Record the exit code in the convenience variable $_exitcode, so
3444 that the user can inspect this again later. */
3445 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3446 (LONGEST
) ecs
->ws
.value
.integer
);
3448 /* Also record this in the inferior itself. */
3449 current_inferior ()->has_exit_code
= 1;
3450 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
3452 print_exited_reason (ecs
->ws
.value
.integer
);
3455 print_signal_exited_reason (ecs
->ws
.value
.sig
);
3457 gdb_flush (gdb_stdout
);
3458 target_mourn_inferior ();
3459 singlestep_breakpoints_inserted_p
= 0;
3460 cancel_single_step_breakpoints ();
3461 stop_print_frame
= 0;
3462 stop_stepping (ecs
);
3465 /* The following are the only cases in which we keep going;
3466 the above cases end in a continue or goto. */
3467 case TARGET_WAITKIND_FORKED
:
3468 case TARGET_WAITKIND_VFORKED
:
3471 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3472 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
3474 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORKED\n");
3477 /* Check whether the inferior is displaced stepping. */
3479 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3480 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3481 struct displaced_step_inferior_state
*displaced
3482 = get_displaced_stepping_state (ptid_get_pid (ecs
->ptid
));
3484 /* If checking displaced stepping is supported, and thread
3485 ecs->ptid is displaced stepping. */
3486 if (displaced
&& ptid_equal (displaced
->step_ptid
, ecs
->ptid
))
3488 struct inferior
*parent_inf
3489 = find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3490 struct regcache
*child_regcache
;
3491 CORE_ADDR parent_pc
;
3493 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3494 indicating that the displaced stepping of syscall instruction
3495 has been done. Perform cleanup for parent process here. Note
3496 that this operation also cleans up the child process for vfork,
3497 because their pages are shared. */
3498 displaced_step_fixup (ecs
->ptid
, GDB_SIGNAL_TRAP
);
3500 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3502 /* Restore scratch pad for child process. */
3503 displaced_step_restore (displaced
, ecs
->ws
.value
.related_pid
);
3506 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3507 the child's PC is also within the scratchpad. Set the child's PC
3508 to the parent's PC value, which has already been fixed up.
3509 FIXME: we use the parent's aspace here, although we're touching
3510 the child, because the child hasn't been added to the inferior
3511 list yet at this point. */
3514 = get_thread_arch_aspace_regcache (ecs
->ws
.value
.related_pid
,
3516 parent_inf
->aspace
);
3517 /* Read PC value of parent process. */
3518 parent_pc
= regcache_read_pc (regcache
);
3520 if (debug_displaced
)
3521 fprintf_unfiltered (gdb_stdlog
,
3522 "displaced: write child pc from %s to %s\n",
3524 regcache_read_pc (child_regcache
)),
3525 paddress (gdbarch
, parent_pc
));
3527 regcache_write_pc (child_regcache
, parent_pc
);
3531 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3532 context_switch (ecs
->ptid
);
3534 /* Immediately detach breakpoints from the child before there's
3535 any chance of letting the user delete breakpoints from the
3536 breakpoint lists. If we don't do this early, it's easy to
3537 leave left over traps in the child, vis: "break foo; catch
3538 fork; c; <fork>; del; c; <child calls foo>". We only follow
3539 the fork on the last `continue', and by that time the
3540 breakpoint at "foo" is long gone from the breakpoint table.
3541 If we vforked, then we don't need to unpatch here, since both
3542 parent and child are sharing the same memory pages; we'll
3543 need to unpatch at follow/detach time instead to be certain
3544 that new breakpoints added between catchpoint hit time and
3545 vfork follow are detached. */
3546 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
3548 /* This won't actually modify the breakpoint list, but will
3549 physically remove the breakpoints from the child. */
3550 detach_breakpoints (ecs
->ws
.value
.related_pid
);
3553 if (singlestep_breakpoints_inserted_p
)
3555 /* Pull the single step breakpoints out of the target. */
3556 remove_single_step_breakpoints ();
3557 singlestep_breakpoints_inserted_p
= 0;
3560 /* In case the event is caught by a catchpoint, remember that
3561 the event is to be followed at the next resume of the thread,
3562 and not immediately. */
3563 ecs
->event_thread
->pending_follow
= ecs
->ws
;
3565 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3567 ecs
->event_thread
->control
.stop_bpstat
3568 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3569 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3571 /* Note that we're interested in knowing the bpstat actually
3572 causes a stop, not just if it may explain the signal.
3573 Software watchpoints, for example, always appear in the
3576 = !bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
);
3578 /* If no catchpoint triggered for this, then keep going. */
3579 if (ecs
->random_signal
)
3585 = (follow_fork_mode_string
== follow_fork_mode_child
);
3587 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3589 should_resume
= follow_fork ();
3592 child
= ecs
->ws
.value
.related_pid
;
3594 /* In non-stop mode, also resume the other branch. */
3595 if (non_stop
&& !detach_fork
)
3598 switch_to_thread (parent
);
3600 switch_to_thread (child
);
3602 ecs
->event_thread
= inferior_thread ();
3603 ecs
->ptid
= inferior_ptid
;
3608 switch_to_thread (child
);
3610 switch_to_thread (parent
);
3612 ecs
->event_thread
= inferior_thread ();
3613 ecs
->ptid
= inferior_ptid
;
3618 stop_stepping (ecs
);
3621 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3622 goto process_event_stop_test
;
3624 case TARGET_WAITKIND_VFORK_DONE
:
3625 /* Done with the shared memory region. Re-insert breakpoints in
3626 the parent, and keep going. */
3629 fprintf_unfiltered (gdb_stdlog
,
3630 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3632 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3633 context_switch (ecs
->ptid
);
3635 current_inferior ()->waiting_for_vfork_done
= 0;
3636 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
3637 /* This also takes care of reinserting breakpoints in the
3638 previously locked inferior. */
3642 case TARGET_WAITKIND_EXECD
:
3644 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
3646 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3647 context_switch (ecs
->ptid
);
3649 singlestep_breakpoints_inserted_p
= 0;
3650 cancel_single_step_breakpoints ();
3652 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3654 /* Do whatever is necessary to the parent branch of the vfork. */
3655 handle_vfork_child_exec_or_exit (1);
3657 /* This causes the eventpoints and symbol table to be reset.
3658 Must do this now, before trying to determine whether to
3660 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
3662 ecs
->event_thread
->control
.stop_bpstat
3663 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3664 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3666 = (bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
3668 == BPSTAT_SIGNAL_NO
);
3670 /* Note that this may be referenced from inside
3671 bpstat_stop_status above, through inferior_has_execd. */
3672 xfree (ecs
->ws
.value
.execd_pathname
);
3673 ecs
->ws
.value
.execd_pathname
= NULL
;
3675 /* If no catchpoint triggered for this, then keep going. */
3676 if (ecs
->random_signal
)
3678 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3682 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3683 goto process_event_stop_test
;
3685 /* Be careful not to try to gather much state about a thread
3686 that's in a syscall. It's frequently a losing proposition. */
3687 case TARGET_WAITKIND_SYSCALL_ENTRY
:
3689 fprintf_unfiltered (gdb_stdlog
,
3690 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3691 /* Getting the current syscall number. */
3692 if (handle_syscall_event (ecs
) != 0)
3694 goto process_event_stop_test
;
3696 /* Before examining the threads further, step this thread to
3697 get it entirely out of the syscall. (We get notice of the
3698 event when the thread is just on the verge of exiting a
3699 syscall. Stepping one instruction seems to get it back
3701 case TARGET_WAITKIND_SYSCALL_RETURN
:
3703 fprintf_unfiltered (gdb_stdlog
,
3704 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3705 if (handle_syscall_event (ecs
) != 0)
3707 goto process_event_stop_test
;
3709 case TARGET_WAITKIND_STOPPED
:
3711 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
3712 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
3715 case TARGET_WAITKIND_NO_HISTORY
:
3717 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
3718 /* Reverse execution: target ran out of history info. */
3720 /* Pull the single step breakpoints out of the target. */
3721 if (singlestep_breakpoints_inserted_p
)
3723 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3724 context_switch (ecs
->ptid
);
3725 remove_single_step_breakpoints ();
3726 singlestep_breakpoints_inserted_p
= 0;
3728 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3729 print_no_history_reason ();
3730 stop_stepping (ecs
);
3734 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
3736 /* Do we need to clean up the state of a thread that has
3737 completed a displaced single-step? (Doing so usually affects
3738 the PC, so do it here, before we set stop_pc.) */
3739 displaced_step_fixup (ecs
->ptid
,
3740 ecs
->event_thread
->suspend
.stop_signal
);
3742 /* If we either finished a single-step or hit a breakpoint, but
3743 the user wanted this thread to be stopped, pretend we got a
3744 SIG0 (generic unsignaled stop). */
3746 if (ecs
->event_thread
->stop_requested
3747 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3748 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3751 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3755 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3756 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3757 struct cleanup
*old_chain
= save_inferior_ptid ();
3759 inferior_ptid
= ecs
->ptid
;
3761 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
3762 paddress (gdbarch
, stop_pc
));
3763 if (target_stopped_by_watchpoint ())
3767 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
3769 if (target_stopped_data_address (¤t_target
, &addr
))
3770 fprintf_unfiltered (gdb_stdlog
,
3771 "infrun: stopped data address = %s\n",
3772 paddress (gdbarch
, addr
));
3774 fprintf_unfiltered (gdb_stdlog
,
3775 "infrun: (no data address available)\n");
3778 do_cleanups (old_chain
);
3781 if (stepping_past_singlestep_breakpoint
)
3783 gdb_assert (singlestep_breakpoints_inserted_p
);
3784 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
3785 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
3787 stepping_past_singlestep_breakpoint
= 0;
3789 /* We've either finished single-stepping past the single-step
3790 breakpoint, or stopped for some other reason. It would be nice if
3791 we could tell, but we can't reliably. */
3792 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3795 fprintf_unfiltered (gdb_stdlog
,
3796 "infrun: stepping_past_"
3797 "singlestep_breakpoint\n");
3798 /* Pull the single step breakpoints out of the target. */
3799 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3800 context_switch (ecs
->ptid
);
3801 remove_single_step_breakpoints ();
3802 singlestep_breakpoints_inserted_p
= 0;
3804 ecs
->random_signal
= 0;
3805 ecs
->event_thread
->control
.trap_expected
= 0;
3807 context_switch (saved_singlestep_ptid
);
3808 if (deprecated_context_hook
)
3809 deprecated_context_hook (pid_to_thread_id (saved_singlestep_ptid
));
3811 resume (1, GDB_SIGNAL_0
);
3812 prepare_to_wait (ecs
);
3817 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
3819 /* In non-stop mode, there's never a deferred_step_ptid set. */
3820 gdb_assert (!non_stop
);
3822 /* If we stopped for some other reason than single-stepping, ignore
3823 the fact that we were supposed to switch back. */
3824 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3827 fprintf_unfiltered (gdb_stdlog
,
3828 "infrun: handling deferred step\n");
3830 /* Pull the single step breakpoints out of the target. */
3831 if (singlestep_breakpoints_inserted_p
)
3833 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3834 context_switch (ecs
->ptid
);
3835 remove_single_step_breakpoints ();
3836 singlestep_breakpoints_inserted_p
= 0;
3839 ecs
->event_thread
->control
.trap_expected
= 0;
3841 context_switch (deferred_step_ptid
);
3842 deferred_step_ptid
= null_ptid
;
3843 /* Suppress spurious "Switching to ..." message. */
3844 previous_inferior_ptid
= inferior_ptid
;
3846 resume (1, GDB_SIGNAL_0
);
3847 prepare_to_wait (ecs
);
3851 deferred_step_ptid
= null_ptid
;
3854 /* See if a thread hit a thread-specific breakpoint that was meant for
3855 another thread. If so, then step that thread past the breakpoint,
3858 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3860 int thread_hop_needed
= 0;
3861 struct address_space
*aspace
=
3862 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
3864 /* Check if a regular breakpoint has been hit before checking
3865 for a potential single step breakpoint. Otherwise, GDB will
3866 not see this breakpoint hit when stepping onto breakpoints. */
3867 if (regular_breakpoint_inserted_here_p (aspace
, stop_pc
))
3869 ecs
->random_signal
= 0;
3870 if (!breakpoint_thread_match (aspace
, stop_pc
, ecs
->ptid
))
3871 thread_hop_needed
= 1;
3873 else if (singlestep_breakpoints_inserted_p
)
3875 /* We have not context switched yet, so this should be true
3876 no matter which thread hit the singlestep breakpoint. */
3877 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
3879 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
3881 target_pid_to_str (ecs
->ptid
));
3883 ecs
->random_signal
= 0;
3884 /* The call to in_thread_list is necessary because PTIDs sometimes
3885 change when we go from single-threaded to multi-threaded. If
3886 the singlestep_ptid is still in the list, assume that it is
3887 really different from ecs->ptid. */
3888 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
3889 && in_thread_list (singlestep_ptid
))
3891 /* If the PC of the thread we were trying to single-step
3892 has changed, discard this event (which we were going
3893 to ignore anyway), and pretend we saw that thread
3894 trap. This prevents us continuously moving the
3895 single-step breakpoint forward, one instruction at a
3896 time. If the PC has changed, then the thread we were
3897 trying to single-step has trapped or been signalled,
3898 but the event has not been reported to GDB yet.
3900 There might be some cases where this loses signal
3901 information, if a signal has arrived at exactly the
3902 same time that the PC changed, but this is the best
3903 we can do with the information available. Perhaps we
3904 should arrange to report all events for all threads
3905 when they stop, or to re-poll the remote looking for
3906 this particular thread (i.e. temporarily enable
3909 CORE_ADDR new_singlestep_pc
3910 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
3912 if (new_singlestep_pc
!= singlestep_pc
)
3914 enum gdb_signal stop_signal
;
3917 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
3918 " but expected thread advanced also\n");
3920 /* The current context still belongs to
3921 singlestep_ptid. Don't swap here, since that's
3922 the context we want to use. Just fudge our
3923 state and continue. */
3924 stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
3925 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3926 ecs
->ptid
= singlestep_ptid
;
3927 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3928 ecs
->event_thread
->suspend
.stop_signal
= stop_signal
;
3929 stop_pc
= new_singlestep_pc
;
3934 fprintf_unfiltered (gdb_stdlog
,
3935 "infrun: unexpected thread\n");
3937 thread_hop_needed
= 1;
3938 stepping_past_singlestep_breakpoint
= 1;
3939 saved_singlestep_ptid
= singlestep_ptid
;
3944 if (thread_hop_needed
)
3946 struct regcache
*thread_regcache
;
3947 int remove_status
= 0;
3950 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
3952 /* Switch context before touching inferior memory, the
3953 previous thread may have exited. */
3954 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
3955 context_switch (ecs
->ptid
);
3957 /* Saw a breakpoint, but it was hit by the wrong thread.
3960 if (singlestep_breakpoints_inserted_p
)
3962 /* Pull the single step breakpoints out of the target. */
3963 remove_single_step_breakpoints ();
3964 singlestep_breakpoints_inserted_p
= 0;
3967 /* If the arch can displace step, don't remove the
3969 thread_regcache
= get_thread_regcache (ecs
->ptid
);
3970 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
3971 remove_status
= remove_breakpoints ();
3973 /* Did we fail to remove breakpoints? If so, try
3974 to set the PC past the bp. (There's at least
3975 one situation in which we can fail to remove
3976 the bp's: On HP-UX's that use ttrace, we can't
3977 change the address space of a vforking child
3978 process until the child exits (well, okay, not
3979 then either :-) or execs. */
3980 if (remove_status
!= 0)
3981 error (_("Cannot step over breakpoint hit in wrong thread"));
3986 /* Only need to require the next event from this
3987 thread in all-stop mode. */
3988 waiton_ptid
= ecs
->ptid
;
3989 infwait_state
= infwait_thread_hop_state
;
3992 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3997 else if (singlestep_breakpoints_inserted_p
)
3999 ecs
->random_signal
= 0;
4003 ecs
->random_signal
= 1;
4005 /* See if something interesting happened to the non-current thread. If
4006 so, then switch to that thread. */
4007 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4010 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
4012 context_switch (ecs
->ptid
);
4014 if (deprecated_context_hook
)
4015 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
4018 /* At this point, get hold of the now-current thread's frame. */
4019 frame
= get_current_frame ();
4020 gdbarch
= get_frame_arch (frame
);
4022 if (singlestep_breakpoints_inserted_p
)
4024 /* Pull the single step breakpoints out of the target. */
4025 remove_single_step_breakpoints ();
4026 singlestep_breakpoints_inserted_p
= 0;
4029 if (stepped_after_stopped_by_watchpoint
)
4030 stopped_by_watchpoint
= 0;
4032 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
4034 /* If necessary, step over this watchpoint. We'll be back to display
4036 if (stopped_by_watchpoint
4037 && (target_have_steppable_watchpoint
4038 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
4040 /* At this point, we are stopped at an instruction which has
4041 attempted to write to a piece of memory under control of
4042 a watchpoint. The instruction hasn't actually executed
4043 yet. If we were to evaluate the watchpoint expression
4044 now, we would get the old value, and therefore no change
4045 would seem to have occurred.
4047 In order to make watchpoints work `right', we really need
4048 to complete the memory write, and then evaluate the
4049 watchpoint expression. We do this by single-stepping the
4052 It may not be necessary to disable the watchpoint to stop over
4053 it. For example, the PA can (with some kernel cooperation)
4054 single step over a watchpoint without disabling the watchpoint.
4056 It is far more common to need to disable a watchpoint to step
4057 the inferior over it. If we have non-steppable watchpoints,
4058 we must disable the current watchpoint; it's simplest to
4059 disable all watchpoints and breakpoints. */
4062 if (!target_have_steppable_watchpoint
)
4064 remove_breakpoints ();
4065 /* See comment in resume why we need to stop bypassing signals
4066 while breakpoints have been removed. */
4067 target_pass_signals (0, NULL
);
4070 hw_step
= maybe_software_singlestep (gdbarch
, stop_pc
);
4071 target_resume (ecs
->ptid
, hw_step
, GDB_SIGNAL_0
);
4072 waiton_ptid
= ecs
->ptid
;
4073 if (target_have_steppable_watchpoint
)
4074 infwait_state
= infwait_step_watch_state
;
4076 infwait_state
= infwait_nonstep_watch_state
;
4077 prepare_to_wait (ecs
);
4081 clear_stop_func (ecs
);
4082 ecs
->event_thread
->stepping_over_breakpoint
= 0;
4083 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
4084 ecs
->event_thread
->control
.stop_step
= 0;
4085 stop_print_frame
= 1;
4086 ecs
->random_signal
= 0;
4087 stopped_by_random_signal
= 0;
4089 /* Hide inlined functions starting here, unless we just performed stepi or
4090 nexti. After stepi and nexti, always show the innermost frame (not any
4091 inline function call sites). */
4092 if (ecs
->event_thread
->control
.step_range_end
!= 1)
4094 struct address_space
*aspace
=
4095 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
4097 /* skip_inline_frames is expensive, so we avoid it if we can
4098 determine that the address is one where functions cannot have
4099 been inlined. This improves performance with inferiors that
4100 load a lot of shared libraries, because the solib event
4101 breakpoint is defined as the address of a function (i.e. not
4102 inline). Note that we have to check the previous PC as well
4103 as the current one to catch cases when we have just
4104 single-stepped off a breakpoint prior to reinstating it.
4105 Note that we're assuming that the code we single-step to is
4106 not inline, but that's not definitive: there's nothing
4107 preventing the event breakpoint function from containing
4108 inlined code, and the single-step ending up there. If the
4109 user had set a breakpoint on that inlined code, the missing
4110 skip_inline_frames call would break things. Fortunately
4111 that's an extremely unlikely scenario. */
4112 if (!pc_at_non_inline_function (aspace
, stop_pc
, &ecs
->ws
)
4113 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4114 && ecs
->event_thread
->control
.trap_expected
4115 && pc_at_non_inline_function (aspace
,
4116 ecs
->event_thread
->prev_pc
,
4119 skip_inline_frames (ecs
->ptid
);
4121 /* Re-fetch current thread's frame in case that invalidated
4123 frame
= get_current_frame ();
4124 gdbarch
= get_frame_arch (frame
);
4128 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4129 && ecs
->event_thread
->control
.trap_expected
4130 && gdbarch_single_step_through_delay_p (gdbarch
)
4131 && currently_stepping (ecs
->event_thread
))
4133 /* We're trying to step off a breakpoint. Turns out that we're
4134 also on an instruction that needs to be stepped multiple
4135 times before it's been fully executing. E.g., architectures
4136 with a delay slot. It needs to be stepped twice, once for
4137 the instruction and once for the delay slot. */
4138 int step_through_delay
4139 = gdbarch_single_step_through_delay (gdbarch
, frame
);
4141 if (debug_infrun
&& step_through_delay
)
4142 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
4143 if (ecs
->event_thread
->control
.step_range_end
== 0
4144 && step_through_delay
)
4146 /* The user issued a continue when stopped at a breakpoint.
4147 Set up for another trap and get out of here. */
4148 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4152 else if (step_through_delay
)
4154 /* The user issued a step when stopped at a breakpoint.
4155 Maybe we should stop, maybe we should not - the delay
4156 slot *might* correspond to a line of source. In any
4157 case, don't decide that here, just set
4158 ecs->stepping_over_breakpoint, making sure we
4159 single-step again before breakpoints are re-inserted. */
4160 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4164 /* Look at the cause of the stop, and decide what to do.
4165 The alternatives are:
4166 1) stop_stepping and return; to really stop and return to the debugger,
4167 2) keep_going and return to start up again
4168 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
4169 3) set ecs->random_signal to 1, and the decision between 1 and 2
4170 will be made according to the signal handling tables. */
4172 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4176 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
4177 stop_print_frame
= 0;
4178 stop_stepping (ecs
);
4182 /* This is originated from start_remote(), start_inferior() and
4183 shared libraries hook functions. */
4184 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
4187 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
4188 stop_stepping (ecs
);
4192 /* This originates from attach_command(). We need to overwrite
4193 the stop_signal here, because some kernels don't ignore a
4194 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4195 See more comments in inferior.h. On the other hand, if we
4196 get a non-SIGSTOP, report it to the user - assume the backend
4197 will handle the SIGSTOP if it should show up later.
4199 Also consider that the attach is complete when we see a
4200 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4201 target extended-remote report it instead of a SIGSTOP
4202 (e.g. gdbserver). We already rely on SIGTRAP being our
4203 signal, so this is no exception.
4205 Also consider that the attach is complete when we see a
4206 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4207 the target to stop all threads of the inferior, in case the
4208 low level attach operation doesn't stop them implicitly. If
4209 they weren't stopped implicitly, then the stub will report a
4210 GDB_SIGNAL_0, meaning: stopped for no particular reason
4211 other than GDB's request. */
4212 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
4213 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
4214 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4215 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
4217 stop_stepping (ecs
);
4218 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4222 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4223 handles this event. */
4224 ecs
->event_thread
->control
.stop_bpstat
4225 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4226 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4228 /* Following in case break condition called a
4230 stop_print_frame
= 1;
4232 /* This is where we handle "moribund" watchpoints. Unlike
4233 software breakpoints traps, hardware watchpoint traps are
4234 always distinguishable from random traps. If no high-level
4235 watchpoint is associated with the reported stop data address
4236 anymore, then the bpstat does not explain the signal ---
4237 simply make sure to ignore it if `stopped_by_watchpoint' is
4241 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4242 && (bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4244 == BPSTAT_SIGNAL_NO
)
4245 && stopped_by_watchpoint
)
4246 fprintf_unfiltered (gdb_stdlog
,
4247 "infrun: no user watchpoint explains "
4248 "watchpoint SIGTRAP, ignoring\n");
4250 /* NOTE: cagney/2003-03-29: These two checks for a random signal
4251 at one stage in the past included checks for an inferior
4252 function call's call dummy's return breakpoint. The original
4253 comment, that went with the test, read:
4255 ``End of a stack dummy. Some systems (e.g. Sony news) give
4256 another signal besides SIGTRAP, so check here as well as
4259 If someone ever tries to get call dummys on a
4260 non-executable stack to work (where the target would stop
4261 with something like a SIGSEGV), then those tests might need
4262 to be re-instated. Given, however, that the tests were only
4263 enabled when momentary breakpoints were not being used, I
4264 suspect that it won't be the case.
4266 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4267 be necessary for call dummies on a non-executable stack on
4270 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4272 = !((bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4274 != BPSTAT_SIGNAL_NO
)
4275 || stopped_by_watchpoint
4276 || ecs
->event_thread
->control
.trap_expected
4277 || (ecs
->event_thread
->control
.step_range_end
4278 && (ecs
->event_thread
->control
.step_resume_breakpoint
4282 enum bpstat_signal_value sval
;
4284 sval
= bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4285 ecs
->event_thread
->suspend
.stop_signal
);
4286 ecs
->random_signal
= (sval
== BPSTAT_SIGNAL_NO
);
4288 if (sval
== BPSTAT_SIGNAL_HIDE
)
4289 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
4292 process_event_stop_test
:
4294 /* Re-fetch current thread's frame in case we did a
4295 "goto process_event_stop_test" above. */
4296 frame
= get_current_frame ();
4297 gdbarch
= get_frame_arch (frame
);
4299 /* For the program's own signals, act according to
4300 the signal handling tables. */
4302 if (ecs
->random_signal
)
4304 /* Signal not for debugging purposes. */
4306 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
4309 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n",
4310 ecs
->event_thread
->suspend
.stop_signal
);
4312 stopped_by_random_signal
= 1;
4314 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
4317 target_terminal_ours_for_output ();
4318 print_signal_received_reason
4319 (ecs
->event_thread
->suspend
.stop_signal
);
4321 /* Always stop on signals if we're either just gaining control
4322 of the program, or the user explicitly requested this thread
4323 to remain stopped. */
4324 if (stop_soon
!= NO_STOP_QUIETLY
4325 || ecs
->event_thread
->stop_requested
4327 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
4329 stop_stepping (ecs
);
4332 /* If not going to stop, give terminal back
4333 if we took it away. */
4335 target_terminal_inferior ();
4337 /* Clear the signal if it should not be passed. */
4338 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
4339 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4341 if (ecs
->event_thread
->prev_pc
== stop_pc
4342 && ecs
->event_thread
->control
.trap_expected
4343 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4345 /* We were just starting a new sequence, attempting to
4346 single-step off of a breakpoint and expecting a SIGTRAP.
4347 Instead this signal arrives. This signal will take us out
4348 of the stepping range so GDB needs to remember to, when
4349 the signal handler returns, resume stepping off that
4351 /* To simplify things, "continue" is forced to use the same
4352 code paths as single-step - set a breakpoint at the
4353 signal return address and then, once hit, step off that
4356 fprintf_unfiltered (gdb_stdlog
,
4357 "infrun: signal arrived while stepping over "
4360 insert_hp_step_resume_breakpoint_at_frame (frame
);
4361 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4362 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4363 ecs
->event_thread
->control
.trap_expected
= 0;
4368 if (ecs
->event_thread
->control
.step_range_end
!= 0
4369 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4370 && pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4371 && frame_id_eq (get_stack_frame_id (frame
),
4372 ecs
->event_thread
->control
.step_stack_frame_id
)
4373 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4375 /* The inferior is about to take a signal that will take it
4376 out of the single step range. Set a breakpoint at the
4377 current PC (which is presumably where the signal handler
4378 will eventually return) and then allow the inferior to
4381 Note that this is only needed for a signal delivered
4382 while in the single-step range. Nested signals aren't a
4383 problem as they eventually all return. */
4385 fprintf_unfiltered (gdb_stdlog
,
4386 "infrun: signal may take us out of "
4387 "single-step range\n");
4389 insert_hp_step_resume_breakpoint_at_frame (frame
);
4390 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4391 ecs
->event_thread
->control
.trap_expected
= 0;
4396 /* Note: step_resume_breakpoint may be non-NULL. This occures
4397 when either there's a nested signal, or when there's a
4398 pending signal enabled just as the signal handler returns
4399 (leaving the inferior at the step-resume-breakpoint without
4400 actually executing it). Either way continue until the
4401 breakpoint is really hit. */
4405 /* Handle cases caused by hitting a breakpoint. */
4407 CORE_ADDR jmp_buf_pc
;
4408 struct bpstat_what what
;
4410 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
4412 if (what
.call_dummy
)
4414 stop_stack_dummy
= what
.call_dummy
;
4417 /* If we hit an internal event that triggers symbol changes, the
4418 current frame will be invalidated within bpstat_what (e.g.,
4419 if we hit an internal solib event). Re-fetch it. */
4420 frame
= get_current_frame ();
4421 gdbarch
= get_frame_arch (frame
);
4423 switch (what
.main_action
)
4425 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4426 /* If we hit the breakpoint at longjmp while stepping, we
4427 install a momentary breakpoint at the target of the
4431 fprintf_unfiltered (gdb_stdlog
,
4432 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4434 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4436 if (what
.is_longjmp
)
4438 struct value
*arg_value
;
4440 /* If we set the longjmp breakpoint via a SystemTap
4441 probe, then use it to extract the arguments. The
4442 destination PC is the third argument to the
4444 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
4446 jmp_buf_pc
= value_as_address (arg_value
);
4447 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
4448 || !gdbarch_get_longjmp_target (gdbarch
,
4449 frame
, &jmp_buf_pc
))
4452 fprintf_unfiltered (gdb_stdlog
,
4453 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4454 "(!gdbarch_get_longjmp_target)\n");
4459 /* Insert a breakpoint at resume address. */
4460 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4463 check_exception_resume (ecs
, frame
);
4467 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4469 struct frame_info
*init_frame
;
4471 /* There are several cases to consider.
4473 1. The initiating frame no longer exists. In this case
4474 we must stop, because the exception or longjmp has gone
4477 2. The initiating frame exists, and is the same as the
4478 current frame. We stop, because the exception or
4479 longjmp has been caught.
4481 3. The initiating frame exists and is different from
4482 the current frame. This means the exception or longjmp
4483 has been caught beneath the initiating frame, so keep
4486 4. longjmp breakpoint has been placed just to protect
4487 against stale dummy frames and user is not interested
4488 in stopping around longjmps. */
4491 fprintf_unfiltered (gdb_stdlog
,
4492 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4494 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
4496 delete_exception_resume_breakpoint (ecs
->event_thread
);
4498 if (what
.is_longjmp
)
4500 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
->num
);
4502 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
4510 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
4514 struct frame_id current_id
4515 = get_frame_id (get_current_frame ());
4516 if (frame_id_eq (current_id
,
4517 ecs
->event_thread
->initiating_frame
))
4519 /* Case 2. Fall through. */
4529 /* For Cases 1 and 2, remove the step-resume breakpoint,
4531 delete_step_resume_breakpoint (ecs
->event_thread
);
4533 ecs
->event_thread
->control
.stop_step
= 1;
4534 print_end_stepping_range_reason ();
4535 stop_stepping (ecs
);
4539 case BPSTAT_WHAT_SINGLE
:
4541 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4542 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4543 /* Still need to check other stuff, at least the case where
4544 we are stepping and step out of the right range. */
4547 case BPSTAT_WHAT_STEP_RESUME
:
4549 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4551 delete_step_resume_breakpoint (ecs
->event_thread
);
4552 if (ecs
->event_thread
->control
.proceed_to_finish
4553 && execution_direction
== EXEC_REVERSE
)
4555 struct thread_info
*tp
= ecs
->event_thread
;
4557 /* We are finishing a function in reverse, and just hit
4558 the step-resume breakpoint at the start address of
4559 the function, and we're almost there -- just need to
4560 back up by one more single-step, which should take us
4561 back to the function call. */
4562 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
4566 fill_in_stop_func (gdbarch
, ecs
);
4567 if (stop_pc
== ecs
->stop_func_start
4568 && execution_direction
== EXEC_REVERSE
)
4570 /* We are stepping over a function call in reverse, and
4571 just hit the step-resume breakpoint at the start
4572 address of the function. Go back to single-stepping,
4573 which should take us back to the function call. */
4574 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4580 case BPSTAT_WHAT_STOP_NOISY
:
4582 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4583 stop_print_frame
= 1;
4585 /* We are about to nuke the step_resume_breakpointt via the
4586 cleanup chain, so no need to worry about it here. */
4588 stop_stepping (ecs
);
4591 case BPSTAT_WHAT_STOP_SILENT
:
4593 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4594 stop_print_frame
= 0;
4596 /* We are about to nuke the step_resume_breakpoin via the
4597 cleanup chain, so no need to worry about it here. */
4599 stop_stepping (ecs
);
4602 case BPSTAT_WHAT_HP_STEP_RESUME
:
4604 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4606 delete_step_resume_breakpoint (ecs
->event_thread
);
4607 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4609 /* Back when the step-resume breakpoint was inserted, we
4610 were trying to single-step off a breakpoint. Go back
4612 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4613 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4619 case BPSTAT_WHAT_KEEP_CHECKING
:
4624 /* We come here if we hit a breakpoint but should not
4625 stop for it. Possibly we also were stepping
4626 and should stop for that. So fall through and
4627 test for stepping. But, if not stepping,
4630 /* In all-stop mode, if we're currently stepping but have stopped in
4631 some other thread, we need to switch back to the stepped thread. */
4634 struct thread_info
*tp
;
4636 tp
= iterate_over_threads (currently_stepping_or_nexting_callback
,
4640 /* However, if the current thread is blocked on some internal
4641 breakpoint, and we simply need to step over that breakpoint
4642 to get it going again, do that first. */
4643 if ((ecs
->event_thread
->control
.trap_expected
4644 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
4645 || ecs
->event_thread
->stepping_over_breakpoint
)
4651 /* If the stepping thread exited, then don't try to switch
4652 back and resume it, which could fail in several different
4653 ways depending on the target. Instead, just keep going.
4655 We can find a stepping dead thread in the thread list in
4658 - The target supports thread exit events, and when the
4659 target tries to delete the thread from the thread list,
4660 inferior_ptid pointed at the exiting thread. In such
4661 case, calling delete_thread does not really remove the
4662 thread from the list; instead, the thread is left listed,
4663 with 'exited' state.
4665 - The target's debug interface does not support thread
4666 exit events, and so we have no idea whatsoever if the
4667 previously stepping thread is still alive. For that
4668 reason, we need to synchronously query the target
4670 if (is_exited (tp
->ptid
)
4671 || !target_thread_alive (tp
->ptid
))
4674 fprintf_unfiltered (gdb_stdlog
,
4675 "infrun: not switching back to "
4676 "stepped thread, it has vanished\n");
4678 delete_thread (tp
->ptid
);
4683 /* Otherwise, we no longer expect a trap in the current thread.
4684 Clear the trap_expected flag before switching back -- this is
4685 what keep_going would do as well, if we called it. */
4686 ecs
->event_thread
->control
.trap_expected
= 0;
4689 fprintf_unfiltered (gdb_stdlog
,
4690 "infrun: switching back to stepped thread\n");
4692 ecs
->event_thread
= tp
;
4693 ecs
->ptid
= tp
->ptid
;
4694 context_switch (ecs
->ptid
);
4700 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
4703 fprintf_unfiltered (gdb_stdlog
,
4704 "infrun: step-resume breakpoint is inserted\n");
4706 /* Having a step-resume breakpoint overrides anything
4707 else having to do with stepping commands until
4708 that breakpoint is reached. */
4713 if (ecs
->event_thread
->control
.step_range_end
== 0)
4716 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
4717 /* Likewise if we aren't even stepping. */
4722 /* Re-fetch current thread's frame in case the code above caused
4723 the frame cache to be re-initialized, making our FRAME variable
4724 a dangling pointer. */
4725 frame
= get_current_frame ();
4726 gdbarch
= get_frame_arch (frame
);
4727 fill_in_stop_func (gdbarch
, ecs
);
4729 /* If stepping through a line, keep going if still within it.
4731 Note that step_range_end is the address of the first instruction
4732 beyond the step range, and NOT the address of the last instruction
4735 Note also that during reverse execution, we may be stepping
4736 through a function epilogue and therefore must detect when
4737 the current-frame changes in the middle of a line. */
4739 if (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4740 && (execution_direction
!= EXEC_REVERSE
4741 || frame_id_eq (get_frame_id (frame
),
4742 ecs
->event_thread
->control
.step_frame_id
)))
4746 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
4747 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
4748 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
4750 /* Tentatively re-enable range stepping; `resume' disables it if
4751 necessary (e.g., if we're stepping over a breakpoint or we
4752 have software watchpoints). */
4753 ecs
->event_thread
->control
.may_range_step
= 1;
4755 /* When stepping backward, stop at beginning of line range
4756 (unless it's the function entry point, in which case
4757 keep going back to the call point). */
4758 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
4759 && stop_pc
!= ecs
->stop_func_start
4760 && execution_direction
== EXEC_REVERSE
)
4762 ecs
->event_thread
->control
.stop_step
= 1;
4763 print_end_stepping_range_reason ();
4764 stop_stepping (ecs
);
4772 /* We stepped out of the stepping range. */
4774 /* If we are stepping at the source level and entered the runtime
4775 loader dynamic symbol resolution code...
4777 EXEC_FORWARD: we keep on single stepping until we exit the run
4778 time loader code and reach the callee's address.
4780 EXEC_REVERSE: we've already executed the callee (backward), and
4781 the runtime loader code is handled just like any other
4782 undebuggable function call. Now we need only keep stepping
4783 backward through the trampoline code, and that's handled further
4784 down, so there is nothing for us to do here. */
4786 if (execution_direction
!= EXEC_REVERSE
4787 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4788 && in_solib_dynsym_resolve_code (stop_pc
))
4790 CORE_ADDR pc_after_resolver
=
4791 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
4794 fprintf_unfiltered (gdb_stdlog
,
4795 "infrun: stepped into dynsym resolve code\n");
4797 if (pc_after_resolver
)
4799 /* Set up a step-resume breakpoint at the address
4800 indicated by SKIP_SOLIB_RESOLVER. */
4801 struct symtab_and_line sr_sal
;
4804 sr_sal
.pc
= pc_after_resolver
;
4805 sr_sal
.pspace
= get_frame_program_space (frame
);
4807 insert_step_resume_breakpoint_at_sal (gdbarch
,
4808 sr_sal
, null_frame_id
);
4815 if (ecs
->event_thread
->control
.step_range_end
!= 1
4816 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4817 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4818 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
4821 fprintf_unfiltered (gdb_stdlog
,
4822 "infrun: stepped into signal trampoline\n");
4823 /* The inferior, while doing a "step" or "next", has ended up in
4824 a signal trampoline (either by a signal being delivered or by
4825 the signal handler returning). Just single-step until the
4826 inferior leaves the trampoline (either by calling the handler
4832 /* If we're in the return path from a shared library trampoline,
4833 we want to proceed through the trampoline when stepping. */
4834 /* macro/2012-04-25: This needs to come before the subroutine
4835 call check below as on some targets return trampolines look
4836 like subroutine calls (MIPS16 return thunks). */
4837 if (gdbarch_in_solib_return_trampoline (gdbarch
,
4838 stop_pc
, ecs
->stop_func_name
)
4839 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
4841 /* Determine where this trampoline returns. */
4842 CORE_ADDR real_stop_pc
;
4844 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4847 fprintf_unfiltered (gdb_stdlog
,
4848 "infrun: stepped into solib return tramp\n");
4850 /* Only proceed through if we know where it's going. */
4853 /* And put the step-breakpoint there and go until there. */
4854 struct symtab_and_line sr_sal
;
4856 init_sal (&sr_sal
); /* initialize to zeroes */
4857 sr_sal
.pc
= real_stop_pc
;
4858 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4859 sr_sal
.pspace
= get_frame_program_space (frame
);
4861 /* Do not specify what the fp should be when we stop since
4862 on some machines the prologue is where the new fp value
4864 insert_step_resume_breakpoint_at_sal (gdbarch
,
4865 sr_sal
, null_frame_id
);
4867 /* Restart without fiddling with the step ranges or
4874 /* Check for subroutine calls. The check for the current frame
4875 equalling the step ID is not necessary - the check of the
4876 previous frame's ID is sufficient - but it is a common case and
4877 cheaper than checking the previous frame's ID.
4879 NOTE: frame_id_eq will never report two invalid frame IDs as
4880 being equal, so to get into this block, both the current and
4881 previous frame must have valid frame IDs. */
4882 /* The outer_frame_id check is a heuristic to detect stepping
4883 through startup code. If we step over an instruction which
4884 sets the stack pointer from an invalid value to a valid value,
4885 we may detect that as a subroutine call from the mythical
4886 "outermost" function. This could be fixed by marking
4887 outermost frames as !stack_p,code_p,special_p. Then the
4888 initial outermost frame, before sp was valid, would
4889 have code_addr == &_start. See the comment in frame_id_eq
4891 if (!frame_id_eq (get_stack_frame_id (frame
),
4892 ecs
->event_thread
->control
.step_stack_frame_id
)
4893 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4894 ecs
->event_thread
->control
.step_stack_frame_id
)
4895 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
4897 || step_start_function
!= find_pc_function (stop_pc
))))
4899 CORE_ADDR real_stop_pc
;
4902 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
4904 if ((ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
4905 || ((ecs
->event_thread
->control
.step_range_end
== 1)
4906 && in_prologue (gdbarch
, ecs
->event_thread
->prev_pc
,
4907 ecs
->stop_func_start
)))
4909 /* I presume that step_over_calls is only 0 when we're
4910 supposed to be stepping at the assembly language level
4911 ("stepi"). Just stop. */
4912 /* Also, maybe we just did a "nexti" inside a prolog, so we
4913 thought it was a subroutine call but it was not. Stop as
4915 /* And this works the same backward as frontward. MVS */
4916 ecs
->event_thread
->control
.stop_step
= 1;
4917 print_end_stepping_range_reason ();
4918 stop_stepping (ecs
);
4922 /* Reverse stepping through solib trampolines. */
4924 if (execution_direction
== EXEC_REVERSE
4925 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
4926 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4927 || (ecs
->stop_func_start
== 0
4928 && in_solib_dynsym_resolve_code (stop_pc
))))
4930 /* Any solib trampoline code can be handled in reverse
4931 by simply continuing to single-step. We have already
4932 executed the solib function (backwards), and a few
4933 steps will take us back through the trampoline to the
4939 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4941 /* We're doing a "next".
4943 Normal (forward) execution: set a breakpoint at the
4944 callee's return address (the address at which the caller
4947 Reverse (backward) execution. set the step-resume
4948 breakpoint at the start of the function that we just
4949 stepped into (backwards), and continue to there. When we
4950 get there, we'll need to single-step back to the caller. */
4952 if (execution_direction
== EXEC_REVERSE
)
4954 /* If we're already at the start of the function, we've either
4955 just stepped backward into a single instruction function,
4956 or stepped back out of a signal handler to the first instruction
4957 of the function. Just keep going, which will single-step back
4959 if (ecs
->stop_func_start
!= stop_pc
)
4961 struct symtab_and_line sr_sal
;
4963 /* Normal function call return (static or dynamic). */
4965 sr_sal
.pc
= ecs
->stop_func_start
;
4966 sr_sal
.pspace
= get_frame_program_space (frame
);
4967 insert_step_resume_breakpoint_at_sal (gdbarch
,
4968 sr_sal
, null_frame_id
);
4972 insert_step_resume_breakpoint_at_caller (frame
);
4978 /* If we are in a function call trampoline (a stub between the
4979 calling routine and the real function), locate the real
4980 function. That's what tells us (a) whether we want to step
4981 into it at all, and (b) what prologue we want to run to the
4982 end of, if we do step into it. */
4983 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
4984 if (real_stop_pc
== 0)
4985 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4986 if (real_stop_pc
!= 0)
4987 ecs
->stop_func_start
= real_stop_pc
;
4989 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
4991 struct symtab_and_line sr_sal
;
4994 sr_sal
.pc
= ecs
->stop_func_start
;
4995 sr_sal
.pspace
= get_frame_program_space (frame
);
4997 insert_step_resume_breakpoint_at_sal (gdbarch
,
4998 sr_sal
, null_frame_id
);
5003 /* If we have line number information for the function we are
5004 thinking of stepping into and the function isn't on the skip
5007 If there are several symtabs at that PC (e.g. with include
5008 files), just want to know whether *any* of them have line
5009 numbers. find_pc_line handles this. */
5011 struct symtab_and_line tmp_sal
;
5013 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5014 if (tmp_sal
.line
!= 0
5015 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
5018 if (execution_direction
== EXEC_REVERSE
)
5019 handle_step_into_function_backward (gdbarch
, ecs
);
5021 handle_step_into_function (gdbarch
, ecs
);
5026 /* If we have no line number and the step-stop-if-no-debug is
5027 set, we stop the step so that the user has a chance to switch
5028 in assembly mode. */
5029 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5030 && step_stop_if_no_debug
)
5032 ecs
->event_thread
->control
.stop_step
= 1;
5033 print_end_stepping_range_reason ();
5034 stop_stepping (ecs
);
5038 if (execution_direction
== EXEC_REVERSE
)
5040 /* If we're already at the start of the function, we've either just
5041 stepped backward into a single instruction function without line
5042 number info, or stepped back out of a signal handler to the first
5043 instruction of the function without line number info. Just keep
5044 going, which will single-step back to the caller. */
5045 if (ecs
->stop_func_start
!= stop_pc
)
5047 /* Set a breakpoint at callee's start address.
5048 From there we can step once and be back in the caller. */
5049 struct symtab_and_line sr_sal
;
5052 sr_sal
.pc
= ecs
->stop_func_start
;
5053 sr_sal
.pspace
= get_frame_program_space (frame
);
5054 insert_step_resume_breakpoint_at_sal (gdbarch
,
5055 sr_sal
, null_frame_id
);
5059 /* Set a breakpoint at callee's return address (the address
5060 at which the caller will resume). */
5061 insert_step_resume_breakpoint_at_caller (frame
);
5067 /* Reverse stepping through solib trampolines. */
5069 if (execution_direction
== EXEC_REVERSE
5070 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
5072 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5073 || (ecs
->stop_func_start
== 0
5074 && in_solib_dynsym_resolve_code (stop_pc
)))
5076 /* Any solib trampoline code can be handled in reverse
5077 by simply continuing to single-step. We have already
5078 executed the solib function (backwards), and a few
5079 steps will take us back through the trampoline to the
5084 else if (in_solib_dynsym_resolve_code (stop_pc
))
5086 /* Stepped backward into the solib dynsym resolver.
5087 Set a breakpoint at its start and continue, then
5088 one more step will take us out. */
5089 struct symtab_and_line sr_sal
;
5092 sr_sal
.pc
= ecs
->stop_func_start
;
5093 sr_sal
.pspace
= get_frame_program_space (frame
);
5094 insert_step_resume_breakpoint_at_sal (gdbarch
,
5095 sr_sal
, null_frame_id
);
5101 stop_pc_sal
= find_pc_line (stop_pc
, 0);
5103 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5104 the trampoline processing logic, however, there are some trampolines
5105 that have no names, so we should do trampoline handling first. */
5106 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5107 && ecs
->stop_func_name
== NULL
5108 && stop_pc_sal
.line
== 0)
5111 fprintf_unfiltered (gdb_stdlog
,
5112 "infrun: stepped into undebuggable function\n");
5114 /* The inferior just stepped into, or returned to, an
5115 undebuggable function (where there is no debugging information
5116 and no line number corresponding to the address where the
5117 inferior stopped). Since we want to skip this kind of code,
5118 we keep going until the inferior returns from this
5119 function - unless the user has asked us not to (via
5120 set step-mode) or we no longer know how to get back
5121 to the call site. */
5122 if (step_stop_if_no_debug
5123 || !frame_id_p (frame_unwind_caller_id (frame
)))
5125 /* If we have no line number and the step-stop-if-no-debug
5126 is set, we stop the step so that the user has a chance to
5127 switch in assembly mode. */
5128 ecs
->event_thread
->control
.stop_step
= 1;
5129 print_end_stepping_range_reason ();
5130 stop_stepping (ecs
);
5135 /* Set a breakpoint at callee's return address (the address
5136 at which the caller will resume). */
5137 insert_step_resume_breakpoint_at_caller (frame
);
5143 if (ecs
->event_thread
->control
.step_range_end
== 1)
5145 /* It is stepi or nexti. We always want to stop stepping after
5148 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
5149 ecs
->event_thread
->control
.stop_step
= 1;
5150 print_end_stepping_range_reason ();
5151 stop_stepping (ecs
);
5155 if (stop_pc_sal
.line
== 0)
5157 /* We have no line number information. That means to stop
5158 stepping (does this always happen right after one instruction,
5159 when we do "s" in a function with no line numbers,
5160 or can this happen as a result of a return or longjmp?). */
5162 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
5163 ecs
->event_thread
->control
.stop_step
= 1;
5164 print_end_stepping_range_reason ();
5165 stop_stepping (ecs
);
5169 /* Look for "calls" to inlined functions, part one. If the inline
5170 frame machinery detected some skipped call sites, we have entered
5171 a new inline function. */
5173 if (frame_id_eq (get_frame_id (get_current_frame ()),
5174 ecs
->event_thread
->control
.step_frame_id
)
5175 && inline_skipped_frames (ecs
->ptid
))
5177 struct symtab_and_line call_sal
;
5180 fprintf_unfiltered (gdb_stdlog
,
5181 "infrun: stepped into inlined function\n");
5183 find_frame_sal (get_current_frame (), &call_sal
);
5185 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
5187 /* For "step", we're going to stop. But if the call site
5188 for this inlined function is on the same source line as
5189 we were previously stepping, go down into the function
5190 first. Otherwise stop at the call site. */
5192 if (call_sal
.line
== ecs
->event_thread
->current_line
5193 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5194 step_into_inline_frame (ecs
->ptid
);
5196 ecs
->event_thread
->control
.stop_step
= 1;
5197 print_end_stepping_range_reason ();
5198 stop_stepping (ecs
);
5203 /* For "next", we should stop at the call site if it is on a
5204 different source line. Otherwise continue through the
5205 inlined function. */
5206 if (call_sal
.line
== ecs
->event_thread
->current_line
5207 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5211 ecs
->event_thread
->control
.stop_step
= 1;
5212 print_end_stepping_range_reason ();
5213 stop_stepping (ecs
);
5219 /* Look for "calls" to inlined functions, part two. If we are still
5220 in the same real function we were stepping through, but we have
5221 to go further up to find the exact frame ID, we are stepping
5222 through a more inlined call beyond its call site. */
5224 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5225 && !frame_id_eq (get_frame_id (get_current_frame ()),
5226 ecs
->event_thread
->control
.step_frame_id
)
5227 && stepped_in_from (get_current_frame (),
5228 ecs
->event_thread
->control
.step_frame_id
))
5231 fprintf_unfiltered (gdb_stdlog
,
5232 "infrun: stepping through inlined function\n");
5234 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5238 ecs
->event_thread
->control
.stop_step
= 1;
5239 print_end_stepping_range_reason ();
5240 stop_stepping (ecs
);
5245 if ((stop_pc
== stop_pc_sal
.pc
)
5246 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
5247 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
5249 /* We are at the start of a different line. So stop. Note that
5250 we don't stop if we step into the middle of a different line.
5251 That is said to make things like for (;;) statements work
5254 fprintf_unfiltered (gdb_stdlog
,
5255 "infrun: stepped to a different line\n");
5256 ecs
->event_thread
->control
.stop_step
= 1;
5257 print_end_stepping_range_reason ();
5258 stop_stepping (ecs
);
5262 /* We aren't done stepping.
5264 Optimize by setting the stepping range to the line.
5265 (We might not be in the original line, but if we entered a
5266 new line in mid-statement, we continue stepping. This makes
5267 things like for(;;) statements work better.) */
5269 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
5270 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
5271 ecs
->event_thread
->control
.may_range_step
= 1;
5272 set_step_info (frame
, stop_pc_sal
);
5275 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
5279 /* Is thread TP in the middle of single-stepping? */
5282 currently_stepping (struct thread_info
*tp
)
5284 return ((tp
->control
.step_range_end
5285 && tp
->control
.step_resume_breakpoint
== NULL
)
5286 || tp
->control
.trap_expected
5287 || bpstat_should_step ());
5290 /* Returns true if any thread *but* the one passed in "data" is in the
5291 middle of stepping or of handling a "next". */
5294 currently_stepping_or_nexting_callback (struct thread_info
*tp
, void *data
)
5299 return (tp
->control
.step_range_end
5300 || tp
->control
.trap_expected
);
5303 /* Inferior has stepped into a subroutine call with source code that
5304 we should not step over. Do step to the first line of code in
5308 handle_step_into_function (struct gdbarch
*gdbarch
,
5309 struct execution_control_state
*ecs
)
5312 struct symtab_and_line stop_func_sal
, sr_sal
;
5314 fill_in_stop_func (gdbarch
, ecs
);
5316 s
= find_pc_symtab (stop_pc
);
5317 if (s
&& s
->language
!= language_asm
)
5318 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5319 ecs
->stop_func_start
);
5321 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5322 /* Use the step_resume_break to step until the end of the prologue,
5323 even if that involves jumps (as it seems to on the vax under
5325 /* If the prologue ends in the middle of a source line, continue to
5326 the end of that source line (if it is still within the function).
5327 Otherwise, just go to end of prologue. */
5328 if (stop_func_sal
.end
5329 && stop_func_sal
.pc
!= ecs
->stop_func_start
5330 && stop_func_sal
.end
< ecs
->stop_func_end
)
5331 ecs
->stop_func_start
= stop_func_sal
.end
;
5333 /* Architectures which require breakpoint adjustment might not be able
5334 to place a breakpoint at the computed address. If so, the test
5335 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5336 ecs->stop_func_start to an address at which a breakpoint may be
5337 legitimately placed.
5339 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5340 made, GDB will enter an infinite loop when stepping through
5341 optimized code consisting of VLIW instructions which contain
5342 subinstructions corresponding to different source lines. On
5343 FR-V, it's not permitted to place a breakpoint on any but the
5344 first subinstruction of a VLIW instruction. When a breakpoint is
5345 set, GDB will adjust the breakpoint address to the beginning of
5346 the VLIW instruction. Thus, we need to make the corresponding
5347 adjustment here when computing the stop address. */
5349 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
5351 ecs
->stop_func_start
5352 = gdbarch_adjust_breakpoint_address (gdbarch
,
5353 ecs
->stop_func_start
);
5356 if (ecs
->stop_func_start
== stop_pc
)
5358 /* We are already there: stop now. */
5359 ecs
->event_thread
->control
.stop_step
= 1;
5360 print_end_stepping_range_reason ();
5361 stop_stepping (ecs
);
5366 /* Put the step-breakpoint there and go until there. */
5367 init_sal (&sr_sal
); /* initialize to zeroes */
5368 sr_sal
.pc
= ecs
->stop_func_start
;
5369 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
5370 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
5372 /* Do not specify what the fp should be when we stop since on
5373 some machines the prologue is where the new fp value is
5375 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
5377 /* And make sure stepping stops right away then. */
5378 ecs
->event_thread
->control
.step_range_end
5379 = ecs
->event_thread
->control
.step_range_start
;
5384 /* Inferior has stepped backward into a subroutine call with source
5385 code that we should not step over. Do step to the beginning of the
5386 last line of code in it. */
5389 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
5390 struct execution_control_state
*ecs
)
5393 struct symtab_and_line stop_func_sal
;
5395 fill_in_stop_func (gdbarch
, ecs
);
5397 s
= find_pc_symtab (stop_pc
);
5398 if (s
&& s
->language
!= language_asm
)
5399 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5400 ecs
->stop_func_start
);
5402 stop_func_sal
= find_pc_line (stop_pc
, 0);
5404 /* OK, we're just going to keep stepping here. */
5405 if (stop_func_sal
.pc
== stop_pc
)
5407 /* We're there already. Just stop stepping now. */
5408 ecs
->event_thread
->control
.stop_step
= 1;
5409 print_end_stepping_range_reason ();
5410 stop_stepping (ecs
);
5414 /* Else just reset the step range and keep going.
5415 No step-resume breakpoint, they don't work for
5416 epilogues, which can have multiple entry paths. */
5417 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
5418 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
5424 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5425 This is used to both functions and to skip over code. */
5428 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
5429 struct symtab_and_line sr_sal
,
5430 struct frame_id sr_id
,
5431 enum bptype sr_type
)
5433 /* There should never be more than one step-resume or longjmp-resume
5434 breakpoint per thread, so we should never be setting a new
5435 step_resume_breakpoint when one is already active. */
5436 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
5437 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
5440 fprintf_unfiltered (gdb_stdlog
,
5441 "infrun: inserting step-resume breakpoint at %s\n",
5442 paddress (gdbarch
, sr_sal
.pc
));
5444 inferior_thread ()->control
.step_resume_breakpoint
5445 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
);
5449 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5450 struct symtab_and_line sr_sal
,
5451 struct frame_id sr_id
)
5453 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
5458 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5459 This is used to skip a potential signal handler.
5461 This is called with the interrupted function's frame. The signal
5462 handler, when it returns, will resume the interrupted function at
5466 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5468 struct symtab_and_line sr_sal
;
5469 struct gdbarch
*gdbarch
;
5471 gdb_assert (return_frame
!= NULL
);
5472 init_sal (&sr_sal
); /* initialize to zeros */
5474 gdbarch
= get_frame_arch (return_frame
);
5475 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
5476 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5477 sr_sal
.pspace
= get_frame_program_space (return_frame
);
5479 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
5480 get_stack_frame_id (return_frame
),
5484 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5485 is used to skip a function after stepping into it (for "next" or if
5486 the called function has no debugging information).
5488 The current function has almost always been reached by single
5489 stepping a call or return instruction. NEXT_FRAME belongs to the
5490 current function, and the breakpoint will be set at the caller's
5493 This is a separate function rather than reusing
5494 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5495 get_prev_frame, which may stop prematurely (see the implementation
5496 of frame_unwind_caller_id for an example). */
5499 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
5501 struct symtab_and_line sr_sal
;
5502 struct gdbarch
*gdbarch
;
5504 /* We shouldn't have gotten here if we don't know where the call site
5506 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
5508 init_sal (&sr_sal
); /* initialize to zeros */
5510 gdbarch
= frame_unwind_caller_arch (next_frame
);
5511 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
5512 frame_unwind_caller_pc (next_frame
));
5513 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5514 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
5516 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
5517 frame_unwind_caller_id (next_frame
));
5520 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5521 new breakpoint at the target of a jmp_buf. The handling of
5522 longjmp-resume uses the same mechanisms used for handling
5523 "step-resume" breakpoints. */
5526 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
5528 /* There should never be more than one longjmp-resume breakpoint per
5529 thread, so we should never be setting a new
5530 longjmp_resume_breakpoint when one is already active. */
5531 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
5534 fprintf_unfiltered (gdb_stdlog
,
5535 "infrun: inserting longjmp-resume breakpoint at %s\n",
5536 paddress (gdbarch
, pc
));
5538 inferior_thread ()->control
.exception_resume_breakpoint
=
5539 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
5542 /* Insert an exception resume breakpoint. TP is the thread throwing
5543 the exception. The block B is the block of the unwinder debug hook
5544 function. FRAME is the frame corresponding to the call to this
5545 function. SYM is the symbol of the function argument holding the
5546 target PC of the exception. */
5549 insert_exception_resume_breakpoint (struct thread_info
*tp
,
5551 struct frame_info
*frame
,
5554 volatile struct gdb_exception e
;
5556 /* We want to ignore errors here. */
5557 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5559 struct symbol
*vsym
;
5560 struct value
*value
;
5562 struct breakpoint
*bp
;
5564 vsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
), b
, VAR_DOMAIN
, NULL
);
5565 value
= read_var_value (vsym
, frame
);
5566 /* If the value was optimized out, revert to the old behavior. */
5567 if (! value_optimized_out (value
))
5569 handler
= value_as_address (value
);
5572 fprintf_unfiltered (gdb_stdlog
,
5573 "infrun: exception resume at %lx\n",
5574 (unsigned long) handler
);
5576 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5577 handler
, bp_exception_resume
);
5579 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
5582 bp
->thread
= tp
->num
;
5583 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5588 /* A helper for check_exception_resume that sets an
5589 exception-breakpoint based on a SystemTap probe. */
5592 insert_exception_resume_from_probe (struct thread_info
*tp
,
5593 const struct probe
*probe
,
5594 struct frame_info
*frame
)
5596 struct value
*arg_value
;
5598 struct breakpoint
*bp
;
5600 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
5604 handler
= value_as_address (arg_value
);
5607 fprintf_unfiltered (gdb_stdlog
,
5608 "infrun: exception resume at %s\n",
5609 paddress (get_objfile_arch (probe
->objfile
),
5612 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5613 handler
, bp_exception_resume
);
5614 bp
->thread
= tp
->num
;
5615 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5618 /* This is called when an exception has been intercepted. Check to
5619 see whether the exception's destination is of interest, and if so,
5620 set an exception resume breakpoint there. */
5623 check_exception_resume (struct execution_control_state
*ecs
,
5624 struct frame_info
*frame
)
5626 volatile struct gdb_exception e
;
5627 const struct probe
*probe
;
5628 struct symbol
*func
;
5630 /* First see if this exception unwinding breakpoint was set via a
5631 SystemTap probe point. If so, the probe has two arguments: the
5632 CFA and the HANDLER. We ignore the CFA, extract the handler, and
5633 set a breakpoint there. */
5634 probe
= find_probe_by_pc (get_frame_pc (frame
));
5637 insert_exception_resume_from_probe (ecs
->event_thread
, probe
, frame
);
5641 func
= get_frame_function (frame
);
5645 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5648 struct block_iterator iter
;
5652 /* The exception breakpoint is a thread-specific breakpoint on
5653 the unwinder's debug hook, declared as:
5655 void _Unwind_DebugHook (void *cfa, void *handler);
5657 The CFA argument indicates the frame to which control is
5658 about to be transferred. HANDLER is the destination PC.
5660 We ignore the CFA and set a temporary breakpoint at HANDLER.
5661 This is not extremely efficient but it avoids issues in gdb
5662 with computing the DWARF CFA, and it also works even in weird
5663 cases such as throwing an exception from inside a signal
5666 b
= SYMBOL_BLOCK_VALUE (func
);
5667 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5669 if (!SYMBOL_IS_ARGUMENT (sym
))
5676 insert_exception_resume_breakpoint (ecs
->event_thread
,
5685 stop_stepping (struct execution_control_state
*ecs
)
5688 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
5690 /* Let callers know we don't want to wait for the inferior anymore. */
5691 ecs
->wait_some_more
= 0;
5694 /* This function handles various cases where we need to continue
5695 waiting for the inferior. */
5696 /* (Used to be the keep_going: label in the old wait_for_inferior). */
5699 keep_going (struct execution_control_state
*ecs
)
5701 /* Make sure normal_stop is called if we get a QUIT handled before
5703 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
5705 /* Save the pc before execution, to compare with pc after stop. */
5706 ecs
->event_thread
->prev_pc
5707 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5709 /* If we did not do break;, it means we should keep running the
5710 inferior and not return to debugger. */
5712 if (ecs
->event_thread
->control
.trap_expected
5713 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5715 /* We took a signal (which we are supposed to pass through to
5716 the inferior, else we'd not get here) and we haven't yet
5717 gotten our trap. Simply continue. */
5719 discard_cleanups (old_cleanups
);
5720 resume (currently_stepping (ecs
->event_thread
),
5721 ecs
->event_thread
->suspend
.stop_signal
);
5725 /* Either the trap was not expected, but we are continuing
5726 anyway (the user asked that this signal be passed to the
5729 The signal was SIGTRAP, e.g. it was our signal, but we
5730 decided we should resume from it.
5732 We're going to run this baby now!
5734 Note that insert_breakpoints won't try to re-insert
5735 already inserted breakpoints. Therefore, we don't
5736 care if breakpoints were already inserted, or not. */
5738 if (ecs
->event_thread
->stepping_over_breakpoint
)
5740 struct regcache
*thread_regcache
= get_thread_regcache (ecs
->ptid
);
5742 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
5743 /* Since we can't do a displaced step, we have to remove
5744 the breakpoint while we step it. To keep things
5745 simple, we remove them all. */
5746 remove_breakpoints ();
5750 volatile struct gdb_exception e
;
5752 /* Stop stepping when inserting breakpoints
5754 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5756 insert_breakpoints ();
5760 exception_print (gdb_stderr
, e
);
5761 stop_stepping (ecs
);
5766 ecs
->event_thread
->control
.trap_expected
5767 = ecs
->event_thread
->stepping_over_breakpoint
;
5769 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
5770 specifies that such a signal should be delivered to the
5773 Typically, this would occure when a user is debugging a
5774 target monitor on a simulator: the target monitor sets a
5775 breakpoint; the simulator encounters this break-point and
5776 halts the simulation handing control to GDB; GDB, noteing
5777 that the break-point isn't valid, returns control back to the
5778 simulator; the simulator then delivers the hardware
5779 equivalent of a SIGNAL_TRAP to the program being debugged. */
5781 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5782 && !signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
5783 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5785 discard_cleanups (old_cleanups
);
5786 resume (currently_stepping (ecs
->event_thread
),
5787 ecs
->event_thread
->suspend
.stop_signal
);
5790 prepare_to_wait (ecs
);
5793 /* This function normally comes after a resume, before
5794 handle_inferior_event exits. It takes care of any last bits of
5795 housekeeping, and sets the all-important wait_some_more flag. */
5798 prepare_to_wait (struct execution_control_state
*ecs
)
5801 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
5803 /* This is the old end of the while loop. Let everybody know we
5804 want to wait for the inferior some more and get called again
5806 ecs
->wait_some_more
= 1;
5809 /* Several print_*_reason functions to print why the inferior has stopped.
5810 We always print something when the inferior exits, or receives a signal.
5811 The rest of the cases are dealt with later on in normal_stop and
5812 print_it_typical. Ideally there should be a call to one of these
5813 print_*_reason functions functions from handle_inferior_event each time
5814 stop_stepping is called. */
5816 /* Print why the inferior has stopped.
5817 We are done with a step/next/si/ni command, print why the inferior has
5818 stopped. For now print nothing. Print a message only if not in the middle
5819 of doing a "step n" operation for n > 1. */
5822 print_end_stepping_range_reason (void)
5824 if ((!inferior_thread ()->step_multi
5825 || !inferior_thread ()->control
.stop_step
)
5826 && ui_out_is_mi_like_p (current_uiout
))
5827 ui_out_field_string (current_uiout
, "reason",
5828 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
5831 /* The inferior was terminated by a signal, print why it stopped. */
5834 print_signal_exited_reason (enum gdb_signal siggnal
)
5836 struct ui_out
*uiout
= current_uiout
;
5838 annotate_signalled ();
5839 if (ui_out_is_mi_like_p (uiout
))
5841 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
5842 ui_out_text (uiout
, "\nProgram terminated with signal ");
5843 annotate_signal_name ();
5844 ui_out_field_string (uiout
, "signal-name",
5845 gdb_signal_to_name (siggnal
));
5846 annotate_signal_name_end ();
5847 ui_out_text (uiout
, ", ");
5848 annotate_signal_string ();
5849 ui_out_field_string (uiout
, "signal-meaning",
5850 gdb_signal_to_string (siggnal
));
5851 annotate_signal_string_end ();
5852 ui_out_text (uiout
, ".\n");
5853 ui_out_text (uiout
, "The program no longer exists.\n");
5856 /* The inferior program is finished, print why it stopped. */
5859 print_exited_reason (int exitstatus
)
5861 struct inferior
*inf
= current_inferior ();
5862 const char *pidstr
= target_pid_to_str (pid_to_ptid (inf
->pid
));
5863 struct ui_out
*uiout
= current_uiout
;
5865 annotate_exited (exitstatus
);
5868 if (ui_out_is_mi_like_p (uiout
))
5869 ui_out_field_string (uiout
, "reason",
5870 async_reason_lookup (EXEC_ASYNC_EXITED
));
5871 ui_out_text (uiout
, "[Inferior ");
5872 ui_out_text (uiout
, plongest (inf
->num
));
5873 ui_out_text (uiout
, " (");
5874 ui_out_text (uiout
, pidstr
);
5875 ui_out_text (uiout
, ") exited with code ");
5876 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) exitstatus
);
5877 ui_out_text (uiout
, "]\n");
5881 if (ui_out_is_mi_like_p (uiout
))
5883 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
5884 ui_out_text (uiout
, "[Inferior ");
5885 ui_out_text (uiout
, plongest (inf
->num
));
5886 ui_out_text (uiout
, " (");
5887 ui_out_text (uiout
, pidstr
);
5888 ui_out_text (uiout
, ") exited normally]\n");
5890 /* Support the --return-child-result option. */
5891 return_child_result_value
= exitstatus
;
5894 /* Signal received, print why the inferior has stopped. The signal table
5895 tells us to print about it. */
5898 print_signal_received_reason (enum gdb_signal siggnal
)
5900 struct ui_out
*uiout
= current_uiout
;
5904 if (siggnal
== GDB_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
5906 struct thread_info
*t
= inferior_thread ();
5908 ui_out_text (uiout
, "\n[");
5909 ui_out_field_string (uiout
, "thread-name",
5910 target_pid_to_str (t
->ptid
));
5911 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
5912 ui_out_text (uiout
, " stopped");
5916 ui_out_text (uiout
, "\nProgram received signal ");
5917 annotate_signal_name ();
5918 if (ui_out_is_mi_like_p (uiout
))
5920 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
5921 ui_out_field_string (uiout
, "signal-name",
5922 gdb_signal_to_name (siggnal
));
5923 annotate_signal_name_end ();
5924 ui_out_text (uiout
, ", ");
5925 annotate_signal_string ();
5926 ui_out_field_string (uiout
, "signal-meaning",
5927 gdb_signal_to_string (siggnal
));
5928 annotate_signal_string_end ();
5930 ui_out_text (uiout
, ".\n");
5933 /* Reverse execution: target ran out of history info, print why the inferior
5937 print_no_history_reason (void)
5939 ui_out_text (current_uiout
, "\nNo more reverse-execution history.\n");
5942 /* Here to return control to GDB when the inferior stops for real.
5943 Print appropriate messages, remove breakpoints, give terminal our modes.
5945 STOP_PRINT_FRAME nonzero means print the executing frame
5946 (pc, function, args, file, line number and line text).
5947 BREAKPOINTS_FAILED nonzero means stop was due to error
5948 attempting to insert breakpoints. */
5953 struct target_waitstatus last
;
5955 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
5957 get_last_target_status (&last_ptid
, &last
);
5959 /* If an exception is thrown from this point on, make sure to
5960 propagate GDB's knowledge of the executing state to the
5961 frontend/user running state. A QUIT is an easy exception to see
5962 here, so do this before any filtered output. */
5964 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
5965 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
5966 && last
.kind
!= TARGET_WAITKIND_EXITED
5967 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
5968 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
5970 /* In non-stop mode, we don't want GDB to switch threads behind the
5971 user's back, to avoid races where the user is typing a command to
5972 apply to thread x, but GDB switches to thread y before the user
5973 finishes entering the command. */
5975 /* As with the notification of thread events, we want to delay
5976 notifying the user that we've switched thread context until
5977 the inferior actually stops.
5979 There's no point in saying anything if the inferior has exited.
5980 Note that SIGNALLED here means "exited with a signal", not
5981 "received a signal". */
5983 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
5984 && target_has_execution
5985 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
5986 && last
.kind
!= TARGET_WAITKIND_EXITED
5987 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
5989 target_terminal_ours_for_output ();
5990 printf_filtered (_("[Switching to %s]\n"),
5991 target_pid_to_str (inferior_ptid
));
5992 annotate_thread_changed ();
5993 previous_inferior_ptid
= inferior_ptid
;
5996 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
5998 gdb_assert (sync_execution
|| !target_can_async_p ());
6000 target_terminal_ours_for_output ();
6001 printf_filtered (_("No unwaited-for children left.\n"));
6004 if (!breakpoints_always_inserted_mode () && target_has_execution
)
6006 if (remove_breakpoints ())
6008 target_terminal_ours_for_output ();
6009 printf_filtered (_("Cannot remove breakpoints because "
6010 "program is no longer writable.\nFurther "
6011 "execution is probably impossible.\n"));
6015 /* If an auto-display called a function and that got a signal,
6016 delete that auto-display to avoid an infinite recursion. */
6018 if (stopped_by_random_signal
)
6019 disable_current_display ();
6021 /* Don't print a message if in the middle of doing a "step n"
6022 operation for n > 1 */
6023 if (target_has_execution
6024 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6025 && last
.kind
!= TARGET_WAITKIND_EXITED
6026 && inferior_thread ()->step_multi
6027 && inferior_thread ()->control
.stop_step
)
6030 target_terminal_ours ();
6031 async_enable_stdin ();
6033 /* Set the current source location. This will also happen if we
6034 display the frame below, but the current SAL will be incorrect
6035 during a user hook-stop function. */
6036 if (has_stack_frames () && !stop_stack_dummy
)
6037 set_current_sal_from_frame (get_current_frame (), 1);
6039 /* Let the user/frontend see the threads as stopped. */
6040 do_cleanups (old_chain
);
6042 /* Look up the hook_stop and run it (CLI internally handles problem
6043 of stop_command's pre-hook not existing). */
6045 catch_errors (hook_stop_stub
, stop_command
,
6046 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
6048 if (!has_stack_frames ())
6051 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
6052 || last
.kind
== TARGET_WAITKIND_EXITED
)
6055 /* Select innermost stack frame - i.e., current frame is frame 0,
6056 and current location is based on that.
6057 Don't do this on return from a stack dummy routine,
6058 or if the program has exited. */
6060 if (!stop_stack_dummy
)
6062 select_frame (get_current_frame ());
6064 /* Print current location without a level number, if
6065 we have changed functions or hit a breakpoint.
6066 Print source line if we have one.
6067 bpstat_print() contains the logic deciding in detail
6068 what to print, based on the event(s) that just occurred. */
6070 /* If --batch-silent is enabled then there's no need to print the current
6071 source location, and to try risks causing an error message about
6072 missing source files. */
6073 if (stop_print_frame
&& !batch_silent
)
6077 int do_frame_printing
= 1;
6078 struct thread_info
*tp
= inferior_thread ();
6080 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, last
.kind
);
6084 /* FIXME: cagney/2002-12-01: Given that a frame ID does
6085 (or should) carry around the function and does (or
6086 should) use that when doing a frame comparison. */
6087 if (tp
->control
.stop_step
6088 && frame_id_eq (tp
->control
.step_frame_id
,
6089 get_frame_id (get_current_frame ()))
6090 && step_start_function
== find_pc_function (stop_pc
))
6091 source_flag
= SRC_LINE
; /* Finished step, just
6092 print source line. */
6094 source_flag
= SRC_AND_LOC
; /* Print location and
6097 case PRINT_SRC_AND_LOC
:
6098 source_flag
= SRC_AND_LOC
; /* Print location and
6101 case PRINT_SRC_ONLY
:
6102 source_flag
= SRC_LINE
;
6105 source_flag
= SRC_LINE
; /* something bogus */
6106 do_frame_printing
= 0;
6109 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
6112 /* The behavior of this routine with respect to the source
6114 SRC_LINE: Print only source line
6115 LOCATION: Print only location
6116 SRC_AND_LOC: Print location and source line. */
6117 if (do_frame_printing
)
6118 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
6120 /* Display the auto-display expressions. */
6125 /* Save the function value return registers, if we care.
6126 We might be about to restore their previous contents. */
6127 if (inferior_thread ()->control
.proceed_to_finish
6128 && execution_direction
!= EXEC_REVERSE
)
6130 /* This should not be necessary. */
6132 regcache_xfree (stop_registers
);
6134 /* NB: The copy goes through to the target picking up the value of
6135 all the registers. */
6136 stop_registers
= regcache_dup (get_current_regcache ());
6139 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
6141 /* Pop the empty frame that contains the stack dummy.
6142 This also restores inferior state prior to the call
6143 (struct infcall_suspend_state). */
6144 struct frame_info
*frame
= get_current_frame ();
6146 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
6148 /* frame_pop() calls reinit_frame_cache as the last thing it
6149 does which means there's currently no selected frame. We
6150 don't need to re-establish a selected frame if the dummy call
6151 returns normally, that will be done by
6152 restore_infcall_control_state. However, we do have to handle
6153 the case where the dummy call is returning after being
6154 stopped (e.g. the dummy call previously hit a breakpoint).
6155 We can't know which case we have so just always re-establish
6156 a selected frame here. */
6157 select_frame (get_current_frame ());
6161 annotate_stopped ();
6163 /* Suppress the stop observer if we're in the middle of:
6165 - a step n (n > 1), as there still more steps to be done.
6167 - a "finish" command, as the observer will be called in
6168 finish_command_continuation, so it can include the inferior
6169 function's return value.
6171 - calling an inferior function, as we pretend we inferior didn't
6172 run at all. The return value of the call is handled by the
6173 expression evaluator, through call_function_by_hand. */
6175 if (!target_has_execution
6176 || last
.kind
== TARGET_WAITKIND_SIGNALLED
6177 || last
.kind
== TARGET_WAITKIND_EXITED
6178 || last
.kind
== TARGET_WAITKIND_NO_RESUMED
6179 || (!(inferior_thread ()->step_multi
6180 && inferior_thread ()->control
.stop_step
)
6181 && !(inferior_thread ()->control
.stop_bpstat
6182 && inferior_thread ()->control
.proceed_to_finish
)
6183 && !inferior_thread ()->control
.in_infcall
))
6185 if (!ptid_equal (inferior_ptid
, null_ptid
))
6186 observer_notify_normal_stop (inferior_thread ()->control
.stop_bpstat
,
6189 observer_notify_normal_stop (NULL
, stop_print_frame
);
6192 if (target_has_execution
)
6194 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6195 && last
.kind
!= TARGET_WAITKIND_EXITED
)
6196 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6197 Delete any breakpoint that is to be deleted at the next stop. */
6198 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
6201 /* Try to get rid of automatically added inferiors that are no
6202 longer needed. Keeping those around slows down things linearly.
6203 Note that this never removes the current inferior. */
6208 hook_stop_stub (void *cmd
)
6210 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
6215 signal_stop_state (int signo
)
6217 return signal_stop
[signo
];
6221 signal_print_state (int signo
)
6223 return signal_print
[signo
];
6227 signal_pass_state (int signo
)
6229 return signal_program
[signo
];
6233 signal_cache_update (int signo
)
6237 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
6238 signal_cache_update (signo
);
6243 signal_pass
[signo
] = (signal_stop
[signo
] == 0
6244 && signal_print
[signo
] == 0
6245 && signal_program
[signo
] == 1
6246 && signal_catch
[signo
] == 0);
6250 signal_stop_update (int signo
, int state
)
6252 int ret
= signal_stop
[signo
];
6254 signal_stop
[signo
] = state
;
6255 signal_cache_update (signo
);
6260 signal_print_update (int signo
, int state
)
6262 int ret
= signal_print
[signo
];
6264 signal_print
[signo
] = state
;
6265 signal_cache_update (signo
);
6270 signal_pass_update (int signo
, int state
)
6272 int ret
= signal_program
[signo
];
6274 signal_program
[signo
] = state
;
6275 signal_cache_update (signo
);
6279 /* Update the global 'signal_catch' from INFO and notify the
6283 signal_catch_update (const unsigned int *info
)
6287 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
6288 signal_catch
[i
] = info
[i
] > 0;
6289 signal_cache_update (-1);
6290 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6294 sig_print_header (void)
6296 printf_filtered (_("Signal Stop\tPrint\tPass "
6297 "to program\tDescription\n"));
6301 sig_print_info (enum gdb_signal oursig
)
6303 const char *name
= gdb_signal_to_name (oursig
);
6304 int name_padding
= 13 - strlen (name
);
6306 if (name_padding
<= 0)
6309 printf_filtered ("%s", name
);
6310 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
6311 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
6312 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
6313 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
6314 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
6317 /* Specify how various signals in the inferior should be handled. */
6320 handle_command (char *args
, int from_tty
)
6323 int digits
, wordlen
;
6324 int sigfirst
, signum
, siglast
;
6325 enum gdb_signal oursig
;
6328 unsigned char *sigs
;
6329 struct cleanup
*old_chain
;
6333 error_no_arg (_("signal to handle"));
6336 /* Allocate and zero an array of flags for which signals to handle. */
6338 nsigs
= (int) GDB_SIGNAL_LAST
;
6339 sigs
= (unsigned char *) alloca (nsigs
);
6340 memset (sigs
, 0, nsigs
);
6342 /* Break the command line up into args. */
6344 argv
= gdb_buildargv (args
);
6345 old_chain
= make_cleanup_freeargv (argv
);
6347 /* Walk through the args, looking for signal oursigs, signal names, and
6348 actions. Signal numbers and signal names may be interspersed with
6349 actions, with the actions being performed for all signals cumulatively
6350 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6352 while (*argv
!= NULL
)
6354 wordlen
= strlen (*argv
);
6355 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
6359 sigfirst
= siglast
= -1;
6361 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
6363 /* Apply action to all signals except those used by the
6364 debugger. Silently skip those. */
6367 siglast
= nsigs
- 1;
6369 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
6371 SET_SIGS (nsigs
, sigs
, signal_stop
);
6372 SET_SIGS (nsigs
, sigs
, signal_print
);
6374 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
6376 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6378 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
6380 SET_SIGS (nsigs
, sigs
, signal_print
);
6382 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
6384 SET_SIGS (nsigs
, sigs
, signal_program
);
6386 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
6388 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6390 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
6392 SET_SIGS (nsigs
, sigs
, signal_program
);
6394 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
6396 UNSET_SIGS (nsigs
, sigs
, signal_print
);
6397 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6399 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
6401 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6403 else if (digits
> 0)
6405 /* It is numeric. The numeric signal refers to our own
6406 internal signal numbering from target.h, not to host/target
6407 signal number. This is a feature; users really should be
6408 using symbolic names anyway, and the common ones like
6409 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6411 sigfirst
= siglast
= (int)
6412 gdb_signal_from_command (atoi (*argv
));
6413 if ((*argv
)[digits
] == '-')
6416 gdb_signal_from_command (atoi ((*argv
) + digits
+ 1));
6418 if (sigfirst
> siglast
)
6420 /* Bet he didn't figure we'd think of this case... */
6428 oursig
= gdb_signal_from_name (*argv
);
6429 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
6431 sigfirst
= siglast
= (int) oursig
;
6435 /* Not a number and not a recognized flag word => complain. */
6436 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
6440 /* If any signal numbers or symbol names were found, set flags for
6441 which signals to apply actions to. */
6443 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
6445 switch ((enum gdb_signal
) signum
)
6447 case GDB_SIGNAL_TRAP
:
6448 case GDB_SIGNAL_INT
:
6449 if (!allsigs
&& !sigs
[signum
])
6451 if (query (_("%s is used by the debugger.\n\
6452 Are you sure you want to change it? "),
6453 gdb_signal_to_name ((enum gdb_signal
) signum
)))
6459 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6460 gdb_flush (gdb_stdout
);
6465 case GDB_SIGNAL_DEFAULT
:
6466 case GDB_SIGNAL_UNKNOWN
:
6467 /* Make sure that "all" doesn't print these. */
6478 for (signum
= 0; signum
< nsigs
; signum
++)
6481 signal_cache_update (-1);
6482 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6483 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
6487 /* Show the results. */
6488 sig_print_header ();
6489 for (; signum
< nsigs
; signum
++)
6491 sig_print_info (signum
);
6497 do_cleanups (old_chain
);
6500 /* Complete the "handle" command. */
6502 static VEC (char_ptr
) *
6503 handle_completer (struct cmd_list_element
*ignore
,
6504 const char *text
, const char *word
)
6506 VEC (char_ptr
) *vec_signals
, *vec_keywords
, *return_val
;
6507 static const char * const keywords
[] =
6521 vec_signals
= signal_completer (ignore
, text
, word
);
6522 vec_keywords
= complete_on_enum (keywords
, word
, word
);
6524 return_val
= VEC_merge (char_ptr
, vec_signals
, vec_keywords
);
6525 VEC_free (char_ptr
, vec_signals
);
6526 VEC_free (char_ptr
, vec_keywords
);
6531 xdb_handle_command (char *args
, int from_tty
)
6534 struct cleanup
*old_chain
;
6537 error_no_arg (_("xdb command"));
6539 /* Break the command line up into args. */
6541 argv
= gdb_buildargv (args
);
6542 old_chain
= make_cleanup_freeargv (argv
);
6543 if (argv
[1] != (char *) NULL
)
6548 bufLen
= strlen (argv
[0]) + 20;
6549 argBuf
= (char *) xmalloc (bufLen
);
6553 enum gdb_signal oursig
;
6555 oursig
= gdb_signal_from_name (argv
[0]);
6556 memset (argBuf
, 0, bufLen
);
6557 if (strcmp (argv
[1], "Q") == 0)
6558 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6561 if (strcmp (argv
[1], "s") == 0)
6563 if (!signal_stop
[oursig
])
6564 sprintf (argBuf
, "%s %s", argv
[0], "stop");
6566 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
6568 else if (strcmp (argv
[1], "i") == 0)
6570 if (!signal_program
[oursig
])
6571 sprintf (argBuf
, "%s %s", argv
[0], "pass");
6573 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
6575 else if (strcmp (argv
[1], "r") == 0)
6577 if (!signal_print
[oursig
])
6578 sprintf (argBuf
, "%s %s", argv
[0], "print");
6580 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6586 handle_command (argBuf
, from_tty
);
6588 printf_filtered (_("Invalid signal handling flag.\n"));
6593 do_cleanups (old_chain
);
6597 gdb_signal_from_command (int num
)
6599 if (num
>= 1 && num
<= 15)
6600 return (enum gdb_signal
) num
;
6601 error (_("Only signals 1-15 are valid as numeric signals.\n\
6602 Use \"info signals\" for a list of symbolic signals."));
6605 /* Print current contents of the tables set by the handle command.
6606 It is possible we should just be printing signals actually used
6607 by the current target (but for things to work right when switching
6608 targets, all signals should be in the signal tables). */
6611 signals_info (char *signum_exp
, int from_tty
)
6613 enum gdb_signal oursig
;
6615 sig_print_header ();
6619 /* First see if this is a symbol name. */
6620 oursig
= gdb_signal_from_name (signum_exp
);
6621 if (oursig
== GDB_SIGNAL_UNKNOWN
)
6623 /* No, try numeric. */
6625 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
6627 sig_print_info (oursig
);
6631 printf_filtered ("\n");
6632 /* These ugly casts brought to you by the native VAX compiler. */
6633 for (oursig
= GDB_SIGNAL_FIRST
;
6634 (int) oursig
< (int) GDB_SIGNAL_LAST
;
6635 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
6639 if (oursig
!= GDB_SIGNAL_UNKNOWN
6640 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
6641 sig_print_info (oursig
);
6644 printf_filtered (_("\nUse the \"handle\" command "
6645 "to change these tables.\n"));
6648 /* Check if it makes sense to read $_siginfo from the current thread
6649 at this point. If not, throw an error. */
6652 validate_siginfo_access (void)
6654 /* No current inferior, no siginfo. */
6655 if (ptid_equal (inferior_ptid
, null_ptid
))
6656 error (_("No thread selected."));
6658 /* Don't try to read from a dead thread. */
6659 if (is_exited (inferior_ptid
))
6660 error (_("The current thread has terminated"));
6662 /* ... or from a spinning thread. */
6663 if (is_running (inferior_ptid
))
6664 error (_("Selected thread is running."));
6667 /* The $_siginfo convenience variable is a bit special. We don't know
6668 for sure the type of the value until we actually have a chance to
6669 fetch the data. The type can change depending on gdbarch, so it is
6670 also dependent on which thread you have selected.
6672 1. making $_siginfo be an internalvar that creates a new value on
6675 2. making the value of $_siginfo be an lval_computed value. */
6677 /* This function implements the lval_computed support for reading a
6681 siginfo_value_read (struct value
*v
)
6683 LONGEST transferred
;
6685 validate_siginfo_access ();
6688 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
6690 value_contents_all_raw (v
),
6692 TYPE_LENGTH (value_type (v
)));
6694 if (transferred
!= TYPE_LENGTH (value_type (v
)))
6695 error (_("Unable to read siginfo"));
6698 /* This function implements the lval_computed support for writing a
6702 siginfo_value_write (struct value
*v
, struct value
*fromval
)
6704 LONGEST transferred
;
6706 validate_siginfo_access ();
6708 transferred
= target_write (¤t_target
,
6709 TARGET_OBJECT_SIGNAL_INFO
,
6711 value_contents_all_raw (fromval
),
6713 TYPE_LENGTH (value_type (fromval
)));
6715 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
6716 error (_("Unable to write siginfo"));
6719 static const struct lval_funcs siginfo_value_funcs
=
6725 /* Return a new value with the correct type for the siginfo object of
6726 the current thread using architecture GDBARCH. Return a void value
6727 if there's no object available. */
6729 static struct value
*
6730 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
6733 if (target_has_stack
6734 && !ptid_equal (inferior_ptid
, null_ptid
)
6735 && gdbarch_get_siginfo_type_p (gdbarch
))
6737 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6739 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
6742 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
6746 /* infcall_suspend_state contains state about the program itself like its
6747 registers and any signal it received when it last stopped.
6748 This state must be restored regardless of how the inferior function call
6749 ends (either successfully, or after it hits a breakpoint or signal)
6750 if the program is to properly continue where it left off. */
6752 struct infcall_suspend_state
6754 struct thread_suspend_state thread_suspend
;
6755 #if 0 /* Currently unused and empty structures are not valid C. */
6756 struct inferior_suspend_state inferior_suspend
;
6761 struct regcache
*registers
;
6763 /* Format of SIGINFO_DATA or NULL if it is not present. */
6764 struct gdbarch
*siginfo_gdbarch
;
6766 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6767 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6768 content would be invalid. */
6769 gdb_byte
*siginfo_data
;
6772 struct infcall_suspend_state
*
6773 save_infcall_suspend_state (void)
6775 struct infcall_suspend_state
*inf_state
;
6776 struct thread_info
*tp
= inferior_thread ();
6778 struct inferior
*inf
= current_inferior ();
6780 struct regcache
*regcache
= get_current_regcache ();
6781 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6782 gdb_byte
*siginfo_data
= NULL
;
6784 if (gdbarch_get_siginfo_type_p (gdbarch
))
6786 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6787 size_t len
= TYPE_LENGTH (type
);
6788 struct cleanup
*back_to
;
6790 siginfo_data
= xmalloc (len
);
6791 back_to
= make_cleanup (xfree
, siginfo_data
);
6793 if (target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6794 siginfo_data
, 0, len
) == len
)
6795 discard_cleanups (back_to
);
6798 /* Errors ignored. */
6799 do_cleanups (back_to
);
6800 siginfo_data
= NULL
;
6804 inf_state
= XZALLOC (struct infcall_suspend_state
);
6808 inf_state
->siginfo_gdbarch
= gdbarch
;
6809 inf_state
->siginfo_data
= siginfo_data
;
6812 inf_state
->thread_suspend
= tp
->suspend
;
6813 #if 0 /* Currently unused and empty structures are not valid C. */
6814 inf_state
->inferior_suspend
= inf
->suspend
;
6817 /* run_inferior_call will not use the signal due to its `proceed' call with
6818 GDB_SIGNAL_0 anyway. */
6819 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6821 inf_state
->stop_pc
= stop_pc
;
6823 inf_state
->registers
= regcache_dup (regcache
);
6828 /* Restore inferior session state to INF_STATE. */
6831 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6833 struct thread_info
*tp
= inferior_thread ();
6835 struct inferior
*inf
= current_inferior ();
6837 struct regcache
*regcache
= get_current_regcache ();
6838 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6840 tp
->suspend
= inf_state
->thread_suspend
;
6841 #if 0 /* Currently unused and empty structures are not valid C. */
6842 inf
->suspend
= inf_state
->inferior_suspend
;
6845 stop_pc
= inf_state
->stop_pc
;
6847 if (inf_state
->siginfo_gdbarch
== gdbarch
)
6849 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6851 /* Errors ignored. */
6852 target_write (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6853 inf_state
->siginfo_data
, 0, TYPE_LENGTH (type
));
6856 /* The inferior can be gone if the user types "print exit(0)"
6857 (and perhaps other times). */
6858 if (target_has_execution
)
6859 /* NB: The register write goes through to the target. */
6860 regcache_cpy (regcache
, inf_state
->registers
);
6862 discard_infcall_suspend_state (inf_state
);
6866 do_restore_infcall_suspend_state_cleanup (void *state
)
6868 restore_infcall_suspend_state (state
);
6872 make_cleanup_restore_infcall_suspend_state
6873 (struct infcall_suspend_state
*inf_state
)
6875 return make_cleanup (do_restore_infcall_suspend_state_cleanup
, inf_state
);
6879 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6881 regcache_xfree (inf_state
->registers
);
6882 xfree (inf_state
->siginfo_data
);
6887 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
6889 return inf_state
->registers
;
6892 /* infcall_control_state contains state regarding gdb's control of the
6893 inferior itself like stepping control. It also contains session state like
6894 the user's currently selected frame. */
6896 struct infcall_control_state
6898 struct thread_control_state thread_control
;
6899 struct inferior_control_state inferior_control
;
6902 enum stop_stack_kind stop_stack_dummy
;
6903 int stopped_by_random_signal
;
6904 int stop_after_trap
;
6906 /* ID if the selected frame when the inferior function call was made. */
6907 struct frame_id selected_frame_id
;
6910 /* Save all of the information associated with the inferior<==>gdb
6913 struct infcall_control_state
*
6914 save_infcall_control_state (void)
6916 struct infcall_control_state
*inf_status
= xmalloc (sizeof (*inf_status
));
6917 struct thread_info
*tp
= inferior_thread ();
6918 struct inferior
*inf
= current_inferior ();
6920 inf_status
->thread_control
= tp
->control
;
6921 inf_status
->inferior_control
= inf
->control
;
6923 tp
->control
.step_resume_breakpoint
= NULL
;
6924 tp
->control
.exception_resume_breakpoint
= NULL
;
6926 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6927 chain. If caller's caller is walking the chain, they'll be happier if we
6928 hand them back the original chain when restore_infcall_control_state is
6930 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
6933 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
6934 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
6935 inf_status
->stop_after_trap
= stop_after_trap
;
6937 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
6943 restore_selected_frame (void *args
)
6945 struct frame_id
*fid
= (struct frame_id
*) args
;
6946 struct frame_info
*frame
;
6948 frame
= frame_find_by_id (*fid
);
6950 /* If inf_status->selected_frame_id is NULL, there was no previously
6954 warning (_("Unable to restore previously selected frame."));
6958 select_frame (frame
);
6963 /* Restore inferior session state to INF_STATUS. */
6966 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
6968 struct thread_info
*tp
= inferior_thread ();
6969 struct inferior
*inf
= current_inferior ();
6971 if (tp
->control
.step_resume_breakpoint
)
6972 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
6974 if (tp
->control
.exception_resume_breakpoint
)
6975 tp
->control
.exception_resume_breakpoint
->disposition
6976 = disp_del_at_next_stop
;
6978 /* Handle the bpstat_copy of the chain. */
6979 bpstat_clear (&tp
->control
.stop_bpstat
);
6981 tp
->control
= inf_status
->thread_control
;
6982 inf
->control
= inf_status
->inferior_control
;
6985 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
6986 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
6987 stop_after_trap
= inf_status
->stop_after_trap
;
6989 if (target_has_stack
)
6991 /* The point of catch_errors is that if the stack is clobbered,
6992 walking the stack might encounter a garbage pointer and
6993 error() trying to dereference it. */
6995 (restore_selected_frame
, &inf_status
->selected_frame_id
,
6996 "Unable to restore previously selected frame:\n",
6997 RETURN_MASK_ERROR
) == 0)
6998 /* Error in restoring the selected frame. Select the innermost
7000 select_frame (get_current_frame ());
7007 do_restore_infcall_control_state_cleanup (void *sts
)
7009 restore_infcall_control_state (sts
);
7013 make_cleanup_restore_infcall_control_state
7014 (struct infcall_control_state
*inf_status
)
7016 return make_cleanup (do_restore_infcall_control_state_cleanup
, inf_status
);
7020 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
7022 if (inf_status
->thread_control
.step_resume_breakpoint
)
7023 inf_status
->thread_control
.step_resume_breakpoint
->disposition
7024 = disp_del_at_next_stop
;
7026 if (inf_status
->thread_control
.exception_resume_breakpoint
)
7027 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
7028 = disp_del_at_next_stop
;
7030 /* See save_infcall_control_state for info on stop_bpstat. */
7031 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
7037 ptid_match (ptid_t ptid
, ptid_t filter
)
7039 if (ptid_equal (filter
, minus_one_ptid
))
7041 if (ptid_is_pid (filter
)
7042 && ptid_get_pid (ptid
) == ptid_get_pid (filter
))
7044 else if (ptid_equal (ptid
, filter
))
7050 /* restore_inferior_ptid() will be used by the cleanup machinery
7051 to restore the inferior_ptid value saved in a call to
7052 save_inferior_ptid(). */
7055 restore_inferior_ptid (void *arg
)
7057 ptid_t
*saved_ptid_ptr
= arg
;
7059 inferior_ptid
= *saved_ptid_ptr
;
7063 /* Save the value of inferior_ptid so that it may be restored by a
7064 later call to do_cleanups(). Returns the struct cleanup pointer
7065 needed for later doing the cleanup. */
7068 save_inferior_ptid (void)
7070 ptid_t
*saved_ptid_ptr
;
7072 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
7073 *saved_ptid_ptr
= inferior_ptid
;
7074 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
7078 /* User interface for reverse debugging:
7079 Set exec-direction / show exec-direction commands
7080 (returns error unless target implements to_set_exec_direction method). */
7082 int execution_direction
= EXEC_FORWARD
;
7083 static const char exec_forward
[] = "forward";
7084 static const char exec_reverse
[] = "reverse";
7085 static const char *exec_direction
= exec_forward
;
7086 static const char *const exec_direction_names
[] = {
7093 set_exec_direction_func (char *args
, int from_tty
,
7094 struct cmd_list_element
*cmd
)
7096 if (target_can_execute_reverse
)
7098 if (!strcmp (exec_direction
, exec_forward
))
7099 execution_direction
= EXEC_FORWARD
;
7100 else if (!strcmp (exec_direction
, exec_reverse
))
7101 execution_direction
= EXEC_REVERSE
;
7105 exec_direction
= exec_forward
;
7106 error (_("Target does not support this operation."));
7111 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
7112 struct cmd_list_element
*cmd
, const char *value
)
7114 switch (execution_direction
) {
7116 fprintf_filtered (out
, _("Forward.\n"));
7119 fprintf_filtered (out
, _("Reverse.\n"));
7122 internal_error (__FILE__
, __LINE__
,
7123 _("bogus execution_direction value: %d"),
7124 (int) execution_direction
);
7128 /* User interface for non-stop mode. */
7133 set_non_stop (char *args
, int from_tty
,
7134 struct cmd_list_element
*c
)
7136 if (target_has_execution
)
7138 non_stop_1
= non_stop
;
7139 error (_("Cannot change this setting while the inferior is running."));
7142 non_stop
= non_stop_1
;
7146 show_non_stop (struct ui_file
*file
, int from_tty
,
7147 struct cmd_list_element
*c
, const char *value
)
7149 fprintf_filtered (file
,
7150 _("Controlling the inferior in non-stop mode is %s.\n"),
7155 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
7156 struct cmd_list_element
*c
, const char *value
)
7158 fprintf_filtered (file
, _("Resuming the execution of threads "
7159 "of all processes is %s.\n"), value
);
7162 /* Implementation of `siginfo' variable. */
7164 static const struct internalvar_funcs siginfo_funcs
=
7172 _initialize_infrun (void)
7176 struct cmd_list_element
*c
;
7178 add_info ("signals", signals_info
, _("\
7179 What debugger does when program gets various signals.\n\
7180 Specify a signal as argument to print info on that signal only."));
7181 add_info_alias ("handle", "signals", 0);
7183 c
= add_com ("handle", class_run
, handle_command
, _("\
7184 Specify how to handle signals.\n\
7185 Usage: handle SIGNAL [ACTIONS]\n\
7186 Args are signals and actions to apply to those signals.\n\
7187 If no actions are specified, the current settings for the specified signals\n\
7188 will be displayed instead.\n\
7190 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7191 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7192 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7193 The special arg \"all\" is recognized to mean all signals except those\n\
7194 used by the debugger, typically SIGTRAP and SIGINT.\n\
7196 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7197 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7198 Stop means reenter debugger if this signal happens (implies print).\n\
7199 Print means print a message if this signal happens.\n\
7200 Pass means let program see this signal; otherwise program doesn't know.\n\
7201 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7202 Pass and Stop may be combined.\n\
7204 Multiple signals may be specified. Signal numbers and signal names\n\
7205 may be interspersed with actions, with the actions being performed for\n\
7206 all signals cumulatively specified."));
7207 set_cmd_completer (c
, handle_completer
);
7211 add_com ("lz", class_info
, signals_info
, _("\
7212 What debugger does when program gets various signals.\n\
7213 Specify a signal as argument to print info on that signal only."));
7214 add_com ("z", class_run
, xdb_handle_command
, _("\
7215 Specify how to handle a signal.\n\
7216 Args are signals and actions to apply to those signals.\n\
7217 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7218 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7219 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7220 The special arg \"all\" is recognized to mean all signals except those\n\
7221 used by the debugger, typically SIGTRAP and SIGINT.\n\
7222 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7223 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7224 nopass), \"Q\" (noprint)\n\
7225 Stop means reenter debugger if this signal happens (implies print).\n\
7226 Print means print a message if this signal happens.\n\
7227 Pass means let program see this signal; otherwise program doesn't know.\n\
7228 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7229 Pass and Stop may be combined."));
7233 stop_command
= add_cmd ("stop", class_obscure
,
7234 not_just_help_class_command
, _("\
7235 There is no `stop' command, but you can set a hook on `stop'.\n\
7236 This allows you to set a list of commands to be run each time execution\n\
7237 of the program stops."), &cmdlist
);
7239 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
7240 Set inferior debugging."), _("\
7241 Show inferior debugging."), _("\
7242 When non-zero, inferior specific debugging is enabled."),
7245 &setdebuglist
, &showdebuglist
);
7247 add_setshow_boolean_cmd ("displaced", class_maintenance
,
7248 &debug_displaced
, _("\
7249 Set displaced stepping debugging."), _("\
7250 Show displaced stepping debugging."), _("\
7251 When non-zero, displaced stepping specific debugging is enabled."),
7253 show_debug_displaced
,
7254 &setdebuglist
, &showdebuglist
);
7256 add_setshow_boolean_cmd ("non-stop", no_class
,
7258 Set whether gdb controls the inferior in non-stop mode."), _("\
7259 Show whether gdb controls the inferior in non-stop mode."), _("\
7260 When debugging a multi-threaded program and this setting is\n\
7261 off (the default, also called all-stop mode), when one thread stops\n\
7262 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7263 all other threads in the program while you interact with the thread of\n\
7264 interest. When you continue or step a thread, you can allow the other\n\
7265 threads to run, or have them remain stopped, but while you inspect any\n\
7266 thread's state, all threads stop.\n\
7268 In non-stop mode, when one thread stops, other threads can continue\n\
7269 to run freely. You'll be able to step each thread independently,\n\
7270 leave it stopped or free to run as needed."),
7276 numsigs
= (int) GDB_SIGNAL_LAST
;
7277 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
7278 signal_print
= (unsigned char *)
7279 xmalloc (sizeof (signal_print
[0]) * numsigs
);
7280 signal_program
= (unsigned char *)
7281 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7282 signal_catch
= (unsigned char *)
7283 xmalloc (sizeof (signal_catch
[0]) * numsigs
);
7284 signal_pass
= (unsigned char *)
7285 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7286 for (i
= 0; i
< numsigs
; i
++)
7289 signal_print
[i
] = 1;
7290 signal_program
[i
] = 1;
7291 signal_catch
[i
] = 0;
7294 /* Signals caused by debugger's own actions
7295 should not be given to the program afterwards. */
7296 signal_program
[GDB_SIGNAL_TRAP
] = 0;
7297 signal_program
[GDB_SIGNAL_INT
] = 0;
7299 /* Signals that are not errors should not normally enter the debugger. */
7300 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
7301 signal_print
[GDB_SIGNAL_ALRM
] = 0;
7302 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
7303 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
7304 signal_stop
[GDB_SIGNAL_PROF
] = 0;
7305 signal_print
[GDB_SIGNAL_PROF
] = 0;
7306 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
7307 signal_print
[GDB_SIGNAL_CHLD
] = 0;
7308 signal_stop
[GDB_SIGNAL_IO
] = 0;
7309 signal_print
[GDB_SIGNAL_IO
] = 0;
7310 signal_stop
[GDB_SIGNAL_POLL
] = 0;
7311 signal_print
[GDB_SIGNAL_POLL
] = 0;
7312 signal_stop
[GDB_SIGNAL_URG
] = 0;
7313 signal_print
[GDB_SIGNAL_URG
] = 0;
7314 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
7315 signal_print
[GDB_SIGNAL_WINCH
] = 0;
7316 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
7317 signal_print
[GDB_SIGNAL_PRIO
] = 0;
7319 /* These signals are used internally by user-level thread
7320 implementations. (See signal(5) on Solaris.) Like the above
7321 signals, a healthy program receives and handles them as part of
7322 its normal operation. */
7323 signal_stop
[GDB_SIGNAL_LWP
] = 0;
7324 signal_print
[GDB_SIGNAL_LWP
] = 0;
7325 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
7326 signal_print
[GDB_SIGNAL_WAITING
] = 0;
7327 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
7328 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
7330 /* Update cached state. */
7331 signal_cache_update (-1);
7333 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
7334 &stop_on_solib_events
, _("\
7335 Set stopping for shared library events."), _("\
7336 Show stopping for shared library events."), _("\
7337 If nonzero, gdb will give control to the user when the dynamic linker\n\
7338 notifies gdb of shared library events. The most common event of interest\n\
7339 to the user would be loading/unloading of a new library."),
7340 set_stop_on_solib_events
,
7341 show_stop_on_solib_events
,
7342 &setlist
, &showlist
);
7344 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
7345 follow_fork_mode_kind_names
,
7346 &follow_fork_mode_string
, _("\
7347 Set debugger response to a program call of fork or vfork."), _("\
7348 Show debugger response to a program call of fork or vfork."), _("\
7349 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7350 parent - the original process is debugged after a fork\n\
7351 child - the new process is debugged after a fork\n\
7352 The unfollowed process will continue to run.\n\
7353 By default, the debugger will follow the parent process."),
7355 show_follow_fork_mode_string
,
7356 &setlist
, &showlist
);
7358 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
7359 follow_exec_mode_names
,
7360 &follow_exec_mode_string
, _("\
7361 Set debugger response to a program call of exec."), _("\
7362 Show debugger response to a program call of exec."), _("\
7363 An exec call replaces the program image of a process.\n\
7365 follow-exec-mode can be:\n\
7367 new - the debugger creates a new inferior and rebinds the process\n\
7368 to this new inferior. The program the process was running before\n\
7369 the exec call can be restarted afterwards by restarting the original\n\
7372 same - the debugger keeps the process bound to the same inferior.\n\
7373 The new executable image replaces the previous executable loaded in\n\
7374 the inferior. Restarting the inferior after the exec call restarts\n\
7375 the executable the process was running after the exec call.\n\
7377 By default, the debugger will use the same inferior."),
7379 show_follow_exec_mode_string
,
7380 &setlist
, &showlist
);
7382 add_setshow_enum_cmd ("scheduler-locking", class_run
,
7383 scheduler_enums
, &scheduler_mode
, _("\
7384 Set mode for locking scheduler during execution."), _("\
7385 Show mode for locking scheduler during execution."), _("\
7386 off == no locking (threads may preempt at any time)\n\
7387 on == full locking (no thread except the current thread may run)\n\
7388 step == scheduler locked during every single-step operation.\n\
7389 In this mode, no other thread may run during a step command.\n\
7390 Other threads may run while stepping over a function call ('next')."),
7391 set_schedlock_func
, /* traps on target vector */
7392 show_scheduler_mode
,
7393 &setlist
, &showlist
);
7395 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
7396 Set mode for resuming threads of all processes."), _("\
7397 Show mode for resuming threads of all processes."), _("\
7398 When on, execution commands (such as 'continue' or 'next') resume all\n\
7399 threads of all processes. When off (which is the default), execution\n\
7400 commands only resume the threads of the current process. The set of\n\
7401 threads that are resumed is further refined by the scheduler-locking\n\
7402 mode (see help set scheduler-locking)."),
7404 show_schedule_multiple
,
7405 &setlist
, &showlist
);
7407 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
7408 Set mode of the step operation."), _("\
7409 Show mode of the step operation."), _("\
7410 When set, doing a step over a function without debug line information\n\
7411 will stop at the first instruction of that function. Otherwise, the\n\
7412 function is skipped and the step command stops at a different source line."),
7414 show_step_stop_if_no_debug
,
7415 &setlist
, &showlist
);
7417 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
7418 &can_use_displaced_stepping
, _("\
7419 Set debugger's willingness to use displaced stepping."), _("\
7420 Show debugger's willingness to use displaced stepping."), _("\
7421 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7422 supported by the target architecture. If off, gdb will not use displaced\n\
7423 stepping to step over breakpoints, even if such is supported by the target\n\
7424 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7425 if the target architecture supports it and non-stop mode is active, but will not\n\
7426 use it in all-stop mode (see help set non-stop)."),
7428 show_can_use_displaced_stepping
,
7429 &setlist
, &showlist
);
7431 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
7432 &exec_direction
, _("Set direction of execution.\n\
7433 Options are 'forward' or 'reverse'."),
7434 _("Show direction of execution (forward/reverse)."),
7435 _("Tells gdb whether to execute forward or backward."),
7436 set_exec_direction_func
, show_exec_direction_func
,
7437 &setlist
, &showlist
);
7439 /* Set/show detach-on-fork: user-settable mode. */
7441 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
7442 Set whether gdb will detach the child of a fork."), _("\
7443 Show whether gdb will detach the child of a fork."), _("\
7444 Tells gdb whether to detach the child of a fork."),
7445 NULL
, NULL
, &setlist
, &showlist
);
7447 /* Set/show disable address space randomization mode. */
7449 add_setshow_boolean_cmd ("disable-randomization", class_support
,
7450 &disable_randomization
, _("\
7451 Set disabling of debuggee's virtual address space randomization."), _("\
7452 Show disabling of debuggee's virtual address space randomization."), _("\
7453 When this mode is on (which is the default), randomization of the virtual\n\
7454 address space is disabled. Standalone programs run with the randomization\n\
7455 enabled by default on some platforms."),
7456 &set_disable_randomization
,
7457 &show_disable_randomization
,
7458 &setlist
, &showlist
);
7460 /* ptid initializations */
7461 inferior_ptid
= null_ptid
;
7462 target_last_wait_ptid
= minus_one_ptid
;
7464 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
7465 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
7466 observer_attach_thread_exit (infrun_thread_thread_exit
);
7467 observer_attach_inferior_exit (infrun_inferior_exit
);
7469 /* Explicitly create without lookup, since that tries to create a
7470 value with a void typed value, and when we get here, gdbarch
7471 isn't initialized yet. At this point, we're quite sure there
7472 isn't another convenience variable of the same name. */
7473 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
7475 add_setshow_boolean_cmd ("observer", no_class
,
7476 &observer_mode_1
, _("\
7477 Set whether gdb controls the inferior in observer mode."), _("\
7478 Show whether gdb controls the inferior in observer mode."), _("\
7479 In observer mode, GDB can get data from the inferior, but not\n\
7480 affect its execution. Registers and memory may not be changed,\n\
7481 breakpoints may not be set, and the program cannot be interrupted\n\