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"
40 #include "observable.h"
45 #include "mi/mi-common.h"
46 #include "event-top.h"
48 #include "record-full.h"
49 #include "inline-frame.h"
51 #include "tracepoint.h"
55 #include "completer.h"
56 #include "target-descriptions.h"
57 #include "target-dcache.h"
60 #include "gdbsupport/event-loop.h"
61 #include "thread-fsm.h"
62 #include "gdbsupport/enum-flags.h"
63 #include "progspace-and-thread.h"
64 #include "gdbsupport/gdb_optional.h"
65 #include "arch-utils.h"
66 #include "gdbsupport/scope-exit.h"
67 #include "gdbsupport/forward-scope-exit.h"
68 #include "gdbsupport/gdb_select.h"
69 #include <unordered_map>
70 #include "async-event.h"
71 #include "gdbsupport/selftest.h"
72 #include "scoped-mock-context.h"
73 #include "test-target.h"
74 #include "gdbsupport/common-debug.h"
75 #include "gdbsupport/buildargv.h"
76 #include "extension.h"
79 /* Prototypes for local functions */
81 static void sig_print_info (enum gdb_signal
);
83 static void sig_print_header (void);
85 static void follow_inferior_reset_breakpoints (void);
87 static bool currently_stepping (struct thread_info
*tp
);
89 static void insert_hp_step_resume_breakpoint_at_frame (frame_info_ptr
);
91 static void insert_step_resume_breakpoint_at_caller (frame_info_ptr
);
93 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
95 static bool maybe_software_singlestep (struct gdbarch
*gdbarch
);
97 static void resume (gdb_signal sig
);
99 static void wait_for_inferior (inferior
*inf
);
101 static void restart_threads (struct thread_info
*event_thread
,
102 inferior
*inf
= nullptr);
104 static bool start_step_over (void);
106 static bool step_over_info_valid_p (void);
108 /* Asynchronous signal handler registered as event loop source for
109 when we have pending events ready to be passed to the core. */
110 static struct async_event_handler
*infrun_async_inferior_event_token
;
112 /* Stores whether infrun_async was previously enabled or disabled.
113 Starts off as -1, indicating "never enabled/disabled". */
114 static int infrun_is_async
= -1;
119 infrun_async (int enable
)
121 if (infrun_is_async
!= enable
)
123 infrun_is_async
= enable
;
125 infrun_debug_printf ("enable=%d", enable
);
128 mark_async_event_handler (infrun_async_inferior_event_token
);
130 clear_async_event_handler (infrun_async_inferior_event_token
);
137 mark_infrun_async_event_handler (void)
139 mark_async_event_handler (infrun_async_inferior_event_token
);
142 /* When set, stop the 'step' command if we enter a function which has
143 no line number information. The normal behavior is that we step
144 over such function. */
145 bool step_stop_if_no_debug
= false;
147 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
148 struct cmd_list_element
*c
, const char *value
)
150 gdb_printf (file
, _("Mode of the step operation is %s.\n"), value
);
153 /* proceed and normal_stop use this to notify the user when the
154 inferior stopped in a different thread than it had been running in.
155 It can also be used to find for which thread normal_stop last
157 static thread_info_ref previous_thread
;
162 update_previous_thread ()
164 if (inferior_ptid
== null_ptid
)
165 previous_thread
= nullptr;
167 previous_thread
= thread_info_ref::new_reference (inferior_thread ());
173 get_previous_thread ()
175 return previous_thread
.get ();
178 /* If set (default for legacy reasons), when following a fork, GDB
179 will detach from one of the fork branches, child or parent.
180 Exactly which branch is detached depends on 'set follow-fork-mode'
183 static bool detach_fork
= true;
185 bool debug_infrun
= false;
187 show_debug_infrun (struct ui_file
*file
, int from_tty
,
188 struct cmd_list_element
*c
, const char *value
)
190 gdb_printf (file
, _("Inferior debugging is %s.\n"), value
);
193 /* Support for disabling address space randomization. */
195 bool disable_randomization
= true;
198 show_disable_randomization (struct ui_file
*file
, int from_tty
,
199 struct cmd_list_element
*c
, const char *value
)
201 if (target_supports_disable_randomization ())
203 _("Disabling randomization of debuggee's "
204 "virtual address space is %s.\n"),
207 gdb_puts (_("Disabling randomization of debuggee's "
208 "virtual address space is unsupported on\n"
209 "this platform.\n"), file
);
213 set_disable_randomization (const char *args
, int from_tty
,
214 struct cmd_list_element
*c
)
216 if (!target_supports_disable_randomization ())
217 error (_("Disabling randomization of debuggee's "
218 "virtual address space is unsupported on\n"
222 /* User interface for non-stop mode. */
224 bool non_stop
= false;
225 static bool non_stop_1
= false;
228 set_non_stop (const char *args
, int from_tty
,
229 struct cmd_list_element
*c
)
231 if (target_has_execution ())
233 non_stop_1
= non_stop
;
234 error (_("Cannot change this setting while the inferior is running."));
237 non_stop
= non_stop_1
;
241 show_non_stop (struct ui_file
*file
, int from_tty
,
242 struct cmd_list_element
*c
, const char *value
)
245 _("Controlling the inferior in non-stop mode is %s.\n"),
249 /* "Observer mode" is somewhat like a more extreme version of
250 non-stop, in which all GDB operations that might affect the
251 target's execution have been disabled. */
253 static bool observer_mode
= false;
254 static bool observer_mode_1
= false;
257 set_observer_mode (const char *args
, int from_tty
,
258 struct cmd_list_element
*c
)
260 if (target_has_execution ())
262 observer_mode_1
= observer_mode
;
263 error (_("Cannot change this setting while the inferior is running."));
266 observer_mode
= observer_mode_1
;
268 may_write_registers
= !observer_mode
;
269 may_write_memory
= !observer_mode
;
270 may_insert_breakpoints
= !observer_mode
;
271 may_insert_tracepoints
= !observer_mode
;
272 /* We can insert fast tracepoints in or out of observer mode,
273 but enable them if we're going into this mode. */
275 may_insert_fast_tracepoints
= true;
276 may_stop
= !observer_mode
;
277 update_target_permissions ();
279 /* Going *into* observer mode we must force non-stop, then
280 going out we leave it that way. */
283 pagination_enabled
= false;
284 non_stop
= non_stop_1
= true;
288 gdb_printf (_("Observer mode is now %s.\n"),
289 (observer_mode
? "on" : "off"));
293 show_observer_mode (struct ui_file
*file
, int from_tty
,
294 struct cmd_list_element
*c
, const char *value
)
296 gdb_printf (file
, _("Observer mode is %s.\n"), value
);
299 /* This updates the value of observer mode based on changes in
300 permissions. Note that we are deliberately ignoring the values of
301 may-write-registers and may-write-memory, since the user may have
302 reason to enable these during a session, for instance to turn on a
303 debugging-related global. */
306 update_observer_mode (void)
308 bool newval
= (!may_insert_breakpoints
309 && !may_insert_tracepoints
310 && may_insert_fast_tracepoints
314 /* Let the user know if things change. */
315 if (newval
!= observer_mode
)
316 gdb_printf (_("Observer mode is now %s.\n"),
317 (newval
? "on" : "off"));
319 observer_mode
= observer_mode_1
= newval
;
322 /* Tables of how to react to signals; the user sets them. */
324 static unsigned char signal_stop
[GDB_SIGNAL_LAST
];
325 static unsigned char signal_print
[GDB_SIGNAL_LAST
];
326 static unsigned char signal_program
[GDB_SIGNAL_LAST
];
328 /* Table of signals that are registered with "catch signal". A
329 non-zero entry indicates that the signal is caught by some "catch
331 static unsigned char signal_catch
[GDB_SIGNAL_LAST
];
333 /* Table of signals that the target may silently handle.
334 This is automatically determined from the flags above,
335 and simply cached here. */
336 static unsigned char signal_pass
[GDB_SIGNAL_LAST
];
338 #define SET_SIGS(nsigs,sigs,flags) \
340 int signum = (nsigs); \
341 while (signum-- > 0) \
342 if ((sigs)[signum]) \
343 (flags)[signum] = 1; \
346 #define UNSET_SIGS(nsigs,sigs,flags) \
348 int signum = (nsigs); \
349 while (signum-- > 0) \
350 if ((sigs)[signum]) \
351 (flags)[signum] = 0; \
354 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
355 this function is to avoid exporting `signal_program'. */
358 update_signals_program_target (void)
360 target_program_signals (signal_program
);
363 /* Value to pass to target_resume() to cause all threads to resume. */
365 #define RESUME_ALL minus_one_ptid
367 /* Command list pointer for the "stop" placeholder. */
369 static struct cmd_list_element
*stop_command
;
371 /* Nonzero if we want to give control to the user when we're notified
372 of shared library events by the dynamic linker. */
373 int stop_on_solib_events
;
375 /* Enable or disable optional shared library event breakpoints
376 as appropriate when the above flag is changed. */
379 set_stop_on_solib_events (const char *args
,
380 int from_tty
, struct cmd_list_element
*c
)
382 update_solib_breakpoints ();
386 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
387 struct cmd_list_element
*c
, const char *value
)
389 gdb_printf (file
, _("Stopping for shared library events is %s.\n"),
393 /* True after stop if current stack frame should be printed. */
395 static bool stop_print_frame
;
397 /* This is a cached copy of the target/ptid/waitstatus of the last
398 event returned by target_wait().
399 This information is returned by get_last_target_status(). */
400 static process_stratum_target
*target_last_proc_target
;
401 static ptid_t target_last_wait_ptid
;
402 static struct target_waitstatus target_last_waitstatus
;
404 void init_thread_stepping_state (struct thread_info
*tss
);
406 static const char follow_fork_mode_child
[] = "child";
407 static const char follow_fork_mode_parent
[] = "parent";
409 static const char *const follow_fork_mode_kind_names
[] = {
410 follow_fork_mode_child
,
411 follow_fork_mode_parent
,
415 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
417 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
418 struct cmd_list_element
*c
, const char *value
)
421 _("Debugger response to a program "
422 "call of fork or vfork is \"%s\".\n"),
427 /* Handle changes to the inferior list based on the type of fork,
428 which process is being followed, and whether the other process
429 should be detached. On entry inferior_ptid must be the ptid of
430 the fork parent. At return inferior_ptid is the ptid of the
431 followed inferior. */
434 follow_fork_inferior (bool follow_child
, bool detach_fork
)
436 target_waitkind fork_kind
= inferior_thread ()->pending_follow
.kind ();
437 gdb_assert (fork_kind
== TARGET_WAITKIND_FORKED
438 || fork_kind
== TARGET_WAITKIND_VFORKED
);
439 bool has_vforked
= fork_kind
== TARGET_WAITKIND_VFORKED
;
440 ptid_t parent_ptid
= inferior_ptid
;
441 ptid_t child_ptid
= inferior_thread ()->pending_follow
.child_ptid ();
444 && !non_stop
/* Non-stop always resumes both branches. */
445 && current_ui
->prompt_state
== PROMPT_BLOCKED
446 && !(follow_child
|| detach_fork
|| sched_multi
))
448 /* The parent stays blocked inside the vfork syscall until the
449 child execs or exits. If we don't let the child run, then
450 the parent stays blocked. If we're telling the parent to run
451 in the foreground, the user will not be able to ctrl-c to get
452 back the terminal, effectively hanging the debug session. */
453 gdb_printf (gdb_stderr
, _("\
454 Can not resume the parent process over vfork in the foreground while\n\
455 holding the child stopped. Try \"set detach-on-fork\" or \
456 \"set schedule-multiple\".\n"));
460 inferior
*parent_inf
= current_inferior ();
461 inferior
*child_inf
= nullptr;
463 gdb_assert (parent_inf
->thread_waiting_for_vfork_done
== nullptr);
467 /* Detach new forked process? */
470 /* Before detaching from the child, remove all breakpoints
471 from it. If we forked, then this has already been taken
472 care of by infrun.c. If we vforked however, any
473 breakpoint inserted in the parent is visible in the
474 child, even those added while stopped in a vfork
475 catchpoint. This will remove the breakpoints from the
476 parent also, but they'll be reinserted below. */
479 /* Keep breakpoints list in sync. */
480 remove_breakpoints_inf (current_inferior ());
483 if (print_inferior_events
)
485 /* Ensure that we have a process ptid. */
486 ptid_t process_ptid
= ptid_t (child_ptid
.pid ());
488 target_terminal::ours_for_output ();
489 gdb_printf (_("[Detaching after %s from child %s]\n"),
490 has_vforked
? "vfork" : "fork",
491 target_pid_to_str (process_ptid
).c_str ());
496 /* Add process to GDB's tables. */
497 child_inf
= add_inferior (child_ptid
.pid ());
499 child_inf
->attach_flag
= parent_inf
->attach_flag
;
500 copy_terminal_info (child_inf
, parent_inf
);
501 child_inf
->gdbarch
= parent_inf
->gdbarch
;
502 child_inf
->tdesc_info
= parent_inf
->tdesc_info
;
504 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
506 /* If this is a vfork child, then the address-space is
507 shared with the parent. */
510 child_inf
->pspace
= parent_inf
->pspace
;
511 child_inf
->aspace
= parent_inf
->aspace
;
513 exec_on_vfork (child_inf
);
515 /* The parent will be frozen until the child is done
516 with the shared region. Keep track of the
518 child_inf
->vfork_parent
= parent_inf
;
519 child_inf
->pending_detach
= false;
520 parent_inf
->vfork_child
= child_inf
;
521 parent_inf
->pending_detach
= false;
525 child_inf
->aspace
= new address_space ();
526 child_inf
->pspace
= new program_space (child_inf
->aspace
);
527 child_inf
->removable
= true;
528 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
534 /* If we detached from the child, then we have to be careful
535 to not insert breakpoints in the parent until the child
536 is done with the shared memory region. However, if we're
537 staying attached to the child, then we can and should
538 insert breakpoints, so that we can debug it. A
539 subsequent child exec or exit is enough to know when does
540 the child stops using the parent's address space. */
541 parent_inf
->thread_waiting_for_vfork_done
542 = detach_fork
? inferior_thread () : nullptr;
543 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
548 /* Follow the child. */
550 if (print_inferior_events
)
552 std::string parent_pid
= target_pid_to_str (parent_ptid
);
553 std::string child_pid
= target_pid_to_str (child_ptid
);
555 target_terminal::ours_for_output ();
556 gdb_printf (_("[Attaching after %s %s to child %s]\n"),
558 has_vforked
? "vfork" : "fork",
562 /* Add the new inferior first, so that the target_detach below
563 doesn't unpush the target. */
565 child_inf
= add_inferior (child_ptid
.pid ());
567 child_inf
->attach_flag
= parent_inf
->attach_flag
;
568 copy_terminal_info (child_inf
, parent_inf
);
569 child_inf
->gdbarch
= parent_inf
->gdbarch
;
570 child_inf
->tdesc_info
= parent_inf
->tdesc_info
;
574 /* If this is a vfork child, then the address-space is shared
576 child_inf
->aspace
= parent_inf
->aspace
;
577 child_inf
->pspace
= parent_inf
->pspace
;
579 exec_on_vfork (child_inf
);
581 else if (detach_fork
)
583 /* We follow the child and detach from the parent: move the parent's
584 program space to the child. This simplifies some things, like
585 doing "next" over fork() and landing on the expected line in the
586 child (note, that is broken with "set detach-on-fork off").
588 Before assigning brand new spaces for the parent, remove
589 breakpoints from it: because the new pspace won't match
590 currently inserted locations, the normal detach procedure
591 wouldn't remove them, and we would leave them inserted when
593 remove_breakpoints_inf (parent_inf
);
595 child_inf
->aspace
= parent_inf
->aspace
;
596 child_inf
->pspace
= parent_inf
->pspace
;
597 parent_inf
->aspace
= new address_space ();
598 parent_inf
->pspace
= new program_space (parent_inf
->aspace
);
599 clone_program_space (parent_inf
->pspace
, child_inf
->pspace
);
601 /* The parent inferior is still the current one, so keep things
603 set_current_program_space (parent_inf
->pspace
);
607 child_inf
->aspace
= new address_space ();
608 child_inf
->pspace
= new program_space (child_inf
->aspace
);
609 child_inf
->removable
= true;
610 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
611 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
615 gdb_assert (current_inferior () == parent_inf
);
617 /* If we are setting up an inferior for the child, target_follow_fork is
618 responsible for pushing the appropriate targets on the new inferior's
619 target stack and adding the initial thread (with ptid CHILD_PTID).
621 If we are not setting up an inferior for the child (because following
622 the parent and detach_fork is true), it is responsible for detaching
624 target_follow_fork (child_inf
, child_ptid
, fork_kind
, follow_child
,
627 gdb::observers::inferior_forked
.notify (parent_inf
, child_inf
, fork_kind
);
629 /* target_follow_fork must leave the parent as the current inferior. If we
630 want to follow the child, we make it the current one below. */
631 gdb_assert (current_inferior () == parent_inf
);
633 /* If there is a child inferior, target_follow_fork must have created a thread
635 if (child_inf
!= nullptr)
636 gdb_assert (!child_inf
->thread_list
.empty ());
638 /* Clear the parent thread's pending follow field. Do this before calling
639 target_detach, so that the target can differentiate the two following
642 - We continue past a fork with "follow-fork-mode == child" &&
643 "detach-on-fork on", and therefore detach the parent. In that
644 case the target should not detach the fork child.
645 - We run to a fork catchpoint and the user types "detach". In that
646 case, the target should detach the fork child in addition to the
649 The former case will have pending_follow cleared, the later will have
650 pending_follow set. */
651 thread_info
*parent_thread
= parent_inf
->find_thread (parent_ptid
);
652 gdb_assert (parent_thread
!= nullptr);
653 parent_thread
->pending_follow
.set_spurious ();
655 /* Detach the parent if needed. */
658 /* If we're vforking, we want to hold on to the parent until
659 the child exits or execs. At child exec or exit time we
660 can remove the old breakpoints from the parent and detach
661 or resume debugging it. Otherwise, detach the parent now;
662 we'll want to reuse it's program/address spaces, but we
663 can't set them to the child before removing breakpoints
664 from the parent, otherwise, the breakpoints module could
665 decide to remove breakpoints from the wrong process (since
666 they'd be assigned to the same address space). */
670 gdb_assert (child_inf
->vfork_parent
== nullptr);
671 gdb_assert (parent_inf
->vfork_child
== nullptr);
672 child_inf
->vfork_parent
= parent_inf
;
673 child_inf
->pending_detach
= false;
674 parent_inf
->vfork_child
= child_inf
;
675 parent_inf
->pending_detach
= detach_fork
;
677 else if (detach_fork
)
679 if (print_inferior_events
)
681 /* Ensure that we have a process ptid. */
682 ptid_t process_ptid
= ptid_t (parent_ptid
.pid ());
684 target_terminal::ours_for_output ();
685 gdb_printf (_("[Detaching after fork from "
687 target_pid_to_str (process_ptid
).c_str ());
690 target_detach (parent_inf
, 0);
694 /* If we ended up creating a new inferior, call post_create_inferior to inform
695 the various subcomponents. */
696 if (child_inf
!= nullptr)
698 /* If FOLLOW_CHILD, we leave CHILD_INF as the current inferior
699 (do not restore the parent as the current inferior). */
700 gdb::optional
<scoped_restore_current_thread
> maybe_restore
;
703 maybe_restore
.emplace ();
705 switch_to_thread (*child_inf
->threads ().begin ());
706 post_create_inferior (0);
712 /* Set the last target status as TP having stopped. */
715 set_last_target_status_stopped (thread_info
*tp
)
717 set_last_target_status (tp
->inf
->process_target (), tp
->ptid
,
718 target_waitstatus
{}.set_stopped (GDB_SIGNAL_0
));
721 /* Tell the target to follow the fork we're stopped at. Returns true
722 if the inferior should be resumed; false, if the target for some
723 reason decided it's best not to resume. */
728 bool follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
729 bool should_resume
= true;
731 /* Copy user stepping state to the new inferior thread. FIXME: the
732 followed fork child thread should have a copy of most of the
733 parent thread structure's run control related fields, not just these.
734 Initialized to avoid "may be used uninitialized" warnings from gcc. */
735 struct breakpoint
*step_resume_breakpoint
= nullptr;
736 struct breakpoint
*exception_resume_breakpoint
= nullptr;
737 CORE_ADDR step_range_start
= 0;
738 CORE_ADDR step_range_end
= 0;
739 int current_line
= 0;
740 symtab
*current_symtab
= nullptr;
741 struct frame_id step_frame_id
= { 0 };
745 thread_info
*cur_thr
= inferior_thread ();
748 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
749 process_stratum_target
*resume_target
750 = user_visible_resume_target (resume_ptid
);
752 /* Check if there's a thread that we're about to resume, other
753 than the current, with an unfollowed fork/vfork. If so,
754 switch back to it, to tell the target to follow it (in either
755 direction). We'll afterwards refuse to resume, and inform
756 the user what happened. */
757 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
763 /* follow_fork_inferior clears tp->pending_follow, and below
764 we'll need the value after the follow_fork_inferior
766 target_waitkind kind
= tp
->pending_follow
.kind ();
768 if (kind
!= TARGET_WAITKIND_SPURIOUS
)
770 infrun_debug_printf ("need to follow-fork [%s] first",
771 tp
->ptid
.to_string ().c_str ());
773 switch_to_thread (tp
);
775 /* Set up inferior(s) as specified by the caller, and
776 tell the target to do whatever is necessary to follow
777 either parent or child. */
780 /* The thread that started the execution command
781 won't exist in the child. Abort the command and
782 immediately stop in this thread, in the child,
784 should_resume
= false;
788 /* Following the parent, so let the thread fork its
789 child freely, it won't influence the current
790 execution command. */
791 if (follow_fork_inferior (follow_child
, detach_fork
))
793 /* Target refused to follow, or there's some
794 other reason we shouldn't resume. */
795 switch_to_thread (cur_thr
);
796 set_last_target_status_stopped (cur_thr
);
800 /* If we're following a vfork, when we need to leave
801 the just-forked thread as selected, as we need to
802 solo-resume it to collect the VFORK_DONE event.
803 If we're following a fork, however, switch back
804 to the original thread that we continue stepping
806 if (kind
!= TARGET_WAITKIND_VFORKED
)
808 gdb_assert (kind
== TARGET_WAITKIND_FORKED
);
809 switch_to_thread (cur_thr
);
818 thread_info
*tp
= inferior_thread ();
820 /* If there were any forks/vforks that were caught and are now to be
821 followed, then do so now. */
822 switch (tp
->pending_follow
.kind ())
824 case TARGET_WAITKIND_FORKED
:
825 case TARGET_WAITKIND_VFORKED
:
827 ptid_t parent
, child
;
828 std::unique_ptr
<struct thread_fsm
> thread_fsm
;
830 /* If the user did a next/step, etc, over a fork call,
831 preserve the stepping state in the fork child. */
832 if (follow_child
&& should_resume
)
834 step_resume_breakpoint
= clone_momentary_breakpoint
835 (tp
->control
.step_resume_breakpoint
);
836 step_range_start
= tp
->control
.step_range_start
;
837 step_range_end
= tp
->control
.step_range_end
;
838 current_line
= tp
->current_line
;
839 current_symtab
= tp
->current_symtab
;
840 step_frame_id
= tp
->control
.step_frame_id
;
841 exception_resume_breakpoint
842 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
843 thread_fsm
= tp
->release_thread_fsm ();
845 /* For now, delete the parent's sr breakpoint, otherwise,
846 parent/child sr breakpoints are considered duplicates,
847 and the child version will not be installed. Remove
848 this when the breakpoints module becomes aware of
849 inferiors and address spaces. */
850 delete_step_resume_breakpoint (tp
);
851 tp
->control
.step_range_start
= 0;
852 tp
->control
.step_range_end
= 0;
853 tp
->control
.step_frame_id
= null_frame_id
;
854 delete_exception_resume_breakpoint (tp
);
857 parent
= inferior_ptid
;
858 child
= tp
->pending_follow
.child_ptid ();
860 /* If handling a vfork, stop all the inferior's threads, they will be
861 restarted when the vfork shared region is complete. */
862 if (tp
->pending_follow
.kind () == TARGET_WAITKIND_VFORKED
863 && target_is_non_stop_p ())
864 stop_all_threads ("handling vfork", tp
->inf
);
866 process_stratum_target
*parent_targ
= tp
->inf
->process_target ();
867 /* Set up inferior(s) as specified by the caller, and tell the
868 target to do whatever is necessary to follow either parent
870 if (follow_fork_inferior (follow_child
, detach_fork
))
872 /* Target refused to follow, or there's some other reason
873 we shouldn't resume. */
878 /* If we followed the child, switch to it... */
881 tp
= parent_targ
->find_thread (child
);
882 switch_to_thread (tp
);
884 /* ... and preserve the stepping state, in case the
885 user was stepping over the fork call. */
888 tp
->control
.step_resume_breakpoint
889 = step_resume_breakpoint
;
890 tp
->control
.step_range_start
= step_range_start
;
891 tp
->control
.step_range_end
= step_range_end
;
892 tp
->current_line
= current_line
;
893 tp
->current_symtab
= current_symtab
;
894 tp
->control
.step_frame_id
= step_frame_id
;
895 tp
->control
.exception_resume_breakpoint
896 = exception_resume_breakpoint
;
897 tp
->set_thread_fsm (std::move (thread_fsm
));
901 /* If we get here, it was because we're trying to
902 resume from a fork catchpoint, but, the user
903 has switched threads away from the thread that
904 forked. In that case, the resume command
905 issued is most likely not applicable to the
906 child, so just warn, and refuse to resume. */
907 warning (_("Not resuming: switched threads "
908 "before following fork child."));
911 /* Reset breakpoints in the child as appropriate. */
912 follow_inferior_reset_breakpoints ();
917 case TARGET_WAITKIND_SPURIOUS
:
918 /* Nothing to follow. */
921 internal_error ("Unexpected pending_follow.kind %d\n",
922 tp
->pending_follow
.kind ());
927 set_last_target_status_stopped (tp
);
928 return should_resume
;
932 follow_inferior_reset_breakpoints (void)
934 struct thread_info
*tp
= inferior_thread ();
936 /* Was there a step_resume breakpoint? (There was if the user
937 did a "next" at the fork() call.) If so, explicitly reset its
938 thread number. Cloned step_resume breakpoints are disabled on
939 creation, so enable it here now that it is associated with the
942 step_resumes are a form of bp that are made to be per-thread.
943 Since we created the step_resume bp when the parent process
944 was being debugged, and now are switching to the child process,
945 from the breakpoint package's viewpoint, that's a switch of
946 "threads". We must update the bp's notion of which thread
947 it is for, or it'll be ignored when it triggers. */
949 if (tp
->control
.step_resume_breakpoint
)
951 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
952 tp
->control
.step_resume_breakpoint
->loc
->enabled
= 1;
955 /* Treat exception_resume breakpoints like step_resume breakpoints. */
956 if (tp
->control
.exception_resume_breakpoint
)
958 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
959 tp
->control
.exception_resume_breakpoint
->loc
->enabled
= 1;
962 /* Reinsert all breakpoints in the child. The user may have set
963 breakpoints after catching the fork, in which case those
964 were never set in the child, but only in the parent. This makes
965 sure the inserted breakpoints match the breakpoint list. */
967 breakpoint_re_set ();
968 insert_breakpoints ();
971 /* The child has exited or execed: resume THREAD, a thread of the parent,
972 if it was meant to be executing. */
975 proceed_after_vfork_done (thread_info
*thread
)
977 if (thread
->state
== THREAD_RUNNING
978 && !thread
->executing ()
979 && !thread
->stop_requested
980 && thread
->stop_signal () == GDB_SIGNAL_0
)
982 infrun_debug_printf ("resuming vfork parent thread %s",
983 thread
->ptid
.to_string ().c_str ());
985 switch_to_thread (thread
);
986 clear_proceed_status (0);
987 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
991 /* Called whenever we notice an exec or exit event, to handle
992 detaching or resuming a vfork parent. */
995 handle_vfork_child_exec_or_exit (int exec
)
997 struct inferior
*inf
= current_inferior ();
999 if (inf
->vfork_parent
)
1001 inferior
*resume_parent
= nullptr;
1003 /* This exec or exit marks the end of the shared memory region
1004 between the parent and the child. Break the bonds. */
1005 inferior
*vfork_parent
= inf
->vfork_parent
;
1006 inf
->vfork_parent
->vfork_child
= nullptr;
1007 inf
->vfork_parent
= nullptr;
1009 /* If the user wanted to detach from the parent, now is the
1011 if (vfork_parent
->pending_detach
)
1013 struct program_space
*pspace
;
1014 struct address_space
*aspace
;
1016 /* follow-fork child, detach-on-fork on. */
1018 vfork_parent
->pending_detach
= false;
1020 scoped_restore_current_pspace_and_thread restore_thread
;
1022 /* We're letting loose of the parent. */
1023 thread_info
*tp
= any_live_thread_of_inferior (vfork_parent
);
1024 switch_to_thread (tp
);
1026 /* We're about to detach from the parent, which implicitly
1027 removes breakpoints from its address space. There's a
1028 catch here: we want to reuse the spaces for the child,
1029 but, parent/child are still sharing the pspace at this
1030 point, although the exec in reality makes the kernel give
1031 the child a fresh set of new pages. The problem here is
1032 that the breakpoints module being unaware of this, would
1033 likely chose the child process to write to the parent
1034 address space. Swapping the child temporarily away from
1035 the spaces has the desired effect. Yes, this is "sort
1038 pspace
= inf
->pspace
;
1039 aspace
= inf
->aspace
;
1040 inf
->aspace
= nullptr;
1041 inf
->pspace
= nullptr;
1043 if (print_inferior_events
)
1046 = target_pid_to_str (ptid_t (vfork_parent
->pid
));
1048 target_terminal::ours_for_output ();
1052 gdb_printf (_("[Detaching vfork parent %s "
1053 "after child exec]\n"), pidstr
.c_str ());
1057 gdb_printf (_("[Detaching vfork parent %s "
1058 "after child exit]\n"), pidstr
.c_str ());
1062 target_detach (vfork_parent
, 0);
1065 inf
->pspace
= pspace
;
1066 inf
->aspace
= aspace
;
1070 /* We're staying attached to the parent, so, really give the
1071 child a new address space. */
1072 inf
->pspace
= new program_space (maybe_new_address_space ());
1073 inf
->aspace
= inf
->pspace
->aspace
;
1074 inf
->removable
= true;
1075 set_current_program_space (inf
->pspace
);
1077 resume_parent
= vfork_parent
;
1081 /* If this is a vfork child exiting, then the pspace and
1082 aspaces were shared with the parent. Since we're
1083 reporting the process exit, we'll be mourning all that is
1084 found in the address space, and switching to null_ptid,
1085 preparing to start a new inferior. But, since we don't
1086 want to clobber the parent's address/program spaces, we
1087 go ahead and create a new one for this exiting
1090 /* Switch to no-thread while running clone_program_space, so
1091 that clone_program_space doesn't want to read the
1092 selected frame of a dead process. */
1093 scoped_restore_current_thread restore_thread
;
1094 switch_to_no_thread ();
1096 inf
->pspace
= new program_space (maybe_new_address_space ());
1097 inf
->aspace
= inf
->pspace
->aspace
;
1098 set_current_program_space (inf
->pspace
);
1099 inf
->removable
= true;
1100 inf
->symfile_flags
= SYMFILE_NO_READ
;
1101 clone_program_space (inf
->pspace
, vfork_parent
->pspace
);
1103 resume_parent
= vfork_parent
;
1106 gdb_assert (current_program_space
== inf
->pspace
);
1108 if (non_stop
&& resume_parent
!= nullptr)
1110 /* If the user wanted the parent to be running, let it go
1112 scoped_restore_current_thread restore_thread
;
1114 infrun_debug_printf ("resuming vfork parent process %d",
1115 resume_parent
->pid
);
1117 for (thread_info
*thread
: resume_parent
->threads ())
1118 proceed_after_vfork_done (thread
);
1123 /* Handle TARGET_WAITKIND_VFORK_DONE. */
1126 handle_vfork_done (thread_info
*event_thread
)
1128 /* We only care about this event if inferior::thread_waiting_for_vfork_done is
1129 set, that is if we are waiting for a vfork child not under our control
1130 (because we detached it) to exec or exit.
1132 If an inferior has vforked and we are debugging the child, we don't use
1133 the vfork-done event to get notified about the end of the shared address
1134 space window. We rely instead on the child's exec or exit event, and the
1135 inferior::vfork_{parent,child} fields are used instead. See
1136 handle_vfork_child_exec_or_exit for that. */
1137 if (event_thread
->inf
->thread_waiting_for_vfork_done
== nullptr)
1139 infrun_debug_printf ("not waiting for a vfork-done event");
1143 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1145 /* We stopped all threads (other than the vforking thread) of the inferior in
1146 follow_fork and kept them stopped until now. It should therefore not be
1147 possible for another thread to have reported a vfork during that window.
1148 If THREAD_WAITING_FOR_VFORK_DONE is set, it has to be the same thread whose
1149 vfork-done we are handling right now. */
1150 gdb_assert (event_thread
->inf
->thread_waiting_for_vfork_done
== event_thread
);
1152 event_thread
->inf
->thread_waiting_for_vfork_done
= nullptr;
1153 event_thread
->inf
->pspace
->breakpoints_not_allowed
= 0;
1155 /* On non-stop targets, we stopped all the inferior's threads in follow_fork,
1156 resume them now. On all-stop targets, everything that needs to be resumed
1157 will be when we resume the event thread. */
1158 if (target_is_non_stop_p ())
1160 /* restart_threads and start_step_over may change the current thread, make
1161 sure we leave the event thread as the current thread. */
1162 scoped_restore_current_thread restore_thread
;
1164 insert_breakpoints ();
1167 if (!step_over_info_valid_p ())
1168 restart_threads (event_thread
, event_thread
->inf
);
1172 /* Enum strings for "set|show follow-exec-mode". */
1174 static const char follow_exec_mode_new
[] = "new";
1175 static const char follow_exec_mode_same
[] = "same";
1176 static const char *const follow_exec_mode_names
[] =
1178 follow_exec_mode_new
,
1179 follow_exec_mode_same
,
1183 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1185 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1186 struct cmd_list_element
*c
, const char *value
)
1188 gdb_printf (file
, _("Follow exec mode is \"%s\".\n"), value
);
1191 /* EXEC_FILE_TARGET is assumed to be non-NULL. */
1194 follow_exec (ptid_t ptid
, const char *exec_file_target
)
1196 int pid
= ptid
.pid ();
1197 ptid_t process_ptid
;
1199 /* Switch terminal for any messages produced e.g. by
1200 breakpoint_re_set. */
1201 target_terminal::ours_for_output ();
1203 /* This is an exec event that we actually wish to pay attention to.
1204 Refresh our symbol table to the newly exec'd program, remove any
1205 momentary bp's, etc.
1207 If there are breakpoints, they aren't really inserted now,
1208 since the exec() transformed our inferior into a fresh set
1211 We want to preserve symbolic breakpoints on the list, since
1212 we have hopes that they can be reset after the new a.out's
1213 symbol table is read.
1215 However, any "raw" breakpoints must be removed from the list
1216 (e.g., the solib bp's), since their address is probably invalid
1219 And, we DON'T want to call delete_breakpoints() here, since
1220 that may write the bp's "shadow contents" (the instruction
1221 value that was overwritten with a TRAP instruction). Since
1222 we now have a new a.out, those shadow contents aren't valid. */
1224 mark_breakpoints_out ();
1226 /* The target reports the exec event to the main thread, even if
1227 some other thread does the exec, and even if the main thread was
1228 stopped or already gone. We may still have non-leader threads of
1229 the process on our list. E.g., on targets that don't have thread
1230 exit events (like remote); or on native Linux in non-stop mode if
1231 there were only two threads in the inferior and the non-leader
1232 one is the one that execs (and nothing forces an update of the
1233 thread list up to here). When debugging remotely, it's best to
1234 avoid extra traffic, when possible, so avoid syncing the thread
1235 list with the target, and instead go ahead and delete all threads
1236 of the process but one that reported the event. Note this must
1237 be done before calling update_breakpoints_after_exec, as
1238 otherwise clearing the threads' resources would reference stale
1239 thread breakpoints -- it may have been one of these threads that
1240 stepped across the exec. We could just clear their stepping
1241 states, but as long as we're iterating, might as well delete
1242 them. Deleting them now rather than at the next user-visible
1243 stop provides a nicer sequence of events for user and MI
1245 for (thread_info
*th
: all_threads_safe ())
1246 if (th
->ptid
.pid () == pid
&& th
->ptid
!= ptid
)
1249 /* We also need to clear any left over stale state for the
1250 leader/event thread. E.g., if there was any step-resume
1251 breakpoint or similar, it's gone now. We cannot truly
1252 step-to-next statement through an exec(). */
1253 thread_info
*th
= inferior_thread ();
1254 th
->control
.step_resume_breakpoint
= nullptr;
1255 th
->control
.exception_resume_breakpoint
= nullptr;
1256 th
->control
.single_step_breakpoints
= nullptr;
1257 th
->control
.step_range_start
= 0;
1258 th
->control
.step_range_end
= 0;
1260 /* The user may have had the main thread held stopped in the
1261 previous image (e.g., schedlock on, or non-stop). Release
1263 th
->stop_requested
= 0;
1265 update_breakpoints_after_exec ();
1267 /* What is this a.out's name? */
1268 process_ptid
= ptid_t (pid
);
1269 gdb_printf (_("%s is executing new program: %s\n"),
1270 target_pid_to_str (process_ptid
).c_str (),
1273 /* We've followed the inferior through an exec. Therefore, the
1274 inferior has essentially been killed & reborn. */
1276 breakpoint_init_inferior (inf_execd
);
1278 gdb::unique_xmalloc_ptr
<char> exec_file_host
1279 = exec_file_find (exec_file_target
, nullptr);
1281 /* If we were unable to map the executable target pathname onto a host
1282 pathname, tell the user that. Otherwise GDB's subsequent behavior
1283 is confusing. Maybe it would even be better to stop at this point
1284 so that the user can specify a file manually before continuing. */
1285 if (exec_file_host
== nullptr)
1286 warning (_("Could not load symbols for executable %s.\n"
1287 "Do you need \"set sysroot\"?"),
1290 /* Reset the shared library package. This ensures that we get a
1291 shlib event when the child reaches "_start", at which point the
1292 dld will have had a chance to initialize the child. */
1293 /* Also, loading a symbol file below may trigger symbol lookups, and
1294 we don't want those to be satisfied by the libraries of the
1295 previous incarnation of this process. */
1296 no_shared_libraries (nullptr, 0);
1298 inferior
*execing_inferior
= current_inferior ();
1299 inferior
*following_inferior
;
1301 if (follow_exec_mode_string
== follow_exec_mode_new
)
1303 /* The user wants to keep the old inferior and program spaces
1304 around. Create a new fresh one, and switch to it. */
1306 /* Do exit processing for the original inferior before setting the new
1307 inferior's pid. Having two inferiors with the same pid would confuse
1308 find_inferior_p(t)id. Transfer the terminal state and info from the
1309 old to the new inferior. */
1310 following_inferior
= add_inferior_with_spaces ();
1312 swap_terminal_info (following_inferior
, execing_inferior
);
1313 exit_inferior_silent (execing_inferior
);
1315 following_inferior
->pid
= pid
;
1319 /* follow-exec-mode is "same", we continue execution in the execing
1321 following_inferior
= execing_inferior
;
1323 /* The old description may no longer be fit for the new image.
1324 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1325 old description; we'll read a new one below. No need to do
1326 this on "follow-exec-mode new", as the old inferior stays
1327 around (its description is later cleared/refetched on
1329 target_clear_description ();
1332 target_follow_exec (following_inferior
, ptid
, exec_file_target
);
1334 gdb_assert (current_inferior () == following_inferior
);
1335 gdb_assert (current_program_space
== following_inferior
->pspace
);
1337 /* Attempt to open the exec file. SYMFILE_DEFER_BP_RESET is used
1338 because the proper displacement for a PIE (Position Independent
1339 Executable) main symbol file will only be computed by
1340 solib_create_inferior_hook below. breakpoint_re_set would fail
1341 to insert the breakpoints with the zero displacement. */
1342 try_open_exec_file (exec_file_host
.get (), following_inferior
,
1343 SYMFILE_DEFER_BP_RESET
);
1345 /* If the target can specify a description, read it. Must do this
1346 after flipping to the new executable (because the target supplied
1347 description must be compatible with the executable's
1348 architecture, and the old executable may e.g., be 32-bit, while
1349 the new one 64-bit), and before anything involving memory or
1351 target_find_description ();
1353 gdb::observers::inferior_execd
.notify (execing_inferior
, following_inferior
);
1355 breakpoint_re_set ();
1357 /* Reinsert all breakpoints. (Those which were symbolic have
1358 been reset to the proper address in the new a.out, thanks
1359 to symbol_file_command...). */
1360 insert_breakpoints ();
1362 /* The next resume of this inferior should bring it to the shlib
1363 startup breakpoints. (If the user had also set bp's on
1364 "main" from the old (parent) process, then they'll auto-
1365 matically get reset there in the new process.). */
1368 /* The chain of threads that need to do a step-over operation to get
1369 past e.g., a breakpoint. What technique is used to step over the
1370 breakpoint/watchpoint does not matter -- all threads end up in the
1371 same queue, to maintain rough temporal order of execution, in order
1372 to avoid starvation, otherwise, we could e.g., find ourselves
1373 constantly stepping the same couple threads past their breakpoints
1374 over and over, if the single-step finish fast enough. */
1375 thread_step_over_list global_thread_step_over_list
;
1377 /* Bit flags indicating what the thread needs to step over. */
1379 enum step_over_what_flag
1381 /* Step over a breakpoint. */
1382 STEP_OVER_BREAKPOINT
= 1,
1384 /* Step past a non-continuable watchpoint, in order to let the
1385 instruction execute so we can evaluate the watchpoint
1387 STEP_OVER_WATCHPOINT
= 2
1389 DEF_ENUM_FLAGS_TYPE (enum step_over_what_flag
, step_over_what
);
1391 /* Info about an instruction that is being stepped over. */
1393 struct step_over_info
1395 /* If we're stepping past a breakpoint, this is the address space
1396 and address of the instruction the breakpoint is set at. We'll
1397 skip inserting all breakpoints here. Valid iff ASPACE is
1399 const address_space
*aspace
= nullptr;
1400 CORE_ADDR address
= 0;
1402 /* The instruction being stepped over triggers a nonsteppable
1403 watchpoint. If true, we'll skip inserting watchpoints. */
1404 int nonsteppable_watchpoint_p
= 0;
1406 /* The thread's global number. */
1410 /* The step-over info of the location that is being stepped over.
1412 Note that with async/breakpoint always-inserted mode, a user might
1413 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1414 being stepped over. As setting a new breakpoint inserts all
1415 breakpoints, we need to make sure the breakpoint being stepped over
1416 isn't inserted then. We do that by only clearing the step-over
1417 info when the step-over is actually finished (or aborted).
1419 Presently GDB can only step over one breakpoint at any given time.
1420 Given threads that can't run code in the same address space as the
1421 breakpoint's can't really miss the breakpoint, GDB could be taught
1422 to step-over at most one breakpoint per address space (so this info
1423 could move to the address space object if/when GDB is extended).
1424 The set of breakpoints being stepped over will normally be much
1425 smaller than the set of all breakpoints, so a flag in the
1426 breakpoint location structure would be wasteful. A separate list
1427 also saves complexity and run-time, as otherwise we'd have to go
1428 through all breakpoint locations clearing their flag whenever we
1429 start a new sequence. Similar considerations weigh against storing
1430 this info in the thread object. Plus, not all step overs actually
1431 have breakpoint locations -- e.g., stepping past a single-step
1432 breakpoint, or stepping to complete a non-continuable
1434 static struct step_over_info step_over_info
;
1436 /* Record the address of the breakpoint/instruction we're currently
1438 N.B. We record the aspace and address now, instead of say just the thread,
1439 because when we need the info later the thread may be running. */
1442 set_step_over_info (const address_space
*aspace
, CORE_ADDR address
,
1443 int nonsteppable_watchpoint_p
,
1446 step_over_info
.aspace
= aspace
;
1447 step_over_info
.address
= address
;
1448 step_over_info
.nonsteppable_watchpoint_p
= nonsteppable_watchpoint_p
;
1449 step_over_info
.thread
= thread
;
1452 /* Called when we're not longer stepping over a breakpoint / an
1453 instruction, so all breakpoints are free to be (re)inserted. */
1456 clear_step_over_info (void)
1458 infrun_debug_printf ("clearing step over info");
1459 step_over_info
.aspace
= nullptr;
1460 step_over_info
.address
= 0;
1461 step_over_info
.nonsteppable_watchpoint_p
= 0;
1462 step_over_info
.thread
= -1;
1468 stepping_past_instruction_at (struct address_space
*aspace
,
1471 return (step_over_info
.aspace
!= nullptr
1472 && breakpoint_address_match (aspace
, address
,
1473 step_over_info
.aspace
,
1474 step_over_info
.address
));
1480 thread_is_stepping_over_breakpoint (int thread
)
1482 return (step_over_info
.thread
!= -1
1483 && thread
== step_over_info
.thread
);
1489 stepping_past_nonsteppable_watchpoint (void)
1491 return step_over_info
.nonsteppable_watchpoint_p
;
1494 /* Returns true if step-over info is valid. */
1497 step_over_info_valid_p (void)
1499 return (step_over_info
.aspace
!= nullptr
1500 || stepping_past_nonsteppable_watchpoint ());
1504 /* Displaced stepping. */
1506 /* In non-stop debugging mode, we must take special care to manage
1507 breakpoints properly; in particular, the traditional strategy for
1508 stepping a thread past a breakpoint it has hit is unsuitable.
1509 'Displaced stepping' is a tactic for stepping one thread past a
1510 breakpoint it has hit while ensuring that other threads running
1511 concurrently will hit the breakpoint as they should.
1513 The traditional way to step a thread T off a breakpoint in a
1514 multi-threaded program in all-stop mode is as follows:
1516 a0) Initially, all threads are stopped, and breakpoints are not
1518 a1) We single-step T, leaving breakpoints uninserted.
1519 a2) We insert breakpoints, and resume all threads.
1521 In non-stop debugging, however, this strategy is unsuitable: we
1522 don't want to have to stop all threads in the system in order to
1523 continue or step T past a breakpoint. Instead, we use displaced
1526 n0) Initially, T is stopped, other threads are running, and
1527 breakpoints are inserted.
1528 n1) We copy the instruction "under" the breakpoint to a separate
1529 location, outside the main code stream, making any adjustments
1530 to the instruction, register, and memory state as directed by
1532 n2) We single-step T over the instruction at its new location.
1533 n3) We adjust the resulting register and memory state as directed
1534 by T's architecture. This includes resetting T's PC to point
1535 back into the main instruction stream.
1538 This approach depends on the following gdbarch methods:
1540 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1541 indicate where to copy the instruction, and how much space must
1542 be reserved there. We use these in step n1.
1544 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1545 address, and makes any necessary adjustments to the instruction,
1546 register contents, and memory. We use this in step n1.
1548 - gdbarch_displaced_step_fixup adjusts registers and memory after
1549 we have successfully single-stepped the instruction, to yield the
1550 same effect the instruction would have had if we had executed it
1551 at its original address. We use this in step n3.
1553 The gdbarch_displaced_step_copy_insn and
1554 gdbarch_displaced_step_fixup functions must be written so that
1555 copying an instruction with gdbarch_displaced_step_copy_insn,
1556 single-stepping across the copied instruction, and then applying
1557 gdbarch_displaced_insn_fixup should have the same effects on the
1558 thread's memory and registers as stepping the instruction in place
1559 would have. Exactly which responsibilities fall to the copy and
1560 which fall to the fixup is up to the author of those functions.
1562 See the comments in gdbarch.sh for details.
1564 Note that displaced stepping and software single-step cannot
1565 currently be used in combination, although with some care I think
1566 they could be made to. Software single-step works by placing
1567 breakpoints on all possible subsequent instructions; if the
1568 displaced instruction is a PC-relative jump, those breakpoints
1569 could fall in very strange places --- on pages that aren't
1570 executable, or at addresses that are not proper instruction
1571 boundaries. (We do generally let other threads run while we wait
1572 to hit the software single-step breakpoint, and they might
1573 encounter such a corrupted instruction.) One way to work around
1574 this would be to have gdbarch_displaced_step_copy_insn fully
1575 simulate the effect of PC-relative instructions (and return NULL)
1576 on architectures that use software single-stepping.
1578 In non-stop mode, we can have independent and simultaneous step
1579 requests, so more than one thread may need to simultaneously step
1580 over a breakpoint. The current implementation assumes there is
1581 only one scratch space per process. In this case, we have to
1582 serialize access to the scratch space. If thread A wants to step
1583 over a breakpoint, but we are currently waiting for some other
1584 thread to complete a displaced step, we leave thread A stopped and
1585 place it in the displaced_step_request_queue. Whenever a displaced
1586 step finishes, we pick the next thread in the queue and start a new
1587 displaced step operation on it. See displaced_step_prepare and
1588 displaced_step_finish for details. */
1590 /* Return true if THREAD is doing a displaced step. */
1593 displaced_step_in_progress_thread (thread_info
*thread
)
1595 gdb_assert (thread
!= nullptr);
1597 return thread
->displaced_step_state
.in_progress ();
1600 /* Return true if INF has a thread doing a displaced step. */
1603 displaced_step_in_progress (inferior
*inf
)
1605 return inf
->displaced_step_state
.in_progress_count
> 0;
1608 /* Return true if any thread is doing a displaced step. */
1611 displaced_step_in_progress_any_thread ()
1613 for (inferior
*inf
: all_non_exited_inferiors ())
1615 if (displaced_step_in_progress (inf
))
1623 infrun_inferior_exit (struct inferior
*inf
)
1625 inf
->displaced_step_state
.reset ();
1626 inf
->thread_waiting_for_vfork_done
= nullptr;
1630 infrun_inferior_execd (inferior
*exec_inf
, inferior
*follow_inf
)
1632 /* If some threads where was doing a displaced step in this inferior at the
1633 moment of the exec, they no longer exist. Even if the exec'ing thread
1634 doing a displaced step, we don't want to to any fixup nor restore displaced
1635 stepping buffer bytes. */
1636 follow_inf
->displaced_step_state
.reset ();
1638 for (thread_info
*thread
: follow_inf
->threads ())
1639 thread
->displaced_step_state
.reset ();
1641 /* Since an in-line step is done with everything else stopped, if there was
1642 one in progress at the time of the exec, it must have been the exec'ing
1644 clear_step_over_info ();
1646 follow_inf
->thread_waiting_for_vfork_done
= nullptr;
1649 /* If ON, and the architecture supports it, GDB will use displaced
1650 stepping to step over breakpoints. If OFF, or if the architecture
1651 doesn't support it, GDB will instead use the traditional
1652 hold-and-step approach. If AUTO (which is the default), GDB will
1653 decide which technique to use to step over breakpoints depending on
1654 whether the target works in a non-stop way (see use_displaced_stepping). */
1656 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1659 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1660 struct cmd_list_element
*c
,
1663 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1665 _("Debugger's willingness to use displaced stepping "
1666 "to step over breakpoints is %s (currently %s).\n"),
1667 value
, target_is_non_stop_p () ? "on" : "off");
1670 _("Debugger's willingness to use displaced stepping "
1671 "to step over breakpoints is %s.\n"), value
);
1674 /* Return true if the gdbarch implements the required methods to use
1675 displaced stepping. */
1678 gdbarch_supports_displaced_stepping (gdbarch
*arch
)
1680 /* Only check for the presence of `prepare`. The gdbarch verification ensures
1681 that if `prepare` is provided, so is `finish`. */
1682 return gdbarch_displaced_step_prepare_p (arch
);
1685 /* Return non-zero if displaced stepping can/should be used to step
1686 over breakpoints of thread TP. */
1689 use_displaced_stepping (thread_info
*tp
)
1691 /* If the user disabled it explicitly, don't use displaced stepping. */
1692 if (can_use_displaced_stepping
== AUTO_BOOLEAN_FALSE
)
1695 /* If "auto", only use displaced stepping if the target operates in a non-stop
1697 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
1698 && !target_is_non_stop_p ())
1701 gdbarch
*gdbarch
= get_thread_regcache (tp
)->arch ();
1703 /* If the architecture doesn't implement displaced stepping, don't use
1705 if (!gdbarch_supports_displaced_stepping (gdbarch
))
1708 /* If recording, don't use displaced stepping. */
1709 if (find_record_target () != nullptr)
1712 /* If displaced stepping failed before for this inferior, don't bother trying
1714 if (tp
->inf
->displaced_step_state
.failed_before
)
1720 /* Simple function wrapper around displaced_step_thread_state::reset. */
1723 displaced_step_reset (displaced_step_thread_state
*displaced
)
1725 displaced
->reset ();
1728 /* A cleanup that wraps displaced_step_reset. We use this instead of, say,
1729 SCOPE_EXIT, because it needs to be discardable with "cleanup.release ()". */
1731 using displaced_step_reset_cleanup
= FORWARD_SCOPE_EXIT (displaced_step_reset
);
1733 /* Prepare to single-step, using displaced stepping.
1735 Note that we cannot use displaced stepping when we have a signal to
1736 deliver. If we have a signal to deliver and an instruction to step
1737 over, then after the step, there will be no indication from the
1738 target whether the thread entered a signal handler or ignored the
1739 signal and stepped over the instruction successfully --- both cases
1740 result in a simple SIGTRAP. In the first case we mustn't do a
1741 fixup, and in the second case we must --- but we can't tell which.
1742 Comments in the code for 'random signals' in handle_inferior_event
1743 explain how we handle this case instead.
1745 Returns DISPLACED_STEP_PREPARE_STATUS_OK if preparing was successful -- this
1746 thread is going to be stepped now; DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
1747 if displaced stepping this thread got queued; or
1748 DISPLACED_STEP_PREPARE_STATUS_CANT if this instruction can't be displaced
1751 static displaced_step_prepare_status
1752 displaced_step_prepare_throw (thread_info
*tp
)
1754 regcache
*regcache
= get_thread_regcache (tp
);
1755 struct gdbarch
*gdbarch
= regcache
->arch ();
1756 displaced_step_thread_state
&disp_step_thread_state
1757 = tp
->displaced_step_state
;
1759 /* We should never reach this function if the architecture does not
1760 support displaced stepping. */
1761 gdb_assert (gdbarch_supports_displaced_stepping (gdbarch
));
1763 /* Nor if the thread isn't meant to step over a breakpoint. */
1764 gdb_assert (tp
->control
.trap_expected
);
1766 /* Disable range stepping while executing in the scratch pad. We
1767 want a single-step even if executing the displaced instruction in
1768 the scratch buffer lands within the stepping range (e.g., a
1770 tp
->control
.may_range_step
= 0;
1772 /* We are about to start a displaced step for this thread. If one is already
1773 in progress, something's wrong. */
1774 gdb_assert (!disp_step_thread_state
.in_progress ());
1776 if (tp
->inf
->displaced_step_state
.unavailable
)
1778 /* The gdbarch tells us it's not worth asking to try a prepare because
1779 it is likely that it will return unavailable, so don't bother asking. */
1781 displaced_debug_printf ("deferring step of %s",
1782 tp
->ptid
.to_string ().c_str ());
1784 global_thread_step_over_chain_enqueue (tp
);
1785 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1788 displaced_debug_printf ("displaced-stepping %s now",
1789 tp
->ptid
.to_string ().c_str ());
1791 scoped_restore_current_thread restore_thread
;
1793 switch_to_thread (tp
);
1795 CORE_ADDR original_pc
= regcache_read_pc (regcache
);
1796 CORE_ADDR displaced_pc
;
1798 /* Display the instruction we are going to displaced step. */
1799 if (debug_displaced
)
1801 string_file tmp_stream
;
1802 int dislen
= gdb_print_insn (gdbarch
, original_pc
, &tmp_stream
,
1807 gdb::byte_vector
insn_buf (dislen
);
1808 read_memory (original_pc
, insn_buf
.data (), insn_buf
.size ());
1810 std::string insn_bytes
= bytes_to_string (insn_buf
);
1812 displaced_debug_printf ("original insn %s: %s \t %s",
1813 paddress (gdbarch
, original_pc
),
1814 insn_bytes
.c_str (),
1815 tmp_stream
.string ().c_str ());
1818 displaced_debug_printf ("original insn %s: invalid length: %d",
1819 paddress (gdbarch
, original_pc
), dislen
);
1822 displaced_step_prepare_status status
1823 = gdbarch_displaced_step_prepare (gdbarch
, tp
, displaced_pc
);
1825 if (status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
1827 displaced_debug_printf ("failed to prepare (%s)",
1828 tp
->ptid
.to_string ().c_str ());
1830 return DISPLACED_STEP_PREPARE_STATUS_CANT
;
1832 else if (status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
1834 /* Not enough displaced stepping resources available, defer this
1835 request by placing it the queue. */
1837 displaced_debug_printf ("not enough resources available, "
1838 "deferring step of %s",
1839 tp
->ptid
.to_string ().c_str ());
1841 global_thread_step_over_chain_enqueue (tp
);
1843 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1846 gdb_assert (status
== DISPLACED_STEP_PREPARE_STATUS_OK
);
1848 /* Save the information we need to fix things up if the step
1850 disp_step_thread_state
.set (gdbarch
);
1852 tp
->inf
->displaced_step_state
.in_progress_count
++;
1854 displaced_debug_printf ("prepared successfully thread=%s, "
1855 "original_pc=%s, displaced_pc=%s",
1856 tp
->ptid
.to_string ().c_str (),
1857 paddress (gdbarch
, original_pc
),
1858 paddress (gdbarch
, displaced_pc
));
1860 /* Display the new displaced instruction(s). */
1861 if (debug_displaced
)
1863 string_file tmp_stream
;
1864 CORE_ADDR addr
= displaced_pc
;
1866 /* If displaced stepping is going to use h/w single step then we know
1867 that the replacement instruction can only be a single instruction,
1868 in that case set the end address at the next byte.
1870 Otherwise the displaced stepping copy instruction routine could
1871 have generated multiple instructions, and all we know is that they
1872 must fit within the LEN bytes of the buffer. */
1874 = addr
+ (gdbarch_displaced_step_hw_singlestep (gdbarch
)
1875 ? 1 : gdbarch_displaced_step_buffer_length (gdbarch
));
1879 int dislen
= gdb_print_insn (gdbarch
, addr
, &tmp_stream
, nullptr);
1882 displaced_debug_printf
1883 ("replacement insn %s: invalid length: %d",
1884 paddress (gdbarch
, addr
), dislen
);
1888 gdb::byte_vector
insn_buf (dislen
);
1889 read_memory (addr
, insn_buf
.data (), insn_buf
.size ());
1891 std::string insn_bytes
= bytes_to_string (insn_buf
);
1892 std::string insn_str
= tmp_stream
.release ();
1893 displaced_debug_printf ("replacement insn %s: %s \t %s",
1894 paddress (gdbarch
, addr
),
1895 insn_bytes
.c_str (),
1901 return DISPLACED_STEP_PREPARE_STATUS_OK
;
1904 /* Wrapper for displaced_step_prepare_throw that disabled further
1905 attempts at displaced stepping if we get a memory error. */
1907 static displaced_step_prepare_status
1908 displaced_step_prepare (thread_info
*thread
)
1910 displaced_step_prepare_status status
1911 = DISPLACED_STEP_PREPARE_STATUS_CANT
;
1915 status
= displaced_step_prepare_throw (thread
);
1917 catch (const gdb_exception_error
&ex
)
1919 if (ex
.error
!= MEMORY_ERROR
1920 && ex
.error
!= NOT_SUPPORTED_ERROR
)
1923 infrun_debug_printf ("caught exception, disabling displaced stepping: %s",
1926 /* Be verbose if "set displaced-stepping" is "on", silent if
1928 if (can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1930 warning (_("disabling displaced stepping: %s"),
1934 /* Disable further displaced stepping attempts. */
1935 thread
->inf
->displaced_step_state
.failed_before
= 1;
1941 /* If we displaced stepped an instruction successfully, adjust registers and
1942 memory to yield the same effect the instruction would have had if we had
1943 executed it at its original address, and return
1944 DISPLACED_STEP_FINISH_STATUS_OK. If the instruction didn't complete,
1945 relocate the PC and return DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED.
1947 If the thread wasn't displaced stepping, return
1948 DISPLACED_STEP_FINISH_STATUS_OK as well. */
1950 static displaced_step_finish_status
1951 displaced_step_finish (thread_info
*event_thread
,
1952 const target_waitstatus
&event_status
)
1954 displaced_step_thread_state
*displaced
= &event_thread
->displaced_step_state
;
1956 /* Was this thread performing a displaced step? */
1957 if (!displaced
->in_progress ())
1958 return DISPLACED_STEP_FINISH_STATUS_OK
;
1960 gdb_assert (event_thread
->inf
->displaced_step_state
.in_progress_count
> 0);
1961 event_thread
->inf
->displaced_step_state
.in_progress_count
--;
1963 /* Fixup may need to read memory/registers. Switch to the thread
1964 that we're fixing up. Also, target_stopped_by_watchpoint checks
1965 the current thread, and displaced_step_restore performs ptid-dependent
1966 memory accesses using current_inferior(). */
1967 switch_to_thread (event_thread
);
1969 displaced_step_reset_cleanup
cleanup (displaced
);
1971 /* Do the fixup, and release the resources acquired to do the displaced
1973 return gdbarch_displaced_step_finish (displaced
->get_original_gdbarch (),
1974 event_thread
, event_status
);
1977 /* Data to be passed around while handling an event. This data is
1978 discarded between events. */
1979 struct execution_control_state
1981 explicit execution_control_state (thread_info
*thr
= nullptr)
1982 : ptid (thr
== nullptr ? null_ptid
: thr
->ptid
),
1987 process_stratum_target
*target
= nullptr;
1989 /* The thread that got the event, if this was a thread event; NULL
1991 struct thread_info
*event_thread
;
1993 struct target_waitstatus ws
;
1994 int stop_func_filled_in
= 0;
1995 CORE_ADDR stop_func_alt_start
= 0;
1996 CORE_ADDR stop_func_start
= 0;
1997 CORE_ADDR stop_func_end
= 0;
1998 const char *stop_func_name
= nullptr;
1999 int wait_some_more
= 0;
2001 /* True if the event thread hit the single-step breakpoint of
2002 another thread. Thus the event doesn't cause a stop, the thread
2003 needs to be single-stepped past the single-step breakpoint before
2004 we can switch back to the original stepping thread. */
2005 int hit_singlestep_breakpoint
= 0;
2008 static void keep_going_pass_signal (struct execution_control_state
*ecs
);
2009 static void prepare_to_wait (struct execution_control_state
*ecs
);
2010 static bool keep_going_stepped_thread (struct thread_info
*tp
);
2011 static step_over_what
thread_still_needs_step_over (struct thread_info
*tp
);
2013 /* Are there any pending step-over requests? If so, run all we can
2014 now and return true. Otherwise, return false. */
2017 start_step_over (void)
2019 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
2021 /* Don't start a new step-over if we already have an in-line
2022 step-over operation ongoing. */
2023 if (step_over_info_valid_p ())
2026 /* Steal the global thread step over chain. As we try to initiate displaced
2027 steps, threads will be enqueued in the global chain if no buffers are
2028 available. If we iterated on the global chain directly, we might iterate
2030 thread_step_over_list threads_to_step
2031 = std::move (global_thread_step_over_list
);
2033 infrun_debug_printf ("stealing global queue of threads to step, length = %d",
2034 thread_step_over_chain_length (threads_to_step
));
2036 bool started
= false;
2038 /* On scope exit (whatever the reason, return or exception), if there are
2039 threads left in the THREADS_TO_STEP chain, put back these threads in the
2043 if (threads_to_step
.empty ())
2044 infrun_debug_printf ("step-over queue now empty");
2047 infrun_debug_printf ("putting back %d threads to step in global queue",
2048 thread_step_over_chain_length (threads_to_step
));
2050 global_thread_step_over_chain_enqueue_chain
2051 (std::move (threads_to_step
));
2055 thread_step_over_list_safe_range range
2056 = make_thread_step_over_list_safe_range (threads_to_step
);
2058 for (thread_info
*tp
: range
)
2060 step_over_what step_what
;
2061 int must_be_in_line
;
2063 gdb_assert (!tp
->stop_requested
);
2065 if (tp
->inf
->displaced_step_state
.unavailable
)
2067 /* The arch told us to not even try preparing another displaced step
2068 for this inferior. Just leave the thread in THREADS_TO_STEP, it
2069 will get moved to the global chain on scope exit. */
2073 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr)
2075 /* When we stop all threads, handling a vfork, any thread in the step
2076 over chain remains there. A user could also try to continue a
2077 thread stopped at a breakpoint while another thread is waiting for
2078 a vfork-done event. In any case, we don't want to start a step
2083 /* Remove thread from the THREADS_TO_STEP chain. If anything goes wrong
2084 while we try to prepare the displaced step, we don't add it back to
2085 the global step over chain. This is to avoid a thread staying in the
2086 step over chain indefinitely if something goes wrong when resuming it
2087 If the error is intermittent and it still needs a step over, it will
2088 get enqueued again when we try to resume it normally. */
2089 threads_to_step
.erase (threads_to_step
.iterator_to (*tp
));
2091 step_what
= thread_still_needs_step_over (tp
);
2092 must_be_in_line
= ((step_what
& STEP_OVER_WATCHPOINT
)
2093 || ((step_what
& STEP_OVER_BREAKPOINT
)
2094 && !use_displaced_stepping (tp
)));
2096 /* We currently stop all threads of all processes to step-over
2097 in-line. If we need to start a new in-line step-over, let
2098 any pending displaced steps finish first. */
2099 if (must_be_in_line
&& displaced_step_in_progress_any_thread ())
2101 global_thread_step_over_chain_enqueue (tp
);
2105 if (tp
->control
.trap_expected
2107 || tp
->executing ())
2109 internal_error ("[%s] has inconsistent state: "
2110 "trap_expected=%d, resumed=%d, executing=%d\n",
2111 tp
->ptid
.to_string ().c_str (),
2112 tp
->control
.trap_expected
,
2117 infrun_debug_printf ("resuming [%s] for step-over",
2118 tp
->ptid
.to_string ().c_str ());
2120 /* keep_going_pass_signal skips the step-over if the breakpoint
2121 is no longer inserted. In all-stop, we want to keep looking
2122 for a thread that needs a step-over instead of resuming TP,
2123 because we wouldn't be able to resume anything else until the
2124 target stops again. In non-stop, the resume always resumes
2125 only TP, so it's OK to let the thread resume freely. */
2126 if (!target_is_non_stop_p () && !step_what
)
2129 switch_to_thread (tp
);
2130 execution_control_state
ecs (tp
);
2131 keep_going_pass_signal (&ecs
);
2133 if (!ecs
.wait_some_more
)
2134 error (_("Command aborted."));
2136 /* If the thread's step over could not be initiated because no buffers
2137 were available, it was re-added to the global step over chain. */
2140 infrun_debug_printf ("[%s] was resumed.",
2141 tp
->ptid
.to_string ().c_str ());
2142 gdb_assert (!thread_is_in_step_over_chain (tp
));
2146 infrun_debug_printf ("[%s] was NOT resumed.",
2147 tp
->ptid
.to_string ().c_str ());
2148 gdb_assert (thread_is_in_step_over_chain (tp
));
2151 /* If we started a new in-line step-over, we're done. */
2152 if (step_over_info_valid_p ())
2154 gdb_assert (tp
->control
.trap_expected
);
2159 if (!target_is_non_stop_p ())
2161 /* On all-stop, shouldn't have resumed unless we needed a
2163 gdb_assert (tp
->control
.trap_expected
2164 || tp
->step_after_step_resume_breakpoint
);
2166 /* With remote targets (at least), in all-stop, we can't
2167 issue any further remote commands until the program stops
2173 /* Either the thread no longer needed a step-over, or a new
2174 displaced stepping sequence started. Even in the latter
2175 case, continue looking. Maybe we can also start another
2176 displaced step on a thread of other process. */
2182 /* Update global variables holding ptids to hold NEW_PTID if they were
2183 holding OLD_PTID. */
2185 infrun_thread_ptid_changed (process_stratum_target
*target
,
2186 ptid_t old_ptid
, ptid_t new_ptid
)
2188 if (inferior_ptid
== old_ptid
2189 && current_inferior ()->process_target () == target
)
2190 inferior_ptid
= new_ptid
;
2195 static const char schedlock_off
[] = "off";
2196 static const char schedlock_on
[] = "on";
2197 static const char schedlock_step
[] = "step";
2198 static const char schedlock_replay
[] = "replay";
2199 static const char *const scheduler_enums
[] = {
2206 static const char *scheduler_mode
= schedlock_replay
;
2208 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
2209 struct cmd_list_element
*c
, const char *value
)
2212 _("Mode for locking scheduler "
2213 "during execution is \"%s\".\n"),
2218 set_schedlock_func (const char *args
, int from_tty
, struct cmd_list_element
*c
)
2220 if (!target_can_lock_scheduler ())
2222 scheduler_mode
= schedlock_off
;
2223 error (_("Target '%s' cannot support this command."),
2224 target_shortname ());
2228 /* True if execution commands resume all threads of all processes by
2229 default; otherwise, resume only threads of the current inferior
2231 bool sched_multi
= false;
2233 /* Try to setup for software single stepping. Return true if target_resume()
2234 should use hardware single step.
2236 GDBARCH the current gdbarch. */
2239 maybe_software_singlestep (struct gdbarch
*gdbarch
)
2241 bool hw_step
= true;
2243 if (execution_direction
== EXEC_FORWARD
2244 && gdbarch_software_single_step_p (gdbarch
))
2245 hw_step
= !insert_single_step_breakpoints (gdbarch
);
2253 user_visible_resume_ptid (int step
)
2259 /* With non-stop mode on, threads are always handled
2261 resume_ptid
= inferior_ptid
;
2263 else if ((scheduler_mode
== schedlock_on
)
2264 || (scheduler_mode
== schedlock_step
&& step
))
2266 /* User-settable 'scheduler' mode requires solo thread
2268 resume_ptid
= inferior_ptid
;
2270 else if ((scheduler_mode
== schedlock_replay
)
2271 && target_record_will_replay (minus_one_ptid
, execution_direction
))
2273 /* User-settable 'scheduler' mode requires solo thread resume in replay
2275 resume_ptid
= inferior_ptid
;
2277 else if (!sched_multi
&& target_supports_multi_process ())
2279 /* Resume all threads of the current process (and none of other
2281 resume_ptid
= ptid_t (inferior_ptid
.pid ());
2285 /* Resume all threads of all processes. */
2286 resume_ptid
= RESUME_ALL
;
2294 process_stratum_target
*
2295 user_visible_resume_target (ptid_t resume_ptid
)
2297 return (resume_ptid
== minus_one_ptid
&& sched_multi
2299 : current_inferior ()->process_target ());
2302 /* Find a thread from the inferiors that we'll resume that is waiting
2303 for a vfork-done event. */
2305 static thread_info
*
2306 find_thread_waiting_for_vfork_done ()
2308 gdb_assert (!target_is_non_stop_p ());
2312 for (inferior
*inf
: all_non_exited_inferiors ())
2313 if (inf
->thread_waiting_for_vfork_done
!= nullptr)
2314 return inf
->thread_waiting_for_vfork_done
;
2318 inferior
*cur_inf
= current_inferior ();
2319 if (cur_inf
->thread_waiting_for_vfork_done
!= nullptr)
2320 return cur_inf
->thread_waiting_for_vfork_done
;
2325 /* Return a ptid representing the set of threads that we will resume,
2326 in the perspective of the target, assuming run control handling
2327 does not require leaving some threads stopped (e.g., stepping past
2328 breakpoint). USER_STEP indicates whether we're about to start the
2329 target for a stepping command. */
2332 internal_resume_ptid (int user_step
)
2334 /* In non-stop, we always control threads individually. Note that
2335 the target may always work in non-stop mode even with "set
2336 non-stop off", in which case user_visible_resume_ptid could
2337 return a wildcard ptid. */
2338 if (target_is_non_stop_p ())
2339 return inferior_ptid
;
2341 /* The rest of the function assumes non-stop==off and
2342 target-non-stop==off.
2344 If a thread is waiting for a vfork-done event, it means breakpoints are out
2345 for this inferior (well, program space in fact). We don't want to resume
2346 any thread other than the one waiting for vfork done, otherwise these other
2347 threads could miss breakpoints. So if a thread in the resumption set is
2348 waiting for a vfork-done event, resume only that thread.
2350 The resumption set width depends on whether schedule-multiple is on or off.
2352 Note that if the target_resume interface was more flexible, we could be
2353 smarter here when schedule-multiple is on. For example, imagine 3
2354 inferiors with 2 threads each (1.1, 1.2, 2.1, 2.2, 3.1 and 3.2). Threads
2355 2.1 and 3.2 are both waiting for a vfork-done event. Then we could ask the
2356 target(s) to resume:
2358 - All threads of inferior 1
2362 Since we don't have that flexibility (we can only pass one ptid), just
2363 resume the first thread waiting for a vfork-done event we find (e.g. thread
2365 thread_info
*thr
= find_thread_waiting_for_vfork_done ();
2368 /* If we have a thread that is waiting for a vfork-done event,
2369 then we should have switched to it earlier. Calling
2370 target_resume with thread scope is only possible when the
2371 current thread matches the thread scope. */
2372 gdb_assert (thr
->ptid
== inferior_ptid
);
2373 gdb_assert (thr
->inf
->process_target ()
2374 == inferior_thread ()->inf
->process_target ());
2378 return user_visible_resume_ptid (user_step
);
2381 /* Wrapper for target_resume, that handles infrun-specific
2385 do_target_resume (ptid_t resume_ptid
, bool step
, enum gdb_signal sig
)
2387 struct thread_info
*tp
= inferior_thread ();
2389 gdb_assert (!tp
->stop_requested
);
2391 /* Install inferior's terminal modes. */
2392 target_terminal::inferior ();
2394 /* Avoid confusing the next resume, if the next stop/resume
2395 happens to apply to another thread. */
2396 tp
->set_stop_signal (GDB_SIGNAL_0
);
2398 /* Advise target which signals may be handled silently.
2400 If we have removed breakpoints because we are stepping over one
2401 in-line (in any thread), we need to receive all signals to avoid
2402 accidentally skipping a breakpoint during execution of a signal
2405 Likewise if we're displaced stepping, otherwise a trap for a
2406 breakpoint in a signal handler might be confused with the
2407 displaced step finishing. We don't make the displaced_step_finish
2408 step distinguish the cases instead, because:
2410 - a backtrace while stopped in the signal handler would show the
2411 scratch pad as frame older than the signal handler, instead of
2412 the real mainline code.
2414 - when the thread is later resumed, the signal handler would
2415 return to the scratch pad area, which would no longer be
2417 if (step_over_info_valid_p ()
2418 || displaced_step_in_progress (tp
->inf
))
2419 target_pass_signals ({});
2421 target_pass_signals (signal_pass
);
2423 infrun_debug_printf ("resume_ptid=%s, step=%d, sig=%s",
2424 resume_ptid
.to_string ().c_str (),
2425 step
, gdb_signal_to_symbol_string (sig
));
2427 target_resume (resume_ptid
, step
, sig
);
2430 /* Resume the inferior. SIG is the signal to give the inferior
2431 (GDB_SIGNAL_0 for none). Note: don't call this directly; instead
2432 call 'resume', which handles exceptions. */
2435 resume_1 (enum gdb_signal sig
)
2437 struct regcache
*regcache
= get_current_regcache ();
2438 struct gdbarch
*gdbarch
= regcache
->arch ();
2439 struct thread_info
*tp
= inferior_thread ();
2440 const address_space
*aspace
= regcache
->aspace ();
2442 /* This represents the user's step vs continue request. When
2443 deciding whether "set scheduler-locking step" applies, it's the
2444 user's intention that counts. */
2445 const int user_step
= tp
->control
.stepping_command
;
2446 /* This represents what we'll actually request the target to do.
2447 This can decay from a step to a continue, if e.g., we need to
2448 implement single-stepping with breakpoints (software
2452 gdb_assert (!tp
->stop_requested
);
2453 gdb_assert (!thread_is_in_step_over_chain (tp
));
2455 if (tp
->has_pending_waitstatus ())
2458 ("thread %s has pending wait "
2459 "status %s (currently_stepping=%d).",
2460 tp
->ptid
.to_string ().c_str (),
2461 tp
->pending_waitstatus ().to_string ().c_str (),
2462 currently_stepping (tp
));
2464 tp
->inf
->process_target ()->threads_executing
= true;
2465 tp
->set_resumed (true);
2467 /* FIXME: What should we do if we are supposed to resume this
2468 thread with a signal? Maybe we should maintain a queue of
2469 pending signals to deliver. */
2470 if (sig
!= GDB_SIGNAL_0
)
2472 warning (_("Couldn't deliver signal %s to %s."),
2473 gdb_signal_to_name (sig
),
2474 tp
->ptid
.to_string ().c_str ());
2477 tp
->set_stop_signal (GDB_SIGNAL_0
);
2479 if (target_can_async_p ())
2481 target_async (true);
2482 /* Tell the event loop we have an event to process. */
2483 mark_async_event_handler (infrun_async_inferior_event_token
);
2488 tp
->stepped_breakpoint
= 0;
2490 /* Depends on stepped_breakpoint. */
2491 step
= currently_stepping (tp
);
2493 if (current_inferior ()->thread_waiting_for_vfork_done
!= nullptr)
2495 /* Don't try to single-step a vfork parent that is waiting for
2496 the child to get out of the shared memory region (by exec'ing
2497 or exiting). This is particularly important on software
2498 single-step archs, as the child process would trip on the
2499 software single step breakpoint inserted for the parent
2500 process. Since the parent will not actually execute any
2501 instruction until the child is out of the shared region (such
2502 are vfork's semantics), it is safe to simply continue it.
2503 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2504 the parent, and tell it to `keep_going', which automatically
2505 re-sets it stepping. */
2506 infrun_debug_printf ("resume : clear step");
2510 CORE_ADDR pc
= regcache_read_pc (regcache
);
2512 infrun_debug_printf ("step=%d, signal=%s, trap_expected=%d, "
2513 "current thread [%s] at %s",
2514 step
, gdb_signal_to_symbol_string (sig
),
2515 tp
->control
.trap_expected
,
2516 inferior_ptid
.to_string ().c_str (),
2517 paddress (gdbarch
, pc
));
2519 /* Normally, by the time we reach `resume', the breakpoints are either
2520 removed or inserted, as appropriate. The exception is if we're sitting
2521 at a permanent breakpoint; we need to step over it, but permanent
2522 breakpoints can't be removed. So we have to test for it here. */
2523 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2525 if (sig
!= GDB_SIGNAL_0
)
2527 /* We have a signal to pass to the inferior. The resume
2528 may, or may not take us to the signal handler. If this
2529 is a step, we'll need to stop in the signal handler, if
2530 there's one, (if the target supports stepping into
2531 handlers), or in the next mainline instruction, if
2532 there's no handler. If this is a continue, we need to be
2533 sure to run the handler with all breakpoints inserted.
2534 In all cases, set a breakpoint at the current address
2535 (where the handler returns to), and once that breakpoint
2536 is hit, resume skipping the permanent breakpoint. If
2537 that breakpoint isn't hit, then we've stepped into the
2538 signal handler (or hit some other event). We'll delete
2539 the step-resume breakpoint then. */
2541 infrun_debug_printf ("resume: skipping permanent breakpoint, "
2542 "deliver signal first");
2544 clear_step_over_info ();
2545 tp
->control
.trap_expected
= 0;
2547 if (tp
->control
.step_resume_breakpoint
== nullptr)
2549 /* Set a "high-priority" step-resume, as we don't want
2550 user breakpoints at PC to trigger (again) when this
2552 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2553 gdb_assert (tp
->control
.step_resume_breakpoint
->loc
->permanent
);
2555 tp
->step_after_step_resume_breakpoint
= step
;
2558 insert_breakpoints ();
2562 /* There's no signal to pass, we can go ahead and skip the
2563 permanent breakpoint manually. */
2564 infrun_debug_printf ("skipping permanent breakpoint");
2565 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2566 /* Update pc to reflect the new address from which we will
2567 execute instructions. */
2568 pc
= regcache_read_pc (regcache
);
2572 /* We've already advanced the PC, so the stepping part
2573 is done. Now we need to arrange for a trap to be
2574 reported to handle_inferior_event. Set a breakpoint
2575 at the current PC, and run to it. Don't update
2576 prev_pc, because if we end in
2577 switch_back_to_stepped_thread, we want the "expected
2578 thread advanced also" branch to be taken. IOW, we
2579 don't want this thread to step further from PC
2581 gdb_assert (!step_over_info_valid_p ());
2582 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
2583 insert_breakpoints ();
2585 resume_ptid
= internal_resume_ptid (user_step
);
2586 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
2587 tp
->set_resumed (true);
2593 /* If we have a breakpoint to step over, make sure to do a single
2594 step only. Same if we have software watchpoints. */
2595 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2596 tp
->control
.may_range_step
= 0;
2598 /* If displaced stepping is enabled, step over breakpoints by executing a
2599 copy of the instruction at a different address.
2601 We can't use displaced stepping when we have a signal to deliver;
2602 the comments for displaced_step_prepare explain why. The
2603 comments in the handle_inferior event for dealing with 'random
2604 signals' explain what we do instead.
2606 We can't use displaced stepping when we are waiting for vfork_done
2607 event, displaced stepping breaks the vfork child similarly as single
2608 step software breakpoint. */
2609 if (tp
->control
.trap_expected
2610 && use_displaced_stepping (tp
)
2611 && !step_over_info_valid_p ()
2612 && sig
== GDB_SIGNAL_0
2613 && current_inferior ()->thread_waiting_for_vfork_done
== nullptr)
2615 displaced_step_prepare_status prepare_status
2616 = displaced_step_prepare (tp
);
2618 if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
2620 infrun_debug_printf ("Got placed in step-over queue");
2622 tp
->control
.trap_expected
= 0;
2625 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
2627 /* Fallback to stepping over the breakpoint in-line. */
2629 if (target_is_non_stop_p ())
2630 stop_all_threads ("displaced stepping falling back on inline stepping");
2632 set_step_over_info (regcache
->aspace (),
2633 regcache_read_pc (regcache
), 0, tp
->global_num
);
2635 step
= maybe_software_singlestep (gdbarch
);
2637 insert_breakpoints ();
2639 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_OK
)
2641 /* Update pc to reflect the new address from which we will
2642 execute instructions due to displaced stepping. */
2643 pc
= regcache_read_pc (get_thread_regcache (tp
));
2645 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
);
2648 gdb_assert_not_reached ("Invalid displaced_step_prepare_status "
2652 /* Do we need to do it the hard way, w/temp breakpoints? */
2654 step
= maybe_software_singlestep (gdbarch
);
2656 /* Currently, our software single-step implementation leads to different
2657 results than hardware single-stepping in one situation: when stepping
2658 into delivering a signal which has an associated signal handler,
2659 hardware single-step will stop at the first instruction of the handler,
2660 while software single-step will simply skip execution of the handler.
2662 For now, this difference in behavior is accepted since there is no
2663 easy way to actually implement single-stepping into a signal handler
2664 without kernel support.
2666 However, there is one scenario where this difference leads to follow-on
2667 problems: if we're stepping off a breakpoint by removing all breakpoints
2668 and then single-stepping. In this case, the software single-step
2669 behavior means that even if there is a *breakpoint* in the signal
2670 handler, GDB still would not stop.
2672 Fortunately, we can at least fix this particular issue. We detect
2673 here the case where we are about to deliver a signal while software
2674 single-stepping with breakpoints removed. In this situation, we
2675 revert the decisions to remove all breakpoints and insert single-
2676 step breakpoints, and instead we install a step-resume breakpoint
2677 at the current address, deliver the signal without stepping, and
2678 once we arrive back at the step-resume breakpoint, actually step
2679 over the breakpoint we originally wanted to step over. */
2680 if (thread_has_single_step_breakpoints_set (tp
)
2681 && sig
!= GDB_SIGNAL_0
2682 && step_over_info_valid_p ())
2684 /* If we have nested signals or a pending signal is delivered
2685 immediately after a handler returns, might already have
2686 a step-resume breakpoint set on the earlier handler. We cannot
2687 set another step-resume breakpoint; just continue on until the
2688 original breakpoint is hit. */
2689 if (tp
->control
.step_resume_breakpoint
== nullptr)
2691 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2692 tp
->step_after_step_resume_breakpoint
= 1;
2695 delete_single_step_breakpoints (tp
);
2697 clear_step_over_info ();
2698 tp
->control
.trap_expected
= 0;
2700 insert_breakpoints ();
2703 /* If STEP is set, it's a request to use hardware stepping
2704 facilities. But in that case, we should never
2705 use singlestep breakpoint. */
2706 gdb_assert (!(thread_has_single_step_breakpoints_set (tp
) && step
));
2708 /* Decide the set of threads to ask the target to resume. */
2709 if (tp
->control
.trap_expected
)
2711 /* We're allowing a thread to run past a breakpoint it has
2712 hit, either by single-stepping the thread with the breakpoint
2713 removed, or by displaced stepping, with the breakpoint inserted.
2714 In the former case, we need to single-step only this thread,
2715 and keep others stopped, as they can miss this breakpoint if
2716 allowed to run. That's not really a problem for displaced
2717 stepping, but, we still keep other threads stopped, in case
2718 another thread is also stopped for a breakpoint waiting for
2719 its turn in the displaced stepping queue. */
2720 resume_ptid
= inferior_ptid
;
2723 resume_ptid
= internal_resume_ptid (user_step
);
2725 if (execution_direction
!= EXEC_REVERSE
2726 && step
&& breakpoint_inserted_here_p (aspace
, pc
))
2728 /* There are two cases where we currently need to step a
2729 breakpoint instruction when we have a signal to deliver:
2731 - See handle_signal_stop where we handle random signals that
2732 could take out us out of the stepping range. Normally, in
2733 that case we end up continuing (instead of stepping) over the
2734 signal handler with a breakpoint at PC, but there are cases
2735 where we should _always_ single-step, even if we have a
2736 step-resume breakpoint, like when a software watchpoint is
2737 set. Assuming single-stepping and delivering a signal at the
2738 same time would takes us to the signal handler, then we could
2739 have removed the breakpoint at PC to step over it. However,
2740 some hardware step targets (like e.g., Mac OS) can't step
2741 into signal handlers, and for those, we need to leave the
2742 breakpoint at PC inserted, as otherwise if the handler
2743 recurses and executes PC again, it'll miss the breakpoint.
2744 So we leave the breakpoint inserted anyway, but we need to
2745 record that we tried to step a breakpoint instruction, so
2746 that adjust_pc_after_break doesn't end up confused.
2748 - In non-stop if we insert a breakpoint (e.g., a step-resume)
2749 in one thread after another thread that was stepping had been
2750 momentarily paused for a step-over. When we re-resume the
2751 stepping thread, it may be resumed from that address with a
2752 breakpoint that hasn't trapped yet. Seen with
2753 gdb.threads/non-stop-fair-events.exp, on targets that don't
2754 do displaced stepping. */
2756 infrun_debug_printf ("resume: [%s] stepped breakpoint",
2757 tp
->ptid
.to_string ().c_str ());
2759 tp
->stepped_breakpoint
= 1;
2761 /* Most targets can step a breakpoint instruction, thus
2762 executing it normally. But if this one cannot, just
2763 continue and we will hit it anyway. */
2764 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2768 if (tp
->control
.may_range_step
)
2770 /* If we're resuming a thread with the PC out of the step
2771 range, then we're doing some nested/finer run control
2772 operation, like stepping the thread out of the dynamic
2773 linker or the displaced stepping scratch pad. We
2774 shouldn't have allowed a range step then. */
2775 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2778 do_target_resume (resume_ptid
, step
, sig
);
2779 tp
->set_resumed (true);
2782 /* Resume the inferior. SIG is the signal to give the inferior
2783 (GDB_SIGNAL_0 for none). This is a wrapper around 'resume_1' that
2784 rolls back state on error. */
2787 resume (gdb_signal sig
)
2793 catch (const gdb_exception
&ex
)
2795 /* If resuming is being aborted for any reason, delete any
2796 single-step breakpoint resume_1 may have created, to avoid
2797 confusing the following resumption, and to avoid leaving
2798 single-step breakpoints perturbing other threads, in case
2799 we're running in non-stop mode. */
2800 if (inferior_ptid
!= null_ptid
)
2801 delete_single_step_breakpoints (inferior_thread ());
2811 /* Counter that tracks number of user visible stops. This can be used
2812 to tell whether a command has proceeded the inferior past the
2813 current location. This allows e.g., inferior function calls in
2814 breakpoint commands to not interrupt the command list. When the
2815 call finishes successfully, the inferior is standing at the same
2816 breakpoint as if nothing happened (and so we don't call
2818 static ULONGEST current_stop_id
;
2825 return current_stop_id
;
2828 /* Called when we report a user visible stop. */
2836 /* Clear out all variables saying what to do when inferior is continued.
2837 First do this, then set the ones you want, then call `proceed'. */
2840 clear_proceed_status_thread (struct thread_info
*tp
)
2842 infrun_debug_printf ("%s", tp
->ptid
.to_string ().c_str ());
2844 /* If we're starting a new sequence, then the previous finished
2845 single-step is no longer relevant. */
2846 if (tp
->has_pending_waitstatus ())
2848 if (tp
->stop_reason () == TARGET_STOPPED_BY_SINGLE_STEP
)
2850 infrun_debug_printf ("pending event of %s was a finished step. "
2852 tp
->ptid
.to_string ().c_str ());
2854 tp
->clear_pending_waitstatus ();
2855 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
2860 ("thread %s has pending wait status %s (currently_stepping=%d).",
2861 tp
->ptid
.to_string ().c_str (),
2862 tp
->pending_waitstatus ().to_string ().c_str (),
2863 currently_stepping (tp
));
2867 /* If this signal should not be seen by program, give it zero.
2868 Used for debugging signals. */
2869 if (!signal_pass_state (tp
->stop_signal ()))
2870 tp
->set_stop_signal (GDB_SIGNAL_0
);
2872 tp
->release_thread_fsm ();
2874 tp
->control
.trap_expected
= 0;
2875 tp
->control
.step_range_start
= 0;
2876 tp
->control
.step_range_end
= 0;
2877 tp
->control
.may_range_step
= 0;
2878 tp
->control
.step_frame_id
= null_frame_id
;
2879 tp
->control
.step_stack_frame_id
= null_frame_id
;
2880 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2881 tp
->control
.step_start_function
= nullptr;
2882 tp
->stop_requested
= 0;
2884 tp
->control
.stop_step
= 0;
2886 tp
->control
.proceed_to_finish
= 0;
2888 tp
->control
.stepping_command
= 0;
2890 /* Discard any remaining commands or status from previous stop. */
2891 bpstat_clear (&tp
->control
.stop_bpstat
);
2895 clear_proceed_status (int step
)
2897 /* With scheduler-locking replay, stop replaying other threads if we're
2898 not replaying the user-visible resume ptid.
2900 This is a convenience feature to not require the user to explicitly
2901 stop replaying the other threads. We're assuming that the user's
2902 intent is to resume tracing the recorded process. */
2903 if (!non_stop
&& scheduler_mode
== schedlock_replay
2904 && target_record_is_replaying (minus_one_ptid
)
2905 && !target_record_will_replay (user_visible_resume_ptid (step
),
2906 execution_direction
))
2907 target_record_stop_replaying ();
2909 if (!non_stop
&& inferior_ptid
!= null_ptid
)
2911 ptid_t resume_ptid
= user_visible_resume_ptid (step
);
2912 process_stratum_target
*resume_target
2913 = user_visible_resume_target (resume_ptid
);
2915 /* In all-stop mode, delete the per-thread status of all threads
2916 we're about to resume, implicitly and explicitly. */
2917 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
2918 clear_proceed_status_thread (tp
);
2921 if (inferior_ptid
!= null_ptid
)
2923 struct inferior
*inferior
;
2927 /* If in non-stop mode, only delete the per-thread status of
2928 the current thread. */
2929 clear_proceed_status_thread (inferior_thread ());
2932 inferior
= current_inferior ();
2933 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2936 gdb::observers::about_to_proceed
.notify ();
2939 /* Returns true if TP is still stopped at a breakpoint that needs
2940 stepping-over in order to make progress. If the breakpoint is gone
2941 meanwhile, we can skip the whole step-over dance. */
2944 thread_still_needs_step_over_bp (struct thread_info
*tp
)
2946 if (tp
->stepping_over_breakpoint
)
2948 struct regcache
*regcache
= get_thread_regcache (tp
);
2950 if (breakpoint_here_p (regcache
->aspace (),
2951 regcache_read_pc (regcache
))
2952 == ordinary_breakpoint_here
)
2955 tp
->stepping_over_breakpoint
= 0;
2961 /* Check whether thread TP still needs to start a step-over in order
2962 to make progress when resumed. Returns an bitwise or of enum
2963 step_over_what bits, indicating what needs to be stepped over. */
2965 static step_over_what
2966 thread_still_needs_step_over (struct thread_info
*tp
)
2968 step_over_what what
= 0;
2970 if (thread_still_needs_step_over_bp (tp
))
2971 what
|= STEP_OVER_BREAKPOINT
;
2973 if (tp
->stepping_over_watchpoint
2974 && !target_have_steppable_watchpoint ())
2975 what
|= STEP_OVER_WATCHPOINT
;
2980 /* Returns true if scheduler locking applies. STEP indicates whether
2981 we're about to do a step/next-like command to a thread. */
2984 schedlock_applies (struct thread_info
*tp
)
2986 return (scheduler_mode
== schedlock_on
2987 || (scheduler_mode
== schedlock_step
2988 && tp
->control
.stepping_command
)
2989 || (scheduler_mode
== schedlock_replay
2990 && target_record_will_replay (minus_one_ptid
,
2991 execution_direction
)));
2994 /* Set process_stratum_target::COMMIT_RESUMED_STATE in all target
2995 stacks that have threads executing and don't have threads with
2999 maybe_set_commit_resumed_all_targets ()
3001 scoped_restore_current_thread restore_thread
;
3003 for (inferior
*inf
: all_non_exited_inferiors ())
3005 process_stratum_target
*proc_target
= inf
->process_target ();
3007 if (proc_target
->commit_resumed_state
)
3009 /* We already set this in a previous iteration, via another
3010 inferior sharing the process_stratum target. */
3014 /* If the target has no resumed threads, it would be useless to
3015 ask it to commit the resumed threads. */
3016 if (!proc_target
->threads_executing
)
3018 infrun_debug_printf ("not requesting commit-resumed for target "
3019 "%s, no resumed threads",
3020 proc_target
->shortname ());
3024 /* As an optimization, if a thread from this target has some
3025 status to report, handle it before requiring the target to
3026 commit its resumed threads: handling the status might lead to
3027 resuming more threads. */
3028 if (proc_target
->has_resumed_with_pending_wait_status ())
3030 infrun_debug_printf ("not requesting commit-resumed for target %s, a"
3031 " thread has a pending waitstatus",
3032 proc_target
->shortname ());
3036 switch_to_inferior_no_thread (inf
);
3038 if (target_has_pending_events ())
3040 infrun_debug_printf ("not requesting commit-resumed for target %s, "
3041 "target has pending events",
3042 proc_target
->shortname ());
3046 infrun_debug_printf ("enabling commit-resumed for target %s",
3047 proc_target
->shortname ());
3049 proc_target
->commit_resumed_state
= true;
3056 maybe_call_commit_resumed_all_targets ()
3058 scoped_restore_current_thread restore_thread
;
3060 for (inferior
*inf
: all_non_exited_inferiors ())
3062 process_stratum_target
*proc_target
= inf
->process_target ();
3064 if (!proc_target
->commit_resumed_state
)
3067 switch_to_inferior_no_thread (inf
);
3069 infrun_debug_printf ("calling commit_resumed for target %s",
3070 proc_target
->shortname());
3072 target_commit_resumed ();
3076 /* To track nesting of scoped_disable_commit_resumed objects, ensuring
3077 that only the outermost one attempts to re-enable
3079 static bool enable_commit_resumed
= true;
3083 scoped_disable_commit_resumed::scoped_disable_commit_resumed
3084 (const char *reason
)
3085 : m_reason (reason
),
3086 m_prev_enable_commit_resumed (enable_commit_resumed
)
3088 infrun_debug_printf ("reason=%s", m_reason
);
3090 enable_commit_resumed
= false;
3092 for (inferior
*inf
: all_non_exited_inferiors ())
3094 process_stratum_target
*proc_target
= inf
->process_target ();
3096 if (m_prev_enable_commit_resumed
)
3098 /* This is the outermost instance: force all
3099 COMMIT_RESUMED_STATE to false. */
3100 proc_target
->commit_resumed_state
= false;
3104 /* This is not the outermost instance, we expect
3105 COMMIT_RESUMED_STATE to have been cleared by the
3106 outermost instance. */
3107 gdb_assert (!proc_target
->commit_resumed_state
);
3115 scoped_disable_commit_resumed::reset ()
3121 infrun_debug_printf ("reason=%s", m_reason
);
3123 gdb_assert (!enable_commit_resumed
);
3125 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3127 if (m_prev_enable_commit_resumed
)
3129 /* This is the outermost instance, re-enable
3130 COMMIT_RESUMED_STATE on the targets where it's possible. */
3131 maybe_set_commit_resumed_all_targets ();
3135 /* This is not the outermost instance, we expect
3136 COMMIT_RESUMED_STATE to still be false. */
3137 for (inferior
*inf
: all_non_exited_inferiors ())
3139 process_stratum_target
*proc_target
= inf
->process_target ();
3140 gdb_assert (!proc_target
->commit_resumed_state
);
3147 scoped_disable_commit_resumed::~scoped_disable_commit_resumed ()
3155 scoped_disable_commit_resumed::reset_and_commit ()
3158 maybe_call_commit_resumed_all_targets ();
3163 scoped_enable_commit_resumed::scoped_enable_commit_resumed
3164 (const char *reason
)
3165 : m_reason (reason
),
3166 m_prev_enable_commit_resumed (enable_commit_resumed
)
3168 infrun_debug_printf ("reason=%s", m_reason
);
3170 if (!enable_commit_resumed
)
3172 enable_commit_resumed
= true;
3174 /* Re-enable COMMIT_RESUMED_STATE on the targets where it's
3176 maybe_set_commit_resumed_all_targets ();
3178 maybe_call_commit_resumed_all_targets ();
3184 scoped_enable_commit_resumed::~scoped_enable_commit_resumed ()
3186 infrun_debug_printf ("reason=%s", m_reason
);
3188 gdb_assert (enable_commit_resumed
);
3190 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3192 if (!enable_commit_resumed
)
3194 /* Force all COMMIT_RESUMED_STATE back to false. */
3195 for (inferior
*inf
: all_non_exited_inferiors ())
3197 process_stratum_target
*proc_target
= inf
->process_target ();
3198 proc_target
->commit_resumed_state
= false;
3203 /* Check that all the targets we're about to resume are in non-stop
3204 mode. Ideally, we'd only care whether all targets support
3205 target-async, but we're not there yet. E.g., stop_all_threads
3206 doesn't know how to handle all-stop targets. Also, the remote
3207 protocol in all-stop mode is synchronous, irrespective of
3208 target-async, which means that things like a breakpoint re-set
3209 triggered by one target would try to read memory from all targets
3213 check_multi_target_resumption (process_stratum_target
*resume_target
)
3215 if (!non_stop
&& resume_target
== nullptr)
3217 scoped_restore_current_thread restore_thread
;
3219 /* This is used to track whether we're resuming more than one
3221 process_stratum_target
*first_connection
= nullptr;
3223 /* The first inferior we see with a target that does not work in
3224 always-non-stop mode. */
3225 inferior
*first_not_non_stop
= nullptr;
3227 for (inferior
*inf
: all_non_exited_inferiors ())
3229 switch_to_inferior_no_thread (inf
);
3231 if (!target_has_execution ())
3234 process_stratum_target
*proc_target
3235 = current_inferior ()->process_target();
3237 if (!target_is_non_stop_p ())
3238 first_not_non_stop
= inf
;
3240 if (first_connection
== nullptr)
3241 first_connection
= proc_target
;
3242 else if (first_connection
!= proc_target
3243 && first_not_non_stop
!= nullptr)
3245 switch_to_inferior_no_thread (first_not_non_stop
);
3247 proc_target
= current_inferior ()->process_target();
3249 error (_("Connection %d (%s) does not support "
3250 "multi-target resumption."),
3251 proc_target
->connection_number
,
3252 make_target_connection_string (proc_target
).c_str ());
3258 /* Basic routine for continuing the program in various fashions.
3260 ADDR is the address to resume at, or -1 for resume where stopped.
3261 SIGGNAL is the signal to give it, or GDB_SIGNAL_0 for none,
3262 or GDB_SIGNAL_DEFAULT for act according to how it stopped.
3264 You should call clear_proceed_status before calling proceed. */
3267 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
)
3269 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
3271 struct regcache
*regcache
;
3272 struct gdbarch
*gdbarch
;
3275 /* If we're stopped at a fork/vfork, follow the branch set by the
3276 "set follow-fork-mode" command; otherwise, we'll just proceed
3277 resuming the current thread. */
3278 if (!follow_fork ())
3280 /* The target for some reason decided not to resume. */
3282 if (target_can_async_p ())
3283 inferior_event_handler (INF_EXEC_COMPLETE
);
3287 /* We'll update this if & when we switch to a new thread. */
3288 update_previous_thread ();
3290 regcache
= get_current_regcache ();
3291 gdbarch
= regcache
->arch ();
3292 const address_space
*aspace
= regcache
->aspace ();
3294 pc
= regcache_read_pc_protected (regcache
);
3296 thread_info
*cur_thr
= inferior_thread ();
3298 /* Fill in with reasonable starting values. */
3299 init_thread_stepping_state (cur_thr
);
3301 gdb_assert (!thread_is_in_step_over_chain (cur_thr
));
3304 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
3305 process_stratum_target
*resume_target
3306 = user_visible_resume_target (resume_ptid
);
3308 check_multi_target_resumption (resume_target
);
3310 if (addr
== (CORE_ADDR
) -1)
3312 if (cur_thr
->stop_pc_p ()
3313 && pc
== cur_thr
->stop_pc ()
3314 && breakpoint_here_p (aspace
, pc
) == ordinary_breakpoint_here
3315 && execution_direction
!= EXEC_REVERSE
)
3316 /* There is a breakpoint at the address we will resume at,
3317 step one instruction before inserting breakpoints so that
3318 we do not stop right away (and report a second hit at this
3321 Note, we don't do this in reverse, because we won't
3322 actually be executing the breakpoint insn anyway.
3323 We'll be (un-)executing the previous instruction. */
3324 cur_thr
->stepping_over_breakpoint
= 1;
3325 else if (gdbarch_single_step_through_delay_p (gdbarch
)
3326 && gdbarch_single_step_through_delay (gdbarch
,
3327 get_current_frame ()))
3328 /* We stepped onto an instruction that needs to be stepped
3329 again before re-inserting the breakpoint, do so. */
3330 cur_thr
->stepping_over_breakpoint
= 1;
3334 regcache_write_pc (regcache
, addr
);
3337 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
3338 cur_thr
->set_stop_signal (siggnal
);
3340 /* If an exception is thrown from this point on, make sure to
3341 propagate GDB's knowledge of the executing state to the
3342 frontend/user running state. */
3343 scoped_finish_thread_state
finish_state (resume_target
, resume_ptid
);
3345 /* Even if RESUME_PTID is a wildcard, and we end up resuming fewer
3346 threads (e.g., we might need to set threads stepping over
3347 breakpoints first), from the user/frontend's point of view, all
3348 threads in RESUME_PTID are now running. Unless we're calling an
3349 inferior function, as in that case we pretend the inferior
3350 doesn't run at all. */
3351 if (!cur_thr
->control
.in_infcall
)
3352 set_running (resume_target
, resume_ptid
, true);
3354 infrun_debug_printf ("addr=%s, signal=%s", paddress (gdbarch
, addr
),
3355 gdb_signal_to_symbol_string (siggnal
));
3357 annotate_starting ();
3359 /* Make sure that output from GDB appears before output from the
3361 gdb_flush (gdb_stdout
);
3363 /* Since we've marked the inferior running, give it the terminal. A
3364 QUIT/Ctrl-C from here on is forwarded to the target (which can
3365 still detect attempts to unblock a stuck connection with repeated
3366 Ctrl-C from within target_pass_ctrlc). */
3367 target_terminal::inferior ();
3369 /* In a multi-threaded task we may select another thread and
3370 then continue or step.
3372 But if a thread that we're resuming had stopped at a breakpoint,
3373 it will immediately cause another breakpoint stop without any
3374 execution (i.e. it will report a breakpoint hit incorrectly). So
3375 we must step over it first.
3377 Look for threads other than the current (TP) that reported a
3378 breakpoint hit and haven't been resumed yet since. */
3380 /* If scheduler locking applies, we can avoid iterating over all
3382 if (!non_stop
&& !schedlock_applies (cur_thr
))
3384 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3387 switch_to_thread_no_regs (tp
);
3389 /* Ignore the current thread here. It's handled
3394 if (!thread_still_needs_step_over (tp
))
3397 gdb_assert (!thread_is_in_step_over_chain (tp
));
3399 infrun_debug_printf ("need to step-over [%s] first",
3400 tp
->ptid
.to_string ().c_str ());
3402 global_thread_step_over_chain_enqueue (tp
);
3405 switch_to_thread (cur_thr
);
3408 /* Enqueue the current thread last, so that we move all other
3409 threads over their breakpoints first. */
3410 if (cur_thr
->stepping_over_breakpoint
)
3411 global_thread_step_over_chain_enqueue (cur_thr
);
3413 /* If the thread isn't started, we'll still need to set its prev_pc,
3414 so that switch_back_to_stepped_thread knows the thread hasn't
3415 advanced. Must do this before resuming any thread, as in
3416 all-stop/remote, once we resume we can't send any other packet
3417 until the target stops again. */
3418 cur_thr
->prev_pc
= regcache_read_pc_protected (regcache
);
3421 scoped_disable_commit_resumed
disable_commit_resumed ("proceeding");
3422 bool step_over_started
= start_step_over ();
3424 if (step_over_info_valid_p ())
3426 /* Either this thread started a new in-line step over, or some
3427 other thread was already doing one. In either case, don't
3428 resume anything else until the step-over is finished. */
3430 else if (step_over_started
&& !target_is_non_stop_p ())
3432 /* A new displaced stepping sequence was started. In all-stop,
3433 we can't talk to the target anymore until it next stops. */
3435 else if (!non_stop
&& target_is_non_stop_p ())
3437 INFRUN_SCOPED_DEBUG_START_END
3438 ("resuming threads, all-stop-on-top-of-non-stop");
3440 /* In all-stop, but the target is always in non-stop mode.
3441 Start all other threads that are implicitly resumed too. */
3442 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3445 switch_to_thread_no_regs (tp
);
3447 if (!tp
->inf
->has_execution ())
3449 infrun_debug_printf ("[%s] target has no execution",
3450 tp
->ptid
.to_string ().c_str ());
3456 infrun_debug_printf ("[%s] resumed",
3457 tp
->ptid
.to_string ().c_str ());
3458 gdb_assert (tp
->executing () || tp
->has_pending_waitstatus ());
3462 if (thread_is_in_step_over_chain (tp
))
3464 infrun_debug_printf ("[%s] needs step-over",
3465 tp
->ptid
.to_string ().c_str ());
3469 /* If a thread of that inferior is waiting for a vfork-done
3470 (for a detached vfork child to exec or exit), breakpoints are
3471 removed. We must not resume any thread of that inferior, other
3472 than the one waiting for the vfork-done. */
3473 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr
3474 && tp
!= tp
->inf
->thread_waiting_for_vfork_done
)
3476 infrun_debug_printf ("[%s] another thread of this inferior is "
3477 "waiting for vfork-done",
3478 tp
->ptid
.to_string ().c_str ());
3482 infrun_debug_printf ("resuming %s",
3483 tp
->ptid
.to_string ().c_str ());
3485 execution_control_state
ecs (tp
);
3486 switch_to_thread (tp
);
3487 keep_going_pass_signal (&ecs
);
3488 if (!ecs
.wait_some_more
)
3489 error (_("Command aborted."));
3492 else if (!cur_thr
->resumed ()
3493 && !thread_is_in_step_over_chain (cur_thr
)
3494 /* In non-stop, forbid resuming a thread if some other thread of
3495 that inferior is waiting for a vfork-done event (this means
3496 breakpoints are out for this inferior). */
3498 && cur_thr
->inf
->thread_waiting_for_vfork_done
!= nullptr))
3500 /* The thread wasn't started, and isn't queued, run it now. */
3501 execution_control_state
ecs (cur_thr
);
3502 switch_to_thread (cur_thr
);
3503 keep_going_pass_signal (&ecs
);
3504 if (!ecs
.wait_some_more
)
3505 error (_("Command aborted."));
3508 disable_commit_resumed
.reset_and_commit ();
3511 finish_state
.release ();
3513 /* If we've switched threads above, switch back to the previously
3514 current thread. We don't want the user to see a different
3516 switch_to_thread (cur_thr
);
3518 /* Tell the event loop to wait for it to stop. If the target
3519 supports asynchronous execution, it'll do this from within
3521 if (!target_can_async_p ())
3522 mark_async_event_handler (infrun_async_inferior_event_token
);
3526 /* Start remote-debugging of a machine over a serial link. */
3529 start_remote (int from_tty
)
3531 inferior
*inf
= current_inferior ();
3532 inf
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
3534 /* Always go on waiting for the target, regardless of the mode. */
3535 /* FIXME: cagney/1999-09-23: At present it isn't possible to
3536 indicate to wait_for_inferior that a target should timeout if
3537 nothing is returned (instead of just blocking). Because of this,
3538 targets expecting an immediate response need to, internally, set
3539 things up so that the target_wait() is forced to eventually
3541 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
3542 differentiate to its caller what the state of the target is after
3543 the initial open has been performed. Here we're assuming that
3544 the target has stopped. It should be possible to eventually have
3545 target_open() return to the caller an indication that the target
3546 is currently running and GDB state should be set to the same as
3547 for an async run. */
3548 wait_for_inferior (inf
);
3550 /* Now that the inferior has stopped, do any bookkeeping like
3551 loading shared libraries. We want to do this before normal_stop,
3552 so that the displayed frame is up to date. */
3553 post_create_inferior (from_tty
);
3558 /* Initialize static vars when a new inferior begins. */
3561 init_wait_for_inferior (void)
3563 /* These are meaningless until the first time through wait_for_inferior. */
3565 breakpoint_init_inferior (inf_starting
);
3567 clear_proceed_status (0);
3569 nullify_last_target_wait_ptid ();
3571 update_previous_thread ();
3576 static void handle_inferior_event (struct execution_control_state
*ecs
);
3578 static void handle_step_into_function (struct gdbarch
*gdbarch
,
3579 struct execution_control_state
*ecs
);
3580 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
3581 struct execution_control_state
*ecs
);
3582 static void handle_signal_stop (struct execution_control_state
*ecs
);
3583 static void check_exception_resume (struct execution_control_state
*,
3586 static void end_stepping_range (struct execution_control_state
*ecs
);
3587 static void stop_waiting (struct execution_control_state
*ecs
);
3588 static void keep_going (struct execution_control_state
*ecs
);
3589 static void process_event_stop_test (struct execution_control_state
*ecs
);
3590 static bool switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
3592 /* This function is attached as a "thread_stop_requested" observer.
3593 Cleanup local state that assumed the PTID was to be resumed, and
3594 report the stop to the frontend. */
3597 infrun_thread_stop_requested (ptid_t ptid
)
3599 process_stratum_target
*curr_target
= current_inferior ()->process_target ();
3601 /* PTID was requested to stop. If the thread was already stopped,
3602 but the user/frontend doesn't know about that yet (e.g., the
3603 thread had been temporarily paused for some step-over), set up
3604 for reporting the stop now. */
3605 for (thread_info
*tp
: all_threads (curr_target
, ptid
))
3607 if (tp
->state
!= THREAD_RUNNING
)
3609 if (tp
->executing ())
3612 /* Remove matching threads from the step-over queue, so
3613 start_step_over doesn't try to resume them
3615 if (thread_is_in_step_over_chain (tp
))
3616 global_thread_step_over_chain_remove (tp
);
3618 /* If the thread is stopped, but the user/frontend doesn't
3619 know about that yet, queue a pending event, as if the
3620 thread had just stopped now. Unless the thread already had
3622 if (!tp
->has_pending_waitstatus ())
3624 target_waitstatus ws
;
3625 ws
.set_stopped (GDB_SIGNAL_0
);
3626 tp
->set_pending_waitstatus (ws
);
3629 /* Clear the inline-frame state, since we're re-processing the
3631 clear_inline_frame_state (tp
);
3633 /* If this thread was paused because some other thread was
3634 doing an inline-step over, let that finish first. Once
3635 that happens, we'll restart all threads and consume pending
3636 stop events then. */
3637 if (step_over_info_valid_p ())
3640 /* Otherwise we can process the (new) pending event now. Set
3641 it so this pending event is considered by
3643 tp
->set_resumed (true);
3647 /* Delete the step resume, single-step and longjmp/exception resume
3648 breakpoints of TP. */
3651 delete_thread_infrun_breakpoints (struct thread_info
*tp
)
3653 delete_step_resume_breakpoint (tp
);
3654 delete_exception_resume_breakpoint (tp
);
3655 delete_single_step_breakpoints (tp
);
3658 /* If the target still has execution, call FUNC for each thread that
3659 just stopped. In all-stop, that's all the non-exited threads; in
3660 non-stop, that's the current thread, only. */
3662 typedef void (*for_each_just_stopped_thread_callback_func
)
3663 (struct thread_info
*tp
);
3666 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func
)
3668 if (!target_has_execution () || inferior_ptid
== null_ptid
)
3671 if (target_is_non_stop_p ())
3673 /* If in non-stop mode, only the current thread stopped. */
3674 func (inferior_thread ());
3678 /* In all-stop mode, all threads have stopped. */
3679 for (thread_info
*tp
: all_non_exited_threads ())
3684 /* Delete the step resume and longjmp/exception resume breakpoints of
3685 the threads that just stopped. */
3688 delete_just_stopped_threads_infrun_breakpoints (void)
3690 for_each_just_stopped_thread (delete_thread_infrun_breakpoints
);
3693 /* Delete the single-step breakpoints of the threads that just
3697 delete_just_stopped_threads_single_step_breakpoints (void)
3699 for_each_just_stopped_thread (delete_single_step_breakpoints
);
3705 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
3706 const struct target_waitstatus
&ws
)
3708 infrun_debug_printf ("target_wait (%s [%s], status) =",
3709 waiton_ptid
.to_string ().c_str (),
3710 target_pid_to_str (waiton_ptid
).c_str ());
3711 infrun_debug_printf (" %s [%s],",
3712 result_ptid
.to_string ().c_str (),
3713 target_pid_to_str (result_ptid
).c_str ());
3714 infrun_debug_printf (" %s", ws
.to_string ().c_str ());
3717 /* Select a thread at random, out of those which are resumed and have
3720 static struct thread_info
*
3721 random_pending_event_thread (inferior
*inf
, ptid_t waiton_ptid
)
3723 process_stratum_target
*proc_target
= inf
->process_target ();
3725 = proc_target
->random_resumed_with_pending_wait_status (inf
, waiton_ptid
);
3727 if (thread
== nullptr)
3729 infrun_debug_printf ("None found.");
3733 infrun_debug_printf ("Found %s.", thread
->ptid
.to_string ().c_str ());
3734 gdb_assert (thread
->resumed ());
3735 gdb_assert (thread
->has_pending_waitstatus ());
3740 /* Wrapper for target_wait that first checks whether threads have
3741 pending statuses to report before actually asking the target for
3742 more events. INF is the inferior we're using to call target_wait
3746 do_target_wait_1 (inferior
*inf
, ptid_t ptid
,
3747 target_waitstatus
*status
, target_wait_flags options
)
3749 struct thread_info
*tp
;
3751 /* We know that we are looking for an event in the target of inferior
3752 INF, but we don't know which thread the event might come from. As
3753 such we want to make sure that INFERIOR_PTID is reset so that none of
3754 the wait code relies on it - doing so is always a mistake. */
3755 switch_to_inferior_no_thread (inf
);
3757 /* First check if there is a resumed thread with a wait status
3759 if (ptid
== minus_one_ptid
|| ptid
.is_pid ())
3761 tp
= random_pending_event_thread (inf
, ptid
);
3765 infrun_debug_printf ("Waiting for specific thread %s.",
3766 ptid
.to_string ().c_str ());
3768 /* We have a specific thread to check. */
3769 tp
= inf
->find_thread (ptid
);
3770 gdb_assert (tp
!= nullptr);
3771 if (!tp
->has_pending_waitstatus ())
3776 && (tp
->stop_reason () == TARGET_STOPPED_BY_SW_BREAKPOINT
3777 || tp
->stop_reason () == TARGET_STOPPED_BY_HW_BREAKPOINT
))
3779 struct regcache
*regcache
= get_thread_regcache (tp
);
3780 struct gdbarch
*gdbarch
= regcache
->arch ();
3784 pc
= regcache_read_pc (regcache
);
3786 if (pc
!= tp
->stop_pc ())
3788 infrun_debug_printf ("PC of %s changed. was=%s, now=%s",
3789 tp
->ptid
.to_string ().c_str (),
3790 paddress (gdbarch
, tp
->stop_pc ()),
3791 paddress (gdbarch
, pc
));
3794 else if (!breakpoint_inserted_here_p (regcache
->aspace (), pc
))
3796 infrun_debug_printf ("previous breakpoint of %s, at %s gone",
3797 tp
->ptid
.to_string ().c_str (),
3798 paddress (gdbarch
, pc
));
3805 infrun_debug_printf ("pending event of %s cancelled.",
3806 tp
->ptid
.to_string ().c_str ());
3808 tp
->clear_pending_waitstatus ();
3809 target_waitstatus ws
;
3811 tp
->set_pending_waitstatus (ws
);
3812 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
3818 infrun_debug_printf ("Using pending wait status %s for %s.",
3819 tp
->pending_waitstatus ().to_string ().c_str (),
3820 tp
->ptid
.to_string ().c_str ());
3822 /* Now that we've selected our final event LWP, un-adjust its PC
3823 if it was a software breakpoint (and the target doesn't
3824 always adjust the PC itself). */
3825 if (tp
->stop_reason () == TARGET_STOPPED_BY_SW_BREAKPOINT
3826 && !target_supports_stopped_by_sw_breakpoint ())
3828 struct regcache
*regcache
;
3829 struct gdbarch
*gdbarch
;
3832 regcache
= get_thread_regcache (tp
);
3833 gdbarch
= regcache
->arch ();
3835 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
3840 pc
= regcache_read_pc (regcache
);
3841 regcache_write_pc (regcache
, pc
+ decr_pc
);
3845 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
3846 *status
= tp
->pending_waitstatus ();
3847 tp
->clear_pending_waitstatus ();
3849 /* Wake up the event loop again, until all pending events are
3851 if (target_is_async_p ())
3852 mark_async_event_handler (infrun_async_inferior_event_token
);
3856 /* But if we don't find one, we'll have to wait. */
3858 /* We can't ask a non-async target to do a non-blocking wait, so this will be
3860 if (!target_can_async_p ())
3861 options
&= ~TARGET_WNOHANG
;
3863 return target_wait (ptid
, status
, options
);
3866 /* Wrapper for target_wait that first checks whether threads have
3867 pending statuses to report before actually asking the target for
3868 more events. Polls for events from all inferiors/targets. */
3871 do_target_wait (execution_control_state
*ecs
, target_wait_flags options
)
3873 int num_inferiors
= 0;
3874 int random_selector
;
3876 /* For fairness, we pick the first inferior/target to poll at random
3877 out of all inferiors that may report events, and then continue
3878 polling the rest of the inferior list starting from that one in a
3879 circular fashion until the whole list is polled once. */
3881 auto inferior_matches
= [] (inferior
*inf
)
3883 return inf
->process_target () != nullptr;
3886 /* First see how many matching inferiors we have. */
3887 for (inferior
*inf
: all_inferiors ())
3888 if (inferior_matches (inf
))
3891 if (num_inferiors
== 0)
3893 ecs
->ws
.set_ignore ();
3897 /* Now randomly pick an inferior out of those that matched. */
3898 random_selector
= (int)
3899 ((num_inferiors
* (double) rand ()) / (RAND_MAX
+ 1.0));
3901 if (num_inferiors
> 1)
3902 infrun_debug_printf ("Found %d inferiors, starting at #%d",
3903 num_inferiors
, random_selector
);
3905 /* Select the Nth inferior that matched. */
3907 inferior
*selected
= nullptr;
3909 for (inferior
*inf
: all_inferiors ())
3910 if (inferior_matches (inf
))
3911 if (random_selector
-- == 0)
3917 /* Now poll for events out of each of the matching inferior's
3918 targets, starting from the selected one. */
3920 auto do_wait
= [&] (inferior
*inf
)
3922 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, options
);
3923 ecs
->target
= inf
->process_target ();
3924 return (ecs
->ws
.kind () != TARGET_WAITKIND_IGNORE
);
3927 /* Needed in 'all-stop + target-non-stop' mode, because we end up
3928 here spuriously after the target is all stopped and we've already
3929 reported the stop to the user, polling for events. */
3930 scoped_restore_current_thread restore_thread
;
3932 intrusive_list_iterator
<inferior
> start
3933 = inferior_list
.iterator_to (*selected
);
3935 for (intrusive_list_iterator
<inferior
> it
= start
;
3936 it
!= inferior_list
.end ();
3939 inferior
*inf
= &*it
;
3941 if (inferior_matches (inf
) && do_wait (inf
))
3945 for (intrusive_list_iterator
<inferior
> it
= inferior_list
.begin ();
3949 inferior
*inf
= &*it
;
3951 if (inferior_matches (inf
) && do_wait (inf
))
3955 ecs
->ws
.set_ignore ();
3959 /* An event reported by wait_one. */
3961 struct wait_one_event
3963 /* The target the event came out of. */
3964 process_stratum_target
*target
;
3966 /* The PTID the event was for. */
3969 /* The waitstatus. */
3970 target_waitstatus ws
;
3973 static bool handle_one (const wait_one_event
&event
);
3975 /* Prepare and stabilize the inferior for detaching it. E.g.,
3976 detaching while a thread is displaced stepping is a recipe for
3977 crashing it, as nothing would readjust the PC out of the scratch
3981 prepare_for_detach (void)
3983 struct inferior
*inf
= current_inferior ();
3984 ptid_t pid_ptid
= ptid_t (inf
->pid
);
3985 scoped_restore_current_thread restore_thread
;
3987 scoped_restore restore_detaching
= make_scoped_restore (&inf
->detaching
, true);
3989 /* Remove all threads of INF from the global step-over chain. We
3990 want to stop any ongoing step-over, not start any new one. */
3991 thread_step_over_list_safe_range range
3992 = make_thread_step_over_list_safe_range (global_thread_step_over_list
);
3994 for (thread_info
*tp
: range
)
3997 infrun_debug_printf ("removing thread %s from global step over chain",
3998 tp
->ptid
.to_string ().c_str ());
3999 global_thread_step_over_chain_remove (tp
);
4002 /* If we were already in the middle of an inline step-over, and the
4003 thread stepping belongs to the inferior we're detaching, we need
4004 to restart the threads of other inferiors. */
4005 if (step_over_info
.thread
!= -1)
4007 infrun_debug_printf ("inline step-over in-process while detaching");
4009 thread_info
*thr
= find_thread_global_id (step_over_info
.thread
);
4010 if (thr
->inf
== inf
)
4012 /* Since we removed threads of INF from the step-over chain,
4013 we know this won't start a step-over for INF. */
4014 clear_step_over_info ();
4016 if (target_is_non_stop_p ())
4018 /* Start a new step-over in another thread if there's
4019 one that needs it. */
4022 /* Restart all other threads (except the
4023 previously-stepping thread, since that one is still
4025 if (!step_over_info_valid_p ())
4026 restart_threads (thr
);
4031 if (displaced_step_in_progress (inf
))
4033 infrun_debug_printf ("displaced-stepping in-process while detaching");
4035 /* Stop threads currently displaced stepping, aborting it. */
4037 for (thread_info
*thr
: inf
->non_exited_threads ())
4039 if (thr
->displaced_step_state
.in_progress ())
4041 if (thr
->executing ())
4043 if (!thr
->stop_requested
)
4045 target_stop (thr
->ptid
);
4046 thr
->stop_requested
= true;
4050 thr
->set_resumed (false);
4054 while (displaced_step_in_progress (inf
))
4056 wait_one_event event
;
4058 event
.target
= inf
->process_target ();
4059 event
.ptid
= do_target_wait_1 (inf
, pid_ptid
, &event
.ws
, 0);
4062 print_target_wait_results (pid_ptid
, event
.ptid
, event
.ws
);
4067 /* It's OK to leave some of the threads of INF stopped, since
4068 they'll be detached shortly. */
4072 /* If all-stop, but there exists a non-stop target, stop all threads
4073 now that we're presenting the stop to the user. */
4076 stop_all_threads_if_all_stop_mode ()
4078 if (!non_stop
&& exists_non_stop_target ())
4079 stop_all_threads ("presenting stop to user in all-stop");
4082 /* Wait for control to return from inferior to debugger.
4084 If inferior gets a signal, we may decide to start it up again
4085 instead of returning. That is why there is a loop in this function.
4086 When this function actually returns it means the inferior
4087 should be left stopped and GDB should read more commands. */
4090 wait_for_inferior (inferior
*inf
)
4092 infrun_debug_printf ("wait_for_inferior ()");
4094 SCOPE_EXIT
{ delete_just_stopped_threads_infrun_breakpoints (); };
4096 /* If an error happens while handling the event, propagate GDB's
4097 knowledge of the executing state to the frontend/user running
4099 scoped_finish_thread_state finish_state
4100 (inf
->process_target (), minus_one_ptid
);
4104 execution_control_state ecs
;
4106 overlay_cache_invalid
= 1;
4108 /* Flush target cache before starting to handle each event.
4109 Target was running and cache could be stale. This is just a
4110 heuristic. Running threads may modify target memory, but we
4111 don't get any event. */
4112 target_dcache_invalidate ();
4114 ecs
.ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
.ws
, 0);
4115 ecs
.target
= inf
->process_target ();
4118 print_target_wait_results (minus_one_ptid
, ecs
.ptid
, ecs
.ws
);
4120 /* Now figure out what to do with the result of the result. */
4121 handle_inferior_event (&ecs
);
4123 if (!ecs
.wait_some_more
)
4127 stop_all_threads_if_all_stop_mode ();
4129 /* No error, don't finish the state yet. */
4130 finish_state
.release ();
4133 /* Cleanup that reinstalls the readline callback handler, if the
4134 target is running in the background. If while handling the target
4135 event something triggered a secondary prompt, like e.g., a
4136 pagination prompt, we'll have removed the callback handler (see
4137 gdb_readline_wrapper_line). Need to do this as we go back to the
4138 event loop, ready to process further input. Note this has no
4139 effect if the handler hasn't actually been removed, because calling
4140 rl_callback_handler_install resets the line buffer, thus losing
4144 reinstall_readline_callback_handler_cleanup ()
4146 struct ui
*ui
= current_ui
;
4150 /* We're not going back to the top level event loop yet. Don't
4151 install the readline callback, as it'd prep the terminal,
4152 readline-style (raw, noecho) (e.g., --batch). We'll install
4153 it the next time the prompt is displayed, when we're ready
4158 if (ui
->command_editing
&& ui
->prompt_state
!= PROMPT_BLOCKED
)
4159 gdb_rl_callback_handler_reinstall ();
4162 /* Clean up the FSMs of threads that are now stopped. In non-stop,
4163 that's just the event thread. In all-stop, that's all threads. */
4166 clean_up_just_stopped_threads_fsms (struct execution_control_state
*ecs
)
4168 /* The first clean_up call below assumes the event thread is the current
4170 if (ecs
->event_thread
!= nullptr)
4171 gdb_assert (ecs
->event_thread
== inferior_thread ());
4173 if (ecs
->event_thread
!= nullptr
4174 && ecs
->event_thread
->thread_fsm () != nullptr)
4175 ecs
->event_thread
->thread_fsm ()->clean_up (ecs
->event_thread
);
4179 scoped_restore_current_thread restore_thread
;
4181 for (thread_info
*thr
: all_non_exited_threads ())
4183 if (thr
->thread_fsm () == nullptr)
4185 if (thr
== ecs
->event_thread
)
4188 switch_to_thread (thr
);
4189 thr
->thread_fsm ()->clean_up (thr
);
4194 /* Helper for all_uis_check_sync_execution_done that works on the
4198 check_curr_ui_sync_execution_done (void)
4200 struct ui
*ui
= current_ui
;
4202 if (ui
->prompt_state
== PROMPT_NEEDED
4204 && !gdb_in_secondary_prompt_p (ui
))
4206 target_terminal::ours ();
4207 gdb::observers::sync_execution_done
.notify ();
4208 ui
->register_file_handler ();
4215 all_uis_check_sync_execution_done (void)
4217 SWITCH_THRU_ALL_UIS ()
4219 check_curr_ui_sync_execution_done ();
4226 all_uis_on_sync_execution_starting (void)
4228 SWITCH_THRU_ALL_UIS ()
4230 if (current_ui
->prompt_state
== PROMPT_NEEDED
)
4231 async_disable_stdin ();
4235 /* A quit_handler callback installed while we're handling inferior
4239 infrun_quit_handler ()
4241 if (target_terminal::is_ours ())
4245 default_quit_handler would throw a quit in this case, but if
4246 we're handling an event while we have the terminal, it means
4247 the target is running a background execution command, and
4248 thus when users press Ctrl-C, they're wanting to interrupt
4249 whatever command they were executing in the command line.
4253 (gdb) foo bar whatever<ctrl-c>
4255 That Ctrl-C should clear the input line, not interrupt event
4256 handling if it happens that the user types Ctrl-C at just the
4259 It's as-if background event handling was handled by a
4260 separate background thread.
4262 To be clear, the Ctrl-C is not lost -- it will be processed
4263 by the next QUIT call once we're out of fetch_inferior_event
4268 if (check_quit_flag ())
4269 target_pass_ctrlc ();
4273 /* Asynchronous version of wait_for_inferior. It is called by the
4274 event loop whenever a change of state is detected on the file
4275 descriptor corresponding to the target. It can be called more than
4276 once to complete a single execution command. In such cases we need
4277 to keep the state in a global variable ECSS. If it is the last time
4278 that this function is called for a single execution command, then
4279 report to the user that the inferior has stopped, and do the
4280 necessary cleanups. */
4283 fetch_inferior_event ()
4285 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
4287 execution_control_state ecs
;
4290 /* Events are always processed with the main UI as current UI. This
4291 way, warnings, debug output, etc. are always consistently sent to
4292 the main console. */
4293 scoped_restore save_ui
= make_scoped_restore (¤t_ui
, main_ui
);
4295 /* Temporarily disable pagination. Otherwise, the user would be
4296 given an option to press 'q' to quit, which would cause an early
4297 exit and could leave GDB in a half-baked state. */
4298 scoped_restore save_pagination
4299 = make_scoped_restore (&pagination_enabled
, false);
4301 /* Install a quit handler that does nothing if we have the terminal
4302 (meaning the target is running a background execution command),
4303 so that Ctrl-C never interrupts GDB before the event is fully
4305 scoped_restore restore_quit_handler
4306 = make_scoped_restore (&quit_handler
, infrun_quit_handler
);
4308 /* Make sure a SIGINT does not interrupt an extension language while
4309 we're handling an event. That could interrupt a Python unwinder
4310 or a Python observer or some such. A Ctrl-C should either be
4311 forwarded to the inferior if the inferior has the terminal, or,
4312 if GDB has the terminal, should interrupt the command the user is
4313 typing in the CLI. */
4314 scoped_disable_cooperative_sigint_handling restore_coop_sigint
;
4316 /* End up with readline processing input, if necessary. */
4318 SCOPE_EXIT
{ reinstall_readline_callback_handler_cleanup (); };
4320 /* We're handling a live event, so make sure we're doing live
4321 debugging. If we're looking at traceframes while the target is
4322 running, we're going to need to get back to that mode after
4323 handling the event. */
4324 gdb::optional
<scoped_restore_current_traceframe
> maybe_restore_traceframe
;
4327 maybe_restore_traceframe
.emplace ();
4328 set_current_traceframe (-1);
4331 /* The user/frontend should not notice a thread switch due to
4332 internal events. Make sure we revert to the user selected
4333 thread and frame after handling the event and running any
4334 breakpoint commands. */
4335 scoped_restore_current_thread restore_thread
;
4337 overlay_cache_invalid
= 1;
4338 /* Flush target cache before starting to handle each event. Target
4339 was running and cache could be stale. This is just a heuristic.
4340 Running threads may modify target memory, but we don't get any
4342 target_dcache_invalidate ();
4344 scoped_restore save_exec_dir
4345 = make_scoped_restore (&execution_direction
,
4346 target_execution_direction ());
4348 /* Allow targets to pause their resumed threads while we handle
4350 scoped_disable_commit_resumed
disable_commit_resumed ("handling event");
4352 if (!do_target_wait (&ecs
, TARGET_WNOHANG
))
4354 infrun_debug_printf ("do_target_wait returned no event");
4355 disable_commit_resumed
.reset_and_commit ();
4359 gdb_assert (ecs
.ws
.kind () != TARGET_WAITKIND_IGNORE
);
4361 /* Switch to the inferior that generated the event, so we can do
4362 target calls. If the event was not associated to a ptid, */
4363 if (ecs
.ptid
!= null_ptid
4364 && ecs
.ptid
!= minus_one_ptid
)
4365 switch_to_inferior_no_thread (find_inferior_ptid (ecs
.target
, ecs
.ptid
));
4367 switch_to_target_no_thread (ecs
.target
);
4370 print_target_wait_results (minus_one_ptid
, ecs
.ptid
, ecs
.ws
);
4372 /* If an error happens while handling the event, propagate GDB's
4373 knowledge of the executing state to the frontend/user running
4375 ptid_t finish_ptid
= !target_is_non_stop_p () ? minus_one_ptid
: ecs
.ptid
;
4376 scoped_finish_thread_state
finish_state (ecs
.target
, finish_ptid
);
4378 /* Get executed before scoped_restore_current_thread above to apply
4379 still for the thread which has thrown the exception. */
4380 auto defer_bpstat_clear
4381 = make_scope_exit (bpstat_clear_actions
);
4382 auto defer_delete_threads
4383 = make_scope_exit (delete_just_stopped_threads_infrun_breakpoints
);
4385 /* Now figure out what to do with the result of the result. */
4386 handle_inferior_event (&ecs
);
4388 if (!ecs
.wait_some_more
)
4390 struct inferior
*inf
= find_inferior_ptid (ecs
.target
, ecs
.ptid
);
4391 bool should_stop
= true;
4392 struct thread_info
*thr
= ecs
.event_thread
;
4394 delete_just_stopped_threads_infrun_breakpoints ();
4396 if (thr
!= nullptr && thr
->thread_fsm () != nullptr)
4397 should_stop
= thr
->thread_fsm ()->should_stop (thr
);
4405 bool should_notify_stop
= true;
4406 bool proceeded
= false;
4408 stop_all_threads_if_all_stop_mode ();
4410 clean_up_just_stopped_threads_fsms (&ecs
);
4412 if (thr
!= nullptr && thr
->thread_fsm () != nullptr)
4414 = thr
->thread_fsm ()->should_notify_stop ();
4416 if (should_notify_stop
)
4418 /* We may not find an inferior if this was a process exit. */
4419 if (inf
== nullptr || inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
4420 proceeded
= normal_stop ();
4425 inferior_event_handler (INF_EXEC_COMPLETE
);
4429 /* If we got a TARGET_WAITKIND_NO_RESUMED event, then the
4430 previously selected thread is gone. We have two
4431 choices - switch to no thread selected, or restore the
4432 previously selected thread (now exited). We chose the
4433 later, just because that's what GDB used to do. After
4434 this, "info threads" says "The current thread <Thread
4435 ID 2> has terminated." instead of "No thread
4439 && ecs
.ws
.kind () != TARGET_WAITKIND_NO_RESUMED
)
4440 restore_thread
.dont_restore ();
4444 defer_delete_threads
.release ();
4445 defer_bpstat_clear
.release ();
4447 /* No error, don't finish the thread states yet. */
4448 finish_state
.release ();
4450 disable_commit_resumed
.reset_and_commit ();
4452 /* This scope is used to ensure that readline callbacks are
4453 reinstalled here. */
4456 /* Handling this event might have caused some inferiors to become prunable.
4457 For example, the exit of an inferior that was automatically added. Try
4458 to get rid of them. Keeping those around slows down things linearly.
4460 Note that this never removes the current inferior. Therefore, call this
4461 after RESTORE_THREAD went out of scope, in case the event inferior (which was
4462 temporarily made the current inferior) is meant to be deleted.
4464 Call this before all_uis_check_sync_execution_done, so that notifications about
4465 removed inferiors appear before the prompt. */
4468 /* If a UI was in sync execution mode, and now isn't, restore its
4469 prompt (a synchronous execution command has finished, and we're
4470 ready for input). */
4471 all_uis_check_sync_execution_done ();
4474 && exec_done_display_p
4475 && (inferior_ptid
== null_ptid
4476 || inferior_thread ()->state
!= THREAD_RUNNING
))
4477 gdb_printf (_("completed.\n"));
4483 set_step_info (thread_info
*tp
, frame_info_ptr frame
,
4484 struct symtab_and_line sal
)
4486 /* This can be removed once this function no longer implicitly relies on the
4487 inferior_ptid value. */
4488 gdb_assert (inferior_ptid
== tp
->ptid
);
4490 tp
->control
.step_frame_id
= get_frame_id (frame
);
4491 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
4493 tp
->current_symtab
= sal
.symtab
;
4494 tp
->current_line
= sal
.line
;
4497 ("symtab = %s, line = %d, step_frame_id = %s, step_stack_frame_id = %s",
4498 tp
->current_symtab
!= nullptr ? tp
->current_symtab
->filename
: "<null>",
4500 tp
->control
.step_frame_id
.to_string ().c_str (),
4501 tp
->control
.step_stack_frame_id
.to_string ().c_str ());
4504 /* Clear context switchable stepping state. */
4507 init_thread_stepping_state (struct thread_info
*tss
)
4509 tss
->stepped_breakpoint
= 0;
4510 tss
->stepping_over_breakpoint
= 0;
4511 tss
->stepping_over_watchpoint
= 0;
4512 tss
->step_after_step_resume_breakpoint
= 0;
4518 set_last_target_status (process_stratum_target
*target
, ptid_t ptid
,
4519 const target_waitstatus
&status
)
4521 target_last_proc_target
= target
;
4522 target_last_wait_ptid
= ptid
;
4523 target_last_waitstatus
= status
;
4529 get_last_target_status (process_stratum_target
**target
, ptid_t
*ptid
,
4530 target_waitstatus
*status
)
4532 if (target
!= nullptr)
4533 *target
= target_last_proc_target
;
4534 if (ptid
!= nullptr)
4535 *ptid
= target_last_wait_ptid
;
4536 if (status
!= nullptr)
4537 *status
= target_last_waitstatus
;
4543 nullify_last_target_wait_ptid (void)
4545 target_last_proc_target
= nullptr;
4546 target_last_wait_ptid
= minus_one_ptid
;
4547 target_last_waitstatus
= {};
4550 /* Switch thread contexts. */
4553 context_switch (execution_control_state
*ecs
)
4555 if (ecs
->ptid
!= inferior_ptid
4556 && (inferior_ptid
== null_ptid
4557 || ecs
->event_thread
!= inferior_thread ()))
4559 infrun_debug_printf ("Switching context from %s to %s",
4560 inferior_ptid
.to_string ().c_str (),
4561 ecs
->ptid
.to_string ().c_str ());
4564 switch_to_thread (ecs
->event_thread
);
4567 /* If the target can't tell whether we've hit breakpoints
4568 (target_supports_stopped_by_sw_breakpoint), and we got a SIGTRAP,
4569 check whether that could have been caused by a breakpoint. If so,
4570 adjust the PC, per gdbarch_decr_pc_after_break. */
4573 adjust_pc_after_break (struct thread_info
*thread
,
4574 const target_waitstatus
&ws
)
4576 struct regcache
*regcache
;
4577 struct gdbarch
*gdbarch
;
4578 CORE_ADDR breakpoint_pc
, decr_pc
;
4580 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
4581 we aren't, just return.
4583 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
4584 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
4585 implemented by software breakpoints should be handled through the normal
4588 NOTE drow/2004-01-31: On some targets, breakpoints may generate
4589 different signals (SIGILL or SIGEMT for instance), but it is less
4590 clear where the PC is pointing afterwards. It may not match
4591 gdbarch_decr_pc_after_break. I don't know any specific target that
4592 generates these signals at breakpoints (the code has been in GDB since at
4593 least 1992) so I can not guess how to handle them here.
4595 In earlier versions of GDB, a target with
4596 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
4597 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
4598 target with both of these set in GDB history, and it seems unlikely to be
4599 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
4601 if (ws
.kind () != TARGET_WAITKIND_STOPPED
)
4604 if (ws
.sig () != GDB_SIGNAL_TRAP
)
4607 /* In reverse execution, when a breakpoint is hit, the instruction
4608 under it has already been de-executed. The reported PC always
4609 points at the breakpoint address, so adjusting it further would
4610 be wrong. E.g., consider this case on a decr_pc_after_break == 1
4613 B1 0x08000000 : INSN1
4614 B2 0x08000001 : INSN2
4616 PC -> 0x08000003 : INSN4
4618 Say you're stopped at 0x08000003 as above. Reverse continuing
4619 from that point should hit B2 as below. Reading the PC when the
4620 SIGTRAP is reported should read 0x08000001 and INSN2 should have
4621 been de-executed already.
4623 B1 0x08000000 : INSN1
4624 B2 PC -> 0x08000001 : INSN2
4628 We can't apply the same logic as for forward execution, because
4629 we would wrongly adjust the PC to 0x08000000, since there's a
4630 breakpoint at PC - 1. We'd then report a hit on B1, although
4631 INSN1 hadn't been de-executed yet. Doing nothing is the correct
4633 if (execution_direction
== EXEC_REVERSE
)
4636 /* If the target can tell whether the thread hit a SW breakpoint,
4637 trust it. Targets that can tell also adjust the PC
4639 if (target_supports_stopped_by_sw_breakpoint ())
4642 /* Note that relying on whether a breakpoint is planted in memory to
4643 determine this can fail. E.g,. the breakpoint could have been
4644 removed since. Or the thread could have been told to step an
4645 instruction the size of a breakpoint instruction, and only
4646 _after_ was a breakpoint inserted at its address. */
4648 /* If this target does not decrement the PC after breakpoints, then
4649 we have nothing to do. */
4650 regcache
= get_thread_regcache (thread
);
4651 gdbarch
= regcache
->arch ();
4653 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4657 const address_space
*aspace
= regcache
->aspace ();
4659 /* Find the location where (if we've hit a breakpoint) the
4660 breakpoint would be. */
4661 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
4663 /* If the target can't tell whether a software breakpoint triggered,
4664 fallback to figuring it out based on breakpoints we think were
4665 inserted in the target, and on whether the thread was stepped or
4668 /* Check whether there actually is a software breakpoint inserted at
4671 If in non-stop mode, a race condition is possible where we've
4672 removed a breakpoint, but stop events for that breakpoint were
4673 already queued and arrive later. To suppress those spurious
4674 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
4675 and retire them after a number of stop events are reported. Note
4676 this is an heuristic and can thus get confused. The real fix is
4677 to get the "stopped by SW BP and needs adjustment" info out of
4678 the target/kernel (and thus never reach here; see above). */
4679 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
4680 || (target_is_non_stop_p ()
4681 && moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
4683 gdb::optional
<scoped_restore_tmpl
<int>> restore_operation_disable
;
4685 if (record_full_is_used ())
4686 restore_operation_disable
.emplace
4687 (record_full_gdb_operation_disable_set ());
4689 /* When using hardware single-step, a SIGTRAP is reported for both
4690 a completed single-step and a software breakpoint. Need to
4691 differentiate between the two, as the latter needs adjusting
4692 but the former does not.
4694 The SIGTRAP can be due to a completed hardware single-step only if
4695 - we didn't insert software single-step breakpoints
4696 - this thread is currently being stepped
4698 If any of these events did not occur, we must have stopped due
4699 to hitting a software breakpoint, and have to back up to the
4702 As a special case, we could have hardware single-stepped a
4703 software breakpoint. In this case (prev_pc == breakpoint_pc),
4704 we also need to back up to the breakpoint address. */
4706 if (thread_has_single_step_breakpoints_set (thread
)
4707 || !currently_stepping (thread
)
4708 || (thread
->stepped_breakpoint
4709 && thread
->prev_pc
== breakpoint_pc
))
4710 regcache_write_pc (regcache
, breakpoint_pc
);
4715 stepped_in_from (frame_info_ptr frame
, struct frame_id step_frame_id
)
4717 for (frame
= get_prev_frame (frame
);
4719 frame
= get_prev_frame (frame
))
4721 if (get_frame_id (frame
) == step_frame_id
)
4724 if (get_frame_type (frame
) != INLINE_FRAME
)
4731 /* Look for an inline frame that is marked for skip.
4732 If PREV_FRAME is TRUE start at the previous frame,
4733 otherwise start at the current frame. Stop at the
4734 first non-inline frame, or at the frame where the
4738 inline_frame_is_marked_for_skip (bool prev_frame
, struct thread_info
*tp
)
4740 frame_info_ptr frame
= get_current_frame ();
4743 frame
= get_prev_frame (frame
);
4745 for (; frame
!= nullptr; frame
= get_prev_frame (frame
))
4747 const char *fn
= nullptr;
4748 symtab_and_line sal
;
4751 if (get_frame_id (frame
) == tp
->control
.step_frame_id
)
4753 if (get_frame_type (frame
) != INLINE_FRAME
)
4756 sal
= find_frame_sal (frame
);
4757 sym
= get_frame_function (frame
);
4760 fn
= sym
->print_name ();
4763 && function_name_is_marked_for_skip (fn
, sal
))
4770 /* If the event thread has the stop requested flag set, pretend it
4771 stopped for a GDB_SIGNAL_0 (i.e., as if it stopped due to
4775 handle_stop_requested (struct execution_control_state
*ecs
)
4777 if (ecs
->event_thread
->stop_requested
)
4779 ecs
->ws
.set_stopped (GDB_SIGNAL_0
);
4780 handle_signal_stop (ecs
);
4786 /* Auxiliary function that handles syscall entry/return events.
4787 It returns true if the inferior should keep going (and GDB
4788 should ignore the event), or false if the event deserves to be
4792 handle_syscall_event (struct execution_control_state
*ecs
)
4794 struct regcache
*regcache
;
4797 context_switch (ecs
);
4799 regcache
= get_thread_regcache (ecs
->event_thread
);
4800 syscall_number
= ecs
->ws
.syscall_number ();
4801 ecs
->event_thread
->set_stop_pc (regcache_read_pc (regcache
));
4803 if (catch_syscall_enabled () > 0
4804 && catching_syscall_number (syscall_number
))
4806 infrun_debug_printf ("syscall number=%d", syscall_number
);
4808 ecs
->event_thread
->control
.stop_bpstat
4809 = bpstat_stop_status_nowatch (regcache
->aspace (),
4810 ecs
->event_thread
->stop_pc (),
4811 ecs
->event_thread
, ecs
->ws
);
4813 if (handle_stop_requested (ecs
))
4816 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4818 /* Catchpoint hit. */
4823 if (handle_stop_requested (ecs
))
4826 /* If no catchpoint triggered for this, then keep going. */
4832 /* Lazily fill in the execution_control_state's stop_func_* fields. */
4835 fill_in_stop_func (struct gdbarch
*gdbarch
,
4836 struct execution_control_state
*ecs
)
4838 if (!ecs
->stop_func_filled_in
)
4841 const general_symbol_info
*gsi
;
4843 /* Don't care about return value; stop_func_start and stop_func_name
4844 will both be 0 if it doesn't work. */
4845 find_pc_partial_function_sym (ecs
->event_thread
->stop_pc (),
4847 &ecs
->stop_func_start
,
4848 &ecs
->stop_func_end
,
4850 ecs
->stop_func_name
= gsi
== nullptr ? nullptr : gsi
->print_name ();
4852 /* The call to find_pc_partial_function, above, will set
4853 stop_func_start and stop_func_end to the start and end
4854 of the range containing the stop pc. If this range
4855 contains the entry pc for the block (which is always the
4856 case for contiguous blocks), advance stop_func_start past
4857 the function's start offset and entrypoint. Note that
4858 stop_func_start is NOT advanced when in a range of a
4859 non-contiguous block that does not contain the entry pc. */
4860 if (block
!= nullptr
4861 && ecs
->stop_func_start
<= block
->entry_pc ()
4862 && block
->entry_pc () < ecs
->stop_func_end
)
4864 ecs
->stop_func_start
4865 += gdbarch_deprecated_function_start_offset (gdbarch
);
4867 /* PowerPC functions have a Local Entry Point (LEP) and a Global
4868 Entry Point (GEP). There is only one Entry Point (GEP = LEP) for
4869 other architectures. */
4870 ecs
->stop_func_alt_start
= ecs
->stop_func_start
;
4872 if (gdbarch_skip_entrypoint_p (gdbarch
))
4873 ecs
->stop_func_start
4874 = gdbarch_skip_entrypoint (gdbarch
, ecs
->stop_func_start
);
4877 ecs
->stop_func_filled_in
= 1;
4882 /* Return the STOP_SOON field of the inferior pointed at by ECS. */
4884 static enum stop_kind
4885 get_inferior_stop_soon (execution_control_state
*ecs
)
4887 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
4889 gdb_assert (inf
!= nullptr);
4890 return inf
->control
.stop_soon
;
4893 /* Poll for one event out of the current target. Store the resulting
4894 waitstatus in WS, and return the event ptid. Does not block. */
4897 poll_one_curr_target (struct target_waitstatus
*ws
)
4901 overlay_cache_invalid
= 1;
4903 /* Flush target cache before starting to handle each event.
4904 Target was running and cache could be stale. This is just a
4905 heuristic. Running threads may modify target memory, but we
4906 don't get any event. */
4907 target_dcache_invalidate ();
4909 event_ptid
= target_wait (minus_one_ptid
, ws
, TARGET_WNOHANG
);
4912 print_target_wait_results (minus_one_ptid
, event_ptid
, *ws
);
4917 /* Wait for one event out of any target. */
4919 static wait_one_event
4924 for (inferior
*inf
: all_inferiors ())
4926 process_stratum_target
*target
= inf
->process_target ();
4927 if (target
== nullptr
4928 || !target
->is_async_p ()
4929 || !target
->threads_executing
)
4932 switch_to_inferior_no_thread (inf
);
4934 wait_one_event event
;
4935 event
.target
= target
;
4936 event
.ptid
= poll_one_curr_target (&event
.ws
);
4938 if (event
.ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
4940 /* If nothing is resumed, remove the target from the
4942 target_async (false);
4944 else if (event
.ws
.kind () != TARGET_WAITKIND_IGNORE
)
4948 /* Block waiting for some event. */
4955 for (inferior
*inf
: all_inferiors ())
4957 process_stratum_target
*target
= inf
->process_target ();
4958 if (target
== nullptr
4959 || !target
->is_async_p ()
4960 || !target
->threads_executing
)
4963 int fd
= target
->async_wait_fd ();
4964 FD_SET (fd
, &readfds
);
4971 /* No waitable targets left. All must be stopped. */
4972 target_waitstatus ws
;
4973 ws
.set_no_resumed ();
4974 return {nullptr, minus_one_ptid
, std::move (ws
)};
4979 int numfds
= interruptible_select (nfds
, &readfds
, 0, nullptr, 0);
4985 perror_with_name ("interruptible_select");
4990 /* Save the thread's event and stop reason to process it later. */
4993 save_waitstatus (struct thread_info
*tp
, const target_waitstatus
&ws
)
4995 infrun_debug_printf ("saving status %s for %s",
4996 ws
.to_string ().c_str (),
4997 tp
->ptid
.to_string ().c_str ());
4999 /* Record for later. */
5000 tp
->set_pending_waitstatus (ws
);
5002 if (ws
.kind () == TARGET_WAITKIND_STOPPED
5003 && ws
.sig () == GDB_SIGNAL_TRAP
)
5005 struct regcache
*regcache
= get_thread_regcache (tp
);
5006 const address_space
*aspace
= regcache
->aspace ();
5007 CORE_ADDR pc
= regcache_read_pc (regcache
);
5009 adjust_pc_after_break (tp
, tp
->pending_waitstatus ());
5011 scoped_restore_current_thread restore_thread
;
5012 switch_to_thread (tp
);
5014 if (target_stopped_by_watchpoint ())
5015 tp
->set_stop_reason (TARGET_STOPPED_BY_WATCHPOINT
);
5016 else if (target_supports_stopped_by_sw_breakpoint ()
5017 && target_stopped_by_sw_breakpoint ())
5018 tp
->set_stop_reason (TARGET_STOPPED_BY_SW_BREAKPOINT
);
5019 else if (target_supports_stopped_by_hw_breakpoint ()
5020 && target_stopped_by_hw_breakpoint ())
5021 tp
->set_stop_reason (TARGET_STOPPED_BY_HW_BREAKPOINT
);
5022 else if (!target_supports_stopped_by_hw_breakpoint ()
5023 && hardware_breakpoint_inserted_here_p (aspace
, pc
))
5024 tp
->set_stop_reason (TARGET_STOPPED_BY_HW_BREAKPOINT
);
5025 else if (!target_supports_stopped_by_sw_breakpoint ()
5026 && software_breakpoint_inserted_here_p (aspace
, pc
))
5027 tp
->set_stop_reason (TARGET_STOPPED_BY_SW_BREAKPOINT
);
5028 else if (!thread_has_single_step_breakpoints_set (tp
)
5029 && currently_stepping (tp
))
5030 tp
->set_stop_reason (TARGET_STOPPED_BY_SINGLE_STEP
);
5034 /* Mark the non-executing threads accordingly. In all-stop, all
5035 threads of all processes are stopped when we get any event
5036 reported. In non-stop mode, only the event thread stops. */
5039 mark_non_executing_threads (process_stratum_target
*target
,
5041 const target_waitstatus
&ws
)
5045 if (!target_is_non_stop_p ())
5046 mark_ptid
= minus_one_ptid
;
5047 else if (ws
.kind () == TARGET_WAITKIND_SIGNALLED
5048 || ws
.kind () == TARGET_WAITKIND_EXITED
)
5050 /* If we're handling a process exit in non-stop mode, even
5051 though threads haven't been deleted yet, one would think
5052 that there is nothing to do, as threads of the dead process
5053 will be soon deleted, and threads of any other process were
5054 left running. However, on some targets, threads survive a
5055 process exit event. E.g., for the "checkpoint" command,
5056 when the current checkpoint/fork exits, linux-fork.c
5057 automatically switches to another fork from within
5058 target_mourn_inferior, by associating the same
5059 inferior/thread to another fork. We haven't mourned yet at
5060 this point, but we must mark any threads left in the
5061 process as not-executing so that finish_thread_state marks
5062 them stopped (in the user's perspective) if/when we present
5063 the stop to the user. */
5064 mark_ptid
= ptid_t (event_ptid
.pid ());
5067 mark_ptid
= event_ptid
;
5069 set_executing (target
, mark_ptid
, false);
5071 /* Likewise the resumed flag. */
5072 set_resumed (target
, mark_ptid
, false);
5075 /* Handle one event after stopping threads. If the eventing thread
5076 reports back any interesting event, we leave it pending. If the
5077 eventing thread was in the middle of a displaced step, we
5078 cancel/finish it, and unless the thread's inferior is being
5079 detached, put the thread back in the step-over chain. Returns true
5080 if there are no resumed threads left in the target (thus there's no
5081 point in waiting further), false otherwise. */
5084 handle_one (const wait_one_event
&event
)
5087 ("%s %s", event
.ws
.to_string ().c_str (),
5088 event
.ptid
.to_string ().c_str ());
5090 if (event
.ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
5092 /* All resumed threads exited. */
5095 else if (event
.ws
.kind () == TARGET_WAITKIND_THREAD_EXITED
5096 || event
.ws
.kind () == TARGET_WAITKIND_EXITED
5097 || event
.ws
.kind () == TARGET_WAITKIND_SIGNALLED
)
5099 /* One thread/process exited/signalled. */
5101 thread_info
*t
= nullptr;
5103 /* The target may have reported just a pid. If so, try
5104 the first non-exited thread. */
5105 if (event
.ptid
.is_pid ())
5107 int pid
= event
.ptid
.pid ();
5108 inferior
*inf
= find_inferior_pid (event
.target
, pid
);
5109 for (thread_info
*tp
: inf
->non_exited_threads ())
5115 /* If there is no available thread, the event would
5116 have to be appended to a per-inferior event list,
5117 which does not exist (and if it did, we'd have
5118 to adjust run control command to be able to
5119 resume such an inferior). We assert here instead
5120 of going into an infinite loop. */
5121 gdb_assert (t
!= nullptr);
5124 ("using %s", t
->ptid
.to_string ().c_str ());
5128 t
= event
.target
->find_thread (event
.ptid
);
5129 /* Check if this is the first time we see this thread.
5130 Don't bother adding if it individually exited. */
5132 && event
.ws
.kind () != TARGET_WAITKIND_THREAD_EXITED
)
5133 t
= add_thread (event
.target
, event
.ptid
);
5138 /* Set the threads as non-executing to avoid
5139 another stop attempt on them. */
5140 switch_to_thread_no_regs (t
);
5141 mark_non_executing_threads (event
.target
, event
.ptid
,
5143 save_waitstatus (t
, event
.ws
);
5144 t
->stop_requested
= false;
5149 thread_info
*t
= event
.target
->find_thread (event
.ptid
);
5151 t
= add_thread (event
.target
, event
.ptid
);
5153 t
->stop_requested
= 0;
5154 t
->set_executing (false);
5155 t
->set_resumed (false);
5156 t
->control
.may_range_step
= 0;
5158 /* This may be the first time we see the inferior report
5160 if (t
->inf
->needs_setup
)
5162 switch_to_thread_no_regs (t
);
5166 if (event
.ws
.kind () == TARGET_WAITKIND_STOPPED
5167 && event
.ws
.sig () == GDB_SIGNAL_0
)
5169 /* We caught the event that we intended to catch, so
5170 there's no event to save as pending. */
5172 if (displaced_step_finish (t
, event
.ws
)
5173 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5175 /* Add it back to the step-over queue. */
5177 ("displaced-step of %s canceled",
5178 t
->ptid
.to_string ().c_str ());
5180 t
->control
.trap_expected
= 0;
5181 if (!t
->inf
->detaching
)
5182 global_thread_step_over_chain_enqueue (t
);
5187 struct regcache
*regcache
;
5190 ("target_wait %s, saving status for %s",
5191 event
.ws
.to_string ().c_str (),
5192 t
->ptid
.to_string ().c_str ());
5194 /* Record for later. */
5195 save_waitstatus (t
, event
.ws
);
5197 if (displaced_step_finish (t
, event
.ws
)
5198 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5200 /* Add it back to the step-over queue. */
5201 t
->control
.trap_expected
= 0;
5202 if (!t
->inf
->detaching
)
5203 global_thread_step_over_chain_enqueue (t
);
5206 regcache
= get_thread_regcache (t
);
5207 t
->set_stop_pc (regcache_read_pc (regcache
));
5209 infrun_debug_printf ("saved stop_pc=%s for %s "
5210 "(currently_stepping=%d)",
5211 paddress (target_gdbarch (), t
->stop_pc ()),
5212 t
->ptid
.to_string ().c_str (),
5213 currently_stepping (t
));
5223 stop_all_threads (const char *reason
, inferior
*inf
)
5225 /* We may need multiple passes to discover all threads. */
5229 gdb_assert (exists_non_stop_target ());
5231 INFRUN_SCOPED_DEBUG_START_END ("reason=%s, inf=%d", reason
,
5232 inf
!= nullptr ? inf
->num
: -1);
5234 infrun_debug_show_threads ("non-exited threads",
5235 all_non_exited_threads ());
5237 scoped_restore_current_thread restore_thread
;
5239 /* Enable thread events on relevant targets. */
5240 for (auto *target
: all_non_exited_process_targets ())
5242 if (inf
!= nullptr && inf
->process_target () != target
)
5245 switch_to_target_no_thread (target
);
5246 target_thread_events (true);
5251 /* Disable thread events on relevant targets. */
5252 for (auto *target
: all_non_exited_process_targets ())
5254 if (inf
!= nullptr && inf
->process_target () != target
)
5257 switch_to_target_no_thread (target
);
5258 target_thread_events (false);
5261 /* Use debug_prefixed_printf directly to get a meaningful function
5264 debug_prefixed_printf ("infrun", "stop_all_threads", "done");
5267 /* Request threads to stop, and then wait for the stops. Because
5268 threads we already know about can spawn more threads while we're
5269 trying to stop them, and we only learn about new threads when we
5270 update the thread list, do this in a loop, and keep iterating
5271 until two passes find no threads that need to be stopped. */
5272 for (pass
= 0; pass
< 2; pass
++, iterations
++)
5274 infrun_debug_printf ("pass=%d, iterations=%d", pass
, iterations
);
5277 int waits_needed
= 0;
5279 for (auto *target
: all_non_exited_process_targets ())
5281 if (inf
!= nullptr && inf
->process_target () != target
)
5284 switch_to_target_no_thread (target
);
5285 update_thread_list ();
5288 /* Go through all threads looking for threads that we need
5289 to tell the target to stop. */
5290 for (thread_info
*t
: all_non_exited_threads ())
5292 if (inf
!= nullptr && t
->inf
!= inf
)
5295 /* For a single-target setting with an all-stop target,
5296 we would not even arrive here. For a multi-target
5297 setting, until GDB is able to handle a mixture of
5298 all-stop and non-stop targets, simply skip all-stop
5299 targets' threads. This should be fine due to the
5300 protection of 'check_multi_target_resumption'. */
5302 switch_to_thread_no_regs (t
);
5303 if (!target_is_non_stop_p ())
5306 if (t
->executing ())
5308 /* If already stopping, don't request a stop again.
5309 We just haven't seen the notification yet. */
5310 if (!t
->stop_requested
)
5312 infrun_debug_printf (" %s executing, need stop",
5313 t
->ptid
.to_string ().c_str ());
5314 target_stop (t
->ptid
);
5315 t
->stop_requested
= 1;
5319 infrun_debug_printf (" %s executing, already stopping",
5320 t
->ptid
.to_string ().c_str ());
5323 if (t
->stop_requested
)
5328 infrun_debug_printf (" %s not executing",
5329 t
->ptid
.to_string ().c_str ());
5331 /* The thread may be not executing, but still be
5332 resumed with a pending status to process. */
5333 t
->set_resumed (false);
5337 if (waits_needed
== 0)
5340 /* If we find new threads on the second iteration, restart
5341 over. We want to see two iterations in a row with all
5346 for (int i
= 0; i
< waits_needed
; i
++)
5348 wait_one_event event
= wait_one ();
5349 if (handle_one (event
))
5356 /* Handle a TARGET_WAITKIND_NO_RESUMED event. */
5359 handle_no_resumed (struct execution_control_state
*ecs
)
5361 if (target_can_async_p ())
5363 bool any_sync
= false;
5365 for (ui
*ui
: all_uis ())
5367 if (ui
->prompt_state
== PROMPT_BLOCKED
)
5375 /* There were no unwaited-for children left in the target, but,
5376 we're not synchronously waiting for events either. Just
5379 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED (ignoring: bg)");
5380 prepare_to_wait (ecs
);
5385 /* Otherwise, if we were running a synchronous execution command, we
5386 may need to cancel it and give the user back the terminal.
5388 In non-stop mode, the target can't tell whether we've already
5389 consumed previous stop events, so it can end up sending us a
5390 no-resumed event like so:
5392 #0 - thread 1 is left stopped
5394 #1 - thread 2 is resumed and hits breakpoint
5395 -> TARGET_WAITKIND_STOPPED
5397 #2 - thread 3 is resumed and exits
5398 this is the last resumed thread, so
5399 -> TARGET_WAITKIND_NO_RESUMED
5401 #3 - gdb processes stop for thread 2 and decides to re-resume
5404 #4 - gdb processes the TARGET_WAITKIND_NO_RESUMED event.
5405 thread 2 is now resumed, so the event should be ignored.
5407 IOW, if the stop for thread 2 doesn't end a foreground command,
5408 then we need to ignore the following TARGET_WAITKIND_NO_RESUMED
5409 event. But it could be that the event meant that thread 2 itself
5410 (or whatever other thread was the last resumed thread) exited.
5412 To address this we refresh the thread list and check whether we
5413 have resumed threads _now_. In the example above, this removes
5414 thread 3 from the thread list. If thread 2 was re-resumed, we
5415 ignore this event. If we find no thread resumed, then we cancel
5416 the synchronous command and show "no unwaited-for " to the
5419 inferior
*curr_inf
= current_inferior ();
5421 scoped_restore_current_thread restore_thread
;
5422 update_thread_list ();
5426 - the current target has no thread executing, and
5427 - the current inferior is native, and
5428 - the current inferior is the one which has the terminal, and
5431 then a Ctrl-C from this point on would remain stuck in the
5432 kernel, until a thread resumes and dequeues it. That would
5433 result in the GDB CLI not reacting to Ctrl-C, not able to
5434 interrupt the program. To address this, if the current inferior
5435 no longer has any thread executing, we give the terminal to some
5436 other inferior that has at least one thread executing. */
5437 bool swap_terminal
= true;
5439 /* Whether to ignore this TARGET_WAITKIND_NO_RESUMED event, or
5440 whether to report it to the user. */
5441 bool ignore_event
= false;
5443 for (thread_info
*thread
: all_non_exited_threads ())
5445 if (swap_terminal
&& thread
->executing ())
5447 if (thread
->inf
!= curr_inf
)
5449 target_terminal::ours ();
5451 switch_to_thread (thread
);
5452 target_terminal::inferior ();
5454 swap_terminal
= false;
5457 if (!ignore_event
&& thread
->resumed ())
5459 /* Either there were no unwaited-for children left in the
5460 target at some point, but there are now, or some target
5461 other than the eventing one has unwaited-for children
5462 left. Just ignore. */
5463 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED "
5464 "(ignoring: found resumed)");
5466 ignore_event
= true;
5469 if (ignore_event
&& !swap_terminal
)
5475 switch_to_inferior_no_thread (curr_inf
);
5476 prepare_to_wait (ecs
);
5480 /* Go ahead and report the event. */
5484 /* Given an execution control state that has been freshly filled in by
5485 an event from the inferior, figure out what it means and take
5488 The alternatives are:
5490 1) stop_waiting and return; to really stop and return to the
5493 2) keep_going and return; to wait for the next event (set
5494 ecs->event_thread->stepping_over_breakpoint to 1 to single step
5498 handle_inferior_event (struct execution_control_state
*ecs
)
5500 /* Make sure that all temporary struct value objects that were
5501 created during the handling of the event get deleted at the
5503 scoped_value_mark free_values
;
5505 infrun_debug_printf ("%s", ecs
->ws
.to_string ().c_str ());
5507 if (ecs
->ws
.kind () == TARGET_WAITKIND_IGNORE
)
5509 /* We had an event in the inferior, but we are not interested in
5510 handling it at this level. The lower layers have already
5511 done what needs to be done, if anything.
5513 One of the possible circumstances for this is when the
5514 inferior produces output for the console. The inferior has
5515 not stopped, and we are ignoring the event. Another possible
5516 circumstance is any event which the lower level knows will be
5517 reported multiple times without an intervening resume. */
5518 prepare_to_wait (ecs
);
5522 if (ecs
->ws
.kind () == TARGET_WAITKIND_THREAD_EXITED
)
5524 prepare_to_wait (ecs
);
5528 if (ecs
->ws
.kind () == TARGET_WAITKIND_NO_RESUMED
5529 && handle_no_resumed (ecs
))
5532 /* Cache the last target/ptid/waitstatus. */
5533 set_last_target_status (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5535 /* Always clear state belonging to the previous time we stopped. */
5536 stop_stack_dummy
= STOP_NONE
;
5538 if (ecs
->ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
5540 /* No unwaited-for children left. IOW, all resumed children
5542 stop_print_frame
= false;
5547 if (ecs
->ws
.kind () != TARGET_WAITKIND_EXITED
5548 && ecs
->ws
.kind () != TARGET_WAITKIND_SIGNALLED
)
5550 ecs
->event_thread
= ecs
->target
->find_thread (ecs
->ptid
);
5551 /* If it's a new thread, add it to the thread database. */
5552 if (ecs
->event_thread
== nullptr)
5553 ecs
->event_thread
= add_thread (ecs
->target
, ecs
->ptid
);
5555 /* Disable range stepping. If the next step request could use a
5556 range, this will be end up re-enabled then. */
5557 ecs
->event_thread
->control
.may_range_step
= 0;
5560 /* Dependent on valid ECS->EVENT_THREAD. */
5561 adjust_pc_after_break (ecs
->event_thread
, ecs
->ws
);
5563 /* Dependent on the current PC value modified by adjust_pc_after_break. */
5564 reinit_frame_cache ();
5566 breakpoint_retire_moribund ();
5568 /* First, distinguish signals caused by the debugger from signals
5569 that have to do with the program's own actions. Note that
5570 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
5571 on the operating system version. Here we detect when a SIGILL or
5572 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
5573 something similar for SIGSEGV, since a SIGSEGV will be generated
5574 when we're trying to execute a breakpoint instruction on a
5575 non-executable stack. This happens for call dummy breakpoints
5576 for architectures like SPARC that place call dummies on the
5578 if (ecs
->ws
.kind () == TARGET_WAITKIND_STOPPED
5579 && (ecs
->ws
.sig () == GDB_SIGNAL_ILL
5580 || ecs
->ws
.sig () == GDB_SIGNAL_SEGV
5581 || ecs
->ws
.sig () == GDB_SIGNAL_EMT
))
5583 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5585 if (breakpoint_inserted_here_p (regcache
->aspace (),
5586 regcache_read_pc (regcache
)))
5588 infrun_debug_printf ("Treating signal as SIGTRAP");
5589 ecs
->ws
.set_stopped (GDB_SIGNAL_TRAP
);
5593 mark_non_executing_threads (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5595 switch (ecs
->ws
.kind ())
5597 case TARGET_WAITKIND_LOADED
:
5599 context_switch (ecs
);
5600 /* Ignore gracefully during startup of the inferior, as it might
5601 be the shell which has just loaded some objects, otherwise
5602 add the symbols for the newly loaded objects. Also ignore at
5603 the beginning of an attach or remote session; we will query
5604 the full list of libraries once the connection is
5607 stop_kind stop_soon
= get_inferior_stop_soon (ecs
);
5608 if (stop_soon
== NO_STOP_QUIETLY
)
5610 struct regcache
*regcache
;
5612 regcache
= get_thread_regcache (ecs
->event_thread
);
5614 handle_solib_event ();
5616 ecs
->event_thread
->set_stop_pc (regcache_read_pc (regcache
));
5617 ecs
->event_thread
->control
.stop_bpstat
5618 = bpstat_stop_status_nowatch (regcache
->aspace (),
5619 ecs
->event_thread
->stop_pc (),
5620 ecs
->event_thread
, ecs
->ws
);
5622 if (handle_stop_requested (ecs
))
5625 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5627 /* A catchpoint triggered. */
5628 process_event_stop_test (ecs
);
5632 /* If requested, stop when the dynamic linker notifies
5633 gdb of events. This allows the user to get control
5634 and place breakpoints in initializer routines for
5635 dynamically loaded objects (among other things). */
5636 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5637 if (stop_on_solib_events
)
5639 /* Make sure we print "Stopped due to solib-event" in
5641 stop_print_frame
= true;
5648 /* If we are skipping through a shell, or through shared library
5649 loading that we aren't interested in, resume the program. If
5650 we're running the program normally, also resume. */
5651 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
5653 /* Loading of shared libraries might have changed breakpoint
5654 addresses. Make sure new breakpoints are inserted. */
5655 if (stop_soon
== NO_STOP_QUIETLY
)
5656 insert_breakpoints ();
5657 resume (GDB_SIGNAL_0
);
5658 prepare_to_wait (ecs
);
5662 /* But stop if we're attaching or setting up a remote
5664 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
5665 || stop_soon
== STOP_QUIETLY_REMOTE
)
5667 infrun_debug_printf ("quietly stopped");
5672 internal_error (_("unhandled stop_soon: %d"), (int) stop_soon
);
5675 case TARGET_WAITKIND_SPURIOUS
:
5676 if (handle_stop_requested (ecs
))
5678 context_switch (ecs
);
5679 resume (GDB_SIGNAL_0
);
5680 prepare_to_wait (ecs
);
5683 case TARGET_WAITKIND_THREAD_CREATED
:
5684 if (handle_stop_requested (ecs
))
5686 context_switch (ecs
);
5687 if (!switch_back_to_stepped_thread (ecs
))
5691 case TARGET_WAITKIND_EXITED
:
5692 case TARGET_WAITKIND_SIGNALLED
:
5694 /* Depending on the system, ecs->ptid may point to a thread or
5695 to a process. On some targets, target_mourn_inferior may
5696 need to have access to the just-exited thread. That is the
5697 case of GNU/Linux's "checkpoint" support, for example.
5698 Call the switch_to_xxx routine as appropriate. */
5699 thread_info
*thr
= ecs
->target
->find_thread (ecs
->ptid
);
5701 switch_to_thread (thr
);
5704 inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5705 switch_to_inferior_no_thread (inf
);
5708 handle_vfork_child_exec_or_exit (0);
5709 target_terminal::ours (); /* Must do this before mourn anyway. */
5711 /* Clearing any previous state of convenience variables. */
5712 clear_exit_convenience_vars ();
5714 if (ecs
->ws
.kind () == TARGET_WAITKIND_EXITED
)
5716 /* Record the exit code in the convenience variable $_exitcode, so
5717 that the user can inspect this again later. */
5718 set_internalvar_integer (lookup_internalvar ("_exitcode"),
5719 (LONGEST
) ecs
->ws
.exit_status ());
5721 /* Also record this in the inferior itself. */
5722 current_inferior ()->has_exit_code
= true;
5723 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.exit_status ();
5725 /* Support the --return-child-result option. */
5726 return_child_result_value
= ecs
->ws
.exit_status ();
5728 gdb::observers::exited
.notify (ecs
->ws
.exit_status ());
5732 struct gdbarch
*gdbarch
= current_inferior ()->gdbarch
;
5734 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
5736 /* Set the value of the internal variable $_exitsignal,
5737 which holds the signal uncaught by the inferior. */
5738 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
5739 gdbarch_gdb_signal_to_target (gdbarch
,
5744 /* We don't have access to the target's method used for
5745 converting between signal numbers (GDB's internal
5746 representation <-> target's representation).
5747 Therefore, we cannot do a good job at displaying this
5748 information to the user. It's better to just warn
5749 her about it (if infrun debugging is enabled), and
5751 infrun_debug_printf ("Cannot fill $_exitsignal with the correct "
5755 gdb::observers::signal_exited
.notify (ecs
->ws
.sig ());
5758 gdb_flush (gdb_stdout
);
5759 target_mourn_inferior (inferior_ptid
);
5760 stop_print_frame
= false;
5764 case TARGET_WAITKIND_FORKED
:
5765 case TARGET_WAITKIND_VFORKED
:
5766 /* Check whether the inferior is displaced stepping. */
5768 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5769 struct gdbarch
*gdbarch
= regcache
->arch ();
5770 inferior
*parent_inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5772 /* If this is a fork (child gets its own address space copy)
5773 and some displaced step buffers were in use at the time of
5774 the fork, restore the displaced step buffer bytes in the
5777 Architectures which support displaced stepping and fork
5778 events must supply an implementation of
5779 gdbarch_displaced_step_restore_all_in_ptid. This is not
5780 enforced during gdbarch validation to support architectures
5781 which support displaced stepping but not forks. */
5782 if (ecs
->ws
.kind () == TARGET_WAITKIND_FORKED
5783 && gdbarch_supports_displaced_stepping (gdbarch
))
5784 gdbarch_displaced_step_restore_all_in_ptid
5785 (gdbarch
, parent_inf
, ecs
->ws
.child_ptid ());
5787 /* If displaced stepping is supported, and thread ecs->ptid is
5788 displaced stepping. */
5789 if (displaced_step_in_progress_thread (ecs
->event_thread
))
5791 struct regcache
*child_regcache
;
5792 CORE_ADDR parent_pc
;
5794 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
5795 indicating that the displaced stepping of syscall instruction
5796 has been done. Perform cleanup for parent process here. Note
5797 that this operation also cleans up the child process for vfork,
5798 because their pages are shared. */
5799 displaced_step_finish (ecs
->event_thread
, ecs
->ws
);
5800 /* Start a new step-over in another thread if there's one
5804 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
5805 the child's PC is also within the scratchpad. Set the child's PC
5806 to the parent's PC value, which has already been fixed up.
5807 FIXME: we use the parent's aspace here, although we're touching
5808 the child, because the child hasn't been added to the inferior
5809 list yet at this point. */
5812 = get_thread_arch_aspace_regcache (parent_inf
,
5813 ecs
->ws
.child_ptid (),
5815 parent_inf
->aspace
);
5816 /* Read PC value of parent process. */
5817 parent_pc
= regcache_read_pc (regcache
);
5819 displaced_debug_printf ("write child pc from %s to %s",
5821 regcache_read_pc (child_regcache
)),
5822 paddress (gdbarch
, parent_pc
));
5824 regcache_write_pc (child_regcache
, parent_pc
);
5828 context_switch (ecs
);
5830 /* Immediately detach breakpoints from the child before there's
5831 any chance of letting the user delete breakpoints from the
5832 breakpoint lists. If we don't do this early, it's easy to
5833 leave left over traps in the child, vis: "break foo; catch
5834 fork; c; <fork>; del; c; <child calls foo>". We only follow
5835 the fork on the last `continue', and by that time the
5836 breakpoint at "foo" is long gone from the breakpoint table.
5837 If we vforked, then we don't need to unpatch here, since both
5838 parent and child are sharing the same memory pages; we'll
5839 need to unpatch at follow/detach time instead to be certain
5840 that new breakpoints added between catchpoint hit time and
5841 vfork follow are detached. */
5842 if (ecs
->ws
.kind () != TARGET_WAITKIND_VFORKED
)
5844 /* This won't actually modify the breakpoint list, but will
5845 physically remove the breakpoints from the child. */
5846 detach_breakpoints (ecs
->ws
.child_ptid ());
5849 delete_just_stopped_threads_single_step_breakpoints ();
5851 /* In case the event is caught by a catchpoint, remember that
5852 the event is to be followed at the next resume of the thread,
5853 and not immediately. */
5854 ecs
->event_thread
->pending_follow
= ecs
->ws
;
5856 ecs
->event_thread
->set_stop_pc
5857 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
5859 ecs
->event_thread
->control
.stop_bpstat
5860 = bpstat_stop_status_nowatch (get_current_regcache ()->aspace (),
5861 ecs
->event_thread
->stop_pc (),
5862 ecs
->event_thread
, ecs
->ws
);
5864 if (handle_stop_requested (ecs
))
5867 /* If no catchpoint triggered for this, then keep going. Note
5868 that we're interested in knowing the bpstat actually causes a
5869 stop, not just if it may explain the signal. Software
5870 watchpoints, for example, always appear in the bpstat. */
5871 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5874 = (follow_fork_mode_string
== follow_fork_mode_child
);
5876 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5878 process_stratum_target
*targ
5879 = ecs
->event_thread
->inf
->process_target ();
5881 bool should_resume
= follow_fork ();
5883 /* Note that one of these may be an invalid pointer,
5884 depending on detach_fork. */
5885 thread_info
*parent
= ecs
->event_thread
;
5886 thread_info
*child
= targ
->find_thread (ecs
->ws
.child_ptid ());
5888 /* At this point, the parent is marked running, and the
5889 child is marked stopped. */
5891 /* If not resuming the parent, mark it stopped. */
5892 if (follow_child
&& !detach_fork
&& !non_stop
&& !sched_multi
)
5893 parent
->set_running (false);
5895 /* If resuming the child, mark it running. */
5896 if (follow_child
|| (!detach_fork
&& (non_stop
|| sched_multi
)))
5897 child
->set_running (true);
5899 /* In non-stop mode, also resume the other branch. */
5900 if (!detach_fork
&& (non_stop
5901 || (sched_multi
&& target_is_non_stop_p ())))
5904 switch_to_thread (parent
);
5906 switch_to_thread (child
);
5908 ecs
->event_thread
= inferior_thread ();
5909 ecs
->ptid
= inferior_ptid
;
5914 switch_to_thread (child
);
5916 switch_to_thread (parent
);
5918 ecs
->event_thread
= inferior_thread ();
5919 ecs
->ptid
= inferior_ptid
;
5923 /* Never call switch_back_to_stepped_thread if we are waiting for
5924 vfork-done (waiting for an external vfork child to exec or
5925 exit). We will resume only the vforking thread for the purpose
5926 of collecting the vfork-done event, and we will restart any
5927 step once the critical shared address space window is done. */
5930 && parent
->inf
->thread_waiting_for_vfork_done
!= nullptr)
5931 || !switch_back_to_stepped_thread (ecs
))
5938 process_event_stop_test (ecs
);
5941 case TARGET_WAITKIND_VFORK_DONE
:
5942 /* Done with the shared memory region. Re-insert breakpoints in
5943 the parent, and keep going. */
5945 context_switch (ecs
);
5947 handle_vfork_done (ecs
->event_thread
);
5948 gdb_assert (inferior_thread () == ecs
->event_thread
);
5950 if (handle_stop_requested (ecs
))
5953 if (!switch_back_to_stepped_thread (ecs
))
5955 gdb_assert (inferior_thread () == ecs
->event_thread
);
5956 /* This also takes care of reinserting breakpoints in the
5957 previously locked inferior. */
5962 case TARGET_WAITKIND_EXECD
:
5964 /* Note we can't read registers yet (the stop_pc), because we
5965 don't yet know the inferior's post-exec architecture.
5966 'stop_pc' is explicitly read below instead. */
5967 switch_to_thread_no_regs (ecs
->event_thread
);
5969 /* Do whatever is necessary to the parent branch of the vfork. */
5970 handle_vfork_child_exec_or_exit (1);
5972 /* This causes the eventpoints and symbol table to be reset.
5973 Must do this now, before trying to determine whether to
5975 follow_exec (inferior_ptid
, ecs
->ws
.execd_pathname ());
5977 /* In follow_exec we may have deleted the original thread and
5978 created a new one. Make sure that the event thread is the
5979 execd thread for that case (this is a nop otherwise). */
5980 ecs
->event_thread
= inferior_thread ();
5982 ecs
->event_thread
->set_stop_pc
5983 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
5985 ecs
->event_thread
->control
.stop_bpstat
5986 = bpstat_stop_status_nowatch (get_current_regcache ()->aspace (),
5987 ecs
->event_thread
->stop_pc (),
5988 ecs
->event_thread
, ecs
->ws
);
5990 if (handle_stop_requested (ecs
))
5993 /* If no catchpoint triggered for this, then keep going. */
5994 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5996 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6000 process_event_stop_test (ecs
);
6003 /* Be careful not to try to gather much state about a thread
6004 that's in a syscall. It's frequently a losing proposition. */
6005 case TARGET_WAITKIND_SYSCALL_ENTRY
:
6006 /* Getting the current syscall number. */
6007 if (handle_syscall_event (ecs
) == 0)
6008 process_event_stop_test (ecs
);
6011 /* Before examining the threads further, step this thread to
6012 get it entirely out of the syscall. (We get notice of the
6013 event when the thread is just on the verge of exiting a
6014 syscall. Stepping one instruction seems to get it back
6016 case TARGET_WAITKIND_SYSCALL_RETURN
:
6017 if (handle_syscall_event (ecs
) == 0)
6018 process_event_stop_test (ecs
);
6021 case TARGET_WAITKIND_STOPPED
:
6022 handle_signal_stop (ecs
);
6025 case TARGET_WAITKIND_NO_HISTORY
:
6026 /* Reverse execution: target ran out of history info. */
6028 /* Switch to the stopped thread. */
6029 context_switch (ecs
);
6030 infrun_debug_printf ("stopped");
6032 delete_just_stopped_threads_single_step_breakpoints ();
6033 ecs
->event_thread
->set_stop_pc
6034 (regcache_read_pc (get_thread_regcache (inferior_thread ())));
6036 if (handle_stop_requested (ecs
))
6039 gdb::observers::no_history
.notify ();
6045 /* Restart threads back to what they were trying to do back when we
6046 paused them (because of an in-line step-over or vfork, for example).
6047 The EVENT_THREAD thread is ignored (not restarted).
6049 If INF is non-nullptr, only resume threads from INF. */
6052 restart_threads (struct thread_info
*event_thread
, inferior
*inf
)
6054 INFRUN_SCOPED_DEBUG_START_END ("event_thread=%s, inf=%d",
6055 event_thread
->ptid
.to_string ().c_str (),
6056 inf
!= nullptr ? inf
->num
: -1);
6058 gdb_assert (!step_over_info_valid_p ());
6060 /* In case the instruction just stepped spawned a new thread. */
6061 update_thread_list ();
6063 for (thread_info
*tp
: all_non_exited_threads ())
6065 if (inf
!= nullptr && tp
->inf
!= inf
)
6068 if (tp
->inf
->detaching
)
6070 infrun_debug_printf ("restart threads: [%s] inferior detaching",
6071 tp
->ptid
.to_string ().c_str ());
6075 switch_to_thread_no_regs (tp
);
6077 if (tp
== event_thread
)
6079 infrun_debug_printf ("restart threads: [%s] is event thread",
6080 tp
->ptid
.to_string ().c_str ());
6084 if (!(tp
->state
== THREAD_RUNNING
|| tp
->control
.in_infcall
))
6086 infrun_debug_printf ("restart threads: [%s] not meant to be running",
6087 tp
->ptid
.to_string ().c_str ());
6093 infrun_debug_printf ("restart threads: [%s] resumed",
6094 tp
->ptid
.to_string ().c_str ());
6095 gdb_assert (tp
->executing () || tp
->has_pending_waitstatus ());
6099 if (thread_is_in_step_over_chain (tp
))
6101 infrun_debug_printf ("restart threads: [%s] needs step-over",
6102 tp
->ptid
.to_string ().c_str ());
6103 gdb_assert (!tp
->resumed ());
6108 if (tp
->has_pending_waitstatus ())
6110 infrun_debug_printf ("restart threads: [%s] has pending status",
6111 tp
->ptid
.to_string ().c_str ());
6112 tp
->set_resumed (true);
6116 gdb_assert (!tp
->stop_requested
);
6118 /* If some thread needs to start a step-over at this point, it
6119 should still be in the step-over queue, and thus skipped
6121 if (thread_still_needs_step_over (tp
))
6123 internal_error ("thread [%s] needs a step-over, but not in "
6124 "step-over queue\n",
6125 tp
->ptid
.to_string ().c_str ());
6128 if (currently_stepping (tp
))
6130 infrun_debug_printf ("restart threads: [%s] was stepping",
6131 tp
->ptid
.to_string ().c_str ());
6132 keep_going_stepped_thread (tp
);
6136 infrun_debug_printf ("restart threads: [%s] continuing",
6137 tp
->ptid
.to_string ().c_str ());
6138 execution_control_state
ecs (tp
);
6139 switch_to_thread (tp
);
6140 keep_going_pass_signal (&ecs
);
6145 /* Callback for iterate_over_threads. Find a resumed thread that has
6146 a pending waitstatus. */
6149 resumed_thread_with_pending_status (struct thread_info
*tp
,
6152 return tp
->resumed () && tp
->has_pending_waitstatus ();
6155 /* Called when we get an event that may finish an in-line or
6156 out-of-line (displaced stepping) step-over started previously.
6157 Return true if the event is processed and we should go back to the
6158 event loop; false if the caller should continue processing the
6162 finish_step_over (struct execution_control_state
*ecs
)
6164 displaced_step_finish (ecs
->event_thread
, ecs
->ws
);
6166 bool had_step_over_info
= step_over_info_valid_p ();
6168 if (had_step_over_info
)
6170 /* If we're stepping over a breakpoint with all threads locked,
6171 then only the thread that was stepped should be reporting
6173 gdb_assert (ecs
->event_thread
->control
.trap_expected
);
6175 clear_step_over_info ();
6178 if (!target_is_non_stop_p ())
6181 /* Start a new step-over in another thread if there's one that
6185 /* If we were stepping over a breakpoint before, and haven't started
6186 a new in-line step-over sequence, then restart all other threads
6187 (except the event thread). We can't do this in all-stop, as then
6188 e.g., we wouldn't be able to issue any other remote packet until
6189 these other threads stop. */
6190 if (had_step_over_info
&& !step_over_info_valid_p ())
6192 struct thread_info
*pending
;
6194 /* If we only have threads with pending statuses, the restart
6195 below won't restart any thread and so nothing re-inserts the
6196 breakpoint we just stepped over. But we need it inserted
6197 when we later process the pending events, otherwise if
6198 another thread has a pending event for this breakpoint too,
6199 we'd discard its event (because the breakpoint that
6200 originally caused the event was no longer inserted). */
6201 context_switch (ecs
);
6202 insert_breakpoints ();
6204 restart_threads (ecs
->event_thread
);
6206 /* If we have events pending, go through handle_inferior_event
6207 again, picking up a pending event at random. This avoids
6208 thread starvation. */
6210 /* But not if we just stepped over a watchpoint in order to let
6211 the instruction execute so we can evaluate its expression.
6212 The set of watchpoints that triggered is recorded in the
6213 breakpoint objects themselves (see bp->watchpoint_triggered).
6214 If we processed another event first, that other event could
6215 clobber this info. */
6216 if (ecs
->event_thread
->stepping_over_watchpoint
)
6219 pending
= iterate_over_threads (resumed_thread_with_pending_status
,
6221 if (pending
!= nullptr)
6223 struct thread_info
*tp
= ecs
->event_thread
;
6224 struct regcache
*regcache
;
6226 infrun_debug_printf ("found resumed threads with "
6227 "pending events, saving status");
6229 gdb_assert (pending
!= tp
);
6231 /* Record the event thread's event for later. */
6232 save_waitstatus (tp
, ecs
->ws
);
6233 /* This was cleared early, by handle_inferior_event. Set it
6234 so this pending event is considered by
6236 tp
->set_resumed (true);
6238 gdb_assert (!tp
->executing ());
6240 regcache
= get_thread_regcache (tp
);
6241 tp
->set_stop_pc (regcache_read_pc (regcache
));
6243 infrun_debug_printf ("saved stop_pc=%s for %s "
6244 "(currently_stepping=%d)",
6245 paddress (target_gdbarch (), tp
->stop_pc ()),
6246 tp
->ptid
.to_string ().c_str (),
6247 currently_stepping (tp
));
6249 /* This in-line step-over finished; clear this so we won't
6250 start a new one. This is what handle_signal_stop would
6251 do, if we returned false. */
6252 tp
->stepping_over_breakpoint
= 0;
6254 /* Wake up the event loop again. */
6255 mark_async_event_handler (infrun_async_inferior_event_token
);
6257 prepare_to_wait (ecs
);
6265 /* Come here when the program has stopped with a signal. */
6268 handle_signal_stop (struct execution_control_state
*ecs
)
6270 frame_info_ptr frame
;
6271 struct gdbarch
*gdbarch
;
6272 int stopped_by_watchpoint
;
6273 enum stop_kind stop_soon
;
6276 gdb_assert (ecs
->ws
.kind () == TARGET_WAITKIND_STOPPED
);
6278 ecs
->event_thread
->set_stop_signal (ecs
->ws
.sig ());
6280 /* Do we need to clean up the state of a thread that has
6281 completed a displaced single-step? (Doing so usually affects
6282 the PC, so do it here, before we set stop_pc.) */
6283 if (finish_step_over (ecs
))
6286 /* If we either finished a single-step or hit a breakpoint, but
6287 the user wanted this thread to be stopped, pretend we got a
6288 SIG0 (generic unsignaled stop). */
6289 if (ecs
->event_thread
->stop_requested
6290 && ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
6291 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6293 ecs
->event_thread
->set_stop_pc
6294 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
6296 context_switch (ecs
);
6298 if (deprecated_context_hook
)
6299 deprecated_context_hook (ecs
->event_thread
->global_num
);
6303 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
6304 struct gdbarch
*reg_gdbarch
= regcache
->arch ();
6307 ("stop_pc=%s", paddress (reg_gdbarch
, ecs
->event_thread
->stop_pc ()));
6308 if (target_stopped_by_watchpoint ())
6312 infrun_debug_printf ("stopped by watchpoint");
6314 if (target_stopped_data_address (current_inferior ()->top_target (),
6316 infrun_debug_printf ("stopped data address=%s",
6317 paddress (reg_gdbarch
, addr
));
6319 infrun_debug_printf ("(no data address available)");
6323 /* This is originated from start_remote(), start_inferior() and
6324 shared libraries hook functions. */
6325 stop_soon
= get_inferior_stop_soon (ecs
);
6326 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
6328 infrun_debug_printf ("quietly stopped");
6329 stop_print_frame
= true;
6334 /* This originates from attach_command(). We need to overwrite
6335 the stop_signal here, because some kernels don't ignore a
6336 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
6337 See more comments in inferior.h. On the other hand, if we
6338 get a non-SIGSTOP, report it to the user - assume the backend
6339 will handle the SIGSTOP if it should show up later.
6341 Also consider that the attach is complete when we see a
6342 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
6343 target extended-remote report it instead of a SIGSTOP
6344 (e.g. gdbserver). We already rely on SIGTRAP being our
6345 signal, so this is no exception.
6347 Also consider that the attach is complete when we see a
6348 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
6349 the target to stop all threads of the inferior, in case the
6350 low level attach operation doesn't stop them implicitly. If
6351 they weren't stopped implicitly, then the stub will report a
6352 GDB_SIGNAL_0, meaning: stopped for no particular reason
6353 other than GDB's request. */
6354 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
6355 && (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_STOP
6356 || ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6357 || ecs
->event_thread
->stop_signal () == GDB_SIGNAL_0
))
6359 stop_print_frame
= true;
6361 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6365 /* At this point, get hold of the now-current thread's frame. */
6366 frame
= get_current_frame ();
6367 gdbarch
= get_frame_arch (frame
);
6369 /* Pull the single step breakpoints out of the target. */
6370 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
6372 struct regcache
*regcache
;
6375 regcache
= get_thread_regcache (ecs
->event_thread
);
6376 const address_space
*aspace
= regcache
->aspace ();
6378 pc
= regcache_read_pc (regcache
);
6380 /* However, before doing so, if this single-step breakpoint was
6381 actually for another thread, set this thread up for moving
6383 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
6386 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
6388 infrun_debug_printf ("[%s] hit another thread's single-step "
6390 ecs
->ptid
.to_string ().c_str ());
6391 ecs
->hit_singlestep_breakpoint
= 1;
6396 infrun_debug_printf ("[%s] hit its single-step breakpoint",
6397 ecs
->ptid
.to_string ().c_str ());
6400 delete_just_stopped_threads_single_step_breakpoints ();
6402 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6403 && ecs
->event_thread
->control
.trap_expected
6404 && ecs
->event_thread
->stepping_over_watchpoint
)
6405 stopped_by_watchpoint
= 0;
6407 stopped_by_watchpoint
= watchpoints_triggered (ecs
->ws
);
6409 /* If necessary, step over this watchpoint. We'll be back to display
6411 if (stopped_by_watchpoint
6412 && (target_have_steppable_watchpoint ()
6413 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
6415 /* At this point, we are stopped at an instruction which has
6416 attempted to write to a piece of memory under control of
6417 a watchpoint. The instruction hasn't actually executed
6418 yet. If we were to evaluate the watchpoint expression
6419 now, we would get the old value, and therefore no change
6420 would seem to have occurred.
6422 In order to make watchpoints work `right', we really need
6423 to complete the memory write, and then evaluate the
6424 watchpoint expression. We do this by single-stepping the
6427 It may not be necessary to disable the watchpoint to step over
6428 it. For example, the PA can (with some kernel cooperation)
6429 single step over a watchpoint without disabling the watchpoint.
6431 It is far more common to need to disable a watchpoint to step
6432 the inferior over it. If we have non-steppable watchpoints,
6433 we must disable the current watchpoint; it's simplest to
6434 disable all watchpoints.
6436 Any breakpoint at PC must also be stepped over -- if there's
6437 one, it will have already triggered before the watchpoint
6438 triggered, and we either already reported it to the user, or
6439 it didn't cause a stop and we called keep_going. In either
6440 case, if there was a breakpoint at PC, we must be trying to
6442 ecs
->event_thread
->stepping_over_watchpoint
= 1;
6447 ecs
->event_thread
->stepping_over_breakpoint
= 0;
6448 ecs
->event_thread
->stepping_over_watchpoint
= 0;
6449 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
6450 ecs
->event_thread
->control
.stop_step
= 0;
6451 stop_print_frame
= true;
6452 stopped_by_random_signal
= 0;
6453 bpstat
*stop_chain
= nullptr;
6455 /* Hide inlined functions starting here, unless we just performed stepi or
6456 nexti. After stepi and nexti, always show the innermost frame (not any
6457 inline function call sites). */
6458 if (ecs
->event_thread
->control
.step_range_end
!= 1)
6460 const address_space
*aspace
6461 = get_thread_regcache (ecs
->event_thread
)->aspace ();
6463 /* skip_inline_frames is expensive, so we avoid it if we can
6464 determine that the address is one where functions cannot have
6465 been inlined. This improves performance with inferiors that
6466 load a lot of shared libraries, because the solib event
6467 breakpoint is defined as the address of a function (i.e. not
6468 inline). Note that we have to check the previous PC as well
6469 as the current one to catch cases when we have just
6470 single-stepped off a breakpoint prior to reinstating it.
6471 Note that we're assuming that the code we single-step to is
6472 not inline, but that's not definitive: there's nothing
6473 preventing the event breakpoint function from containing
6474 inlined code, and the single-step ending up there. If the
6475 user had set a breakpoint on that inlined code, the missing
6476 skip_inline_frames call would break things. Fortunately
6477 that's an extremely unlikely scenario. */
6478 if (!pc_at_non_inline_function (aspace
,
6479 ecs
->event_thread
->stop_pc (),
6481 && !(ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6482 && ecs
->event_thread
->control
.trap_expected
6483 && pc_at_non_inline_function (aspace
,
6484 ecs
->event_thread
->prev_pc
,
6487 stop_chain
= build_bpstat_chain (aspace
,
6488 ecs
->event_thread
->stop_pc (),
6490 skip_inline_frames (ecs
->event_thread
, stop_chain
);
6492 /* Re-fetch current thread's frame in case that invalidated
6494 frame
= get_current_frame ();
6495 gdbarch
= get_frame_arch (frame
);
6499 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6500 && ecs
->event_thread
->control
.trap_expected
6501 && gdbarch_single_step_through_delay_p (gdbarch
)
6502 && currently_stepping (ecs
->event_thread
))
6504 /* We're trying to step off a breakpoint. Turns out that we're
6505 also on an instruction that needs to be stepped multiple
6506 times before it's been fully executing. E.g., architectures
6507 with a delay slot. It needs to be stepped twice, once for
6508 the instruction and once for the delay slot. */
6509 int step_through_delay
6510 = gdbarch_single_step_through_delay (gdbarch
, frame
);
6512 if (step_through_delay
)
6513 infrun_debug_printf ("step through delay");
6515 if (ecs
->event_thread
->control
.step_range_end
== 0
6516 && step_through_delay
)
6518 /* The user issued a continue when stopped at a breakpoint.
6519 Set up for another trap and get out of here. */
6520 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6524 else if (step_through_delay
)
6526 /* The user issued a step when stopped at a breakpoint.
6527 Maybe we should stop, maybe we should not - the delay
6528 slot *might* correspond to a line of source. In any
6529 case, don't decide that here, just set
6530 ecs->stepping_over_breakpoint, making sure we
6531 single-step again before breakpoints are re-inserted. */
6532 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6536 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
6537 handles this event. */
6538 ecs
->event_thread
->control
.stop_bpstat
6539 = bpstat_stop_status (get_current_regcache ()->aspace (),
6540 ecs
->event_thread
->stop_pc (),
6541 ecs
->event_thread
, ecs
->ws
, stop_chain
);
6543 /* Following in case break condition called a
6545 stop_print_frame
= true;
6547 /* This is where we handle "moribund" watchpoints. Unlike
6548 software breakpoints traps, hardware watchpoint traps are
6549 always distinguishable from random traps. If no high-level
6550 watchpoint is associated with the reported stop data address
6551 anymore, then the bpstat does not explain the signal ---
6552 simply make sure to ignore it if `stopped_by_watchpoint' is
6555 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6556 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6558 && stopped_by_watchpoint
)
6560 infrun_debug_printf ("no user watchpoint explains watchpoint SIGTRAP, "
6564 /* NOTE: cagney/2003-03-29: These checks for a random signal
6565 at one stage in the past included checks for an inferior
6566 function call's call dummy's return breakpoint. The original
6567 comment, that went with the test, read:
6569 ``End of a stack dummy. Some systems (e.g. Sony news) give
6570 another signal besides SIGTRAP, so check here as well as
6573 If someone ever tries to get call dummys on a
6574 non-executable stack to work (where the target would stop
6575 with something like a SIGSEGV), then those tests might need
6576 to be re-instated. Given, however, that the tests were only
6577 enabled when momentary breakpoints were not being used, I
6578 suspect that it won't be the case.
6580 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
6581 be necessary for call dummies on a non-executable stack on
6584 /* See if the breakpoints module can explain the signal. */
6586 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6587 ecs
->event_thread
->stop_signal ());
6589 /* Maybe this was a trap for a software breakpoint that has since
6591 if (random_signal
&& target_stopped_by_sw_breakpoint ())
6593 if (gdbarch_program_breakpoint_here_p (gdbarch
,
6594 ecs
->event_thread
->stop_pc ()))
6596 struct regcache
*regcache
;
6599 /* Re-adjust PC to what the program would see if GDB was not
6601 regcache
= get_thread_regcache (ecs
->event_thread
);
6602 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
6605 gdb::optional
<scoped_restore_tmpl
<int>>
6606 restore_operation_disable
;
6608 if (record_full_is_used ())
6609 restore_operation_disable
.emplace
6610 (record_full_gdb_operation_disable_set ());
6612 regcache_write_pc (regcache
,
6613 ecs
->event_thread
->stop_pc () + decr_pc
);
6618 /* A delayed software breakpoint event. Ignore the trap. */
6619 infrun_debug_printf ("delayed software breakpoint trap, ignoring");
6624 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
6625 has since been removed. */
6626 if (random_signal
&& target_stopped_by_hw_breakpoint ())
6628 /* A delayed hardware breakpoint event. Ignore the trap. */
6629 infrun_debug_printf ("delayed hardware breakpoint/watchpoint "
6634 /* If not, perhaps stepping/nexting can. */
6636 random_signal
= !(ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6637 && currently_stepping (ecs
->event_thread
));
6639 /* Perhaps the thread hit a single-step breakpoint of _another_
6640 thread. Single-step breakpoints are transparent to the
6641 breakpoints module. */
6643 random_signal
= !ecs
->hit_singlestep_breakpoint
;
6645 /* No? Perhaps we got a moribund watchpoint. */
6647 random_signal
= !stopped_by_watchpoint
;
6649 /* Always stop if the user explicitly requested this thread to
6651 if (ecs
->event_thread
->stop_requested
)
6654 infrun_debug_printf ("user-requested stop");
6657 /* For the program's own signals, act according to
6658 the signal handling tables. */
6662 /* Signal not for debugging purposes. */
6663 enum gdb_signal stop_signal
= ecs
->event_thread
->stop_signal ();
6665 infrun_debug_printf ("random signal (%s)",
6666 gdb_signal_to_symbol_string (stop_signal
));
6668 stopped_by_random_signal
= 1;
6670 /* Always stop on signals if we're either just gaining control
6671 of the program, or the user explicitly requested this thread
6672 to remain stopped. */
6673 if (stop_soon
!= NO_STOP_QUIETLY
6674 || ecs
->event_thread
->stop_requested
6675 || signal_stop_state (ecs
->event_thread
->stop_signal ()))
6681 /* Notify observers the signal has "handle print" set. Note we
6682 returned early above if stopping; normal_stop handles the
6683 printing in that case. */
6684 if (signal_print
[ecs
->event_thread
->stop_signal ()])
6686 /* The signal table tells us to print about this signal. */
6687 target_terminal::ours_for_output ();
6688 gdb::observers::signal_received
.notify (ecs
->event_thread
->stop_signal ());
6689 target_terminal::inferior ();
6692 /* Clear the signal if it should not be passed. */
6693 if (signal_program
[ecs
->event_thread
->stop_signal ()] == 0)
6694 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6696 if (ecs
->event_thread
->prev_pc
== ecs
->event_thread
->stop_pc ()
6697 && ecs
->event_thread
->control
.trap_expected
6698 && ecs
->event_thread
->control
.step_resume_breakpoint
== nullptr)
6700 /* We were just starting a new sequence, attempting to
6701 single-step off of a breakpoint and expecting a SIGTRAP.
6702 Instead this signal arrives. This signal will take us out
6703 of the stepping range so GDB needs to remember to, when
6704 the signal handler returns, resume stepping off that
6706 /* To simplify things, "continue" is forced to use the same
6707 code paths as single-step - set a breakpoint at the
6708 signal return address and then, once hit, step off that
6710 infrun_debug_printf ("signal arrived while stepping over breakpoint");
6712 insert_hp_step_resume_breakpoint_at_frame (frame
);
6713 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6714 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6715 ecs
->event_thread
->control
.trap_expected
= 0;
6717 /* If we were nexting/stepping some other thread, switch to
6718 it, so that we don't continue it, losing control. */
6719 if (!switch_back_to_stepped_thread (ecs
))
6724 if (ecs
->event_thread
->stop_signal () != GDB_SIGNAL_0
6725 && (pc_in_thread_step_range (ecs
->event_thread
->stop_pc (),
6727 || ecs
->event_thread
->control
.step_range_end
== 1)
6728 && (get_stack_frame_id (frame
)
6729 == ecs
->event_thread
->control
.step_stack_frame_id
)
6730 && ecs
->event_thread
->control
.step_resume_breakpoint
== nullptr)
6732 /* The inferior is about to take a signal that will take it
6733 out of the single step range. Set a breakpoint at the
6734 current PC (which is presumably where the signal handler
6735 will eventually return) and then allow the inferior to
6738 Note that this is only needed for a signal delivered
6739 while in the single-step range. Nested signals aren't a
6740 problem as they eventually all return. */
6741 infrun_debug_printf ("signal may take us out of single-step range");
6743 clear_step_over_info ();
6744 insert_hp_step_resume_breakpoint_at_frame (frame
);
6745 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6746 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6747 ecs
->event_thread
->control
.trap_expected
= 0;
6752 /* Note: step_resume_breakpoint may be non-NULL. This occurs
6753 when either there's a nested signal, or when there's a
6754 pending signal enabled just as the signal handler returns
6755 (leaving the inferior at the step-resume-breakpoint without
6756 actually executing it). Either way continue until the
6757 breakpoint is really hit. */
6759 if (!switch_back_to_stepped_thread (ecs
))
6761 infrun_debug_printf ("random signal, keep going");
6768 process_event_stop_test (ecs
);
6771 /* Come here when we've got some debug event / signal we can explain
6772 (IOW, not a random signal), and test whether it should cause a
6773 stop, or whether we should resume the inferior (transparently).
6774 E.g., could be a breakpoint whose condition evaluates false; we
6775 could be still stepping within the line; etc. */
6778 process_event_stop_test (struct execution_control_state
*ecs
)
6780 struct symtab_and_line stop_pc_sal
;
6781 frame_info_ptr frame
;
6782 struct gdbarch
*gdbarch
;
6783 CORE_ADDR jmp_buf_pc
;
6784 struct bpstat_what what
;
6786 /* Handle cases caused by hitting a breakpoint. */
6788 frame
= get_current_frame ();
6789 gdbarch
= get_frame_arch (frame
);
6791 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
6793 if (what
.call_dummy
)
6795 stop_stack_dummy
= what
.call_dummy
;
6798 /* A few breakpoint types have callbacks associated (e.g.,
6799 bp_jit_event). Run them now. */
6800 bpstat_run_callbacks (ecs
->event_thread
->control
.stop_bpstat
);
6802 /* If we hit an internal event that triggers symbol changes, the
6803 current frame will be invalidated within bpstat_what (e.g., if we
6804 hit an internal solib event). Re-fetch it. */
6805 frame
= get_current_frame ();
6806 gdbarch
= get_frame_arch (frame
);
6808 switch (what
.main_action
)
6810 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
6811 /* If we hit the breakpoint at longjmp while stepping, we
6812 install a momentary breakpoint at the target of the
6815 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME");
6817 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6819 if (what
.is_longjmp
)
6821 struct value
*arg_value
;
6823 /* If we set the longjmp breakpoint via a SystemTap probe,
6824 then use it to extract the arguments. The destination PC
6825 is the third argument to the probe. */
6826 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
6829 jmp_buf_pc
= value_as_address (arg_value
);
6830 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
6832 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
6833 || !gdbarch_get_longjmp_target (gdbarch
,
6834 frame
, &jmp_buf_pc
))
6836 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME "
6837 "(!gdbarch_get_longjmp_target)");
6842 /* Insert a breakpoint at resume address. */
6843 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
6846 check_exception_resume (ecs
, frame
);
6850 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
6852 frame_info_ptr init_frame
;
6854 /* There are several cases to consider.
6856 1. The initiating frame no longer exists. In this case we
6857 must stop, because the exception or longjmp has gone too
6860 2. The initiating frame exists, and is the same as the
6861 current frame. We stop, because the exception or longjmp
6864 3. The initiating frame exists and is different from the
6865 current frame. This means the exception or longjmp has
6866 been caught beneath the initiating frame, so keep going.
6868 4. longjmp breakpoint has been placed just to protect
6869 against stale dummy frames and user is not interested in
6870 stopping around longjmps. */
6872 infrun_debug_printf ("BPSTAT_WHAT_CLEAR_LONGJMP_RESUME");
6874 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
6876 delete_exception_resume_breakpoint (ecs
->event_thread
);
6878 if (what
.is_longjmp
)
6880 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
6882 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
6890 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
6894 struct frame_id current_id
6895 = get_frame_id (get_current_frame ());
6896 if (current_id
== ecs
->event_thread
->initiating_frame
)
6898 /* Case 2. Fall through. */
6908 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
6910 delete_step_resume_breakpoint (ecs
->event_thread
);
6912 end_stepping_range (ecs
);
6916 case BPSTAT_WHAT_SINGLE
:
6917 infrun_debug_printf ("BPSTAT_WHAT_SINGLE");
6918 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6919 /* Still need to check other stuff, at least the case where we
6920 are stepping and step out of the right range. */
6923 case BPSTAT_WHAT_STEP_RESUME
:
6924 infrun_debug_printf ("BPSTAT_WHAT_STEP_RESUME");
6926 delete_step_resume_breakpoint (ecs
->event_thread
);
6927 if (ecs
->event_thread
->control
.proceed_to_finish
6928 && execution_direction
== EXEC_REVERSE
)
6930 struct thread_info
*tp
= ecs
->event_thread
;
6932 /* We are finishing a function in reverse, and just hit the
6933 step-resume breakpoint at the start address of the
6934 function, and we're almost there -- just need to back up
6935 by one more single-step, which should take us back to the
6937 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
6941 fill_in_stop_func (gdbarch
, ecs
);
6942 if (ecs
->event_thread
->stop_pc () == ecs
->stop_func_start
6943 && execution_direction
== EXEC_REVERSE
)
6945 /* We are stepping over a function call in reverse, and just
6946 hit the step-resume breakpoint at the start address of
6947 the function. Go back to single-stepping, which should
6948 take us back to the function call. */
6949 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6955 case BPSTAT_WHAT_STOP_NOISY
:
6956 infrun_debug_printf ("BPSTAT_WHAT_STOP_NOISY");
6957 stop_print_frame
= true;
6959 /* Assume the thread stopped for a breakpoint. We'll still check
6960 whether a/the breakpoint is there when the thread is next
6962 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6967 case BPSTAT_WHAT_STOP_SILENT
:
6968 infrun_debug_printf ("BPSTAT_WHAT_STOP_SILENT");
6969 stop_print_frame
= false;
6971 /* Assume the thread stopped for a breakpoint. We'll still check
6972 whether a/the breakpoint is there when the thread is next
6974 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6978 case BPSTAT_WHAT_HP_STEP_RESUME
:
6979 infrun_debug_printf ("BPSTAT_WHAT_HP_STEP_RESUME");
6981 delete_step_resume_breakpoint (ecs
->event_thread
);
6982 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
6984 /* Back when the step-resume breakpoint was inserted, we
6985 were trying to single-step off a breakpoint. Go back to
6987 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6988 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6994 case BPSTAT_WHAT_KEEP_CHECKING
:
6998 /* If we stepped a permanent breakpoint and we had a high priority
6999 step-resume breakpoint for the address we stepped, but we didn't
7000 hit it, then we must have stepped into the signal handler. The
7001 step-resume was only necessary to catch the case of _not_
7002 stepping into the handler, so delete it, and fall through to
7003 checking whether the step finished. */
7004 if (ecs
->event_thread
->stepped_breakpoint
)
7006 struct breakpoint
*sr_bp
7007 = ecs
->event_thread
->control
.step_resume_breakpoint
;
7009 if (sr_bp
!= nullptr
7010 && sr_bp
->loc
->permanent
7011 && sr_bp
->type
== bp_hp_step_resume
7012 && sr_bp
->loc
->address
== ecs
->event_thread
->prev_pc
)
7014 infrun_debug_printf ("stepped permanent breakpoint, stopped in handler");
7015 delete_step_resume_breakpoint (ecs
->event_thread
);
7016 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
7020 /* We come here if we hit a breakpoint but should not stop for it.
7021 Possibly we also were stepping and should stop for that. So fall
7022 through and test for stepping. But, if not stepping, do not
7025 /* In all-stop mode, if we're currently stepping but have stopped in
7026 some other thread, we need to switch back to the stepped thread. */
7027 if (switch_back_to_stepped_thread (ecs
))
7030 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
7032 infrun_debug_printf ("step-resume breakpoint is inserted");
7034 /* Having a step-resume breakpoint overrides anything
7035 else having to do with stepping commands until
7036 that breakpoint is reached. */
7041 if (ecs
->event_thread
->control
.step_range_end
== 0)
7043 infrun_debug_printf ("no stepping, continue");
7044 /* Likewise if we aren't even stepping. */
7049 /* Re-fetch current thread's frame in case the code above caused
7050 the frame cache to be re-initialized, making our FRAME variable
7051 a dangling pointer. */
7052 frame
= get_current_frame ();
7053 gdbarch
= get_frame_arch (frame
);
7054 fill_in_stop_func (gdbarch
, ecs
);
7056 /* If stepping through a line, keep going if still within it.
7058 Note that step_range_end is the address of the first instruction
7059 beyond the step range, and NOT the address of the last instruction
7062 Note also that during reverse execution, we may be stepping
7063 through a function epilogue and therefore must detect when
7064 the current-frame changes in the middle of a line. */
7066 if (pc_in_thread_step_range (ecs
->event_thread
->stop_pc (),
7068 && (execution_direction
!= EXEC_REVERSE
7069 || get_frame_id (frame
) == ecs
->event_thread
->control
.step_frame_id
))
7072 ("stepping inside range [%s-%s]",
7073 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
7074 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
7076 /* Tentatively re-enable range stepping; `resume' disables it if
7077 necessary (e.g., if we're stepping over a breakpoint or we
7078 have software watchpoints). */
7079 ecs
->event_thread
->control
.may_range_step
= 1;
7081 /* When stepping backward, stop at beginning of line range
7082 (unless it's the function entry point, in which case
7083 keep going back to the call point). */
7084 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7085 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
7086 && stop_pc
!= ecs
->stop_func_start
7087 && execution_direction
== EXEC_REVERSE
)
7088 end_stepping_range (ecs
);
7095 /* We stepped out of the stepping range. */
7097 /* If we are stepping at the source level and entered the runtime
7098 loader dynamic symbol resolution code...
7100 EXEC_FORWARD: we keep on single stepping until we exit the run
7101 time loader code and reach the callee's address.
7103 EXEC_REVERSE: we've already executed the callee (backward), and
7104 the runtime loader code is handled just like any other
7105 undebuggable function call. Now we need only keep stepping
7106 backward through the trampoline code, and that's handled further
7107 down, so there is nothing for us to do here. */
7109 if (execution_direction
!= EXEC_REVERSE
7110 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7111 && in_solib_dynsym_resolve_code (ecs
->event_thread
->stop_pc ())
7112 && (ecs
->event_thread
->control
.step_start_function
== nullptr
7113 || !in_solib_dynsym_resolve_code (
7114 ecs
->event_thread
->control
.step_start_function
->value_block ()
7117 CORE_ADDR pc_after_resolver
=
7118 gdbarch_skip_solib_resolver (gdbarch
, ecs
->event_thread
->stop_pc ());
7120 infrun_debug_printf ("stepped into dynsym resolve code");
7122 if (pc_after_resolver
)
7124 /* Set up a step-resume breakpoint at the address
7125 indicated by SKIP_SOLIB_RESOLVER. */
7126 symtab_and_line sr_sal
;
7127 sr_sal
.pc
= pc_after_resolver
;
7128 sr_sal
.pspace
= get_frame_program_space (frame
);
7130 insert_step_resume_breakpoint_at_sal (gdbarch
,
7131 sr_sal
, null_frame_id
);
7138 /* Step through an indirect branch thunk. */
7139 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7140 && gdbarch_in_indirect_branch_thunk (gdbarch
,
7141 ecs
->event_thread
->stop_pc ()))
7143 infrun_debug_printf ("stepped into indirect branch thunk");
7148 if (ecs
->event_thread
->control
.step_range_end
!= 1
7149 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7150 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7151 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
7153 infrun_debug_printf ("stepped into signal trampoline");
7154 /* The inferior, while doing a "step" or "next", has ended up in
7155 a signal trampoline (either by a signal being delivered or by
7156 the signal handler returning). Just single-step until the
7157 inferior leaves the trampoline (either by calling the handler
7163 /* If we're in the return path from a shared library trampoline,
7164 we want to proceed through the trampoline when stepping. */
7165 /* macro/2012-04-25: This needs to come before the subroutine
7166 call check below as on some targets return trampolines look
7167 like subroutine calls (MIPS16 return thunks). */
7168 if (gdbarch_in_solib_return_trampoline (gdbarch
,
7169 ecs
->event_thread
->stop_pc (),
7170 ecs
->stop_func_name
)
7171 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7173 /* Determine where this trampoline returns. */
7174 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7175 CORE_ADDR real_stop_pc
7176 = gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7178 infrun_debug_printf ("stepped into solib return tramp");
7180 /* Only proceed through if we know where it's going. */
7183 /* And put the step-breakpoint there and go until there. */
7184 symtab_and_line sr_sal
;
7185 sr_sal
.pc
= real_stop_pc
;
7186 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7187 sr_sal
.pspace
= get_frame_program_space (frame
);
7189 /* Do not specify what the fp should be when we stop since
7190 on some machines the prologue is where the new fp value
7192 insert_step_resume_breakpoint_at_sal (gdbarch
,
7193 sr_sal
, null_frame_id
);
7195 /* Restart without fiddling with the step ranges or
7202 /* Check for subroutine calls. The check for the current frame
7203 equalling the step ID is not necessary - the check of the
7204 previous frame's ID is sufficient - but it is a common case and
7205 cheaper than checking the previous frame's ID.
7207 NOTE: frame_id::operator== will never report two invalid frame IDs as
7208 being equal, so to get into this block, both the current and
7209 previous frame must have valid frame IDs. */
7210 /* The outer_frame_id check is a heuristic to detect stepping
7211 through startup code. If we step over an instruction which
7212 sets the stack pointer from an invalid value to a valid value,
7213 we may detect that as a subroutine call from the mythical
7214 "outermost" function. This could be fixed by marking
7215 outermost frames as !stack_p,code_p,special_p. Then the
7216 initial outermost frame, before sp was valid, would
7217 have code_addr == &_start. See the comment in frame_id::operator==
7219 if ((get_stack_frame_id (frame
)
7220 != ecs
->event_thread
->control
.step_stack_frame_id
)
7221 && ((frame_unwind_caller_id (get_current_frame ())
7222 == ecs
->event_thread
->control
.step_stack_frame_id
)
7223 && ((ecs
->event_thread
->control
.step_stack_frame_id
7225 || (ecs
->event_thread
->control
.step_start_function
7226 != find_pc_function (ecs
->event_thread
->stop_pc ())))))
7228 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7229 CORE_ADDR real_stop_pc
;
7231 infrun_debug_printf ("stepped into subroutine");
7233 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
7235 /* I presume that step_over_calls is only 0 when we're
7236 supposed to be stepping at the assembly language level
7237 ("stepi"). Just stop. */
7238 /* And this works the same backward as frontward. MVS */
7239 end_stepping_range (ecs
);
7243 /* Reverse stepping through solib trampolines. */
7245 if (execution_direction
== EXEC_REVERSE
7246 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7247 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7248 || (ecs
->stop_func_start
== 0
7249 && in_solib_dynsym_resolve_code (stop_pc
))))
7251 /* Any solib trampoline code can be handled in reverse
7252 by simply continuing to single-step. We have already
7253 executed the solib function (backwards), and a few
7254 steps will take us back through the trampoline to the
7260 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7262 /* We're doing a "next".
7264 Normal (forward) execution: set a breakpoint at the
7265 callee's return address (the address at which the caller
7268 Reverse (backward) execution. set the step-resume
7269 breakpoint at the start of the function that we just
7270 stepped into (backwards), and continue to there. When we
7271 get there, we'll need to single-step back to the caller. */
7273 if (execution_direction
== EXEC_REVERSE
)
7275 /* If we're already at the start of the function, we've either
7276 just stepped backward into a single instruction function,
7277 or stepped back out of a signal handler to the first instruction
7278 of the function. Just keep going, which will single-step back
7280 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
7282 /* Normal function call return (static or dynamic). */
7283 symtab_and_line sr_sal
;
7284 sr_sal
.pc
= ecs
->stop_func_start
;
7285 sr_sal
.pspace
= get_frame_program_space (frame
);
7286 insert_step_resume_breakpoint_at_sal (gdbarch
,
7287 sr_sal
, get_stack_frame_id (frame
));
7291 insert_step_resume_breakpoint_at_caller (frame
);
7297 /* If we are in a function call trampoline (a stub between the
7298 calling routine and the real function), locate the real
7299 function. That's what tells us (a) whether we want to step
7300 into it at all, and (b) what prologue we want to run to the
7301 end of, if we do step into it. */
7302 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
7303 if (real_stop_pc
== 0)
7304 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7305 if (real_stop_pc
!= 0)
7306 ecs
->stop_func_start
= real_stop_pc
;
7308 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
7310 symtab_and_line sr_sal
;
7311 sr_sal
.pc
= ecs
->stop_func_start
;
7312 sr_sal
.pspace
= get_frame_program_space (frame
);
7314 insert_step_resume_breakpoint_at_sal (gdbarch
,
7315 sr_sal
, null_frame_id
);
7320 /* If we have line number information for the function we are
7321 thinking of stepping into and the function isn't on the skip
7324 If there are several symtabs at that PC (e.g. with include
7325 files), just want to know whether *any* of them have line
7326 numbers. find_pc_line handles this. */
7328 struct symtab_and_line tmp_sal
;
7330 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7331 if (tmp_sal
.line
!= 0
7332 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
7334 && !inline_frame_is_marked_for_skip (true, ecs
->event_thread
))
7336 if (execution_direction
== EXEC_REVERSE
)
7337 handle_step_into_function_backward (gdbarch
, ecs
);
7339 handle_step_into_function (gdbarch
, ecs
);
7344 /* If we have no line number and the step-stop-if-no-debug is
7345 set, we stop the step so that the user has a chance to switch
7346 in assembly mode. */
7347 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7348 && step_stop_if_no_debug
)
7350 end_stepping_range (ecs
);
7354 if (execution_direction
== EXEC_REVERSE
)
7356 /* If we're already at the start of the function, we've either just
7357 stepped backward into a single instruction function without line
7358 number info, or stepped back out of a signal handler to the first
7359 instruction of the function without line number info. Just keep
7360 going, which will single-step back to the caller. */
7361 if (ecs
->stop_func_start
!= stop_pc
)
7363 /* Set a breakpoint at callee's start address.
7364 From there we can step once and be back in the caller. */
7365 symtab_and_line sr_sal
;
7366 sr_sal
.pc
= ecs
->stop_func_start
;
7367 sr_sal
.pspace
= get_frame_program_space (frame
);
7368 insert_step_resume_breakpoint_at_sal (gdbarch
,
7369 sr_sal
, null_frame_id
);
7373 /* Set a breakpoint at callee's return address (the address
7374 at which the caller will resume). */
7375 insert_step_resume_breakpoint_at_caller (frame
);
7381 /* Reverse stepping through solib trampolines. */
7383 if (execution_direction
== EXEC_REVERSE
7384 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7386 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7388 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7389 || (ecs
->stop_func_start
== 0
7390 && in_solib_dynsym_resolve_code (stop_pc
)))
7392 /* Any solib trampoline code can be handled in reverse
7393 by simply continuing to single-step. We have already
7394 executed the solib function (backwards), and a few
7395 steps will take us back through the trampoline to the
7400 else if (in_solib_dynsym_resolve_code (stop_pc
))
7402 /* Stepped backward into the solib dynsym resolver.
7403 Set a breakpoint at its start and continue, then
7404 one more step will take us out. */
7405 symtab_and_line sr_sal
;
7406 sr_sal
.pc
= ecs
->stop_func_start
;
7407 sr_sal
.pspace
= get_frame_program_space (frame
);
7408 insert_step_resume_breakpoint_at_sal (gdbarch
,
7409 sr_sal
, null_frame_id
);
7415 /* This always returns the sal for the inner-most frame when we are in a
7416 stack of inlined frames, even if GDB actually believes that it is in a
7417 more outer frame. This is checked for below by calls to
7418 inline_skipped_frames. */
7419 stop_pc_sal
= find_pc_line (ecs
->event_thread
->stop_pc (), 0);
7421 /* NOTE: tausq/2004-05-24: This if block used to be done before all
7422 the trampoline processing logic, however, there are some trampolines
7423 that have no names, so we should do trampoline handling first. */
7424 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7425 && ecs
->stop_func_name
== nullptr
7426 && stop_pc_sal
.line
== 0)
7428 infrun_debug_printf ("stepped into undebuggable function");
7430 /* The inferior just stepped into, or returned to, an
7431 undebuggable function (where there is no debugging information
7432 and no line number corresponding to the address where the
7433 inferior stopped). Since we want to skip this kind of code,
7434 we keep going until the inferior returns from this
7435 function - unless the user has asked us not to (via
7436 set step-mode) or we no longer know how to get back
7437 to the call site. */
7438 if (step_stop_if_no_debug
7439 || !frame_id_p (frame_unwind_caller_id (frame
)))
7441 /* If we have no line number and the step-stop-if-no-debug
7442 is set, we stop the step so that the user has a chance to
7443 switch in assembly mode. */
7444 end_stepping_range (ecs
);
7449 /* Set a breakpoint at callee's return address (the address
7450 at which the caller will resume). */
7451 insert_step_resume_breakpoint_at_caller (frame
);
7457 if (execution_direction
== EXEC_REVERSE
7458 && ecs
->event_thread
->control
.proceed_to_finish
7459 && ecs
->event_thread
->stop_pc () >= ecs
->stop_func_alt_start
7460 && ecs
->event_thread
->stop_pc () < ecs
->stop_func_start
)
7462 /* We are executing the reverse-finish command.
7463 If the system supports multiple entry points and we are finishing a
7464 function in reverse. If we are between the entry points singe-step
7465 back to the alternate entry point. If we are at the alternate entry
7466 point -- just need to back up by one more single-step, which
7467 should take us back to the function call. */
7468 ecs
->event_thread
->control
.step_range_start
7469 = ecs
->event_thread
->control
.step_range_end
= 1;
7475 if (ecs
->event_thread
->control
.step_range_end
== 1)
7477 /* It is stepi or nexti. We always want to stop stepping after
7479 infrun_debug_printf ("stepi/nexti");
7480 end_stepping_range (ecs
);
7484 if (stop_pc_sal
.line
== 0)
7486 /* We have no line number information. That means to stop
7487 stepping (does this always happen right after one instruction,
7488 when we do "s" in a function with no line numbers,
7489 or can this happen as a result of a return or longjmp?). */
7490 infrun_debug_printf ("line number info");
7491 end_stepping_range (ecs
);
7495 /* Look for "calls" to inlined functions, part one. If the inline
7496 frame machinery detected some skipped call sites, we have entered
7497 a new inline function. */
7499 if ((get_frame_id (get_current_frame ())
7500 == ecs
->event_thread
->control
.step_frame_id
)
7501 && inline_skipped_frames (ecs
->event_thread
))
7503 infrun_debug_printf ("stepped into inlined function");
7505 symtab_and_line call_sal
= find_frame_sal (get_current_frame ());
7507 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
7509 /* For "step", we're going to stop. But if the call site
7510 for this inlined function is on the same source line as
7511 we were previously stepping, go down into the function
7512 first. Otherwise stop at the call site. */
7514 if (call_sal
.line
== ecs
->event_thread
->current_line
7515 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7517 step_into_inline_frame (ecs
->event_thread
);
7518 if (inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7525 end_stepping_range (ecs
);
7530 /* For "next", we should stop at the call site if it is on a
7531 different source line. Otherwise continue through the
7532 inlined function. */
7533 if (call_sal
.line
== ecs
->event_thread
->current_line
7534 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7537 end_stepping_range (ecs
);
7542 /* Look for "calls" to inlined functions, part two. If we are still
7543 in the same real function we were stepping through, but we have
7544 to go further up to find the exact frame ID, we are stepping
7545 through a more inlined call beyond its call site. */
7547 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
7548 && (get_frame_id (get_current_frame ())
7549 != ecs
->event_thread
->control
.step_frame_id
)
7550 && stepped_in_from (get_current_frame (),
7551 ecs
->event_thread
->control
.step_frame_id
))
7553 infrun_debug_printf ("stepping through inlined function");
7555 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
7556 || inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7559 end_stepping_range (ecs
);
7563 bool refresh_step_info
= true;
7564 if ((ecs
->event_thread
->stop_pc () == stop_pc_sal
.pc
)
7565 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
7566 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
7568 /* We are at a different line. */
7570 if (stop_pc_sal
.is_stmt
)
7572 /* We are at the start of a statement.
7574 So stop. Note that we don't stop if we step into the middle of a
7575 statement. That is said to make things like for (;;) statements
7577 infrun_debug_printf ("stepped to a different line");
7578 end_stepping_range (ecs
);
7581 else if (get_frame_id (get_current_frame ())
7582 == ecs
->event_thread
->control
.step_frame_id
)
7584 /* We are not at the start of a statement, and we have not changed
7587 We ignore this line table entry, and continue stepping forward,
7588 looking for a better place to stop. */
7589 refresh_step_info
= false;
7590 infrun_debug_printf ("stepped to a different line, but "
7591 "it's not the start of a statement");
7595 /* We are not the start of a statement, and we have changed frame.
7597 We ignore this line table entry, and continue stepping forward,
7598 looking for a better place to stop. Keep refresh_step_info at
7599 true to note that the frame has changed, but ignore the line
7600 number to make sure we don't ignore a subsequent entry with the
7601 same line number. */
7602 stop_pc_sal
.line
= 0;
7603 infrun_debug_printf ("stepped to a different frame, but "
7604 "it's not the start of a statement");
7608 /* We aren't done stepping.
7610 Optimize by setting the stepping range to the line.
7611 (We might not be in the original line, but if we entered a
7612 new line in mid-statement, we continue stepping. This makes
7613 things like for(;;) statements work better.)
7615 If we entered a SAL that indicates a non-statement line table entry,
7616 then we update the stepping range, but we don't update the step info,
7617 which includes things like the line number we are stepping away from.
7618 This means we will stop when we find a line table entry that is marked
7619 as is-statement, even if it matches the non-statement one we just
7622 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
7623 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
7624 ecs
->event_thread
->control
.may_range_step
= 1;
7626 ("updated step range, start = %s, end = %s, may_range_step = %d",
7627 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
7628 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
),
7629 ecs
->event_thread
->control
.may_range_step
);
7630 if (refresh_step_info
)
7631 set_step_info (ecs
->event_thread
, frame
, stop_pc_sal
);
7633 infrun_debug_printf ("keep going");
7637 static bool restart_stepped_thread (process_stratum_target
*resume_target
,
7638 ptid_t resume_ptid
);
7640 /* In all-stop mode, if we're currently stepping but have stopped in
7641 some other thread, we may need to switch back to the stepped
7642 thread. Returns true we set the inferior running, false if we left
7643 it stopped (and the event needs further processing). */
7646 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
7648 if (!target_is_non_stop_p ())
7650 /* If any thread is blocked on some internal breakpoint, and we
7651 simply need to step over that breakpoint to get it going
7652 again, do that first. */
7654 /* However, if we see an event for the stepping thread, then we
7655 know all other threads have been moved past their breakpoints
7656 already. Let the caller check whether the step is finished,
7657 etc., before deciding to move it past a breakpoint. */
7658 if (ecs
->event_thread
->control
.step_range_end
!= 0)
7661 /* Check if the current thread is blocked on an incomplete
7662 step-over, interrupted by a random signal. */
7663 if (ecs
->event_thread
->control
.trap_expected
7664 && ecs
->event_thread
->stop_signal () != GDB_SIGNAL_TRAP
)
7667 ("need to finish step-over of [%s]",
7668 ecs
->event_thread
->ptid
.to_string ().c_str ());
7673 /* Check if the current thread is blocked by a single-step
7674 breakpoint of another thread. */
7675 if (ecs
->hit_singlestep_breakpoint
)
7677 infrun_debug_printf ("need to step [%s] over single-step breakpoint",
7678 ecs
->ptid
.to_string ().c_str ());
7683 /* If this thread needs yet another step-over (e.g., stepping
7684 through a delay slot), do it first before moving on to
7686 if (thread_still_needs_step_over (ecs
->event_thread
))
7689 ("thread [%s] still needs step-over",
7690 ecs
->event_thread
->ptid
.to_string ().c_str ());
7695 /* If scheduler locking applies even if not stepping, there's no
7696 need to walk over threads. Above we've checked whether the
7697 current thread is stepping. If some other thread not the
7698 event thread is stepping, then it must be that scheduler
7699 locking is not in effect. */
7700 if (schedlock_applies (ecs
->event_thread
))
7703 /* Otherwise, we no longer expect a trap in the current thread.
7704 Clear the trap_expected flag before switching back -- this is
7705 what keep_going does as well, if we call it. */
7706 ecs
->event_thread
->control
.trap_expected
= 0;
7708 /* Likewise, clear the signal if it should not be passed. */
7709 if (!signal_program
[ecs
->event_thread
->stop_signal ()])
7710 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
7712 if (restart_stepped_thread (ecs
->target
, ecs
->ptid
))
7714 prepare_to_wait (ecs
);
7718 switch_to_thread (ecs
->event_thread
);
7724 /* Look for the thread that was stepping, and resume it.
7725 RESUME_TARGET / RESUME_PTID indicate the set of threads the caller
7726 is resuming. Return true if a thread was started, false
7730 restart_stepped_thread (process_stratum_target
*resume_target
,
7733 /* Do all pending step-overs before actually proceeding with
7735 if (start_step_over ())
7738 for (thread_info
*tp
: all_threads_safe ())
7740 if (tp
->state
== THREAD_EXITED
)
7743 if (tp
->has_pending_waitstatus ())
7746 /* Ignore threads of processes the caller is not
7749 && (tp
->inf
->process_target () != resume_target
7750 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7753 if (tp
->control
.trap_expected
)
7755 infrun_debug_printf ("switching back to stepped thread (step-over)");
7757 if (keep_going_stepped_thread (tp
))
7762 for (thread_info
*tp
: all_threads_safe ())
7764 if (tp
->state
== THREAD_EXITED
)
7767 if (tp
->has_pending_waitstatus ())
7770 /* Ignore threads of processes the caller is not
7773 && (tp
->inf
->process_target () != resume_target
7774 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7777 /* Did we find the stepping thread? */
7778 if (tp
->control
.step_range_end
)
7780 infrun_debug_printf ("switching back to stepped thread (stepping)");
7782 if (keep_going_stepped_thread (tp
))
7793 restart_after_all_stop_detach (process_stratum_target
*proc_target
)
7795 /* Note we don't check target_is_non_stop_p() here, because the
7796 current inferior may no longer have a process_stratum target
7797 pushed, as we just detached. */
7799 /* See if we have a THREAD_RUNNING thread that need to be
7800 re-resumed. If we have any thread that is already executing,
7801 then we don't need to resume the target -- it is already been
7802 resumed. With the remote target (in all-stop), it's even
7803 impossible to issue another resumption if the target is already
7804 resumed, until the target reports a stop. */
7805 for (thread_info
*thr
: all_threads (proc_target
))
7807 if (thr
->state
!= THREAD_RUNNING
)
7810 /* If we have any thread that is already executing, then we
7811 don't need to resume the target -- it is already been
7813 if (thr
->executing ())
7816 /* If we have a pending event to process, skip resuming the
7817 target and go straight to processing it. */
7818 if (thr
->resumed () && thr
->has_pending_waitstatus ())
7822 /* Alright, we need to re-resume the target. If a thread was
7823 stepping, we need to restart it stepping. */
7824 if (restart_stepped_thread (proc_target
, minus_one_ptid
))
7827 /* Otherwise, find the first THREAD_RUNNING thread and resume
7829 for (thread_info
*thr
: all_threads (proc_target
))
7831 if (thr
->state
!= THREAD_RUNNING
)
7834 execution_control_state
ecs (thr
);
7835 switch_to_thread (thr
);
7841 /* Set a previously stepped thread back to stepping. Returns true on
7842 success, false if the resume is not possible (e.g., the thread
7846 keep_going_stepped_thread (struct thread_info
*tp
)
7848 frame_info_ptr frame
;
7850 /* If the stepping thread exited, then don't try to switch back and
7851 resume it, which could fail in several different ways depending
7852 on the target. Instead, just keep going.
7854 We can find a stepping dead thread in the thread list in two
7857 - The target supports thread exit events, and when the target
7858 tries to delete the thread from the thread list, inferior_ptid
7859 pointed at the exiting thread. In such case, calling
7860 delete_thread does not really remove the thread from the list;
7861 instead, the thread is left listed, with 'exited' state.
7863 - The target's debug interface does not support thread exit
7864 events, and so we have no idea whatsoever if the previously
7865 stepping thread is still alive. For that reason, we need to
7866 synchronously query the target now. */
7868 if (tp
->state
== THREAD_EXITED
|| !target_thread_alive (tp
->ptid
))
7870 infrun_debug_printf ("not resuming previously stepped thread, it has "
7877 infrun_debug_printf ("resuming previously stepped thread");
7879 execution_control_state
ecs (tp
);
7880 switch_to_thread (tp
);
7882 tp
->set_stop_pc (regcache_read_pc (get_thread_regcache (tp
)));
7883 frame
= get_current_frame ();
7885 /* If the PC of the thread we were trying to single-step has
7886 changed, then that thread has trapped or been signaled, but the
7887 event has not been reported to GDB yet. Re-poll the target
7888 looking for this particular thread's event (i.e. temporarily
7889 enable schedlock) by:
7891 - setting a break at the current PC
7892 - resuming that particular thread, only (by setting trap
7895 This prevents us continuously moving the single-step breakpoint
7896 forward, one instruction at a time, overstepping. */
7898 if (tp
->stop_pc () != tp
->prev_pc
)
7902 infrun_debug_printf ("expected thread advanced also (%s -> %s)",
7903 paddress (target_gdbarch (), tp
->prev_pc
),
7904 paddress (target_gdbarch (), tp
->stop_pc ()));
7906 /* Clear the info of the previous step-over, as it's no longer
7907 valid (if the thread was trying to step over a breakpoint, it
7908 has already succeeded). It's what keep_going would do too,
7909 if we called it. Do this before trying to insert the sss
7910 breakpoint, otherwise if we were previously trying to step
7911 over this exact address in another thread, the breakpoint is
7913 clear_step_over_info ();
7914 tp
->control
.trap_expected
= 0;
7916 insert_single_step_breakpoint (get_frame_arch (frame
),
7917 get_frame_address_space (frame
),
7920 tp
->set_resumed (true);
7921 resume_ptid
= internal_resume_ptid (tp
->control
.stepping_command
);
7922 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
7926 infrun_debug_printf ("expected thread still hasn't advanced");
7928 keep_going_pass_signal (&ecs
);
7934 /* Is thread TP in the middle of (software or hardware)
7935 single-stepping? (Note the result of this function must never be
7936 passed directly as target_resume's STEP parameter.) */
7939 currently_stepping (struct thread_info
*tp
)
7941 return ((tp
->control
.step_range_end
7942 && tp
->control
.step_resume_breakpoint
== nullptr)
7943 || tp
->control
.trap_expected
7944 || tp
->stepped_breakpoint
7945 || bpstat_should_step ());
7948 /* Inferior has stepped into a subroutine call with source code that
7949 we should not step over. Do step to the first line of code in
7953 handle_step_into_function (struct gdbarch
*gdbarch
,
7954 struct execution_control_state
*ecs
)
7956 fill_in_stop_func (gdbarch
, ecs
);
7958 compunit_symtab
*cust
7959 = find_pc_compunit_symtab (ecs
->event_thread
->stop_pc ());
7960 if (cust
!= nullptr && cust
->language () != language_asm
)
7961 ecs
->stop_func_start
7962 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7964 symtab_and_line stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7965 /* Use the step_resume_break to step until the end of the prologue,
7966 even if that involves jumps (as it seems to on the vax under
7968 /* If the prologue ends in the middle of a source line, continue to
7969 the end of that source line (if it is still within the function).
7970 Otherwise, just go to end of prologue. */
7971 if (stop_func_sal
.end
7972 && stop_func_sal
.pc
!= ecs
->stop_func_start
7973 && stop_func_sal
.end
< ecs
->stop_func_end
)
7974 ecs
->stop_func_start
= stop_func_sal
.end
;
7976 /* Architectures which require breakpoint adjustment might not be able
7977 to place a breakpoint at the computed address. If so, the test
7978 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
7979 ecs->stop_func_start to an address at which a breakpoint may be
7980 legitimately placed.
7982 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
7983 made, GDB will enter an infinite loop when stepping through
7984 optimized code consisting of VLIW instructions which contain
7985 subinstructions corresponding to different source lines. On
7986 FR-V, it's not permitted to place a breakpoint on any but the
7987 first subinstruction of a VLIW instruction. When a breakpoint is
7988 set, GDB will adjust the breakpoint address to the beginning of
7989 the VLIW instruction. Thus, we need to make the corresponding
7990 adjustment here when computing the stop address. */
7992 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7994 ecs
->stop_func_start
7995 = gdbarch_adjust_breakpoint_address (gdbarch
,
7996 ecs
->stop_func_start
);
7999 if (ecs
->stop_func_start
== ecs
->event_thread
->stop_pc ())
8001 /* We are already there: stop now. */
8002 end_stepping_range (ecs
);
8007 /* Put the step-breakpoint there and go until there. */
8008 symtab_and_line sr_sal
;
8009 sr_sal
.pc
= ecs
->stop_func_start
;
8010 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
8011 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
8013 /* Do not specify what the fp should be when we stop since on
8014 some machines the prologue is where the new fp value is
8016 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
8018 /* And make sure stepping stops right away then. */
8019 ecs
->event_thread
->control
.step_range_end
8020 = ecs
->event_thread
->control
.step_range_start
;
8025 /* Inferior has stepped backward into a subroutine call with source
8026 code that we should not step over. Do step to the beginning of the
8027 last line of code in it. */
8030 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
8031 struct execution_control_state
*ecs
)
8033 struct compunit_symtab
*cust
;
8034 struct symtab_and_line stop_func_sal
;
8036 fill_in_stop_func (gdbarch
, ecs
);
8038 cust
= find_pc_compunit_symtab (ecs
->event_thread
->stop_pc ());
8039 if (cust
!= nullptr && cust
->language () != language_asm
)
8040 ecs
->stop_func_start
8041 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
8043 stop_func_sal
= find_pc_line (ecs
->event_thread
->stop_pc (), 0);
8045 /* OK, we're just going to keep stepping here. */
8046 if (stop_func_sal
.pc
== ecs
->event_thread
->stop_pc ())
8048 /* We're there already. Just stop stepping now. */
8049 end_stepping_range (ecs
);
8053 /* Else just reset the step range and keep going.
8054 No step-resume breakpoint, they don't work for
8055 epilogues, which can have multiple entry paths. */
8056 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
8057 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
8063 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
8064 This is used to both functions and to skip over code. */
8067 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
8068 struct symtab_and_line sr_sal
,
8069 struct frame_id sr_id
,
8070 enum bptype sr_type
)
8072 /* There should never be more than one step-resume or longjmp-resume
8073 breakpoint per thread, so we should never be setting a new
8074 step_resume_breakpoint when one is already active. */
8075 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== nullptr);
8076 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
8078 infrun_debug_printf ("inserting step-resume breakpoint at %s",
8079 paddress (gdbarch
, sr_sal
.pc
));
8081 inferior_thread ()->control
.step_resume_breakpoint
8082 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
).release ();
8086 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
8087 struct symtab_and_line sr_sal
,
8088 struct frame_id sr_id
)
8090 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
8095 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
8096 This is used to skip a potential signal handler.
8098 This is called with the interrupted function's frame. The signal
8099 handler, when it returns, will resume the interrupted function at
8103 insert_hp_step_resume_breakpoint_at_frame (frame_info_ptr return_frame
)
8105 gdb_assert (return_frame
!= nullptr);
8107 struct gdbarch
*gdbarch
= get_frame_arch (return_frame
);
8109 symtab_and_line sr_sal
;
8110 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
8111 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
8112 sr_sal
.pspace
= get_frame_program_space (return_frame
);
8114 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
8115 get_stack_frame_id (return_frame
),
8119 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
8120 is used to skip a function after stepping into it (for "next" or if
8121 the called function has no debugging information).
8123 The current function has almost always been reached by single
8124 stepping a call or return instruction. NEXT_FRAME belongs to the
8125 current function, and the breakpoint will be set at the caller's
8128 This is a separate function rather than reusing
8129 insert_hp_step_resume_breakpoint_at_frame in order to avoid
8130 get_prev_frame, which may stop prematurely (see the implementation
8131 of frame_unwind_caller_id for an example). */
8134 insert_step_resume_breakpoint_at_caller (frame_info_ptr next_frame
)
8136 /* We shouldn't have gotten here if we don't know where the call site
8138 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
8140 struct gdbarch
*gdbarch
= frame_unwind_caller_arch (next_frame
);
8142 symtab_and_line sr_sal
;
8143 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
8144 frame_unwind_caller_pc (next_frame
));
8145 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
8146 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
8148 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
8149 frame_unwind_caller_id (next_frame
));
8152 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
8153 new breakpoint at the target of a jmp_buf. The handling of
8154 longjmp-resume uses the same mechanisms used for handling
8155 "step-resume" breakpoints. */
8158 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8160 /* There should never be more than one longjmp-resume breakpoint per
8161 thread, so we should never be setting a new
8162 longjmp_resume_breakpoint when one is already active. */
8163 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== nullptr);
8165 infrun_debug_printf ("inserting longjmp-resume breakpoint at %s",
8166 paddress (gdbarch
, pc
));
8168 inferior_thread ()->control
.exception_resume_breakpoint
=
8169 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
).release ();
8172 /* Insert an exception resume breakpoint. TP is the thread throwing
8173 the exception. The block B is the block of the unwinder debug hook
8174 function. FRAME is the frame corresponding to the call to this
8175 function. SYM is the symbol of the function argument holding the
8176 target PC of the exception. */
8179 insert_exception_resume_breakpoint (struct thread_info
*tp
,
8180 const struct block
*b
,
8181 frame_info_ptr frame
,
8186 struct block_symbol vsym
;
8187 struct value
*value
;
8189 struct breakpoint
*bp
;
8191 vsym
= lookup_symbol_search_name (sym
->search_name (),
8193 value
= read_var_value (vsym
.symbol
, vsym
.block
, frame
);
8194 /* If the value was optimized out, revert to the old behavior. */
8195 if (! value
->optimized_out ())
8197 handler
= value_as_address (value
);
8199 infrun_debug_printf ("exception resume at %lx",
8200 (unsigned long) handler
);
8202 /* set_momentary_breakpoint_at_pc creates a thread-specific
8203 breakpoint for the current inferior thread. */
8204 gdb_assert (tp
== inferior_thread ());
8205 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8207 bp_exception_resume
).release ();
8209 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
8212 tp
->control
.exception_resume_breakpoint
= bp
;
8215 catch (const gdb_exception_error
&e
)
8217 /* We want to ignore errors here. */
8221 /* A helper for check_exception_resume that sets an
8222 exception-breakpoint based on a SystemTap probe. */
8225 insert_exception_resume_from_probe (struct thread_info
*tp
,
8226 const struct bound_probe
*probe
,
8227 frame_info_ptr frame
)
8229 struct value
*arg_value
;
8231 struct breakpoint
*bp
;
8233 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
8237 handler
= value_as_address (arg_value
);
8239 infrun_debug_printf ("exception resume at %s",
8240 paddress (probe
->objfile
->arch (), handler
));
8242 /* set_momentary_breakpoint_at_pc creates a thread-specific breakpoint
8243 for the current inferior thread. */
8244 gdb_assert (tp
== inferior_thread ());
8245 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8246 handler
, bp_exception_resume
).release ();
8247 tp
->control
.exception_resume_breakpoint
= bp
;
8250 /* This is called when an exception has been intercepted. Check to
8251 see whether the exception's destination is of interest, and if so,
8252 set an exception resume breakpoint there. */
8255 check_exception_resume (struct execution_control_state
*ecs
,
8256 frame_info_ptr frame
)
8258 struct bound_probe probe
;
8259 struct symbol
*func
;
8261 /* First see if this exception unwinding breakpoint was set via a
8262 SystemTap probe point. If so, the probe has two arguments: the
8263 CFA and the HANDLER. We ignore the CFA, extract the handler, and
8264 set a breakpoint there. */
8265 probe
= find_probe_by_pc (get_frame_pc (frame
));
8268 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
8272 func
= get_frame_function (frame
);
8278 const struct block
*b
;
8281 /* The exception breakpoint is a thread-specific breakpoint on
8282 the unwinder's debug hook, declared as:
8284 void _Unwind_DebugHook (void *cfa, void *handler);
8286 The CFA argument indicates the frame to which control is
8287 about to be transferred. HANDLER is the destination PC.
8289 We ignore the CFA and set a temporary breakpoint at HANDLER.
8290 This is not extremely efficient but it avoids issues in gdb
8291 with computing the DWARF CFA, and it also works even in weird
8292 cases such as throwing an exception from inside a signal
8295 b
= func
->value_block ();
8296 for (struct symbol
*sym
: block_iterator_range (b
))
8298 if (!sym
->is_argument ())
8305 insert_exception_resume_breakpoint (ecs
->event_thread
,
8311 catch (const gdb_exception_error
&e
)
8317 stop_waiting (struct execution_control_state
*ecs
)
8319 infrun_debug_printf ("stop_waiting");
8321 /* Let callers know we don't want to wait for the inferior anymore. */
8322 ecs
->wait_some_more
= 0;
8325 /* Like keep_going, but passes the signal to the inferior, even if the
8326 signal is set to nopass. */
8329 keep_going_pass_signal (struct execution_control_state
*ecs
)
8331 gdb_assert (ecs
->event_thread
->ptid
== inferior_ptid
);
8332 gdb_assert (!ecs
->event_thread
->resumed ());
8334 /* Save the pc before execution, to compare with pc after stop. */
8335 ecs
->event_thread
->prev_pc
8336 = regcache_read_pc_protected (get_thread_regcache (ecs
->event_thread
));
8338 if (ecs
->event_thread
->control
.trap_expected
)
8340 struct thread_info
*tp
= ecs
->event_thread
;
8342 infrun_debug_printf ("%s has trap_expected set, "
8343 "resuming to collect trap",
8344 tp
->ptid
.to_string ().c_str ());
8346 /* We haven't yet gotten our trap, and either: intercepted a
8347 non-signal event (e.g., a fork); or took a signal which we
8348 are supposed to pass through to the inferior. Simply
8350 resume (ecs
->event_thread
->stop_signal ());
8352 else if (step_over_info_valid_p ())
8354 /* Another thread is stepping over a breakpoint in-line. If
8355 this thread needs a step-over too, queue the request. In
8356 either case, this resume must be deferred for later. */
8357 struct thread_info
*tp
= ecs
->event_thread
;
8359 if (ecs
->hit_singlestep_breakpoint
8360 || thread_still_needs_step_over (tp
))
8362 infrun_debug_printf ("step-over already in progress: "
8363 "step-over for %s deferred",
8364 tp
->ptid
.to_string ().c_str ());
8365 global_thread_step_over_chain_enqueue (tp
);
8368 infrun_debug_printf ("step-over in progress: resume of %s deferred",
8369 tp
->ptid
.to_string ().c_str ());
8373 struct regcache
*regcache
= get_current_regcache ();
8376 step_over_what step_what
;
8378 /* Either the trap was not expected, but we are continuing
8379 anyway (if we got a signal, the user asked it be passed to
8382 We got our expected trap, but decided we should resume from
8385 We're going to run this baby now!
8387 Note that insert_breakpoints won't try to re-insert
8388 already inserted breakpoints. Therefore, we don't
8389 care if breakpoints were already inserted, or not. */
8391 /* If we need to step over a breakpoint, and we're not using
8392 displaced stepping to do so, insert all breakpoints
8393 (watchpoints, etc.) but the one we're stepping over, step one
8394 instruction, and then re-insert the breakpoint when that step
8397 step_what
= thread_still_needs_step_over (ecs
->event_thread
);
8399 remove_bp
= (ecs
->hit_singlestep_breakpoint
8400 || (step_what
& STEP_OVER_BREAKPOINT
));
8401 remove_wps
= (step_what
& STEP_OVER_WATCHPOINT
);
8403 /* We can't use displaced stepping if we need to step past a
8404 watchpoint. The instruction copied to the scratch pad would
8405 still trigger the watchpoint. */
8407 && (remove_wps
|| !use_displaced_stepping (ecs
->event_thread
)))
8409 set_step_over_info (regcache
->aspace (),
8410 regcache_read_pc (regcache
), remove_wps
,
8411 ecs
->event_thread
->global_num
);
8413 else if (remove_wps
)
8414 set_step_over_info (nullptr, 0, remove_wps
, -1);
8416 /* If we now need to do an in-line step-over, we need to stop
8417 all other threads. Note this must be done before
8418 insert_breakpoints below, because that removes the breakpoint
8419 we're about to step over, otherwise other threads could miss
8421 if (step_over_info_valid_p () && target_is_non_stop_p ())
8422 stop_all_threads ("starting in-line step-over");
8424 /* Stop stepping if inserting breakpoints fails. */
8427 insert_breakpoints ();
8429 catch (const gdb_exception_error
&e
)
8431 exception_print (gdb_stderr
, e
);
8433 clear_step_over_info ();
8437 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
8439 resume (ecs
->event_thread
->stop_signal ());
8442 prepare_to_wait (ecs
);
8445 /* Called when we should continue running the inferior, because the
8446 current event doesn't cause a user visible stop. This does the
8447 resuming part; waiting for the next event is done elsewhere. */
8450 keep_going (struct execution_control_state
*ecs
)
8452 if (ecs
->event_thread
->control
.trap_expected
8453 && ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
8454 ecs
->event_thread
->control
.trap_expected
= 0;
8456 if (!signal_program
[ecs
->event_thread
->stop_signal ()])
8457 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
8458 keep_going_pass_signal (ecs
);
8461 /* This function normally comes after a resume, before
8462 handle_inferior_event exits. It takes care of any last bits of
8463 housekeeping, and sets the all-important wait_some_more flag. */
8466 prepare_to_wait (struct execution_control_state
*ecs
)
8468 infrun_debug_printf ("prepare_to_wait");
8470 ecs
->wait_some_more
= 1;
8472 /* If the target can't async, emulate it by marking the infrun event
8473 handler such that as soon as we get back to the event-loop, we
8474 immediately end up in fetch_inferior_event again calling
8476 if (!target_can_async_p ())
8477 mark_infrun_async_event_handler ();
8480 /* We are done with the step range of a step/next/si/ni command.
8481 Called once for each n of a "step n" operation. */
8484 end_stepping_range (struct execution_control_state
*ecs
)
8486 ecs
->event_thread
->control
.stop_step
= 1;
8490 /* Several print_*_reason functions to print why the inferior has stopped.
8491 We always print something when the inferior exits, or receives a signal.
8492 The rest of the cases are dealt with later on in normal_stop and
8493 print_it_typical. Ideally there should be a call to one of these
8494 print_*_reason functions functions from handle_inferior_event each time
8495 stop_waiting is called.
8497 Note that we don't call these directly, instead we delegate that to
8498 the interpreters, through observers. Interpreters then call these
8499 with whatever uiout is right. */
8502 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8504 annotate_signalled ();
8505 if (uiout
->is_mi_like_p ())
8507 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
8508 uiout
->text ("\nProgram terminated with signal ");
8509 annotate_signal_name ();
8510 uiout
->field_string ("signal-name",
8511 gdb_signal_to_name (siggnal
));
8512 annotate_signal_name_end ();
8514 annotate_signal_string ();
8515 uiout
->field_string ("signal-meaning",
8516 gdb_signal_to_string (siggnal
));
8517 annotate_signal_string_end ();
8518 uiout
->text (".\n");
8519 uiout
->text ("The program no longer exists.\n");
8523 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
8525 struct inferior
*inf
= current_inferior ();
8526 std::string pidstr
= target_pid_to_str (ptid_t (inf
->pid
));
8528 annotate_exited (exitstatus
);
8531 if (uiout
->is_mi_like_p ())
8532 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXITED
));
8533 std::string exit_code_str
8534 = string_printf ("0%o", (unsigned int) exitstatus
);
8535 uiout
->message ("[Inferior %s (%s) exited with code %pF]\n",
8536 plongest (inf
->num
), pidstr
.c_str (),
8537 string_field ("exit-code", exit_code_str
.c_str ()));
8541 if (uiout
->is_mi_like_p ())
8543 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
8544 uiout
->message ("[Inferior %s (%s) exited normally]\n",
8545 plongest (inf
->num
), pidstr
.c_str ());
8550 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8552 struct thread_info
*thr
= inferior_thread ();
8554 infrun_debug_printf ("signal = %s", gdb_signal_to_string (siggnal
));
8558 if (uiout
->is_mi_like_p ())
8560 else if (show_thread_that_caused_stop ())
8562 uiout
->text ("\nThread ");
8563 uiout
->field_string ("thread-id", print_thread_id (thr
));
8565 const char *name
= thread_name (thr
);
8566 if (name
!= nullptr)
8568 uiout
->text (" \"");
8569 uiout
->field_string ("name", name
);
8574 uiout
->text ("\nProgram");
8576 if (siggnal
== GDB_SIGNAL_0
&& !uiout
->is_mi_like_p ())
8577 uiout
->text (" stopped");
8580 uiout
->text (" received signal ");
8581 annotate_signal_name ();
8582 if (uiout
->is_mi_like_p ())
8584 ("reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
8585 uiout
->field_string ("signal-name", gdb_signal_to_name (siggnal
));
8586 annotate_signal_name_end ();
8588 annotate_signal_string ();
8589 uiout
->field_string ("signal-meaning", gdb_signal_to_string (siggnal
));
8591 struct regcache
*regcache
= get_current_regcache ();
8592 struct gdbarch
*gdbarch
= regcache
->arch ();
8593 if (gdbarch_report_signal_info_p (gdbarch
))
8594 gdbarch_report_signal_info (gdbarch
, uiout
, siggnal
);
8596 annotate_signal_string_end ();
8598 uiout
->text (".\n");
8602 print_no_history_reason (struct ui_out
*uiout
)
8604 if (uiout
->is_mi_like_p ())
8605 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_NO_HISTORY
));
8607 uiout
->text ("\nNo more reverse-execution history.\n");
8610 /* Print current location without a level number, if we have changed
8611 functions or hit a breakpoint. Print source line if we have one.
8612 bpstat_print contains the logic deciding in detail what to print,
8613 based on the event(s) that just occurred. */
8616 print_stop_location (const target_waitstatus
&ws
)
8619 enum print_what source_flag
;
8620 int do_frame_printing
= 1;
8621 struct thread_info
*tp
= inferior_thread ();
8623 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
.kind ());
8627 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
8628 should) carry around the function and does (or should) use
8629 that when doing a frame comparison. */
8630 if (tp
->control
.stop_step
8631 && (tp
->control
.step_frame_id
8632 == get_frame_id (get_current_frame ()))
8633 && (tp
->control
.step_start_function
8634 == find_pc_function (tp
->stop_pc ())))
8636 /* Finished step, just print source line. */
8637 source_flag
= SRC_LINE
;
8641 /* Print location and source line. */
8642 source_flag
= SRC_AND_LOC
;
8645 case PRINT_SRC_AND_LOC
:
8646 /* Print location and source line. */
8647 source_flag
= SRC_AND_LOC
;
8649 case PRINT_SRC_ONLY
:
8650 source_flag
= SRC_LINE
;
8653 /* Something bogus. */
8654 source_flag
= SRC_LINE
;
8655 do_frame_printing
= 0;
8658 internal_error (_("Unknown value."));
8661 /* The behavior of this routine with respect to the source
8663 SRC_LINE: Print only source line
8664 LOCATION: Print only location
8665 SRC_AND_LOC: Print location and source line. */
8666 if (do_frame_printing
)
8667 print_stack_frame (get_selected_frame (nullptr), 0, source_flag
, 1);
8673 print_stop_event (struct ui_out
*uiout
, bool displays
)
8675 struct target_waitstatus last
;
8676 struct thread_info
*tp
;
8678 get_last_target_status (nullptr, nullptr, &last
);
8681 scoped_restore save_uiout
= make_scoped_restore (¤t_uiout
, uiout
);
8683 print_stop_location (last
);
8685 /* Display the auto-display expressions. */
8690 tp
= inferior_thread ();
8691 if (tp
->thread_fsm () != nullptr
8692 && tp
->thread_fsm ()->finished_p ())
8694 struct return_value_info
*rv
;
8696 rv
= tp
->thread_fsm ()->return_value ();
8698 print_return_value (uiout
, rv
);
8705 maybe_remove_breakpoints (void)
8707 if (!breakpoints_should_be_inserted_now () && target_has_execution ())
8709 if (remove_breakpoints ())
8711 target_terminal::ours_for_output ();
8712 gdb_printf (_("Cannot remove breakpoints because "
8713 "program is no longer writable.\nFurther "
8714 "execution is probably impossible.\n"));
8719 /* The execution context that just caused a normal stop. */
8725 DISABLE_COPY_AND_ASSIGN (stop_context
);
8727 bool changed () const;
8732 /* The event PTID. */
8736 /* If stopp for a thread event, this is the thread that caused the
8738 thread_info_ref thread
;
8740 /* The inferior that caused the stop. */
8744 /* Initializes a new stop context. If stopped for a thread event, this
8745 takes a strong reference to the thread. */
8747 stop_context::stop_context ()
8749 stop_id
= get_stop_id ();
8750 ptid
= inferior_ptid
;
8751 inf_num
= current_inferior ()->num
;
8753 if (inferior_ptid
!= null_ptid
)
8755 /* Take a strong reference so that the thread can't be deleted
8757 thread
= thread_info_ref::new_reference (inferior_thread ());
8761 /* Return true if the current context no longer matches the saved stop
8765 stop_context::changed () const
8767 if (ptid
!= inferior_ptid
)
8769 if (inf_num
!= current_inferior ()->num
)
8771 if (thread
!= nullptr && thread
->state
!= THREAD_STOPPED
)
8773 if (get_stop_id () != stop_id
)
8783 struct target_waitstatus last
;
8785 get_last_target_status (nullptr, nullptr, &last
);
8789 /* If an exception is thrown from this point on, make sure to
8790 propagate GDB's knowledge of the executing state to the
8791 frontend/user running state. A QUIT is an easy exception to see
8792 here, so do this before any filtered output. */
8794 ptid_t finish_ptid
= null_ptid
;
8797 finish_ptid
= minus_one_ptid
;
8798 else if (last
.kind () == TARGET_WAITKIND_SIGNALLED
8799 || last
.kind () == TARGET_WAITKIND_EXITED
)
8801 /* On some targets, we may still have live threads in the
8802 inferior when we get a process exit event. E.g., for
8803 "checkpoint", when the current checkpoint/fork exits,
8804 linux-fork.c automatically switches to another fork from
8805 within target_mourn_inferior. */
8806 if (inferior_ptid
!= null_ptid
)
8807 finish_ptid
= ptid_t (inferior_ptid
.pid ());
8809 else if (last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
8810 finish_ptid
= inferior_ptid
;
8812 gdb::optional
<scoped_finish_thread_state
> maybe_finish_thread_state
;
8813 if (finish_ptid
!= null_ptid
)
8815 maybe_finish_thread_state
.emplace
8816 (user_visible_resume_target (finish_ptid
), finish_ptid
);
8819 /* As we're presenting a stop, and potentially removing breakpoints,
8820 update the thread list so we can tell whether there are threads
8821 running on the target. With target remote, for example, we can
8822 only learn about new threads when we explicitly update the thread
8823 list. Do this before notifying the interpreters about signal
8824 stops, end of stepping ranges, etc., so that the "new thread"
8825 output is emitted before e.g., "Program received signal FOO",
8826 instead of after. */
8827 update_thread_list ();
8829 if (last
.kind () == TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
8830 gdb::observers::signal_received
.notify (inferior_thread ()->stop_signal ());
8832 /* As with the notification of thread events, we want to delay
8833 notifying the user that we've switched thread context until
8834 the inferior actually stops.
8836 There's no point in saying anything if the inferior has exited.
8837 Note that SIGNALLED here means "exited with a signal", not
8838 "received a signal".
8840 Also skip saying anything in non-stop mode. In that mode, as we
8841 don't want GDB to switch threads behind the user's back, to avoid
8842 races where the user is typing a command to apply to thread x,
8843 but GDB switches to thread y before the user finishes entering
8844 the command, fetch_inferior_event installs a cleanup to restore
8845 the current thread back to the thread the user had selected right
8846 after this event is handled, so we're not really switching, only
8847 informing of a stop. */
8850 if ((last
.kind () != TARGET_WAITKIND_SIGNALLED
8851 && last
.kind () != TARGET_WAITKIND_EXITED
8852 && last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
8853 && target_has_execution ()
8854 && previous_thread
!= inferior_thread ())
8856 SWITCH_THRU_ALL_UIS ()
8858 target_terminal::ours_for_output ();
8859 gdb_printf (_("[Switching to %s]\n"),
8860 target_pid_to_str (inferior_ptid
).c_str ());
8861 annotate_thread_changed ();
8865 update_previous_thread ();
8868 if (last
.kind () == TARGET_WAITKIND_NO_RESUMED
)
8870 SWITCH_THRU_ALL_UIS ()
8871 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
8873 target_terminal::ours_for_output ();
8874 gdb_printf (_("No unwaited-for children left.\n"));
8878 /* Note: this depends on the update_thread_list call above. */
8879 maybe_remove_breakpoints ();
8881 /* If an auto-display called a function and that got a signal,
8882 delete that auto-display to avoid an infinite recursion. */
8884 if (stopped_by_random_signal
)
8885 disable_current_display ();
8887 SWITCH_THRU_ALL_UIS ()
8889 async_enable_stdin ();
8892 /* Let the user/frontend see the threads as stopped. */
8893 maybe_finish_thread_state
.reset ();
8895 /* Select innermost stack frame - i.e., current frame is frame 0,
8896 and current location is based on that. Handle the case where the
8897 dummy call is returning after being stopped. E.g. the dummy call
8898 previously hit a breakpoint. (If the dummy call returns
8899 normally, we won't reach here.) Do this before the stop hook is
8900 run, so that it doesn't get to see the temporary dummy frame,
8901 which is not where we'll present the stop. */
8902 if (has_stack_frames ())
8904 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
8906 /* Pop the empty frame that contains the stack dummy. This
8907 also restores inferior state prior to the call (struct
8908 infcall_suspend_state). */
8909 frame_info_ptr frame
= get_current_frame ();
8911 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
8913 /* frame_pop calls reinit_frame_cache as the last thing it
8914 does which means there's now no selected frame. */
8917 select_frame (get_current_frame ());
8919 /* Set the current source location. */
8920 set_current_sal_from_frame (get_current_frame ());
8923 /* Look up the hook_stop and run it (CLI internally handles problem
8924 of stop_command's pre-hook not existing). */
8925 stop_context saved_context
;
8929 execute_cmd_pre_hook (stop_command
);
8931 catch (const gdb_exception_error
&ex
)
8933 exception_fprintf (gdb_stderr
, ex
,
8934 "Error while running hook_stop:\n");
8937 /* If the stop hook resumes the target, then there's no point in
8938 trying to notify about the previous stop; its context is
8939 gone. Likewise if the command switches thread or inferior --
8940 the observers would print a stop for the wrong
8942 if (saved_context
.changed ())
8945 /* Notify observers about the stop. This is where the interpreters
8946 print the stop event. */
8947 if (inferior_ptid
!= null_ptid
)
8948 gdb::observers::normal_stop
.notify (inferior_thread ()->control
.stop_bpstat
,
8951 gdb::observers::normal_stop
.notify (nullptr, stop_print_frame
);
8953 annotate_stopped ();
8955 if (target_has_execution ())
8957 if (last
.kind () != TARGET_WAITKIND_SIGNALLED
8958 && last
.kind () != TARGET_WAITKIND_EXITED
8959 && last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
8960 /* Delete the breakpoint we stopped at, if it wants to be deleted.
8961 Delete any breakpoint that is to be deleted at the next stop. */
8962 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
8969 signal_stop_state (int signo
)
8971 return signal_stop
[signo
];
8975 signal_print_state (int signo
)
8977 return signal_print
[signo
];
8981 signal_pass_state (int signo
)
8983 return signal_program
[signo
];
8987 signal_cache_update (int signo
)
8991 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
8992 signal_cache_update (signo
);
8997 signal_pass
[signo
] = (signal_stop
[signo
] == 0
8998 && signal_print
[signo
] == 0
8999 && signal_program
[signo
] == 1
9000 && signal_catch
[signo
] == 0);
9004 signal_stop_update (int signo
, int state
)
9006 int ret
= signal_stop
[signo
];
9008 signal_stop
[signo
] = state
;
9009 signal_cache_update (signo
);
9014 signal_print_update (int signo
, int state
)
9016 int ret
= signal_print
[signo
];
9018 signal_print
[signo
] = state
;
9019 signal_cache_update (signo
);
9024 signal_pass_update (int signo
, int state
)
9026 int ret
= signal_program
[signo
];
9028 signal_program
[signo
] = state
;
9029 signal_cache_update (signo
);
9033 /* Update the global 'signal_catch' from INFO and notify the
9037 signal_catch_update (const unsigned int *info
)
9041 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
9042 signal_catch
[i
] = info
[i
] > 0;
9043 signal_cache_update (-1);
9044 target_pass_signals (signal_pass
);
9048 sig_print_header (void)
9050 gdb_printf (_("Signal Stop\tPrint\tPass "
9051 "to program\tDescription\n"));
9055 sig_print_info (enum gdb_signal oursig
)
9057 const char *name
= gdb_signal_to_name (oursig
);
9058 int name_padding
= 13 - strlen (name
);
9060 if (name_padding
<= 0)
9063 gdb_printf ("%s", name
);
9064 gdb_printf ("%*.*s ", name_padding
, name_padding
, " ");
9065 gdb_printf ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
9066 gdb_printf ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
9067 gdb_printf ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
9068 gdb_printf ("%s\n", gdb_signal_to_string (oursig
));
9071 /* Specify how various signals in the inferior should be handled. */
9074 handle_command (const char *args
, int from_tty
)
9076 int digits
, wordlen
;
9077 int sigfirst
, siglast
;
9078 enum gdb_signal oursig
;
9081 if (args
== nullptr)
9083 error_no_arg (_("signal to handle"));
9086 /* Allocate and zero an array of flags for which signals to handle. */
9088 const size_t nsigs
= GDB_SIGNAL_LAST
;
9089 unsigned char sigs
[nsigs
] {};
9091 /* Break the command line up into args. */
9093 gdb_argv
built_argv (args
);
9095 /* Walk through the args, looking for signal oursigs, signal names, and
9096 actions. Signal numbers and signal names may be interspersed with
9097 actions, with the actions being performed for all signals cumulatively
9098 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
9100 for (char *arg
: built_argv
)
9102 wordlen
= strlen (arg
);
9103 for (digits
= 0; isdigit (arg
[digits
]); digits
++)
9107 sigfirst
= siglast
= -1;
9109 if (wordlen
>= 1 && !strncmp (arg
, "all", wordlen
))
9111 /* Apply action to all signals except those used by the
9112 debugger. Silently skip those. */
9115 siglast
= nsigs
- 1;
9117 else if (wordlen
>= 1 && !strncmp (arg
, "stop", wordlen
))
9119 SET_SIGS (nsigs
, sigs
, signal_stop
);
9120 SET_SIGS (nsigs
, sigs
, signal_print
);
9122 else if (wordlen
>= 1 && !strncmp (arg
, "ignore", wordlen
))
9124 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9126 else if (wordlen
>= 2 && !strncmp (arg
, "print", wordlen
))
9128 SET_SIGS (nsigs
, sigs
, signal_print
);
9130 else if (wordlen
>= 2 && !strncmp (arg
, "pass", wordlen
))
9132 SET_SIGS (nsigs
, sigs
, signal_program
);
9134 else if (wordlen
>= 3 && !strncmp (arg
, "nostop", wordlen
))
9136 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9138 else if (wordlen
>= 3 && !strncmp (arg
, "noignore", wordlen
))
9140 SET_SIGS (nsigs
, sigs
, signal_program
);
9142 else if (wordlen
>= 4 && !strncmp (arg
, "noprint", wordlen
))
9144 UNSET_SIGS (nsigs
, sigs
, signal_print
);
9145 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9147 else if (wordlen
>= 4 && !strncmp (arg
, "nopass", wordlen
))
9149 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9151 else if (digits
> 0)
9153 /* It is numeric. The numeric signal refers to our own
9154 internal signal numbering from target.h, not to host/target
9155 signal number. This is a feature; users really should be
9156 using symbolic names anyway, and the common ones like
9157 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
9159 sigfirst
= siglast
= (int)
9160 gdb_signal_from_command (atoi (arg
));
9161 if (arg
[digits
] == '-')
9164 gdb_signal_from_command (atoi (arg
+ digits
+ 1));
9166 if (sigfirst
> siglast
)
9168 /* Bet he didn't figure we'd think of this case... */
9169 std::swap (sigfirst
, siglast
);
9174 oursig
= gdb_signal_from_name (arg
);
9175 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
9177 sigfirst
= siglast
= (int) oursig
;
9181 /* Not a number and not a recognized flag word => complain. */
9182 error (_("Unrecognized or ambiguous flag word: \"%s\"."), arg
);
9186 /* If any signal numbers or symbol names were found, set flags for
9187 which signals to apply actions to. */
9189 for (int signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
9191 switch ((enum gdb_signal
) signum
)
9193 case GDB_SIGNAL_TRAP
:
9194 case GDB_SIGNAL_INT
:
9195 if (!allsigs
&& !sigs
[signum
])
9197 if (query (_("%s is used by the debugger.\n\
9198 Are you sure you want to change it? "),
9199 gdb_signal_to_name ((enum gdb_signal
) signum
)))
9204 gdb_printf (_("Not confirmed, unchanged.\n"));
9208 case GDB_SIGNAL_DEFAULT
:
9209 case GDB_SIGNAL_UNKNOWN
:
9210 /* Make sure that "all" doesn't print these. */
9219 for (int signum
= 0; signum
< nsigs
; signum
++)
9222 signal_cache_update (-1);
9223 target_pass_signals (signal_pass
);
9224 target_program_signals (signal_program
);
9228 /* Show the results. */
9229 sig_print_header ();
9230 for (; signum
< nsigs
; signum
++)
9232 sig_print_info ((enum gdb_signal
) signum
);
9239 /* Complete the "handle" command. */
9242 handle_completer (struct cmd_list_element
*ignore
,
9243 completion_tracker
&tracker
,
9244 const char *text
, const char *word
)
9246 static const char * const keywords
[] =
9260 signal_completer (ignore
, tracker
, text
, word
);
9261 complete_on_enum (tracker
, keywords
, word
, word
);
9265 gdb_signal_from_command (int num
)
9267 if (num
>= 1 && num
<= 15)
9268 return (enum gdb_signal
) num
;
9269 error (_("Only signals 1-15 are valid as numeric signals.\n\
9270 Use \"info signals\" for a list of symbolic signals."));
9273 /* Print current contents of the tables set by the handle command.
9274 It is possible we should just be printing signals actually used
9275 by the current target (but for things to work right when switching
9276 targets, all signals should be in the signal tables). */
9279 info_signals_command (const char *signum_exp
, int from_tty
)
9281 enum gdb_signal oursig
;
9283 sig_print_header ();
9287 /* First see if this is a symbol name. */
9288 oursig
= gdb_signal_from_name (signum_exp
);
9289 if (oursig
== GDB_SIGNAL_UNKNOWN
)
9291 /* No, try numeric. */
9293 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
9295 sig_print_info (oursig
);
9300 /* These ugly casts brought to you by the native VAX compiler. */
9301 for (oursig
= GDB_SIGNAL_FIRST
;
9302 (int) oursig
< (int) GDB_SIGNAL_LAST
;
9303 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
9307 if (oursig
!= GDB_SIGNAL_UNKNOWN
9308 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
9309 sig_print_info (oursig
);
9312 gdb_printf (_("\nUse the \"handle\" command "
9313 "to change these tables.\n"));
9316 /* The $_siginfo convenience variable is a bit special. We don't know
9317 for sure the type of the value until we actually have a chance to
9318 fetch the data. The type can change depending on gdbarch, so it is
9319 also dependent on which thread you have selected.
9321 1. making $_siginfo be an internalvar that creates a new value on
9324 2. making the value of $_siginfo be an lval_computed value. */
9326 /* This function implements the lval_computed support for reading a
9330 siginfo_value_read (struct value
*v
)
9332 LONGEST transferred
;
9334 /* If we can access registers, so can we access $_siginfo. Likewise
9336 validate_registers_access ();
9339 target_read (current_inferior ()->top_target (),
9340 TARGET_OBJECT_SIGNAL_INFO
,
9342 v
->contents_all_raw ().data (),
9344 v
->type ()->length ());
9346 if (transferred
!= v
->type ()->length ())
9347 error (_("Unable to read siginfo"));
9350 /* This function implements the lval_computed support for writing a
9354 siginfo_value_write (struct value
*v
, struct value
*fromval
)
9356 LONGEST transferred
;
9358 /* If we can access registers, so can we access $_siginfo. Likewise
9360 validate_registers_access ();
9362 transferred
= target_write (current_inferior ()->top_target (),
9363 TARGET_OBJECT_SIGNAL_INFO
,
9365 fromval
->contents_all_raw ().data (),
9367 fromval
->type ()->length ());
9369 if (transferred
!= fromval
->type ()->length ())
9370 error (_("Unable to write siginfo"));
9373 static const struct lval_funcs siginfo_value_funcs
=
9379 /* Return a new value with the correct type for the siginfo object of
9380 the current thread using architecture GDBARCH. Return a void value
9381 if there's no object available. */
9383 static struct value
*
9384 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
9387 if (target_has_stack ()
9388 && inferior_ptid
!= null_ptid
9389 && gdbarch_get_siginfo_type_p (gdbarch
))
9391 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9393 return value::allocate_computed (type
, &siginfo_value_funcs
, nullptr);
9396 return value::allocate (builtin_type (gdbarch
)->builtin_void
);
9400 /* infcall_suspend_state contains state about the program itself like its
9401 registers and any signal it received when it last stopped.
9402 This state must be restored regardless of how the inferior function call
9403 ends (either successfully, or after it hits a breakpoint or signal)
9404 if the program is to properly continue where it left off. */
9406 class infcall_suspend_state
9409 /* Capture state from GDBARCH, TP, and REGCACHE that must be restored
9410 once the inferior function call has finished. */
9411 infcall_suspend_state (struct gdbarch
*gdbarch
,
9412 const struct thread_info
*tp
,
9413 struct regcache
*regcache
)
9414 : m_registers (new readonly_detached_regcache (*regcache
))
9416 tp
->save_suspend_to (m_thread_suspend
);
9418 gdb::unique_xmalloc_ptr
<gdb_byte
> siginfo_data
;
9420 if (gdbarch_get_siginfo_type_p (gdbarch
))
9422 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9423 size_t len
= type
->length ();
9425 siginfo_data
.reset ((gdb_byte
*) xmalloc (len
));
9427 if (target_read (current_inferior ()->top_target (),
9428 TARGET_OBJECT_SIGNAL_INFO
, nullptr,
9429 siginfo_data
.get (), 0, len
) != len
)
9431 /* Errors ignored. */
9432 siginfo_data
.reset (nullptr);
9438 m_siginfo_gdbarch
= gdbarch
;
9439 m_siginfo_data
= std::move (siginfo_data
);
9443 /* Return a pointer to the stored register state. */
9445 readonly_detached_regcache
*registers () const
9447 return m_registers
.get ();
9450 /* Restores the stored state into GDBARCH, TP, and REGCACHE. */
9452 void restore (struct gdbarch
*gdbarch
,
9453 struct thread_info
*tp
,
9454 struct regcache
*regcache
) const
9456 tp
->restore_suspend_from (m_thread_suspend
);
9458 if (m_siginfo_gdbarch
== gdbarch
)
9460 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9462 /* Errors ignored. */
9463 target_write (current_inferior ()->top_target (),
9464 TARGET_OBJECT_SIGNAL_INFO
, nullptr,
9465 m_siginfo_data
.get (), 0, type
->length ());
9468 /* The inferior can be gone if the user types "print exit(0)"
9469 (and perhaps other times). */
9470 if (target_has_execution ())
9471 /* NB: The register write goes through to the target. */
9472 regcache
->restore (registers ());
9476 /* How the current thread stopped before the inferior function call was
9478 struct thread_suspend_state m_thread_suspend
;
9480 /* The registers before the inferior function call was executed. */
9481 std::unique_ptr
<readonly_detached_regcache
> m_registers
;
9483 /* Format of SIGINFO_DATA or NULL if it is not present. */
9484 struct gdbarch
*m_siginfo_gdbarch
= nullptr;
9486 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
9487 gdbarch_get_siginfo_type ()->length (). For different gdbarch the
9488 content would be invalid. */
9489 gdb::unique_xmalloc_ptr
<gdb_byte
> m_siginfo_data
;
9492 infcall_suspend_state_up
9493 save_infcall_suspend_state ()
9495 struct thread_info
*tp
= inferior_thread ();
9496 struct regcache
*regcache
= get_current_regcache ();
9497 struct gdbarch
*gdbarch
= regcache
->arch ();
9499 infcall_suspend_state_up inf_state
9500 (new struct infcall_suspend_state (gdbarch
, tp
, regcache
));
9502 /* Having saved the current state, adjust the thread state, discarding
9503 any stop signal information. The stop signal is not useful when
9504 starting an inferior function call, and run_inferior_call will not use
9505 the signal due to its `proceed' call with GDB_SIGNAL_0. */
9506 tp
->set_stop_signal (GDB_SIGNAL_0
);
9511 /* Restore inferior session state to INF_STATE. */
9514 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9516 struct thread_info
*tp
= inferior_thread ();
9517 struct regcache
*regcache
= get_current_regcache ();
9518 struct gdbarch
*gdbarch
= regcache
->arch ();
9520 inf_state
->restore (gdbarch
, tp
, regcache
);
9521 discard_infcall_suspend_state (inf_state
);
9525 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9530 readonly_detached_regcache
*
9531 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
9533 return inf_state
->registers ();
9536 /* infcall_control_state contains state regarding gdb's control of the
9537 inferior itself like stepping control. It also contains session state like
9538 the user's currently selected frame. */
9540 struct infcall_control_state
9542 struct thread_control_state thread_control
;
9543 struct inferior_control_state inferior_control
;
9546 enum stop_stack_kind stop_stack_dummy
= STOP_NONE
;
9547 int stopped_by_random_signal
= 0;
9549 /* ID and level of the selected frame when the inferior function
9551 struct frame_id selected_frame_id
{};
9552 int selected_frame_level
= -1;
9555 /* Save all of the information associated with the inferior<==>gdb
9558 infcall_control_state_up
9559 save_infcall_control_state ()
9561 infcall_control_state_up
inf_status (new struct infcall_control_state
);
9562 struct thread_info
*tp
= inferior_thread ();
9563 struct inferior
*inf
= current_inferior ();
9565 inf_status
->thread_control
= tp
->control
;
9566 inf_status
->inferior_control
= inf
->control
;
9568 tp
->control
.step_resume_breakpoint
= nullptr;
9569 tp
->control
.exception_resume_breakpoint
= nullptr;
9571 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
9572 chain. If caller's caller is walking the chain, they'll be happier if we
9573 hand them back the original chain when restore_infcall_control_state is
9575 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
9578 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
9579 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
9581 save_selected_frame (&inf_status
->selected_frame_id
,
9582 &inf_status
->selected_frame_level
);
9587 /* Restore inferior session state to INF_STATUS. */
9590 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
9592 struct thread_info
*tp
= inferior_thread ();
9593 struct inferior
*inf
= current_inferior ();
9595 if (tp
->control
.step_resume_breakpoint
)
9596 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
9598 if (tp
->control
.exception_resume_breakpoint
)
9599 tp
->control
.exception_resume_breakpoint
->disposition
9600 = disp_del_at_next_stop
;
9602 /* Handle the bpstat_copy of the chain. */
9603 bpstat_clear (&tp
->control
.stop_bpstat
);
9605 tp
->control
= inf_status
->thread_control
;
9606 inf
->control
= inf_status
->inferior_control
;
9609 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
9610 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
9612 if (target_has_stack ())
9614 restore_selected_frame (inf_status
->selected_frame_id
,
9615 inf_status
->selected_frame_level
);
9622 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
9624 if (inf_status
->thread_control
.step_resume_breakpoint
)
9625 inf_status
->thread_control
.step_resume_breakpoint
->disposition
9626 = disp_del_at_next_stop
;
9628 if (inf_status
->thread_control
.exception_resume_breakpoint
)
9629 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
9630 = disp_del_at_next_stop
;
9632 /* See save_infcall_control_state for info on stop_bpstat. */
9633 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
9641 clear_exit_convenience_vars (void)
9643 clear_internalvar (lookup_internalvar ("_exitsignal"));
9644 clear_internalvar (lookup_internalvar ("_exitcode"));
9648 /* User interface for reverse debugging:
9649 Set exec-direction / show exec-direction commands
9650 (returns error unless target implements to_set_exec_direction method). */
9652 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
9653 static const char exec_forward
[] = "forward";
9654 static const char exec_reverse
[] = "reverse";
9655 static const char *exec_direction
= exec_forward
;
9656 static const char *const exec_direction_names
[] = {
9663 set_exec_direction_func (const char *args
, int from_tty
,
9664 struct cmd_list_element
*cmd
)
9666 if (target_can_execute_reverse ())
9668 if (!strcmp (exec_direction
, exec_forward
))
9669 execution_direction
= EXEC_FORWARD
;
9670 else if (!strcmp (exec_direction
, exec_reverse
))
9671 execution_direction
= EXEC_REVERSE
;
9675 exec_direction
= exec_forward
;
9676 error (_("Target does not support this operation."));
9681 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
9682 struct cmd_list_element
*cmd
, const char *value
)
9684 switch (execution_direction
) {
9686 gdb_printf (out
, _("Forward.\n"));
9689 gdb_printf (out
, _("Reverse.\n"));
9692 internal_error (_("bogus execution_direction value: %d"),
9693 (int) execution_direction
);
9698 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
9699 struct cmd_list_element
*c
, const char *value
)
9701 gdb_printf (file
, _("Resuming the execution of threads "
9702 "of all processes is %s.\n"), value
);
9705 /* Implementation of `siginfo' variable. */
9707 static const struct internalvar_funcs siginfo_funcs
=
9713 /* Callback for infrun's target events source. This is marked when a
9714 thread has a pending status to process. */
9717 infrun_async_inferior_event_handler (gdb_client_data data
)
9719 clear_async_event_handler (infrun_async_inferior_event_token
);
9720 inferior_event_handler (INF_REG_EVENT
);
9727 /* Verify that when two threads with the same ptid exist (from two different
9728 targets) and one of them changes ptid, we only update inferior_ptid if
9729 it is appropriate. */
9732 infrun_thread_ptid_changed ()
9734 gdbarch
*arch
= current_inferior ()->gdbarch
;
9736 /* The thread which inferior_ptid represents changes ptid. */
9738 scoped_restore_current_pspace_and_thread restore
;
9740 scoped_mock_context
<test_target_ops
> target1 (arch
);
9741 scoped_mock_context
<test_target_ops
> target2 (arch
);
9743 ptid_t
old_ptid (111, 222);
9744 ptid_t
new_ptid (111, 333);
9746 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9747 target1
.mock_thread
.ptid
= old_ptid
;
9748 target1
.mock_inferior
.ptid_thread_map
.clear ();
9749 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
9751 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9752 target2
.mock_thread
.ptid
= old_ptid
;
9753 target2
.mock_inferior
.ptid_thread_map
.clear ();
9754 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
9756 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9757 set_current_inferior (&target1
.mock_inferior
);
9759 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9761 gdb_assert (inferior_ptid
== new_ptid
);
9764 /* A thread with the same ptid as inferior_ptid, but from another target,
9767 scoped_restore_current_pspace_and_thread restore
;
9769 scoped_mock_context
<test_target_ops
> target1 (arch
);
9770 scoped_mock_context
<test_target_ops
> target2 (arch
);
9772 ptid_t
old_ptid (111, 222);
9773 ptid_t
new_ptid (111, 333);
9775 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9776 target1
.mock_thread
.ptid
= old_ptid
;
9777 target1
.mock_inferior
.ptid_thread_map
.clear ();
9778 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
9780 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9781 target2
.mock_thread
.ptid
= old_ptid
;
9782 target2
.mock_inferior
.ptid_thread_map
.clear ();
9783 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
9785 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9786 set_current_inferior (&target2
.mock_inferior
);
9788 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9790 gdb_assert (inferior_ptid
== old_ptid
);
9794 } /* namespace selftests */
9796 #endif /* GDB_SELF_TEST */
9798 void _initialize_infrun ();
9800 _initialize_infrun ()
9802 struct cmd_list_element
*c
;
9804 /* Register extra event sources in the event loop. */
9805 infrun_async_inferior_event_token
9806 = create_async_event_handler (infrun_async_inferior_event_handler
, nullptr,
9809 cmd_list_element
*info_signals_cmd
9810 = add_info ("signals", info_signals_command
, _("\
9811 What debugger does when program gets various signals.\n\
9812 Specify a signal as argument to print info on that signal only."));
9813 add_info_alias ("handle", info_signals_cmd
, 0);
9815 c
= add_com ("handle", class_run
, handle_command
, _("\
9816 Specify how to handle signals.\n\
9817 Usage: handle SIGNAL [ACTIONS]\n\
9818 Args are signals and actions to apply to those signals.\n\
9819 If no actions are specified, the current settings for the specified signals\n\
9820 will be displayed instead.\n\
9822 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
9823 from 1-15 are allowed for compatibility with old versions of GDB.\n\
9824 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
9825 The special arg \"all\" is recognized to mean all signals except those\n\
9826 used by the debugger, typically SIGTRAP and SIGINT.\n\
9828 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
9829 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
9830 Stop means reenter debugger if this signal happens (implies print).\n\
9831 Print means print a message if this signal happens.\n\
9832 Pass means let program see this signal; otherwise program doesn't know.\n\
9833 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
9834 Pass and Stop may be combined.\n\
9836 Multiple signals may be specified. Signal numbers and signal names\n\
9837 may be interspersed with actions, with the actions being performed for\n\
9838 all signals cumulatively specified."));
9839 set_cmd_completer (c
, handle_completer
);
9841 stop_command
= add_cmd ("stop", class_obscure
,
9842 not_just_help_class_command
, _("\
9843 There is no `stop' command, but you can set a hook on `stop'.\n\
9844 This allows you to set a list of commands to be run each time execution\n\
9845 of the program stops."), &cmdlist
);
9847 add_setshow_boolean_cmd
9848 ("infrun", class_maintenance
, &debug_infrun
,
9849 _("Set inferior debugging."),
9850 _("Show inferior debugging."),
9851 _("When non-zero, inferior specific debugging is enabled."),
9852 nullptr, show_debug_infrun
, &setdebuglist
, &showdebuglist
);
9854 add_setshow_boolean_cmd ("non-stop", no_class
,
9856 Set whether gdb controls the inferior in non-stop mode."), _("\
9857 Show whether gdb controls the inferior in non-stop mode."), _("\
9858 When debugging a multi-threaded program and this setting is\n\
9859 off (the default, also called all-stop mode), when one thread stops\n\
9860 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
9861 all other threads in the program while you interact with the thread of\n\
9862 interest. When you continue or step a thread, you can allow the other\n\
9863 threads to run, or have them remain stopped, but while you inspect any\n\
9864 thread's state, all threads stop.\n\
9866 In non-stop mode, when one thread stops, other threads can continue\n\
9867 to run freely. You'll be able to step each thread independently,\n\
9868 leave it stopped or free to run as needed."),
9874 for (size_t i
= 0; i
< GDB_SIGNAL_LAST
; i
++)
9877 signal_print
[i
] = 1;
9878 signal_program
[i
] = 1;
9879 signal_catch
[i
] = 0;
9882 /* Signals caused by debugger's own actions should not be given to
9883 the program afterwards.
9885 Do not deliver GDB_SIGNAL_TRAP by default, except when the user
9886 explicitly specifies that it should be delivered to the target
9887 program. Typically, that would occur when a user is debugging a
9888 target monitor on a simulator: the target monitor sets a
9889 breakpoint; the simulator encounters this breakpoint and halts
9890 the simulation handing control to GDB; GDB, noting that the stop
9891 address doesn't map to any known breakpoint, returns control back
9892 to the simulator; the simulator then delivers the hardware
9893 equivalent of a GDB_SIGNAL_TRAP to the program being
9895 signal_program
[GDB_SIGNAL_TRAP
] = 0;
9896 signal_program
[GDB_SIGNAL_INT
] = 0;
9898 /* Signals that are not errors should not normally enter the debugger. */
9899 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
9900 signal_print
[GDB_SIGNAL_ALRM
] = 0;
9901 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
9902 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
9903 signal_stop
[GDB_SIGNAL_PROF
] = 0;
9904 signal_print
[GDB_SIGNAL_PROF
] = 0;
9905 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
9906 signal_print
[GDB_SIGNAL_CHLD
] = 0;
9907 signal_stop
[GDB_SIGNAL_IO
] = 0;
9908 signal_print
[GDB_SIGNAL_IO
] = 0;
9909 signal_stop
[GDB_SIGNAL_POLL
] = 0;
9910 signal_print
[GDB_SIGNAL_POLL
] = 0;
9911 signal_stop
[GDB_SIGNAL_URG
] = 0;
9912 signal_print
[GDB_SIGNAL_URG
] = 0;
9913 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
9914 signal_print
[GDB_SIGNAL_WINCH
] = 0;
9915 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
9916 signal_print
[GDB_SIGNAL_PRIO
] = 0;
9918 /* These signals are used internally by user-level thread
9919 implementations. (See signal(5) on Solaris.) Like the above
9920 signals, a healthy program receives and handles them as part of
9921 its normal operation. */
9922 signal_stop
[GDB_SIGNAL_LWP
] = 0;
9923 signal_print
[GDB_SIGNAL_LWP
] = 0;
9924 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
9925 signal_print
[GDB_SIGNAL_WAITING
] = 0;
9926 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
9927 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
9928 signal_stop
[GDB_SIGNAL_LIBRT
] = 0;
9929 signal_print
[GDB_SIGNAL_LIBRT
] = 0;
9931 /* Update cached state. */
9932 signal_cache_update (-1);
9934 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
9935 &stop_on_solib_events
, _("\
9936 Set stopping for shared library events."), _("\
9937 Show stopping for shared library events."), _("\
9938 If nonzero, gdb will give control to the user when the dynamic linker\n\
9939 notifies gdb of shared library events. The most common event of interest\n\
9940 to the user would be loading/unloading of a new library."),
9941 set_stop_on_solib_events
,
9942 show_stop_on_solib_events
,
9943 &setlist
, &showlist
);
9945 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
9946 follow_fork_mode_kind_names
,
9947 &follow_fork_mode_string
, _("\
9948 Set debugger response to a program call of fork or vfork."), _("\
9949 Show debugger response to a program call of fork or vfork."), _("\
9950 A fork or vfork creates a new process. follow-fork-mode can be:\n\
9951 parent - the original process is debugged after a fork\n\
9952 child - the new process is debugged after a fork\n\
9953 The unfollowed process will continue to run.\n\
9954 By default, the debugger will follow the parent process."),
9956 show_follow_fork_mode_string
,
9957 &setlist
, &showlist
);
9959 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
9960 follow_exec_mode_names
,
9961 &follow_exec_mode_string
, _("\
9962 Set debugger response to a program call of exec."), _("\
9963 Show debugger response to a program call of exec."), _("\
9964 An exec call replaces the program image of a process.\n\
9966 follow-exec-mode can be:\n\
9968 new - the debugger creates a new inferior and rebinds the process\n\
9969 to this new inferior. The program the process was running before\n\
9970 the exec call can be restarted afterwards by restarting the original\n\
9973 same - the debugger keeps the process bound to the same inferior.\n\
9974 The new executable image replaces the previous executable loaded in\n\
9975 the inferior. Restarting the inferior after the exec call restarts\n\
9976 the executable the process was running after the exec call.\n\
9978 By default, the debugger will use the same inferior."),
9980 show_follow_exec_mode_string
,
9981 &setlist
, &showlist
);
9983 add_setshow_enum_cmd ("scheduler-locking", class_run
,
9984 scheduler_enums
, &scheduler_mode
, _("\
9985 Set mode for locking scheduler during execution."), _("\
9986 Show mode for locking scheduler during execution."), _("\
9987 off == no locking (threads may preempt at any time)\n\
9988 on == full locking (no thread except the current thread may run)\n\
9989 This applies to both normal execution and replay mode.\n\
9990 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
9991 In this mode, other threads may run during other commands.\n\
9992 This applies to both normal execution and replay mode.\n\
9993 replay == scheduler locked in replay mode and unlocked during normal execution."),
9994 set_schedlock_func
, /* traps on target vector */
9995 show_scheduler_mode
,
9996 &setlist
, &showlist
);
9998 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
9999 Set mode for resuming threads of all processes."), _("\
10000 Show mode for resuming threads of all processes."), _("\
10001 When on, execution commands (such as 'continue' or 'next') resume all\n\
10002 threads of all processes. When off (which is the default), execution\n\
10003 commands only resume the threads of the current process. The set of\n\
10004 threads that are resumed is further refined by the scheduler-locking\n\
10005 mode (see help set scheduler-locking)."),
10007 show_schedule_multiple
,
10008 &setlist
, &showlist
);
10010 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
10011 Set mode of the step operation."), _("\
10012 Show mode of the step operation."), _("\
10013 When set, doing a step over a function without debug line information\n\
10014 will stop at the first instruction of that function. Otherwise, the\n\
10015 function is skipped and the step command stops at a different source line."),
10017 show_step_stop_if_no_debug
,
10018 &setlist
, &showlist
);
10020 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
10021 &can_use_displaced_stepping
, _("\
10022 Set debugger's willingness to use displaced stepping."), _("\
10023 Show debugger's willingness to use displaced stepping."), _("\
10024 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
10025 supported by the target architecture. If off, gdb will not use displaced\n\
10026 stepping to step over breakpoints, even if such is supported by the target\n\
10027 architecture. If auto (which is the default), gdb will use displaced stepping\n\
10028 if the target architecture supports it and non-stop mode is active, but will not\n\
10029 use it in all-stop mode (see help set non-stop)."),
10031 show_can_use_displaced_stepping
,
10032 &setlist
, &showlist
);
10034 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
10035 &exec_direction
, _("Set direction of execution.\n\
10036 Options are 'forward' or 'reverse'."),
10037 _("Show direction of execution (forward/reverse)."),
10038 _("Tells gdb whether to execute forward or backward."),
10039 set_exec_direction_func
, show_exec_direction_func
,
10040 &setlist
, &showlist
);
10042 /* Set/show detach-on-fork: user-settable mode. */
10044 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
10045 Set whether gdb will detach the child of a fork."), _("\
10046 Show whether gdb will detach the child of a fork."), _("\
10047 Tells gdb whether to detach the child of a fork."),
10048 nullptr, nullptr, &setlist
, &showlist
);
10050 /* Set/show disable address space randomization mode. */
10052 add_setshow_boolean_cmd ("disable-randomization", class_support
,
10053 &disable_randomization
, _("\
10054 Set disabling of debuggee's virtual address space randomization."), _("\
10055 Show disabling of debuggee's virtual address space randomization."), _("\
10056 When this mode is on (which is the default), randomization of the virtual\n\
10057 address space is disabled. Standalone programs run with the randomization\n\
10058 enabled by default on some platforms."),
10059 &set_disable_randomization
,
10060 &show_disable_randomization
,
10061 &setlist
, &showlist
);
10063 /* ptid initializations */
10064 inferior_ptid
= null_ptid
;
10065 target_last_wait_ptid
= minus_one_ptid
;
10067 gdb::observers::thread_ptid_changed
.attach (infrun_thread_ptid_changed
,
10069 gdb::observers::thread_stop_requested
.attach (infrun_thread_stop_requested
,
10071 gdb::observers::inferior_exit
.attach (infrun_inferior_exit
, "infrun");
10072 gdb::observers::inferior_execd
.attach (infrun_inferior_execd
, "infrun");
10074 /* Explicitly create without lookup, since that tries to create a
10075 value with a void typed value, and when we get here, gdbarch
10076 isn't initialized yet. At this point, we're quite sure there
10077 isn't another convenience variable of the same name. */
10078 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, nullptr);
10080 add_setshow_boolean_cmd ("observer", no_class
,
10081 &observer_mode_1
, _("\
10082 Set whether gdb controls the inferior in observer mode."), _("\
10083 Show whether gdb controls the inferior in observer mode."), _("\
10084 In observer mode, GDB can get data from the inferior, but not\n\
10085 affect its execution. Registers and memory may not be changed,\n\
10086 breakpoints may not be set, and the program cannot be interrupted\n\
10089 show_observer_mode
,
10094 selftests::register_test ("infrun_thread_ptid_changed",
10095 selftests::infrun_thread_ptid_changed
);