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 target_waitkind fork_kind
= inferior_thread ()->pending_follow
.kind ();
439 gdb_assert (fork_kind
== TARGET_WAITKIND_FORKED
440 || fork_kind
== TARGET_WAITKIND_VFORKED
);
441 bool has_vforked
= fork_kind
== TARGET_WAITKIND_VFORKED
;
442 ptid_t parent_ptid
= inferior_ptid
;
443 ptid_t child_ptid
= inferior_thread ()->pending_follow
.child_ptid ();
446 && !non_stop
/* Non-stop always resumes both branches. */
447 && current_ui
->prompt_state
== PROMPT_BLOCKED
448 && !(follow_child
|| detach_fork
|| sched_multi
))
450 /* The parent stays blocked inside the vfork syscall until the
451 child execs or exits. If we don't let the child run, then
452 the parent stays blocked. If we're telling the parent to run
453 in the foreground, the user will not be able to ctrl-c to get
454 back the terminal, effectively hanging the debug session. */
455 gdb_printf (gdb_stderr
, _("\
456 Can not resume the parent process over vfork in the foreground while\n\
457 holding the child stopped. Try \"set detach-on-fork\" or \
458 \"set schedule-multiple\".\n"));
462 inferior
*parent_inf
= current_inferior ();
463 inferior
*child_inf
= nullptr;
465 gdb_assert (parent_inf
->thread_waiting_for_vfork_done
== nullptr);
469 /* Detach new forked process? */
472 /* Before detaching from the child, remove all breakpoints
473 from it. If we forked, then this has already been taken
474 care of by infrun.c. If we vforked however, any
475 breakpoint inserted in the parent is visible in the
476 child, even those added while stopped in a vfork
477 catchpoint. This will remove the breakpoints from the
478 parent also, but they'll be reinserted below. */
481 /* Keep breakpoints list in sync. */
482 remove_breakpoints_inf (current_inferior ());
485 if (print_inferior_events
)
487 /* Ensure that we have a process ptid. */
488 ptid_t process_ptid
= ptid_t (child_ptid
.pid ());
490 target_terminal::ours_for_output ();
491 gdb_printf (_("[Detaching after %s from child %s]\n"),
492 has_vforked
? "vfork" : "fork",
493 target_pid_to_str (process_ptid
).c_str ());
498 /* Add process to GDB's tables. */
499 child_inf
= add_inferior (child_ptid
.pid ());
501 child_inf
->attach_flag
= parent_inf
->attach_flag
;
502 copy_terminal_info (child_inf
, parent_inf
);
503 child_inf
->gdbarch
= parent_inf
->gdbarch
;
504 child_inf
->tdesc_info
= parent_inf
->tdesc_info
;
506 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
508 /* If this is a vfork child, then the address-space is
509 shared with the parent. */
512 child_inf
->pspace
= parent_inf
->pspace
;
513 child_inf
->aspace
= parent_inf
->aspace
;
515 exec_on_vfork (child_inf
);
517 /* The parent will be frozen until the child is done
518 with the shared region. Keep track of the
520 child_inf
->vfork_parent
= parent_inf
;
521 child_inf
->pending_detach
= false;
522 parent_inf
->vfork_child
= child_inf
;
523 parent_inf
->pending_detach
= false;
527 child_inf
->aspace
= new address_space ();
528 child_inf
->pspace
= new program_space (child_inf
->aspace
);
529 child_inf
->removable
= true;
530 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
536 /* If we detached from the child, then we have to be careful
537 to not insert breakpoints in the parent until the child
538 is done with the shared memory region. However, if we're
539 staying attached to the child, then we can and should
540 insert breakpoints, so that we can debug it. A
541 subsequent child exec or exit is enough to know when does
542 the child stops using the parent's address space. */
543 parent_inf
->thread_waiting_for_vfork_done
544 = detach_fork
? inferior_thread () : nullptr;
545 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
550 /* Follow the child. */
552 if (print_inferior_events
)
554 std::string parent_pid
= target_pid_to_str (parent_ptid
);
555 std::string child_pid
= target_pid_to_str (child_ptid
);
557 target_terminal::ours_for_output ();
558 gdb_printf (_("[Attaching after %s %s to child %s]\n"),
560 has_vforked
? "vfork" : "fork",
564 /* Add the new inferior first, so that the target_detach below
565 doesn't unpush the target. */
567 child_inf
= add_inferior (child_ptid
.pid ());
569 child_inf
->attach_flag
= parent_inf
->attach_flag
;
570 copy_terminal_info (child_inf
, parent_inf
);
571 child_inf
->gdbarch
= parent_inf
->gdbarch
;
572 child_inf
->tdesc_info
= parent_inf
->tdesc_info
;
576 /* If this is a vfork child, then the address-space is shared
578 child_inf
->aspace
= parent_inf
->aspace
;
579 child_inf
->pspace
= parent_inf
->pspace
;
581 exec_on_vfork (child_inf
);
583 else if (detach_fork
)
585 /* We follow the child and detach from the parent: move the parent's
586 program space to the child. This simplifies some things, like
587 doing "next" over fork() and landing on the expected line in the
588 child (note, that is broken with "set detach-on-fork off").
590 Before assigning brand new spaces for the parent, remove
591 breakpoints from it: because the new pspace won't match
592 currently inserted locations, the normal detach procedure
593 wouldn't remove them, and we would leave them inserted when
595 remove_breakpoints_inf (parent_inf
);
597 child_inf
->aspace
= parent_inf
->aspace
;
598 child_inf
->pspace
= parent_inf
->pspace
;
599 parent_inf
->aspace
= new address_space ();
600 parent_inf
->pspace
= new program_space (parent_inf
->aspace
);
601 clone_program_space (parent_inf
->pspace
, child_inf
->pspace
);
603 /* The parent inferior is still the current one, so keep things
605 set_current_program_space (parent_inf
->pspace
);
609 child_inf
->aspace
= new address_space ();
610 child_inf
->pspace
= new program_space (child_inf
->aspace
);
611 child_inf
->removable
= true;
612 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
613 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
617 gdb_assert (current_inferior () == parent_inf
);
619 /* If we are setting up an inferior for the child, target_follow_fork is
620 responsible for pushing the appropriate targets on the new inferior's
621 target stack and adding the initial thread (with ptid CHILD_PTID).
623 If we are not setting up an inferior for the child (because following
624 the parent and detach_fork is true), it is responsible for detaching
626 target_follow_fork (child_inf
, child_ptid
, fork_kind
, follow_child
,
629 gdb::observers::inferior_forked
.notify (parent_inf
, child_inf
, fork_kind
);
631 /* target_follow_fork must leave the parent as the current inferior. If we
632 want to follow the child, we make it the current one below. */
633 gdb_assert (current_inferior () == parent_inf
);
635 /* If there is a child inferior, target_follow_fork must have created a thread
637 if (child_inf
!= nullptr)
638 gdb_assert (!child_inf
->thread_list
.empty ());
640 /* Clear the parent thread's pending follow field. Do this before calling
641 target_detach, so that the target can differentiate the two following
644 - We continue past a fork with "follow-fork-mode == child" &&
645 "detach-on-fork on", and therefore detach the parent. In that
646 case the target should not detach the fork child.
647 - We run to a fork catchpoint and the user types "detach". In that
648 case, the target should detach the fork child in addition to the
651 The former case will have pending_follow cleared, the later will have
652 pending_follow set. */
653 thread_info
*parent_thread
= parent_inf
->find_thread (parent_ptid
);
654 gdb_assert (parent_thread
!= nullptr);
655 parent_thread
->pending_follow
.set_spurious ();
657 /* Detach the parent if needed. */
660 /* If we're vforking, we want to hold on to the parent until
661 the child exits or execs. At child exec or exit time we
662 can remove the old breakpoints from the parent and detach
663 or resume debugging it. Otherwise, detach the parent now;
664 we'll want to reuse it's program/address spaces, but we
665 can't set them to the child before removing breakpoints
666 from the parent, otherwise, the breakpoints module could
667 decide to remove breakpoints from the wrong process (since
668 they'd be assigned to the same address space). */
672 gdb_assert (child_inf
->vfork_parent
== nullptr);
673 gdb_assert (parent_inf
->vfork_child
== nullptr);
674 child_inf
->vfork_parent
= parent_inf
;
675 child_inf
->pending_detach
= false;
676 parent_inf
->vfork_child
= child_inf
;
677 parent_inf
->pending_detach
= detach_fork
;
679 else if (detach_fork
)
681 if (print_inferior_events
)
683 /* Ensure that we have a process ptid. */
684 ptid_t process_ptid
= ptid_t (parent_ptid
.pid ());
686 target_terminal::ours_for_output ();
687 gdb_printf (_("[Detaching after fork from "
689 target_pid_to_str (process_ptid
).c_str ());
692 target_detach (parent_inf
, 0);
696 /* If we ended up creating a new inferior, call post_create_inferior to inform
697 the various subcomponents. */
698 if (child_inf
!= nullptr)
700 /* If FOLLOW_CHILD, we leave CHILD_INF as the current inferior
701 (do not restore the parent as the current inferior). */
702 gdb::optional
<scoped_restore_current_thread
> maybe_restore
;
705 maybe_restore
.emplace ();
707 switch_to_thread (*child_inf
->threads ().begin ());
708 post_create_inferior (0);
714 /* Set the last target status as TP having stopped. */
717 set_last_target_status_stopped (thread_info
*tp
)
719 set_last_target_status (tp
->inf
->process_target (), tp
->ptid
,
720 target_waitstatus
{}.set_stopped (GDB_SIGNAL_0
));
723 /* Tell the target to follow the fork we're stopped at. Returns true
724 if the inferior should be resumed; false, if the target for some
725 reason decided it's best not to resume. */
730 bool follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
731 bool should_resume
= true;
733 /* Copy user stepping state to the new inferior thread. FIXME: the
734 followed fork child thread should have a copy of most of the
735 parent thread structure's run control related fields, not just these.
736 Initialized to avoid "may be used uninitialized" warnings from gcc. */
737 struct breakpoint
*step_resume_breakpoint
= nullptr;
738 struct breakpoint
*exception_resume_breakpoint
= nullptr;
739 CORE_ADDR step_range_start
= 0;
740 CORE_ADDR step_range_end
= 0;
741 int current_line
= 0;
742 symtab
*current_symtab
= nullptr;
743 struct frame_id step_frame_id
= { 0 };
747 thread_info
*cur_thr
= inferior_thread ();
750 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
751 process_stratum_target
*resume_target
752 = user_visible_resume_target (resume_ptid
);
754 /* Check if there's a thread that we're about to resume, other
755 than the current, with an unfollowed fork/vfork. If so,
756 switch back to it, to tell the target to follow it (in either
757 direction). We'll afterwards refuse to resume, and inform
758 the user what happened. */
759 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
765 /* follow_fork_inferior clears tp->pending_follow, and below
766 we'll need the value after the follow_fork_inferior
768 target_waitkind kind
= tp
->pending_follow
.kind ();
770 if (kind
!= TARGET_WAITKIND_SPURIOUS
)
772 infrun_debug_printf ("need to follow-fork [%s] first",
773 tp
->ptid
.to_string ().c_str ());
775 switch_to_thread (tp
);
777 /* Set up inferior(s) as specified by the caller, and
778 tell the target to do whatever is necessary to follow
779 either parent or child. */
782 /* The thread that started the execution command
783 won't exist in the child. Abort the command and
784 immediately stop in this thread, in the child,
786 should_resume
= false;
790 /* Following the parent, so let the thread fork its
791 child freely, it won't influence the current
792 execution command. */
793 if (follow_fork_inferior (follow_child
, detach_fork
))
795 /* Target refused to follow, or there's some
796 other reason we shouldn't resume. */
797 switch_to_thread (cur_thr
);
798 set_last_target_status_stopped (cur_thr
);
802 /* If we're following a vfork, when we need to leave
803 the just-forked thread as selected, as we need to
804 solo-resume it to collect the VFORK_DONE event.
805 If we're following a fork, however, switch back
806 to the original thread that we continue stepping
808 if (kind
!= TARGET_WAITKIND_VFORKED
)
810 gdb_assert (kind
== TARGET_WAITKIND_FORKED
);
811 switch_to_thread (cur_thr
);
820 thread_info
*tp
= inferior_thread ();
822 /* If there were any forks/vforks that were caught and are now to be
823 followed, then do so now. */
824 switch (tp
->pending_follow
.kind ())
826 case TARGET_WAITKIND_FORKED
:
827 case TARGET_WAITKIND_VFORKED
:
829 ptid_t parent
, child
;
830 std::unique_ptr
<struct thread_fsm
> thread_fsm
;
832 /* If the user did a next/step, etc, over a fork call,
833 preserve the stepping state in the fork child. */
834 if (follow_child
&& should_resume
)
836 step_resume_breakpoint
= clone_momentary_breakpoint
837 (tp
->control
.step_resume_breakpoint
);
838 step_range_start
= tp
->control
.step_range_start
;
839 step_range_end
= tp
->control
.step_range_end
;
840 current_line
= tp
->current_line
;
841 current_symtab
= tp
->current_symtab
;
842 step_frame_id
= tp
->control
.step_frame_id
;
843 exception_resume_breakpoint
844 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
845 thread_fsm
= tp
->release_thread_fsm ();
847 /* For now, delete the parent's sr breakpoint, otherwise,
848 parent/child sr breakpoints are considered duplicates,
849 and the child version will not be installed. Remove
850 this when the breakpoints module becomes aware of
851 inferiors and address spaces. */
852 delete_step_resume_breakpoint (tp
);
853 tp
->control
.step_range_start
= 0;
854 tp
->control
.step_range_end
= 0;
855 tp
->control
.step_frame_id
= null_frame_id
;
856 delete_exception_resume_breakpoint (tp
);
859 parent
= inferior_ptid
;
860 child
= tp
->pending_follow
.child_ptid ();
862 /* If handling a vfork, stop all the inferior's threads, they will be
863 restarted when the vfork shared region is complete. */
864 if (tp
->pending_follow
.kind () == TARGET_WAITKIND_VFORKED
865 && target_is_non_stop_p ())
866 stop_all_threads ("handling vfork", tp
->inf
);
868 process_stratum_target
*parent_targ
= tp
->inf
->process_target ();
869 /* Set up inferior(s) as specified by the caller, and tell the
870 target to do whatever is necessary to follow either parent
872 if (follow_fork_inferior (follow_child
, detach_fork
))
874 /* Target refused to follow, or there's some other reason
875 we shouldn't resume. */
880 /* If we followed the child, switch to it... */
883 tp
= parent_targ
->find_thread (child
);
884 switch_to_thread (tp
);
886 /* ... and preserve the stepping state, in case the
887 user was stepping over the fork call. */
890 tp
->control
.step_resume_breakpoint
891 = step_resume_breakpoint
;
892 tp
->control
.step_range_start
= step_range_start
;
893 tp
->control
.step_range_end
= step_range_end
;
894 tp
->current_line
= current_line
;
895 tp
->current_symtab
= current_symtab
;
896 tp
->control
.step_frame_id
= step_frame_id
;
897 tp
->control
.exception_resume_breakpoint
898 = exception_resume_breakpoint
;
899 tp
->set_thread_fsm (std::move (thread_fsm
));
903 /* If we get here, it was because we're trying to
904 resume from a fork catchpoint, but, the user
905 has switched threads away from the thread that
906 forked. In that case, the resume command
907 issued is most likely not applicable to the
908 child, so just warn, and refuse to resume. */
909 warning (_("Not resuming: switched threads "
910 "before following fork child."));
913 /* Reset breakpoints in the child as appropriate. */
914 follow_inferior_reset_breakpoints ();
919 case TARGET_WAITKIND_SPURIOUS
:
920 /* Nothing to follow. */
923 internal_error ("Unexpected pending_follow.kind %d\n",
924 tp
->pending_follow
.kind ());
929 set_last_target_status_stopped (tp
);
930 return should_resume
;
934 follow_inferior_reset_breakpoints (void)
936 struct thread_info
*tp
= inferior_thread ();
938 /* Was there a step_resume breakpoint? (There was if the user
939 did a "next" at the fork() call.) If so, explicitly reset its
940 thread number. Cloned step_resume breakpoints are disabled on
941 creation, so enable it here now that it is associated with the
944 step_resumes are a form of bp that are made to be per-thread.
945 Since we created the step_resume bp when the parent process
946 was being debugged, and now are switching to the child process,
947 from the breakpoint package's viewpoint, that's a switch of
948 "threads". We must update the bp's notion of which thread
949 it is for, or it'll be ignored when it triggers. */
951 if (tp
->control
.step_resume_breakpoint
)
953 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
954 tp
->control
.step_resume_breakpoint
->first_loc ().enabled
= 1;
957 /* Treat exception_resume breakpoints like step_resume breakpoints. */
958 if (tp
->control
.exception_resume_breakpoint
)
960 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
961 tp
->control
.exception_resume_breakpoint
->first_loc ().enabled
= 1;
964 /* Reinsert all breakpoints in the child. The user may have set
965 breakpoints after catching the fork, in which case those
966 were never set in the child, but only in the parent. This makes
967 sure the inserted breakpoints match the breakpoint list. */
969 breakpoint_re_set ();
970 insert_breakpoints ();
973 /* The child has exited or execed: resume THREAD, a thread of the parent,
974 if it was meant to be executing. */
977 proceed_after_vfork_done (thread_info
*thread
)
979 if (thread
->state
== THREAD_RUNNING
980 && !thread
->executing ()
981 && !thread
->stop_requested
982 && thread
->stop_signal () == GDB_SIGNAL_0
)
984 infrun_debug_printf ("resuming vfork parent thread %s",
985 thread
->ptid
.to_string ().c_str ());
987 switch_to_thread (thread
);
988 clear_proceed_status (0);
989 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
993 /* Called whenever we notice an exec or exit event, to handle
994 detaching or resuming a vfork parent. */
997 handle_vfork_child_exec_or_exit (int exec
)
999 struct inferior
*inf
= current_inferior ();
1001 if (inf
->vfork_parent
)
1003 inferior
*resume_parent
= nullptr;
1005 /* This exec or exit marks the end of the shared memory region
1006 between the parent and the child. Break the bonds. */
1007 inferior
*vfork_parent
= inf
->vfork_parent
;
1008 inf
->vfork_parent
->vfork_child
= nullptr;
1009 inf
->vfork_parent
= nullptr;
1011 /* If the user wanted to detach from the parent, now is the
1013 if (vfork_parent
->pending_detach
)
1015 struct program_space
*pspace
;
1016 struct address_space
*aspace
;
1018 /* follow-fork child, detach-on-fork on. */
1020 vfork_parent
->pending_detach
= false;
1022 scoped_restore_current_pspace_and_thread restore_thread
;
1024 /* We're letting loose of the parent. */
1025 thread_info
*tp
= any_live_thread_of_inferior (vfork_parent
);
1026 switch_to_thread (tp
);
1028 /* We're about to detach from the parent, which implicitly
1029 removes breakpoints from its address space. There's a
1030 catch here: we want to reuse the spaces for the child,
1031 but, parent/child are still sharing the pspace at this
1032 point, although the exec in reality makes the kernel give
1033 the child a fresh set of new pages. The problem here is
1034 that the breakpoints module being unaware of this, would
1035 likely chose the child process to write to the parent
1036 address space. Swapping the child temporarily away from
1037 the spaces has the desired effect. Yes, this is "sort
1040 pspace
= inf
->pspace
;
1041 aspace
= inf
->aspace
;
1042 inf
->aspace
= nullptr;
1043 inf
->pspace
= nullptr;
1045 if (print_inferior_events
)
1048 = target_pid_to_str (ptid_t (vfork_parent
->pid
));
1050 target_terminal::ours_for_output ();
1054 gdb_printf (_("[Detaching vfork parent %s "
1055 "after child exec]\n"), pidstr
.c_str ());
1059 gdb_printf (_("[Detaching vfork parent %s "
1060 "after child exit]\n"), pidstr
.c_str ());
1064 target_detach (vfork_parent
, 0);
1067 inf
->pspace
= pspace
;
1068 inf
->aspace
= aspace
;
1072 /* We're staying attached to the parent, so, really give the
1073 child a new address space. */
1074 inf
->pspace
= new program_space (maybe_new_address_space ());
1075 inf
->aspace
= inf
->pspace
->aspace
;
1076 inf
->removable
= true;
1077 set_current_program_space (inf
->pspace
);
1079 resume_parent
= vfork_parent
;
1083 /* If this is a vfork child exiting, then the pspace and
1084 aspaces were shared with the parent. Since we're
1085 reporting the process exit, we'll be mourning all that is
1086 found in the address space, and switching to null_ptid,
1087 preparing to start a new inferior. But, since we don't
1088 want to clobber the parent's address/program spaces, we
1089 go ahead and create a new one for this exiting
1092 /* Switch to no-thread while running clone_program_space, so
1093 that clone_program_space doesn't want to read the
1094 selected frame of a dead process. */
1095 scoped_restore_current_thread restore_thread
;
1096 switch_to_no_thread ();
1098 inf
->pspace
= new program_space (maybe_new_address_space ());
1099 inf
->aspace
= inf
->pspace
->aspace
;
1100 set_current_program_space (inf
->pspace
);
1101 inf
->removable
= true;
1102 inf
->symfile_flags
= SYMFILE_NO_READ
;
1103 clone_program_space (inf
->pspace
, vfork_parent
->pspace
);
1105 resume_parent
= vfork_parent
;
1108 gdb_assert (current_program_space
== inf
->pspace
);
1110 if (non_stop
&& resume_parent
!= nullptr)
1112 /* If the user wanted the parent to be running, let it go
1114 scoped_restore_current_thread restore_thread
;
1116 infrun_debug_printf ("resuming vfork parent process %d",
1117 resume_parent
->pid
);
1119 for (thread_info
*thread
: resume_parent
->threads ())
1120 proceed_after_vfork_done (thread
);
1125 /* Handle TARGET_WAITKIND_VFORK_DONE. */
1128 handle_vfork_done (thread_info
*event_thread
)
1130 /* We only care about this event if inferior::thread_waiting_for_vfork_done is
1131 set, that is if we are waiting for a vfork child not under our control
1132 (because we detached it) to exec or exit.
1134 If an inferior has vforked and we are debugging the child, we don't use
1135 the vfork-done event to get notified about the end of the shared address
1136 space window. We rely instead on the child's exec or exit event, and the
1137 inferior::vfork_{parent,child} fields are used instead. See
1138 handle_vfork_child_exec_or_exit for that. */
1139 if (event_thread
->inf
->thread_waiting_for_vfork_done
== nullptr)
1141 infrun_debug_printf ("not waiting for a vfork-done event");
1145 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1147 /* We stopped all threads (other than the vforking thread) of the inferior in
1148 follow_fork and kept them stopped until now. It should therefore not be
1149 possible for another thread to have reported a vfork during that window.
1150 If THREAD_WAITING_FOR_VFORK_DONE is set, it has to be the same thread whose
1151 vfork-done we are handling right now. */
1152 gdb_assert (event_thread
->inf
->thread_waiting_for_vfork_done
== event_thread
);
1154 event_thread
->inf
->thread_waiting_for_vfork_done
= nullptr;
1155 event_thread
->inf
->pspace
->breakpoints_not_allowed
= 0;
1157 /* On non-stop targets, we stopped all the inferior's threads in follow_fork,
1158 resume them now. On all-stop targets, everything that needs to be resumed
1159 will be when we resume the event thread. */
1160 if (target_is_non_stop_p ())
1162 /* restart_threads and start_step_over may change the current thread, make
1163 sure we leave the event thread as the current thread. */
1164 scoped_restore_current_thread restore_thread
;
1166 insert_breakpoints ();
1169 if (!step_over_info_valid_p ())
1170 restart_threads (event_thread
, event_thread
->inf
);
1174 /* Enum strings for "set|show follow-exec-mode". */
1176 static const char follow_exec_mode_new
[] = "new";
1177 static const char follow_exec_mode_same
[] = "same";
1178 static const char *const follow_exec_mode_names
[] =
1180 follow_exec_mode_new
,
1181 follow_exec_mode_same
,
1185 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1187 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1188 struct cmd_list_element
*c
, const char *value
)
1190 gdb_printf (file
, _("Follow exec mode is \"%s\".\n"), value
);
1193 /* EXEC_FILE_TARGET is assumed to be non-NULL. */
1196 follow_exec (ptid_t ptid
, const char *exec_file_target
)
1198 int pid
= ptid
.pid ();
1199 ptid_t process_ptid
;
1201 /* Switch terminal for any messages produced e.g. by
1202 breakpoint_re_set. */
1203 target_terminal::ours_for_output ();
1205 /* This is an exec event that we actually wish to pay attention to.
1206 Refresh our symbol table to the newly exec'd program, remove any
1207 momentary bp's, etc.
1209 If there are breakpoints, they aren't really inserted now,
1210 since the exec() transformed our inferior into a fresh set
1213 We want to preserve symbolic breakpoints on the list, since
1214 we have hopes that they can be reset after the new a.out's
1215 symbol table is read.
1217 However, any "raw" breakpoints must be removed from the list
1218 (e.g., the solib bp's), since their address is probably invalid
1221 And, we DON'T want to call delete_breakpoints() here, since
1222 that may write the bp's "shadow contents" (the instruction
1223 value that was overwritten with a TRAP instruction). Since
1224 we now have a new a.out, those shadow contents aren't valid. */
1226 mark_breakpoints_out ();
1228 /* The target reports the exec event to the main thread, even if
1229 some other thread does the exec, and even if the main thread was
1230 stopped or already gone. We may still have non-leader threads of
1231 the process on our list. E.g., on targets that don't have thread
1232 exit events (like remote); or on native Linux in non-stop mode if
1233 there were only two threads in the inferior and the non-leader
1234 one is the one that execs (and nothing forces an update of the
1235 thread list up to here). When debugging remotely, it's best to
1236 avoid extra traffic, when possible, so avoid syncing the thread
1237 list with the target, and instead go ahead and delete all threads
1238 of the process but one that reported the event. Note this must
1239 be done before calling update_breakpoints_after_exec, as
1240 otherwise clearing the threads' resources would reference stale
1241 thread breakpoints -- it may have been one of these threads that
1242 stepped across the exec. We could just clear their stepping
1243 states, but as long as we're iterating, might as well delete
1244 them. Deleting them now rather than at the next user-visible
1245 stop provides a nicer sequence of events for user and MI
1247 for (thread_info
*th
: all_threads_safe ())
1248 if (th
->ptid
.pid () == pid
&& th
->ptid
!= ptid
)
1251 /* We also need to clear any left over stale state for the
1252 leader/event thread. E.g., if there was any step-resume
1253 breakpoint or similar, it's gone now. We cannot truly
1254 step-to-next statement through an exec(). */
1255 thread_info
*th
= inferior_thread ();
1256 th
->control
.step_resume_breakpoint
= nullptr;
1257 th
->control
.exception_resume_breakpoint
= nullptr;
1258 th
->control
.single_step_breakpoints
= nullptr;
1259 th
->control
.step_range_start
= 0;
1260 th
->control
.step_range_end
= 0;
1262 /* The user may have had the main thread held stopped in the
1263 previous image (e.g., schedlock on, or non-stop). Release
1265 th
->stop_requested
= 0;
1267 update_breakpoints_after_exec ();
1269 /* What is this a.out's name? */
1270 process_ptid
= ptid_t (pid
);
1271 gdb_printf (_("%s is executing new program: %s\n"),
1272 target_pid_to_str (process_ptid
).c_str (),
1275 /* We've followed the inferior through an exec. Therefore, the
1276 inferior has essentially been killed & reborn. */
1278 breakpoint_init_inferior (inf_execd
);
1280 gdb::unique_xmalloc_ptr
<char> exec_file_host
1281 = exec_file_find (exec_file_target
, nullptr);
1283 /* If we were unable to map the executable target pathname onto a host
1284 pathname, tell the user that. Otherwise GDB's subsequent behavior
1285 is confusing. Maybe it would even be better to stop at this point
1286 so that the user can specify a file manually before continuing. */
1287 if (exec_file_host
== nullptr)
1288 warning (_("Could not load symbols for executable %s.\n"
1289 "Do you need \"set sysroot\"?"),
1292 /* Reset the shared library package. This ensures that we get a
1293 shlib event when the child reaches "_start", at which point the
1294 dld will have had a chance to initialize the child. */
1295 /* Also, loading a symbol file below may trigger symbol lookups, and
1296 we don't want those to be satisfied by the libraries of the
1297 previous incarnation of this process. */
1298 no_shared_libraries (nullptr, 0);
1300 inferior
*execing_inferior
= current_inferior ();
1301 inferior
*following_inferior
;
1303 if (follow_exec_mode_string
== follow_exec_mode_new
)
1305 /* The user wants to keep the old inferior and program spaces
1306 around. Create a new fresh one, and switch to it. */
1308 /* Do exit processing for the original inferior before setting the new
1309 inferior's pid. Having two inferiors with the same pid would confuse
1310 find_inferior_p(t)id. Transfer the terminal state and info from the
1311 old to the new inferior. */
1312 following_inferior
= add_inferior_with_spaces ();
1314 swap_terminal_info (following_inferior
, execing_inferior
);
1315 exit_inferior_silent (execing_inferior
);
1317 following_inferior
->pid
= pid
;
1321 /* follow-exec-mode is "same", we continue execution in the execing
1323 following_inferior
= execing_inferior
;
1325 /* The old description may no longer be fit for the new image.
1326 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1327 old description; we'll read a new one below. No need to do
1328 this on "follow-exec-mode new", as the old inferior stays
1329 around (its description is later cleared/refetched on
1331 target_clear_description ();
1334 target_follow_exec (following_inferior
, ptid
, exec_file_target
);
1336 gdb_assert (current_inferior () == following_inferior
);
1337 gdb_assert (current_program_space
== following_inferior
->pspace
);
1339 /* Attempt to open the exec file. SYMFILE_DEFER_BP_RESET is used
1340 because the proper displacement for a PIE (Position Independent
1341 Executable) main symbol file will only be computed by
1342 solib_create_inferior_hook below. breakpoint_re_set would fail
1343 to insert the breakpoints with the zero displacement. */
1344 try_open_exec_file (exec_file_host
.get (), following_inferior
,
1345 SYMFILE_DEFER_BP_RESET
);
1347 /* If the target can specify a description, read it. Must do this
1348 after flipping to the new executable (because the target supplied
1349 description must be compatible with the executable's
1350 architecture, and the old executable may e.g., be 32-bit, while
1351 the new one 64-bit), and before anything involving memory or
1353 target_find_description ();
1355 gdb::observers::inferior_execd
.notify (execing_inferior
, following_inferior
);
1357 breakpoint_re_set ();
1359 /* Reinsert all breakpoints. (Those which were symbolic have
1360 been reset to the proper address in the new a.out, thanks
1361 to symbol_file_command...). */
1362 insert_breakpoints ();
1364 /* The next resume of this inferior should bring it to the shlib
1365 startup breakpoints. (If the user had also set bp's on
1366 "main" from the old (parent) process, then they'll auto-
1367 matically get reset there in the new process.). */
1370 /* The chain of threads that need to do a step-over operation to get
1371 past e.g., a breakpoint. What technique is used to step over the
1372 breakpoint/watchpoint does not matter -- all threads end up in the
1373 same queue, to maintain rough temporal order of execution, in order
1374 to avoid starvation, otherwise, we could e.g., find ourselves
1375 constantly stepping the same couple threads past their breakpoints
1376 over and over, if the single-step finish fast enough. */
1377 thread_step_over_list global_thread_step_over_list
;
1379 /* Bit flags indicating what the thread needs to step over. */
1381 enum step_over_what_flag
1383 /* Step over a breakpoint. */
1384 STEP_OVER_BREAKPOINT
= 1,
1386 /* Step past a non-continuable watchpoint, in order to let the
1387 instruction execute so we can evaluate the watchpoint
1389 STEP_OVER_WATCHPOINT
= 2
1391 DEF_ENUM_FLAGS_TYPE (enum step_over_what_flag
, step_over_what
);
1393 /* Info about an instruction that is being stepped over. */
1395 struct step_over_info
1397 /* If we're stepping past a breakpoint, this is the address space
1398 and address of the instruction the breakpoint is set at. We'll
1399 skip inserting all breakpoints here. Valid iff ASPACE is
1401 const address_space
*aspace
= nullptr;
1402 CORE_ADDR address
= 0;
1404 /* The instruction being stepped over triggers a nonsteppable
1405 watchpoint. If true, we'll skip inserting watchpoints. */
1406 int nonsteppable_watchpoint_p
= 0;
1408 /* The thread's global number. */
1412 /* The step-over info of the location that is being stepped over.
1414 Note that with async/breakpoint always-inserted mode, a user might
1415 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1416 being stepped over. As setting a new breakpoint inserts all
1417 breakpoints, we need to make sure the breakpoint being stepped over
1418 isn't inserted then. We do that by only clearing the step-over
1419 info when the step-over is actually finished (or aborted).
1421 Presently GDB can only step over one breakpoint at any given time.
1422 Given threads that can't run code in the same address space as the
1423 breakpoint's can't really miss the breakpoint, GDB could be taught
1424 to step-over at most one breakpoint per address space (so this info
1425 could move to the address space object if/when GDB is extended).
1426 The set of breakpoints being stepped over will normally be much
1427 smaller than the set of all breakpoints, so a flag in the
1428 breakpoint location structure would be wasteful. A separate list
1429 also saves complexity and run-time, as otherwise we'd have to go
1430 through all breakpoint locations clearing their flag whenever we
1431 start a new sequence. Similar considerations weigh against storing
1432 this info in the thread object. Plus, not all step overs actually
1433 have breakpoint locations -- e.g., stepping past a single-step
1434 breakpoint, or stepping to complete a non-continuable
1436 static struct step_over_info step_over_info
;
1438 /* Record the address of the breakpoint/instruction we're currently
1440 N.B. We record the aspace and address now, instead of say just the thread,
1441 because when we need the info later the thread may be running. */
1444 set_step_over_info (const address_space
*aspace
, CORE_ADDR address
,
1445 int nonsteppable_watchpoint_p
,
1448 step_over_info
.aspace
= aspace
;
1449 step_over_info
.address
= address
;
1450 step_over_info
.nonsteppable_watchpoint_p
= nonsteppable_watchpoint_p
;
1451 step_over_info
.thread
= thread
;
1454 /* Called when we're not longer stepping over a breakpoint / an
1455 instruction, so all breakpoints are free to be (re)inserted. */
1458 clear_step_over_info (void)
1460 infrun_debug_printf ("clearing step over info");
1461 step_over_info
.aspace
= nullptr;
1462 step_over_info
.address
= 0;
1463 step_over_info
.nonsteppable_watchpoint_p
= 0;
1464 step_over_info
.thread
= -1;
1470 stepping_past_instruction_at (struct address_space
*aspace
,
1473 return (step_over_info
.aspace
!= nullptr
1474 && breakpoint_address_match (aspace
, address
,
1475 step_over_info
.aspace
,
1476 step_over_info
.address
));
1482 thread_is_stepping_over_breakpoint (int thread
)
1484 return (step_over_info
.thread
!= -1
1485 && thread
== step_over_info
.thread
);
1491 stepping_past_nonsteppable_watchpoint (void)
1493 return step_over_info
.nonsteppable_watchpoint_p
;
1496 /* Returns true if step-over info is valid. */
1499 step_over_info_valid_p (void)
1501 return (step_over_info
.aspace
!= nullptr
1502 || stepping_past_nonsteppable_watchpoint ());
1506 /* Displaced stepping. */
1508 /* In non-stop debugging mode, we must take special care to manage
1509 breakpoints properly; in particular, the traditional strategy for
1510 stepping a thread past a breakpoint it has hit is unsuitable.
1511 'Displaced stepping' is a tactic for stepping one thread past a
1512 breakpoint it has hit while ensuring that other threads running
1513 concurrently will hit the breakpoint as they should.
1515 The traditional way to step a thread T off a breakpoint in a
1516 multi-threaded program in all-stop mode is as follows:
1518 a0) Initially, all threads are stopped, and breakpoints are not
1520 a1) We single-step T, leaving breakpoints uninserted.
1521 a2) We insert breakpoints, and resume all threads.
1523 In non-stop debugging, however, this strategy is unsuitable: we
1524 don't want to have to stop all threads in the system in order to
1525 continue or step T past a breakpoint. Instead, we use displaced
1528 n0) Initially, T is stopped, other threads are running, and
1529 breakpoints are inserted.
1530 n1) We copy the instruction "under" the breakpoint to a separate
1531 location, outside the main code stream, making any adjustments
1532 to the instruction, register, and memory state as directed by
1534 n2) We single-step T over the instruction at its new location.
1535 n3) We adjust the resulting register and memory state as directed
1536 by T's architecture. This includes resetting T's PC to point
1537 back into the main instruction stream.
1540 This approach depends on the following gdbarch methods:
1542 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1543 indicate where to copy the instruction, and how much space must
1544 be reserved there. We use these in step n1.
1546 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1547 address, and makes any necessary adjustments to the instruction,
1548 register contents, and memory. We use this in step n1.
1550 - gdbarch_displaced_step_fixup adjusts registers and memory after
1551 we have successfully single-stepped the instruction, to yield the
1552 same effect the instruction would have had if we had executed it
1553 at its original address. We use this in step n3.
1555 The gdbarch_displaced_step_copy_insn and
1556 gdbarch_displaced_step_fixup functions must be written so that
1557 copying an instruction with gdbarch_displaced_step_copy_insn,
1558 single-stepping across the copied instruction, and then applying
1559 gdbarch_displaced_insn_fixup should have the same effects on the
1560 thread's memory and registers as stepping the instruction in place
1561 would have. Exactly which responsibilities fall to the copy and
1562 which fall to the fixup is up to the author of those functions.
1564 See the comments in gdbarch.sh for details.
1566 Note that displaced stepping and software single-step cannot
1567 currently be used in combination, although with some care I think
1568 they could be made to. Software single-step works by placing
1569 breakpoints on all possible subsequent instructions; if the
1570 displaced instruction is a PC-relative jump, those breakpoints
1571 could fall in very strange places --- on pages that aren't
1572 executable, or at addresses that are not proper instruction
1573 boundaries. (We do generally let other threads run while we wait
1574 to hit the software single-step breakpoint, and they might
1575 encounter such a corrupted instruction.) One way to work around
1576 this would be to have gdbarch_displaced_step_copy_insn fully
1577 simulate the effect of PC-relative instructions (and return NULL)
1578 on architectures that use software single-stepping.
1580 In non-stop mode, we can have independent and simultaneous step
1581 requests, so more than one thread may need to simultaneously step
1582 over a breakpoint. The current implementation assumes there is
1583 only one scratch space per process. In this case, we have to
1584 serialize access to the scratch space. If thread A wants to step
1585 over a breakpoint, but we are currently waiting for some other
1586 thread to complete a displaced step, we leave thread A stopped and
1587 place it in the displaced_step_request_queue. Whenever a displaced
1588 step finishes, we pick the next thread in the queue and start a new
1589 displaced step operation on it. See displaced_step_prepare and
1590 displaced_step_finish for details. */
1592 /* Return true if THREAD is doing a displaced step. */
1595 displaced_step_in_progress_thread (thread_info
*thread
)
1597 gdb_assert (thread
!= nullptr);
1599 return thread
->displaced_step_state
.in_progress ();
1602 /* Return true if INF has a thread doing a displaced step. */
1605 displaced_step_in_progress (inferior
*inf
)
1607 return inf
->displaced_step_state
.in_progress_count
> 0;
1610 /* Return true if any thread is doing a displaced step. */
1613 displaced_step_in_progress_any_thread ()
1615 for (inferior
*inf
: all_non_exited_inferiors ())
1617 if (displaced_step_in_progress (inf
))
1625 infrun_inferior_exit (struct inferior
*inf
)
1627 inf
->displaced_step_state
.reset ();
1628 inf
->thread_waiting_for_vfork_done
= nullptr;
1632 infrun_inferior_execd (inferior
*exec_inf
, inferior
*follow_inf
)
1634 /* If some threads where was doing a displaced step in this inferior at the
1635 moment of the exec, they no longer exist. Even if the exec'ing thread
1636 doing a displaced step, we don't want to to any fixup nor restore displaced
1637 stepping buffer bytes. */
1638 follow_inf
->displaced_step_state
.reset ();
1640 for (thread_info
*thread
: follow_inf
->threads ())
1641 thread
->displaced_step_state
.reset ();
1643 /* Since an in-line step is done with everything else stopped, if there was
1644 one in progress at the time of the exec, it must have been the exec'ing
1646 clear_step_over_info ();
1648 follow_inf
->thread_waiting_for_vfork_done
= nullptr;
1651 /* If ON, and the architecture supports it, GDB will use displaced
1652 stepping to step over breakpoints. If OFF, or if the architecture
1653 doesn't support it, GDB will instead use the traditional
1654 hold-and-step approach. If AUTO (which is the default), GDB will
1655 decide which technique to use to step over breakpoints depending on
1656 whether the target works in a non-stop way (see use_displaced_stepping). */
1658 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1661 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1662 struct cmd_list_element
*c
,
1665 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1667 _("Debugger's willingness to use displaced stepping "
1668 "to step over breakpoints is %s (currently %s).\n"),
1669 value
, target_is_non_stop_p () ? "on" : "off");
1672 _("Debugger's willingness to use displaced stepping "
1673 "to step over breakpoints is %s.\n"), value
);
1676 /* Return true if the gdbarch implements the required methods to use
1677 displaced stepping. */
1680 gdbarch_supports_displaced_stepping (gdbarch
*arch
)
1682 /* Only check for the presence of `prepare`. The gdbarch verification ensures
1683 that if `prepare` is provided, so is `finish`. */
1684 return gdbarch_displaced_step_prepare_p (arch
);
1687 /* Return non-zero if displaced stepping can/should be used to step
1688 over breakpoints of thread TP. */
1691 use_displaced_stepping (thread_info
*tp
)
1693 /* If the user disabled it explicitly, don't use displaced stepping. */
1694 if (can_use_displaced_stepping
== AUTO_BOOLEAN_FALSE
)
1697 /* If "auto", only use displaced stepping if the target operates in a non-stop
1699 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
1700 && !target_is_non_stop_p ())
1703 gdbarch
*gdbarch
= get_thread_regcache (tp
)->arch ();
1705 /* If the architecture doesn't implement displaced stepping, don't use
1707 if (!gdbarch_supports_displaced_stepping (gdbarch
))
1710 /* If recording, don't use displaced stepping. */
1711 if (find_record_target () != nullptr)
1714 /* If displaced stepping failed before for this inferior, don't bother trying
1716 if (tp
->inf
->displaced_step_state
.failed_before
)
1722 /* Simple function wrapper around displaced_step_thread_state::reset. */
1725 displaced_step_reset (displaced_step_thread_state
*displaced
)
1727 displaced
->reset ();
1730 /* A cleanup that wraps displaced_step_reset. We use this instead of, say,
1731 SCOPE_EXIT, because it needs to be discardable with "cleanup.release ()". */
1733 using displaced_step_reset_cleanup
= FORWARD_SCOPE_EXIT (displaced_step_reset
);
1735 /* Prepare to single-step, using displaced stepping.
1737 Note that we cannot use displaced stepping when we have a signal to
1738 deliver. If we have a signal to deliver and an instruction to step
1739 over, then after the step, there will be no indication from the
1740 target whether the thread entered a signal handler or ignored the
1741 signal and stepped over the instruction successfully --- both cases
1742 result in a simple SIGTRAP. In the first case we mustn't do a
1743 fixup, and in the second case we must --- but we can't tell which.
1744 Comments in the code for 'random signals' in handle_inferior_event
1745 explain how we handle this case instead.
1747 Returns DISPLACED_STEP_PREPARE_STATUS_OK if preparing was successful -- this
1748 thread is going to be stepped now; DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
1749 if displaced stepping this thread got queued; or
1750 DISPLACED_STEP_PREPARE_STATUS_CANT if this instruction can't be displaced
1753 static displaced_step_prepare_status
1754 displaced_step_prepare_throw (thread_info
*tp
)
1756 regcache
*regcache
= get_thread_regcache (tp
);
1757 struct gdbarch
*gdbarch
= regcache
->arch ();
1758 displaced_step_thread_state
&disp_step_thread_state
1759 = tp
->displaced_step_state
;
1761 /* We should never reach this function if the architecture does not
1762 support displaced stepping. */
1763 gdb_assert (gdbarch_supports_displaced_stepping (gdbarch
));
1765 /* Nor if the thread isn't meant to step over a breakpoint. */
1766 gdb_assert (tp
->control
.trap_expected
);
1768 /* Disable range stepping while executing in the scratch pad. We
1769 want a single-step even if executing the displaced instruction in
1770 the scratch buffer lands within the stepping range (e.g., a
1772 tp
->control
.may_range_step
= 0;
1774 /* We are about to start a displaced step for this thread. If one is already
1775 in progress, something's wrong. */
1776 gdb_assert (!disp_step_thread_state
.in_progress ());
1778 if (tp
->inf
->displaced_step_state
.unavailable
)
1780 /* The gdbarch tells us it's not worth asking to try a prepare because
1781 it is likely that it will return unavailable, so don't bother asking. */
1783 displaced_debug_printf ("deferring step of %s",
1784 tp
->ptid
.to_string ().c_str ());
1786 global_thread_step_over_chain_enqueue (tp
);
1787 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1790 displaced_debug_printf ("displaced-stepping %s now",
1791 tp
->ptid
.to_string ().c_str ());
1793 scoped_restore_current_thread restore_thread
;
1795 switch_to_thread (tp
);
1797 CORE_ADDR original_pc
= regcache_read_pc (regcache
);
1798 CORE_ADDR displaced_pc
;
1800 /* Display the instruction we are going to displaced step. */
1801 if (debug_displaced
)
1803 string_file tmp_stream
;
1804 int dislen
= gdb_print_insn (gdbarch
, original_pc
, &tmp_stream
,
1809 gdb::byte_vector
insn_buf (dislen
);
1810 read_memory (original_pc
, insn_buf
.data (), insn_buf
.size ());
1812 std::string insn_bytes
= bytes_to_string (insn_buf
);
1814 displaced_debug_printf ("original insn %s: %s \t %s",
1815 paddress (gdbarch
, original_pc
),
1816 insn_bytes
.c_str (),
1817 tmp_stream
.string ().c_str ());
1820 displaced_debug_printf ("original insn %s: invalid length: %d",
1821 paddress (gdbarch
, original_pc
), dislen
);
1824 displaced_step_prepare_status status
1825 = gdbarch_displaced_step_prepare (gdbarch
, tp
, displaced_pc
);
1827 if (status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
1829 displaced_debug_printf ("failed to prepare (%s)",
1830 tp
->ptid
.to_string ().c_str ());
1832 return DISPLACED_STEP_PREPARE_STATUS_CANT
;
1834 else if (status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
1836 /* Not enough displaced stepping resources available, defer this
1837 request by placing it the queue. */
1839 displaced_debug_printf ("not enough resources available, "
1840 "deferring step of %s",
1841 tp
->ptid
.to_string ().c_str ());
1843 global_thread_step_over_chain_enqueue (tp
);
1845 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1848 gdb_assert (status
== DISPLACED_STEP_PREPARE_STATUS_OK
);
1850 /* Save the information we need to fix things up if the step
1852 disp_step_thread_state
.set (gdbarch
);
1854 tp
->inf
->displaced_step_state
.in_progress_count
++;
1856 displaced_debug_printf ("prepared successfully thread=%s, "
1857 "original_pc=%s, displaced_pc=%s",
1858 tp
->ptid
.to_string ().c_str (),
1859 paddress (gdbarch
, original_pc
),
1860 paddress (gdbarch
, displaced_pc
));
1862 /* Display the new displaced instruction(s). */
1863 if (debug_displaced
)
1865 string_file tmp_stream
;
1866 CORE_ADDR addr
= displaced_pc
;
1868 /* If displaced stepping is going to use h/w single step then we know
1869 that the replacement instruction can only be a single instruction,
1870 in that case set the end address at the next byte.
1872 Otherwise the displaced stepping copy instruction routine could
1873 have generated multiple instructions, and all we know is that they
1874 must fit within the LEN bytes of the buffer. */
1876 = addr
+ (gdbarch_displaced_step_hw_singlestep (gdbarch
)
1877 ? 1 : gdbarch_displaced_step_buffer_length (gdbarch
));
1881 int dislen
= gdb_print_insn (gdbarch
, addr
, &tmp_stream
, nullptr);
1884 displaced_debug_printf
1885 ("replacement insn %s: invalid length: %d",
1886 paddress (gdbarch
, addr
), dislen
);
1890 gdb::byte_vector
insn_buf (dislen
);
1891 read_memory (addr
, insn_buf
.data (), insn_buf
.size ());
1893 std::string insn_bytes
= bytes_to_string (insn_buf
);
1894 std::string insn_str
= tmp_stream
.release ();
1895 displaced_debug_printf ("replacement insn %s: %s \t %s",
1896 paddress (gdbarch
, addr
),
1897 insn_bytes
.c_str (),
1903 return DISPLACED_STEP_PREPARE_STATUS_OK
;
1906 /* Wrapper for displaced_step_prepare_throw that disabled further
1907 attempts at displaced stepping if we get a memory error. */
1909 static displaced_step_prepare_status
1910 displaced_step_prepare (thread_info
*thread
)
1912 displaced_step_prepare_status status
1913 = DISPLACED_STEP_PREPARE_STATUS_CANT
;
1917 status
= displaced_step_prepare_throw (thread
);
1919 catch (const gdb_exception_error
&ex
)
1921 if (ex
.error
!= MEMORY_ERROR
1922 && ex
.error
!= NOT_SUPPORTED_ERROR
)
1925 infrun_debug_printf ("caught exception, disabling displaced stepping: %s",
1928 /* Be verbose if "set displaced-stepping" is "on", silent if
1930 if (can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1932 warning (_("disabling displaced stepping: %s"),
1936 /* Disable further displaced stepping attempts. */
1937 thread
->inf
->displaced_step_state
.failed_before
= 1;
1943 /* If we displaced stepped an instruction successfully, adjust registers and
1944 memory to yield the same effect the instruction would have had if we had
1945 executed it at its original address, and return
1946 DISPLACED_STEP_FINISH_STATUS_OK. If the instruction didn't complete,
1947 relocate the PC and return DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED.
1949 If the thread wasn't displaced stepping, return
1950 DISPLACED_STEP_FINISH_STATUS_OK as well. */
1952 static displaced_step_finish_status
1953 displaced_step_finish (thread_info
*event_thread
,
1954 const target_waitstatus
&event_status
)
1956 displaced_step_thread_state
*displaced
= &event_thread
->displaced_step_state
;
1958 /* Was this thread performing a displaced step? */
1959 if (!displaced
->in_progress ())
1960 return DISPLACED_STEP_FINISH_STATUS_OK
;
1962 gdb_assert (event_thread
->inf
->displaced_step_state
.in_progress_count
> 0);
1963 event_thread
->inf
->displaced_step_state
.in_progress_count
--;
1965 /* Fixup may need to read memory/registers. Switch to the thread
1966 that we're fixing up. Also, target_stopped_by_watchpoint checks
1967 the current thread, and displaced_step_restore performs ptid-dependent
1968 memory accesses using current_inferior(). */
1969 switch_to_thread (event_thread
);
1971 displaced_step_reset_cleanup
cleanup (displaced
);
1973 /* Do the fixup, and release the resources acquired to do the displaced
1975 return gdbarch_displaced_step_finish (displaced
->get_original_gdbarch (),
1976 event_thread
, event_status
);
1979 /* Data to be passed around while handling an event. This data is
1980 discarded between events. */
1981 struct execution_control_state
1983 explicit execution_control_state (thread_info
*thr
= nullptr)
1984 : ptid (thr
== nullptr ? null_ptid
: thr
->ptid
),
1989 process_stratum_target
*target
= nullptr;
1991 /* The thread that got the event, if this was a thread event; NULL
1993 struct thread_info
*event_thread
;
1995 struct target_waitstatus ws
;
1996 int stop_func_filled_in
= 0;
1997 CORE_ADDR stop_func_alt_start
= 0;
1998 CORE_ADDR stop_func_start
= 0;
1999 CORE_ADDR stop_func_end
= 0;
2000 const char *stop_func_name
= nullptr;
2001 int wait_some_more
= 0;
2003 /* True if the event thread hit the single-step breakpoint of
2004 another thread. Thus the event doesn't cause a stop, the thread
2005 needs to be single-stepped past the single-step breakpoint before
2006 we can switch back to the original stepping thread. */
2007 int hit_singlestep_breakpoint
= 0;
2010 static void keep_going_pass_signal (struct execution_control_state
*ecs
);
2011 static void prepare_to_wait (struct execution_control_state
*ecs
);
2012 static bool keep_going_stepped_thread (struct thread_info
*tp
);
2013 static step_over_what
thread_still_needs_step_over (struct thread_info
*tp
);
2015 /* Are there any pending step-over requests? If so, run all we can
2016 now and return true. Otherwise, return false. */
2019 start_step_over (void)
2021 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
2023 /* Don't start a new step-over if we already have an in-line
2024 step-over operation ongoing. */
2025 if (step_over_info_valid_p ())
2028 /* Steal the global thread step over chain. As we try to initiate displaced
2029 steps, threads will be enqueued in the global chain if no buffers are
2030 available. If we iterated on the global chain directly, we might iterate
2032 thread_step_over_list threads_to_step
2033 = std::move (global_thread_step_over_list
);
2035 infrun_debug_printf ("stealing global queue of threads to step, length = %d",
2036 thread_step_over_chain_length (threads_to_step
));
2038 bool started
= false;
2040 /* On scope exit (whatever the reason, return or exception), if there are
2041 threads left in the THREADS_TO_STEP chain, put back these threads in the
2045 if (threads_to_step
.empty ())
2046 infrun_debug_printf ("step-over queue now empty");
2049 infrun_debug_printf ("putting back %d threads to step in global queue",
2050 thread_step_over_chain_length (threads_to_step
));
2052 global_thread_step_over_chain_enqueue_chain
2053 (std::move (threads_to_step
));
2057 thread_step_over_list_safe_range range
2058 = make_thread_step_over_list_safe_range (threads_to_step
);
2060 for (thread_info
*tp
: range
)
2062 step_over_what step_what
;
2063 int must_be_in_line
;
2065 gdb_assert (!tp
->stop_requested
);
2067 if (tp
->inf
->displaced_step_state
.unavailable
)
2069 /* The arch told us to not even try preparing another displaced step
2070 for this inferior. Just leave the thread in THREADS_TO_STEP, it
2071 will get moved to the global chain on scope exit. */
2075 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr)
2077 /* When we stop all threads, handling a vfork, any thread in the step
2078 over chain remains there. A user could also try to continue a
2079 thread stopped at a breakpoint while another thread is waiting for
2080 a vfork-done event. In any case, we don't want to start a step
2085 /* Remove thread from the THREADS_TO_STEP chain. If anything goes wrong
2086 while we try to prepare the displaced step, we don't add it back to
2087 the global step over chain. This is to avoid a thread staying in the
2088 step over chain indefinitely if something goes wrong when resuming it
2089 If the error is intermittent and it still needs a step over, it will
2090 get enqueued again when we try to resume it normally. */
2091 threads_to_step
.erase (threads_to_step
.iterator_to (*tp
));
2093 step_what
= thread_still_needs_step_over (tp
);
2094 must_be_in_line
= ((step_what
& STEP_OVER_WATCHPOINT
)
2095 || ((step_what
& STEP_OVER_BREAKPOINT
)
2096 && !use_displaced_stepping (tp
)));
2098 /* We currently stop all threads of all processes to step-over
2099 in-line. If we need to start a new in-line step-over, let
2100 any pending displaced steps finish first. */
2101 if (must_be_in_line
&& displaced_step_in_progress_any_thread ())
2103 global_thread_step_over_chain_enqueue (tp
);
2107 if (tp
->control
.trap_expected
2109 || tp
->executing ())
2111 internal_error ("[%s] has inconsistent state: "
2112 "trap_expected=%d, resumed=%d, executing=%d\n",
2113 tp
->ptid
.to_string ().c_str (),
2114 tp
->control
.trap_expected
,
2119 infrun_debug_printf ("resuming [%s] for step-over",
2120 tp
->ptid
.to_string ().c_str ());
2122 /* keep_going_pass_signal skips the step-over if the breakpoint
2123 is no longer inserted. In all-stop, we want to keep looking
2124 for a thread that needs a step-over instead of resuming TP,
2125 because we wouldn't be able to resume anything else until the
2126 target stops again. In non-stop, the resume always resumes
2127 only TP, so it's OK to let the thread resume freely. */
2128 if (!target_is_non_stop_p () && !step_what
)
2131 switch_to_thread (tp
);
2132 execution_control_state
ecs (tp
);
2133 keep_going_pass_signal (&ecs
);
2135 if (!ecs
.wait_some_more
)
2136 error (_("Command aborted."));
2138 /* If the thread's step over could not be initiated because no buffers
2139 were available, it was re-added to the global step over chain. */
2142 infrun_debug_printf ("[%s] was resumed.",
2143 tp
->ptid
.to_string ().c_str ());
2144 gdb_assert (!thread_is_in_step_over_chain (tp
));
2148 infrun_debug_printf ("[%s] was NOT resumed.",
2149 tp
->ptid
.to_string ().c_str ());
2150 gdb_assert (thread_is_in_step_over_chain (tp
));
2153 /* If we started a new in-line step-over, we're done. */
2154 if (step_over_info_valid_p ())
2156 gdb_assert (tp
->control
.trap_expected
);
2161 if (!target_is_non_stop_p ())
2163 /* On all-stop, shouldn't have resumed unless we needed a
2165 gdb_assert (tp
->control
.trap_expected
2166 || tp
->step_after_step_resume_breakpoint
);
2168 /* With remote targets (at least), in all-stop, we can't
2169 issue any further remote commands until the program stops
2175 /* Either the thread no longer needed a step-over, or a new
2176 displaced stepping sequence started. Even in the latter
2177 case, continue looking. Maybe we can also start another
2178 displaced step on a thread of other process. */
2184 /* Update global variables holding ptids to hold NEW_PTID if they were
2185 holding OLD_PTID. */
2187 infrun_thread_ptid_changed (process_stratum_target
*target
,
2188 ptid_t old_ptid
, ptid_t new_ptid
)
2190 if (inferior_ptid
== old_ptid
2191 && current_inferior ()->process_target () == target
)
2192 inferior_ptid
= new_ptid
;
2197 static const char schedlock_off
[] = "off";
2198 static const char schedlock_on
[] = "on";
2199 static const char schedlock_step
[] = "step";
2200 static const char schedlock_replay
[] = "replay";
2201 static const char *const scheduler_enums
[] = {
2208 static const char *scheduler_mode
= schedlock_replay
;
2210 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
2211 struct cmd_list_element
*c
, const char *value
)
2214 _("Mode for locking scheduler "
2215 "during execution is \"%s\".\n"),
2220 set_schedlock_func (const char *args
, int from_tty
, struct cmd_list_element
*c
)
2222 if (!target_can_lock_scheduler ())
2224 scheduler_mode
= schedlock_off
;
2225 error (_("Target '%s' cannot support this command."),
2226 target_shortname ());
2230 /* True if execution commands resume all threads of all processes by
2231 default; otherwise, resume only threads of the current inferior
2233 bool sched_multi
= false;
2235 /* Try to setup for software single stepping. Return true if target_resume()
2236 should use hardware single step.
2238 GDBARCH the current gdbarch. */
2241 maybe_software_singlestep (struct gdbarch
*gdbarch
)
2243 bool hw_step
= true;
2245 if (execution_direction
== EXEC_FORWARD
2246 && gdbarch_software_single_step_p (gdbarch
))
2247 hw_step
= !insert_single_step_breakpoints (gdbarch
);
2255 user_visible_resume_ptid (int step
)
2261 /* With non-stop mode on, threads are always handled
2263 resume_ptid
= inferior_ptid
;
2265 else if ((scheduler_mode
== schedlock_on
)
2266 || (scheduler_mode
== schedlock_step
&& step
))
2268 /* User-settable 'scheduler' mode requires solo thread
2270 resume_ptid
= inferior_ptid
;
2272 else if ((scheduler_mode
== schedlock_replay
)
2273 && target_record_will_replay (minus_one_ptid
, execution_direction
))
2275 /* User-settable 'scheduler' mode requires solo thread resume in replay
2277 resume_ptid
= inferior_ptid
;
2279 else if (!sched_multi
&& target_supports_multi_process ())
2281 /* Resume all threads of the current process (and none of other
2283 resume_ptid
= ptid_t (inferior_ptid
.pid ());
2287 /* Resume all threads of all processes. */
2288 resume_ptid
= RESUME_ALL
;
2296 process_stratum_target
*
2297 user_visible_resume_target (ptid_t resume_ptid
)
2299 return (resume_ptid
== minus_one_ptid
&& sched_multi
2301 : current_inferior ()->process_target ());
2304 /* Find a thread from the inferiors that we'll resume that is waiting
2305 for a vfork-done event. */
2307 static thread_info
*
2308 find_thread_waiting_for_vfork_done ()
2310 gdb_assert (!target_is_non_stop_p ());
2314 for (inferior
*inf
: all_non_exited_inferiors ())
2315 if (inf
->thread_waiting_for_vfork_done
!= nullptr)
2316 return inf
->thread_waiting_for_vfork_done
;
2320 inferior
*cur_inf
= current_inferior ();
2321 if (cur_inf
->thread_waiting_for_vfork_done
!= nullptr)
2322 return cur_inf
->thread_waiting_for_vfork_done
;
2327 /* Return a ptid representing the set of threads that we will resume,
2328 in the perspective of the target, assuming run control handling
2329 does not require leaving some threads stopped (e.g., stepping past
2330 breakpoint). USER_STEP indicates whether we're about to start the
2331 target for a stepping command. */
2334 internal_resume_ptid (int user_step
)
2336 /* In non-stop, we always control threads individually. Note that
2337 the target may always work in non-stop mode even with "set
2338 non-stop off", in which case user_visible_resume_ptid could
2339 return a wildcard ptid. */
2340 if (target_is_non_stop_p ())
2341 return inferior_ptid
;
2343 /* The rest of the function assumes non-stop==off and
2344 target-non-stop==off.
2346 If a thread is waiting for a vfork-done event, it means breakpoints are out
2347 for this inferior (well, program space in fact). We don't want to resume
2348 any thread other than the one waiting for vfork done, otherwise these other
2349 threads could miss breakpoints. So if a thread in the resumption set is
2350 waiting for a vfork-done event, resume only that thread.
2352 The resumption set width depends on whether schedule-multiple is on or off.
2354 Note that if the target_resume interface was more flexible, we could be
2355 smarter here when schedule-multiple is on. For example, imagine 3
2356 inferiors with 2 threads each (1.1, 1.2, 2.1, 2.2, 3.1 and 3.2). Threads
2357 2.1 and 3.2 are both waiting for a vfork-done event. Then we could ask the
2358 target(s) to resume:
2360 - All threads of inferior 1
2364 Since we don't have that flexibility (we can only pass one ptid), just
2365 resume the first thread waiting for a vfork-done event we find (e.g. thread
2367 thread_info
*thr
= find_thread_waiting_for_vfork_done ();
2370 /* If we have a thread that is waiting for a vfork-done event,
2371 then we should have switched to it earlier. Calling
2372 target_resume with thread scope is only possible when the
2373 current thread matches the thread scope. */
2374 gdb_assert (thr
->ptid
== inferior_ptid
);
2375 gdb_assert (thr
->inf
->process_target ()
2376 == inferior_thread ()->inf
->process_target ());
2380 return user_visible_resume_ptid (user_step
);
2383 /* Wrapper for target_resume, that handles infrun-specific
2387 do_target_resume (ptid_t resume_ptid
, bool step
, enum gdb_signal sig
)
2389 struct thread_info
*tp
= inferior_thread ();
2391 gdb_assert (!tp
->stop_requested
);
2393 /* Install inferior's terminal modes. */
2394 target_terminal::inferior ();
2396 /* Avoid confusing the next resume, if the next stop/resume
2397 happens to apply to another thread. */
2398 tp
->set_stop_signal (GDB_SIGNAL_0
);
2400 /* Advise target which signals may be handled silently.
2402 If we have removed breakpoints because we are stepping over one
2403 in-line (in any thread), we need to receive all signals to avoid
2404 accidentally skipping a breakpoint during execution of a signal
2407 Likewise if we're displaced stepping, otherwise a trap for a
2408 breakpoint in a signal handler might be confused with the
2409 displaced step finishing. We don't make the displaced_step_finish
2410 step distinguish the cases instead, because:
2412 - a backtrace while stopped in the signal handler would show the
2413 scratch pad as frame older than the signal handler, instead of
2414 the real mainline code.
2416 - when the thread is later resumed, the signal handler would
2417 return to the scratch pad area, which would no longer be
2419 if (step_over_info_valid_p ()
2420 || displaced_step_in_progress (tp
->inf
))
2421 target_pass_signals ({});
2423 target_pass_signals (signal_pass
);
2425 infrun_debug_printf ("resume_ptid=%s, step=%d, sig=%s",
2426 resume_ptid
.to_string ().c_str (),
2427 step
, gdb_signal_to_symbol_string (sig
));
2429 target_resume (resume_ptid
, step
, sig
);
2432 /* Resume the inferior. SIG is the signal to give the inferior
2433 (GDB_SIGNAL_0 for none). Note: don't call this directly; instead
2434 call 'resume', which handles exceptions. */
2437 resume_1 (enum gdb_signal sig
)
2439 struct regcache
*regcache
= get_current_regcache ();
2440 struct gdbarch
*gdbarch
= regcache
->arch ();
2441 struct thread_info
*tp
= inferior_thread ();
2442 const address_space
*aspace
= regcache
->aspace ();
2444 /* This represents the user's step vs continue request. When
2445 deciding whether "set scheduler-locking step" applies, it's the
2446 user's intention that counts. */
2447 const int user_step
= tp
->control
.stepping_command
;
2448 /* This represents what we'll actually request the target to do.
2449 This can decay from a step to a continue, if e.g., we need to
2450 implement single-stepping with breakpoints (software
2454 gdb_assert (!tp
->stop_requested
);
2455 gdb_assert (!thread_is_in_step_over_chain (tp
));
2457 if (tp
->has_pending_waitstatus ())
2460 ("thread %s has pending wait "
2461 "status %s (currently_stepping=%d).",
2462 tp
->ptid
.to_string ().c_str (),
2463 tp
->pending_waitstatus ().to_string ().c_str (),
2464 currently_stepping (tp
));
2466 tp
->inf
->process_target ()->threads_executing
= true;
2467 tp
->set_resumed (true);
2469 /* FIXME: What should we do if we are supposed to resume this
2470 thread with a signal? Maybe we should maintain a queue of
2471 pending signals to deliver. */
2472 if (sig
!= GDB_SIGNAL_0
)
2474 warning (_("Couldn't deliver signal %s to %s."),
2475 gdb_signal_to_name (sig
),
2476 tp
->ptid
.to_string ().c_str ());
2479 tp
->set_stop_signal (GDB_SIGNAL_0
);
2481 if (target_can_async_p ())
2483 target_async (true);
2484 /* Tell the event loop we have an event to process. */
2485 mark_async_event_handler (infrun_async_inferior_event_token
);
2490 tp
->stepped_breakpoint
= 0;
2492 /* Depends on stepped_breakpoint. */
2493 step
= currently_stepping (tp
);
2495 if (current_inferior ()->thread_waiting_for_vfork_done
!= nullptr)
2497 /* Don't try to single-step a vfork parent that is waiting for
2498 the child to get out of the shared memory region (by exec'ing
2499 or exiting). This is particularly important on software
2500 single-step archs, as the child process would trip on the
2501 software single step breakpoint inserted for the parent
2502 process. Since the parent will not actually execute any
2503 instruction until the child is out of the shared region (such
2504 are vfork's semantics), it is safe to simply continue it.
2505 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2506 the parent, and tell it to `keep_going', which automatically
2507 re-sets it stepping. */
2508 infrun_debug_printf ("resume : clear step");
2512 CORE_ADDR pc
= regcache_read_pc (regcache
);
2514 infrun_debug_printf ("step=%d, signal=%s, trap_expected=%d, "
2515 "current thread [%s] at %s",
2516 step
, gdb_signal_to_symbol_string (sig
),
2517 tp
->control
.trap_expected
,
2518 inferior_ptid
.to_string ().c_str (),
2519 paddress (gdbarch
, pc
));
2521 /* Normally, by the time we reach `resume', the breakpoints are either
2522 removed or inserted, as appropriate. The exception is if we're sitting
2523 at a permanent breakpoint; we need to step over it, but permanent
2524 breakpoints can't be removed. So we have to test for it here. */
2525 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2527 if (sig
!= GDB_SIGNAL_0
)
2529 /* We have a signal to pass to the inferior. The resume
2530 may, or may not take us to the signal handler. If this
2531 is a step, we'll need to stop in the signal handler, if
2532 there's one, (if the target supports stepping into
2533 handlers), or in the next mainline instruction, if
2534 there's no handler. If this is a continue, we need to be
2535 sure to run the handler with all breakpoints inserted.
2536 In all cases, set a breakpoint at the current address
2537 (where the handler returns to), and once that breakpoint
2538 is hit, resume skipping the permanent breakpoint. If
2539 that breakpoint isn't hit, then we've stepped into the
2540 signal handler (or hit some other event). We'll delete
2541 the step-resume breakpoint then. */
2543 infrun_debug_printf ("resume: skipping permanent breakpoint, "
2544 "deliver signal first");
2546 clear_step_over_info ();
2547 tp
->control
.trap_expected
= 0;
2549 if (tp
->control
.step_resume_breakpoint
== nullptr)
2551 /* Set a "high-priority" step-resume, as we don't want
2552 user breakpoints at PC to trigger (again) when this
2554 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2555 gdb_assert (tp
->control
.step_resume_breakpoint
->first_loc ()
2558 tp
->step_after_step_resume_breakpoint
= step
;
2561 insert_breakpoints ();
2565 /* There's no signal to pass, we can go ahead and skip the
2566 permanent breakpoint manually. */
2567 infrun_debug_printf ("skipping permanent breakpoint");
2568 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2569 /* Update pc to reflect the new address from which we will
2570 execute instructions. */
2571 pc
= regcache_read_pc (regcache
);
2575 /* We've already advanced the PC, so the stepping part
2576 is done. Now we need to arrange for a trap to be
2577 reported to handle_inferior_event. Set a breakpoint
2578 at the current PC, and run to it. Don't update
2579 prev_pc, because if we end in
2580 switch_back_to_stepped_thread, we want the "expected
2581 thread advanced also" branch to be taken. IOW, we
2582 don't want this thread to step further from PC
2584 gdb_assert (!step_over_info_valid_p ());
2585 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
2586 insert_breakpoints ();
2588 resume_ptid
= internal_resume_ptid (user_step
);
2589 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
2590 tp
->set_resumed (true);
2596 /* If we have a breakpoint to step over, make sure to do a single
2597 step only. Same if we have software watchpoints. */
2598 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2599 tp
->control
.may_range_step
= 0;
2601 /* If displaced stepping is enabled, step over breakpoints by executing a
2602 copy of the instruction at a different address.
2604 We can't use displaced stepping when we have a signal to deliver;
2605 the comments for displaced_step_prepare explain why. The
2606 comments in the handle_inferior event for dealing with 'random
2607 signals' explain what we do instead.
2609 We can't use displaced stepping when we are waiting for vfork_done
2610 event, displaced stepping breaks the vfork child similarly as single
2611 step software breakpoint. */
2612 if (tp
->control
.trap_expected
2613 && use_displaced_stepping (tp
)
2614 && !step_over_info_valid_p ()
2615 && sig
== GDB_SIGNAL_0
2616 && current_inferior ()->thread_waiting_for_vfork_done
== nullptr)
2618 displaced_step_prepare_status prepare_status
2619 = displaced_step_prepare (tp
);
2621 if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
2623 infrun_debug_printf ("Got placed in step-over queue");
2625 tp
->control
.trap_expected
= 0;
2628 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
2630 /* Fallback to stepping over the breakpoint in-line. */
2632 if (target_is_non_stop_p ())
2633 stop_all_threads ("displaced stepping falling back on inline stepping");
2635 set_step_over_info (regcache
->aspace (),
2636 regcache_read_pc (regcache
), 0, tp
->global_num
);
2638 step
= maybe_software_singlestep (gdbarch
);
2640 insert_breakpoints ();
2642 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_OK
)
2644 /* Update pc to reflect the new address from which we will
2645 execute instructions due to displaced stepping. */
2646 pc
= regcache_read_pc (get_thread_regcache (tp
));
2648 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
);
2651 gdb_assert_not_reached ("Invalid displaced_step_prepare_status "
2655 /* Do we need to do it the hard way, w/temp breakpoints? */
2657 step
= maybe_software_singlestep (gdbarch
);
2659 /* Currently, our software single-step implementation leads to different
2660 results than hardware single-stepping in one situation: when stepping
2661 into delivering a signal which has an associated signal handler,
2662 hardware single-step will stop at the first instruction of the handler,
2663 while software single-step will simply skip execution of the handler.
2665 For now, this difference in behavior is accepted since there is no
2666 easy way to actually implement single-stepping into a signal handler
2667 without kernel support.
2669 However, there is one scenario where this difference leads to follow-on
2670 problems: if we're stepping off a breakpoint by removing all breakpoints
2671 and then single-stepping. In this case, the software single-step
2672 behavior means that even if there is a *breakpoint* in the signal
2673 handler, GDB still would not stop.
2675 Fortunately, we can at least fix this particular issue. We detect
2676 here the case where we are about to deliver a signal while software
2677 single-stepping with breakpoints removed. In this situation, we
2678 revert the decisions to remove all breakpoints and insert single-
2679 step breakpoints, and instead we install a step-resume breakpoint
2680 at the current address, deliver the signal without stepping, and
2681 once we arrive back at the step-resume breakpoint, actually step
2682 over the breakpoint we originally wanted to step over. */
2683 if (thread_has_single_step_breakpoints_set (tp
)
2684 && sig
!= GDB_SIGNAL_0
2685 && step_over_info_valid_p ())
2687 /* If we have nested signals or a pending signal is delivered
2688 immediately after a handler returns, might already have
2689 a step-resume breakpoint set on the earlier handler. We cannot
2690 set another step-resume breakpoint; just continue on until the
2691 original breakpoint is hit. */
2692 if (tp
->control
.step_resume_breakpoint
== nullptr)
2694 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2695 tp
->step_after_step_resume_breakpoint
= 1;
2698 delete_single_step_breakpoints (tp
);
2700 clear_step_over_info ();
2701 tp
->control
.trap_expected
= 0;
2703 insert_breakpoints ();
2706 /* If STEP is set, it's a request to use hardware stepping
2707 facilities. But in that case, we should never
2708 use singlestep breakpoint. */
2709 gdb_assert (!(thread_has_single_step_breakpoints_set (tp
) && step
));
2711 /* Decide the set of threads to ask the target to resume. */
2712 if (tp
->control
.trap_expected
)
2714 /* We're allowing a thread to run past a breakpoint it has
2715 hit, either by single-stepping the thread with the breakpoint
2716 removed, or by displaced stepping, with the breakpoint inserted.
2717 In the former case, we need to single-step only this thread,
2718 and keep others stopped, as they can miss this breakpoint if
2719 allowed to run. That's not really a problem for displaced
2720 stepping, but, we still keep other threads stopped, in case
2721 another thread is also stopped for a breakpoint waiting for
2722 its turn in the displaced stepping queue. */
2723 resume_ptid
= inferior_ptid
;
2726 resume_ptid
= internal_resume_ptid (user_step
);
2728 if (execution_direction
!= EXEC_REVERSE
2729 && step
&& breakpoint_inserted_here_p (aspace
, pc
))
2731 /* There are two cases where we currently need to step a
2732 breakpoint instruction when we have a signal to deliver:
2734 - See handle_signal_stop where we handle random signals that
2735 could take out us out of the stepping range. Normally, in
2736 that case we end up continuing (instead of stepping) over the
2737 signal handler with a breakpoint at PC, but there are cases
2738 where we should _always_ single-step, even if we have a
2739 step-resume breakpoint, like when a software watchpoint is
2740 set. Assuming single-stepping and delivering a signal at the
2741 same time would takes us to the signal handler, then we could
2742 have removed the breakpoint at PC to step over it. However,
2743 some hardware step targets (like e.g., Mac OS) can't step
2744 into signal handlers, and for those, we need to leave the
2745 breakpoint at PC inserted, as otherwise if the handler
2746 recurses and executes PC again, it'll miss the breakpoint.
2747 So we leave the breakpoint inserted anyway, but we need to
2748 record that we tried to step a breakpoint instruction, so
2749 that adjust_pc_after_break doesn't end up confused.
2751 - In non-stop if we insert a breakpoint (e.g., a step-resume)
2752 in one thread after another thread that was stepping had been
2753 momentarily paused for a step-over. When we re-resume the
2754 stepping thread, it may be resumed from that address with a
2755 breakpoint that hasn't trapped yet. Seen with
2756 gdb.threads/non-stop-fair-events.exp, on targets that don't
2757 do displaced stepping. */
2759 infrun_debug_printf ("resume: [%s] stepped breakpoint",
2760 tp
->ptid
.to_string ().c_str ());
2762 tp
->stepped_breakpoint
= 1;
2764 /* Most targets can step a breakpoint instruction, thus
2765 executing it normally. But if this one cannot, just
2766 continue and we will hit it anyway. */
2767 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2771 if (tp
->control
.may_range_step
)
2773 /* If we're resuming a thread with the PC out of the step
2774 range, then we're doing some nested/finer run control
2775 operation, like stepping the thread out of the dynamic
2776 linker or the displaced stepping scratch pad. We
2777 shouldn't have allowed a range step then. */
2778 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2781 do_target_resume (resume_ptid
, step
, sig
);
2782 tp
->set_resumed (true);
2785 /* Resume the inferior. SIG is the signal to give the inferior
2786 (GDB_SIGNAL_0 for none). This is a wrapper around 'resume_1' that
2787 rolls back state on error. */
2790 resume (gdb_signal sig
)
2796 catch (const gdb_exception
&ex
)
2798 /* If resuming is being aborted for any reason, delete any
2799 single-step breakpoint resume_1 may have created, to avoid
2800 confusing the following resumption, and to avoid leaving
2801 single-step breakpoints perturbing other threads, in case
2802 we're running in non-stop mode. */
2803 if (inferior_ptid
!= null_ptid
)
2804 delete_single_step_breakpoints (inferior_thread ());
2814 /* Counter that tracks number of user visible stops. This can be used
2815 to tell whether a command has proceeded the inferior past the
2816 current location. This allows e.g., inferior function calls in
2817 breakpoint commands to not interrupt the command list. When the
2818 call finishes successfully, the inferior is standing at the same
2819 breakpoint as if nothing happened (and so we don't call
2821 static ULONGEST current_stop_id
;
2828 return current_stop_id
;
2831 /* Called when we report a user visible stop. */
2839 /* Clear out all variables saying what to do when inferior is continued.
2840 First do this, then set the ones you want, then call `proceed'. */
2843 clear_proceed_status_thread (struct thread_info
*tp
)
2845 infrun_debug_printf ("%s", tp
->ptid
.to_string ().c_str ());
2847 /* If we're starting a new sequence, then the previous finished
2848 single-step is no longer relevant. */
2849 if (tp
->has_pending_waitstatus ())
2851 if (tp
->stop_reason () == TARGET_STOPPED_BY_SINGLE_STEP
)
2853 infrun_debug_printf ("pending event of %s was a finished step. "
2855 tp
->ptid
.to_string ().c_str ());
2857 tp
->clear_pending_waitstatus ();
2858 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
2863 ("thread %s has pending wait status %s (currently_stepping=%d).",
2864 tp
->ptid
.to_string ().c_str (),
2865 tp
->pending_waitstatus ().to_string ().c_str (),
2866 currently_stepping (tp
));
2870 /* If this signal should not be seen by program, give it zero.
2871 Used for debugging signals. */
2872 if (!signal_pass_state (tp
->stop_signal ()))
2873 tp
->set_stop_signal (GDB_SIGNAL_0
);
2875 tp
->release_thread_fsm ();
2877 tp
->control
.trap_expected
= 0;
2878 tp
->control
.step_range_start
= 0;
2879 tp
->control
.step_range_end
= 0;
2880 tp
->control
.may_range_step
= 0;
2881 tp
->control
.step_frame_id
= null_frame_id
;
2882 tp
->control
.step_stack_frame_id
= null_frame_id
;
2883 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2884 tp
->control
.step_start_function
= nullptr;
2885 tp
->stop_requested
= 0;
2887 tp
->control
.stop_step
= 0;
2889 tp
->control
.proceed_to_finish
= 0;
2891 tp
->control
.stepping_command
= 0;
2893 /* Discard any remaining commands or status from previous stop. */
2894 bpstat_clear (&tp
->control
.stop_bpstat
);
2898 clear_proceed_status (int step
)
2900 /* With scheduler-locking replay, stop replaying other threads if we're
2901 not replaying the user-visible resume ptid.
2903 This is a convenience feature to not require the user to explicitly
2904 stop replaying the other threads. We're assuming that the user's
2905 intent is to resume tracing the recorded process. */
2906 if (!non_stop
&& scheduler_mode
== schedlock_replay
2907 && target_record_is_replaying (minus_one_ptid
)
2908 && !target_record_will_replay (user_visible_resume_ptid (step
),
2909 execution_direction
))
2910 target_record_stop_replaying ();
2912 if (!non_stop
&& inferior_ptid
!= null_ptid
)
2914 ptid_t resume_ptid
= user_visible_resume_ptid (step
);
2915 process_stratum_target
*resume_target
2916 = user_visible_resume_target (resume_ptid
);
2918 /* In all-stop mode, delete the per-thread status of all threads
2919 we're about to resume, implicitly and explicitly. */
2920 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
2921 clear_proceed_status_thread (tp
);
2924 if (inferior_ptid
!= null_ptid
)
2926 struct inferior
*inferior
;
2930 /* If in non-stop mode, only delete the per-thread status of
2931 the current thread. */
2932 clear_proceed_status_thread (inferior_thread ());
2935 inferior
= current_inferior ();
2936 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2939 gdb::observers::about_to_proceed
.notify ();
2942 /* Returns true if TP is still stopped at a breakpoint that needs
2943 stepping-over in order to make progress. If the breakpoint is gone
2944 meanwhile, we can skip the whole step-over dance. */
2947 thread_still_needs_step_over_bp (struct thread_info
*tp
)
2949 if (tp
->stepping_over_breakpoint
)
2951 struct regcache
*regcache
= get_thread_regcache (tp
);
2953 if (breakpoint_here_p (regcache
->aspace (),
2954 regcache_read_pc (regcache
))
2955 == ordinary_breakpoint_here
)
2958 tp
->stepping_over_breakpoint
= 0;
2964 /* Check whether thread TP still needs to start a step-over in order
2965 to make progress when resumed. Returns an bitwise or of enum
2966 step_over_what bits, indicating what needs to be stepped over. */
2968 static step_over_what
2969 thread_still_needs_step_over (struct thread_info
*tp
)
2971 step_over_what what
= 0;
2973 if (thread_still_needs_step_over_bp (tp
))
2974 what
|= STEP_OVER_BREAKPOINT
;
2976 if (tp
->stepping_over_watchpoint
2977 && !target_have_steppable_watchpoint ())
2978 what
|= STEP_OVER_WATCHPOINT
;
2983 /* Returns true if scheduler locking applies. STEP indicates whether
2984 we're about to do a step/next-like command to a thread. */
2987 schedlock_applies (struct thread_info
*tp
)
2989 return (scheduler_mode
== schedlock_on
2990 || (scheduler_mode
== schedlock_step
2991 && tp
->control
.stepping_command
)
2992 || (scheduler_mode
== schedlock_replay
2993 && target_record_will_replay (minus_one_ptid
,
2994 execution_direction
)));
2997 /* Set process_stratum_target::COMMIT_RESUMED_STATE in all target
2998 stacks that have threads executing and don't have threads with
3002 maybe_set_commit_resumed_all_targets ()
3004 scoped_restore_current_thread restore_thread
;
3006 for (inferior
*inf
: all_non_exited_inferiors ())
3008 process_stratum_target
*proc_target
= inf
->process_target ();
3010 if (proc_target
->commit_resumed_state
)
3012 /* We already set this in a previous iteration, via another
3013 inferior sharing the process_stratum target. */
3017 /* If the target has no resumed threads, it would be useless to
3018 ask it to commit the resumed threads. */
3019 if (!proc_target
->threads_executing
)
3021 infrun_debug_printf ("not requesting commit-resumed for target "
3022 "%s, no resumed threads",
3023 proc_target
->shortname ());
3027 /* As an optimization, if a thread from this target has some
3028 status to report, handle it before requiring the target to
3029 commit its resumed threads: handling the status might lead to
3030 resuming more threads. */
3031 if (proc_target
->has_resumed_with_pending_wait_status ())
3033 infrun_debug_printf ("not requesting commit-resumed for target %s, a"
3034 " thread has a pending waitstatus",
3035 proc_target
->shortname ());
3039 switch_to_inferior_no_thread (inf
);
3041 if (target_has_pending_events ())
3043 infrun_debug_printf ("not requesting commit-resumed for target %s, "
3044 "target has pending events",
3045 proc_target
->shortname ());
3049 infrun_debug_printf ("enabling commit-resumed for target %s",
3050 proc_target
->shortname ());
3052 proc_target
->commit_resumed_state
= true;
3059 maybe_call_commit_resumed_all_targets ()
3061 scoped_restore_current_thread restore_thread
;
3063 for (inferior
*inf
: all_non_exited_inferiors ())
3065 process_stratum_target
*proc_target
= inf
->process_target ();
3067 if (!proc_target
->commit_resumed_state
)
3070 switch_to_inferior_no_thread (inf
);
3072 infrun_debug_printf ("calling commit_resumed for target %s",
3073 proc_target
->shortname());
3075 target_commit_resumed ();
3079 /* To track nesting of scoped_disable_commit_resumed objects, ensuring
3080 that only the outermost one attempts to re-enable
3082 static bool enable_commit_resumed
= true;
3086 scoped_disable_commit_resumed::scoped_disable_commit_resumed
3087 (const char *reason
)
3088 : m_reason (reason
),
3089 m_prev_enable_commit_resumed (enable_commit_resumed
)
3091 infrun_debug_printf ("reason=%s", m_reason
);
3093 enable_commit_resumed
= false;
3095 for (inferior
*inf
: all_non_exited_inferiors ())
3097 process_stratum_target
*proc_target
= inf
->process_target ();
3099 if (m_prev_enable_commit_resumed
)
3101 /* This is the outermost instance: force all
3102 COMMIT_RESUMED_STATE to false. */
3103 proc_target
->commit_resumed_state
= false;
3107 /* This is not the outermost instance, we expect
3108 COMMIT_RESUMED_STATE to have been cleared by the
3109 outermost instance. */
3110 gdb_assert (!proc_target
->commit_resumed_state
);
3118 scoped_disable_commit_resumed::reset ()
3124 infrun_debug_printf ("reason=%s", m_reason
);
3126 gdb_assert (!enable_commit_resumed
);
3128 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3130 if (m_prev_enable_commit_resumed
)
3132 /* This is the outermost instance, re-enable
3133 COMMIT_RESUMED_STATE on the targets where it's possible. */
3134 maybe_set_commit_resumed_all_targets ();
3138 /* This is not the outermost instance, we expect
3139 COMMIT_RESUMED_STATE to still be false. */
3140 for (inferior
*inf
: all_non_exited_inferiors ())
3142 process_stratum_target
*proc_target
= inf
->process_target ();
3143 gdb_assert (!proc_target
->commit_resumed_state
);
3150 scoped_disable_commit_resumed::~scoped_disable_commit_resumed ()
3158 scoped_disable_commit_resumed::reset_and_commit ()
3161 maybe_call_commit_resumed_all_targets ();
3166 scoped_enable_commit_resumed::scoped_enable_commit_resumed
3167 (const char *reason
)
3168 : m_reason (reason
),
3169 m_prev_enable_commit_resumed (enable_commit_resumed
)
3171 infrun_debug_printf ("reason=%s", m_reason
);
3173 if (!enable_commit_resumed
)
3175 enable_commit_resumed
= true;
3177 /* Re-enable COMMIT_RESUMED_STATE on the targets where it's
3179 maybe_set_commit_resumed_all_targets ();
3181 maybe_call_commit_resumed_all_targets ();
3187 scoped_enable_commit_resumed::~scoped_enable_commit_resumed ()
3189 infrun_debug_printf ("reason=%s", m_reason
);
3191 gdb_assert (enable_commit_resumed
);
3193 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3195 if (!enable_commit_resumed
)
3197 /* Force all COMMIT_RESUMED_STATE back to false. */
3198 for (inferior
*inf
: all_non_exited_inferiors ())
3200 process_stratum_target
*proc_target
= inf
->process_target ();
3201 proc_target
->commit_resumed_state
= false;
3206 /* Check that all the targets we're about to resume are in non-stop
3207 mode. Ideally, we'd only care whether all targets support
3208 target-async, but we're not there yet. E.g., stop_all_threads
3209 doesn't know how to handle all-stop targets. Also, the remote
3210 protocol in all-stop mode is synchronous, irrespective of
3211 target-async, which means that things like a breakpoint re-set
3212 triggered by one target would try to read memory from all targets
3216 check_multi_target_resumption (process_stratum_target
*resume_target
)
3218 if (!non_stop
&& resume_target
== nullptr)
3220 scoped_restore_current_thread restore_thread
;
3222 /* This is used to track whether we're resuming more than one
3224 process_stratum_target
*first_connection
= nullptr;
3226 /* The first inferior we see with a target that does not work in
3227 always-non-stop mode. */
3228 inferior
*first_not_non_stop
= nullptr;
3230 for (inferior
*inf
: all_non_exited_inferiors ())
3232 switch_to_inferior_no_thread (inf
);
3234 if (!target_has_execution ())
3237 process_stratum_target
*proc_target
3238 = current_inferior ()->process_target();
3240 if (!target_is_non_stop_p ())
3241 first_not_non_stop
= inf
;
3243 if (first_connection
== nullptr)
3244 first_connection
= proc_target
;
3245 else if (first_connection
!= proc_target
3246 && first_not_non_stop
!= nullptr)
3248 switch_to_inferior_no_thread (first_not_non_stop
);
3250 proc_target
= current_inferior ()->process_target();
3252 error (_("Connection %d (%s) does not support "
3253 "multi-target resumption."),
3254 proc_target
->connection_number
,
3255 make_target_connection_string (proc_target
).c_str ());
3261 /* Basic routine for continuing the program in various fashions.
3263 ADDR is the address to resume at, or -1 for resume where stopped.
3264 SIGGNAL is the signal to give it, or GDB_SIGNAL_0 for none,
3265 or GDB_SIGNAL_DEFAULT for act according to how it stopped.
3267 You should call clear_proceed_status before calling proceed. */
3270 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
)
3272 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
3274 struct regcache
*regcache
;
3275 struct gdbarch
*gdbarch
;
3278 /* If we're stopped at a fork/vfork, follow the branch set by the
3279 "set follow-fork-mode" command; otherwise, we'll just proceed
3280 resuming the current thread. */
3281 if (!follow_fork ())
3283 /* The target for some reason decided not to resume. */
3285 if (target_can_async_p ())
3286 inferior_event_handler (INF_EXEC_COMPLETE
);
3290 /* We'll update this if & when we switch to a new thread. */
3291 update_previous_thread ();
3293 regcache
= get_current_regcache ();
3294 gdbarch
= regcache
->arch ();
3295 const address_space
*aspace
= regcache
->aspace ();
3297 pc
= regcache_read_pc_protected (regcache
);
3299 thread_info
*cur_thr
= inferior_thread ();
3301 /* Fill in with reasonable starting values. */
3302 init_thread_stepping_state (cur_thr
);
3304 gdb_assert (!thread_is_in_step_over_chain (cur_thr
));
3307 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
3308 process_stratum_target
*resume_target
3309 = user_visible_resume_target (resume_ptid
);
3311 check_multi_target_resumption (resume_target
);
3313 if (addr
== (CORE_ADDR
) -1)
3315 if (cur_thr
->stop_pc_p ()
3316 && pc
== cur_thr
->stop_pc ()
3317 && breakpoint_here_p (aspace
, pc
) == ordinary_breakpoint_here
3318 && execution_direction
!= EXEC_REVERSE
)
3319 /* There is a breakpoint at the address we will resume at,
3320 step one instruction before inserting breakpoints so that
3321 we do not stop right away (and report a second hit at this
3324 Note, we don't do this in reverse, because we won't
3325 actually be executing the breakpoint insn anyway.
3326 We'll be (un-)executing the previous instruction. */
3327 cur_thr
->stepping_over_breakpoint
= 1;
3328 else if (gdbarch_single_step_through_delay_p (gdbarch
)
3329 && gdbarch_single_step_through_delay (gdbarch
,
3330 get_current_frame ()))
3331 /* We stepped onto an instruction that needs to be stepped
3332 again before re-inserting the breakpoint, do so. */
3333 cur_thr
->stepping_over_breakpoint
= 1;
3337 regcache_write_pc (regcache
, addr
);
3340 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
3341 cur_thr
->set_stop_signal (siggnal
);
3343 /* If an exception is thrown from this point on, make sure to
3344 propagate GDB's knowledge of the executing state to the
3345 frontend/user running state. */
3346 scoped_finish_thread_state
finish_state (resume_target
, resume_ptid
);
3348 /* Even if RESUME_PTID is a wildcard, and we end up resuming fewer
3349 threads (e.g., we might need to set threads stepping over
3350 breakpoints first), from the user/frontend's point of view, all
3351 threads in RESUME_PTID are now running. Unless we're calling an
3352 inferior function, as in that case we pretend the inferior
3353 doesn't run at all. */
3354 if (!cur_thr
->control
.in_infcall
)
3355 set_running (resume_target
, resume_ptid
, true);
3357 infrun_debug_printf ("addr=%s, signal=%s", paddress (gdbarch
, addr
),
3358 gdb_signal_to_symbol_string (siggnal
));
3360 annotate_starting ();
3362 /* Make sure that output from GDB appears before output from the
3364 gdb_flush (gdb_stdout
);
3366 /* Since we've marked the inferior running, give it the terminal. A
3367 QUIT/Ctrl-C from here on is forwarded to the target (which can
3368 still detect attempts to unblock a stuck connection with repeated
3369 Ctrl-C from within target_pass_ctrlc). */
3370 target_terminal::inferior ();
3372 /* In a multi-threaded task we may select another thread and
3373 then continue or step.
3375 But if a thread that we're resuming had stopped at a breakpoint,
3376 it will immediately cause another breakpoint stop without any
3377 execution (i.e. it will report a breakpoint hit incorrectly). So
3378 we must step over it first.
3380 Look for threads other than the current (TP) that reported a
3381 breakpoint hit and haven't been resumed yet since. */
3383 /* If scheduler locking applies, we can avoid iterating over all
3385 if (!non_stop
&& !schedlock_applies (cur_thr
))
3387 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3390 switch_to_thread_no_regs (tp
);
3392 /* Ignore the current thread here. It's handled
3397 if (!thread_still_needs_step_over (tp
))
3400 gdb_assert (!thread_is_in_step_over_chain (tp
));
3402 infrun_debug_printf ("need to step-over [%s] first",
3403 tp
->ptid
.to_string ().c_str ());
3405 global_thread_step_over_chain_enqueue (tp
);
3408 switch_to_thread (cur_thr
);
3411 /* Enqueue the current thread last, so that we move all other
3412 threads over their breakpoints first. */
3413 if (cur_thr
->stepping_over_breakpoint
)
3414 global_thread_step_over_chain_enqueue (cur_thr
);
3416 /* If the thread isn't started, we'll still need to set its prev_pc,
3417 so that switch_back_to_stepped_thread knows the thread hasn't
3418 advanced. Must do this before resuming any thread, as in
3419 all-stop/remote, once we resume we can't send any other packet
3420 until the target stops again. */
3421 cur_thr
->prev_pc
= regcache_read_pc_protected (regcache
);
3424 scoped_disable_commit_resumed
disable_commit_resumed ("proceeding");
3425 bool step_over_started
= start_step_over ();
3427 if (step_over_info_valid_p ())
3429 /* Either this thread started a new in-line step over, or some
3430 other thread was already doing one. In either case, don't
3431 resume anything else until the step-over is finished. */
3433 else if (step_over_started
&& !target_is_non_stop_p ())
3435 /* A new displaced stepping sequence was started. In all-stop,
3436 we can't talk to the target anymore until it next stops. */
3438 else if (!non_stop
&& target_is_non_stop_p ())
3440 INFRUN_SCOPED_DEBUG_START_END
3441 ("resuming threads, all-stop-on-top-of-non-stop");
3443 /* In all-stop, but the target is always in non-stop mode.
3444 Start all other threads that are implicitly resumed too. */
3445 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3448 switch_to_thread_no_regs (tp
);
3450 if (!tp
->inf
->has_execution ())
3452 infrun_debug_printf ("[%s] target has no execution",
3453 tp
->ptid
.to_string ().c_str ());
3459 infrun_debug_printf ("[%s] resumed",
3460 tp
->ptid
.to_string ().c_str ());
3461 gdb_assert (tp
->executing () || tp
->has_pending_waitstatus ());
3465 if (thread_is_in_step_over_chain (tp
))
3467 infrun_debug_printf ("[%s] needs step-over",
3468 tp
->ptid
.to_string ().c_str ());
3472 /* If a thread of that inferior is waiting for a vfork-done
3473 (for a detached vfork child to exec or exit), breakpoints are
3474 removed. We must not resume any thread of that inferior, other
3475 than the one waiting for the vfork-done. */
3476 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr
3477 && tp
!= tp
->inf
->thread_waiting_for_vfork_done
)
3479 infrun_debug_printf ("[%s] another thread of this inferior is "
3480 "waiting for vfork-done",
3481 tp
->ptid
.to_string ().c_str ());
3485 infrun_debug_printf ("resuming %s",
3486 tp
->ptid
.to_string ().c_str ());
3488 execution_control_state
ecs (tp
);
3489 switch_to_thread (tp
);
3490 keep_going_pass_signal (&ecs
);
3491 if (!ecs
.wait_some_more
)
3492 error (_("Command aborted."));
3495 else if (!cur_thr
->resumed ()
3496 && !thread_is_in_step_over_chain (cur_thr
)
3497 /* In non-stop, forbid resuming a thread if some other thread of
3498 that inferior is waiting for a vfork-done event (this means
3499 breakpoints are out for this inferior). */
3501 && cur_thr
->inf
->thread_waiting_for_vfork_done
!= nullptr))
3503 /* The thread wasn't started, and isn't queued, run it now. */
3504 execution_control_state
ecs (cur_thr
);
3505 switch_to_thread (cur_thr
);
3506 keep_going_pass_signal (&ecs
);
3507 if (!ecs
.wait_some_more
)
3508 error (_("Command aborted."));
3511 disable_commit_resumed
.reset_and_commit ();
3514 finish_state
.release ();
3516 /* If we've switched threads above, switch back to the previously
3517 current thread. We don't want the user to see a different
3519 switch_to_thread (cur_thr
);
3521 /* Tell the event loop to wait for it to stop. If the target
3522 supports asynchronous execution, it'll do this from within
3524 if (!target_can_async_p ())
3525 mark_async_event_handler (infrun_async_inferior_event_token
);
3529 /* Start remote-debugging of a machine over a serial link. */
3532 start_remote (int from_tty
)
3534 inferior
*inf
= current_inferior ();
3535 inf
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
3537 /* Always go on waiting for the target, regardless of the mode. */
3538 /* FIXME: cagney/1999-09-23: At present it isn't possible to
3539 indicate to wait_for_inferior that a target should timeout if
3540 nothing is returned (instead of just blocking). Because of this,
3541 targets expecting an immediate response need to, internally, set
3542 things up so that the target_wait() is forced to eventually
3544 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
3545 differentiate to its caller what the state of the target is after
3546 the initial open has been performed. Here we're assuming that
3547 the target has stopped. It should be possible to eventually have
3548 target_open() return to the caller an indication that the target
3549 is currently running and GDB state should be set to the same as
3550 for an async run. */
3551 wait_for_inferior (inf
);
3553 /* Now that the inferior has stopped, do any bookkeeping like
3554 loading shared libraries. We want to do this before normal_stop,
3555 so that the displayed frame is up to date. */
3556 post_create_inferior (from_tty
);
3561 /* Initialize static vars when a new inferior begins. */
3564 init_wait_for_inferior (void)
3566 /* These are meaningless until the first time through wait_for_inferior. */
3568 breakpoint_init_inferior (inf_starting
);
3570 clear_proceed_status (0);
3572 nullify_last_target_wait_ptid ();
3574 update_previous_thread ();
3579 static void handle_inferior_event (struct execution_control_state
*ecs
);
3581 static void handle_step_into_function (struct gdbarch
*gdbarch
,
3582 struct execution_control_state
*ecs
);
3583 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
3584 struct execution_control_state
*ecs
);
3585 static void handle_signal_stop (struct execution_control_state
*ecs
);
3586 static void check_exception_resume (struct execution_control_state
*,
3589 static void end_stepping_range (struct execution_control_state
*ecs
);
3590 static void stop_waiting (struct execution_control_state
*ecs
);
3591 static void keep_going (struct execution_control_state
*ecs
);
3592 static void process_event_stop_test (struct execution_control_state
*ecs
);
3593 static bool switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
3595 /* This function is attached as a "thread_stop_requested" observer.
3596 Cleanup local state that assumed the PTID was to be resumed, and
3597 report the stop to the frontend. */
3600 infrun_thread_stop_requested (ptid_t ptid
)
3602 process_stratum_target
*curr_target
= current_inferior ()->process_target ();
3604 /* PTID was requested to stop. If the thread was already stopped,
3605 but the user/frontend doesn't know about that yet (e.g., the
3606 thread had been temporarily paused for some step-over), set up
3607 for reporting the stop now. */
3608 for (thread_info
*tp
: all_threads (curr_target
, ptid
))
3610 if (tp
->state
!= THREAD_RUNNING
)
3612 if (tp
->executing ())
3615 /* Remove matching threads from the step-over queue, so
3616 start_step_over doesn't try to resume them
3618 if (thread_is_in_step_over_chain (tp
))
3619 global_thread_step_over_chain_remove (tp
);
3621 /* If the thread is stopped, but the user/frontend doesn't
3622 know about that yet, queue a pending event, as if the
3623 thread had just stopped now. Unless the thread already had
3625 if (!tp
->has_pending_waitstatus ())
3627 target_waitstatus ws
;
3628 ws
.set_stopped (GDB_SIGNAL_0
);
3629 tp
->set_pending_waitstatus (ws
);
3632 /* Clear the inline-frame state, since we're re-processing the
3634 clear_inline_frame_state (tp
);
3636 /* If this thread was paused because some other thread was
3637 doing an inline-step over, let that finish first. Once
3638 that happens, we'll restart all threads and consume pending
3639 stop events then. */
3640 if (step_over_info_valid_p ())
3643 /* Otherwise we can process the (new) pending event now. Set
3644 it so this pending event is considered by
3646 tp
->set_resumed (true);
3650 /* Delete the step resume, single-step and longjmp/exception resume
3651 breakpoints of TP. */
3654 delete_thread_infrun_breakpoints (struct thread_info
*tp
)
3656 delete_step_resume_breakpoint (tp
);
3657 delete_exception_resume_breakpoint (tp
);
3658 delete_single_step_breakpoints (tp
);
3661 /* If the target still has execution, call FUNC for each thread that
3662 just stopped. In all-stop, that's all the non-exited threads; in
3663 non-stop, that's the current thread, only. */
3665 typedef void (*for_each_just_stopped_thread_callback_func
)
3666 (struct thread_info
*tp
);
3669 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func
)
3671 if (!target_has_execution () || inferior_ptid
== null_ptid
)
3674 if (target_is_non_stop_p ())
3676 /* If in non-stop mode, only the current thread stopped. */
3677 func (inferior_thread ());
3681 /* In all-stop mode, all threads have stopped. */
3682 for (thread_info
*tp
: all_non_exited_threads ())
3687 /* Delete the step resume and longjmp/exception resume breakpoints of
3688 the threads that just stopped. */
3691 delete_just_stopped_threads_infrun_breakpoints (void)
3693 for_each_just_stopped_thread (delete_thread_infrun_breakpoints
);
3696 /* Delete the single-step breakpoints of the threads that just
3700 delete_just_stopped_threads_single_step_breakpoints (void)
3702 for_each_just_stopped_thread (delete_single_step_breakpoints
);
3708 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
3709 const struct target_waitstatus
&ws
)
3711 infrun_debug_printf ("target_wait (%s [%s], status) =",
3712 waiton_ptid
.to_string ().c_str (),
3713 target_pid_to_str (waiton_ptid
).c_str ());
3714 infrun_debug_printf (" %s [%s],",
3715 result_ptid
.to_string ().c_str (),
3716 target_pid_to_str (result_ptid
).c_str ());
3717 infrun_debug_printf (" %s", ws
.to_string ().c_str ());
3720 /* Select a thread at random, out of those which are resumed and have
3723 static struct thread_info
*
3724 random_pending_event_thread (inferior
*inf
, ptid_t waiton_ptid
)
3726 process_stratum_target
*proc_target
= inf
->process_target ();
3728 = proc_target
->random_resumed_with_pending_wait_status (inf
, waiton_ptid
);
3730 if (thread
== nullptr)
3732 infrun_debug_printf ("None found.");
3736 infrun_debug_printf ("Found %s.", thread
->ptid
.to_string ().c_str ());
3737 gdb_assert (thread
->resumed ());
3738 gdb_assert (thread
->has_pending_waitstatus ());
3743 /* Wrapper for target_wait that first checks whether threads have
3744 pending statuses to report before actually asking the target for
3745 more events. INF is the inferior we're using to call target_wait
3749 do_target_wait_1 (inferior
*inf
, ptid_t ptid
,
3750 target_waitstatus
*status
, target_wait_flags options
)
3752 struct thread_info
*tp
;
3754 /* We know that we are looking for an event in the target of inferior
3755 INF, but we don't know which thread the event might come from. As
3756 such we want to make sure that INFERIOR_PTID is reset so that none of
3757 the wait code relies on it - doing so is always a mistake. */
3758 switch_to_inferior_no_thread (inf
);
3760 /* First check if there is a resumed thread with a wait status
3762 if (ptid
== minus_one_ptid
|| ptid
.is_pid ())
3764 tp
= random_pending_event_thread (inf
, ptid
);
3768 infrun_debug_printf ("Waiting for specific thread %s.",
3769 ptid
.to_string ().c_str ());
3771 /* We have a specific thread to check. */
3772 tp
= inf
->find_thread (ptid
);
3773 gdb_assert (tp
!= nullptr);
3774 if (!tp
->has_pending_waitstatus ())
3779 && (tp
->stop_reason () == TARGET_STOPPED_BY_SW_BREAKPOINT
3780 || tp
->stop_reason () == TARGET_STOPPED_BY_HW_BREAKPOINT
))
3782 struct regcache
*regcache
= get_thread_regcache (tp
);
3783 struct gdbarch
*gdbarch
= regcache
->arch ();
3787 pc
= regcache_read_pc (regcache
);
3789 if (pc
!= tp
->stop_pc ())
3791 infrun_debug_printf ("PC of %s changed. was=%s, now=%s",
3792 tp
->ptid
.to_string ().c_str (),
3793 paddress (gdbarch
, tp
->stop_pc ()),
3794 paddress (gdbarch
, pc
));
3797 else if (!breakpoint_inserted_here_p (regcache
->aspace (), pc
))
3799 infrun_debug_printf ("previous breakpoint of %s, at %s gone",
3800 tp
->ptid
.to_string ().c_str (),
3801 paddress (gdbarch
, pc
));
3808 infrun_debug_printf ("pending event of %s cancelled.",
3809 tp
->ptid
.to_string ().c_str ());
3811 tp
->clear_pending_waitstatus ();
3812 target_waitstatus ws
;
3814 tp
->set_pending_waitstatus (ws
);
3815 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
3821 infrun_debug_printf ("Using pending wait status %s for %s.",
3822 tp
->pending_waitstatus ().to_string ().c_str (),
3823 tp
->ptid
.to_string ().c_str ());
3825 /* Now that we've selected our final event LWP, un-adjust its PC
3826 if it was a software breakpoint (and the target doesn't
3827 always adjust the PC itself). */
3828 if (tp
->stop_reason () == TARGET_STOPPED_BY_SW_BREAKPOINT
3829 && !target_supports_stopped_by_sw_breakpoint ())
3831 struct regcache
*regcache
;
3832 struct gdbarch
*gdbarch
;
3835 regcache
= get_thread_regcache (tp
);
3836 gdbarch
= regcache
->arch ();
3838 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
3843 pc
= regcache_read_pc (regcache
);
3844 regcache_write_pc (regcache
, pc
+ decr_pc
);
3848 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
3849 *status
= tp
->pending_waitstatus ();
3850 tp
->clear_pending_waitstatus ();
3852 /* Wake up the event loop again, until all pending events are
3854 if (target_is_async_p ())
3855 mark_async_event_handler (infrun_async_inferior_event_token
);
3859 /* But if we don't find one, we'll have to wait. */
3861 /* We can't ask a non-async target to do a non-blocking wait, so this will be
3863 if (!target_can_async_p ())
3864 options
&= ~TARGET_WNOHANG
;
3866 return target_wait (ptid
, status
, options
);
3869 /* Wrapper for target_wait that first checks whether threads have
3870 pending statuses to report before actually asking the target for
3871 more events. Polls for events from all inferiors/targets. */
3874 do_target_wait (execution_control_state
*ecs
, target_wait_flags options
)
3876 int num_inferiors
= 0;
3877 int random_selector
;
3879 /* For fairness, we pick the first inferior/target to poll at random
3880 out of all inferiors that may report events, and then continue
3881 polling the rest of the inferior list starting from that one in a
3882 circular fashion until the whole list is polled once. */
3884 auto inferior_matches
= [] (inferior
*inf
)
3886 return inf
->process_target () != nullptr;
3889 /* First see how many matching inferiors we have. */
3890 for (inferior
*inf
: all_inferiors ())
3891 if (inferior_matches (inf
))
3894 if (num_inferiors
== 0)
3896 ecs
->ws
.set_ignore ();
3900 /* Now randomly pick an inferior out of those that matched. */
3901 random_selector
= (int)
3902 ((num_inferiors
* (double) rand ()) / (RAND_MAX
+ 1.0));
3904 if (num_inferiors
> 1)
3905 infrun_debug_printf ("Found %d inferiors, starting at #%d",
3906 num_inferiors
, random_selector
);
3908 /* Select the Nth inferior that matched. */
3910 inferior
*selected
= nullptr;
3912 for (inferior
*inf
: all_inferiors ())
3913 if (inferior_matches (inf
))
3914 if (random_selector
-- == 0)
3920 /* Now poll for events out of each of the matching inferior's
3921 targets, starting from the selected one. */
3923 auto do_wait
= [&] (inferior
*inf
)
3925 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, options
);
3926 ecs
->target
= inf
->process_target ();
3927 return (ecs
->ws
.kind () != TARGET_WAITKIND_IGNORE
);
3930 /* Needed in 'all-stop + target-non-stop' mode, because we end up
3931 here spuriously after the target is all stopped and we've already
3932 reported the stop to the user, polling for events. */
3933 scoped_restore_current_thread restore_thread
;
3935 intrusive_list_iterator
<inferior
> start
3936 = inferior_list
.iterator_to (*selected
);
3938 for (intrusive_list_iterator
<inferior
> it
= start
;
3939 it
!= inferior_list
.end ();
3942 inferior
*inf
= &*it
;
3944 if (inferior_matches (inf
) && do_wait (inf
))
3948 for (intrusive_list_iterator
<inferior
> it
= inferior_list
.begin ();
3952 inferior
*inf
= &*it
;
3954 if (inferior_matches (inf
) && do_wait (inf
))
3958 ecs
->ws
.set_ignore ();
3962 /* An event reported by wait_one. */
3964 struct wait_one_event
3966 /* The target the event came out of. */
3967 process_stratum_target
*target
;
3969 /* The PTID the event was for. */
3972 /* The waitstatus. */
3973 target_waitstatus ws
;
3976 static bool handle_one (const wait_one_event
&event
);
3978 /* Prepare and stabilize the inferior for detaching it. E.g.,
3979 detaching while a thread is displaced stepping is a recipe for
3980 crashing it, as nothing would readjust the PC out of the scratch
3984 prepare_for_detach (void)
3986 struct inferior
*inf
= current_inferior ();
3987 ptid_t pid_ptid
= ptid_t (inf
->pid
);
3988 scoped_restore_current_thread restore_thread
;
3990 scoped_restore restore_detaching
= make_scoped_restore (&inf
->detaching
, true);
3992 /* Remove all threads of INF from the global step-over chain. We
3993 want to stop any ongoing step-over, not start any new one. */
3994 thread_step_over_list_safe_range range
3995 = make_thread_step_over_list_safe_range (global_thread_step_over_list
);
3997 for (thread_info
*tp
: range
)
4000 infrun_debug_printf ("removing thread %s from global step over chain",
4001 tp
->ptid
.to_string ().c_str ());
4002 global_thread_step_over_chain_remove (tp
);
4005 /* If we were already in the middle of an inline step-over, and the
4006 thread stepping belongs to the inferior we're detaching, we need
4007 to restart the threads of other inferiors. */
4008 if (step_over_info
.thread
!= -1)
4010 infrun_debug_printf ("inline step-over in-process while detaching");
4012 thread_info
*thr
= find_thread_global_id (step_over_info
.thread
);
4013 if (thr
->inf
== inf
)
4015 /* Since we removed threads of INF from the step-over chain,
4016 we know this won't start a step-over for INF. */
4017 clear_step_over_info ();
4019 if (target_is_non_stop_p ())
4021 /* Start a new step-over in another thread if there's
4022 one that needs it. */
4025 /* Restart all other threads (except the
4026 previously-stepping thread, since that one is still
4028 if (!step_over_info_valid_p ())
4029 restart_threads (thr
);
4034 if (displaced_step_in_progress (inf
))
4036 infrun_debug_printf ("displaced-stepping in-process while detaching");
4038 /* Stop threads currently displaced stepping, aborting it. */
4040 for (thread_info
*thr
: inf
->non_exited_threads ())
4042 if (thr
->displaced_step_state
.in_progress ())
4044 if (thr
->executing ())
4046 if (!thr
->stop_requested
)
4048 target_stop (thr
->ptid
);
4049 thr
->stop_requested
= true;
4053 thr
->set_resumed (false);
4057 while (displaced_step_in_progress (inf
))
4059 wait_one_event event
;
4061 event
.target
= inf
->process_target ();
4062 event
.ptid
= do_target_wait_1 (inf
, pid_ptid
, &event
.ws
, 0);
4065 print_target_wait_results (pid_ptid
, event
.ptid
, event
.ws
);
4070 /* It's OK to leave some of the threads of INF stopped, since
4071 they'll be detached shortly. */
4075 /* If all-stop, but there exists a non-stop target, stop all threads
4076 now that we're presenting the stop to the user. */
4079 stop_all_threads_if_all_stop_mode ()
4081 if (!non_stop
&& exists_non_stop_target ())
4082 stop_all_threads ("presenting stop to user in all-stop");
4085 /* Wait for control to return from inferior to debugger.
4087 If inferior gets a signal, we may decide to start it up again
4088 instead of returning. That is why there is a loop in this function.
4089 When this function actually returns it means the inferior
4090 should be left stopped and GDB should read more commands. */
4093 wait_for_inferior (inferior
*inf
)
4095 infrun_debug_printf ("wait_for_inferior ()");
4097 SCOPE_EXIT
{ delete_just_stopped_threads_infrun_breakpoints (); };
4099 /* If an error happens while handling the event, propagate GDB's
4100 knowledge of the executing state to the frontend/user running
4102 scoped_finish_thread_state finish_state
4103 (inf
->process_target (), minus_one_ptid
);
4107 execution_control_state ecs
;
4109 overlay_cache_invalid
= 1;
4111 /* Flush target cache before starting to handle each event.
4112 Target was running and cache could be stale. This is just a
4113 heuristic. Running threads may modify target memory, but we
4114 don't get any event. */
4115 target_dcache_invalidate ();
4117 ecs
.ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
.ws
, 0);
4118 ecs
.target
= inf
->process_target ();
4121 print_target_wait_results (minus_one_ptid
, ecs
.ptid
, ecs
.ws
);
4123 /* Now figure out what to do with the result of the result. */
4124 handle_inferior_event (&ecs
);
4126 if (!ecs
.wait_some_more
)
4130 stop_all_threads_if_all_stop_mode ();
4132 /* No error, don't finish the state yet. */
4133 finish_state
.release ();
4136 /* Cleanup that reinstalls the readline callback handler, if the
4137 target is running in the background. If while handling the target
4138 event something triggered a secondary prompt, like e.g., a
4139 pagination prompt, we'll have removed the callback handler (see
4140 gdb_readline_wrapper_line). Need to do this as we go back to the
4141 event loop, ready to process further input. Note this has no
4142 effect if the handler hasn't actually been removed, because calling
4143 rl_callback_handler_install resets the line buffer, thus losing
4147 reinstall_readline_callback_handler_cleanup ()
4149 struct ui
*ui
= current_ui
;
4153 /* We're not going back to the top level event loop yet. Don't
4154 install the readline callback, as it'd prep the terminal,
4155 readline-style (raw, noecho) (e.g., --batch). We'll install
4156 it the next time the prompt is displayed, when we're ready
4161 if (ui
->command_editing
&& ui
->prompt_state
!= PROMPT_BLOCKED
)
4162 gdb_rl_callback_handler_reinstall ();
4165 /* Clean up the FSMs of threads that are now stopped. In non-stop,
4166 that's just the event thread. In all-stop, that's all threads. */
4169 clean_up_just_stopped_threads_fsms (struct execution_control_state
*ecs
)
4171 /* The first clean_up call below assumes the event thread is the current
4173 if (ecs
->event_thread
!= nullptr)
4174 gdb_assert (ecs
->event_thread
== inferior_thread ());
4176 if (ecs
->event_thread
!= nullptr
4177 && ecs
->event_thread
->thread_fsm () != nullptr)
4178 ecs
->event_thread
->thread_fsm ()->clean_up (ecs
->event_thread
);
4182 scoped_restore_current_thread restore_thread
;
4184 for (thread_info
*thr
: all_non_exited_threads ())
4186 if (thr
->thread_fsm () == nullptr)
4188 if (thr
== ecs
->event_thread
)
4191 switch_to_thread (thr
);
4192 thr
->thread_fsm ()->clean_up (thr
);
4197 /* Helper for all_uis_check_sync_execution_done that works on the
4201 check_curr_ui_sync_execution_done (void)
4203 struct ui
*ui
= current_ui
;
4205 if (ui
->prompt_state
== PROMPT_NEEDED
4207 && !gdb_in_secondary_prompt_p (ui
))
4209 target_terminal::ours ();
4210 gdb::observers::sync_execution_done
.notify ();
4211 ui
->register_file_handler ();
4218 all_uis_check_sync_execution_done (void)
4220 SWITCH_THRU_ALL_UIS ()
4222 check_curr_ui_sync_execution_done ();
4229 all_uis_on_sync_execution_starting (void)
4231 SWITCH_THRU_ALL_UIS ()
4233 if (current_ui
->prompt_state
== PROMPT_NEEDED
)
4234 async_disable_stdin ();
4238 /* A quit_handler callback installed while we're handling inferior
4242 infrun_quit_handler ()
4244 if (target_terminal::is_ours ())
4248 default_quit_handler would throw a quit in this case, but if
4249 we're handling an event while we have the terminal, it means
4250 the target is running a background execution command, and
4251 thus when users press Ctrl-C, they're wanting to interrupt
4252 whatever command they were executing in the command line.
4256 (gdb) foo bar whatever<ctrl-c>
4258 That Ctrl-C should clear the input line, not interrupt event
4259 handling if it happens that the user types Ctrl-C at just the
4262 It's as-if background event handling was handled by a
4263 separate background thread.
4265 To be clear, the Ctrl-C is not lost -- it will be processed
4266 by the next QUIT call once we're out of fetch_inferior_event
4271 if (check_quit_flag ())
4272 target_pass_ctrlc ();
4276 /* Asynchronous version of wait_for_inferior. It is called by the
4277 event loop whenever a change of state is detected on the file
4278 descriptor corresponding to the target. It can be called more than
4279 once to complete a single execution command. In such cases we need
4280 to keep the state in a global variable ECSS. If it is the last time
4281 that this function is called for a single execution command, then
4282 report to the user that the inferior has stopped, and do the
4283 necessary cleanups. */
4286 fetch_inferior_event ()
4288 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
4290 execution_control_state ecs
;
4293 /* Events are always processed with the main UI as current UI. This
4294 way, warnings, debug output, etc. are always consistently sent to
4295 the main console. */
4296 scoped_restore save_ui
= make_scoped_restore (¤t_ui
, main_ui
);
4298 /* Temporarily disable pagination. Otherwise, the user would be
4299 given an option to press 'q' to quit, which would cause an early
4300 exit and could leave GDB in a half-baked state. */
4301 scoped_restore save_pagination
4302 = make_scoped_restore (&pagination_enabled
, false);
4304 /* Install a quit handler that does nothing if we have the terminal
4305 (meaning the target is running a background execution command),
4306 so that Ctrl-C never interrupts GDB before the event is fully
4308 scoped_restore restore_quit_handler
4309 = make_scoped_restore (&quit_handler
, infrun_quit_handler
);
4311 /* Make sure a SIGINT does not interrupt an extension language while
4312 we're handling an event. That could interrupt a Python unwinder
4313 or a Python observer or some such. A Ctrl-C should either be
4314 forwarded to the inferior if the inferior has the terminal, or,
4315 if GDB has the terminal, should interrupt the command the user is
4316 typing in the CLI. */
4317 scoped_disable_cooperative_sigint_handling restore_coop_sigint
;
4319 /* End up with readline processing input, if necessary. */
4321 SCOPE_EXIT
{ reinstall_readline_callback_handler_cleanup (); };
4323 /* We're handling a live event, so make sure we're doing live
4324 debugging. If we're looking at traceframes while the target is
4325 running, we're going to need to get back to that mode after
4326 handling the event. */
4327 gdb::optional
<scoped_restore_current_traceframe
> maybe_restore_traceframe
;
4330 maybe_restore_traceframe
.emplace ();
4331 set_current_traceframe (-1);
4334 /* The user/frontend should not notice a thread switch due to
4335 internal events. Make sure we revert to the user selected
4336 thread and frame after handling the event and running any
4337 breakpoint commands. */
4338 scoped_restore_current_thread restore_thread
;
4340 overlay_cache_invalid
= 1;
4341 /* Flush target cache before starting to handle each event. Target
4342 was running and cache could be stale. This is just a heuristic.
4343 Running threads may modify target memory, but we don't get any
4345 target_dcache_invalidate ();
4347 scoped_restore save_exec_dir
4348 = make_scoped_restore (&execution_direction
,
4349 target_execution_direction ());
4351 /* Allow targets to pause their resumed threads while we handle
4353 scoped_disable_commit_resumed
disable_commit_resumed ("handling event");
4355 if (!do_target_wait (&ecs
, TARGET_WNOHANG
))
4357 infrun_debug_printf ("do_target_wait returned no event");
4358 disable_commit_resumed
.reset_and_commit ();
4362 gdb_assert (ecs
.ws
.kind () != TARGET_WAITKIND_IGNORE
);
4364 /* Switch to the inferior that generated the event, so we can do
4365 target calls. If the event was not associated to a ptid, */
4366 if (ecs
.ptid
!= null_ptid
4367 && ecs
.ptid
!= minus_one_ptid
)
4368 switch_to_inferior_no_thread (find_inferior_ptid (ecs
.target
, ecs
.ptid
));
4370 switch_to_target_no_thread (ecs
.target
);
4373 print_target_wait_results (minus_one_ptid
, ecs
.ptid
, ecs
.ws
);
4375 /* If an error happens while handling the event, propagate GDB's
4376 knowledge of the executing state to the frontend/user running
4378 ptid_t finish_ptid
= !target_is_non_stop_p () ? minus_one_ptid
: ecs
.ptid
;
4379 scoped_finish_thread_state
finish_state (ecs
.target
, finish_ptid
);
4381 /* Get executed before scoped_restore_current_thread above to apply
4382 still for the thread which has thrown the exception. */
4383 auto defer_bpstat_clear
4384 = make_scope_exit (bpstat_clear_actions
);
4385 auto defer_delete_threads
4386 = make_scope_exit (delete_just_stopped_threads_infrun_breakpoints
);
4388 /* Now figure out what to do with the result of the result. */
4389 handle_inferior_event (&ecs
);
4391 if (!ecs
.wait_some_more
)
4393 struct inferior
*inf
= find_inferior_ptid (ecs
.target
, ecs
.ptid
);
4394 bool should_stop
= true;
4395 struct thread_info
*thr
= ecs
.event_thread
;
4397 delete_just_stopped_threads_infrun_breakpoints ();
4399 if (thr
!= nullptr && thr
->thread_fsm () != nullptr)
4400 should_stop
= thr
->thread_fsm ()->should_stop (thr
);
4408 bool should_notify_stop
= true;
4409 bool proceeded
= false;
4411 stop_all_threads_if_all_stop_mode ();
4413 clean_up_just_stopped_threads_fsms (&ecs
);
4415 if (thr
!= nullptr && thr
->thread_fsm () != nullptr)
4417 = thr
->thread_fsm ()->should_notify_stop ();
4419 if (should_notify_stop
)
4421 /* We may not find an inferior if this was a process exit. */
4422 if (inf
== nullptr || inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
4423 proceeded
= normal_stop ();
4428 inferior_event_handler (INF_EXEC_COMPLETE
);
4432 /* If we got a TARGET_WAITKIND_NO_RESUMED event, then the
4433 previously selected thread is gone. We have two
4434 choices - switch to no thread selected, or restore the
4435 previously selected thread (now exited). We chose the
4436 later, just because that's what GDB used to do. After
4437 this, "info threads" says "The current thread <Thread
4438 ID 2> has terminated." instead of "No thread
4442 && ecs
.ws
.kind () != TARGET_WAITKIND_NO_RESUMED
)
4443 restore_thread
.dont_restore ();
4447 defer_delete_threads
.release ();
4448 defer_bpstat_clear
.release ();
4450 /* No error, don't finish the thread states yet. */
4451 finish_state
.release ();
4453 disable_commit_resumed
.reset_and_commit ();
4455 /* This scope is used to ensure that readline callbacks are
4456 reinstalled here. */
4459 /* Handling this event might have caused some inferiors to become prunable.
4460 For example, the exit of an inferior that was automatically added. Try
4461 to get rid of them. Keeping those around slows down things linearly.
4463 Note that this never removes the current inferior. Therefore, call this
4464 after RESTORE_THREAD went out of scope, in case the event inferior (which was
4465 temporarily made the current inferior) is meant to be deleted.
4467 Call this before all_uis_check_sync_execution_done, so that notifications about
4468 removed inferiors appear before the prompt. */
4471 /* If a UI was in sync execution mode, and now isn't, restore its
4472 prompt (a synchronous execution command has finished, and we're
4473 ready for input). */
4474 all_uis_check_sync_execution_done ();
4477 && exec_done_display_p
4478 && (inferior_ptid
== null_ptid
4479 || inferior_thread ()->state
!= THREAD_RUNNING
))
4480 gdb_printf (_("completed.\n"));
4486 set_step_info (thread_info
*tp
, frame_info_ptr frame
,
4487 struct symtab_and_line sal
)
4489 /* This can be removed once this function no longer implicitly relies on the
4490 inferior_ptid value. */
4491 gdb_assert (inferior_ptid
== tp
->ptid
);
4493 tp
->control
.step_frame_id
= get_frame_id (frame
);
4494 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
4496 tp
->current_symtab
= sal
.symtab
;
4497 tp
->current_line
= sal
.line
;
4500 ("symtab = %s, line = %d, step_frame_id = %s, step_stack_frame_id = %s",
4501 tp
->current_symtab
!= nullptr ? tp
->current_symtab
->filename
: "<null>",
4503 tp
->control
.step_frame_id
.to_string ().c_str (),
4504 tp
->control
.step_stack_frame_id
.to_string ().c_str ());
4507 /* Clear context switchable stepping state. */
4510 init_thread_stepping_state (struct thread_info
*tss
)
4512 tss
->stepped_breakpoint
= 0;
4513 tss
->stepping_over_breakpoint
= 0;
4514 tss
->stepping_over_watchpoint
= 0;
4515 tss
->step_after_step_resume_breakpoint
= 0;
4521 set_last_target_status (process_stratum_target
*target
, ptid_t ptid
,
4522 const target_waitstatus
&status
)
4524 target_last_proc_target
= target
;
4525 target_last_wait_ptid
= ptid
;
4526 target_last_waitstatus
= status
;
4532 get_last_target_status (process_stratum_target
**target
, ptid_t
*ptid
,
4533 target_waitstatus
*status
)
4535 if (target
!= nullptr)
4536 *target
= target_last_proc_target
;
4537 if (ptid
!= nullptr)
4538 *ptid
= target_last_wait_ptid
;
4539 if (status
!= nullptr)
4540 *status
= target_last_waitstatus
;
4546 nullify_last_target_wait_ptid (void)
4548 target_last_proc_target
= nullptr;
4549 target_last_wait_ptid
= minus_one_ptid
;
4550 target_last_waitstatus
= {};
4553 /* Switch thread contexts. */
4556 context_switch (execution_control_state
*ecs
)
4558 if (ecs
->ptid
!= inferior_ptid
4559 && (inferior_ptid
== null_ptid
4560 || ecs
->event_thread
!= inferior_thread ()))
4562 infrun_debug_printf ("Switching context from %s to %s",
4563 inferior_ptid
.to_string ().c_str (),
4564 ecs
->ptid
.to_string ().c_str ());
4567 switch_to_thread (ecs
->event_thread
);
4570 /* If the target can't tell whether we've hit breakpoints
4571 (target_supports_stopped_by_sw_breakpoint), and we got a SIGTRAP,
4572 check whether that could have been caused by a breakpoint. If so,
4573 adjust the PC, per gdbarch_decr_pc_after_break. */
4576 adjust_pc_after_break (struct thread_info
*thread
,
4577 const target_waitstatus
&ws
)
4579 struct regcache
*regcache
;
4580 struct gdbarch
*gdbarch
;
4581 CORE_ADDR breakpoint_pc
, decr_pc
;
4583 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
4584 we aren't, just return.
4586 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
4587 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
4588 implemented by software breakpoints should be handled through the normal
4591 NOTE drow/2004-01-31: On some targets, breakpoints may generate
4592 different signals (SIGILL or SIGEMT for instance), but it is less
4593 clear where the PC is pointing afterwards. It may not match
4594 gdbarch_decr_pc_after_break. I don't know any specific target that
4595 generates these signals at breakpoints (the code has been in GDB since at
4596 least 1992) so I can not guess how to handle them here.
4598 In earlier versions of GDB, a target with
4599 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
4600 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
4601 target with both of these set in GDB history, and it seems unlikely to be
4602 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
4604 if (ws
.kind () != TARGET_WAITKIND_STOPPED
)
4607 if (ws
.sig () != GDB_SIGNAL_TRAP
)
4610 /* In reverse execution, when a breakpoint is hit, the instruction
4611 under it has already been de-executed. The reported PC always
4612 points at the breakpoint address, so adjusting it further would
4613 be wrong. E.g., consider this case on a decr_pc_after_break == 1
4616 B1 0x08000000 : INSN1
4617 B2 0x08000001 : INSN2
4619 PC -> 0x08000003 : INSN4
4621 Say you're stopped at 0x08000003 as above. Reverse continuing
4622 from that point should hit B2 as below. Reading the PC when the
4623 SIGTRAP is reported should read 0x08000001 and INSN2 should have
4624 been de-executed already.
4626 B1 0x08000000 : INSN1
4627 B2 PC -> 0x08000001 : INSN2
4631 We can't apply the same logic as for forward execution, because
4632 we would wrongly adjust the PC to 0x08000000, since there's a
4633 breakpoint at PC - 1. We'd then report a hit on B1, although
4634 INSN1 hadn't been de-executed yet. Doing nothing is the correct
4636 if (execution_direction
== EXEC_REVERSE
)
4639 /* If the target can tell whether the thread hit a SW breakpoint,
4640 trust it. Targets that can tell also adjust the PC
4642 if (target_supports_stopped_by_sw_breakpoint ())
4645 /* Note that relying on whether a breakpoint is planted in memory to
4646 determine this can fail. E.g,. the breakpoint could have been
4647 removed since. Or the thread could have been told to step an
4648 instruction the size of a breakpoint instruction, and only
4649 _after_ was a breakpoint inserted at its address. */
4651 /* If this target does not decrement the PC after breakpoints, then
4652 we have nothing to do. */
4653 regcache
= get_thread_regcache (thread
);
4654 gdbarch
= regcache
->arch ();
4656 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4660 const address_space
*aspace
= regcache
->aspace ();
4662 /* Find the location where (if we've hit a breakpoint) the
4663 breakpoint would be. */
4664 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
4666 /* If the target can't tell whether a software breakpoint triggered,
4667 fallback to figuring it out based on breakpoints we think were
4668 inserted in the target, and on whether the thread was stepped or
4671 /* Check whether there actually is a software breakpoint inserted at
4674 If in non-stop mode, a race condition is possible where we've
4675 removed a breakpoint, but stop events for that breakpoint were
4676 already queued and arrive later. To suppress those spurious
4677 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
4678 and retire them after a number of stop events are reported. Note
4679 this is an heuristic and can thus get confused. The real fix is
4680 to get the "stopped by SW BP and needs adjustment" info out of
4681 the target/kernel (and thus never reach here; see above). */
4682 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
4683 || (target_is_non_stop_p ()
4684 && moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
4686 gdb::optional
<scoped_restore_tmpl
<int>> restore_operation_disable
;
4688 if (record_full_is_used ())
4689 restore_operation_disable
.emplace
4690 (record_full_gdb_operation_disable_set ());
4692 /* When using hardware single-step, a SIGTRAP is reported for both
4693 a completed single-step and a software breakpoint. Need to
4694 differentiate between the two, as the latter needs adjusting
4695 but the former does not.
4697 The SIGTRAP can be due to a completed hardware single-step only if
4698 - we didn't insert software single-step breakpoints
4699 - this thread is currently being stepped
4701 If any of these events did not occur, we must have stopped due
4702 to hitting a software breakpoint, and have to back up to the
4705 As a special case, we could have hardware single-stepped a
4706 software breakpoint. In this case (prev_pc == breakpoint_pc),
4707 we also need to back up to the breakpoint address. */
4709 if (thread_has_single_step_breakpoints_set (thread
)
4710 || !currently_stepping (thread
)
4711 || (thread
->stepped_breakpoint
4712 && thread
->prev_pc
== breakpoint_pc
))
4713 regcache_write_pc (regcache
, breakpoint_pc
);
4718 stepped_in_from (frame_info_ptr frame
, struct frame_id step_frame_id
)
4720 for (frame
= get_prev_frame (frame
);
4722 frame
= get_prev_frame (frame
))
4724 if (get_frame_id (frame
) == step_frame_id
)
4727 if (get_frame_type (frame
) != INLINE_FRAME
)
4734 /* Look for an inline frame that is marked for skip.
4735 If PREV_FRAME is TRUE start at the previous frame,
4736 otherwise start at the current frame. Stop at the
4737 first non-inline frame, or at the frame where the
4741 inline_frame_is_marked_for_skip (bool prev_frame
, struct thread_info
*tp
)
4743 frame_info_ptr frame
= get_current_frame ();
4746 frame
= get_prev_frame (frame
);
4748 for (; frame
!= nullptr; frame
= get_prev_frame (frame
))
4750 const char *fn
= nullptr;
4751 symtab_and_line sal
;
4754 if (get_frame_id (frame
) == tp
->control
.step_frame_id
)
4756 if (get_frame_type (frame
) != INLINE_FRAME
)
4759 sal
= find_frame_sal (frame
);
4760 sym
= get_frame_function (frame
);
4763 fn
= sym
->print_name ();
4766 && function_name_is_marked_for_skip (fn
, sal
))
4773 /* If the event thread has the stop requested flag set, pretend it
4774 stopped for a GDB_SIGNAL_0 (i.e., as if it stopped due to
4778 handle_stop_requested (struct execution_control_state
*ecs
)
4780 if (ecs
->event_thread
->stop_requested
)
4782 ecs
->ws
.set_stopped (GDB_SIGNAL_0
);
4783 handle_signal_stop (ecs
);
4789 /* Auxiliary function that handles syscall entry/return events.
4790 It returns true if the inferior should keep going (and GDB
4791 should ignore the event), or false if the event deserves to be
4795 handle_syscall_event (struct execution_control_state
*ecs
)
4797 struct regcache
*regcache
;
4800 context_switch (ecs
);
4802 regcache
= get_thread_regcache (ecs
->event_thread
);
4803 syscall_number
= ecs
->ws
.syscall_number ();
4804 ecs
->event_thread
->set_stop_pc (regcache_read_pc (regcache
));
4806 if (catch_syscall_enabled () > 0
4807 && catching_syscall_number (syscall_number
))
4809 infrun_debug_printf ("syscall number=%d", syscall_number
);
4811 ecs
->event_thread
->control
.stop_bpstat
4812 = bpstat_stop_status_nowatch (regcache
->aspace (),
4813 ecs
->event_thread
->stop_pc (),
4814 ecs
->event_thread
, ecs
->ws
);
4816 if (handle_stop_requested (ecs
))
4819 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4821 /* Catchpoint hit. */
4826 if (handle_stop_requested (ecs
))
4829 /* If no catchpoint triggered for this, then keep going. */
4835 /* Lazily fill in the execution_control_state's stop_func_* fields. */
4838 fill_in_stop_func (struct gdbarch
*gdbarch
,
4839 struct execution_control_state
*ecs
)
4841 if (!ecs
->stop_func_filled_in
)
4844 const general_symbol_info
*gsi
;
4846 /* Don't care about return value; stop_func_start and stop_func_name
4847 will both be 0 if it doesn't work. */
4848 find_pc_partial_function_sym (ecs
->event_thread
->stop_pc (),
4850 &ecs
->stop_func_start
,
4851 &ecs
->stop_func_end
,
4853 ecs
->stop_func_name
= gsi
== nullptr ? nullptr : gsi
->print_name ();
4855 /* The call to find_pc_partial_function, above, will set
4856 stop_func_start and stop_func_end to the start and end
4857 of the range containing the stop pc. If this range
4858 contains the entry pc for the block (which is always the
4859 case for contiguous blocks), advance stop_func_start past
4860 the function's start offset and entrypoint. Note that
4861 stop_func_start is NOT advanced when in a range of a
4862 non-contiguous block that does not contain the entry pc. */
4863 if (block
!= nullptr
4864 && ecs
->stop_func_start
<= block
->entry_pc ()
4865 && block
->entry_pc () < ecs
->stop_func_end
)
4867 ecs
->stop_func_start
4868 += gdbarch_deprecated_function_start_offset (gdbarch
);
4870 /* PowerPC functions have a Local Entry Point (LEP) and a Global
4871 Entry Point (GEP). There is only one Entry Point (GEP = LEP) for
4872 other architectures. */
4873 ecs
->stop_func_alt_start
= ecs
->stop_func_start
;
4875 if (gdbarch_skip_entrypoint_p (gdbarch
))
4876 ecs
->stop_func_start
4877 = gdbarch_skip_entrypoint (gdbarch
, ecs
->stop_func_start
);
4880 ecs
->stop_func_filled_in
= 1;
4885 /* Return the STOP_SOON field of the inferior pointed at by ECS. */
4887 static enum stop_kind
4888 get_inferior_stop_soon (execution_control_state
*ecs
)
4890 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
4892 gdb_assert (inf
!= nullptr);
4893 return inf
->control
.stop_soon
;
4896 /* Poll for one event out of the current target. Store the resulting
4897 waitstatus in WS, and return the event ptid. Does not block. */
4900 poll_one_curr_target (struct target_waitstatus
*ws
)
4904 overlay_cache_invalid
= 1;
4906 /* Flush target cache before starting to handle each event.
4907 Target was running and cache could be stale. This is just a
4908 heuristic. Running threads may modify target memory, but we
4909 don't get any event. */
4910 target_dcache_invalidate ();
4912 event_ptid
= target_wait (minus_one_ptid
, ws
, TARGET_WNOHANG
);
4915 print_target_wait_results (minus_one_ptid
, event_ptid
, *ws
);
4920 /* Wait for one event out of any target. */
4922 static wait_one_event
4927 for (inferior
*inf
: all_inferiors ())
4929 process_stratum_target
*target
= inf
->process_target ();
4930 if (target
== nullptr
4931 || !target
->is_async_p ()
4932 || !target
->threads_executing
)
4935 switch_to_inferior_no_thread (inf
);
4937 wait_one_event event
;
4938 event
.target
= target
;
4939 event
.ptid
= poll_one_curr_target (&event
.ws
);
4941 if (event
.ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
4943 /* If nothing is resumed, remove the target from the
4945 target_async (false);
4947 else if (event
.ws
.kind () != TARGET_WAITKIND_IGNORE
)
4951 /* Block waiting for some event. */
4958 for (inferior
*inf
: all_inferiors ())
4960 process_stratum_target
*target
= inf
->process_target ();
4961 if (target
== nullptr
4962 || !target
->is_async_p ()
4963 || !target
->threads_executing
)
4966 int fd
= target
->async_wait_fd ();
4967 FD_SET (fd
, &readfds
);
4974 /* No waitable targets left. All must be stopped. */
4975 target_waitstatus ws
;
4976 ws
.set_no_resumed ();
4977 return {nullptr, minus_one_ptid
, std::move (ws
)};
4982 int numfds
= interruptible_select (nfds
, &readfds
, 0, nullptr, 0);
4988 perror_with_name ("interruptible_select");
4993 /* Save the thread's event and stop reason to process it later. */
4996 save_waitstatus (struct thread_info
*tp
, const target_waitstatus
&ws
)
4998 infrun_debug_printf ("saving status %s for %s",
4999 ws
.to_string ().c_str (),
5000 tp
->ptid
.to_string ().c_str ());
5002 /* Record for later. */
5003 tp
->set_pending_waitstatus (ws
);
5005 if (ws
.kind () == TARGET_WAITKIND_STOPPED
5006 && ws
.sig () == GDB_SIGNAL_TRAP
)
5008 struct regcache
*regcache
= get_thread_regcache (tp
);
5009 const address_space
*aspace
= regcache
->aspace ();
5010 CORE_ADDR pc
= regcache_read_pc (regcache
);
5012 adjust_pc_after_break (tp
, tp
->pending_waitstatus ());
5014 scoped_restore_current_thread restore_thread
;
5015 switch_to_thread (tp
);
5017 if (target_stopped_by_watchpoint ())
5018 tp
->set_stop_reason (TARGET_STOPPED_BY_WATCHPOINT
);
5019 else if (target_supports_stopped_by_sw_breakpoint ()
5020 && target_stopped_by_sw_breakpoint ())
5021 tp
->set_stop_reason (TARGET_STOPPED_BY_SW_BREAKPOINT
);
5022 else if (target_supports_stopped_by_hw_breakpoint ()
5023 && target_stopped_by_hw_breakpoint ())
5024 tp
->set_stop_reason (TARGET_STOPPED_BY_HW_BREAKPOINT
);
5025 else if (!target_supports_stopped_by_hw_breakpoint ()
5026 && hardware_breakpoint_inserted_here_p (aspace
, pc
))
5027 tp
->set_stop_reason (TARGET_STOPPED_BY_HW_BREAKPOINT
);
5028 else if (!target_supports_stopped_by_sw_breakpoint ()
5029 && software_breakpoint_inserted_here_p (aspace
, pc
))
5030 tp
->set_stop_reason (TARGET_STOPPED_BY_SW_BREAKPOINT
);
5031 else if (!thread_has_single_step_breakpoints_set (tp
)
5032 && currently_stepping (tp
))
5033 tp
->set_stop_reason (TARGET_STOPPED_BY_SINGLE_STEP
);
5037 /* Mark the non-executing threads accordingly. In all-stop, all
5038 threads of all processes are stopped when we get any event
5039 reported. In non-stop mode, only the event thread stops. */
5042 mark_non_executing_threads (process_stratum_target
*target
,
5044 const target_waitstatus
&ws
)
5048 if (!target_is_non_stop_p ())
5049 mark_ptid
= minus_one_ptid
;
5050 else if (ws
.kind () == TARGET_WAITKIND_SIGNALLED
5051 || ws
.kind () == TARGET_WAITKIND_EXITED
)
5053 /* If we're handling a process exit in non-stop mode, even
5054 though threads haven't been deleted yet, one would think
5055 that there is nothing to do, as threads of the dead process
5056 will be soon deleted, and threads of any other process were
5057 left running. However, on some targets, threads survive a
5058 process exit event. E.g., for the "checkpoint" command,
5059 when the current checkpoint/fork exits, linux-fork.c
5060 automatically switches to another fork from within
5061 target_mourn_inferior, by associating the same
5062 inferior/thread to another fork. We haven't mourned yet at
5063 this point, but we must mark any threads left in the
5064 process as not-executing so that finish_thread_state marks
5065 them stopped (in the user's perspective) if/when we present
5066 the stop to the user. */
5067 mark_ptid
= ptid_t (event_ptid
.pid ());
5070 mark_ptid
= event_ptid
;
5072 set_executing (target
, mark_ptid
, false);
5074 /* Likewise the resumed flag. */
5075 set_resumed (target
, mark_ptid
, false);
5078 /* Handle one event after stopping threads. If the eventing thread
5079 reports back any interesting event, we leave it pending. If the
5080 eventing thread was in the middle of a displaced step, we
5081 cancel/finish it, and unless the thread's inferior is being
5082 detached, put the thread back in the step-over chain. Returns true
5083 if there are no resumed threads left in the target (thus there's no
5084 point in waiting further), false otherwise. */
5087 handle_one (const wait_one_event
&event
)
5090 ("%s %s", event
.ws
.to_string ().c_str (),
5091 event
.ptid
.to_string ().c_str ());
5093 if (event
.ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
5095 /* All resumed threads exited. */
5098 else if (event
.ws
.kind () == TARGET_WAITKIND_THREAD_EXITED
5099 || event
.ws
.kind () == TARGET_WAITKIND_EXITED
5100 || event
.ws
.kind () == TARGET_WAITKIND_SIGNALLED
)
5102 /* One thread/process exited/signalled. */
5104 thread_info
*t
= nullptr;
5106 /* The target may have reported just a pid. If so, try
5107 the first non-exited thread. */
5108 if (event
.ptid
.is_pid ())
5110 int pid
= event
.ptid
.pid ();
5111 inferior
*inf
= find_inferior_pid (event
.target
, pid
);
5112 for (thread_info
*tp
: inf
->non_exited_threads ())
5118 /* If there is no available thread, the event would
5119 have to be appended to a per-inferior event list,
5120 which does not exist (and if it did, we'd have
5121 to adjust run control command to be able to
5122 resume such an inferior). We assert here instead
5123 of going into an infinite loop. */
5124 gdb_assert (t
!= nullptr);
5127 ("using %s", t
->ptid
.to_string ().c_str ());
5131 t
= event
.target
->find_thread (event
.ptid
);
5132 /* Check if this is the first time we see this thread.
5133 Don't bother adding if it individually exited. */
5135 && event
.ws
.kind () != TARGET_WAITKIND_THREAD_EXITED
)
5136 t
= add_thread (event
.target
, event
.ptid
);
5141 /* Set the threads as non-executing to avoid
5142 another stop attempt on them. */
5143 switch_to_thread_no_regs (t
);
5144 mark_non_executing_threads (event
.target
, event
.ptid
,
5146 save_waitstatus (t
, event
.ws
);
5147 t
->stop_requested
= false;
5152 thread_info
*t
= event
.target
->find_thread (event
.ptid
);
5154 t
= add_thread (event
.target
, event
.ptid
);
5156 t
->stop_requested
= 0;
5157 t
->set_executing (false);
5158 t
->set_resumed (false);
5159 t
->control
.may_range_step
= 0;
5161 /* This may be the first time we see the inferior report
5163 if (t
->inf
->needs_setup
)
5165 switch_to_thread_no_regs (t
);
5169 if (event
.ws
.kind () == TARGET_WAITKIND_STOPPED
5170 && event
.ws
.sig () == GDB_SIGNAL_0
)
5172 /* We caught the event that we intended to catch, so
5173 there's no event to save as pending. */
5175 if (displaced_step_finish (t
, event
.ws
)
5176 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5178 /* Add it back to the step-over queue. */
5180 ("displaced-step of %s canceled",
5181 t
->ptid
.to_string ().c_str ());
5183 t
->control
.trap_expected
= 0;
5184 if (!t
->inf
->detaching
)
5185 global_thread_step_over_chain_enqueue (t
);
5190 struct regcache
*regcache
;
5193 ("target_wait %s, saving status for %s",
5194 event
.ws
.to_string ().c_str (),
5195 t
->ptid
.to_string ().c_str ());
5197 /* Record for later. */
5198 save_waitstatus (t
, event
.ws
);
5200 if (displaced_step_finish (t
, event
.ws
)
5201 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5203 /* Add it back to the step-over queue. */
5204 t
->control
.trap_expected
= 0;
5205 if (!t
->inf
->detaching
)
5206 global_thread_step_over_chain_enqueue (t
);
5209 regcache
= get_thread_regcache (t
);
5210 t
->set_stop_pc (regcache_read_pc (regcache
));
5212 infrun_debug_printf ("saved stop_pc=%s for %s "
5213 "(currently_stepping=%d)",
5214 paddress (target_gdbarch (), t
->stop_pc ()),
5215 t
->ptid
.to_string ().c_str (),
5216 currently_stepping (t
));
5226 stop_all_threads (const char *reason
, inferior
*inf
)
5228 /* We may need multiple passes to discover all threads. */
5232 gdb_assert (exists_non_stop_target ());
5234 INFRUN_SCOPED_DEBUG_START_END ("reason=%s, inf=%d", reason
,
5235 inf
!= nullptr ? inf
->num
: -1);
5237 infrun_debug_show_threads ("non-exited threads",
5238 all_non_exited_threads ());
5240 scoped_restore_current_thread restore_thread
;
5242 /* Enable thread events on relevant targets. */
5243 for (auto *target
: all_non_exited_process_targets ())
5245 if (inf
!= nullptr && inf
->process_target () != target
)
5248 switch_to_target_no_thread (target
);
5249 target_thread_events (true);
5254 /* Disable thread events on relevant targets. */
5255 for (auto *target
: all_non_exited_process_targets ())
5257 if (inf
!= nullptr && inf
->process_target () != target
)
5260 switch_to_target_no_thread (target
);
5261 target_thread_events (false);
5264 /* Use debug_prefixed_printf directly to get a meaningful function
5267 debug_prefixed_printf ("infrun", "stop_all_threads", "done");
5270 /* Request threads to stop, and then wait for the stops. Because
5271 threads we already know about can spawn more threads while we're
5272 trying to stop them, and we only learn about new threads when we
5273 update the thread list, do this in a loop, and keep iterating
5274 until two passes find no threads that need to be stopped. */
5275 for (pass
= 0; pass
< 2; pass
++, iterations
++)
5277 infrun_debug_printf ("pass=%d, iterations=%d", pass
, iterations
);
5280 int waits_needed
= 0;
5282 for (auto *target
: all_non_exited_process_targets ())
5284 if (inf
!= nullptr && inf
->process_target () != target
)
5287 switch_to_target_no_thread (target
);
5288 update_thread_list ();
5291 /* Go through all threads looking for threads that we need
5292 to tell the target to stop. */
5293 for (thread_info
*t
: all_non_exited_threads ())
5295 if (inf
!= nullptr && t
->inf
!= inf
)
5298 /* For a single-target setting with an all-stop target,
5299 we would not even arrive here. For a multi-target
5300 setting, until GDB is able to handle a mixture of
5301 all-stop and non-stop targets, simply skip all-stop
5302 targets' threads. This should be fine due to the
5303 protection of 'check_multi_target_resumption'. */
5305 switch_to_thread_no_regs (t
);
5306 if (!target_is_non_stop_p ())
5309 if (t
->executing ())
5311 /* If already stopping, don't request a stop again.
5312 We just haven't seen the notification yet. */
5313 if (!t
->stop_requested
)
5315 infrun_debug_printf (" %s executing, need stop",
5316 t
->ptid
.to_string ().c_str ());
5317 target_stop (t
->ptid
);
5318 t
->stop_requested
= 1;
5322 infrun_debug_printf (" %s executing, already stopping",
5323 t
->ptid
.to_string ().c_str ());
5326 if (t
->stop_requested
)
5331 infrun_debug_printf (" %s not executing",
5332 t
->ptid
.to_string ().c_str ());
5334 /* The thread may be not executing, but still be
5335 resumed with a pending status to process. */
5336 t
->set_resumed (false);
5340 if (waits_needed
== 0)
5343 /* If we find new threads on the second iteration, restart
5344 over. We want to see two iterations in a row with all
5349 for (int i
= 0; i
< waits_needed
; i
++)
5351 wait_one_event event
= wait_one ();
5352 if (handle_one (event
))
5359 /* Handle a TARGET_WAITKIND_NO_RESUMED event. */
5362 handle_no_resumed (struct execution_control_state
*ecs
)
5364 if (target_can_async_p ())
5366 bool any_sync
= false;
5368 for (ui
*ui
: all_uis ())
5370 if (ui
->prompt_state
== PROMPT_BLOCKED
)
5378 /* There were no unwaited-for children left in the target, but,
5379 we're not synchronously waiting for events either. Just
5382 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED (ignoring: bg)");
5383 prepare_to_wait (ecs
);
5388 /* Otherwise, if we were running a synchronous execution command, we
5389 may need to cancel it and give the user back the terminal.
5391 In non-stop mode, the target can't tell whether we've already
5392 consumed previous stop events, so it can end up sending us a
5393 no-resumed event like so:
5395 #0 - thread 1 is left stopped
5397 #1 - thread 2 is resumed and hits breakpoint
5398 -> TARGET_WAITKIND_STOPPED
5400 #2 - thread 3 is resumed and exits
5401 this is the last resumed thread, so
5402 -> TARGET_WAITKIND_NO_RESUMED
5404 #3 - gdb processes stop for thread 2 and decides to re-resume
5407 #4 - gdb processes the TARGET_WAITKIND_NO_RESUMED event.
5408 thread 2 is now resumed, so the event should be ignored.
5410 IOW, if the stop for thread 2 doesn't end a foreground command,
5411 then we need to ignore the following TARGET_WAITKIND_NO_RESUMED
5412 event. But it could be that the event meant that thread 2 itself
5413 (or whatever other thread was the last resumed thread) exited.
5415 To address this we refresh the thread list and check whether we
5416 have resumed threads _now_. In the example above, this removes
5417 thread 3 from the thread list. If thread 2 was re-resumed, we
5418 ignore this event. If we find no thread resumed, then we cancel
5419 the synchronous command and show "no unwaited-for " to the
5422 inferior
*curr_inf
= current_inferior ();
5424 scoped_restore_current_thread restore_thread
;
5425 update_thread_list ();
5429 - the current target has no thread executing, and
5430 - the current inferior is native, and
5431 - the current inferior is the one which has the terminal, and
5434 then a Ctrl-C from this point on would remain stuck in the
5435 kernel, until a thread resumes and dequeues it. That would
5436 result in the GDB CLI not reacting to Ctrl-C, not able to
5437 interrupt the program. To address this, if the current inferior
5438 no longer has any thread executing, we give the terminal to some
5439 other inferior that has at least one thread executing. */
5440 bool swap_terminal
= true;
5442 /* Whether to ignore this TARGET_WAITKIND_NO_RESUMED event, or
5443 whether to report it to the user. */
5444 bool ignore_event
= false;
5446 for (thread_info
*thread
: all_non_exited_threads ())
5448 if (swap_terminal
&& thread
->executing ())
5450 if (thread
->inf
!= curr_inf
)
5452 target_terminal::ours ();
5454 switch_to_thread (thread
);
5455 target_terminal::inferior ();
5457 swap_terminal
= false;
5460 if (!ignore_event
&& thread
->resumed ())
5462 /* Either there were no unwaited-for children left in the
5463 target at some point, but there are now, or some target
5464 other than the eventing one has unwaited-for children
5465 left. Just ignore. */
5466 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED "
5467 "(ignoring: found resumed)");
5469 ignore_event
= true;
5472 if (ignore_event
&& !swap_terminal
)
5478 switch_to_inferior_no_thread (curr_inf
);
5479 prepare_to_wait (ecs
);
5483 /* Go ahead and report the event. */
5487 /* Given an execution control state that has been freshly filled in by
5488 an event from the inferior, figure out what it means and take
5491 The alternatives are:
5493 1) stop_waiting and return; to really stop and return to the
5496 2) keep_going and return; to wait for the next event (set
5497 ecs->event_thread->stepping_over_breakpoint to 1 to single step
5501 handle_inferior_event (struct execution_control_state
*ecs
)
5503 /* Make sure that all temporary struct value objects that were
5504 created during the handling of the event get deleted at the
5506 scoped_value_mark free_values
;
5508 infrun_debug_printf ("%s", ecs
->ws
.to_string ().c_str ());
5510 if (ecs
->ws
.kind () == TARGET_WAITKIND_IGNORE
)
5512 /* We had an event in the inferior, but we are not interested in
5513 handling it at this level. The lower layers have already
5514 done what needs to be done, if anything.
5516 One of the possible circumstances for this is when the
5517 inferior produces output for the console. The inferior has
5518 not stopped, and we are ignoring the event. Another possible
5519 circumstance is any event which the lower level knows will be
5520 reported multiple times without an intervening resume. */
5521 prepare_to_wait (ecs
);
5525 if (ecs
->ws
.kind () == TARGET_WAITKIND_THREAD_EXITED
)
5527 prepare_to_wait (ecs
);
5531 if (ecs
->ws
.kind () == TARGET_WAITKIND_NO_RESUMED
5532 && handle_no_resumed (ecs
))
5535 /* Cache the last target/ptid/waitstatus. */
5536 set_last_target_status (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5538 /* Always clear state belonging to the previous time we stopped. */
5539 stop_stack_dummy
= STOP_NONE
;
5541 if (ecs
->ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
5543 /* No unwaited-for children left. IOW, all resumed children
5545 stop_print_frame
= false;
5550 if (ecs
->ws
.kind () != TARGET_WAITKIND_EXITED
5551 && ecs
->ws
.kind () != TARGET_WAITKIND_SIGNALLED
)
5553 ecs
->event_thread
= ecs
->target
->find_thread (ecs
->ptid
);
5554 /* If it's a new thread, add it to the thread database. */
5555 if (ecs
->event_thread
== nullptr)
5556 ecs
->event_thread
= add_thread (ecs
->target
, ecs
->ptid
);
5558 /* Disable range stepping. If the next step request could use a
5559 range, this will be end up re-enabled then. */
5560 ecs
->event_thread
->control
.may_range_step
= 0;
5563 /* Dependent on valid ECS->EVENT_THREAD. */
5564 adjust_pc_after_break (ecs
->event_thread
, ecs
->ws
);
5566 /* Dependent on the current PC value modified by adjust_pc_after_break. */
5567 reinit_frame_cache ();
5569 breakpoint_retire_moribund ();
5571 /* First, distinguish signals caused by the debugger from signals
5572 that have to do with the program's own actions. Note that
5573 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
5574 on the operating system version. Here we detect when a SIGILL or
5575 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
5576 something similar for SIGSEGV, since a SIGSEGV will be generated
5577 when we're trying to execute a breakpoint instruction on a
5578 non-executable stack. This happens for call dummy breakpoints
5579 for architectures like SPARC that place call dummies on the
5581 if (ecs
->ws
.kind () == TARGET_WAITKIND_STOPPED
5582 && (ecs
->ws
.sig () == GDB_SIGNAL_ILL
5583 || ecs
->ws
.sig () == GDB_SIGNAL_SEGV
5584 || ecs
->ws
.sig () == GDB_SIGNAL_EMT
))
5586 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5588 if (breakpoint_inserted_here_p (regcache
->aspace (),
5589 regcache_read_pc (regcache
)))
5591 infrun_debug_printf ("Treating signal as SIGTRAP");
5592 ecs
->ws
.set_stopped (GDB_SIGNAL_TRAP
);
5596 mark_non_executing_threads (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5598 switch (ecs
->ws
.kind ())
5600 case TARGET_WAITKIND_LOADED
:
5602 context_switch (ecs
);
5603 /* Ignore gracefully during startup of the inferior, as it might
5604 be the shell which has just loaded some objects, otherwise
5605 add the symbols for the newly loaded objects. Also ignore at
5606 the beginning of an attach or remote session; we will query
5607 the full list of libraries once the connection is
5610 stop_kind stop_soon
= get_inferior_stop_soon (ecs
);
5611 if (stop_soon
== NO_STOP_QUIETLY
)
5613 struct regcache
*regcache
;
5615 regcache
= get_thread_regcache (ecs
->event_thread
);
5617 handle_solib_event ();
5619 ecs
->event_thread
->set_stop_pc (regcache_read_pc (regcache
));
5620 ecs
->event_thread
->control
.stop_bpstat
5621 = bpstat_stop_status_nowatch (regcache
->aspace (),
5622 ecs
->event_thread
->stop_pc (),
5623 ecs
->event_thread
, ecs
->ws
);
5625 if (handle_stop_requested (ecs
))
5628 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5630 /* A catchpoint triggered. */
5631 process_event_stop_test (ecs
);
5635 /* If requested, stop when the dynamic linker notifies
5636 gdb of events. This allows the user to get control
5637 and place breakpoints in initializer routines for
5638 dynamically loaded objects (among other things). */
5639 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5640 if (stop_on_solib_events
)
5642 /* Make sure we print "Stopped due to solib-event" in
5644 stop_print_frame
= true;
5651 /* If we are skipping through a shell, or through shared library
5652 loading that we aren't interested in, resume the program. If
5653 we're running the program normally, also resume. */
5654 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
5656 /* Loading of shared libraries might have changed breakpoint
5657 addresses. Make sure new breakpoints are inserted. */
5658 if (stop_soon
== NO_STOP_QUIETLY
)
5659 insert_breakpoints ();
5660 resume (GDB_SIGNAL_0
);
5661 prepare_to_wait (ecs
);
5665 /* But stop if we're attaching or setting up a remote
5667 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
5668 || stop_soon
== STOP_QUIETLY_REMOTE
)
5670 infrun_debug_printf ("quietly stopped");
5675 internal_error (_("unhandled stop_soon: %d"), (int) stop_soon
);
5678 case TARGET_WAITKIND_SPURIOUS
:
5679 if (handle_stop_requested (ecs
))
5681 context_switch (ecs
);
5682 resume (GDB_SIGNAL_0
);
5683 prepare_to_wait (ecs
);
5686 case TARGET_WAITKIND_THREAD_CREATED
:
5687 if (handle_stop_requested (ecs
))
5689 context_switch (ecs
);
5690 if (!switch_back_to_stepped_thread (ecs
))
5694 case TARGET_WAITKIND_EXITED
:
5695 case TARGET_WAITKIND_SIGNALLED
:
5697 /* Depending on the system, ecs->ptid may point to a thread or
5698 to a process. On some targets, target_mourn_inferior may
5699 need to have access to the just-exited thread. That is the
5700 case of GNU/Linux's "checkpoint" support, for example.
5701 Call the switch_to_xxx routine as appropriate. */
5702 thread_info
*thr
= ecs
->target
->find_thread (ecs
->ptid
);
5704 switch_to_thread (thr
);
5707 inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5708 switch_to_inferior_no_thread (inf
);
5711 handle_vfork_child_exec_or_exit (0);
5712 target_terminal::ours (); /* Must do this before mourn anyway. */
5714 /* Clearing any previous state of convenience variables. */
5715 clear_exit_convenience_vars ();
5717 if (ecs
->ws
.kind () == TARGET_WAITKIND_EXITED
)
5719 /* Record the exit code in the convenience variable $_exitcode, so
5720 that the user can inspect this again later. */
5721 set_internalvar_integer (lookup_internalvar ("_exitcode"),
5722 (LONGEST
) ecs
->ws
.exit_status ());
5724 /* Also record this in the inferior itself. */
5725 current_inferior ()->has_exit_code
= true;
5726 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.exit_status ();
5728 /* Support the --return-child-result option. */
5729 return_child_result_value
= ecs
->ws
.exit_status ();
5731 gdb::observers::exited
.notify (ecs
->ws
.exit_status ());
5735 struct gdbarch
*gdbarch
= current_inferior ()->gdbarch
;
5737 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
5739 /* Set the value of the internal variable $_exitsignal,
5740 which holds the signal uncaught by the inferior. */
5741 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
5742 gdbarch_gdb_signal_to_target (gdbarch
,
5747 /* We don't have access to the target's method used for
5748 converting between signal numbers (GDB's internal
5749 representation <-> target's representation).
5750 Therefore, we cannot do a good job at displaying this
5751 information to the user. It's better to just warn
5752 her about it (if infrun debugging is enabled), and
5754 infrun_debug_printf ("Cannot fill $_exitsignal with the correct "
5758 gdb::observers::signal_exited
.notify (ecs
->ws
.sig ());
5761 gdb_flush (gdb_stdout
);
5762 target_mourn_inferior (inferior_ptid
);
5763 stop_print_frame
= false;
5767 case TARGET_WAITKIND_FORKED
:
5768 case TARGET_WAITKIND_VFORKED
:
5769 /* Check whether the inferior is displaced stepping. */
5771 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5772 struct gdbarch
*gdbarch
= regcache
->arch ();
5773 inferior
*parent_inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5775 /* If this is a fork (child gets its own address space copy)
5776 and some displaced step buffers were in use at the time of
5777 the fork, restore the displaced step buffer bytes in the
5780 Architectures which support displaced stepping and fork
5781 events must supply an implementation of
5782 gdbarch_displaced_step_restore_all_in_ptid. This is not
5783 enforced during gdbarch validation to support architectures
5784 which support displaced stepping but not forks. */
5785 if (ecs
->ws
.kind () == TARGET_WAITKIND_FORKED
5786 && gdbarch_supports_displaced_stepping (gdbarch
))
5787 gdbarch_displaced_step_restore_all_in_ptid
5788 (gdbarch
, parent_inf
, ecs
->ws
.child_ptid ());
5790 /* If displaced stepping is supported, and thread ecs->ptid is
5791 displaced stepping. */
5792 if (displaced_step_in_progress_thread (ecs
->event_thread
))
5794 struct regcache
*child_regcache
;
5795 CORE_ADDR parent_pc
;
5797 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
5798 indicating that the displaced stepping of syscall instruction
5799 has been done. Perform cleanup for parent process here. Note
5800 that this operation also cleans up the child process for vfork,
5801 because their pages are shared. */
5802 displaced_step_finish (ecs
->event_thread
, ecs
->ws
);
5803 /* Start a new step-over in another thread if there's one
5807 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
5808 the child's PC is also within the scratchpad. Set the child's PC
5809 to the parent's PC value, which has already been fixed up.
5810 FIXME: we use the parent's aspace here, although we're touching
5811 the child, because the child hasn't been added to the inferior
5812 list yet at this point. */
5815 = get_thread_arch_aspace_regcache (parent_inf
,
5816 ecs
->ws
.child_ptid (),
5818 parent_inf
->aspace
);
5819 /* Read PC value of parent process. */
5820 parent_pc
= regcache_read_pc (regcache
);
5822 displaced_debug_printf ("write child pc from %s to %s",
5824 regcache_read_pc (child_regcache
)),
5825 paddress (gdbarch
, parent_pc
));
5827 regcache_write_pc (child_regcache
, parent_pc
);
5831 context_switch (ecs
);
5833 /* Immediately detach breakpoints from the child before there's
5834 any chance of letting the user delete breakpoints from the
5835 breakpoint lists. If we don't do this early, it's easy to
5836 leave left over traps in the child, vis: "break foo; catch
5837 fork; c; <fork>; del; c; <child calls foo>". We only follow
5838 the fork on the last `continue', and by that time the
5839 breakpoint at "foo" is long gone from the breakpoint table.
5840 If we vforked, then we don't need to unpatch here, since both
5841 parent and child are sharing the same memory pages; we'll
5842 need to unpatch at follow/detach time instead to be certain
5843 that new breakpoints added between catchpoint hit time and
5844 vfork follow are detached. */
5845 if (ecs
->ws
.kind () != TARGET_WAITKIND_VFORKED
)
5847 /* This won't actually modify the breakpoint list, but will
5848 physically remove the breakpoints from the child. */
5849 detach_breakpoints (ecs
->ws
.child_ptid ());
5852 delete_just_stopped_threads_single_step_breakpoints ();
5854 /* In case the event is caught by a catchpoint, remember that
5855 the event is to be followed at the next resume of the thread,
5856 and not immediately. */
5857 ecs
->event_thread
->pending_follow
= ecs
->ws
;
5859 ecs
->event_thread
->set_stop_pc
5860 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
5862 ecs
->event_thread
->control
.stop_bpstat
5863 = bpstat_stop_status_nowatch (get_current_regcache ()->aspace (),
5864 ecs
->event_thread
->stop_pc (),
5865 ecs
->event_thread
, ecs
->ws
);
5867 if (handle_stop_requested (ecs
))
5870 /* If no catchpoint triggered for this, then keep going. Note
5871 that we're interested in knowing the bpstat actually causes a
5872 stop, not just if it may explain the signal. Software
5873 watchpoints, for example, always appear in the bpstat. */
5874 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5877 = (follow_fork_mode_string
== follow_fork_mode_child
);
5879 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5881 process_stratum_target
*targ
5882 = ecs
->event_thread
->inf
->process_target ();
5884 bool should_resume
= follow_fork ();
5886 /* Note that one of these may be an invalid pointer,
5887 depending on detach_fork. */
5888 thread_info
*parent
= ecs
->event_thread
;
5889 thread_info
*child
= targ
->find_thread (ecs
->ws
.child_ptid ());
5891 /* At this point, the parent is marked running, and the
5892 child is marked stopped. */
5894 /* If not resuming the parent, mark it stopped. */
5895 if (follow_child
&& !detach_fork
&& !non_stop
&& !sched_multi
)
5896 parent
->set_running (false);
5898 /* If resuming the child, mark it running. */
5899 if (follow_child
|| (!detach_fork
&& (non_stop
|| sched_multi
)))
5900 child
->set_running (true);
5902 /* In non-stop mode, also resume the other branch. */
5903 if (!detach_fork
&& (non_stop
5904 || (sched_multi
&& target_is_non_stop_p ())))
5907 switch_to_thread (parent
);
5909 switch_to_thread (child
);
5911 ecs
->event_thread
= inferior_thread ();
5912 ecs
->ptid
= inferior_ptid
;
5917 switch_to_thread (child
);
5919 switch_to_thread (parent
);
5921 ecs
->event_thread
= inferior_thread ();
5922 ecs
->ptid
= inferior_ptid
;
5926 /* Never call switch_back_to_stepped_thread if we are waiting for
5927 vfork-done (waiting for an external vfork child to exec or
5928 exit). We will resume only the vforking thread for the purpose
5929 of collecting the vfork-done event, and we will restart any
5930 step once the critical shared address space window is done. */
5933 && parent
->inf
->thread_waiting_for_vfork_done
!= nullptr)
5934 || !switch_back_to_stepped_thread (ecs
))
5941 process_event_stop_test (ecs
);
5944 case TARGET_WAITKIND_VFORK_DONE
:
5945 /* Done with the shared memory region. Re-insert breakpoints in
5946 the parent, and keep going. */
5948 context_switch (ecs
);
5950 handle_vfork_done (ecs
->event_thread
);
5951 gdb_assert (inferior_thread () == ecs
->event_thread
);
5953 if (handle_stop_requested (ecs
))
5956 if (!switch_back_to_stepped_thread (ecs
))
5958 gdb_assert (inferior_thread () == ecs
->event_thread
);
5959 /* This also takes care of reinserting breakpoints in the
5960 previously locked inferior. */
5965 case TARGET_WAITKIND_EXECD
:
5967 /* Note we can't read registers yet (the stop_pc), because we
5968 don't yet know the inferior's post-exec architecture.
5969 'stop_pc' is explicitly read below instead. */
5970 switch_to_thread_no_regs (ecs
->event_thread
);
5972 /* Do whatever is necessary to the parent branch of the vfork. */
5973 handle_vfork_child_exec_or_exit (1);
5975 /* This causes the eventpoints and symbol table to be reset.
5976 Must do this now, before trying to determine whether to
5978 follow_exec (inferior_ptid
, ecs
->ws
.execd_pathname ());
5980 /* In follow_exec we may have deleted the original thread and
5981 created a new one. Make sure that the event thread is the
5982 execd thread for that case (this is a nop otherwise). */
5983 ecs
->event_thread
= inferior_thread ();
5985 ecs
->event_thread
->set_stop_pc
5986 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
5988 ecs
->event_thread
->control
.stop_bpstat
5989 = bpstat_stop_status_nowatch (get_current_regcache ()->aspace (),
5990 ecs
->event_thread
->stop_pc (),
5991 ecs
->event_thread
, ecs
->ws
);
5993 if (handle_stop_requested (ecs
))
5996 /* If no catchpoint triggered for this, then keep going. */
5997 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5999 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6003 process_event_stop_test (ecs
);
6006 /* Be careful not to try to gather much state about a thread
6007 that's in a syscall. It's frequently a losing proposition. */
6008 case TARGET_WAITKIND_SYSCALL_ENTRY
:
6009 /* Getting the current syscall number. */
6010 if (handle_syscall_event (ecs
) == 0)
6011 process_event_stop_test (ecs
);
6014 /* Before examining the threads further, step this thread to
6015 get it entirely out of the syscall. (We get notice of the
6016 event when the thread is just on the verge of exiting a
6017 syscall. Stepping one instruction seems to get it back
6019 case TARGET_WAITKIND_SYSCALL_RETURN
:
6020 if (handle_syscall_event (ecs
) == 0)
6021 process_event_stop_test (ecs
);
6024 case TARGET_WAITKIND_STOPPED
:
6025 handle_signal_stop (ecs
);
6028 case TARGET_WAITKIND_NO_HISTORY
:
6029 /* Reverse execution: target ran out of history info. */
6031 /* Switch to the stopped thread. */
6032 context_switch (ecs
);
6033 infrun_debug_printf ("stopped");
6035 delete_just_stopped_threads_single_step_breakpoints ();
6036 ecs
->event_thread
->set_stop_pc
6037 (regcache_read_pc (get_thread_regcache (inferior_thread ())));
6039 if (handle_stop_requested (ecs
))
6042 gdb::observers::no_history
.notify ();
6048 /* Restart threads back to what they were trying to do back when we
6049 paused them (because of an in-line step-over or vfork, for example).
6050 The EVENT_THREAD thread is ignored (not restarted).
6052 If INF is non-nullptr, only resume threads from INF. */
6055 restart_threads (struct thread_info
*event_thread
, inferior
*inf
)
6057 INFRUN_SCOPED_DEBUG_START_END ("event_thread=%s, inf=%d",
6058 event_thread
->ptid
.to_string ().c_str (),
6059 inf
!= nullptr ? inf
->num
: -1);
6061 gdb_assert (!step_over_info_valid_p ());
6063 /* In case the instruction just stepped spawned a new thread. */
6064 update_thread_list ();
6066 for (thread_info
*tp
: all_non_exited_threads ())
6068 if (inf
!= nullptr && tp
->inf
!= inf
)
6071 if (tp
->inf
->detaching
)
6073 infrun_debug_printf ("restart threads: [%s] inferior detaching",
6074 tp
->ptid
.to_string ().c_str ());
6078 switch_to_thread_no_regs (tp
);
6080 if (tp
== event_thread
)
6082 infrun_debug_printf ("restart threads: [%s] is event thread",
6083 tp
->ptid
.to_string ().c_str ());
6087 if (!(tp
->state
== THREAD_RUNNING
|| tp
->control
.in_infcall
))
6089 infrun_debug_printf ("restart threads: [%s] not meant to be running",
6090 tp
->ptid
.to_string ().c_str ());
6096 infrun_debug_printf ("restart threads: [%s] resumed",
6097 tp
->ptid
.to_string ().c_str ());
6098 gdb_assert (tp
->executing () || tp
->has_pending_waitstatus ());
6102 if (thread_is_in_step_over_chain (tp
))
6104 infrun_debug_printf ("restart threads: [%s] needs step-over",
6105 tp
->ptid
.to_string ().c_str ());
6106 gdb_assert (!tp
->resumed ());
6111 if (tp
->has_pending_waitstatus ())
6113 infrun_debug_printf ("restart threads: [%s] has pending status",
6114 tp
->ptid
.to_string ().c_str ());
6115 tp
->set_resumed (true);
6119 gdb_assert (!tp
->stop_requested
);
6121 /* If some thread needs to start a step-over at this point, it
6122 should still be in the step-over queue, and thus skipped
6124 if (thread_still_needs_step_over (tp
))
6126 internal_error ("thread [%s] needs a step-over, but not in "
6127 "step-over queue\n",
6128 tp
->ptid
.to_string ().c_str ());
6131 if (currently_stepping (tp
))
6133 infrun_debug_printf ("restart threads: [%s] was stepping",
6134 tp
->ptid
.to_string ().c_str ());
6135 keep_going_stepped_thread (tp
);
6139 infrun_debug_printf ("restart threads: [%s] continuing",
6140 tp
->ptid
.to_string ().c_str ());
6141 execution_control_state
ecs (tp
);
6142 switch_to_thread (tp
);
6143 keep_going_pass_signal (&ecs
);
6148 /* Callback for iterate_over_threads. Find a resumed thread that has
6149 a pending waitstatus. */
6152 resumed_thread_with_pending_status (struct thread_info
*tp
,
6155 return tp
->resumed () && tp
->has_pending_waitstatus ();
6158 /* Called when we get an event that may finish an in-line or
6159 out-of-line (displaced stepping) step-over started previously.
6160 Return true if the event is processed and we should go back to the
6161 event loop; false if the caller should continue processing the
6165 finish_step_over (struct execution_control_state
*ecs
)
6167 displaced_step_finish (ecs
->event_thread
, ecs
->ws
);
6169 bool had_step_over_info
= step_over_info_valid_p ();
6171 if (had_step_over_info
)
6173 /* If we're stepping over a breakpoint with all threads locked,
6174 then only the thread that was stepped should be reporting
6176 gdb_assert (ecs
->event_thread
->control
.trap_expected
);
6178 clear_step_over_info ();
6181 if (!target_is_non_stop_p ())
6184 /* Start a new step-over in another thread if there's one that
6188 /* If we were stepping over a breakpoint before, and haven't started
6189 a new in-line step-over sequence, then restart all other threads
6190 (except the event thread). We can't do this in all-stop, as then
6191 e.g., we wouldn't be able to issue any other remote packet until
6192 these other threads stop. */
6193 if (had_step_over_info
&& !step_over_info_valid_p ())
6195 struct thread_info
*pending
;
6197 /* If we only have threads with pending statuses, the restart
6198 below won't restart any thread and so nothing re-inserts the
6199 breakpoint we just stepped over. But we need it inserted
6200 when we later process the pending events, otherwise if
6201 another thread has a pending event for this breakpoint too,
6202 we'd discard its event (because the breakpoint that
6203 originally caused the event was no longer inserted). */
6204 context_switch (ecs
);
6205 insert_breakpoints ();
6207 restart_threads (ecs
->event_thread
);
6209 /* If we have events pending, go through handle_inferior_event
6210 again, picking up a pending event at random. This avoids
6211 thread starvation. */
6213 /* But not if we just stepped over a watchpoint in order to let
6214 the instruction execute so we can evaluate its expression.
6215 The set of watchpoints that triggered is recorded in the
6216 breakpoint objects themselves (see bp->watchpoint_triggered).
6217 If we processed another event first, that other event could
6218 clobber this info. */
6219 if (ecs
->event_thread
->stepping_over_watchpoint
)
6222 pending
= iterate_over_threads (resumed_thread_with_pending_status
,
6224 if (pending
!= nullptr)
6226 struct thread_info
*tp
= ecs
->event_thread
;
6227 struct regcache
*regcache
;
6229 infrun_debug_printf ("found resumed threads with "
6230 "pending events, saving status");
6232 gdb_assert (pending
!= tp
);
6234 /* Record the event thread's event for later. */
6235 save_waitstatus (tp
, ecs
->ws
);
6236 /* This was cleared early, by handle_inferior_event. Set it
6237 so this pending event is considered by
6239 tp
->set_resumed (true);
6241 gdb_assert (!tp
->executing ());
6243 regcache
= get_thread_regcache (tp
);
6244 tp
->set_stop_pc (regcache_read_pc (regcache
));
6246 infrun_debug_printf ("saved stop_pc=%s for %s "
6247 "(currently_stepping=%d)",
6248 paddress (target_gdbarch (), tp
->stop_pc ()),
6249 tp
->ptid
.to_string ().c_str (),
6250 currently_stepping (tp
));
6252 /* This in-line step-over finished; clear this so we won't
6253 start a new one. This is what handle_signal_stop would
6254 do, if we returned false. */
6255 tp
->stepping_over_breakpoint
= 0;
6257 /* Wake up the event loop again. */
6258 mark_async_event_handler (infrun_async_inferior_event_token
);
6260 prepare_to_wait (ecs
);
6271 notify_signal_received (gdb_signal sig
)
6273 interps_notify_signal_received (sig
);
6274 gdb::observers::signal_received
.notify (sig
);
6277 /* Come here when the program has stopped with a signal. */
6280 handle_signal_stop (struct execution_control_state
*ecs
)
6282 frame_info_ptr frame
;
6283 struct gdbarch
*gdbarch
;
6284 int stopped_by_watchpoint
;
6285 enum stop_kind stop_soon
;
6288 gdb_assert (ecs
->ws
.kind () == TARGET_WAITKIND_STOPPED
);
6290 ecs
->event_thread
->set_stop_signal (ecs
->ws
.sig ());
6292 /* Do we need to clean up the state of a thread that has
6293 completed a displaced single-step? (Doing so usually affects
6294 the PC, so do it here, before we set stop_pc.) */
6295 if (finish_step_over (ecs
))
6298 /* If we either finished a single-step or hit a breakpoint, but
6299 the user wanted this thread to be stopped, pretend we got a
6300 SIG0 (generic unsignaled stop). */
6301 if (ecs
->event_thread
->stop_requested
6302 && ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
6303 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6305 ecs
->event_thread
->set_stop_pc
6306 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
6308 context_switch (ecs
);
6310 if (deprecated_context_hook
)
6311 deprecated_context_hook (ecs
->event_thread
->global_num
);
6315 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
6316 struct gdbarch
*reg_gdbarch
= regcache
->arch ();
6319 ("stop_pc=%s", paddress (reg_gdbarch
, ecs
->event_thread
->stop_pc ()));
6320 if (target_stopped_by_watchpoint ())
6324 infrun_debug_printf ("stopped by watchpoint");
6326 if (target_stopped_data_address (current_inferior ()->top_target (),
6328 infrun_debug_printf ("stopped data address=%s",
6329 paddress (reg_gdbarch
, addr
));
6331 infrun_debug_printf ("(no data address available)");
6335 /* This is originated from start_remote(), start_inferior() and
6336 shared libraries hook functions. */
6337 stop_soon
= get_inferior_stop_soon (ecs
);
6338 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
6340 infrun_debug_printf ("quietly stopped");
6341 stop_print_frame
= true;
6346 /* This originates from attach_command(). We need to overwrite
6347 the stop_signal here, because some kernels don't ignore a
6348 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
6349 See more comments in inferior.h. On the other hand, if we
6350 get a non-SIGSTOP, report it to the user - assume the backend
6351 will handle the SIGSTOP if it should show up later.
6353 Also consider that the attach is complete when we see a
6354 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
6355 target extended-remote report it instead of a SIGSTOP
6356 (e.g. gdbserver). We already rely on SIGTRAP being our
6357 signal, so this is no exception.
6359 Also consider that the attach is complete when we see a
6360 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
6361 the target to stop all threads of the inferior, in case the
6362 low level attach operation doesn't stop them implicitly. If
6363 they weren't stopped implicitly, then the stub will report a
6364 GDB_SIGNAL_0, meaning: stopped for no particular reason
6365 other than GDB's request. */
6366 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
6367 && (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_STOP
6368 || ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6369 || ecs
->event_thread
->stop_signal () == GDB_SIGNAL_0
))
6371 stop_print_frame
= true;
6373 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6377 /* At this point, get hold of the now-current thread's frame. */
6378 frame
= get_current_frame ();
6379 gdbarch
= get_frame_arch (frame
);
6381 /* Pull the single step breakpoints out of the target. */
6382 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
6384 struct regcache
*regcache
;
6387 regcache
= get_thread_regcache (ecs
->event_thread
);
6388 const address_space
*aspace
= regcache
->aspace ();
6390 pc
= regcache_read_pc (regcache
);
6392 /* However, before doing so, if this single-step breakpoint was
6393 actually for another thread, set this thread up for moving
6395 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
6398 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
6400 infrun_debug_printf ("[%s] hit another thread's single-step "
6402 ecs
->ptid
.to_string ().c_str ());
6403 ecs
->hit_singlestep_breakpoint
= 1;
6408 infrun_debug_printf ("[%s] hit its single-step breakpoint",
6409 ecs
->ptid
.to_string ().c_str ());
6412 delete_just_stopped_threads_single_step_breakpoints ();
6414 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6415 && ecs
->event_thread
->control
.trap_expected
6416 && ecs
->event_thread
->stepping_over_watchpoint
)
6417 stopped_by_watchpoint
= 0;
6419 stopped_by_watchpoint
= watchpoints_triggered (ecs
->ws
);
6421 /* If necessary, step over this watchpoint. We'll be back to display
6423 if (stopped_by_watchpoint
6424 && (target_have_steppable_watchpoint ()
6425 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
6427 /* At this point, we are stopped at an instruction which has
6428 attempted to write to a piece of memory under control of
6429 a watchpoint. The instruction hasn't actually executed
6430 yet. If we were to evaluate the watchpoint expression
6431 now, we would get the old value, and therefore no change
6432 would seem to have occurred.
6434 In order to make watchpoints work `right', we really need
6435 to complete the memory write, and then evaluate the
6436 watchpoint expression. We do this by single-stepping the
6439 It may not be necessary to disable the watchpoint to step over
6440 it. For example, the PA can (with some kernel cooperation)
6441 single step over a watchpoint without disabling the watchpoint.
6443 It is far more common to need to disable a watchpoint to step
6444 the inferior over it. If we have non-steppable watchpoints,
6445 we must disable the current watchpoint; it's simplest to
6446 disable all watchpoints.
6448 Any breakpoint at PC must also be stepped over -- if there's
6449 one, it will have already triggered before the watchpoint
6450 triggered, and we either already reported it to the user, or
6451 it didn't cause a stop and we called keep_going. In either
6452 case, if there was a breakpoint at PC, we must be trying to
6454 ecs
->event_thread
->stepping_over_watchpoint
= 1;
6459 ecs
->event_thread
->stepping_over_breakpoint
= 0;
6460 ecs
->event_thread
->stepping_over_watchpoint
= 0;
6461 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
6462 ecs
->event_thread
->control
.stop_step
= 0;
6463 stop_print_frame
= true;
6464 stopped_by_random_signal
= 0;
6465 bpstat
*stop_chain
= nullptr;
6467 /* Hide inlined functions starting here, unless we just performed stepi or
6468 nexti. After stepi and nexti, always show the innermost frame (not any
6469 inline function call sites). */
6470 if (ecs
->event_thread
->control
.step_range_end
!= 1)
6472 const address_space
*aspace
6473 = get_thread_regcache (ecs
->event_thread
)->aspace ();
6475 /* skip_inline_frames is expensive, so we avoid it if we can
6476 determine that the address is one where functions cannot have
6477 been inlined. This improves performance with inferiors that
6478 load a lot of shared libraries, because the solib event
6479 breakpoint is defined as the address of a function (i.e. not
6480 inline). Note that we have to check the previous PC as well
6481 as the current one to catch cases when we have just
6482 single-stepped off a breakpoint prior to reinstating it.
6483 Note that we're assuming that the code we single-step to is
6484 not inline, but that's not definitive: there's nothing
6485 preventing the event breakpoint function from containing
6486 inlined code, and the single-step ending up there. If the
6487 user had set a breakpoint on that inlined code, the missing
6488 skip_inline_frames call would break things. Fortunately
6489 that's an extremely unlikely scenario. */
6490 if (!pc_at_non_inline_function (aspace
,
6491 ecs
->event_thread
->stop_pc (),
6493 && !(ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6494 && ecs
->event_thread
->control
.trap_expected
6495 && pc_at_non_inline_function (aspace
,
6496 ecs
->event_thread
->prev_pc
,
6499 stop_chain
= build_bpstat_chain (aspace
,
6500 ecs
->event_thread
->stop_pc (),
6502 skip_inline_frames (ecs
->event_thread
, stop_chain
);
6504 /* Re-fetch current thread's frame in case that invalidated
6506 frame
= get_current_frame ();
6507 gdbarch
= get_frame_arch (frame
);
6511 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6512 && ecs
->event_thread
->control
.trap_expected
6513 && gdbarch_single_step_through_delay_p (gdbarch
)
6514 && currently_stepping (ecs
->event_thread
))
6516 /* We're trying to step off a breakpoint. Turns out that we're
6517 also on an instruction that needs to be stepped multiple
6518 times before it's been fully executing. E.g., architectures
6519 with a delay slot. It needs to be stepped twice, once for
6520 the instruction and once for the delay slot. */
6521 int step_through_delay
6522 = gdbarch_single_step_through_delay (gdbarch
, frame
);
6524 if (step_through_delay
)
6525 infrun_debug_printf ("step through delay");
6527 if (ecs
->event_thread
->control
.step_range_end
== 0
6528 && step_through_delay
)
6530 /* The user issued a continue when stopped at a breakpoint.
6531 Set up for another trap and get out of here. */
6532 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6536 else if (step_through_delay
)
6538 /* The user issued a step when stopped at a breakpoint.
6539 Maybe we should stop, maybe we should not - the delay
6540 slot *might* correspond to a line of source. In any
6541 case, don't decide that here, just set
6542 ecs->stepping_over_breakpoint, making sure we
6543 single-step again before breakpoints are re-inserted. */
6544 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6548 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
6549 handles this event. */
6550 ecs
->event_thread
->control
.stop_bpstat
6551 = bpstat_stop_status (get_current_regcache ()->aspace (),
6552 ecs
->event_thread
->stop_pc (),
6553 ecs
->event_thread
, ecs
->ws
, stop_chain
);
6555 /* Following in case break condition called a
6557 stop_print_frame
= true;
6559 /* This is where we handle "moribund" watchpoints. Unlike
6560 software breakpoints traps, hardware watchpoint traps are
6561 always distinguishable from random traps. If no high-level
6562 watchpoint is associated with the reported stop data address
6563 anymore, then the bpstat does not explain the signal ---
6564 simply make sure to ignore it if `stopped_by_watchpoint' is
6567 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6568 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6570 && stopped_by_watchpoint
)
6572 infrun_debug_printf ("no user watchpoint explains watchpoint SIGTRAP, "
6576 /* NOTE: cagney/2003-03-29: These checks for a random signal
6577 at one stage in the past included checks for an inferior
6578 function call's call dummy's return breakpoint. The original
6579 comment, that went with the test, read:
6581 ``End of a stack dummy. Some systems (e.g. Sony news) give
6582 another signal besides SIGTRAP, so check here as well as
6585 If someone ever tries to get call dummys on a
6586 non-executable stack to work (where the target would stop
6587 with something like a SIGSEGV), then those tests might need
6588 to be re-instated. Given, however, that the tests were only
6589 enabled when momentary breakpoints were not being used, I
6590 suspect that it won't be the case.
6592 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
6593 be necessary for call dummies on a non-executable stack on
6596 /* See if the breakpoints module can explain the signal. */
6598 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6599 ecs
->event_thread
->stop_signal ());
6601 /* Maybe this was a trap for a software breakpoint that has since
6603 if (random_signal
&& target_stopped_by_sw_breakpoint ())
6605 if (gdbarch_program_breakpoint_here_p (gdbarch
,
6606 ecs
->event_thread
->stop_pc ()))
6608 struct regcache
*regcache
;
6611 /* Re-adjust PC to what the program would see if GDB was not
6613 regcache
= get_thread_regcache (ecs
->event_thread
);
6614 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
6617 gdb::optional
<scoped_restore_tmpl
<int>>
6618 restore_operation_disable
;
6620 if (record_full_is_used ())
6621 restore_operation_disable
.emplace
6622 (record_full_gdb_operation_disable_set ());
6624 regcache_write_pc (regcache
,
6625 ecs
->event_thread
->stop_pc () + decr_pc
);
6630 /* A delayed software breakpoint event. Ignore the trap. */
6631 infrun_debug_printf ("delayed software breakpoint trap, ignoring");
6636 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
6637 has since been removed. */
6638 if (random_signal
&& target_stopped_by_hw_breakpoint ())
6640 /* A delayed hardware breakpoint event. Ignore the trap. */
6641 infrun_debug_printf ("delayed hardware breakpoint/watchpoint "
6646 /* If not, perhaps stepping/nexting can. */
6648 random_signal
= !(ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6649 && currently_stepping (ecs
->event_thread
));
6651 /* Perhaps the thread hit a single-step breakpoint of _another_
6652 thread. Single-step breakpoints are transparent to the
6653 breakpoints module. */
6655 random_signal
= !ecs
->hit_singlestep_breakpoint
;
6657 /* No? Perhaps we got a moribund watchpoint. */
6659 random_signal
= !stopped_by_watchpoint
;
6661 /* Always stop if the user explicitly requested this thread to
6663 if (ecs
->event_thread
->stop_requested
)
6666 infrun_debug_printf ("user-requested stop");
6669 /* For the program's own signals, act according to
6670 the signal handling tables. */
6674 /* Signal not for debugging purposes. */
6675 enum gdb_signal stop_signal
= ecs
->event_thread
->stop_signal ();
6677 infrun_debug_printf ("random signal (%s)",
6678 gdb_signal_to_symbol_string (stop_signal
));
6680 stopped_by_random_signal
= 1;
6682 /* Always stop on signals if we're either just gaining control
6683 of the program, or the user explicitly requested this thread
6684 to remain stopped. */
6685 if (stop_soon
!= NO_STOP_QUIETLY
6686 || ecs
->event_thread
->stop_requested
6687 || signal_stop_state (ecs
->event_thread
->stop_signal ()))
6693 /* Notify observers the signal has "handle print" set. Note we
6694 returned early above if stopping; normal_stop handles the
6695 printing in that case. */
6696 if (signal_print
[ecs
->event_thread
->stop_signal ()])
6698 /* The signal table tells us to print about this signal. */
6699 target_terminal::ours_for_output ();
6700 notify_signal_received (ecs
->event_thread
->stop_signal ());
6701 target_terminal::inferior ();
6704 /* Clear the signal if it should not be passed. */
6705 if (signal_program
[ecs
->event_thread
->stop_signal ()] == 0)
6706 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6708 if (ecs
->event_thread
->prev_pc
== ecs
->event_thread
->stop_pc ()
6709 && ecs
->event_thread
->control
.trap_expected
6710 && ecs
->event_thread
->control
.step_resume_breakpoint
== nullptr)
6712 /* We were just starting a new sequence, attempting to
6713 single-step off of a breakpoint and expecting a SIGTRAP.
6714 Instead this signal arrives. This signal will take us out
6715 of the stepping range so GDB needs to remember to, when
6716 the signal handler returns, resume stepping off that
6718 /* To simplify things, "continue" is forced to use the same
6719 code paths as single-step - set a breakpoint at the
6720 signal return address and then, once hit, step off that
6722 infrun_debug_printf ("signal arrived while stepping over breakpoint");
6724 insert_hp_step_resume_breakpoint_at_frame (frame
);
6725 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6726 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6727 ecs
->event_thread
->control
.trap_expected
= 0;
6729 /* If we were nexting/stepping some other thread, switch to
6730 it, so that we don't continue it, losing control. */
6731 if (!switch_back_to_stepped_thread (ecs
))
6736 if (ecs
->event_thread
->stop_signal () != GDB_SIGNAL_0
6737 && (pc_in_thread_step_range (ecs
->event_thread
->stop_pc (),
6739 || ecs
->event_thread
->control
.step_range_end
== 1)
6740 && (get_stack_frame_id (frame
)
6741 == ecs
->event_thread
->control
.step_stack_frame_id
)
6742 && ecs
->event_thread
->control
.step_resume_breakpoint
== nullptr)
6744 /* The inferior is about to take a signal that will take it
6745 out of the single step range. Set a breakpoint at the
6746 current PC (which is presumably where the signal handler
6747 will eventually return) and then allow the inferior to
6750 Note that this is only needed for a signal delivered
6751 while in the single-step range. Nested signals aren't a
6752 problem as they eventually all return. */
6753 infrun_debug_printf ("signal may take us out of single-step range");
6755 clear_step_over_info ();
6756 insert_hp_step_resume_breakpoint_at_frame (frame
);
6757 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6758 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6759 ecs
->event_thread
->control
.trap_expected
= 0;
6764 /* Note: step_resume_breakpoint may be non-NULL. This occurs
6765 when either there's a nested signal, or when there's a
6766 pending signal enabled just as the signal handler returns
6767 (leaving the inferior at the step-resume-breakpoint without
6768 actually executing it). Either way continue until the
6769 breakpoint is really hit. */
6771 if (!switch_back_to_stepped_thread (ecs
))
6773 infrun_debug_printf ("random signal, keep going");
6780 process_event_stop_test (ecs
);
6783 /* Come here when we've got some debug event / signal we can explain
6784 (IOW, not a random signal), and test whether it should cause a
6785 stop, or whether we should resume the inferior (transparently).
6786 E.g., could be a breakpoint whose condition evaluates false; we
6787 could be still stepping within the line; etc. */
6790 process_event_stop_test (struct execution_control_state
*ecs
)
6792 struct symtab_and_line stop_pc_sal
;
6793 frame_info_ptr frame
;
6794 struct gdbarch
*gdbarch
;
6795 CORE_ADDR jmp_buf_pc
;
6796 struct bpstat_what what
;
6798 /* Handle cases caused by hitting a breakpoint. */
6800 frame
= get_current_frame ();
6801 gdbarch
= get_frame_arch (frame
);
6803 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
6805 if (what
.call_dummy
)
6807 stop_stack_dummy
= what
.call_dummy
;
6810 /* A few breakpoint types have callbacks associated (e.g.,
6811 bp_jit_event). Run them now. */
6812 bpstat_run_callbacks (ecs
->event_thread
->control
.stop_bpstat
);
6814 /* If we hit an internal event that triggers symbol changes, the
6815 current frame will be invalidated within bpstat_what (e.g., if we
6816 hit an internal solib event). Re-fetch it. */
6817 frame
= get_current_frame ();
6818 gdbarch
= get_frame_arch (frame
);
6820 switch (what
.main_action
)
6822 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
6823 /* If we hit the breakpoint at longjmp while stepping, we
6824 install a momentary breakpoint at the target of the
6827 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME");
6829 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6831 if (what
.is_longjmp
)
6833 struct value
*arg_value
;
6835 /* If we set the longjmp breakpoint via a SystemTap probe,
6836 then use it to extract the arguments. The destination PC
6837 is the third argument to the probe. */
6838 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
6841 jmp_buf_pc
= value_as_address (arg_value
);
6842 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
6844 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
6845 || !gdbarch_get_longjmp_target (gdbarch
,
6846 frame
, &jmp_buf_pc
))
6848 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME "
6849 "(!gdbarch_get_longjmp_target)");
6854 /* Insert a breakpoint at resume address. */
6855 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
6858 check_exception_resume (ecs
, frame
);
6862 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
6864 frame_info_ptr init_frame
;
6866 /* There are several cases to consider.
6868 1. The initiating frame no longer exists. In this case we
6869 must stop, because the exception or longjmp has gone too
6872 2. The initiating frame exists, and is the same as the
6873 current frame. We stop, because the exception or longjmp
6876 3. The initiating frame exists and is different from the
6877 current frame. This means the exception or longjmp has
6878 been caught beneath the initiating frame, so keep going.
6880 4. longjmp breakpoint has been placed just to protect
6881 against stale dummy frames and user is not interested in
6882 stopping around longjmps. */
6884 infrun_debug_printf ("BPSTAT_WHAT_CLEAR_LONGJMP_RESUME");
6886 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
6888 delete_exception_resume_breakpoint (ecs
->event_thread
);
6890 if (what
.is_longjmp
)
6892 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
6894 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
6902 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
6906 struct frame_id current_id
6907 = get_frame_id (get_current_frame ());
6908 if (current_id
== ecs
->event_thread
->initiating_frame
)
6910 /* Case 2. Fall through. */
6920 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
6922 delete_step_resume_breakpoint (ecs
->event_thread
);
6924 end_stepping_range (ecs
);
6928 case BPSTAT_WHAT_SINGLE
:
6929 infrun_debug_printf ("BPSTAT_WHAT_SINGLE");
6930 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6931 /* Still need to check other stuff, at least the case where we
6932 are stepping and step out of the right range. */
6935 case BPSTAT_WHAT_STEP_RESUME
:
6936 infrun_debug_printf ("BPSTAT_WHAT_STEP_RESUME");
6938 delete_step_resume_breakpoint (ecs
->event_thread
);
6939 if (ecs
->event_thread
->control
.proceed_to_finish
6940 && execution_direction
== EXEC_REVERSE
)
6942 struct thread_info
*tp
= ecs
->event_thread
;
6944 /* We are finishing a function in reverse, and just hit the
6945 step-resume breakpoint at the start address of the
6946 function, and we're almost there -- just need to back up
6947 by one more single-step, which should take us back to the
6949 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
6953 fill_in_stop_func (gdbarch
, ecs
);
6954 if (ecs
->event_thread
->stop_pc () == ecs
->stop_func_start
6955 && execution_direction
== EXEC_REVERSE
)
6957 /* We are stepping over a function call in reverse, and just
6958 hit the step-resume breakpoint at the start address of
6959 the function. Go back to single-stepping, which should
6960 take us back to the function call. */
6961 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6967 case BPSTAT_WHAT_STOP_NOISY
:
6968 infrun_debug_printf ("BPSTAT_WHAT_STOP_NOISY");
6969 stop_print_frame
= true;
6971 /* Assume the thread stopped for a breakpoint. We'll still check
6972 whether a/the breakpoint is there when the thread is next
6974 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6979 case BPSTAT_WHAT_STOP_SILENT
:
6980 infrun_debug_printf ("BPSTAT_WHAT_STOP_SILENT");
6981 stop_print_frame
= false;
6983 /* Assume the thread stopped for a breakpoint. We'll still check
6984 whether a/the breakpoint is there when the thread is next
6986 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6990 case BPSTAT_WHAT_HP_STEP_RESUME
:
6991 infrun_debug_printf ("BPSTAT_WHAT_HP_STEP_RESUME");
6993 delete_step_resume_breakpoint (ecs
->event_thread
);
6994 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
6996 /* Back when the step-resume breakpoint was inserted, we
6997 were trying to single-step off a breakpoint. Go back to
6999 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
7000 ecs
->event_thread
->stepping_over_breakpoint
= 1;
7006 case BPSTAT_WHAT_KEEP_CHECKING
:
7010 /* If we stepped a permanent breakpoint and we had a high priority
7011 step-resume breakpoint for the address we stepped, but we didn't
7012 hit it, then we must have stepped into the signal handler. The
7013 step-resume was only necessary to catch the case of _not_
7014 stepping into the handler, so delete it, and fall through to
7015 checking whether the step finished. */
7016 if (ecs
->event_thread
->stepped_breakpoint
)
7018 struct breakpoint
*sr_bp
7019 = ecs
->event_thread
->control
.step_resume_breakpoint
;
7021 if (sr_bp
!= nullptr
7022 && sr_bp
->first_loc ().permanent
7023 && sr_bp
->type
== bp_hp_step_resume
7024 && sr_bp
->first_loc ().address
== ecs
->event_thread
->prev_pc
)
7026 infrun_debug_printf ("stepped permanent breakpoint, stopped in handler");
7027 delete_step_resume_breakpoint (ecs
->event_thread
);
7028 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
7032 /* We come here if we hit a breakpoint but should not stop for it.
7033 Possibly we also were stepping and should stop for that. So fall
7034 through and test for stepping. But, if not stepping, do not
7037 /* In all-stop mode, if we're currently stepping but have stopped in
7038 some other thread, we need to switch back to the stepped thread. */
7039 if (switch_back_to_stepped_thread (ecs
))
7042 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
7044 infrun_debug_printf ("step-resume breakpoint is inserted");
7046 /* Having a step-resume breakpoint overrides anything
7047 else having to do with stepping commands until
7048 that breakpoint is reached. */
7053 if (ecs
->event_thread
->control
.step_range_end
== 0)
7055 infrun_debug_printf ("no stepping, continue");
7056 /* Likewise if we aren't even stepping. */
7061 /* Re-fetch current thread's frame in case the code above caused
7062 the frame cache to be re-initialized, making our FRAME variable
7063 a dangling pointer. */
7064 frame
= get_current_frame ();
7065 gdbarch
= get_frame_arch (frame
);
7066 fill_in_stop_func (gdbarch
, ecs
);
7068 /* If stepping through a line, keep going if still within it.
7070 Note that step_range_end is the address of the first instruction
7071 beyond the step range, and NOT the address of the last instruction
7074 Note also that during reverse execution, we may be stepping
7075 through a function epilogue and therefore must detect when
7076 the current-frame changes in the middle of a line. */
7078 if (pc_in_thread_step_range (ecs
->event_thread
->stop_pc (),
7080 && (execution_direction
!= EXEC_REVERSE
7081 || get_frame_id (frame
) == ecs
->event_thread
->control
.step_frame_id
))
7084 ("stepping inside range [%s-%s]",
7085 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
7086 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
7088 /* Tentatively re-enable range stepping; `resume' disables it if
7089 necessary (e.g., if we're stepping over a breakpoint or we
7090 have software watchpoints). */
7091 ecs
->event_thread
->control
.may_range_step
= 1;
7093 /* When stepping backward, stop at beginning of line range
7094 (unless it's the function entry point, in which case
7095 keep going back to the call point). */
7096 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7097 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
7098 && stop_pc
!= ecs
->stop_func_start
7099 && execution_direction
== EXEC_REVERSE
)
7100 end_stepping_range (ecs
);
7107 /* We stepped out of the stepping range. */
7109 /* If we are stepping at the source level and entered the runtime
7110 loader dynamic symbol resolution code...
7112 EXEC_FORWARD: we keep on single stepping until we exit the run
7113 time loader code and reach the callee's address.
7115 EXEC_REVERSE: we've already executed the callee (backward), and
7116 the runtime loader code is handled just like any other
7117 undebuggable function call. Now we need only keep stepping
7118 backward through the trampoline code, and that's handled further
7119 down, so there is nothing for us to do here. */
7121 if (execution_direction
!= EXEC_REVERSE
7122 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7123 && in_solib_dynsym_resolve_code (ecs
->event_thread
->stop_pc ())
7124 && (ecs
->event_thread
->control
.step_start_function
== nullptr
7125 || !in_solib_dynsym_resolve_code (
7126 ecs
->event_thread
->control
.step_start_function
->value_block ()
7129 CORE_ADDR pc_after_resolver
=
7130 gdbarch_skip_solib_resolver (gdbarch
, ecs
->event_thread
->stop_pc ());
7132 infrun_debug_printf ("stepped into dynsym resolve code");
7134 if (pc_after_resolver
)
7136 /* Set up a step-resume breakpoint at the address
7137 indicated by SKIP_SOLIB_RESOLVER. */
7138 symtab_and_line sr_sal
;
7139 sr_sal
.pc
= pc_after_resolver
;
7140 sr_sal
.pspace
= get_frame_program_space (frame
);
7142 insert_step_resume_breakpoint_at_sal (gdbarch
,
7143 sr_sal
, null_frame_id
);
7150 /* Step through an indirect branch thunk. */
7151 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7152 && gdbarch_in_indirect_branch_thunk (gdbarch
,
7153 ecs
->event_thread
->stop_pc ()))
7155 infrun_debug_printf ("stepped into indirect branch thunk");
7160 if (ecs
->event_thread
->control
.step_range_end
!= 1
7161 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7162 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7163 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
7165 infrun_debug_printf ("stepped into signal trampoline");
7166 /* The inferior, while doing a "step" or "next", has ended up in
7167 a signal trampoline (either by a signal being delivered or by
7168 the signal handler returning). Just single-step until the
7169 inferior leaves the trampoline (either by calling the handler
7175 /* If we're in the return path from a shared library trampoline,
7176 we want to proceed through the trampoline when stepping. */
7177 /* macro/2012-04-25: This needs to come before the subroutine
7178 call check below as on some targets return trampolines look
7179 like subroutine calls (MIPS16 return thunks). */
7180 if (gdbarch_in_solib_return_trampoline (gdbarch
,
7181 ecs
->event_thread
->stop_pc (),
7182 ecs
->stop_func_name
)
7183 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7185 /* Determine where this trampoline returns. */
7186 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7187 CORE_ADDR real_stop_pc
7188 = gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7190 infrun_debug_printf ("stepped into solib return tramp");
7192 /* Only proceed through if we know where it's going. */
7195 /* And put the step-breakpoint there and go until there. */
7196 symtab_and_line sr_sal
;
7197 sr_sal
.pc
= real_stop_pc
;
7198 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7199 sr_sal
.pspace
= get_frame_program_space (frame
);
7201 /* Do not specify what the fp should be when we stop since
7202 on some machines the prologue is where the new fp value
7204 insert_step_resume_breakpoint_at_sal (gdbarch
,
7205 sr_sal
, null_frame_id
);
7207 /* Restart without fiddling with the step ranges or
7214 /* Check for subroutine calls. The check for the current frame
7215 equalling the step ID is not necessary - the check of the
7216 previous frame's ID is sufficient - but it is a common case and
7217 cheaper than checking the previous frame's ID.
7219 NOTE: frame_id::operator== will never report two invalid frame IDs as
7220 being equal, so to get into this block, both the current and
7221 previous frame must have valid frame IDs. */
7222 /* The outer_frame_id check is a heuristic to detect stepping
7223 through startup code. If we step over an instruction which
7224 sets the stack pointer from an invalid value to a valid value,
7225 we may detect that as a subroutine call from the mythical
7226 "outermost" function. This could be fixed by marking
7227 outermost frames as !stack_p,code_p,special_p. Then the
7228 initial outermost frame, before sp was valid, would
7229 have code_addr == &_start. See the comment in frame_id::operator==
7231 if ((get_stack_frame_id (frame
)
7232 != ecs
->event_thread
->control
.step_stack_frame_id
)
7233 && ((frame_unwind_caller_id (get_current_frame ())
7234 == ecs
->event_thread
->control
.step_stack_frame_id
)
7235 && ((ecs
->event_thread
->control
.step_stack_frame_id
7237 || (ecs
->event_thread
->control
.step_start_function
7238 != find_pc_function (ecs
->event_thread
->stop_pc ())))))
7240 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7241 CORE_ADDR real_stop_pc
;
7243 infrun_debug_printf ("stepped into subroutine");
7245 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
7247 /* I presume that step_over_calls is only 0 when we're
7248 supposed to be stepping at the assembly language level
7249 ("stepi"). Just stop. */
7250 /* And this works the same backward as frontward. MVS */
7251 end_stepping_range (ecs
);
7255 /* Reverse stepping through solib trampolines. */
7257 if (execution_direction
== EXEC_REVERSE
7258 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7259 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7260 || (ecs
->stop_func_start
== 0
7261 && in_solib_dynsym_resolve_code (stop_pc
))))
7263 /* Any solib trampoline code can be handled in reverse
7264 by simply continuing to single-step. We have already
7265 executed the solib function (backwards), and a few
7266 steps will take us back through the trampoline to the
7272 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7274 /* We're doing a "next".
7276 Normal (forward) execution: set a breakpoint at the
7277 callee's return address (the address at which the caller
7280 Reverse (backward) execution. set the step-resume
7281 breakpoint at the start of the function that we just
7282 stepped into (backwards), and continue to there. When we
7283 get there, we'll need to single-step back to the caller. */
7285 if (execution_direction
== EXEC_REVERSE
)
7287 /* If we're already at the start of the function, we've either
7288 just stepped backward into a single instruction function,
7289 or stepped back out of a signal handler to the first instruction
7290 of the function. Just keep going, which will single-step back
7292 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
7294 /* Normal function call return (static or dynamic). */
7295 symtab_and_line sr_sal
;
7296 sr_sal
.pc
= ecs
->stop_func_start
;
7297 sr_sal
.pspace
= get_frame_program_space (frame
);
7298 insert_step_resume_breakpoint_at_sal (gdbarch
,
7299 sr_sal
, get_stack_frame_id (frame
));
7303 insert_step_resume_breakpoint_at_caller (frame
);
7309 /* If we are in a function call trampoline (a stub between the
7310 calling routine and the real function), locate the real
7311 function. That's what tells us (a) whether we want to step
7312 into it at all, and (b) what prologue we want to run to the
7313 end of, if we do step into it. */
7314 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
7315 if (real_stop_pc
== 0)
7316 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7317 if (real_stop_pc
!= 0)
7318 ecs
->stop_func_start
= real_stop_pc
;
7320 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
7322 symtab_and_line sr_sal
;
7323 sr_sal
.pc
= ecs
->stop_func_start
;
7324 sr_sal
.pspace
= get_frame_program_space (frame
);
7326 insert_step_resume_breakpoint_at_sal (gdbarch
,
7327 sr_sal
, null_frame_id
);
7332 /* If we have line number information for the function we are
7333 thinking of stepping into and the function isn't on the skip
7336 If there are several symtabs at that PC (e.g. with include
7337 files), just want to know whether *any* of them have line
7338 numbers. find_pc_line handles this. */
7340 struct symtab_and_line tmp_sal
;
7342 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7343 if (tmp_sal
.line
!= 0
7344 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
7346 && !inline_frame_is_marked_for_skip (true, ecs
->event_thread
))
7348 if (execution_direction
== EXEC_REVERSE
)
7349 handle_step_into_function_backward (gdbarch
, ecs
);
7351 handle_step_into_function (gdbarch
, ecs
);
7356 /* If we have no line number and the step-stop-if-no-debug is
7357 set, we stop the step so that the user has a chance to switch
7358 in assembly mode. */
7359 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7360 && step_stop_if_no_debug
)
7362 end_stepping_range (ecs
);
7366 if (execution_direction
== EXEC_REVERSE
)
7368 /* If we're already at the start of the function, we've either just
7369 stepped backward into a single instruction function without line
7370 number info, or stepped back out of a signal handler to the first
7371 instruction of the function without line number info. Just keep
7372 going, which will single-step back to the caller. */
7373 if (ecs
->stop_func_start
!= stop_pc
)
7375 /* Set a breakpoint at callee's start address.
7376 From there we can step once and be back in the caller. */
7377 symtab_and_line sr_sal
;
7378 sr_sal
.pc
= ecs
->stop_func_start
;
7379 sr_sal
.pspace
= get_frame_program_space (frame
);
7380 insert_step_resume_breakpoint_at_sal (gdbarch
,
7381 sr_sal
, null_frame_id
);
7385 /* Set a breakpoint at callee's return address (the address
7386 at which the caller will resume). */
7387 insert_step_resume_breakpoint_at_caller (frame
);
7393 /* Reverse stepping through solib trampolines. */
7395 if (execution_direction
== EXEC_REVERSE
7396 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7398 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7400 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7401 || (ecs
->stop_func_start
== 0
7402 && in_solib_dynsym_resolve_code (stop_pc
)))
7404 /* Any solib trampoline code can be handled in reverse
7405 by simply continuing to single-step. We have already
7406 executed the solib function (backwards), and a few
7407 steps will take us back through the trampoline to the
7412 else if (in_solib_dynsym_resolve_code (stop_pc
))
7414 /* Stepped backward into the solib dynsym resolver.
7415 Set a breakpoint at its start and continue, then
7416 one more step will take us out. */
7417 symtab_and_line sr_sal
;
7418 sr_sal
.pc
= ecs
->stop_func_start
;
7419 sr_sal
.pspace
= get_frame_program_space (frame
);
7420 insert_step_resume_breakpoint_at_sal (gdbarch
,
7421 sr_sal
, null_frame_id
);
7427 /* This always returns the sal for the inner-most frame when we are in a
7428 stack of inlined frames, even if GDB actually believes that it is in a
7429 more outer frame. This is checked for below by calls to
7430 inline_skipped_frames. */
7431 stop_pc_sal
= find_pc_line (ecs
->event_thread
->stop_pc (), 0);
7433 /* NOTE: tausq/2004-05-24: This if block used to be done before all
7434 the trampoline processing logic, however, there are some trampolines
7435 that have no names, so we should do trampoline handling first. */
7436 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7437 && ecs
->stop_func_name
== nullptr
7438 && stop_pc_sal
.line
== 0)
7440 infrun_debug_printf ("stepped into undebuggable function");
7442 /* The inferior just stepped into, or returned to, an
7443 undebuggable function (where there is no debugging information
7444 and no line number corresponding to the address where the
7445 inferior stopped). Since we want to skip this kind of code,
7446 we keep going until the inferior returns from this
7447 function - unless the user has asked us not to (via
7448 set step-mode) or we no longer know how to get back
7449 to the call site. */
7450 if (step_stop_if_no_debug
7451 || !frame_id_p (frame_unwind_caller_id (frame
)))
7453 /* If we have no line number and the step-stop-if-no-debug
7454 is set, we stop the step so that the user has a chance to
7455 switch in assembly mode. */
7456 end_stepping_range (ecs
);
7461 /* Set a breakpoint at callee's return address (the address
7462 at which the caller will resume). */
7463 insert_step_resume_breakpoint_at_caller (frame
);
7469 if (execution_direction
== EXEC_REVERSE
7470 && ecs
->event_thread
->control
.proceed_to_finish
7471 && ecs
->event_thread
->stop_pc () >= ecs
->stop_func_alt_start
7472 && ecs
->event_thread
->stop_pc () < ecs
->stop_func_start
)
7474 /* We are executing the reverse-finish command.
7475 If the system supports multiple entry points and we are finishing a
7476 function in reverse. If we are between the entry points singe-step
7477 back to the alternate entry point. If we are at the alternate entry
7478 point -- just need to back up by one more single-step, which
7479 should take us back to the function call. */
7480 ecs
->event_thread
->control
.step_range_start
7481 = ecs
->event_thread
->control
.step_range_end
= 1;
7487 if (ecs
->event_thread
->control
.step_range_end
== 1)
7489 /* It is stepi or nexti. We always want to stop stepping after
7491 infrun_debug_printf ("stepi/nexti");
7492 end_stepping_range (ecs
);
7496 if (stop_pc_sal
.line
== 0)
7498 /* We have no line number information. That means to stop
7499 stepping (does this always happen right after one instruction,
7500 when we do "s" in a function with no line numbers,
7501 or can this happen as a result of a return or longjmp?). */
7502 infrun_debug_printf ("line number info");
7503 end_stepping_range (ecs
);
7507 /* Look for "calls" to inlined functions, part one. If the inline
7508 frame machinery detected some skipped call sites, we have entered
7509 a new inline function. */
7511 if ((get_frame_id (get_current_frame ())
7512 == ecs
->event_thread
->control
.step_frame_id
)
7513 && inline_skipped_frames (ecs
->event_thread
))
7515 infrun_debug_printf ("stepped into inlined function");
7517 symtab_and_line call_sal
= find_frame_sal (get_current_frame ());
7519 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
7521 /* For "step", we're going to stop. But if the call site
7522 for this inlined function is on the same source line as
7523 we were previously stepping, go down into the function
7524 first. Otherwise stop at the call site. */
7526 if (call_sal
.line
== ecs
->event_thread
->current_line
7527 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7529 step_into_inline_frame (ecs
->event_thread
);
7530 if (inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7537 end_stepping_range (ecs
);
7542 /* For "next", we should stop at the call site if it is on a
7543 different source line. Otherwise continue through the
7544 inlined function. */
7545 if (call_sal
.line
== ecs
->event_thread
->current_line
7546 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7549 end_stepping_range (ecs
);
7554 /* Look for "calls" to inlined functions, part two. If we are still
7555 in the same real function we were stepping through, but we have
7556 to go further up to find the exact frame ID, we are stepping
7557 through a more inlined call beyond its call site. */
7559 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
7560 && (get_frame_id (get_current_frame ())
7561 != ecs
->event_thread
->control
.step_frame_id
)
7562 && stepped_in_from (get_current_frame (),
7563 ecs
->event_thread
->control
.step_frame_id
))
7565 infrun_debug_printf ("stepping through inlined function");
7567 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
7568 || inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7571 end_stepping_range (ecs
);
7575 bool refresh_step_info
= true;
7576 if ((ecs
->event_thread
->stop_pc () == stop_pc_sal
.pc
)
7577 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
7578 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
7580 /* We are at a different line. */
7582 if (stop_pc_sal
.is_stmt
)
7584 /* We are at the start of a statement.
7586 So stop. Note that we don't stop if we step into the middle of a
7587 statement. That is said to make things like for (;;) statements
7589 infrun_debug_printf ("stepped to a different line");
7590 end_stepping_range (ecs
);
7593 else if (get_frame_id (get_current_frame ())
7594 == ecs
->event_thread
->control
.step_frame_id
)
7596 /* We are not at the start of a statement, and we have not changed
7599 We ignore this line table entry, and continue stepping forward,
7600 looking for a better place to stop. */
7601 refresh_step_info
= false;
7602 infrun_debug_printf ("stepped to a different line, but "
7603 "it's not the start of a statement");
7607 /* We are not the start of a statement, and we have changed frame.
7609 We ignore this line table entry, and continue stepping forward,
7610 looking for a better place to stop. Keep refresh_step_info at
7611 true to note that the frame has changed, but ignore the line
7612 number to make sure we don't ignore a subsequent entry with the
7613 same line number. */
7614 stop_pc_sal
.line
= 0;
7615 infrun_debug_printf ("stepped to a different frame, but "
7616 "it's not the start of a statement");
7620 /* We aren't done stepping.
7622 Optimize by setting the stepping range to the line.
7623 (We might not be in the original line, but if we entered a
7624 new line in mid-statement, we continue stepping. This makes
7625 things like for(;;) statements work better.)
7627 If we entered a SAL that indicates a non-statement line table entry,
7628 then we update the stepping range, but we don't update the step info,
7629 which includes things like the line number we are stepping away from.
7630 This means we will stop when we find a line table entry that is marked
7631 as is-statement, even if it matches the non-statement one we just
7634 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
7635 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
7636 ecs
->event_thread
->control
.may_range_step
= 1;
7638 ("updated step range, start = %s, end = %s, may_range_step = %d",
7639 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
7640 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
),
7641 ecs
->event_thread
->control
.may_range_step
);
7642 if (refresh_step_info
)
7643 set_step_info (ecs
->event_thread
, frame
, stop_pc_sal
);
7645 infrun_debug_printf ("keep going");
7649 static bool restart_stepped_thread (process_stratum_target
*resume_target
,
7650 ptid_t resume_ptid
);
7652 /* In all-stop mode, if we're currently stepping but have stopped in
7653 some other thread, we may need to switch back to the stepped
7654 thread. Returns true we set the inferior running, false if we left
7655 it stopped (and the event needs further processing). */
7658 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
7660 if (!target_is_non_stop_p ())
7662 /* If any thread is blocked on some internal breakpoint, and we
7663 simply need to step over that breakpoint to get it going
7664 again, do that first. */
7666 /* However, if we see an event for the stepping thread, then we
7667 know all other threads have been moved past their breakpoints
7668 already. Let the caller check whether the step is finished,
7669 etc., before deciding to move it past a breakpoint. */
7670 if (ecs
->event_thread
->control
.step_range_end
!= 0)
7673 /* Check if the current thread is blocked on an incomplete
7674 step-over, interrupted by a random signal. */
7675 if (ecs
->event_thread
->control
.trap_expected
7676 && ecs
->event_thread
->stop_signal () != GDB_SIGNAL_TRAP
)
7679 ("need to finish step-over of [%s]",
7680 ecs
->event_thread
->ptid
.to_string ().c_str ());
7685 /* Check if the current thread is blocked by a single-step
7686 breakpoint of another thread. */
7687 if (ecs
->hit_singlestep_breakpoint
)
7689 infrun_debug_printf ("need to step [%s] over single-step breakpoint",
7690 ecs
->ptid
.to_string ().c_str ());
7695 /* If this thread needs yet another step-over (e.g., stepping
7696 through a delay slot), do it first before moving on to
7698 if (thread_still_needs_step_over (ecs
->event_thread
))
7701 ("thread [%s] still needs step-over",
7702 ecs
->event_thread
->ptid
.to_string ().c_str ());
7707 /* If scheduler locking applies even if not stepping, there's no
7708 need to walk over threads. Above we've checked whether the
7709 current thread is stepping. If some other thread not the
7710 event thread is stepping, then it must be that scheduler
7711 locking is not in effect. */
7712 if (schedlock_applies (ecs
->event_thread
))
7715 /* Otherwise, we no longer expect a trap in the current thread.
7716 Clear the trap_expected flag before switching back -- this is
7717 what keep_going does as well, if we call it. */
7718 ecs
->event_thread
->control
.trap_expected
= 0;
7720 /* Likewise, clear the signal if it should not be passed. */
7721 if (!signal_program
[ecs
->event_thread
->stop_signal ()])
7722 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
7724 if (restart_stepped_thread (ecs
->target
, ecs
->ptid
))
7726 prepare_to_wait (ecs
);
7730 switch_to_thread (ecs
->event_thread
);
7736 /* Look for the thread that was stepping, and resume it.
7737 RESUME_TARGET / RESUME_PTID indicate the set of threads the caller
7738 is resuming. Return true if a thread was started, false
7742 restart_stepped_thread (process_stratum_target
*resume_target
,
7745 /* Do all pending step-overs before actually proceeding with
7747 if (start_step_over ())
7750 for (thread_info
*tp
: all_threads_safe ())
7752 if (tp
->state
== THREAD_EXITED
)
7755 if (tp
->has_pending_waitstatus ())
7758 /* Ignore threads of processes the caller is not
7761 && (tp
->inf
->process_target () != resume_target
7762 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7765 if (tp
->control
.trap_expected
)
7767 infrun_debug_printf ("switching back to stepped thread (step-over)");
7769 if (keep_going_stepped_thread (tp
))
7774 for (thread_info
*tp
: all_threads_safe ())
7776 if (tp
->state
== THREAD_EXITED
)
7779 if (tp
->has_pending_waitstatus ())
7782 /* Ignore threads of processes the caller is not
7785 && (tp
->inf
->process_target () != resume_target
7786 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7789 /* Did we find the stepping thread? */
7790 if (tp
->control
.step_range_end
)
7792 infrun_debug_printf ("switching back to stepped thread (stepping)");
7794 if (keep_going_stepped_thread (tp
))
7805 restart_after_all_stop_detach (process_stratum_target
*proc_target
)
7807 /* Note we don't check target_is_non_stop_p() here, because the
7808 current inferior may no longer have a process_stratum target
7809 pushed, as we just detached. */
7811 /* See if we have a THREAD_RUNNING thread that need to be
7812 re-resumed. If we have any thread that is already executing,
7813 then we don't need to resume the target -- it is already been
7814 resumed. With the remote target (in all-stop), it's even
7815 impossible to issue another resumption if the target is already
7816 resumed, until the target reports a stop. */
7817 for (thread_info
*thr
: all_threads (proc_target
))
7819 if (thr
->state
!= THREAD_RUNNING
)
7822 /* If we have any thread that is already executing, then we
7823 don't need to resume the target -- it is already been
7825 if (thr
->executing ())
7828 /* If we have a pending event to process, skip resuming the
7829 target and go straight to processing it. */
7830 if (thr
->resumed () && thr
->has_pending_waitstatus ())
7834 /* Alright, we need to re-resume the target. If a thread was
7835 stepping, we need to restart it stepping. */
7836 if (restart_stepped_thread (proc_target
, minus_one_ptid
))
7839 /* Otherwise, find the first THREAD_RUNNING thread and resume
7841 for (thread_info
*thr
: all_threads (proc_target
))
7843 if (thr
->state
!= THREAD_RUNNING
)
7846 execution_control_state
ecs (thr
);
7847 switch_to_thread (thr
);
7853 /* Set a previously stepped thread back to stepping. Returns true on
7854 success, false if the resume is not possible (e.g., the thread
7858 keep_going_stepped_thread (struct thread_info
*tp
)
7860 frame_info_ptr frame
;
7862 /* If the stepping thread exited, then don't try to switch back and
7863 resume it, which could fail in several different ways depending
7864 on the target. Instead, just keep going.
7866 We can find a stepping dead thread in the thread list in two
7869 - The target supports thread exit events, and when the target
7870 tries to delete the thread from the thread list, inferior_ptid
7871 pointed at the exiting thread. In such case, calling
7872 delete_thread does not really remove the thread from the list;
7873 instead, the thread is left listed, with 'exited' state.
7875 - The target's debug interface does not support thread exit
7876 events, and so we have no idea whatsoever if the previously
7877 stepping thread is still alive. For that reason, we need to
7878 synchronously query the target now. */
7880 if (tp
->state
== THREAD_EXITED
|| !target_thread_alive (tp
->ptid
))
7882 infrun_debug_printf ("not resuming previously stepped thread, it has "
7889 infrun_debug_printf ("resuming previously stepped thread");
7891 execution_control_state
ecs (tp
);
7892 switch_to_thread (tp
);
7894 tp
->set_stop_pc (regcache_read_pc (get_thread_regcache (tp
)));
7895 frame
= get_current_frame ();
7897 /* If the PC of the thread we were trying to single-step has
7898 changed, then that thread has trapped or been signaled, but the
7899 event has not been reported to GDB yet. Re-poll the target
7900 looking for this particular thread's event (i.e. temporarily
7901 enable schedlock) by:
7903 - setting a break at the current PC
7904 - resuming that particular thread, only (by setting trap
7907 This prevents us continuously moving the single-step breakpoint
7908 forward, one instruction at a time, overstepping. */
7910 if (tp
->stop_pc () != tp
->prev_pc
)
7914 infrun_debug_printf ("expected thread advanced also (%s -> %s)",
7915 paddress (target_gdbarch (), tp
->prev_pc
),
7916 paddress (target_gdbarch (), tp
->stop_pc ()));
7918 /* Clear the info of the previous step-over, as it's no longer
7919 valid (if the thread was trying to step over a breakpoint, it
7920 has already succeeded). It's what keep_going would do too,
7921 if we called it. Do this before trying to insert the sss
7922 breakpoint, otherwise if we were previously trying to step
7923 over this exact address in another thread, the breakpoint is
7925 clear_step_over_info ();
7926 tp
->control
.trap_expected
= 0;
7928 insert_single_step_breakpoint (get_frame_arch (frame
),
7929 get_frame_address_space (frame
),
7932 tp
->set_resumed (true);
7933 resume_ptid
= internal_resume_ptid (tp
->control
.stepping_command
);
7934 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
7938 infrun_debug_printf ("expected thread still hasn't advanced");
7940 keep_going_pass_signal (&ecs
);
7946 /* Is thread TP in the middle of (software or hardware)
7947 single-stepping? (Note the result of this function must never be
7948 passed directly as target_resume's STEP parameter.) */
7951 currently_stepping (struct thread_info
*tp
)
7953 return ((tp
->control
.step_range_end
7954 && tp
->control
.step_resume_breakpoint
== nullptr)
7955 || tp
->control
.trap_expected
7956 || tp
->stepped_breakpoint
7957 || bpstat_should_step ());
7960 /* Inferior has stepped into a subroutine call with source code that
7961 we should not step over. Do step to the first line of code in
7965 handle_step_into_function (struct gdbarch
*gdbarch
,
7966 struct execution_control_state
*ecs
)
7968 fill_in_stop_func (gdbarch
, ecs
);
7970 compunit_symtab
*cust
7971 = find_pc_compunit_symtab (ecs
->event_thread
->stop_pc ());
7972 if (cust
!= nullptr && cust
->language () != language_asm
)
7973 ecs
->stop_func_start
7974 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7976 symtab_and_line stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7977 /* Use the step_resume_break to step until the end of the prologue,
7978 even if that involves jumps (as it seems to on the vax under
7980 /* If the prologue ends in the middle of a source line, continue to
7981 the end of that source line (if it is still within the function).
7982 Otherwise, just go to end of prologue. */
7983 if (stop_func_sal
.end
7984 && stop_func_sal
.pc
!= ecs
->stop_func_start
7985 && stop_func_sal
.end
< ecs
->stop_func_end
)
7986 ecs
->stop_func_start
= stop_func_sal
.end
;
7988 /* Architectures which require breakpoint adjustment might not be able
7989 to place a breakpoint at the computed address. If so, the test
7990 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
7991 ecs->stop_func_start to an address at which a breakpoint may be
7992 legitimately placed.
7994 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
7995 made, GDB will enter an infinite loop when stepping through
7996 optimized code consisting of VLIW instructions which contain
7997 subinstructions corresponding to different source lines. On
7998 FR-V, it's not permitted to place a breakpoint on any but the
7999 first subinstruction of a VLIW instruction. When a breakpoint is
8000 set, GDB will adjust the breakpoint address to the beginning of
8001 the VLIW instruction. Thus, we need to make the corresponding
8002 adjustment here when computing the stop address. */
8004 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
8006 ecs
->stop_func_start
8007 = gdbarch_adjust_breakpoint_address (gdbarch
,
8008 ecs
->stop_func_start
);
8011 if (ecs
->stop_func_start
== ecs
->event_thread
->stop_pc ())
8013 /* We are already there: stop now. */
8014 end_stepping_range (ecs
);
8019 /* Put the step-breakpoint there and go until there. */
8020 symtab_and_line sr_sal
;
8021 sr_sal
.pc
= ecs
->stop_func_start
;
8022 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
8023 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
8025 /* Do not specify what the fp should be when we stop since on
8026 some machines the prologue is where the new fp value is
8028 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
8030 /* And make sure stepping stops right away then. */
8031 ecs
->event_thread
->control
.step_range_end
8032 = ecs
->event_thread
->control
.step_range_start
;
8037 /* Inferior has stepped backward into a subroutine call with source
8038 code that we should not step over. Do step to the beginning of the
8039 last line of code in it. */
8042 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
8043 struct execution_control_state
*ecs
)
8045 struct compunit_symtab
*cust
;
8046 struct symtab_and_line stop_func_sal
;
8048 fill_in_stop_func (gdbarch
, ecs
);
8050 cust
= find_pc_compunit_symtab (ecs
->event_thread
->stop_pc ());
8051 if (cust
!= nullptr && cust
->language () != language_asm
)
8052 ecs
->stop_func_start
8053 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
8055 stop_func_sal
= find_pc_line (ecs
->event_thread
->stop_pc (), 0);
8057 /* OK, we're just going to keep stepping here. */
8058 if (stop_func_sal
.pc
== ecs
->event_thread
->stop_pc ())
8060 /* We're there already. Just stop stepping now. */
8061 end_stepping_range (ecs
);
8065 /* Else just reset the step range and keep going.
8066 No step-resume breakpoint, they don't work for
8067 epilogues, which can have multiple entry paths. */
8068 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
8069 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
8075 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
8076 This is used to both functions and to skip over code. */
8079 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
8080 struct symtab_and_line sr_sal
,
8081 struct frame_id sr_id
,
8082 enum bptype sr_type
)
8084 /* There should never be more than one step-resume or longjmp-resume
8085 breakpoint per thread, so we should never be setting a new
8086 step_resume_breakpoint when one is already active. */
8087 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== nullptr);
8088 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
8090 infrun_debug_printf ("inserting step-resume breakpoint at %s",
8091 paddress (gdbarch
, sr_sal
.pc
));
8093 inferior_thread ()->control
.step_resume_breakpoint
8094 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
).release ();
8098 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
8099 struct symtab_and_line sr_sal
,
8100 struct frame_id sr_id
)
8102 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
8107 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
8108 This is used to skip a potential signal handler.
8110 This is called with the interrupted function's frame. The signal
8111 handler, when it returns, will resume the interrupted function at
8115 insert_hp_step_resume_breakpoint_at_frame (frame_info_ptr return_frame
)
8117 gdb_assert (return_frame
!= nullptr);
8119 struct gdbarch
*gdbarch
= get_frame_arch (return_frame
);
8121 symtab_and_line sr_sal
;
8122 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
8123 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
8124 sr_sal
.pspace
= get_frame_program_space (return_frame
);
8126 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
8127 get_stack_frame_id (return_frame
),
8131 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
8132 is used to skip a function after stepping into it (for "next" or if
8133 the called function has no debugging information).
8135 The current function has almost always been reached by single
8136 stepping a call or return instruction. NEXT_FRAME belongs to the
8137 current function, and the breakpoint will be set at the caller's
8140 This is a separate function rather than reusing
8141 insert_hp_step_resume_breakpoint_at_frame in order to avoid
8142 get_prev_frame, which may stop prematurely (see the implementation
8143 of frame_unwind_caller_id for an example). */
8146 insert_step_resume_breakpoint_at_caller (frame_info_ptr next_frame
)
8148 /* We shouldn't have gotten here if we don't know where the call site
8150 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
8152 struct gdbarch
*gdbarch
= frame_unwind_caller_arch (next_frame
);
8154 symtab_and_line sr_sal
;
8155 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
8156 frame_unwind_caller_pc (next_frame
));
8157 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
8158 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
8160 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
8161 frame_unwind_caller_id (next_frame
));
8164 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
8165 new breakpoint at the target of a jmp_buf. The handling of
8166 longjmp-resume uses the same mechanisms used for handling
8167 "step-resume" breakpoints. */
8170 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8172 /* There should never be more than one longjmp-resume breakpoint per
8173 thread, so we should never be setting a new
8174 longjmp_resume_breakpoint when one is already active. */
8175 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== nullptr);
8177 infrun_debug_printf ("inserting longjmp-resume breakpoint at %s",
8178 paddress (gdbarch
, pc
));
8180 inferior_thread ()->control
.exception_resume_breakpoint
=
8181 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
).release ();
8184 /* Insert an exception resume breakpoint. TP is the thread throwing
8185 the exception. The block B is the block of the unwinder debug hook
8186 function. FRAME is the frame corresponding to the call to this
8187 function. SYM is the symbol of the function argument holding the
8188 target PC of the exception. */
8191 insert_exception_resume_breakpoint (struct thread_info
*tp
,
8192 const struct block
*b
,
8193 frame_info_ptr frame
,
8198 struct block_symbol vsym
;
8199 struct value
*value
;
8201 struct breakpoint
*bp
;
8203 vsym
= lookup_symbol_search_name (sym
->search_name (),
8205 value
= read_var_value (vsym
.symbol
, vsym
.block
, frame
);
8206 /* If the value was optimized out, revert to the old behavior. */
8207 if (! value
->optimized_out ())
8209 handler
= value_as_address (value
);
8211 infrun_debug_printf ("exception resume at %lx",
8212 (unsigned long) handler
);
8214 /* set_momentary_breakpoint_at_pc creates a thread-specific
8215 breakpoint for the current inferior thread. */
8216 gdb_assert (tp
== inferior_thread ());
8217 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8219 bp_exception_resume
).release ();
8221 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
8224 tp
->control
.exception_resume_breakpoint
= bp
;
8227 catch (const gdb_exception_error
&e
)
8229 /* We want to ignore errors here. */
8233 /* A helper for check_exception_resume that sets an
8234 exception-breakpoint based on a SystemTap probe. */
8237 insert_exception_resume_from_probe (struct thread_info
*tp
,
8238 const struct bound_probe
*probe
,
8239 frame_info_ptr frame
)
8241 struct value
*arg_value
;
8243 struct breakpoint
*bp
;
8245 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
8249 handler
= value_as_address (arg_value
);
8251 infrun_debug_printf ("exception resume at %s",
8252 paddress (probe
->objfile
->arch (), handler
));
8254 /* set_momentary_breakpoint_at_pc creates a thread-specific breakpoint
8255 for the current inferior thread. */
8256 gdb_assert (tp
== inferior_thread ());
8257 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8258 handler
, bp_exception_resume
).release ();
8259 tp
->control
.exception_resume_breakpoint
= bp
;
8262 /* This is called when an exception has been intercepted. Check to
8263 see whether the exception's destination is of interest, and if so,
8264 set an exception resume breakpoint there. */
8267 check_exception_resume (struct execution_control_state
*ecs
,
8268 frame_info_ptr frame
)
8270 struct bound_probe probe
;
8271 struct symbol
*func
;
8273 /* First see if this exception unwinding breakpoint was set via a
8274 SystemTap probe point. If so, the probe has two arguments: the
8275 CFA and the HANDLER. We ignore the CFA, extract the handler, and
8276 set a breakpoint there. */
8277 probe
= find_probe_by_pc (get_frame_pc (frame
));
8280 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
8284 func
= get_frame_function (frame
);
8290 const struct block
*b
;
8293 /* The exception breakpoint is a thread-specific breakpoint on
8294 the unwinder's debug hook, declared as:
8296 void _Unwind_DebugHook (void *cfa, void *handler);
8298 The CFA argument indicates the frame to which control is
8299 about to be transferred. HANDLER is the destination PC.
8301 We ignore the CFA and set a temporary breakpoint at HANDLER.
8302 This is not extremely efficient but it avoids issues in gdb
8303 with computing the DWARF CFA, and it also works even in weird
8304 cases such as throwing an exception from inside a signal
8307 b
= func
->value_block ();
8308 for (struct symbol
*sym
: block_iterator_range (b
))
8310 if (!sym
->is_argument ())
8317 insert_exception_resume_breakpoint (ecs
->event_thread
,
8323 catch (const gdb_exception_error
&e
)
8329 stop_waiting (struct execution_control_state
*ecs
)
8331 infrun_debug_printf ("stop_waiting");
8333 /* Let callers know we don't want to wait for the inferior anymore. */
8334 ecs
->wait_some_more
= 0;
8337 /* Like keep_going, but passes the signal to the inferior, even if the
8338 signal is set to nopass. */
8341 keep_going_pass_signal (struct execution_control_state
*ecs
)
8343 gdb_assert (ecs
->event_thread
->ptid
== inferior_ptid
);
8344 gdb_assert (!ecs
->event_thread
->resumed ());
8346 /* Save the pc before execution, to compare with pc after stop. */
8347 ecs
->event_thread
->prev_pc
8348 = regcache_read_pc_protected (get_thread_regcache (ecs
->event_thread
));
8350 if (ecs
->event_thread
->control
.trap_expected
)
8352 struct thread_info
*tp
= ecs
->event_thread
;
8354 infrun_debug_printf ("%s has trap_expected set, "
8355 "resuming to collect trap",
8356 tp
->ptid
.to_string ().c_str ());
8358 /* We haven't yet gotten our trap, and either: intercepted a
8359 non-signal event (e.g., a fork); or took a signal which we
8360 are supposed to pass through to the inferior. Simply
8362 resume (ecs
->event_thread
->stop_signal ());
8364 else if (step_over_info_valid_p ())
8366 /* Another thread is stepping over a breakpoint in-line. If
8367 this thread needs a step-over too, queue the request. In
8368 either case, this resume must be deferred for later. */
8369 struct thread_info
*tp
= ecs
->event_thread
;
8371 if (ecs
->hit_singlestep_breakpoint
8372 || thread_still_needs_step_over (tp
))
8374 infrun_debug_printf ("step-over already in progress: "
8375 "step-over for %s deferred",
8376 tp
->ptid
.to_string ().c_str ());
8377 global_thread_step_over_chain_enqueue (tp
);
8380 infrun_debug_printf ("step-over in progress: resume of %s deferred",
8381 tp
->ptid
.to_string ().c_str ());
8385 struct regcache
*regcache
= get_current_regcache ();
8388 step_over_what step_what
;
8390 /* Either the trap was not expected, but we are continuing
8391 anyway (if we got a signal, the user asked it be passed to
8394 We got our expected trap, but decided we should resume from
8397 We're going to run this baby now!
8399 Note that insert_breakpoints won't try to re-insert
8400 already inserted breakpoints. Therefore, we don't
8401 care if breakpoints were already inserted, or not. */
8403 /* If we need to step over a breakpoint, and we're not using
8404 displaced stepping to do so, insert all breakpoints
8405 (watchpoints, etc.) but the one we're stepping over, step one
8406 instruction, and then re-insert the breakpoint when that step
8409 step_what
= thread_still_needs_step_over (ecs
->event_thread
);
8411 remove_bp
= (ecs
->hit_singlestep_breakpoint
8412 || (step_what
& STEP_OVER_BREAKPOINT
));
8413 remove_wps
= (step_what
& STEP_OVER_WATCHPOINT
);
8415 /* We can't use displaced stepping if we need to step past a
8416 watchpoint. The instruction copied to the scratch pad would
8417 still trigger the watchpoint. */
8419 && (remove_wps
|| !use_displaced_stepping (ecs
->event_thread
)))
8421 set_step_over_info (regcache
->aspace (),
8422 regcache_read_pc (regcache
), remove_wps
,
8423 ecs
->event_thread
->global_num
);
8425 else if (remove_wps
)
8426 set_step_over_info (nullptr, 0, remove_wps
, -1);
8428 /* If we now need to do an in-line step-over, we need to stop
8429 all other threads. Note this must be done before
8430 insert_breakpoints below, because that removes the breakpoint
8431 we're about to step over, otherwise other threads could miss
8433 if (step_over_info_valid_p () && target_is_non_stop_p ())
8434 stop_all_threads ("starting in-line step-over");
8436 /* Stop stepping if inserting breakpoints fails. */
8439 insert_breakpoints ();
8441 catch (const gdb_exception_error
&e
)
8443 exception_print (gdb_stderr
, e
);
8445 clear_step_over_info ();
8449 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
8451 resume (ecs
->event_thread
->stop_signal ());
8454 prepare_to_wait (ecs
);
8457 /* Called when we should continue running the inferior, because the
8458 current event doesn't cause a user visible stop. This does the
8459 resuming part; waiting for the next event is done elsewhere. */
8462 keep_going (struct execution_control_state
*ecs
)
8464 if (ecs
->event_thread
->control
.trap_expected
8465 && ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
8466 ecs
->event_thread
->control
.trap_expected
= 0;
8468 if (!signal_program
[ecs
->event_thread
->stop_signal ()])
8469 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
8470 keep_going_pass_signal (ecs
);
8473 /* This function normally comes after a resume, before
8474 handle_inferior_event exits. It takes care of any last bits of
8475 housekeeping, and sets the all-important wait_some_more flag. */
8478 prepare_to_wait (struct execution_control_state
*ecs
)
8480 infrun_debug_printf ("prepare_to_wait");
8482 ecs
->wait_some_more
= 1;
8484 /* If the target can't async, emulate it by marking the infrun event
8485 handler such that as soon as we get back to the event-loop, we
8486 immediately end up in fetch_inferior_event again calling
8488 if (!target_can_async_p ())
8489 mark_infrun_async_event_handler ();
8492 /* We are done with the step range of a step/next/si/ni command.
8493 Called once for each n of a "step n" operation. */
8496 end_stepping_range (struct execution_control_state
*ecs
)
8498 ecs
->event_thread
->control
.stop_step
= 1;
8502 /* Several print_*_reason functions to print why the inferior has stopped.
8503 We always print something when the inferior exits, or receives a signal.
8504 The rest of the cases are dealt with later on in normal_stop and
8505 print_it_typical. Ideally there should be a call to one of these
8506 print_*_reason functions functions from handle_inferior_event each time
8507 stop_waiting is called.
8509 Note that we don't call these directly, instead we delegate that to
8510 the interpreters, through observers. Interpreters then call these
8511 with whatever uiout is right. */
8514 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8516 annotate_signalled ();
8517 if (uiout
->is_mi_like_p ())
8519 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
8520 uiout
->text ("\nProgram terminated with signal ");
8521 annotate_signal_name ();
8522 uiout
->field_string ("signal-name",
8523 gdb_signal_to_name (siggnal
));
8524 annotate_signal_name_end ();
8526 annotate_signal_string ();
8527 uiout
->field_string ("signal-meaning",
8528 gdb_signal_to_string (siggnal
));
8529 annotate_signal_string_end ();
8530 uiout
->text (".\n");
8531 uiout
->text ("The program no longer exists.\n");
8535 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
8537 struct inferior
*inf
= current_inferior ();
8538 std::string pidstr
= target_pid_to_str (ptid_t (inf
->pid
));
8540 annotate_exited (exitstatus
);
8543 if (uiout
->is_mi_like_p ())
8544 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXITED
));
8545 std::string exit_code_str
8546 = string_printf ("0%o", (unsigned int) exitstatus
);
8547 uiout
->message ("[Inferior %s (%s) exited with code %pF]\n",
8548 plongest (inf
->num
), pidstr
.c_str (),
8549 string_field ("exit-code", exit_code_str
.c_str ()));
8553 if (uiout
->is_mi_like_p ())
8555 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
8556 uiout
->message ("[Inferior %s (%s) exited normally]\n",
8557 plongest (inf
->num
), pidstr
.c_str ());
8562 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8564 struct thread_info
*thr
= inferior_thread ();
8566 infrun_debug_printf ("signal = %s", gdb_signal_to_string (siggnal
));
8570 if (uiout
->is_mi_like_p ())
8572 else if (show_thread_that_caused_stop ())
8574 uiout
->text ("\nThread ");
8575 uiout
->field_string ("thread-id", print_thread_id (thr
));
8577 const char *name
= thread_name (thr
);
8578 if (name
!= nullptr)
8580 uiout
->text (" \"");
8581 uiout
->field_string ("name", name
);
8586 uiout
->text ("\nProgram");
8588 if (siggnal
== GDB_SIGNAL_0
&& !uiout
->is_mi_like_p ())
8589 uiout
->text (" stopped");
8592 uiout
->text (" received signal ");
8593 annotate_signal_name ();
8594 if (uiout
->is_mi_like_p ())
8596 ("reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
8597 uiout
->field_string ("signal-name", gdb_signal_to_name (siggnal
));
8598 annotate_signal_name_end ();
8600 annotate_signal_string ();
8601 uiout
->field_string ("signal-meaning", gdb_signal_to_string (siggnal
));
8603 struct regcache
*regcache
= get_current_regcache ();
8604 struct gdbarch
*gdbarch
= regcache
->arch ();
8605 if (gdbarch_report_signal_info_p (gdbarch
))
8606 gdbarch_report_signal_info (gdbarch
, uiout
, siggnal
);
8608 annotate_signal_string_end ();
8610 uiout
->text (".\n");
8614 print_no_history_reason (struct ui_out
*uiout
)
8616 if (uiout
->is_mi_like_p ())
8617 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_NO_HISTORY
));
8619 uiout
->text ("\nNo more reverse-execution history.\n");
8622 /* Print current location without a level number, if we have changed
8623 functions or hit a breakpoint. Print source line if we have one.
8624 bpstat_print contains the logic deciding in detail what to print,
8625 based on the event(s) that just occurred. */
8628 print_stop_location (const target_waitstatus
&ws
)
8631 enum print_what source_flag
;
8632 int do_frame_printing
= 1;
8633 struct thread_info
*tp
= inferior_thread ();
8635 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
.kind ());
8639 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
8640 should) carry around the function and does (or should) use
8641 that when doing a frame comparison. */
8642 if (tp
->control
.stop_step
8643 && (tp
->control
.step_frame_id
8644 == get_frame_id (get_current_frame ()))
8645 && (tp
->control
.step_start_function
8646 == find_pc_function (tp
->stop_pc ())))
8648 /* Finished step, just print source line. */
8649 source_flag
= SRC_LINE
;
8653 /* Print location and source line. */
8654 source_flag
= SRC_AND_LOC
;
8657 case PRINT_SRC_AND_LOC
:
8658 /* Print location and source line. */
8659 source_flag
= SRC_AND_LOC
;
8661 case PRINT_SRC_ONLY
:
8662 source_flag
= SRC_LINE
;
8665 /* Something bogus. */
8666 source_flag
= SRC_LINE
;
8667 do_frame_printing
= 0;
8670 internal_error (_("Unknown value."));
8673 /* The behavior of this routine with respect to the source
8675 SRC_LINE: Print only source line
8676 LOCATION: Print only location
8677 SRC_AND_LOC: Print location and source line. */
8678 if (do_frame_printing
)
8679 print_stack_frame (get_selected_frame (nullptr), 0, source_flag
, 1);
8685 print_stop_event (struct ui_out
*uiout
, bool displays
)
8687 struct target_waitstatus last
;
8688 struct thread_info
*tp
;
8690 get_last_target_status (nullptr, nullptr, &last
);
8693 scoped_restore save_uiout
= make_scoped_restore (¤t_uiout
, uiout
);
8695 print_stop_location (last
);
8697 /* Display the auto-display expressions. */
8702 tp
= inferior_thread ();
8703 if (tp
->thread_fsm () != nullptr
8704 && tp
->thread_fsm ()->finished_p ())
8706 struct return_value_info
*rv
;
8708 rv
= tp
->thread_fsm ()->return_value ();
8710 print_return_value (uiout
, rv
);
8717 maybe_remove_breakpoints (void)
8719 if (!breakpoints_should_be_inserted_now () && target_has_execution ())
8721 if (remove_breakpoints ())
8723 target_terminal::ours_for_output ();
8724 gdb_printf (_("Cannot remove breakpoints because "
8725 "program is no longer writable.\nFurther "
8726 "execution is probably impossible.\n"));
8731 /* The execution context that just caused a normal stop. */
8737 DISABLE_COPY_AND_ASSIGN (stop_context
);
8739 bool changed () const;
8744 /* The event PTID. */
8748 /* If stopp for a thread event, this is the thread that caused the
8750 thread_info_ref thread
;
8752 /* The inferior that caused the stop. */
8756 /* Initializes a new stop context. If stopped for a thread event, this
8757 takes a strong reference to the thread. */
8759 stop_context::stop_context ()
8761 stop_id
= get_stop_id ();
8762 ptid
= inferior_ptid
;
8763 inf_num
= current_inferior ()->num
;
8765 if (inferior_ptid
!= null_ptid
)
8767 /* Take a strong reference so that the thread can't be deleted
8769 thread
= thread_info_ref::new_reference (inferior_thread ());
8773 /* Return true if the current context no longer matches the saved stop
8777 stop_context::changed () const
8779 if (ptid
!= inferior_ptid
)
8781 if (inf_num
!= current_inferior ()->num
)
8783 if (thread
!= nullptr && thread
->state
!= THREAD_STOPPED
)
8785 if (get_stop_id () != stop_id
)
8795 struct target_waitstatus last
;
8797 get_last_target_status (nullptr, nullptr, &last
);
8801 /* If an exception is thrown from this point on, make sure to
8802 propagate GDB's knowledge of the executing state to the
8803 frontend/user running state. A QUIT is an easy exception to see
8804 here, so do this before any filtered output. */
8806 ptid_t finish_ptid
= null_ptid
;
8809 finish_ptid
= minus_one_ptid
;
8810 else if (last
.kind () == TARGET_WAITKIND_SIGNALLED
8811 || last
.kind () == TARGET_WAITKIND_EXITED
)
8813 /* On some targets, we may still have live threads in the
8814 inferior when we get a process exit event. E.g., for
8815 "checkpoint", when the current checkpoint/fork exits,
8816 linux-fork.c automatically switches to another fork from
8817 within target_mourn_inferior. */
8818 if (inferior_ptid
!= null_ptid
)
8819 finish_ptid
= ptid_t (inferior_ptid
.pid ());
8821 else if (last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
8822 finish_ptid
= inferior_ptid
;
8824 gdb::optional
<scoped_finish_thread_state
> maybe_finish_thread_state
;
8825 if (finish_ptid
!= null_ptid
)
8827 maybe_finish_thread_state
.emplace
8828 (user_visible_resume_target (finish_ptid
), finish_ptid
);
8831 /* As we're presenting a stop, and potentially removing breakpoints,
8832 update the thread list so we can tell whether there are threads
8833 running on the target. With target remote, for example, we can
8834 only learn about new threads when we explicitly update the thread
8835 list. Do this before notifying the interpreters about signal
8836 stops, end of stepping ranges, etc., so that the "new thread"
8837 output is emitted before e.g., "Program received signal FOO",
8838 instead of after. */
8839 update_thread_list ();
8841 if (last
.kind () == TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
8842 notify_signal_received (inferior_thread ()->stop_signal ());
8844 /* As with the notification of thread events, we want to delay
8845 notifying the user that we've switched thread context until
8846 the inferior actually stops.
8848 There's no point in saying anything if the inferior has exited.
8849 Note that SIGNALLED here means "exited with a signal", not
8850 "received a signal".
8852 Also skip saying anything in non-stop mode. In that mode, as we
8853 don't want GDB to switch threads behind the user's back, to avoid
8854 races where the user is typing a command to apply to thread x,
8855 but GDB switches to thread y before the user finishes entering
8856 the command, fetch_inferior_event installs a cleanup to restore
8857 the current thread back to the thread the user had selected right
8858 after this event is handled, so we're not really switching, only
8859 informing of a stop. */
8862 if ((last
.kind () != TARGET_WAITKIND_SIGNALLED
8863 && last
.kind () != TARGET_WAITKIND_EXITED
8864 && last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
8865 && target_has_execution ()
8866 && previous_thread
!= inferior_thread ())
8868 SWITCH_THRU_ALL_UIS ()
8870 target_terminal::ours_for_output ();
8871 gdb_printf (_("[Switching to %s]\n"),
8872 target_pid_to_str (inferior_ptid
).c_str ());
8873 annotate_thread_changed ();
8877 update_previous_thread ();
8880 if (last
.kind () == TARGET_WAITKIND_NO_RESUMED
)
8882 SWITCH_THRU_ALL_UIS ()
8883 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
8885 target_terminal::ours_for_output ();
8886 gdb_printf (_("No unwaited-for children left.\n"));
8890 /* Note: this depends on the update_thread_list call above. */
8891 maybe_remove_breakpoints ();
8893 /* If an auto-display called a function and that got a signal,
8894 delete that auto-display to avoid an infinite recursion. */
8896 if (stopped_by_random_signal
)
8897 disable_current_display ();
8899 SWITCH_THRU_ALL_UIS ()
8901 async_enable_stdin ();
8904 /* Let the user/frontend see the threads as stopped. */
8905 maybe_finish_thread_state
.reset ();
8907 /* Select innermost stack frame - i.e., current frame is frame 0,
8908 and current location is based on that. Handle the case where the
8909 dummy call is returning after being stopped. E.g. the dummy call
8910 previously hit a breakpoint. (If the dummy call returns
8911 normally, we won't reach here.) Do this before the stop hook is
8912 run, so that it doesn't get to see the temporary dummy frame,
8913 which is not where we'll present the stop. */
8914 if (has_stack_frames ())
8916 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
8918 /* Pop the empty frame that contains the stack dummy. This
8919 also restores inferior state prior to the call (struct
8920 infcall_suspend_state). */
8921 frame_info_ptr frame
= get_current_frame ();
8923 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
8925 /* frame_pop calls reinit_frame_cache as the last thing it
8926 does which means there's now no selected frame. */
8929 select_frame (get_current_frame ());
8931 /* Set the current source location. */
8932 set_current_sal_from_frame (get_current_frame ());
8935 /* Look up the hook_stop and run it (CLI internally handles problem
8936 of stop_command's pre-hook not existing). */
8937 stop_context saved_context
;
8941 execute_cmd_pre_hook (stop_command
);
8943 catch (const gdb_exception_error
&ex
)
8945 exception_fprintf (gdb_stderr
, ex
,
8946 "Error while running hook_stop:\n");
8949 /* If the stop hook resumes the target, then there's no point in
8950 trying to notify about the previous stop; its context is
8951 gone. Likewise if the command switches thread or inferior --
8952 the observers would print a stop for the wrong
8954 if (saved_context
.changed ())
8957 /* Notify observers about the stop. This is where the interpreters
8958 print the stop event. */
8959 if (inferior_ptid
!= null_ptid
)
8960 gdb::observers::normal_stop
.notify (inferior_thread ()->control
.stop_bpstat
,
8963 gdb::observers::normal_stop
.notify (nullptr, stop_print_frame
);
8965 annotate_stopped ();
8967 if (target_has_execution ())
8969 if (last
.kind () != TARGET_WAITKIND_SIGNALLED
8970 && last
.kind () != TARGET_WAITKIND_EXITED
8971 && last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
8972 /* Delete the breakpoint we stopped at, if it wants to be deleted.
8973 Delete any breakpoint that is to be deleted at the next stop. */
8974 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
8981 signal_stop_state (int signo
)
8983 return signal_stop
[signo
];
8987 signal_print_state (int signo
)
8989 return signal_print
[signo
];
8993 signal_pass_state (int signo
)
8995 return signal_program
[signo
];
8999 signal_cache_update (int signo
)
9003 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
9004 signal_cache_update (signo
);
9009 signal_pass
[signo
] = (signal_stop
[signo
] == 0
9010 && signal_print
[signo
] == 0
9011 && signal_program
[signo
] == 1
9012 && signal_catch
[signo
] == 0);
9016 signal_stop_update (int signo
, int state
)
9018 int ret
= signal_stop
[signo
];
9020 signal_stop
[signo
] = state
;
9021 signal_cache_update (signo
);
9026 signal_print_update (int signo
, int state
)
9028 int ret
= signal_print
[signo
];
9030 signal_print
[signo
] = state
;
9031 signal_cache_update (signo
);
9036 signal_pass_update (int signo
, int state
)
9038 int ret
= signal_program
[signo
];
9040 signal_program
[signo
] = state
;
9041 signal_cache_update (signo
);
9045 /* Update the global 'signal_catch' from INFO and notify the
9049 signal_catch_update (const unsigned int *info
)
9053 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
9054 signal_catch
[i
] = info
[i
] > 0;
9055 signal_cache_update (-1);
9056 target_pass_signals (signal_pass
);
9060 sig_print_header (void)
9062 gdb_printf (_("Signal Stop\tPrint\tPass "
9063 "to program\tDescription\n"));
9067 sig_print_info (enum gdb_signal oursig
)
9069 const char *name
= gdb_signal_to_name (oursig
);
9070 int name_padding
= 13 - strlen (name
);
9072 if (name_padding
<= 0)
9075 gdb_printf ("%s", name
);
9076 gdb_printf ("%*.*s ", name_padding
, name_padding
, " ");
9077 gdb_printf ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
9078 gdb_printf ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
9079 gdb_printf ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
9080 gdb_printf ("%s\n", gdb_signal_to_string (oursig
));
9083 /* Specify how various signals in the inferior should be handled. */
9086 handle_command (const char *args
, int from_tty
)
9088 int digits
, wordlen
;
9089 int sigfirst
, siglast
;
9090 enum gdb_signal oursig
;
9093 if (args
== nullptr)
9095 error_no_arg (_("signal to handle"));
9098 /* Allocate and zero an array of flags for which signals to handle. */
9100 const size_t nsigs
= GDB_SIGNAL_LAST
;
9101 unsigned char sigs
[nsigs
] {};
9103 /* Break the command line up into args. */
9105 gdb_argv
built_argv (args
);
9107 /* Walk through the args, looking for signal oursigs, signal names, and
9108 actions. Signal numbers and signal names may be interspersed with
9109 actions, with the actions being performed for all signals cumulatively
9110 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
9112 for (char *arg
: built_argv
)
9114 wordlen
= strlen (arg
);
9115 for (digits
= 0; isdigit (arg
[digits
]); digits
++)
9119 sigfirst
= siglast
= -1;
9121 if (wordlen
>= 1 && !strncmp (arg
, "all", wordlen
))
9123 /* Apply action to all signals except those used by the
9124 debugger. Silently skip those. */
9127 siglast
= nsigs
- 1;
9129 else if (wordlen
>= 1 && !strncmp (arg
, "stop", wordlen
))
9131 SET_SIGS (nsigs
, sigs
, signal_stop
);
9132 SET_SIGS (nsigs
, sigs
, signal_print
);
9134 else if (wordlen
>= 1 && !strncmp (arg
, "ignore", wordlen
))
9136 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9138 else if (wordlen
>= 2 && !strncmp (arg
, "print", wordlen
))
9140 SET_SIGS (nsigs
, sigs
, signal_print
);
9142 else if (wordlen
>= 2 && !strncmp (arg
, "pass", wordlen
))
9144 SET_SIGS (nsigs
, sigs
, signal_program
);
9146 else if (wordlen
>= 3 && !strncmp (arg
, "nostop", wordlen
))
9148 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9150 else if (wordlen
>= 3 && !strncmp (arg
, "noignore", wordlen
))
9152 SET_SIGS (nsigs
, sigs
, signal_program
);
9154 else if (wordlen
>= 4 && !strncmp (arg
, "noprint", wordlen
))
9156 UNSET_SIGS (nsigs
, sigs
, signal_print
);
9157 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9159 else if (wordlen
>= 4 && !strncmp (arg
, "nopass", wordlen
))
9161 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9163 else if (digits
> 0)
9165 /* It is numeric. The numeric signal refers to our own
9166 internal signal numbering from target.h, not to host/target
9167 signal number. This is a feature; users really should be
9168 using symbolic names anyway, and the common ones like
9169 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
9171 sigfirst
= siglast
= (int)
9172 gdb_signal_from_command (atoi (arg
));
9173 if (arg
[digits
] == '-')
9176 gdb_signal_from_command (atoi (arg
+ digits
+ 1));
9178 if (sigfirst
> siglast
)
9180 /* Bet he didn't figure we'd think of this case... */
9181 std::swap (sigfirst
, siglast
);
9186 oursig
= gdb_signal_from_name (arg
);
9187 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
9189 sigfirst
= siglast
= (int) oursig
;
9193 /* Not a number and not a recognized flag word => complain. */
9194 error (_("Unrecognized or ambiguous flag word: \"%s\"."), arg
);
9198 /* If any signal numbers or symbol names were found, set flags for
9199 which signals to apply actions to. */
9201 for (int signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
9203 switch ((enum gdb_signal
) signum
)
9205 case GDB_SIGNAL_TRAP
:
9206 case GDB_SIGNAL_INT
:
9207 if (!allsigs
&& !sigs
[signum
])
9209 if (query (_("%s is used by the debugger.\n\
9210 Are you sure you want to change it? "),
9211 gdb_signal_to_name ((enum gdb_signal
) signum
)))
9216 gdb_printf (_("Not confirmed, unchanged.\n"));
9220 case GDB_SIGNAL_DEFAULT
:
9221 case GDB_SIGNAL_UNKNOWN
:
9222 /* Make sure that "all" doesn't print these. */
9231 for (int signum
= 0; signum
< nsigs
; signum
++)
9234 signal_cache_update (-1);
9235 target_pass_signals (signal_pass
);
9236 target_program_signals (signal_program
);
9240 /* Show the results. */
9241 sig_print_header ();
9242 for (; signum
< nsigs
; signum
++)
9244 sig_print_info ((enum gdb_signal
) signum
);
9251 /* Complete the "handle" command. */
9254 handle_completer (struct cmd_list_element
*ignore
,
9255 completion_tracker
&tracker
,
9256 const char *text
, const char *word
)
9258 static const char * const keywords
[] =
9272 signal_completer (ignore
, tracker
, text
, word
);
9273 complete_on_enum (tracker
, keywords
, word
, word
);
9277 gdb_signal_from_command (int num
)
9279 if (num
>= 1 && num
<= 15)
9280 return (enum gdb_signal
) num
;
9281 error (_("Only signals 1-15 are valid as numeric signals.\n\
9282 Use \"info signals\" for a list of symbolic signals."));
9285 /* Print current contents of the tables set by the handle command.
9286 It is possible we should just be printing signals actually used
9287 by the current target (but for things to work right when switching
9288 targets, all signals should be in the signal tables). */
9291 info_signals_command (const char *signum_exp
, int from_tty
)
9293 enum gdb_signal oursig
;
9295 sig_print_header ();
9299 /* First see if this is a symbol name. */
9300 oursig
= gdb_signal_from_name (signum_exp
);
9301 if (oursig
== GDB_SIGNAL_UNKNOWN
)
9303 /* No, try numeric. */
9305 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
9307 sig_print_info (oursig
);
9312 /* These ugly casts brought to you by the native VAX compiler. */
9313 for (oursig
= GDB_SIGNAL_FIRST
;
9314 (int) oursig
< (int) GDB_SIGNAL_LAST
;
9315 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
9319 if (oursig
!= GDB_SIGNAL_UNKNOWN
9320 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
9321 sig_print_info (oursig
);
9324 gdb_printf (_("\nUse the \"handle\" command "
9325 "to change these tables.\n"));
9328 /* The $_siginfo convenience variable is a bit special. We don't know
9329 for sure the type of the value until we actually have a chance to
9330 fetch the data. The type can change depending on gdbarch, so it is
9331 also dependent on which thread you have selected.
9333 1. making $_siginfo be an internalvar that creates a new value on
9336 2. making the value of $_siginfo be an lval_computed value. */
9338 /* This function implements the lval_computed support for reading a
9342 siginfo_value_read (struct value
*v
)
9344 LONGEST transferred
;
9346 /* If we can access registers, so can we access $_siginfo. Likewise
9348 validate_registers_access ();
9351 target_read (current_inferior ()->top_target (),
9352 TARGET_OBJECT_SIGNAL_INFO
,
9354 v
->contents_all_raw ().data (),
9356 v
->type ()->length ());
9358 if (transferred
!= v
->type ()->length ())
9359 error (_("Unable to read siginfo"));
9362 /* This function implements the lval_computed support for writing a
9366 siginfo_value_write (struct value
*v
, struct value
*fromval
)
9368 LONGEST transferred
;
9370 /* If we can access registers, so can we access $_siginfo. Likewise
9372 validate_registers_access ();
9374 transferred
= target_write (current_inferior ()->top_target (),
9375 TARGET_OBJECT_SIGNAL_INFO
,
9377 fromval
->contents_all_raw ().data (),
9379 fromval
->type ()->length ());
9381 if (transferred
!= fromval
->type ()->length ())
9382 error (_("Unable to write siginfo"));
9385 static const struct lval_funcs siginfo_value_funcs
=
9391 /* Return a new value with the correct type for the siginfo object of
9392 the current thread using architecture GDBARCH. Return a void value
9393 if there's no object available. */
9395 static struct value
*
9396 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
9399 if (target_has_stack ()
9400 && inferior_ptid
!= null_ptid
9401 && gdbarch_get_siginfo_type_p (gdbarch
))
9403 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9405 return value::allocate_computed (type
, &siginfo_value_funcs
, nullptr);
9408 return value::allocate (builtin_type (gdbarch
)->builtin_void
);
9412 /* infcall_suspend_state contains state about the program itself like its
9413 registers and any signal it received when it last stopped.
9414 This state must be restored regardless of how the inferior function call
9415 ends (either successfully, or after it hits a breakpoint or signal)
9416 if the program is to properly continue where it left off. */
9418 class infcall_suspend_state
9421 /* Capture state from GDBARCH, TP, and REGCACHE that must be restored
9422 once the inferior function call has finished. */
9423 infcall_suspend_state (struct gdbarch
*gdbarch
,
9424 const struct thread_info
*tp
,
9425 struct regcache
*regcache
)
9426 : m_registers (new readonly_detached_regcache (*regcache
))
9428 tp
->save_suspend_to (m_thread_suspend
);
9430 gdb::unique_xmalloc_ptr
<gdb_byte
> siginfo_data
;
9432 if (gdbarch_get_siginfo_type_p (gdbarch
))
9434 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9435 size_t len
= type
->length ();
9437 siginfo_data
.reset ((gdb_byte
*) xmalloc (len
));
9439 if (target_read (current_inferior ()->top_target (),
9440 TARGET_OBJECT_SIGNAL_INFO
, nullptr,
9441 siginfo_data
.get (), 0, len
) != len
)
9443 /* Errors ignored. */
9444 siginfo_data
.reset (nullptr);
9450 m_siginfo_gdbarch
= gdbarch
;
9451 m_siginfo_data
= std::move (siginfo_data
);
9455 /* Return a pointer to the stored register state. */
9457 readonly_detached_regcache
*registers () const
9459 return m_registers
.get ();
9462 /* Restores the stored state into GDBARCH, TP, and REGCACHE. */
9464 void restore (struct gdbarch
*gdbarch
,
9465 struct thread_info
*tp
,
9466 struct regcache
*regcache
) const
9468 tp
->restore_suspend_from (m_thread_suspend
);
9470 if (m_siginfo_gdbarch
== gdbarch
)
9472 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9474 /* Errors ignored. */
9475 target_write (current_inferior ()->top_target (),
9476 TARGET_OBJECT_SIGNAL_INFO
, nullptr,
9477 m_siginfo_data
.get (), 0, type
->length ());
9480 /* The inferior can be gone if the user types "print exit(0)"
9481 (and perhaps other times). */
9482 if (target_has_execution ())
9483 /* NB: The register write goes through to the target. */
9484 regcache
->restore (registers ());
9488 /* How the current thread stopped before the inferior function call was
9490 struct thread_suspend_state m_thread_suspend
;
9492 /* The registers before the inferior function call was executed. */
9493 std::unique_ptr
<readonly_detached_regcache
> m_registers
;
9495 /* Format of SIGINFO_DATA or NULL if it is not present. */
9496 struct gdbarch
*m_siginfo_gdbarch
= nullptr;
9498 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
9499 gdbarch_get_siginfo_type ()->length (). For different gdbarch the
9500 content would be invalid. */
9501 gdb::unique_xmalloc_ptr
<gdb_byte
> m_siginfo_data
;
9504 infcall_suspend_state_up
9505 save_infcall_suspend_state ()
9507 struct thread_info
*tp
= inferior_thread ();
9508 struct regcache
*regcache
= get_current_regcache ();
9509 struct gdbarch
*gdbarch
= regcache
->arch ();
9511 infcall_suspend_state_up inf_state
9512 (new struct infcall_suspend_state (gdbarch
, tp
, regcache
));
9514 /* Having saved the current state, adjust the thread state, discarding
9515 any stop signal information. The stop signal is not useful when
9516 starting an inferior function call, and run_inferior_call will not use
9517 the signal due to its `proceed' call with GDB_SIGNAL_0. */
9518 tp
->set_stop_signal (GDB_SIGNAL_0
);
9523 /* Restore inferior session state to INF_STATE. */
9526 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9528 struct thread_info
*tp
= inferior_thread ();
9529 struct regcache
*regcache
= get_current_regcache ();
9530 struct gdbarch
*gdbarch
= regcache
->arch ();
9532 inf_state
->restore (gdbarch
, tp
, regcache
);
9533 discard_infcall_suspend_state (inf_state
);
9537 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9542 readonly_detached_regcache
*
9543 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
9545 return inf_state
->registers ();
9548 /* infcall_control_state contains state regarding gdb's control of the
9549 inferior itself like stepping control. It also contains session state like
9550 the user's currently selected frame. */
9552 struct infcall_control_state
9554 struct thread_control_state thread_control
;
9555 struct inferior_control_state inferior_control
;
9558 enum stop_stack_kind stop_stack_dummy
= STOP_NONE
;
9559 int stopped_by_random_signal
= 0;
9561 /* ID and level of the selected frame when the inferior function
9563 struct frame_id selected_frame_id
{};
9564 int selected_frame_level
= -1;
9567 /* Save all of the information associated with the inferior<==>gdb
9570 infcall_control_state_up
9571 save_infcall_control_state ()
9573 infcall_control_state_up
inf_status (new struct infcall_control_state
);
9574 struct thread_info
*tp
= inferior_thread ();
9575 struct inferior
*inf
= current_inferior ();
9577 inf_status
->thread_control
= tp
->control
;
9578 inf_status
->inferior_control
= inf
->control
;
9580 tp
->control
.step_resume_breakpoint
= nullptr;
9581 tp
->control
.exception_resume_breakpoint
= nullptr;
9583 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
9584 chain. If caller's caller is walking the chain, they'll be happier if we
9585 hand them back the original chain when restore_infcall_control_state is
9587 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
9590 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
9591 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
9593 save_selected_frame (&inf_status
->selected_frame_id
,
9594 &inf_status
->selected_frame_level
);
9599 /* Restore inferior session state to INF_STATUS. */
9602 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
9604 struct thread_info
*tp
= inferior_thread ();
9605 struct inferior
*inf
= current_inferior ();
9607 if (tp
->control
.step_resume_breakpoint
)
9608 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
9610 if (tp
->control
.exception_resume_breakpoint
)
9611 tp
->control
.exception_resume_breakpoint
->disposition
9612 = disp_del_at_next_stop
;
9614 /* Handle the bpstat_copy of the chain. */
9615 bpstat_clear (&tp
->control
.stop_bpstat
);
9617 tp
->control
= inf_status
->thread_control
;
9618 inf
->control
= inf_status
->inferior_control
;
9621 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
9622 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
9624 if (target_has_stack ())
9626 restore_selected_frame (inf_status
->selected_frame_id
,
9627 inf_status
->selected_frame_level
);
9634 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
9636 if (inf_status
->thread_control
.step_resume_breakpoint
)
9637 inf_status
->thread_control
.step_resume_breakpoint
->disposition
9638 = disp_del_at_next_stop
;
9640 if (inf_status
->thread_control
.exception_resume_breakpoint
)
9641 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
9642 = disp_del_at_next_stop
;
9644 /* See save_infcall_control_state for info on stop_bpstat. */
9645 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
9653 clear_exit_convenience_vars (void)
9655 clear_internalvar (lookup_internalvar ("_exitsignal"));
9656 clear_internalvar (lookup_internalvar ("_exitcode"));
9660 /* User interface for reverse debugging:
9661 Set exec-direction / show exec-direction commands
9662 (returns error unless target implements to_set_exec_direction method). */
9664 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
9665 static const char exec_forward
[] = "forward";
9666 static const char exec_reverse
[] = "reverse";
9667 static const char *exec_direction
= exec_forward
;
9668 static const char *const exec_direction_names
[] = {
9675 set_exec_direction_func (const char *args
, int from_tty
,
9676 struct cmd_list_element
*cmd
)
9678 if (target_can_execute_reverse ())
9680 if (!strcmp (exec_direction
, exec_forward
))
9681 execution_direction
= EXEC_FORWARD
;
9682 else if (!strcmp (exec_direction
, exec_reverse
))
9683 execution_direction
= EXEC_REVERSE
;
9687 exec_direction
= exec_forward
;
9688 error (_("Target does not support this operation."));
9693 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
9694 struct cmd_list_element
*cmd
, const char *value
)
9696 switch (execution_direction
) {
9698 gdb_printf (out
, _("Forward.\n"));
9701 gdb_printf (out
, _("Reverse.\n"));
9704 internal_error (_("bogus execution_direction value: %d"),
9705 (int) execution_direction
);
9710 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
9711 struct cmd_list_element
*c
, const char *value
)
9713 gdb_printf (file
, _("Resuming the execution of threads "
9714 "of all processes is %s.\n"), value
);
9717 /* Implementation of `siginfo' variable. */
9719 static const struct internalvar_funcs siginfo_funcs
=
9725 /* Callback for infrun's target events source. This is marked when a
9726 thread has a pending status to process. */
9729 infrun_async_inferior_event_handler (gdb_client_data data
)
9731 clear_async_event_handler (infrun_async_inferior_event_token
);
9732 inferior_event_handler (INF_REG_EVENT
);
9739 /* Verify that when two threads with the same ptid exist (from two different
9740 targets) and one of them changes ptid, we only update inferior_ptid if
9741 it is appropriate. */
9744 infrun_thread_ptid_changed ()
9746 gdbarch
*arch
= current_inferior ()->gdbarch
;
9748 /* The thread which inferior_ptid represents changes ptid. */
9750 scoped_restore_current_pspace_and_thread restore
;
9752 scoped_mock_context
<test_target_ops
> target1 (arch
);
9753 scoped_mock_context
<test_target_ops
> target2 (arch
);
9755 ptid_t
old_ptid (111, 222);
9756 ptid_t
new_ptid (111, 333);
9758 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9759 target1
.mock_thread
.ptid
= old_ptid
;
9760 target1
.mock_inferior
.ptid_thread_map
.clear ();
9761 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
9763 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9764 target2
.mock_thread
.ptid
= old_ptid
;
9765 target2
.mock_inferior
.ptid_thread_map
.clear ();
9766 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
9768 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9769 set_current_inferior (&target1
.mock_inferior
);
9771 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9773 gdb_assert (inferior_ptid
== new_ptid
);
9776 /* A thread with the same ptid as inferior_ptid, but from another target,
9779 scoped_restore_current_pspace_and_thread restore
;
9781 scoped_mock_context
<test_target_ops
> target1 (arch
);
9782 scoped_mock_context
<test_target_ops
> target2 (arch
);
9784 ptid_t
old_ptid (111, 222);
9785 ptid_t
new_ptid (111, 333);
9787 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9788 target1
.mock_thread
.ptid
= old_ptid
;
9789 target1
.mock_inferior
.ptid_thread_map
.clear ();
9790 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
9792 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9793 target2
.mock_thread
.ptid
= old_ptid
;
9794 target2
.mock_inferior
.ptid_thread_map
.clear ();
9795 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
9797 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9798 set_current_inferior (&target2
.mock_inferior
);
9800 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9802 gdb_assert (inferior_ptid
== old_ptid
);
9806 } /* namespace selftests */
9808 #endif /* GDB_SELF_TEST */
9810 void _initialize_infrun ();
9812 _initialize_infrun ()
9814 struct cmd_list_element
*c
;
9816 /* Register extra event sources in the event loop. */
9817 infrun_async_inferior_event_token
9818 = create_async_event_handler (infrun_async_inferior_event_handler
, nullptr,
9821 cmd_list_element
*info_signals_cmd
9822 = add_info ("signals", info_signals_command
, _("\
9823 What debugger does when program gets various signals.\n\
9824 Specify a signal as argument to print info on that signal only."));
9825 add_info_alias ("handle", info_signals_cmd
, 0);
9827 c
= add_com ("handle", class_run
, handle_command
, _("\
9828 Specify how to handle signals.\n\
9829 Usage: handle SIGNAL [ACTIONS]\n\
9830 Args are signals and actions to apply to those signals.\n\
9831 If no actions are specified, the current settings for the specified signals\n\
9832 will be displayed instead.\n\
9834 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
9835 from 1-15 are allowed for compatibility with old versions of GDB.\n\
9836 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
9837 The special arg \"all\" is recognized to mean all signals except those\n\
9838 used by the debugger, typically SIGTRAP and SIGINT.\n\
9840 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
9841 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
9842 Stop means reenter debugger if this signal happens (implies print).\n\
9843 Print means print a message if this signal happens.\n\
9844 Pass means let program see this signal; otherwise program doesn't know.\n\
9845 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
9846 Pass and Stop may be combined.\n\
9848 Multiple signals may be specified. Signal numbers and signal names\n\
9849 may be interspersed with actions, with the actions being performed for\n\
9850 all signals cumulatively specified."));
9851 set_cmd_completer (c
, handle_completer
);
9853 stop_command
= add_cmd ("stop", class_obscure
,
9854 not_just_help_class_command
, _("\
9855 There is no `stop' command, but you can set a hook on `stop'.\n\
9856 This allows you to set a list of commands to be run each time execution\n\
9857 of the program stops."), &cmdlist
);
9859 add_setshow_boolean_cmd
9860 ("infrun", class_maintenance
, &debug_infrun
,
9861 _("Set inferior debugging."),
9862 _("Show inferior debugging."),
9863 _("When non-zero, inferior specific debugging is enabled."),
9864 nullptr, show_debug_infrun
, &setdebuglist
, &showdebuglist
);
9866 add_setshow_boolean_cmd ("non-stop", no_class
,
9868 Set whether gdb controls the inferior in non-stop mode."), _("\
9869 Show whether gdb controls the inferior in non-stop mode."), _("\
9870 When debugging a multi-threaded program and this setting is\n\
9871 off (the default, also called all-stop mode), when one thread stops\n\
9872 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
9873 all other threads in the program while you interact with the thread of\n\
9874 interest. When you continue or step a thread, you can allow the other\n\
9875 threads to run, or have them remain stopped, but while you inspect any\n\
9876 thread's state, all threads stop.\n\
9878 In non-stop mode, when one thread stops, other threads can continue\n\
9879 to run freely. You'll be able to step each thread independently,\n\
9880 leave it stopped or free to run as needed."),
9886 for (size_t i
= 0; i
< GDB_SIGNAL_LAST
; i
++)
9889 signal_print
[i
] = 1;
9890 signal_program
[i
] = 1;
9891 signal_catch
[i
] = 0;
9894 /* Signals caused by debugger's own actions should not be given to
9895 the program afterwards.
9897 Do not deliver GDB_SIGNAL_TRAP by default, except when the user
9898 explicitly specifies that it should be delivered to the target
9899 program. Typically, that would occur when a user is debugging a
9900 target monitor on a simulator: the target monitor sets a
9901 breakpoint; the simulator encounters this breakpoint and halts
9902 the simulation handing control to GDB; GDB, noting that the stop
9903 address doesn't map to any known breakpoint, returns control back
9904 to the simulator; the simulator then delivers the hardware
9905 equivalent of a GDB_SIGNAL_TRAP to the program being
9907 signal_program
[GDB_SIGNAL_TRAP
] = 0;
9908 signal_program
[GDB_SIGNAL_INT
] = 0;
9910 /* Signals that are not errors should not normally enter the debugger. */
9911 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
9912 signal_print
[GDB_SIGNAL_ALRM
] = 0;
9913 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
9914 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
9915 signal_stop
[GDB_SIGNAL_PROF
] = 0;
9916 signal_print
[GDB_SIGNAL_PROF
] = 0;
9917 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
9918 signal_print
[GDB_SIGNAL_CHLD
] = 0;
9919 signal_stop
[GDB_SIGNAL_IO
] = 0;
9920 signal_print
[GDB_SIGNAL_IO
] = 0;
9921 signal_stop
[GDB_SIGNAL_POLL
] = 0;
9922 signal_print
[GDB_SIGNAL_POLL
] = 0;
9923 signal_stop
[GDB_SIGNAL_URG
] = 0;
9924 signal_print
[GDB_SIGNAL_URG
] = 0;
9925 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
9926 signal_print
[GDB_SIGNAL_WINCH
] = 0;
9927 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
9928 signal_print
[GDB_SIGNAL_PRIO
] = 0;
9930 /* These signals are used internally by user-level thread
9931 implementations. (See signal(5) on Solaris.) Like the above
9932 signals, a healthy program receives and handles them as part of
9933 its normal operation. */
9934 signal_stop
[GDB_SIGNAL_LWP
] = 0;
9935 signal_print
[GDB_SIGNAL_LWP
] = 0;
9936 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
9937 signal_print
[GDB_SIGNAL_WAITING
] = 0;
9938 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
9939 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
9940 signal_stop
[GDB_SIGNAL_LIBRT
] = 0;
9941 signal_print
[GDB_SIGNAL_LIBRT
] = 0;
9943 /* Update cached state. */
9944 signal_cache_update (-1);
9946 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
9947 &stop_on_solib_events
, _("\
9948 Set stopping for shared library events."), _("\
9949 Show stopping for shared library events."), _("\
9950 If nonzero, gdb will give control to the user when the dynamic linker\n\
9951 notifies gdb of shared library events. The most common event of interest\n\
9952 to the user would be loading/unloading of a new library."),
9953 set_stop_on_solib_events
,
9954 show_stop_on_solib_events
,
9955 &setlist
, &showlist
);
9957 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
9958 follow_fork_mode_kind_names
,
9959 &follow_fork_mode_string
, _("\
9960 Set debugger response to a program call of fork or vfork."), _("\
9961 Show debugger response to a program call of fork or vfork."), _("\
9962 A fork or vfork creates a new process. follow-fork-mode can be:\n\
9963 parent - the original process is debugged after a fork\n\
9964 child - the new process is debugged after a fork\n\
9965 The unfollowed process will continue to run.\n\
9966 By default, the debugger will follow the parent process."),
9968 show_follow_fork_mode_string
,
9969 &setlist
, &showlist
);
9971 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
9972 follow_exec_mode_names
,
9973 &follow_exec_mode_string
, _("\
9974 Set debugger response to a program call of exec."), _("\
9975 Show debugger response to a program call of exec."), _("\
9976 An exec call replaces the program image of a process.\n\
9978 follow-exec-mode can be:\n\
9980 new - the debugger creates a new inferior and rebinds the process\n\
9981 to this new inferior. The program the process was running before\n\
9982 the exec call can be restarted afterwards by restarting the original\n\
9985 same - the debugger keeps the process bound to the same inferior.\n\
9986 The new executable image replaces the previous executable loaded in\n\
9987 the inferior. Restarting the inferior after the exec call restarts\n\
9988 the executable the process was running after the exec call.\n\
9990 By default, the debugger will use the same inferior."),
9992 show_follow_exec_mode_string
,
9993 &setlist
, &showlist
);
9995 add_setshow_enum_cmd ("scheduler-locking", class_run
,
9996 scheduler_enums
, &scheduler_mode
, _("\
9997 Set mode for locking scheduler during execution."), _("\
9998 Show mode for locking scheduler during execution."), _("\
9999 off == no locking (threads may preempt at any time)\n\
10000 on == full locking (no thread except the current thread may run)\n\
10001 This applies to both normal execution and replay mode.\n\
10002 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
10003 In this mode, other threads may run during other commands.\n\
10004 This applies to both normal execution and replay mode.\n\
10005 replay == scheduler locked in replay mode and unlocked during normal execution."),
10006 set_schedlock_func
, /* traps on target vector */
10007 show_scheduler_mode
,
10008 &setlist
, &showlist
);
10010 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
10011 Set mode for resuming threads of all processes."), _("\
10012 Show mode for resuming threads of all processes."), _("\
10013 When on, execution commands (such as 'continue' or 'next') resume all\n\
10014 threads of all processes. When off (which is the default), execution\n\
10015 commands only resume the threads of the current process. The set of\n\
10016 threads that are resumed is further refined by the scheduler-locking\n\
10017 mode (see help set scheduler-locking)."),
10019 show_schedule_multiple
,
10020 &setlist
, &showlist
);
10022 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
10023 Set mode of the step operation."), _("\
10024 Show mode of the step operation."), _("\
10025 When set, doing a step over a function without debug line information\n\
10026 will stop at the first instruction of that function. Otherwise, the\n\
10027 function is skipped and the step command stops at a different source line."),
10029 show_step_stop_if_no_debug
,
10030 &setlist
, &showlist
);
10032 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
10033 &can_use_displaced_stepping
, _("\
10034 Set debugger's willingness to use displaced stepping."), _("\
10035 Show debugger's willingness to use displaced stepping."), _("\
10036 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
10037 supported by the target architecture. If off, gdb will not use displaced\n\
10038 stepping to step over breakpoints, even if such is supported by the target\n\
10039 architecture. If auto (which is the default), gdb will use displaced stepping\n\
10040 if the target architecture supports it and non-stop mode is active, but will not\n\
10041 use it in all-stop mode (see help set non-stop)."),
10043 show_can_use_displaced_stepping
,
10044 &setlist
, &showlist
);
10046 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
10047 &exec_direction
, _("Set direction of execution.\n\
10048 Options are 'forward' or 'reverse'."),
10049 _("Show direction of execution (forward/reverse)."),
10050 _("Tells gdb whether to execute forward or backward."),
10051 set_exec_direction_func
, show_exec_direction_func
,
10052 &setlist
, &showlist
);
10054 /* Set/show detach-on-fork: user-settable mode. */
10056 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
10057 Set whether gdb will detach the child of a fork."), _("\
10058 Show whether gdb will detach the child of a fork."), _("\
10059 Tells gdb whether to detach the child of a fork."),
10060 nullptr, nullptr, &setlist
, &showlist
);
10062 /* Set/show disable address space randomization mode. */
10064 add_setshow_boolean_cmd ("disable-randomization", class_support
,
10065 &disable_randomization
, _("\
10066 Set disabling of debuggee's virtual address space randomization."), _("\
10067 Show disabling of debuggee's virtual address space randomization."), _("\
10068 When this mode is on (which is the default), randomization of the virtual\n\
10069 address space is disabled. Standalone programs run with the randomization\n\
10070 enabled by default on some platforms."),
10071 &set_disable_randomization
,
10072 &show_disable_randomization
,
10073 &setlist
, &showlist
);
10075 /* ptid initializations */
10076 inferior_ptid
= null_ptid
;
10077 target_last_wait_ptid
= minus_one_ptid
;
10079 gdb::observers::thread_ptid_changed
.attach (infrun_thread_ptid_changed
,
10081 gdb::observers::thread_stop_requested
.attach (infrun_thread_stop_requested
,
10083 gdb::observers::inferior_exit
.attach (infrun_inferior_exit
, "infrun");
10084 gdb::observers::inferior_execd
.attach (infrun_inferior_execd
, "infrun");
10086 /* Explicitly create without lookup, since that tries to create a
10087 value with a void typed value, and when we get here, gdbarch
10088 isn't initialized yet. At this point, we're quite sure there
10089 isn't another convenience variable of the same name. */
10090 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, nullptr);
10092 add_setshow_boolean_cmd ("observer", no_class
,
10093 &observer_mode_1
, _("\
10094 Set whether gdb controls the inferior in observer mode."), _("\
10095 Show whether gdb controls the inferior in observer mode."), _("\
10096 In observer mode, GDB can get data from the inferior, but not\n\
10097 affect its execution. Registers and memory may not be changed,\n\
10098 breakpoints may not be set, and the program cannot be interrupted\n\
10101 show_observer_mode
,
10106 selftests::register_test ("infrun_thread_ptid_changed",
10107 selftests::infrun_thread_ptid_changed
);