1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2023 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 "displaced-stepping.h"
28 #include "breakpoint.h"
32 #include "target-connection.h"
33 #include "gdbthread.h"
41 #include "observable.h"
46 #include "mi/mi-common.h"
47 #include "event-top.h"
49 #include "record-full.h"
50 #include "inline-frame.h"
52 #include "tracepoint.h"
56 #include "completer.h"
57 #include "target-descriptions.h"
58 #include "target-dcache.h"
61 #include "gdbsupport/event-loop.h"
62 #include "thread-fsm.h"
63 #include "gdbsupport/enum-flags.h"
64 #include "progspace-and-thread.h"
65 #include "gdbsupport/gdb_optional.h"
66 #include "arch-utils.h"
67 #include "gdbsupport/scope-exit.h"
68 #include "gdbsupport/forward-scope-exit.h"
69 #include "gdbsupport/gdb_select.h"
70 #include <unordered_map>
71 #include "async-event.h"
72 #include "gdbsupport/selftest.h"
73 #include "scoped-mock-context.h"
74 #include "test-target.h"
75 #include "gdbsupport/common-debug.h"
76 #include "gdbsupport/buildargv.h"
77 #include "extension.h"
80 /* Prototypes for local functions */
82 static void sig_print_info (enum gdb_signal
);
84 static void sig_print_header (void);
86 static void follow_inferior_reset_breakpoints (void);
88 static bool currently_stepping (struct thread_info
*tp
);
90 static void insert_hp_step_resume_breakpoint_at_frame (frame_info_ptr
);
92 static void insert_step_resume_breakpoint_at_caller (frame_info_ptr
);
94 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
96 static bool maybe_software_singlestep (struct gdbarch
*gdbarch
);
98 static void resume (gdb_signal sig
);
100 static void wait_for_inferior (inferior
*inf
);
102 static void restart_threads (struct thread_info
*event_thread
,
103 inferior
*inf
= nullptr);
105 static bool start_step_over (void);
107 static bool step_over_info_valid_p (void);
109 /* Asynchronous signal handler registered as event loop source for
110 when we have pending events ready to be passed to the core. */
111 static struct async_event_handler
*infrun_async_inferior_event_token
;
113 /* Stores whether infrun_async was previously enabled or disabled.
114 Starts off as -1, indicating "never enabled/disabled". */
115 static int infrun_is_async
= -1;
120 infrun_async (int enable
)
122 if (infrun_is_async
!= enable
)
124 infrun_is_async
= enable
;
126 infrun_debug_printf ("enable=%d", enable
);
129 mark_async_event_handler (infrun_async_inferior_event_token
);
131 clear_async_event_handler (infrun_async_inferior_event_token
);
138 mark_infrun_async_event_handler (void)
140 mark_async_event_handler (infrun_async_inferior_event_token
);
143 /* When set, stop the 'step' command if we enter a function which has
144 no line number information. The normal behavior is that we step
145 over such function. */
146 bool step_stop_if_no_debug
= false;
148 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
149 struct cmd_list_element
*c
, const char *value
)
151 gdb_printf (file
, _("Mode of the step operation is %s.\n"), value
);
154 /* proceed and normal_stop use this to notify the user when the
155 inferior stopped in a different thread than it had been running in.
156 It can also be used to find for which thread normal_stop last
158 static thread_info_ref previous_thread
;
163 update_previous_thread ()
165 if (inferior_ptid
== null_ptid
)
166 previous_thread
= nullptr;
168 previous_thread
= thread_info_ref::new_reference (inferior_thread ());
174 get_previous_thread ()
176 return previous_thread
.get ();
179 /* If set (default for legacy reasons), when following a fork, GDB
180 will detach from one of the fork branches, child or parent.
181 Exactly which branch is detached depends on 'set follow-fork-mode'
184 static bool detach_fork
= true;
186 bool debug_infrun
= false;
188 show_debug_infrun (struct ui_file
*file
, int from_tty
,
189 struct cmd_list_element
*c
, const char *value
)
191 gdb_printf (file
, _("Inferior debugging is %s.\n"), value
);
194 /* Support for disabling address space randomization. */
196 bool disable_randomization
= true;
199 show_disable_randomization (struct ui_file
*file
, int from_tty
,
200 struct cmd_list_element
*c
, const char *value
)
202 if (target_supports_disable_randomization ())
204 _("Disabling randomization of debuggee's "
205 "virtual address space is %s.\n"),
208 gdb_puts (_("Disabling randomization of debuggee's "
209 "virtual address space is unsupported on\n"
210 "this platform.\n"), file
);
214 set_disable_randomization (const char *args
, int from_tty
,
215 struct cmd_list_element
*c
)
217 if (!target_supports_disable_randomization ())
218 error (_("Disabling randomization of debuggee's "
219 "virtual address space is unsupported on\n"
223 /* User interface for non-stop mode. */
225 bool non_stop
= false;
226 static bool non_stop_1
= false;
229 set_non_stop (const char *args
, int from_tty
,
230 struct cmd_list_element
*c
)
232 if (target_has_execution ())
234 non_stop_1
= non_stop
;
235 error (_("Cannot change this setting while the inferior is running."));
238 non_stop
= non_stop_1
;
242 show_non_stop (struct ui_file
*file
, int from_tty
,
243 struct cmd_list_element
*c
, const char *value
)
246 _("Controlling the inferior in non-stop mode is %s.\n"),
250 /* "Observer mode" is somewhat like a more extreme version of
251 non-stop, in which all GDB operations that might affect the
252 target's execution have been disabled. */
254 static bool observer_mode
= false;
255 static bool observer_mode_1
= false;
258 set_observer_mode (const char *args
, int from_tty
,
259 struct cmd_list_element
*c
)
261 if (target_has_execution ())
263 observer_mode_1
= observer_mode
;
264 error (_("Cannot change this setting while the inferior is running."));
267 observer_mode
= observer_mode_1
;
269 may_write_registers
= !observer_mode
;
270 may_write_memory
= !observer_mode
;
271 may_insert_breakpoints
= !observer_mode
;
272 may_insert_tracepoints
= !observer_mode
;
273 /* We can insert fast tracepoints in or out of observer mode,
274 but enable them if we're going into this mode. */
276 may_insert_fast_tracepoints
= true;
277 may_stop
= !observer_mode
;
278 update_target_permissions ();
280 /* Going *into* observer mode we must force non-stop, then
281 going out we leave it that way. */
284 pagination_enabled
= false;
285 non_stop
= non_stop_1
= true;
289 gdb_printf (_("Observer mode is now %s.\n"),
290 (observer_mode
? "on" : "off"));
294 show_observer_mode (struct ui_file
*file
, int from_tty
,
295 struct cmd_list_element
*c
, const char *value
)
297 gdb_printf (file
, _("Observer mode is %s.\n"), value
);
300 /* This updates the value of observer mode based on changes in
301 permissions. Note that we are deliberately ignoring the values of
302 may-write-registers and may-write-memory, since the user may have
303 reason to enable these during a session, for instance to turn on a
304 debugging-related global. */
307 update_observer_mode (void)
309 bool newval
= (!may_insert_breakpoints
310 && !may_insert_tracepoints
311 && may_insert_fast_tracepoints
315 /* Let the user know if things change. */
316 if (newval
!= observer_mode
)
317 gdb_printf (_("Observer mode is now %s.\n"),
318 (newval
? "on" : "off"));
320 observer_mode
= observer_mode_1
= newval
;
323 /* Tables of how to react to signals; the user sets them. */
325 static unsigned char signal_stop
[GDB_SIGNAL_LAST
];
326 static unsigned char signal_print
[GDB_SIGNAL_LAST
];
327 static unsigned char signal_program
[GDB_SIGNAL_LAST
];
329 /* Table of signals that are registered with "catch signal". A
330 non-zero entry indicates that the signal is caught by some "catch
332 static unsigned char signal_catch
[GDB_SIGNAL_LAST
];
334 /* Table of signals that the target may silently handle.
335 This is automatically determined from the flags above,
336 and simply cached here. */
337 static unsigned char signal_pass
[GDB_SIGNAL_LAST
];
339 #define SET_SIGS(nsigs,sigs,flags) \
341 int signum = (nsigs); \
342 while (signum-- > 0) \
343 if ((sigs)[signum]) \
344 (flags)[signum] = 1; \
347 #define UNSET_SIGS(nsigs,sigs,flags) \
349 int signum = (nsigs); \
350 while (signum-- > 0) \
351 if ((sigs)[signum]) \
352 (flags)[signum] = 0; \
355 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
356 this function is to avoid exporting `signal_program'. */
359 update_signals_program_target (void)
361 target_program_signals (signal_program
);
364 /* Value to pass to target_resume() to cause all threads to resume. */
366 #define RESUME_ALL minus_one_ptid
368 /* Command list pointer for the "stop" placeholder. */
370 static struct cmd_list_element
*stop_command
;
372 /* Nonzero if we want to give control to the user when we're notified
373 of shared library events by the dynamic linker. */
374 int stop_on_solib_events
;
376 /* Enable or disable optional shared library event breakpoints
377 as appropriate when the above flag is changed. */
380 set_stop_on_solib_events (const char *args
,
381 int from_tty
, struct cmd_list_element
*c
)
383 update_solib_breakpoints ();
387 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
388 struct cmd_list_element
*c
, const char *value
)
390 gdb_printf (file
, _("Stopping for shared library events is %s.\n"),
394 /* True after stop if current stack frame should be printed. */
396 static bool stop_print_frame
;
398 /* This is a cached copy of the target/ptid/waitstatus of the last
399 event returned by target_wait().
400 This information is returned by get_last_target_status(). */
401 static process_stratum_target
*target_last_proc_target
;
402 static ptid_t target_last_wait_ptid
;
403 static struct target_waitstatus target_last_waitstatus
;
405 void init_thread_stepping_state (struct thread_info
*tss
);
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
)
422 _("Debugger response to a program "
423 "call of fork or vfork is \"%s\".\n"),
428 /* Handle changes to the inferior list based on the type of fork,
429 which process is being followed, and whether the other process
430 should be detached. On entry inferior_ptid must be the ptid of
431 the fork parent. At return inferior_ptid is the ptid of the
432 followed inferior. */
435 follow_fork_inferior (bool follow_child
, bool detach_fork
)
437 target_waitkind fork_kind
= inferior_thread ()->pending_follow
.kind ();
438 gdb_assert (fork_kind
== TARGET_WAITKIND_FORKED
439 || fork_kind
== TARGET_WAITKIND_VFORKED
);
440 bool has_vforked
= fork_kind
== TARGET_WAITKIND_VFORKED
;
441 ptid_t parent_ptid
= inferior_ptid
;
442 ptid_t child_ptid
= inferior_thread ()->pending_follow
.child_ptid ();
445 && !non_stop
/* Non-stop always resumes both branches. */
446 && current_ui
->prompt_state
== PROMPT_BLOCKED
447 && !(follow_child
|| detach_fork
|| sched_multi
))
449 /* The parent stays blocked inside the vfork syscall until the
450 child execs or exits. If we don't let the child run, then
451 the parent stays blocked. If we're telling the parent to run
452 in the foreground, the user will not be able to ctrl-c to get
453 back the terminal, effectively hanging the debug session. */
454 gdb_printf (gdb_stderr
, _("\
455 Can not resume the parent process over vfork in the foreground while\n\
456 holding the child stopped. Try \"set detach-on-fork\" or \
457 \"set schedule-multiple\".\n"));
461 inferior
*parent_inf
= current_inferior ();
462 inferior
*child_inf
= nullptr;
464 gdb_assert (parent_inf
->thread_waiting_for_vfork_done
== nullptr);
468 /* Detach new forked process? */
471 /* Before detaching from the child, remove all breakpoints
472 from it. If we forked, then this has already been taken
473 care of by infrun.c. If we vforked however, any
474 breakpoint inserted in the parent is visible in the
475 child, even those added while stopped in a vfork
476 catchpoint. This will remove the breakpoints from the
477 parent also, but they'll be reinserted below. */
480 /* Keep breakpoints list in sync. */
481 remove_breakpoints_inf (current_inferior ());
484 if (print_inferior_events
)
486 /* Ensure that we have a process ptid. */
487 ptid_t process_ptid
= ptid_t (child_ptid
.pid ());
489 target_terminal::ours_for_output ();
490 gdb_printf (_("[Detaching after %s from child %s]\n"),
491 has_vforked
? "vfork" : "fork",
492 target_pid_to_str (process_ptid
).c_str ());
497 /* Add process to GDB's tables. */
498 child_inf
= add_inferior (child_ptid
.pid ());
500 child_inf
->attach_flag
= parent_inf
->attach_flag
;
501 copy_terminal_info (child_inf
, parent_inf
);
502 child_inf
->gdbarch
= parent_inf
->gdbarch
;
503 child_inf
->tdesc_info
= parent_inf
->tdesc_info
;
505 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
507 /* If this is a vfork child, then the address-space is
508 shared with the parent. */
511 child_inf
->pspace
= parent_inf
->pspace
;
512 child_inf
->aspace
= parent_inf
->aspace
;
514 exec_on_vfork (child_inf
);
516 /* The parent will be frozen until the child is done
517 with the shared region. Keep track of the
519 child_inf
->vfork_parent
= parent_inf
;
520 child_inf
->pending_detach
= false;
521 parent_inf
->vfork_child
= child_inf
;
522 parent_inf
->pending_detach
= false;
526 child_inf
->aspace
= new address_space ();
527 child_inf
->pspace
= new program_space (child_inf
->aspace
);
528 child_inf
->removable
= true;
529 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
535 /* If we detached from the child, then we have to be careful
536 to not insert breakpoints in the parent until the child
537 is done with the shared memory region. However, if we're
538 staying attached to the child, then we can and should
539 insert breakpoints, so that we can debug it. A
540 subsequent child exec or exit is enough to know when does
541 the child stops using the parent's address space. */
542 parent_inf
->thread_waiting_for_vfork_done
543 = detach_fork
? inferior_thread () : nullptr;
544 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
549 /* Follow the child. */
551 if (print_inferior_events
)
553 std::string parent_pid
= target_pid_to_str (parent_ptid
);
554 std::string child_pid
= target_pid_to_str (child_ptid
);
556 target_terminal::ours_for_output ();
557 gdb_printf (_("[Attaching after %s %s to child %s]\n"),
559 has_vforked
? "vfork" : "fork",
563 /* Add the new inferior first, so that the target_detach below
564 doesn't unpush the target. */
566 child_inf
= add_inferior (child_ptid
.pid ());
568 child_inf
->attach_flag
= parent_inf
->attach_flag
;
569 copy_terminal_info (child_inf
, parent_inf
);
570 child_inf
->gdbarch
= parent_inf
->gdbarch
;
571 child_inf
->tdesc_info
= parent_inf
->tdesc_info
;
575 /* If this is a vfork child, then the address-space is shared
577 child_inf
->aspace
= parent_inf
->aspace
;
578 child_inf
->pspace
= parent_inf
->pspace
;
580 exec_on_vfork (child_inf
);
582 else if (detach_fork
)
584 /* We follow the child and detach from the parent: move the parent's
585 program space to the child. This simplifies some things, like
586 doing "next" over fork() and landing on the expected line in the
587 child (note, that is broken with "set detach-on-fork off").
589 Before assigning brand new spaces for the parent, remove
590 breakpoints from it: because the new pspace won't match
591 currently inserted locations, the normal detach procedure
592 wouldn't remove them, and we would leave them inserted when
594 remove_breakpoints_inf (parent_inf
);
596 child_inf
->aspace
= parent_inf
->aspace
;
597 child_inf
->pspace
= parent_inf
->pspace
;
598 parent_inf
->aspace
= new address_space ();
599 parent_inf
->pspace
= new program_space (parent_inf
->aspace
);
600 clone_program_space (parent_inf
->pspace
, child_inf
->pspace
);
602 /* The parent inferior is still the current one, so keep things
604 set_current_program_space (parent_inf
->pspace
);
608 child_inf
->aspace
= new address_space ();
609 child_inf
->pspace
= new program_space (child_inf
->aspace
);
610 child_inf
->removable
= true;
611 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
612 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
616 gdb_assert (current_inferior () == parent_inf
);
618 /* If we are setting up an inferior for the child, target_follow_fork is
619 responsible for pushing the appropriate targets on the new inferior's
620 target stack and adding the initial thread (with ptid CHILD_PTID).
622 If we are not setting up an inferior for the child (because following
623 the parent and detach_fork is true), it is responsible for detaching
625 target_follow_fork (child_inf
, child_ptid
, fork_kind
, follow_child
,
628 gdb::observers::inferior_forked
.notify (parent_inf
, child_inf
, fork_kind
);
630 /* target_follow_fork must leave the parent as the current inferior. If we
631 want to follow the child, we make it the current one below. */
632 gdb_assert (current_inferior () == parent_inf
);
634 /* If there is a child inferior, target_follow_fork must have created a thread
636 if (child_inf
!= nullptr)
637 gdb_assert (!child_inf
->thread_list
.empty ());
639 /* Clear the parent thread's pending follow field. Do this before calling
640 target_detach, so that the target can differentiate the two following
643 - We continue past a fork with "follow-fork-mode == child" &&
644 "detach-on-fork on", and therefore detach the parent. In that
645 case the target should not detach the fork child.
646 - We run to a fork catchpoint and the user types "detach". In that
647 case, the target should detach the fork child in addition to the
650 The former case will have pending_follow cleared, the later will have
651 pending_follow set. */
652 thread_info
*parent_thread
= parent_inf
->find_thread (parent_ptid
);
653 gdb_assert (parent_thread
!= nullptr);
654 parent_thread
->pending_follow
.set_spurious ();
656 /* Detach the parent if needed. */
659 /* If we're vforking, we want to hold on to the parent until
660 the child exits or execs. At child exec or exit time we
661 can remove the old breakpoints from the parent and detach
662 or resume debugging it. Otherwise, detach the parent now;
663 we'll want to reuse it's program/address spaces, but we
664 can't set them to the child before removing breakpoints
665 from the parent, otherwise, the breakpoints module could
666 decide to remove breakpoints from the wrong process (since
667 they'd be assigned to the same address space). */
671 gdb_assert (child_inf
->vfork_parent
== nullptr);
672 gdb_assert (parent_inf
->vfork_child
== nullptr);
673 child_inf
->vfork_parent
= parent_inf
;
674 child_inf
->pending_detach
= false;
675 parent_inf
->vfork_child
= child_inf
;
676 parent_inf
->pending_detach
= detach_fork
;
678 else if (detach_fork
)
680 if (print_inferior_events
)
682 /* Ensure that we have a process ptid. */
683 ptid_t process_ptid
= ptid_t (parent_ptid
.pid ());
685 target_terminal::ours_for_output ();
686 gdb_printf (_("[Detaching after fork from "
688 target_pid_to_str (process_ptid
).c_str ());
691 target_detach (parent_inf
, 0);
695 /* If we ended up creating a new inferior, call post_create_inferior to inform
696 the various subcomponents. */
697 if (child_inf
!= nullptr)
699 /* If FOLLOW_CHILD, we leave CHILD_INF as the current inferior
700 (do not restore the parent as the current inferior). */
701 gdb::optional
<scoped_restore_current_thread
> maybe_restore
;
704 maybe_restore
.emplace ();
706 switch_to_thread (*child_inf
->threads ().begin ());
707 post_create_inferior (0);
713 /* Set the last target status as TP having stopped. */
716 set_last_target_status_stopped (thread_info
*tp
)
718 set_last_target_status (tp
->inf
->process_target (), tp
->ptid
,
719 target_waitstatus
{}.set_stopped (GDB_SIGNAL_0
));
722 /* Tell the target to follow the fork we're stopped at. Returns true
723 if the inferior should be resumed; false, if the target for some
724 reason decided it's best not to resume. */
729 bool follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
730 bool should_resume
= true;
732 /* Copy user stepping state to the new inferior thread. FIXME: the
733 followed fork child thread should have a copy of most of the
734 parent thread structure's run control related fields, not just these.
735 Initialized to avoid "may be used uninitialized" warnings from gcc. */
736 struct breakpoint
*step_resume_breakpoint
= nullptr;
737 struct breakpoint
*exception_resume_breakpoint
= nullptr;
738 CORE_ADDR step_range_start
= 0;
739 CORE_ADDR step_range_end
= 0;
740 int current_line
= 0;
741 symtab
*current_symtab
= nullptr;
742 struct frame_id step_frame_id
= { 0 };
746 thread_info
*cur_thr
= inferior_thread ();
749 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
750 process_stratum_target
*resume_target
751 = user_visible_resume_target (resume_ptid
);
753 /* Check if there's a thread that we're about to resume, other
754 than the current, with an unfollowed fork/vfork. If so,
755 switch back to it, to tell the target to follow it (in either
756 direction). We'll afterwards refuse to resume, and inform
757 the user what happened. */
758 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
764 /* follow_fork_inferior clears tp->pending_follow, and below
765 we'll need the value after the follow_fork_inferior
767 target_waitkind kind
= tp
->pending_follow
.kind ();
769 if (kind
!= TARGET_WAITKIND_SPURIOUS
)
771 infrun_debug_printf ("need to follow-fork [%s] first",
772 tp
->ptid
.to_string ().c_str ());
774 switch_to_thread (tp
);
776 /* Set up inferior(s) as specified by the caller, and
777 tell the target to do whatever is necessary to follow
778 either parent or child. */
781 /* The thread that started the execution command
782 won't exist in the child. Abort the command and
783 immediately stop in this thread, in the child,
785 should_resume
= false;
789 /* Following the parent, so let the thread fork its
790 child freely, it won't influence the current
791 execution command. */
792 if (follow_fork_inferior (follow_child
, detach_fork
))
794 /* Target refused to follow, or there's some
795 other reason we shouldn't resume. */
796 switch_to_thread (cur_thr
);
797 set_last_target_status_stopped (cur_thr
);
801 /* If we're following a vfork, when we need to leave
802 the just-forked thread as selected, as we need to
803 solo-resume it to collect the VFORK_DONE event.
804 If we're following a fork, however, switch back
805 to the original thread that we continue stepping
807 if (kind
!= TARGET_WAITKIND_VFORKED
)
809 gdb_assert (kind
== TARGET_WAITKIND_FORKED
);
810 switch_to_thread (cur_thr
);
819 thread_info
*tp
= inferior_thread ();
821 /* If there were any forks/vforks that were caught and are now to be
822 followed, then do so now. */
823 switch (tp
->pending_follow
.kind ())
825 case TARGET_WAITKIND_FORKED
:
826 case TARGET_WAITKIND_VFORKED
:
828 ptid_t parent
, child
;
829 std::unique_ptr
<struct thread_fsm
> thread_fsm
;
831 /* If the user did a next/step, etc, over a fork call,
832 preserve the stepping state in the fork child. */
833 if (follow_child
&& should_resume
)
835 step_resume_breakpoint
= clone_momentary_breakpoint
836 (tp
->control
.step_resume_breakpoint
);
837 step_range_start
= tp
->control
.step_range_start
;
838 step_range_end
= tp
->control
.step_range_end
;
839 current_line
= tp
->current_line
;
840 current_symtab
= tp
->current_symtab
;
841 step_frame_id
= tp
->control
.step_frame_id
;
842 exception_resume_breakpoint
843 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
844 thread_fsm
= tp
->release_thread_fsm ();
846 /* For now, delete the parent's sr breakpoint, otherwise,
847 parent/child sr breakpoints are considered duplicates,
848 and the child version will not be installed. Remove
849 this when the breakpoints module becomes aware of
850 inferiors and address spaces. */
851 delete_step_resume_breakpoint (tp
);
852 tp
->control
.step_range_start
= 0;
853 tp
->control
.step_range_end
= 0;
854 tp
->control
.step_frame_id
= null_frame_id
;
855 delete_exception_resume_breakpoint (tp
);
858 parent
= inferior_ptid
;
859 child
= tp
->pending_follow
.child_ptid ();
861 /* If handling a vfork, stop all the inferior's threads, they will be
862 restarted when the vfork shared region is complete. */
863 if (tp
->pending_follow
.kind () == TARGET_WAITKIND_VFORKED
864 && target_is_non_stop_p ())
865 stop_all_threads ("handling vfork", tp
->inf
);
867 process_stratum_target
*parent_targ
= tp
->inf
->process_target ();
868 /* Set up inferior(s) as specified by the caller, and tell the
869 target to do whatever is necessary to follow either parent
871 if (follow_fork_inferior (follow_child
, detach_fork
))
873 /* Target refused to follow, or there's some other reason
874 we shouldn't resume. */
879 /* If we followed the child, switch to it... */
882 tp
= parent_targ
->find_thread (child
);
883 switch_to_thread (tp
);
885 /* ... and preserve the stepping state, in case the
886 user was stepping over the fork call. */
889 tp
->control
.step_resume_breakpoint
890 = step_resume_breakpoint
;
891 tp
->control
.step_range_start
= step_range_start
;
892 tp
->control
.step_range_end
= step_range_end
;
893 tp
->current_line
= current_line
;
894 tp
->current_symtab
= current_symtab
;
895 tp
->control
.step_frame_id
= step_frame_id
;
896 tp
->control
.exception_resume_breakpoint
897 = exception_resume_breakpoint
;
898 tp
->set_thread_fsm (std::move (thread_fsm
));
902 /* If we get here, it was because we're trying to
903 resume from a fork catchpoint, but, the user
904 has switched threads away from the thread that
905 forked. In that case, the resume command
906 issued is most likely not applicable to the
907 child, so just warn, and refuse to resume. */
908 warning (_("Not resuming: switched threads "
909 "before following fork child."));
912 /* Reset breakpoints in the child as appropriate. */
913 follow_inferior_reset_breakpoints ();
918 case TARGET_WAITKIND_SPURIOUS
:
919 /* Nothing to follow. */
922 internal_error ("Unexpected pending_follow.kind %d\n",
923 tp
->pending_follow
.kind ());
928 set_last_target_status_stopped (tp
);
929 return should_resume
;
933 follow_inferior_reset_breakpoints (void)
935 struct thread_info
*tp
= inferior_thread ();
937 /* Was there a step_resume breakpoint? (There was if the user
938 did a "next" at the fork() call.) If so, explicitly reset its
939 thread number. Cloned step_resume breakpoints are disabled on
940 creation, so enable it here now that it is associated with the
943 step_resumes are a form of bp that are made to be per-thread.
944 Since we created the step_resume bp when the parent process
945 was being debugged, and now are switching to the child process,
946 from the breakpoint package's viewpoint, that's a switch of
947 "threads". We must update the bp's notion of which thread
948 it is for, or it'll be ignored when it triggers. */
950 if (tp
->control
.step_resume_breakpoint
)
952 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
953 tp
->control
.step_resume_breakpoint
->first_loc ().enabled
= 1;
956 /* Treat exception_resume breakpoints like step_resume breakpoints. */
957 if (tp
->control
.exception_resume_breakpoint
)
959 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
960 tp
->control
.exception_resume_breakpoint
->first_loc ().enabled
= 1;
963 /* Reinsert all breakpoints in the child. The user may have set
964 breakpoints after catching the fork, in which case those
965 were never set in the child, but only in the parent. This makes
966 sure the inserted breakpoints match the breakpoint list. */
968 breakpoint_re_set ();
969 insert_breakpoints ();
972 /* The child has exited or execed: resume THREAD, a thread of the parent,
973 if it was meant to be executing. */
976 proceed_after_vfork_done (thread_info
*thread
)
978 if (thread
->state
== THREAD_RUNNING
979 && !thread
->executing ()
980 && !thread
->stop_requested
981 && thread
->stop_signal () == GDB_SIGNAL_0
)
983 infrun_debug_printf ("resuming vfork parent thread %s",
984 thread
->ptid
.to_string ().c_str ());
986 switch_to_thread (thread
);
987 clear_proceed_status (0);
988 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
992 /* Called whenever we notice an exec or exit event, to handle
993 detaching or resuming a vfork parent. */
996 handle_vfork_child_exec_or_exit (int exec
)
998 struct inferior
*inf
= current_inferior ();
1000 if (inf
->vfork_parent
)
1002 inferior
*resume_parent
= nullptr;
1004 /* This exec or exit marks the end of the shared memory region
1005 between the parent and the child. Break the bonds. */
1006 inferior
*vfork_parent
= inf
->vfork_parent
;
1007 inf
->vfork_parent
->vfork_child
= nullptr;
1008 inf
->vfork_parent
= nullptr;
1010 /* If the user wanted to detach from the parent, now is the
1012 if (vfork_parent
->pending_detach
)
1014 struct program_space
*pspace
;
1015 struct address_space
*aspace
;
1017 /* follow-fork child, detach-on-fork on. */
1019 vfork_parent
->pending_detach
= false;
1021 scoped_restore_current_pspace_and_thread restore_thread
;
1023 /* We're letting loose of the parent. */
1024 thread_info
*tp
= any_live_thread_of_inferior (vfork_parent
);
1025 switch_to_thread (tp
);
1027 /* We're about to detach from the parent, which implicitly
1028 removes breakpoints from its address space. There's a
1029 catch here: we want to reuse the spaces for the child,
1030 but, parent/child are still sharing the pspace at this
1031 point, although the exec in reality makes the kernel give
1032 the child a fresh set of new pages. The problem here is
1033 that the breakpoints module being unaware of this, would
1034 likely chose the child process to write to the parent
1035 address space. Swapping the child temporarily away from
1036 the spaces has the desired effect. Yes, this is "sort
1039 pspace
= inf
->pspace
;
1040 aspace
= inf
->aspace
;
1041 inf
->aspace
= nullptr;
1042 inf
->pspace
= nullptr;
1044 if (print_inferior_events
)
1047 = target_pid_to_str (ptid_t (vfork_parent
->pid
));
1049 target_terminal::ours_for_output ();
1053 gdb_printf (_("[Detaching vfork parent %s "
1054 "after child exec]\n"), pidstr
.c_str ());
1058 gdb_printf (_("[Detaching vfork parent %s "
1059 "after child exit]\n"), pidstr
.c_str ());
1063 target_detach (vfork_parent
, 0);
1066 inf
->pspace
= pspace
;
1067 inf
->aspace
= aspace
;
1071 /* We're staying attached to the parent, so, really give the
1072 child a new address space. */
1073 inf
->pspace
= new program_space (maybe_new_address_space ());
1074 inf
->aspace
= inf
->pspace
->aspace
;
1075 inf
->removable
= true;
1076 set_current_program_space (inf
->pspace
);
1078 resume_parent
= vfork_parent
;
1082 /* If this is a vfork child exiting, then the pspace and
1083 aspaces were shared with the parent. Since we're
1084 reporting the process exit, we'll be mourning all that is
1085 found in the address space, and switching to null_ptid,
1086 preparing to start a new inferior. But, since we don't
1087 want to clobber the parent's address/program spaces, we
1088 go ahead and create a new one for this exiting
1091 /* Switch to no-thread while running clone_program_space, so
1092 that clone_program_space doesn't want to read the
1093 selected frame of a dead process. */
1094 scoped_restore_current_thread restore_thread
;
1095 switch_to_no_thread ();
1097 inf
->pspace
= new program_space (maybe_new_address_space ());
1098 inf
->aspace
= inf
->pspace
->aspace
;
1099 set_current_program_space (inf
->pspace
);
1100 inf
->removable
= true;
1101 inf
->symfile_flags
= SYMFILE_NO_READ
;
1102 clone_program_space (inf
->pspace
, vfork_parent
->pspace
);
1104 resume_parent
= vfork_parent
;
1107 gdb_assert (current_program_space
== inf
->pspace
);
1109 if (non_stop
&& resume_parent
!= nullptr)
1111 /* If the user wanted the parent to be running, let it go
1113 scoped_restore_current_thread restore_thread
;
1115 infrun_debug_printf ("resuming vfork parent process %d",
1116 resume_parent
->pid
);
1118 for (thread_info
*thread
: resume_parent
->threads ())
1119 proceed_after_vfork_done (thread
);
1124 /* Handle TARGET_WAITKIND_VFORK_DONE. */
1127 handle_vfork_done (thread_info
*event_thread
)
1129 /* We only care about this event if inferior::thread_waiting_for_vfork_done is
1130 set, that is if we are waiting for a vfork child not under our control
1131 (because we detached it) to exec or exit.
1133 If an inferior has vforked and we are debugging the child, we don't use
1134 the vfork-done event to get notified about the end of the shared address
1135 space window. We rely instead on the child's exec or exit event, and the
1136 inferior::vfork_{parent,child} fields are used instead. See
1137 handle_vfork_child_exec_or_exit for that. */
1138 if (event_thread
->inf
->thread_waiting_for_vfork_done
== nullptr)
1140 infrun_debug_printf ("not waiting for a vfork-done event");
1144 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1146 /* We stopped all threads (other than the vforking thread) of the inferior in
1147 follow_fork and kept them stopped until now. It should therefore not be
1148 possible for another thread to have reported a vfork during that window.
1149 If THREAD_WAITING_FOR_VFORK_DONE is set, it has to be the same thread whose
1150 vfork-done we are handling right now. */
1151 gdb_assert (event_thread
->inf
->thread_waiting_for_vfork_done
== event_thread
);
1153 event_thread
->inf
->thread_waiting_for_vfork_done
= nullptr;
1154 event_thread
->inf
->pspace
->breakpoints_not_allowed
= 0;
1156 /* On non-stop targets, we stopped all the inferior's threads in follow_fork,
1157 resume them now. On all-stop targets, everything that needs to be resumed
1158 will be when we resume the event thread. */
1159 if (target_is_non_stop_p ())
1161 /* restart_threads and start_step_over may change the current thread, make
1162 sure we leave the event thread as the current thread. */
1163 scoped_restore_current_thread restore_thread
;
1165 insert_breakpoints ();
1168 if (!step_over_info_valid_p ())
1169 restart_threads (event_thread
, event_thread
->inf
);
1173 /* Enum strings for "set|show follow-exec-mode". */
1175 static const char follow_exec_mode_new
[] = "new";
1176 static const char follow_exec_mode_same
[] = "same";
1177 static const char *const follow_exec_mode_names
[] =
1179 follow_exec_mode_new
,
1180 follow_exec_mode_same
,
1184 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1186 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1187 struct cmd_list_element
*c
, const char *value
)
1189 gdb_printf (file
, _("Follow exec mode is \"%s\".\n"), value
);
1192 /* EXEC_FILE_TARGET is assumed to be non-NULL. */
1195 follow_exec (ptid_t ptid
, const char *exec_file_target
)
1197 int pid
= ptid
.pid ();
1198 ptid_t process_ptid
;
1200 /* Switch terminal for any messages produced e.g. by
1201 breakpoint_re_set. */
1202 target_terminal::ours_for_output ();
1204 /* This is an exec event that we actually wish to pay attention to.
1205 Refresh our symbol table to the newly exec'd program, remove any
1206 momentary bp's, etc.
1208 If there are breakpoints, they aren't really inserted now,
1209 since the exec() transformed our inferior into a fresh set
1212 We want to preserve symbolic breakpoints on the list, since
1213 we have hopes that they can be reset after the new a.out's
1214 symbol table is read.
1216 However, any "raw" breakpoints must be removed from the list
1217 (e.g., the solib bp's), since their address is probably invalid
1220 And, we DON'T want to call delete_breakpoints() here, since
1221 that may write the bp's "shadow contents" (the instruction
1222 value that was overwritten with a TRAP instruction). Since
1223 we now have a new a.out, those shadow contents aren't valid. */
1225 mark_breakpoints_out ();
1227 /* The target reports the exec event to the main thread, even if
1228 some other thread does the exec, and even if the main thread was
1229 stopped or already gone. We may still have non-leader threads of
1230 the process on our list. E.g., on targets that don't have thread
1231 exit events (like remote); or on native Linux in non-stop mode if
1232 there were only two threads in the inferior and the non-leader
1233 one is the one that execs (and nothing forces an update of the
1234 thread list up to here). When debugging remotely, it's best to
1235 avoid extra traffic, when possible, so avoid syncing the thread
1236 list with the target, and instead go ahead and delete all threads
1237 of the process but one that reported the event. Note this must
1238 be done before calling update_breakpoints_after_exec, as
1239 otherwise clearing the threads' resources would reference stale
1240 thread breakpoints -- it may have been one of these threads that
1241 stepped across the exec. We could just clear their stepping
1242 states, but as long as we're iterating, might as well delete
1243 them. Deleting them now rather than at the next user-visible
1244 stop provides a nicer sequence of events for user and MI
1246 for (thread_info
*th
: all_threads_safe ())
1247 if (th
->ptid
.pid () == pid
&& th
->ptid
!= ptid
)
1250 /* We also need to clear any left over stale state for the
1251 leader/event thread. E.g., if there was any step-resume
1252 breakpoint or similar, it's gone now. We cannot truly
1253 step-to-next statement through an exec(). */
1254 thread_info
*th
= inferior_thread ();
1255 th
->control
.step_resume_breakpoint
= nullptr;
1256 th
->control
.exception_resume_breakpoint
= nullptr;
1257 th
->control
.single_step_breakpoints
= nullptr;
1258 th
->control
.step_range_start
= 0;
1259 th
->control
.step_range_end
= 0;
1261 /* The user may have had the main thread held stopped in the
1262 previous image (e.g., schedlock on, or non-stop). Release
1264 th
->stop_requested
= 0;
1266 update_breakpoints_after_exec ();
1268 /* What is this a.out's name? */
1269 process_ptid
= ptid_t (pid
);
1270 gdb_printf (_("%s is executing new program: %s\n"),
1271 target_pid_to_str (process_ptid
).c_str (),
1274 /* We've followed the inferior through an exec. Therefore, the
1275 inferior has essentially been killed & reborn. */
1277 breakpoint_init_inferior (inf_execd
);
1279 gdb::unique_xmalloc_ptr
<char> exec_file_host
1280 = exec_file_find (exec_file_target
, nullptr);
1282 /* If we were unable to map the executable target pathname onto a host
1283 pathname, tell the user that. Otherwise GDB's subsequent behavior
1284 is confusing. Maybe it would even be better to stop at this point
1285 so that the user can specify a file manually before continuing. */
1286 if (exec_file_host
== nullptr)
1287 warning (_("Could not load symbols for executable %s.\n"
1288 "Do you need \"set sysroot\"?"),
1291 /* Reset the shared library package. This ensures that we get a
1292 shlib event when the child reaches "_start", at which point the
1293 dld will have had a chance to initialize the child. */
1294 /* Also, loading a symbol file below may trigger symbol lookups, and
1295 we don't want those to be satisfied by the libraries of the
1296 previous incarnation of this process. */
1297 no_shared_libraries (nullptr, 0);
1299 inferior
*execing_inferior
= current_inferior ();
1300 inferior
*following_inferior
;
1302 if (follow_exec_mode_string
== follow_exec_mode_new
)
1304 /* The user wants to keep the old inferior and program spaces
1305 around. Create a new fresh one, and switch to it. */
1307 /* Do exit processing for the original inferior before setting the new
1308 inferior's pid. Having two inferiors with the same pid would confuse
1309 find_inferior_p(t)id. Transfer the terminal state and info from the
1310 old to the new inferior. */
1311 following_inferior
= add_inferior_with_spaces ();
1313 swap_terminal_info (following_inferior
, execing_inferior
);
1314 exit_inferior_silent (execing_inferior
);
1316 following_inferior
->pid
= pid
;
1320 /* follow-exec-mode is "same", we continue execution in the execing
1322 following_inferior
= execing_inferior
;
1324 /* The old description may no longer be fit for the new image.
1325 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1326 old description; we'll read a new one below. No need to do
1327 this on "follow-exec-mode new", as the old inferior stays
1328 around (its description is later cleared/refetched on
1330 target_clear_description ();
1333 target_follow_exec (following_inferior
, ptid
, exec_file_target
);
1335 gdb_assert (current_inferior () == following_inferior
);
1336 gdb_assert (current_program_space
== following_inferior
->pspace
);
1338 /* Attempt to open the exec file. SYMFILE_DEFER_BP_RESET is used
1339 because the proper displacement for a PIE (Position Independent
1340 Executable) main symbol file will only be computed by
1341 solib_create_inferior_hook below. breakpoint_re_set would fail
1342 to insert the breakpoints with the zero displacement. */
1343 try_open_exec_file (exec_file_host
.get (), following_inferior
,
1344 SYMFILE_DEFER_BP_RESET
);
1346 /* If the target can specify a description, read it. Must do this
1347 after flipping to the new executable (because the target supplied
1348 description must be compatible with the executable's
1349 architecture, and the old executable may e.g., be 32-bit, while
1350 the new one 64-bit), and before anything involving memory or
1352 target_find_description ();
1354 gdb::observers::inferior_execd
.notify (execing_inferior
, following_inferior
);
1356 breakpoint_re_set ();
1358 /* Reinsert all breakpoints. (Those which were symbolic have
1359 been reset to the proper address in the new a.out, thanks
1360 to symbol_file_command...). */
1361 insert_breakpoints ();
1363 /* The next resume of this inferior should bring it to the shlib
1364 startup breakpoints. (If the user had also set bp's on
1365 "main" from the old (parent) process, then they'll auto-
1366 matically get reset there in the new process.). */
1369 /* The chain of threads that need to do a step-over operation to get
1370 past e.g., a breakpoint. What technique is used to step over the
1371 breakpoint/watchpoint does not matter -- all threads end up in the
1372 same queue, to maintain rough temporal order of execution, in order
1373 to avoid starvation, otherwise, we could e.g., find ourselves
1374 constantly stepping the same couple threads past their breakpoints
1375 over and over, if the single-step finish fast enough. */
1376 thread_step_over_list global_thread_step_over_list
;
1378 /* Bit flags indicating what the thread needs to step over. */
1380 enum step_over_what_flag
1382 /* Step over a breakpoint. */
1383 STEP_OVER_BREAKPOINT
= 1,
1385 /* Step past a non-continuable watchpoint, in order to let the
1386 instruction execute so we can evaluate the watchpoint
1388 STEP_OVER_WATCHPOINT
= 2
1390 DEF_ENUM_FLAGS_TYPE (enum step_over_what_flag
, step_over_what
);
1392 /* Info about an instruction that is being stepped over. */
1394 struct step_over_info
1396 /* If we're stepping past a breakpoint, this is the address space
1397 and address of the instruction the breakpoint is set at. We'll
1398 skip inserting all breakpoints here. Valid iff ASPACE is
1400 const address_space
*aspace
= nullptr;
1401 CORE_ADDR address
= 0;
1403 /* The instruction being stepped over triggers a nonsteppable
1404 watchpoint. If true, we'll skip inserting watchpoints. */
1405 int nonsteppable_watchpoint_p
= 0;
1407 /* The thread's global number. */
1411 /* The step-over info of the location that is being stepped over.
1413 Note that with async/breakpoint always-inserted mode, a user might
1414 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1415 being stepped over. As setting a new breakpoint inserts all
1416 breakpoints, we need to make sure the breakpoint being stepped over
1417 isn't inserted then. We do that by only clearing the step-over
1418 info when the step-over is actually finished (or aborted).
1420 Presently GDB can only step over one breakpoint at any given time.
1421 Given threads that can't run code in the same address space as the
1422 breakpoint's can't really miss the breakpoint, GDB could be taught
1423 to step-over at most one breakpoint per address space (so this info
1424 could move to the address space object if/when GDB is extended).
1425 The set of breakpoints being stepped over will normally be much
1426 smaller than the set of all breakpoints, so a flag in the
1427 breakpoint location structure would be wasteful. A separate list
1428 also saves complexity and run-time, as otherwise we'd have to go
1429 through all breakpoint locations clearing their flag whenever we
1430 start a new sequence. Similar considerations weigh against storing
1431 this info in the thread object. Plus, not all step overs actually
1432 have breakpoint locations -- e.g., stepping past a single-step
1433 breakpoint, or stepping to complete a non-continuable
1435 static struct step_over_info step_over_info
;
1437 /* Record the address of the breakpoint/instruction we're currently
1439 N.B. We record the aspace and address now, instead of say just the thread,
1440 because when we need the info later the thread may be running. */
1443 set_step_over_info (const address_space
*aspace
, CORE_ADDR address
,
1444 int nonsteppable_watchpoint_p
,
1447 step_over_info
.aspace
= aspace
;
1448 step_over_info
.address
= address
;
1449 step_over_info
.nonsteppable_watchpoint_p
= nonsteppable_watchpoint_p
;
1450 step_over_info
.thread
= thread
;
1453 /* Called when we're not longer stepping over a breakpoint / an
1454 instruction, so all breakpoints are free to be (re)inserted. */
1457 clear_step_over_info (void)
1459 infrun_debug_printf ("clearing step over info");
1460 step_over_info
.aspace
= nullptr;
1461 step_over_info
.address
= 0;
1462 step_over_info
.nonsteppable_watchpoint_p
= 0;
1463 step_over_info
.thread
= -1;
1469 stepping_past_instruction_at (struct address_space
*aspace
,
1472 return (step_over_info
.aspace
!= nullptr
1473 && breakpoint_address_match (aspace
, address
,
1474 step_over_info
.aspace
,
1475 step_over_info
.address
));
1481 thread_is_stepping_over_breakpoint (int thread
)
1483 return (step_over_info
.thread
!= -1
1484 && thread
== step_over_info
.thread
);
1490 stepping_past_nonsteppable_watchpoint (void)
1492 return step_over_info
.nonsteppable_watchpoint_p
;
1495 /* Returns true if step-over info is valid. */
1498 step_over_info_valid_p (void)
1500 return (step_over_info
.aspace
!= nullptr
1501 || stepping_past_nonsteppable_watchpoint ());
1505 /* Displaced stepping. */
1507 /* In non-stop debugging mode, we must take special care to manage
1508 breakpoints properly; in particular, the traditional strategy for
1509 stepping a thread past a breakpoint it has hit is unsuitable.
1510 'Displaced stepping' is a tactic for stepping one thread past a
1511 breakpoint it has hit while ensuring that other threads running
1512 concurrently will hit the breakpoint as they should.
1514 The traditional way to step a thread T off a breakpoint in a
1515 multi-threaded program in all-stop mode is as follows:
1517 a0) Initially, all threads are stopped, and breakpoints are not
1519 a1) We single-step T, leaving breakpoints uninserted.
1520 a2) We insert breakpoints, and resume all threads.
1522 In non-stop debugging, however, this strategy is unsuitable: we
1523 don't want to have to stop all threads in the system in order to
1524 continue or step T past a breakpoint. Instead, we use displaced
1527 n0) Initially, T is stopped, other threads are running, and
1528 breakpoints are inserted.
1529 n1) We copy the instruction "under" the breakpoint to a separate
1530 location, outside the main code stream, making any adjustments
1531 to the instruction, register, and memory state as directed by
1533 n2) We single-step T over the instruction at its new location.
1534 n3) We adjust the resulting register and memory state as directed
1535 by T's architecture. This includes resetting T's PC to point
1536 back into the main instruction stream.
1539 This approach depends on the following gdbarch methods:
1541 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1542 indicate where to copy the instruction, and how much space must
1543 be reserved there. We use these in step n1.
1545 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1546 address, and makes any necessary adjustments to the instruction,
1547 register contents, and memory. We use this in step n1.
1549 - gdbarch_displaced_step_fixup adjusts registers and memory after
1550 we have successfully single-stepped the instruction, to yield the
1551 same effect the instruction would have had if we had executed it
1552 at its original address. We use this in step n3.
1554 The gdbarch_displaced_step_copy_insn and
1555 gdbarch_displaced_step_fixup functions must be written so that
1556 copying an instruction with gdbarch_displaced_step_copy_insn,
1557 single-stepping across the copied instruction, and then applying
1558 gdbarch_displaced_insn_fixup should have the same effects on the
1559 thread's memory and registers as stepping the instruction in place
1560 would have. Exactly which responsibilities fall to the copy and
1561 which fall to the fixup is up to the author of those functions.
1563 See the comments in gdbarch.sh for details.
1565 Note that displaced stepping and software single-step cannot
1566 currently be used in combination, although with some care I think
1567 they could be made to. Software single-step works by placing
1568 breakpoints on all possible subsequent instructions; if the
1569 displaced instruction is a PC-relative jump, those breakpoints
1570 could fall in very strange places --- on pages that aren't
1571 executable, or at addresses that are not proper instruction
1572 boundaries. (We do generally let other threads run while we wait
1573 to hit the software single-step breakpoint, and they might
1574 encounter such a corrupted instruction.) One way to work around
1575 this would be to have gdbarch_displaced_step_copy_insn fully
1576 simulate the effect of PC-relative instructions (and return NULL)
1577 on architectures that use software single-stepping.
1579 In non-stop mode, we can have independent and simultaneous step
1580 requests, so more than one thread may need to simultaneously step
1581 over a breakpoint. The current implementation assumes there is
1582 only one scratch space per process. In this case, we have to
1583 serialize access to the scratch space. If thread A wants to step
1584 over a breakpoint, but we are currently waiting for some other
1585 thread to complete a displaced step, we leave thread A stopped and
1586 place it in the displaced_step_request_queue. Whenever a displaced
1587 step finishes, we pick the next thread in the queue and start a new
1588 displaced step operation on it. See displaced_step_prepare and
1589 displaced_step_finish for details. */
1591 /* Return true if THREAD is doing a displaced step. */
1594 displaced_step_in_progress_thread (thread_info
*thread
)
1596 gdb_assert (thread
!= nullptr);
1598 return thread
->displaced_step_state
.in_progress ();
1601 /* Return true if INF has a thread doing a displaced step. */
1604 displaced_step_in_progress (inferior
*inf
)
1606 return inf
->displaced_step_state
.in_progress_count
> 0;
1609 /* Return true if any thread is doing a displaced step. */
1612 displaced_step_in_progress_any_thread ()
1614 for (inferior
*inf
: all_non_exited_inferiors ())
1616 if (displaced_step_in_progress (inf
))
1624 infrun_inferior_exit (struct inferior
*inf
)
1626 inf
->displaced_step_state
.reset ();
1627 inf
->thread_waiting_for_vfork_done
= nullptr;
1631 infrun_inferior_execd (inferior
*exec_inf
, inferior
*follow_inf
)
1633 /* If some threads where was doing a displaced step in this inferior at the
1634 moment of the exec, they no longer exist. Even if the exec'ing thread
1635 doing a displaced step, we don't want to to any fixup nor restore displaced
1636 stepping buffer bytes. */
1637 follow_inf
->displaced_step_state
.reset ();
1639 for (thread_info
*thread
: follow_inf
->threads ())
1640 thread
->displaced_step_state
.reset ();
1642 /* Since an in-line step is done with everything else stopped, if there was
1643 one in progress at the time of the exec, it must have been the exec'ing
1645 clear_step_over_info ();
1647 follow_inf
->thread_waiting_for_vfork_done
= nullptr;
1650 /* If ON, and the architecture supports it, GDB will use displaced
1651 stepping to step over breakpoints. If OFF, or if the architecture
1652 doesn't support it, GDB will instead use the traditional
1653 hold-and-step approach. If AUTO (which is the default), GDB will
1654 decide which technique to use to step over breakpoints depending on
1655 whether the target works in a non-stop way (see use_displaced_stepping). */
1657 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1660 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1661 struct cmd_list_element
*c
,
1664 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1666 _("Debugger's willingness to use displaced stepping "
1667 "to step over breakpoints is %s (currently %s).\n"),
1668 value
, target_is_non_stop_p () ? "on" : "off");
1671 _("Debugger's willingness to use displaced stepping "
1672 "to step over breakpoints is %s.\n"), value
);
1675 /* Return true if the gdbarch implements the required methods to use
1676 displaced stepping. */
1679 gdbarch_supports_displaced_stepping (gdbarch
*arch
)
1681 /* Only check for the presence of `prepare`. The gdbarch verification ensures
1682 that if `prepare` is provided, so is `finish`. */
1683 return gdbarch_displaced_step_prepare_p (arch
);
1686 /* Return non-zero if displaced stepping can/should be used to step
1687 over breakpoints of thread TP. */
1690 use_displaced_stepping (thread_info
*tp
)
1692 /* If the user disabled it explicitly, don't use displaced stepping. */
1693 if (can_use_displaced_stepping
== AUTO_BOOLEAN_FALSE
)
1696 /* If "auto", only use displaced stepping if the target operates in a non-stop
1698 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
1699 && !target_is_non_stop_p ())
1702 gdbarch
*gdbarch
= get_thread_regcache (tp
)->arch ();
1704 /* If the architecture doesn't implement displaced stepping, don't use
1706 if (!gdbarch_supports_displaced_stepping (gdbarch
))
1709 /* If recording, don't use displaced stepping. */
1710 if (find_record_target () != nullptr)
1713 /* If displaced stepping failed before for this inferior, don't bother trying
1715 if (tp
->inf
->displaced_step_state
.failed_before
)
1721 /* Simple function wrapper around displaced_step_thread_state::reset. */
1724 displaced_step_reset (displaced_step_thread_state
*displaced
)
1726 displaced
->reset ();
1729 /* A cleanup that wraps displaced_step_reset. We use this instead of, say,
1730 SCOPE_EXIT, because it needs to be discardable with "cleanup.release ()". */
1732 using displaced_step_reset_cleanup
= FORWARD_SCOPE_EXIT (displaced_step_reset
);
1734 /* Prepare to single-step, using displaced stepping.
1736 Note that we cannot use displaced stepping when we have a signal to
1737 deliver. If we have a signal to deliver and an instruction to step
1738 over, then after the step, there will be no indication from the
1739 target whether the thread entered a signal handler or ignored the
1740 signal and stepped over the instruction successfully --- both cases
1741 result in a simple SIGTRAP. In the first case we mustn't do a
1742 fixup, and in the second case we must --- but we can't tell which.
1743 Comments in the code for 'random signals' in handle_inferior_event
1744 explain how we handle this case instead.
1746 Returns DISPLACED_STEP_PREPARE_STATUS_OK if preparing was successful -- this
1747 thread is going to be stepped now; DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
1748 if displaced stepping this thread got queued; or
1749 DISPLACED_STEP_PREPARE_STATUS_CANT if this instruction can't be displaced
1752 static displaced_step_prepare_status
1753 displaced_step_prepare_throw (thread_info
*tp
)
1755 regcache
*regcache
= get_thread_regcache (tp
);
1756 struct gdbarch
*gdbarch
= regcache
->arch ();
1757 displaced_step_thread_state
&disp_step_thread_state
1758 = tp
->displaced_step_state
;
1760 /* We should never reach this function if the architecture does not
1761 support displaced stepping. */
1762 gdb_assert (gdbarch_supports_displaced_stepping (gdbarch
));
1764 /* Nor if the thread isn't meant to step over a breakpoint. */
1765 gdb_assert (tp
->control
.trap_expected
);
1767 /* Disable range stepping while executing in the scratch pad. We
1768 want a single-step even if executing the displaced instruction in
1769 the scratch buffer lands within the stepping range (e.g., a
1771 tp
->control
.may_range_step
= 0;
1773 /* We are about to start a displaced step for this thread. If one is already
1774 in progress, something's wrong. */
1775 gdb_assert (!disp_step_thread_state
.in_progress ());
1777 if (tp
->inf
->displaced_step_state
.unavailable
)
1779 /* The gdbarch tells us it's not worth asking to try a prepare because
1780 it is likely that it will return unavailable, so don't bother asking. */
1782 displaced_debug_printf ("deferring step of %s",
1783 tp
->ptid
.to_string ().c_str ());
1785 global_thread_step_over_chain_enqueue (tp
);
1786 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1789 displaced_debug_printf ("displaced-stepping %s now",
1790 tp
->ptid
.to_string ().c_str ());
1792 scoped_restore_current_thread restore_thread
;
1794 switch_to_thread (tp
);
1796 CORE_ADDR original_pc
= regcache_read_pc (regcache
);
1797 CORE_ADDR displaced_pc
;
1799 /* Display the instruction we are going to displaced step. */
1800 if (debug_displaced
)
1802 string_file tmp_stream
;
1803 int dislen
= gdb_print_insn (gdbarch
, original_pc
, &tmp_stream
,
1808 gdb::byte_vector
insn_buf (dislen
);
1809 read_memory (original_pc
, insn_buf
.data (), insn_buf
.size ());
1811 std::string insn_bytes
= bytes_to_string (insn_buf
);
1813 displaced_debug_printf ("original insn %s: %s \t %s",
1814 paddress (gdbarch
, original_pc
),
1815 insn_bytes
.c_str (),
1816 tmp_stream
.string ().c_str ());
1819 displaced_debug_printf ("original insn %s: invalid length: %d",
1820 paddress (gdbarch
, original_pc
), dislen
);
1823 displaced_step_prepare_status status
1824 = gdbarch_displaced_step_prepare (gdbarch
, tp
, displaced_pc
);
1826 if (status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
1828 displaced_debug_printf ("failed to prepare (%s)",
1829 tp
->ptid
.to_string ().c_str ());
1831 return DISPLACED_STEP_PREPARE_STATUS_CANT
;
1833 else if (status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
1835 /* Not enough displaced stepping resources available, defer this
1836 request by placing it the queue. */
1838 displaced_debug_printf ("not enough resources available, "
1839 "deferring step of %s",
1840 tp
->ptid
.to_string ().c_str ());
1842 global_thread_step_over_chain_enqueue (tp
);
1844 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1847 gdb_assert (status
== DISPLACED_STEP_PREPARE_STATUS_OK
);
1849 /* Save the information we need to fix things up if the step
1851 disp_step_thread_state
.set (gdbarch
);
1853 tp
->inf
->displaced_step_state
.in_progress_count
++;
1855 displaced_debug_printf ("prepared successfully thread=%s, "
1856 "original_pc=%s, displaced_pc=%s",
1857 tp
->ptid
.to_string ().c_str (),
1858 paddress (gdbarch
, original_pc
),
1859 paddress (gdbarch
, displaced_pc
));
1861 /* Display the new displaced instruction(s). */
1862 if (debug_displaced
)
1864 string_file tmp_stream
;
1865 CORE_ADDR addr
= displaced_pc
;
1867 /* If displaced stepping is going to use h/w single step then we know
1868 that the replacement instruction can only be a single instruction,
1869 in that case set the end address at the next byte.
1871 Otherwise the displaced stepping copy instruction routine could
1872 have generated multiple instructions, and all we know is that they
1873 must fit within the LEN bytes of the buffer. */
1875 = addr
+ (gdbarch_displaced_step_hw_singlestep (gdbarch
)
1876 ? 1 : gdbarch_displaced_step_buffer_length (gdbarch
));
1880 int dislen
= gdb_print_insn (gdbarch
, addr
, &tmp_stream
, nullptr);
1883 displaced_debug_printf
1884 ("replacement insn %s: invalid length: %d",
1885 paddress (gdbarch
, addr
), dislen
);
1889 gdb::byte_vector
insn_buf (dislen
);
1890 read_memory (addr
, insn_buf
.data (), insn_buf
.size ());
1892 std::string insn_bytes
= bytes_to_string (insn_buf
);
1893 std::string insn_str
= tmp_stream
.release ();
1894 displaced_debug_printf ("replacement insn %s: %s \t %s",
1895 paddress (gdbarch
, addr
),
1896 insn_bytes
.c_str (),
1902 return DISPLACED_STEP_PREPARE_STATUS_OK
;
1905 /* Wrapper for displaced_step_prepare_throw that disabled further
1906 attempts at displaced stepping if we get a memory error. */
1908 static displaced_step_prepare_status
1909 displaced_step_prepare (thread_info
*thread
)
1911 displaced_step_prepare_status status
1912 = DISPLACED_STEP_PREPARE_STATUS_CANT
;
1916 status
= displaced_step_prepare_throw (thread
);
1918 catch (const gdb_exception_error
&ex
)
1920 if (ex
.error
!= MEMORY_ERROR
1921 && ex
.error
!= NOT_SUPPORTED_ERROR
)
1924 infrun_debug_printf ("caught exception, disabling displaced stepping: %s",
1927 /* Be verbose if "set displaced-stepping" is "on", silent if
1929 if (can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1931 warning (_("disabling displaced stepping: %s"),
1935 /* Disable further displaced stepping attempts. */
1936 thread
->inf
->displaced_step_state
.failed_before
= 1;
1942 /* If we displaced stepped an instruction successfully, adjust registers and
1943 memory to yield the same effect the instruction would have had if we had
1944 executed it at its original address, and return
1945 DISPLACED_STEP_FINISH_STATUS_OK. If the instruction didn't complete,
1946 relocate the PC and return DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED.
1948 If the thread wasn't displaced stepping, return
1949 DISPLACED_STEP_FINISH_STATUS_OK as well. */
1951 static displaced_step_finish_status
1952 displaced_step_finish (thread_info
*event_thread
,
1953 const target_waitstatus
&event_status
)
1955 displaced_step_thread_state
*displaced
= &event_thread
->displaced_step_state
;
1957 /* Was this thread performing a displaced step? */
1958 if (!displaced
->in_progress ())
1959 return DISPLACED_STEP_FINISH_STATUS_OK
;
1961 gdb_assert (event_thread
->inf
->displaced_step_state
.in_progress_count
> 0);
1962 event_thread
->inf
->displaced_step_state
.in_progress_count
--;
1964 /* Fixup may need to read memory/registers. Switch to the thread
1965 that we're fixing up. Also, target_stopped_by_watchpoint checks
1966 the current thread, and displaced_step_restore performs ptid-dependent
1967 memory accesses using current_inferior(). */
1968 switch_to_thread (event_thread
);
1970 displaced_step_reset_cleanup
cleanup (displaced
);
1972 /* Do the fixup, and release the resources acquired to do the displaced
1974 return gdbarch_displaced_step_finish (displaced
->get_original_gdbarch (),
1975 event_thread
, event_status
);
1978 /* Data to be passed around while handling an event. This data is
1979 discarded between events. */
1980 struct execution_control_state
1982 explicit execution_control_state (thread_info
*thr
= nullptr)
1983 : ptid (thr
== nullptr ? null_ptid
: thr
->ptid
),
1988 process_stratum_target
*target
= nullptr;
1990 /* The thread that got the event, if this was a thread event; NULL
1992 struct thread_info
*event_thread
;
1994 struct target_waitstatus ws
;
1995 int stop_func_filled_in
= 0;
1996 CORE_ADDR stop_func_alt_start
= 0;
1997 CORE_ADDR stop_func_start
= 0;
1998 CORE_ADDR stop_func_end
= 0;
1999 const char *stop_func_name
= nullptr;
2000 int wait_some_more
= 0;
2002 /* True if the event thread hit the single-step breakpoint of
2003 another thread. Thus the event doesn't cause a stop, the thread
2004 needs to be single-stepped past the single-step breakpoint before
2005 we can switch back to the original stepping thread. */
2006 int hit_singlestep_breakpoint
= 0;
2009 static void keep_going_pass_signal (struct execution_control_state
*ecs
);
2010 static void prepare_to_wait (struct execution_control_state
*ecs
);
2011 static bool keep_going_stepped_thread (struct thread_info
*tp
);
2012 static step_over_what
thread_still_needs_step_over (struct thread_info
*tp
);
2014 /* Are there any pending step-over requests? If so, run all we can
2015 now and return true. Otherwise, return false. */
2018 start_step_over (void)
2020 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
2022 /* Don't start a new step-over if we already have an in-line
2023 step-over operation ongoing. */
2024 if (step_over_info_valid_p ())
2027 /* Steal the global thread step over chain. As we try to initiate displaced
2028 steps, threads will be enqueued in the global chain if no buffers are
2029 available. If we iterated on the global chain directly, we might iterate
2031 thread_step_over_list threads_to_step
2032 = std::move (global_thread_step_over_list
);
2034 infrun_debug_printf ("stealing global queue of threads to step, length = %d",
2035 thread_step_over_chain_length (threads_to_step
));
2037 bool started
= false;
2039 /* On scope exit (whatever the reason, return or exception), if there are
2040 threads left in the THREADS_TO_STEP chain, put back these threads in the
2044 if (threads_to_step
.empty ())
2045 infrun_debug_printf ("step-over queue now empty");
2048 infrun_debug_printf ("putting back %d threads to step in global queue",
2049 thread_step_over_chain_length (threads_to_step
));
2051 global_thread_step_over_chain_enqueue_chain
2052 (std::move (threads_to_step
));
2056 thread_step_over_list_safe_range range
2057 = make_thread_step_over_list_safe_range (threads_to_step
);
2059 for (thread_info
*tp
: range
)
2061 step_over_what step_what
;
2062 int must_be_in_line
;
2064 gdb_assert (!tp
->stop_requested
);
2066 if (tp
->inf
->displaced_step_state
.unavailable
)
2068 /* The arch told us to not even try preparing another displaced step
2069 for this inferior. Just leave the thread in THREADS_TO_STEP, it
2070 will get moved to the global chain on scope exit. */
2074 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr)
2076 /* When we stop all threads, handling a vfork, any thread in the step
2077 over chain remains there. A user could also try to continue a
2078 thread stopped at a breakpoint while another thread is waiting for
2079 a vfork-done event. In any case, we don't want to start a step
2084 /* Remove thread from the THREADS_TO_STEP chain. If anything goes wrong
2085 while we try to prepare the displaced step, we don't add it back to
2086 the global step over chain. This is to avoid a thread staying in the
2087 step over chain indefinitely if something goes wrong when resuming it
2088 If the error is intermittent and it still needs a step over, it will
2089 get enqueued again when we try to resume it normally. */
2090 threads_to_step
.erase (threads_to_step
.iterator_to (*tp
));
2092 step_what
= thread_still_needs_step_over (tp
);
2093 must_be_in_line
= ((step_what
& STEP_OVER_WATCHPOINT
)
2094 || ((step_what
& STEP_OVER_BREAKPOINT
)
2095 && !use_displaced_stepping (tp
)));
2097 /* We currently stop all threads of all processes to step-over
2098 in-line. If we need to start a new in-line step-over, let
2099 any pending displaced steps finish first. */
2100 if (must_be_in_line
&& displaced_step_in_progress_any_thread ())
2102 global_thread_step_over_chain_enqueue (tp
);
2106 if (tp
->control
.trap_expected
2108 || tp
->executing ())
2110 internal_error ("[%s] has inconsistent state: "
2111 "trap_expected=%d, resumed=%d, executing=%d\n",
2112 tp
->ptid
.to_string ().c_str (),
2113 tp
->control
.trap_expected
,
2118 infrun_debug_printf ("resuming [%s] for step-over",
2119 tp
->ptid
.to_string ().c_str ());
2121 /* keep_going_pass_signal skips the step-over if the breakpoint
2122 is no longer inserted. In all-stop, we want to keep looking
2123 for a thread that needs a step-over instead of resuming TP,
2124 because we wouldn't be able to resume anything else until the
2125 target stops again. In non-stop, the resume always resumes
2126 only TP, so it's OK to let the thread resume freely. */
2127 if (!target_is_non_stop_p () && !step_what
)
2130 switch_to_thread (tp
);
2131 execution_control_state
ecs (tp
);
2132 keep_going_pass_signal (&ecs
);
2134 if (!ecs
.wait_some_more
)
2135 error (_("Command aborted."));
2137 /* If the thread's step over could not be initiated because no buffers
2138 were available, it was re-added to the global step over chain. */
2141 infrun_debug_printf ("[%s] was resumed.",
2142 tp
->ptid
.to_string ().c_str ());
2143 gdb_assert (!thread_is_in_step_over_chain (tp
));
2147 infrun_debug_printf ("[%s] was NOT resumed.",
2148 tp
->ptid
.to_string ().c_str ());
2149 gdb_assert (thread_is_in_step_over_chain (tp
));
2152 /* If we started a new in-line step-over, we're done. */
2153 if (step_over_info_valid_p ())
2155 gdb_assert (tp
->control
.trap_expected
);
2160 if (!target_is_non_stop_p ())
2162 /* On all-stop, shouldn't have resumed unless we needed a
2164 gdb_assert (tp
->control
.trap_expected
2165 || tp
->step_after_step_resume_breakpoint
);
2167 /* With remote targets (at least), in all-stop, we can't
2168 issue any further remote commands until the program stops
2174 /* Either the thread no longer needed a step-over, or a new
2175 displaced stepping sequence started. Even in the latter
2176 case, continue looking. Maybe we can also start another
2177 displaced step on a thread of other process. */
2183 /* Update global variables holding ptids to hold NEW_PTID if they were
2184 holding OLD_PTID. */
2186 infrun_thread_ptid_changed (process_stratum_target
*target
,
2187 ptid_t old_ptid
, ptid_t new_ptid
)
2189 if (inferior_ptid
== old_ptid
2190 && current_inferior ()->process_target () == target
)
2191 inferior_ptid
= new_ptid
;
2196 static const char schedlock_off
[] = "off";
2197 static const char schedlock_on
[] = "on";
2198 static const char schedlock_step
[] = "step";
2199 static const char schedlock_replay
[] = "replay";
2200 static const char *const scheduler_enums
[] = {
2207 static const char *scheduler_mode
= schedlock_replay
;
2209 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
2210 struct cmd_list_element
*c
, const char *value
)
2213 _("Mode for locking scheduler "
2214 "during execution is \"%s\".\n"),
2219 set_schedlock_func (const char *args
, int from_tty
, struct cmd_list_element
*c
)
2221 if (!target_can_lock_scheduler ())
2223 scheduler_mode
= schedlock_off
;
2224 error (_("Target '%s' cannot support this command."),
2225 target_shortname ());
2229 /* True if execution commands resume all threads of all processes by
2230 default; otherwise, resume only threads of the current inferior
2232 bool sched_multi
= false;
2234 /* Try to setup for software single stepping. Return true if target_resume()
2235 should use hardware single step.
2237 GDBARCH the current gdbarch. */
2240 maybe_software_singlestep (struct gdbarch
*gdbarch
)
2242 bool hw_step
= true;
2244 if (execution_direction
== EXEC_FORWARD
2245 && gdbarch_software_single_step_p (gdbarch
))
2246 hw_step
= !insert_single_step_breakpoints (gdbarch
);
2254 user_visible_resume_ptid (int step
)
2260 /* With non-stop mode on, threads are always handled
2262 resume_ptid
= inferior_ptid
;
2264 else if ((scheduler_mode
== schedlock_on
)
2265 || (scheduler_mode
== schedlock_step
&& step
))
2267 /* User-settable 'scheduler' mode requires solo thread
2269 resume_ptid
= inferior_ptid
;
2271 else if ((scheduler_mode
== schedlock_replay
)
2272 && target_record_will_replay (minus_one_ptid
, execution_direction
))
2274 /* User-settable 'scheduler' mode requires solo thread resume in replay
2276 resume_ptid
= inferior_ptid
;
2278 else if (!sched_multi
&& target_supports_multi_process ())
2280 /* Resume all threads of the current process (and none of other
2282 resume_ptid
= ptid_t (inferior_ptid
.pid ());
2286 /* Resume all threads of all processes. */
2287 resume_ptid
= RESUME_ALL
;
2295 process_stratum_target
*
2296 user_visible_resume_target (ptid_t resume_ptid
)
2298 return (resume_ptid
== minus_one_ptid
&& sched_multi
2300 : current_inferior ()->process_target ());
2303 /* Find a thread from the inferiors that we'll resume that is waiting
2304 for a vfork-done event. */
2306 static thread_info
*
2307 find_thread_waiting_for_vfork_done ()
2309 gdb_assert (!target_is_non_stop_p ());
2313 for (inferior
*inf
: all_non_exited_inferiors ())
2314 if (inf
->thread_waiting_for_vfork_done
!= nullptr)
2315 return inf
->thread_waiting_for_vfork_done
;
2319 inferior
*cur_inf
= current_inferior ();
2320 if (cur_inf
->thread_waiting_for_vfork_done
!= nullptr)
2321 return cur_inf
->thread_waiting_for_vfork_done
;
2326 /* Return a ptid representing the set of threads that we will resume,
2327 in the perspective of the target, assuming run control handling
2328 does not require leaving some threads stopped (e.g., stepping past
2329 breakpoint). USER_STEP indicates whether we're about to start the
2330 target for a stepping command. */
2333 internal_resume_ptid (int user_step
)
2335 /* In non-stop, we always control threads individually. Note that
2336 the target may always work in non-stop mode even with "set
2337 non-stop off", in which case user_visible_resume_ptid could
2338 return a wildcard ptid. */
2339 if (target_is_non_stop_p ())
2340 return inferior_ptid
;
2342 /* The rest of the function assumes non-stop==off and
2343 target-non-stop==off.
2345 If a thread is waiting for a vfork-done event, it means breakpoints are out
2346 for this inferior (well, program space in fact). We don't want to resume
2347 any thread other than the one waiting for vfork done, otherwise these other
2348 threads could miss breakpoints. So if a thread in the resumption set is
2349 waiting for a vfork-done event, resume only that thread.
2351 The resumption set width depends on whether schedule-multiple is on or off.
2353 Note that if the target_resume interface was more flexible, we could be
2354 smarter here when schedule-multiple is on. For example, imagine 3
2355 inferiors with 2 threads each (1.1, 1.2, 2.1, 2.2, 3.1 and 3.2). Threads
2356 2.1 and 3.2 are both waiting for a vfork-done event. Then we could ask the
2357 target(s) to resume:
2359 - All threads of inferior 1
2363 Since we don't have that flexibility (we can only pass one ptid), just
2364 resume the first thread waiting for a vfork-done event we find (e.g. thread
2366 thread_info
*thr
= find_thread_waiting_for_vfork_done ();
2369 /* If we have a thread that is waiting for a vfork-done event,
2370 then we should have switched to it earlier. Calling
2371 target_resume with thread scope is only possible when the
2372 current thread matches the thread scope. */
2373 gdb_assert (thr
->ptid
== inferior_ptid
);
2374 gdb_assert (thr
->inf
->process_target ()
2375 == inferior_thread ()->inf
->process_target ());
2379 return user_visible_resume_ptid (user_step
);
2382 /* Wrapper for target_resume, that handles infrun-specific
2386 do_target_resume (ptid_t resume_ptid
, bool step
, enum gdb_signal sig
)
2388 struct thread_info
*tp
= inferior_thread ();
2390 gdb_assert (!tp
->stop_requested
);
2392 /* Install inferior's terminal modes. */
2393 target_terminal::inferior ();
2395 /* Avoid confusing the next resume, if the next stop/resume
2396 happens to apply to another thread. */
2397 tp
->set_stop_signal (GDB_SIGNAL_0
);
2399 /* Advise target which signals may be handled silently.
2401 If we have removed breakpoints because we are stepping over one
2402 in-line (in any thread), we need to receive all signals to avoid
2403 accidentally skipping a breakpoint during execution of a signal
2406 Likewise if we're displaced stepping, otherwise a trap for a
2407 breakpoint in a signal handler might be confused with the
2408 displaced step finishing. We don't make the displaced_step_finish
2409 step distinguish the cases instead, because:
2411 - a backtrace while stopped in the signal handler would show the
2412 scratch pad as frame older than the signal handler, instead of
2413 the real mainline code.
2415 - when the thread is later resumed, the signal handler would
2416 return to the scratch pad area, which would no longer be
2418 if (step_over_info_valid_p ()
2419 || displaced_step_in_progress (tp
->inf
))
2420 target_pass_signals ({});
2422 target_pass_signals (signal_pass
);
2424 infrun_debug_printf ("resume_ptid=%s, step=%d, sig=%s",
2425 resume_ptid
.to_string ().c_str (),
2426 step
, gdb_signal_to_symbol_string (sig
));
2428 target_resume (resume_ptid
, step
, sig
);
2431 /* Resume the inferior. SIG is the signal to give the inferior
2432 (GDB_SIGNAL_0 for none). Note: don't call this directly; instead
2433 call 'resume', which handles exceptions. */
2436 resume_1 (enum gdb_signal sig
)
2438 struct regcache
*regcache
= get_current_regcache ();
2439 struct gdbarch
*gdbarch
= regcache
->arch ();
2440 struct thread_info
*tp
= inferior_thread ();
2441 const address_space
*aspace
= regcache
->aspace ();
2443 /* This represents the user's step vs continue request. When
2444 deciding whether "set scheduler-locking step" applies, it's the
2445 user's intention that counts. */
2446 const int user_step
= tp
->control
.stepping_command
;
2447 /* This represents what we'll actually request the target to do.
2448 This can decay from a step to a continue, if e.g., we need to
2449 implement single-stepping with breakpoints (software
2453 gdb_assert (!tp
->stop_requested
);
2454 gdb_assert (!thread_is_in_step_over_chain (tp
));
2456 if (tp
->has_pending_waitstatus ())
2459 ("thread %s has pending wait "
2460 "status %s (currently_stepping=%d).",
2461 tp
->ptid
.to_string ().c_str (),
2462 tp
->pending_waitstatus ().to_string ().c_str (),
2463 currently_stepping (tp
));
2465 tp
->inf
->process_target ()->threads_executing
= true;
2466 tp
->set_resumed (true);
2468 /* FIXME: What should we do if we are supposed to resume this
2469 thread with a signal? Maybe we should maintain a queue of
2470 pending signals to deliver. */
2471 if (sig
!= GDB_SIGNAL_0
)
2473 warning (_("Couldn't deliver signal %s to %s."),
2474 gdb_signal_to_name (sig
),
2475 tp
->ptid
.to_string ().c_str ());
2478 tp
->set_stop_signal (GDB_SIGNAL_0
);
2480 if (target_can_async_p ())
2482 target_async (true);
2483 /* Tell the event loop we have an event to process. */
2484 mark_async_event_handler (infrun_async_inferior_event_token
);
2489 tp
->stepped_breakpoint
= 0;
2491 /* Depends on stepped_breakpoint. */
2492 step
= currently_stepping (tp
);
2494 if (current_inferior ()->thread_waiting_for_vfork_done
!= nullptr)
2496 /* Don't try to single-step a vfork parent that is waiting for
2497 the child to get out of the shared memory region (by exec'ing
2498 or exiting). This is particularly important on software
2499 single-step archs, as the child process would trip on the
2500 software single step breakpoint inserted for the parent
2501 process. Since the parent will not actually execute any
2502 instruction until the child is out of the shared region (such
2503 are vfork's semantics), it is safe to simply continue it.
2504 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2505 the parent, and tell it to `keep_going', which automatically
2506 re-sets it stepping. */
2507 infrun_debug_printf ("resume : clear step");
2511 CORE_ADDR pc
= regcache_read_pc (regcache
);
2513 infrun_debug_printf ("step=%d, signal=%s, trap_expected=%d, "
2514 "current thread [%s] at %s",
2515 step
, gdb_signal_to_symbol_string (sig
),
2516 tp
->control
.trap_expected
,
2517 inferior_ptid
.to_string ().c_str (),
2518 paddress (gdbarch
, pc
));
2520 /* Normally, by the time we reach `resume', the breakpoints are either
2521 removed or inserted, as appropriate. The exception is if we're sitting
2522 at a permanent breakpoint; we need to step over it, but permanent
2523 breakpoints can't be removed. So we have to test for it here. */
2524 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2526 if (sig
!= GDB_SIGNAL_0
)
2528 /* We have a signal to pass to the inferior. The resume
2529 may, or may not take us to the signal handler. If this
2530 is a step, we'll need to stop in the signal handler, if
2531 there's one, (if the target supports stepping into
2532 handlers), or in the next mainline instruction, if
2533 there's no handler. If this is a continue, we need to be
2534 sure to run the handler with all breakpoints inserted.
2535 In all cases, set a breakpoint at the current address
2536 (where the handler returns to), and once that breakpoint
2537 is hit, resume skipping the permanent breakpoint. If
2538 that breakpoint isn't hit, then we've stepped into the
2539 signal handler (or hit some other event). We'll delete
2540 the step-resume breakpoint then. */
2542 infrun_debug_printf ("resume: skipping permanent breakpoint, "
2543 "deliver signal first");
2545 clear_step_over_info ();
2546 tp
->control
.trap_expected
= 0;
2548 if (tp
->control
.step_resume_breakpoint
== nullptr)
2550 /* Set a "high-priority" step-resume, as we don't want
2551 user breakpoints at PC to trigger (again) when this
2553 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2554 gdb_assert (tp
->control
.step_resume_breakpoint
->first_loc ()
2557 tp
->step_after_step_resume_breakpoint
= step
;
2560 insert_breakpoints ();
2564 /* There's no signal to pass, we can go ahead and skip the
2565 permanent breakpoint manually. */
2566 infrun_debug_printf ("skipping permanent breakpoint");
2567 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2568 /* Update pc to reflect the new address from which we will
2569 execute instructions. */
2570 pc
= regcache_read_pc (regcache
);
2574 /* We've already advanced the PC, so the stepping part
2575 is done. Now we need to arrange for a trap to be
2576 reported to handle_inferior_event. Set a breakpoint
2577 at the current PC, and run to it. Don't update
2578 prev_pc, because if we end in
2579 switch_back_to_stepped_thread, we want the "expected
2580 thread advanced also" branch to be taken. IOW, we
2581 don't want this thread to step further from PC
2583 gdb_assert (!step_over_info_valid_p ());
2584 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
2585 insert_breakpoints ();
2587 resume_ptid
= internal_resume_ptid (user_step
);
2588 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
2589 tp
->set_resumed (true);
2595 /* If we have a breakpoint to step over, make sure to do a single
2596 step only. Same if we have software watchpoints. */
2597 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2598 tp
->control
.may_range_step
= 0;
2600 /* If displaced stepping is enabled, step over breakpoints by executing a
2601 copy of the instruction at a different address.
2603 We can't use displaced stepping when we have a signal to deliver;
2604 the comments for displaced_step_prepare explain why. The
2605 comments in the handle_inferior event for dealing with 'random
2606 signals' explain what we do instead.
2608 We can't use displaced stepping when we are waiting for vfork_done
2609 event, displaced stepping breaks the vfork child similarly as single
2610 step software breakpoint. */
2611 if (tp
->control
.trap_expected
2612 && use_displaced_stepping (tp
)
2613 && !step_over_info_valid_p ()
2614 && sig
== GDB_SIGNAL_0
2615 && current_inferior ()->thread_waiting_for_vfork_done
== nullptr)
2617 displaced_step_prepare_status prepare_status
2618 = displaced_step_prepare (tp
);
2620 if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
2622 infrun_debug_printf ("Got placed in step-over queue");
2624 tp
->control
.trap_expected
= 0;
2627 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
2629 /* Fallback to stepping over the breakpoint in-line. */
2631 if (target_is_non_stop_p ())
2632 stop_all_threads ("displaced stepping falling back on inline stepping");
2634 set_step_over_info (regcache
->aspace (),
2635 regcache_read_pc (regcache
), 0, tp
->global_num
);
2637 step
= maybe_software_singlestep (gdbarch
);
2639 insert_breakpoints ();
2641 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_OK
)
2643 /* Update pc to reflect the new address from which we will
2644 execute instructions due to displaced stepping. */
2645 pc
= regcache_read_pc (get_thread_regcache (tp
));
2647 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
);
2650 gdb_assert_not_reached ("Invalid displaced_step_prepare_status "
2654 /* Do we need to do it the hard way, w/temp breakpoints? */
2656 step
= maybe_software_singlestep (gdbarch
);
2658 /* Currently, our software single-step implementation leads to different
2659 results than hardware single-stepping in one situation: when stepping
2660 into delivering a signal which has an associated signal handler,
2661 hardware single-step will stop at the first instruction of the handler,
2662 while software single-step will simply skip execution of the handler.
2664 For now, this difference in behavior is accepted since there is no
2665 easy way to actually implement single-stepping into a signal handler
2666 without kernel support.
2668 However, there is one scenario where this difference leads to follow-on
2669 problems: if we're stepping off a breakpoint by removing all breakpoints
2670 and then single-stepping. In this case, the software single-step
2671 behavior means that even if there is a *breakpoint* in the signal
2672 handler, GDB still would not stop.
2674 Fortunately, we can at least fix this particular issue. We detect
2675 here the case where we are about to deliver a signal while software
2676 single-stepping with breakpoints removed. In this situation, we
2677 revert the decisions to remove all breakpoints and insert single-
2678 step breakpoints, and instead we install a step-resume breakpoint
2679 at the current address, deliver the signal without stepping, and
2680 once we arrive back at the step-resume breakpoint, actually step
2681 over the breakpoint we originally wanted to step over. */
2682 if (thread_has_single_step_breakpoints_set (tp
)
2683 && sig
!= GDB_SIGNAL_0
2684 && step_over_info_valid_p ())
2686 /* If we have nested signals or a pending signal is delivered
2687 immediately after a handler returns, might already have
2688 a step-resume breakpoint set on the earlier handler. We cannot
2689 set another step-resume breakpoint; just continue on until the
2690 original breakpoint is hit. */
2691 if (tp
->control
.step_resume_breakpoint
== nullptr)
2693 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2694 tp
->step_after_step_resume_breakpoint
= 1;
2697 delete_single_step_breakpoints (tp
);
2699 clear_step_over_info ();
2700 tp
->control
.trap_expected
= 0;
2702 insert_breakpoints ();
2705 /* If STEP is set, it's a request to use hardware stepping
2706 facilities. But in that case, we should never
2707 use singlestep breakpoint. */
2708 gdb_assert (!(thread_has_single_step_breakpoints_set (tp
) && step
));
2710 /* Decide the set of threads to ask the target to resume. */
2711 if (tp
->control
.trap_expected
)
2713 /* We're allowing a thread to run past a breakpoint it has
2714 hit, either by single-stepping the thread with the breakpoint
2715 removed, or by displaced stepping, with the breakpoint inserted.
2716 In the former case, we need to single-step only this thread,
2717 and keep others stopped, as they can miss this breakpoint if
2718 allowed to run. That's not really a problem for displaced
2719 stepping, but, we still keep other threads stopped, in case
2720 another thread is also stopped for a breakpoint waiting for
2721 its turn in the displaced stepping queue. */
2722 resume_ptid
= inferior_ptid
;
2725 resume_ptid
= internal_resume_ptid (user_step
);
2727 if (execution_direction
!= EXEC_REVERSE
2728 && step
&& breakpoint_inserted_here_p (aspace
, pc
))
2730 /* There are two cases where we currently need to step a
2731 breakpoint instruction when we have a signal to deliver:
2733 - See handle_signal_stop where we handle random signals that
2734 could take out us out of the stepping range. Normally, in
2735 that case we end up continuing (instead of stepping) over the
2736 signal handler with a breakpoint at PC, but there are cases
2737 where we should _always_ single-step, even if we have a
2738 step-resume breakpoint, like when a software watchpoint is
2739 set. Assuming single-stepping and delivering a signal at the
2740 same time would takes us to the signal handler, then we could
2741 have removed the breakpoint at PC to step over it. However,
2742 some hardware step targets (like e.g., Mac OS) can't step
2743 into signal handlers, and for those, we need to leave the
2744 breakpoint at PC inserted, as otherwise if the handler
2745 recurses and executes PC again, it'll miss the breakpoint.
2746 So we leave the breakpoint inserted anyway, but we need to
2747 record that we tried to step a breakpoint instruction, so
2748 that adjust_pc_after_break doesn't end up confused.
2750 - In non-stop if we insert a breakpoint (e.g., a step-resume)
2751 in one thread after another thread that was stepping had been
2752 momentarily paused for a step-over. When we re-resume the
2753 stepping thread, it may be resumed from that address with a
2754 breakpoint that hasn't trapped yet. Seen with
2755 gdb.threads/non-stop-fair-events.exp, on targets that don't
2756 do displaced stepping. */
2758 infrun_debug_printf ("resume: [%s] stepped breakpoint",
2759 tp
->ptid
.to_string ().c_str ());
2761 tp
->stepped_breakpoint
= 1;
2763 /* Most targets can step a breakpoint instruction, thus
2764 executing it normally. But if this one cannot, just
2765 continue and we will hit it anyway. */
2766 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2770 if (tp
->control
.may_range_step
)
2772 /* If we're resuming a thread with the PC out of the step
2773 range, then we're doing some nested/finer run control
2774 operation, like stepping the thread out of the dynamic
2775 linker or the displaced stepping scratch pad. We
2776 shouldn't have allowed a range step then. */
2777 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2780 do_target_resume (resume_ptid
, step
, sig
);
2781 tp
->set_resumed (true);
2784 /* Resume the inferior. SIG is the signal to give the inferior
2785 (GDB_SIGNAL_0 for none). This is a wrapper around 'resume_1' that
2786 rolls back state on error. */
2789 resume (gdb_signal sig
)
2795 catch (const gdb_exception
&ex
)
2797 /* If resuming is being aborted for any reason, delete any
2798 single-step breakpoint resume_1 may have created, to avoid
2799 confusing the following resumption, and to avoid leaving
2800 single-step breakpoints perturbing other threads, in case
2801 we're running in non-stop mode. */
2802 if (inferior_ptid
!= null_ptid
)
2803 delete_single_step_breakpoints (inferior_thread ());
2813 /* Counter that tracks number of user visible stops. This can be used
2814 to tell whether a command has proceeded the inferior past the
2815 current location. This allows e.g., inferior function calls in
2816 breakpoint commands to not interrupt the command list. When the
2817 call finishes successfully, the inferior is standing at the same
2818 breakpoint as if nothing happened (and so we don't call
2820 static ULONGEST current_stop_id
;
2827 return current_stop_id
;
2830 /* Called when we report a user visible stop. */
2838 /* Clear out all variables saying what to do when inferior is continued.
2839 First do this, then set the ones you want, then call `proceed'. */
2842 clear_proceed_status_thread (struct thread_info
*tp
)
2844 infrun_debug_printf ("%s", tp
->ptid
.to_string ().c_str ());
2846 /* If we're starting a new sequence, then the previous finished
2847 single-step is no longer relevant. */
2848 if (tp
->has_pending_waitstatus ())
2850 if (tp
->stop_reason () == TARGET_STOPPED_BY_SINGLE_STEP
)
2852 infrun_debug_printf ("pending event of %s was a finished step. "
2854 tp
->ptid
.to_string ().c_str ());
2856 tp
->clear_pending_waitstatus ();
2857 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
2862 ("thread %s has pending wait status %s (currently_stepping=%d).",
2863 tp
->ptid
.to_string ().c_str (),
2864 tp
->pending_waitstatus ().to_string ().c_str (),
2865 currently_stepping (tp
));
2869 /* If this signal should not be seen by program, give it zero.
2870 Used for debugging signals. */
2871 if (!signal_pass_state (tp
->stop_signal ()))
2872 tp
->set_stop_signal (GDB_SIGNAL_0
);
2874 tp
->release_thread_fsm ();
2876 tp
->control
.trap_expected
= 0;
2877 tp
->control
.step_range_start
= 0;
2878 tp
->control
.step_range_end
= 0;
2879 tp
->control
.may_range_step
= 0;
2880 tp
->control
.step_frame_id
= null_frame_id
;
2881 tp
->control
.step_stack_frame_id
= null_frame_id
;
2882 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2883 tp
->control
.step_start_function
= nullptr;
2884 tp
->stop_requested
= 0;
2886 tp
->control
.stop_step
= 0;
2888 tp
->control
.proceed_to_finish
= 0;
2890 tp
->control
.stepping_command
= 0;
2892 /* Discard any remaining commands or status from previous stop. */
2893 bpstat_clear (&tp
->control
.stop_bpstat
);
2897 clear_proceed_status (int step
)
2899 /* With scheduler-locking replay, stop replaying other threads if we're
2900 not replaying the user-visible resume ptid.
2902 This is a convenience feature to not require the user to explicitly
2903 stop replaying the other threads. We're assuming that the user's
2904 intent is to resume tracing the recorded process. */
2905 if (!non_stop
&& scheduler_mode
== schedlock_replay
2906 && target_record_is_replaying (minus_one_ptid
)
2907 && !target_record_will_replay (user_visible_resume_ptid (step
),
2908 execution_direction
))
2909 target_record_stop_replaying ();
2911 if (!non_stop
&& inferior_ptid
!= null_ptid
)
2913 ptid_t resume_ptid
= user_visible_resume_ptid (step
);
2914 process_stratum_target
*resume_target
2915 = user_visible_resume_target (resume_ptid
);
2917 /* In all-stop mode, delete the per-thread status of all threads
2918 we're about to resume, implicitly and explicitly. */
2919 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
2920 clear_proceed_status_thread (tp
);
2923 if (inferior_ptid
!= null_ptid
)
2925 struct inferior
*inferior
;
2929 /* If in non-stop mode, only delete the per-thread status of
2930 the current thread. */
2931 clear_proceed_status_thread (inferior_thread ());
2934 inferior
= current_inferior ();
2935 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2938 gdb::observers::about_to_proceed
.notify ();
2941 /* Returns true if TP is still stopped at a breakpoint that needs
2942 stepping-over in order to make progress. If the breakpoint is gone
2943 meanwhile, we can skip the whole step-over dance. */
2946 thread_still_needs_step_over_bp (struct thread_info
*tp
)
2948 if (tp
->stepping_over_breakpoint
)
2950 struct regcache
*regcache
= get_thread_regcache (tp
);
2952 if (breakpoint_here_p (regcache
->aspace (),
2953 regcache_read_pc (regcache
))
2954 == ordinary_breakpoint_here
)
2957 tp
->stepping_over_breakpoint
= 0;
2963 /* Check whether thread TP still needs to start a step-over in order
2964 to make progress when resumed. Returns an bitwise or of enum
2965 step_over_what bits, indicating what needs to be stepped over. */
2967 static step_over_what
2968 thread_still_needs_step_over (struct thread_info
*tp
)
2970 step_over_what what
= 0;
2972 if (thread_still_needs_step_over_bp (tp
))
2973 what
|= STEP_OVER_BREAKPOINT
;
2975 if (tp
->stepping_over_watchpoint
2976 && !target_have_steppable_watchpoint ())
2977 what
|= STEP_OVER_WATCHPOINT
;
2982 /* Returns true if scheduler locking applies. STEP indicates whether
2983 we're about to do a step/next-like command to a thread. */
2986 schedlock_applies (struct thread_info
*tp
)
2988 return (scheduler_mode
== schedlock_on
2989 || (scheduler_mode
== schedlock_step
2990 && tp
->control
.stepping_command
)
2991 || (scheduler_mode
== schedlock_replay
2992 && target_record_will_replay (minus_one_ptid
,
2993 execution_direction
)));
2996 /* Set process_stratum_target::COMMIT_RESUMED_STATE in all target
2997 stacks that have threads executing and don't have threads with
3001 maybe_set_commit_resumed_all_targets ()
3003 scoped_restore_current_thread restore_thread
;
3005 for (inferior
*inf
: all_non_exited_inferiors ())
3007 process_stratum_target
*proc_target
= inf
->process_target ();
3009 if (proc_target
->commit_resumed_state
)
3011 /* We already set this in a previous iteration, via another
3012 inferior sharing the process_stratum target. */
3016 /* If the target has no resumed threads, it would be useless to
3017 ask it to commit the resumed threads. */
3018 if (!proc_target
->threads_executing
)
3020 infrun_debug_printf ("not requesting commit-resumed for target "
3021 "%s, no resumed threads",
3022 proc_target
->shortname ());
3026 /* As an optimization, if a thread from this target has some
3027 status to report, handle it before requiring the target to
3028 commit its resumed threads: handling the status might lead to
3029 resuming more threads. */
3030 if (proc_target
->has_resumed_with_pending_wait_status ())
3032 infrun_debug_printf ("not requesting commit-resumed for target %s, a"
3033 " thread has a pending waitstatus",
3034 proc_target
->shortname ());
3038 switch_to_inferior_no_thread (inf
);
3040 if (target_has_pending_events ())
3042 infrun_debug_printf ("not requesting commit-resumed for target %s, "
3043 "target has pending events",
3044 proc_target
->shortname ());
3048 infrun_debug_printf ("enabling commit-resumed for target %s",
3049 proc_target
->shortname ());
3051 proc_target
->commit_resumed_state
= true;
3058 maybe_call_commit_resumed_all_targets ()
3060 scoped_restore_current_thread restore_thread
;
3062 for (inferior
*inf
: all_non_exited_inferiors ())
3064 process_stratum_target
*proc_target
= inf
->process_target ();
3066 if (!proc_target
->commit_resumed_state
)
3069 switch_to_inferior_no_thread (inf
);
3071 infrun_debug_printf ("calling commit_resumed for target %s",
3072 proc_target
->shortname());
3074 target_commit_resumed ();
3078 /* To track nesting of scoped_disable_commit_resumed objects, ensuring
3079 that only the outermost one attempts to re-enable
3081 static bool enable_commit_resumed
= true;
3085 scoped_disable_commit_resumed::scoped_disable_commit_resumed
3086 (const char *reason
)
3087 : m_reason (reason
),
3088 m_prev_enable_commit_resumed (enable_commit_resumed
)
3090 infrun_debug_printf ("reason=%s", m_reason
);
3092 enable_commit_resumed
= false;
3094 for (inferior
*inf
: all_non_exited_inferiors ())
3096 process_stratum_target
*proc_target
= inf
->process_target ();
3098 if (m_prev_enable_commit_resumed
)
3100 /* This is the outermost instance: force all
3101 COMMIT_RESUMED_STATE to false. */
3102 proc_target
->commit_resumed_state
= false;
3106 /* This is not the outermost instance, we expect
3107 COMMIT_RESUMED_STATE to have been cleared by the
3108 outermost instance. */
3109 gdb_assert (!proc_target
->commit_resumed_state
);
3117 scoped_disable_commit_resumed::reset ()
3123 infrun_debug_printf ("reason=%s", m_reason
);
3125 gdb_assert (!enable_commit_resumed
);
3127 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3129 if (m_prev_enable_commit_resumed
)
3131 /* This is the outermost instance, re-enable
3132 COMMIT_RESUMED_STATE on the targets where it's possible. */
3133 maybe_set_commit_resumed_all_targets ();
3137 /* This is not the outermost instance, we expect
3138 COMMIT_RESUMED_STATE to still be false. */
3139 for (inferior
*inf
: all_non_exited_inferiors ())
3141 process_stratum_target
*proc_target
= inf
->process_target ();
3142 gdb_assert (!proc_target
->commit_resumed_state
);
3149 scoped_disable_commit_resumed::~scoped_disable_commit_resumed ()
3157 scoped_disable_commit_resumed::reset_and_commit ()
3160 maybe_call_commit_resumed_all_targets ();
3165 scoped_enable_commit_resumed::scoped_enable_commit_resumed
3166 (const char *reason
)
3167 : m_reason (reason
),
3168 m_prev_enable_commit_resumed (enable_commit_resumed
)
3170 infrun_debug_printf ("reason=%s", m_reason
);
3172 if (!enable_commit_resumed
)
3174 enable_commit_resumed
= true;
3176 /* Re-enable COMMIT_RESUMED_STATE on the targets where it's
3178 maybe_set_commit_resumed_all_targets ();
3180 maybe_call_commit_resumed_all_targets ();
3186 scoped_enable_commit_resumed::~scoped_enable_commit_resumed ()
3188 infrun_debug_printf ("reason=%s", m_reason
);
3190 gdb_assert (enable_commit_resumed
);
3192 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3194 if (!enable_commit_resumed
)
3196 /* Force all COMMIT_RESUMED_STATE back to false. */
3197 for (inferior
*inf
: all_non_exited_inferiors ())
3199 process_stratum_target
*proc_target
= inf
->process_target ();
3200 proc_target
->commit_resumed_state
= false;
3205 /* Check that all the targets we're about to resume are in non-stop
3206 mode. Ideally, we'd only care whether all targets support
3207 target-async, but we're not there yet. E.g., stop_all_threads
3208 doesn't know how to handle all-stop targets. Also, the remote
3209 protocol in all-stop mode is synchronous, irrespective of
3210 target-async, which means that things like a breakpoint re-set
3211 triggered by one target would try to read memory from all targets
3215 check_multi_target_resumption (process_stratum_target
*resume_target
)
3217 if (!non_stop
&& resume_target
== nullptr)
3219 scoped_restore_current_thread restore_thread
;
3221 /* This is used to track whether we're resuming more than one
3223 process_stratum_target
*first_connection
= nullptr;
3225 /* The first inferior we see with a target that does not work in
3226 always-non-stop mode. */
3227 inferior
*first_not_non_stop
= nullptr;
3229 for (inferior
*inf
: all_non_exited_inferiors ())
3231 switch_to_inferior_no_thread (inf
);
3233 if (!target_has_execution ())
3236 process_stratum_target
*proc_target
3237 = current_inferior ()->process_target();
3239 if (!target_is_non_stop_p ())
3240 first_not_non_stop
= inf
;
3242 if (first_connection
== nullptr)
3243 first_connection
= proc_target
;
3244 else if (first_connection
!= proc_target
3245 && first_not_non_stop
!= nullptr)
3247 switch_to_inferior_no_thread (first_not_non_stop
);
3249 proc_target
= current_inferior ()->process_target();
3251 error (_("Connection %d (%s) does not support "
3252 "multi-target resumption."),
3253 proc_target
->connection_number
,
3254 make_target_connection_string (proc_target
).c_str ());
3260 /* Basic routine for continuing the program in various fashions.
3262 ADDR is the address to resume at, or -1 for resume where stopped.
3263 SIGGNAL is the signal to give it, or GDB_SIGNAL_0 for none,
3264 or GDB_SIGNAL_DEFAULT for act according to how it stopped.
3266 You should call clear_proceed_status before calling proceed. */
3269 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
)
3271 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
3273 struct regcache
*regcache
;
3274 struct gdbarch
*gdbarch
;
3277 /* If we're stopped at a fork/vfork, follow the branch set by the
3278 "set follow-fork-mode" command; otherwise, we'll just proceed
3279 resuming the current thread. */
3280 if (!follow_fork ())
3282 /* The target for some reason decided not to resume. */
3284 if (target_can_async_p ())
3285 inferior_event_handler (INF_EXEC_COMPLETE
);
3289 /* We'll update this if & when we switch to a new thread. */
3290 update_previous_thread ();
3292 regcache
= get_current_regcache ();
3293 gdbarch
= regcache
->arch ();
3294 const address_space
*aspace
= regcache
->aspace ();
3296 pc
= regcache_read_pc_protected (regcache
);
3298 thread_info
*cur_thr
= inferior_thread ();
3300 /* Fill in with reasonable starting values. */
3301 init_thread_stepping_state (cur_thr
);
3303 gdb_assert (!thread_is_in_step_over_chain (cur_thr
));
3306 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
3307 process_stratum_target
*resume_target
3308 = user_visible_resume_target (resume_ptid
);
3310 check_multi_target_resumption (resume_target
);
3312 if (addr
== (CORE_ADDR
) -1)
3314 if (cur_thr
->stop_pc_p ()
3315 && pc
== cur_thr
->stop_pc ()
3316 && breakpoint_here_p (aspace
, pc
) == ordinary_breakpoint_here
3317 && execution_direction
!= EXEC_REVERSE
)
3318 /* There is a breakpoint at the address we will resume at,
3319 step one instruction before inserting breakpoints so that
3320 we do not stop right away (and report a second hit at this
3323 Note, we don't do this in reverse, because we won't
3324 actually be executing the breakpoint insn anyway.
3325 We'll be (un-)executing the previous instruction. */
3326 cur_thr
->stepping_over_breakpoint
= 1;
3327 else if (gdbarch_single_step_through_delay_p (gdbarch
)
3328 && gdbarch_single_step_through_delay (gdbarch
,
3329 get_current_frame ()))
3330 /* We stepped onto an instruction that needs to be stepped
3331 again before re-inserting the breakpoint, do so. */
3332 cur_thr
->stepping_over_breakpoint
= 1;
3336 regcache_write_pc (regcache
, addr
);
3339 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
3340 cur_thr
->set_stop_signal (siggnal
);
3342 /* If an exception is thrown from this point on, make sure to
3343 propagate GDB's knowledge of the executing state to the
3344 frontend/user running state. */
3345 scoped_finish_thread_state
finish_state (resume_target
, resume_ptid
);
3347 /* Even if RESUME_PTID is a wildcard, and we end up resuming fewer
3348 threads (e.g., we might need to set threads stepping over
3349 breakpoints first), from the user/frontend's point of view, all
3350 threads in RESUME_PTID are now running. Unless we're calling an
3351 inferior function, as in that case we pretend the inferior
3352 doesn't run at all. */
3353 if (!cur_thr
->control
.in_infcall
)
3354 set_running (resume_target
, resume_ptid
, true);
3356 infrun_debug_printf ("addr=%s, signal=%s", paddress (gdbarch
, addr
),
3357 gdb_signal_to_symbol_string (siggnal
));
3359 annotate_starting ();
3361 /* Make sure that output from GDB appears before output from the
3363 gdb_flush (gdb_stdout
);
3365 /* Since we've marked the inferior running, give it the terminal. A
3366 QUIT/Ctrl-C from here on is forwarded to the target (which can
3367 still detect attempts to unblock a stuck connection with repeated
3368 Ctrl-C from within target_pass_ctrlc). */
3369 target_terminal::inferior ();
3371 /* In a multi-threaded task we may select another thread and
3372 then continue or step.
3374 But if a thread that we're resuming had stopped at a breakpoint,
3375 it will immediately cause another breakpoint stop without any
3376 execution (i.e. it will report a breakpoint hit incorrectly). So
3377 we must step over it first.
3379 Look for threads other than the current (TP) that reported a
3380 breakpoint hit and haven't been resumed yet since. */
3382 /* If scheduler locking applies, we can avoid iterating over all
3384 if (!non_stop
&& !schedlock_applies (cur_thr
))
3386 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3389 switch_to_thread_no_regs (tp
);
3391 /* Ignore the current thread here. It's handled
3396 if (!thread_still_needs_step_over (tp
))
3399 gdb_assert (!thread_is_in_step_over_chain (tp
));
3401 infrun_debug_printf ("need to step-over [%s] first",
3402 tp
->ptid
.to_string ().c_str ());
3404 global_thread_step_over_chain_enqueue (tp
);
3407 switch_to_thread (cur_thr
);
3410 /* Enqueue the current thread last, so that we move all other
3411 threads over their breakpoints first. */
3412 if (cur_thr
->stepping_over_breakpoint
)
3413 global_thread_step_over_chain_enqueue (cur_thr
);
3415 /* If the thread isn't started, we'll still need to set its prev_pc,
3416 so that switch_back_to_stepped_thread knows the thread hasn't
3417 advanced. Must do this before resuming any thread, as in
3418 all-stop/remote, once we resume we can't send any other packet
3419 until the target stops again. */
3420 cur_thr
->prev_pc
= regcache_read_pc_protected (regcache
);
3423 scoped_disable_commit_resumed
disable_commit_resumed ("proceeding");
3424 bool step_over_started
= start_step_over ();
3426 if (step_over_info_valid_p ())
3428 /* Either this thread started a new in-line step over, or some
3429 other thread was already doing one. In either case, don't
3430 resume anything else until the step-over is finished. */
3432 else if (step_over_started
&& !target_is_non_stop_p ())
3434 /* A new displaced stepping sequence was started. In all-stop,
3435 we can't talk to the target anymore until it next stops. */
3437 else if (!non_stop
&& target_is_non_stop_p ())
3439 INFRUN_SCOPED_DEBUG_START_END
3440 ("resuming threads, all-stop-on-top-of-non-stop");
3442 /* In all-stop, but the target is always in non-stop mode.
3443 Start all other threads that are implicitly resumed too. */
3444 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3447 switch_to_thread_no_regs (tp
);
3449 if (!tp
->inf
->has_execution ())
3451 infrun_debug_printf ("[%s] target has no execution",
3452 tp
->ptid
.to_string ().c_str ());
3458 infrun_debug_printf ("[%s] resumed",
3459 tp
->ptid
.to_string ().c_str ());
3460 gdb_assert (tp
->executing () || tp
->has_pending_waitstatus ());
3464 if (thread_is_in_step_over_chain (tp
))
3466 infrun_debug_printf ("[%s] needs step-over",
3467 tp
->ptid
.to_string ().c_str ());
3471 /* If a thread of that inferior is waiting for a vfork-done
3472 (for a detached vfork child to exec or exit), breakpoints are
3473 removed. We must not resume any thread of that inferior, other
3474 than the one waiting for the vfork-done. */
3475 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr
3476 && tp
!= tp
->inf
->thread_waiting_for_vfork_done
)
3478 infrun_debug_printf ("[%s] another thread of this inferior is "
3479 "waiting for vfork-done",
3480 tp
->ptid
.to_string ().c_str ());
3484 infrun_debug_printf ("resuming %s",
3485 tp
->ptid
.to_string ().c_str ());
3487 execution_control_state
ecs (tp
);
3488 switch_to_thread (tp
);
3489 keep_going_pass_signal (&ecs
);
3490 if (!ecs
.wait_some_more
)
3491 error (_("Command aborted."));
3494 else if (!cur_thr
->resumed ()
3495 && !thread_is_in_step_over_chain (cur_thr
)
3496 /* In non-stop, forbid resuming a thread if some other thread of
3497 that inferior is waiting for a vfork-done event (this means
3498 breakpoints are out for this inferior). */
3500 && cur_thr
->inf
->thread_waiting_for_vfork_done
!= nullptr))
3502 /* The thread wasn't started, and isn't queued, run it now. */
3503 execution_control_state
ecs (cur_thr
);
3504 switch_to_thread (cur_thr
);
3505 keep_going_pass_signal (&ecs
);
3506 if (!ecs
.wait_some_more
)
3507 error (_("Command aborted."));
3510 disable_commit_resumed
.reset_and_commit ();
3513 finish_state
.release ();
3515 /* If we've switched threads above, switch back to the previously
3516 current thread. We don't want the user to see a different
3518 switch_to_thread (cur_thr
);
3520 /* Tell the event loop to wait for it to stop. If the target
3521 supports asynchronous execution, it'll do this from within
3523 if (!target_can_async_p ())
3524 mark_async_event_handler (infrun_async_inferior_event_token
);
3528 /* Start remote-debugging of a machine over a serial link. */
3531 start_remote (int from_tty
)
3533 inferior
*inf
= current_inferior ();
3534 inf
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
3536 /* Always go on waiting for the target, regardless of the mode. */
3537 /* FIXME: cagney/1999-09-23: At present it isn't possible to
3538 indicate to wait_for_inferior that a target should timeout if
3539 nothing is returned (instead of just blocking). Because of this,
3540 targets expecting an immediate response need to, internally, set
3541 things up so that the target_wait() is forced to eventually
3543 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
3544 differentiate to its caller what the state of the target is after
3545 the initial open has been performed. Here we're assuming that
3546 the target has stopped. It should be possible to eventually have
3547 target_open() return to the caller an indication that the target
3548 is currently running and GDB state should be set to the same as
3549 for an async run. */
3550 wait_for_inferior (inf
);
3552 /* Now that the inferior has stopped, do any bookkeeping like
3553 loading shared libraries. We want to do this before normal_stop,
3554 so that the displayed frame is up to date. */
3555 post_create_inferior (from_tty
);
3560 /* Initialize static vars when a new inferior begins. */
3563 init_wait_for_inferior (void)
3565 /* These are meaningless until the first time through wait_for_inferior. */
3567 breakpoint_init_inferior (inf_starting
);
3569 clear_proceed_status (0);
3571 nullify_last_target_wait_ptid ();
3573 update_previous_thread ();
3578 static void handle_inferior_event (struct execution_control_state
*ecs
);
3580 static void handle_step_into_function (struct gdbarch
*gdbarch
,
3581 struct execution_control_state
*ecs
);
3582 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
3583 struct execution_control_state
*ecs
);
3584 static void handle_signal_stop (struct execution_control_state
*ecs
);
3585 static void check_exception_resume (struct execution_control_state
*,
3588 static void end_stepping_range (struct execution_control_state
*ecs
);
3589 static void stop_waiting (struct execution_control_state
*ecs
);
3590 static void keep_going (struct execution_control_state
*ecs
);
3591 static void process_event_stop_test (struct execution_control_state
*ecs
);
3592 static bool switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
3594 /* This function is attached as a "thread_stop_requested" observer.
3595 Cleanup local state that assumed the PTID was to be resumed, and
3596 report the stop to the frontend. */
3599 infrun_thread_stop_requested (ptid_t ptid
)
3601 process_stratum_target
*curr_target
= current_inferior ()->process_target ();
3603 /* PTID was requested to stop. If the thread was already stopped,
3604 but the user/frontend doesn't know about that yet (e.g., the
3605 thread had been temporarily paused for some step-over), set up
3606 for reporting the stop now. */
3607 for (thread_info
*tp
: all_threads (curr_target
, ptid
))
3609 if (tp
->state
!= THREAD_RUNNING
)
3611 if (tp
->executing ())
3614 /* Remove matching threads from the step-over queue, so
3615 start_step_over doesn't try to resume them
3617 if (thread_is_in_step_over_chain (tp
))
3618 global_thread_step_over_chain_remove (tp
);
3620 /* If the thread is stopped, but the user/frontend doesn't
3621 know about that yet, queue a pending event, as if the
3622 thread had just stopped now. Unless the thread already had
3624 if (!tp
->has_pending_waitstatus ())
3626 target_waitstatus ws
;
3627 ws
.set_stopped (GDB_SIGNAL_0
);
3628 tp
->set_pending_waitstatus (ws
);
3631 /* Clear the inline-frame state, since we're re-processing the
3633 clear_inline_frame_state (tp
);
3635 /* If this thread was paused because some other thread was
3636 doing an inline-step over, let that finish first. Once
3637 that happens, we'll restart all threads and consume pending
3638 stop events then. */
3639 if (step_over_info_valid_p ())
3642 /* Otherwise we can process the (new) pending event now. Set
3643 it so this pending event is considered by
3645 tp
->set_resumed (true);
3649 /* Delete the step resume, single-step and longjmp/exception resume
3650 breakpoints of TP. */
3653 delete_thread_infrun_breakpoints (struct thread_info
*tp
)
3655 delete_step_resume_breakpoint (tp
);
3656 delete_exception_resume_breakpoint (tp
);
3657 delete_single_step_breakpoints (tp
);
3660 /* If the target still has execution, call FUNC for each thread that
3661 just stopped. In all-stop, that's all the non-exited threads; in
3662 non-stop, that's the current thread, only. */
3664 typedef void (*for_each_just_stopped_thread_callback_func
)
3665 (struct thread_info
*tp
);
3668 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func
)
3670 if (!target_has_execution () || inferior_ptid
== null_ptid
)
3673 if (target_is_non_stop_p ())
3675 /* If in non-stop mode, only the current thread stopped. */
3676 func (inferior_thread ());
3680 /* In all-stop mode, all threads have stopped. */
3681 for (thread_info
*tp
: all_non_exited_threads ())
3686 /* Delete the step resume and longjmp/exception resume breakpoints of
3687 the threads that just stopped. */
3690 delete_just_stopped_threads_infrun_breakpoints (void)
3692 for_each_just_stopped_thread (delete_thread_infrun_breakpoints
);
3695 /* Delete the single-step breakpoints of the threads that just
3699 delete_just_stopped_threads_single_step_breakpoints (void)
3701 for_each_just_stopped_thread (delete_single_step_breakpoints
);
3707 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
3708 const struct target_waitstatus
&ws
)
3710 infrun_debug_printf ("target_wait (%s [%s], status) =",
3711 waiton_ptid
.to_string ().c_str (),
3712 target_pid_to_str (waiton_ptid
).c_str ());
3713 infrun_debug_printf (" %s [%s],",
3714 result_ptid
.to_string ().c_str (),
3715 target_pid_to_str (result_ptid
).c_str ());
3716 infrun_debug_printf (" %s", ws
.to_string ().c_str ());
3719 /* Select a thread at random, out of those which are resumed and have
3722 static struct thread_info
*
3723 random_pending_event_thread (inferior
*inf
, ptid_t waiton_ptid
)
3725 process_stratum_target
*proc_target
= inf
->process_target ();
3727 = proc_target
->random_resumed_with_pending_wait_status (inf
, waiton_ptid
);
3729 if (thread
== nullptr)
3731 infrun_debug_printf ("None found.");
3735 infrun_debug_printf ("Found %s.", thread
->ptid
.to_string ().c_str ());
3736 gdb_assert (thread
->resumed ());
3737 gdb_assert (thread
->has_pending_waitstatus ());
3742 /* Wrapper for target_wait that first checks whether threads have
3743 pending statuses to report before actually asking the target for
3744 more events. INF is the inferior we're using to call target_wait
3748 do_target_wait_1 (inferior
*inf
, ptid_t ptid
,
3749 target_waitstatus
*status
, target_wait_flags options
)
3751 struct thread_info
*tp
;
3753 /* We know that we are looking for an event in the target of inferior
3754 INF, but we don't know which thread the event might come from. As
3755 such we want to make sure that INFERIOR_PTID is reset so that none of
3756 the wait code relies on it - doing so is always a mistake. */
3757 switch_to_inferior_no_thread (inf
);
3759 /* First check if there is a resumed thread with a wait status
3761 if (ptid
== minus_one_ptid
|| ptid
.is_pid ())
3763 tp
= random_pending_event_thread (inf
, ptid
);
3767 infrun_debug_printf ("Waiting for specific thread %s.",
3768 ptid
.to_string ().c_str ());
3770 /* We have a specific thread to check. */
3771 tp
= inf
->find_thread (ptid
);
3772 gdb_assert (tp
!= nullptr);
3773 if (!tp
->has_pending_waitstatus ())
3778 && (tp
->stop_reason () == TARGET_STOPPED_BY_SW_BREAKPOINT
3779 || tp
->stop_reason () == TARGET_STOPPED_BY_HW_BREAKPOINT
))
3781 struct regcache
*regcache
= get_thread_regcache (tp
);
3782 struct gdbarch
*gdbarch
= regcache
->arch ();
3786 pc
= regcache_read_pc (regcache
);
3788 if (pc
!= tp
->stop_pc ())
3790 infrun_debug_printf ("PC of %s changed. was=%s, now=%s",
3791 tp
->ptid
.to_string ().c_str (),
3792 paddress (gdbarch
, tp
->stop_pc ()),
3793 paddress (gdbarch
, pc
));
3796 else if (!breakpoint_inserted_here_p (regcache
->aspace (), pc
))
3798 infrun_debug_printf ("previous breakpoint of %s, at %s gone",
3799 tp
->ptid
.to_string ().c_str (),
3800 paddress (gdbarch
, pc
));
3807 infrun_debug_printf ("pending event of %s cancelled.",
3808 tp
->ptid
.to_string ().c_str ());
3810 tp
->clear_pending_waitstatus ();
3811 target_waitstatus ws
;
3813 tp
->set_pending_waitstatus (ws
);
3814 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
3820 infrun_debug_printf ("Using pending wait status %s for %s.",
3821 tp
->pending_waitstatus ().to_string ().c_str (),
3822 tp
->ptid
.to_string ().c_str ());
3824 /* Now that we've selected our final event LWP, un-adjust its PC
3825 if it was a software breakpoint (and the target doesn't
3826 always adjust the PC itself). */
3827 if (tp
->stop_reason () == TARGET_STOPPED_BY_SW_BREAKPOINT
3828 && !target_supports_stopped_by_sw_breakpoint ())
3830 struct regcache
*regcache
;
3831 struct gdbarch
*gdbarch
;
3834 regcache
= get_thread_regcache (tp
);
3835 gdbarch
= regcache
->arch ();
3837 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
3842 pc
= regcache_read_pc (regcache
);
3843 regcache_write_pc (regcache
, pc
+ decr_pc
);
3847 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
3848 *status
= tp
->pending_waitstatus ();
3849 tp
->clear_pending_waitstatus ();
3851 /* Wake up the event loop again, until all pending events are
3853 if (target_is_async_p ())
3854 mark_async_event_handler (infrun_async_inferior_event_token
);
3858 /* But if we don't find one, we'll have to wait. */
3860 /* We can't ask a non-async target to do a non-blocking wait, so this will be
3862 if (!target_can_async_p ())
3863 options
&= ~TARGET_WNOHANG
;
3865 return target_wait (ptid
, status
, options
);
3868 /* Wrapper for target_wait that first checks whether threads have
3869 pending statuses to report before actually asking the target for
3870 more events. Polls for events from all inferiors/targets. */
3873 do_target_wait (execution_control_state
*ecs
, target_wait_flags options
)
3875 int num_inferiors
= 0;
3876 int random_selector
;
3878 /* For fairness, we pick the first inferior/target to poll at random
3879 out of all inferiors that may report events, and then continue
3880 polling the rest of the inferior list starting from that one in a
3881 circular fashion until the whole list is polled once. */
3883 auto inferior_matches
= [] (inferior
*inf
)
3885 return inf
->process_target () != nullptr;
3888 /* First see how many matching inferiors we have. */
3889 for (inferior
*inf
: all_inferiors ())
3890 if (inferior_matches (inf
))
3893 if (num_inferiors
== 0)
3895 ecs
->ws
.set_ignore ();
3899 /* Now randomly pick an inferior out of those that matched. */
3900 random_selector
= (int)
3901 ((num_inferiors
* (double) rand ()) / (RAND_MAX
+ 1.0));
3903 if (num_inferiors
> 1)
3904 infrun_debug_printf ("Found %d inferiors, starting at #%d",
3905 num_inferiors
, random_selector
);
3907 /* Select the Nth inferior that matched. */
3909 inferior
*selected
= nullptr;
3911 for (inferior
*inf
: all_inferiors ())
3912 if (inferior_matches (inf
))
3913 if (random_selector
-- == 0)
3919 /* Now poll for events out of each of the matching inferior's
3920 targets, starting from the selected one. */
3922 auto do_wait
= [&] (inferior
*inf
)
3924 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, options
);
3925 ecs
->target
= inf
->process_target ();
3926 return (ecs
->ws
.kind () != TARGET_WAITKIND_IGNORE
);
3929 /* Needed in 'all-stop + target-non-stop' mode, because we end up
3930 here spuriously after the target is all stopped and we've already
3931 reported the stop to the user, polling for events. */
3932 scoped_restore_current_thread restore_thread
;
3934 intrusive_list_iterator
<inferior
> start
3935 = inferior_list
.iterator_to (*selected
);
3937 for (intrusive_list_iterator
<inferior
> it
= start
;
3938 it
!= inferior_list
.end ();
3941 inferior
*inf
= &*it
;
3943 if (inferior_matches (inf
) && do_wait (inf
))
3947 for (intrusive_list_iterator
<inferior
> it
= inferior_list
.begin ();
3951 inferior
*inf
= &*it
;
3953 if (inferior_matches (inf
) && do_wait (inf
))
3957 ecs
->ws
.set_ignore ();
3961 /* An event reported by wait_one. */
3963 struct wait_one_event
3965 /* The target the event came out of. */
3966 process_stratum_target
*target
;
3968 /* The PTID the event was for. */
3971 /* The waitstatus. */
3972 target_waitstatus ws
;
3975 static bool handle_one (const wait_one_event
&event
);
3977 /* Prepare and stabilize the inferior for detaching it. E.g.,
3978 detaching while a thread is displaced stepping is a recipe for
3979 crashing it, as nothing would readjust the PC out of the scratch
3983 prepare_for_detach (void)
3985 struct inferior
*inf
= current_inferior ();
3986 ptid_t pid_ptid
= ptid_t (inf
->pid
);
3987 scoped_restore_current_thread restore_thread
;
3989 scoped_restore restore_detaching
= make_scoped_restore (&inf
->detaching
, true);
3991 /* Remove all threads of INF from the global step-over chain. We
3992 want to stop any ongoing step-over, not start any new one. */
3993 thread_step_over_list_safe_range range
3994 = make_thread_step_over_list_safe_range (global_thread_step_over_list
);
3996 for (thread_info
*tp
: range
)
3999 infrun_debug_printf ("removing thread %s from global step over chain",
4000 tp
->ptid
.to_string ().c_str ());
4001 global_thread_step_over_chain_remove (tp
);
4004 /* If we were already in the middle of an inline step-over, and the
4005 thread stepping belongs to the inferior we're detaching, we need
4006 to restart the threads of other inferiors. */
4007 if (step_over_info
.thread
!= -1)
4009 infrun_debug_printf ("inline step-over in-process while detaching");
4011 thread_info
*thr
= find_thread_global_id (step_over_info
.thread
);
4012 if (thr
->inf
== inf
)
4014 /* Since we removed threads of INF from the step-over chain,
4015 we know this won't start a step-over for INF. */
4016 clear_step_over_info ();
4018 if (target_is_non_stop_p ())
4020 /* Start a new step-over in another thread if there's
4021 one that needs it. */
4024 /* Restart all other threads (except the
4025 previously-stepping thread, since that one is still
4027 if (!step_over_info_valid_p ())
4028 restart_threads (thr
);
4033 if (displaced_step_in_progress (inf
))
4035 infrun_debug_printf ("displaced-stepping in-process while detaching");
4037 /* Stop threads currently displaced stepping, aborting it. */
4039 for (thread_info
*thr
: inf
->non_exited_threads ())
4041 if (thr
->displaced_step_state
.in_progress ())
4043 if (thr
->executing ())
4045 if (!thr
->stop_requested
)
4047 target_stop (thr
->ptid
);
4048 thr
->stop_requested
= true;
4052 thr
->set_resumed (false);
4056 while (displaced_step_in_progress (inf
))
4058 wait_one_event event
;
4060 event
.target
= inf
->process_target ();
4061 event
.ptid
= do_target_wait_1 (inf
, pid_ptid
, &event
.ws
, 0);
4064 print_target_wait_results (pid_ptid
, event
.ptid
, event
.ws
);
4069 /* It's OK to leave some of the threads of INF stopped, since
4070 they'll be detached shortly. */
4074 /* If all-stop, but there exists a non-stop target, stop all threads
4075 now that we're presenting the stop to the user. */
4078 stop_all_threads_if_all_stop_mode ()
4080 if (!non_stop
&& exists_non_stop_target ())
4081 stop_all_threads ("presenting stop to user in all-stop");
4084 /* Wait for control to return from inferior to debugger.
4086 If inferior gets a signal, we may decide to start it up again
4087 instead of returning. That is why there is a loop in this function.
4088 When this function actually returns it means the inferior
4089 should be left stopped and GDB should read more commands. */
4092 wait_for_inferior (inferior
*inf
)
4094 infrun_debug_printf ("wait_for_inferior ()");
4096 SCOPE_EXIT
{ delete_just_stopped_threads_infrun_breakpoints (); };
4098 /* If an error happens while handling the event, propagate GDB's
4099 knowledge of the executing state to the frontend/user running
4101 scoped_finish_thread_state finish_state
4102 (inf
->process_target (), minus_one_ptid
);
4106 execution_control_state ecs
;
4108 overlay_cache_invalid
= 1;
4110 /* Flush target cache before starting to handle each event.
4111 Target was running and cache could be stale. This is just a
4112 heuristic. Running threads may modify target memory, but we
4113 don't get any event. */
4114 target_dcache_invalidate ();
4116 ecs
.ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
.ws
, 0);
4117 ecs
.target
= inf
->process_target ();
4120 print_target_wait_results (minus_one_ptid
, ecs
.ptid
, ecs
.ws
);
4122 /* Now figure out what to do with the result of the result. */
4123 handle_inferior_event (&ecs
);
4125 if (!ecs
.wait_some_more
)
4129 stop_all_threads_if_all_stop_mode ();
4131 /* No error, don't finish the state yet. */
4132 finish_state
.release ();
4135 /* Cleanup that reinstalls the readline callback handler, if the
4136 target is running in the background. If while handling the target
4137 event something triggered a secondary prompt, like e.g., a
4138 pagination prompt, we'll have removed the callback handler (see
4139 gdb_readline_wrapper_line). Need to do this as we go back to the
4140 event loop, ready to process further input. Note this has no
4141 effect if the handler hasn't actually been removed, because calling
4142 rl_callback_handler_install resets the line buffer, thus losing
4146 reinstall_readline_callback_handler_cleanup ()
4148 struct ui
*ui
= current_ui
;
4152 /* We're not going back to the top level event loop yet. Don't
4153 install the readline callback, as it'd prep the terminal,
4154 readline-style (raw, noecho) (e.g., --batch). We'll install
4155 it the next time the prompt is displayed, when we're ready
4160 if (ui
->command_editing
&& ui
->prompt_state
!= PROMPT_BLOCKED
)
4161 gdb_rl_callback_handler_reinstall ();
4164 /* Clean up the FSMs of threads that are now stopped. In non-stop,
4165 that's just the event thread. In all-stop, that's all threads. */
4168 clean_up_just_stopped_threads_fsms (struct execution_control_state
*ecs
)
4170 /* The first clean_up call below assumes the event thread is the current
4172 if (ecs
->event_thread
!= nullptr)
4173 gdb_assert (ecs
->event_thread
== inferior_thread ());
4175 if (ecs
->event_thread
!= nullptr
4176 && ecs
->event_thread
->thread_fsm () != nullptr)
4177 ecs
->event_thread
->thread_fsm ()->clean_up (ecs
->event_thread
);
4181 scoped_restore_current_thread restore_thread
;
4183 for (thread_info
*thr
: all_non_exited_threads ())
4185 if (thr
->thread_fsm () == nullptr)
4187 if (thr
== ecs
->event_thread
)
4190 switch_to_thread (thr
);
4191 thr
->thread_fsm ()->clean_up (thr
);
4196 /* Helper for all_uis_check_sync_execution_done that works on the
4200 check_curr_ui_sync_execution_done (void)
4202 struct ui
*ui
= current_ui
;
4204 if (ui
->prompt_state
== PROMPT_NEEDED
4206 && !gdb_in_secondary_prompt_p (ui
))
4208 target_terminal::ours ();
4209 gdb::observers::sync_execution_done
.notify ();
4210 ui
->register_file_handler ();
4217 all_uis_check_sync_execution_done (void)
4219 SWITCH_THRU_ALL_UIS ()
4221 check_curr_ui_sync_execution_done ();
4228 all_uis_on_sync_execution_starting (void)
4230 SWITCH_THRU_ALL_UIS ()
4232 if (current_ui
->prompt_state
== PROMPT_NEEDED
)
4233 async_disable_stdin ();
4237 /* A quit_handler callback installed while we're handling inferior
4241 infrun_quit_handler ()
4243 if (target_terminal::is_ours ())
4247 default_quit_handler would throw a quit in this case, but if
4248 we're handling an event while we have the terminal, it means
4249 the target is running a background execution command, and
4250 thus when users press Ctrl-C, they're wanting to interrupt
4251 whatever command they were executing in the command line.
4255 (gdb) foo bar whatever<ctrl-c>
4257 That Ctrl-C should clear the input line, not interrupt event
4258 handling if it happens that the user types Ctrl-C at just the
4261 It's as-if background event handling was handled by a
4262 separate background thread.
4264 To be clear, the Ctrl-C is not lost -- it will be processed
4265 by the next QUIT call once we're out of fetch_inferior_event
4270 if (check_quit_flag ())
4271 target_pass_ctrlc ();
4275 /* Asynchronous version of wait_for_inferior. It is called by the
4276 event loop whenever a change of state is detected on the file
4277 descriptor corresponding to the target. It can be called more than
4278 once to complete a single execution command. In such cases we need
4279 to keep the state in a global variable ECSS. If it is the last time
4280 that this function is called for a single execution command, then
4281 report to the user that the inferior has stopped, and do the
4282 necessary cleanups. */
4285 fetch_inferior_event ()
4287 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
4289 execution_control_state ecs
;
4292 /* Events are always processed with the main UI as current UI. This
4293 way, warnings, debug output, etc. are always consistently sent to
4294 the main console. */
4295 scoped_restore save_ui
= make_scoped_restore (¤t_ui
, main_ui
);
4297 /* Temporarily disable pagination. Otherwise, the user would be
4298 given an option to press 'q' to quit, which would cause an early
4299 exit and could leave GDB in a half-baked state. */
4300 scoped_restore save_pagination
4301 = make_scoped_restore (&pagination_enabled
, false);
4303 /* Install a quit handler that does nothing if we have the terminal
4304 (meaning the target is running a background execution command),
4305 so that Ctrl-C never interrupts GDB before the event is fully
4307 scoped_restore restore_quit_handler
4308 = make_scoped_restore (&quit_handler
, infrun_quit_handler
);
4310 /* Make sure a SIGINT does not interrupt an extension language while
4311 we're handling an event. That could interrupt a Python unwinder
4312 or a Python observer or some such. A Ctrl-C should either be
4313 forwarded to the inferior if the inferior has the terminal, or,
4314 if GDB has the terminal, should interrupt the command the user is
4315 typing in the CLI. */
4316 scoped_disable_cooperative_sigint_handling restore_coop_sigint
;
4318 /* End up with readline processing input, if necessary. */
4320 SCOPE_EXIT
{ reinstall_readline_callback_handler_cleanup (); };
4322 /* We're handling a live event, so make sure we're doing live
4323 debugging. If we're looking at traceframes while the target is
4324 running, we're going to need to get back to that mode after
4325 handling the event. */
4326 gdb::optional
<scoped_restore_current_traceframe
> maybe_restore_traceframe
;
4329 maybe_restore_traceframe
.emplace ();
4330 set_current_traceframe (-1);
4333 /* The user/frontend should not notice a thread switch due to
4334 internal events. Make sure we revert to the user selected
4335 thread and frame after handling the event and running any
4336 breakpoint commands. */
4337 scoped_restore_current_thread restore_thread
;
4339 overlay_cache_invalid
= 1;
4340 /* Flush target cache before starting to handle each event. Target
4341 was running and cache could be stale. This is just a heuristic.
4342 Running threads may modify target memory, but we don't get any
4344 target_dcache_invalidate ();
4346 scoped_restore save_exec_dir
4347 = make_scoped_restore (&execution_direction
,
4348 target_execution_direction ());
4350 /* Allow targets to pause their resumed threads while we handle
4352 scoped_disable_commit_resumed
disable_commit_resumed ("handling event");
4354 if (!do_target_wait (&ecs
, TARGET_WNOHANG
))
4356 infrun_debug_printf ("do_target_wait returned no event");
4357 disable_commit_resumed
.reset_and_commit ();
4361 gdb_assert (ecs
.ws
.kind () != TARGET_WAITKIND_IGNORE
);
4363 /* Switch to the inferior that generated the event, so we can do
4364 target calls. If the event was not associated to a ptid, */
4365 if (ecs
.ptid
!= null_ptid
4366 && ecs
.ptid
!= minus_one_ptid
)
4367 switch_to_inferior_no_thread (find_inferior_ptid (ecs
.target
, ecs
.ptid
));
4369 switch_to_target_no_thread (ecs
.target
);
4372 print_target_wait_results (minus_one_ptid
, ecs
.ptid
, ecs
.ws
);
4374 /* If an error happens while handling the event, propagate GDB's
4375 knowledge of the executing state to the frontend/user running
4377 ptid_t finish_ptid
= !target_is_non_stop_p () ? minus_one_ptid
: ecs
.ptid
;
4378 scoped_finish_thread_state
finish_state (ecs
.target
, finish_ptid
);
4380 /* Get executed before scoped_restore_current_thread above to apply
4381 still for the thread which has thrown the exception. */
4382 auto defer_bpstat_clear
4383 = make_scope_exit (bpstat_clear_actions
);
4384 auto defer_delete_threads
4385 = make_scope_exit (delete_just_stopped_threads_infrun_breakpoints
);
4387 /* Now figure out what to do with the result of the result. */
4388 handle_inferior_event (&ecs
);
4390 if (!ecs
.wait_some_more
)
4392 struct inferior
*inf
= find_inferior_ptid (ecs
.target
, ecs
.ptid
);
4393 bool should_stop
= true;
4394 struct thread_info
*thr
= ecs
.event_thread
;
4396 delete_just_stopped_threads_infrun_breakpoints ();
4398 if (thr
!= nullptr && thr
->thread_fsm () != nullptr)
4399 should_stop
= thr
->thread_fsm ()->should_stop (thr
);
4407 bool should_notify_stop
= true;
4408 bool proceeded
= false;
4410 stop_all_threads_if_all_stop_mode ();
4412 clean_up_just_stopped_threads_fsms (&ecs
);
4414 if (thr
!= nullptr && thr
->thread_fsm () != nullptr)
4416 = thr
->thread_fsm ()->should_notify_stop ();
4418 if (should_notify_stop
)
4420 /* We may not find an inferior if this was a process exit. */
4421 if (inf
== nullptr || inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
4422 proceeded
= normal_stop ();
4427 inferior_event_handler (INF_EXEC_COMPLETE
);
4431 /* If we got a TARGET_WAITKIND_NO_RESUMED event, then the
4432 previously selected thread is gone. We have two
4433 choices - switch to no thread selected, or restore the
4434 previously selected thread (now exited). We chose the
4435 later, just because that's what GDB used to do. After
4436 this, "info threads" says "The current thread <Thread
4437 ID 2> has terminated." instead of "No thread
4441 && ecs
.ws
.kind () != TARGET_WAITKIND_NO_RESUMED
)
4442 restore_thread
.dont_restore ();
4446 defer_delete_threads
.release ();
4447 defer_bpstat_clear
.release ();
4449 /* No error, don't finish the thread states yet. */
4450 finish_state
.release ();
4452 disable_commit_resumed
.reset_and_commit ();
4454 /* This scope is used to ensure that readline callbacks are
4455 reinstalled here. */
4458 /* Handling this event might have caused some inferiors to become prunable.
4459 For example, the exit of an inferior that was automatically added. Try
4460 to get rid of them. Keeping those around slows down things linearly.
4462 Note that this never removes the current inferior. Therefore, call this
4463 after RESTORE_THREAD went out of scope, in case the event inferior (which was
4464 temporarily made the current inferior) is meant to be deleted.
4466 Call this before all_uis_check_sync_execution_done, so that notifications about
4467 removed inferiors appear before the prompt. */
4470 /* If a UI was in sync execution mode, and now isn't, restore its
4471 prompt (a synchronous execution command has finished, and we're
4472 ready for input). */
4473 all_uis_check_sync_execution_done ();
4476 && exec_done_display_p
4477 && (inferior_ptid
== null_ptid
4478 || inferior_thread ()->state
!= THREAD_RUNNING
))
4479 gdb_printf (_("completed.\n"));
4485 set_step_info (thread_info
*tp
, frame_info_ptr frame
,
4486 struct symtab_and_line sal
)
4488 /* This can be removed once this function no longer implicitly relies on the
4489 inferior_ptid value. */
4490 gdb_assert (inferior_ptid
== tp
->ptid
);
4492 tp
->control
.step_frame_id
= get_frame_id (frame
);
4493 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
4495 tp
->current_symtab
= sal
.symtab
;
4496 tp
->current_line
= sal
.line
;
4499 ("symtab = %s, line = %d, step_frame_id = %s, step_stack_frame_id = %s",
4500 tp
->current_symtab
!= nullptr ? tp
->current_symtab
->filename
: "<null>",
4502 tp
->control
.step_frame_id
.to_string ().c_str (),
4503 tp
->control
.step_stack_frame_id
.to_string ().c_str ());
4506 /* Clear context switchable stepping state. */
4509 init_thread_stepping_state (struct thread_info
*tss
)
4511 tss
->stepped_breakpoint
= 0;
4512 tss
->stepping_over_breakpoint
= 0;
4513 tss
->stepping_over_watchpoint
= 0;
4514 tss
->step_after_step_resume_breakpoint
= 0;
4520 set_last_target_status (process_stratum_target
*target
, ptid_t ptid
,
4521 const target_waitstatus
&status
)
4523 target_last_proc_target
= target
;
4524 target_last_wait_ptid
= ptid
;
4525 target_last_waitstatus
= status
;
4531 get_last_target_status (process_stratum_target
**target
, ptid_t
*ptid
,
4532 target_waitstatus
*status
)
4534 if (target
!= nullptr)
4535 *target
= target_last_proc_target
;
4536 if (ptid
!= nullptr)
4537 *ptid
= target_last_wait_ptid
;
4538 if (status
!= nullptr)
4539 *status
= target_last_waitstatus
;
4545 nullify_last_target_wait_ptid (void)
4547 target_last_proc_target
= nullptr;
4548 target_last_wait_ptid
= minus_one_ptid
;
4549 target_last_waitstatus
= {};
4552 /* Switch thread contexts. */
4555 context_switch (execution_control_state
*ecs
)
4557 if (ecs
->ptid
!= inferior_ptid
4558 && (inferior_ptid
== null_ptid
4559 || ecs
->event_thread
!= inferior_thread ()))
4561 infrun_debug_printf ("Switching context from %s to %s",
4562 inferior_ptid
.to_string ().c_str (),
4563 ecs
->ptid
.to_string ().c_str ());
4566 switch_to_thread (ecs
->event_thread
);
4569 /* If the target can't tell whether we've hit breakpoints
4570 (target_supports_stopped_by_sw_breakpoint), and we got a SIGTRAP,
4571 check whether that could have been caused by a breakpoint. If so,
4572 adjust the PC, per gdbarch_decr_pc_after_break. */
4575 adjust_pc_after_break (struct thread_info
*thread
,
4576 const target_waitstatus
&ws
)
4578 struct regcache
*regcache
;
4579 struct gdbarch
*gdbarch
;
4580 CORE_ADDR breakpoint_pc
, decr_pc
;
4582 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
4583 we aren't, just return.
4585 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
4586 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
4587 implemented by software breakpoints should be handled through the normal
4590 NOTE drow/2004-01-31: On some targets, breakpoints may generate
4591 different signals (SIGILL or SIGEMT for instance), but it is less
4592 clear where the PC is pointing afterwards. It may not match
4593 gdbarch_decr_pc_after_break. I don't know any specific target that
4594 generates these signals at breakpoints (the code has been in GDB since at
4595 least 1992) so I can not guess how to handle them here.
4597 In earlier versions of GDB, a target with
4598 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
4599 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
4600 target with both of these set in GDB history, and it seems unlikely to be
4601 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
4603 if (ws
.kind () != TARGET_WAITKIND_STOPPED
)
4606 if (ws
.sig () != GDB_SIGNAL_TRAP
)
4609 /* In reverse execution, when a breakpoint is hit, the instruction
4610 under it has already been de-executed. The reported PC always
4611 points at the breakpoint address, so adjusting it further would
4612 be wrong. E.g., consider this case on a decr_pc_after_break == 1
4615 B1 0x08000000 : INSN1
4616 B2 0x08000001 : INSN2
4618 PC -> 0x08000003 : INSN4
4620 Say you're stopped at 0x08000003 as above. Reverse continuing
4621 from that point should hit B2 as below. Reading the PC when the
4622 SIGTRAP is reported should read 0x08000001 and INSN2 should have
4623 been de-executed already.
4625 B1 0x08000000 : INSN1
4626 B2 PC -> 0x08000001 : INSN2
4630 We can't apply the same logic as for forward execution, because
4631 we would wrongly adjust the PC to 0x08000000, since there's a
4632 breakpoint at PC - 1. We'd then report a hit on B1, although
4633 INSN1 hadn't been de-executed yet. Doing nothing is the correct
4635 if (execution_direction
== EXEC_REVERSE
)
4638 /* If the target can tell whether the thread hit a SW breakpoint,
4639 trust it. Targets that can tell also adjust the PC
4641 if (target_supports_stopped_by_sw_breakpoint ())
4644 /* Note that relying on whether a breakpoint is planted in memory to
4645 determine this can fail. E.g,. the breakpoint could have been
4646 removed since. Or the thread could have been told to step an
4647 instruction the size of a breakpoint instruction, and only
4648 _after_ was a breakpoint inserted at its address. */
4650 /* If this target does not decrement the PC after breakpoints, then
4651 we have nothing to do. */
4652 regcache
= get_thread_regcache (thread
);
4653 gdbarch
= regcache
->arch ();
4655 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4659 const address_space
*aspace
= regcache
->aspace ();
4661 /* Find the location where (if we've hit a breakpoint) the
4662 breakpoint would be. */
4663 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
4665 /* If the target can't tell whether a software breakpoint triggered,
4666 fallback to figuring it out based on breakpoints we think were
4667 inserted in the target, and on whether the thread was stepped or
4670 /* Check whether there actually is a software breakpoint inserted at
4673 If in non-stop mode, a race condition is possible where we've
4674 removed a breakpoint, but stop events for that breakpoint were
4675 already queued and arrive later. To suppress those spurious
4676 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
4677 and retire them after a number of stop events are reported. Note
4678 this is an heuristic and can thus get confused. The real fix is
4679 to get the "stopped by SW BP and needs adjustment" info out of
4680 the target/kernel (and thus never reach here; see above). */
4681 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
4682 || (target_is_non_stop_p ()
4683 && moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
4685 gdb::optional
<scoped_restore_tmpl
<int>> restore_operation_disable
;
4687 if (record_full_is_used ())
4688 restore_operation_disable
.emplace
4689 (record_full_gdb_operation_disable_set ());
4691 /* When using hardware single-step, a SIGTRAP is reported for both
4692 a completed single-step and a software breakpoint. Need to
4693 differentiate between the two, as the latter needs adjusting
4694 but the former does not.
4696 The SIGTRAP can be due to a completed hardware single-step only if
4697 - we didn't insert software single-step breakpoints
4698 - this thread is currently being stepped
4700 If any of these events did not occur, we must have stopped due
4701 to hitting a software breakpoint, and have to back up to the
4704 As a special case, we could have hardware single-stepped a
4705 software breakpoint. In this case (prev_pc == breakpoint_pc),
4706 we also need to back up to the breakpoint address. */
4708 if (thread_has_single_step_breakpoints_set (thread
)
4709 || !currently_stepping (thread
)
4710 || (thread
->stepped_breakpoint
4711 && thread
->prev_pc
== breakpoint_pc
))
4712 regcache_write_pc (regcache
, breakpoint_pc
);
4717 stepped_in_from (frame_info_ptr frame
, struct frame_id step_frame_id
)
4719 for (frame
= get_prev_frame (frame
);
4721 frame
= get_prev_frame (frame
))
4723 if (get_frame_id (frame
) == step_frame_id
)
4726 if (get_frame_type (frame
) != INLINE_FRAME
)
4733 /* Look for an inline frame that is marked for skip.
4734 If PREV_FRAME is TRUE start at the previous frame,
4735 otherwise start at the current frame. Stop at the
4736 first non-inline frame, or at the frame where the
4740 inline_frame_is_marked_for_skip (bool prev_frame
, struct thread_info
*tp
)
4742 frame_info_ptr frame
= get_current_frame ();
4745 frame
= get_prev_frame (frame
);
4747 for (; frame
!= nullptr; frame
= get_prev_frame (frame
))
4749 const char *fn
= nullptr;
4750 symtab_and_line sal
;
4753 if (get_frame_id (frame
) == tp
->control
.step_frame_id
)
4755 if (get_frame_type (frame
) != INLINE_FRAME
)
4758 sal
= find_frame_sal (frame
);
4759 sym
= get_frame_function (frame
);
4762 fn
= sym
->print_name ();
4765 && function_name_is_marked_for_skip (fn
, sal
))
4772 /* If the event thread has the stop requested flag set, pretend it
4773 stopped for a GDB_SIGNAL_0 (i.e., as if it stopped due to
4777 handle_stop_requested (struct execution_control_state
*ecs
)
4779 if (ecs
->event_thread
->stop_requested
)
4781 ecs
->ws
.set_stopped (GDB_SIGNAL_0
);
4782 handle_signal_stop (ecs
);
4788 /* Auxiliary function that handles syscall entry/return events.
4789 It returns true if the inferior should keep going (and GDB
4790 should ignore the event), or false if the event deserves to be
4794 handle_syscall_event (struct execution_control_state
*ecs
)
4796 struct regcache
*regcache
;
4799 context_switch (ecs
);
4801 regcache
= get_thread_regcache (ecs
->event_thread
);
4802 syscall_number
= ecs
->ws
.syscall_number ();
4803 ecs
->event_thread
->set_stop_pc (regcache_read_pc (regcache
));
4805 if (catch_syscall_enabled () > 0
4806 && catching_syscall_number (syscall_number
))
4808 infrun_debug_printf ("syscall number=%d", syscall_number
);
4810 ecs
->event_thread
->control
.stop_bpstat
4811 = bpstat_stop_status_nowatch (regcache
->aspace (),
4812 ecs
->event_thread
->stop_pc (),
4813 ecs
->event_thread
, ecs
->ws
);
4815 if (handle_stop_requested (ecs
))
4818 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4820 /* Catchpoint hit. */
4825 if (handle_stop_requested (ecs
))
4828 /* If no catchpoint triggered for this, then keep going. */
4834 /* Lazily fill in the execution_control_state's stop_func_* fields. */
4837 fill_in_stop_func (struct gdbarch
*gdbarch
,
4838 struct execution_control_state
*ecs
)
4840 if (!ecs
->stop_func_filled_in
)
4843 const general_symbol_info
*gsi
;
4845 /* Don't care about return value; stop_func_start and stop_func_name
4846 will both be 0 if it doesn't work. */
4847 find_pc_partial_function_sym (ecs
->event_thread
->stop_pc (),
4849 &ecs
->stop_func_start
,
4850 &ecs
->stop_func_end
,
4852 ecs
->stop_func_name
= gsi
== nullptr ? nullptr : gsi
->print_name ();
4854 /* The call to find_pc_partial_function, above, will set
4855 stop_func_start and stop_func_end to the start and end
4856 of the range containing the stop pc. If this range
4857 contains the entry pc for the block (which is always the
4858 case for contiguous blocks), advance stop_func_start past
4859 the function's start offset and entrypoint. Note that
4860 stop_func_start is NOT advanced when in a range of a
4861 non-contiguous block that does not contain the entry pc. */
4862 if (block
!= nullptr
4863 && ecs
->stop_func_start
<= block
->entry_pc ()
4864 && block
->entry_pc () < ecs
->stop_func_end
)
4866 ecs
->stop_func_start
4867 += gdbarch_deprecated_function_start_offset (gdbarch
);
4869 /* PowerPC functions have a Local Entry Point (LEP) and a Global
4870 Entry Point (GEP). There is only one Entry Point (GEP = LEP) for
4871 other architectures. */
4872 ecs
->stop_func_alt_start
= ecs
->stop_func_start
;
4874 if (gdbarch_skip_entrypoint_p (gdbarch
))
4875 ecs
->stop_func_start
4876 = gdbarch_skip_entrypoint (gdbarch
, ecs
->stop_func_start
);
4879 ecs
->stop_func_filled_in
= 1;
4884 /* Return the STOP_SOON field of the inferior pointed at by ECS. */
4886 static enum stop_kind
4887 get_inferior_stop_soon (execution_control_state
*ecs
)
4889 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
4891 gdb_assert (inf
!= nullptr);
4892 return inf
->control
.stop_soon
;
4895 /* Poll for one event out of the current target. Store the resulting
4896 waitstatus in WS, and return the event ptid. Does not block. */
4899 poll_one_curr_target (struct target_waitstatus
*ws
)
4903 overlay_cache_invalid
= 1;
4905 /* Flush target cache before starting to handle each event.
4906 Target was running and cache could be stale. This is just a
4907 heuristic. Running threads may modify target memory, but we
4908 don't get any event. */
4909 target_dcache_invalidate ();
4911 event_ptid
= target_wait (minus_one_ptid
, ws
, TARGET_WNOHANG
);
4914 print_target_wait_results (minus_one_ptid
, event_ptid
, *ws
);
4919 /* Wait for one event out of any target. */
4921 static wait_one_event
4926 for (inferior
*inf
: all_inferiors ())
4928 process_stratum_target
*target
= inf
->process_target ();
4929 if (target
== nullptr
4930 || !target
->is_async_p ()
4931 || !target
->threads_executing
)
4934 switch_to_inferior_no_thread (inf
);
4936 wait_one_event event
;
4937 event
.target
= target
;
4938 event
.ptid
= poll_one_curr_target (&event
.ws
);
4940 if (event
.ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
4942 /* If nothing is resumed, remove the target from the
4944 target_async (false);
4946 else if (event
.ws
.kind () != TARGET_WAITKIND_IGNORE
)
4950 /* Block waiting for some event. */
4957 for (inferior
*inf
: all_inferiors ())
4959 process_stratum_target
*target
= inf
->process_target ();
4960 if (target
== nullptr
4961 || !target
->is_async_p ()
4962 || !target
->threads_executing
)
4965 int fd
= target
->async_wait_fd ();
4966 FD_SET (fd
, &readfds
);
4973 /* No waitable targets left. All must be stopped. */
4974 target_waitstatus ws
;
4975 ws
.set_no_resumed ();
4976 return {nullptr, minus_one_ptid
, std::move (ws
)};
4981 int numfds
= interruptible_select (nfds
, &readfds
, 0, nullptr, 0);
4987 perror_with_name ("interruptible_select");
4992 /* Save the thread's event and stop reason to process it later. */
4995 save_waitstatus (struct thread_info
*tp
, const target_waitstatus
&ws
)
4997 infrun_debug_printf ("saving status %s for %s",
4998 ws
.to_string ().c_str (),
4999 tp
->ptid
.to_string ().c_str ());
5001 /* Record for later. */
5002 tp
->set_pending_waitstatus (ws
);
5004 if (ws
.kind () == TARGET_WAITKIND_STOPPED
5005 && ws
.sig () == GDB_SIGNAL_TRAP
)
5007 struct regcache
*regcache
= get_thread_regcache (tp
);
5008 const address_space
*aspace
= regcache
->aspace ();
5009 CORE_ADDR pc
= regcache_read_pc (regcache
);
5011 adjust_pc_after_break (tp
, tp
->pending_waitstatus ());
5013 scoped_restore_current_thread restore_thread
;
5014 switch_to_thread (tp
);
5016 if (target_stopped_by_watchpoint ())
5017 tp
->set_stop_reason (TARGET_STOPPED_BY_WATCHPOINT
);
5018 else if (target_supports_stopped_by_sw_breakpoint ()
5019 && target_stopped_by_sw_breakpoint ())
5020 tp
->set_stop_reason (TARGET_STOPPED_BY_SW_BREAKPOINT
);
5021 else if (target_supports_stopped_by_hw_breakpoint ()
5022 && target_stopped_by_hw_breakpoint ())
5023 tp
->set_stop_reason (TARGET_STOPPED_BY_HW_BREAKPOINT
);
5024 else if (!target_supports_stopped_by_hw_breakpoint ()
5025 && hardware_breakpoint_inserted_here_p (aspace
, pc
))
5026 tp
->set_stop_reason (TARGET_STOPPED_BY_HW_BREAKPOINT
);
5027 else if (!target_supports_stopped_by_sw_breakpoint ()
5028 && software_breakpoint_inserted_here_p (aspace
, pc
))
5029 tp
->set_stop_reason (TARGET_STOPPED_BY_SW_BREAKPOINT
);
5030 else if (!thread_has_single_step_breakpoints_set (tp
)
5031 && currently_stepping (tp
))
5032 tp
->set_stop_reason (TARGET_STOPPED_BY_SINGLE_STEP
);
5036 /* Mark the non-executing threads accordingly. In all-stop, all
5037 threads of all processes are stopped when we get any event
5038 reported. In non-stop mode, only the event thread stops. */
5041 mark_non_executing_threads (process_stratum_target
*target
,
5043 const target_waitstatus
&ws
)
5047 if (!target_is_non_stop_p ())
5048 mark_ptid
= minus_one_ptid
;
5049 else if (ws
.kind () == TARGET_WAITKIND_SIGNALLED
5050 || ws
.kind () == TARGET_WAITKIND_EXITED
)
5052 /* If we're handling a process exit in non-stop mode, even
5053 though threads haven't been deleted yet, one would think
5054 that there is nothing to do, as threads of the dead process
5055 will be soon deleted, and threads of any other process were
5056 left running. However, on some targets, threads survive a
5057 process exit event. E.g., for the "checkpoint" command,
5058 when the current checkpoint/fork exits, linux-fork.c
5059 automatically switches to another fork from within
5060 target_mourn_inferior, by associating the same
5061 inferior/thread to another fork. We haven't mourned yet at
5062 this point, but we must mark any threads left in the
5063 process as not-executing so that finish_thread_state marks
5064 them stopped (in the user's perspective) if/when we present
5065 the stop to the user. */
5066 mark_ptid
= ptid_t (event_ptid
.pid ());
5069 mark_ptid
= event_ptid
;
5071 set_executing (target
, mark_ptid
, false);
5073 /* Likewise the resumed flag. */
5074 set_resumed (target
, mark_ptid
, false);
5077 /* Handle one event after stopping threads. If the eventing thread
5078 reports back any interesting event, we leave it pending. If the
5079 eventing thread was in the middle of a displaced step, we
5080 cancel/finish it, and unless the thread's inferior is being
5081 detached, put the thread back in the step-over chain. Returns true
5082 if there are no resumed threads left in the target (thus there's no
5083 point in waiting further), false otherwise. */
5086 handle_one (const wait_one_event
&event
)
5089 ("%s %s", event
.ws
.to_string ().c_str (),
5090 event
.ptid
.to_string ().c_str ());
5092 if (event
.ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
5094 /* All resumed threads exited. */
5097 else if (event
.ws
.kind () == TARGET_WAITKIND_THREAD_EXITED
5098 || event
.ws
.kind () == TARGET_WAITKIND_EXITED
5099 || event
.ws
.kind () == TARGET_WAITKIND_SIGNALLED
)
5101 /* One thread/process exited/signalled. */
5103 thread_info
*t
= nullptr;
5105 /* The target may have reported just a pid. If so, try
5106 the first non-exited thread. */
5107 if (event
.ptid
.is_pid ())
5109 int pid
= event
.ptid
.pid ();
5110 inferior
*inf
= find_inferior_pid (event
.target
, pid
);
5111 for (thread_info
*tp
: inf
->non_exited_threads ())
5117 /* If there is no available thread, the event would
5118 have to be appended to a per-inferior event list,
5119 which does not exist (and if it did, we'd have
5120 to adjust run control command to be able to
5121 resume such an inferior). We assert here instead
5122 of going into an infinite loop. */
5123 gdb_assert (t
!= nullptr);
5126 ("using %s", t
->ptid
.to_string ().c_str ());
5130 t
= event
.target
->find_thread (event
.ptid
);
5131 /* Check if this is the first time we see this thread.
5132 Don't bother adding if it individually exited. */
5134 && event
.ws
.kind () != TARGET_WAITKIND_THREAD_EXITED
)
5135 t
= add_thread (event
.target
, event
.ptid
);
5140 /* Set the threads as non-executing to avoid
5141 another stop attempt on them. */
5142 switch_to_thread_no_regs (t
);
5143 mark_non_executing_threads (event
.target
, event
.ptid
,
5145 save_waitstatus (t
, event
.ws
);
5146 t
->stop_requested
= false;
5151 thread_info
*t
= event
.target
->find_thread (event
.ptid
);
5153 t
= add_thread (event
.target
, event
.ptid
);
5155 t
->stop_requested
= 0;
5156 t
->set_executing (false);
5157 t
->set_resumed (false);
5158 t
->control
.may_range_step
= 0;
5160 /* This may be the first time we see the inferior report
5162 if (t
->inf
->needs_setup
)
5164 switch_to_thread_no_regs (t
);
5168 if (event
.ws
.kind () == TARGET_WAITKIND_STOPPED
5169 && event
.ws
.sig () == GDB_SIGNAL_0
)
5171 /* We caught the event that we intended to catch, so
5172 there's no event to save as pending. */
5174 if (displaced_step_finish (t
, event
.ws
)
5175 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5177 /* Add it back to the step-over queue. */
5179 ("displaced-step of %s canceled",
5180 t
->ptid
.to_string ().c_str ());
5182 t
->control
.trap_expected
= 0;
5183 if (!t
->inf
->detaching
)
5184 global_thread_step_over_chain_enqueue (t
);
5189 struct regcache
*regcache
;
5192 ("target_wait %s, saving status for %s",
5193 event
.ws
.to_string ().c_str (),
5194 t
->ptid
.to_string ().c_str ());
5196 /* Record for later. */
5197 save_waitstatus (t
, event
.ws
);
5199 if (displaced_step_finish (t
, event
.ws
)
5200 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5202 /* Add it back to the step-over queue. */
5203 t
->control
.trap_expected
= 0;
5204 if (!t
->inf
->detaching
)
5205 global_thread_step_over_chain_enqueue (t
);
5208 regcache
= get_thread_regcache (t
);
5209 t
->set_stop_pc (regcache_read_pc (regcache
));
5211 infrun_debug_printf ("saved stop_pc=%s for %s "
5212 "(currently_stepping=%d)",
5213 paddress (target_gdbarch (), t
->stop_pc ()),
5214 t
->ptid
.to_string ().c_str (),
5215 currently_stepping (t
));
5225 stop_all_threads (const char *reason
, inferior
*inf
)
5227 /* We may need multiple passes to discover all threads. */
5231 gdb_assert (exists_non_stop_target ());
5233 INFRUN_SCOPED_DEBUG_START_END ("reason=%s, inf=%d", reason
,
5234 inf
!= nullptr ? inf
->num
: -1);
5236 infrun_debug_show_threads ("non-exited threads",
5237 all_non_exited_threads ());
5239 scoped_restore_current_thread restore_thread
;
5241 /* Enable thread events on relevant targets. */
5242 for (auto *target
: all_non_exited_process_targets ())
5244 if (inf
!= nullptr && inf
->process_target () != target
)
5247 switch_to_target_no_thread (target
);
5248 target_thread_events (true);
5253 /* Disable thread events on relevant targets. */
5254 for (auto *target
: all_non_exited_process_targets ())
5256 if (inf
!= nullptr && inf
->process_target () != target
)
5259 switch_to_target_no_thread (target
);
5260 target_thread_events (false);
5263 /* Use debug_prefixed_printf directly to get a meaningful function
5266 debug_prefixed_printf ("infrun", "stop_all_threads", "done");
5269 /* Request threads to stop, and then wait for the stops. Because
5270 threads we already know about can spawn more threads while we're
5271 trying to stop them, and we only learn about new threads when we
5272 update the thread list, do this in a loop, and keep iterating
5273 until two passes find no threads that need to be stopped. */
5274 for (pass
= 0; pass
< 2; pass
++, iterations
++)
5276 infrun_debug_printf ("pass=%d, iterations=%d", pass
, iterations
);
5279 int waits_needed
= 0;
5281 for (auto *target
: all_non_exited_process_targets ())
5283 if (inf
!= nullptr && inf
->process_target () != target
)
5286 switch_to_target_no_thread (target
);
5287 update_thread_list ();
5290 /* Go through all threads looking for threads that we need
5291 to tell the target to stop. */
5292 for (thread_info
*t
: all_non_exited_threads ())
5294 if (inf
!= nullptr && t
->inf
!= inf
)
5297 /* For a single-target setting with an all-stop target,
5298 we would not even arrive here. For a multi-target
5299 setting, until GDB is able to handle a mixture of
5300 all-stop and non-stop targets, simply skip all-stop
5301 targets' threads. This should be fine due to the
5302 protection of 'check_multi_target_resumption'. */
5304 switch_to_thread_no_regs (t
);
5305 if (!target_is_non_stop_p ())
5308 if (t
->executing ())
5310 /* If already stopping, don't request a stop again.
5311 We just haven't seen the notification yet. */
5312 if (!t
->stop_requested
)
5314 infrun_debug_printf (" %s executing, need stop",
5315 t
->ptid
.to_string ().c_str ());
5316 target_stop (t
->ptid
);
5317 t
->stop_requested
= 1;
5321 infrun_debug_printf (" %s executing, already stopping",
5322 t
->ptid
.to_string ().c_str ());
5325 if (t
->stop_requested
)
5330 infrun_debug_printf (" %s not executing",
5331 t
->ptid
.to_string ().c_str ());
5333 /* The thread may be not executing, but still be
5334 resumed with a pending status to process. */
5335 t
->set_resumed (false);
5339 if (waits_needed
== 0)
5342 /* If we find new threads on the second iteration, restart
5343 over. We want to see two iterations in a row with all
5348 for (int i
= 0; i
< waits_needed
; i
++)
5350 wait_one_event event
= wait_one ();
5351 if (handle_one (event
))
5358 /* Handle a TARGET_WAITKIND_NO_RESUMED event. */
5361 handle_no_resumed (struct execution_control_state
*ecs
)
5363 if (target_can_async_p ())
5365 bool any_sync
= false;
5367 for (ui
*ui
: all_uis ())
5369 if (ui
->prompt_state
== PROMPT_BLOCKED
)
5377 /* There were no unwaited-for children left in the target, but,
5378 we're not synchronously waiting for events either. Just
5381 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED (ignoring: bg)");
5382 prepare_to_wait (ecs
);
5387 /* Otherwise, if we were running a synchronous execution command, we
5388 may need to cancel it and give the user back the terminal.
5390 In non-stop mode, the target can't tell whether we've already
5391 consumed previous stop events, so it can end up sending us a
5392 no-resumed event like so:
5394 #0 - thread 1 is left stopped
5396 #1 - thread 2 is resumed and hits breakpoint
5397 -> TARGET_WAITKIND_STOPPED
5399 #2 - thread 3 is resumed and exits
5400 this is the last resumed thread, so
5401 -> TARGET_WAITKIND_NO_RESUMED
5403 #3 - gdb processes stop for thread 2 and decides to re-resume
5406 #4 - gdb processes the TARGET_WAITKIND_NO_RESUMED event.
5407 thread 2 is now resumed, so the event should be ignored.
5409 IOW, if the stop for thread 2 doesn't end a foreground command,
5410 then we need to ignore the following TARGET_WAITKIND_NO_RESUMED
5411 event. But it could be that the event meant that thread 2 itself
5412 (or whatever other thread was the last resumed thread) exited.
5414 To address this we refresh the thread list and check whether we
5415 have resumed threads _now_. In the example above, this removes
5416 thread 3 from the thread list. If thread 2 was re-resumed, we
5417 ignore this event. If we find no thread resumed, then we cancel
5418 the synchronous command and show "no unwaited-for " to the
5421 inferior
*curr_inf
= current_inferior ();
5423 scoped_restore_current_thread restore_thread
;
5424 update_thread_list ();
5428 - the current target has no thread executing, and
5429 - the current inferior is native, and
5430 - the current inferior is the one which has the terminal, and
5433 then a Ctrl-C from this point on would remain stuck in the
5434 kernel, until a thread resumes and dequeues it. That would
5435 result in the GDB CLI not reacting to Ctrl-C, not able to
5436 interrupt the program. To address this, if the current inferior
5437 no longer has any thread executing, we give the terminal to some
5438 other inferior that has at least one thread executing. */
5439 bool swap_terminal
= true;
5441 /* Whether to ignore this TARGET_WAITKIND_NO_RESUMED event, or
5442 whether to report it to the user. */
5443 bool ignore_event
= false;
5445 for (thread_info
*thread
: all_non_exited_threads ())
5447 if (swap_terminal
&& thread
->executing ())
5449 if (thread
->inf
!= curr_inf
)
5451 target_terminal::ours ();
5453 switch_to_thread (thread
);
5454 target_terminal::inferior ();
5456 swap_terminal
= false;
5459 if (!ignore_event
&& thread
->resumed ())
5461 /* Either there were no unwaited-for children left in the
5462 target at some point, but there are now, or some target
5463 other than the eventing one has unwaited-for children
5464 left. Just ignore. */
5465 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED "
5466 "(ignoring: found resumed)");
5468 ignore_event
= true;
5471 if (ignore_event
&& !swap_terminal
)
5477 switch_to_inferior_no_thread (curr_inf
);
5478 prepare_to_wait (ecs
);
5482 /* Go ahead and report the event. */
5486 /* Given an execution control state that has been freshly filled in by
5487 an event from the inferior, figure out what it means and take
5490 The alternatives are:
5492 1) stop_waiting and return; to really stop and return to the
5495 2) keep_going and return; to wait for the next event (set
5496 ecs->event_thread->stepping_over_breakpoint to 1 to single step
5500 handle_inferior_event (struct execution_control_state
*ecs
)
5502 /* Make sure that all temporary struct value objects that were
5503 created during the handling of the event get deleted at the
5505 scoped_value_mark free_values
;
5507 infrun_debug_printf ("%s", ecs
->ws
.to_string ().c_str ());
5509 if (ecs
->ws
.kind () == TARGET_WAITKIND_IGNORE
)
5511 /* We had an event in the inferior, but we are not interested in
5512 handling it at this level. The lower layers have already
5513 done what needs to be done, if anything.
5515 One of the possible circumstances for this is when the
5516 inferior produces output for the console. The inferior has
5517 not stopped, and we are ignoring the event. Another possible
5518 circumstance is any event which the lower level knows will be
5519 reported multiple times without an intervening resume. */
5520 prepare_to_wait (ecs
);
5524 if (ecs
->ws
.kind () == TARGET_WAITKIND_THREAD_EXITED
)
5526 prepare_to_wait (ecs
);
5530 if (ecs
->ws
.kind () == TARGET_WAITKIND_NO_RESUMED
5531 && handle_no_resumed (ecs
))
5534 /* Cache the last target/ptid/waitstatus. */
5535 set_last_target_status (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5537 /* Always clear state belonging to the previous time we stopped. */
5538 stop_stack_dummy
= STOP_NONE
;
5540 if (ecs
->ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
5542 /* No unwaited-for children left. IOW, all resumed children
5544 stop_print_frame
= false;
5549 if (ecs
->ws
.kind () != TARGET_WAITKIND_EXITED
5550 && ecs
->ws
.kind () != TARGET_WAITKIND_SIGNALLED
)
5552 ecs
->event_thread
= ecs
->target
->find_thread (ecs
->ptid
);
5553 /* If it's a new thread, add it to the thread database. */
5554 if (ecs
->event_thread
== nullptr)
5555 ecs
->event_thread
= add_thread (ecs
->target
, ecs
->ptid
);
5557 /* Disable range stepping. If the next step request could use a
5558 range, this will be end up re-enabled then. */
5559 ecs
->event_thread
->control
.may_range_step
= 0;
5562 /* Dependent on valid ECS->EVENT_THREAD. */
5563 adjust_pc_after_break (ecs
->event_thread
, ecs
->ws
);
5565 /* Dependent on the current PC value modified by adjust_pc_after_break. */
5566 reinit_frame_cache ();
5568 breakpoint_retire_moribund ();
5570 /* First, distinguish signals caused by the debugger from signals
5571 that have to do with the program's own actions. Note that
5572 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
5573 on the operating system version. Here we detect when a SIGILL or
5574 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
5575 something similar for SIGSEGV, since a SIGSEGV will be generated
5576 when we're trying to execute a breakpoint instruction on a
5577 non-executable stack. This happens for call dummy breakpoints
5578 for architectures like SPARC that place call dummies on the
5580 if (ecs
->ws
.kind () == TARGET_WAITKIND_STOPPED
5581 && (ecs
->ws
.sig () == GDB_SIGNAL_ILL
5582 || ecs
->ws
.sig () == GDB_SIGNAL_SEGV
5583 || ecs
->ws
.sig () == GDB_SIGNAL_EMT
))
5585 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5587 if (breakpoint_inserted_here_p (regcache
->aspace (),
5588 regcache_read_pc (regcache
)))
5590 infrun_debug_printf ("Treating signal as SIGTRAP");
5591 ecs
->ws
.set_stopped (GDB_SIGNAL_TRAP
);
5595 mark_non_executing_threads (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5597 switch (ecs
->ws
.kind ())
5599 case TARGET_WAITKIND_LOADED
:
5601 context_switch (ecs
);
5602 /* Ignore gracefully during startup of the inferior, as it might
5603 be the shell which has just loaded some objects, otherwise
5604 add the symbols for the newly loaded objects. Also ignore at
5605 the beginning of an attach or remote session; we will query
5606 the full list of libraries once the connection is
5609 stop_kind stop_soon
= get_inferior_stop_soon (ecs
);
5610 if (stop_soon
== NO_STOP_QUIETLY
)
5612 struct regcache
*regcache
;
5614 regcache
= get_thread_regcache (ecs
->event_thread
);
5616 handle_solib_event ();
5618 ecs
->event_thread
->set_stop_pc (regcache_read_pc (regcache
));
5619 ecs
->event_thread
->control
.stop_bpstat
5620 = bpstat_stop_status_nowatch (regcache
->aspace (),
5621 ecs
->event_thread
->stop_pc (),
5622 ecs
->event_thread
, ecs
->ws
);
5624 if (handle_stop_requested (ecs
))
5627 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5629 /* A catchpoint triggered. */
5630 process_event_stop_test (ecs
);
5634 /* If requested, stop when the dynamic linker notifies
5635 gdb of events. This allows the user to get control
5636 and place breakpoints in initializer routines for
5637 dynamically loaded objects (among other things). */
5638 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5639 if (stop_on_solib_events
)
5641 /* Make sure we print "Stopped due to solib-event" in
5643 stop_print_frame
= true;
5650 /* If we are skipping through a shell, or through shared library
5651 loading that we aren't interested in, resume the program. If
5652 we're running the program normally, also resume. */
5653 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
5655 /* Loading of shared libraries might have changed breakpoint
5656 addresses. Make sure new breakpoints are inserted. */
5657 if (stop_soon
== NO_STOP_QUIETLY
)
5658 insert_breakpoints ();
5659 resume (GDB_SIGNAL_0
);
5660 prepare_to_wait (ecs
);
5664 /* But stop if we're attaching or setting up a remote
5666 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
5667 || stop_soon
== STOP_QUIETLY_REMOTE
)
5669 infrun_debug_printf ("quietly stopped");
5674 internal_error (_("unhandled stop_soon: %d"), (int) stop_soon
);
5677 case TARGET_WAITKIND_SPURIOUS
:
5678 if (handle_stop_requested (ecs
))
5680 context_switch (ecs
);
5681 resume (GDB_SIGNAL_0
);
5682 prepare_to_wait (ecs
);
5685 case TARGET_WAITKIND_THREAD_CREATED
:
5686 if (handle_stop_requested (ecs
))
5688 context_switch (ecs
);
5689 if (!switch_back_to_stepped_thread (ecs
))
5693 case TARGET_WAITKIND_EXITED
:
5694 case TARGET_WAITKIND_SIGNALLED
:
5696 /* Depending on the system, ecs->ptid may point to a thread or
5697 to a process. On some targets, target_mourn_inferior may
5698 need to have access to the just-exited thread. That is the
5699 case of GNU/Linux's "checkpoint" support, for example.
5700 Call the switch_to_xxx routine as appropriate. */
5701 thread_info
*thr
= ecs
->target
->find_thread (ecs
->ptid
);
5703 switch_to_thread (thr
);
5706 inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5707 switch_to_inferior_no_thread (inf
);
5710 handle_vfork_child_exec_or_exit (0);
5711 target_terminal::ours (); /* Must do this before mourn anyway. */
5713 /* Clearing any previous state of convenience variables. */
5714 clear_exit_convenience_vars ();
5716 if (ecs
->ws
.kind () == TARGET_WAITKIND_EXITED
)
5718 /* Record the exit code in the convenience variable $_exitcode, so
5719 that the user can inspect this again later. */
5720 set_internalvar_integer (lookup_internalvar ("_exitcode"),
5721 (LONGEST
) ecs
->ws
.exit_status ());
5723 /* Also record this in the inferior itself. */
5724 current_inferior ()->has_exit_code
= true;
5725 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.exit_status ();
5727 /* Support the --return-child-result option. */
5728 return_child_result_value
= ecs
->ws
.exit_status ();
5730 gdb::observers::exited
.notify (ecs
->ws
.exit_status ());
5734 struct gdbarch
*gdbarch
= current_inferior ()->gdbarch
;
5736 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
5738 /* Set the value of the internal variable $_exitsignal,
5739 which holds the signal uncaught by the inferior. */
5740 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
5741 gdbarch_gdb_signal_to_target (gdbarch
,
5746 /* We don't have access to the target's method used for
5747 converting between signal numbers (GDB's internal
5748 representation <-> target's representation).
5749 Therefore, we cannot do a good job at displaying this
5750 information to the user. It's better to just warn
5751 her about it (if infrun debugging is enabled), and
5753 infrun_debug_printf ("Cannot fill $_exitsignal with the correct "
5757 gdb::observers::signal_exited
.notify (ecs
->ws
.sig ());
5760 gdb_flush (gdb_stdout
);
5761 target_mourn_inferior (inferior_ptid
);
5762 stop_print_frame
= false;
5766 case TARGET_WAITKIND_FORKED
:
5767 case TARGET_WAITKIND_VFORKED
:
5768 /* Check whether the inferior is displaced stepping. */
5770 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5771 struct gdbarch
*gdbarch
= regcache
->arch ();
5772 inferior
*parent_inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5774 /* If this is a fork (child gets its own address space copy)
5775 and some displaced step buffers were in use at the time of
5776 the fork, restore the displaced step buffer bytes in the
5779 Architectures which support displaced stepping and fork
5780 events must supply an implementation of
5781 gdbarch_displaced_step_restore_all_in_ptid. This is not
5782 enforced during gdbarch validation to support architectures
5783 which support displaced stepping but not forks. */
5784 if (ecs
->ws
.kind () == TARGET_WAITKIND_FORKED
5785 && gdbarch_supports_displaced_stepping (gdbarch
))
5786 gdbarch_displaced_step_restore_all_in_ptid
5787 (gdbarch
, parent_inf
, ecs
->ws
.child_ptid ());
5789 /* If displaced stepping is supported, and thread ecs->ptid is
5790 displaced stepping. */
5791 if (displaced_step_in_progress_thread (ecs
->event_thread
))
5793 struct regcache
*child_regcache
;
5794 CORE_ADDR parent_pc
;
5796 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
5797 indicating that the displaced stepping of syscall instruction
5798 has been done. Perform cleanup for parent process here. Note
5799 that this operation also cleans up the child process for vfork,
5800 because their pages are shared. */
5801 displaced_step_finish (ecs
->event_thread
, ecs
->ws
);
5802 /* Start a new step-over in another thread if there's one
5806 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
5807 the child's PC is also within the scratchpad. Set the child's PC
5808 to the parent's PC value, which has already been fixed up.
5809 FIXME: we use the parent's aspace here, although we're touching
5810 the child, because the child hasn't been added to the inferior
5811 list yet at this point. */
5814 = get_thread_arch_aspace_regcache (parent_inf
,
5815 ecs
->ws
.child_ptid (),
5817 parent_inf
->aspace
);
5818 /* Read PC value of parent process. */
5819 parent_pc
= regcache_read_pc (regcache
);
5821 displaced_debug_printf ("write child pc from %s to %s",
5823 regcache_read_pc (child_regcache
)),
5824 paddress (gdbarch
, parent_pc
));
5826 regcache_write_pc (child_regcache
, parent_pc
);
5830 context_switch (ecs
);
5832 /* Immediately detach breakpoints from the child before there's
5833 any chance of letting the user delete breakpoints from the
5834 breakpoint lists. If we don't do this early, it's easy to
5835 leave left over traps in the child, vis: "break foo; catch
5836 fork; c; <fork>; del; c; <child calls foo>". We only follow
5837 the fork on the last `continue', and by that time the
5838 breakpoint at "foo" is long gone from the breakpoint table.
5839 If we vforked, then we don't need to unpatch here, since both
5840 parent and child are sharing the same memory pages; we'll
5841 need to unpatch at follow/detach time instead to be certain
5842 that new breakpoints added between catchpoint hit time and
5843 vfork follow are detached. */
5844 if (ecs
->ws
.kind () != TARGET_WAITKIND_VFORKED
)
5846 /* This won't actually modify the breakpoint list, but will
5847 physically remove the breakpoints from the child. */
5848 detach_breakpoints (ecs
->ws
.child_ptid ());
5851 delete_just_stopped_threads_single_step_breakpoints ();
5853 /* In case the event is caught by a catchpoint, remember that
5854 the event is to be followed at the next resume of the thread,
5855 and not immediately. */
5856 ecs
->event_thread
->pending_follow
= ecs
->ws
;
5858 ecs
->event_thread
->set_stop_pc
5859 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
5861 ecs
->event_thread
->control
.stop_bpstat
5862 = bpstat_stop_status_nowatch (get_current_regcache ()->aspace (),
5863 ecs
->event_thread
->stop_pc (),
5864 ecs
->event_thread
, ecs
->ws
);
5866 if (handle_stop_requested (ecs
))
5869 /* If no catchpoint triggered for this, then keep going. Note
5870 that we're interested in knowing the bpstat actually causes a
5871 stop, not just if it may explain the signal. Software
5872 watchpoints, for example, always appear in the bpstat. */
5873 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5876 = (follow_fork_mode_string
== follow_fork_mode_child
);
5878 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5880 process_stratum_target
*targ
5881 = ecs
->event_thread
->inf
->process_target ();
5883 bool should_resume
= follow_fork ();
5885 /* Note that one of these may be an invalid pointer,
5886 depending on detach_fork. */
5887 thread_info
*parent
= ecs
->event_thread
;
5888 thread_info
*child
= targ
->find_thread (ecs
->ws
.child_ptid ());
5890 /* At this point, the parent is marked running, and the
5891 child is marked stopped. */
5893 /* If not resuming the parent, mark it stopped. */
5894 if (follow_child
&& !detach_fork
&& !non_stop
&& !sched_multi
)
5895 parent
->set_running (false);
5897 /* If resuming the child, mark it running. */
5898 if (follow_child
|| (!detach_fork
&& (non_stop
|| sched_multi
)))
5899 child
->set_running (true);
5901 /* In non-stop mode, also resume the other branch. */
5902 if (!detach_fork
&& (non_stop
5903 || (sched_multi
&& target_is_non_stop_p ())))
5906 switch_to_thread (parent
);
5908 switch_to_thread (child
);
5910 ecs
->event_thread
= inferior_thread ();
5911 ecs
->ptid
= inferior_ptid
;
5916 switch_to_thread (child
);
5918 switch_to_thread (parent
);
5920 ecs
->event_thread
= inferior_thread ();
5921 ecs
->ptid
= inferior_ptid
;
5925 /* Never call switch_back_to_stepped_thread if we are waiting for
5926 vfork-done (waiting for an external vfork child to exec or
5927 exit). We will resume only the vforking thread for the purpose
5928 of collecting the vfork-done event, and we will restart any
5929 step once the critical shared address space window is done. */
5932 && parent
->inf
->thread_waiting_for_vfork_done
!= nullptr)
5933 || !switch_back_to_stepped_thread (ecs
))
5940 process_event_stop_test (ecs
);
5943 case TARGET_WAITKIND_VFORK_DONE
:
5944 /* Done with the shared memory region. Re-insert breakpoints in
5945 the parent, and keep going. */
5947 context_switch (ecs
);
5949 handle_vfork_done (ecs
->event_thread
);
5950 gdb_assert (inferior_thread () == ecs
->event_thread
);
5952 if (handle_stop_requested (ecs
))
5955 if (!switch_back_to_stepped_thread (ecs
))
5957 gdb_assert (inferior_thread () == ecs
->event_thread
);
5958 /* This also takes care of reinserting breakpoints in the
5959 previously locked inferior. */
5964 case TARGET_WAITKIND_EXECD
:
5966 /* Note we can't read registers yet (the stop_pc), because we
5967 don't yet know the inferior's post-exec architecture.
5968 'stop_pc' is explicitly read below instead. */
5969 switch_to_thread_no_regs (ecs
->event_thread
);
5971 /* Do whatever is necessary to the parent branch of the vfork. */
5972 handle_vfork_child_exec_or_exit (1);
5974 /* This causes the eventpoints and symbol table to be reset.
5975 Must do this now, before trying to determine whether to
5977 follow_exec (inferior_ptid
, ecs
->ws
.execd_pathname ());
5979 /* In follow_exec we may have deleted the original thread and
5980 created a new one. Make sure that the event thread is the
5981 execd thread for that case (this is a nop otherwise). */
5982 ecs
->event_thread
= inferior_thread ();
5984 ecs
->event_thread
->set_stop_pc
5985 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
5987 ecs
->event_thread
->control
.stop_bpstat
5988 = bpstat_stop_status_nowatch (get_current_regcache ()->aspace (),
5989 ecs
->event_thread
->stop_pc (),
5990 ecs
->event_thread
, ecs
->ws
);
5992 if (handle_stop_requested (ecs
))
5995 /* If no catchpoint triggered for this, then keep going. */
5996 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5998 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6002 process_event_stop_test (ecs
);
6005 /* Be careful not to try to gather much state about a thread
6006 that's in a syscall. It's frequently a losing proposition. */
6007 case TARGET_WAITKIND_SYSCALL_ENTRY
:
6008 /* Getting the current syscall number. */
6009 if (handle_syscall_event (ecs
) == 0)
6010 process_event_stop_test (ecs
);
6013 /* Before examining the threads further, step this thread to
6014 get it entirely out of the syscall. (We get notice of the
6015 event when the thread is just on the verge of exiting a
6016 syscall. Stepping one instruction seems to get it back
6018 case TARGET_WAITKIND_SYSCALL_RETURN
:
6019 if (handle_syscall_event (ecs
) == 0)
6020 process_event_stop_test (ecs
);
6023 case TARGET_WAITKIND_STOPPED
:
6024 handle_signal_stop (ecs
);
6027 case TARGET_WAITKIND_NO_HISTORY
:
6028 /* Reverse execution: target ran out of history info. */
6030 /* Switch to the stopped thread. */
6031 context_switch (ecs
);
6032 infrun_debug_printf ("stopped");
6034 delete_just_stopped_threads_single_step_breakpoints ();
6035 ecs
->event_thread
->set_stop_pc
6036 (regcache_read_pc (get_thread_regcache (inferior_thread ())));
6038 if (handle_stop_requested (ecs
))
6041 gdb::observers::no_history
.notify ();
6047 /* Restart threads back to what they were trying to do back when we
6048 paused them (because of an in-line step-over or vfork, for example).
6049 The EVENT_THREAD thread is ignored (not restarted).
6051 If INF is non-nullptr, only resume threads from INF. */
6054 restart_threads (struct thread_info
*event_thread
, inferior
*inf
)
6056 INFRUN_SCOPED_DEBUG_START_END ("event_thread=%s, inf=%d",
6057 event_thread
->ptid
.to_string ().c_str (),
6058 inf
!= nullptr ? inf
->num
: -1);
6060 gdb_assert (!step_over_info_valid_p ());
6062 /* In case the instruction just stepped spawned a new thread. */
6063 update_thread_list ();
6065 for (thread_info
*tp
: all_non_exited_threads ())
6067 if (inf
!= nullptr && tp
->inf
!= inf
)
6070 if (tp
->inf
->detaching
)
6072 infrun_debug_printf ("restart threads: [%s] inferior detaching",
6073 tp
->ptid
.to_string ().c_str ());
6077 switch_to_thread_no_regs (tp
);
6079 if (tp
== event_thread
)
6081 infrun_debug_printf ("restart threads: [%s] is event thread",
6082 tp
->ptid
.to_string ().c_str ());
6086 if (!(tp
->state
== THREAD_RUNNING
|| tp
->control
.in_infcall
))
6088 infrun_debug_printf ("restart threads: [%s] not meant to be running",
6089 tp
->ptid
.to_string ().c_str ());
6095 infrun_debug_printf ("restart threads: [%s] resumed",
6096 tp
->ptid
.to_string ().c_str ());
6097 gdb_assert (tp
->executing () || tp
->has_pending_waitstatus ());
6101 if (thread_is_in_step_over_chain (tp
))
6103 infrun_debug_printf ("restart threads: [%s] needs step-over",
6104 tp
->ptid
.to_string ().c_str ());
6105 gdb_assert (!tp
->resumed ());
6110 if (tp
->has_pending_waitstatus ())
6112 infrun_debug_printf ("restart threads: [%s] has pending status",
6113 tp
->ptid
.to_string ().c_str ());
6114 tp
->set_resumed (true);
6118 gdb_assert (!tp
->stop_requested
);
6120 /* If some thread needs to start a step-over at this point, it
6121 should still be in the step-over queue, and thus skipped
6123 if (thread_still_needs_step_over (tp
))
6125 internal_error ("thread [%s] needs a step-over, but not in "
6126 "step-over queue\n",
6127 tp
->ptid
.to_string ().c_str ());
6130 if (currently_stepping (tp
))
6132 infrun_debug_printf ("restart threads: [%s] was stepping",
6133 tp
->ptid
.to_string ().c_str ());
6134 keep_going_stepped_thread (tp
);
6138 infrun_debug_printf ("restart threads: [%s] continuing",
6139 tp
->ptid
.to_string ().c_str ());
6140 execution_control_state
ecs (tp
);
6141 switch_to_thread (tp
);
6142 keep_going_pass_signal (&ecs
);
6147 /* Callback for iterate_over_threads. Find a resumed thread that has
6148 a pending waitstatus. */
6151 resumed_thread_with_pending_status (struct thread_info
*tp
,
6154 return tp
->resumed () && tp
->has_pending_waitstatus ();
6157 /* Called when we get an event that may finish an in-line or
6158 out-of-line (displaced stepping) step-over started previously.
6159 Return true if the event is processed and we should go back to the
6160 event loop; false if the caller should continue processing the
6164 finish_step_over (struct execution_control_state
*ecs
)
6166 displaced_step_finish (ecs
->event_thread
, ecs
->ws
);
6168 bool had_step_over_info
= step_over_info_valid_p ();
6170 if (had_step_over_info
)
6172 /* If we're stepping over a breakpoint with all threads locked,
6173 then only the thread that was stepped should be reporting
6175 gdb_assert (ecs
->event_thread
->control
.trap_expected
);
6177 clear_step_over_info ();
6180 if (!target_is_non_stop_p ())
6183 /* Start a new step-over in another thread if there's one that
6187 /* If we were stepping over a breakpoint before, and haven't started
6188 a new in-line step-over sequence, then restart all other threads
6189 (except the event thread). We can't do this in all-stop, as then
6190 e.g., we wouldn't be able to issue any other remote packet until
6191 these other threads stop. */
6192 if (had_step_over_info
&& !step_over_info_valid_p ())
6194 struct thread_info
*pending
;
6196 /* If we only have threads with pending statuses, the restart
6197 below won't restart any thread and so nothing re-inserts the
6198 breakpoint we just stepped over. But we need it inserted
6199 when we later process the pending events, otherwise if
6200 another thread has a pending event for this breakpoint too,
6201 we'd discard its event (because the breakpoint that
6202 originally caused the event was no longer inserted). */
6203 context_switch (ecs
);
6204 insert_breakpoints ();
6206 restart_threads (ecs
->event_thread
);
6208 /* If we have events pending, go through handle_inferior_event
6209 again, picking up a pending event at random. This avoids
6210 thread starvation. */
6212 /* But not if we just stepped over a watchpoint in order to let
6213 the instruction execute so we can evaluate its expression.
6214 The set of watchpoints that triggered is recorded in the
6215 breakpoint objects themselves (see bp->watchpoint_triggered).
6216 If we processed another event first, that other event could
6217 clobber this info. */
6218 if (ecs
->event_thread
->stepping_over_watchpoint
)
6221 pending
= iterate_over_threads (resumed_thread_with_pending_status
,
6223 if (pending
!= nullptr)
6225 struct thread_info
*tp
= ecs
->event_thread
;
6226 struct regcache
*regcache
;
6228 infrun_debug_printf ("found resumed threads with "
6229 "pending events, saving status");
6231 gdb_assert (pending
!= tp
);
6233 /* Record the event thread's event for later. */
6234 save_waitstatus (tp
, ecs
->ws
);
6235 /* This was cleared early, by handle_inferior_event. Set it
6236 so this pending event is considered by
6238 tp
->set_resumed (true);
6240 gdb_assert (!tp
->executing ());
6242 regcache
= get_thread_regcache (tp
);
6243 tp
->set_stop_pc (regcache_read_pc (regcache
));
6245 infrun_debug_printf ("saved stop_pc=%s for %s "
6246 "(currently_stepping=%d)",
6247 paddress (target_gdbarch (), tp
->stop_pc ()),
6248 tp
->ptid
.to_string ().c_str (),
6249 currently_stepping (tp
));
6251 /* This in-line step-over finished; clear this so we won't
6252 start a new one. This is what handle_signal_stop would
6253 do, if we returned false. */
6254 tp
->stepping_over_breakpoint
= 0;
6256 /* Wake up the event loop again. */
6257 mark_async_event_handler (infrun_async_inferior_event_token
);
6259 prepare_to_wait (ecs
);
6267 /* Come here when the program has stopped with a signal. */
6270 handle_signal_stop (struct execution_control_state
*ecs
)
6272 frame_info_ptr frame
;
6273 struct gdbarch
*gdbarch
;
6274 int stopped_by_watchpoint
;
6275 enum stop_kind stop_soon
;
6278 gdb_assert (ecs
->ws
.kind () == TARGET_WAITKIND_STOPPED
);
6280 ecs
->event_thread
->set_stop_signal (ecs
->ws
.sig ());
6282 /* Do we need to clean up the state of a thread that has
6283 completed a displaced single-step? (Doing so usually affects
6284 the PC, so do it here, before we set stop_pc.) */
6285 if (finish_step_over (ecs
))
6288 /* If we either finished a single-step or hit a breakpoint, but
6289 the user wanted this thread to be stopped, pretend we got a
6290 SIG0 (generic unsignaled stop). */
6291 if (ecs
->event_thread
->stop_requested
6292 && ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
6293 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6295 ecs
->event_thread
->set_stop_pc
6296 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
6298 context_switch (ecs
);
6300 if (deprecated_context_hook
)
6301 deprecated_context_hook (ecs
->event_thread
->global_num
);
6305 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
6306 struct gdbarch
*reg_gdbarch
= regcache
->arch ();
6309 ("stop_pc=%s", paddress (reg_gdbarch
, ecs
->event_thread
->stop_pc ()));
6310 if (target_stopped_by_watchpoint ())
6314 infrun_debug_printf ("stopped by watchpoint");
6316 if (target_stopped_data_address (current_inferior ()->top_target (),
6318 infrun_debug_printf ("stopped data address=%s",
6319 paddress (reg_gdbarch
, addr
));
6321 infrun_debug_printf ("(no data address available)");
6325 /* This is originated from start_remote(), start_inferior() and
6326 shared libraries hook functions. */
6327 stop_soon
= get_inferior_stop_soon (ecs
);
6328 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
6330 infrun_debug_printf ("quietly stopped");
6331 stop_print_frame
= true;
6336 /* This originates from attach_command(). We need to overwrite
6337 the stop_signal here, because some kernels don't ignore a
6338 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
6339 See more comments in inferior.h. On the other hand, if we
6340 get a non-SIGSTOP, report it to the user - assume the backend
6341 will handle the SIGSTOP if it should show up later.
6343 Also consider that the attach is complete when we see a
6344 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
6345 target extended-remote report it instead of a SIGSTOP
6346 (e.g. gdbserver). We already rely on SIGTRAP being our
6347 signal, so this is no exception.
6349 Also consider that the attach is complete when we see a
6350 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
6351 the target to stop all threads of the inferior, in case the
6352 low level attach operation doesn't stop them implicitly. If
6353 they weren't stopped implicitly, then the stub will report a
6354 GDB_SIGNAL_0, meaning: stopped for no particular reason
6355 other than GDB's request. */
6356 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
6357 && (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_STOP
6358 || ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6359 || ecs
->event_thread
->stop_signal () == GDB_SIGNAL_0
))
6361 stop_print_frame
= true;
6363 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6367 /* At this point, get hold of the now-current thread's frame. */
6368 frame
= get_current_frame ();
6369 gdbarch
= get_frame_arch (frame
);
6371 /* Pull the single step breakpoints out of the target. */
6372 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
6374 struct regcache
*regcache
;
6377 regcache
= get_thread_regcache (ecs
->event_thread
);
6378 const address_space
*aspace
= regcache
->aspace ();
6380 pc
= regcache_read_pc (regcache
);
6382 /* However, before doing so, if this single-step breakpoint was
6383 actually for another thread, set this thread up for moving
6385 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
6388 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
6390 infrun_debug_printf ("[%s] hit another thread's single-step "
6392 ecs
->ptid
.to_string ().c_str ());
6393 ecs
->hit_singlestep_breakpoint
= 1;
6398 infrun_debug_printf ("[%s] hit its single-step breakpoint",
6399 ecs
->ptid
.to_string ().c_str ());
6402 delete_just_stopped_threads_single_step_breakpoints ();
6404 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6405 && ecs
->event_thread
->control
.trap_expected
6406 && ecs
->event_thread
->stepping_over_watchpoint
)
6407 stopped_by_watchpoint
= 0;
6409 stopped_by_watchpoint
= watchpoints_triggered (ecs
->ws
);
6411 /* If necessary, step over this watchpoint. We'll be back to display
6413 if (stopped_by_watchpoint
6414 && (target_have_steppable_watchpoint ()
6415 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
6417 /* At this point, we are stopped at an instruction which has
6418 attempted to write to a piece of memory under control of
6419 a watchpoint. The instruction hasn't actually executed
6420 yet. If we were to evaluate the watchpoint expression
6421 now, we would get the old value, and therefore no change
6422 would seem to have occurred.
6424 In order to make watchpoints work `right', we really need
6425 to complete the memory write, and then evaluate the
6426 watchpoint expression. We do this by single-stepping the
6429 It may not be necessary to disable the watchpoint to step over
6430 it. For example, the PA can (with some kernel cooperation)
6431 single step over a watchpoint without disabling the watchpoint.
6433 It is far more common to need to disable a watchpoint to step
6434 the inferior over it. If we have non-steppable watchpoints,
6435 we must disable the current watchpoint; it's simplest to
6436 disable all watchpoints.
6438 Any breakpoint at PC must also be stepped over -- if there's
6439 one, it will have already triggered before the watchpoint
6440 triggered, and we either already reported it to the user, or
6441 it didn't cause a stop and we called keep_going. In either
6442 case, if there was a breakpoint at PC, we must be trying to
6444 ecs
->event_thread
->stepping_over_watchpoint
= 1;
6449 ecs
->event_thread
->stepping_over_breakpoint
= 0;
6450 ecs
->event_thread
->stepping_over_watchpoint
= 0;
6451 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
6452 ecs
->event_thread
->control
.stop_step
= 0;
6453 stop_print_frame
= true;
6454 stopped_by_random_signal
= 0;
6455 bpstat
*stop_chain
= nullptr;
6457 /* Hide inlined functions starting here, unless we just performed stepi or
6458 nexti. After stepi and nexti, always show the innermost frame (not any
6459 inline function call sites). */
6460 if (ecs
->event_thread
->control
.step_range_end
!= 1)
6462 const address_space
*aspace
6463 = get_thread_regcache (ecs
->event_thread
)->aspace ();
6465 /* skip_inline_frames is expensive, so we avoid it if we can
6466 determine that the address is one where functions cannot have
6467 been inlined. This improves performance with inferiors that
6468 load a lot of shared libraries, because the solib event
6469 breakpoint is defined as the address of a function (i.e. not
6470 inline). Note that we have to check the previous PC as well
6471 as the current one to catch cases when we have just
6472 single-stepped off a breakpoint prior to reinstating it.
6473 Note that we're assuming that the code we single-step to is
6474 not inline, but that's not definitive: there's nothing
6475 preventing the event breakpoint function from containing
6476 inlined code, and the single-step ending up there. If the
6477 user had set a breakpoint on that inlined code, the missing
6478 skip_inline_frames call would break things. Fortunately
6479 that's an extremely unlikely scenario. */
6480 if (!pc_at_non_inline_function (aspace
,
6481 ecs
->event_thread
->stop_pc (),
6483 && !(ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6484 && ecs
->event_thread
->control
.trap_expected
6485 && pc_at_non_inline_function (aspace
,
6486 ecs
->event_thread
->prev_pc
,
6489 stop_chain
= build_bpstat_chain (aspace
,
6490 ecs
->event_thread
->stop_pc (),
6492 skip_inline_frames (ecs
->event_thread
, stop_chain
);
6494 /* Re-fetch current thread's frame in case that invalidated
6496 frame
= get_current_frame ();
6497 gdbarch
= get_frame_arch (frame
);
6501 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6502 && ecs
->event_thread
->control
.trap_expected
6503 && gdbarch_single_step_through_delay_p (gdbarch
)
6504 && currently_stepping (ecs
->event_thread
))
6506 /* We're trying to step off a breakpoint. Turns out that we're
6507 also on an instruction that needs to be stepped multiple
6508 times before it's been fully executing. E.g., architectures
6509 with a delay slot. It needs to be stepped twice, once for
6510 the instruction and once for the delay slot. */
6511 int step_through_delay
6512 = gdbarch_single_step_through_delay (gdbarch
, frame
);
6514 if (step_through_delay
)
6515 infrun_debug_printf ("step through delay");
6517 if (ecs
->event_thread
->control
.step_range_end
== 0
6518 && step_through_delay
)
6520 /* The user issued a continue when stopped at a breakpoint.
6521 Set up for another trap and get out of here. */
6522 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6526 else if (step_through_delay
)
6528 /* The user issued a step when stopped at a breakpoint.
6529 Maybe we should stop, maybe we should not - the delay
6530 slot *might* correspond to a line of source. In any
6531 case, don't decide that here, just set
6532 ecs->stepping_over_breakpoint, making sure we
6533 single-step again before breakpoints are re-inserted. */
6534 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6538 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
6539 handles this event. */
6540 ecs
->event_thread
->control
.stop_bpstat
6541 = bpstat_stop_status (get_current_regcache ()->aspace (),
6542 ecs
->event_thread
->stop_pc (),
6543 ecs
->event_thread
, ecs
->ws
, stop_chain
);
6545 /* Following in case break condition called a
6547 stop_print_frame
= true;
6549 /* This is where we handle "moribund" watchpoints. Unlike
6550 software breakpoints traps, hardware watchpoint traps are
6551 always distinguishable from random traps. If no high-level
6552 watchpoint is associated with the reported stop data address
6553 anymore, then the bpstat does not explain the signal ---
6554 simply make sure to ignore it if `stopped_by_watchpoint' is
6557 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6558 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6560 && stopped_by_watchpoint
)
6562 infrun_debug_printf ("no user watchpoint explains watchpoint SIGTRAP, "
6566 /* NOTE: cagney/2003-03-29: These checks for a random signal
6567 at one stage in the past included checks for an inferior
6568 function call's call dummy's return breakpoint. The original
6569 comment, that went with the test, read:
6571 ``End of a stack dummy. Some systems (e.g. Sony news) give
6572 another signal besides SIGTRAP, so check here as well as
6575 If someone ever tries to get call dummys on a
6576 non-executable stack to work (where the target would stop
6577 with something like a SIGSEGV), then those tests might need
6578 to be re-instated. Given, however, that the tests were only
6579 enabled when momentary breakpoints were not being used, I
6580 suspect that it won't be the case.
6582 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
6583 be necessary for call dummies on a non-executable stack on
6586 /* See if the breakpoints module can explain the signal. */
6588 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6589 ecs
->event_thread
->stop_signal ());
6591 /* Maybe this was a trap for a software breakpoint that has since
6593 if (random_signal
&& target_stopped_by_sw_breakpoint ())
6595 if (gdbarch_program_breakpoint_here_p (gdbarch
,
6596 ecs
->event_thread
->stop_pc ()))
6598 struct regcache
*regcache
;
6601 /* Re-adjust PC to what the program would see if GDB was not
6603 regcache
= get_thread_regcache (ecs
->event_thread
);
6604 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
6607 gdb::optional
<scoped_restore_tmpl
<int>>
6608 restore_operation_disable
;
6610 if (record_full_is_used ())
6611 restore_operation_disable
.emplace
6612 (record_full_gdb_operation_disable_set ());
6614 regcache_write_pc (regcache
,
6615 ecs
->event_thread
->stop_pc () + decr_pc
);
6620 /* A delayed software breakpoint event. Ignore the trap. */
6621 infrun_debug_printf ("delayed software breakpoint trap, ignoring");
6626 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
6627 has since been removed. */
6628 if (random_signal
&& target_stopped_by_hw_breakpoint ())
6630 /* A delayed hardware breakpoint event. Ignore the trap. */
6631 infrun_debug_printf ("delayed hardware breakpoint/watchpoint "
6636 /* If not, perhaps stepping/nexting can. */
6638 random_signal
= !(ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6639 && currently_stepping (ecs
->event_thread
));
6641 /* Perhaps the thread hit a single-step breakpoint of _another_
6642 thread. Single-step breakpoints are transparent to the
6643 breakpoints module. */
6645 random_signal
= !ecs
->hit_singlestep_breakpoint
;
6647 /* No? Perhaps we got a moribund watchpoint. */
6649 random_signal
= !stopped_by_watchpoint
;
6651 /* Always stop if the user explicitly requested this thread to
6653 if (ecs
->event_thread
->stop_requested
)
6656 infrun_debug_printf ("user-requested stop");
6659 /* For the program's own signals, act according to
6660 the signal handling tables. */
6664 /* Signal not for debugging purposes. */
6665 enum gdb_signal stop_signal
= ecs
->event_thread
->stop_signal ();
6667 infrun_debug_printf ("random signal (%s)",
6668 gdb_signal_to_symbol_string (stop_signal
));
6670 stopped_by_random_signal
= 1;
6672 /* Always stop on signals if we're either just gaining control
6673 of the program, or the user explicitly requested this thread
6674 to remain stopped. */
6675 if (stop_soon
!= NO_STOP_QUIETLY
6676 || ecs
->event_thread
->stop_requested
6677 || signal_stop_state (ecs
->event_thread
->stop_signal ()))
6683 /* Notify observers the signal has "handle print" set. Note we
6684 returned early above if stopping; normal_stop handles the
6685 printing in that case. */
6686 if (signal_print
[ecs
->event_thread
->stop_signal ()])
6688 /* The signal table tells us to print about this signal. */
6689 target_terminal::ours_for_output ();
6690 gdb::observers::signal_received
.notify (ecs
->event_thread
->stop_signal ());
6691 target_terminal::inferior ();
6694 /* Clear the signal if it should not be passed. */
6695 if (signal_program
[ecs
->event_thread
->stop_signal ()] == 0)
6696 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6698 if (ecs
->event_thread
->prev_pc
== ecs
->event_thread
->stop_pc ()
6699 && ecs
->event_thread
->control
.trap_expected
6700 && ecs
->event_thread
->control
.step_resume_breakpoint
== nullptr)
6702 /* We were just starting a new sequence, attempting to
6703 single-step off of a breakpoint and expecting a SIGTRAP.
6704 Instead this signal arrives. This signal will take us out
6705 of the stepping range so GDB needs to remember to, when
6706 the signal handler returns, resume stepping off that
6708 /* To simplify things, "continue" is forced to use the same
6709 code paths as single-step - set a breakpoint at the
6710 signal return address and then, once hit, step off that
6712 infrun_debug_printf ("signal arrived while stepping over breakpoint");
6714 insert_hp_step_resume_breakpoint_at_frame (frame
);
6715 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6716 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6717 ecs
->event_thread
->control
.trap_expected
= 0;
6719 /* If we were nexting/stepping some other thread, switch to
6720 it, so that we don't continue it, losing control. */
6721 if (!switch_back_to_stepped_thread (ecs
))
6726 if (ecs
->event_thread
->stop_signal () != GDB_SIGNAL_0
6727 && (pc_in_thread_step_range (ecs
->event_thread
->stop_pc (),
6729 || ecs
->event_thread
->control
.step_range_end
== 1)
6730 && (get_stack_frame_id (frame
)
6731 == ecs
->event_thread
->control
.step_stack_frame_id
)
6732 && ecs
->event_thread
->control
.step_resume_breakpoint
== nullptr)
6734 /* The inferior is about to take a signal that will take it
6735 out of the single step range. Set a breakpoint at the
6736 current PC (which is presumably where the signal handler
6737 will eventually return) and then allow the inferior to
6740 Note that this is only needed for a signal delivered
6741 while in the single-step range. Nested signals aren't a
6742 problem as they eventually all return. */
6743 infrun_debug_printf ("signal may take us out of single-step range");
6745 clear_step_over_info ();
6746 insert_hp_step_resume_breakpoint_at_frame (frame
);
6747 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6748 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6749 ecs
->event_thread
->control
.trap_expected
= 0;
6754 /* Note: step_resume_breakpoint may be non-NULL. This occurs
6755 when either there's a nested signal, or when there's a
6756 pending signal enabled just as the signal handler returns
6757 (leaving the inferior at the step-resume-breakpoint without
6758 actually executing it). Either way continue until the
6759 breakpoint is really hit. */
6761 if (!switch_back_to_stepped_thread (ecs
))
6763 infrun_debug_printf ("random signal, keep going");
6770 process_event_stop_test (ecs
);
6773 /* Come here when we've got some debug event / signal we can explain
6774 (IOW, not a random signal), and test whether it should cause a
6775 stop, or whether we should resume the inferior (transparently).
6776 E.g., could be a breakpoint whose condition evaluates false; we
6777 could be still stepping within the line; etc. */
6780 process_event_stop_test (struct execution_control_state
*ecs
)
6782 struct symtab_and_line stop_pc_sal
;
6783 frame_info_ptr frame
;
6784 struct gdbarch
*gdbarch
;
6785 CORE_ADDR jmp_buf_pc
;
6786 struct bpstat_what what
;
6788 /* Handle cases caused by hitting a breakpoint. */
6790 frame
= get_current_frame ();
6791 gdbarch
= get_frame_arch (frame
);
6793 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
6795 if (what
.call_dummy
)
6797 stop_stack_dummy
= what
.call_dummy
;
6800 /* A few breakpoint types have callbacks associated (e.g.,
6801 bp_jit_event). Run them now. */
6802 bpstat_run_callbacks (ecs
->event_thread
->control
.stop_bpstat
);
6804 /* If we hit an internal event that triggers symbol changes, the
6805 current frame will be invalidated within bpstat_what (e.g., if we
6806 hit an internal solib event). Re-fetch it. */
6807 frame
= get_current_frame ();
6808 gdbarch
= get_frame_arch (frame
);
6810 switch (what
.main_action
)
6812 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
6813 /* If we hit the breakpoint at longjmp while stepping, we
6814 install a momentary breakpoint at the target of the
6817 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME");
6819 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6821 if (what
.is_longjmp
)
6823 struct value
*arg_value
;
6825 /* If we set the longjmp breakpoint via a SystemTap probe,
6826 then use it to extract the arguments. The destination PC
6827 is the third argument to the probe. */
6828 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
6831 jmp_buf_pc
= value_as_address (arg_value
);
6832 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
6834 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
6835 || !gdbarch_get_longjmp_target (gdbarch
,
6836 frame
, &jmp_buf_pc
))
6838 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME "
6839 "(!gdbarch_get_longjmp_target)");
6844 /* Insert a breakpoint at resume address. */
6845 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
6848 check_exception_resume (ecs
, frame
);
6852 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
6854 frame_info_ptr init_frame
;
6856 /* There are several cases to consider.
6858 1. The initiating frame no longer exists. In this case we
6859 must stop, because the exception or longjmp has gone too
6862 2. The initiating frame exists, and is the same as the
6863 current frame. We stop, because the exception or longjmp
6866 3. The initiating frame exists and is different from the
6867 current frame. This means the exception or longjmp has
6868 been caught beneath the initiating frame, so keep going.
6870 4. longjmp breakpoint has been placed just to protect
6871 against stale dummy frames and user is not interested in
6872 stopping around longjmps. */
6874 infrun_debug_printf ("BPSTAT_WHAT_CLEAR_LONGJMP_RESUME");
6876 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
6878 delete_exception_resume_breakpoint (ecs
->event_thread
);
6880 if (what
.is_longjmp
)
6882 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
6884 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
6892 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
6896 struct frame_id current_id
6897 = get_frame_id (get_current_frame ());
6898 if (current_id
== ecs
->event_thread
->initiating_frame
)
6900 /* Case 2. Fall through. */
6910 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
6912 delete_step_resume_breakpoint (ecs
->event_thread
);
6914 end_stepping_range (ecs
);
6918 case BPSTAT_WHAT_SINGLE
:
6919 infrun_debug_printf ("BPSTAT_WHAT_SINGLE");
6920 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6921 /* Still need to check other stuff, at least the case where we
6922 are stepping and step out of the right range. */
6925 case BPSTAT_WHAT_STEP_RESUME
:
6926 infrun_debug_printf ("BPSTAT_WHAT_STEP_RESUME");
6928 delete_step_resume_breakpoint (ecs
->event_thread
);
6929 if (ecs
->event_thread
->control
.proceed_to_finish
6930 && execution_direction
== EXEC_REVERSE
)
6932 struct thread_info
*tp
= ecs
->event_thread
;
6934 /* We are finishing a function in reverse, and just hit the
6935 step-resume breakpoint at the start address of the
6936 function, and we're almost there -- just need to back up
6937 by one more single-step, which should take us back to the
6939 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
6943 fill_in_stop_func (gdbarch
, ecs
);
6944 if (ecs
->event_thread
->stop_pc () == ecs
->stop_func_start
6945 && execution_direction
== EXEC_REVERSE
)
6947 /* We are stepping over a function call in reverse, and just
6948 hit the step-resume breakpoint at the start address of
6949 the function. Go back to single-stepping, which should
6950 take us back to the function call. */
6951 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6957 case BPSTAT_WHAT_STOP_NOISY
:
6958 infrun_debug_printf ("BPSTAT_WHAT_STOP_NOISY");
6959 stop_print_frame
= true;
6961 /* Assume the thread stopped for a breakpoint. We'll still check
6962 whether a/the breakpoint is there when the thread is next
6964 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6969 case BPSTAT_WHAT_STOP_SILENT
:
6970 infrun_debug_printf ("BPSTAT_WHAT_STOP_SILENT");
6971 stop_print_frame
= false;
6973 /* Assume the thread stopped for a breakpoint. We'll still check
6974 whether a/the breakpoint is there when the thread is next
6976 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6980 case BPSTAT_WHAT_HP_STEP_RESUME
:
6981 infrun_debug_printf ("BPSTAT_WHAT_HP_STEP_RESUME");
6983 delete_step_resume_breakpoint (ecs
->event_thread
);
6984 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
6986 /* Back when the step-resume breakpoint was inserted, we
6987 were trying to single-step off a breakpoint. Go back to
6989 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6990 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6996 case BPSTAT_WHAT_KEEP_CHECKING
:
7000 /* If we stepped a permanent breakpoint and we had a high priority
7001 step-resume breakpoint for the address we stepped, but we didn't
7002 hit it, then we must have stepped into the signal handler. The
7003 step-resume was only necessary to catch the case of _not_
7004 stepping into the handler, so delete it, and fall through to
7005 checking whether the step finished. */
7006 if (ecs
->event_thread
->stepped_breakpoint
)
7008 struct breakpoint
*sr_bp
7009 = ecs
->event_thread
->control
.step_resume_breakpoint
;
7011 if (sr_bp
!= nullptr
7012 && sr_bp
->first_loc ().permanent
7013 && sr_bp
->type
== bp_hp_step_resume
7014 && sr_bp
->first_loc ().address
== ecs
->event_thread
->prev_pc
)
7016 infrun_debug_printf ("stepped permanent breakpoint, stopped in handler");
7017 delete_step_resume_breakpoint (ecs
->event_thread
);
7018 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
7022 /* We come here if we hit a breakpoint but should not stop for it.
7023 Possibly we also were stepping and should stop for that. So fall
7024 through and test for stepping. But, if not stepping, do not
7027 /* In all-stop mode, if we're currently stepping but have stopped in
7028 some other thread, we need to switch back to the stepped thread. */
7029 if (switch_back_to_stepped_thread (ecs
))
7032 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
7034 infrun_debug_printf ("step-resume breakpoint is inserted");
7036 /* Having a step-resume breakpoint overrides anything
7037 else having to do with stepping commands until
7038 that breakpoint is reached. */
7043 if (ecs
->event_thread
->control
.step_range_end
== 0)
7045 infrun_debug_printf ("no stepping, continue");
7046 /* Likewise if we aren't even stepping. */
7051 /* Re-fetch current thread's frame in case the code above caused
7052 the frame cache to be re-initialized, making our FRAME variable
7053 a dangling pointer. */
7054 frame
= get_current_frame ();
7055 gdbarch
= get_frame_arch (frame
);
7056 fill_in_stop_func (gdbarch
, ecs
);
7058 /* If stepping through a line, keep going if still within it.
7060 Note that step_range_end is the address of the first instruction
7061 beyond the step range, and NOT the address of the last instruction
7064 Note also that during reverse execution, we may be stepping
7065 through a function epilogue and therefore must detect when
7066 the current-frame changes in the middle of a line. */
7068 if (pc_in_thread_step_range (ecs
->event_thread
->stop_pc (),
7070 && (execution_direction
!= EXEC_REVERSE
7071 || get_frame_id (frame
) == ecs
->event_thread
->control
.step_frame_id
))
7074 ("stepping inside range [%s-%s]",
7075 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
7076 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
7078 /* Tentatively re-enable range stepping; `resume' disables it if
7079 necessary (e.g., if we're stepping over a breakpoint or we
7080 have software watchpoints). */
7081 ecs
->event_thread
->control
.may_range_step
= 1;
7083 /* When stepping backward, stop at beginning of line range
7084 (unless it's the function entry point, in which case
7085 keep going back to the call point). */
7086 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7087 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
7088 && stop_pc
!= ecs
->stop_func_start
7089 && execution_direction
== EXEC_REVERSE
)
7090 end_stepping_range (ecs
);
7097 /* We stepped out of the stepping range. */
7099 /* If we are stepping at the source level and entered the runtime
7100 loader dynamic symbol resolution code...
7102 EXEC_FORWARD: we keep on single stepping until we exit the run
7103 time loader code and reach the callee's address.
7105 EXEC_REVERSE: we've already executed the callee (backward), and
7106 the runtime loader code is handled just like any other
7107 undebuggable function call. Now we need only keep stepping
7108 backward through the trampoline code, and that's handled further
7109 down, so there is nothing for us to do here. */
7111 if (execution_direction
!= EXEC_REVERSE
7112 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7113 && in_solib_dynsym_resolve_code (ecs
->event_thread
->stop_pc ())
7114 && (ecs
->event_thread
->control
.step_start_function
== nullptr
7115 || !in_solib_dynsym_resolve_code (
7116 ecs
->event_thread
->control
.step_start_function
->value_block ()
7119 CORE_ADDR pc_after_resolver
=
7120 gdbarch_skip_solib_resolver (gdbarch
, ecs
->event_thread
->stop_pc ());
7122 infrun_debug_printf ("stepped into dynsym resolve code");
7124 if (pc_after_resolver
)
7126 /* Set up a step-resume breakpoint at the address
7127 indicated by SKIP_SOLIB_RESOLVER. */
7128 symtab_and_line sr_sal
;
7129 sr_sal
.pc
= pc_after_resolver
;
7130 sr_sal
.pspace
= get_frame_program_space (frame
);
7132 insert_step_resume_breakpoint_at_sal (gdbarch
,
7133 sr_sal
, null_frame_id
);
7140 /* Step through an indirect branch thunk. */
7141 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7142 && gdbarch_in_indirect_branch_thunk (gdbarch
,
7143 ecs
->event_thread
->stop_pc ()))
7145 infrun_debug_printf ("stepped into indirect branch thunk");
7150 if (ecs
->event_thread
->control
.step_range_end
!= 1
7151 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7152 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7153 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
7155 infrun_debug_printf ("stepped into signal trampoline");
7156 /* The inferior, while doing a "step" or "next", has ended up in
7157 a signal trampoline (either by a signal being delivered or by
7158 the signal handler returning). Just single-step until the
7159 inferior leaves the trampoline (either by calling the handler
7165 /* If we're in the return path from a shared library trampoline,
7166 we want to proceed through the trampoline when stepping. */
7167 /* macro/2012-04-25: This needs to come before the subroutine
7168 call check below as on some targets return trampolines look
7169 like subroutine calls (MIPS16 return thunks). */
7170 if (gdbarch_in_solib_return_trampoline (gdbarch
,
7171 ecs
->event_thread
->stop_pc (),
7172 ecs
->stop_func_name
)
7173 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7175 /* Determine where this trampoline returns. */
7176 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7177 CORE_ADDR real_stop_pc
7178 = gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7180 infrun_debug_printf ("stepped into solib return tramp");
7182 /* Only proceed through if we know where it's going. */
7185 /* And put the step-breakpoint there and go until there. */
7186 symtab_and_line sr_sal
;
7187 sr_sal
.pc
= real_stop_pc
;
7188 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7189 sr_sal
.pspace
= get_frame_program_space (frame
);
7191 /* Do not specify what the fp should be when we stop since
7192 on some machines the prologue is where the new fp value
7194 insert_step_resume_breakpoint_at_sal (gdbarch
,
7195 sr_sal
, null_frame_id
);
7197 /* Restart without fiddling with the step ranges or
7204 /* Check for subroutine calls. The check for the current frame
7205 equalling the step ID is not necessary - the check of the
7206 previous frame's ID is sufficient - but it is a common case and
7207 cheaper than checking the previous frame's ID.
7209 NOTE: frame_id::operator== will never report two invalid frame IDs as
7210 being equal, so to get into this block, both the current and
7211 previous frame must have valid frame IDs. */
7212 /* The outer_frame_id check is a heuristic to detect stepping
7213 through startup code. If we step over an instruction which
7214 sets the stack pointer from an invalid value to a valid value,
7215 we may detect that as a subroutine call from the mythical
7216 "outermost" function. This could be fixed by marking
7217 outermost frames as !stack_p,code_p,special_p. Then the
7218 initial outermost frame, before sp was valid, would
7219 have code_addr == &_start. See the comment in frame_id::operator==
7221 if ((get_stack_frame_id (frame
)
7222 != ecs
->event_thread
->control
.step_stack_frame_id
)
7223 && ((frame_unwind_caller_id (get_current_frame ())
7224 == ecs
->event_thread
->control
.step_stack_frame_id
)
7225 && ((ecs
->event_thread
->control
.step_stack_frame_id
7227 || (ecs
->event_thread
->control
.step_start_function
7228 != find_pc_function (ecs
->event_thread
->stop_pc ())))))
7230 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7231 CORE_ADDR real_stop_pc
;
7233 infrun_debug_printf ("stepped into subroutine");
7235 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
7237 /* I presume that step_over_calls is only 0 when we're
7238 supposed to be stepping at the assembly language level
7239 ("stepi"). Just stop. */
7240 /* And this works the same backward as frontward. MVS */
7241 end_stepping_range (ecs
);
7245 /* Reverse stepping through solib trampolines. */
7247 if (execution_direction
== EXEC_REVERSE
7248 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7249 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7250 || (ecs
->stop_func_start
== 0
7251 && in_solib_dynsym_resolve_code (stop_pc
))))
7253 /* Any solib trampoline code can be handled in reverse
7254 by simply continuing to single-step. We have already
7255 executed the solib function (backwards), and a few
7256 steps will take us back through the trampoline to the
7262 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7264 /* We're doing a "next".
7266 Normal (forward) execution: set a breakpoint at the
7267 callee's return address (the address at which the caller
7270 Reverse (backward) execution. set the step-resume
7271 breakpoint at the start of the function that we just
7272 stepped into (backwards), and continue to there. When we
7273 get there, we'll need to single-step back to the caller. */
7275 if (execution_direction
== EXEC_REVERSE
)
7277 /* If we're already at the start of the function, we've either
7278 just stepped backward into a single instruction function,
7279 or stepped back out of a signal handler to the first instruction
7280 of the function. Just keep going, which will single-step back
7282 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
7284 /* Normal function call return (static or dynamic). */
7285 symtab_and_line sr_sal
;
7286 sr_sal
.pc
= ecs
->stop_func_start
;
7287 sr_sal
.pspace
= get_frame_program_space (frame
);
7288 insert_step_resume_breakpoint_at_sal (gdbarch
,
7289 sr_sal
, get_stack_frame_id (frame
));
7293 insert_step_resume_breakpoint_at_caller (frame
);
7299 /* If we are in a function call trampoline (a stub between the
7300 calling routine and the real function), locate the real
7301 function. That's what tells us (a) whether we want to step
7302 into it at all, and (b) what prologue we want to run to the
7303 end of, if we do step into it. */
7304 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
7305 if (real_stop_pc
== 0)
7306 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7307 if (real_stop_pc
!= 0)
7308 ecs
->stop_func_start
= real_stop_pc
;
7310 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
7312 symtab_and_line sr_sal
;
7313 sr_sal
.pc
= ecs
->stop_func_start
;
7314 sr_sal
.pspace
= get_frame_program_space (frame
);
7316 insert_step_resume_breakpoint_at_sal (gdbarch
,
7317 sr_sal
, null_frame_id
);
7322 /* If we have line number information for the function we are
7323 thinking of stepping into and the function isn't on the skip
7326 If there are several symtabs at that PC (e.g. with include
7327 files), just want to know whether *any* of them have line
7328 numbers. find_pc_line handles this. */
7330 struct symtab_and_line tmp_sal
;
7332 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7333 if (tmp_sal
.line
!= 0
7334 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
7336 && !inline_frame_is_marked_for_skip (true, ecs
->event_thread
))
7338 if (execution_direction
== EXEC_REVERSE
)
7339 handle_step_into_function_backward (gdbarch
, ecs
);
7341 handle_step_into_function (gdbarch
, ecs
);
7346 /* If we have no line number and the step-stop-if-no-debug is
7347 set, we stop the step so that the user has a chance to switch
7348 in assembly mode. */
7349 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7350 && step_stop_if_no_debug
)
7352 end_stepping_range (ecs
);
7356 if (execution_direction
== EXEC_REVERSE
)
7358 /* If we're already at the start of the function, we've either just
7359 stepped backward into a single instruction function without line
7360 number info, or stepped back out of a signal handler to the first
7361 instruction of the function without line number info. Just keep
7362 going, which will single-step back to the caller. */
7363 if (ecs
->stop_func_start
!= stop_pc
)
7365 /* Set a breakpoint at callee's start address.
7366 From there we can step once and be back in the caller. */
7367 symtab_and_line sr_sal
;
7368 sr_sal
.pc
= ecs
->stop_func_start
;
7369 sr_sal
.pspace
= get_frame_program_space (frame
);
7370 insert_step_resume_breakpoint_at_sal (gdbarch
,
7371 sr_sal
, null_frame_id
);
7375 /* Set a breakpoint at callee's return address (the address
7376 at which the caller will resume). */
7377 insert_step_resume_breakpoint_at_caller (frame
);
7383 /* Reverse stepping through solib trampolines. */
7385 if (execution_direction
== EXEC_REVERSE
7386 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7388 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7390 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7391 || (ecs
->stop_func_start
== 0
7392 && in_solib_dynsym_resolve_code (stop_pc
)))
7394 /* Any solib trampoline code can be handled in reverse
7395 by simply continuing to single-step. We have already
7396 executed the solib function (backwards), and a few
7397 steps will take us back through the trampoline to the
7402 else if (in_solib_dynsym_resolve_code (stop_pc
))
7404 /* Stepped backward into the solib dynsym resolver.
7405 Set a breakpoint at its start and continue, then
7406 one more step will take us out. */
7407 symtab_and_line sr_sal
;
7408 sr_sal
.pc
= ecs
->stop_func_start
;
7409 sr_sal
.pspace
= get_frame_program_space (frame
);
7410 insert_step_resume_breakpoint_at_sal (gdbarch
,
7411 sr_sal
, null_frame_id
);
7417 /* This always returns the sal for the inner-most frame when we are in a
7418 stack of inlined frames, even if GDB actually believes that it is in a
7419 more outer frame. This is checked for below by calls to
7420 inline_skipped_frames. */
7421 stop_pc_sal
= find_pc_line (ecs
->event_thread
->stop_pc (), 0);
7423 /* NOTE: tausq/2004-05-24: This if block used to be done before all
7424 the trampoline processing logic, however, there are some trampolines
7425 that have no names, so we should do trampoline handling first. */
7426 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7427 && ecs
->stop_func_name
== nullptr
7428 && stop_pc_sal
.line
== 0)
7430 infrun_debug_printf ("stepped into undebuggable function");
7432 /* The inferior just stepped into, or returned to, an
7433 undebuggable function (where there is no debugging information
7434 and no line number corresponding to the address where the
7435 inferior stopped). Since we want to skip this kind of code,
7436 we keep going until the inferior returns from this
7437 function - unless the user has asked us not to (via
7438 set step-mode) or we no longer know how to get back
7439 to the call site. */
7440 if (step_stop_if_no_debug
7441 || !frame_id_p (frame_unwind_caller_id (frame
)))
7443 /* If we have no line number and the step-stop-if-no-debug
7444 is set, we stop the step so that the user has a chance to
7445 switch in assembly mode. */
7446 end_stepping_range (ecs
);
7451 /* Set a breakpoint at callee's return address (the address
7452 at which the caller will resume). */
7453 insert_step_resume_breakpoint_at_caller (frame
);
7459 if (execution_direction
== EXEC_REVERSE
7460 && ecs
->event_thread
->control
.proceed_to_finish
7461 && ecs
->event_thread
->stop_pc () >= ecs
->stop_func_alt_start
7462 && ecs
->event_thread
->stop_pc () < ecs
->stop_func_start
)
7464 /* We are executing the reverse-finish command.
7465 If the system supports multiple entry points and we are finishing a
7466 function in reverse. If we are between the entry points singe-step
7467 back to the alternate entry point. If we are at the alternate entry
7468 point -- just need to back up by one more single-step, which
7469 should take us back to the function call. */
7470 ecs
->event_thread
->control
.step_range_start
7471 = ecs
->event_thread
->control
.step_range_end
= 1;
7477 if (ecs
->event_thread
->control
.step_range_end
== 1)
7479 /* It is stepi or nexti. We always want to stop stepping after
7481 infrun_debug_printf ("stepi/nexti");
7482 end_stepping_range (ecs
);
7486 if (stop_pc_sal
.line
== 0)
7488 /* We have no line number information. That means to stop
7489 stepping (does this always happen right after one instruction,
7490 when we do "s" in a function with no line numbers,
7491 or can this happen as a result of a return or longjmp?). */
7492 infrun_debug_printf ("line number info");
7493 end_stepping_range (ecs
);
7497 /* Look for "calls" to inlined functions, part one. If the inline
7498 frame machinery detected some skipped call sites, we have entered
7499 a new inline function. */
7501 if ((get_frame_id (get_current_frame ())
7502 == ecs
->event_thread
->control
.step_frame_id
)
7503 && inline_skipped_frames (ecs
->event_thread
))
7505 infrun_debug_printf ("stepped into inlined function");
7507 symtab_and_line call_sal
= find_frame_sal (get_current_frame ());
7509 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
7511 /* For "step", we're going to stop. But if the call site
7512 for this inlined function is on the same source line as
7513 we were previously stepping, go down into the function
7514 first. Otherwise stop at the call site. */
7516 if (call_sal
.line
== ecs
->event_thread
->current_line
7517 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7519 step_into_inline_frame (ecs
->event_thread
);
7520 if (inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7527 end_stepping_range (ecs
);
7532 /* For "next", we should stop at the call site if it is on a
7533 different source line. Otherwise continue through the
7534 inlined function. */
7535 if (call_sal
.line
== ecs
->event_thread
->current_line
7536 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7539 end_stepping_range (ecs
);
7544 /* Look for "calls" to inlined functions, part two. If we are still
7545 in the same real function we were stepping through, but we have
7546 to go further up to find the exact frame ID, we are stepping
7547 through a more inlined call beyond its call site. */
7549 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
7550 && (get_frame_id (get_current_frame ())
7551 != ecs
->event_thread
->control
.step_frame_id
)
7552 && stepped_in_from (get_current_frame (),
7553 ecs
->event_thread
->control
.step_frame_id
))
7555 infrun_debug_printf ("stepping through inlined function");
7557 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
7558 || inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7561 end_stepping_range (ecs
);
7565 bool refresh_step_info
= true;
7566 if ((ecs
->event_thread
->stop_pc () == stop_pc_sal
.pc
)
7567 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
7568 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
7570 /* We are at a different line. */
7572 if (stop_pc_sal
.is_stmt
)
7574 /* We are at the start of a statement.
7576 So stop. Note that we don't stop if we step into the middle of a
7577 statement. That is said to make things like for (;;) statements
7579 infrun_debug_printf ("stepped to a different line");
7580 end_stepping_range (ecs
);
7583 else if (get_frame_id (get_current_frame ())
7584 == ecs
->event_thread
->control
.step_frame_id
)
7586 /* We are not at the start of a statement, and we have not changed
7589 We ignore this line table entry, and continue stepping forward,
7590 looking for a better place to stop. */
7591 refresh_step_info
= false;
7592 infrun_debug_printf ("stepped to a different line, but "
7593 "it's not the start of a statement");
7597 /* We are not the start of a statement, and we have changed frame.
7599 We ignore this line table entry, and continue stepping forward,
7600 looking for a better place to stop. Keep refresh_step_info at
7601 true to note that the frame has changed, but ignore the line
7602 number to make sure we don't ignore a subsequent entry with the
7603 same line number. */
7604 stop_pc_sal
.line
= 0;
7605 infrun_debug_printf ("stepped to a different frame, but "
7606 "it's not the start of a statement");
7610 /* We aren't done stepping.
7612 Optimize by setting the stepping range to the line.
7613 (We might not be in the original line, but if we entered a
7614 new line in mid-statement, we continue stepping. This makes
7615 things like for(;;) statements work better.)
7617 If we entered a SAL that indicates a non-statement line table entry,
7618 then we update the stepping range, but we don't update the step info,
7619 which includes things like the line number we are stepping away from.
7620 This means we will stop when we find a line table entry that is marked
7621 as is-statement, even if it matches the non-statement one we just
7624 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
7625 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
7626 ecs
->event_thread
->control
.may_range_step
= 1;
7628 ("updated step range, start = %s, end = %s, may_range_step = %d",
7629 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
7630 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
),
7631 ecs
->event_thread
->control
.may_range_step
);
7632 if (refresh_step_info
)
7633 set_step_info (ecs
->event_thread
, frame
, stop_pc_sal
);
7635 infrun_debug_printf ("keep going");
7639 static bool restart_stepped_thread (process_stratum_target
*resume_target
,
7640 ptid_t resume_ptid
);
7642 /* In all-stop mode, if we're currently stepping but have stopped in
7643 some other thread, we may need to switch back to the stepped
7644 thread. Returns true we set the inferior running, false if we left
7645 it stopped (and the event needs further processing). */
7648 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
7650 if (!target_is_non_stop_p ())
7652 /* If any thread is blocked on some internal breakpoint, and we
7653 simply need to step over that breakpoint to get it going
7654 again, do that first. */
7656 /* However, if we see an event for the stepping thread, then we
7657 know all other threads have been moved past their breakpoints
7658 already. Let the caller check whether the step is finished,
7659 etc., before deciding to move it past a breakpoint. */
7660 if (ecs
->event_thread
->control
.step_range_end
!= 0)
7663 /* Check if the current thread is blocked on an incomplete
7664 step-over, interrupted by a random signal. */
7665 if (ecs
->event_thread
->control
.trap_expected
7666 && ecs
->event_thread
->stop_signal () != GDB_SIGNAL_TRAP
)
7669 ("need to finish step-over of [%s]",
7670 ecs
->event_thread
->ptid
.to_string ().c_str ());
7675 /* Check if the current thread is blocked by a single-step
7676 breakpoint of another thread. */
7677 if (ecs
->hit_singlestep_breakpoint
)
7679 infrun_debug_printf ("need to step [%s] over single-step breakpoint",
7680 ecs
->ptid
.to_string ().c_str ());
7685 /* If this thread needs yet another step-over (e.g., stepping
7686 through a delay slot), do it first before moving on to
7688 if (thread_still_needs_step_over (ecs
->event_thread
))
7691 ("thread [%s] still needs step-over",
7692 ecs
->event_thread
->ptid
.to_string ().c_str ());
7697 /* If scheduler locking applies even if not stepping, there's no
7698 need to walk over threads. Above we've checked whether the
7699 current thread is stepping. If some other thread not the
7700 event thread is stepping, then it must be that scheduler
7701 locking is not in effect. */
7702 if (schedlock_applies (ecs
->event_thread
))
7705 /* Otherwise, we no longer expect a trap in the current thread.
7706 Clear the trap_expected flag before switching back -- this is
7707 what keep_going does as well, if we call it. */
7708 ecs
->event_thread
->control
.trap_expected
= 0;
7710 /* Likewise, clear the signal if it should not be passed. */
7711 if (!signal_program
[ecs
->event_thread
->stop_signal ()])
7712 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
7714 if (restart_stepped_thread (ecs
->target
, ecs
->ptid
))
7716 prepare_to_wait (ecs
);
7720 switch_to_thread (ecs
->event_thread
);
7726 /* Look for the thread that was stepping, and resume it.
7727 RESUME_TARGET / RESUME_PTID indicate the set of threads the caller
7728 is resuming. Return true if a thread was started, false
7732 restart_stepped_thread (process_stratum_target
*resume_target
,
7735 /* Do all pending step-overs before actually proceeding with
7737 if (start_step_over ())
7740 for (thread_info
*tp
: all_threads_safe ())
7742 if (tp
->state
== THREAD_EXITED
)
7745 if (tp
->has_pending_waitstatus ())
7748 /* Ignore threads of processes the caller is not
7751 && (tp
->inf
->process_target () != resume_target
7752 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7755 if (tp
->control
.trap_expected
)
7757 infrun_debug_printf ("switching back to stepped thread (step-over)");
7759 if (keep_going_stepped_thread (tp
))
7764 for (thread_info
*tp
: all_threads_safe ())
7766 if (tp
->state
== THREAD_EXITED
)
7769 if (tp
->has_pending_waitstatus ())
7772 /* Ignore threads of processes the caller is not
7775 && (tp
->inf
->process_target () != resume_target
7776 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7779 /* Did we find the stepping thread? */
7780 if (tp
->control
.step_range_end
)
7782 infrun_debug_printf ("switching back to stepped thread (stepping)");
7784 if (keep_going_stepped_thread (tp
))
7795 restart_after_all_stop_detach (process_stratum_target
*proc_target
)
7797 /* Note we don't check target_is_non_stop_p() here, because the
7798 current inferior may no longer have a process_stratum target
7799 pushed, as we just detached. */
7801 /* See if we have a THREAD_RUNNING thread that need to be
7802 re-resumed. If we have any thread that is already executing,
7803 then we don't need to resume the target -- it is already been
7804 resumed. With the remote target (in all-stop), it's even
7805 impossible to issue another resumption if the target is already
7806 resumed, until the target reports a stop. */
7807 for (thread_info
*thr
: all_threads (proc_target
))
7809 if (thr
->state
!= THREAD_RUNNING
)
7812 /* If we have any thread that is already executing, then we
7813 don't need to resume the target -- it is already been
7815 if (thr
->executing ())
7818 /* If we have a pending event to process, skip resuming the
7819 target and go straight to processing it. */
7820 if (thr
->resumed () && thr
->has_pending_waitstatus ())
7824 /* Alright, we need to re-resume the target. If a thread was
7825 stepping, we need to restart it stepping. */
7826 if (restart_stepped_thread (proc_target
, minus_one_ptid
))
7829 /* Otherwise, find the first THREAD_RUNNING thread and resume
7831 for (thread_info
*thr
: all_threads (proc_target
))
7833 if (thr
->state
!= THREAD_RUNNING
)
7836 execution_control_state
ecs (thr
);
7837 switch_to_thread (thr
);
7843 /* Set a previously stepped thread back to stepping. Returns true on
7844 success, false if the resume is not possible (e.g., the thread
7848 keep_going_stepped_thread (struct thread_info
*tp
)
7850 frame_info_ptr frame
;
7852 /* If the stepping thread exited, then don't try to switch back and
7853 resume it, which could fail in several different ways depending
7854 on the target. Instead, just keep going.
7856 We can find a stepping dead thread in the thread list in two
7859 - The target supports thread exit events, and when the target
7860 tries to delete the thread from the thread list, inferior_ptid
7861 pointed at the exiting thread. In such case, calling
7862 delete_thread does not really remove the thread from the list;
7863 instead, the thread is left listed, with 'exited' state.
7865 - The target's debug interface does not support thread exit
7866 events, and so we have no idea whatsoever if the previously
7867 stepping thread is still alive. For that reason, we need to
7868 synchronously query the target now. */
7870 if (tp
->state
== THREAD_EXITED
|| !target_thread_alive (tp
->ptid
))
7872 infrun_debug_printf ("not resuming previously stepped thread, it has "
7879 infrun_debug_printf ("resuming previously stepped thread");
7881 execution_control_state
ecs (tp
);
7882 switch_to_thread (tp
);
7884 tp
->set_stop_pc (regcache_read_pc (get_thread_regcache (tp
)));
7885 frame
= get_current_frame ();
7887 /* If the PC of the thread we were trying to single-step has
7888 changed, then that thread has trapped or been signaled, but the
7889 event has not been reported to GDB yet. Re-poll the target
7890 looking for this particular thread's event (i.e. temporarily
7891 enable schedlock) by:
7893 - setting a break at the current PC
7894 - resuming that particular thread, only (by setting trap
7897 This prevents us continuously moving the single-step breakpoint
7898 forward, one instruction at a time, overstepping. */
7900 if (tp
->stop_pc () != tp
->prev_pc
)
7904 infrun_debug_printf ("expected thread advanced also (%s -> %s)",
7905 paddress (target_gdbarch (), tp
->prev_pc
),
7906 paddress (target_gdbarch (), tp
->stop_pc ()));
7908 /* Clear the info of the previous step-over, as it's no longer
7909 valid (if the thread was trying to step over a breakpoint, it
7910 has already succeeded). It's what keep_going would do too,
7911 if we called it. Do this before trying to insert the sss
7912 breakpoint, otherwise if we were previously trying to step
7913 over this exact address in another thread, the breakpoint is
7915 clear_step_over_info ();
7916 tp
->control
.trap_expected
= 0;
7918 insert_single_step_breakpoint (get_frame_arch (frame
),
7919 get_frame_address_space (frame
),
7922 tp
->set_resumed (true);
7923 resume_ptid
= internal_resume_ptid (tp
->control
.stepping_command
);
7924 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
7928 infrun_debug_printf ("expected thread still hasn't advanced");
7930 keep_going_pass_signal (&ecs
);
7936 /* Is thread TP in the middle of (software or hardware)
7937 single-stepping? (Note the result of this function must never be
7938 passed directly as target_resume's STEP parameter.) */
7941 currently_stepping (struct thread_info
*tp
)
7943 return ((tp
->control
.step_range_end
7944 && tp
->control
.step_resume_breakpoint
== nullptr)
7945 || tp
->control
.trap_expected
7946 || tp
->stepped_breakpoint
7947 || bpstat_should_step ());
7950 /* Inferior has stepped into a subroutine call with source code that
7951 we should not step over. Do step to the first line of code in
7955 handle_step_into_function (struct gdbarch
*gdbarch
,
7956 struct execution_control_state
*ecs
)
7958 fill_in_stop_func (gdbarch
, ecs
);
7960 compunit_symtab
*cust
7961 = find_pc_compunit_symtab (ecs
->event_thread
->stop_pc ());
7962 if (cust
!= nullptr && cust
->language () != language_asm
)
7963 ecs
->stop_func_start
7964 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7966 symtab_and_line stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7967 /* Use the step_resume_break to step until the end of the prologue,
7968 even if that involves jumps (as it seems to on the vax under
7970 /* If the prologue ends in the middle of a source line, continue to
7971 the end of that source line (if it is still within the function).
7972 Otherwise, just go to end of prologue. */
7973 if (stop_func_sal
.end
7974 && stop_func_sal
.pc
!= ecs
->stop_func_start
7975 && stop_func_sal
.end
< ecs
->stop_func_end
)
7976 ecs
->stop_func_start
= stop_func_sal
.end
;
7978 /* Architectures which require breakpoint adjustment might not be able
7979 to place a breakpoint at the computed address. If so, the test
7980 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
7981 ecs->stop_func_start to an address at which a breakpoint may be
7982 legitimately placed.
7984 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
7985 made, GDB will enter an infinite loop when stepping through
7986 optimized code consisting of VLIW instructions which contain
7987 subinstructions corresponding to different source lines. On
7988 FR-V, it's not permitted to place a breakpoint on any but the
7989 first subinstruction of a VLIW instruction. When a breakpoint is
7990 set, GDB will adjust the breakpoint address to the beginning of
7991 the VLIW instruction. Thus, we need to make the corresponding
7992 adjustment here when computing the stop address. */
7994 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7996 ecs
->stop_func_start
7997 = gdbarch_adjust_breakpoint_address (gdbarch
,
7998 ecs
->stop_func_start
);
8001 if (ecs
->stop_func_start
== ecs
->event_thread
->stop_pc ())
8003 /* We are already there: stop now. */
8004 end_stepping_range (ecs
);
8009 /* Put the step-breakpoint there and go until there. */
8010 symtab_and_line sr_sal
;
8011 sr_sal
.pc
= ecs
->stop_func_start
;
8012 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
8013 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
8015 /* Do not specify what the fp should be when we stop since on
8016 some machines the prologue is where the new fp value is
8018 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
8020 /* And make sure stepping stops right away then. */
8021 ecs
->event_thread
->control
.step_range_end
8022 = ecs
->event_thread
->control
.step_range_start
;
8027 /* Inferior has stepped backward into a subroutine call with source
8028 code that we should not step over. Do step to the beginning of the
8029 last line of code in it. */
8032 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
8033 struct execution_control_state
*ecs
)
8035 struct compunit_symtab
*cust
;
8036 struct symtab_and_line stop_func_sal
;
8038 fill_in_stop_func (gdbarch
, ecs
);
8040 cust
= find_pc_compunit_symtab (ecs
->event_thread
->stop_pc ());
8041 if (cust
!= nullptr && cust
->language () != language_asm
)
8042 ecs
->stop_func_start
8043 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
8045 stop_func_sal
= find_pc_line (ecs
->event_thread
->stop_pc (), 0);
8047 /* OK, we're just going to keep stepping here. */
8048 if (stop_func_sal
.pc
== ecs
->event_thread
->stop_pc ())
8050 /* We're there already. Just stop stepping now. */
8051 end_stepping_range (ecs
);
8055 /* Else just reset the step range and keep going.
8056 No step-resume breakpoint, they don't work for
8057 epilogues, which can have multiple entry paths. */
8058 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
8059 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
8065 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
8066 This is used to both functions and to skip over code. */
8069 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
8070 struct symtab_and_line sr_sal
,
8071 struct frame_id sr_id
,
8072 enum bptype sr_type
)
8074 /* There should never be more than one step-resume or longjmp-resume
8075 breakpoint per thread, so we should never be setting a new
8076 step_resume_breakpoint when one is already active. */
8077 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== nullptr);
8078 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
8080 infrun_debug_printf ("inserting step-resume breakpoint at %s",
8081 paddress (gdbarch
, sr_sal
.pc
));
8083 inferior_thread ()->control
.step_resume_breakpoint
8084 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
).release ();
8088 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
8089 struct symtab_and_line sr_sal
,
8090 struct frame_id sr_id
)
8092 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
8097 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
8098 This is used to skip a potential signal handler.
8100 This is called with the interrupted function's frame. The signal
8101 handler, when it returns, will resume the interrupted function at
8105 insert_hp_step_resume_breakpoint_at_frame (frame_info_ptr return_frame
)
8107 gdb_assert (return_frame
!= nullptr);
8109 struct gdbarch
*gdbarch
= get_frame_arch (return_frame
);
8111 symtab_and_line sr_sal
;
8112 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
8113 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
8114 sr_sal
.pspace
= get_frame_program_space (return_frame
);
8116 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
8117 get_stack_frame_id (return_frame
),
8121 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
8122 is used to skip a function after stepping into it (for "next" or if
8123 the called function has no debugging information).
8125 The current function has almost always been reached by single
8126 stepping a call or return instruction. NEXT_FRAME belongs to the
8127 current function, and the breakpoint will be set at the caller's
8130 This is a separate function rather than reusing
8131 insert_hp_step_resume_breakpoint_at_frame in order to avoid
8132 get_prev_frame, which may stop prematurely (see the implementation
8133 of frame_unwind_caller_id for an example). */
8136 insert_step_resume_breakpoint_at_caller (frame_info_ptr next_frame
)
8138 /* We shouldn't have gotten here if we don't know where the call site
8140 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
8142 struct gdbarch
*gdbarch
= frame_unwind_caller_arch (next_frame
);
8144 symtab_and_line sr_sal
;
8145 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
8146 frame_unwind_caller_pc (next_frame
));
8147 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
8148 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
8150 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
8151 frame_unwind_caller_id (next_frame
));
8154 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
8155 new breakpoint at the target of a jmp_buf. The handling of
8156 longjmp-resume uses the same mechanisms used for handling
8157 "step-resume" breakpoints. */
8160 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8162 /* There should never be more than one longjmp-resume breakpoint per
8163 thread, so we should never be setting a new
8164 longjmp_resume_breakpoint when one is already active. */
8165 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== nullptr);
8167 infrun_debug_printf ("inserting longjmp-resume breakpoint at %s",
8168 paddress (gdbarch
, pc
));
8170 inferior_thread ()->control
.exception_resume_breakpoint
=
8171 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
).release ();
8174 /* Insert an exception resume breakpoint. TP is the thread throwing
8175 the exception. The block B is the block of the unwinder debug hook
8176 function. FRAME is the frame corresponding to the call to this
8177 function. SYM is the symbol of the function argument holding the
8178 target PC of the exception. */
8181 insert_exception_resume_breakpoint (struct thread_info
*tp
,
8182 const struct block
*b
,
8183 frame_info_ptr frame
,
8188 struct block_symbol vsym
;
8189 struct value
*value
;
8191 struct breakpoint
*bp
;
8193 vsym
= lookup_symbol_search_name (sym
->search_name (),
8195 value
= read_var_value (vsym
.symbol
, vsym
.block
, frame
);
8196 /* If the value was optimized out, revert to the old behavior. */
8197 if (! value
->optimized_out ())
8199 handler
= value_as_address (value
);
8201 infrun_debug_printf ("exception resume at %lx",
8202 (unsigned long) handler
);
8204 /* set_momentary_breakpoint_at_pc creates a thread-specific
8205 breakpoint for the current inferior thread. */
8206 gdb_assert (tp
== inferior_thread ());
8207 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8209 bp_exception_resume
).release ();
8211 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
8214 tp
->control
.exception_resume_breakpoint
= bp
;
8217 catch (const gdb_exception_error
&e
)
8219 /* We want to ignore errors here. */
8223 /* A helper for check_exception_resume that sets an
8224 exception-breakpoint based on a SystemTap probe. */
8227 insert_exception_resume_from_probe (struct thread_info
*tp
,
8228 const struct bound_probe
*probe
,
8229 frame_info_ptr frame
)
8231 struct value
*arg_value
;
8233 struct breakpoint
*bp
;
8235 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
8239 handler
= value_as_address (arg_value
);
8241 infrun_debug_printf ("exception resume at %s",
8242 paddress (probe
->objfile
->arch (), handler
));
8244 /* set_momentary_breakpoint_at_pc creates a thread-specific breakpoint
8245 for the current inferior thread. */
8246 gdb_assert (tp
== inferior_thread ());
8247 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8248 handler
, bp_exception_resume
).release ();
8249 tp
->control
.exception_resume_breakpoint
= bp
;
8252 /* This is called when an exception has been intercepted. Check to
8253 see whether the exception's destination is of interest, and if so,
8254 set an exception resume breakpoint there. */
8257 check_exception_resume (struct execution_control_state
*ecs
,
8258 frame_info_ptr frame
)
8260 struct bound_probe probe
;
8261 struct symbol
*func
;
8263 /* First see if this exception unwinding breakpoint was set via a
8264 SystemTap probe point. If so, the probe has two arguments: the
8265 CFA and the HANDLER. We ignore the CFA, extract the handler, and
8266 set a breakpoint there. */
8267 probe
= find_probe_by_pc (get_frame_pc (frame
));
8270 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
8274 func
= get_frame_function (frame
);
8280 const struct block
*b
;
8283 /* The exception breakpoint is a thread-specific breakpoint on
8284 the unwinder's debug hook, declared as:
8286 void _Unwind_DebugHook (void *cfa, void *handler);
8288 The CFA argument indicates the frame to which control is
8289 about to be transferred. HANDLER is the destination PC.
8291 We ignore the CFA and set a temporary breakpoint at HANDLER.
8292 This is not extremely efficient but it avoids issues in gdb
8293 with computing the DWARF CFA, and it also works even in weird
8294 cases such as throwing an exception from inside a signal
8297 b
= func
->value_block ();
8298 for (struct symbol
*sym
: block_iterator_range (b
))
8300 if (!sym
->is_argument ())
8307 insert_exception_resume_breakpoint (ecs
->event_thread
,
8313 catch (const gdb_exception_error
&e
)
8319 stop_waiting (struct execution_control_state
*ecs
)
8321 infrun_debug_printf ("stop_waiting");
8323 /* Let callers know we don't want to wait for the inferior anymore. */
8324 ecs
->wait_some_more
= 0;
8327 /* Like keep_going, but passes the signal to the inferior, even if the
8328 signal is set to nopass. */
8331 keep_going_pass_signal (struct execution_control_state
*ecs
)
8333 gdb_assert (ecs
->event_thread
->ptid
== inferior_ptid
);
8334 gdb_assert (!ecs
->event_thread
->resumed ());
8336 /* Save the pc before execution, to compare with pc after stop. */
8337 ecs
->event_thread
->prev_pc
8338 = regcache_read_pc_protected (get_thread_regcache (ecs
->event_thread
));
8340 if (ecs
->event_thread
->control
.trap_expected
)
8342 struct thread_info
*tp
= ecs
->event_thread
;
8344 infrun_debug_printf ("%s has trap_expected set, "
8345 "resuming to collect trap",
8346 tp
->ptid
.to_string ().c_str ());
8348 /* We haven't yet gotten our trap, and either: intercepted a
8349 non-signal event (e.g., a fork); or took a signal which we
8350 are supposed to pass through to the inferior. Simply
8352 resume (ecs
->event_thread
->stop_signal ());
8354 else if (step_over_info_valid_p ())
8356 /* Another thread is stepping over a breakpoint in-line. If
8357 this thread needs a step-over too, queue the request. In
8358 either case, this resume must be deferred for later. */
8359 struct thread_info
*tp
= ecs
->event_thread
;
8361 if (ecs
->hit_singlestep_breakpoint
8362 || thread_still_needs_step_over (tp
))
8364 infrun_debug_printf ("step-over already in progress: "
8365 "step-over for %s deferred",
8366 tp
->ptid
.to_string ().c_str ());
8367 global_thread_step_over_chain_enqueue (tp
);
8370 infrun_debug_printf ("step-over in progress: resume of %s deferred",
8371 tp
->ptid
.to_string ().c_str ());
8375 struct regcache
*regcache
= get_current_regcache ();
8378 step_over_what step_what
;
8380 /* Either the trap was not expected, but we are continuing
8381 anyway (if we got a signal, the user asked it be passed to
8384 We got our expected trap, but decided we should resume from
8387 We're going to run this baby now!
8389 Note that insert_breakpoints won't try to re-insert
8390 already inserted breakpoints. Therefore, we don't
8391 care if breakpoints were already inserted, or not. */
8393 /* If we need to step over a breakpoint, and we're not using
8394 displaced stepping to do so, insert all breakpoints
8395 (watchpoints, etc.) but the one we're stepping over, step one
8396 instruction, and then re-insert the breakpoint when that step
8399 step_what
= thread_still_needs_step_over (ecs
->event_thread
);
8401 remove_bp
= (ecs
->hit_singlestep_breakpoint
8402 || (step_what
& STEP_OVER_BREAKPOINT
));
8403 remove_wps
= (step_what
& STEP_OVER_WATCHPOINT
);
8405 /* We can't use displaced stepping if we need to step past a
8406 watchpoint. The instruction copied to the scratch pad would
8407 still trigger the watchpoint. */
8409 && (remove_wps
|| !use_displaced_stepping (ecs
->event_thread
)))
8411 set_step_over_info (regcache
->aspace (),
8412 regcache_read_pc (regcache
), remove_wps
,
8413 ecs
->event_thread
->global_num
);
8415 else if (remove_wps
)
8416 set_step_over_info (nullptr, 0, remove_wps
, -1);
8418 /* If we now need to do an in-line step-over, we need to stop
8419 all other threads. Note this must be done before
8420 insert_breakpoints below, because that removes the breakpoint
8421 we're about to step over, otherwise other threads could miss
8423 if (step_over_info_valid_p () && target_is_non_stop_p ())
8424 stop_all_threads ("starting in-line step-over");
8426 /* Stop stepping if inserting breakpoints fails. */
8429 insert_breakpoints ();
8431 catch (const gdb_exception_error
&e
)
8433 exception_print (gdb_stderr
, e
);
8435 clear_step_over_info ();
8439 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
8441 resume (ecs
->event_thread
->stop_signal ());
8444 prepare_to_wait (ecs
);
8447 /* Called when we should continue running the inferior, because the
8448 current event doesn't cause a user visible stop. This does the
8449 resuming part; waiting for the next event is done elsewhere. */
8452 keep_going (struct execution_control_state
*ecs
)
8454 if (ecs
->event_thread
->control
.trap_expected
8455 && ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
8456 ecs
->event_thread
->control
.trap_expected
= 0;
8458 if (!signal_program
[ecs
->event_thread
->stop_signal ()])
8459 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
8460 keep_going_pass_signal (ecs
);
8463 /* This function normally comes after a resume, before
8464 handle_inferior_event exits. It takes care of any last bits of
8465 housekeeping, and sets the all-important wait_some_more flag. */
8468 prepare_to_wait (struct execution_control_state
*ecs
)
8470 infrun_debug_printf ("prepare_to_wait");
8472 ecs
->wait_some_more
= 1;
8474 /* If the target can't async, emulate it by marking the infrun event
8475 handler such that as soon as we get back to the event-loop, we
8476 immediately end up in fetch_inferior_event again calling
8478 if (!target_can_async_p ())
8479 mark_infrun_async_event_handler ();
8482 /* We are done with the step range of a step/next/si/ni command.
8483 Called once for each n of a "step n" operation. */
8486 end_stepping_range (struct execution_control_state
*ecs
)
8488 ecs
->event_thread
->control
.stop_step
= 1;
8492 /* Several print_*_reason functions to print why the inferior has stopped.
8493 We always print something when the inferior exits, or receives a signal.
8494 The rest of the cases are dealt with later on in normal_stop and
8495 print_it_typical. Ideally there should be a call to one of these
8496 print_*_reason functions functions from handle_inferior_event each time
8497 stop_waiting is called.
8499 Note that we don't call these directly, instead we delegate that to
8500 the interpreters, through observers. Interpreters then call these
8501 with whatever uiout is right. */
8504 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8506 annotate_signalled ();
8507 if (uiout
->is_mi_like_p ())
8509 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
8510 uiout
->text ("\nProgram terminated with signal ");
8511 annotate_signal_name ();
8512 uiout
->field_string ("signal-name",
8513 gdb_signal_to_name (siggnal
));
8514 annotate_signal_name_end ();
8516 annotate_signal_string ();
8517 uiout
->field_string ("signal-meaning",
8518 gdb_signal_to_string (siggnal
));
8519 annotate_signal_string_end ();
8520 uiout
->text (".\n");
8521 uiout
->text ("The program no longer exists.\n");
8525 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
8527 struct inferior
*inf
= current_inferior ();
8528 std::string pidstr
= target_pid_to_str (ptid_t (inf
->pid
));
8530 annotate_exited (exitstatus
);
8533 if (uiout
->is_mi_like_p ())
8534 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXITED
));
8535 std::string exit_code_str
8536 = string_printf ("0%o", (unsigned int) exitstatus
);
8537 uiout
->message ("[Inferior %s (%s) exited with code %pF]\n",
8538 plongest (inf
->num
), pidstr
.c_str (),
8539 string_field ("exit-code", exit_code_str
.c_str ()));
8543 if (uiout
->is_mi_like_p ())
8545 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
8546 uiout
->message ("[Inferior %s (%s) exited normally]\n",
8547 plongest (inf
->num
), pidstr
.c_str ());
8552 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8554 struct thread_info
*thr
= inferior_thread ();
8556 infrun_debug_printf ("signal = %s", gdb_signal_to_string (siggnal
));
8560 if (uiout
->is_mi_like_p ())
8562 else if (show_thread_that_caused_stop ())
8564 uiout
->text ("\nThread ");
8565 uiout
->field_string ("thread-id", print_thread_id (thr
));
8567 const char *name
= thread_name (thr
);
8568 if (name
!= nullptr)
8570 uiout
->text (" \"");
8571 uiout
->field_string ("name", name
);
8576 uiout
->text ("\nProgram");
8578 if (siggnal
== GDB_SIGNAL_0
&& !uiout
->is_mi_like_p ())
8579 uiout
->text (" stopped");
8582 uiout
->text (" received signal ");
8583 annotate_signal_name ();
8584 if (uiout
->is_mi_like_p ())
8586 ("reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
8587 uiout
->field_string ("signal-name", gdb_signal_to_name (siggnal
));
8588 annotate_signal_name_end ();
8590 annotate_signal_string ();
8591 uiout
->field_string ("signal-meaning", gdb_signal_to_string (siggnal
));
8593 struct regcache
*regcache
= get_current_regcache ();
8594 struct gdbarch
*gdbarch
= regcache
->arch ();
8595 if (gdbarch_report_signal_info_p (gdbarch
))
8596 gdbarch_report_signal_info (gdbarch
, uiout
, siggnal
);
8598 annotate_signal_string_end ();
8600 uiout
->text (".\n");
8604 print_no_history_reason (struct ui_out
*uiout
)
8606 if (uiout
->is_mi_like_p ())
8607 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_NO_HISTORY
));
8609 uiout
->text ("\nNo more reverse-execution history.\n");
8612 /* Print current location without a level number, if we have changed
8613 functions or hit a breakpoint. Print source line if we have one.
8614 bpstat_print contains the logic deciding in detail what to print,
8615 based on the event(s) that just occurred. */
8618 print_stop_location (const target_waitstatus
&ws
)
8621 enum print_what source_flag
;
8622 int do_frame_printing
= 1;
8623 struct thread_info
*tp
= inferior_thread ();
8625 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
.kind ());
8629 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
8630 should) carry around the function and does (or should) use
8631 that when doing a frame comparison. */
8632 if (tp
->control
.stop_step
8633 && (tp
->control
.step_frame_id
8634 == get_frame_id (get_current_frame ()))
8635 && (tp
->control
.step_start_function
8636 == find_pc_function (tp
->stop_pc ())))
8638 /* Finished step, just print source line. */
8639 source_flag
= SRC_LINE
;
8643 /* Print location and source line. */
8644 source_flag
= SRC_AND_LOC
;
8647 case PRINT_SRC_AND_LOC
:
8648 /* Print location and source line. */
8649 source_flag
= SRC_AND_LOC
;
8651 case PRINT_SRC_ONLY
:
8652 source_flag
= SRC_LINE
;
8655 /* Something bogus. */
8656 source_flag
= SRC_LINE
;
8657 do_frame_printing
= 0;
8660 internal_error (_("Unknown value."));
8663 /* The behavior of this routine with respect to the source
8665 SRC_LINE: Print only source line
8666 LOCATION: Print only location
8667 SRC_AND_LOC: Print location and source line. */
8668 if (do_frame_printing
)
8669 print_stack_frame (get_selected_frame (nullptr), 0, source_flag
, 1);
8675 print_stop_event (struct ui_out
*uiout
, bool displays
)
8677 struct target_waitstatus last
;
8678 struct thread_info
*tp
;
8680 get_last_target_status (nullptr, nullptr, &last
);
8683 scoped_restore save_uiout
= make_scoped_restore (¤t_uiout
, uiout
);
8685 print_stop_location (last
);
8687 /* Display the auto-display expressions. */
8692 tp
= inferior_thread ();
8693 if (tp
->thread_fsm () != nullptr
8694 && tp
->thread_fsm ()->finished_p ())
8696 struct return_value_info
*rv
;
8698 rv
= tp
->thread_fsm ()->return_value ();
8700 print_return_value (uiout
, rv
);
8707 maybe_remove_breakpoints (void)
8709 if (!breakpoints_should_be_inserted_now () && target_has_execution ())
8711 if (remove_breakpoints ())
8713 target_terminal::ours_for_output ();
8714 gdb_printf (_("Cannot remove breakpoints because "
8715 "program is no longer writable.\nFurther "
8716 "execution is probably impossible.\n"));
8721 /* The execution context that just caused a normal stop. */
8727 DISABLE_COPY_AND_ASSIGN (stop_context
);
8729 bool changed () const;
8734 /* The event PTID. */
8738 /* If stopp for a thread event, this is the thread that caused the
8740 thread_info_ref thread
;
8742 /* The inferior that caused the stop. */
8746 /* Initializes a new stop context. If stopped for a thread event, this
8747 takes a strong reference to the thread. */
8749 stop_context::stop_context ()
8751 stop_id
= get_stop_id ();
8752 ptid
= inferior_ptid
;
8753 inf_num
= current_inferior ()->num
;
8755 if (inferior_ptid
!= null_ptid
)
8757 /* Take a strong reference so that the thread can't be deleted
8759 thread
= thread_info_ref::new_reference (inferior_thread ());
8763 /* Return true if the current context no longer matches the saved stop
8767 stop_context::changed () const
8769 if (ptid
!= inferior_ptid
)
8771 if (inf_num
!= current_inferior ()->num
)
8773 if (thread
!= nullptr && thread
->state
!= THREAD_STOPPED
)
8775 if (get_stop_id () != stop_id
)
8785 struct target_waitstatus last
;
8787 get_last_target_status (nullptr, nullptr, &last
);
8791 /* If an exception is thrown from this point on, make sure to
8792 propagate GDB's knowledge of the executing state to the
8793 frontend/user running state. A QUIT is an easy exception to see
8794 here, so do this before any filtered output. */
8796 ptid_t finish_ptid
= null_ptid
;
8799 finish_ptid
= minus_one_ptid
;
8800 else if (last
.kind () == TARGET_WAITKIND_SIGNALLED
8801 || last
.kind () == TARGET_WAITKIND_EXITED
)
8803 /* On some targets, we may still have live threads in the
8804 inferior when we get a process exit event. E.g., for
8805 "checkpoint", when the current checkpoint/fork exits,
8806 linux-fork.c automatically switches to another fork from
8807 within target_mourn_inferior. */
8808 if (inferior_ptid
!= null_ptid
)
8809 finish_ptid
= ptid_t (inferior_ptid
.pid ());
8811 else if (last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
8812 finish_ptid
= inferior_ptid
;
8814 gdb::optional
<scoped_finish_thread_state
> maybe_finish_thread_state
;
8815 if (finish_ptid
!= null_ptid
)
8817 maybe_finish_thread_state
.emplace
8818 (user_visible_resume_target (finish_ptid
), finish_ptid
);
8821 /* As we're presenting a stop, and potentially removing breakpoints,
8822 update the thread list so we can tell whether there are threads
8823 running on the target. With target remote, for example, we can
8824 only learn about new threads when we explicitly update the thread
8825 list. Do this before notifying the interpreters about signal
8826 stops, end of stepping ranges, etc., so that the "new thread"
8827 output is emitted before e.g., "Program received signal FOO",
8828 instead of after. */
8829 update_thread_list ();
8831 if (last
.kind () == TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
8832 gdb::observers::signal_received
.notify (inferior_thread ()->stop_signal ());
8834 /* As with the notification of thread events, we want to delay
8835 notifying the user that we've switched thread context until
8836 the inferior actually stops.
8838 There's no point in saying anything if the inferior has exited.
8839 Note that SIGNALLED here means "exited with a signal", not
8840 "received a signal".
8842 Also skip saying anything in non-stop mode. In that mode, as we
8843 don't want GDB to switch threads behind the user's back, to avoid
8844 races where the user is typing a command to apply to thread x,
8845 but GDB switches to thread y before the user finishes entering
8846 the command, fetch_inferior_event installs a cleanup to restore
8847 the current thread back to the thread the user had selected right
8848 after this event is handled, so we're not really switching, only
8849 informing of a stop. */
8852 if ((last
.kind () != TARGET_WAITKIND_SIGNALLED
8853 && last
.kind () != TARGET_WAITKIND_EXITED
8854 && last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
8855 && target_has_execution ()
8856 && previous_thread
!= inferior_thread ())
8858 SWITCH_THRU_ALL_UIS ()
8860 target_terminal::ours_for_output ();
8861 gdb_printf (_("[Switching to %s]\n"),
8862 target_pid_to_str (inferior_ptid
).c_str ());
8863 annotate_thread_changed ();
8867 update_previous_thread ();
8870 if (last
.kind () == TARGET_WAITKIND_NO_RESUMED
)
8872 SWITCH_THRU_ALL_UIS ()
8873 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
8875 target_terminal::ours_for_output ();
8876 gdb_printf (_("No unwaited-for children left.\n"));
8880 /* Note: this depends on the update_thread_list call above. */
8881 maybe_remove_breakpoints ();
8883 /* If an auto-display called a function and that got a signal,
8884 delete that auto-display to avoid an infinite recursion. */
8886 if (stopped_by_random_signal
)
8887 disable_current_display ();
8889 SWITCH_THRU_ALL_UIS ()
8891 async_enable_stdin ();
8894 /* Let the user/frontend see the threads as stopped. */
8895 maybe_finish_thread_state
.reset ();
8897 /* Select innermost stack frame - i.e., current frame is frame 0,
8898 and current location is based on that. Handle the case where the
8899 dummy call is returning after being stopped. E.g. the dummy call
8900 previously hit a breakpoint. (If the dummy call returns
8901 normally, we won't reach here.) Do this before the stop hook is
8902 run, so that it doesn't get to see the temporary dummy frame,
8903 which is not where we'll present the stop. */
8904 if (has_stack_frames ())
8906 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
8908 /* Pop the empty frame that contains the stack dummy. This
8909 also restores inferior state prior to the call (struct
8910 infcall_suspend_state). */
8911 frame_info_ptr frame
= get_current_frame ();
8913 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
8915 /* frame_pop calls reinit_frame_cache as the last thing it
8916 does which means there's now no selected frame. */
8919 select_frame (get_current_frame ());
8921 /* Set the current source location. */
8922 set_current_sal_from_frame (get_current_frame ());
8925 /* Look up the hook_stop and run it (CLI internally handles problem
8926 of stop_command's pre-hook not existing). */
8927 stop_context saved_context
;
8931 execute_cmd_pre_hook (stop_command
);
8933 catch (const gdb_exception_error
&ex
)
8935 exception_fprintf (gdb_stderr
, ex
,
8936 "Error while running hook_stop:\n");
8939 /* If the stop hook resumes the target, then there's no point in
8940 trying to notify about the previous stop; its context is
8941 gone. Likewise if the command switches thread or inferior --
8942 the observers would print a stop for the wrong
8944 if (saved_context
.changed ())
8947 /* Notify observers about the stop. This is where the interpreters
8948 print the stop event. */
8949 if (inferior_ptid
!= null_ptid
)
8950 gdb::observers::normal_stop
.notify (inferior_thread ()->control
.stop_bpstat
,
8953 gdb::observers::normal_stop
.notify (nullptr, stop_print_frame
);
8955 annotate_stopped ();
8957 if (target_has_execution ())
8959 if (last
.kind () != TARGET_WAITKIND_SIGNALLED
8960 && last
.kind () != TARGET_WAITKIND_EXITED
8961 && last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
8962 /* Delete the breakpoint we stopped at, if it wants to be deleted.
8963 Delete any breakpoint that is to be deleted at the next stop. */
8964 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
8971 signal_stop_state (int signo
)
8973 return signal_stop
[signo
];
8977 signal_print_state (int signo
)
8979 return signal_print
[signo
];
8983 signal_pass_state (int signo
)
8985 return signal_program
[signo
];
8989 signal_cache_update (int signo
)
8993 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
8994 signal_cache_update (signo
);
8999 signal_pass
[signo
] = (signal_stop
[signo
] == 0
9000 && signal_print
[signo
] == 0
9001 && signal_program
[signo
] == 1
9002 && signal_catch
[signo
] == 0);
9006 signal_stop_update (int signo
, int state
)
9008 int ret
= signal_stop
[signo
];
9010 signal_stop
[signo
] = state
;
9011 signal_cache_update (signo
);
9016 signal_print_update (int signo
, int state
)
9018 int ret
= signal_print
[signo
];
9020 signal_print
[signo
] = state
;
9021 signal_cache_update (signo
);
9026 signal_pass_update (int signo
, int state
)
9028 int ret
= signal_program
[signo
];
9030 signal_program
[signo
] = state
;
9031 signal_cache_update (signo
);
9035 /* Update the global 'signal_catch' from INFO and notify the
9039 signal_catch_update (const unsigned int *info
)
9043 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
9044 signal_catch
[i
] = info
[i
] > 0;
9045 signal_cache_update (-1);
9046 target_pass_signals (signal_pass
);
9050 sig_print_header (void)
9052 gdb_printf (_("Signal Stop\tPrint\tPass "
9053 "to program\tDescription\n"));
9057 sig_print_info (enum gdb_signal oursig
)
9059 const char *name
= gdb_signal_to_name (oursig
);
9060 int name_padding
= 13 - strlen (name
);
9062 if (name_padding
<= 0)
9065 gdb_printf ("%s", name
);
9066 gdb_printf ("%*.*s ", name_padding
, name_padding
, " ");
9067 gdb_printf ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
9068 gdb_printf ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
9069 gdb_printf ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
9070 gdb_printf ("%s\n", gdb_signal_to_string (oursig
));
9073 /* Specify how various signals in the inferior should be handled. */
9076 handle_command (const char *args
, int from_tty
)
9078 int digits
, wordlen
;
9079 int sigfirst
, siglast
;
9080 enum gdb_signal oursig
;
9083 if (args
== nullptr)
9085 error_no_arg (_("signal to handle"));
9088 /* Allocate and zero an array of flags for which signals to handle. */
9090 const size_t nsigs
= GDB_SIGNAL_LAST
;
9091 unsigned char sigs
[nsigs
] {};
9093 /* Break the command line up into args. */
9095 gdb_argv
built_argv (args
);
9097 /* Walk through the args, looking for signal oursigs, signal names, and
9098 actions. Signal numbers and signal names may be interspersed with
9099 actions, with the actions being performed for all signals cumulatively
9100 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
9102 for (char *arg
: built_argv
)
9104 wordlen
= strlen (arg
);
9105 for (digits
= 0; isdigit (arg
[digits
]); digits
++)
9109 sigfirst
= siglast
= -1;
9111 if (wordlen
>= 1 && !strncmp (arg
, "all", wordlen
))
9113 /* Apply action to all signals except those used by the
9114 debugger. Silently skip those. */
9117 siglast
= nsigs
- 1;
9119 else if (wordlen
>= 1 && !strncmp (arg
, "stop", wordlen
))
9121 SET_SIGS (nsigs
, sigs
, signal_stop
);
9122 SET_SIGS (nsigs
, sigs
, signal_print
);
9124 else if (wordlen
>= 1 && !strncmp (arg
, "ignore", wordlen
))
9126 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9128 else if (wordlen
>= 2 && !strncmp (arg
, "print", wordlen
))
9130 SET_SIGS (nsigs
, sigs
, signal_print
);
9132 else if (wordlen
>= 2 && !strncmp (arg
, "pass", wordlen
))
9134 SET_SIGS (nsigs
, sigs
, signal_program
);
9136 else if (wordlen
>= 3 && !strncmp (arg
, "nostop", wordlen
))
9138 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9140 else if (wordlen
>= 3 && !strncmp (arg
, "noignore", wordlen
))
9142 SET_SIGS (nsigs
, sigs
, signal_program
);
9144 else if (wordlen
>= 4 && !strncmp (arg
, "noprint", wordlen
))
9146 UNSET_SIGS (nsigs
, sigs
, signal_print
);
9147 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9149 else if (wordlen
>= 4 && !strncmp (arg
, "nopass", wordlen
))
9151 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9153 else if (digits
> 0)
9155 /* It is numeric. The numeric signal refers to our own
9156 internal signal numbering from target.h, not to host/target
9157 signal number. This is a feature; users really should be
9158 using symbolic names anyway, and the common ones like
9159 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
9161 sigfirst
= siglast
= (int)
9162 gdb_signal_from_command (atoi (arg
));
9163 if (arg
[digits
] == '-')
9166 gdb_signal_from_command (atoi (arg
+ digits
+ 1));
9168 if (sigfirst
> siglast
)
9170 /* Bet he didn't figure we'd think of this case... */
9171 std::swap (sigfirst
, siglast
);
9176 oursig
= gdb_signal_from_name (arg
);
9177 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
9179 sigfirst
= siglast
= (int) oursig
;
9183 /* Not a number and not a recognized flag word => complain. */
9184 error (_("Unrecognized or ambiguous flag word: \"%s\"."), arg
);
9188 /* If any signal numbers or symbol names were found, set flags for
9189 which signals to apply actions to. */
9191 for (int signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
9193 switch ((enum gdb_signal
) signum
)
9195 case GDB_SIGNAL_TRAP
:
9196 case GDB_SIGNAL_INT
:
9197 if (!allsigs
&& !sigs
[signum
])
9199 if (query (_("%s is used by the debugger.\n\
9200 Are you sure you want to change it? "),
9201 gdb_signal_to_name ((enum gdb_signal
) signum
)))
9206 gdb_printf (_("Not confirmed, unchanged.\n"));
9210 case GDB_SIGNAL_DEFAULT
:
9211 case GDB_SIGNAL_UNKNOWN
:
9212 /* Make sure that "all" doesn't print these. */
9221 for (int signum
= 0; signum
< nsigs
; signum
++)
9224 signal_cache_update (-1);
9225 target_pass_signals (signal_pass
);
9226 target_program_signals (signal_program
);
9230 /* Show the results. */
9231 sig_print_header ();
9232 for (; signum
< nsigs
; signum
++)
9234 sig_print_info ((enum gdb_signal
) signum
);
9241 /* Complete the "handle" command. */
9244 handle_completer (struct cmd_list_element
*ignore
,
9245 completion_tracker
&tracker
,
9246 const char *text
, const char *word
)
9248 static const char * const keywords
[] =
9262 signal_completer (ignore
, tracker
, text
, word
);
9263 complete_on_enum (tracker
, keywords
, word
, word
);
9267 gdb_signal_from_command (int num
)
9269 if (num
>= 1 && num
<= 15)
9270 return (enum gdb_signal
) num
;
9271 error (_("Only signals 1-15 are valid as numeric signals.\n\
9272 Use \"info signals\" for a list of symbolic signals."));
9275 /* Print current contents of the tables set by the handle command.
9276 It is possible we should just be printing signals actually used
9277 by the current target (but for things to work right when switching
9278 targets, all signals should be in the signal tables). */
9281 info_signals_command (const char *signum_exp
, int from_tty
)
9283 enum gdb_signal oursig
;
9285 sig_print_header ();
9289 /* First see if this is a symbol name. */
9290 oursig
= gdb_signal_from_name (signum_exp
);
9291 if (oursig
== GDB_SIGNAL_UNKNOWN
)
9293 /* No, try numeric. */
9295 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
9297 sig_print_info (oursig
);
9302 /* These ugly casts brought to you by the native VAX compiler. */
9303 for (oursig
= GDB_SIGNAL_FIRST
;
9304 (int) oursig
< (int) GDB_SIGNAL_LAST
;
9305 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
9309 if (oursig
!= GDB_SIGNAL_UNKNOWN
9310 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
9311 sig_print_info (oursig
);
9314 gdb_printf (_("\nUse the \"handle\" command "
9315 "to change these tables.\n"));
9318 /* The $_siginfo convenience variable is a bit special. We don't know
9319 for sure the type of the value until we actually have a chance to
9320 fetch the data. The type can change depending on gdbarch, so it is
9321 also dependent on which thread you have selected.
9323 1. making $_siginfo be an internalvar that creates a new value on
9326 2. making the value of $_siginfo be an lval_computed value. */
9328 /* This function implements the lval_computed support for reading a
9332 siginfo_value_read (struct value
*v
)
9334 LONGEST transferred
;
9336 /* If we can access registers, so can we access $_siginfo. Likewise
9338 validate_registers_access ();
9341 target_read (current_inferior ()->top_target (),
9342 TARGET_OBJECT_SIGNAL_INFO
,
9344 v
->contents_all_raw ().data (),
9346 v
->type ()->length ());
9348 if (transferred
!= v
->type ()->length ())
9349 error (_("Unable to read siginfo"));
9352 /* This function implements the lval_computed support for writing a
9356 siginfo_value_write (struct value
*v
, struct value
*fromval
)
9358 LONGEST transferred
;
9360 /* If we can access registers, so can we access $_siginfo. Likewise
9362 validate_registers_access ();
9364 transferred
= target_write (current_inferior ()->top_target (),
9365 TARGET_OBJECT_SIGNAL_INFO
,
9367 fromval
->contents_all_raw ().data (),
9369 fromval
->type ()->length ());
9371 if (transferred
!= fromval
->type ()->length ())
9372 error (_("Unable to write siginfo"));
9375 static const struct lval_funcs siginfo_value_funcs
=
9381 /* Return a new value with the correct type for the siginfo object of
9382 the current thread using architecture GDBARCH. Return a void value
9383 if there's no object available. */
9385 static struct value
*
9386 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
9389 if (target_has_stack ()
9390 && inferior_ptid
!= null_ptid
9391 && gdbarch_get_siginfo_type_p (gdbarch
))
9393 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9395 return value::allocate_computed (type
, &siginfo_value_funcs
, nullptr);
9398 return value::allocate (builtin_type (gdbarch
)->builtin_void
);
9402 /* infcall_suspend_state contains state about the program itself like its
9403 registers and any signal it received when it last stopped.
9404 This state must be restored regardless of how the inferior function call
9405 ends (either successfully, or after it hits a breakpoint or signal)
9406 if the program is to properly continue where it left off. */
9408 class infcall_suspend_state
9411 /* Capture state from GDBARCH, TP, and REGCACHE that must be restored
9412 once the inferior function call has finished. */
9413 infcall_suspend_state (struct gdbarch
*gdbarch
,
9414 const struct thread_info
*tp
,
9415 struct regcache
*regcache
)
9416 : m_registers (new readonly_detached_regcache (*regcache
))
9418 tp
->save_suspend_to (m_thread_suspend
);
9420 gdb::unique_xmalloc_ptr
<gdb_byte
> siginfo_data
;
9422 if (gdbarch_get_siginfo_type_p (gdbarch
))
9424 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9425 size_t len
= type
->length ();
9427 siginfo_data
.reset ((gdb_byte
*) xmalloc (len
));
9429 if (target_read (current_inferior ()->top_target (),
9430 TARGET_OBJECT_SIGNAL_INFO
, nullptr,
9431 siginfo_data
.get (), 0, len
) != len
)
9433 /* Errors ignored. */
9434 siginfo_data
.reset (nullptr);
9440 m_siginfo_gdbarch
= gdbarch
;
9441 m_siginfo_data
= std::move (siginfo_data
);
9445 /* Return a pointer to the stored register state. */
9447 readonly_detached_regcache
*registers () const
9449 return m_registers
.get ();
9452 /* Restores the stored state into GDBARCH, TP, and REGCACHE. */
9454 void restore (struct gdbarch
*gdbarch
,
9455 struct thread_info
*tp
,
9456 struct regcache
*regcache
) const
9458 tp
->restore_suspend_from (m_thread_suspend
);
9460 if (m_siginfo_gdbarch
== gdbarch
)
9462 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9464 /* Errors ignored. */
9465 target_write (current_inferior ()->top_target (),
9466 TARGET_OBJECT_SIGNAL_INFO
, nullptr,
9467 m_siginfo_data
.get (), 0, type
->length ());
9470 /* The inferior can be gone if the user types "print exit(0)"
9471 (and perhaps other times). */
9472 if (target_has_execution ())
9473 /* NB: The register write goes through to the target. */
9474 regcache
->restore (registers ());
9478 /* How the current thread stopped before the inferior function call was
9480 struct thread_suspend_state m_thread_suspend
;
9482 /* The registers before the inferior function call was executed. */
9483 std::unique_ptr
<readonly_detached_regcache
> m_registers
;
9485 /* Format of SIGINFO_DATA or NULL if it is not present. */
9486 struct gdbarch
*m_siginfo_gdbarch
= nullptr;
9488 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
9489 gdbarch_get_siginfo_type ()->length (). For different gdbarch the
9490 content would be invalid. */
9491 gdb::unique_xmalloc_ptr
<gdb_byte
> m_siginfo_data
;
9494 infcall_suspend_state_up
9495 save_infcall_suspend_state ()
9497 struct thread_info
*tp
= inferior_thread ();
9498 struct regcache
*regcache
= get_current_regcache ();
9499 struct gdbarch
*gdbarch
= regcache
->arch ();
9501 infcall_suspend_state_up inf_state
9502 (new struct infcall_suspend_state (gdbarch
, tp
, regcache
));
9504 /* Having saved the current state, adjust the thread state, discarding
9505 any stop signal information. The stop signal is not useful when
9506 starting an inferior function call, and run_inferior_call will not use
9507 the signal due to its `proceed' call with GDB_SIGNAL_0. */
9508 tp
->set_stop_signal (GDB_SIGNAL_0
);
9513 /* Restore inferior session state to INF_STATE. */
9516 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9518 struct thread_info
*tp
= inferior_thread ();
9519 struct regcache
*regcache
= get_current_regcache ();
9520 struct gdbarch
*gdbarch
= regcache
->arch ();
9522 inf_state
->restore (gdbarch
, tp
, regcache
);
9523 discard_infcall_suspend_state (inf_state
);
9527 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9532 readonly_detached_regcache
*
9533 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
9535 return inf_state
->registers ();
9538 /* infcall_control_state contains state regarding gdb's control of the
9539 inferior itself like stepping control. It also contains session state like
9540 the user's currently selected frame. */
9542 struct infcall_control_state
9544 struct thread_control_state thread_control
;
9545 struct inferior_control_state inferior_control
;
9548 enum stop_stack_kind stop_stack_dummy
= STOP_NONE
;
9549 int stopped_by_random_signal
= 0;
9551 /* ID and level of the selected frame when the inferior function
9553 struct frame_id selected_frame_id
{};
9554 int selected_frame_level
= -1;
9557 /* Save all of the information associated with the inferior<==>gdb
9560 infcall_control_state_up
9561 save_infcall_control_state ()
9563 infcall_control_state_up
inf_status (new struct infcall_control_state
);
9564 struct thread_info
*tp
= inferior_thread ();
9565 struct inferior
*inf
= current_inferior ();
9567 inf_status
->thread_control
= tp
->control
;
9568 inf_status
->inferior_control
= inf
->control
;
9570 tp
->control
.step_resume_breakpoint
= nullptr;
9571 tp
->control
.exception_resume_breakpoint
= nullptr;
9573 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
9574 chain. If caller's caller is walking the chain, they'll be happier if we
9575 hand them back the original chain when restore_infcall_control_state is
9577 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
9580 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
9581 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
9583 save_selected_frame (&inf_status
->selected_frame_id
,
9584 &inf_status
->selected_frame_level
);
9589 /* Restore inferior session state to INF_STATUS. */
9592 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
9594 struct thread_info
*tp
= inferior_thread ();
9595 struct inferior
*inf
= current_inferior ();
9597 if (tp
->control
.step_resume_breakpoint
)
9598 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
9600 if (tp
->control
.exception_resume_breakpoint
)
9601 tp
->control
.exception_resume_breakpoint
->disposition
9602 = disp_del_at_next_stop
;
9604 /* Handle the bpstat_copy of the chain. */
9605 bpstat_clear (&tp
->control
.stop_bpstat
);
9607 tp
->control
= inf_status
->thread_control
;
9608 inf
->control
= inf_status
->inferior_control
;
9611 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
9612 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
9614 if (target_has_stack ())
9616 restore_selected_frame (inf_status
->selected_frame_id
,
9617 inf_status
->selected_frame_level
);
9624 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
9626 if (inf_status
->thread_control
.step_resume_breakpoint
)
9627 inf_status
->thread_control
.step_resume_breakpoint
->disposition
9628 = disp_del_at_next_stop
;
9630 if (inf_status
->thread_control
.exception_resume_breakpoint
)
9631 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
9632 = disp_del_at_next_stop
;
9634 /* See save_infcall_control_state for info on stop_bpstat. */
9635 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
9643 clear_exit_convenience_vars (void)
9645 clear_internalvar (lookup_internalvar ("_exitsignal"));
9646 clear_internalvar (lookup_internalvar ("_exitcode"));
9650 /* User interface for reverse debugging:
9651 Set exec-direction / show exec-direction commands
9652 (returns error unless target implements to_set_exec_direction method). */
9654 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
9655 static const char exec_forward
[] = "forward";
9656 static const char exec_reverse
[] = "reverse";
9657 static const char *exec_direction
= exec_forward
;
9658 static const char *const exec_direction_names
[] = {
9665 set_exec_direction_func (const char *args
, int from_tty
,
9666 struct cmd_list_element
*cmd
)
9668 if (target_can_execute_reverse ())
9670 if (!strcmp (exec_direction
, exec_forward
))
9671 execution_direction
= EXEC_FORWARD
;
9672 else if (!strcmp (exec_direction
, exec_reverse
))
9673 execution_direction
= EXEC_REVERSE
;
9677 exec_direction
= exec_forward
;
9678 error (_("Target does not support this operation."));
9683 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
9684 struct cmd_list_element
*cmd
, const char *value
)
9686 switch (execution_direction
) {
9688 gdb_printf (out
, _("Forward.\n"));
9691 gdb_printf (out
, _("Reverse.\n"));
9694 internal_error (_("bogus execution_direction value: %d"),
9695 (int) execution_direction
);
9700 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
9701 struct cmd_list_element
*c
, const char *value
)
9703 gdb_printf (file
, _("Resuming the execution of threads "
9704 "of all processes is %s.\n"), value
);
9707 /* Implementation of `siginfo' variable. */
9709 static const struct internalvar_funcs siginfo_funcs
=
9715 /* Callback for infrun's target events source. This is marked when a
9716 thread has a pending status to process. */
9719 infrun_async_inferior_event_handler (gdb_client_data data
)
9721 clear_async_event_handler (infrun_async_inferior_event_token
);
9722 inferior_event_handler (INF_REG_EVENT
);
9729 /* Verify that when two threads with the same ptid exist (from two different
9730 targets) and one of them changes ptid, we only update inferior_ptid if
9731 it is appropriate. */
9734 infrun_thread_ptid_changed ()
9736 gdbarch
*arch
= current_inferior ()->gdbarch
;
9738 /* The thread which inferior_ptid represents changes ptid. */
9740 scoped_restore_current_pspace_and_thread restore
;
9742 scoped_mock_context
<test_target_ops
> target1 (arch
);
9743 scoped_mock_context
<test_target_ops
> target2 (arch
);
9745 ptid_t
old_ptid (111, 222);
9746 ptid_t
new_ptid (111, 333);
9748 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9749 target1
.mock_thread
.ptid
= old_ptid
;
9750 target1
.mock_inferior
.ptid_thread_map
.clear ();
9751 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
9753 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9754 target2
.mock_thread
.ptid
= old_ptid
;
9755 target2
.mock_inferior
.ptid_thread_map
.clear ();
9756 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
9758 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9759 set_current_inferior (&target1
.mock_inferior
);
9761 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9763 gdb_assert (inferior_ptid
== new_ptid
);
9766 /* A thread with the same ptid as inferior_ptid, but from another target,
9769 scoped_restore_current_pspace_and_thread restore
;
9771 scoped_mock_context
<test_target_ops
> target1 (arch
);
9772 scoped_mock_context
<test_target_ops
> target2 (arch
);
9774 ptid_t
old_ptid (111, 222);
9775 ptid_t
new_ptid (111, 333);
9777 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9778 target1
.mock_thread
.ptid
= old_ptid
;
9779 target1
.mock_inferior
.ptid_thread_map
.clear ();
9780 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
9782 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9783 target2
.mock_thread
.ptid
= old_ptid
;
9784 target2
.mock_inferior
.ptid_thread_map
.clear ();
9785 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
9787 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9788 set_current_inferior (&target2
.mock_inferior
);
9790 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9792 gdb_assert (inferior_ptid
== old_ptid
);
9796 } /* namespace selftests */
9798 #endif /* GDB_SELF_TEST */
9800 void _initialize_infrun ();
9802 _initialize_infrun ()
9804 struct cmd_list_element
*c
;
9806 /* Register extra event sources in the event loop. */
9807 infrun_async_inferior_event_token
9808 = create_async_event_handler (infrun_async_inferior_event_handler
, nullptr,
9811 cmd_list_element
*info_signals_cmd
9812 = add_info ("signals", info_signals_command
, _("\
9813 What debugger does when program gets various signals.\n\
9814 Specify a signal as argument to print info on that signal only."));
9815 add_info_alias ("handle", info_signals_cmd
, 0);
9817 c
= add_com ("handle", class_run
, handle_command
, _("\
9818 Specify how to handle signals.\n\
9819 Usage: handle SIGNAL [ACTIONS]\n\
9820 Args are signals and actions to apply to those signals.\n\
9821 If no actions are specified, the current settings for the specified signals\n\
9822 will be displayed instead.\n\
9824 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
9825 from 1-15 are allowed for compatibility with old versions of GDB.\n\
9826 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
9827 The special arg \"all\" is recognized to mean all signals except those\n\
9828 used by the debugger, typically SIGTRAP and SIGINT.\n\
9830 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
9831 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
9832 Stop means reenter debugger if this signal happens (implies print).\n\
9833 Print means print a message if this signal happens.\n\
9834 Pass means let program see this signal; otherwise program doesn't know.\n\
9835 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
9836 Pass and Stop may be combined.\n\
9838 Multiple signals may be specified. Signal numbers and signal names\n\
9839 may be interspersed with actions, with the actions being performed for\n\
9840 all signals cumulatively specified."));
9841 set_cmd_completer (c
, handle_completer
);
9843 stop_command
= add_cmd ("stop", class_obscure
,
9844 not_just_help_class_command
, _("\
9845 There is no `stop' command, but you can set a hook on `stop'.\n\
9846 This allows you to set a list of commands to be run each time execution\n\
9847 of the program stops."), &cmdlist
);
9849 add_setshow_boolean_cmd
9850 ("infrun", class_maintenance
, &debug_infrun
,
9851 _("Set inferior debugging."),
9852 _("Show inferior debugging."),
9853 _("When non-zero, inferior specific debugging is enabled."),
9854 nullptr, show_debug_infrun
, &setdebuglist
, &showdebuglist
);
9856 add_setshow_boolean_cmd ("non-stop", no_class
,
9858 Set whether gdb controls the inferior in non-stop mode."), _("\
9859 Show whether gdb controls the inferior in non-stop mode."), _("\
9860 When debugging a multi-threaded program and this setting is\n\
9861 off (the default, also called all-stop mode), when one thread stops\n\
9862 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
9863 all other threads in the program while you interact with the thread of\n\
9864 interest. When you continue or step a thread, you can allow the other\n\
9865 threads to run, or have them remain stopped, but while you inspect any\n\
9866 thread's state, all threads stop.\n\
9868 In non-stop mode, when one thread stops, other threads can continue\n\
9869 to run freely. You'll be able to step each thread independently,\n\
9870 leave it stopped or free to run as needed."),
9876 for (size_t i
= 0; i
< GDB_SIGNAL_LAST
; i
++)
9879 signal_print
[i
] = 1;
9880 signal_program
[i
] = 1;
9881 signal_catch
[i
] = 0;
9884 /* Signals caused by debugger's own actions should not be given to
9885 the program afterwards.
9887 Do not deliver GDB_SIGNAL_TRAP by default, except when the user
9888 explicitly specifies that it should be delivered to the target
9889 program. Typically, that would occur when a user is debugging a
9890 target monitor on a simulator: the target monitor sets a
9891 breakpoint; the simulator encounters this breakpoint and halts
9892 the simulation handing control to GDB; GDB, noting that the stop
9893 address doesn't map to any known breakpoint, returns control back
9894 to the simulator; the simulator then delivers the hardware
9895 equivalent of a GDB_SIGNAL_TRAP to the program being
9897 signal_program
[GDB_SIGNAL_TRAP
] = 0;
9898 signal_program
[GDB_SIGNAL_INT
] = 0;
9900 /* Signals that are not errors should not normally enter the debugger. */
9901 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
9902 signal_print
[GDB_SIGNAL_ALRM
] = 0;
9903 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
9904 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
9905 signal_stop
[GDB_SIGNAL_PROF
] = 0;
9906 signal_print
[GDB_SIGNAL_PROF
] = 0;
9907 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
9908 signal_print
[GDB_SIGNAL_CHLD
] = 0;
9909 signal_stop
[GDB_SIGNAL_IO
] = 0;
9910 signal_print
[GDB_SIGNAL_IO
] = 0;
9911 signal_stop
[GDB_SIGNAL_POLL
] = 0;
9912 signal_print
[GDB_SIGNAL_POLL
] = 0;
9913 signal_stop
[GDB_SIGNAL_URG
] = 0;
9914 signal_print
[GDB_SIGNAL_URG
] = 0;
9915 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
9916 signal_print
[GDB_SIGNAL_WINCH
] = 0;
9917 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
9918 signal_print
[GDB_SIGNAL_PRIO
] = 0;
9920 /* These signals are used internally by user-level thread
9921 implementations. (See signal(5) on Solaris.) Like the above
9922 signals, a healthy program receives and handles them as part of
9923 its normal operation. */
9924 signal_stop
[GDB_SIGNAL_LWP
] = 0;
9925 signal_print
[GDB_SIGNAL_LWP
] = 0;
9926 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
9927 signal_print
[GDB_SIGNAL_WAITING
] = 0;
9928 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
9929 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
9930 signal_stop
[GDB_SIGNAL_LIBRT
] = 0;
9931 signal_print
[GDB_SIGNAL_LIBRT
] = 0;
9933 /* Update cached state. */
9934 signal_cache_update (-1);
9936 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
9937 &stop_on_solib_events
, _("\
9938 Set stopping for shared library events."), _("\
9939 Show stopping for shared library events."), _("\
9940 If nonzero, gdb will give control to the user when the dynamic linker\n\
9941 notifies gdb of shared library events. The most common event of interest\n\
9942 to the user would be loading/unloading of a new library."),
9943 set_stop_on_solib_events
,
9944 show_stop_on_solib_events
,
9945 &setlist
, &showlist
);
9947 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
9948 follow_fork_mode_kind_names
,
9949 &follow_fork_mode_string
, _("\
9950 Set debugger response to a program call of fork or vfork."), _("\
9951 Show debugger response to a program call of fork or vfork."), _("\
9952 A fork or vfork creates a new process. follow-fork-mode can be:\n\
9953 parent - the original process is debugged after a fork\n\
9954 child - the new process is debugged after a fork\n\
9955 The unfollowed process will continue to run.\n\
9956 By default, the debugger will follow the parent process."),
9958 show_follow_fork_mode_string
,
9959 &setlist
, &showlist
);
9961 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
9962 follow_exec_mode_names
,
9963 &follow_exec_mode_string
, _("\
9964 Set debugger response to a program call of exec."), _("\
9965 Show debugger response to a program call of exec."), _("\
9966 An exec call replaces the program image of a process.\n\
9968 follow-exec-mode can be:\n\
9970 new - the debugger creates a new inferior and rebinds the process\n\
9971 to this new inferior. The program the process was running before\n\
9972 the exec call can be restarted afterwards by restarting the original\n\
9975 same - the debugger keeps the process bound to the same inferior.\n\
9976 The new executable image replaces the previous executable loaded in\n\
9977 the inferior. Restarting the inferior after the exec call restarts\n\
9978 the executable the process was running after the exec call.\n\
9980 By default, the debugger will use the same inferior."),
9982 show_follow_exec_mode_string
,
9983 &setlist
, &showlist
);
9985 add_setshow_enum_cmd ("scheduler-locking", class_run
,
9986 scheduler_enums
, &scheduler_mode
, _("\
9987 Set mode for locking scheduler during execution."), _("\
9988 Show mode for locking scheduler during execution."), _("\
9989 off == no locking (threads may preempt at any time)\n\
9990 on == full locking (no thread except the current thread may run)\n\
9991 This applies to both normal execution and replay mode.\n\
9992 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
9993 In this mode, other threads may run during other commands.\n\
9994 This applies to both normal execution and replay mode.\n\
9995 replay == scheduler locked in replay mode and unlocked during normal execution."),
9996 set_schedlock_func
, /* traps on target vector */
9997 show_scheduler_mode
,
9998 &setlist
, &showlist
);
10000 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
10001 Set mode for resuming threads of all processes."), _("\
10002 Show mode for resuming threads of all processes."), _("\
10003 When on, execution commands (such as 'continue' or 'next') resume all\n\
10004 threads of all processes. When off (which is the default), execution\n\
10005 commands only resume the threads of the current process. The set of\n\
10006 threads that are resumed is further refined by the scheduler-locking\n\
10007 mode (see help set scheduler-locking)."),
10009 show_schedule_multiple
,
10010 &setlist
, &showlist
);
10012 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
10013 Set mode of the step operation."), _("\
10014 Show mode of the step operation."), _("\
10015 When set, doing a step over a function without debug line information\n\
10016 will stop at the first instruction of that function. Otherwise, the\n\
10017 function is skipped and the step command stops at a different source line."),
10019 show_step_stop_if_no_debug
,
10020 &setlist
, &showlist
);
10022 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
10023 &can_use_displaced_stepping
, _("\
10024 Set debugger's willingness to use displaced stepping."), _("\
10025 Show debugger's willingness to use displaced stepping."), _("\
10026 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
10027 supported by the target architecture. If off, gdb will not use displaced\n\
10028 stepping to step over breakpoints, even if such is supported by the target\n\
10029 architecture. If auto (which is the default), gdb will use displaced stepping\n\
10030 if the target architecture supports it and non-stop mode is active, but will not\n\
10031 use it in all-stop mode (see help set non-stop)."),
10033 show_can_use_displaced_stepping
,
10034 &setlist
, &showlist
);
10036 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
10037 &exec_direction
, _("Set direction of execution.\n\
10038 Options are 'forward' or 'reverse'."),
10039 _("Show direction of execution (forward/reverse)."),
10040 _("Tells gdb whether to execute forward or backward."),
10041 set_exec_direction_func
, show_exec_direction_func
,
10042 &setlist
, &showlist
);
10044 /* Set/show detach-on-fork: user-settable mode. */
10046 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
10047 Set whether gdb will detach the child of a fork."), _("\
10048 Show whether gdb will detach the child of a fork."), _("\
10049 Tells gdb whether to detach the child of a fork."),
10050 nullptr, nullptr, &setlist
, &showlist
);
10052 /* Set/show disable address space randomization mode. */
10054 add_setshow_boolean_cmd ("disable-randomization", class_support
,
10055 &disable_randomization
, _("\
10056 Set disabling of debuggee's virtual address space randomization."), _("\
10057 Show disabling of debuggee's virtual address space randomization."), _("\
10058 When this mode is on (which is the default), randomization of the virtual\n\
10059 address space is disabled. Standalone programs run with the randomization\n\
10060 enabled by default on some platforms."),
10061 &set_disable_randomization
,
10062 &show_disable_randomization
,
10063 &setlist
, &showlist
);
10065 /* ptid initializations */
10066 inferior_ptid
= null_ptid
;
10067 target_last_wait_ptid
= minus_one_ptid
;
10069 gdb::observers::thread_ptid_changed
.attach (infrun_thread_ptid_changed
,
10071 gdb::observers::thread_stop_requested
.attach (infrun_thread_stop_requested
,
10073 gdb::observers::inferior_exit
.attach (infrun_inferior_exit
, "infrun");
10074 gdb::observers::inferior_execd
.attach (infrun_inferior_execd
, "infrun");
10076 /* Explicitly create without lookup, since that tries to create a
10077 value with a void typed value, and when we get here, gdbarch
10078 isn't initialized yet. At this point, we're quite sure there
10079 isn't another convenience variable of the same name. */
10080 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, nullptr);
10082 add_setshow_boolean_cmd ("observer", no_class
,
10083 &observer_mode_1
, _("\
10084 Set whether gdb controls the inferior in observer mode."), _("\
10085 Show whether gdb controls the inferior in observer mode."), _("\
10086 In observer mode, GDB can get data from the inferior, but not\n\
10087 affect its execution. Registers and memory may not be changed,\n\
10088 breakpoints may not be set, and the program cannot be interrupted\n\
10091 show_observer_mode
,
10096 selftests::register_test ("infrun_thread_ptid_changed",
10097 selftests::infrun_thread_ptid_changed
);