1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2023 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "displaced-stepping.h"
28 #include "breakpoint.h"
32 #include "target-connection.h"
33 #include "gdbthread.h"
41 #include "observable.h"
46 #include "mi/mi-common.h"
47 #include "event-top.h"
49 #include "record-full.h"
50 #include "inline-frame.h"
52 #include "tracepoint.h"
56 #include "completer.h"
57 #include "target-descriptions.h"
58 #include "target-dcache.h"
61 #include "gdbsupport/event-loop.h"
62 #include "thread-fsm.h"
63 #include "gdbsupport/enum-flags.h"
64 #include "progspace-and-thread.h"
65 #include "gdbsupport/gdb_optional.h"
66 #include "arch-utils.h"
67 #include "gdbsupport/scope-exit.h"
68 #include "gdbsupport/forward-scope-exit.h"
69 #include "gdbsupport/gdb_select.h"
70 #include <unordered_map>
71 #include "async-event.h"
72 #include "gdbsupport/selftest.h"
73 #include "scoped-mock-context.h"
74 #include "test-target.h"
75 #include "gdbsupport/common-debug.h"
76 #include "gdbsupport/buildargv.h"
77 #include "extension.h"
81 /* Prototypes for local functions */
83 static void sig_print_info (enum gdb_signal
);
85 static void sig_print_header (void);
87 static void follow_inferior_reset_breakpoints (void);
89 static bool currently_stepping (struct thread_info
*tp
);
91 static void insert_hp_step_resume_breakpoint_at_frame (frame_info_ptr
);
93 static void insert_step_resume_breakpoint_at_caller (frame_info_ptr
);
95 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
97 static bool maybe_software_singlestep (struct gdbarch
*gdbarch
);
99 static void resume (gdb_signal sig
);
101 static void wait_for_inferior (inferior
*inf
);
103 static void restart_threads (struct thread_info
*event_thread
,
104 inferior
*inf
= nullptr);
106 static bool start_step_over (void);
108 static bool step_over_info_valid_p (void);
110 /* Asynchronous signal handler registered as event loop source for
111 when we have pending events ready to be passed to the core. */
112 static struct async_event_handler
*infrun_async_inferior_event_token
;
114 /* Stores whether infrun_async was previously enabled or disabled.
115 Starts off as -1, indicating "never enabled/disabled". */
116 static int infrun_is_async
= -1;
121 infrun_async (int enable
)
123 if (infrun_is_async
!= enable
)
125 infrun_is_async
= enable
;
127 infrun_debug_printf ("enable=%d", enable
);
130 mark_async_event_handler (infrun_async_inferior_event_token
);
132 clear_async_event_handler (infrun_async_inferior_event_token
);
139 mark_infrun_async_event_handler (void)
141 mark_async_event_handler (infrun_async_inferior_event_token
);
144 /* When set, stop the 'step' command if we enter a function which has
145 no line number information. The normal behavior is that we step
146 over such function. */
147 bool step_stop_if_no_debug
= false;
149 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
150 struct cmd_list_element
*c
, const char *value
)
152 gdb_printf (file
, _("Mode of the step operation is %s.\n"), value
);
155 /* proceed and normal_stop use this to notify the user when the
156 inferior stopped in a different thread than it had been running in.
157 It can also be used to find for which thread normal_stop last
159 static thread_info_ref previous_thread
;
164 update_previous_thread ()
166 if (inferior_ptid
== null_ptid
)
167 previous_thread
= nullptr;
169 previous_thread
= thread_info_ref::new_reference (inferior_thread ());
175 get_previous_thread ()
177 return previous_thread
.get ();
180 /* If set (default for legacy reasons), when following a fork, GDB
181 will detach from one of the fork branches, child or parent.
182 Exactly which branch is detached depends on 'set follow-fork-mode'
185 static bool detach_fork
= true;
187 bool debug_infrun
= false;
189 show_debug_infrun (struct ui_file
*file
, int from_tty
,
190 struct cmd_list_element
*c
, const char *value
)
192 gdb_printf (file
, _("Inferior debugging is %s.\n"), value
);
195 /* Support for disabling address space randomization. */
197 bool disable_randomization
= true;
200 show_disable_randomization (struct ui_file
*file
, int from_tty
,
201 struct cmd_list_element
*c
, const char *value
)
203 if (target_supports_disable_randomization ())
205 _("Disabling randomization of debuggee's "
206 "virtual address space is %s.\n"),
209 gdb_puts (_("Disabling randomization of debuggee's "
210 "virtual address space is unsupported on\n"
211 "this platform.\n"), file
);
215 set_disable_randomization (const char *args
, int from_tty
,
216 struct cmd_list_element
*c
)
218 if (!target_supports_disable_randomization ())
219 error (_("Disabling randomization of debuggee's "
220 "virtual address space is unsupported on\n"
224 /* User interface for non-stop mode. */
226 bool non_stop
= false;
227 static bool non_stop_1
= false;
230 set_non_stop (const char *args
, int from_tty
,
231 struct cmd_list_element
*c
)
233 if (target_has_execution ())
235 non_stop_1
= non_stop
;
236 error (_("Cannot change this setting while the inferior is running."));
239 non_stop
= non_stop_1
;
243 show_non_stop (struct ui_file
*file
, int from_tty
,
244 struct cmd_list_element
*c
, const char *value
)
247 _("Controlling the inferior in non-stop mode is %s.\n"),
251 /* "Observer mode" is somewhat like a more extreme version of
252 non-stop, in which all GDB operations that might affect the
253 target's execution have been disabled. */
255 static bool observer_mode
= false;
256 static bool observer_mode_1
= false;
259 set_observer_mode (const char *args
, int from_tty
,
260 struct cmd_list_element
*c
)
262 if (target_has_execution ())
264 observer_mode_1
= observer_mode
;
265 error (_("Cannot change this setting while the inferior is running."));
268 observer_mode
= observer_mode_1
;
270 may_write_registers
= !observer_mode
;
271 may_write_memory
= !observer_mode
;
272 may_insert_breakpoints
= !observer_mode
;
273 may_insert_tracepoints
= !observer_mode
;
274 /* We can insert fast tracepoints in or out of observer mode,
275 but enable them if we're going into this mode. */
277 may_insert_fast_tracepoints
= true;
278 may_stop
= !observer_mode
;
279 update_target_permissions ();
281 /* Going *into* observer mode we must force non-stop, then
282 going out we leave it that way. */
285 pagination_enabled
= false;
286 non_stop
= non_stop_1
= true;
290 gdb_printf (_("Observer mode is now %s.\n"),
291 (observer_mode
? "on" : "off"));
295 show_observer_mode (struct ui_file
*file
, int from_tty
,
296 struct cmd_list_element
*c
, const char *value
)
298 gdb_printf (file
, _("Observer mode is %s.\n"), value
);
301 /* This updates the value of observer mode based on changes in
302 permissions. Note that we are deliberately ignoring the values of
303 may-write-registers and may-write-memory, since the user may have
304 reason to enable these during a session, for instance to turn on a
305 debugging-related global. */
308 update_observer_mode (void)
310 bool newval
= (!may_insert_breakpoints
311 && !may_insert_tracepoints
312 && may_insert_fast_tracepoints
316 /* Let the user know if things change. */
317 if (newval
!= observer_mode
)
318 gdb_printf (_("Observer mode is now %s.\n"),
319 (newval
? "on" : "off"));
321 observer_mode
= observer_mode_1
= newval
;
324 /* Tables of how to react to signals; the user sets them. */
326 static unsigned char signal_stop
[GDB_SIGNAL_LAST
];
327 static unsigned char signal_print
[GDB_SIGNAL_LAST
];
328 static unsigned char signal_program
[GDB_SIGNAL_LAST
];
330 /* Table of signals that are registered with "catch signal". A
331 non-zero entry indicates that the signal is caught by some "catch
333 static unsigned char signal_catch
[GDB_SIGNAL_LAST
];
335 /* Table of signals that the target may silently handle.
336 This is automatically determined from the flags above,
337 and simply cached here. */
338 static unsigned char signal_pass
[GDB_SIGNAL_LAST
];
340 #define SET_SIGS(nsigs,sigs,flags) \
342 int signum = (nsigs); \
343 while (signum-- > 0) \
344 if ((sigs)[signum]) \
345 (flags)[signum] = 1; \
348 #define UNSET_SIGS(nsigs,sigs,flags) \
350 int signum = (nsigs); \
351 while (signum-- > 0) \
352 if ((sigs)[signum]) \
353 (flags)[signum] = 0; \
356 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
357 this function is to avoid exporting `signal_program'. */
360 update_signals_program_target (void)
362 target_program_signals (signal_program
);
365 /* Value to pass to target_resume() to cause all threads to resume. */
367 #define RESUME_ALL minus_one_ptid
369 /* Command list pointer for the "stop" placeholder. */
371 static struct cmd_list_element
*stop_command
;
373 /* Nonzero if we want to give control to the user when we're notified
374 of shared library events by the dynamic linker. */
375 int stop_on_solib_events
;
377 /* Enable or disable optional shared library event breakpoints
378 as appropriate when the above flag is changed. */
381 set_stop_on_solib_events (const char *args
,
382 int from_tty
, struct cmd_list_element
*c
)
384 update_solib_breakpoints ();
388 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
389 struct cmd_list_element
*c
, const char *value
)
391 gdb_printf (file
, _("Stopping for shared library events is %s.\n"),
395 /* True after stop if current stack frame should be printed. */
397 static bool stop_print_frame
;
399 /* This is a cached copy of the target/ptid/waitstatus of the last
400 event returned by target_wait().
401 This information is returned by get_last_target_status(). */
402 static process_stratum_target
*target_last_proc_target
;
403 static ptid_t target_last_wait_ptid
;
404 static struct target_waitstatus target_last_waitstatus
;
406 void init_thread_stepping_state (struct thread_info
*tss
);
408 static const char follow_fork_mode_child
[] = "child";
409 static const char follow_fork_mode_parent
[] = "parent";
411 static const char *const follow_fork_mode_kind_names
[] = {
412 follow_fork_mode_child
,
413 follow_fork_mode_parent
,
417 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
419 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
420 struct cmd_list_element
*c
, const char *value
)
423 _("Debugger response to a program "
424 "call of fork or vfork is \"%s\".\n"),
429 /* Handle changes to the inferior list based on the type of fork,
430 which process is being followed, and whether the other process
431 should be detached. On entry inferior_ptid must be the ptid of
432 the fork parent. At return inferior_ptid is the ptid of the
433 followed inferior. */
436 follow_fork_inferior (bool follow_child
, bool detach_fork
)
438 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
440 infrun_debug_printf ("follow_child = %d, detach_fork = %d",
441 follow_child
, detach_fork
);
443 target_waitkind fork_kind
= inferior_thread ()->pending_follow
.kind ();
444 gdb_assert (fork_kind
== TARGET_WAITKIND_FORKED
445 || fork_kind
== TARGET_WAITKIND_VFORKED
);
446 bool has_vforked
= fork_kind
== TARGET_WAITKIND_VFORKED
;
447 ptid_t parent_ptid
= inferior_ptid
;
448 ptid_t child_ptid
= inferior_thread ()->pending_follow
.child_ptid ();
451 && !non_stop
/* Non-stop always resumes both branches. */
452 && current_ui
->prompt_state
== PROMPT_BLOCKED
453 && !(follow_child
|| detach_fork
|| sched_multi
))
455 /* The parent stays blocked inside the vfork syscall until the
456 child execs or exits. If we don't let the child run, then
457 the parent stays blocked. If we're telling the parent to run
458 in the foreground, the user will not be able to ctrl-c to get
459 back the terminal, effectively hanging the debug session. */
460 gdb_printf (gdb_stderr
, _("\
461 Can not resume the parent process over vfork in the foreground while\n\
462 holding the child stopped. Try \"set detach-on-fork\" or \
463 \"set schedule-multiple\".\n"));
467 inferior
*parent_inf
= current_inferior ();
468 inferior
*child_inf
= nullptr;
470 gdb_assert (parent_inf
->thread_waiting_for_vfork_done
== nullptr);
474 /* Detach new forked process? */
477 /* Before detaching from the child, remove all breakpoints
478 from it. If we forked, then this has already been taken
479 care of by infrun.c. If we vforked however, any
480 breakpoint inserted in the parent is visible in the
481 child, even those added while stopped in a vfork
482 catchpoint. This will remove the breakpoints from the
483 parent also, but they'll be reinserted below. */
486 /* Keep breakpoints list in sync. */
487 remove_breakpoints_inf (current_inferior ());
490 if (print_inferior_events
)
492 /* Ensure that we have a process ptid. */
493 ptid_t process_ptid
= ptid_t (child_ptid
.pid ());
495 target_terminal::ours_for_output ();
496 gdb_printf (_("[Detaching after %s from child %s]\n"),
497 has_vforked
? "vfork" : "fork",
498 target_pid_to_str (process_ptid
).c_str ());
503 /* Add process to GDB's tables. */
504 child_inf
= add_inferior (child_ptid
.pid ());
506 child_inf
->attach_flag
= parent_inf
->attach_flag
;
507 copy_terminal_info (child_inf
, parent_inf
);
508 child_inf
->set_arch (parent_inf
->arch ());
509 child_inf
->tdesc_info
= parent_inf
->tdesc_info
;
511 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
513 /* If this is a vfork child, then the address-space is
514 shared with the parent. */
517 child_inf
->pspace
= parent_inf
->pspace
;
518 child_inf
->aspace
= parent_inf
->aspace
;
520 exec_on_vfork (child_inf
);
522 /* The parent will be frozen until the child is done
523 with the shared region. Keep track of the
525 child_inf
->vfork_parent
= parent_inf
;
526 child_inf
->pending_detach
= false;
527 parent_inf
->vfork_child
= child_inf
;
528 parent_inf
->pending_detach
= false;
532 child_inf
->aspace
= new address_space ();
533 child_inf
->pspace
= new program_space (child_inf
->aspace
);
534 child_inf
->removable
= true;
535 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
541 /* If we detached from the child, then we have to be careful
542 to not insert breakpoints in the parent until the child
543 is done with the shared memory region. However, if we're
544 staying attached to the child, then we can and should
545 insert breakpoints, so that we can debug it. A
546 subsequent child exec or exit is enough to know when does
547 the child stops using the parent's address space. */
548 parent_inf
->thread_waiting_for_vfork_done
549 = detach_fork
? inferior_thread () : nullptr;
550 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
553 ("parent_inf->thread_waiting_for_vfork_done == %s",
554 (parent_inf
->thread_waiting_for_vfork_done
== nullptr
556 : (parent_inf
->thread_waiting_for_vfork_done
557 ->ptid
.to_string ().c_str ())));
562 /* Follow the child. */
564 if (print_inferior_events
)
566 std::string parent_pid
= target_pid_to_str (parent_ptid
);
567 std::string child_pid
= target_pid_to_str (child_ptid
);
569 target_terminal::ours_for_output ();
570 gdb_printf (_("[Attaching after %s %s to child %s]\n"),
572 has_vforked
? "vfork" : "fork",
576 /* Add the new inferior first, so that the target_detach below
577 doesn't unpush the target. */
579 child_inf
= add_inferior (child_ptid
.pid ());
581 child_inf
->attach_flag
= parent_inf
->attach_flag
;
582 copy_terminal_info (child_inf
, parent_inf
);
583 child_inf
->set_arch (parent_inf
->arch ());
584 child_inf
->tdesc_info
= parent_inf
->tdesc_info
;
588 /* If this is a vfork child, then the address-space is shared
590 child_inf
->aspace
= parent_inf
->aspace
;
591 child_inf
->pspace
= parent_inf
->pspace
;
593 exec_on_vfork (child_inf
);
595 else if (detach_fork
)
597 /* We follow the child and detach from the parent: move the parent's
598 program space to the child. This simplifies some things, like
599 doing "next" over fork() and landing on the expected line in the
600 child (note, that is broken with "set detach-on-fork off").
602 Before assigning brand new spaces for the parent, remove
603 breakpoints from it: because the new pspace won't match
604 currently inserted locations, the normal detach procedure
605 wouldn't remove them, and we would leave them inserted when
607 remove_breakpoints_inf (parent_inf
);
609 child_inf
->aspace
= parent_inf
->aspace
;
610 child_inf
->pspace
= parent_inf
->pspace
;
611 parent_inf
->aspace
= new address_space ();
612 parent_inf
->pspace
= new program_space (parent_inf
->aspace
);
613 clone_program_space (parent_inf
->pspace
, child_inf
->pspace
);
615 /* The parent inferior is still the current one, so keep things
617 set_current_program_space (parent_inf
->pspace
);
621 child_inf
->aspace
= new address_space ();
622 child_inf
->pspace
= new program_space (child_inf
->aspace
);
623 child_inf
->removable
= true;
624 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
625 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
629 gdb_assert (current_inferior () == parent_inf
);
631 /* If we are setting up an inferior for the child, target_follow_fork is
632 responsible for pushing the appropriate targets on the new inferior's
633 target stack and adding the initial thread (with ptid CHILD_PTID).
635 If we are not setting up an inferior for the child (because following
636 the parent and detach_fork is true), it is responsible for detaching
638 target_follow_fork (child_inf
, child_ptid
, fork_kind
, follow_child
,
641 gdb::observers::inferior_forked
.notify (parent_inf
, child_inf
, fork_kind
);
643 /* target_follow_fork must leave the parent as the current inferior. If we
644 want to follow the child, we make it the current one below. */
645 gdb_assert (current_inferior () == parent_inf
);
647 /* If there is a child inferior, target_follow_fork must have created a thread
649 if (child_inf
!= nullptr)
650 gdb_assert (!child_inf
->thread_list
.empty ());
652 /* Clear the parent thread's pending follow field. Do this before calling
653 target_detach, so that the target can differentiate the two following
656 - We continue past a fork with "follow-fork-mode == child" &&
657 "detach-on-fork on", and therefore detach the parent. In that
658 case the target should not detach the fork child.
659 - We run to a fork catchpoint and the user types "detach". In that
660 case, the target should detach the fork child in addition to the
663 The former case will have pending_follow cleared, the later will have
664 pending_follow set. */
665 thread_info
*parent_thread
= parent_inf
->find_thread (parent_ptid
);
666 gdb_assert (parent_thread
!= nullptr);
667 parent_thread
->pending_follow
.set_spurious ();
669 /* Detach the parent if needed. */
672 /* If we're vforking, we want to hold on to the parent until
673 the child exits or execs. At child exec or exit time we
674 can remove the old breakpoints from the parent and detach
675 or resume debugging it. Otherwise, detach the parent now;
676 we'll want to reuse it's program/address spaces, but we
677 can't set them to the child before removing breakpoints
678 from the parent, otherwise, the breakpoints module could
679 decide to remove breakpoints from the wrong process (since
680 they'd be assigned to the same address space). */
684 gdb_assert (child_inf
->vfork_parent
== nullptr);
685 gdb_assert (parent_inf
->vfork_child
== nullptr);
686 child_inf
->vfork_parent
= parent_inf
;
687 child_inf
->pending_detach
= false;
688 parent_inf
->vfork_child
= child_inf
;
689 parent_inf
->pending_detach
= detach_fork
;
691 else if (detach_fork
)
693 if (print_inferior_events
)
695 /* Ensure that we have a process ptid. */
696 ptid_t process_ptid
= ptid_t (parent_ptid
.pid ());
698 target_terminal::ours_for_output ();
699 gdb_printf (_("[Detaching after fork from "
701 target_pid_to_str (process_ptid
).c_str ());
704 target_detach (parent_inf
, 0);
708 /* If we ended up creating a new inferior, call post_create_inferior to inform
709 the various subcomponents. */
710 if (child_inf
!= nullptr)
712 /* If FOLLOW_CHILD, we leave CHILD_INF as the current inferior
713 (do not restore the parent as the current inferior). */
714 gdb::optional
<scoped_restore_current_thread
> maybe_restore
;
716 if (!follow_child
&& !sched_multi
)
717 maybe_restore
.emplace ();
719 switch_to_thread (*child_inf
->threads ().begin ());
720 post_create_inferior (0);
726 /* Set the last target status as TP having stopped. */
729 set_last_target_status_stopped (thread_info
*tp
)
731 set_last_target_status (tp
->inf
->process_target (), tp
->ptid
,
732 target_waitstatus
{}.set_stopped (GDB_SIGNAL_0
));
735 /* Tell the target to follow the fork we're stopped at. Returns true
736 if the inferior should be resumed; false, if the target for some
737 reason decided it's best not to resume. */
742 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
744 bool follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
745 bool should_resume
= true;
747 /* Copy user stepping state to the new inferior thread. FIXME: the
748 followed fork child thread should have a copy of most of the
749 parent thread structure's run control related fields, not just these.
750 Initialized to avoid "may be used uninitialized" warnings from gcc. */
751 struct breakpoint
*step_resume_breakpoint
= nullptr;
752 struct breakpoint
*exception_resume_breakpoint
= nullptr;
753 CORE_ADDR step_range_start
= 0;
754 CORE_ADDR step_range_end
= 0;
755 int current_line
= 0;
756 symtab
*current_symtab
= nullptr;
757 struct frame_id step_frame_id
= { 0 };
761 thread_info
*cur_thr
= inferior_thread ();
764 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
765 process_stratum_target
*resume_target
766 = user_visible_resume_target (resume_ptid
);
768 /* Check if there's a thread that we're about to resume, other
769 than the current, with an unfollowed fork/vfork. If so,
770 switch back to it, to tell the target to follow it (in either
771 direction). We'll afterwards refuse to resume, and inform
772 the user what happened. */
773 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
779 /* follow_fork_inferior clears tp->pending_follow, and below
780 we'll need the value after the follow_fork_inferior
782 target_waitkind kind
= tp
->pending_follow
.kind ();
784 if (kind
!= TARGET_WAITKIND_SPURIOUS
)
786 infrun_debug_printf ("need to follow-fork [%s] first",
787 tp
->ptid
.to_string ().c_str ());
789 switch_to_thread (tp
);
791 /* Set up inferior(s) as specified by the caller, and
792 tell the target to do whatever is necessary to follow
793 either parent or child. */
796 /* The thread that started the execution command
797 won't exist in the child. Abort the command and
798 immediately stop in this thread, in the child,
800 should_resume
= false;
804 /* Following the parent, so let the thread fork its
805 child freely, it won't influence the current
806 execution command. */
807 if (follow_fork_inferior (follow_child
, detach_fork
))
809 /* Target refused to follow, or there's some
810 other reason we shouldn't resume. */
811 switch_to_thread (cur_thr
);
812 set_last_target_status_stopped (cur_thr
);
816 /* If we're following a vfork, when we need to leave
817 the just-forked thread as selected, as we need to
818 solo-resume it to collect the VFORK_DONE event.
819 If we're following a fork, however, switch back
820 to the original thread that we continue stepping
822 if (kind
!= TARGET_WAITKIND_VFORKED
)
824 gdb_assert (kind
== TARGET_WAITKIND_FORKED
);
825 switch_to_thread (cur_thr
);
834 thread_info
*tp
= inferior_thread ();
836 /* If there were any forks/vforks that were caught and are now to be
837 followed, then do so now. */
838 switch (tp
->pending_follow
.kind ())
840 case TARGET_WAITKIND_FORKED
:
841 case TARGET_WAITKIND_VFORKED
:
843 ptid_t parent
, child
;
844 std::unique_ptr
<struct thread_fsm
> thread_fsm
;
846 /* If the user did a next/step, etc, over a fork call,
847 preserve the stepping state in the fork child. */
848 if (follow_child
&& should_resume
)
850 step_resume_breakpoint
= clone_momentary_breakpoint
851 (tp
->control
.step_resume_breakpoint
);
852 step_range_start
= tp
->control
.step_range_start
;
853 step_range_end
= tp
->control
.step_range_end
;
854 current_line
= tp
->current_line
;
855 current_symtab
= tp
->current_symtab
;
856 step_frame_id
= tp
->control
.step_frame_id
;
857 exception_resume_breakpoint
858 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
859 thread_fsm
= tp
->release_thread_fsm ();
861 /* For now, delete the parent's sr breakpoint, otherwise,
862 parent/child sr breakpoints are considered duplicates,
863 and the child version will not be installed. Remove
864 this when the breakpoints module becomes aware of
865 inferiors and address spaces. */
866 delete_step_resume_breakpoint (tp
);
867 tp
->control
.step_range_start
= 0;
868 tp
->control
.step_range_end
= 0;
869 tp
->control
.step_frame_id
= null_frame_id
;
870 delete_exception_resume_breakpoint (tp
);
873 parent
= inferior_ptid
;
874 child
= tp
->pending_follow
.child_ptid ();
876 /* If handling a vfork, stop all the inferior's threads, they will be
877 restarted when the vfork shared region is complete. */
878 if (tp
->pending_follow
.kind () == TARGET_WAITKIND_VFORKED
879 && target_is_non_stop_p ())
880 stop_all_threads ("handling vfork", tp
->inf
);
882 process_stratum_target
*parent_targ
= tp
->inf
->process_target ();
883 /* Set up inferior(s) as specified by the caller, and tell the
884 target to do whatever is necessary to follow either parent
886 if (follow_fork_inferior (follow_child
, detach_fork
))
888 /* Target refused to follow, or there's some other reason
889 we shouldn't resume. */
894 /* If we followed the child, switch to it... */
897 tp
= parent_targ
->find_thread (child
);
898 switch_to_thread (tp
);
900 /* ... and preserve the stepping state, in case the
901 user was stepping over the fork call. */
904 tp
->control
.step_resume_breakpoint
905 = step_resume_breakpoint
;
906 tp
->control
.step_range_start
= step_range_start
;
907 tp
->control
.step_range_end
= step_range_end
;
908 tp
->current_line
= current_line
;
909 tp
->current_symtab
= current_symtab
;
910 tp
->control
.step_frame_id
= step_frame_id
;
911 tp
->control
.exception_resume_breakpoint
912 = exception_resume_breakpoint
;
913 tp
->set_thread_fsm (std::move (thread_fsm
));
917 /* If we get here, it was because we're trying to
918 resume from a fork catchpoint, but, the user
919 has switched threads away from the thread that
920 forked. In that case, the resume command
921 issued is most likely not applicable to the
922 child, so just warn, and refuse to resume. */
923 warning (_("Not resuming: switched threads "
924 "before following fork child."));
927 /* Reset breakpoints in the child as appropriate. */
928 follow_inferior_reset_breakpoints ();
933 case TARGET_WAITKIND_SPURIOUS
:
934 /* Nothing to follow. */
937 internal_error ("Unexpected pending_follow.kind %d\n",
938 tp
->pending_follow
.kind ());
943 set_last_target_status_stopped (tp
);
944 return should_resume
;
948 follow_inferior_reset_breakpoints (void)
950 struct thread_info
*tp
= inferior_thread ();
952 /* Was there a step_resume breakpoint? (There was if the user
953 did a "next" at the fork() call.) If so, explicitly reset its
954 thread number. Cloned step_resume breakpoints are disabled on
955 creation, so enable it here now that it is associated with the
958 step_resumes are a form of bp that are made to be per-thread.
959 Since we created the step_resume bp when the parent process
960 was being debugged, and now are switching to the child process,
961 from the breakpoint package's viewpoint, that's a switch of
962 "threads". We must update the bp's notion of which thread
963 it is for, or it'll be ignored when it triggers. */
965 if (tp
->control
.step_resume_breakpoint
)
967 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
968 tp
->control
.step_resume_breakpoint
->first_loc ().enabled
= 1;
971 /* Treat exception_resume breakpoints like step_resume breakpoints. */
972 if (tp
->control
.exception_resume_breakpoint
)
974 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
975 tp
->control
.exception_resume_breakpoint
->first_loc ().enabled
= 1;
978 /* Reinsert all breakpoints in the child. The user may have set
979 breakpoints after catching the fork, in which case those
980 were never set in the child, but only in the parent. This makes
981 sure the inserted breakpoints match the breakpoint list. */
983 breakpoint_re_set ();
984 insert_breakpoints ();
987 /* The child has exited or execed: resume THREAD, a thread of the parent,
988 if it was meant to be executing. */
991 proceed_after_vfork_done (thread_info
*thread
)
993 if (thread
->state
== THREAD_RUNNING
994 && !thread
->executing ()
995 && !thread
->stop_requested
996 && thread
->stop_signal () == GDB_SIGNAL_0
)
998 infrun_debug_printf ("resuming vfork parent thread %s",
999 thread
->ptid
.to_string ().c_str ());
1001 switch_to_thread (thread
);
1002 clear_proceed_status (0);
1003 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1007 /* Called whenever we notice an exec or exit event, to handle
1008 detaching or resuming a vfork parent. */
1011 handle_vfork_child_exec_or_exit (int exec
)
1013 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1015 struct inferior
*inf
= current_inferior ();
1017 if (inf
->vfork_parent
)
1019 inferior
*resume_parent
= nullptr;
1021 /* This exec or exit marks the end of the shared memory region
1022 between the parent and the child. Break the bonds. */
1023 inferior
*vfork_parent
= inf
->vfork_parent
;
1024 inf
->vfork_parent
->vfork_child
= nullptr;
1025 inf
->vfork_parent
= nullptr;
1027 /* If the user wanted to detach from the parent, now is the
1029 if (vfork_parent
->pending_detach
)
1031 struct program_space
*pspace
;
1032 struct address_space
*aspace
;
1034 /* follow-fork child, detach-on-fork on. */
1036 vfork_parent
->pending_detach
= false;
1038 scoped_restore_current_pspace_and_thread restore_thread
;
1040 /* We're letting loose of the parent. */
1041 thread_info
*tp
= any_live_thread_of_inferior (vfork_parent
);
1042 switch_to_thread (tp
);
1044 /* We're about to detach from the parent, which implicitly
1045 removes breakpoints from its address space. There's a
1046 catch here: we want to reuse the spaces for the child,
1047 but, parent/child are still sharing the pspace at this
1048 point, although the exec in reality makes the kernel give
1049 the child a fresh set of new pages. The problem here is
1050 that the breakpoints module being unaware of this, would
1051 likely chose the child process to write to the parent
1052 address space. Swapping the child temporarily away from
1053 the spaces has the desired effect. Yes, this is "sort
1056 pspace
= inf
->pspace
;
1057 aspace
= inf
->aspace
;
1058 inf
->aspace
= nullptr;
1059 inf
->pspace
= nullptr;
1061 if (print_inferior_events
)
1064 = target_pid_to_str (ptid_t (vfork_parent
->pid
));
1066 target_terminal::ours_for_output ();
1070 gdb_printf (_("[Detaching vfork parent %s "
1071 "after child exec]\n"), pidstr
.c_str ());
1075 gdb_printf (_("[Detaching vfork parent %s "
1076 "after child exit]\n"), pidstr
.c_str ());
1080 target_detach (vfork_parent
, 0);
1083 inf
->pspace
= pspace
;
1084 inf
->aspace
= aspace
;
1088 /* We're staying attached to the parent, so, really give the
1089 child a new address space. */
1090 inf
->pspace
= new program_space (maybe_new_address_space ());
1091 inf
->aspace
= inf
->pspace
->aspace
;
1092 inf
->removable
= true;
1093 set_current_program_space (inf
->pspace
);
1095 resume_parent
= vfork_parent
;
1099 /* If this is a vfork child exiting, then the pspace and
1100 aspaces were shared with the parent. Since we're
1101 reporting the process exit, we'll be mourning all that is
1102 found in the address space, and switching to null_ptid,
1103 preparing to start a new inferior. But, since we don't
1104 want to clobber the parent's address/program spaces, we
1105 go ahead and create a new one for this exiting
1108 /* Switch to no-thread while running clone_program_space, so
1109 that clone_program_space doesn't want to read the
1110 selected frame of a dead process. */
1111 scoped_restore_current_thread restore_thread
;
1112 switch_to_no_thread ();
1114 inf
->pspace
= new program_space (maybe_new_address_space ());
1115 inf
->aspace
= inf
->pspace
->aspace
;
1116 set_current_program_space (inf
->pspace
);
1117 inf
->removable
= true;
1118 inf
->symfile_flags
= SYMFILE_NO_READ
;
1119 clone_program_space (inf
->pspace
, vfork_parent
->pspace
);
1121 resume_parent
= vfork_parent
;
1124 gdb_assert (current_program_space
== inf
->pspace
);
1126 if (non_stop
&& resume_parent
!= nullptr)
1128 /* If the user wanted the parent to be running, let it go
1130 scoped_restore_current_thread restore_thread
;
1132 infrun_debug_printf ("resuming vfork parent process %d",
1133 resume_parent
->pid
);
1135 for (thread_info
*thread
: resume_parent
->threads ())
1136 proceed_after_vfork_done (thread
);
1141 /* Handle TARGET_WAITKIND_VFORK_DONE. */
1144 handle_vfork_done (thread_info
*event_thread
)
1146 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1148 /* We only care about this event if inferior::thread_waiting_for_vfork_done is
1149 set, that is if we are waiting for a vfork child not under our control
1150 (because we detached it) to exec or exit.
1152 If an inferior has vforked and we are debugging the child, we don't use
1153 the vfork-done event to get notified about the end of the shared address
1154 space window. We rely instead on the child's exec or exit event, and the
1155 inferior::vfork_{parent,child} fields are used instead. See
1156 handle_vfork_child_exec_or_exit for that. */
1157 if (event_thread
->inf
->thread_waiting_for_vfork_done
== nullptr)
1159 infrun_debug_printf ("not waiting for a vfork-done event");
1163 /* We stopped all threads (other than the vforking thread) of the inferior in
1164 follow_fork and kept them stopped until now. It should therefore not be
1165 possible for another thread to have reported a vfork during that window.
1166 If THREAD_WAITING_FOR_VFORK_DONE is set, it has to be the same thread whose
1167 vfork-done we are handling right now. */
1168 gdb_assert (event_thread
->inf
->thread_waiting_for_vfork_done
== event_thread
);
1170 event_thread
->inf
->thread_waiting_for_vfork_done
= nullptr;
1171 event_thread
->inf
->pspace
->breakpoints_not_allowed
= 0;
1173 /* On non-stop targets, we stopped all the inferior's threads in follow_fork,
1174 resume them now. On all-stop targets, everything that needs to be resumed
1175 will be when we resume the event thread. */
1176 if (target_is_non_stop_p ())
1178 /* restart_threads and start_step_over may change the current thread, make
1179 sure we leave the event thread as the current thread. */
1180 scoped_restore_current_thread restore_thread
;
1182 insert_breakpoints ();
1185 if (!step_over_info_valid_p ())
1186 restart_threads (event_thread
, event_thread
->inf
);
1190 /* Enum strings for "set|show follow-exec-mode". */
1192 static const char follow_exec_mode_new
[] = "new";
1193 static const char follow_exec_mode_same
[] = "same";
1194 static const char *const follow_exec_mode_names
[] =
1196 follow_exec_mode_new
,
1197 follow_exec_mode_same
,
1201 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1203 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1204 struct cmd_list_element
*c
, const char *value
)
1206 gdb_printf (file
, _("Follow exec mode is \"%s\".\n"), value
);
1209 /* EXEC_FILE_TARGET is assumed to be non-NULL. */
1212 follow_exec (ptid_t ptid
, const char *exec_file_target
)
1214 int pid
= ptid
.pid ();
1215 ptid_t process_ptid
;
1217 /* Switch terminal for any messages produced e.g. by
1218 breakpoint_re_set. */
1219 target_terminal::ours_for_output ();
1221 /* This is an exec event that we actually wish to pay attention to.
1222 Refresh our symbol table to the newly exec'd program, remove any
1223 momentary bp's, etc.
1225 If there are breakpoints, they aren't really inserted now,
1226 since the exec() transformed our inferior into a fresh set
1229 We want to preserve symbolic breakpoints on the list, since
1230 we have hopes that they can be reset after the new a.out's
1231 symbol table is read.
1233 However, any "raw" breakpoints must be removed from the list
1234 (e.g., the solib bp's), since their address is probably invalid
1237 And, we DON'T want to call delete_breakpoints() here, since
1238 that may write the bp's "shadow contents" (the instruction
1239 value that was overwritten with a TRAP instruction). Since
1240 we now have a new a.out, those shadow contents aren't valid. */
1242 mark_breakpoints_out ();
1244 /* The target reports the exec event to the main thread, even if
1245 some other thread does the exec, and even if the main thread was
1246 stopped or already gone. We may still have non-leader threads of
1247 the process on our list. E.g., on targets that don't have thread
1248 exit events (like remote) and nothing forces an update of the
1249 thread list up to here. When debugging remotely, it's best to
1250 avoid extra traffic, when possible, so avoid syncing the thread
1251 list with the target, and instead go ahead and delete all threads
1252 of the process but the one that reported the event. Note this must
1253 be done before calling update_breakpoints_after_exec, as
1254 otherwise clearing the threads' resources would reference stale
1255 thread breakpoints -- it may have been one of these threads that
1256 stepped across the exec. We could just clear their stepping
1257 states, but as long as we're iterating, might as well delete
1258 them. Deleting them now rather than at the next user-visible
1259 stop provides a nicer sequence of events for user and MI
1261 for (thread_info
*th
: all_threads_safe ())
1262 if (th
->ptid
.pid () == pid
&& th
->ptid
!= ptid
)
1265 /* We also need to clear any left over stale state for the
1266 leader/event thread. E.g., if there was any step-resume
1267 breakpoint or similar, it's gone now. We cannot truly
1268 step-to-next statement through an exec(). */
1269 thread_info
*th
= inferior_thread ();
1270 th
->control
.step_resume_breakpoint
= nullptr;
1271 th
->control
.exception_resume_breakpoint
= nullptr;
1272 th
->control
.single_step_breakpoints
= nullptr;
1273 th
->control
.step_range_start
= 0;
1274 th
->control
.step_range_end
= 0;
1276 /* The user may have had the main thread held stopped in the
1277 previous image (e.g., schedlock on, or non-stop). Release
1279 th
->stop_requested
= 0;
1281 update_breakpoints_after_exec ();
1283 /* What is this a.out's name? */
1284 process_ptid
= ptid_t (pid
);
1285 gdb_printf (_("%s is executing new program: %s\n"),
1286 target_pid_to_str (process_ptid
).c_str (),
1289 /* We've followed the inferior through an exec. Therefore, the
1290 inferior has essentially been killed & reborn. */
1292 breakpoint_init_inferior (inf_execd
);
1294 gdb::unique_xmalloc_ptr
<char> exec_file_host
1295 = exec_file_find (exec_file_target
, nullptr);
1297 /* If we were unable to map the executable target pathname onto a host
1298 pathname, tell the user that. Otherwise GDB's subsequent behavior
1299 is confusing. Maybe it would even be better to stop at this point
1300 so that the user can specify a file manually before continuing. */
1301 if (exec_file_host
== nullptr)
1302 warning (_("Could not load symbols for executable %s.\n"
1303 "Do you need \"set sysroot\"?"),
1306 /* Reset the shared library package. This ensures that we get a
1307 shlib event when the child reaches "_start", at which point the
1308 dld will have had a chance to initialize the child. */
1309 /* Also, loading a symbol file below may trigger symbol lookups, and
1310 we don't want those to be satisfied by the libraries of the
1311 previous incarnation of this process. */
1312 no_shared_libraries (nullptr, 0);
1314 inferior
*execing_inferior
= current_inferior ();
1315 inferior
*following_inferior
;
1317 if (follow_exec_mode_string
== follow_exec_mode_new
)
1319 /* The user wants to keep the old inferior and program spaces
1320 around. Create a new fresh one, and switch to it. */
1322 /* Do exit processing for the original inferior before setting the new
1323 inferior's pid. Having two inferiors with the same pid would confuse
1324 find_inferior_p(t)id. Transfer the terminal state and info from the
1325 old to the new inferior. */
1326 following_inferior
= add_inferior_with_spaces ();
1328 swap_terminal_info (following_inferior
, execing_inferior
);
1329 exit_inferior (execing_inferior
);
1331 following_inferior
->pid
= pid
;
1335 /* follow-exec-mode is "same", we continue execution in the execing
1337 following_inferior
= execing_inferior
;
1339 /* The old description may no longer be fit for the new image.
1340 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1341 old description; we'll read a new one below. No need to do
1342 this on "follow-exec-mode new", as the old inferior stays
1343 around (its description is later cleared/refetched on
1345 target_clear_description ();
1348 target_follow_exec (following_inferior
, ptid
, exec_file_target
);
1350 gdb_assert (current_inferior () == following_inferior
);
1351 gdb_assert (current_program_space
== following_inferior
->pspace
);
1353 /* Attempt to open the exec file. SYMFILE_DEFER_BP_RESET is used
1354 because the proper displacement for a PIE (Position Independent
1355 Executable) main symbol file will only be computed by
1356 solib_create_inferior_hook below. breakpoint_re_set would fail
1357 to insert the breakpoints with the zero displacement. */
1358 try_open_exec_file (exec_file_host
.get (), following_inferior
,
1359 SYMFILE_DEFER_BP_RESET
);
1361 /* If the target can specify a description, read it. Must do this
1362 after flipping to the new executable (because the target supplied
1363 description must be compatible with the executable's
1364 architecture, and the old executable may e.g., be 32-bit, while
1365 the new one 64-bit), and before anything involving memory or
1367 target_find_description ();
1369 gdb::observers::inferior_execd
.notify (execing_inferior
, following_inferior
);
1371 breakpoint_re_set ();
1373 /* Reinsert all breakpoints. (Those which were symbolic have
1374 been reset to the proper address in the new a.out, thanks
1375 to symbol_file_command...). */
1376 insert_breakpoints ();
1378 /* The next resume of this inferior should bring it to the shlib
1379 startup breakpoints. (If the user had also set bp's on
1380 "main" from the old (parent) process, then they'll auto-
1381 matically get reset there in the new process.). */
1384 /* The chain of threads that need to do a step-over operation to get
1385 past e.g., a breakpoint. What technique is used to step over the
1386 breakpoint/watchpoint does not matter -- all threads end up in the
1387 same queue, to maintain rough temporal order of execution, in order
1388 to avoid starvation, otherwise, we could e.g., find ourselves
1389 constantly stepping the same couple threads past their breakpoints
1390 over and over, if the single-step finish fast enough. */
1391 thread_step_over_list global_thread_step_over_list
;
1393 /* Bit flags indicating what the thread needs to step over. */
1395 enum step_over_what_flag
1397 /* Step over a breakpoint. */
1398 STEP_OVER_BREAKPOINT
= 1,
1400 /* Step past a non-continuable watchpoint, in order to let the
1401 instruction execute so we can evaluate the watchpoint
1403 STEP_OVER_WATCHPOINT
= 2
1405 DEF_ENUM_FLAGS_TYPE (enum step_over_what_flag
, step_over_what
);
1407 /* Info about an instruction that is being stepped over. */
1409 struct step_over_info
1411 /* If we're stepping past a breakpoint, this is the address space
1412 and address of the instruction the breakpoint is set at. We'll
1413 skip inserting all breakpoints here. Valid iff ASPACE is
1415 const address_space
*aspace
= nullptr;
1416 CORE_ADDR address
= 0;
1418 /* The instruction being stepped over triggers a nonsteppable
1419 watchpoint. If true, we'll skip inserting watchpoints. */
1420 int nonsteppable_watchpoint_p
= 0;
1422 /* The thread's global number. */
1426 /* The step-over info of the location that is being stepped over.
1428 Note that with async/breakpoint always-inserted mode, a user might
1429 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1430 being stepped over. As setting a new breakpoint inserts all
1431 breakpoints, we need to make sure the breakpoint being stepped over
1432 isn't inserted then. We do that by only clearing the step-over
1433 info when the step-over is actually finished (or aborted).
1435 Presently GDB can only step over one breakpoint at any given time.
1436 Given threads that can't run code in the same address space as the
1437 breakpoint's can't really miss the breakpoint, GDB could be taught
1438 to step-over at most one breakpoint per address space (so this info
1439 could move to the address space object if/when GDB is extended).
1440 The set of breakpoints being stepped over will normally be much
1441 smaller than the set of all breakpoints, so a flag in the
1442 breakpoint location structure would be wasteful. A separate list
1443 also saves complexity and run-time, as otherwise we'd have to go
1444 through all breakpoint locations clearing their flag whenever we
1445 start a new sequence. Similar considerations weigh against storing
1446 this info in the thread object. Plus, not all step overs actually
1447 have breakpoint locations -- e.g., stepping past a single-step
1448 breakpoint, or stepping to complete a non-continuable
1450 static struct step_over_info step_over_info
;
1452 /* Record the address of the breakpoint/instruction we're currently
1454 N.B. We record the aspace and address now, instead of say just the thread,
1455 because when we need the info later the thread may be running. */
1458 set_step_over_info (const address_space
*aspace
, CORE_ADDR address
,
1459 int nonsteppable_watchpoint_p
,
1462 step_over_info
.aspace
= aspace
;
1463 step_over_info
.address
= address
;
1464 step_over_info
.nonsteppable_watchpoint_p
= nonsteppable_watchpoint_p
;
1465 step_over_info
.thread
= thread
;
1468 /* Called when we're not longer stepping over a breakpoint / an
1469 instruction, so all breakpoints are free to be (re)inserted. */
1472 clear_step_over_info (void)
1474 infrun_debug_printf ("clearing step over info");
1475 step_over_info
.aspace
= nullptr;
1476 step_over_info
.address
= 0;
1477 step_over_info
.nonsteppable_watchpoint_p
= 0;
1478 step_over_info
.thread
= -1;
1484 stepping_past_instruction_at (struct address_space
*aspace
,
1487 return (step_over_info
.aspace
!= nullptr
1488 && breakpoint_address_match (aspace
, address
,
1489 step_over_info
.aspace
,
1490 step_over_info
.address
));
1496 thread_is_stepping_over_breakpoint (int thread
)
1498 return (step_over_info
.thread
!= -1
1499 && thread
== step_over_info
.thread
);
1505 stepping_past_nonsteppable_watchpoint (void)
1507 return step_over_info
.nonsteppable_watchpoint_p
;
1510 /* Returns true if step-over info is valid. */
1513 step_over_info_valid_p (void)
1515 return (step_over_info
.aspace
!= nullptr
1516 || stepping_past_nonsteppable_watchpoint ());
1520 /* Displaced stepping. */
1522 /* In non-stop debugging mode, we must take special care to manage
1523 breakpoints properly; in particular, the traditional strategy for
1524 stepping a thread past a breakpoint it has hit is unsuitable.
1525 'Displaced stepping' is a tactic for stepping one thread past a
1526 breakpoint it has hit while ensuring that other threads running
1527 concurrently will hit the breakpoint as they should.
1529 The traditional way to step a thread T off a breakpoint in a
1530 multi-threaded program in all-stop mode is as follows:
1532 a0) Initially, all threads are stopped, and breakpoints are not
1534 a1) We single-step T, leaving breakpoints uninserted.
1535 a2) We insert breakpoints, and resume all threads.
1537 In non-stop debugging, however, this strategy is unsuitable: we
1538 don't want to have to stop all threads in the system in order to
1539 continue or step T past a breakpoint. Instead, we use displaced
1542 n0) Initially, T is stopped, other threads are running, and
1543 breakpoints are inserted.
1544 n1) We copy the instruction "under" the breakpoint to a separate
1545 location, outside the main code stream, making any adjustments
1546 to the instruction, register, and memory state as directed by
1548 n2) We single-step T over the instruction at its new location.
1549 n3) We adjust the resulting register and memory state as directed
1550 by T's architecture. This includes resetting T's PC to point
1551 back into the main instruction stream.
1554 This approach depends on the following gdbarch methods:
1556 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1557 indicate where to copy the instruction, and how much space must
1558 be reserved there. We use these in step n1.
1560 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1561 address, and makes any necessary adjustments to the instruction,
1562 register contents, and memory. We use this in step n1.
1564 - gdbarch_displaced_step_fixup adjusts registers and memory after
1565 we have successfully single-stepped the instruction, to yield the
1566 same effect the instruction would have had if we had executed it
1567 at its original address. We use this in step n3.
1569 The gdbarch_displaced_step_copy_insn and
1570 gdbarch_displaced_step_fixup functions must be written so that
1571 copying an instruction with gdbarch_displaced_step_copy_insn,
1572 single-stepping across the copied instruction, and then applying
1573 gdbarch_displaced_insn_fixup should have the same effects on the
1574 thread's memory and registers as stepping the instruction in place
1575 would have. Exactly which responsibilities fall to the copy and
1576 which fall to the fixup is up to the author of those functions.
1578 See the comments in gdbarch.sh for details.
1580 Note that displaced stepping and software single-step cannot
1581 currently be used in combination, although with some care I think
1582 they could be made to. Software single-step works by placing
1583 breakpoints on all possible subsequent instructions; if the
1584 displaced instruction is a PC-relative jump, those breakpoints
1585 could fall in very strange places --- on pages that aren't
1586 executable, or at addresses that are not proper instruction
1587 boundaries. (We do generally let other threads run while we wait
1588 to hit the software single-step breakpoint, and they might
1589 encounter such a corrupted instruction.) One way to work around
1590 this would be to have gdbarch_displaced_step_copy_insn fully
1591 simulate the effect of PC-relative instructions (and return NULL)
1592 on architectures that use software single-stepping.
1594 In non-stop mode, we can have independent and simultaneous step
1595 requests, so more than one thread may need to simultaneously step
1596 over a breakpoint. The current implementation assumes there is
1597 only one scratch space per process. In this case, we have to
1598 serialize access to the scratch space. If thread A wants to step
1599 over a breakpoint, but we are currently waiting for some other
1600 thread to complete a displaced step, we leave thread A stopped and
1601 place it in the displaced_step_request_queue. Whenever a displaced
1602 step finishes, we pick the next thread in the queue and start a new
1603 displaced step operation on it. See displaced_step_prepare and
1604 displaced_step_finish for details. */
1606 /* Return true if THREAD is doing a displaced step. */
1609 displaced_step_in_progress_thread (thread_info
*thread
)
1611 gdb_assert (thread
!= nullptr);
1613 return thread
->displaced_step_state
.in_progress ();
1616 /* Return true if INF has a thread doing a displaced step. */
1619 displaced_step_in_progress (inferior
*inf
)
1621 return inf
->displaced_step_state
.in_progress_count
> 0;
1624 /* Return true if any thread is doing a displaced step. */
1627 displaced_step_in_progress_any_thread ()
1629 for (inferior
*inf
: all_non_exited_inferiors ())
1631 if (displaced_step_in_progress (inf
))
1639 infrun_inferior_exit (struct inferior
*inf
)
1641 inf
->displaced_step_state
.reset ();
1642 inf
->thread_waiting_for_vfork_done
= nullptr;
1646 infrun_inferior_execd (inferior
*exec_inf
, inferior
*follow_inf
)
1648 /* If some threads where was doing a displaced step in this inferior at the
1649 moment of the exec, they no longer exist. Even if the exec'ing thread
1650 doing a displaced step, we don't want to to any fixup nor restore displaced
1651 stepping buffer bytes. */
1652 follow_inf
->displaced_step_state
.reset ();
1654 for (thread_info
*thread
: follow_inf
->threads ())
1655 thread
->displaced_step_state
.reset ();
1657 /* Since an in-line step is done with everything else stopped, if there was
1658 one in progress at the time of the exec, it must have been the exec'ing
1660 clear_step_over_info ();
1662 follow_inf
->thread_waiting_for_vfork_done
= nullptr;
1665 /* If ON, and the architecture supports it, GDB will use displaced
1666 stepping to step over breakpoints. If OFF, or if the architecture
1667 doesn't support it, GDB will instead use the traditional
1668 hold-and-step approach. If AUTO (which is the default), GDB will
1669 decide which technique to use to step over breakpoints depending on
1670 whether the target works in a non-stop way (see use_displaced_stepping). */
1672 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1675 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1676 struct cmd_list_element
*c
,
1679 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1681 _("Debugger's willingness to use displaced stepping "
1682 "to step over breakpoints is %s (currently %s).\n"),
1683 value
, target_is_non_stop_p () ? "on" : "off");
1686 _("Debugger's willingness to use displaced stepping "
1687 "to step over breakpoints is %s.\n"), value
);
1690 /* Return true if the gdbarch implements the required methods to use
1691 displaced stepping. */
1694 gdbarch_supports_displaced_stepping (gdbarch
*arch
)
1696 /* Only check for the presence of `prepare`. The gdbarch verification ensures
1697 that if `prepare` is provided, so is `finish`. */
1698 return gdbarch_displaced_step_prepare_p (arch
);
1701 /* Return non-zero if displaced stepping can/should be used to step
1702 over breakpoints of thread TP. */
1705 use_displaced_stepping (thread_info
*tp
)
1707 /* If the user disabled it explicitly, don't use displaced stepping. */
1708 if (can_use_displaced_stepping
== AUTO_BOOLEAN_FALSE
)
1711 /* If "auto", only use displaced stepping if the target operates in a non-stop
1713 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
1714 && !target_is_non_stop_p ())
1717 gdbarch
*gdbarch
= get_thread_regcache (tp
)->arch ();
1719 /* If the architecture doesn't implement displaced stepping, don't use
1721 if (!gdbarch_supports_displaced_stepping (gdbarch
))
1724 /* If recording, don't use displaced stepping. */
1725 if (find_record_target () != nullptr)
1728 /* If displaced stepping failed before for this inferior, don't bother trying
1730 if (tp
->inf
->displaced_step_state
.failed_before
)
1736 /* Simple function wrapper around displaced_step_thread_state::reset. */
1739 displaced_step_reset (displaced_step_thread_state
*displaced
)
1741 displaced
->reset ();
1744 /* A cleanup that wraps displaced_step_reset. We use this instead of, say,
1745 SCOPE_EXIT, because it needs to be discardable with "cleanup.release ()". */
1747 using displaced_step_reset_cleanup
= FORWARD_SCOPE_EXIT (displaced_step_reset
);
1749 /* Prepare to single-step, using displaced stepping.
1751 Note that we cannot use displaced stepping when we have a signal to
1752 deliver. If we have a signal to deliver and an instruction to step
1753 over, then after the step, there will be no indication from the
1754 target whether the thread entered a signal handler or ignored the
1755 signal and stepped over the instruction successfully --- both cases
1756 result in a simple SIGTRAP. In the first case we mustn't do a
1757 fixup, and in the second case we must --- but we can't tell which.
1758 Comments in the code for 'random signals' in handle_inferior_event
1759 explain how we handle this case instead.
1761 Returns DISPLACED_STEP_PREPARE_STATUS_OK if preparing was successful -- this
1762 thread is going to be stepped now; DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
1763 if displaced stepping this thread got queued; or
1764 DISPLACED_STEP_PREPARE_STATUS_CANT if this instruction can't be displaced
1767 static displaced_step_prepare_status
1768 displaced_step_prepare_throw (thread_info
*tp
)
1770 regcache
*regcache
= get_thread_regcache (tp
);
1771 struct gdbarch
*gdbarch
= regcache
->arch ();
1772 displaced_step_thread_state
&disp_step_thread_state
1773 = tp
->displaced_step_state
;
1775 /* We should never reach this function if the architecture does not
1776 support displaced stepping. */
1777 gdb_assert (gdbarch_supports_displaced_stepping (gdbarch
));
1779 /* Nor if the thread isn't meant to step over a breakpoint. */
1780 gdb_assert (tp
->control
.trap_expected
);
1782 /* Disable range stepping while executing in the scratch pad. We
1783 want a single-step even if executing the displaced instruction in
1784 the scratch buffer lands within the stepping range (e.g., a
1786 tp
->control
.may_range_step
= 0;
1788 /* We are about to start a displaced step for this thread. If one is already
1789 in progress, something's wrong. */
1790 gdb_assert (!disp_step_thread_state
.in_progress ());
1792 if (tp
->inf
->displaced_step_state
.unavailable
)
1794 /* The gdbarch tells us it's not worth asking to try a prepare because
1795 it is likely that it will return unavailable, so don't bother asking. */
1797 displaced_debug_printf ("deferring step of %s",
1798 tp
->ptid
.to_string ().c_str ());
1800 global_thread_step_over_chain_enqueue (tp
);
1801 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1804 displaced_debug_printf ("displaced-stepping %s now",
1805 tp
->ptid
.to_string ().c_str ());
1807 scoped_restore_current_thread restore_thread
;
1809 switch_to_thread (tp
);
1811 CORE_ADDR original_pc
= regcache_read_pc (regcache
);
1812 CORE_ADDR displaced_pc
;
1814 /* Display the instruction we are going to displaced step. */
1815 if (debug_displaced
)
1817 string_file tmp_stream
;
1818 int dislen
= gdb_print_insn (gdbarch
, original_pc
, &tmp_stream
,
1823 gdb::byte_vector
insn_buf (dislen
);
1824 read_memory (original_pc
, insn_buf
.data (), insn_buf
.size ());
1826 std::string insn_bytes
= bytes_to_string (insn_buf
);
1828 displaced_debug_printf ("original insn %s: %s \t %s",
1829 paddress (gdbarch
, original_pc
),
1830 insn_bytes
.c_str (),
1831 tmp_stream
.string ().c_str ());
1834 displaced_debug_printf ("original insn %s: invalid length: %d",
1835 paddress (gdbarch
, original_pc
), dislen
);
1838 displaced_step_prepare_status status
1839 = gdbarch_displaced_step_prepare (gdbarch
, tp
, displaced_pc
);
1841 if (status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
1843 displaced_debug_printf ("failed to prepare (%s)",
1844 tp
->ptid
.to_string ().c_str ());
1846 return DISPLACED_STEP_PREPARE_STATUS_CANT
;
1848 else if (status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
1850 /* Not enough displaced stepping resources available, defer this
1851 request by placing it the queue. */
1853 displaced_debug_printf ("not enough resources available, "
1854 "deferring step of %s",
1855 tp
->ptid
.to_string ().c_str ());
1857 global_thread_step_over_chain_enqueue (tp
);
1859 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1862 gdb_assert (status
== DISPLACED_STEP_PREPARE_STATUS_OK
);
1864 /* Save the information we need to fix things up if the step
1866 disp_step_thread_state
.set (gdbarch
);
1868 tp
->inf
->displaced_step_state
.in_progress_count
++;
1870 displaced_debug_printf ("prepared successfully thread=%s, "
1871 "original_pc=%s, displaced_pc=%s",
1872 tp
->ptid
.to_string ().c_str (),
1873 paddress (gdbarch
, original_pc
),
1874 paddress (gdbarch
, displaced_pc
));
1876 /* Display the new displaced instruction(s). */
1877 if (debug_displaced
)
1879 string_file tmp_stream
;
1880 CORE_ADDR addr
= displaced_pc
;
1882 /* If displaced stepping is going to use h/w single step then we know
1883 that the replacement instruction can only be a single instruction,
1884 in that case set the end address at the next byte.
1886 Otherwise the displaced stepping copy instruction routine could
1887 have generated multiple instructions, and all we know is that they
1888 must fit within the LEN bytes of the buffer. */
1890 = addr
+ (gdbarch_displaced_step_hw_singlestep (gdbarch
)
1891 ? 1 : gdbarch_displaced_step_buffer_length (gdbarch
));
1895 int dislen
= gdb_print_insn (gdbarch
, addr
, &tmp_stream
, nullptr);
1898 displaced_debug_printf
1899 ("replacement insn %s: invalid length: %d",
1900 paddress (gdbarch
, addr
), dislen
);
1904 gdb::byte_vector
insn_buf (dislen
);
1905 read_memory (addr
, insn_buf
.data (), insn_buf
.size ());
1907 std::string insn_bytes
= bytes_to_string (insn_buf
);
1908 std::string insn_str
= tmp_stream
.release ();
1909 displaced_debug_printf ("replacement insn %s: %s \t %s",
1910 paddress (gdbarch
, addr
),
1911 insn_bytes
.c_str (),
1917 return DISPLACED_STEP_PREPARE_STATUS_OK
;
1920 /* Wrapper for displaced_step_prepare_throw that disabled further
1921 attempts at displaced stepping if we get a memory error. */
1923 static displaced_step_prepare_status
1924 displaced_step_prepare (thread_info
*thread
)
1926 displaced_step_prepare_status status
1927 = DISPLACED_STEP_PREPARE_STATUS_CANT
;
1931 status
= displaced_step_prepare_throw (thread
);
1933 catch (const gdb_exception_error
&ex
)
1935 if (ex
.error
!= MEMORY_ERROR
1936 && ex
.error
!= NOT_SUPPORTED_ERROR
)
1939 infrun_debug_printf ("caught exception, disabling displaced stepping: %s",
1942 /* Be verbose if "set displaced-stepping" is "on", silent if
1944 if (can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1946 warning (_("disabling displaced stepping: %s"),
1950 /* Disable further displaced stepping attempts. */
1951 thread
->inf
->displaced_step_state
.failed_before
= 1;
1957 /* Maybe disable thread-{cloned,created,exited} event reporting after
1958 a step-over (either in-line or displaced) finishes. */
1961 update_thread_events_after_step_over (thread_info
*event_thread
,
1962 const target_waitstatus
&event_status
)
1964 if (target_supports_set_thread_options (0))
1966 /* We can control per-thread options. Disable events for the
1967 event thread, unless the thread is gone. */
1968 if (event_status
.kind () != TARGET_WAITKIND_THREAD_EXITED
)
1969 event_thread
->set_thread_options (0);
1973 /* We can only control the target-wide target_thread_events
1974 setting. Disable it, but only if other threads don't need it
1976 if (!displaced_step_in_progress_any_thread ())
1977 target_thread_events (false);
1981 /* If we displaced stepped an instruction successfully, adjust registers and
1982 memory to yield the same effect the instruction would have had if we had
1983 executed it at its original address, and return
1984 DISPLACED_STEP_FINISH_STATUS_OK. If the instruction didn't complete,
1985 relocate the PC and return DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED.
1987 If the thread wasn't displaced stepping, return
1988 DISPLACED_STEP_FINISH_STATUS_OK as well. */
1990 static displaced_step_finish_status
1991 displaced_step_finish (thread_info
*event_thread
,
1992 const target_waitstatus
&event_status
)
1994 /* Check whether the parent is displaced stepping. */
1995 struct regcache
*regcache
= get_thread_regcache (event_thread
);
1996 struct gdbarch
*gdbarch
= regcache
->arch ();
1997 inferior
*parent_inf
= event_thread
->inf
;
1999 /* If this was a fork/vfork/clone, this event indicates that the
2000 displaced stepping of the syscall instruction has been done, so
2001 we perform cleanup for parent here. Also note that this
2002 operation also cleans up the child for vfork, because their pages
2005 /* If this is a fork (child gets its own address space copy) and
2006 some displaced step buffers were in use at the time of the fork,
2007 restore the displaced step buffer bytes in the child process.
2009 Architectures which support displaced stepping and fork events
2010 must supply an implementation of
2011 gdbarch_displaced_step_restore_all_in_ptid. This is not enforced
2012 during gdbarch validation to support architectures which support
2013 displaced stepping but not forks. */
2014 if (event_status
.kind () == TARGET_WAITKIND_FORKED
2015 && gdbarch_supports_displaced_stepping (gdbarch
))
2016 gdbarch_displaced_step_restore_all_in_ptid
2017 (gdbarch
, parent_inf
, event_status
.child_ptid ());
2019 displaced_step_thread_state
*displaced
= &event_thread
->displaced_step_state
;
2021 /* Was this thread performing a displaced step? */
2022 if (!displaced
->in_progress ())
2023 return DISPLACED_STEP_FINISH_STATUS_OK
;
2025 update_thread_events_after_step_over (event_thread
, event_status
);
2027 gdb_assert (event_thread
->inf
->displaced_step_state
.in_progress_count
> 0);
2028 event_thread
->inf
->displaced_step_state
.in_progress_count
--;
2030 /* Fixup may need to read memory/registers. Switch to the thread
2031 that we're fixing up. Also, target_stopped_by_watchpoint checks
2032 the current thread, and displaced_step_restore performs ptid-dependent
2033 memory accesses using current_inferior(). */
2034 switch_to_thread (event_thread
);
2036 displaced_step_reset_cleanup
cleanup (displaced
);
2038 /* Do the fixup, and release the resources acquired to do the displaced
2040 displaced_step_finish_status status
2041 = gdbarch_displaced_step_finish (displaced
->get_original_gdbarch (),
2042 event_thread
, event_status
);
2044 if (event_status
.kind () == TARGET_WAITKIND_FORKED
2045 || event_status
.kind () == TARGET_WAITKIND_VFORKED
2046 || event_status
.kind () == TARGET_WAITKIND_THREAD_CLONED
)
2048 /* Since the vfork/fork/clone syscall instruction was executed
2049 in the scratchpad, the child's PC is also within the
2050 scratchpad. Set the child's PC to the parent's PC value,
2051 which has already been fixed up. Note: we use the parent's
2052 aspace here, although we're touching the child, because the
2053 child hasn't been added to the inferior list yet at this
2056 struct regcache
*child_regcache
2057 = get_thread_arch_aspace_regcache (parent_inf
,
2058 event_status
.child_ptid (),
2060 parent_inf
->aspace
);
2061 /* Read PC value of parent. */
2062 CORE_ADDR parent_pc
= regcache_read_pc (regcache
);
2064 displaced_debug_printf ("write child pc from %s to %s",
2066 regcache_read_pc (child_regcache
)),
2067 paddress (gdbarch
, parent_pc
));
2069 regcache_write_pc (child_regcache
, parent_pc
);
2075 /* Data to be passed around while handling an event. This data is
2076 discarded between events. */
2077 struct execution_control_state
2079 explicit execution_control_state (thread_info
*thr
= nullptr)
2080 : ptid (thr
== nullptr ? null_ptid
: thr
->ptid
),
2085 process_stratum_target
*target
= nullptr;
2087 /* The thread that got the event, if this was a thread event; NULL
2089 struct thread_info
*event_thread
;
2091 struct target_waitstatus ws
;
2092 int stop_func_filled_in
= 0;
2093 CORE_ADDR stop_func_alt_start
= 0;
2094 CORE_ADDR stop_func_start
= 0;
2095 CORE_ADDR stop_func_end
= 0;
2096 const char *stop_func_name
= nullptr;
2097 int wait_some_more
= 0;
2099 /* True if the event thread hit the single-step breakpoint of
2100 another thread. Thus the event doesn't cause a stop, the thread
2101 needs to be single-stepped past the single-step breakpoint before
2102 we can switch back to the original stepping thread. */
2103 int hit_singlestep_breakpoint
= 0;
2106 static void keep_going_pass_signal (struct execution_control_state
*ecs
);
2107 static void prepare_to_wait (struct execution_control_state
*ecs
);
2108 static bool keep_going_stepped_thread (struct thread_info
*tp
);
2109 static step_over_what
thread_still_needs_step_over (struct thread_info
*tp
);
2111 /* Are there any pending step-over requests? If so, run all we can
2112 now and return true. Otherwise, return false. */
2115 start_step_over (void)
2117 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
2119 /* Don't start a new step-over if we already have an in-line
2120 step-over operation ongoing. */
2121 if (step_over_info_valid_p ())
2124 /* Steal the global thread step over chain. As we try to initiate displaced
2125 steps, threads will be enqueued in the global chain if no buffers are
2126 available. If we iterated on the global chain directly, we might iterate
2128 thread_step_over_list threads_to_step
2129 = std::move (global_thread_step_over_list
);
2131 infrun_debug_printf ("stealing global queue of threads to step, length = %d",
2132 thread_step_over_chain_length (threads_to_step
));
2134 bool started
= false;
2136 /* On scope exit (whatever the reason, return or exception), if there are
2137 threads left in the THREADS_TO_STEP chain, put back these threads in the
2141 if (threads_to_step
.empty ())
2142 infrun_debug_printf ("step-over queue now empty");
2145 infrun_debug_printf ("putting back %d threads to step in global queue",
2146 thread_step_over_chain_length (threads_to_step
));
2148 global_thread_step_over_chain_enqueue_chain
2149 (std::move (threads_to_step
));
2153 thread_step_over_list_safe_range range
2154 = make_thread_step_over_list_safe_range (threads_to_step
);
2156 for (thread_info
*tp
: range
)
2158 step_over_what step_what
;
2159 int must_be_in_line
;
2161 gdb_assert (!tp
->stop_requested
);
2163 if (tp
->inf
->displaced_step_state
.unavailable
)
2165 /* The arch told us to not even try preparing another displaced step
2166 for this inferior. Just leave the thread in THREADS_TO_STEP, it
2167 will get moved to the global chain on scope exit. */
2171 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr)
2173 /* When we stop all threads, handling a vfork, any thread in the step
2174 over chain remains there. A user could also try to continue a
2175 thread stopped at a breakpoint while another thread is waiting for
2176 a vfork-done event. In any case, we don't want to start a step
2181 /* Remove thread from the THREADS_TO_STEP chain. If anything goes wrong
2182 while we try to prepare the displaced step, we don't add it back to
2183 the global step over chain. This is to avoid a thread staying in the
2184 step over chain indefinitely if something goes wrong when resuming it
2185 If the error is intermittent and it still needs a step over, it will
2186 get enqueued again when we try to resume it normally. */
2187 threads_to_step
.erase (threads_to_step
.iterator_to (*tp
));
2189 step_what
= thread_still_needs_step_over (tp
);
2190 must_be_in_line
= ((step_what
& STEP_OVER_WATCHPOINT
)
2191 || ((step_what
& STEP_OVER_BREAKPOINT
)
2192 && !use_displaced_stepping (tp
)));
2194 /* We currently stop all threads of all processes to step-over
2195 in-line. If we need to start a new in-line step-over, let
2196 any pending displaced steps finish first. */
2197 if (must_be_in_line
&& displaced_step_in_progress_any_thread ())
2199 global_thread_step_over_chain_enqueue (tp
);
2203 if (tp
->control
.trap_expected
2205 || tp
->executing ())
2207 internal_error ("[%s] has inconsistent state: "
2208 "trap_expected=%d, resumed=%d, executing=%d\n",
2209 tp
->ptid
.to_string ().c_str (),
2210 tp
->control
.trap_expected
,
2215 infrun_debug_printf ("resuming [%s] for step-over",
2216 tp
->ptid
.to_string ().c_str ());
2218 /* keep_going_pass_signal skips the step-over if the breakpoint
2219 is no longer inserted. In all-stop, we want to keep looking
2220 for a thread that needs a step-over instead of resuming TP,
2221 because we wouldn't be able to resume anything else until the
2222 target stops again. In non-stop, the resume always resumes
2223 only TP, so it's OK to let the thread resume freely. */
2224 if (!target_is_non_stop_p () && !step_what
)
2227 switch_to_thread (tp
);
2228 execution_control_state
ecs (tp
);
2229 keep_going_pass_signal (&ecs
);
2231 if (!ecs
.wait_some_more
)
2232 error (_("Command aborted."));
2234 /* If the thread's step over could not be initiated because no buffers
2235 were available, it was re-added to the global step over chain. */
2238 infrun_debug_printf ("[%s] was resumed.",
2239 tp
->ptid
.to_string ().c_str ());
2240 gdb_assert (!thread_is_in_step_over_chain (tp
));
2244 infrun_debug_printf ("[%s] was NOT resumed.",
2245 tp
->ptid
.to_string ().c_str ());
2246 gdb_assert (thread_is_in_step_over_chain (tp
));
2249 /* If we started a new in-line step-over, we're done. */
2250 if (step_over_info_valid_p ())
2252 gdb_assert (tp
->control
.trap_expected
);
2257 if (!target_is_non_stop_p ())
2259 /* On all-stop, shouldn't have resumed unless we needed a
2261 gdb_assert (tp
->control
.trap_expected
2262 || tp
->step_after_step_resume_breakpoint
);
2264 /* With remote targets (at least), in all-stop, we can't
2265 issue any further remote commands until the program stops
2271 /* Either the thread no longer needed a step-over, or a new
2272 displaced stepping sequence started. Even in the latter
2273 case, continue looking. Maybe we can also start another
2274 displaced step on a thread of other process. */
2280 /* Update global variables holding ptids to hold NEW_PTID if they were
2281 holding OLD_PTID. */
2283 infrun_thread_ptid_changed (process_stratum_target
*target
,
2284 ptid_t old_ptid
, ptid_t new_ptid
)
2286 if (inferior_ptid
== old_ptid
2287 && current_inferior ()->process_target () == target
)
2288 inferior_ptid
= new_ptid
;
2293 static const char schedlock_off
[] = "off";
2294 static const char schedlock_on
[] = "on";
2295 static const char schedlock_step
[] = "step";
2296 static const char schedlock_replay
[] = "replay";
2297 static const char *const scheduler_enums
[] = {
2304 static const char *scheduler_mode
= schedlock_replay
;
2306 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
2307 struct cmd_list_element
*c
, const char *value
)
2310 _("Mode for locking scheduler "
2311 "during execution is \"%s\".\n"),
2316 set_schedlock_func (const char *args
, int from_tty
, struct cmd_list_element
*c
)
2318 if (!target_can_lock_scheduler ())
2320 scheduler_mode
= schedlock_off
;
2321 error (_("Target '%s' cannot support this command."),
2322 target_shortname ());
2326 /* True if execution commands resume all threads of all processes by
2327 default; otherwise, resume only threads of the current inferior
2329 bool sched_multi
= false;
2331 /* Try to setup for software single stepping. Return true if target_resume()
2332 should use hardware single step.
2334 GDBARCH the current gdbarch. */
2337 maybe_software_singlestep (struct gdbarch
*gdbarch
)
2339 bool hw_step
= true;
2341 if (execution_direction
== EXEC_FORWARD
2342 && gdbarch_software_single_step_p (gdbarch
))
2343 hw_step
= !insert_single_step_breakpoints (gdbarch
);
2351 user_visible_resume_ptid (int step
)
2357 /* With non-stop mode on, threads are always handled
2359 resume_ptid
= inferior_ptid
;
2361 else if ((scheduler_mode
== schedlock_on
)
2362 || (scheduler_mode
== schedlock_step
&& step
))
2364 /* User-settable 'scheduler' mode requires solo thread
2366 resume_ptid
= inferior_ptid
;
2368 else if ((scheduler_mode
== schedlock_replay
)
2369 && target_record_will_replay (minus_one_ptid
, execution_direction
))
2371 /* User-settable 'scheduler' mode requires solo thread resume in replay
2373 resume_ptid
= inferior_ptid
;
2375 else if (!sched_multi
&& target_supports_multi_process ())
2377 /* Resume all threads of the current process (and none of other
2379 resume_ptid
= ptid_t (inferior_ptid
.pid ());
2383 /* Resume all threads of all processes. */
2384 resume_ptid
= RESUME_ALL
;
2392 process_stratum_target
*
2393 user_visible_resume_target (ptid_t resume_ptid
)
2395 return (resume_ptid
== minus_one_ptid
&& sched_multi
2397 : current_inferior ()->process_target ());
2400 /* Find a thread from the inferiors that we'll resume that is waiting
2401 for a vfork-done event. */
2403 static thread_info
*
2404 find_thread_waiting_for_vfork_done ()
2406 gdb_assert (!target_is_non_stop_p ());
2410 for (inferior
*inf
: all_non_exited_inferiors ())
2411 if (inf
->thread_waiting_for_vfork_done
!= nullptr)
2412 return inf
->thread_waiting_for_vfork_done
;
2416 inferior
*cur_inf
= current_inferior ();
2417 if (cur_inf
->thread_waiting_for_vfork_done
!= nullptr)
2418 return cur_inf
->thread_waiting_for_vfork_done
;
2423 /* Return a ptid representing the set of threads that we will resume,
2424 in the perspective of the target, assuming run control handling
2425 does not require leaving some threads stopped (e.g., stepping past
2426 breakpoint). USER_STEP indicates whether we're about to start the
2427 target for a stepping command. */
2430 internal_resume_ptid (int user_step
)
2432 /* In non-stop, we always control threads individually. Note that
2433 the target may always work in non-stop mode even with "set
2434 non-stop off", in which case user_visible_resume_ptid could
2435 return a wildcard ptid. */
2436 if (target_is_non_stop_p ())
2437 return inferior_ptid
;
2439 /* The rest of the function assumes non-stop==off and
2440 target-non-stop==off.
2442 If a thread is waiting for a vfork-done event, it means breakpoints are out
2443 for this inferior (well, program space in fact). We don't want to resume
2444 any thread other than the one waiting for vfork done, otherwise these other
2445 threads could miss breakpoints. So if a thread in the resumption set is
2446 waiting for a vfork-done event, resume only that thread.
2448 The resumption set width depends on whether schedule-multiple is on or off.
2450 Note that if the target_resume interface was more flexible, we could be
2451 smarter here when schedule-multiple is on. For example, imagine 3
2452 inferiors with 2 threads each (1.1, 1.2, 2.1, 2.2, 3.1 and 3.2). Threads
2453 2.1 and 3.2 are both waiting for a vfork-done event. Then we could ask the
2454 target(s) to resume:
2456 - All threads of inferior 1
2460 Since we don't have that flexibility (we can only pass one ptid), just
2461 resume the first thread waiting for a vfork-done event we find (e.g. thread
2463 thread_info
*thr
= find_thread_waiting_for_vfork_done ();
2466 /* If we have a thread that is waiting for a vfork-done event,
2467 then we should have switched to it earlier. Calling
2468 target_resume with thread scope is only possible when the
2469 current thread matches the thread scope. */
2470 gdb_assert (thr
->ptid
== inferior_ptid
);
2471 gdb_assert (thr
->inf
->process_target ()
2472 == inferior_thread ()->inf
->process_target ());
2476 return user_visible_resume_ptid (user_step
);
2479 /* Wrapper for target_resume, that handles infrun-specific
2483 do_target_resume (ptid_t resume_ptid
, bool step
, enum gdb_signal sig
)
2485 struct thread_info
*tp
= inferior_thread ();
2487 gdb_assert (!tp
->stop_requested
);
2489 /* Install inferior's terminal modes. */
2490 target_terminal::inferior ();
2492 /* Avoid confusing the next resume, if the next stop/resume
2493 happens to apply to another thread. */
2494 tp
->set_stop_signal (GDB_SIGNAL_0
);
2496 /* Advise target which signals may be handled silently.
2498 If we have removed breakpoints because we are stepping over one
2499 in-line (in any thread), we need to receive all signals to avoid
2500 accidentally skipping a breakpoint during execution of a signal
2503 Likewise if we're displaced stepping, otherwise a trap for a
2504 breakpoint in a signal handler might be confused with the
2505 displaced step finishing. We don't make the displaced_step_finish
2506 step distinguish the cases instead, because:
2508 - a backtrace while stopped in the signal handler would show the
2509 scratch pad as frame older than the signal handler, instead of
2510 the real mainline code.
2512 - when the thread is later resumed, the signal handler would
2513 return to the scratch pad area, which would no longer be
2515 if (step_over_info_valid_p ()
2516 || displaced_step_in_progress (tp
->inf
))
2517 target_pass_signals ({});
2519 target_pass_signals (signal_pass
);
2521 /* Request that the target report thread-{created,cloned,exited}
2522 events in the following situations:
2524 - If we are performing an in-line step-over-breakpoint, then we
2525 will remove a breakpoint from the target and only run the
2526 current thread. We don't want any new thread (spawned by the
2527 step) to start running, as it might miss the breakpoint. We
2528 need to clear the step-over state if the stepped thread exits,
2529 so we also enable thread-exit events.
2531 - If we are stepping over a breakpoint out of line (displaced
2532 stepping) then we won't remove a breakpoint from the target,
2533 but, if the step spawns a new clone thread, then we will need
2534 to fixup the $pc address in the clone child too, so we need it
2535 to start stopped. We need to release the displaced stepping
2536 buffer if the stepped thread exits, so we also enable
2539 if (step_over_info_valid_p ()
2540 || displaced_step_in_progress_thread (tp
))
2542 gdb_thread_options options
2543 = GDB_THREAD_OPTION_CLONE
| GDB_THREAD_OPTION_EXIT
;
2544 if (target_supports_set_thread_options (options
))
2545 tp
->set_thread_options (options
);
2547 target_thread_events (true);
2550 /* If we're resuming more than one thread simultaneously, then any
2551 thread other than the leader is being set to run free. Clear any
2552 previous thread option for those threads. */
2553 if (resume_ptid
!= inferior_ptid
&& target_supports_set_thread_options (0))
2555 process_stratum_target
*resume_target
= tp
->inf
->process_target ();
2556 for (thread_info
*thr_iter
: all_non_exited_threads (resume_target
,
2559 thr_iter
->set_thread_options (0);
2562 infrun_debug_printf ("resume_ptid=%s, step=%d, sig=%s",
2563 resume_ptid
.to_string ().c_str (),
2564 step
, gdb_signal_to_symbol_string (sig
));
2566 target_resume (resume_ptid
, step
, sig
);
2569 /* Resume the inferior. SIG is the signal to give the inferior
2570 (GDB_SIGNAL_0 for none). Note: don't call this directly; instead
2571 call 'resume', which handles exceptions. */
2574 resume_1 (enum gdb_signal sig
)
2576 struct regcache
*regcache
= get_current_regcache ();
2577 struct gdbarch
*gdbarch
= regcache
->arch ();
2578 struct thread_info
*tp
= inferior_thread ();
2579 const address_space
*aspace
= regcache
->aspace ();
2581 /* This represents the user's step vs continue request. When
2582 deciding whether "set scheduler-locking step" applies, it's the
2583 user's intention that counts. */
2584 const int user_step
= tp
->control
.stepping_command
;
2585 /* This represents what we'll actually request the target to do.
2586 This can decay from a step to a continue, if e.g., we need to
2587 implement single-stepping with breakpoints (software
2591 gdb_assert (!tp
->stop_requested
);
2592 gdb_assert (!thread_is_in_step_over_chain (tp
));
2594 if (tp
->has_pending_waitstatus ())
2597 ("thread %s has pending wait "
2598 "status %s (currently_stepping=%d).",
2599 tp
->ptid
.to_string ().c_str (),
2600 tp
->pending_waitstatus ().to_string ().c_str (),
2601 currently_stepping (tp
));
2603 tp
->inf
->process_target ()->threads_executing
= true;
2604 tp
->set_resumed (true);
2606 /* FIXME: What should we do if we are supposed to resume this
2607 thread with a signal? Maybe we should maintain a queue of
2608 pending signals to deliver. */
2609 if (sig
!= GDB_SIGNAL_0
)
2611 warning (_("Couldn't deliver signal %s to %s."),
2612 gdb_signal_to_name (sig
),
2613 tp
->ptid
.to_string ().c_str ());
2616 tp
->set_stop_signal (GDB_SIGNAL_0
);
2618 if (target_can_async_p ())
2620 target_async (true);
2621 /* Tell the event loop we have an event to process. */
2622 mark_async_event_handler (infrun_async_inferior_event_token
);
2627 tp
->stepped_breakpoint
= 0;
2629 /* Depends on stepped_breakpoint. */
2630 step
= currently_stepping (tp
);
2632 if (current_inferior ()->thread_waiting_for_vfork_done
!= nullptr)
2634 /* Don't try to single-step a vfork parent that is waiting for
2635 the child to get out of the shared memory region (by exec'ing
2636 or exiting). This is particularly important on software
2637 single-step archs, as the child process would trip on the
2638 software single step breakpoint inserted for the parent
2639 process. Since the parent will not actually execute any
2640 instruction until the child is out of the shared region (such
2641 are vfork's semantics), it is safe to simply continue it.
2642 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2643 the parent, and tell it to `keep_going', which automatically
2644 re-sets it stepping. */
2645 infrun_debug_printf ("resume : clear step");
2649 CORE_ADDR pc
= regcache_read_pc (regcache
);
2651 infrun_debug_printf ("step=%d, signal=%s, trap_expected=%d, "
2652 "current thread [%s] at %s",
2653 step
, gdb_signal_to_symbol_string (sig
),
2654 tp
->control
.trap_expected
,
2655 inferior_ptid
.to_string ().c_str (),
2656 paddress (gdbarch
, pc
));
2658 /* Normally, by the time we reach `resume', the breakpoints are either
2659 removed or inserted, as appropriate. The exception is if we're sitting
2660 at a permanent breakpoint; we need to step over it, but permanent
2661 breakpoints can't be removed. So we have to test for it here. */
2662 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2664 if (sig
!= GDB_SIGNAL_0
)
2666 /* We have a signal to pass to the inferior. The resume
2667 may, or may not take us to the signal handler. If this
2668 is a step, we'll need to stop in the signal handler, if
2669 there's one, (if the target supports stepping into
2670 handlers), or in the next mainline instruction, if
2671 there's no handler. If this is a continue, we need to be
2672 sure to run the handler with all breakpoints inserted.
2673 In all cases, set a breakpoint at the current address
2674 (where the handler returns to), and once that breakpoint
2675 is hit, resume skipping the permanent breakpoint. If
2676 that breakpoint isn't hit, then we've stepped into the
2677 signal handler (or hit some other event). We'll delete
2678 the step-resume breakpoint then. */
2680 infrun_debug_printf ("resume: skipping permanent breakpoint, "
2681 "deliver signal first");
2683 clear_step_over_info ();
2684 tp
->control
.trap_expected
= 0;
2686 if (tp
->control
.step_resume_breakpoint
== nullptr)
2688 /* Set a "high-priority" step-resume, as we don't want
2689 user breakpoints at PC to trigger (again) when this
2691 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2692 gdb_assert (tp
->control
.step_resume_breakpoint
->first_loc ()
2695 tp
->step_after_step_resume_breakpoint
= step
;
2698 insert_breakpoints ();
2702 /* There's no signal to pass, we can go ahead and skip the
2703 permanent breakpoint manually. */
2704 infrun_debug_printf ("skipping permanent breakpoint");
2705 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2706 /* Update pc to reflect the new address from which we will
2707 execute instructions. */
2708 pc
= regcache_read_pc (regcache
);
2712 /* We've already advanced the PC, so the stepping part
2713 is done. Now we need to arrange for a trap to be
2714 reported to handle_inferior_event. Set a breakpoint
2715 at the current PC, and run to it. Don't update
2716 prev_pc, because if we end in
2717 switch_back_to_stepped_thread, we want the "expected
2718 thread advanced also" branch to be taken. IOW, we
2719 don't want this thread to step further from PC
2721 gdb_assert (!step_over_info_valid_p ());
2722 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
2723 insert_breakpoints ();
2725 resume_ptid
= internal_resume_ptid (user_step
);
2726 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
2727 tp
->set_resumed (true);
2733 /* If we have a breakpoint to step over, make sure to do a single
2734 step only. Same if we have software watchpoints. */
2735 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2736 tp
->control
.may_range_step
= 0;
2738 /* If displaced stepping is enabled, step over breakpoints by executing a
2739 copy of the instruction at a different address.
2741 We can't use displaced stepping when we have a signal to deliver;
2742 the comments for displaced_step_prepare explain why. The
2743 comments in the handle_inferior event for dealing with 'random
2744 signals' explain what we do instead.
2746 We can't use displaced stepping when we are waiting for vfork_done
2747 event, displaced stepping breaks the vfork child similarly as single
2748 step software breakpoint. */
2749 if (tp
->control
.trap_expected
2750 && use_displaced_stepping (tp
)
2751 && !step_over_info_valid_p ()
2752 && sig
== GDB_SIGNAL_0
2753 && current_inferior ()->thread_waiting_for_vfork_done
== nullptr)
2755 displaced_step_prepare_status prepare_status
2756 = displaced_step_prepare (tp
);
2758 if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
2760 infrun_debug_printf ("Got placed in step-over queue");
2762 tp
->control
.trap_expected
= 0;
2765 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
2767 /* Fallback to stepping over the breakpoint in-line. */
2769 if (target_is_non_stop_p ())
2770 stop_all_threads ("displaced stepping falling back on inline stepping");
2772 set_step_over_info (regcache
->aspace (),
2773 regcache_read_pc (regcache
), 0, tp
->global_num
);
2775 step
= maybe_software_singlestep (gdbarch
);
2777 insert_breakpoints ();
2779 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_OK
)
2781 /* Update pc to reflect the new address from which we will
2782 execute instructions due to displaced stepping. */
2783 pc
= regcache_read_pc (get_thread_regcache (tp
));
2785 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
);
2788 gdb_assert_not_reached ("Invalid displaced_step_prepare_status "
2792 /* Do we need to do it the hard way, w/temp breakpoints? */
2794 step
= maybe_software_singlestep (gdbarch
);
2796 /* Currently, our software single-step implementation leads to different
2797 results than hardware single-stepping in one situation: when stepping
2798 into delivering a signal which has an associated signal handler,
2799 hardware single-step will stop at the first instruction of the handler,
2800 while software single-step will simply skip execution of the handler.
2802 For now, this difference in behavior is accepted since there is no
2803 easy way to actually implement single-stepping into a signal handler
2804 without kernel support.
2806 However, there is one scenario where this difference leads to follow-on
2807 problems: if we're stepping off a breakpoint by removing all breakpoints
2808 and then single-stepping. In this case, the software single-step
2809 behavior means that even if there is a *breakpoint* in the signal
2810 handler, GDB still would not stop.
2812 Fortunately, we can at least fix this particular issue. We detect
2813 here the case where we are about to deliver a signal while software
2814 single-stepping with breakpoints removed. In this situation, we
2815 revert the decisions to remove all breakpoints and insert single-
2816 step breakpoints, and instead we install a step-resume breakpoint
2817 at the current address, deliver the signal without stepping, and
2818 once we arrive back at the step-resume breakpoint, actually step
2819 over the breakpoint we originally wanted to step over. */
2820 if (thread_has_single_step_breakpoints_set (tp
)
2821 && sig
!= GDB_SIGNAL_0
2822 && step_over_info_valid_p ())
2824 /* If we have nested signals or a pending signal is delivered
2825 immediately after a handler returns, might already have
2826 a step-resume breakpoint set on the earlier handler. We cannot
2827 set another step-resume breakpoint; just continue on until the
2828 original breakpoint is hit. */
2829 if (tp
->control
.step_resume_breakpoint
== nullptr)
2831 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2832 tp
->step_after_step_resume_breakpoint
= 1;
2835 delete_single_step_breakpoints (tp
);
2837 clear_step_over_info ();
2838 tp
->control
.trap_expected
= 0;
2840 insert_breakpoints ();
2843 /* If STEP is set, it's a request to use hardware stepping
2844 facilities. But in that case, we should never
2845 use singlestep breakpoint. */
2846 gdb_assert (!(thread_has_single_step_breakpoints_set (tp
) && step
));
2848 /* Decide the set of threads to ask the target to resume. */
2849 if (tp
->control
.trap_expected
)
2851 /* We're allowing a thread to run past a breakpoint it has
2852 hit, either by single-stepping the thread with the breakpoint
2853 removed, or by displaced stepping, with the breakpoint inserted.
2854 In the former case, we need to single-step only this thread,
2855 and keep others stopped, as they can miss this breakpoint if
2856 allowed to run. That's not really a problem for displaced
2857 stepping, but, we still keep other threads stopped, in case
2858 another thread is also stopped for a breakpoint waiting for
2859 its turn in the displaced stepping queue. */
2860 resume_ptid
= inferior_ptid
;
2863 resume_ptid
= internal_resume_ptid (user_step
);
2865 if (execution_direction
!= EXEC_REVERSE
2866 && step
&& breakpoint_inserted_here_p (aspace
, pc
))
2868 /* There are two cases where we currently need to step a
2869 breakpoint instruction when we have a signal to deliver:
2871 - See handle_signal_stop where we handle random signals that
2872 could take out us out of the stepping range. Normally, in
2873 that case we end up continuing (instead of stepping) over the
2874 signal handler with a breakpoint at PC, but there are cases
2875 where we should _always_ single-step, even if we have a
2876 step-resume breakpoint, like when a software watchpoint is
2877 set. Assuming single-stepping and delivering a signal at the
2878 same time would takes us to the signal handler, then we could
2879 have removed the breakpoint at PC to step over it. However,
2880 some hardware step targets (like e.g., Mac OS) can't step
2881 into signal handlers, and for those, we need to leave the
2882 breakpoint at PC inserted, as otherwise if the handler
2883 recurses and executes PC again, it'll miss the breakpoint.
2884 So we leave the breakpoint inserted anyway, but we need to
2885 record that we tried to step a breakpoint instruction, so
2886 that adjust_pc_after_break doesn't end up confused.
2888 - In non-stop if we insert a breakpoint (e.g., a step-resume)
2889 in one thread after another thread that was stepping had been
2890 momentarily paused for a step-over. When we re-resume the
2891 stepping thread, it may be resumed from that address with a
2892 breakpoint that hasn't trapped yet. Seen with
2893 gdb.threads/non-stop-fair-events.exp, on targets that don't
2894 do displaced stepping. */
2896 infrun_debug_printf ("resume: [%s] stepped breakpoint",
2897 tp
->ptid
.to_string ().c_str ());
2899 tp
->stepped_breakpoint
= 1;
2901 /* Most targets can step a breakpoint instruction, thus
2902 executing it normally. But if this one cannot, just
2903 continue and we will hit it anyway. */
2904 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2908 if (tp
->control
.may_range_step
)
2910 /* If we're resuming a thread with the PC out of the step
2911 range, then we're doing some nested/finer run control
2912 operation, like stepping the thread out of the dynamic
2913 linker or the displaced stepping scratch pad. We
2914 shouldn't have allowed a range step then. */
2915 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2918 do_target_resume (resume_ptid
, step
, sig
);
2919 tp
->set_resumed (true);
2922 /* Resume the inferior. SIG is the signal to give the inferior
2923 (GDB_SIGNAL_0 for none). This is a wrapper around 'resume_1' that
2924 rolls back state on error. */
2927 resume (gdb_signal sig
)
2933 catch (const gdb_exception
&ex
)
2935 /* If resuming is being aborted for any reason, delete any
2936 single-step breakpoint resume_1 may have created, to avoid
2937 confusing the following resumption, and to avoid leaving
2938 single-step breakpoints perturbing other threads, in case
2939 we're running in non-stop mode. */
2940 if (inferior_ptid
!= null_ptid
)
2941 delete_single_step_breakpoints (inferior_thread ());
2951 /* Counter that tracks number of user visible stops. This can be used
2952 to tell whether a command has proceeded the inferior past the
2953 current location. This allows e.g., inferior function calls in
2954 breakpoint commands to not interrupt the command list. When the
2955 call finishes successfully, the inferior is standing at the same
2956 breakpoint as if nothing happened (and so we don't call
2958 static ULONGEST current_stop_id
;
2965 return current_stop_id
;
2968 /* Called when we report a user visible stop. */
2976 /* Clear out all variables saying what to do when inferior is continued.
2977 First do this, then set the ones you want, then call `proceed'. */
2980 clear_proceed_status_thread (struct thread_info
*tp
)
2982 infrun_debug_printf ("%s", tp
->ptid
.to_string ().c_str ());
2984 /* If we're starting a new sequence, then the previous finished
2985 single-step is no longer relevant. */
2986 if (tp
->has_pending_waitstatus ())
2988 if (tp
->stop_reason () == TARGET_STOPPED_BY_SINGLE_STEP
)
2990 infrun_debug_printf ("pending event of %s was a finished step. "
2992 tp
->ptid
.to_string ().c_str ());
2994 tp
->clear_pending_waitstatus ();
2995 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
3000 ("thread %s has pending wait status %s (currently_stepping=%d).",
3001 tp
->ptid
.to_string ().c_str (),
3002 tp
->pending_waitstatus ().to_string ().c_str (),
3003 currently_stepping (tp
));
3007 /* If this signal should not be seen by program, give it zero.
3008 Used for debugging signals. */
3009 if (!signal_pass_state (tp
->stop_signal ()))
3010 tp
->set_stop_signal (GDB_SIGNAL_0
);
3012 tp
->release_thread_fsm ();
3014 tp
->control
.trap_expected
= 0;
3015 tp
->control
.step_range_start
= 0;
3016 tp
->control
.step_range_end
= 0;
3017 tp
->control
.may_range_step
= 0;
3018 tp
->control
.step_frame_id
= null_frame_id
;
3019 tp
->control
.step_stack_frame_id
= null_frame_id
;
3020 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
3021 tp
->control
.step_start_function
= nullptr;
3022 tp
->stop_requested
= 0;
3024 tp
->control
.stop_step
= 0;
3026 tp
->control
.proceed_to_finish
= 0;
3028 tp
->control
.stepping_command
= 0;
3030 /* Discard any remaining commands or status from previous stop. */
3031 bpstat_clear (&tp
->control
.stop_bpstat
);
3034 /* Notify the current interpreter and observers that the target is about to
3038 notify_about_to_proceed ()
3040 top_level_interpreter ()->on_about_to_proceed ();
3041 gdb::observers::about_to_proceed
.notify ();
3045 clear_proceed_status (int step
)
3047 /* With scheduler-locking replay, stop replaying other threads if we're
3048 not replaying the user-visible resume ptid.
3050 This is a convenience feature to not require the user to explicitly
3051 stop replaying the other threads. We're assuming that the user's
3052 intent is to resume tracing the recorded process. */
3053 if (!non_stop
&& scheduler_mode
== schedlock_replay
3054 && target_record_is_replaying (minus_one_ptid
)
3055 && !target_record_will_replay (user_visible_resume_ptid (step
),
3056 execution_direction
))
3057 target_record_stop_replaying ();
3059 if (!non_stop
&& inferior_ptid
!= null_ptid
)
3061 ptid_t resume_ptid
= user_visible_resume_ptid (step
);
3062 process_stratum_target
*resume_target
3063 = user_visible_resume_target (resume_ptid
);
3065 /* In all-stop mode, delete the per-thread status of all threads
3066 we're about to resume, implicitly and explicitly. */
3067 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
3068 clear_proceed_status_thread (tp
);
3071 if (inferior_ptid
!= null_ptid
)
3073 struct inferior
*inferior
;
3077 /* If in non-stop mode, only delete the per-thread status of
3078 the current thread. */
3079 clear_proceed_status_thread (inferior_thread ());
3082 inferior
= current_inferior ();
3083 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
3086 notify_about_to_proceed ();
3089 /* Returns true if TP is still stopped at a breakpoint that needs
3090 stepping-over in order to make progress. If the breakpoint is gone
3091 meanwhile, we can skip the whole step-over dance. */
3094 thread_still_needs_step_over_bp (struct thread_info
*tp
)
3096 if (tp
->stepping_over_breakpoint
)
3098 struct regcache
*regcache
= get_thread_regcache (tp
);
3100 if (breakpoint_here_p (regcache
->aspace (),
3101 regcache_read_pc (regcache
))
3102 == ordinary_breakpoint_here
)
3105 tp
->stepping_over_breakpoint
= 0;
3111 /* Check whether thread TP still needs to start a step-over in order
3112 to make progress when resumed. Returns an bitwise or of enum
3113 step_over_what bits, indicating what needs to be stepped over. */
3115 static step_over_what
3116 thread_still_needs_step_over (struct thread_info
*tp
)
3118 step_over_what what
= 0;
3120 if (thread_still_needs_step_over_bp (tp
))
3121 what
|= STEP_OVER_BREAKPOINT
;
3123 if (tp
->stepping_over_watchpoint
3124 && !target_have_steppable_watchpoint ())
3125 what
|= STEP_OVER_WATCHPOINT
;
3130 /* Returns true if scheduler locking applies. STEP indicates whether
3131 we're about to do a step/next-like command to a thread. */
3134 schedlock_applies (struct thread_info
*tp
)
3136 return (scheduler_mode
== schedlock_on
3137 || (scheduler_mode
== schedlock_step
3138 && tp
->control
.stepping_command
)
3139 || (scheduler_mode
== schedlock_replay
3140 && target_record_will_replay (minus_one_ptid
,
3141 execution_direction
)));
3144 /* Set process_stratum_target::COMMIT_RESUMED_STATE in all target
3145 stacks that have threads executing and don't have threads with
3149 maybe_set_commit_resumed_all_targets ()
3151 scoped_restore_current_thread restore_thread
;
3153 for (inferior
*inf
: all_non_exited_inferiors ())
3155 process_stratum_target
*proc_target
= inf
->process_target ();
3157 if (proc_target
->commit_resumed_state
)
3159 /* We already set this in a previous iteration, via another
3160 inferior sharing the process_stratum target. */
3164 /* If the target has no resumed threads, it would be useless to
3165 ask it to commit the resumed threads. */
3166 if (!proc_target
->threads_executing
)
3168 infrun_debug_printf ("not requesting commit-resumed for target "
3169 "%s, no resumed threads",
3170 proc_target
->shortname ());
3174 /* As an optimization, if a thread from this target has some
3175 status to report, handle it before requiring the target to
3176 commit its resumed threads: handling the status might lead to
3177 resuming more threads. */
3178 if (proc_target
->has_resumed_with_pending_wait_status ())
3180 infrun_debug_printf ("not requesting commit-resumed for target %s, a"
3181 " thread has a pending waitstatus",
3182 proc_target
->shortname ());
3186 switch_to_inferior_no_thread (inf
);
3188 if (target_has_pending_events ())
3190 infrun_debug_printf ("not requesting commit-resumed for target %s, "
3191 "target has pending events",
3192 proc_target
->shortname ());
3196 infrun_debug_printf ("enabling commit-resumed for target %s",
3197 proc_target
->shortname ());
3199 proc_target
->commit_resumed_state
= true;
3206 maybe_call_commit_resumed_all_targets ()
3208 scoped_restore_current_thread restore_thread
;
3210 for (inferior
*inf
: all_non_exited_inferiors ())
3212 process_stratum_target
*proc_target
= inf
->process_target ();
3214 if (!proc_target
->commit_resumed_state
)
3217 switch_to_inferior_no_thread (inf
);
3219 infrun_debug_printf ("calling commit_resumed for target %s",
3220 proc_target
->shortname());
3222 target_commit_resumed ();
3226 /* To track nesting of scoped_disable_commit_resumed objects, ensuring
3227 that only the outermost one attempts to re-enable
3229 static bool enable_commit_resumed
= true;
3233 scoped_disable_commit_resumed::scoped_disable_commit_resumed
3234 (const char *reason
)
3235 : m_reason (reason
),
3236 m_prev_enable_commit_resumed (enable_commit_resumed
)
3238 infrun_debug_printf ("reason=%s", m_reason
);
3240 enable_commit_resumed
= false;
3242 for (inferior
*inf
: all_non_exited_inferiors ())
3244 process_stratum_target
*proc_target
= inf
->process_target ();
3246 if (m_prev_enable_commit_resumed
)
3248 /* This is the outermost instance: force all
3249 COMMIT_RESUMED_STATE to false. */
3250 proc_target
->commit_resumed_state
= false;
3254 /* This is not the outermost instance, we expect
3255 COMMIT_RESUMED_STATE to have been cleared by the
3256 outermost instance. */
3257 gdb_assert (!proc_target
->commit_resumed_state
);
3265 scoped_disable_commit_resumed::reset ()
3271 infrun_debug_printf ("reason=%s", m_reason
);
3273 gdb_assert (!enable_commit_resumed
);
3275 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3277 if (m_prev_enable_commit_resumed
)
3279 /* This is the outermost instance, re-enable
3280 COMMIT_RESUMED_STATE on the targets where it's possible. */
3281 maybe_set_commit_resumed_all_targets ();
3285 /* This is not the outermost instance, we expect
3286 COMMIT_RESUMED_STATE to still be false. */
3287 for (inferior
*inf
: all_non_exited_inferiors ())
3289 process_stratum_target
*proc_target
= inf
->process_target ();
3290 gdb_assert (!proc_target
->commit_resumed_state
);
3297 scoped_disable_commit_resumed::~scoped_disable_commit_resumed ()
3305 scoped_disable_commit_resumed::reset_and_commit ()
3308 maybe_call_commit_resumed_all_targets ();
3313 scoped_enable_commit_resumed::scoped_enable_commit_resumed
3314 (const char *reason
)
3315 : m_reason (reason
),
3316 m_prev_enable_commit_resumed (enable_commit_resumed
)
3318 infrun_debug_printf ("reason=%s", m_reason
);
3320 if (!enable_commit_resumed
)
3322 enable_commit_resumed
= true;
3324 /* Re-enable COMMIT_RESUMED_STATE on the targets where it's
3326 maybe_set_commit_resumed_all_targets ();
3328 maybe_call_commit_resumed_all_targets ();
3334 scoped_enable_commit_resumed::~scoped_enable_commit_resumed ()
3336 infrun_debug_printf ("reason=%s", m_reason
);
3338 gdb_assert (enable_commit_resumed
);
3340 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3342 if (!enable_commit_resumed
)
3344 /* Force all COMMIT_RESUMED_STATE back to false. */
3345 for (inferior
*inf
: all_non_exited_inferiors ())
3347 process_stratum_target
*proc_target
= inf
->process_target ();
3348 proc_target
->commit_resumed_state
= false;
3353 /* Check that all the targets we're about to resume are in non-stop
3354 mode. Ideally, we'd only care whether all targets support
3355 target-async, but we're not there yet. E.g., stop_all_threads
3356 doesn't know how to handle all-stop targets. Also, the remote
3357 protocol in all-stop mode is synchronous, irrespective of
3358 target-async, which means that things like a breakpoint re-set
3359 triggered by one target would try to read memory from all targets
3363 check_multi_target_resumption (process_stratum_target
*resume_target
)
3365 if (!non_stop
&& resume_target
== nullptr)
3367 scoped_restore_current_thread restore_thread
;
3369 /* This is used to track whether we're resuming more than one
3371 process_stratum_target
*first_connection
= nullptr;
3373 /* The first inferior we see with a target that does not work in
3374 always-non-stop mode. */
3375 inferior
*first_not_non_stop
= nullptr;
3377 for (inferior
*inf
: all_non_exited_inferiors ())
3379 switch_to_inferior_no_thread (inf
);
3381 if (!target_has_execution ())
3384 process_stratum_target
*proc_target
3385 = current_inferior ()->process_target();
3387 if (!target_is_non_stop_p ())
3388 first_not_non_stop
= inf
;
3390 if (first_connection
== nullptr)
3391 first_connection
= proc_target
;
3392 else if (first_connection
!= proc_target
3393 && first_not_non_stop
!= nullptr)
3395 switch_to_inferior_no_thread (first_not_non_stop
);
3397 proc_target
= current_inferior ()->process_target();
3399 error (_("Connection %d (%s) does not support "
3400 "multi-target resumption."),
3401 proc_target
->connection_number
,
3402 make_target_connection_string (proc_target
).c_str ());
3408 /* Helper function for `proceed`. Check if thread TP is suitable for
3409 resuming, and, if it is, switch to the thread and call
3410 `keep_going_pass_signal`. If TP is not suitable for resuming then this
3411 function will just return without switching threads. */
3414 proceed_resume_thread_checked (thread_info
*tp
)
3416 if (!tp
->inf
->has_execution ())
3418 infrun_debug_printf ("[%s] target has no execution",
3419 tp
->ptid
.to_string ().c_str ());
3425 infrun_debug_printf ("[%s] resumed",
3426 tp
->ptid
.to_string ().c_str ());
3427 gdb_assert (tp
->executing () || tp
->has_pending_waitstatus ());
3431 if (thread_is_in_step_over_chain (tp
))
3433 infrun_debug_printf ("[%s] needs step-over",
3434 tp
->ptid
.to_string ().c_str ());
3438 /* When handling a vfork GDB removes all breakpoints from the program
3439 space in which the vfork is being handled. If we are following the
3440 parent then GDB will set the thread_waiting_for_vfork_done member of
3441 the parent inferior. In this case we should take care to only resume
3442 the vfork parent thread, the kernel will hold this thread suspended
3443 until the vfork child has exited or execd, at which point the parent
3444 will be resumed and a VFORK_DONE event sent to GDB. */
3445 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr)
3447 if (target_is_non_stop_p ())
3449 /* For non-stop targets, regardless of whether GDB is using
3450 all-stop or non-stop mode, threads are controlled
3453 When a thread is handling a vfork, breakpoints are removed
3454 from the inferior (well, program space in fact), so it is
3455 critical that we don't try to resume any thread other than the
3457 if (tp
!= tp
->inf
->thread_waiting_for_vfork_done
)
3459 infrun_debug_printf ("[%s] thread %s of this inferior is "
3460 "waiting for vfork-done",
3461 tp
->ptid
.to_string ().c_str (),
3462 tp
->inf
->thread_waiting_for_vfork_done
3463 ->ptid
.to_string ().c_str ());
3469 /* For all-stop targets, when we attempt to resume the inferior,
3470 we will only resume the vfork parent thread, this is handled
3471 in internal_resume_ptid.
3473 Additionally, we will always be called with the vfork parent
3474 thread as the current thread (TP) thanks to follow_fork, as
3475 such the following assertion should hold.
3477 Beyond this there is nothing more that needs to be done
3479 gdb_assert (tp
== tp
->inf
->thread_waiting_for_vfork_done
);
3483 /* When handling a vfork GDB removes all breakpoints from the program
3484 space in which the vfork is being handled. If we are following the
3485 child then GDB will set vfork_child member of the vfork parent
3486 inferior. Once the child has either exited or execd then GDB will
3487 detach from the parent process. Until that point GDB should not
3488 resume any thread in the parent process. */
3489 if (tp
->inf
->vfork_child
!= nullptr)
3491 infrun_debug_printf ("[%s] thread is part of a vfork parent, child is %d",
3492 tp
->ptid
.to_string ().c_str (),
3493 tp
->inf
->vfork_child
->pid
);
3497 infrun_debug_printf ("resuming %s",
3498 tp
->ptid
.to_string ().c_str ());
3500 execution_control_state
ecs (tp
);
3501 switch_to_thread (tp
);
3502 keep_going_pass_signal (&ecs
);
3503 if (!ecs
.wait_some_more
)
3504 error (_("Command aborted."));
3507 /* Basic routine for continuing the program in various fashions.
3509 ADDR is the address to resume at, or -1 for resume where stopped.
3510 SIGGNAL is the signal to give it, or GDB_SIGNAL_0 for none,
3511 or GDB_SIGNAL_DEFAULT for act according to how it stopped.
3513 You should call clear_proceed_status before calling proceed. */
3516 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
)
3518 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
3520 struct regcache
*regcache
;
3521 struct gdbarch
*gdbarch
;
3524 /* If we're stopped at a fork/vfork, switch to either the parent or child
3525 thread as defined by the "set follow-fork-mode" command, or, if both
3526 the parent and child are controlled by GDB, and schedule-multiple is
3527 on, follow the child. If none of the above apply then we just proceed
3528 resuming the current thread. */
3529 if (!follow_fork ())
3531 /* The target for some reason decided not to resume. */
3533 if (target_can_async_p ())
3534 inferior_event_handler (INF_EXEC_COMPLETE
);
3538 /* We'll update this if & when we switch to a new thread. */
3539 update_previous_thread ();
3541 regcache
= get_current_regcache ();
3542 gdbarch
= regcache
->arch ();
3543 const address_space
*aspace
= regcache
->aspace ();
3545 pc
= regcache_read_pc_protected (regcache
);
3547 thread_info
*cur_thr
= inferior_thread ();
3549 infrun_debug_printf ("cur_thr = %s", cur_thr
->ptid
.to_string ().c_str ());
3551 /* Fill in with reasonable starting values. */
3552 init_thread_stepping_state (cur_thr
);
3554 gdb_assert (!thread_is_in_step_over_chain (cur_thr
));
3557 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
3558 process_stratum_target
*resume_target
3559 = user_visible_resume_target (resume_ptid
);
3561 check_multi_target_resumption (resume_target
);
3563 if (addr
== (CORE_ADDR
) -1)
3565 if (cur_thr
->stop_pc_p ()
3566 && pc
== cur_thr
->stop_pc ()
3567 && breakpoint_here_p (aspace
, pc
) == ordinary_breakpoint_here
3568 && execution_direction
!= EXEC_REVERSE
)
3569 /* There is a breakpoint at the address we will resume at,
3570 step one instruction before inserting breakpoints so that
3571 we do not stop right away (and report a second hit at this
3574 Note, we don't do this in reverse, because we won't
3575 actually be executing the breakpoint insn anyway.
3576 We'll be (un-)executing the previous instruction. */
3577 cur_thr
->stepping_over_breakpoint
= 1;
3578 else if (gdbarch_single_step_through_delay_p (gdbarch
)
3579 && gdbarch_single_step_through_delay (gdbarch
,
3580 get_current_frame ()))
3581 /* We stepped onto an instruction that needs to be stepped
3582 again before re-inserting the breakpoint, do so. */
3583 cur_thr
->stepping_over_breakpoint
= 1;
3587 regcache_write_pc (regcache
, addr
);
3590 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
3591 cur_thr
->set_stop_signal (siggnal
);
3593 /* If an exception is thrown from this point on, make sure to
3594 propagate GDB's knowledge of the executing state to the
3595 frontend/user running state. */
3596 scoped_finish_thread_state
finish_state (resume_target
, resume_ptid
);
3598 /* Even if RESUME_PTID is a wildcard, and we end up resuming fewer
3599 threads (e.g., we might need to set threads stepping over
3600 breakpoints first), from the user/frontend's point of view, all
3601 threads in RESUME_PTID are now running. Unless we're calling an
3602 inferior function, as in that case we pretend the inferior
3603 doesn't run at all. */
3604 if (!cur_thr
->control
.in_infcall
)
3605 set_running (resume_target
, resume_ptid
, true);
3607 infrun_debug_printf ("addr=%s, signal=%s, resume_ptid=%s",
3608 paddress (gdbarch
, addr
),
3609 gdb_signal_to_symbol_string (siggnal
),
3610 resume_ptid
.to_string ().c_str ());
3612 annotate_starting ();
3614 /* Make sure that output from GDB appears before output from the
3616 gdb_flush (gdb_stdout
);
3618 /* Since we've marked the inferior running, give it the terminal. A
3619 QUIT/Ctrl-C from here on is forwarded to the target (which can
3620 still detect attempts to unblock a stuck connection with repeated
3621 Ctrl-C from within target_pass_ctrlc). */
3622 target_terminal::inferior ();
3624 /* In a multi-threaded task we may select another thread and
3625 then continue or step.
3627 But if a thread that we're resuming had stopped at a breakpoint,
3628 it will immediately cause another breakpoint stop without any
3629 execution (i.e. it will report a breakpoint hit incorrectly). So
3630 we must step over it first.
3632 Look for threads other than the current (TP) that reported a
3633 breakpoint hit and haven't been resumed yet since. */
3635 /* If scheduler locking applies, we can avoid iterating over all
3637 if (!non_stop
&& !schedlock_applies (cur_thr
))
3639 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3642 switch_to_thread_no_regs (tp
);
3644 /* Ignore the current thread here. It's handled
3649 if (!thread_still_needs_step_over (tp
))
3652 gdb_assert (!thread_is_in_step_over_chain (tp
));
3654 infrun_debug_printf ("need to step-over [%s] first",
3655 tp
->ptid
.to_string ().c_str ());
3657 global_thread_step_over_chain_enqueue (tp
);
3660 switch_to_thread (cur_thr
);
3663 /* Enqueue the current thread last, so that we move all other
3664 threads over their breakpoints first. */
3665 if (cur_thr
->stepping_over_breakpoint
)
3666 global_thread_step_over_chain_enqueue (cur_thr
);
3668 /* If the thread isn't started, we'll still need to set its prev_pc,
3669 so that switch_back_to_stepped_thread knows the thread hasn't
3670 advanced. Must do this before resuming any thread, as in
3671 all-stop/remote, once we resume we can't send any other packet
3672 until the target stops again. */
3673 cur_thr
->prev_pc
= regcache_read_pc_protected (regcache
);
3676 scoped_disable_commit_resumed
disable_commit_resumed ("proceeding");
3677 bool step_over_started
= start_step_over ();
3679 if (step_over_info_valid_p ())
3681 /* Either this thread started a new in-line step over, or some
3682 other thread was already doing one. In either case, don't
3683 resume anything else until the step-over is finished. */
3685 else if (step_over_started
&& !target_is_non_stop_p ())
3687 /* A new displaced stepping sequence was started. In all-stop,
3688 we can't talk to the target anymore until it next stops. */
3690 else if (!non_stop
&& target_is_non_stop_p ())
3692 INFRUN_SCOPED_DEBUG_START_END
3693 ("resuming threads, all-stop-on-top-of-non-stop");
3695 /* In all-stop, but the target is always in non-stop mode.
3696 Start all other threads that are implicitly resumed too. */
3697 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3700 switch_to_thread_no_regs (tp
);
3701 proceed_resume_thread_checked (tp
);
3705 proceed_resume_thread_checked (cur_thr
);
3707 disable_commit_resumed
.reset_and_commit ();
3710 finish_state
.release ();
3712 /* If we've switched threads above, switch back to the previously
3713 current thread. We don't want the user to see a different
3715 switch_to_thread (cur_thr
);
3717 /* Tell the event loop to wait for it to stop. If the target
3718 supports asynchronous execution, it'll do this from within
3720 if (!target_can_async_p ())
3721 mark_async_event_handler (infrun_async_inferior_event_token
);
3725 /* Start remote-debugging of a machine over a serial link. */
3728 start_remote (int from_tty
)
3730 inferior
*inf
= current_inferior ();
3731 inf
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
3733 /* Always go on waiting for the target, regardless of the mode. */
3734 /* FIXME: cagney/1999-09-23: At present it isn't possible to
3735 indicate to wait_for_inferior that a target should timeout if
3736 nothing is returned (instead of just blocking). Because of this,
3737 targets expecting an immediate response need to, internally, set
3738 things up so that the target_wait() is forced to eventually
3740 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
3741 differentiate to its caller what the state of the target is after
3742 the initial open has been performed. Here we're assuming that
3743 the target has stopped. It should be possible to eventually have
3744 target_open() return to the caller an indication that the target
3745 is currently running and GDB state should be set to the same as
3746 for an async run. */
3747 wait_for_inferior (inf
);
3749 /* Now that the inferior has stopped, do any bookkeeping like
3750 loading shared libraries. We want to do this before normal_stop,
3751 so that the displayed frame is up to date. */
3752 post_create_inferior (from_tty
);
3757 /* Initialize static vars when a new inferior begins. */
3760 init_wait_for_inferior (void)
3762 /* These are meaningless until the first time through wait_for_inferior. */
3764 breakpoint_init_inferior (inf_starting
);
3766 clear_proceed_status (0);
3768 nullify_last_target_wait_ptid ();
3770 update_previous_thread ();
3775 static void handle_inferior_event (struct execution_control_state
*ecs
);
3777 static void handle_step_into_function (struct gdbarch
*gdbarch
,
3778 struct execution_control_state
*ecs
);
3779 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
3780 struct execution_control_state
*ecs
);
3781 static void handle_signal_stop (struct execution_control_state
*ecs
);
3782 static void check_exception_resume (struct execution_control_state
*,
3785 static void end_stepping_range (struct execution_control_state
*ecs
);
3786 static void stop_waiting (struct execution_control_state
*ecs
);
3787 static void keep_going (struct execution_control_state
*ecs
);
3788 static void process_event_stop_test (struct execution_control_state
*ecs
);
3789 static bool switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
3791 /* This function is attached as a "thread_stop_requested" observer.
3792 Cleanup local state that assumed the PTID was to be resumed, and
3793 report the stop to the frontend. */
3796 infrun_thread_stop_requested (ptid_t ptid
)
3798 process_stratum_target
*curr_target
= current_inferior ()->process_target ();
3800 /* PTID was requested to stop. If the thread was already stopped,
3801 but the user/frontend doesn't know about that yet (e.g., the
3802 thread had been temporarily paused for some step-over), set up
3803 for reporting the stop now. */
3804 for (thread_info
*tp
: all_threads (curr_target
, ptid
))
3806 if (tp
->state
!= THREAD_RUNNING
)
3808 if (tp
->executing ())
3811 /* Remove matching threads from the step-over queue, so
3812 start_step_over doesn't try to resume them
3814 if (thread_is_in_step_over_chain (tp
))
3815 global_thread_step_over_chain_remove (tp
);
3817 /* If the thread is stopped, but the user/frontend doesn't
3818 know about that yet, queue a pending event, as if the
3819 thread had just stopped now. Unless the thread already had
3821 if (!tp
->has_pending_waitstatus ())
3823 target_waitstatus ws
;
3824 ws
.set_stopped (GDB_SIGNAL_0
);
3825 tp
->set_pending_waitstatus (ws
);
3828 /* Clear the inline-frame state, since we're re-processing the
3830 clear_inline_frame_state (tp
);
3832 /* If this thread was paused because some other thread was
3833 doing an inline-step over, let that finish first. Once
3834 that happens, we'll restart all threads and consume pending
3835 stop events then. */
3836 if (step_over_info_valid_p ())
3839 /* Otherwise we can process the (new) pending event now. Set
3840 it so this pending event is considered by
3842 tp
->set_resumed (true);
3846 /* Delete the step resume, single-step and longjmp/exception resume
3847 breakpoints of TP. */
3850 delete_thread_infrun_breakpoints (struct thread_info
*tp
)
3852 delete_step_resume_breakpoint (tp
);
3853 delete_exception_resume_breakpoint (tp
);
3854 delete_single_step_breakpoints (tp
);
3857 /* If the target still has execution, call FUNC for each thread that
3858 just stopped. In all-stop, that's all the non-exited threads; in
3859 non-stop, that's the current thread, only. */
3861 typedef void (*for_each_just_stopped_thread_callback_func
)
3862 (struct thread_info
*tp
);
3865 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func
)
3867 if (!target_has_execution () || inferior_ptid
== null_ptid
)
3870 if (target_is_non_stop_p ())
3872 /* If in non-stop mode, only the current thread stopped. */
3873 func (inferior_thread ());
3877 /* In all-stop mode, all threads have stopped. */
3878 for (thread_info
*tp
: all_non_exited_threads ())
3883 /* Delete the step resume and longjmp/exception resume breakpoints of
3884 the threads that just stopped. */
3887 delete_just_stopped_threads_infrun_breakpoints (void)
3889 for_each_just_stopped_thread (delete_thread_infrun_breakpoints
);
3892 /* Delete the single-step breakpoints of the threads that just
3896 delete_just_stopped_threads_single_step_breakpoints (void)
3898 for_each_just_stopped_thread (delete_single_step_breakpoints
);
3904 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
3905 const struct target_waitstatus
&ws
)
3907 infrun_debug_printf ("target_wait (%s [%s], status) =",
3908 waiton_ptid
.to_string ().c_str (),
3909 target_pid_to_str (waiton_ptid
).c_str ());
3910 infrun_debug_printf (" %s [%s],",
3911 result_ptid
.to_string ().c_str (),
3912 target_pid_to_str (result_ptid
).c_str ());
3913 infrun_debug_printf (" %s", ws
.to_string ().c_str ());
3916 /* Select a thread at random, out of those which are resumed and have
3919 static struct thread_info
*
3920 random_pending_event_thread (inferior
*inf
, ptid_t waiton_ptid
)
3922 process_stratum_target
*proc_target
= inf
->process_target ();
3924 = proc_target
->random_resumed_with_pending_wait_status (inf
, waiton_ptid
);
3926 if (thread
== nullptr)
3928 infrun_debug_printf ("None found.");
3932 infrun_debug_printf ("Found %s.", thread
->ptid
.to_string ().c_str ());
3933 gdb_assert (thread
->resumed ());
3934 gdb_assert (thread
->has_pending_waitstatus ());
3939 /* Wrapper for target_wait that first checks whether threads have
3940 pending statuses to report before actually asking the target for
3941 more events. INF is the inferior we're using to call target_wait
3945 do_target_wait_1 (inferior
*inf
, ptid_t ptid
,
3946 target_waitstatus
*status
, target_wait_flags options
)
3948 struct thread_info
*tp
;
3950 /* We know that we are looking for an event in the target of inferior
3951 INF, but we don't know which thread the event might come from. As
3952 such we want to make sure that INFERIOR_PTID is reset so that none of
3953 the wait code relies on it - doing so is always a mistake. */
3954 switch_to_inferior_no_thread (inf
);
3956 /* First check if there is a resumed thread with a wait status
3958 if (ptid
== minus_one_ptid
|| ptid
.is_pid ())
3960 tp
= random_pending_event_thread (inf
, ptid
);
3964 infrun_debug_printf ("Waiting for specific thread %s.",
3965 ptid
.to_string ().c_str ());
3967 /* We have a specific thread to check. */
3968 tp
= inf
->find_thread (ptid
);
3969 gdb_assert (tp
!= nullptr);
3970 if (!tp
->has_pending_waitstatus ())
3975 && (tp
->stop_reason () == TARGET_STOPPED_BY_SW_BREAKPOINT
3976 || tp
->stop_reason () == TARGET_STOPPED_BY_HW_BREAKPOINT
))
3978 struct regcache
*regcache
= get_thread_regcache (tp
);
3979 struct gdbarch
*gdbarch
= regcache
->arch ();
3983 pc
= regcache_read_pc (regcache
);
3985 if (pc
!= tp
->stop_pc ())
3987 infrun_debug_printf ("PC of %s changed. was=%s, now=%s",
3988 tp
->ptid
.to_string ().c_str (),
3989 paddress (gdbarch
, tp
->stop_pc ()),
3990 paddress (gdbarch
, pc
));
3993 else if (!breakpoint_inserted_here_p (regcache
->aspace (), pc
))
3995 infrun_debug_printf ("previous breakpoint of %s, at %s gone",
3996 tp
->ptid
.to_string ().c_str (),
3997 paddress (gdbarch
, pc
));
4004 infrun_debug_printf ("pending event of %s cancelled.",
4005 tp
->ptid
.to_string ().c_str ());
4007 tp
->clear_pending_waitstatus ();
4008 target_waitstatus ws
;
4010 tp
->set_pending_waitstatus (ws
);
4011 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
4017 infrun_debug_printf ("Using pending wait status %s for %s.",
4018 tp
->pending_waitstatus ().to_string ().c_str (),
4019 tp
->ptid
.to_string ().c_str ());
4021 /* Now that we've selected our final event LWP, un-adjust its PC
4022 if it was a software breakpoint (and the target doesn't
4023 always adjust the PC itself). */
4024 if (tp
->stop_reason () == TARGET_STOPPED_BY_SW_BREAKPOINT
4025 && !target_supports_stopped_by_sw_breakpoint ())
4027 struct regcache
*regcache
;
4028 struct gdbarch
*gdbarch
;
4031 regcache
= get_thread_regcache (tp
);
4032 gdbarch
= regcache
->arch ();
4034 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4039 pc
= regcache_read_pc (regcache
);
4040 regcache_write_pc (regcache
, pc
+ decr_pc
);
4044 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
4045 *status
= tp
->pending_waitstatus ();
4046 tp
->clear_pending_waitstatus ();
4048 /* Wake up the event loop again, until all pending events are
4050 if (target_is_async_p ())
4051 mark_async_event_handler (infrun_async_inferior_event_token
);
4055 /* But if we don't find one, we'll have to wait. */
4057 /* We can't ask a non-async target to do a non-blocking wait, so this will be
4059 if (!target_can_async_p ())
4060 options
&= ~TARGET_WNOHANG
;
4062 return target_wait (ptid
, status
, options
);
4065 /* Wrapper for target_wait that first checks whether threads have
4066 pending statuses to report before actually asking the target for
4067 more events. Polls for events from all inferiors/targets. */
4070 do_target_wait (execution_control_state
*ecs
, target_wait_flags options
)
4072 int num_inferiors
= 0;
4073 int random_selector
;
4075 /* For fairness, we pick the first inferior/target to poll at random
4076 out of all inferiors that may report events, and then continue
4077 polling the rest of the inferior list starting from that one in a
4078 circular fashion until the whole list is polled once. */
4080 auto inferior_matches
= [] (inferior
*inf
)
4082 return inf
->process_target () != nullptr;
4085 /* First see how many matching inferiors we have. */
4086 for (inferior
*inf
: all_inferiors ())
4087 if (inferior_matches (inf
))
4090 if (num_inferiors
== 0)
4092 ecs
->ws
.set_ignore ();
4096 /* Now randomly pick an inferior out of those that matched. */
4097 random_selector
= (int)
4098 ((num_inferiors
* (double) rand ()) / (RAND_MAX
+ 1.0));
4100 if (num_inferiors
> 1)
4101 infrun_debug_printf ("Found %d inferiors, starting at #%d",
4102 num_inferiors
, random_selector
);
4104 /* Select the Nth inferior that matched. */
4106 inferior
*selected
= nullptr;
4108 for (inferior
*inf
: all_inferiors ())
4109 if (inferior_matches (inf
))
4110 if (random_selector
-- == 0)
4116 /* Now poll for events out of each of the matching inferior's
4117 targets, starting from the selected one. */
4119 auto do_wait
= [&] (inferior
*inf
)
4121 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, options
);
4122 ecs
->target
= inf
->process_target ();
4123 return (ecs
->ws
.kind () != TARGET_WAITKIND_IGNORE
);
4126 /* Needed in 'all-stop + target-non-stop' mode, because we end up
4127 here spuriously after the target is all stopped and we've already
4128 reported the stop to the user, polling for events. */
4129 scoped_restore_current_thread restore_thread
;
4131 intrusive_list_iterator
<inferior
> start
4132 = inferior_list
.iterator_to (*selected
);
4134 for (intrusive_list_iterator
<inferior
> it
= start
;
4135 it
!= inferior_list
.end ();
4138 inferior
*inf
= &*it
;
4140 if (inferior_matches (inf
) && do_wait (inf
))
4144 for (intrusive_list_iterator
<inferior
> it
= inferior_list
.begin ();
4148 inferior
*inf
= &*it
;
4150 if (inferior_matches (inf
) && do_wait (inf
))
4154 ecs
->ws
.set_ignore ();
4158 /* An event reported by wait_one. */
4160 struct wait_one_event
4162 /* The target the event came out of. */
4163 process_stratum_target
*target
;
4165 /* The PTID the event was for. */
4168 /* The waitstatus. */
4169 target_waitstatus ws
;
4172 static bool handle_one (const wait_one_event
&event
);
4173 static int finish_step_over (struct execution_control_state
*ecs
);
4175 /* Prepare and stabilize the inferior for detaching it. E.g.,
4176 detaching while a thread is displaced stepping is a recipe for
4177 crashing it, as nothing would readjust the PC out of the scratch
4181 prepare_for_detach (void)
4183 struct inferior
*inf
= current_inferior ();
4184 ptid_t pid_ptid
= ptid_t (inf
->pid
);
4185 scoped_restore_current_thread restore_thread
;
4187 scoped_restore restore_detaching
= make_scoped_restore (&inf
->detaching
, true);
4189 /* Remove all threads of INF from the global step-over chain. We
4190 want to stop any ongoing step-over, not start any new one. */
4191 thread_step_over_list_safe_range range
4192 = make_thread_step_over_list_safe_range (global_thread_step_over_list
);
4194 for (thread_info
*tp
: range
)
4197 infrun_debug_printf ("removing thread %s from global step over chain",
4198 tp
->ptid
.to_string ().c_str ());
4199 global_thread_step_over_chain_remove (tp
);
4202 /* If we were already in the middle of an inline step-over, and the
4203 thread stepping belongs to the inferior we're detaching, we need
4204 to restart the threads of other inferiors. */
4205 if (step_over_info
.thread
!= -1)
4207 infrun_debug_printf ("inline step-over in-process while detaching");
4209 thread_info
*thr
= find_thread_global_id (step_over_info
.thread
);
4210 if (thr
->inf
== inf
)
4212 /* Since we removed threads of INF from the step-over chain,
4213 we know this won't start a step-over for INF. */
4214 clear_step_over_info ();
4216 if (target_is_non_stop_p ())
4218 /* Start a new step-over in another thread if there's
4219 one that needs it. */
4222 /* Restart all other threads (except the
4223 previously-stepping thread, since that one is still
4225 if (!step_over_info_valid_p ())
4226 restart_threads (thr
);
4231 if (displaced_step_in_progress (inf
))
4233 infrun_debug_printf ("displaced-stepping in-process while detaching");
4235 /* Stop threads currently displaced stepping, aborting it. */
4237 for (thread_info
*thr
: inf
->non_exited_threads ())
4239 if (thr
->displaced_step_state
.in_progress ())
4241 if (thr
->executing ())
4243 if (!thr
->stop_requested
)
4245 target_stop (thr
->ptid
);
4246 thr
->stop_requested
= true;
4250 thr
->set_resumed (false);
4254 while (displaced_step_in_progress (inf
))
4256 wait_one_event event
;
4258 event
.target
= inf
->process_target ();
4259 event
.ptid
= do_target_wait_1 (inf
, pid_ptid
, &event
.ws
, 0);
4262 print_target_wait_results (pid_ptid
, event
.ptid
, event
.ws
);
4267 /* It's OK to leave some of the threads of INF stopped, since
4268 they'll be detached shortly. */
4272 /* If all-stop, but there exists a non-stop target, stop all threads
4273 now that we're presenting the stop to the user. */
4276 stop_all_threads_if_all_stop_mode ()
4278 if (!non_stop
&& exists_non_stop_target ())
4279 stop_all_threads ("presenting stop to user in all-stop");
4282 /* Wait for control to return from inferior to debugger.
4284 If inferior gets a signal, we may decide to start it up again
4285 instead of returning. That is why there is a loop in this function.
4286 When this function actually returns it means the inferior
4287 should be left stopped and GDB should read more commands. */
4290 wait_for_inferior (inferior
*inf
)
4292 infrun_debug_printf ("wait_for_inferior ()");
4294 SCOPE_EXIT
{ delete_just_stopped_threads_infrun_breakpoints (); };
4296 /* If an error happens while handling the event, propagate GDB's
4297 knowledge of the executing state to the frontend/user running
4299 scoped_finish_thread_state finish_state
4300 (inf
->process_target (), minus_one_ptid
);
4304 execution_control_state ecs
;
4306 overlay_cache_invalid
= 1;
4308 /* Flush target cache before starting to handle each event.
4309 Target was running and cache could be stale. This is just a
4310 heuristic. Running threads may modify target memory, but we
4311 don't get any event. */
4312 target_dcache_invalidate ();
4314 ecs
.ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
.ws
, 0);
4315 ecs
.target
= inf
->process_target ();
4318 print_target_wait_results (minus_one_ptid
, ecs
.ptid
, ecs
.ws
);
4320 /* Now figure out what to do with the result of the result. */
4321 handle_inferior_event (&ecs
);
4323 if (!ecs
.wait_some_more
)
4327 stop_all_threads_if_all_stop_mode ();
4329 /* No error, don't finish the state yet. */
4330 finish_state
.release ();
4333 /* Cleanup that reinstalls the readline callback handler, if the
4334 target is running in the background. If while handling the target
4335 event something triggered a secondary prompt, like e.g., a
4336 pagination prompt, we'll have removed the callback handler (see
4337 gdb_readline_wrapper_line). Need to do this as we go back to the
4338 event loop, ready to process further input. Note this has no
4339 effect if the handler hasn't actually been removed, because calling
4340 rl_callback_handler_install resets the line buffer, thus losing
4344 reinstall_readline_callback_handler_cleanup ()
4346 struct ui
*ui
= current_ui
;
4350 /* We're not going back to the top level event loop yet. Don't
4351 install the readline callback, as it'd prep the terminal,
4352 readline-style (raw, noecho) (e.g., --batch). We'll install
4353 it the next time the prompt is displayed, when we're ready
4358 if (ui
->command_editing
&& ui
->prompt_state
!= PROMPT_BLOCKED
)
4359 gdb_rl_callback_handler_reinstall ();
4362 /* Clean up the FSMs of threads that are now stopped. In non-stop,
4363 that's just the event thread. In all-stop, that's all threads. In
4364 all-stop, threads that had a pending exit no longer have a reason
4365 to be around, as their FSMs/commands are canceled, so we delete
4366 them. This avoids "info threads" listing such threads as if they
4367 were alive (and failing to read their registers), the user being
4368 able to select and resume them (and that failing), etc. */
4371 clean_up_just_stopped_threads_fsms (struct execution_control_state
*ecs
)
4373 /* The first clean_up call below assumes the event thread is the current
4375 if (ecs
->event_thread
!= nullptr)
4376 gdb_assert (ecs
->event_thread
== inferior_thread ());
4378 if (ecs
->event_thread
!= nullptr
4379 && ecs
->event_thread
->thread_fsm () != nullptr)
4380 ecs
->event_thread
->thread_fsm ()->clean_up (ecs
->event_thread
);
4384 scoped_restore_current_thread restore_thread
;
4386 for (thread_info
*thr
: all_threads_safe ())
4388 if (thr
->state
== THREAD_EXITED
)
4391 if (thr
== ecs
->event_thread
)
4394 if (thr
->thread_fsm () != nullptr)
4396 switch_to_thread (thr
);
4397 thr
->thread_fsm ()->clean_up (thr
);
4400 /* As we are cancelling the command/FSM of this thread,
4401 whatever was the reason we needed to report a thread
4402 exited event to the user, that reason is gone. Delete
4403 the thread, so that the user doesn't see it in the thread
4404 list, the next proceed doesn't try to resume it, etc. */
4405 if (thr
->has_pending_waitstatus ()
4406 && (thr
->pending_waitstatus ().kind ()
4407 == TARGET_WAITKIND_THREAD_EXITED
))
4408 delete_thread (thr
);
4413 /* Helper for all_uis_check_sync_execution_done that works on the
4417 check_curr_ui_sync_execution_done (void)
4419 struct ui
*ui
= current_ui
;
4421 if (ui
->prompt_state
== PROMPT_NEEDED
4423 && !gdb_in_secondary_prompt_p (ui
))
4425 target_terminal::ours ();
4426 top_level_interpreter ()->on_sync_execution_done ();
4427 ui
->register_file_handler ();
4434 all_uis_check_sync_execution_done (void)
4436 SWITCH_THRU_ALL_UIS ()
4438 check_curr_ui_sync_execution_done ();
4445 all_uis_on_sync_execution_starting (void)
4447 SWITCH_THRU_ALL_UIS ()
4449 if (current_ui
->prompt_state
== PROMPT_NEEDED
)
4450 async_disable_stdin ();
4454 /* A quit_handler callback installed while we're handling inferior
4458 infrun_quit_handler ()
4460 if (target_terminal::is_ours ())
4464 default_quit_handler would throw a quit in this case, but if
4465 we're handling an event while we have the terminal, it means
4466 the target is running a background execution command, and
4467 thus when users press Ctrl-C, they're wanting to interrupt
4468 whatever command they were executing in the command line.
4472 (gdb) foo bar whatever<ctrl-c>
4474 That Ctrl-C should clear the input line, not interrupt event
4475 handling if it happens that the user types Ctrl-C at just the
4478 It's as-if background event handling was handled by a
4479 separate background thread.
4481 To be clear, the Ctrl-C is not lost -- it will be processed
4482 by the next QUIT call once we're out of fetch_inferior_event
4487 if (check_quit_flag ())
4488 target_pass_ctrlc ();
4492 /* Asynchronous version of wait_for_inferior. It is called by the
4493 event loop whenever a change of state is detected on the file
4494 descriptor corresponding to the target. It can be called more than
4495 once to complete a single execution command. In such cases we need
4496 to keep the state in a global variable ECSS. If it is the last time
4497 that this function is called for a single execution command, then
4498 report to the user that the inferior has stopped, and do the
4499 necessary cleanups. */
4502 fetch_inferior_event ()
4504 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
4506 execution_control_state ecs
;
4509 /* Events are always processed with the main UI as current UI. This
4510 way, warnings, debug output, etc. are always consistently sent to
4511 the main console. */
4512 scoped_restore save_ui
= make_scoped_restore (¤t_ui
, main_ui
);
4514 /* Temporarily disable pagination. Otherwise, the user would be
4515 given an option to press 'q' to quit, which would cause an early
4516 exit and could leave GDB in a half-baked state. */
4517 scoped_restore save_pagination
4518 = make_scoped_restore (&pagination_enabled
, false);
4520 /* Install a quit handler that does nothing if we have the terminal
4521 (meaning the target is running a background execution command),
4522 so that Ctrl-C never interrupts GDB before the event is fully
4524 scoped_restore restore_quit_handler
4525 = make_scoped_restore (&quit_handler
, infrun_quit_handler
);
4527 /* Make sure a SIGINT does not interrupt an extension language while
4528 we're handling an event. That could interrupt a Python unwinder
4529 or a Python observer or some such. A Ctrl-C should either be
4530 forwarded to the inferior if the inferior has the terminal, or,
4531 if GDB has the terminal, should interrupt the command the user is
4532 typing in the CLI. */
4533 scoped_disable_cooperative_sigint_handling restore_coop_sigint
;
4535 /* End up with readline processing input, if necessary. */
4537 SCOPE_EXIT
{ reinstall_readline_callback_handler_cleanup (); };
4539 /* We're handling a live event, so make sure we're doing live
4540 debugging. If we're looking at traceframes while the target is
4541 running, we're going to need to get back to that mode after
4542 handling the event. */
4543 gdb::optional
<scoped_restore_current_traceframe
> maybe_restore_traceframe
;
4546 maybe_restore_traceframe
.emplace ();
4547 set_current_traceframe (-1);
4550 /* The user/frontend should not notice a thread switch due to
4551 internal events. Make sure we revert to the user selected
4552 thread and frame after handling the event and running any
4553 breakpoint commands. */
4554 scoped_restore_current_thread restore_thread
;
4556 overlay_cache_invalid
= 1;
4557 /* Flush target cache before starting to handle each event. Target
4558 was running and cache could be stale. This is just a heuristic.
4559 Running threads may modify target memory, but we don't get any
4561 target_dcache_invalidate ();
4563 scoped_restore save_exec_dir
4564 = make_scoped_restore (&execution_direction
,
4565 target_execution_direction ());
4567 /* Allow targets to pause their resumed threads while we handle
4569 scoped_disable_commit_resumed
disable_commit_resumed ("handling event");
4571 if (!do_target_wait (&ecs
, TARGET_WNOHANG
))
4573 infrun_debug_printf ("do_target_wait returned no event");
4574 disable_commit_resumed
.reset_and_commit ();
4578 gdb_assert (ecs
.ws
.kind () != TARGET_WAITKIND_IGNORE
);
4580 /* Switch to the inferior that generated the event, so we can do
4581 target calls. If the event was not associated to a ptid, */
4582 if (ecs
.ptid
!= null_ptid
4583 && ecs
.ptid
!= minus_one_ptid
)
4584 switch_to_inferior_no_thread (find_inferior_ptid (ecs
.target
, ecs
.ptid
));
4586 switch_to_target_no_thread (ecs
.target
);
4589 print_target_wait_results (minus_one_ptid
, ecs
.ptid
, ecs
.ws
);
4591 /* If an error happens while handling the event, propagate GDB's
4592 knowledge of the executing state to the frontend/user running
4594 ptid_t finish_ptid
= !target_is_non_stop_p () ? minus_one_ptid
: ecs
.ptid
;
4595 scoped_finish_thread_state
finish_state (ecs
.target
, finish_ptid
);
4597 /* Get executed before scoped_restore_current_thread above to apply
4598 still for the thread which has thrown the exception. */
4599 auto defer_bpstat_clear
4600 = make_scope_exit (bpstat_clear_actions
);
4601 auto defer_delete_threads
4602 = make_scope_exit (delete_just_stopped_threads_infrun_breakpoints
);
4604 int stop_id
= get_stop_id ();
4606 /* Now figure out what to do with the result of the result. */
4607 handle_inferior_event (&ecs
);
4609 if (!ecs
.wait_some_more
)
4611 struct inferior
*inf
= find_inferior_ptid (ecs
.target
, ecs
.ptid
);
4612 bool should_stop
= true;
4613 struct thread_info
*thr
= ecs
.event_thread
;
4615 delete_just_stopped_threads_infrun_breakpoints ();
4617 if (thr
!= nullptr && thr
->thread_fsm () != nullptr)
4618 should_stop
= thr
->thread_fsm ()->should_stop (thr
);
4626 bool should_notify_stop
= true;
4627 bool proceeded
= false;
4629 stop_all_threads_if_all_stop_mode ();
4631 clean_up_just_stopped_threads_fsms (&ecs
);
4633 if (stop_id
!= get_stop_id ())
4635 /* If the stop-id has changed then a stop has already been
4636 presented to the user in handle_inferior_event, this is
4637 likely a failed inferior call. As the stop has already
4638 been announced then we should not notify again.
4640 Also, if the prompt state is not PROMPT_NEEDED then GDB
4641 will not be ready for user input after this function. */
4642 should_notify_stop
= false;
4643 gdb_assert (current_ui
->prompt_state
== PROMPT_NEEDED
);
4645 else if (thr
!= nullptr && thr
->thread_fsm () != nullptr)
4647 = thr
->thread_fsm ()->should_notify_stop ();
4649 if (should_notify_stop
)
4651 /* We may not find an inferior if this was a process exit. */
4652 if (inf
== nullptr || inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
4653 proceeded
= normal_stop ();
4658 inferior_event_handler (INF_EXEC_COMPLETE
);
4662 /* If we got a TARGET_WAITKIND_NO_RESUMED event, then the
4663 previously selected thread is gone. We have two
4664 choices - switch to no thread selected, or restore the
4665 previously selected thread (now exited). We chose the
4666 later, just because that's what GDB used to do. After
4667 this, "info threads" says "The current thread <Thread
4668 ID 2> has terminated." instead of "No thread
4672 && ecs
.ws
.kind () != TARGET_WAITKIND_NO_RESUMED
)
4673 restore_thread
.dont_restore ();
4677 defer_delete_threads
.release ();
4678 defer_bpstat_clear
.release ();
4680 /* No error, don't finish the thread states yet. */
4681 finish_state
.release ();
4683 disable_commit_resumed
.reset_and_commit ();
4685 /* This scope is used to ensure that readline callbacks are
4686 reinstalled here. */
4689 /* Handling this event might have caused some inferiors to become prunable.
4690 For example, the exit of an inferior that was automatically added. Try
4691 to get rid of them. Keeping those around slows down things linearly.
4693 Note that this never removes the current inferior. Therefore, call this
4694 after RESTORE_THREAD went out of scope, in case the event inferior (which was
4695 temporarily made the current inferior) is meant to be deleted.
4697 Call this before all_uis_check_sync_execution_done, so that notifications about
4698 removed inferiors appear before the prompt. */
4701 /* If a UI was in sync execution mode, and now isn't, restore its
4702 prompt (a synchronous execution command has finished, and we're
4703 ready for input). */
4704 all_uis_check_sync_execution_done ();
4707 && exec_done_display_p
4708 && (inferior_ptid
== null_ptid
4709 || inferior_thread ()->state
!= THREAD_RUNNING
))
4710 gdb_printf (_("completed.\n"));
4716 set_step_info (thread_info
*tp
, frame_info_ptr frame
,
4717 struct symtab_and_line sal
)
4719 /* This can be removed once this function no longer implicitly relies on the
4720 inferior_ptid value. */
4721 gdb_assert (inferior_ptid
== tp
->ptid
);
4723 tp
->control
.step_frame_id
= get_frame_id (frame
);
4724 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
4726 tp
->current_symtab
= sal
.symtab
;
4727 tp
->current_line
= sal
.line
;
4730 ("symtab = %s, line = %d, step_frame_id = %s, step_stack_frame_id = %s",
4731 tp
->current_symtab
!= nullptr ? tp
->current_symtab
->filename
: "<null>",
4733 tp
->control
.step_frame_id
.to_string ().c_str (),
4734 tp
->control
.step_stack_frame_id
.to_string ().c_str ());
4737 /* Clear context switchable stepping state. */
4740 init_thread_stepping_state (struct thread_info
*tss
)
4742 tss
->stepped_breakpoint
= 0;
4743 tss
->stepping_over_breakpoint
= 0;
4744 tss
->stepping_over_watchpoint
= 0;
4745 tss
->step_after_step_resume_breakpoint
= 0;
4751 set_last_target_status (process_stratum_target
*target
, ptid_t ptid
,
4752 const target_waitstatus
&status
)
4754 target_last_proc_target
= target
;
4755 target_last_wait_ptid
= ptid
;
4756 target_last_waitstatus
= status
;
4762 get_last_target_status (process_stratum_target
**target
, ptid_t
*ptid
,
4763 target_waitstatus
*status
)
4765 if (target
!= nullptr)
4766 *target
= target_last_proc_target
;
4767 if (ptid
!= nullptr)
4768 *ptid
= target_last_wait_ptid
;
4769 if (status
!= nullptr)
4770 *status
= target_last_waitstatus
;
4776 nullify_last_target_wait_ptid (void)
4778 target_last_proc_target
= nullptr;
4779 target_last_wait_ptid
= minus_one_ptid
;
4780 target_last_waitstatus
= {};
4783 /* Switch thread contexts. */
4786 context_switch (execution_control_state
*ecs
)
4788 if (ecs
->ptid
!= inferior_ptid
4789 && (inferior_ptid
== null_ptid
4790 || ecs
->event_thread
!= inferior_thread ()))
4792 infrun_debug_printf ("Switching context from %s to %s",
4793 inferior_ptid
.to_string ().c_str (),
4794 ecs
->ptid
.to_string ().c_str ());
4797 switch_to_thread (ecs
->event_thread
);
4800 /* If the target can't tell whether we've hit breakpoints
4801 (target_supports_stopped_by_sw_breakpoint), and we got a SIGTRAP,
4802 check whether that could have been caused by a breakpoint. If so,
4803 adjust the PC, per gdbarch_decr_pc_after_break. */
4806 adjust_pc_after_break (struct thread_info
*thread
,
4807 const target_waitstatus
&ws
)
4809 struct regcache
*regcache
;
4810 struct gdbarch
*gdbarch
;
4811 CORE_ADDR breakpoint_pc
, decr_pc
;
4813 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
4814 we aren't, just return.
4816 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
4817 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
4818 implemented by software breakpoints should be handled through the normal
4821 NOTE drow/2004-01-31: On some targets, breakpoints may generate
4822 different signals (SIGILL or SIGEMT for instance), but it is less
4823 clear where the PC is pointing afterwards. It may not match
4824 gdbarch_decr_pc_after_break. I don't know any specific target that
4825 generates these signals at breakpoints (the code has been in GDB since at
4826 least 1992) so I can not guess how to handle them here.
4828 In earlier versions of GDB, a target with
4829 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
4830 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
4831 target with both of these set in GDB history, and it seems unlikely to be
4832 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
4834 if (ws
.kind () != TARGET_WAITKIND_STOPPED
)
4837 if (ws
.sig () != GDB_SIGNAL_TRAP
)
4840 /* In reverse execution, when a breakpoint is hit, the instruction
4841 under it has already been de-executed. The reported PC always
4842 points at the breakpoint address, so adjusting it further would
4843 be wrong. E.g., consider this case on a decr_pc_after_break == 1
4846 B1 0x08000000 : INSN1
4847 B2 0x08000001 : INSN2
4849 PC -> 0x08000003 : INSN4
4851 Say you're stopped at 0x08000003 as above. Reverse continuing
4852 from that point should hit B2 as below. Reading the PC when the
4853 SIGTRAP is reported should read 0x08000001 and INSN2 should have
4854 been de-executed already.
4856 B1 0x08000000 : INSN1
4857 B2 PC -> 0x08000001 : INSN2
4861 We can't apply the same logic as for forward execution, because
4862 we would wrongly adjust the PC to 0x08000000, since there's a
4863 breakpoint at PC - 1. We'd then report a hit on B1, although
4864 INSN1 hadn't been de-executed yet. Doing nothing is the correct
4866 if (execution_direction
== EXEC_REVERSE
)
4869 /* If the target can tell whether the thread hit a SW breakpoint,
4870 trust it. Targets that can tell also adjust the PC
4872 if (target_supports_stopped_by_sw_breakpoint ())
4875 /* Note that relying on whether a breakpoint is planted in memory to
4876 determine this can fail. E.g,. the breakpoint could have been
4877 removed since. Or the thread could have been told to step an
4878 instruction the size of a breakpoint instruction, and only
4879 _after_ was a breakpoint inserted at its address. */
4881 /* If this target does not decrement the PC after breakpoints, then
4882 we have nothing to do. */
4883 regcache
= get_thread_regcache (thread
);
4884 gdbarch
= regcache
->arch ();
4886 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4890 const address_space
*aspace
= regcache
->aspace ();
4892 /* Find the location where (if we've hit a breakpoint) the
4893 breakpoint would be. */
4894 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
4896 /* If the target can't tell whether a software breakpoint triggered,
4897 fallback to figuring it out based on breakpoints we think were
4898 inserted in the target, and on whether the thread was stepped or
4901 /* Check whether there actually is a software breakpoint inserted at
4904 If in non-stop mode, a race condition is possible where we've
4905 removed a breakpoint, but stop events for that breakpoint were
4906 already queued and arrive later. To suppress those spurious
4907 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
4908 and retire them after a number of stop events are reported. Note
4909 this is an heuristic and can thus get confused. The real fix is
4910 to get the "stopped by SW BP and needs adjustment" info out of
4911 the target/kernel (and thus never reach here; see above). */
4912 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
4913 || (target_is_non_stop_p ()
4914 && moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
4916 gdb::optional
<scoped_restore_tmpl
<int>> restore_operation_disable
;
4918 if (record_full_is_used ())
4919 restore_operation_disable
.emplace
4920 (record_full_gdb_operation_disable_set ());
4922 /* When using hardware single-step, a SIGTRAP is reported for both
4923 a completed single-step and a software breakpoint. Need to
4924 differentiate between the two, as the latter needs adjusting
4925 but the former does not.
4927 The SIGTRAP can be due to a completed hardware single-step only if
4928 - we didn't insert software single-step breakpoints
4929 - this thread is currently being stepped
4931 If any of these events did not occur, we must have stopped due
4932 to hitting a software breakpoint, and have to back up to the
4935 As a special case, we could have hardware single-stepped a
4936 software breakpoint. In this case (prev_pc == breakpoint_pc),
4937 we also need to back up to the breakpoint address. */
4939 if (thread_has_single_step_breakpoints_set (thread
)
4940 || !currently_stepping (thread
)
4941 || (thread
->stepped_breakpoint
4942 && thread
->prev_pc
== breakpoint_pc
))
4943 regcache_write_pc (regcache
, breakpoint_pc
);
4948 stepped_in_from (frame_info_ptr frame
, struct frame_id step_frame_id
)
4950 for (frame
= get_prev_frame (frame
);
4952 frame
= get_prev_frame (frame
))
4954 if (get_frame_id (frame
) == step_frame_id
)
4957 if (get_frame_type (frame
) != INLINE_FRAME
)
4964 /* Look for an inline frame that is marked for skip.
4965 If PREV_FRAME is TRUE start at the previous frame,
4966 otherwise start at the current frame. Stop at the
4967 first non-inline frame, or at the frame where the
4971 inline_frame_is_marked_for_skip (bool prev_frame
, struct thread_info
*tp
)
4973 frame_info_ptr frame
= get_current_frame ();
4976 frame
= get_prev_frame (frame
);
4978 for (; frame
!= nullptr; frame
= get_prev_frame (frame
))
4980 const char *fn
= nullptr;
4981 symtab_and_line sal
;
4984 if (get_frame_id (frame
) == tp
->control
.step_frame_id
)
4986 if (get_frame_type (frame
) != INLINE_FRAME
)
4989 sal
= find_frame_sal (frame
);
4990 sym
= get_frame_function (frame
);
4993 fn
= sym
->print_name ();
4996 && function_name_is_marked_for_skip (fn
, sal
))
5003 /* If the event thread has the stop requested flag set, pretend it
5004 stopped for a GDB_SIGNAL_0 (i.e., as if it stopped due to
5008 handle_stop_requested (struct execution_control_state
*ecs
)
5010 if (ecs
->event_thread
->stop_requested
)
5012 ecs
->ws
.set_stopped (GDB_SIGNAL_0
);
5013 handle_signal_stop (ecs
);
5019 /* Auxiliary function that handles syscall entry/return events.
5020 It returns true if the inferior should keep going (and GDB
5021 should ignore the event), or false if the event deserves to be
5025 handle_syscall_event (struct execution_control_state
*ecs
)
5027 struct regcache
*regcache
;
5030 context_switch (ecs
);
5032 regcache
= get_thread_regcache (ecs
->event_thread
);
5033 syscall_number
= ecs
->ws
.syscall_number ();
5034 ecs
->event_thread
->set_stop_pc (regcache_read_pc (regcache
));
5036 if (catch_syscall_enabled () > 0
5037 && catching_syscall_number (syscall_number
))
5039 infrun_debug_printf ("syscall number=%d", syscall_number
);
5041 ecs
->event_thread
->control
.stop_bpstat
5042 = bpstat_stop_status_nowatch (regcache
->aspace (),
5043 ecs
->event_thread
->stop_pc (),
5044 ecs
->event_thread
, ecs
->ws
);
5046 if (handle_stop_requested (ecs
))
5049 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5051 /* Catchpoint hit. */
5056 if (handle_stop_requested (ecs
))
5059 /* If no catchpoint triggered for this, then keep going. */
5065 /* Lazily fill in the execution_control_state's stop_func_* fields. */
5068 fill_in_stop_func (struct gdbarch
*gdbarch
,
5069 struct execution_control_state
*ecs
)
5071 if (!ecs
->stop_func_filled_in
)
5074 const general_symbol_info
*gsi
;
5076 /* Don't care about return value; stop_func_start and stop_func_name
5077 will both be 0 if it doesn't work. */
5078 find_pc_partial_function_sym (ecs
->event_thread
->stop_pc (),
5080 &ecs
->stop_func_start
,
5081 &ecs
->stop_func_end
,
5083 ecs
->stop_func_name
= gsi
== nullptr ? nullptr : gsi
->print_name ();
5085 /* The call to find_pc_partial_function, above, will set
5086 stop_func_start and stop_func_end to the start and end
5087 of the range containing the stop pc. If this range
5088 contains the entry pc for the block (which is always the
5089 case for contiguous blocks), advance stop_func_start past
5090 the function's start offset and entrypoint. Note that
5091 stop_func_start is NOT advanced when in a range of a
5092 non-contiguous block that does not contain the entry pc. */
5093 if (block
!= nullptr
5094 && ecs
->stop_func_start
<= block
->entry_pc ()
5095 && block
->entry_pc () < ecs
->stop_func_end
)
5097 ecs
->stop_func_start
5098 += gdbarch_deprecated_function_start_offset (gdbarch
);
5100 /* PowerPC functions have a Local Entry Point (LEP) and a Global
5101 Entry Point (GEP). There is only one Entry Point (GEP = LEP) for
5102 other architectures. */
5103 ecs
->stop_func_alt_start
= ecs
->stop_func_start
;
5105 if (gdbarch_skip_entrypoint_p (gdbarch
))
5106 ecs
->stop_func_start
5107 = gdbarch_skip_entrypoint (gdbarch
, ecs
->stop_func_start
);
5110 ecs
->stop_func_filled_in
= 1;
5115 /* Return the STOP_SOON field of the inferior pointed at by ECS. */
5117 static enum stop_kind
5118 get_inferior_stop_soon (execution_control_state
*ecs
)
5120 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5122 gdb_assert (inf
!= nullptr);
5123 return inf
->control
.stop_soon
;
5126 /* Poll for one event out of the current target. Store the resulting
5127 waitstatus in WS, and return the event ptid. Does not block. */
5130 poll_one_curr_target (struct target_waitstatus
*ws
)
5134 overlay_cache_invalid
= 1;
5136 /* Flush target cache before starting to handle each event.
5137 Target was running and cache could be stale. This is just a
5138 heuristic. Running threads may modify target memory, but we
5139 don't get any event. */
5140 target_dcache_invalidate ();
5142 event_ptid
= target_wait (minus_one_ptid
, ws
, TARGET_WNOHANG
);
5145 print_target_wait_results (minus_one_ptid
, event_ptid
, *ws
);
5150 /* Wait for one event out of any target. */
5152 static wait_one_event
5157 for (inferior
*inf
: all_inferiors ())
5159 process_stratum_target
*target
= inf
->process_target ();
5160 if (target
== nullptr
5161 || !target
->is_async_p ()
5162 || !target
->threads_executing
)
5165 switch_to_inferior_no_thread (inf
);
5167 wait_one_event event
;
5168 event
.target
= target
;
5169 event
.ptid
= poll_one_curr_target (&event
.ws
);
5171 if (event
.ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
5173 /* If nothing is resumed, remove the target from the
5175 target_async (false);
5177 else if (event
.ws
.kind () != TARGET_WAITKIND_IGNORE
)
5181 /* Block waiting for some event. */
5188 for (inferior
*inf
: all_inferiors ())
5190 process_stratum_target
*target
= inf
->process_target ();
5191 if (target
== nullptr
5192 || !target
->is_async_p ()
5193 || !target
->threads_executing
)
5196 int fd
= target
->async_wait_fd ();
5197 FD_SET (fd
, &readfds
);
5204 /* No waitable targets left. All must be stopped. */
5205 target_waitstatus ws
;
5206 ws
.set_no_resumed ();
5207 return {nullptr, minus_one_ptid
, std::move (ws
)};
5212 int numfds
= interruptible_select (nfds
, &readfds
, 0, nullptr, 0);
5218 perror_with_name ("interruptible_select");
5223 /* Save the thread's event and stop reason to process it later. */
5226 save_waitstatus (struct thread_info
*tp
, const target_waitstatus
&ws
)
5228 infrun_debug_printf ("saving status %s for %s",
5229 ws
.to_string ().c_str (),
5230 tp
->ptid
.to_string ().c_str ());
5232 /* Record for later. */
5233 tp
->set_pending_waitstatus (ws
);
5235 if (ws
.kind () == TARGET_WAITKIND_STOPPED
5236 && ws
.sig () == GDB_SIGNAL_TRAP
)
5238 struct regcache
*regcache
= get_thread_regcache (tp
);
5239 const address_space
*aspace
= regcache
->aspace ();
5240 CORE_ADDR pc
= regcache_read_pc (regcache
);
5242 adjust_pc_after_break (tp
, tp
->pending_waitstatus ());
5244 scoped_restore_current_thread restore_thread
;
5245 switch_to_thread (tp
);
5247 if (target_stopped_by_watchpoint ())
5248 tp
->set_stop_reason (TARGET_STOPPED_BY_WATCHPOINT
);
5249 else if (target_supports_stopped_by_sw_breakpoint ()
5250 && target_stopped_by_sw_breakpoint ())
5251 tp
->set_stop_reason (TARGET_STOPPED_BY_SW_BREAKPOINT
);
5252 else if (target_supports_stopped_by_hw_breakpoint ()
5253 && target_stopped_by_hw_breakpoint ())
5254 tp
->set_stop_reason (TARGET_STOPPED_BY_HW_BREAKPOINT
);
5255 else if (!target_supports_stopped_by_hw_breakpoint ()
5256 && hardware_breakpoint_inserted_here_p (aspace
, pc
))
5257 tp
->set_stop_reason (TARGET_STOPPED_BY_HW_BREAKPOINT
);
5258 else if (!target_supports_stopped_by_sw_breakpoint ()
5259 && software_breakpoint_inserted_here_p (aspace
, pc
))
5260 tp
->set_stop_reason (TARGET_STOPPED_BY_SW_BREAKPOINT
);
5261 else if (!thread_has_single_step_breakpoints_set (tp
)
5262 && currently_stepping (tp
))
5263 tp
->set_stop_reason (TARGET_STOPPED_BY_SINGLE_STEP
);
5267 /* Mark the non-executing threads accordingly. In all-stop, all
5268 threads of all processes are stopped when we get any event
5269 reported. In non-stop mode, only the event thread stops. */
5272 mark_non_executing_threads (process_stratum_target
*target
,
5274 const target_waitstatus
&ws
)
5278 if (!target_is_non_stop_p ())
5279 mark_ptid
= minus_one_ptid
;
5280 else if (ws
.kind () == TARGET_WAITKIND_SIGNALLED
5281 || ws
.kind () == TARGET_WAITKIND_EXITED
)
5283 /* If we're handling a process exit in non-stop mode, even
5284 though threads haven't been deleted yet, one would think
5285 that there is nothing to do, as threads of the dead process
5286 will be soon deleted, and threads of any other process were
5287 left running. However, on some targets, threads survive a
5288 process exit event. E.g., for the "checkpoint" command,
5289 when the current checkpoint/fork exits, linux-fork.c
5290 automatically switches to another fork from within
5291 target_mourn_inferior, by associating the same
5292 inferior/thread to another fork. We haven't mourned yet at
5293 this point, but we must mark any threads left in the
5294 process as not-executing so that finish_thread_state marks
5295 them stopped (in the user's perspective) if/when we present
5296 the stop to the user. */
5297 mark_ptid
= ptid_t (event_ptid
.pid ());
5300 mark_ptid
= event_ptid
;
5302 set_executing (target
, mark_ptid
, false);
5304 /* Likewise the resumed flag. */
5305 set_resumed (target
, mark_ptid
, false);
5308 /* Handle one event after stopping threads. If the eventing thread
5309 reports back any interesting event, we leave it pending. If the
5310 eventing thread was in the middle of a displaced step, we
5311 cancel/finish it, and unless the thread's inferior is being
5312 detached, put the thread back in the step-over chain. Returns true
5313 if there are no resumed threads left in the target (thus there's no
5314 point in waiting further), false otherwise. */
5317 handle_one (const wait_one_event
&event
)
5320 ("%s %s", event
.ws
.to_string ().c_str (),
5321 event
.ptid
.to_string ().c_str ());
5323 if (event
.ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
5325 /* All resumed threads exited. */
5328 else if (event
.ws
.kind () == TARGET_WAITKIND_THREAD_EXITED
5329 || event
.ws
.kind () == TARGET_WAITKIND_EXITED
5330 || event
.ws
.kind () == TARGET_WAITKIND_SIGNALLED
)
5332 /* One thread/process exited/signalled. */
5334 thread_info
*t
= nullptr;
5336 /* The target may have reported just a pid. If so, try
5337 the first non-exited thread. */
5338 if (event
.ptid
.is_pid ())
5340 int pid
= event
.ptid
.pid ();
5341 inferior
*inf
= find_inferior_pid (event
.target
, pid
);
5342 for (thread_info
*tp
: inf
->non_exited_threads ())
5348 /* If there is no available thread, the event would
5349 have to be appended to a per-inferior event list,
5350 which does not exist (and if it did, we'd have
5351 to adjust run control command to be able to
5352 resume such an inferior). We assert here instead
5353 of going into an infinite loop. */
5354 gdb_assert (t
!= nullptr);
5357 ("using %s", t
->ptid
.to_string ().c_str ());
5361 t
= event
.target
->find_thread (event
.ptid
);
5362 /* Check if this is the first time we see this thread.
5363 Don't bother adding if it individually exited. */
5365 && event
.ws
.kind () != TARGET_WAITKIND_THREAD_EXITED
)
5366 t
= add_thread (event
.target
, event
.ptid
);
5371 /* Set the threads as non-executing to avoid
5372 another stop attempt on them. */
5373 switch_to_thread_no_regs (t
);
5374 mark_non_executing_threads (event
.target
, event
.ptid
,
5376 save_waitstatus (t
, event
.ws
);
5377 t
->stop_requested
= false;
5379 if (event
.ws
.kind () == TARGET_WAITKIND_THREAD_EXITED
)
5381 if (displaced_step_finish (t
, event
.ws
)
5382 != DISPLACED_STEP_FINISH_STATUS_OK
)
5384 gdb_assert_not_reached ("displaced_step_finish on "
5385 "exited thread failed");
5392 thread_info
*t
= event
.target
->find_thread (event
.ptid
);
5394 t
= add_thread (event
.target
, event
.ptid
);
5396 t
->stop_requested
= 0;
5397 t
->set_executing (false);
5398 t
->set_resumed (false);
5399 t
->control
.may_range_step
= 0;
5401 /* This may be the first time we see the inferior report
5403 if (t
->inf
->needs_setup
)
5405 switch_to_thread_no_regs (t
);
5409 if (event
.ws
.kind () == TARGET_WAITKIND_STOPPED
5410 && event
.ws
.sig () == GDB_SIGNAL_0
)
5412 /* We caught the event that we intended to catch, so
5413 there's no event to save as pending. */
5415 if (displaced_step_finish (t
, event
.ws
)
5416 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5418 /* Add it back to the step-over queue. */
5420 ("displaced-step of %s canceled",
5421 t
->ptid
.to_string ().c_str ());
5423 t
->control
.trap_expected
= 0;
5424 if (!t
->inf
->detaching
)
5425 global_thread_step_over_chain_enqueue (t
);
5430 struct regcache
*regcache
;
5433 ("target_wait %s, saving status for %s",
5434 event
.ws
.to_string ().c_str (),
5435 t
->ptid
.to_string ().c_str ());
5437 /* Record for later. */
5438 save_waitstatus (t
, event
.ws
);
5440 if (displaced_step_finish (t
, event
.ws
)
5441 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5443 /* Add it back to the step-over queue. */
5444 t
->control
.trap_expected
= 0;
5445 if (!t
->inf
->detaching
)
5446 global_thread_step_over_chain_enqueue (t
);
5449 regcache
= get_thread_regcache (t
);
5450 t
->set_stop_pc (regcache_read_pc (regcache
));
5452 infrun_debug_printf ("saved stop_pc=%s for %s "
5453 "(currently_stepping=%d)",
5454 paddress (current_inferior ()->arch (),
5456 t
->ptid
.to_string ().c_str (),
5457 currently_stepping (t
));
5467 stop_all_threads (const char *reason
, inferior
*inf
)
5469 /* We may need multiple passes to discover all threads. */
5473 gdb_assert (exists_non_stop_target ());
5475 INFRUN_SCOPED_DEBUG_START_END ("reason=%s, inf=%d", reason
,
5476 inf
!= nullptr ? inf
->num
: -1);
5478 infrun_debug_show_threads ("non-exited threads",
5479 all_non_exited_threads ());
5481 scoped_restore_current_thread restore_thread
;
5483 /* Enable thread events on relevant targets. */
5484 for (auto *target
: all_non_exited_process_targets ())
5486 if (inf
!= nullptr && inf
->process_target () != target
)
5489 switch_to_target_no_thread (target
);
5490 target_thread_events (true);
5495 /* Disable thread events on relevant targets. */
5496 for (auto *target
: all_non_exited_process_targets ())
5498 if (inf
!= nullptr && inf
->process_target () != target
)
5501 switch_to_target_no_thread (target
);
5502 target_thread_events (false);
5505 /* Use debug_prefixed_printf directly to get a meaningful function
5508 debug_prefixed_printf ("infrun", "stop_all_threads", "done");
5511 /* Request threads to stop, and then wait for the stops. Because
5512 threads we already know about can spawn more threads while we're
5513 trying to stop them, and we only learn about new threads when we
5514 update the thread list, do this in a loop, and keep iterating
5515 until two passes find no threads that need to be stopped. */
5516 for (pass
= 0; pass
< 2; pass
++, iterations
++)
5518 infrun_debug_printf ("pass=%d, iterations=%d", pass
, iterations
);
5521 int waits_needed
= 0;
5523 for (auto *target
: all_non_exited_process_targets ())
5525 if (inf
!= nullptr && inf
->process_target () != target
)
5528 switch_to_target_no_thread (target
);
5529 update_thread_list ();
5532 /* Go through all threads looking for threads that we need
5533 to tell the target to stop. */
5534 for (thread_info
*t
: all_non_exited_threads ())
5536 if (inf
!= nullptr && t
->inf
!= inf
)
5539 /* For a single-target setting with an all-stop target,
5540 we would not even arrive here. For a multi-target
5541 setting, until GDB is able to handle a mixture of
5542 all-stop and non-stop targets, simply skip all-stop
5543 targets' threads. This should be fine due to the
5544 protection of 'check_multi_target_resumption'. */
5546 switch_to_thread_no_regs (t
);
5547 if (!target_is_non_stop_p ())
5550 if (t
->executing ())
5552 /* If already stopping, don't request a stop again.
5553 We just haven't seen the notification yet. */
5554 if (!t
->stop_requested
)
5556 infrun_debug_printf (" %s executing, need stop",
5557 t
->ptid
.to_string ().c_str ());
5558 target_stop (t
->ptid
);
5559 t
->stop_requested
= 1;
5563 infrun_debug_printf (" %s executing, already stopping",
5564 t
->ptid
.to_string ().c_str ());
5567 if (t
->stop_requested
)
5572 infrun_debug_printf (" %s not executing",
5573 t
->ptid
.to_string ().c_str ());
5575 /* The thread may be not executing, but still be
5576 resumed with a pending status to process. */
5577 t
->set_resumed (false);
5581 if (waits_needed
== 0)
5584 /* If we find new threads on the second iteration, restart
5585 over. We want to see two iterations in a row with all
5590 for (int i
= 0; i
< waits_needed
; i
++)
5592 wait_one_event event
= wait_one ();
5593 if (handle_one (event
))
5600 /* Handle a TARGET_WAITKIND_NO_RESUMED event. Return true if we
5601 handled the event and should continue waiting. Return false if we
5602 should stop and report the event to the user. */
5605 handle_no_resumed (struct execution_control_state
*ecs
)
5607 if (target_can_async_p ())
5609 bool any_sync
= false;
5611 for (ui
*ui
: all_uis ())
5613 if (ui
->prompt_state
== PROMPT_BLOCKED
)
5621 /* There were no unwaited-for children left in the target, but,
5622 we're not synchronously waiting for events either. Just
5625 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED (ignoring: bg)");
5626 prepare_to_wait (ecs
);
5631 /* Otherwise, if we were running a synchronous execution command, we
5632 may need to cancel it and give the user back the terminal.
5634 In non-stop mode, the target can't tell whether we've already
5635 consumed previous stop events, so it can end up sending us a
5636 no-resumed event like so:
5638 #0 - thread 1 is left stopped
5640 #1 - thread 2 is resumed and hits breakpoint
5641 -> TARGET_WAITKIND_STOPPED
5643 #2 - thread 3 is resumed and exits
5644 this is the last resumed thread, so
5645 -> TARGET_WAITKIND_NO_RESUMED
5647 #3 - gdb processes stop for thread 2 and decides to re-resume
5650 #4 - gdb processes the TARGET_WAITKIND_NO_RESUMED event.
5651 thread 2 is now resumed, so the event should be ignored.
5653 IOW, if the stop for thread 2 doesn't end a foreground command,
5654 then we need to ignore the following TARGET_WAITKIND_NO_RESUMED
5655 event. But it could be that the event meant that thread 2 itself
5656 (or whatever other thread was the last resumed thread) exited.
5658 To address this we refresh the thread list and check whether we
5659 have resumed threads _now_. In the example above, this removes
5660 thread 3 from the thread list. If thread 2 was re-resumed, we
5661 ignore this event. If we find no thread resumed, then we cancel
5662 the synchronous command and show "no unwaited-for " to the
5665 inferior
*curr_inf
= current_inferior ();
5667 scoped_restore_current_thread restore_thread
;
5668 update_thread_list ();
5672 - the current target has no thread executing, and
5673 - the current inferior is native, and
5674 - the current inferior is the one which has the terminal, and
5677 then a Ctrl-C from this point on would remain stuck in the
5678 kernel, until a thread resumes and dequeues it. That would
5679 result in the GDB CLI not reacting to Ctrl-C, not able to
5680 interrupt the program. To address this, if the current inferior
5681 no longer has any thread executing, we give the terminal to some
5682 other inferior that has at least one thread executing. */
5683 bool swap_terminal
= true;
5685 /* Whether to ignore this TARGET_WAITKIND_NO_RESUMED event, or
5686 whether to report it to the user. */
5687 bool ignore_event
= false;
5689 for (thread_info
*thread
: all_non_exited_threads ())
5691 if (swap_terminal
&& thread
->executing ())
5693 if (thread
->inf
!= curr_inf
)
5695 target_terminal::ours ();
5697 switch_to_thread (thread
);
5698 target_terminal::inferior ();
5700 swap_terminal
= false;
5703 if (!ignore_event
&& thread
->resumed ())
5705 /* Either there were no unwaited-for children left in the
5706 target at some point, but there are now, or some target
5707 other than the eventing one has unwaited-for children
5708 left. Just ignore. */
5709 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED "
5710 "(ignoring: found resumed)");
5712 ignore_event
= true;
5715 if (ignore_event
&& !swap_terminal
)
5721 switch_to_inferior_no_thread (curr_inf
);
5722 prepare_to_wait (ecs
);
5726 /* Go ahead and report the event. */
5730 /* Handle a TARGET_WAITKIND_THREAD_EXITED event. Return true if we
5731 handled the event and should continue waiting. Return false if we
5732 should stop and report the event to the user. */
5735 handle_thread_exited (execution_control_state
*ecs
)
5737 context_switch (ecs
);
5739 /* Clear these so we don't re-start the thread stepping over a
5740 breakpoint/watchpoint. */
5741 ecs
->event_thread
->stepping_over_breakpoint
= 0;
5742 ecs
->event_thread
->stepping_over_watchpoint
= 0;
5744 /* Maybe the thread was doing a step-over, if so release
5745 resources and start any further pending step-overs.
5747 If we are on a non-stop target and the thread was doing an
5748 in-line step, this also restarts the other threads. */
5749 int ret
= finish_step_over (ecs
);
5751 /* finish_step_over returns true if it moves ecs' wait status
5752 back into the thread, so that we go handle another pending
5753 event before this one. But we know it never does that if
5754 the event thread has exited. */
5755 gdb_assert (ret
== 0);
5757 /* If finish_step_over started a new in-line step-over, don't
5758 try to restart anything else. */
5759 if (step_over_info_valid_p ())
5761 delete_thread (ecs
->event_thread
);
5765 /* Maybe we are on an all-stop target and we got this event
5766 while doing a step-like command on another thread. If so,
5767 go back to doing that. If this thread was stepping,
5768 switch_back_to_stepped_thread will consider that the thread
5769 was interrupted mid-step and will try keep stepping it. We
5770 don't want that, the thread is gone. So clear the proceed
5771 status so it doesn't do that. */
5772 clear_proceed_status_thread (ecs
->event_thread
);
5773 if (switch_back_to_stepped_thread (ecs
))
5775 delete_thread (ecs
->event_thread
);
5779 inferior
*inf
= ecs
->event_thread
->inf
;
5780 bool slock_applies
= schedlock_applies (ecs
->event_thread
);
5782 delete_thread (ecs
->event_thread
);
5783 ecs
->event_thread
= nullptr;
5785 /* Continue handling the event as if we had gotten a
5786 TARGET_WAITKIND_NO_RESUMED. */
5787 auto handle_as_no_resumed
= [ecs
] ()
5789 /* handle_no_resumed doesn't really look at the event kind, but
5790 normal_stop does. */
5791 ecs
->ws
.set_no_resumed ();
5792 ecs
->event_thread
= nullptr;
5793 ecs
->ptid
= minus_one_ptid
;
5795 /* Re-record the last target status. */
5796 set_last_target_status (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5798 return handle_no_resumed (ecs
);
5801 /* If we are on an all-stop target, the target has stopped all
5802 threads to report the event. We don't actually want to
5803 stop, so restart the threads. */
5804 if (!target_is_non_stop_p ())
5808 /* Since the target is !non-stop, then everything is stopped
5809 at this point, and we can't assume we'll get further
5810 events until we resume the target again. Handle this
5811 event like if it were a TARGET_WAITKIND_NO_RESUMED. Note
5812 this refreshes the thread list and checks whether there
5813 are other resumed threads before deciding whether to
5814 print "no-unwaited-for left". This is important because
5815 the user could have done:
5817 (gdb) set scheduler-locking on
5823 ... and only one of the threads exited. */
5824 return handle_as_no_resumed ();
5828 /* Switch to the first non-exited thread we can find, and
5830 auto range
= inf
->non_exited_threads ();
5831 if (range
.begin () == range
.end ())
5833 /* Looks like the target reported a
5834 TARGET_WAITKIND_THREAD_EXITED for its last known
5836 return handle_as_no_resumed ();
5838 thread_info
*non_exited_thread
= *range
.begin ();
5839 switch_to_thread (non_exited_thread
);
5840 insert_breakpoints ();
5841 resume (GDB_SIGNAL_0
);
5845 prepare_to_wait (ecs
);
5849 /* Given an execution control state that has been freshly filled in by
5850 an event from the inferior, figure out what it means and take
5853 The alternatives are:
5855 1) stop_waiting and return; to really stop and return to the
5858 2) keep_going and return; to wait for the next event (set
5859 ecs->event_thread->stepping_over_breakpoint to 1 to single step
5863 handle_inferior_event (struct execution_control_state
*ecs
)
5865 /* Make sure that all temporary struct value objects that were
5866 created during the handling of the event get deleted at the
5868 scoped_value_mark free_values
;
5870 infrun_debug_printf ("%s", ecs
->ws
.to_string ().c_str ());
5872 if (ecs
->ws
.kind () == TARGET_WAITKIND_IGNORE
)
5874 /* We had an event in the inferior, but we are not interested in
5875 handling it at this level. The lower layers have already
5876 done what needs to be done, if anything.
5878 One of the possible circumstances for this is when the
5879 inferior produces output for the console. The inferior has
5880 not stopped, and we are ignoring the event. Another possible
5881 circumstance is any event which the lower level knows will be
5882 reported multiple times without an intervening resume. */
5883 prepare_to_wait (ecs
);
5887 if (ecs
->ws
.kind () == TARGET_WAITKIND_NO_RESUMED
5888 && handle_no_resumed (ecs
))
5891 /* Cache the last target/ptid/waitstatus. */
5892 set_last_target_status (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5894 /* Always clear state belonging to the previous time we stopped. */
5895 stop_stack_dummy
= STOP_NONE
;
5897 if (ecs
->ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
5899 /* No unwaited-for children left. IOW, all resumed children
5905 if (ecs
->ws
.kind () != TARGET_WAITKIND_EXITED
5906 && ecs
->ws
.kind () != TARGET_WAITKIND_SIGNALLED
)
5908 ecs
->event_thread
= ecs
->target
->find_thread (ecs
->ptid
);
5909 /* If it's a new thread, add it to the thread database. */
5910 if (ecs
->event_thread
== nullptr)
5911 ecs
->event_thread
= add_thread (ecs
->target
, ecs
->ptid
);
5913 /* Disable range stepping. If the next step request could use a
5914 range, this will be end up re-enabled then. */
5915 ecs
->event_thread
->control
.may_range_step
= 0;
5918 /* Dependent on valid ECS->EVENT_THREAD. */
5919 adjust_pc_after_break (ecs
->event_thread
, ecs
->ws
);
5921 /* Dependent on the current PC value modified by adjust_pc_after_break. */
5922 reinit_frame_cache ();
5924 breakpoint_retire_moribund ();
5926 /* First, distinguish signals caused by the debugger from signals
5927 that have to do with the program's own actions. Note that
5928 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
5929 on the operating system version. Here we detect when a SIGILL or
5930 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
5931 something similar for SIGSEGV, since a SIGSEGV will be generated
5932 when we're trying to execute a breakpoint instruction on a
5933 non-executable stack. This happens for call dummy breakpoints
5934 for architectures like SPARC that place call dummies on the
5936 if (ecs
->ws
.kind () == TARGET_WAITKIND_STOPPED
5937 && (ecs
->ws
.sig () == GDB_SIGNAL_ILL
5938 || ecs
->ws
.sig () == GDB_SIGNAL_SEGV
5939 || ecs
->ws
.sig () == GDB_SIGNAL_EMT
))
5941 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5943 if (breakpoint_inserted_here_p (regcache
->aspace (),
5944 regcache_read_pc (regcache
)))
5946 infrun_debug_printf ("Treating signal as SIGTRAP");
5947 ecs
->ws
.set_stopped (GDB_SIGNAL_TRAP
);
5951 mark_non_executing_threads (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5953 switch (ecs
->ws
.kind ())
5955 case TARGET_WAITKIND_LOADED
:
5957 context_switch (ecs
);
5958 /* Ignore gracefully during startup of the inferior, as it might
5959 be the shell which has just loaded some objects, otherwise
5960 add the symbols for the newly loaded objects. Also ignore at
5961 the beginning of an attach or remote session; we will query
5962 the full list of libraries once the connection is
5965 stop_kind stop_soon
= get_inferior_stop_soon (ecs
);
5966 if (stop_soon
== NO_STOP_QUIETLY
)
5968 struct regcache
*regcache
;
5970 regcache
= get_thread_regcache (ecs
->event_thread
);
5972 handle_solib_event ();
5974 ecs
->event_thread
->set_stop_pc (regcache_read_pc (regcache
));
5975 ecs
->event_thread
->control
.stop_bpstat
5976 = bpstat_stop_status_nowatch (regcache
->aspace (),
5977 ecs
->event_thread
->stop_pc (),
5978 ecs
->event_thread
, ecs
->ws
);
5980 if (handle_stop_requested (ecs
))
5983 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5985 /* A catchpoint triggered. */
5986 process_event_stop_test (ecs
);
5990 /* If requested, stop when the dynamic linker notifies
5991 gdb of events. This allows the user to get control
5992 and place breakpoints in initializer routines for
5993 dynamically loaded objects (among other things). */
5994 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5995 if (stop_on_solib_events
)
5997 /* Make sure we print "Stopped due to solib-event" in
5999 stop_print_frame
= true;
6006 /* If we are skipping through a shell, or through shared library
6007 loading that we aren't interested in, resume the program. If
6008 we're running the program normally, also resume. */
6009 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
6011 /* Loading of shared libraries might have changed breakpoint
6012 addresses. Make sure new breakpoints are inserted. */
6013 if (stop_soon
== NO_STOP_QUIETLY
)
6014 insert_breakpoints ();
6015 resume (GDB_SIGNAL_0
);
6016 prepare_to_wait (ecs
);
6020 /* But stop if we're attaching or setting up a remote
6022 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
6023 || stop_soon
== STOP_QUIETLY_REMOTE
)
6025 infrun_debug_printf ("quietly stopped");
6030 internal_error (_("unhandled stop_soon: %d"), (int) stop_soon
);
6033 case TARGET_WAITKIND_SPURIOUS
:
6034 if (handle_stop_requested (ecs
))
6036 context_switch (ecs
);
6037 resume (GDB_SIGNAL_0
);
6038 prepare_to_wait (ecs
);
6041 case TARGET_WAITKIND_THREAD_CREATED
:
6042 if (handle_stop_requested (ecs
))
6044 context_switch (ecs
);
6045 if (!switch_back_to_stepped_thread (ecs
))
6049 case TARGET_WAITKIND_THREAD_EXITED
:
6050 if (handle_thread_exited (ecs
))
6055 case TARGET_WAITKIND_EXITED
:
6056 case TARGET_WAITKIND_SIGNALLED
:
6058 /* Depending on the system, ecs->ptid may point to a thread or
6059 to a process. On some targets, target_mourn_inferior may
6060 need to have access to the just-exited thread. That is the
6061 case of GNU/Linux's "checkpoint" support, for example.
6062 Call the switch_to_xxx routine as appropriate. */
6063 thread_info
*thr
= ecs
->target
->find_thread (ecs
->ptid
);
6065 switch_to_thread (thr
);
6068 inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
6069 switch_to_inferior_no_thread (inf
);
6072 handle_vfork_child_exec_or_exit (0);
6073 target_terminal::ours (); /* Must do this before mourn anyway. */
6075 /* Clearing any previous state of convenience variables. */
6076 clear_exit_convenience_vars ();
6078 if (ecs
->ws
.kind () == TARGET_WAITKIND_EXITED
)
6080 /* Record the exit code in the convenience variable $_exitcode, so
6081 that the user can inspect this again later. */
6082 set_internalvar_integer (lookup_internalvar ("_exitcode"),
6083 (LONGEST
) ecs
->ws
.exit_status ());
6085 /* Also record this in the inferior itself. */
6086 current_inferior ()->has_exit_code
= true;
6087 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.exit_status ();
6089 /* Support the --return-child-result option. */
6090 return_child_result_value
= ecs
->ws
.exit_status ();
6092 interps_notify_exited (ecs
->ws
.exit_status ());
6096 struct gdbarch
*gdbarch
= current_inferior ()->arch ();
6098 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
6100 /* Set the value of the internal variable $_exitsignal,
6101 which holds the signal uncaught by the inferior. */
6102 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
6103 gdbarch_gdb_signal_to_target (gdbarch
,
6108 /* We don't have access to the target's method used for
6109 converting between signal numbers (GDB's internal
6110 representation <-> target's representation).
6111 Therefore, we cannot do a good job at displaying this
6112 information to the user. It's better to just warn
6113 her about it (if infrun debugging is enabled), and
6115 infrun_debug_printf ("Cannot fill $_exitsignal with the correct "
6119 interps_notify_signal_exited (ecs
->ws
.sig ());
6122 gdb_flush (gdb_stdout
);
6123 target_mourn_inferior (inferior_ptid
);
6124 stop_print_frame
= false;
6128 case TARGET_WAITKIND_FORKED
:
6129 case TARGET_WAITKIND_VFORKED
:
6130 case TARGET_WAITKIND_THREAD_CLONED
:
6132 displaced_step_finish (ecs
->event_thread
, ecs
->ws
);
6134 /* Start a new step-over in another thread if there's one that
6138 context_switch (ecs
);
6140 /* Immediately detach breakpoints from the child before there's
6141 any chance of letting the user delete breakpoints from the
6142 breakpoint lists. If we don't do this early, it's easy to
6143 leave left over traps in the child, vis: "break foo; catch
6144 fork; c; <fork>; del; c; <child calls foo>". We only follow
6145 the fork on the last `continue', and by that time the
6146 breakpoint at "foo" is long gone from the breakpoint table.
6147 If we vforked, then we don't need to unpatch here, since both
6148 parent and child are sharing the same memory pages; we'll
6149 need to unpatch at follow/detach time instead to be certain
6150 that new breakpoints added between catchpoint hit time and
6151 vfork follow are detached. */
6152 if (ecs
->ws
.kind () == TARGET_WAITKIND_FORKED
)
6154 /* This won't actually modify the breakpoint list, but will
6155 physically remove the breakpoints from the child. */
6156 detach_breakpoints (ecs
->ws
.child_ptid ());
6159 delete_just_stopped_threads_single_step_breakpoints ();
6161 /* In case the event is caught by a catchpoint, remember that
6162 the event is to be followed at the next resume of the thread,
6163 and not immediately. */
6164 ecs
->event_thread
->pending_follow
= ecs
->ws
;
6166 ecs
->event_thread
->set_stop_pc
6167 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
6169 ecs
->event_thread
->control
.stop_bpstat
6170 = bpstat_stop_status_nowatch (get_current_regcache ()->aspace (),
6171 ecs
->event_thread
->stop_pc (),
6172 ecs
->event_thread
, ecs
->ws
);
6174 if (handle_stop_requested (ecs
))
6177 /* If no catchpoint triggered for this, then keep going. Note
6178 that we're interested in knowing the bpstat actually causes a
6179 stop, not just if it may explain the signal. Software
6180 watchpoints, for example, always appear in the bpstat. */
6181 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
6184 = (ecs
->ws
.kind () != TARGET_WAITKIND_THREAD_CLONED
6185 && follow_fork_mode_string
== follow_fork_mode_child
);
6187 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6189 process_stratum_target
*targ
6190 = ecs
->event_thread
->inf
->process_target ();
6193 if (ecs
->ws
.kind () != TARGET_WAITKIND_THREAD_CLONED
)
6194 should_resume
= follow_fork ();
6197 should_resume
= true;
6198 inferior
*inf
= ecs
->event_thread
->inf
;
6199 inf
->top_target ()->follow_clone (ecs
->ws
.child_ptid ());
6200 ecs
->event_thread
->pending_follow
.set_spurious ();
6203 /* Note that one of these may be an invalid pointer,
6204 depending on detach_fork. */
6205 thread_info
*parent
= ecs
->event_thread
;
6206 thread_info
*child
= targ
->find_thread (ecs
->ws
.child_ptid ());
6208 /* At this point, the parent is marked running, and the
6209 child is marked stopped. */
6211 /* If not resuming the parent, mark it stopped. */
6212 if (ecs
->ws
.kind () != TARGET_WAITKIND_THREAD_CLONED
6213 && follow_child
&& !detach_fork
&& !non_stop
&& !sched_multi
)
6214 parent
->set_running (false);
6216 /* If resuming the child, mark it running. */
6217 if (ecs
->ws
.kind () == TARGET_WAITKIND_THREAD_CLONED
6218 || (follow_child
|| (!detach_fork
&& (non_stop
|| sched_multi
))))
6219 child
->set_running (true);
6221 /* In non-stop mode, also resume the other branch. */
6222 if ((ecs
->ws
.kind () == TARGET_WAITKIND_THREAD_CLONED
6223 && target_is_non_stop_p ())
6224 || (!detach_fork
&& (non_stop
6226 && target_is_non_stop_p ()))))
6229 switch_to_thread (parent
);
6231 switch_to_thread (child
);
6233 ecs
->event_thread
= inferior_thread ();
6234 ecs
->ptid
= inferior_ptid
;
6239 switch_to_thread (child
);
6241 switch_to_thread (parent
);
6243 ecs
->event_thread
= inferior_thread ();
6244 ecs
->ptid
= inferior_ptid
;
6248 /* Never call switch_back_to_stepped_thread if we are waiting for
6249 vfork-done (waiting for an external vfork child to exec or
6250 exit). We will resume only the vforking thread for the purpose
6251 of collecting the vfork-done event, and we will restart any
6252 step once the critical shared address space window is done. */
6255 && parent
->inf
->thread_waiting_for_vfork_done
!= nullptr)
6256 || !switch_back_to_stepped_thread (ecs
))
6263 process_event_stop_test (ecs
);
6266 case TARGET_WAITKIND_VFORK_DONE
:
6267 /* Done with the shared memory region. Re-insert breakpoints in
6268 the parent, and keep going. */
6270 context_switch (ecs
);
6272 handle_vfork_done (ecs
->event_thread
);
6273 gdb_assert (inferior_thread () == ecs
->event_thread
);
6275 if (handle_stop_requested (ecs
))
6278 if (!switch_back_to_stepped_thread (ecs
))
6280 gdb_assert (inferior_thread () == ecs
->event_thread
);
6281 /* This also takes care of reinserting breakpoints in the
6282 previously locked inferior. */
6287 case TARGET_WAITKIND_EXECD
:
6289 /* Note we can't read registers yet (the stop_pc), because we
6290 don't yet know the inferior's post-exec architecture.
6291 'stop_pc' is explicitly read below instead. */
6292 switch_to_thread_no_regs (ecs
->event_thread
);
6294 /* Do whatever is necessary to the parent branch of the vfork. */
6295 handle_vfork_child_exec_or_exit (1);
6297 /* This causes the eventpoints and symbol table to be reset.
6298 Must do this now, before trying to determine whether to
6300 follow_exec (inferior_ptid
, ecs
->ws
.execd_pathname ());
6302 /* In follow_exec we may have deleted the original thread and
6303 created a new one. Make sure that the event thread is the
6304 execd thread for that case (this is a nop otherwise). */
6305 ecs
->event_thread
= inferior_thread ();
6307 ecs
->event_thread
->set_stop_pc
6308 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
6310 ecs
->event_thread
->control
.stop_bpstat
6311 = bpstat_stop_status_nowatch (get_current_regcache ()->aspace (),
6312 ecs
->event_thread
->stop_pc (),
6313 ecs
->event_thread
, ecs
->ws
);
6315 if (handle_stop_requested (ecs
))
6318 /* If no catchpoint triggered for this, then keep going. */
6319 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
6321 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6325 process_event_stop_test (ecs
);
6328 /* Be careful not to try to gather much state about a thread
6329 that's in a syscall. It's frequently a losing proposition. */
6330 case TARGET_WAITKIND_SYSCALL_ENTRY
:
6331 /* Getting the current syscall number. */
6332 if (handle_syscall_event (ecs
) == 0)
6333 process_event_stop_test (ecs
);
6336 /* Before examining the threads further, step this thread to
6337 get it entirely out of the syscall. (We get notice of the
6338 event when the thread is just on the verge of exiting a
6339 syscall. Stepping one instruction seems to get it back
6341 case TARGET_WAITKIND_SYSCALL_RETURN
:
6342 if (handle_syscall_event (ecs
) == 0)
6343 process_event_stop_test (ecs
);
6346 case TARGET_WAITKIND_STOPPED
:
6347 handle_signal_stop (ecs
);
6350 case TARGET_WAITKIND_NO_HISTORY
:
6351 /* Reverse execution: target ran out of history info. */
6353 /* Switch to the stopped thread. */
6354 context_switch (ecs
);
6355 infrun_debug_printf ("stopped");
6357 delete_just_stopped_threads_single_step_breakpoints ();
6358 ecs
->event_thread
->set_stop_pc
6359 (regcache_read_pc (get_thread_regcache (inferior_thread ())));
6361 if (handle_stop_requested (ecs
))
6364 interps_notify_no_history ();
6370 /* Restart threads back to what they were trying to do back when we
6371 paused them (because of an in-line step-over or vfork, for example).
6372 The EVENT_THREAD thread is ignored (not restarted).
6374 If INF is non-nullptr, only resume threads from INF. */
6377 restart_threads (struct thread_info
*event_thread
, inferior
*inf
)
6379 INFRUN_SCOPED_DEBUG_START_END ("event_thread=%s, inf=%d",
6380 event_thread
->ptid
.to_string ().c_str (),
6381 inf
!= nullptr ? inf
->num
: -1);
6383 gdb_assert (!step_over_info_valid_p ());
6385 /* In case the instruction just stepped spawned a new thread. */
6386 update_thread_list ();
6388 for (thread_info
*tp
: all_non_exited_threads ())
6390 if (inf
!= nullptr && tp
->inf
!= inf
)
6393 if (tp
->inf
->detaching
)
6395 infrun_debug_printf ("restart threads: [%s] inferior detaching",
6396 tp
->ptid
.to_string ().c_str ());
6400 switch_to_thread_no_regs (tp
);
6402 if (tp
== event_thread
)
6404 infrun_debug_printf ("restart threads: [%s] is event thread",
6405 tp
->ptid
.to_string ().c_str ());
6409 if (!(tp
->state
== THREAD_RUNNING
|| tp
->control
.in_infcall
))
6411 infrun_debug_printf ("restart threads: [%s] not meant to be running",
6412 tp
->ptid
.to_string ().c_str ());
6418 infrun_debug_printf ("restart threads: [%s] resumed",
6419 tp
->ptid
.to_string ().c_str ());
6420 gdb_assert (tp
->executing () || tp
->has_pending_waitstatus ());
6424 if (thread_is_in_step_over_chain (tp
))
6426 infrun_debug_printf ("restart threads: [%s] needs step-over",
6427 tp
->ptid
.to_string ().c_str ());
6428 gdb_assert (!tp
->resumed ());
6433 if (tp
->has_pending_waitstatus ())
6435 infrun_debug_printf ("restart threads: [%s] has pending status",
6436 tp
->ptid
.to_string ().c_str ());
6437 tp
->set_resumed (true);
6441 gdb_assert (!tp
->stop_requested
);
6443 /* If some thread needs to start a step-over at this point, it
6444 should still be in the step-over queue, and thus skipped
6446 if (thread_still_needs_step_over (tp
))
6448 internal_error ("thread [%s] needs a step-over, but not in "
6449 "step-over queue\n",
6450 tp
->ptid
.to_string ().c_str ());
6453 if (currently_stepping (tp
))
6455 infrun_debug_printf ("restart threads: [%s] was stepping",
6456 tp
->ptid
.to_string ().c_str ());
6457 keep_going_stepped_thread (tp
);
6461 infrun_debug_printf ("restart threads: [%s] continuing",
6462 tp
->ptid
.to_string ().c_str ());
6463 execution_control_state
ecs (tp
);
6464 switch_to_thread (tp
);
6465 keep_going_pass_signal (&ecs
);
6470 /* Callback for iterate_over_threads. Find a resumed thread that has
6471 a pending waitstatus. */
6474 resumed_thread_with_pending_status (struct thread_info
*tp
,
6477 return tp
->resumed () && tp
->has_pending_waitstatus ();
6480 /* Called when we get an event that may finish an in-line or
6481 out-of-line (displaced stepping) step-over started previously.
6482 Return true if the event is processed and we should go back to the
6483 event loop; false if the caller should continue processing the
6487 finish_step_over (struct execution_control_state
*ecs
)
6489 displaced_step_finish (ecs
->event_thread
, ecs
->ws
);
6491 bool had_step_over_info
= step_over_info_valid_p ();
6493 if (had_step_over_info
)
6495 /* If we're stepping over a breakpoint with all threads locked,
6496 then only the thread that was stepped should be reporting
6498 gdb_assert (ecs
->event_thread
->control
.trap_expected
);
6500 update_thread_events_after_step_over (ecs
->event_thread
, ecs
->ws
);
6502 clear_step_over_info ();
6505 if (!target_is_non_stop_p ())
6508 /* Start a new step-over in another thread if there's one that
6512 /* If we were stepping over a breakpoint before, and haven't started
6513 a new in-line step-over sequence, then restart all other threads
6514 (except the event thread). We can't do this in all-stop, as then
6515 e.g., we wouldn't be able to issue any other remote packet until
6516 these other threads stop. */
6517 if (had_step_over_info
&& !step_over_info_valid_p ())
6519 struct thread_info
*pending
;
6521 /* If we only have threads with pending statuses, the restart
6522 below won't restart any thread and so nothing re-inserts the
6523 breakpoint we just stepped over. But we need it inserted
6524 when we later process the pending events, otherwise if
6525 another thread has a pending event for this breakpoint too,
6526 we'd discard its event (because the breakpoint that
6527 originally caused the event was no longer inserted). */
6528 context_switch (ecs
);
6529 insert_breakpoints ();
6531 restart_threads (ecs
->event_thread
);
6533 /* If we have events pending, go through handle_inferior_event
6534 again, picking up a pending event at random. This avoids
6535 thread starvation. */
6537 /* But not if we just stepped over a watchpoint in order to let
6538 the instruction execute so we can evaluate its expression.
6539 The set of watchpoints that triggered is recorded in the
6540 breakpoint objects themselves (see bp->watchpoint_triggered).
6541 If we processed another event first, that other event could
6542 clobber this info. */
6543 if (ecs
->event_thread
->stepping_over_watchpoint
)
6546 /* The code below is meant to avoid one thread hogging the event
6547 loop by doing constant in-line step overs. If the stepping
6548 thread exited, there's no risk for this to happen, so we can
6549 safely let our caller process the event immediately. */
6550 if (ecs
->ws
.kind () == TARGET_WAITKIND_THREAD_EXITED
)
6553 pending
= iterate_over_threads (resumed_thread_with_pending_status
,
6555 if (pending
!= nullptr)
6557 struct thread_info
*tp
= ecs
->event_thread
;
6558 struct regcache
*regcache
;
6560 infrun_debug_printf ("found resumed threads with "
6561 "pending events, saving status");
6563 gdb_assert (pending
!= tp
);
6565 /* Record the event thread's event for later. */
6566 save_waitstatus (tp
, ecs
->ws
);
6567 /* This was cleared early, by handle_inferior_event. Set it
6568 so this pending event is considered by
6570 tp
->set_resumed (true);
6572 gdb_assert (!tp
->executing ());
6574 regcache
= get_thread_regcache (tp
);
6575 tp
->set_stop_pc (regcache_read_pc (regcache
));
6577 infrun_debug_printf ("saved stop_pc=%s for %s "
6578 "(currently_stepping=%d)",
6579 paddress (current_inferior ()->arch (),
6581 tp
->ptid
.to_string ().c_str (),
6582 currently_stepping (tp
));
6584 /* This in-line step-over finished; clear this so we won't
6585 start a new one. This is what handle_signal_stop would
6586 do, if we returned false. */
6587 tp
->stepping_over_breakpoint
= 0;
6589 /* Wake up the event loop again. */
6590 mark_async_event_handler (infrun_async_inferior_event_token
);
6592 prepare_to_wait (ecs
);
6603 notify_signal_received (gdb_signal sig
)
6605 interps_notify_signal_received (sig
);
6606 gdb::observers::signal_received
.notify (sig
);
6612 notify_normal_stop (bpstat
*bs
, int print_frame
)
6614 interps_notify_normal_stop (bs
, print_frame
);
6615 gdb::observers::normal_stop
.notify (bs
, print_frame
);
6620 void notify_user_selected_context_changed (user_selected_what selection
)
6622 interps_notify_user_selected_context_changed (selection
);
6623 gdb::observers::user_selected_context_changed
.notify (selection
);
6626 /* Come here when the program has stopped with a signal. */
6629 handle_signal_stop (struct execution_control_state
*ecs
)
6631 frame_info_ptr frame
;
6632 struct gdbarch
*gdbarch
;
6633 int stopped_by_watchpoint
;
6634 enum stop_kind stop_soon
;
6637 gdb_assert (ecs
->ws
.kind () == TARGET_WAITKIND_STOPPED
);
6639 ecs
->event_thread
->set_stop_signal (ecs
->ws
.sig ());
6641 /* Do we need to clean up the state of a thread that has
6642 completed a displaced single-step? (Doing so usually affects
6643 the PC, so do it here, before we set stop_pc.) */
6644 if (finish_step_over (ecs
))
6647 /* If we either finished a single-step or hit a breakpoint, but
6648 the user wanted this thread to be stopped, pretend we got a
6649 SIG0 (generic unsignaled stop). */
6650 if (ecs
->event_thread
->stop_requested
6651 && ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
6652 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6654 ecs
->event_thread
->set_stop_pc
6655 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
6657 context_switch (ecs
);
6659 if (deprecated_context_hook
)
6660 deprecated_context_hook (ecs
->event_thread
->global_num
);
6664 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
6665 struct gdbarch
*reg_gdbarch
= regcache
->arch ();
6668 ("stop_pc=%s", paddress (reg_gdbarch
, ecs
->event_thread
->stop_pc ()));
6669 if (target_stopped_by_watchpoint ())
6673 infrun_debug_printf ("stopped by watchpoint");
6675 if (target_stopped_data_address (current_inferior ()->top_target (),
6677 infrun_debug_printf ("stopped data address=%s",
6678 paddress (reg_gdbarch
, addr
));
6680 infrun_debug_printf ("(no data address available)");
6684 /* This is originated from start_remote(), start_inferior() and
6685 shared libraries hook functions. */
6686 stop_soon
= get_inferior_stop_soon (ecs
);
6687 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
6689 infrun_debug_printf ("quietly stopped");
6690 stop_print_frame
= true;
6695 /* This originates from attach_command(). We need to overwrite
6696 the stop_signal here, because some kernels don't ignore a
6697 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
6698 See more comments in inferior.h. On the other hand, if we
6699 get a non-SIGSTOP, report it to the user - assume the backend
6700 will handle the SIGSTOP if it should show up later.
6702 Also consider that the attach is complete when we see a
6703 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
6704 target extended-remote report it instead of a SIGSTOP
6705 (e.g. gdbserver). We already rely on SIGTRAP being our
6706 signal, so this is no exception.
6708 Also consider that the attach is complete when we see a
6709 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
6710 the target to stop all threads of the inferior, in case the
6711 low level attach operation doesn't stop them implicitly. If
6712 they weren't stopped implicitly, then the stub will report a
6713 GDB_SIGNAL_0, meaning: stopped for no particular reason
6714 other than GDB's request. */
6715 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
6716 && (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_STOP
6717 || ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6718 || ecs
->event_thread
->stop_signal () == GDB_SIGNAL_0
))
6720 stop_print_frame
= true;
6722 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6726 /* At this point, get hold of the now-current thread's frame. */
6727 frame
= get_current_frame ();
6728 gdbarch
= get_frame_arch (frame
);
6730 /* Pull the single step breakpoints out of the target. */
6731 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
6733 struct regcache
*regcache
;
6736 regcache
= get_thread_regcache (ecs
->event_thread
);
6737 const address_space
*aspace
= regcache
->aspace ();
6739 pc
= regcache_read_pc (regcache
);
6741 /* However, before doing so, if this single-step breakpoint was
6742 actually for another thread, set this thread up for moving
6744 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
6747 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
6749 infrun_debug_printf ("[%s] hit another thread's single-step "
6751 ecs
->ptid
.to_string ().c_str ());
6752 ecs
->hit_singlestep_breakpoint
= 1;
6757 infrun_debug_printf ("[%s] hit its single-step breakpoint",
6758 ecs
->ptid
.to_string ().c_str ());
6761 delete_just_stopped_threads_single_step_breakpoints ();
6763 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6764 && ecs
->event_thread
->control
.trap_expected
6765 && ecs
->event_thread
->stepping_over_watchpoint
)
6766 stopped_by_watchpoint
= 0;
6768 stopped_by_watchpoint
= watchpoints_triggered (ecs
->ws
);
6770 /* If necessary, step over this watchpoint. We'll be back to display
6772 if (stopped_by_watchpoint
6773 && (target_have_steppable_watchpoint ()
6774 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
6776 /* At this point, we are stopped at an instruction which has
6777 attempted to write to a piece of memory under control of
6778 a watchpoint. The instruction hasn't actually executed
6779 yet. If we were to evaluate the watchpoint expression
6780 now, we would get the old value, and therefore no change
6781 would seem to have occurred.
6783 In order to make watchpoints work `right', we really need
6784 to complete the memory write, and then evaluate the
6785 watchpoint expression. We do this by single-stepping the
6788 It may not be necessary to disable the watchpoint to step over
6789 it. For example, the PA can (with some kernel cooperation)
6790 single step over a watchpoint without disabling the watchpoint.
6792 It is far more common to need to disable a watchpoint to step
6793 the inferior over it. If we have non-steppable watchpoints,
6794 we must disable the current watchpoint; it's simplest to
6795 disable all watchpoints.
6797 Any breakpoint at PC must also be stepped over -- if there's
6798 one, it will have already triggered before the watchpoint
6799 triggered, and we either already reported it to the user, or
6800 it didn't cause a stop and we called keep_going. In either
6801 case, if there was a breakpoint at PC, we must be trying to
6803 ecs
->event_thread
->stepping_over_watchpoint
= 1;
6808 ecs
->event_thread
->stepping_over_breakpoint
= 0;
6809 ecs
->event_thread
->stepping_over_watchpoint
= 0;
6810 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
6811 ecs
->event_thread
->control
.stop_step
= 0;
6812 stop_print_frame
= true;
6813 stopped_by_random_signal
= 0;
6814 bpstat
*stop_chain
= nullptr;
6816 /* Hide inlined functions starting here, unless we just performed stepi or
6817 nexti. After stepi and nexti, always show the innermost frame (not any
6818 inline function call sites). */
6819 if (ecs
->event_thread
->control
.step_range_end
!= 1)
6821 const address_space
*aspace
6822 = get_thread_regcache (ecs
->event_thread
)->aspace ();
6824 /* skip_inline_frames is expensive, so we avoid it if we can
6825 determine that the address is one where functions cannot have
6826 been inlined. This improves performance with inferiors that
6827 load a lot of shared libraries, because the solib event
6828 breakpoint is defined as the address of a function (i.e. not
6829 inline). Note that we have to check the previous PC as well
6830 as the current one to catch cases when we have just
6831 single-stepped off a breakpoint prior to reinstating it.
6832 Note that we're assuming that the code we single-step to is
6833 not inline, but that's not definitive: there's nothing
6834 preventing the event breakpoint function from containing
6835 inlined code, and the single-step ending up there. If the
6836 user had set a breakpoint on that inlined code, the missing
6837 skip_inline_frames call would break things. Fortunately
6838 that's an extremely unlikely scenario. */
6839 if (!pc_at_non_inline_function (aspace
,
6840 ecs
->event_thread
->stop_pc (),
6842 && !(ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6843 && ecs
->event_thread
->control
.trap_expected
6844 && pc_at_non_inline_function (aspace
,
6845 ecs
->event_thread
->prev_pc
,
6848 stop_chain
= build_bpstat_chain (aspace
,
6849 ecs
->event_thread
->stop_pc (),
6851 skip_inline_frames (ecs
->event_thread
, stop_chain
);
6853 /* Re-fetch current thread's frame in case that invalidated
6855 frame
= get_current_frame ();
6856 gdbarch
= get_frame_arch (frame
);
6860 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6861 && ecs
->event_thread
->control
.trap_expected
6862 && gdbarch_single_step_through_delay_p (gdbarch
)
6863 && currently_stepping (ecs
->event_thread
))
6865 /* We're trying to step off a breakpoint. Turns out that we're
6866 also on an instruction that needs to be stepped multiple
6867 times before it's been fully executing. E.g., architectures
6868 with a delay slot. It needs to be stepped twice, once for
6869 the instruction and once for the delay slot. */
6870 int step_through_delay
6871 = gdbarch_single_step_through_delay (gdbarch
, frame
);
6873 if (step_through_delay
)
6874 infrun_debug_printf ("step through delay");
6876 if (ecs
->event_thread
->control
.step_range_end
== 0
6877 && step_through_delay
)
6879 /* The user issued a continue when stopped at a breakpoint.
6880 Set up for another trap and get out of here. */
6881 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6885 else if (step_through_delay
)
6887 /* The user issued a step when stopped at a breakpoint.
6888 Maybe we should stop, maybe we should not - the delay
6889 slot *might* correspond to a line of source. In any
6890 case, don't decide that here, just set
6891 ecs->stepping_over_breakpoint, making sure we
6892 single-step again before breakpoints are re-inserted. */
6893 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6897 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
6898 handles this event. */
6899 ecs
->event_thread
->control
.stop_bpstat
6900 = bpstat_stop_status (get_current_regcache ()->aspace (),
6901 ecs
->event_thread
->stop_pc (),
6902 ecs
->event_thread
, ecs
->ws
, stop_chain
);
6904 /* Following in case break condition called a
6906 stop_print_frame
= true;
6908 /* This is where we handle "moribund" watchpoints. Unlike
6909 software breakpoints traps, hardware watchpoint traps are
6910 always distinguishable from random traps. If no high-level
6911 watchpoint is associated with the reported stop data address
6912 anymore, then the bpstat does not explain the signal ---
6913 simply make sure to ignore it if `stopped_by_watchpoint' is
6916 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6917 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6919 && stopped_by_watchpoint
)
6921 infrun_debug_printf ("no user watchpoint explains watchpoint SIGTRAP, "
6925 /* NOTE: cagney/2003-03-29: These checks for a random signal
6926 at one stage in the past included checks for an inferior
6927 function call's call dummy's return breakpoint. The original
6928 comment, that went with the test, read:
6930 ``End of a stack dummy. Some systems (e.g. Sony news) give
6931 another signal besides SIGTRAP, so check here as well as
6934 If someone ever tries to get call dummys on a
6935 non-executable stack to work (where the target would stop
6936 with something like a SIGSEGV), then those tests might need
6937 to be re-instated. Given, however, that the tests were only
6938 enabled when momentary breakpoints were not being used, I
6939 suspect that it won't be the case.
6941 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
6942 be necessary for call dummies on a non-executable stack on
6945 /* See if the breakpoints module can explain the signal. */
6947 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6948 ecs
->event_thread
->stop_signal ());
6950 /* Maybe this was a trap for a software breakpoint that has since
6952 if (random_signal
&& target_stopped_by_sw_breakpoint ())
6954 if (gdbarch_program_breakpoint_here_p (gdbarch
,
6955 ecs
->event_thread
->stop_pc ()))
6957 struct regcache
*regcache
;
6960 /* Re-adjust PC to what the program would see if GDB was not
6962 regcache
= get_thread_regcache (ecs
->event_thread
);
6963 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
6966 gdb::optional
<scoped_restore_tmpl
<int>>
6967 restore_operation_disable
;
6969 if (record_full_is_used ())
6970 restore_operation_disable
.emplace
6971 (record_full_gdb_operation_disable_set ());
6973 regcache_write_pc (regcache
,
6974 ecs
->event_thread
->stop_pc () + decr_pc
);
6979 /* A delayed software breakpoint event. Ignore the trap. */
6980 infrun_debug_printf ("delayed software breakpoint trap, ignoring");
6985 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
6986 has since been removed. */
6987 if (random_signal
&& target_stopped_by_hw_breakpoint ())
6989 /* A delayed hardware breakpoint event. Ignore the trap. */
6990 infrun_debug_printf ("delayed hardware breakpoint/watchpoint "
6995 /* If not, perhaps stepping/nexting can. */
6997 random_signal
= !(ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6998 && currently_stepping (ecs
->event_thread
));
7000 /* Perhaps the thread hit a single-step breakpoint of _another_
7001 thread. Single-step breakpoints are transparent to the
7002 breakpoints module. */
7004 random_signal
= !ecs
->hit_singlestep_breakpoint
;
7006 /* No? Perhaps we got a moribund watchpoint. */
7008 random_signal
= !stopped_by_watchpoint
;
7010 /* Always stop if the user explicitly requested this thread to
7012 if (ecs
->event_thread
->stop_requested
)
7015 infrun_debug_printf ("user-requested stop");
7018 /* For the program's own signals, act according to
7019 the signal handling tables. */
7023 /* Signal not for debugging purposes. */
7024 enum gdb_signal stop_signal
= ecs
->event_thread
->stop_signal ();
7026 infrun_debug_printf ("random signal (%s)",
7027 gdb_signal_to_symbol_string (stop_signal
));
7029 stopped_by_random_signal
= 1;
7031 /* Always stop on signals if we're either just gaining control
7032 of the program, or the user explicitly requested this thread
7033 to remain stopped. */
7034 if (stop_soon
!= NO_STOP_QUIETLY
7035 || ecs
->event_thread
->stop_requested
7036 || signal_stop_state (ecs
->event_thread
->stop_signal ()))
7042 /* Notify observers the signal has "handle print" set. Note we
7043 returned early above if stopping; normal_stop handles the
7044 printing in that case. */
7045 if (signal_print
[ecs
->event_thread
->stop_signal ()])
7047 /* The signal table tells us to print about this signal. */
7048 target_terminal::ours_for_output ();
7049 notify_signal_received (ecs
->event_thread
->stop_signal ());
7050 target_terminal::inferior ();
7053 /* Clear the signal if it should not be passed. */
7054 if (signal_program
[ecs
->event_thread
->stop_signal ()] == 0)
7055 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
7057 if (ecs
->event_thread
->prev_pc
== ecs
->event_thread
->stop_pc ()
7058 && ecs
->event_thread
->control
.trap_expected
7059 && ecs
->event_thread
->control
.step_resume_breakpoint
== nullptr)
7061 /* We were just starting a new sequence, attempting to
7062 single-step off of a breakpoint and expecting a SIGTRAP.
7063 Instead this signal arrives. This signal will take us out
7064 of the stepping range so GDB needs to remember to, when
7065 the signal handler returns, resume stepping off that
7067 /* To simplify things, "continue" is forced to use the same
7068 code paths as single-step - set a breakpoint at the
7069 signal return address and then, once hit, step off that
7071 infrun_debug_printf ("signal arrived while stepping over breakpoint");
7073 insert_hp_step_resume_breakpoint_at_frame (frame
);
7074 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
7075 /* Reset trap_expected to ensure breakpoints are re-inserted. */
7076 ecs
->event_thread
->control
.trap_expected
= 0;
7078 /* If we were nexting/stepping some other thread, switch to
7079 it, so that we don't continue it, losing control. */
7080 if (!switch_back_to_stepped_thread (ecs
))
7085 if (ecs
->event_thread
->stop_signal () != GDB_SIGNAL_0
7086 && (pc_in_thread_step_range (ecs
->event_thread
->stop_pc (),
7088 || ecs
->event_thread
->control
.step_range_end
== 1)
7089 && (get_stack_frame_id (frame
)
7090 == ecs
->event_thread
->control
.step_stack_frame_id
)
7091 && ecs
->event_thread
->control
.step_resume_breakpoint
== nullptr)
7093 /* The inferior is about to take a signal that will take it
7094 out of the single step range. Set a breakpoint at the
7095 current PC (which is presumably where the signal handler
7096 will eventually return) and then allow the inferior to
7099 Note that this is only needed for a signal delivered
7100 while in the single-step range. Nested signals aren't a
7101 problem as they eventually all return. */
7102 infrun_debug_printf ("signal may take us out of single-step range");
7104 clear_step_over_info ();
7105 insert_hp_step_resume_breakpoint_at_frame (frame
);
7106 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
7107 /* Reset trap_expected to ensure breakpoints are re-inserted. */
7108 ecs
->event_thread
->control
.trap_expected
= 0;
7113 /* Note: step_resume_breakpoint may be non-NULL. This occurs
7114 when either there's a nested signal, or when there's a
7115 pending signal enabled just as the signal handler returns
7116 (leaving the inferior at the step-resume-breakpoint without
7117 actually executing it). Either way continue until the
7118 breakpoint is really hit. */
7120 if (!switch_back_to_stepped_thread (ecs
))
7122 infrun_debug_printf ("random signal, keep going");
7129 process_event_stop_test (ecs
);
7132 /* Come here when we've got some debug event / signal we can explain
7133 (IOW, not a random signal), and test whether it should cause a
7134 stop, or whether we should resume the inferior (transparently).
7135 E.g., could be a breakpoint whose condition evaluates false; we
7136 could be still stepping within the line; etc. */
7139 process_event_stop_test (struct execution_control_state
*ecs
)
7141 struct symtab_and_line stop_pc_sal
;
7142 frame_info_ptr frame
;
7143 struct gdbarch
*gdbarch
;
7144 CORE_ADDR jmp_buf_pc
;
7145 struct bpstat_what what
;
7147 /* Handle cases caused by hitting a breakpoint. */
7149 frame
= get_current_frame ();
7150 gdbarch
= get_frame_arch (frame
);
7152 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
7154 if (what
.call_dummy
)
7156 stop_stack_dummy
= what
.call_dummy
;
7159 /* A few breakpoint types have callbacks associated (e.g.,
7160 bp_jit_event). Run them now. */
7161 bpstat_run_callbacks (ecs
->event_thread
->control
.stop_bpstat
);
7163 /* If we hit an internal event that triggers symbol changes, the
7164 current frame will be invalidated within bpstat_what (e.g., if we
7165 hit an internal solib event). Re-fetch it. */
7166 frame
= get_current_frame ();
7167 gdbarch
= get_frame_arch (frame
);
7169 switch (what
.main_action
)
7171 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
7172 /* If we hit the breakpoint at longjmp while stepping, we
7173 install a momentary breakpoint at the target of the
7176 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME");
7178 ecs
->event_thread
->stepping_over_breakpoint
= 1;
7180 if (what
.is_longjmp
)
7182 struct value
*arg_value
;
7184 /* If we set the longjmp breakpoint via a SystemTap probe,
7185 then use it to extract the arguments. The destination PC
7186 is the third argument to the probe. */
7187 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
7190 jmp_buf_pc
= value_as_address (arg_value
);
7191 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
7193 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
7194 || !gdbarch_get_longjmp_target (gdbarch
,
7195 frame
, &jmp_buf_pc
))
7197 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME "
7198 "(!gdbarch_get_longjmp_target)");
7203 /* Insert a breakpoint at resume address. */
7204 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
7207 check_exception_resume (ecs
, frame
);
7211 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
7213 frame_info_ptr init_frame
;
7215 /* There are several cases to consider.
7217 1. The initiating frame no longer exists. In this case we
7218 must stop, because the exception or longjmp has gone too
7221 2. The initiating frame exists, and is the same as the
7222 current frame. We stop, because the exception or longjmp
7225 3. The initiating frame exists and is different from the
7226 current frame. This means the exception or longjmp has
7227 been caught beneath the initiating frame, so keep going.
7229 4. longjmp breakpoint has been placed just to protect
7230 against stale dummy frames and user is not interested in
7231 stopping around longjmps. */
7233 infrun_debug_printf ("BPSTAT_WHAT_CLEAR_LONGJMP_RESUME");
7235 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
7237 delete_exception_resume_breakpoint (ecs
->event_thread
);
7239 if (what
.is_longjmp
)
7241 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
7243 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
7251 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
7255 struct frame_id current_id
7256 = get_frame_id (get_current_frame ());
7257 if (current_id
== ecs
->event_thread
->initiating_frame
)
7259 /* Case 2. Fall through. */
7269 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
7271 delete_step_resume_breakpoint (ecs
->event_thread
);
7273 end_stepping_range (ecs
);
7277 case BPSTAT_WHAT_SINGLE
:
7278 infrun_debug_printf ("BPSTAT_WHAT_SINGLE");
7279 ecs
->event_thread
->stepping_over_breakpoint
= 1;
7280 /* Still need to check other stuff, at least the case where we
7281 are stepping and step out of the right range. */
7284 case BPSTAT_WHAT_STEP_RESUME
:
7285 infrun_debug_printf ("BPSTAT_WHAT_STEP_RESUME");
7287 delete_step_resume_breakpoint (ecs
->event_thread
);
7288 if (ecs
->event_thread
->control
.proceed_to_finish
7289 && execution_direction
== EXEC_REVERSE
)
7291 struct thread_info
*tp
= ecs
->event_thread
;
7293 /* We are finishing a function in reverse, and just hit the
7294 step-resume breakpoint at the start address of the
7295 function, and we're almost there -- just need to back up
7296 by one more single-step, which should take us back to the
7298 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
7302 fill_in_stop_func (gdbarch
, ecs
);
7303 if (ecs
->event_thread
->stop_pc () == ecs
->stop_func_start
7304 && execution_direction
== EXEC_REVERSE
)
7306 /* We are stepping over a function call in reverse, and just
7307 hit the step-resume breakpoint at the start address of
7308 the function. Go back to single-stepping, which should
7309 take us back to the function call. */
7310 ecs
->event_thread
->stepping_over_breakpoint
= 1;
7316 case BPSTAT_WHAT_STOP_NOISY
:
7317 infrun_debug_printf ("BPSTAT_WHAT_STOP_NOISY");
7318 stop_print_frame
= true;
7320 /* Assume the thread stopped for a breakpoint. We'll still check
7321 whether a/the breakpoint is there when the thread is next
7323 ecs
->event_thread
->stepping_over_breakpoint
= 1;
7328 case BPSTAT_WHAT_STOP_SILENT
:
7329 infrun_debug_printf ("BPSTAT_WHAT_STOP_SILENT");
7330 stop_print_frame
= false;
7332 /* Assume the thread stopped for a breakpoint. We'll still check
7333 whether a/the breakpoint is there when the thread is next
7335 ecs
->event_thread
->stepping_over_breakpoint
= 1;
7339 case BPSTAT_WHAT_HP_STEP_RESUME
:
7340 infrun_debug_printf ("BPSTAT_WHAT_HP_STEP_RESUME");
7342 delete_step_resume_breakpoint (ecs
->event_thread
);
7343 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
7345 /* Back when the step-resume breakpoint was inserted, we
7346 were trying to single-step off a breakpoint. Go back to
7348 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
7349 ecs
->event_thread
->stepping_over_breakpoint
= 1;
7355 case BPSTAT_WHAT_KEEP_CHECKING
:
7359 /* If we stepped a permanent breakpoint and we had a high priority
7360 step-resume breakpoint for the address we stepped, but we didn't
7361 hit it, then we must have stepped into the signal handler. The
7362 step-resume was only necessary to catch the case of _not_
7363 stepping into the handler, so delete it, and fall through to
7364 checking whether the step finished. */
7365 if (ecs
->event_thread
->stepped_breakpoint
)
7367 struct breakpoint
*sr_bp
7368 = ecs
->event_thread
->control
.step_resume_breakpoint
;
7370 if (sr_bp
!= nullptr
7371 && sr_bp
->first_loc ().permanent
7372 && sr_bp
->type
== bp_hp_step_resume
7373 && sr_bp
->first_loc ().address
== ecs
->event_thread
->prev_pc
)
7375 infrun_debug_printf ("stepped permanent breakpoint, stopped in handler");
7376 delete_step_resume_breakpoint (ecs
->event_thread
);
7377 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
7381 /* We come here if we hit a breakpoint but should not stop for it.
7382 Possibly we also were stepping and should stop for that. So fall
7383 through and test for stepping. But, if not stepping, do not
7386 /* In all-stop mode, if we're currently stepping but have stopped in
7387 some other thread, we need to switch back to the stepped thread. */
7388 if (switch_back_to_stepped_thread (ecs
))
7391 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
7393 infrun_debug_printf ("step-resume breakpoint is inserted");
7395 /* Having a step-resume breakpoint overrides anything
7396 else having to do with stepping commands until
7397 that breakpoint is reached. */
7402 if (ecs
->event_thread
->control
.step_range_end
== 0)
7404 infrun_debug_printf ("no stepping, continue");
7405 /* Likewise if we aren't even stepping. */
7410 /* Re-fetch current thread's frame in case the code above caused
7411 the frame cache to be re-initialized, making our FRAME variable
7412 a dangling pointer. */
7413 frame
= get_current_frame ();
7414 gdbarch
= get_frame_arch (frame
);
7415 fill_in_stop_func (gdbarch
, ecs
);
7417 /* If stepping through a line, keep going if still within it.
7419 Note that step_range_end is the address of the first instruction
7420 beyond the step range, and NOT the address of the last instruction
7423 Note also that during reverse execution, we may be stepping
7424 through a function epilogue and therefore must detect when
7425 the current-frame changes in the middle of a line. */
7427 if (pc_in_thread_step_range (ecs
->event_thread
->stop_pc (),
7429 && (execution_direction
!= EXEC_REVERSE
7430 || get_frame_id (frame
) == ecs
->event_thread
->control
.step_frame_id
))
7433 ("stepping inside range [%s-%s]",
7434 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
7435 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
7437 /* Tentatively re-enable range stepping; `resume' disables it if
7438 necessary (e.g., if we're stepping over a breakpoint or we
7439 have software watchpoints). */
7440 ecs
->event_thread
->control
.may_range_step
= 1;
7442 /* When stepping backward, stop at beginning of line range
7443 (unless it's the function entry point, in which case
7444 keep going back to the call point). */
7445 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7446 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
7447 && stop_pc
!= ecs
->stop_func_start
7448 && execution_direction
== EXEC_REVERSE
)
7449 end_stepping_range (ecs
);
7456 /* We stepped out of the stepping range. */
7458 /* If we are stepping at the source level and entered the runtime
7459 loader dynamic symbol resolution code...
7461 EXEC_FORWARD: we keep on single stepping until we exit the run
7462 time loader code and reach the callee's address.
7464 EXEC_REVERSE: we've already executed the callee (backward), and
7465 the runtime loader code is handled just like any other
7466 undebuggable function call. Now we need only keep stepping
7467 backward through the trampoline code, and that's handled further
7468 down, so there is nothing for us to do here. */
7470 if (execution_direction
!= EXEC_REVERSE
7471 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7472 && in_solib_dynsym_resolve_code (ecs
->event_thread
->stop_pc ())
7473 && (ecs
->event_thread
->control
.step_start_function
== nullptr
7474 || !in_solib_dynsym_resolve_code (
7475 ecs
->event_thread
->control
.step_start_function
->value_block ()
7478 CORE_ADDR pc_after_resolver
=
7479 gdbarch_skip_solib_resolver (gdbarch
, ecs
->event_thread
->stop_pc ());
7481 infrun_debug_printf ("stepped into dynsym resolve code");
7483 if (pc_after_resolver
)
7485 /* Set up a step-resume breakpoint at the address
7486 indicated by SKIP_SOLIB_RESOLVER. */
7487 symtab_and_line sr_sal
;
7488 sr_sal
.pc
= pc_after_resolver
;
7489 sr_sal
.pspace
= get_frame_program_space (frame
);
7491 insert_step_resume_breakpoint_at_sal (gdbarch
,
7492 sr_sal
, null_frame_id
);
7499 /* Step through an indirect branch thunk. */
7500 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7501 && gdbarch_in_indirect_branch_thunk (gdbarch
,
7502 ecs
->event_thread
->stop_pc ()))
7504 infrun_debug_printf ("stepped into indirect branch thunk");
7509 if (ecs
->event_thread
->control
.step_range_end
!= 1
7510 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7511 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7512 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
7514 infrun_debug_printf ("stepped into signal trampoline");
7515 /* The inferior, while doing a "step" or "next", has ended up in
7516 a signal trampoline (either by a signal being delivered or by
7517 the signal handler returning). Just single-step until the
7518 inferior leaves the trampoline (either by calling the handler
7524 /* If we're in the return path from a shared library trampoline,
7525 we want to proceed through the trampoline when stepping. */
7526 /* macro/2012-04-25: This needs to come before the subroutine
7527 call check below as on some targets return trampolines look
7528 like subroutine calls (MIPS16 return thunks). */
7529 if (gdbarch_in_solib_return_trampoline (gdbarch
,
7530 ecs
->event_thread
->stop_pc (),
7531 ecs
->stop_func_name
)
7532 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7534 /* Determine where this trampoline returns. */
7535 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7536 CORE_ADDR real_stop_pc
7537 = gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7539 infrun_debug_printf ("stepped into solib return tramp");
7541 /* Only proceed through if we know where it's going. */
7544 /* And put the step-breakpoint there and go until there. */
7545 symtab_and_line sr_sal
;
7546 sr_sal
.pc
= real_stop_pc
;
7547 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7548 sr_sal
.pspace
= get_frame_program_space (frame
);
7550 /* Do not specify what the fp should be when we stop since
7551 on some machines the prologue is where the new fp value
7553 insert_step_resume_breakpoint_at_sal (gdbarch
,
7554 sr_sal
, null_frame_id
);
7556 /* Restart without fiddling with the step ranges or
7563 /* Check for subroutine calls. The check for the current frame
7564 equalling the step ID is not necessary - the check of the
7565 previous frame's ID is sufficient - but it is a common case and
7566 cheaper than checking the previous frame's ID.
7568 NOTE: frame_id::operator== will never report two invalid frame IDs as
7569 being equal, so to get into this block, both the current and
7570 previous frame must have valid frame IDs. */
7571 /* The outer_frame_id check is a heuristic to detect stepping
7572 through startup code. If we step over an instruction which
7573 sets the stack pointer from an invalid value to a valid value,
7574 we may detect that as a subroutine call from the mythical
7575 "outermost" function. This could be fixed by marking
7576 outermost frames as !stack_p,code_p,special_p. Then the
7577 initial outermost frame, before sp was valid, would
7578 have code_addr == &_start. See the comment in frame_id::operator==
7581 /* We want "nexti" to step into, not over, signal handlers invoked
7582 by the kernel, therefore this subroutine check should not trigger
7583 for a signal handler invocation. On most platforms, this is already
7584 not the case, as the kernel puts a signal trampoline frame onto the
7585 stack to handle proper return after the handler, and therefore at this
7586 point, the current frame is a grandchild of the step frame, not a
7587 child. However, on some platforms, the kernel actually uses a
7588 trampoline to handle *invocation* of the handler. In that case,
7589 when executing the first instruction of the trampoline, this check
7590 would erroneously detect the trampoline invocation as a subroutine
7591 call. Fix this by checking for SIGTRAMP_FRAME. */
7592 if ((get_stack_frame_id (frame
)
7593 != ecs
->event_thread
->control
.step_stack_frame_id
)
7594 && get_frame_type (frame
) != SIGTRAMP_FRAME
7595 && ((frame_unwind_caller_id (get_current_frame ())
7596 == ecs
->event_thread
->control
.step_stack_frame_id
)
7597 && ((ecs
->event_thread
->control
.step_stack_frame_id
7599 || (ecs
->event_thread
->control
.step_start_function
7600 != find_pc_function (ecs
->event_thread
->stop_pc ())))))
7602 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7603 CORE_ADDR real_stop_pc
;
7605 infrun_debug_printf ("stepped into subroutine");
7607 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
7609 /* I presume that step_over_calls is only 0 when we're
7610 supposed to be stepping at the assembly language level
7611 ("stepi"). Just stop. */
7612 /* And this works the same backward as frontward. MVS */
7613 end_stepping_range (ecs
);
7617 /* Reverse stepping through solib trampolines. */
7619 if (execution_direction
== EXEC_REVERSE
7620 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7621 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7622 || (ecs
->stop_func_start
== 0
7623 && in_solib_dynsym_resolve_code (stop_pc
))))
7625 /* Any solib trampoline code can be handled in reverse
7626 by simply continuing to single-step. We have already
7627 executed the solib function (backwards), and a few
7628 steps will take us back through the trampoline to the
7634 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7636 /* We're doing a "next".
7638 Normal (forward) execution: set a breakpoint at the
7639 callee's return address (the address at which the caller
7642 Reverse (backward) execution. set the step-resume
7643 breakpoint at the start of the function that we just
7644 stepped into (backwards), and continue to there. When we
7645 get there, we'll need to single-step back to the caller. */
7647 if (execution_direction
== EXEC_REVERSE
)
7649 /* If we're already at the start of the function, we've either
7650 just stepped backward into a single instruction function,
7651 or stepped back out of a signal handler to the first instruction
7652 of the function. Just keep going, which will single-step back
7654 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
7656 /* Normal function call return (static or dynamic). */
7657 symtab_and_line sr_sal
;
7658 sr_sal
.pc
= ecs
->stop_func_start
;
7659 sr_sal
.pspace
= get_frame_program_space (frame
);
7660 insert_step_resume_breakpoint_at_sal (gdbarch
,
7661 sr_sal
, get_stack_frame_id (frame
));
7665 insert_step_resume_breakpoint_at_caller (frame
);
7671 /* If we are in a function call trampoline (a stub between the
7672 calling routine and the real function), locate the real
7673 function. That's what tells us (a) whether we want to step
7674 into it at all, and (b) what prologue we want to run to the
7675 end of, if we do step into it. */
7676 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
7677 if (real_stop_pc
== 0)
7678 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7679 if (real_stop_pc
!= 0)
7680 ecs
->stop_func_start
= real_stop_pc
;
7682 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
7684 symtab_and_line sr_sal
;
7685 sr_sal
.pc
= ecs
->stop_func_start
;
7686 sr_sal
.pspace
= get_frame_program_space (frame
);
7688 insert_step_resume_breakpoint_at_sal (gdbarch
,
7689 sr_sal
, null_frame_id
);
7694 /* If we have line number information for the function we are
7695 thinking of stepping into and the function isn't on the skip
7698 If there are several symtabs at that PC (e.g. with include
7699 files), just want to know whether *any* of them have line
7700 numbers. find_pc_line handles this. */
7702 struct symtab_and_line tmp_sal
;
7704 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7705 if (tmp_sal
.line
!= 0
7706 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
7708 && !inline_frame_is_marked_for_skip (true, ecs
->event_thread
))
7710 if (execution_direction
== EXEC_REVERSE
)
7711 handle_step_into_function_backward (gdbarch
, ecs
);
7713 handle_step_into_function (gdbarch
, ecs
);
7718 /* If we have no line number and the step-stop-if-no-debug is
7719 set, we stop the step so that the user has a chance to switch
7720 in assembly mode. */
7721 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7722 && step_stop_if_no_debug
)
7724 end_stepping_range (ecs
);
7728 if (execution_direction
== EXEC_REVERSE
)
7730 /* If we're already at the start of the function, we've either just
7731 stepped backward into a single instruction function without line
7732 number info, or stepped back out of a signal handler to the first
7733 instruction of the function without line number info. Just keep
7734 going, which will single-step back to the caller. */
7735 if (ecs
->stop_func_start
!= stop_pc
)
7737 /* Set a breakpoint at callee's start address.
7738 From there we can step once and be back in the caller. */
7739 symtab_and_line sr_sal
;
7740 sr_sal
.pc
= ecs
->stop_func_start
;
7741 sr_sal
.pspace
= get_frame_program_space (frame
);
7742 insert_step_resume_breakpoint_at_sal (gdbarch
,
7743 sr_sal
, null_frame_id
);
7747 /* Set a breakpoint at callee's return address (the address
7748 at which the caller will resume). */
7749 insert_step_resume_breakpoint_at_caller (frame
);
7755 /* Reverse stepping through solib trampolines. */
7757 if (execution_direction
== EXEC_REVERSE
7758 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7760 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7762 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7763 || (ecs
->stop_func_start
== 0
7764 && in_solib_dynsym_resolve_code (stop_pc
)))
7766 /* Any solib trampoline code can be handled in reverse
7767 by simply continuing to single-step. We have already
7768 executed the solib function (backwards), and a few
7769 steps will take us back through the trampoline to the
7774 else if (in_solib_dynsym_resolve_code (stop_pc
))
7776 /* Stepped backward into the solib dynsym resolver.
7777 Set a breakpoint at its start and continue, then
7778 one more step will take us out. */
7779 symtab_and_line sr_sal
;
7780 sr_sal
.pc
= ecs
->stop_func_start
;
7781 sr_sal
.pspace
= get_frame_program_space (frame
);
7782 insert_step_resume_breakpoint_at_sal (gdbarch
,
7783 sr_sal
, null_frame_id
);
7789 /* This always returns the sal for the inner-most frame when we are in a
7790 stack of inlined frames, even if GDB actually believes that it is in a
7791 more outer frame. This is checked for below by calls to
7792 inline_skipped_frames. */
7793 stop_pc_sal
= find_pc_line (ecs
->event_thread
->stop_pc (), 0);
7795 /* NOTE: tausq/2004-05-24: This if block used to be done before all
7796 the trampoline processing logic, however, there are some trampolines
7797 that have no names, so we should do trampoline handling first. */
7798 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7799 && ecs
->stop_func_name
== nullptr
7800 && stop_pc_sal
.line
== 0)
7802 infrun_debug_printf ("stepped into undebuggable function");
7804 /* The inferior just stepped into, or returned to, an
7805 undebuggable function (where there is no debugging information
7806 and no line number corresponding to the address where the
7807 inferior stopped). Since we want to skip this kind of code,
7808 we keep going until the inferior returns from this
7809 function - unless the user has asked us not to (via
7810 set step-mode) or we no longer know how to get back
7811 to the call site. */
7812 if (step_stop_if_no_debug
7813 || !frame_id_p (frame_unwind_caller_id (frame
)))
7815 /* If we have no line number and the step-stop-if-no-debug
7816 is set, we stop the step so that the user has a chance to
7817 switch in assembly mode. */
7818 end_stepping_range (ecs
);
7823 /* Set a breakpoint at callee's return address (the address
7824 at which the caller will resume). */
7825 insert_step_resume_breakpoint_at_caller (frame
);
7831 if (execution_direction
== EXEC_REVERSE
7832 && ecs
->event_thread
->control
.proceed_to_finish
7833 && ecs
->event_thread
->stop_pc () >= ecs
->stop_func_alt_start
7834 && ecs
->event_thread
->stop_pc () < ecs
->stop_func_start
)
7836 /* We are executing the reverse-finish command.
7837 If the system supports multiple entry points and we are finishing a
7838 function in reverse. If we are between the entry points single-step
7839 back to the alternate entry point. If we are at the alternate entry
7840 point -- just need to back up by one more single-step, which
7841 should take us back to the function call. */
7842 ecs
->event_thread
->control
.step_range_start
7843 = ecs
->event_thread
->control
.step_range_end
= 1;
7849 if (ecs
->event_thread
->control
.step_range_end
== 1)
7851 /* It is stepi or nexti. We always want to stop stepping after
7853 infrun_debug_printf ("stepi/nexti");
7854 end_stepping_range (ecs
);
7858 if (stop_pc_sal
.line
== 0)
7860 /* We have no line number information. That means to stop
7861 stepping (does this always happen right after one instruction,
7862 when we do "s" in a function with no line numbers,
7863 or can this happen as a result of a return or longjmp?). */
7864 infrun_debug_printf ("line number info");
7865 end_stepping_range (ecs
);
7869 /* Look for "calls" to inlined functions, part one. If the inline
7870 frame machinery detected some skipped call sites, we have entered
7871 a new inline function. */
7873 if ((get_frame_id (get_current_frame ())
7874 == ecs
->event_thread
->control
.step_frame_id
)
7875 && inline_skipped_frames (ecs
->event_thread
))
7877 infrun_debug_printf ("stepped into inlined function");
7879 symtab_and_line call_sal
= find_frame_sal (get_current_frame ());
7881 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
7883 /* For "step", we're going to stop. But if the call site
7884 for this inlined function is on the same source line as
7885 we were previously stepping, go down into the function
7886 first. Otherwise stop at the call site. */
7888 if (call_sal
.line
== ecs
->event_thread
->current_line
7889 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7891 step_into_inline_frame (ecs
->event_thread
);
7892 if (inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7899 end_stepping_range (ecs
);
7904 /* For "next", we should stop at the call site if it is on a
7905 different source line. Otherwise continue through the
7906 inlined function. */
7907 if (call_sal
.line
== ecs
->event_thread
->current_line
7908 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7911 end_stepping_range (ecs
);
7916 /* Look for "calls" to inlined functions, part two. If we are still
7917 in the same real function we were stepping through, but we have
7918 to go further up to find the exact frame ID, we are stepping
7919 through a more inlined call beyond its call site. */
7921 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
7922 && (get_frame_id (get_current_frame ())
7923 != ecs
->event_thread
->control
.step_frame_id
)
7924 && stepped_in_from (get_current_frame (),
7925 ecs
->event_thread
->control
.step_frame_id
))
7927 infrun_debug_printf ("stepping through inlined function");
7929 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
7930 || inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7933 end_stepping_range (ecs
);
7937 bool refresh_step_info
= true;
7938 if ((ecs
->event_thread
->stop_pc () == stop_pc_sal
.pc
)
7939 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
7940 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
7942 /* We are at a different line. */
7944 if (stop_pc_sal
.is_stmt
)
7946 /* We are at the start of a statement.
7948 So stop. Note that we don't stop if we step into the middle of a
7949 statement. That is said to make things like for (;;) statements
7951 infrun_debug_printf ("stepped to a different line");
7952 end_stepping_range (ecs
);
7955 else if (get_frame_id (get_current_frame ())
7956 == ecs
->event_thread
->control
.step_frame_id
)
7958 /* We are not at the start of a statement, and we have not changed
7961 We ignore this line table entry, and continue stepping forward,
7962 looking for a better place to stop. */
7963 refresh_step_info
= false;
7964 infrun_debug_printf ("stepped to a different line, but "
7965 "it's not the start of a statement");
7969 /* We are not the start of a statement, and we have changed frame.
7971 We ignore this line table entry, and continue stepping forward,
7972 looking for a better place to stop. Keep refresh_step_info at
7973 true to note that the frame has changed, but ignore the line
7974 number to make sure we don't ignore a subsequent entry with the
7975 same line number. */
7976 stop_pc_sal
.line
= 0;
7977 infrun_debug_printf ("stepped to a different frame, but "
7978 "it's not the start of a statement");
7982 /* We aren't done stepping.
7984 Optimize by setting the stepping range to the line.
7985 (We might not be in the original line, but if we entered a
7986 new line in mid-statement, we continue stepping. This makes
7987 things like for(;;) statements work better.)
7989 If we entered a SAL that indicates a non-statement line table entry,
7990 then we update the stepping range, but we don't update the step info,
7991 which includes things like the line number we are stepping away from.
7992 This means we will stop when we find a line table entry that is marked
7993 as is-statement, even if it matches the non-statement one we just
7996 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
7997 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
7998 ecs
->event_thread
->control
.may_range_step
= 1;
8000 ("updated step range, start = %s, end = %s, may_range_step = %d",
8001 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
8002 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
),
8003 ecs
->event_thread
->control
.may_range_step
);
8004 if (refresh_step_info
)
8005 set_step_info (ecs
->event_thread
, frame
, stop_pc_sal
);
8007 infrun_debug_printf ("keep going");
8011 static bool restart_stepped_thread (process_stratum_target
*resume_target
,
8012 ptid_t resume_ptid
);
8014 /* In all-stop mode, if we're currently stepping but have stopped in
8015 some other thread, we may need to switch back to the stepped
8016 thread. Returns true we set the inferior running, false if we left
8017 it stopped (and the event needs further processing). */
8020 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
8022 if (!target_is_non_stop_p ())
8024 /* If any thread is blocked on some internal breakpoint, and we
8025 simply need to step over that breakpoint to get it going
8026 again, do that first. */
8028 /* However, if we see an event for the stepping thread, then we
8029 know all other threads have been moved past their breakpoints
8030 already. Let the caller check whether the step is finished,
8031 etc., before deciding to move it past a breakpoint. */
8032 if (ecs
->event_thread
->control
.step_range_end
!= 0)
8035 /* Check if the current thread is blocked on an incomplete
8036 step-over, interrupted by a random signal. */
8037 if (ecs
->event_thread
->control
.trap_expected
8038 && ecs
->event_thread
->stop_signal () != GDB_SIGNAL_TRAP
)
8041 ("need to finish step-over of [%s]",
8042 ecs
->event_thread
->ptid
.to_string ().c_str ());
8047 /* Check if the current thread is blocked by a single-step
8048 breakpoint of another thread. */
8049 if (ecs
->hit_singlestep_breakpoint
)
8051 infrun_debug_printf ("need to step [%s] over single-step breakpoint",
8052 ecs
->ptid
.to_string ().c_str ());
8057 /* If this thread needs yet another step-over (e.g., stepping
8058 through a delay slot), do it first before moving on to
8060 if (thread_still_needs_step_over (ecs
->event_thread
))
8063 ("thread [%s] still needs step-over",
8064 ecs
->event_thread
->ptid
.to_string ().c_str ());
8069 /* If scheduler locking applies even if not stepping, there's no
8070 need to walk over threads. Above we've checked whether the
8071 current thread is stepping. If some other thread not the
8072 event thread is stepping, then it must be that scheduler
8073 locking is not in effect. */
8074 if (schedlock_applies (ecs
->event_thread
))
8077 /* Otherwise, we no longer expect a trap in the current thread.
8078 Clear the trap_expected flag before switching back -- this is
8079 what keep_going does as well, if we call it. */
8080 ecs
->event_thread
->control
.trap_expected
= 0;
8082 /* Likewise, clear the signal if it should not be passed. */
8083 if (!signal_program
[ecs
->event_thread
->stop_signal ()])
8084 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
8086 if (restart_stepped_thread (ecs
->target
, ecs
->ptid
))
8088 prepare_to_wait (ecs
);
8092 switch_to_thread (ecs
->event_thread
);
8098 /* Look for the thread that was stepping, and resume it.
8099 RESUME_TARGET / RESUME_PTID indicate the set of threads the caller
8100 is resuming. Return true if a thread was started, false
8104 restart_stepped_thread (process_stratum_target
*resume_target
,
8107 /* Do all pending step-overs before actually proceeding with
8109 if (start_step_over ())
8112 for (thread_info
*tp
: all_threads_safe ())
8114 if (tp
->state
== THREAD_EXITED
)
8117 if (tp
->has_pending_waitstatus ())
8120 /* Ignore threads of processes the caller is not
8123 && (tp
->inf
->process_target () != resume_target
8124 || tp
->inf
->pid
!= resume_ptid
.pid ()))
8127 if (tp
->control
.trap_expected
)
8129 infrun_debug_printf ("switching back to stepped thread (step-over)");
8131 if (keep_going_stepped_thread (tp
))
8136 for (thread_info
*tp
: all_threads_safe ())
8138 if (tp
->state
== THREAD_EXITED
)
8141 if (tp
->has_pending_waitstatus ())
8144 /* Ignore threads of processes the caller is not
8147 && (tp
->inf
->process_target () != resume_target
8148 || tp
->inf
->pid
!= resume_ptid
.pid ()))
8151 /* Did we find the stepping thread? */
8152 if (tp
->control
.step_range_end
)
8154 infrun_debug_printf ("switching back to stepped thread (stepping)");
8156 if (keep_going_stepped_thread (tp
))
8167 restart_after_all_stop_detach (process_stratum_target
*proc_target
)
8169 /* Note we don't check target_is_non_stop_p() here, because the
8170 current inferior may no longer have a process_stratum target
8171 pushed, as we just detached. */
8173 /* See if we have a THREAD_RUNNING thread that need to be
8174 re-resumed. If we have any thread that is already executing,
8175 then we don't need to resume the target -- it is already been
8176 resumed. With the remote target (in all-stop), it's even
8177 impossible to issue another resumption if the target is already
8178 resumed, until the target reports a stop. */
8179 for (thread_info
*thr
: all_threads (proc_target
))
8181 if (thr
->state
!= THREAD_RUNNING
)
8184 /* If we have any thread that is already executing, then we
8185 don't need to resume the target -- it is already been
8187 if (thr
->executing ())
8190 /* If we have a pending event to process, skip resuming the
8191 target and go straight to processing it. */
8192 if (thr
->resumed () && thr
->has_pending_waitstatus ())
8196 /* Alright, we need to re-resume the target. If a thread was
8197 stepping, we need to restart it stepping. */
8198 if (restart_stepped_thread (proc_target
, minus_one_ptid
))
8201 /* Otherwise, find the first THREAD_RUNNING thread and resume
8203 for (thread_info
*thr
: all_threads (proc_target
))
8205 if (thr
->state
!= THREAD_RUNNING
)
8208 execution_control_state
ecs (thr
);
8209 switch_to_thread (thr
);
8215 /* Set a previously stepped thread back to stepping. Returns true on
8216 success, false if the resume is not possible (e.g., the thread
8220 keep_going_stepped_thread (struct thread_info
*tp
)
8222 frame_info_ptr frame
;
8224 /* If the stepping thread exited, then don't try to switch back and
8225 resume it, which could fail in several different ways depending
8226 on the target. Instead, just keep going.
8228 We can find a stepping dead thread in the thread list in two
8231 - The target supports thread exit events, and when the target
8232 tries to delete the thread from the thread list, inferior_ptid
8233 pointed at the exiting thread. In such case, calling
8234 delete_thread does not really remove the thread from the list;
8235 instead, the thread is left listed, with 'exited' state.
8237 - The target's debug interface does not support thread exit
8238 events, and so we have no idea whatsoever if the previously
8239 stepping thread is still alive. For that reason, we need to
8240 synchronously query the target now. */
8242 if (tp
->state
== THREAD_EXITED
|| !target_thread_alive (tp
->ptid
))
8244 infrun_debug_printf ("not resuming previously stepped thread, it has "
8251 infrun_debug_printf ("resuming previously stepped thread");
8253 execution_control_state
ecs (tp
);
8254 switch_to_thread (tp
);
8256 tp
->set_stop_pc (regcache_read_pc (get_thread_regcache (tp
)));
8257 frame
= get_current_frame ();
8259 /* If the PC of the thread we were trying to single-step has
8260 changed, then that thread has trapped or been signaled, but the
8261 event has not been reported to GDB yet. Re-poll the target
8262 looking for this particular thread's event (i.e. temporarily
8263 enable schedlock) by:
8265 - setting a break at the current PC
8266 - resuming that particular thread, only (by setting trap
8269 This prevents us continuously moving the single-step breakpoint
8270 forward, one instruction at a time, overstepping. */
8272 if (tp
->stop_pc () != tp
->prev_pc
)
8276 infrun_debug_printf ("expected thread advanced also (%s -> %s)",
8277 paddress (current_inferior ()->arch (), tp
->prev_pc
),
8278 paddress (current_inferior ()->arch (),
8281 /* Clear the info of the previous step-over, as it's no longer
8282 valid (if the thread was trying to step over a breakpoint, it
8283 has already succeeded). It's what keep_going would do too,
8284 if we called it. Do this before trying to insert the sss
8285 breakpoint, otherwise if we were previously trying to step
8286 over this exact address in another thread, the breakpoint is
8288 clear_step_over_info ();
8289 tp
->control
.trap_expected
= 0;
8291 insert_single_step_breakpoint (get_frame_arch (frame
),
8292 get_frame_address_space (frame
),
8295 tp
->set_resumed (true);
8296 resume_ptid
= internal_resume_ptid (tp
->control
.stepping_command
);
8297 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
8301 infrun_debug_printf ("expected thread still hasn't advanced");
8303 keep_going_pass_signal (&ecs
);
8309 /* Is thread TP in the middle of (software or hardware)
8310 single-stepping? (Note the result of this function must never be
8311 passed directly as target_resume's STEP parameter.) */
8314 currently_stepping (struct thread_info
*tp
)
8316 return ((tp
->control
.step_range_end
8317 && tp
->control
.step_resume_breakpoint
== nullptr)
8318 || tp
->control
.trap_expected
8319 || tp
->stepped_breakpoint
8320 || bpstat_should_step ());
8323 /* Inferior has stepped into a subroutine call with source code that
8324 we should not step over. Do step to the first line of code in
8328 handle_step_into_function (struct gdbarch
*gdbarch
,
8329 struct execution_control_state
*ecs
)
8331 fill_in_stop_func (gdbarch
, ecs
);
8333 compunit_symtab
*cust
8334 = find_pc_compunit_symtab (ecs
->event_thread
->stop_pc ());
8335 if (cust
!= nullptr && cust
->language () != language_asm
)
8336 ecs
->stop_func_start
8337 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
8339 symtab_and_line stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
8340 /* Use the step_resume_break to step until the end of the prologue,
8341 even if that involves jumps (as it seems to on the vax under
8343 /* If the prologue ends in the middle of a source line, continue to
8344 the end of that source line (if it is still within the function).
8345 Otherwise, just go to end of prologue. */
8346 if (stop_func_sal
.end
8347 && stop_func_sal
.pc
!= ecs
->stop_func_start
8348 && stop_func_sal
.end
< ecs
->stop_func_end
)
8349 ecs
->stop_func_start
= stop_func_sal
.end
;
8351 /* Architectures which require breakpoint adjustment might not be able
8352 to place a breakpoint at the computed address. If so, the test
8353 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
8354 ecs->stop_func_start to an address at which a breakpoint may be
8355 legitimately placed.
8357 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
8358 made, GDB will enter an infinite loop when stepping through
8359 optimized code consisting of VLIW instructions which contain
8360 subinstructions corresponding to different source lines. On
8361 FR-V, it's not permitted to place a breakpoint on any but the
8362 first subinstruction of a VLIW instruction. When a breakpoint is
8363 set, GDB will adjust the breakpoint address to the beginning of
8364 the VLIW instruction. Thus, we need to make the corresponding
8365 adjustment here when computing the stop address. */
8367 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
8369 ecs
->stop_func_start
8370 = gdbarch_adjust_breakpoint_address (gdbarch
,
8371 ecs
->stop_func_start
);
8374 if (ecs
->stop_func_start
== ecs
->event_thread
->stop_pc ())
8376 /* We are already there: stop now. */
8377 end_stepping_range (ecs
);
8382 /* Put the step-breakpoint there and go until there. */
8383 symtab_and_line sr_sal
;
8384 sr_sal
.pc
= ecs
->stop_func_start
;
8385 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
8386 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
8388 /* Do not specify what the fp should be when we stop since on
8389 some machines the prologue is where the new fp value is
8391 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
8393 /* And make sure stepping stops right away then. */
8394 ecs
->event_thread
->control
.step_range_end
8395 = ecs
->event_thread
->control
.step_range_start
;
8400 /* Inferior has stepped backward into a subroutine call with source
8401 code that we should not step over. Do step to the beginning of the
8402 last line of code in it. */
8405 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
8406 struct execution_control_state
*ecs
)
8408 struct compunit_symtab
*cust
;
8409 struct symtab_and_line stop_func_sal
;
8411 fill_in_stop_func (gdbarch
, ecs
);
8413 cust
= find_pc_compunit_symtab (ecs
->event_thread
->stop_pc ());
8414 if (cust
!= nullptr && cust
->language () != language_asm
)
8415 ecs
->stop_func_start
8416 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
8418 stop_func_sal
= find_pc_line (ecs
->event_thread
->stop_pc (), 0);
8420 /* OK, we're just going to keep stepping here. */
8421 if (stop_func_sal
.pc
== ecs
->event_thread
->stop_pc ())
8423 /* We're there already. Just stop stepping now. */
8424 end_stepping_range (ecs
);
8428 /* Else just reset the step range and keep going.
8429 No step-resume breakpoint, they don't work for
8430 epilogues, which can have multiple entry paths. */
8431 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
8432 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
8438 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
8439 This is used to both functions and to skip over code. */
8442 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
8443 struct symtab_and_line sr_sal
,
8444 struct frame_id sr_id
,
8445 enum bptype sr_type
)
8447 /* There should never be more than one step-resume or longjmp-resume
8448 breakpoint per thread, so we should never be setting a new
8449 step_resume_breakpoint when one is already active. */
8450 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== nullptr);
8451 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
8453 infrun_debug_printf ("inserting step-resume breakpoint at %s",
8454 paddress (gdbarch
, sr_sal
.pc
));
8456 inferior_thread ()->control
.step_resume_breakpoint
8457 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
).release ();
8461 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
8462 struct symtab_and_line sr_sal
,
8463 struct frame_id sr_id
)
8465 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
8470 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
8471 This is used to skip a potential signal handler.
8473 This is called with the interrupted function's frame. The signal
8474 handler, when it returns, will resume the interrupted function at
8478 insert_hp_step_resume_breakpoint_at_frame (frame_info_ptr return_frame
)
8480 gdb_assert (return_frame
!= nullptr);
8482 struct gdbarch
*gdbarch
= get_frame_arch (return_frame
);
8484 symtab_and_line sr_sal
;
8485 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
8486 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
8487 sr_sal
.pspace
= get_frame_program_space (return_frame
);
8489 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
8490 get_stack_frame_id (return_frame
),
8494 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
8495 is used to skip a function after stepping into it (for "next" or if
8496 the called function has no debugging information).
8498 The current function has almost always been reached by single
8499 stepping a call or return instruction. NEXT_FRAME belongs to the
8500 current function, and the breakpoint will be set at the caller's
8503 This is a separate function rather than reusing
8504 insert_hp_step_resume_breakpoint_at_frame in order to avoid
8505 get_prev_frame, which may stop prematurely (see the implementation
8506 of frame_unwind_caller_id for an example). */
8509 insert_step_resume_breakpoint_at_caller (frame_info_ptr next_frame
)
8511 /* We shouldn't have gotten here if we don't know where the call site
8513 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
8515 struct gdbarch
*gdbarch
= frame_unwind_caller_arch (next_frame
);
8517 symtab_and_line sr_sal
;
8518 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
8519 frame_unwind_caller_pc (next_frame
));
8520 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
8521 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
8523 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
8524 frame_unwind_caller_id (next_frame
));
8527 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
8528 new breakpoint at the target of a jmp_buf. The handling of
8529 longjmp-resume uses the same mechanisms used for handling
8530 "step-resume" breakpoints. */
8533 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8535 /* There should never be more than one longjmp-resume breakpoint per
8536 thread, so we should never be setting a new
8537 longjmp_resume_breakpoint when one is already active. */
8538 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== nullptr);
8540 infrun_debug_printf ("inserting longjmp-resume breakpoint at %s",
8541 paddress (gdbarch
, pc
));
8543 inferior_thread ()->control
.exception_resume_breakpoint
=
8544 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
).release ();
8547 /* Insert an exception resume breakpoint. TP is the thread throwing
8548 the exception. The block B is the block of the unwinder debug hook
8549 function. FRAME is the frame corresponding to the call to this
8550 function. SYM is the symbol of the function argument holding the
8551 target PC of the exception. */
8554 insert_exception_resume_breakpoint (struct thread_info
*tp
,
8555 const struct block
*b
,
8556 frame_info_ptr frame
,
8561 struct block_symbol vsym
;
8562 struct value
*value
;
8564 struct breakpoint
*bp
;
8566 vsym
= lookup_symbol_search_name (sym
->search_name (),
8568 value
= read_var_value (vsym
.symbol
, vsym
.block
, frame
);
8569 /* If the value was optimized out, revert to the old behavior. */
8570 if (! value
->optimized_out ())
8572 handler
= value_as_address (value
);
8574 infrun_debug_printf ("exception resume at %lx",
8575 (unsigned long) handler
);
8577 /* set_momentary_breakpoint_at_pc creates a thread-specific
8578 breakpoint for the current inferior thread. */
8579 gdb_assert (tp
== inferior_thread ());
8580 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8582 bp_exception_resume
).release ();
8584 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
8587 tp
->control
.exception_resume_breakpoint
= bp
;
8590 catch (const gdb_exception_error
&e
)
8592 /* We want to ignore errors here. */
8596 /* A helper for check_exception_resume that sets an
8597 exception-breakpoint based on a SystemTap probe. */
8600 insert_exception_resume_from_probe (struct thread_info
*tp
,
8601 const struct bound_probe
*probe
,
8602 frame_info_ptr frame
)
8604 struct value
*arg_value
;
8606 struct breakpoint
*bp
;
8608 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
8612 handler
= value_as_address (arg_value
);
8614 infrun_debug_printf ("exception resume at %s",
8615 paddress (probe
->objfile
->arch (), handler
));
8617 /* set_momentary_breakpoint_at_pc creates a thread-specific breakpoint
8618 for the current inferior thread. */
8619 gdb_assert (tp
== inferior_thread ());
8620 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8621 handler
, bp_exception_resume
).release ();
8622 tp
->control
.exception_resume_breakpoint
= bp
;
8625 /* This is called when an exception has been intercepted. Check to
8626 see whether the exception's destination is of interest, and if so,
8627 set an exception resume breakpoint there. */
8630 check_exception_resume (struct execution_control_state
*ecs
,
8631 frame_info_ptr frame
)
8633 struct bound_probe probe
;
8634 struct symbol
*func
;
8636 /* First see if this exception unwinding breakpoint was set via a
8637 SystemTap probe point. If so, the probe has two arguments: the
8638 CFA and the HANDLER. We ignore the CFA, extract the handler, and
8639 set a breakpoint there. */
8640 probe
= find_probe_by_pc (get_frame_pc (frame
));
8643 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
8647 func
= get_frame_function (frame
);
8653 const struct block
*b
;
8656 /* The exception breakpoint is a thread-specific breakpoint on
8657 the unwinder's debug hook, declared as:
8659 void _Unwind_DebugHook (void *cfa, void *handler);
8661 The CFA argument indicates the frame to which control is
8662 about to be transferred. HANDLER is the destination PC.
8664 We ignore the CFA and set a temporary breakpoint at HANDLER.
8665 This is not extremely efficient but it avoids issues in gdb
8666 with computing the DWARF CFA, and it also works even in weird
8667 cases such as throwing an exception from inside a signal
8670 b
= func
->value_block ();
8671 for (struct symbol
*sym
: block_iterator_range (b
))
8673 if (!sym
->is_argument ())
8680 insert_exception_resume_breakpoint (ecs
->event_thread
,
8686 catch (const gdb_exception_error
&e
)
8692 stop_waiting (struct execution_control_state
*ecs
)
8694 infrun_debug_printf ("stop_waiting");
8696 /* Let callers know we don't want to wait for the inferior anymore. */
8697 ecs
->wait_some_more
= 0;
8700 /* Like keep_going, but passes the signal to the inferior, even if the
8701 signal is set to nopass. */
8704 keep_going_pass_signal (struct execution_control_state
*ecs
)
8706 gdb_assert (ecs
->event_thread
->ptid
== inferior_ptid
);
8707 gdb_assert (!ecs
->event_thread
->resumed ());
8709 /* Save the pc before execution, to compare with pc after stop. */
8710 ecs
->event_thread
->prev_pc
8711 = regcache_read_pc_protected (get_thread_regcache (ecs
->event_thread
));
8713 if (ecs
->event_thread
->control
.trap_expected
)
8715 struct thread_info
*tp
= ecs
->event_thread
;
8717 infrun_debug_printf ("%s has trap_expected set, "
8718 "resuming to collect trap",
8719 tp
->ptid
.to_string ().c_str ());
8721 /* We haven't yet gotten our trap, and either: intercepted a
8722 non-signal event (e.g., a fork); or took a signal which we
8723 are supposed to pass through to the inferior. Simply
8725 resume (ecs
->event_thread
->stop_signal ());
8727 else if (step_over_info_valid_p ())
8729 /* Another thread is stepping over a breakpoint in-line. If
8730 this thread needs a step-over too, queue the request. In
8731 either case, this resume must be deferred for later. */
8732 struct thread_info
*tp
= ecs
->event_thread
;
8734 if (ecs
->hit_singlestep_breakpoint
8735 || thread_still_needs_step_over (tp
))
8737 infrun_debug_printf ("step-over already in progress: "
8738 "step-over for %s deferred",
8739 tp
->ptid
.to_string ().c_str ());
8740 global_thread_step_over_chain_enqueue (tp
);
8743 infrun_debug_printf ("step-over in progress: resume of %s deferred",
8744 tp
->ptid
.to_string ().c_str ());
8748 struct regcache
*regcache
= get_current_regcache ();
8751 step_over_what step_what
;
8753 /* Either the trap was not expected, but we are continuing
8754 anyway (if we got a signal, the user asked it be passed to
8757 We got our expected trap, but decided we should resume from
8760 We're going to run this baby now!
8762 Note that insert_breakpoints won't try to re-insert
8763 already inserted breakpoints. Therefore, we don't
8764 care if breakpoints were already inserted, or not. */
8766 /* If we need to step over a breakpoint, and we're not using
8767 displaced stepping to do so, insert all breakpoints
8768 (watchpoints, etc.) but the one we're stepping over, step one
8769 instruction, and then re-insert the breakpoint when that step
8772 step_what
= thread_still_needs_step_over (ecs
->event_thread
);
8774 remove_bp
= (ecs
->hit_singlestep_breakpoint
8775 || (step_what
& STEP_OVER_BREAKPOINT
));
8776 remove_wps
= (step_what
& STEP_OVER_WATCHPOINT
);
8778 /* We can't use displaced stepping if we need to step past a
8779 watchpoint. The instruction copied to the scratch pad would
8780 still trigger the watchpoint. */
8782 && (remove_wps
|| !use_displaced_stepping (ecs
->event_thread
)))
8784 set_step_over_info (regcache
->aspace (),
8785 regcache_read_pc (regcache
), remove_wps
,
8786 ecs
->event_thread
->global_num
);
8788 else if (remove_wps
)
8789 set_step_over_info (nullptr, 0, remove_wps
, -1);
8791 /* If we now need to do an in-line step-over, we need to stop
8792 all other threads. Note this must be done before
8793 insert_breakpoints below, because that removes the breakpoint
8794 we're about to step over, otherwise other threads could miss
8796 if (step_over_info_valid_p () && target_is_non_stop_p ())
8797 stop_all_threads ("starting in-line step-over");
8799 /* Stop stepping if inserting breakpoints fails. */
8802 insert_breakpoints ();
8804 catch (const gdb_exception_error
&e
)
8806 exception_print (gdb_stderr
, e
);
8808 clear_step_over_info ();
8812 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
8814 resume (ecs
->event_thread
->stop_signal ());
8817 prepare_to_wait (ecs
);
8820 /* Called when we should continue running the inferior, because the
8821 current event doesn't cause a user visible stop. This does the
8822 resuming part; waiting for the next event is done elsewhere. */
8825 keep_going (struct execution_control_state
*ecs
)
8827 if (ecs
->event_thread
->control
.trap_expected
8828 && ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
8829 ecs
->event_thread
->control
.trap_expected
= 0;
8831 if (!signal_program
[ecs
->event_thread
->stop_signal ()])
8832 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
8833 keep_going_pass_signal (ecs
);
8836 /* This function normally comes after a resume, before
8837 handle_inferior_event exits. It takes care of any last bits of
8838 housekeeping, and sets the all-important wait_some_more flag. */
8841 prepare_to_wait (struct execution_control_state
*ecs
)
8843 infrun_debug_printf ("prepare_to_wait");
8845 ecs
->wait_some_more
= 1;
8847 /* If the target can't async, emulate it by marking the infrun event
8848 handler such that as soon as we get back to the event-loop, we
8849 immediately end up in fetch_inferior_event again calling
8851 if (!target_can_async_p ())
8852 mark_infrun_async_event_handler ();
8855 /* We are done with the step range of a step/next/si/ni command.
8856 Called once for each n of a "step n" operation. */
8859 end_stepping_range (struct execution_control_state
*ecs
)
8861 ecs
->event_thread
->control
.stop_step
= 1;
8865 /* Several print_*_reason functions to print why the inferior has stopped.
8866 We always print something when the inferior exits, or receives a signal.
8867 The rest of the cases are dealt with later on in normal_stop and
8868 print_it_typical. Ideally there should be a call to one of these
8869 print_*_reason functions functions from handle_inferior_event each time
8870 stop_waiting is called.
8872 Note that we don't call these directly, instead we delegate that to
8873 the interpreters, through observers. Interpreters then call these
8874 with whatever uiout is right. */
8877 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8879 annotate_signalled ();
8880 if (uiout
->is_mi_like_p ())
8882 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
8883 uiout
->text ("\nProgram terminated with signal ");
8884 annotate_signal_name ();
8885 uiout
->field_string ("signal-name",
8886 gdb_signal_to_name (siggnal
));
8887 annotate_signal_name_end ();
8889 annotate_signal_string ();
8890 uiout
->field_string ("signal-meaning",
8891 gdb_signal_to_string (siggnal
));
8892 annotate_signal_string_end ();
8893 uiout
->text (".\n");
8894 uiout
->text ("The program no longer exists.\n");
8898 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
8900 struct inferior
*inf
= current_inferior ();
8901 std::string pidstr
= target_pid_to_str (ptid_t (inf
->pid
));
8903 annotate_exited (exitstatus
);
8906 if (uiout
->is_mi_like_p ())
8907 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXITED
));
8908 std::string exit_code_str
8909 = string_printf ("0%o", (unsigned int) exitstatus
);
8910 uiout
->message ("[Inferior %s (%s) exited with code %pF]\n",
8911 plongest (inf
->num
), pidstr
.c_str (),
8912 string_field ("exit-code", exit_code_str
.c_str ()));
8916 if (uiout
->is_mi_like_p ())
8918 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
8919 uiout
->message ("[Inferior %s (%s) exited normally]\n",
8920 plongest (inf
->num
), pidstr
.c_str ());
8925 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8927 struct thread_info
*thr
= inferior_thread ();
8929 infrun_debug_printf ("signal = %s", gdb_signal_to_string (siggnal
));
8933 if (uiout
->is_mi_like_p ())
8935 else if (show_thread_that_caused_stop ())
8937 uiout
->text ("\nThread ");
8938 uiout
->field_string ("thread-id", print_thread_id (thr
));
8940 const char *name
= thread_name (thr
);
8941 if (name
!= nullptr)
8943 uiout
->text (" \"");
8944 uiout
->field_string ("name", name
);
8949 uiout
->text ("\nProgram");
8951 if (siggnal
== GDB_SIGNAL_0
&& !uiout
->is_mi_like_p ())
8952 uiout
->text (" stopped");
8955 uiout
->text (" received signal ");
8956 annotate_signal_name ();
8957 if (uiout
->is_mi_like_p ())
8959 ("reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
8960 uiout
->field_string ("signal-name", gdb_signal_to_name (siggnal
));
8961 annotate_signal_name_end ();
8963 annotate_signal_string ();
8964 uiout
->field_string ("signal-meaning", gdb_signal_to_string (siggnal
));
8966 struct regcache
*regcache
= get_current_regcache ();
8967 struct gdbarch
*gdbarch
= regcache
->arch ();
8968 if (gdbarch_report_signal_info_p (gdbarch
))
8969 gdbarch_report_signal_info (gdbarch
, uiout
, siggnal
);
8971 annotate_signal_string_end ();
8973 uiout
->text (".\n");
8977 print_no_history_reason (struct ui_out
*uiout
)
8979 if (uiout
->is_mi_like_p ())
8980 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_NO_HISTORY
));
8982 uiout
->text ("\nNo more reverse-execution history.\n");
8985 /* Print current location without a level number, if we have changed
8986 functions or hit a breakpoint. Print source line if we have one.
8987 bpstat_print contains the logic deciding in detail what to print,
8988 based on the event(s) that just occurred. */
8991 print_stop_location (const target_waitstatus
&ws
)
8994 enum print_what source_flag
;
8995 int do_frame_printing
= 1;
8996 struct thread_info
*tp
= inferior_thread ();
8998 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
.kind ());
9002 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
9003 should) carry around the function and does (or should) use
9004 that when doing a frame comparison. */
9005 if (tp
->control
.stop_step
9006 && (tp
->control
.step_frame_id
9007 == get_frame_id (get_current_frame ()))
9008 && (tp
->control
.step_start_function
9009 == find_pc_function (tp
->stop_pc ())))
9011 /* Finished step, just print source line. */
9012 source_flag
= SRC_LINE
;
9016 /* Print location and source line. */
9017 source_flag
= SRC_AND_LOC
;
9020 case PRINT_SRC_AND_LOC
:
9021 /* Print location and source line. */
9022 source_flag
= SRC_AND_LOC
;
9024 case PRINT_SRC_ONLY
:
9025 source_flag
= SRC_LINE
;
9028 /* Something bogus. */
9029 source_flag
= SRC_LINE
;
9030 do_frame_printing
= 0;
9033 internal_error (_("Unknown value."));
9036 /* The behavior of this routine with respect to the source
9038 SRC_LINE: Print only source line
9039 LOCATION: Print only location
9040 SRC_AND_LOC: Print location and source line. */
9041 if (do_frame_printing
)
9042 print_stack_frame (get_selected_frame (nullptr), 0, source_flag
, 1);
9048 print_stop_event (struct ui_out
*uiout
, bool displays
)
9050 struct target_waitstatus last
;
9051 struct thread_info
*tp
;
9053 get_last_target_status (nullptr, nullptr, &last
);
9056 scoped_restore save_uiout
= make_scoped_restore (¤t_uiout
, uiout
);
9058 print_stop_location (last
);
9060 /* Display the auto-display expressions. */
9065 tp
= inferior_thread ();
9066 if (tp
->thread_fsm () != nullptr
9067 && tp
->thread_fsm ()->finished_p ())
9069 struct return_value_info
*rv
;
9071 rv
= tp
->thread_fsm ()->return_value ();
9073 print_return_value (uiout
, rv
);
9080 maybe_remove_breakpoints (void)
9082 if (!breakpoints_should_be_inserted_now () && target_has_execution ())
9084 if (remove_breakpoints ())
9086 target_terminal::ours_for_output ();
9087 gdb_printf (_("Cannot remove breakpoints because "
9088 "program is no longer writable.\nFurther "
9089 "execution is probably impossible.\n"));
9094 /* The execution context that just caused a normal stop. */
9100 DISABLE_COPY_AND_ASSIGN (stop_context
);
9102 bool changed () const;
9107 /* The event PTID. */
9111 /* If stopp for a thread event, this is the thread that caused the
9113 thread_info_ref thread
;
9115 /* The inferior that caused the stop. */
9119 /* Initializes a new stop context. If stopped for a thread event, this
9120 takes a strong reference to the thread. */
9122 stop_context::stop_context ()
9124 stop_id
= get_stop_id ();
9125 ptid
= inferior_ptid
;
9126 inf_num
= current_inferior ()->num
;
9128 if (inferior_ptid
!= null_ptid
)
9130 /* Take a strong reference so that the thread can't be deleted
9132 thread
= thread_info_ref::new_reference (inferior_thread ());
9136 /* Return true if the current context no longer matches the saved stop
9140 stop_context::changed () const
9142 if (ptid
!= inferior_ptid
)
9144 if (inf_num
!= current_inferior ()->num
)
9146 if (thread
!= nullptr && thread
->state
!= THREAD_STOPPED
)
9148 if (get_stop_id () != stop_id
)
9158 struct target_waitstatus last
;
9160 get_last_target_status (nullptr, nullptr, &last
);
9164 /* If an exception is thrown from this point on, make sure to
9165 propagate GDB's knowledge of the executing state to the
9166 frontend/user running state. A QUIT is an easy exception to see
9167 here, so do this before any filtered output. */
9169 ptid_t finish_ptid
= null_ptid
;
9172 finish_ptid
= minus_one_ptid
;
9173 else if (last
.kind () == TARGET_WAITKIND_SIGNALLED
9174 || last
.kind () == TARGET_WAITKIND_EXITED
)
9176 /* On some targets, we may still have live threads in the
9177 inferior when we get a process exit event. E.g., for
9178 "checkpoint", when the current checkpoint/fork exits,
9179 linux-fork.c automatically switches to another fork from
9180 within target_mourn_inferior. */
9181 if (inferior_ptid
!= null_ptid
)
9182 finish_ptid
= ptid_t (inferior_ptid
.pid ());
9184 else if (last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
9185 finish_ptid
= inferior_ptid
;
9187 gdb::optional
<scoped_finish_thread_state
> maybe_finish_thread_state
;
9188 if (finish_ptid
!= null_ptid
)
9190 maybe_finish_thread_state
.emplace
9191 (user_visible_resume_target (finish_ptid
), finish_ptid
);
9194 /* As we're presenting a stop, and potentially removing breakpoints,
9195 update the thread list so we can tell whether there are threads
9196 running on the target. With target remote, for example, we can
9197 only learn about new threads when we explicitly update the thread
9198 list. Do this before notifying the interpreters about signal
9199 stops, end of stepping ranges, etc., so that the "new thread"
9200 output is emitted before e.g., "Program received signal FOO",
9201 instead of after. */
9202 update_thread_list ();
9204 if (last
.kind () == TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
9205 notify_signal_received (inferior_thread ()->stop_signal ());
9207 /* As with the notification of thread events, we want to delay
9208 notifying the user that we've switched thread context until
9209 the inferior actually stops.
9211 There's no point in saying anything if the inferior has exited.
9212 Note that SIGNALLED here means "exited with a signal", not
9213 "received a signal".
9215 Also skip saying anything in non-stop mode. In that mode, as we
9216 don't want GDB to switch threads behind the user's back, to avoid
9217 races where the user is typing a command to apply to thread x,
9218 but GDB switches to thread y before the user finishes entering
9219 the command, fetch_inferior_event installs a cleanup to restore
9220 the current thread back to the thread the user had selected right
9221 after this event is handled, so we're not really switching, only
9222 informing of a stop. */
9225 if ((last
.kind () != TARGET_WAITKIND_SIGNALLED
9226 && last
.kind () != TARGET_WAITKIND_EXITED
9227 && last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
9228 && target_has_execution ()
9229 && previous_thread
!= inferior_thread ())
9231 SWITCH_THRU_ALL_UIS ()
9233 target_terminal::ours_for_output ();
9234 gdb_printf (_("[Switching to %s]\n"),
9235 target_pid_to_str (inferior_ptid
).c_str ());
9236 annotate_thread_changed ();
9240 update_previous_thread ();
9243 if (last
.kind () == TARGET_WAITKIND_NO_RESUMED
)
9245 stop_print_frame
= false;
9247 SWITCH_THRU_ALL_UIS ()
9248 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
9250 target_terminal::ours_for_output ();
9251 gdb_printf (_("No unwaited-for children left.\n"));
9255 /* Note: this depends on the update_thread_list call above. */
9256 maybe_remove_breakpoints ();
9258 /* If an auto-display called a function and that got a signal,
9259 delete that auto-display to avoid an infinite recursion. */
9261 if (stopped_by_random_signal
)
9262 disable_current_display ();
9264 SWITCH_THRU_ALL_UIS ()
9266 async_enable_stdin ();
9269 /* Let the user/frontend see the threads as stopped. */
9270 maybe_finish_thread_state
.reset ();
9272 /* Select innermost stack frame - i.e., current frame is frame 0,
9273 and current location is based on that. Handle the case where the
9274 dummy call is returning after being stopped. E.g. the dummy call
9275 previously hit a breakpoint. (If the dummy call returns
9276 normally, we won't reach here.) Do this before the stop hook is
9277 run, so that it doesn't get to see the temporary dummy frame,
9278 which is not where we'll present the stop. */
9279 if (has_stack_frames ())
9281 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
9283 /* Pop the empty frame that contains the stack dummy. This
9284 also restores inferior state prior to the call (struct
9285 infcall_suspend_state). */
9286 frame_info_ptr frame
= get_current_frame ();
9288 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
9290 /* frame_pop calls reinit_frame_cache as the last thing it
9291 does which means there's now no selected frame. */
9294 select_frame (get_current_frame ());
9296 /* Set the current source location. */
9297 set_current_sal_from_frame (get_current_frame ());
9300 /* Look up the hook_stop and run it (CLI internally handles problem
9301 of stop_command's pre-hook not existing). */
9302 stop_context saved_context
;
9306 execute_cmd_pre_hook (stop_command
);
9308 catch (const gdb_exception_error
&ex
)
9310 exception_fprintf (gdb_stderr
, ex
,
9311 "Error while running hook_stop:\n");
9314 /* If the stop hook resumes the target, then there's no point in
9315 trying to notify about the previous stop; its context is
9316 gone. Likewise if the command switches thread or inferior --
9317 the observers would print a stop for the wrong
9319 if (saved_context
.changed ())
9322 /* Notify observers about the stop. This is where the interpreters
9323 print the stop event. */
9324 notify_normal_stop ((inferior_ptid
!= null_ptid
9325 ? inferior_thread ()->control
.stop_bpstat
9328 annotate_stopped ();
9330 if (target_has_execution ())
9332 if (last
.kind () != TARGET_WAITKIND_SIGNALLED
9333 && last
.kind () != TARGET_WAITKIND_EXITED
9334 && last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
9335 /* Delete the breakpoint we stopped at, if it wants to be deleted.
9336 Delete any breakpoint that is to be deleted at the next stop. */
9337 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
9344 signal_stop_state (int signo
)
9346 return signal_stop
[signo
];
9350 signal_print_state (int signo
)
9352 return signal_print
[signo
];
9356 signal_pass_state (int signo
)
9358 return signal_program
[signo
];
9362 signal_cache_update (int signo
)
9366 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
9367 signal_cache_update (signo
);
9372 signal_pass
[signo
] = (signal_stop
[signo
] == 0
9373 && signal_print
[signo
] == 0
9374 && signal_program
[signo
] == 1
9375 && signal_catch
[signo
] == 0);
9379 signal_stop_update (int signo
, int state
)
9381 int ret
= signal_stop
[signo
];
9383 signal_stop
[signo
] = state
;
9384 signal_cache_update (signo
);
9389 signal_print_update (int signo
, int state
)
9391 int ret
= signal_print
[signo
];
9393 signal_print
[signo
] = state
;
9394 signal_cache_update (signo
);
9399 signal_pass_update (int signo
, int state
)
9401 int ret
= signal_program
[signo
];
9403 signal_program
[signo
] = state
;
9404 signal_cache_update (signo
);
9408 /* Update the global 'signal_catch' from INFO and notify the
9412 signal_catch_update (const unsigned int *info
)
9416 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
9417 signal_catch
[i
] = info
[i
] > 0;
9418 signal_cache_update (-1);
9419 target_pass_signals (signal_pass
);
9423 sig_print_header (void)
9425 gdb_printf (_("Signal Stop\tPrint\tPass "
9426 "to program\tDescription\n"));
9430 sig_print_info (enum gdb_signal oursig
)
9432 const char *name
= gdb_signal_to_name (oursig
);
9433 int name_padding
= 13 - strlen (name
);
9435 if (name_padding
<= 0)
9438 gdb_printf ("%s", name
);
9439 gdb_printf ("%*.*s ", name_padding
, name_padding
, " ");
9440 gdb_printf ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
9441 gdb_printf ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
9442 gdb_printf ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
9443 gdb_printf ("%s\n", gdb_signal_to_string (oursig
));
9446 /* Specify how various signals in the inferior should be handled. */
9449 handle_command (const char *args
, int from_tty
)
9451 int digits
, wordlen
;
9452 int sigfirst
, siglast
;
9453 enum gdb_signal oursig
;
9456 if (args
== nullptr)
9458 error_no_arg (_("signal to handle"));
9461 /* Allocate and zero an array of flags for which signals to handle. */
9463 const size_t nsigs
= GDB_SIGNAL_LAST
;
9464 unsigned char sigs
[nsigs
] {};
9466 /* Break the command line up into args. */
9468 gdb_argv
built_argv (args
);
9470 /* Walk through the args, looking for signal oursigs, signal names, and
9471 actions. Signal numbers and signal names may be interspersed with
9472 actions, with the actions being performed for all signals cumulatively
9473 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
9475 for (char *arg
: built_argv
)
9477 wordlen
= strlen (arg
);
9478 for (digits
= 0; isdigit (arg
[digits
]); digits
++)
9482 sigfirst
= siglast
= -1;
9484 if (wordlen
>= 1 && !strncmp (arg
, "all", wordlen
))
9486 /* Apply action to all signals except those used by the
9487 debugger. Silently skip those. */
9490 siglast
= nsigs
- 1;
9492 else if (wordlen
>= 1 && !strncmp (arg
, "stop", wordlen
))
9494 SET_SIGS (nsigs
, sigs
, signal_stop
);
9495 SET_SIGS (nsigs
, sigs
, signal_print
);
9497 else if (wordlen
>= 1 && !strncmp (arg
, "ignore", wordlen
))
9499 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9501 else if (wordlen
>= 2 && !strncmp (arg
, "print", wordlen
))
9503 SET_SIGS (nsigs
, sigs
, signal_print
);
9505 else if (wordlen
>= 2 && !strncmp (arg
, "pass", wordlen
))
9507 SET_SIGS (nsigs
, sigs
, signal_program
);
9509 else if (wordlen
>= 3 && !strncmp (arg
, "nostop", wordlen
))
9511 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9513 else if (wordlen
>= 3 && !strncmp (arg
, "noignore", wordlen
))
9515 SET_SIGS (nsigs
, sigs
, signal_program
);
9517 else if (wordlen
>= 4 && !strncmp (arg
, "noprint", wordlen
))
9519 UNSET_SIGS (nsigs
, sigs
, signal_print
);
9520 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9522 else if (wordlen
>= 4 && !strncmp (arg
, "nopass", wordlen
))
9524 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9526 else if (digits
> 0)
9528 /* It is numeric. The numeric signal refers to our own
9529 internal signal numbering from target.h, not to host/target
9530 signal number. This is a feature; users really should be
9531 using symbolic names anyway, and the common ones like
9532 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
9534 sigfirst
= siglast
= (int)
9535 gdb_signal_from_command (atoi (arg
));
9536 if (arg
[digits
] == '-')
9539 gdb_signal_from_command (atoi (arg
+ digits
+ 1));
9541 if (sigfirst
> siglast
)
9543 /* Bet he didn't figure we'd think of this case... */
9544 std::swap (sigfirst
, siglast
);
9549 oursig
= gdb_signal_from_name (arg
);
9550 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
9552 sigfirst
= siglast
= (int) oursig
;
9556 /* Not a number and not a recognized flag word => complain. */
9557 error (_("Unrecognized or ambiguous flag word: \"%s\"."), arg
);
9561 /* If any signal numbers or symbol names were found, set flags for
9562 which signals to apply actions to. */
9564 for (int signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
9566 switch ((enum gdb_signal
) signum
)
9568 case GDB_SIGNAL_TRAP
:
9569 case GDB_SIGNAL_INT
:
9570 if (!allsigs
&& !sigs
[signum
])
9572 if (query (_("%s is used by the debugger.\n\
9573 Are you sure you want to change it? "),
9574 gdb_signal_to_name ((enum gdb_signal
) signum
)))
9579 gdb_printf (_("Not confirmed, unchanged.\n"));
9583 case GDB_SIGNAL_DEFAULT
:
9584 case GDB_SIGNAL_UNKNOWN
:
9585 /* Make sure that "all" doesn't print these. */
9594 for (int signum
= 0; signum
< nsigs
; signum
++)
9597 signal_cache_update (-1);
9598 target_pass_signals (signal_pass
);
9599 target_program_signals (signal_program
);
9603 /* Show the results. */
9604 sig_print_header ();
9605 for (; signum
< nsigs
; signum
++)
9607 sig_print_info ((enum gdb_signal
) signum
);
9614 /* Complete the "handle" command. */
9617 handle_completer (struct cmd_list_element
*ignore
,
9618 completion_tracker
&tracker
,
9619 const char *text
, const char *word
)
9621 static const char * const keywords
[] =
9635 signal_completer (ignore
, tracker
, text
, word
);
9636 complete_on_enum (tracker
, keywords
, word
, word
);
9640 gdb_signal_from_command (int num
)
9642 if (num
>= 1 && num
<= 15)
9643 return (enum gdb_signal
) num
;
9644 error (_("Only signals 1-15 are valid as numeric signals.\n\
9645 Use \"info signals\" for a list of symbolic signals."));
9648 /* Print current contents of the tables set by the handle command.
9649 It is possible we should just be printing signals actually used
9650 by the current target (but for things to work right when switching
9651 targets, all signals should be in the signal tables). */
9654 info_signals_command (const char *signum_exp
, int from_tty
)
9656 enum gdb_signal oursig
;
9658 sig_print_header ();
9662 /* First see if this is a symbol name. */
9663 oursig
= gdb_signal_from_name (signum_exp
);
9664 if (oursig
== GDB_SIGNAL_UNKNOWN
)
9666 /* No, try numeric. */
9668 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
9670 sig_print_info (oursig
);
9675 /* These ugly casts brought to you by the native VAX compiler. */
9676 for (oursig
= GDB_SIGNAL_FIRST
;
9677 (int) oursig
< (int) GDB_SIGNAL_LAST
;
9678 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
9682 if (oursig
!= GDB_SIGNAL_UNKNOWN
9683 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
9684 sig_print_info (oursig
);
9687 gdb_printf (_("\nUse the \"handle\" command "
9688 "to change these tables.\n"));
9691 /* The $_siginfo convenience variable is a bit special. We don't know
9692 for sure the type of the value until we actually have a chance to
9693 fetch the data. The type can change depending on gdbarch, so it is
9694 also dependent on which thread you have selected.
9696 1. making $_siginfo be an internalvar that creates a new value on
9699 2. making the value of $_siginfo be an lval_computed value. */
9701 /* This function implements the lval_computed support for reading a
9705 siginfo_value_read (struct value
*v
)
9707 LONGEST transferred
;
9709 /* If we can access registers, so can we access $_siginfo. Likewise
9711 validate_registers_access ();
9714 target_read (current_inferior ()->top_target (),
9715 TARGET_OBJECT_SIGNAL_INFO
,
9717 v
->contents_all_raw ().data (),
9719 v
->type ()->length ());
9721 if (transferred
!= v
->type ()->length ())
9722 error (_("Unable to read siginfo"));
9725 /* This function implements the lval_computed support for writing a
9729 siginfo_value_write (struct value
*v
, struct value
*fromval
)
9731 LONGEST transferred
;
9733 /* If we can access registers, so can we access $_siginfo. Likewise
9735 validate_registers_access ();
9737 transferred
= target_write (current_inferior ()->top_target (),
9738 TARGET_OBJECT_SIGNAL_INFO
,
9740 fromval
->contents_all_raw ().data (),
9742 fromval
->type ()->length ());
9744 if (transferred
!= fromval
->type ()->length ())
9745 error (_("Unable to write siginfo"));
9748 static const struct lval_funcs siginfo_value_funcs
=
9754 /* Return a new value with the correct type for the siginfo object of
9755 the current thread using architecture GDBARCH. Return a void value
9756 if there's no object available. */
9758 static struct value
*
9759 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
9762 if (target_has_stack ()
9763 && inferior_ptid
!= null_ptid
9764 && gdbarch_get_siginfo_type_p (gdbarch
))
9766 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9768 return value::allocate_computed (type
, &siginfo_value_funcs
, nullptr);
9771 return value::allocate (builtin_type (gdbarch
)->builtin_void
);
9775 /* infcall_suspend_state contains state about the program itself like its
9776 registers and any signal it received when it last stopped.
9777 This state must be restored regardless of how the inferior function call
9778 ends (either successfully, or after it hits a breakpoint or signal)
9779 if the program is to properly continue where it left off. */
9781 class infcall_suspend_state
9784 /* Capture state from GDBARCH, TP, and REGCACHE that must be restored
9785 once the inferior function call has finished. */
9786 infcall_suspend_state (struct gdbarch
*gdbarch
,
9787 const struct thread_info
*tp
,
9788 struct regcache
*regcache
)
9789 : m_registers (new readonly_detached_regcache (*regcache
))
9791 tp
->save_suspend_to (m_thread_suspend
);
9793 gdb::unique_xmalloc_ptr
<gdb_byte
> siginfo_data
;
9795 if (gdbarch_get_siginfo_type_p (gdbarch
))
9797 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9798 size_t len
= type
->length ();
9800 siginfo_data
.reset ((gdb_byte
*) xmalloc (len
));
9802 if (target_read (current_inferior ()->top_target (),
9803 TARGET_OBJECT_SIGNAL_INFO
, nullptr,
9804 siginfo_data
.get (), 0, len
) != len
)
9806 /* Errors ignored. */
9807 siginfo_data
.reset (nullptr);
9813 m_siginfo_gdbarch
= gdbarch
;
9814 m_siginfo_data
= std::move (siginfo_data
);
9818 /* Return a pointer to the stored register state. */
9820 readonly_detached_regcache
*registers () const
9822 return m_registers
.get ();
9825 /* Restores the stored state into GDBARCH, TP, and REGCACHE. */
9827 void restore (struct gdbarch
*gdbarch
,
9828 struct thread_info
*tp
,
9829 struct regcache
*regcache
) const
9831 tp
->restore_suspend_from (m_thread_suspend
);
9833 if (m_siginfo_gdbarch
== gdbarch
)
9835 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9837 /* Errors ignored. */
9838 target_write (current_inferior ()->top_target (),
9839 TARGET_OBJECT_SIGNAL_INFO
, nullptr,
9840 m_siginfo_data
.get (), 0, type
->length ());
9843 /* The inferior can be gone if the user types "print exit(0)"
9844 (and perhaps other times). */
9845 if (target_has_execution ())
9846 /* NB: The register write goes through to the target. */
9847 regcache
->restore (registers ());
9851 /* How the current thread stopped before the inferior function call was
9853 struct thread_suspend_state m_thread_suspend
;
9855 /* The registers before the inferior function call was executed. */
9856 std::unique_ptr
<readonly_detached_regcache
> m_registers
;
9858 /* Format of SIGINFO_DATA or NULL if it is not present. */
9859 struct gdbarch
*m_siginfo_gdbarch
= nullptr;
9861 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
9862 gdbarch_get_siginfo_type ()->length (). For different gdbarch the
9863 content would be invalid. */
9864 gdb::unique_xmalloc_ptr
<gdb_byte
> m_siginfo_data
;
9867 infcall_suspend_state_up
9868 save_infcall_suspend_state ()
9870 struct thread_info
*tp
= inferior_thread ();
9871 struct regcache
*regcache
= get_current_regcache ();
9872 struct gdbarch
*gdbarch
= regcache
->arch ();
9874 infcall_suspend_state_up inf_state
9875 (new struct infcall_suspend_state (gdbarch
, tp
, regcache
));
9877 /* Having saved the current state, adjust the thread state, discarding
9878 any stop signal information. The stop signal is not useful when
9879 starting an inferior function call, and run_inferior_call will not use
9880 the signal due to its `proceed' call with GDB_SIGNAL_0. */
9881 tp
->set_stop_signal (GDB_SIGNAL_0
);
9886 /* Restore inferior session state to INF_STATE. */
9889 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9891 struct thread_info
*tp
= inferior_thread ();
9892 struct regcache
*regcache
= get_current_regcache ();
9893 struct gdbarch
*gdbarch
= regcache
->arch ();
9895 inf_state
->restore (gdbarch
, tp
, regcache
);
9896 discard_infcall_suspend_state (inf_state
);
9900 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9905 readonly_detached_regcache
*
9906 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
9908 return inf_state
->registers ();
9911 /* infcall_control_state contains state regarding gdb's control of the
9912 inferior itself like stepping control. It also contains session state like
9913 the user's currently selected frame. */
9915 struct infcall_control_state
9917 struct thread_control_state thread_control
;
9918 struct inferior_control_state inferior_control
;
9921 enum stop_stack_kind stop_stack_dummy
= STOP_NONE
;
9922 int stopped_by_random_signal
= 0;
9924 /* ID and level of the selected frame when the inferior function
9926 struct frame_id selected_frame_id
{};
9927 int selected_frame_level
= -1;
9930 /* Save all of the information associated with the inferior<==>gdb
9933 infcall_control_state_up
9934 save_infcall_control_state ()
9936 infcall_control_state_up
inf_status (new struct infcall_control_state
);
9937 struct thread_info
*tp
= inferior_thread ();
9938 struct inferior
*inf
= current_inferior ();
9940 inf_status
->thread_control
= tp
->control
;
9941 inf_status
->inferior_control
= inf
->control
;
9943 tp
->control
.step_resume_breakpoint
= nullptr;
9944 tp
->control
.exception_resume_breakpoint
= nullptr;
9946 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
9947 chain. If caller's caller is walking the chain, they'll be happier if we
9948 hand them back the original chain when restore_infcall_control_state is
9950 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
9953 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
9954 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
9956 save_selected_frame (&inf_status
->selected_frame_id
,
9957 &inf_status
->selected_frame_level
);
9962 /* Restore inferior session state to INF_STATUS. */
9965 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
9967 struct thread_info
*tp
= inferior_thread ();
9968 struct inferior
*inf
= current_inferior ();
9970 if (tp
->control
.step_resume_breakpoint
)
9971 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
9973 if (tp
->control
.exception_resume_breakpoint
)
9974 tp
->control
.exception_resume_breakpoint
->disposition
9975 = disp_del_at_next_stop
;
9977 /* Handle the bpstat_copy of the chain. */
9978 bpstat_clear (&tp
->control
.stop_bpstat
);
9980 tp
->control
= inf_status
->thread_control
;
9981 inf
->control
= inf_status
->inferior_control
;
9984 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
9985 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
9987 if (target_has_stack ())
9989 restore_selected_frame (inf_status
->selected_frame_id
,
9990 inf_status
->selected_frame_level
);
9997 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
9999 if (inf_status
->thread_control
.step_resume_breakpoint
)
10000 inf_status
->thread_control
.step_resume_breakpoint
->disposition
10001 = disp_del_at_next_stop
;
10003 if (inf_status
->thread_control
.exception_resume_breakpoint
)
10004 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
10005 = disp_del_at_next_stop
;
10007 /* See save_infcall_control_state for info on stop_bpstat. */
10008 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
10013 /* See infrun.h. */
10016 clear_exit_convenience_vars (void)
10018 clear_internalvar (lookup_internalvar ("_exitsignal"));
10019 clear_internalvar (lookup_internalvar ("_exitcode"));
10023 /* User interface for reverse debugging:
10024 Set exec-direction / show exec-direction commands
10025 (returns error unless target implements to_set_exec_direction method). */
10027 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
10028 static const char exec_forward
[] = "forward";
10029 static const char exec_reverse
[] = "reverse";
10030 static const char *exec_direction
= exec_forward
;
10031 static const char *const exec_direction_names
[] = {
10038 set_exec_direction_func (const char *args
, int from_tty
,
10039 struct cmd_list_element
*cmd
)
10041 if (target_can_execute_reverse ())
10043 if (!strcmp (exec_direction
, exec_forward
))
10044 execution_direction
= EXEC_FORWARD
;
10045 else if (!strcmp (exec_direction
, exec_reverse
))
10046 execution_direction
= EXEC_REVERSE
;
10050 exec_direction
= exec_forward
;
10051 error (_("Target does not support this operation."));
10056 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
10057 struct cmd_list_element
*cmd
, const char *value
)
10059 switch (execution_direction
) {
10061 gdb_printf (out
, _("Forward.\n"));
10064 gdb_printf (out
, _("Reverse.\n"));
10067 internal_error (_("bogus execution_direction value: %d"),
10068 (int) execution_direction
);
10073 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
10074 struct cmd_list_element
*c
, const char *value
)
10076 gdb_printf (file
, _("Resuming the execution of threads "
10077 "of all processes is %s.\n"), value
);
10080 /* Implementation of `siginfo' variable. */
10082 static const struct internalvar_funcs siginfo_funcs
=
10084 siginfo_make_value
,
10088 /* Callback for infrun's target events source. This is marked when a
10089 thread has a pending status to process. */
10092 infrun_async_inferior_event_handler (gdb_client_data data
)
10094 clear_async_event_handler (infrun_async_inferior_event_token
);
10095 inferior_event_handler (INF_REG_EVENT
);
10099 namespace selftests
10102 /* Verify that when two threads with the same ptid exist (from two different
10103 targets) and one of them changes ptid, we only update inferior_ptid if
10104 it is appropriate. */
10107 infrun_thread_ptid_changed ()
10109 gdbarch
*arch
= current_inferior ()->arch ();
10111 /* The thread which inferior_ptid represents changes ptid. */
10113 scoped_restore_current_pspace_and_thread restore
;
10115 scoped_mock_context
<test_target_ops
> target1 (arch
);
10116 scoped_mock_context
<test_target_ops
> target2 (arch
);
10118 ptid_t
old_ptid (111, 222);
10119 ptid_t
new_ptid (111, 333);
10121 target1
.mock_inferior
.pid
= old_ptid
.pid ();
10122 target1
.mock_thread
.ptid
= old_ptid
;
10123 target1
.mock_inferior
.ptid_thread_map
.clear ();
10124 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
10126 target2
.mock_inferior
.pid
= old_ptid
.pid ();
10127 target2
.mock_thread
.ptid
= old_ptid
;
10128 target2
.mock_inferior
.ptid_thread_map
.clear ();
10129 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
10131 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
10132 set_current_inferior (&target1
.mock_inferior
);
10134 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
10136 gdb_assert (inferior_ptid
== new_ptid
);
10139 /* A thread with the same ptid as inferior_ptid, but from another target,
10142 scoped_restore_current_pspace_and_thread restore
;
10144 scoped_mock_context
<test_target_ops
> target1 (arch
);
10145 scoped_mock_context
<test_target_ops
> target2 (arch
);
10147 ptid_t
old_ptid (111, 222);
10148 ptid_t
new_ptid (111, 333);
10150 target1
.mock_inferior
.pid
= old_ptid
.pid ();
10151 target1
.mock_thread
.ptid
= old_ptid
;
10152 target1
.mock_inferior
.ptid_thread_map
.clear ();
10153 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
10155 target2
.mock_inferior
.pid
= old_ptid
.pid ();
10156 target2
.mock_thread
.ptid
= old_ptid
;
10157 target2
.mock_inferior
.ptid_thread_map
.clear ();
10158 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
10160 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
10161 set_current_inferior (&target2
.mock_inferior
);
10163 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
10165 gdb_assert (inferior_ptid
== old_ptid
);
10169 } /* namespace selftests */
10171 #endif /* GDB_SELF_TEST */
10173 void _initialize_infrun ();
10175 _initialize_infrun ()
10177 struct cmd_list_element
*c
;
10179 /* Register extra event sources in the event loop. */
10180 infrun_async_inferior_event_token
10181 = create_async_event_handler (infrun_async_inferior_event_handler
, nullptr,
10184 cmd_list_element
*info_signals_cmd
10185 = add_info ("signals", info_signals_command
, _("\
10186 What debugger does when program gets various signals.\n\
10187 Specify a signal as argument to print info on that signal only."));
10188 add_info_alias ("handle", info_signals_cmd
, 0);
10190 c
= add_com ("handle", class_run
, handle_command
, _("\
10191 Specify how to handle signals.\n\
10192 Usage: handle SIGNAL [ACTIONS]\n\
10193 Args are signals and actions to apply to those signals.\n\
10194 If no actions are specified, the current settings for the specified signals\n\
10195 will be displayed instead.\n\
10197 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
10198 from 1-15 are allowed for compatibility with old versions of GDB.\n\
10199 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
10200 The special arg \"all\" is recognized to mean all signals except those\n\
10201 used by the debugger, typically SIGTRAP and SIGINT.\n\
10203 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
10204 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
10205 Stop means reenter debugger if this signal happens (implies print).\n\
10206 Print means print a message if this signal happens.\n\
10207 Pass means let program see this signal; otherwise program doesn't know.\n\
10208 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
10209 Pass and Stop may be combined.\n\
10211 Multiple signals may be specified. Signal numbers and signal names\n\
10212 may be interspersed with actions, with the actions being performed for\n\
10213 all signals cumulatively specified."));
10214 set_cmd_completer (c
, handle_completer
);
10216 stop_command
= add_cmd ("stop", class_obscure
,
10217 not_just_help_class_command
, _("\
10218 There is no `stop' command, but you can set a hook on `stop'.\n\
10219 This allows you to set a list of commands to be run each time execution\n\
10220 of the program stops."), &cmdlist
);
10222 add_setshow_boolean_cmd
10223 ("infrun", class_maintenance
, &debug_infrun
,
10224 _("Set inferior debugging."),
10225 _("Show inferior debugging."),
10226 _("When non-zero, inferior specific debugging is enabled."),
10227 nullptr, show_debug_infrun
, &setdebuglist
, &showdebuglist
);
10229 add_setshow_boolean_cmd ("non-stop", no_class
,
10231 Set whether gdb controls the inferior in non-stop mode."), _("\
10232 Show whether gdb controls the inferior in non-stop mode."), _("\
10233 When debugging a multi-threaded program and this setting is\n\
10234 off (the default, also called all-stop mode), when one thread stops\n\
10235 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
10236 all other threads in the program while you interact with the thread of\n\
10237 interest. When you continue or step a thread, you can allow the other\n\
10238 threads to run, or have them remain stopped, but while you inspect any\n\
10239 thread's state, all threads stop.\n\
10241 In non-stop mode, when one thread stops, other threads can continue\n\
10242 to run freely. You'll be able to step each thread independently,\n\
10243 leave it stopped or free to run as needed."),
10249 for (size_t i
= 0; i
< GDB_SIGNAL_LAST
; i
++)
10251 signal_stop
[i
] = 1;
10252 signal_print
[i
] = 1;
10253 signal_program
[i
] = 1;
10254 signal_catch
[i
] = 0;
10257 /* Signals caused by debugger's own actions should not be given to
10258 the program afterwards.
10260 Do not deliver GDB_SIGNAL_TRAP by default, except when the user
10261 explicitly specifies that it should be delivered to the target
10262 program. Typically, that would occur when a user is debugging a
10263 target monitor on a simulator: the target monitor sets a
10264 breakpoint; the simulator encounters this breakpoint and halts
10265 the simulation handing control to GDB; GDB, noting that the stop
10266 address doesn't map to any known breakpoint, returns control back
10267 to the simulator; the simulator then delivers the hardware
10268 equivalent of a GDB_SIGNAL_TRAP to the program being
10270 signal_program
[GDB_SIGNAL_TRAP
] = 0;
10271 signal_program
[GDB_SIGNAL_INT
] = 0;
10273 /* Signals that are not errors should not normally enter the debugger. */
10274 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
10275 signal_print
[GDB_SIGNAL_ALRM
] = 0;
10276 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
10277 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
10278 signal_stop
[GDB_SIGNAL_PROF
] = 0;
10279 signal_print
[GDB_SIGNAL_PROF
] = 0;
10280 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
10281 signal_print
[GDB_SIGNAL_CHLD
] = 0;
10282 signal_stop
[GDB_SIGNAL_IO
] = 0;
10283 signal_print
[GDB_SIGNAL_IO
] = 0;
10284 signal_stop
[GDB_SIGNAL_POLL
] = 0;
10285 signal_print
[GDB_SIGNAL_POLL
] = 0;
10286 signal_stop
[GDB_SIGNAL_URG
] = 0;
10287 signal_print
[GDB_SIGNAL_URG
] = 0;
10288 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
10289 signal_print
[GDB_SIGNAL_WINCH
] = 0;
10290 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
10291 signal_print
[GDB_SIGNAL_PRIO
] = 0;
10293 /* These signals are used internally by user-level thread
10294 implementations. (See signal(5) on Solaris.) Like the above
10295 signals, a healthy program receives and handles them as part of
10296 its normal operation. */
10297 signal_stop
[GDB_SIGNAL_LWP
] = 0;
10298 signal_print
[GDB_SIGNAL_LWP
] = 0;
10299 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
10300 signal_print
[GDB_SIGNAL_WAITING
] = 0;
10301 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
10302 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
10303 signal_stop
[GDB_SIGNAL_LIBRT
] = 0;
10304 signal_print
[GDB_SIGNAL_LIBRT
] = 0;
10306 /* Update cached state. */
10307 signal_cache_update (-1);
10309 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
10310 &stop_on_solib_events
, _("\
10311 Set stopping for shared library events."), _("\
10312 Show stopping for shared library events."), _("\
10313 If nonzero, gdb will give control to the user when the dynamic linker\n\
10314 notifies gdb of shared library events. The most common event of interest\n\
10315 to the user would be loading/unloading of a new library."),
10316 set_stop_on_solib_events
,
10317 show_stop_on_solib_events
,
10318 &setlist
, &showlist
);
10320 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
10321 follow_fork_mode_kind_names
,
10322 &follow_fork_mode_string
, _("\
10323 Set debugger response to a program call of fork or vfork."), _("\
10324 Show debugger response to a program call of fork or vfork."), _("\
10325 A fork or vfork creates a new process. follow-fork-mode can be:\n\
10326 parent - the original process is debugged after a fork\n\
10327 child - the new process is debugged after a fork\n\
10328 The unfollowed process will continue to run.\n\
10329 By default, the debugger will follow the parent process."),
10331 show_follow_fork_mode_string
,
10332 &setlist
, &showlist
);
10334 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
10335 follow_exec_mode_names
,
10336 &follow_exec_mode_string
, _("\
10337 Set debugger response to a program call of exec."), _("\
10338 Show debugger response to a program call of exec."), _("\
10339 An exec call replaces the program image of a process.\n\
10341 follow-exec-mode can be:\n\
10343 new - the debugger creates a new inferior and rebinds the process\n\
10344 to this new inferior. The program the process was running before\n\
10345 the exec call can be restarted afterwards by restarting the original\n\
10348 same - the debugger keeps the process bound to the same inferior.\n\
10349 The new executable image replaces the previous executable loaded in\n\
10350 the inferior. Restarting the inferior after the exec call restarts\n\
10351 the executable the process was running after the exec call.\n\
10353 By default, the debugger will use the same inferior."),
10355 show_follow_exec_mode_string
,
10356 &setlist
, &showlist
);
10358 add_setshow_enum_cmd ("scheduler-locking", class_run
,
10359 scheduler_enums
, &scheduler_mode
, _("\
10360 Set mode for locking scheduler during execution."), _("\
10361 Show mode for locking scheduler during execution."), _("\
10362 off == no locking (threads may preempt at any time)\n\
10363 on == full locking (no thread except the current thread may run)\n\
10364 This applies to both normal execution and replay mode.\n\
10365 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
10366 In this mode, other threads may run during other commands.\n\
10367 This applies to both normal execution and replay mode.\n\
10368 replay == scheduler locked in replay mode and unlocked during normal execution."),
10369 set_schedlock_func
, /* traps on target vector */
10370 show_scheduler_mode
,
10371 &setlist
, &showlist
);
10373 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
10374 Set mode for resuming threads of all processes."), _("\
10375 Show mode for resuming threads of all processes."), _("\
10376 When on, execution commands (such as 'continue' or 'next') resume all\n\
10377 threads of all processes. When off (which is the default), execution\n\
10378 commands only resume the threads of the current process. The set of\n\
10379 threads that are resumed is further refined by the scheduler-locking\n\
10380 mode (see help set scheduler-locking)."),
10382 show_schedule_multiple
,
10383 &setlist
, &showlist
);
10385 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
10386 Set mode of the step operation."), _("\
10387 Show mode of the step operation."), _("\
10388 When set, doing a step over a function without debug line information\n\
10389 will stop at the first instruction of that function. Otherwise, the\n\
10390 function is skipped and the step command stops at a different source line."),
10392 show_step_stop_if_no_debug
,
10393 &setlist
, &showlist
);
10395 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
10396 &can_use_displaced_stepping
, _("\
10397 Set debugger's willingness to use displaced stepping."), _("\
10398 Show debugger's willingness to use displaced stepping."), _("\
10399 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
10400 supported by the target architecture. If off, gdb will not use displaced\n\
10401 stepping to step over breakpoints, even if such is supported by the target\n\
10402 architecture. If auto (which is the default), gdb will use displaced stepping\n\
10403 if the target architecture supports it and non-stop mode is active, but will not\n\
10404 use it in all-stop mode (see help set non-stop)."),
10406 show_can_use_displaced_stepping
,
10407 &setlist
, &showlist
);
10409 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
10410 &exec_direction
, _("Set direction of execution.\n\
10411 Options are 'forward' or 'reverse'."),
10412 _("Show direction of execution (forward/reverse)."),
10413 _("Tells gdb whether to execute forward or backward."),
10414 set_exec_direction_func
, show_exec_direction_func
,
10415 &setlist
, &showlist
);
10417 /* Set/show detach-on-fork: user-settable mode. */
10419 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
10420 Set whether gdb will detach the child of a fork."), _("\
10421 Show whether gdb will detach the child of a fork."), _("\
10422 Tells gdb whether to detach the child of a fork."),
10423 nullptr, nullptr, &setlist
, &showlist
);
10425 /* Set/show disable address space randomization mode. */
10427 add_setshow_boolean_cmd ("disable-randomization", class_support
,
10428 &disable_randomization
, _("\
10429 Set disabling of debuggee's virtual address space randomization."), _("\
10430 Show disabling of debuggee's virtual address space randomization."), _("\
10431 When this mode is on (which is the default), randomization of the virtual\n\
10432 address space is disabled. Standalone programs run with the randomization\n\
10433 enabled by default on some platforms."),
10434 &set_disable_randomization
,
10435 &show_disable_randomization
,
10436 &setlist
, &showlist
);
10438 /* ptid initializations */
10439 inferior_ptid
= null_ptid
;
10440 target_last_wait_ptid
= minus_one_ptid
;
10442 gdb::observers::thread_ptid_changed
.attach (infrun_thread_ptid_changed
,
10444 gdb::observers::thread_stop_requested
.attach (infrun_thread_stop_requested
,
10446 gdb::observers::inferior_exit
.attach (infrun_inferior_exit
, "infrun");
10447 gdb::observers::inferior_execd
.attach (infrun_inferior_execd
, "infrun");
10449 /* Explicitly create without lookup, since that tries to create a
10450 value with a void typed value, and when we get here, gdbarch
10451 isn't initialized yet. At this point, we're quite sure there
10452 isn't another convenience variable of the same name. */
10453 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, nullptr);
10455 add_setshow_boolean_cmd ("observer", no_class
,
10456 &observer_mode_1
, _("\
10457 Set whether gdb controls the inferior in observer mode."), _("\
10458 Show whether gdb controls the inferior in observer mode."), _("\
10459 In observer mode, GDB can get data from the inferior, but not\n\
10460 affect its execution. Registers and memory may not be changed,\n\
10461 breakpoints may not be set, and the program cannot be interrupted\n\
10464 show_observer_mode
,
10469 selftests::register_test ("infrun_thread_ptid_changed",
10470 selftests::infrun_thread_ptid_changed
);