1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2023 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "displaced-stepping.h"
28 #include "breakpoint.h"
32 #include "target-connection.h"
33 #include "gdbthread.h"
40 #include "observable.h"
45 #include "mi/mi-common.h"
46 #include "event-top.h"
48 #include "record-full.h"
49 #include "inline-frame.h"
51 #include "tracepoint.h"
55 #include "completer.h"
56 #include "target-descriptions.h"
57 #include "target-dcache.h"
60 #include "gdbsupport/event-loop.h"
61 #include "thread-fsm.h"
62 #include "gdbsupport/enum-flags.h"
63 #include "progspace-and-thread.h"
64 #include "gdbsupport/gdb_optional.h"
65 #include "arch-utils.h"
66 #include "gdbsupport/scope-exit.h"
67 #include "gdbsupport/forward-scope-exit.h"
68 #include "gdbsupport/gdb_select.h"
69 #include <unordered_map>
70 #include "async-event.h"
71 #include "gdbsupport/selftest.h"
72 #include "scoped-mock-context.h"
73 #include "test-target.h"
74 #include "gdbsupport/common-debug.h"
75 #include "gdbsupport/buildargv.h"
76 #include "extension.h"
78 /* Prototypes for local functions */
80 static void sig_print_info (enum gdb_signal
);
82 static void sig_print_header (void);
84 static void follow_inferior_reset_breakpoints (void);
86 static bool currently_stepping (struct thread_info
*tp
);
88 static void insert_hp_step_resume_breakpoint_at_frame (frame_info_ptr
);
90 static void insert_step_resume_breakpoint_at_caller (frame_info_ptr
);
92 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
94 static bool maybe_software_singlestep (struct gdbarch
*gdbarch
);
96 static void resume (gdb_signal sig
);
98 static void wait_for_inferior (inferior
*inf
);
100 static void restart_threads (struct thread_info
*event_thread
,
101 inferior
*inf
= nullptr);
103 static bool start_step_over (void);
105 static bool step_over_info_valid_p (void);
107 /* Asynchronous signal handler registered as event loop source for
108 when we have pending events ready to be passed to the core. */
109 static struct async_event_handler
*infrun_async_inferior_event_token
;
111 /* Stores whether infrun_async was previously enabled or disabled.
112 Starts off as -1, indicating "never enabled/disabled". */
113 static int infrun_is_async
= -1;
118 infrun_async (int enable
)
120 if (infrun_is_async
!= enable
)
122 infrun_is_async
= enable
;
124 infrun_debug_printf ("enable=%d", enable
);
127 mark_async_event_handler (infrun_async_inferior_event_token
);
129 clear_async_event_handler (infrun_async_inferior_event_token
);
136 mark_infrun_async_event_handler (void)
138 mark_async_event_handler (infrun_async_inferior_event_token
);
141 /* When set, stop the 'step' command if we enter a function which has
142 no line number information. The normal behavior is that we step
143 over such function. */
144 bool step_stop_if_no_debug
= false;
146 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
147 struct cmd_list_element
*c
, const char *value
)
149 gdb_printf (file
, _("Mode of the step operation is %s.\n"), value
);
152 /* proceed and normal_stop use this to notify the user when the
153 inferior stopped in a different thread than it had been running
156 static ptid_t previous_inferior_ptid
;
158 /* If set (default for legacy reasons), when following a fork, GDB
159 will detach from one of the fork branches, child or parent.
160 Exactly which branch is detached depends on 'set follow-fork-mode'
163 static bool detach_fork
= true;
165 bool debug_infrun
= false;
167 show_debug_infrun (struct ui_file
*file
, int from_tty
,
168 struct cmd_list_element
*c
, const char *value
)
170 gdb_printf (file
, _("Inferior debugging is %s.\n"), value
);
173 /* Support for disabling address space randomization. */
175 bool disable_randomization
= true;
178 show_disable_randomization (struct ui_file
*file
, int from_tty
,
179 struct cmd_list_element
*c
, const char *value
)
181 if (target_supports_disable_randomization ())
183 _("Disabling randomization of debuggee's "
184 "virtual address space is %s.\n"),
187 gdb_puts (_("Disabling randomization of debuggee's "
188 "virtual address space is unsupported on\n"
189 "this platform.\n"), file
);
193 set_disable_randomization (const char *args
, int from_tty
,
194 struct cmd_list_element
*c
)
196 if (!target_supports_disable_randomization ())
197 error (_("Disabling randomization of debuggee's "
198 "virtual address space is unsupported on\n"
202 /* User interface for non-stop mode. */
204 bool non_stop
= false;
205 static bool non_stop_1
= false;
208 set_non_stop (const char *args
, int from_tty
,
209 struct cmd_list_element
*c
)
211 if (target_has_execution ())
213 non_stop_1
= non_stop
;
214 error (_("Cannot change this setting while the inferior is running."));
217 non_stop
= non_stop_1
;
221 show_non_stop (struct ui_file
*file
, int from_tty
,
222 struct cmd_list_element
*c
, const char *value
)
225 _("Controlling the inferior in non-stop mode is %s.\n"),
229 /* "Observer mode" is somewhat like a more extreme version of
230 non-stop, in which all GDB operations that might affect the
231 target's execution have been disabled. */
233 static bool observer_mode
= false;
234 static bool observer_mode_1
= false;
237 set_observer_mode (const char *args
, int from_tty
,
238 struct cmd_list_element
*c
)
240 if (target_has_execution ())
242 observer_mode_1
= observer_mode
;
243 error (_("Cannot change this setting while the inferior is running."));
246 observer_mode
= observer_mode_1
;
248 may_write_registers
= !observer_mode
;
249 may_write_memory
= !observer_mode
;
250 may_insert_breakpoints
= !observer_mode
;
251 may_insert_tracepoints
= !observer_mode
;
252 /* We can insert fast tracepoints in or out of observer mode,
253 but enable them if we're going into this mode. */
255 may_insert_fast_tracepoints
= true;
256 may_stop
= !observer_mode
;
257 update_target_permissions ();
259 /* Going *into* observer mode we must force non-stop, then
260 going out we leave it that way. */
263 pagination_enabled
= false;
264 non_stop
= non_stop_1
= true;
268 gdb_printf (_("Observer mode is now %s.\n"),
269 (observer_mode
? "on" : "off"));
273 show_observer_mode (struct ui_file
*file
, int from_tty
,
274 struct cmd_list_element
*c
, const char *value
)
276 gdb_printf (file
, _("Observer mode is %s.\n"), value
);
279 /* This updates the value of observer mode based on changes in
280 permissions. Note that we are deliberately ignoring the values of
281 may-write-registers and may-write-memory, since the user may have
282 reason to enable these during a session, for instance to turn on a
283 debugging-related global. */
286 update_observer_mode (void)
288 bool newval
= (!may_insert_breakpoints
289 && !may_insert_tracepoints
290 && may_insert_fast_tracepoints
294 /* Let the user know if things change. */
295 if (newval
!= observer_mode
)
296 gdb_printf (_("Observer mode is now %s.\n"),
297 (newval
? "on" : "off"));
299 observer_mode
= observer_mode_1
= newval
;
302 /* Tables of how to react to signals; the user sets them. */
304 static unsigned char signal_stop
[GDB_SIGNAL_LAST
];
305 static unsigned char signal_print
[GDB_SIGNAL_LAST
];
306 static unsigned char signal_program
[GDB_SIGNAL_LAST
];
308 /* Table of signals that are registered with "catch signal". A
309 non-zero entry indicates that the signal is caught by some "catch
311 static unsigned char signal_catch
[GDB_SIGNAL_LAST
];
313 /* Table of signals that the target may silently handle.
314 This is automatically determined from the flags above,
315 and simply cached here. */
316 static unsigned char signal_pass
[GDB_SIGNAL_LAST
];
318 #define SET_SIGS(nsigs,sigs,flags) \
320 int signum = (nsigs); \
321 while (signum-- > 0) \
322 if ((sigs)[signum]) \
323 (flags)[signum] = 1; \
326 #define UNSET_SIGS(nsigs,sigs,flags) \
328 int signum = (nsigs); \
329 while (signum-- > 0) \
330 if ((sigs)[signum]) \
331 (flags)[signum] = 0; \
334 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
335 this function is to avoid exporting `signal_program'. */
338 update_signals_program_target (void)
340 target_program_signals (signal_program
);
343 /* Value to pass to target_resume() to cause all threads to resume. */
345 #define RESUME_ALL minus_one_ptid
347 /* Command list pointer for the "stop" placeholder. */
349 static struct cmd_list_element
*stop_command
;
351 /* Nonzero if we want to give control to the user when we're notified
352 of shared library events by the dynamic linker. */
353 int stop_on_solib_events
;
355 /* Enable or disable optional shared library event breakpoints
356 as appropriate when the above flag is changed. */
359 set_stop_on_solib_events (const char *args
,
360 int from_tty
, struct cmd_list_element
*c
)
362 update_solib_breakpoints ();
366 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
367 struct cmd_list_element
*c
, const char *value
)
369 gdb_printf (file
, _("Stopping for shared library events is %s.\n"),
373 /* True after stop if current stack frame should be printed. */
375 static bool stop_print_frame
;
377 /* This is a cached copy of the target/ptid/waitstatus of the last
378 event returned by target_wait().
379 This information is returned by get_last_target_status(). */
380 static process_stratum_target
*target_last_proc_target
;
381 static ptid_t target_last_wait_ptid
;
382 static struct target_waitstatus target_last_waitstatus
;
384 void init_thread_stepping_state (struct thread_info
*tss
);
386 static const char follow_fork_mode_child
[] = "child";
387 static const char follow_fork_mode_parent
[] = "parent";
389 static const char *const follow_fork_mode_kind_names
[] = {
390 follow_fork_mode_child
,
391 follow_fork_mode_parent
,
395 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
397 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
398 struct cmd_list_element
*c
, const char *value
)
401 _("Debugger response to a program "
402 "call of fork or vfork is \"%s\".\n"),
407 /* Handle changes to the inferior list based on the type of fork,
408 which process is being followed, and whether the other process
409 should be detached. On entry inferior_ptid must be the ptid of
410 the fork parent. At return inferior_ptid is the ptid of the
411 followed inferior. */
414 follow_fork_inferior (bool follow_child
, bool detach_fork
)
416 target_waitkind fork_kind
= inferior_thread ()->pending_follow
.kind ();
417 gdb_assert (fork_kind
== TARGET_WAITKIND_FORKED
418 || fork_kind
== TARGET_WAITKIND_VFORKED
);
419 bool has_vforked
= fork_kind
== TARGET_WAITKIND_VFORKED
;
420 ptid_t parent_ptid
= inferior_ptid
;
421 ptid_t child_ptid
= inferior_thread ()->pending_follow
.child_ptid ();
424 && !non_stop
/* Non-stop always resumes both branches. */
425 && current_ui
->prompt_state
== PROMPT_BLOCKED
426 && !(follow_child
|| detach_fork
|| sched_multi
))
428 /* The parent stays blocked inside the vfork syscall until the
429 child execs or exits. If we don't let the child run, then
430 the parent stays blocked. If we're telling the parent to run
431 in the foreground, the user will not be able to ctrl-c to get
432 back the terminal, effectively hanging the debug session. */
433 gdb_printf (gdb_stderr
, _("\
434 Can not resume the parent process over vfork in the foreground while\n\
435 holding the child stopped. Try \"set detach-on-fork\" or \
436 \"set schedule-multiple\".\n"));
440 inferior
*parent_inf
= current_inferior ();
441 inferior
*child_inf
= nullptr;
443 gdb_assert (parent_inf
->thread_waiting_for_vfork_done
== nullptr);
447 /* Detach new forked process? */
450 /* Before detaching from the child, remove all breakpoints
451 from it. If we forked, then this has already been taken
452 care of by infrun.c. If we vforked however, any
453 breakpoint inserted in the parent is visible in the
454 child, even those added while stopped in a vfork
455 catchpoint. This will remove the breakpoints from the
456 parent also, but they'll be reinserted below. */
459 /* Keep breakpoints list in sync. */
460 remove_breakpoints_inf (current_inferior ());
463 if (print_inferior_events
)
465 /* Ensure that we have a process ptid. */
466 ptid_t process_ptid
= ptid_t (child_ptid
.pid ());
468 target_terminal::ours_for_output ();
469 gdb_printf (_("[Detaching after %s from child %s]\n"),
470 has_vforked
? "vfork" : "fork",
471 target_pid_to_str (process_ptid
).c_str ());
476 /* Add process to GDB's tables. */
477 child_inf
= add_inferior (child_ptid
.pid ());
479 child_inf
->attach_flag
= parent_inf
->attach_flag
;
480 copy_terminal_info (child_inf
, parent_inf
);
481 child_inf
->gdbarch
= parent_inf
->gdbarch
;
482 child_inf
->tdesc_info
= parent_inf
->tdesc_info
;
484 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
486 /* If this is a vfork child, then the address-space is
487 shared with the parent. */
490 child_inf
->pspace
= parent_inf
->pspace
;
491 child_inf
->aspace
= parent_inf
->aspace
;
493 exec_on_vfork (child_inf
);
495 /* The parent will be frozen until the child is done
496 with the shared region. Keep track of the
498 child_inf
->vfork_parent
= parent_inf
;
499 child_inf
->pending_detach
= false;
500 parent_inf
->vfork_child
= child_inf
;
501 parent_inf
->pending_detach
= false;
505 child_inf
->aspace
= new address_space ();
506 child_inf
->pspace
= new program_space (child_inf
->aspace
);
507 child_inf
->removable
= true;
508 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
514 /* If we detached from the child, then we have to be careful
515 to not insert breakpoints in the parent until the child
516 is done with the shared memory region. However, if we're
517 staying attached to the child, then we can and should
518 insert breakpoints, so that we can debug it. A
519 subsequent child exec or exit is enough to know when does
520 the child stops using the parent's address space. */
521 parent_inf
->thread_waiting_for_vfork_done
522 = detach_fork
? inferior_thread () : nullptr;
523 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
528 /* Follow the child. */
530 if (print_inferior_events
)
532 std::string parent_pid
= target_pid_to_str (parent_ptid
);
533 std::string child_pid
= target_pid_to_str (child_ptid
);
535 target_terminal::ours_for_output ();
536 gdb_printf (_("[Attaching after %s %s to child %s]\n"),
538 has_vforked
? "vfork" : "fork",
542 /* Add the new inferior first, so that the target_detach below
543 doesn't unpush the target. */
545 child_inf
= add_inferior (child_ptid
.pid ());
547 child_inf
->attach_flag
= parent_inf
->attach_flag
;
548 copy_terminal_info (child_inf
, parent_inf
);
549 child_inf
->gdbarch
= parent_inf
->gdbarch
;
550 child_inf
->tdesc_info
= parent_inf
->tdesc_info
;
554 /* If this is a vfork child, then the address-space is shared
556 child_inf
->aspace
= parent_inf
->aspace
;
557 child_inf
->pspace
= parent_inf
->pspace
;
559 exec_on_vfork (child_inf
);
561 else if (detach_fork
)
563 /* We follow the child and detach from the parent: move the parent's
564 program space to the child. This simplifies some things, like
565 doing "next" over fork() and landing on the expected line in the
566 child (note, that is broken with "set detach-on-fork off").
568 Before assigning brand new spaces for the parent, remove
569 breakpoints from it: because the new pspace won't match
570 currently inserted locations, the normal detach procedure
571 wouldn't remove them, and we would leave them inserted when
573 remove_breakpoints_inf (parent_inf
);
575 child_inf
->aspace
= parent_inf
->aspace
;
576 child_inf
->pspace
= parent_inf
->pspace
;
577 parent_inf
->aspace
= new address_space ();
578 parent_inf
->pspace
= new program_space (parent_inf
->aspace
);
579 clone_program_space (parent_inf
->pspace
, child_inf
->pspace
);
581 /* The parent inferior is still the current one, so keep things
583 set_current_program_space (parent_inf
->pspace
);
587 child_inf
->aspace
= new address_space ();
588 child_inf
->pspace
= new program_space (child_inf
->aspace
);
589 child_inf
->removable
= true;
590 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
591 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
595 gdb_assert (current_inferior () == parent_inf
);
597 /* If we are setting up an inferior for the child, target_follow_fork is
598 responsible for pushing the appropriate targets on the new inferior's
599 target stack and adding the initial thread (with ptid CHILD_PTID).
601 If we are not setting up an inferior for the child (because following
602 the parent and detach_fork is true), it is responsible for detaching
604 target_follow_fork (child_inf
, child_ptid
, fork_kind
, follow_child
,
607 /* target_follow_fork must leave the parent as the current inferior. If we
608 want to follow the child, we make it the current one below. */
609 gdb_assert (current_inferior () == parent_inf
);
611 /* If there is a child inferior, target_follow_fork must have created a thread
613 if (child_inf
!= nullptr)
614 gdb_assert (!child_inf
->thread_list
.empty ());
616 /* Clear the parent thread's pending follow field. Do this before calling
617 target_detach, so that the target can differentiate the two following
620 - We continue past a fork with "follow-fork-mode == child" &&
621 "detach-on-fork on", and therefore detach the parent. In that
622 case the target should not detach the fork child.
623 - We run to a fork catchpoint and the user types "detach". In that
624 case, the target should detach the fork child in addition to the
627 The former case will have pending_follow cleared, the later will have
628 pending_follow set. */
629 thread_info
*parent_thread
= find_thread_ptid (parent_inf
, parent_ptid
);
630 gdb_assert (parent_thread
!= nullptr);
631 parent_thread
->pending_follow
.set_spurious ();
633 /* Detach the parent if needed. */
636 /* If we're vforking, we want to hold on to the parent until
637 the child exits or execs. At child exec or exit time we
638 can remove the old breakpoints from the parent and detach
639 or resume debugging it. Otherwise, detach the parent now;
640 we'll want to reuse it's program/address spaces, but we
641 can't set them to the child before removing breakpoints
642 from the parent, otherwise, the breakpoints module could
643 decide to remove breakpoints from the wrong process (since
644 they'd be assigned to the same address space). */
648 gdb_assert (child_inf
->vfork_parent
== nullptr);
649 gdb_assert (parent_inf
->vfork_child
== nullptr);
650 child_inf
->vfork_parent
= parent_inf
;
651 child_inf
->pending_detach
= false;
652 parent_inf
->vfork_child
= child_inf
;
653 parent_inf
->pending_detach
= detach_fork
;
655 else if (detach_fork
)
657 if (print_inferior_events
)
659 /* Ensure that we have a process ptid. */
660 ptid_t process_ptid
= ptid_t (parent_ptid
.pid ());
662 target_terminal::ours_for_output ();
663 gdb_printf (_("[Detaching after fork from "
665 target_pid_to_str (process_ptid
).c_str ());
668 target_detach (parent_inf
, 0);
672 /* If we ended up creating a new inferior, call post_create_inferior to inform
673 the various subcomponents. */
674 if (child_inf
!= nullptr)
676 /* If FOLLOW_CHILD, we leave CHILD_INF as the current inferior
677 (do not restore the parent as the current inferior). */
678 gdb::optional
<scoped_restore_current_thread
> maybe_restore
;
681 maybe_restore
.emplace ();
683 switch_to_thread (*child_inf
->threads ().begin ());
684 post_create_inferior (0);
690 /* Tell the target to follow the fork we're stopped at. Returns true
691 if the inferior should be resumed; false, if the target for some
692 reason decided it's best not to resume. */
697 bool follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
698 bool should_resume
= true;
700 /* Copy user stepping state to the new inferior thread. FIXME: the
701 followed fork child thread should have a copy of most of the
702 parent thread structure's run control related fields, not just these.
703 Initialized to avoid "may be used uninitialized" warnings from gcc. */
704 struct breakpoint
*step_resume_breakpoint
= nullptr;
705 struct breakpoint
*exception_resume_breakpoint
= nullptr;
706 CORE_ADDR step_range_start
= 0;
707 CORE_ADDR step_range_end
= 0;
708 int current_line
= 0;
709 symtab
*current_symtab
= nullptr;
710 struct frame_id step_frame_id
= { 0 };
714 process_stratum_target
*wait_target
;
716 struct target_waitstatus wait_status
;
718 /* Get the last target status returned by target_wait(). */
719 get_last_target_status (&wait_target
, &wait_ptid
, &wait_status
);
721 /* If not stopped at a fork event, then there's nothing else to
723 if (wait_status
.kind () != TARGET_WAITKIND_FORKED
724 && wait_status
.kind () != TARGET_WAITKIND_VFORKED
)
727 /* Check if we switched over from WAIT_PTID, since the event was
729 if (wait_ptid
!= minus_one_ptid
730 && (current_inferior ()->process_target () != wait_target
731 || inferior_ptid
!= wait_ptid
))
733 /* We did. Switch back to WAIT_PTID thread, to tell the
734 target to follow it (in either direction). We'll
735 afterwards refuse to resume, and inform the user what
737 thread_info
*wait_thread
= find_thread_ptid (wait_target
, wait_ptid
);
738 switch_to_thread (wait_thread
);
739 should_resume
= false;
743 thread_info
*tp
= inferior_thread ();
745 /* If there were any forks/vforks that were caught and are now to be
746 followed, then do so now. */
747 switch (tp
->pending_follow
.kind ())
749 case TARGET_WAITKIND_FORKED
:
750 case TARGET_WAITKIND_VFORKED
:
752 ptid_t parent
, child
;
753 std::unique_ptr
<struct thread_fsm
> thread_fsm
;
755 /* If the user did a next/step, etc, over a fork call,
756 preserve the stepping state in the fork child. */
757 if (follow_child
&& should_resume
)
759 step_resume_breakpoint
= clone_momentary_breakpoint
760 (tp
->control
.step_resume_breakpoint
);
761 step_range_start
= tp
->control
.step_range_start
;
762 step_range_end
= tp
->control
.step_range_end
;
763 current_line
= tp
->current_line
;
764 current_symtab
= tp
->current_symtab
;
765 step_frame_id
= tp
->control
.step_frame_id
;
766 exception_resume_breakpoint
767 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
768 thread_fsm
= tp
->release_thread_fsm ();
770 /* For now, delete the parent's sr breakpoint, otherwise,
771 parent/child sr breakpoints are considered duplicates,
772 and the child version will not be installed. Remove
773 this when the breakpoints module becomes aware of
774 inferiors and address spaces. */
775 delete_step_resume_breakpoint (tp
);
776 tp
->control
.step_range_start
= 0;
777 tp
->control
.step_range_end
= 0;
778 tp
->control
.step_frame_id
= null_frame_id
;
779 delete_exception_resume_breakpoint (tp
);
782 parent
= inferior_ptid
;
783 child
= tp
->pending_follow
.child_ptid ();
785 /* If handling a vfork, stop all the inferior's threads, they will be
786 restarted when the vfork shared region is complete. */
787 if (tp
->pending_follow
.kind () == TARGET_WAITKIND_VFORKED
788 && target_is_non_stop_p ())
789 stop_all_threads ("handling vfork", tp
->inf
);
791 process_stratum_target
*parent_targ
= tp
->inf
->process_target ();
792 /* Set up inferior(s) as specified by the caller, and tell the
793 target to do whatever is necessary to follow either parent
795 if (follow_fork_inferior (follow_child
, detach_fork
))
797 /* Target refused to follow, or there's some other reason
798 we shouldn't resume. */
803 /* This makes sure we don't try to apply the "Switched
804 over from WAIT_PID" logic above. */
805 nullify_last_target_wait_ptid ();
807 /* If we followed the child, switch to it... */
810 thread_info
*child_thr
= find_thread_ptid (parent_targ
, child
);
811 switch_to_thread (child_thr
);
813 /* ... and preserve the stepping state, in case the
814 user was stepping over the fork call. */
817 tp
= inferior_thread ();
818 tp
->control
.step_resume_breakpoint
819 = step_resume_breakpoint
;
820 tp
->control
.step_range_start
= step_range_start
;
821 tp
->control
.step_range_end
= step_range_end
;
822 tp
->current_line
= current_line
;
823 tp
->current_symtab
= current_symtab
;
824 tp
->control
.step_frame_id
= step_frame_id
;
825 tp
->control
.exception_resume_breakpoint
826 = exception_resume_breakpoint
;
827 tp
->set_thread_fsm (std::move (thread_fsm
));
831 /* If we get here, it was because we're trying to
832 resume from a fork catchpoint, but, the user
833 has switched threads away from the thread that
834 forked. In that case, the resume command
835 issued is most likely not applicable to the
836 child, so just warn, and refuse to resume. */
837 warning (_("Not resuming: switched threads "
838 "before following fork child."));
841 /* Reset breakpoints in the child as appropriate. */
842 follow_inferior_reset_breakpoints ();
847 case TARGET_WAITKIND_SPURIOUS
:
848 /* Nothing to follow. */
851 internal_error ("Unexpected pending_follow.kind %d\n",
852 tp
->pending_follow
.kind ());
856 return should_resume
;
860 follow_inferior_reset_breakpoints (void)
862 struct thread_info
*tp
= inferior_thread ();
864 /* Was there a step_resume breakpoint? (There was if the user
865 did a "next" at the fork() call.) If so, explicitly reset its
866 thread number. Cloned step_resume breakpoints are disabled on
867 creation, so enable it here now that it is associated with the
870 step_resumes are a form of bp that are made to be per-thread.
871 Since we created the step_resume bp when the parent process
872 was being debugged, and now are switching to the child process,
873 from the breakpoint package's viewpoint, that's a switch of
874 "threads". We must update the bp's notion of which thread
875 it is for, or it'll be ignored when it triggers. */
877 if (tp
->control
.step_resume_breakpoint
)
879 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
880 tp
->control
.step_resume_breakpoint
->loc
->enabled
= 1;
883 /* Treat exception_resume breakpoints like step_resume breakpoints. */
884 if (tp
->control
.exception_resume_breakpoint
)
886 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
887 tp
->control
.exception_resume_breakpoint
->loc
->enabled
= 1;
890 /* Reinsert all breakpoints in the child. The user may have set
891 breakpoints after catching the fork, in which case those
892 were never set in the child, but only in the parent. This makes
893 sure the inserted breakpoints match the breakpoint list. */
895 breakpoint_re_set ();
896 insert_breakpoints ();
899 /* The child has exited or execed: resume THREAD, a thread of the parent,
900 if it was meant to be executing. */
903 proceed_after_vfork_done (thread_info
*thread
)
905 if (thread
->state
== THREAD_RUNNING
906 && !thread
->executing ()
907 && !thread
->stop_requested
908 && thread
->stop_signal () == GDB_SIGNAL_0
)
910 infrun_debug_printf ("resuming vfork parent thread %s",
911 thread
->ptid
.to_string ().c_str ());
913 switch_to_thread (thread
);
914 clear_proceed_status (0);
915 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
919 /* Called whenever we notice an exec or exit event, to handle
920 detaching or resuming a vfork parent. */
923 handle_vfork_child_exec_or_exit (int exec
)
925 struct inferior
*inf
= current_inferior ();
927 if (inf
->vfork_parent
)
929 inferior
*resume_parent
= nullptr;
931 /* This exec or exit marks the end of the shared memory region
932 between the parent and the child. Break the bonds. */
933 inferior
*vfork_parent
= inf
->vfork_parent
;
934 inf
->vfork_parent
->vfork_child
= nullptr;
935 inf
->vfork_parent
= nullptr;
937 /* If the user wanted to detach from the parent, now is the
939 if (vfork_parent
->pending_detach
)
941 struct program_space
*pspace
;
942 struct address_space
*aspace
;
944 /* follow-fork child, detach-on-fork on. */
946 vfork_parent
->pending_detach
= false;
948 scoped_restore_current_pspace_and_thread restore_thread
;
950 /* We're letting loose of the parent. */
951 thread_info
*tp
= any_live_thread_of_inferior (vfork_parent
);
952 switch_to_thread (tp
);
954 /* We're about to detach from the parent, which implicitly
955 removes breakpoints from its address space. There's a
956 catch here: we want to reuse the spaces for the child,
957 but, parent/child are still sharing the pspace at this
958 point, although the exec in reality makes the kernel give
959 the child a fresh set of new pages. The problem here is
960 that the breakpoints module being unaware of this, would
961 likely chose the child process to write to the parent
962 address space. Swapping the child temporarily away from
963 the spaces has the desired effect. Yes, this is "sort
966 pspace
= inf
->pspace
;
967 aspace
= inf
->aspace
;
968 inf
->aspace
= nullptr;
969 inf
->pspace
= nullptr;
971 if (print_inferior_events
)
974 = target_pid_to_str (ptid_t (vfork_parent
->pid
));
976 target_terminal::ours_for_output ();
980 gdb_printf (_("[Detaching vfork parent %s "
981 "after child exec]\n"), pidstr
.c_str ());
985 gdb_printf (_("[Detaching vfork parent %s "
986 "after child exit]\n"), pidstr
.c_str ());
990 target_detach (vfork_parent
, 0);
993 inf
->pspace
= pspace
;
994 inf
->aspace
= aspace
;
998 /* We're staying attached to the parent, so, really give the
999 child a new address space. */
1000 inf
->pspace
= new program_space (maybe_new_address_space ());
1001 inf
->aspace
= inf
->pspace
->aspace
;
1002 inf
->removable
= true;
1003 set_current_program_space (inf
->pspace
);
1005 resume_parent
= vfork_parent
;
1009 /* If this is a vfork child exiting, then the pspace and
1010 aspaces were shared with the parent. Since we're
1011 reporting the process exit, we'll be mourning all that is
1012 found in the address space, and switching to null_ptid,
1013 preparing to start a new inferior. But, since we don't
1014 want to clobber the parent's address/program spaces, we
1015 go ahead and create a new one for this exiting
1018 /* Switch to no-thread while running clone_program_space, so
1019 that clone_program_space doesn't want to read the
1020 selected frame of a dead process. */
1021 scoped_restore_current_thread restore_thread
;
1022 switch_to_no_thread ();
1024 inf
->pspace
= new program_space (maybe_new_address_space ());
1025 inf
->aspace
= inf
->pspace
->aspace
;
1026 set_current_program_space (inf
->pspace
);
1027 inf
->removable
= true;
1028 inf
->symfile_flags
= SYMFILE_NO_READ
;
1029 clone_program_space (inf
->pspace
, vfork_parent
->pspace
);
1031 resume_parent
= vfork_parent
;
1034 gdb_assert (current_program_space
== inf
->pspace
);
1036 if (non_stop
&& resume_parent
!= nullptr)
1038 /* If the user wanted the parent to be running, let it go
1040 scoped_restore_current_thread restore_thread
;
1042 infrun_debug_printf ("resuming vfork parent process %d",
1043 resume_parent
->pid
);
1045 for (thread_info
*thread
: resume_parent
->threads ())
1046 proceed_after_vfork_done (thread
);
1051 /* Handle TARGET_WAITKIND_VFORK_DONE. */
1054 handle_vfork_done (thread_info
*event_thread
)
1056 /* We only care about this event if inferior::thread_waiting_for_vfork_done is
1057 set, that is if we are waiting for a vfork child not under our control
1058 (because we detached it) to exec or exit.
1060 If an inferior has vforked and we are debugging the child, we don't use
1061 the vfork-done event to get notified about the end of the shared address
1062 space window. We rely instead on the child's exec or exit event, and the
1063 inferior::vfork_{parent,child} fields are used instead. See
1064 handle_vfork_child_exec_or_exit for that. */
1065 if (event_thread
->inf
->thread_waiting_for_vfork_done
== nullptr)
1067 infrun_debug_printf ("not waiting for a vfork-done event");
1071 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1073 /* We stopped all threads (other than the vforking thread) of the inferior in
1074 follow_fork and kept them stopped until now. It should therefore not be
1075 possible for another thread to have reported a vfork during that window.
1076 If THREAD_WAITING_FOR_VFORK_DONE is set, it has to be the same thread whose
1077 vfork-done we are handling right now. */
1078 gdb_assert (event_thread
->inf
->thread_waiting_for_vfork_done
== event_thread
);
1080 event_thread
->inf
->thread_waiting_for_vfork_done
= nullptr;
1081 event_thread
->inf
->pspace
->breakpoints_not_allowed
= 0;
1083 /* On non-stop targets, we stopped all the inferior's threads in follow_fork,
1084 resume them now. On all-stop targets, everything that needs to be resumed
1085 will be when we resume the event thread. */
1086 if (target_is_non_stop_p ())
1088 /* restart_threads and start_step_over may change the current thread, make
1089 sure we leave the event thread as the current thread. */
1090 scoped_restore_current_thread restore_thread
;
1092 insert_breakpoints ();
1095 if (!step_over_info_valid_p ())
1096 restart_threads (event_thread
, event_thread
->inf
);
1100 /* Enum strings for "set|show follow-exec-mode". */
1102 static const char follow_exec_mode_new
[] = "new";
1103 static const char follow_exec_mode_same
[] = "same";
1104 static const char *const follow_exec_mode_names
[] =
1106 follow_exec_mode_new
,
1107 follow_exec_mode_same
,
1111 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1113 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1114 struct cmd_list_element
*c
, const char *value
)
1116 gdb_printf (file
, _("Follow exec mode is \"%s\".\n"), value
);
1119 /* EXEC_FILE_TARGET is assumed to be non-NULL. */
1122 follow_exec (ptid_t ptid
, const char *exec_file_target
)
1124 int pid
= ptid
.pid ();
1125 ptid_t process_ptid
;
1127 /* Switch terminal for any messages produced e.g. by
1128 breakpoint_re_set. */
1129 target_terminal::ours_for_output ();
1131 /* This is an exec event that we actually wish to pay attention to.
1132 Refresh our symbol table to the newly exec'd program, remove any
1133 momentary bp's, etc.
1135 If there are breakpoints, they aren't really inserted now,
1136 since the exec() transformed our inferior into a fresh set
1139 We want to preserve symbolic breakpoints on the list, since
1140 we have hopes that they can be reset after the new a.out's
1141 symbol table is read.
1143 However, any "raw" breakpoints must be removed from the list
1144 (e.g., the solib bp's), since their address is probably invalid
1147 And, we DON'T want to call delete_breakpoints() here, since
1148 that may write the bp's "shadow contents" (the instruction
1149 value that was overwritten with a TRAP instruction). Since
1150 we now have a new a.out, those shadow contents aren't valid. */
1152 mark_breakpoints_out ();
1154 /* The target reports the exec event to the main thread, even if
1155 some other thread does the exec, and even if the main thread was
1156 stopped or already gone. We may still have non-leader threads of
1157 the process on our list. E.g., on targets that don't have thread
1158 exit events (like remote); or on native Linux in non-stop mode if
1159 there were only two threads in the inferior and the non-leader
1160 one is the one that execs (and nothing forces an update of the
1161 thread list up to here). When debugging remotely, it's best to
1162 avoid extra traffic, when possible, so avoid syncing the thread
1163 list with the target, and instead go ahead and delete all threads
1164 of the process but one that reported the event. Note this must
1165 be done before calling update_breakpoints_after_exec, as
1166 otherwise clearing the threads' resources would reference stale
1167 thread breakpoints -- it may have been one of these threads that
1168 stepped across the exec. We could just clear their stepping
1169 states, but as long as we're iterating, might as well delete
1170 them. Deleting them now rather than at the next user-visible
1171 stop provides a nicer sequence of events for user and MI
1173 for (thread_info
*th
: all_threads_safe ())
1174 if (th
->ptid
.pid () == pid
&& th
->ptid
!= ptid
)
1177 /* We also need to clear any left over stale state for the
1178 leader/event thread. E.g., if there was any step-resume
1179 breakpoint or similar, it's gone now. We cannot truly
1180 step-to-next statement through an exec(). */
1181 thread_info
*th
= inferior_thread ();
1182 th
->control
.step_resume_breakpoint
= nullptr;
1183 th
->control
.exception_resume_breakpoint
= nullptr;
1184 th
->control
.single_step_breakpoints
= nullptr;
1185 th
->control
.step_range_start
= 0;
1186 th
->control
.step_range_end
= 0;
1188 /* The user may have had the main thread held stopped in the
1189 previous image (e.g., schedlock on, or non-stop). Release
1191 th
->stop_requested
= 0;
1193 update_breakpoints_after_exec ();
1195 /* What is this a.out's name? */
1196 process_ptid
= ptid_t (pid
);
1197 gdb_printf (_("%s is executing new program: %s\n"),
1198 target_pid_to_str (process_ptid
).c_str (),
1201 /* We've followed the inferior through an exec. Therefore, the
1202 inferior has essentially been killed & reborn. */
1204 breakpoint_init_inferior (inf_execd
);
1206 gdb::unique_xmalloc_ptr
<char> exec_file_host
1207 = exec_file_find (exec_file_target
, nullptr);
1209 /* If we were unable to map the executable target pathname onto a host
1210 pathname, tell the user that. Otherwise GDB's subsequent behavior
1211 is confusing. Maybe it would even be better to stop at this point
1212 so that the user can specify a file manually before continuing. */
1213 if (exec_file_host
== nullptr)
1214 warning (_("Could not load symbols for executable %s.\n"
1215 "Do you need \"set sysroot\"?"),
1218 /* Reset the shared library package. This ensures that we get a
1219 shlib event when the child reaches "_start", at which point the
1220 dld will have had a chance to initialize the child. */
1221 /* Also, loading a symbol file below may trigger symbol lookups, and
1222 we don't want those to be satisfied by the libraries of the
1223 previous incarnation of this process. */
1224 no_shared_libraries (nullptr, 0);
1226 struct inferior
*inf
= current_inferior ();
1228 if (follow_exec_mode_string
== follow_exec_mode_new
)
1230 /* The user wants to keep the old inferior and program spaces
1231 around. Create a new fresh one, and switch to it. */
1233 /* Do exit processing for the original inferior before setting the new
1234 inferior's pid. Having two inferiors with the same pid would confuse
1235 find_inferior_p(t)id. Transfer the terminal state and info from the
1236 old to the new inferior. */
1237 inferior
*new_inferior
= add_inferior_with_spaces ();
1239 swap_terminal_info (new_inferior
, inf
);
1240 exit_inferior_silent (inf
);
1242 new_inferior
->pid
= pid
;
1243 target_follow_exec (new_inferior
, ptid
, exec_file_target
);
1245 /* We continue with the new inferior. */
1250 /* The old description may no longer be fit for the new image.
1251 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1252 old description; we'll read a new one below. No need to do
1253 this on "follow-exec-mode new", as the old inferior stays
1254 around (its description is later cleared/refetched on
1256 target_clear_description ();
1257 target_follow_exec (inf
, ptid
, exec_file_target
);
1260 gdb_assert (current_inferior () == inf
);
1261 gdb_assert (current_program_space
== inf
->pspace
);
1263 /* Attempt to open the exec file. SYMFILE_DEFER_BP_RESET is used
1264 because the proper displacement for a PIE (Position Independent
1265 Executable) main symbol file will only be computed by
1266 solib_create_inferior_hook below. breakpoint_re_set would fail
1267 to insert the breakpoints with the zero displacement. */
1268 try_open_exec_file (exec_file_host
.get (), inf
, SYMFILE_DEFER_BP_RESET
);
1270 /* If the target can specify a description, read it. Must do this
1271 after flipping to the new executable (because the target supplied
1272 description must be compatible with the executable's
1273 architecture, and the old executable may e.g., be 32-bit, while
1274 the new one 64-bit), and before anything involving memory or
1276 target_find_description ();
1278 gdb::observers::inferior_execd
.notify (inf
);
1280 breakpoint_re_set ();
1282 /* Reinsert all breakpoints. (Those which were symbolic have
1283 been reset to the proper address in the new a.out, thanks
1284 to symbol_file_command...). */
1285 insert_breakpoints ();
1287 /* The next resume of this inferior should bring it to the shlib
1288 startup breakpoints. (If the user had also set bp's on
1289 "main" from the old (parent) process, then they'll auto-
1290 matically get reset there in the new process.). */
1293 /* The chain of threads that need to do a step-over operation to get
1294 past e.g., a breakpoint. What technique is used to step over the
1295 breakpoint/watchpoint does not matter -- all threads end up in the
1296 same queue, to maintain rough temporal order of execution, in order
1297 to avoid starvation, otherwise, we could e.g., find ourselves
1298 constantly stepping the same couple threads past their breakpoints
1299 over and over, if the single-step finish fast enough. */
1300 thread_step_over_list global_thread_step_over_list
;
1302 /* Bit flags indicating what the thread needs to step over. */
1304 enum step_over_what_flag
1306 /* Step over a breakpoint. */
1307 STEP_OVER_BREAKPOINT
= 1,
1309 /* Step past a non-continuable watchpoint, in order to let the
1310 instruction execute so we can evaluate the watchpoint
1312 STEP_OVER_WATCHPOINT
= 2
1314 DEF_ENUM_FLAGS_TYPE (enum step_over_what_flag
, step_over_what
);
1316 /* Info about an instruction that is being stepped over. */
1318 struct step_over_info
1320 /* If we're stepping past a breakpoint, this is the address space
1321 and address of the instruction the breakpoint is set at. We'll
1322 skip inserting all breakpoints here. Valid iff ASPACE is
1324 const address_space
*aspace
= nullptr;
1325 CORE_ADDR address
= 0;
1327 /* The instruction being stepped over triggers a nonsteppable
1328 watchpoint. If true, we'll skip inserting watchpoints. */
1329 int nonsteppable_watchpoint_p
= 0;
1331 /* The thread's global number. */
1335 /* The step-over info of the location that is being stepped over.
1337 Note that with async/breakpoint always-inserted mode, a user might
1338 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1339 being stepped over. As setting a new breakpoint inserts all
1340 breakpoints, we need to make sure the breakpoint being stepped over
1341 isn't inserted then. We do that by only clearing the step-over
1342 info when the step-over is actually finished (or aborted).
1344 Presently GDB can only step over one breakpoint at any given time.
1345 Given threads that can't run code in the same address space as the
1346 breakpoint's can't really miss the breakpoint, GDB could be taught
1347 to step-over at most one breakpoint per address space (so this info
1348 could move to the address space object if/when GDB is extended).
1349 The set of breakpoints being stepped over will normally be much
1350 smaller than the set of all breakpoints, so a flag in the
1351 breakpoint location structure would be wasteful. A separate list
1352 also saves complexity and run-time, as otherwise we'd have to go
1353 through all breakpoint locations clearing their flag whenever we
1354 start a new sequence. Similar considerations weigh against storing
1355 this info in the thread object. Plus, not all step overs actually
1356 have breakpoint locations -- e.g., stepping past a single-step
1357 breakpoint, or stepping to complete a non-continuable
1359 static struct step_over_info step_over_info
;
1361 /* Record the address of the breakpoint/instruction we're currently
1363 N.B. We record the aspace and address now, instead of say just the thread,
1364 because when we need the info later the thread may be running. */
1367 set_step_over_info (const address_space
*aspace
, CORE_ADDR address
,
1368 int nonsteppable_watchpoint_p
,
1371 step_over_info
.aspace
= aspace
;
1372 step_over_info
.address
= address
;
1373 step_over_info
.nonsteppable_watchpoint_p
= nonsteppable_watchpoint_p
;
1374 step_over_info
.thread
= thread
;
1377 /* Called when we're not longer stepping over a breakpoint / an
1378 instruction, so all breakpoints are free to be (re)inserted. */
1381 clear_step_over_info (void)
1383 infrun_debug_printf ("clearing step over info");
1384 step_over_info
.aspace
= nullptr;
1385 step_over_info
.address
= 0;
1386 step_over_info
.nonsteppable_watchpoint_p
= 0;
1387 step_over_info
.thread
= -1;
1393 stepping_past_instruction_at (struct address_space
*aspace
,
1396 return (step_over_info
.aspace
!= nullptr
1397 && breakpoint_address_match (aspace
, address
,
1398 step_over_info
.aspace
,
1399 step_over_info
.address
));
1405 thread_is_stepping_over_breakpoint (int thread
)
1407 return (step_over_info
.thread
!= -1
1408 && thread
== step_over_info
.thread
);
1414 stepping_past_nonsteppable_watchpoint (void)
1416 return step_over_info
.nonsteppable_watchpoint_p
;
1419 /* Returns true if step-over info is valid. */
1422 step_over_info_valid_p (void)
1424 return (step_over_info
.aspace
!= nullptr
1425 || stepping_past_nonsteppable_watchpoint ());
1429 /* Displaced stepping. */
1431 /* In non-stop debugging mode, we must take special care to manage
1432 breakpoints properly; in particular, the traditional strategy for
1433 stepping a thread past a breakpoint it has hit is unsuitable.
1434 'Displaced stepping' is a tactic for stepping one thread past a
1435 breakpoint it has hit while ensuring that other threads running
1436 concurrently will hit the breakpoint as they should.
1438 The traditional way to step a thread T off a breakpoint in a
1439 multi-threaded program in all-stop mode is as follows:
1441 a0) Initially, all threads are stopped, and breakpoints are not
1443 a1) We single-step T, leaving breakpoints uninserted.
1444 a2) We insert breakpoints, and resume all threads.
1446 In non-stop debugging, however, this strategy is unsuitable: we
1447 don't want to have to stop all threads in the system in order to
1448 continue or step T past a breakpoint. Instead, we use displaced
1451 n0) Initially, T is stopped, other threads are running, and
1452 breakpoints are inserted.
1453 n1) We copy the instruction "under" the breakpoint to a separate
1454 location, outside the main code stream, making any adjustments
1455 to the instruction, register, and memory state as directed by
1457 n2) We single-step T over the instruction at its new location.
1458 n3) We adjust the resulting register and memory state as directed
1459 by T's architecture. This includes resetting T's PC to point
1460 back into the main instruction stream.
1463 This approach depends on the following gdbarch methods:
1465 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1466 indicate where to copy the instruction, and how much space must
1467 be reserved there. We use these in step n1.
1469 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1470 address, and makes any necessary adjustments to the instruction,
1471 register contents, and memory. We use this in step n1.
1473 - gdbarch_displaced_step_fixup adjusts registers and memory after
1474 we have successfully single-stepped the instruction, to yield the
1475 same effect the instruction would have had if we had executed it
1476 at its original address. We use this in step n3.
1478 The gdbarch_displaced_step_copy_insn and
1479 gdbarch_displaced_step_fixup functions must be written so that
1480 copying an instruction with gdbarch_displaced_step_copy_insn,
1481 single-stepping across the copied instruction, and then applying
1482 gdbarch_displaced_insn_fixup should have the same effects on the
1483 thread's memory and registers as stepping the instruction in place
1484 would have. Exactly which responsibilities fall to the copy and
1485 which fall to the fixup is up to the author of those functions.
1487 See the comments in gdbarch.sh for details.
1489 Note that displaced stepping and software single-step cannot
1490 currently be used in combination, although with some care I think
1491 they could be made to. Software single-step works by placing
1492 breakpoints on all possible subsequent instructions; if the
1493 displaced instruction is a PC-relative jump, those breakpoints
1494 could fall in very strange places --- on pages that aren't
1495 executable, or at addresses that are not proper instruction
1496 boundaries. (We do generally let other threads run while we wait
1497 to hit the software single-step breakpoint, and they might
1498 encounter such a corrupted instruction.) One way to work around
1499 this would be to have gdbarch_displaced_step_copy_insn fully
1500 simulate the effect of PC-relative instructions (and return NULL)
1501 on architectures that use software single-stepping.
1503 In non-stop mode, we can have independent and simultaneous step
1504 requests, so more than one thread may need to simultaneously step
1505 over a breakpoint. The current implementation assumes there is
1506 only one scratch space per process. In this case, we have to
1507 serialize access to the scratch space. If thread A wants to step
1508 over a breakpoint, but we are currently waiting for some other
1509 thread to complete a displaced step, we leave thread A stopped and
1510 place it in the displaced_step_request_queue. Whenever a displaced
1511 step finishes, we pick the next thread in the queue and start a new
1512 displaced step operation on it. See displaced_step_prepare and
1513 displaced_step_finish for details. */
1515 /* Return true if THREAD is doing a displaced step. */
1518 displaced_step_in_progress_thread (thread_info
*thread
)
1520 gdb_assert (thread
!= nullptr);
1522 return thread
->displaced_step_state
.in_progress ();
1525 /* Return true if INF has a thread doing a displaced step. */
1528 displaced_step_in_progress (inferior
*inf
)
1530 return inf
->displaced_step_state
.in_progress_count
> 0;
1533 /* Return true if any thread is doing a displaced step. */
1536 displaced_step_in_progress_any_thread ()
1538 for (inferior
*inf
: all_non_exited_inferiors ())
1540 if (displaced_step_in_progress (inf
))
1548 infrun_inferior_exit (struct inferior
*inf
)
1550 inf
->displaced_step_state
.reset ();
1551 inf
->thread_waiting_for_vfork_done
= nullptr;
1555 infrun_inferior_execd (inferior
*inf
)
1557 /* If some threads where was doing a displaced step in this inferior at the
1558 moment of the exec, they no longer exist. Even if the exec'ing thread
1559 doing a displaced step, we don't want to to any fixup nor restore displaced
1560 stepping buffer bytes. */
1561 inf
->displaced_step_state
.reset ();
1563 for (thread_info
*thread
: inf
->threads ())
1564 thread
->displaced_step_state
.reset ();
1566 /* Since an in-line step is done with everything else stopped, if there was
1567 one in progress at the time of the exec, it must have been the exec'ing
1569 clear_step_over_info ();
1571 inf
->thread_waiting_for_vfork_done
= nullptr;
1574 /* If ON, and the architecture supports it, GDB will use displaced
1575 stepping to step over breakpoints. If OFF, or if the architecture
1576 doesn't support it, GDB will instead use the traditional
1577 hold-and-step approach. If AUTO (which is the default), GDB will
1578 decide which technique to use to step over breakpoints depending on
1579 whether the target works in a non-stop way (see use_displaced_stepping). */
1581 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1584 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1585 struct cmd_list_element
*c
,
1588 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1590 _("Debugger's willingness to use displaced stepping "
1591 "to step over breakpoints is %s (currently %s).\n"),
1592 value
, target_is_non_stop_p () ? "on" : "off");
1595 _("Debugger's willingness to use displaced stepping "
1596 "to step over breakpoints is %s.\n"), value
);
1599 /* Return true if the gdbarch implements the required methods to use
1600 displaced stepping. */
1603 gdbarch_supports_displaced_stepping (gdbarch
*arch
)
1605 /* Only check for the presence of `prepare`. The gdbarch verification ensures
1606 that if `prepare` is provided, so is `finish`. */
1607 return gdbarch_displaced_step_prepare_p (arch
);
1610 /* Return non-zero if displaced stepping can/should be used to step
1611 over breakpoints of thread TP. */
1614 use_displaced_stepping (thread_info
*tp
)
1616 /* If the user disabled it explicitly, don't use displaced stepping. */
1617 if (can_use_displaced_stepping
== AUTO_BOOLEAN_FALSE
)
1620 /* If "auto", only use displaced stepping if the target operates in a non-stop
1622 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
1623 && !target_is_non_stop_p ())
1626 gdbarch
*gdbarch
= get_thread_regcache (tp
)->arch ();
1628 /* If the architecture doesn't implement displaced stepping, don't use
1630 if (!gdbarch_supports_displaced_stepping (gdbarch
))
1633 /* If recording, don't use displaced stepping. */
1634 if (find_record_target () != nullptr)
1637 /* If displaced stepping failed before for this inferior, don't bother trying
1639 if (tp
->inf
->displaced_step_state
.failed_before
)
1645 /* Simple function wrapper around displaced_step_thread_state::reset. */
1648 displaced_step_reset (displaced_step_thread_state
*displaced
)
1650 displaced
->reset ();
1653 /* A cleanup that wraps displaced_step_reset. We use this instead of, say,
1654 SCOPE_EXIT, because it needs to be discardable with "cleanup.release ()". */
1656 using displaced_step_reset_cleanup
= FORWARD_SCOPE_EXIT (displaced_step_reset
);
1661 displaced_step_dump_bytes (const gdb_byte
*buf
, size_t len
)
1665 for (size_t i
= 0; i
< len
; i
++)
1668 ret
+= string_printf ("%02x", buf
[i
]);
1670 ret
+= string_printf (" %02x", buf
[i
]);
1676 /* Prepare to single-step, using displaced stepping.
1678 Note that we cannot use displaced stepping when we have a signal to
1679 deliver. If we have a signal to deliver and an instruction to step
1680 over, then after the step, there will be no indication from the
1681 target whether the thread entered a signal handler or ignored the
1682 signal and stepped over the instruction successfully --- both cases
1683 result in a simple SIGTRAP. In the first case we mustn't do a
1684 fixup, and in the second case we must --- but we can't tell which.
1685 Comments in the code for 'random signals' in handle_inferior_event
1686 explain how we handle this case instead.
1688 Returns DISPLACED_STEP_PREPARE_STATUS_OK if preparing was successful -- this
1689 thread is going to be stepped now; DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
1690 if displaced stepping this thread got queued; or
1691 DISPLACED_STEP_PREPARE_STATUS_CANT if this instruction can't be displaced
1694 static displaced_step_prepare_status
1695 displaced_step_prepare_throw (thread_info
*tp
)
1697 regcache
*regcache
= get_thread_regcache (tp
);
1698 struct gdbarch
*gdbarch
= regcache
->arch ();
1699 displaced_step_thread_state
&disp_step_thread_state
1700 = tp
->displaced_step_state
;
1702 /* We should never reach this function if the architecture does not
1703 support displaced stepping. */
1704 gdb_assert (gdbarch_supports_displaced_stepping (gdbarch
));
1706 /* Nor if the thread isn't meant to step over a breakpoint. */
1707 gdb_assert (tp
->control
.trap_expected
);
1709 /* Disable range stepping while executing in the scratch pad. We
1710 want a single-step even if executing the displaced instruction in
1711 the scratch buffer lands within the stepping range (e.g., a
1713 tp
->control
.may_range_step
= 0;
1715 /* We are about to start a displaced step for this thread. If one is already
1716 in progress, something's wrong. */
1717 gdb_assert (!disp_step_thread_state
.in_progress ());
1719 if (tp
->inf
->displaced_step_state
.unavailable
)
1721 /* The gdbarch tells us it's not worth asking to try a prepare because
1722 it is likely that it will return unavailable, so don't bother asking. */
1724 displaced_debug_printf ("deferring step of %s",
1725 tp
->ptid
.to_string ().c_str ());
1727 global_thread_step_over_chain_enqueue (tp
);
1728 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1731 displaced_debug_printf ("displaced-stepping %s now",
1732 tp
->ptid
.to_string ().c_str ());
1734 scoped_restore_current_thread restore_thread
;
1736 switch_to_thread (tp
);
1738 CORE_ADDR original_pc
= regcache_read_pc (regcache
);
1739 CORE_ADDR displaced_pc
;
1741 displaced_step_prepare_status status
1742 = gdbarch_displaced_step_prepare (gdbarch
, tp
, displaced_pc
);
1744 if (status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
1746 displaced_debug_printf ("failed to prepare (%s)",
1747 tp
->ptid
.to_string ().c_str ());
1749 return DISPLACED_STEP_PREPARE_STATUS_CANT
;
1751 else if (status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
1753 /* Not enough displaced stepping resources available, defer this
1754 request by placing it the queue. */
1756 displaced_debug_printf ("not enough resources available, "
1757 "deferring step of %s",
1758 tp
->ptid
.to_string ().c_str ());
1760 global_thread_step_over_chain_enqueue (tp
);
1762 return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
;
1765 gdb_assert (status
== DISPLACED_STEP_PREPARE_STATUS_OK
);
1767 /* Save the information we need to fix things up if the step
1769 disp_step_thread_state
.set (gdbarch
);
1771 tp
->inf
->displaced_step_state
.in_progress_count
++;
1773 displaced_debug_printf ("prepared successfully thread=%s, "
1774 "original_pc=%s, displaced_pc=%s",
1775 tp
->ptid
.to_string ().c_str (),
1776 paddress (gdbarch
, original_pc
),
1777 paddress (gdbarch
, displaced_pc
));
1779 return DISPLACED_STEP_PREPARE_STATUS_OK
;
1782 /* Wrapper for displaced_step_prepare_throw that disabled further
1783 attempts at displaced stepping if we get a memory error. */
1785 static displaced_step_prepare_status
1786 displaced_step_prepare (thread_info
*thread
)
1788 displaced_step_prepare_status status
1789 = DISPLACED_STEP_PREPARE_STATUS_CANT
;
1793 status
= displaced_step_prepare_throw (thread
);
1795 catch (const gdb_exception_error
&ex
)
1797 if (ex
.error
!= MEMORY_ERROR
1798 && ex
.error
!= NOT_SUPPORTED_ERROR
)
1801 infrun_debug_printf ("caught exception, disabling displaced stepping: %s",
1804 /* Be verbose if "set displaced-stepping" is "on", silent if
1806 if (can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1808 warning (_("disabling displaced stepping: %s"),
1812 /* Disable further displaced stepping attempts. */
1813 thread
->inf
->displaced_step_state
.failed_before
= 1;
1819 /* If we displaced stepped an instruction successfully, adjust registers and
1820 memory to yield the same effect the instruction would have had if we had
1821 executed it at its original address, and return
1822 DISPLACED_STEP_FINISH_STATUS_OK. If the instruction didn't complete,
1823 relocate the PC and return DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED.
1825 If the thread wasn't displaced stepping, return
1826 DISPLACED_STEP_FINISH_STATUS_OK as well. */
1828 static displaced_step_finish_status
1829 displaced_step_finish (thread_info
*event_thread
, enum gdb_signal signal
)
1831 displaced_step_thread_state
*displaced
= &event_thread
->displaced_step_state
;
1833 /* Was this thread performing a displaced step? */
1834 if (!displaced
->in_progress ())
1835 return DISPLACED_STEP_FINISH_STATUS_OK
;
1837 gdb_assert (event_thread
->inf
->displaced_step_state
.in_progress_count
> 0);
1838 event_thread
->inf
->displaced_step_state
.in_progress_count
--;
1840 /* Fixup may need to read memory/registers. Switch to the thread
1841 that we're fixing up. Also, target_stopped_by_watchpoint checks
1842 the current thread, and displaced_step_restore performs ptid-dependent
1843 memory accesses using current_inferior(). */
1844 switch_to_thread (event_thread
);
1846 displaced_step_reset_cleanup
cleanup (displaced
);
1848 /* Do the fixup, and release the resources acquired to do the displaced
1850 return gdbarch_displaced_step_finish (displaced
->get_original_gdbarch (),
1851 event_thread
, signal
);
1854 /* Data to be passed around while handling an event. This data is
1855 discarded between events. */
1856 struct execution_control_state
1858 explicit execution_control_state (thread_info
*thr
= nullptr)
1859 : ptid (thr
== nullptr ? null_ptid
: thr
->ptid
),
1864 process_stratum_target
*target
= nullptr;
1866 /* The thread that got the event, if this was a thread event; NULL
1868 struct thread_info
*event_thread
;
1870 struct target_waitstatus ws
;
1871 int stop_func_filled_in
= 0;
1872 CORE_ADDR stop_func_start
= 0;
1873 CORE_ADDR stop_func_end
= 0;
1874 const char *stop_func_name
= nullptr;
1875 int wait_some_more
= 0;
1877 /* True if the event thread hit the single-step breakpoint of
1878 another thread. Thus the event doesn't cause a stop, the thread
1879 needs to be single-stepped past the single-step breakpoint before
1880 we can switch back to the original stepping thread. */
1881 int hit_singlestep_breakpoint
= 0;
1884 static void keep_going_pass_signal (struct execution_control_state
*ecs
);
1885 static void prepare_to_wait (struct execution_control_state
*ecs
);
1886 static bool keep_going_stepped_thread (struct thread_info
*tp
);
1887 static step_over_what
thread_still_needs_step_over (struct thread_info
*tp
);
1889 /* Are there any pending step-over requests? If so, run all we can
1890 now and return true. Otherwise, return false. */
1893 start_step_over (void)
1895 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
1897 /* Don't start a new step-over if we already have an in-line
1898 step-over operation ongoing. */
1899 if (step_over_info_valid_p ())
1902 /* Steal the global thread step over chain. As we try to initiate displaced
1903 steps, threads will be enqueued in the global chain if no buffers are
1904 available. If we iterated on the global chain directly, we might iterate
1906 thread_step_over_list threads_to_step
1907 = std::move (global_thread_step_over_list
);
1909 infrun_debug_printf ("stealing global queue of threads to step, length = %d",
1910 thread_step_over_chain_length (threads_to_step
));
1912 bool started
= false;
1914 /* On scope exit (whatever the reason, return or exception), if there are
1915 threads left in the THREADS_TO_STEP chain, put back these threads in the
1919 if (threads_to_step
.empty ())
1920 infrun_debug_printf ("step-over queue now empty");
1923 infrun_debug_printf ("putting back %d threads to step in global queue",
1924 thread_step_over_chain_length (threads_to_step
));
1926 global_thread_step_over_chain_enqueue_chain
1927 (std::move (threads_to_step
));
1931 thread_step_over_list_safe_range range
1932 = make_thread_step_over_list_safe_range (threads_to_step
);
1934 for (thread_info
*tp
: range
)
1936 step_over_what step_what
;
1937 int must_be_in_line
;
1939 gdb_assert (!tp
->stop_requested
);
1941 if (tp
->inf
->displaced_step_state
.unavailable
)
1943 /* The arch told us to not even try preparing another displaced step
1944 for this inferior. Just leave the thread in THREADS_TO_STEP, it
1945 will get moved to the global chain on scope exit. */
1949 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr)
1951 /* When we stop all threads, handling a vfork, any thread in the step
1952 over chain remains there. A user could also try to continue a
1953 thread stopped at a breakpoint while another thread is waiting for
1954 a vfork-done event. In any case, we don't want to start a step
1959 /* Remove thread from the THREADS_TO_STEP chain. If anything goes wrong
1960 while we try to prepare the displaced step, we don't add it back to
1961 the global step over chain. This is to avoid a thread staying in the
1962 step over chain indefinitely if something goes wrong when resuming it
1963 If the error is intermittent and it still needs a step over, it will
1964 get enqueued again when we try to resume it normally. */
1965 threads_to_step
.erase (threads_to_step
.iterator_to (*tp
));
1967 step_what
= thread_still_needs_step_over (tp
);
1968 must_be_in_line
= ((step_what
& STEP_OVER_WATCHPOINT
)
1969 || ((step_what
& STEP_OVER_BREAKPOINT
)
1970 && !use_displaced_stepping (tp
)));
1972 /* We currently stop all threads of all processes to step-over
1973 in-line. If we need to start a new in-line step-over, let
1974 any pending displaced steps finish first. */
1975 if (must_be_in_line
&& displaced_step_in_progress_any_thread ())
1977 global_thread_step_over_chain_enqueue (tp
);
1981 if (tp
->control
.trap_expected
1983 || tp
->executing ())
1985 internal_error ("[%s] has inconsistent state: "
1986 "trap_expected=%d, resumed=%d, executing=%d\n",
1987 tp
->ptid
.to_string ().c_str (),
1988 tp
->control
.trap_expected
,
1993 infrun_debug_printf ("resuming [%s] for step-over",
1994 tp
->ptid
.to_string ().c_str ());
1996 /* keep_going_pass_signal skips the step-over if the breakpoint
1997 is no longer inserted. In all-stop, we want to keep looking
1998 for a thread that needs a step-over instead of resuming TP,
1999 because we wouldn't be able to resume anything else until the
2000 target stops again. In non-stop, the resume always resumes
2001 only TP, so it's OK to let the thread resume freely. */
2002 if (!target_is_non_stop_p () && !step_what
)
2005 switch_to_thread (tp
);
2006 execution_control_state
ecs (tp
);
2007 keep_going_pass_signal (&ecs
);
2009 if (!ecs
.wait_some_more
)
2010 error (_("Command aborted."));
2012 /* If the thread's step over could not be initiated because no buffers
2013 were available, it was re-added to the global step over chain. */
2016 infrun_debug_printf ("[%s] was resumed.",
2017 tp
->ptid
.to_string ().c_str ());
2018 gdb_assert (!thread_is_in_step_over_chain (tp
));
2022 infrun_debug_printf ("[%s] was NOT resumed.",
2023 tp
->ptid
.to_string ().c_str ());
2024 gdb_assert (thread_is_in_step_over_chain (tp
));
2027 /* If we started a new in-line step-over, we're done. */
2028 if (step_over_info_valid_p ())
2030 gdb_assert (tp
->control
.trap_expected
);
2035 if (!target_is_non_stop_p ())
2037 /* On all-stop, shouldn't have resumed unless we needed a
2039 gdb_assert (tp
->control
.trap_expected
2040 || tp
->step_after_step_resume_breakpoint
);
2042 /* With remote targets (at least), in all-stop, we can't
2043 issue any further remote commands until the program stops
2049 /* Either the thread no longer needed a step-over, or a new
2050 displaced stepping sequence started. Even in the latter
2051 case, continue looking. Maybe we can also start another
2052 displaced step on a thread of other process. */
2058 /* Update global variables holding ptids to hold NEW_PTID if they were
2059 holding OLD_PTID. */
2061 infrun_thread_ptid_changed (process_stratum_target
*target
,
2062 ptid_t old_ptid
, ptid_t new_ptid
)
2064 if (inferior_ptid
== old_ptid
2065 && current_inferior ()->process_target () == target
)
2066 inferior_ptid
= new_ptid
;
2071 static const char schedlock_off
[] = "off";
2072 static const char schedlock_on
[] = "on";
2073 static const char schedlock_step
[] = "step";
2074 static const char schedlock_replay
[] = "replay";
2075 static const char *const scheduler_enums
[] = {
2082 static const char *scheduler_mode
= schedlock_replay
;
2084 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
2085 struct cmd_list_element
*c
, const char *value
)
2088 _("Mode for locking scheduler "
2089 "during execution is \"%s\".\n"),
2094 set_schedlock_func (const char *args
, int from_tty
, struct cmd_list_element
*c
)
2096 if (!target_can_lock_scheduler ())
2098 scheduler_mode
= schedlock_off
;
2099 error (_("Target '%s' cannot support this command."),
2100 target_shortname ());
2104 /* True if execution commands resume all threads of all processes by
2105 default; otherwise, resume only threads of the current inferior
2107 bool sched_multi
= false;
2109 /* Try to setup for software single stepping. Return true if target_resume()
2110 should use hardware single step.
2112 GDBARCH the current gdbarch. */
2115 maybe_software_singlestep (struct gdbarch
*gdbarch
)
2117 bool hw_step
= true;
2119 if (execution_direction
== EXEC_FORWARD
2120 && gdbarch_software_single_step_p (gdbarch
))
2121 hw_step
= !insert_single_step_breakpoints (gdbarch
);
2129 user_visible_resume_ptid (int step
)
2135 /* With non-stop mode on, threads are always handled
2137 resume_ptid
= inferior_ptid
;
2139 else if ((scheduler_mode
== schedlock_on
)
2140 || (scheduler_mode
== schedlock_step
&& step
))
2142 /* User-settable 'scheduler' mode requires solo thread
2144 resume_ptid
= inferior_ptid
;
2146 else if ((scheduler_mode
== schedlock_replay
)
2147 && target_record_will_replay (minus_one_ptid
, execution_direction
))
2149 /* User-settable 'scheduler' mode requires solo thread resume in replay
2151 resume_ptid
= inferior_ptid
;
2153 else if (!sched_multi
&& target_supports_multi_process ())
2155 /* Resume all threads of the current process (and none of other
2157 resume_ptid
= ptid_t (inferior_ptid
.pid ());
2161 /* Resume all threads of all processes. */
2162 resume_ptid
= RESUME_ALL
;
2170 process_stratum_target
*
2171 user_visible_resume_target (ptid_t resume_ptid
)
2173 return (resume_ptid
== minus_one_ptid
&& sched_multi
2175 : current_inferior ()->process_target ());
2178 /* Return a ptid representing the set of threads that we will resume,
2179 in the perspective of the target, assuming run control handling
2180 does not require leaving some threads stopped (e.g., stepping past
2181 breakpoint). USER_STEP indicates whether we're about to start the
2182 target for a stepping command. */
2185 internal_resume_ptid (int user_step
)
2187 /* In non-stop, we always control threads individually. Note that
2188 the target may always work in non-stop mode even with "set
2189 non-stop off", in which case user_visible_resume_ptid could
2190 return a wildcard ptid. */
2191 if (target_is_non_stop_p ())
2192 return inferior_ptid
;
2194 /* The rest of the function assumes non-stop==off and
2195 target-non-stop==off.
2197 If a thread is waiting for a vfork-done event, it means breakpoints are out
2198 for this inferior (well, program space in fact). We don't want to resume
2199 any thread other than the one waiting for vfork done, otherwise these other
2200 threads could miss breakpoints. So if a thread in the resumption set is
2201 waiting for a vfork-done event, resume only that thread.
2203 The resumption set width depends on whether schedule-multiple is on or off.
2205 Note that if the target_resume interface was more flexible, we could be
2206 smarter here when schedule-multiple is on. For example, imagine 3
2207 inferiors with 2 threads each (1.1, 1.2, 2.1, 2.2, 3.1 and 3.2). Threads
2208 2.1 and 3.2 are both waiting for a vfork-done event. Then we could ask the
2209 target(s) to resume:
2211 - All threads of inferior 1
2215 Since we don't have that flexibility (we can only pass one ptid), just
2216 resume the first thread waiting for a vfork-done event we find (e.g. thread
2220 for (inferior
*inf
: all_non_exited_inferiors ())
2221 if (inf
->thread_waiting_for_vfork_done
!= nullptr)
2222 return inf
->thread_waiting_for_vfork_done
->ptid
;
2224 else if (current_inferior ()->thread_waiting_for_vfork_done
!= nullptr)
2225 return current_inferior ()->thread_waiting_for_vfork_done
->ptid
;
2227 return user_visible_resume_ptid (user_step
);
2230 /* Wrapper for target_resume, that handles infrun-specific
2234 do_target_resume (ptid_t resume_ptid
, bool step
, enum gdb_signal sig
)
2236 struct thread_info
*tp
= inferior_thread ();
2238 gdb_assert (!tp
->stop_requested
);
2240 /* Install inferior's terminal modes. */
2241 target_terminal::inferior ();
2243 /* Avoid confusing the next resume, if the next stop/resume
2244 happens to apply to another thread. */
2245 tp
->set_stop_signal (GDB_SIGNAL_0
);
2247 /* Advise target which signals may be handled silently.
2249 If we have removed breakpoints because we are stepping over one
2250 in-line (in any thread), we need to receive all signals to avoid
2251 accidentally skipping a breakpoint during execution of a signal
2254 Likewise if we're displaced stepping, otherwise a trap for a
2255 breakpoint in a signal handler might be confused with the
2256 displaced step finishing. We don't make the displaced_step_finish
2257 step distinguish the cases instead, because:
2259 - a backtrace while stopped in the signal handler would show the
2260 scratch pad as frame older than the signal handler, instead of
2261 the real mainline code.
2263 - when the thread is later resumed, the signal handler would
2264 return to the scratch pad area, which would no longer be
2266 if (step_over_info_valid_p ()
2267 || displaced_step_in_progress (tp
->inf
))
2268 target_pass_signals ({});
2270 target_pass_signals (signal_pass
);
2272 infrun_debug_printf ("resume_ptid=%s, step=%d, sig=%s",
2273 resume_ptid
.to_string ().c_str (),
2274 step
, gdb_signal_to_symbol_string (sig
));
2276 target_resume (resume_ptid
, step
, sig
);
2279 /* Resume the inferior. SIG is the signal to give the inferior
2280 (GDB_SIGNAL_0 for none). Note: don't call this directly; instead
2281 call 'resume', which handles exceptions. */
2284 resume_1 (enum gdb_signal sig
)
2286 struct regcache
*regcache
= get_current_regcache ();
2287 struct gdbarch
*gdbarch
= regcache
->arch ();
2288 struct thread_info
*tp
= inferior_thread ();
2289 const address_space
*aspace
= regcache
->aspace ();
2291 /* This represents the user's step vs continue request. When
2292 deciding whether "set scheduler-locking step" applies, it's the
2293 user's intention that counts. */
2294 const int user_step
= tp
->control
.stepping_command
;
2295 /* This represents what we'll actually request the target to do.
2296 This can decay from a step to a continue, if e.g., we need to
2297 implement single-stepping with breakpoints (software
2301 gdb_assert (!tp
->stop_requested
);
2302 gdb_assert (!thread_is_in_step_over_chain (tp
));
2304 if (tp
->has_pending_waitstatus ())
2307 ("thread %s has pending wait "
2308 "status %s (currently_stepping=%d).",
2309 tp
->ptid
.to_string ().c_str (),
2310 tp
->pending_waitstatus ().to_string ().c_str (),
2311 currently_stepping (tp
));
2313 tp
->inf
->process_target ()->threads_executing
= true;
2314 tp
->set_resumed (true);
2316 /* FIXME: What should we do if we are supposed to resume this
2317 thread with a signal? Maybe we should maintain a queue of
2318 pending signals to deliver. */
2319 if (sig
!= GDB_SIGNAL_0
)
2321 warning (_("Couldn't deliver signal %s to %s."),
2322 gdb_signal_to_name (sig
),
2323 tp
->ptid
.to_string ().c_str ());
2326 tp
->set_stop_signal (GDB_SIGNAL_0
);
2328 if (target_can_async_p ())
2330 target_async (true);
2331 /* Tell the event loop we have an event to process. */
2332 mark_async_event_handler (infrun_async_inferior_event_token
);
2337 tp
->stepped_breakpoint
= 0;
2339 /* Depends on stepped_breakpoint. */
2340 step
= currently_stepping (tp
);
2342 if (current_inferior ()->thread_waiting_for_vfork_done
!= nullptr)
2344 /* Don't try to single-step a vfork parent that is waiting for
2345 the child to get out of the shared memory region (by exec'ing
2346 or exiting). This is particularly important on software
2347 single-step archs, as the child process would trip on the
2348 software single step breakpoint inserted for the parent
2349 process. Since the parent will not actually execute any
2350 instruction until the child is out of the shared region (such
2351 are vfork's semantics), it is safe to simply continue it.
2352 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2353 the parent, and tell it to `keep_going', which automatically
2354 re-sets it stepping. */
2355 infrun_debug_printf ("resume : clear step");
2359 CORE_ADDR pc
= regcache_read_pc (regcache
);
2361 infrun_debug_printf ("step=%d, signal=%s, trap_expected=%d, "
2362 "current thread [%s] at %s",
2363 step
, gdb_signal_to_symbol_string (sig
),
2364 tp
->control
.trap_expected
,
2365 inferior_ptid
.to_string ().c_str (),
2366 paddress (gdbarch
, pc
));
2368 /* Normally, by the time we reach `resume', the breakpoints are either
2369 removed or inserted, as appropriate. The exception is if we're sitting
2370 at a permanent breakpoint; we need to step over it, but permanent
2371 breakpoints can't be removed. So we have to test for it here. */
2372 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2374 if (sig
!= GDB_SIGNAL_0
)
2376 /* We have a signal to pass to the inferior. The resume
2377 may, or may not take us to the signal handler. If this
2378 is a step, we'll need to stop in the signal handler, if
2379 there's one, (if the target supports stepping into
2380 handlers), or in the next mainline instruction, if
2381 there's no handler. If this is a continue, we need to be
2382 sure to run the handler with all breakpoints inserted.
2383 In all cases, set a breakpoint at the current address
2384 (where the handler returns to), and once that breakpoint
2385 is hit, resume skipping the permanent breakpoint. If
2386 that breakpoint isn't hit, then we've stepped into the
2387 signal handler (or hit some other event). We'll delete
2388 the step-resume breakpoint then. */
2390 infrun_debug_printf ("resume: skipping permanent breakpoint, "
2391 "deliver signal first");
2393 clear_step_over_info ();
2394 tp
->control
.trap_expected
= 0;
2396 if (tp
->control
.step_resume_breakpoint
== nullptr)
2398 /* Set a "high-priority" step-resume, as we don't want
2399 user breakpoints at PC to trigger (again) when this
2401 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2402 gdb_assert (tp
->control
.step_resume_breakpoint
->loc
->permanent
);
2404 tp
->step_after_step_resume_breakpoint
= step
;
2407 insert_breakpoints ();
2411 /* There's no signal to pass, we can go ahead and skip the
2412 permanent breakpoint manually. */
2413 infrun_debug_printf ("skipping permanent breakpoint");
2414 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2415 /* Update pc to reflect the new address from which we will
2416 execute instructions. */
2417 pc
= regcache_read_pc (regcache
);
2421 /* We've already advanced the PC, so the stepping part
2422 is done. Now we need to arrange for a trap to be
2423 reported to handle_inferior_event. Set a breakpoint
2424 at the current PC, and run to it. Don't update
2425 prev_pc, because if we end in
2426 switch_back_to_stepped_thread, we want the "expected
2427 thread advanced also" branch to be taken. IOW, we
2428 don't want this thread to step further from PC
2430 gdb_assert (!step_over_info_valid_p ());
2431 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
2432 insert_breakpoints ();
2434 resume_ptid
= internal_resume_ptid (user_step
);
2435 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
2436 tp
->set_resumed (true);
2442 /* If we have a breakpoint to step over, make sure to do a single
2443 step only. Same if we have software watchpoints. */
2444 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2445 tp
->control
.may_range_step
= 0;
2447 /* If displaced stepping is enabled, step over breakpoints by executing a
2448 copy of the instruction at a different address.
2450 We can't use displaced stepping when we have a signal to deliver;
2451 the comments for displaced_step_prepare explain why. The
2452 comments in the handle_inferior event for dealing with 'random
2453 signals' explain what we do instead.
2455 We can't use displaced stepping when we are waiting for vfork_done
2456 event, displaced stepping breaks the vfork child similarly as single
2457 step software breakpoint. */
2458 if (tp
->control
.trap_expected
2459 && use_displaced_stepping (tp
)
2460 && !step_over_info_valid_p ()
2461 && sig
== GDB_SIGNAL_0
2462 && current_inferior ()->thread_waiting_for_vfork_done
== nullptr)
2464 displaced_step_prepare_status prepare_status
2465 = displaced_step_prepare (tp
);
2467 if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE
)
2469 infrun_debug_printf ("Got placed in step-over queue");
2471 tp
->control
.trap_expected
= 0;
2474 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_CANT
)
2476 /* Fallback to stepping over the breakpoint in-line. */
2478 if (target_is_non_stop_p ())
2479 stop_all_threads ("displaced stepping falling back on inline stepping");
2481 set_step_over_info (regcache
->aspace (),
2482 regcache_read_pc (regcache
), 0, tp
->global_num
);
2484 step
= maybe_software_singlestep (gdbarch
);
2486 insert_breakpoints ();
2488 else if (prepare_status
== DISPLACED_STEP_PREPARE_STATUS_OK
)
2490 /* Update pc to reflect the new address from which we will
2491 execute instructions due to displaced stepping. */
2492 pc
= regcache_read_pc (get_thread_regcache (tp
));
2494 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
);
2497 gdb_assert_not_reached ("Invalid displaced_step_prepare_status "
2501 /* Do we need to do it the hard way, w/temp breakpoints? */
2503 step
= maybe_software_singlestep (gdbarch
);
2505 /* Currently, our software single-step implementation leads to different
2506 results than hardware single-stepping in one situation: when stepping
2507 into delivering a signal which has an associated signal handler,
2508 hardware single-step will stop at the first instruction of the handler,
2509 while software single-step will simply skip execution of the handler.
2511 For now, this difference in behavior is accepted since there is no
2512 easy way to actually implement single-stepping into a signal handler
2513 without kernel support.
2515 However, there is one scenario where this difference leads to follow-on
2516 problems: if we're stepping off a breakpoint by removing all breakpoints
2517 and then single-stepping. In this case, the software single-step
2518 behavior means that even if there is a *breakpoint* in the signal
2519 handler, GDB still would not stop.
2521 Fortunately, we can at least fix this particular issue. We detect
2522 here the case where we are about to deliver a signal while software
2523 single-stepping with breakpoints removed. In this situation, we
2524 revert the decisions to remove all breakpoints and insert single-
2525 step breakpoints, and instead we install a step-resume breakpoint
2526 at the current address, deliver the signal without stepping, and
2527 once we arrive back at the step-resume breakpoint, actually step
2528 over the breakpoint we originally wanted to step over. */
2529 if (thread_has_single_step_breakpoints_set (tp
)
2530 && sig
!= GDB_SIGNAL_0
2531 && step_over_info_valid_p ())
2533 /* If we have nested signals or a pending signal is delivered
2534 immediately after a handler returns, might already have
2535 a step-resume breakpoint set on the earlier handler. We cannot
2536 set another step-resume breakpoint; just continue on until the
2537 original breakpoint is hit. */
2538 if (tp
->control
.step_resume_breakpoint
== nullptr)
2540 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2541 tp
->step_after_step_resume_breakpoint
= 1;
2544 delete_single_step_breakpoints (tp
);
2546 clear_step_over_info ();
2547 tp
->control
.trap_expected
= 0;
2549 insert_breakpoints ();
2552 /* If STEP is set, it's a request to use hardware stepping
2553 facilities. But in that case, we should never
2554 use singlestep breakpoint. */
2555 gdb_assert (!(thread_has_single_step_breakpoints_set (tp
) && step
));
2557 /* Decide the set of threads to ask the target to resume. */
2558 if (tp
->control
.trap_expected
)
2560 /* We're allowing a thread to run past a breakpoint it has
2561 hit, either by single-stepping the thread with the breakpoint
2562 removed, or by displaced stepping, with the breakpoint inserted.
2563 In the former case, we need to single-step only this thread,
2564 and keep others stopped, as they can miss this breakpoint if
2565 allowed to run. That's not really a problem for displaced
2566 stepping, but, we still keep other threads stopped, in case
2567 another thread is also stopped for a breakpoint waiting for
2568 its turn in the displaced stepping queue. */
2569 resume_ptid
= inferior_ptid
;
2572 resume_ptid
= internal_resume_ptid (user_step
);
2574 if (execution_direction
!= EXEC_REVERSE
2575 && step
&& breakpoint_inserted_here_p (aspace
, pc
))
2577 /* There are two cases where we currently need to step a
2578 breakpoint instruction when we have a signal to deliver:
2580 - See handle_signal_stop where we handle random signals that
2581 could take out us out of the stepping range. Normally, in
2582 that case we end up continuing (instead of stepping) over the
2583 signal handler with a breakpoint at PC, but there are cases
2584 where we should _always_ single-step, even if we have a
2585 step-resume breakpoint, like when a software watchpoint is
2586 set. Assuming single-stepping and delivering a signal at the
2587 same time would takes us to the signal handler, then we could
2588 have removed the breakpoint at PC to step over it. However,
2589 some hardware step targets (like e.g., Mac OS) can't step
2590 into signal handlers, and for those, we need to leave the
2591 breakpoint at PC inserted, as otherwise if the handler
2592 recurses and executes PC again, it'll miss the breakpoint.
2593 So we leave the breakpoint inserted anyway, but we need to
2594 record that we tried to step a breakpoint instruction, so
2595 that adjust_pc_after_break doesn't end up confused.
2597 - In non-stop if we insert a breakpoint (e.g., a step-resume)
2598 in one thread after another thread that was stepping had been
2599 momentarily paused for a step-over. When we re-resume the
2600 stepping thread, it may be resumed from that address with a
2601 breakpoint that hasn't trapped yet. Seen with
2602 gdb.threads/non-stop-fair-events.exp, on targets that don't
2603 do displaced stepping. */
2605 infrun_debug_printf ("resume: [%s] stepped breakpoint",
2606 tp
->ptid
.to_string ().c_str ());
2608 tp
->stepped_breakpoint
= 1;
2610 /* Most targets can step a breakpoint instruction, thus
2611 executing it normally. But if this one cannot, just
2612 continue and we will hit it anyway. */
2613 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2618 && tp
->control
.trap_expected
2619 && use_displaced_stepping (tp
)
2620 && !step_over_info_valid_p ())
2622 struct regcache
*resume_regcache
= get_thread_regcache (tp
);
2623 struct gdbarch
*resume_gdbarch
= resume_regcache
->arch ();
2624 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
2627 read_memory (actual_pc
, buf
, sizeof (buf
));
2628 displaced_debug_printf ("run %s: %s",
2629 paddress (resume_gdbarch
, actual_pc
),
2630 displaced_step_dump_bytes
2631 (buf
, sizeof (buf
)).c_str ());
2634 if (tp
->control
.may_range_step
)
2636 /* If we're resuming a thread with the PC out of the step
2637 range, then we're doing some nested/finer run control
2638 operation, like stepping the thread out of the dynamic
2639 linker or the displaced stepping scratch pad. We
2640 shouldn't have allowed a range step then. */
2641 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2644 do_target_resume (resume_ptid
, step
, sig
);
2645 tp
->set_resumed (true);
2648 /* Resume the inferior. SIG is the signal to give the inferior
2649 (GDB_SIGNAL_0 for none). This is a wrapper around 'resume_1' that
2650 rolls back state on error. */
2653 resume (gdb_signal sig
)
2659 catch (const gdb_exception
&ex
)
2661 /* If resuming is being aborted for any reason, delete any
2662 single-step breakpoint resume_1 may have created, to avoid
2663 confusing the following resumption, and to avoid leaving
2664 single-step breakpoints perturbing other threads, in case
2665 we're running in non-stop mode. */
2666 if (inferior_ptid
!= null_ptid
)
2667 delete_single_step_breakpoints (inferior_thread ());
2677 /* Counter that tracks number of user visible stops. This can be used
2678 to tell whether a command has proceeded the inferior past the
2679 current location. This allows e.g., inferior function calls in
2680 breakpoint commands to not interrupt the command list. When the
2681 call finishes successfully, the inferior is standing at the same
2682 breakpoint as if nothing happened (and so we don't call
2684 static ULONGEST current_stop_id
;
2691 return current_stop_id
;
2694 /* Called when we report a user visible stop. */
2702 /* Clear out all variables saying what to do when inferior is continued.
2703 First do this, then set the ones you want, then call `proceed'. */
2706 clear_proceed_status_thread (struct thread_info
*tp
)
2708 infrun_debug_printf ("%s", tp
->ptid
.to_string ().c_str ());
2710 /* If we're starting a new sequence, then the previous finished
2711 single-step is no longer relevant. */
2712 if (tp
->has_pending_waitstatus ())
2714 if (tp
->stop_reason () == TARGET_STOPPED_BY_SINGLE_STEP
)
2716 infrun_debug_printf ("pending event of %s was a finished step. "
2718 tp
->ptid
.to_string ().c_str ());
2720 tp
->clear_pending_waitstatus ();
2721 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
2726 ("thread %s has pending wait status %s (currently_stepping=%d).",
2727 tp
->ptid
.to_string ().c_str (),
2728 tp
->pending_waitstatus ().to_string ().c_str (),
2729 currently_stepping (tp
));
2733 /* If this signal should not be seen by program, give it zero.
2734 Used for debugging signals. */
2735 if (!signal_pass_state (tp
->stop_signal ()))
2736 tp
->set_stop_signal (GDB_SIGNAL_0
);
2738 tp
->release_thread_fsm ();
2740 tp
->control
.trap_expected
= 0;
2741 tp
->control
.step_range_start
= 0;
2742 tp
->control
.step_range_end
= 0;
2743 tp
->control
.may_range_step
= 0;
2744 tp
->control
.step_frame_id
= null_frame_id
;
2745 tp
->control
.step_stack_frame_id
= null_frame_id
;
2746 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2747 tp
->control
.step_start_function
= nullptr;
2748 tp
->stop_requested
= 0;
2750 tp
->control
.stop_step
= 0;
2752 tp
->control
.proceed_to_finish
= 0;
2754 tp
->control
.stepping_command
= 0;
2756 /* Discard any remaining commands or status from previous stop. */
2757 bpstat_clear (&tp
->control
.stop_bpstat
);
2761 clear_proceed_status (int step
)
2763 /* With scheduler-locking replay, stop replaying other threads if we're
2764 not replaying the user-visible resume ptid.
2766 This is a convenience feature to not require the user to explicitly
2767 stop replaying the other threads. We're assuming that the user's
2768 intent is to resume tracing the recorded process. */
2769 if (!non_stop
&& scheduler_mode
== schedlock_replay
2770 && target_record_is_replaying (minus_one_ptid
)
2771 && !target_record_will_replay (user_visible_resume_ptid (step
),
2772 execution_direction
))
2773 target_record_stop_replaying ();
2775 if (!non_stop
&& inferior_ptid
!= null_ptid
)
2777 ptid_t resume_ptid
= user_visible_resume_ptid (step
);
2778 process_stratum_target
*resume_target
2779 = user_visible_resume_target (resume_ptid
);
2781 /* In all-stop mode, delete the per-thread status of all threads
2782 we're about to resume, implicitly and explicitly. */
2783 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
2784 clear_proceed_status_thread (tp
);
2787 if (inferior_ptid
!= null_ptid
)
2789 struct inferior
*inferior
;
2793 /* If in non-stop mode, only delete the per-thread status of
2794 the current thread. */
2795 clear_proceed_status_thread (inferior_thread ());
2798 inferior
= current_inferior ();
2799 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2802 gdb::observers::about_to_proceed
.notify ();
2805 /* Returns true if TP is still stopped at a breakpoint that needs
2806 stepping-over in order to make progress. If the breakpoint is gone
2807 meanwhile, we can skip the whole step-over dance. */
2810 thread_still_needs_step_over_bp (struct thread_info
*tp
)
2812 if (tp
->stepping_over_breakpoint
)
2814 struct regcache
*regcache
= get_thread_regcache (tp
);
2816 if (breakpoint_here_p (regcache
->aspace (),
2817 regcache_read_pc (regcache
))
2818 == ordinary_breakpoint_here
)
2821 tp
->stepping_over_breakpoint
= 0;
2827 /* Check whether thread TP still needs to start a step-over in order
2828 to make progress when resumed. Returns an bitwise or of enum
2829 step_over_what bits, indicating what needs to be stepped over. */
2831 static step_over_what
2832 thread_still_needs_step_over (struct thread_info
*tp
)
2834 step_over_what what
= 0;
2836 if (thread_still_needs_step_over_bp (tp
))
2837 what
|= STEP_OVER_BREAKPOINT
;
2839 if (tp
->stepping_over_watchpoint
2840 && !target_have_steppable_watchpoint ())
2841 what
|= STEP_OVER_WATCHPOINT
;
2846 /* Returns true if scheduler locking applies. STEP indicates whether
2847 we're about to do a step/next-like command to a thread. */
2850 schedlock_applies (struct thread_info
*tp
)
2852 return (scheduler_mode
== schedlock_on
2853 || (scheduler_mode
== schedlock_step
2854 && tp
->control
.stepping_command
)
2855 || (scheduler_mode
== schedlock_replay
2856 && target_record_will_replay (minus_one_ptid
,
2857 execution_direction
)));
2860 /* Set process_stratum_target::COMMIT_RESUMED_STATE in all target
2861 stacks that have threads executing and don't have threads with
2865 maybe_set_commit_resumed_all_targets ()
2867 scoped_restore_current_thread restore_thread
;
2869 for (inferior
*inf
: all_non_exited_inferiors ())
2871 process_stratum_target
*proc_target
= inf
->process_target ();
2873 if (proc_target
->commit_resumed_state
)
2875 /* We already set this in a previous iteration, via another
2876 inferior sharing the process_stratum target. */
2880 /* If the target has no resumed threads, it would be useless to
2881 ask it to commit the resumed threads. */
2882 if (!proc_target
->threads_executing
)
2884 infrun_debug_printf ("not requesting commit-resumed for target "
2885 "%s, no resumed threads",
2886 proc_target
->shortname ());
2890 /* As an optimization, if a thread from this target has some
2891 status to report, handle it before requiring the target to
2892 commit its resumed threads: handling the status might lead to
2893 resuming more threads. */
2894 if (proc_target
->has_resumed_with_pending_wait_status ())
2896 infrun_debug_printf ("not requesting commit-resumed for target %s, a"
2897 " thread has a pending waitstatus",
2898 proc_target
->shortname ());
2902 switch_to_inferior_no_thread (inf
);
2904 if (target_has_pending_events ())
2906 infrun_debug_printf ("not requesting commit-resumed for target %s, "
2907 "target has pending events",
2908 proc_target
->shortname ());
2912 infrun_debug_printf ("enabling commit-resumed for target %s",
2913 proc_target
->shortname ());
2915 proc_target
->commit_resumed_state
= true;
2922 maybe_call_commit_resumed_all_targets ()
2924 scoped_restore_current_thread restore_thread
;
2926 for (inferior
*inf
: all_non_exited_inferiors ())
2928 process_stratum_target
*proc_target
= inf
->process_target ();
2930 if (!proc_target
->commit_resumed_state
)
2933 switch_to_inferior_no_thread (inf
);
2935 infrun_debug_printf ("calling commit_resumed for target %s",
2936 proc_target
->shortname());
2938 target_commit_resumed ();
2942 /* To track nesting of scoped_disable_commit_resumed objects, ensuring
2943 that only the outermost one attempts to re-enable
2945 static bool enable_commit_resumed
= true;
2949 scoped_disable_commit_resumed::scoped_disable_commit_resumed
2950 (const char *reason
)
2951 : m_reason (reason
),
2952 m_prev_enable_commit_resumed (enable_commit_resumed
)
2954 infrun_debug_printf ("reason=%s", m_reason
);
2956 enable_commit_resumed
= false;
2958 for (inferior
*inf
: all_non_exited_inferiors ())
2960 process_stratum_target
*proc_target
= inf
->process_target ();
2962 if (m_prev_enable_commit_resumed
)
2964 /* This is the outermost instance: force all
2965 COMMIT_RESUMED_STATE to false. */
2966 proc_target
->commit_resumed_state
= false;
2970 /* This is not the outermost instance, we expect
2971 COMMIT_RESUMED_STATE to have been cleared by the
2972 outermost instance. */
2973 gdb_assert (!proc_target
->commit_resumed_state
);
2981 scoped_disable_commit_resumed::reset ()
2987 infrun_debug_printf ("reason=%s", m_reason
);
2989 gdb_assert (!enable_commit_resumed
);
2991 enable_commit_resumed
= m_prev_enable_commit_resumed
;
2993 if (m_prev_enable_commit_resumed
)
2995 /* This is the outermost instance, re-enable
2996 COMMIT_RESUMED_STATE on the targets where it's possible. */
2997 maybe_set_commit_resumed_all_targets ();
3001 /* This is not the outermost instance, we expect
3002 COMMIT_RESUMED_STATE to still be false. */
3003 for (inferior
*inf
: all_non_exited_inferiors ())
3005 process_stratum_target
*proc_target
= inf
->process_target ();
3006 gdb_assert (!proc_target
->commit_resumed_state
);
3013 scoped_disable_commit_resumed::~scoped_disable_commit_resumed ()
3021 scoped_disable_commit_resumed::reset_and_commit ()
3024 maybe_call_commit_resumed_all_targets ();
3029 scoped_enable_commit_resumed::scoped_enable_commit_resumed
3030 (const char *reason
)
3031 : m_reason (reason
),
3032 m_prev_enable_commit_resumed (enable_commit_resumed
)
3034 infrun_debug_printf ("reason=%s", m_reason
);
3036 if (!enable_commit_resumed
)
3038 enable_commit_resumed
= true;
3040 /* Re-enable COMMIT_RESUMED_STATE on the targets where it's
3042 maybe_set_commit_resumed_all_targets ();
3044 maybe_call_commit_resumed_all_targets ();
3050 scoped_enable_commit_resumed::~scoped_enable_commit_resumed ()
3052 infrun_debug_printf ("reason=%s", m_reason
);
3054 gdb_assert (enable_commit_resumed
);
3056 enable_commit_resumed
= m_prev_enable_commit_resumed
;
3058 if (!enable_commit_resumed
)
3060 /* Force all COMMIT_RESUMED_STATE back to false. */
3061 for (inferior
*inf
: all_non_exited_inferiors ())
3063 process_stratum_target
*proc_target
= inf
->process_target ();
3064 proc_target
->commit_resumed_state
= false;
3069 /* Check that all the targets we're about to resume are in non-stop
3070 mode. Ideally, we'd only care whether all targets support
3071 target-async, but we're not there yet. E.g., stop_all_threads
3072 doesn't know how to handle all-stop targets. Also, the remote
3073 protocol in all-stop mode is synchronous, irrespective of
3074 target-async, which means that things like a breakpoint re-set
3075 triggered by one target would try to read memory from all targets
3079 check_multi_target_resumption (process_stratum_target
*resume_target
)
3081 if (!non_stop
&& resume_target
== nullptr)
3083 scoped_restore_current_thread restore_thread
;
3085 /* This is used to track whether we're resuming more than one
3087 process_stratum_target
*first_connection
= nullptr;
3089 /* The first inferior we see with a target that does not work in
3090 always-non-stop mode. */
3091 inferior
*first_not_non_stop
= nullptr;
3093 for (inferior
*inf
: all_non_exited_inferiors ())
3095 switch_to_inferior_no_thread (inf
);
3097 if (!target_has_execution ())
3100 process_stratum_target
*proc_target
3101 = current_inferior ()->process_target();
3103 if (!target_is_non_stop_p ())
3104 first_not_non_stop
= inf
;
3106 if (first_connection
== nullptr)
3107 first_connection
= proc_target
;
3108 else if (first_connection
!= proc_target
3109 && first_not_non_stop
!= nullptr)
3111 switch_to_inferior_no_thread (first_not_non_stop
);
3113 proc_target
= current_inferior ()->process_target();
3115 error (_("Connection %d (%s) does not support "
3116 "multi-target resumption."),
3117 proc_target
->connection_number
,
3118 make_target_connection_string (proc_target
).c_str ());
3124 /* Basic routine for continuing the program in various fashions.
3126 ADDR is the address to resume at, or -1 for resume where stopped.
3127 SIGGNAL is the signal to give it, or GDB_SIGNAL_0 for none,
3128 or GDB_SIGNAL_DEFAULT for act according to how it stopped.
3130 You should call clear_proceed_status before calling proceed. */
3133 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
)
3135 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
3137 struct regcache
*regcache
;
3138 struct gdbarch
*gdbarch
;
3141 /* If we're stopped at a fork/vfork, follow the branch set by the
3142 "set follow-fork-mode" command; otherwise, we'll just proceed
3143 resuming the current thread. */
3144 if (!follow_fork ())
3146 /* The target for some reason decided not to resume. */
3148 if (target_can_async_p ())
3149 inferior_event_handler (INF_EXEC_COMPLETE
);
3153 /* We'll update this if & when we switch to a new thread. */
3154 previous_inferior_ptid
= inferior_ptid
;
3156 regcache
= get_current_regcache ();
3157 gdbarch
= regcache
->arch ();
3158 const address_space
*aspace
= regcache
->aspace ();
3160 pc
= regcache_read_pc_protected (regcache
);
3162 thread_info
*cur_thr
= inferior_thread ();
3164 /* Fill in with reasonable starting values. */
3165 init_thread_stepping_state (cur_thr
);
3167 gdb_assert (!thread_is_in_step_over_chain (cur_thr
));
3170 = user_visible_resume_ptid (cur_thr
->control
.stepping_command
);
3171 process_stratum_target
*resume_target
3172 = user_visible_resume_target (resume_ptid
);
3174 check_multi_target_resumption (resume_target
);
3176 if (addr
== (CORE_ADDR
) -1)
3178 if (cur_thr
->stop_pc_p ()
3179 && pc
== cur_thr
->stop_pc ()
3180 && breakpoint_here_p (aspace
, pc
) == ordinary_breakpoint_here
3181 && execution_direction
!= EXEC_REVERSE
)
3182 /* There is a breakpoint at the address we will resume at,
3183 step one instruction before inserting breakpoints so that
3184 we do not stop right away (and report a second hit at this
3187 Note, we don't do this in reverse, because we won't
3188 actually be executing the breakpoint insn anyway.
3189 We'll be (un-)executing the previous instruction. */
3190 cur_thr
->stepping_over_breakpoint
= 1;
3191 else if (gdbarch_single_step_through_delay_p (gdbarch
)
3192 && gdbarch_single_step_through_delay (gdbarch
,
3193 get_current_frame ()))
3194 /* We stepped onto an instruction that needs to be stepped
3195 again before re-inserting the breakpoint, do so. */
3196 cur_thr
->stepping_over_breakpoint
= 1;
3200 regcache_write_pc (regcache
, addr
);
3203 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
3204 cur_thr
->set_stop_signal (siggnal
);
3206 /* If an exception is thrown from this point on, make sure to
3207 propagate GDB's knowledge of the executing state to the
3208 frontend/user running state. */
3209 scoped_finish_thread_state
finish_state (resume_target
, resume_ptid
);
3211 /* Even if RESUME_PTID is a wildcard, and we end up resuming fewer
3212 threads (e.g., we might need to set threads stepping over
3213 breakpoints first), from the user/frontend's point of view, all
3214 threads in RESUME_PTID are now running. Unless we're calling an
3215 inferior function, as in that case we pretend the inferior
3216 doesn't run at all. */
3217 if (!cur_thr
->control
.in_infcall
)
3218 set_running (resume_target
, resume_ptid
, true);
3220 infrun_debug_printf ("addr=%s, signal=%s", paddress (gdbarch
, addr
),
3221 gdb_signal_to_symbol_string (siggnal
));
3223 annotate_starting ();
3225 /* Make sure that output from GDB appears before output from the
3227 gdb_flush (gdb_stdout
);
3229 /* Since we've marked the inferior running, give it the terminal. A
3230 QUIT/Ctrl-C from here on is forwarded to the target (which can
3231 still detect attempts to unblock a stuck connection with repeated
3232 Ctrl-C from within target_pass_ctrlc). */
3233 target_terminal::inferior ();
3235 /* In a multi-threaded task we may select another thread and
3236 then continue or step.
3238 But if a thread that we're resuming had stopped at a breakpoint,
3239 it will immediately cause another breakpoint stop without any
3240 execution (i.e. it will report a breakpoint hit incorrectly). So
3241 we must step over it first.
3243 Look for threads other than the current (TP) that reported a
3244 breakpoint hit and haven't been resumed yet since. */
3246 /* If scheduler locking applies, we can avoid iterating over all
3248 if (!non_stop
&& !schedlock_applies (cur_thr
))
3250 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3253 switch_to_thread_no_regs (tp
);
3255 /* Ignore the current thread here. It's handled
3260 if (!thread_still_needs_step_over (tp
))
3263 gdb_assert (!thread_is_in_step_over_chain (tp
));
3265 infrun_debug_printf ("need to step-over [%s] first",
3266 tp
->ptid
.to_string ().c_str ());
3268 global_thread_step_over_chain_enqueue (tp
);
3271 switch_to_thread (cur_thr
);
3274 /* Enqueue the current thread last, so that we move all other
3275 threads over their breakpoints first. */
3276 if (cur_thr
->stepping_over_breakpoint
)
3277 global_thread_step_over_chain_enqueue (cur_thr
);
3279 /* If the thread isn't started, we'll still need to set its prev_pc,
3280 so that switch_back_to_stepped_thread knows the thread hasn't
3281 advanced. Must do this before resuming any thread, as in
3282 all-stop/remote, once we resume we can't send any other packet
3283 until the target stops again. */
3284 cur_thr
->prev_pc
= regcache_read_pc_protected (regcache
);
3287 scoped_disable_commit_resumed
disable_commit_resumed ("proceeding");
3288 bool step_over_started
= start_step_over ();
3290 if (step_over_info_valid_p ())
3292 /* Either this thread started a new in-line step over, or some
3293 other thread was already doing one. In either case, don't
3294 resume anything else until the step-over is finished. */
3296 else if (step_over_started
&& !target_is_non_stop_p ())
3298 /* A new displaced stepping sequence was started. In all-stop,
3299 we can't talk to the target anymore until it next stops. */
3301 else if (!non_stop
&& target_is_non_stop_p ())
3303 INFRUN_SCOPED_DEBUG_START_END
3304 ("resuming threads, all-stop-on-top-of-non-stop");
3306 /* In all-stop, but the target is always in non-stop mode.
3307 Start all other threads that are implicitly resumed too. */
3308 for (thread_info
*tp
: all_non_exited_threads (resume_target
,
3311 switch_to_thread_no_regs (tp
);
3313 if (!tp
->inf
->has_execution ())
3315 infrun_debug_printf ("[%s] target has no execution",
3316 tp
->ptid
.to_string ().c_str ());
3322 infrun_debug_printf ("[%s] resumed",
3323 tp
->ptid
.to_string ().c_str ());
3324 gdb_assert (tp
->executing () || tp
->has_pending_waitstatus ());
3328 if (thread_is_in_step_over_chain (tp
))
3330 infrun_debug_printf ("[%s] needs step-over",
3331 tp
->ptid
.to_string ().c_str ());
3335 /* If a thread of that inferior is waiting for a vfork-done
3336 (for a detached vfork child to exec or exit), breakpoints are
3337 removed. We must not resume any thread of that inferior, other
3338 than the one waiting for the vfork-done. */
3339 if (tp
->inf
->thread_waiting_for_vfork_done
!= nullptr
3340 && tp
!= tp
->inf
->thread_waiting_for_vfork_done
)
3342 infrun_debug_printf ("[%s] another thread of this inferior is "
3343 "waiting for vfork-done",
3344 tp
->ptid
.to_string ().c_str ());
3348 infrun_debug_printf ("resuming %s",
3349 tp
->ptid
.to_string ().c_str ());
3351 execution_control_state
ecs (tp
);
3352 switch_to_thread (tp
);
3353 keep_going_pass_signal (&ecs
);
3354 if (!ecs
.wait_some_more
)
3355 error (_("Command aborted."));
3358 else if (!cur_thr
->resumed ()
3359 && !thread_is_in_step_over_chain (cur_thr
)
3360 /* In non-stop, forbid resuming a thread if some other thread of
3361 that inferior is waiting for a vfork-done event (this means
3362 breakpoints are out for this inferior). */
3364 && cur_thr
->inf
->thread_waiting_for_vfork_done
!= nullptr))
3366 /* The thread wasn't started, and isn't queued, run it now. */
3367 execution_control_state
ecs (cur_thr
);
3368 switch_to_thread (cur_thr
);
3369 keep_going_pass_signal (&ecs
);
3370 if (!ecs
.wait_some_more
)
3371 error (_("Command aborted."));
3374 disable_commit_resumed
.reset_and_commit ();
3377 finish_state
.release ();
3379 /* If we've switched threads above, switch back to the previously
3380 current thread. We don't want the user to see a different
3382 switch_to_thread (cur_thr
);
3384 /* Tell the event loop to wait for it to stop. If the target
3385 supports asynchronous execution, it'll do this from within
3387 if (!target_can_async_p ())
3388 mark_async_event_handler (infrun_async_inferior_event_token
);
3392 /* Start remote-debugging of a machine over a serial link. */
3395 start_remote (int from_tty
)
3397 inferior
*inf
= current_inferior ();
3398 inf
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
3400 /* Always go on waiting for the target, regardless of the mode. */
3401 /* FIXME: cagney/1999-09-23: At present it isn't possible to
3402 indicate to wait_for_inferior that a target should timeout if
3403 nothing is returned (instead of just blocking). Because of this,
3404 targets expecting an immediate response need to, internally, set
3405 things up so that the target_wait() is forced to eventually
3407 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
3408 differentiate to its caller what the state of the target is after
3409 the initial open has been performed. Here we're assuming that
3410 the target has stopped. It should be possible to eventually have
3411 target_open() return to the caller an indication that the target
3412 is currently running and GDB state should be set to the same as
3413 for an async run. */
3414 wait_for_inferior (inf
);
3416 /* Now that the inferior has stopped, do any bookkeeping like
3417 loading shared libraries. We want to do this before normal_stop,
3418 so that the displayed frame is up to date. */
3419 post_create_inferior (from_tty
);
3424 /* Initialize static vars when a new inferior begins. */
3427 init_wait_for_inferior (void)
3429 /* These are meaningless until the first time through wait_for_inferior. */
3431 breakpoint_init_inferior (inf_starting
);
3433 clear_proceed_status (0);
3435 nullify_last_target_wait_ptid ();
3437 previous_inferior_ptid
= inferior_ptid
;
3442 static void handle_inferior_event (struct execution_control_state
*ecs
);
3444 static void handle_step_into_function (struct gdbarch
*gdbarch
,
3445 struct execution_control_state
*ecs
);
3446 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
3447 struct execution_control_state
*ecs
);
3448 static void handle_signal_stop (struct execution_control_state
*ecs
);
3449 static void check_exception_resume (struct execution_control_state
*,
3452 static void end_stepping_range (struct execution_control_state
*ecs
);
3453 static void stop_waiting (struct execution_control_state
*ecs
);
3454 static void keep_going (struct execution_control_state
*ecs
);
3455 static void process_event_stop_test (struct execution_control_state
*ecs
);
3456 static bool switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
3458 /* This function is attached as a "thread_stop_requested" observer.
3459 Cleanup local state that assumed the PTID was to be resumed, and
3460 report the stop to the frontend. */
3463 infrun_thread_stop_requested (ptid_t ptid
)
3465 process_stratum_target
*curr_target
= current_inferior ()->process_target ();
3467 /* PTID was requested to stop. If the thread was already stopped,
3468 but the user/frontend doesn't know about that yet (e.g., the
3469 thread had been temporarily paused for some step-over), set up
3470 for reporting the stop now. */
3471 for (thread_info
*tp
: all_threads (curr_target
, ptid
))
3473 if (tp
->state
!= THREAD_RUNNING
)
3475 if (tp
->executing ())
3478 /* Remove matching threads from the step-over queue, so
3479 start_step_over doesn't try to resume them
3481 if (thread_is_in_step_over_chain (tp
))
3482 global_thread_step_over_chain_remove (tp
);
3484 /* If the thread is stopped, but the user/frontend doesn't
3485 know about that yet, queue a pending event, as if the
3486 thread had just stopped now. Unless the thread already had
3488 if (!tp
->has_pending_waitstatus ())
3490 target_waitstatus ws
;
3491 ws
.set_stopped (GDB_SIGNAL_0
);
3492 tp
->set_pending_waitstatus (ws
);
3495 /* Clear the inline-frame state, since we're re-processing the
3497 clear_inline_frame_state (tp
);
3499 /* If this thread was paused because some other thread was
3500 doing an inline-step over, let that finish first. Once
3501 that happens, we'll restart all threads and consume pending
3502 stop events then. */
3503 if (step_over_info_valid_p ())
3506 /* Otherwise we can process the (new) pending event now. Set
3507 it so this pending event is considered by
3509 tp
->set_resumed (true);
3514 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
3516 if (target_last_proc_target
== tp
->inf
->process_target ()
3517 && target_last_wait_ptid
== tp
->ptid
)
3518 nullify_last_target_wait_ptid ();
3521 /* Delete the step resume, single-step and longjmp/exception resume
3522 breakpoints of TP. */
3525 delete_thread_infrun_breakpoints (struct thread_info
*tp
)
3527 delete_step_resume_breakpoint (tp
);
3528 delete_exception_resume_breakpoint (tp
);
3529 delete_single_step_breakpoints (tp
);
3532 /* If the target still has execution, call FUNC for each thread that
3533 just stopped. In all-stop, that's all the non-exited threads; in
3534 non-stop, that's the current thread, only. */
3536 typedef void (*for_each_just_stopped_thread_callback_func
)
3537 (struct thread_info
*tp
);
3540 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func
)
3542 if (!target_has_execution () || inferior_ptid
== null_ptid
)
3545 if (target_is_non_stop_p ())
3547 /* If in non-stop mode, only the current thread stopped. */
3548 func (inferior_thread ());
3552 /* In all-stop mode, all threads have stopped. */
3553 for (thread_info
*tp
: all_non_exited_threads ())
3558 /* Delete the step resume and longjmp/exception resume breakpoints of
3559 the threads that just stopped. */
3562 delete_just_stopped_threads_infrun_breakpoints (void)
3564 for_each_just_stopped_thread (delete_thread_infrun_breakpoints
);
3567 /* Delete the single-step breakpoints of the threads that just
3571 delete_just_stopped_threads_single_step_breakpoints (void)
3573 for_each_just_stopped_thread (delete_single_step_breakpoints
);
3579 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
3580 const struct target_waitstatus
&ws
)
3582 infrun_debug_printf ("target_wait (%s [%s], status) =",
3583 waiton_ptid
.to_string ().c_str (),
3584 target_pid_to_str (waiton_ptid
).c_str ());
3585 infrun_debug_printf (" %s [%s],",
3586 result_ptid
.to_string ().c_str (),
3587 target_pid_to_str (result_ptid
).c_str ());
3588 infrun_debug_printf (" %s", ws
.to_string ().c_str ());
3591 /* Select a thread at random, out of those which are resumed and have
3594 static struct thread_info
*
3595 random_pending_event_thread (inferior
*inf
, ptid_t waiton_ptid
)
3597 process_stratum_target
*proc_target
= inf
->process_target ();
3599 = proc_target
->random_resumed_with_pending_wait_status (inf
, waiton_ptid
);
3601 if (thread
== nullptr)
3603 infrun_debug_printf ("None found.");
3607 infrun_debug_printf ("Found %s.", thread
->ptid
.to_string ().c_str ());
3608 gdb_assert (thread
->resumed ());
3609 gdb_assert (thread
->has_pending_waitstatus ());
3614 /* Wrapper for target_wait that first checks whether threads have
3615 pending statuses to report before actually asking the target for
3616 more events. INF is the inferior we're using to call target_wait
3620 do_target_wait_1 (inferior
*inf
, ptid_t ptid
,
3621 target_waitstatus
*status
, target_wait_flags options
)
3623 struct thread_info
*tp
;
3625 /* We know that we are looking for an event in the target of inferior
3626 INF, but we don't know which thread the event might come from. As
3627 such we want to make sure that INFERIOR_PTID is reset so that none of
3628 the wait code relies on it - doing so is always a mistake. */
3629 switch_to_inferior_no_thread (inf
);
3631 /* First check if there is a resumed thread with a wait status
3633 if (ptid
== minus_one_ptid
|| ptid
.is_pid ())
3635 tp
= random_pending_event_thread (inf
, ptid
);
3639 infrun_debug_printf ("Waiting for specific thread %s.",
3640 ptid
.to_string ().c_str ());
3642 /* We have a specific thread to check. */
3643 tp
= find_thread_ptid (inf
, ptid
);
3644 gdb_assert (tp
!= nullptr);
3645 if (!tp
->has_pending_waitstatus ())
3650 && (tp
->stop_reason () == TARGET_STOPPED_BY_SW_BREAKPOINT
3651 || tp
->stop_reason () == TARGET_STOPPED_BY_HW_BREAKPOINT
))
3653 struct regcache
*regcache
= get_thread_regcache (tp
);
3654 struct gdbarch
*gdbarch
= regcache
->arch ();
3658 pc
= regcache_read_pc (regcache
);
3660 if (pc
!= tp
->stop_pc ())
3662 infrun_debug_printf ("PC of %s changed. was=%s, now=%s",
3663 tp
->ptid
.to_string ().c_str (),
3664 paddress (gdbarch
, tp
->stop_pc ()),
3665 paddress (gdbarch
, pc
));
3668 else if (!breakpoint_inserted_here_p (regcache
->aspace (), pc
))
3670 infrun_debug_printf ("previous breakpoint of %s, at %s gone",
3671 tp
->ptid
.to_string ().c_str (),
3672 paddress (gdbarch
, pc
));
3679 infrun_debug_printf ("pending event of %s cancelled.",
3680 tp
->ptid
.to_string ().c_str ());
3682 tp
->clear_pending_waitstatus ();
3683 target_waitstatus ws
;
3685 tp
->set_pending_waitstatus (ws
);
3686 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
3692 infrun_debug_printf ("Using pending wait status %s for %s.",
3693 tp
->pending_waitstatus ().to_string ().c_str (),
3694 tp
->ptid
.to_string ().c_str ());
3696 /* Now that we've selected our final event LWP, un-adjust its PC
3697 if it was a software breakpoint (and the target doesn't
3698 always adjust the PC itself). */
3699 if (tp
->stop_reason () == TARGET_STOPPED_BY_SW_BREAKPOINT
3700 && !target_supports_stopped_by_sw_breakpoint ())
3702 struct regcache
*regcache
;
3703 struct gdbarch
*gdbarch
;
3706 regcache
= get_thread_regcache (tp
);
3707 gdbarch
= regcache
->arch ();
3709 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
3714 pc
= regcache_read_pc (regcache
);
3715 regcache_write_pc (regcache
, pc
+ decr_pc
);
3719 tp
->set_stop_reason (TARGET_STOPPED_BY_NO_REASON
);
3720 *status
= tp
->pending_waitstatus ();
3721 tp
->clear_pending_waitstatus ();
3723 /* Wake up the event loop again, until all pending events are
3725 if (target_is_async_p ())
3726 mark_async_event_handler (infrun_async_inferior_event_token
);
3730 /* But if we don't find one, we'll have to wait. */
3732 /* We can't ask a non-async target to do a non-blocking wait, so this will be
3734 if (!target_can_async_p ())
3735 options
&= ~TARGET_WNOHANG
;
3737 return target_wait (ptid
, status
, options
);
3740 /* Wrapper for target_wait that first checks whether threads have
3741 pending statuses to report before actually asking the target for
3742 more events. Polls for events from all inferiors/targets. */
3745 do_target_wait (execution_control_state
*ecs
, target_wait_flags options
)
3747 int num_inferiors
= 0;
3748 int random_selector
;
3750 /* For fairness, we pick the first inferior/target to poll at random
3751 out of all inferiors that may report events, and then continue
3752 polling the rest of the inferior list starting from that one in a
3753 circular fashion until the whole list is polled once. */
3755 auto inferior_matches
= [] (inferior
*inf
)
3757 return inf
->process_target () != nullptr;
3760 /* First see how many matching inferiors we have. */
3761 for (inferior
*inf
: all_inferiors ())
3762 if (inferior_matches (inf
))
3765 if (num_inferiors
== 0)
3767 ecs
->ws
.set_ignore ();
3771 /* Now randomly pick an inferior out of those that matched. */
3772 random_selector
= (int)
3773 ((num_inferiors
* (double) rand ()) / (RAND_MAX
+ 1.0));
3775 if (num_inferiors
> 1)
3776 infrun_debug_printf ("Found %d inferiors, starting at #%d",
3777 num_inferiors
, random_selector
);
3779 /* Select the Nth inferior that matched. */
3781 inferior
*selected
= nullptr;
3783 for (inferior
*inf
: all_inferiors ())
3784 if (inferior_matches (inf
))
3785 if (random_selector
-- == 0)
3791 /* Now poll for events out of each of the matching inferior's
3792 targets, starting from the selected one. */
3794 auto do_wait
= [&] (inferior
*inf
)
3796 ecs
->ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
->ws
, options
);
3797 ecs
->target
= inf
->process_target ();
3798 return (ecs
->ws
.kind () != TARGET_WAITKIND_IGNORE
);
3801 /* Needed in 'all-stop + target-non-stop' mode, because we end up
3802 here spuriously after the target is all stopped and we've already
3803 reported the stop to the user, polling for events. */
3804 scoped_restore_current_thread restore_thread
;
3806 intrusive_list_iterator
<inferior
> start
3807 = inferior_list
.iterator_to (*selected
);
3809 for (intrusive_list_iterator
<inferior
> it
= start
;
3810 it
!= inferior_list
.end ();
3813 inferior
*inf
= &*it
;
3815 if (inferior_matches (inf
) && do_wait (inf
))
3819 for (intrusive_list_iterator
<inferior
> it
= inferior_list
.begin ();
3823 inferior
*inf
= &*it
;
3825 if (inferior_matches (inf
) && do_wait (inf
))
3829 ecs
->ws
.set_ignore ();
3833 /* An event reported by wait_one. */
3835 struct wait_one_event
3837 /* The target the event came out of. */
3838 process_stratum_target
*target
;
3840 /* The PTID the event was for. */
3843 /* The waitstatus. */
3844 target_waitstatus ws
;
3847 static bool handle_one (const wait_one_event
&event
);
3849 /* Prepare and stabilize the inferior for detaching it. E.g.,
3850 detaching while a thread is displaced stepping is a recipe for
3851 crashing it, as nothing would readjust the PC out of the scratch
3855 prepare_for_detach (void)
3857 struct inferior
*inf
= current_inferior ();
3858 ptid_t pid_ptid
= ptid_t (inf
->pid
);
3859 scoped_restore_current_thread restore_thread
;
3861 scoped_restore restore_detaching
= make_scoped_restore (&inf
->detaching
, true);
3863 /* Remove all threads of INF from the global step-over chain. We
3864 want to stop any ongoing step-over, not start any new one. */
3865 thread_step_over_list_safe_range range
3866 = make_thread_step_over_list_safe_range (global_thread_step_over_list
);
3868 for (thread_info
*tp
: range
)
3871 infrun_debug_printf ("removing thread %s from global step over chain",
3872 tp
->ptid
.to_string ().c_str ());
3873 global_thread_step_over_chain_remove (tp
);
3876 /* If we were already in the middle of an inline step-over, and the
3877 thread stepping belongs to the inferior we're detaching, we need
3878 to restart the threads of other inferiors. */
3879 if (step_over_info
.thread
!= -1)
3881 infrun_debug_printf ("inline step-over in-process while detaching");
3883 thread_info
*thr
= find_thread_global_id (step_over_info
.thread
);
3884 if (thr
->inf
== inf
)
3886 /* Since we removed threads of INF from the step-over chain,
3887 we know this won't start a step-over for INF. */
3888 clear_step_over_info ();
3890 if (target_is_non_stop_p ())
3892 /* Start a new step-over in another thread if there's
3893 one that needs it. */
3896 /* Restart all other threads (except the
3897 previously-stepping thread, since that one is still
3899 if (!step_over_info_valid_p ())
3900 restart_threads (thr
);
3905 if (displaced_step_in_progress (inf
))
3907 infrun_debug_printf ("displaced-stepping in-process while detaching");
3909 /* Stop threads currently displaced stepping, aborting it. */
3911 for (thread_info
*thr
: inf
->non_exited_threads ())
3913 if (thr
->displaced_step_state
.in_progress ())
3915 if (thr
->executing ())
3917 if (!thr
->stop_requested
)
3919 target_stop (thr
->ptid
);
3920 thr
->stop_requested
= true;
3924 thr
->set_resumed (false);
3928 while (displaced_step_in_progress (inf
))
3930 wait_one_event event
;
3932 event
.target
= inf
->process_target ();
3933 event
.ptid
= do_target_wait_1 (inf
, pid_ptid
, &event
.ws
, 0);
3936 print_target_wait_results (pid_ptid
, event
.ptid
, event
.ws
);
3941 /* It's OK to leave some of the threads of INF stopped, since
3942 they'll be detached shortly. */
3946 /* If all-stop, but there exists a non-stop target, stop all threads
3947 now that we're presenting the stop to the user. */
3950 stop_all_threads_if_all_stop_mode ()
3952 if (!non_stop
&& exists_non_stop_target ())
3953 stop_all_threads ("presenting stop to user in all-stop");
3956 /* Wait for control to return from inferior to debugger.
3958 If inferior gets a signal, we may decide to start it up again
3959 instead of returning. That is why there is a loop in this function.
3960 When this function actually returns it means the inferior
3961 should be left stopped and GDB should read more commands. */
3964 wait_for_inferior (inferior
*inf
)
3966 infrun_debug_printf ("wait_for_inferior ()");
3968 SCOPE_EXIT
{ delete_just_stopped_threads_infrun_breakpoints (); };
3970 /* If an error happens while handling the event, propagate GDB's
3971 knowledge of the executing state to the frontend/user running
3973 scoped_finish_thread_state finish_state
3974 (inf
->process_target (), minus_one_ptid
);
3978 execution_control_state ecs
;
3980 overlay_cache_invalid
= 1;
3982 /* Flush target cache before starting to handle each event.
3983 Target was running and cache could be stale. This is just a
3984 heuristic. Running threads may modify target memory, but we
3985 don't get any event. */
3986 target_dcache_invalidate ();
3988 ecs
.ptid
= do_target_wait_1 (inf
, minus_one_ptid
, &ecs
.ws
, 0);
3989 ecs
.target
= inf
->process_target ();
3992 print_target_wait_results (minus_one_ptid
, ecs
.ptid
, ecs
.ws
);
3994 /* Now figure out what to do with the result of the result. */
3995 handle_inferior_event (&ecs
);
3997 if (!ecs
.wait_some_more
)
4001 stop_all_threads_if_all_stop_mode ();
4003 /* No error, don't finish the state yet. */
4004 finish_state
.release ();
4007 /* Cleanup that reinstalls the readline callback handler, if the
4008 target is running in the background. If while handling the target
4009 event something triggered a secondary prompt, like e.g., a
4010 pagination prompt, we'll have removed the callback handler (see
4011 gdb_readline_wrapper_line). Need to do this as we go back to the
4012 event loop, ready to process further input. Note this has no
4013 effect if the handler hasn't actually been removed, because calling
4014 rl_callback_handler_install resets the line buffer, thus losing
4018 reinstall_readline_callback_handler_cleanup ()
4020 struct ui
*ui
= current_ui
;
4024 /* We're not going back to the top level event loop yet. Don't
4025 install the readline callback, as it'd prep the terminal,
4026 readline-style (raw, noecho) (e.g., --batch). We'll install
4027 it the next time the prompt is displayed, when we're ready
4032 if (ui
->command_editing
&& ui
->prompt_state
!= PROMPT_BLOCKED
)
4033 gdb_rl_callback_handler_reinstall ();
4036 /* Clean up the FSMs of threads that are now stopped. In non-stop,
4037 that's just the event thread. In all-stop, that's all threads. */
4040 clean_up_just_stopped_threads_fsms (struct execution_control_state
*ecs
)
4042 /* The first clean_up call below assumes the event thread is the current
4044 if (ecs
->event_thread
!= nullptr)
4045 gdb_assert (ecs
->event_thread
== inferior_thread ());
4047 if (ecs
->event_thread
!= nullptr
4048 && ecs
->event_thread
->thread_fsm () != nullptr)
4049 ecs
->event_thread
->thread_fsm ()->clean_up (ecs
->event_thread
);
4053 scoped_restore_current_thread restore_thread
;
4055 for (thread_info
*thr
: all_non_exited_threads ())
4057 if (thr
->thread_fsm () == nullptr)
4059 if (thr
== ecs
->event_thread
)
4062 switch_to_thread (thr
);
4063 thr
->thread_fsm ()->clean_up (thr
);
4068 /* Helper for all_uis_check_sync_execution_done that works on the
4072 check_curr_ui_sync_execution_done (void)
4074 struct ui
*ui
= current_ui
;
4076 if (ui
->prompt_state
== PROMPT_NEEDED
4078 && !gdb_in_secondary_prompt_p (ui
))
4080 target_terminal::ours ();
4081 gdb::observers::sync_execution_done
.notify ();
4082 ui
->register_file_handler ();
4089 all_uis_check_sync_execution_done (void)
4091 SWITCH_THRU_ALL_UIS ()
4093 check_curr_ui_sync_execution_done ();
4100 all_uis_on_sync_execution_starting (void)
4102 SWITCH_THRU_ALL_UIS ()
4104 if (current_ui
->prompt_state
== PROMPT_NEEDED
)
4105 async_disable_stdin ();
4109 /* A quit_handler callback installed while we're handling inferior
4113 infrun_quit_handler ()
4115 if (target_terminal::is_ours ())
4119 default_quit_handler would throw a quit in this case, but if
4120 we're handling an event while we have the terminal, it means
4121 the target is running a background execution command, and
4122 thus when users press Ctrl-C, they're wanting to interrupt
4123 whatever command they were executing in the command line.
4127 (gdb) foo bar whatever<ctrl-c>
4129 That Ctrl-C should clear the input line, not interrupt event
4130 handling if it happens that the user types Ctrl-C at just the
4133 It's as-if background event handling was handled by a
4134 separate background thread.
4136 To be clear, the Ctrl-C is not lost -- it will be processed
4137 by the next QUIT call once we're out of fetch_inferior_event
4142 if (check_quit_flag ())
4143 target_pass_ctrlc ();
4147 /* Asynchronous version of wait_for_inferior. It is called by the
4148 event loop whenever a change of state is detected on the file
4149 descriptor corresponding to the target. It can be called more than
4150 once to complete a single execution command. In such cases we need
4151 to keep the state in a global variable ECSS. If it is the last time
4152 that this function is called for a single execution command, then
4153 report to the user that the inferior has stopped, and do the
4154 necessary cleanups. */
4157 fetch_inferior_event ()
4159 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
4161 execution_control_state ecs
;
4164 /* Events are always processed with the main UI as current UI. This
4165 way, warnings, debug output, etc. are always consistently sent to
4166 the main console. */
4167 scoped_restore save_ui
= make_scoped_restore (¤t_ui
, main_ui
);
4169 /* Temporarily disable pagination. Otherwise, the user would be
4170 given an option to press 'q' to quit, which would cause an early
4171 exit and could leave GDB in a half-baked state. */
4172 scoped_restore save_pagination
4173 = make_scoped_restore (&pagination_enabled
, false);
4175 /* Install a quit handler that does nothing if we have the terminal
4176 (meaning the target is running a background execution command),
4177 so that Ctrl-C never interrupts GDB before the event is fully
4179 scoped_restore restore_quit_handler
4180 = make_scoped_restore (&quit_handler
, infrun_quit_handler
);
4182 /* Make sure a SIGINT does not interrupt an extension language while
4183 we're handling an event. That could interrupt a Python unwinder
4184 or a Python observer or some such. A Ctrl-C should either be
4185 forwarded to the inferior if the inferior has the terminal, or,
4186 if GDB has the terminal, should interrupt the command the user is
4187 typing in the CLI. */
4188 scoped_disable_cooperative_sigint_handling restore_coop_sigint
;
4190 /* End up with readline processing input, if necessary. */
4192 SCOPE_EXIT
{ reinstall_readline_callback_handler_cleanup (); };
4194 /* We're handling a live event, so make sure we're doing live
4195 debugging. If we're looking at traceframes while the target is
4196 running, we're going to need to get back to that mode after
4197 handling the event. */
4198 gdb::optional
<scoped_restore_current_traceframe
> maybe_restore_traceframe
;
4201 maybe_restore_traceframe
.emplace ();
4202 set_current_traceframe (-1);
4205 /* The user/frontend should not notice a thread switch due to
4206 internal events. Make sure we revert to the user selected
4207 thread and frame after handling the event and running any
4208 breakpoint commands. */
4209 scoped_restore_current_thread restore_thread
;
4211 overlay_cache_invalid
= 1;
4212 /* Flush target cache before starting to handle each event. Target
4213 was running and cache could be stale. This is just a heuristic.
4214 Running threads may modify target memory, but we don't get any
4216 target_dcache_invalidate ();
4218 scoped_restore save_exec_dir
4219 = make_scoped_restore (&execution_direction
,
4220 target_execution_direction ());
4222 /* Allow targets to pause their resumed threads while we handle
4224 scoped_disable_commit_resumed
disable_commit_resumed ("handling event");
4226 if (!do_target_wait (&ecs
, TARGET_WNOHANG
))
4228 infrun_debug_printf ("do_target_wait returned no event");
4229 disable_commit_resumed
.reset_and_commit ();
4233 gdb_assert (ecs
.ws
.kind () != TARGET_WAITKIND_IGNORE
);
4235 /* Switch to the target that generated the event, so we can do
4237 switch_to_target_no_thread (ecs
.target
);
4240 print_target_wait_results (minus_one_ptid
, ecs
.ptid
, ecs
.ws
);
4242 /* If an error happens while handling the event, propagate GDB's
4243 knowledge of the executing state to the frontend/user running
4245 ptid_t finish_ptid
= !target_is_non_stop_p () ? minus_one_ptid
: ecs
.ptid
;
4246 scoped_finish_thread_state
finish_state (ecs
.target
, finish_ptid
);
4248 /* Get executed before scoped_restore_current_thread above to apply
4249 still for the thread which has thrown the exception. */
4250 auto defer_bpstat_clear
4251 = make_scope_exit (bpstat_clear_actions
);
4252 auto defer_delete_threads
4253 = make_scope_exit (delete_just_stopped_threads_infrun_breakpoints
);
4255 /* Now figure out what to do with the result of the result. */
4256 handle_inferior_event (&ecs
);
4258 if (!ecs
.wait_some_more
)
4260 struct inferior
*inf
= find_inferior_ptid (ecs
.target
, ecs
.ptid
);
4261 bool should_stop
= true;
4262 struct thread_info
*thr
= ecs
.event_thread
;
4264 delete_just_stopped_threads_infrun_breakpoints ();
4266 if (thr
!= nullptr && thr
->thread_fsm () != nullptr)
4267 should_stop
= thr
->thread_fsm ()->should_stop (thr
);
4275 bool should_notify_stop
= true;
4276 bool proceeded
= false;
4278 stop_all_threads_if_all_stop_mode ();
4280 clean_up_just_stopped_threads_fsms (&ecs
);
4282 if (thr
!= nullptr && thr
->thread_fsm () != nullptr)
4284 = thr
->thread_fsm ()->should_notify_stop ();
4286 if (should_notify_stop
)
4288 /* We may not find an inferior if this was a process exit. */
4289 if (inf
== nullptr || inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
4290 proceeded
= normal_stop ();
4295 inferior_event_handler (INF_EXEC_COMPLETE
);
4299 /* If we got a TARGET_WAITKIND_NO_RESUMED event, then the
4300 previously selected thread is gone. We have two
4301 choices - switch to no thread selected, or restore the
4302 previously selected thread (now exited). We chose the
4303 later, just because that's what GDB used to do. After
4304 this, "info threads" says "The current thread <Thread
4305 ID 2> has terminated." instead of "No thread
4309 && ecs
.ws
.kind () != TARGET_WAITKIND_NO_RESUMED
)
4310 restore_thread
.dont_restore ();
4314 defer_delete_threads
.release ();
4315 defer_bpstat_clear
.release ();
4317 /* No error, don't finish the thread states yet. */
4318 finish_state
.release ();
4320 disable_commit_resumed
.reset_and_commit ();
4322 /* This scope is used to ensure that readline callbacks are
4323 reinstalled here. */
4326 /* Handling this event might have caused some inferiors to become prunable.
4327 For example, the exit of an inferior that was automatically added. Try
4328 to get rid of them. Keeping those around slows down things linearly.
4330 Note that this never removes the current inferior. Therefore, call this
4331 after RESTORE_THREAD went out of scope, in case the event inferior (which was
4332 temporarily made the current inferior) is meant to be deleted.
4334 Call this before all_uis_check_sync_execution_done, so that notifications about
4335 removed inferiors appear before the prompt. */
4338 /* If a UI was in sync execution mode, and now isn't, restore its
4339 prompt (a synchronous execution command has finished, and we're
4340 ready for input). */
4341 all_uis_check_sync_execution_done ();
4344 && exec_done_display_p
4345 && (inferior_ptid
== null_ptid
4346 || inferior_thread ()->state
!= THREAD_RUNNING
))
4347 gdb_printf (_("completed.\n"));
4353 set_step_info (thread_info
*tp
, frame_info_ptr frame
,
4354 struct symtab_and_line sal
)
4356 /* This can be removed once this function no longer implicitly relies on the
4357 inferior_ptid value. */
4358 gdb_assert (inferior_ptid
== tp
->ptid
);
4360 tp
->control
.step_frame_id
= get_frame_id (frame
);
4361 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
4363 tp
->current_symtab
= sal
.symtab
;
4364 tp
->current_line
= sal
.line
;
4367 ("symtab = %s, line = %d, step_frame_id = %s, step_stack_frame_id = %s",
4368 tp
->current_symtab
!= nullptr ? tp
->current_symtab
->filename
: "<null>",
4370 tp
->control
.step_frame_id
.to_string ().c_str (),
4371 tp
->control
.step_stack_frame_id
.to_string ().c_str ());
4374 /* Clear context switchable stepping state. */
4377 init_thread_stepping_state (struct thread_info
*tss
)
4379 tss
->stepped_breakpoint
= 0;
4380 tss
->stepping_over_breakpoint
= 0;
4381 tss
->stepping_over_watchpoint
= 0;
4382 tss
->step_after_step_resume_breakpoint
= 0;
4388 set_last_target_status (process_stratum_target
*target
, ptid_t ptid
,
4389 const target_waitstatus
&status
)
4391 target_last_proc_target
= target
;
4392 target_last_wait_ptid
= ptid
;
4393 target_last_waitstatus
= status
;
4399 get_last_target_status (process_stratum_target
**target
, ptid_t
*ptid
,
4400 target_waitstatus
*status
)
4402 if (target
!= nullptr)
4403 *target
= target_last_proc_target
;
4404 if (ptid
!= nullptr)
4405 *ptid
= target_last_wait_ptid
;
4406 if (status
!= nullptr)
4407 *status
= target_last_waitstatus
;
4413 nullify_last_target_wait_ptid (void)
4415 target_last_proc_target
= nullptr;
4416 target_last_wait_ptid
= minus_one_ptid
;
4417 target_last_waitstatus
= {};
4420 /* Switch thread contexts. */
4423 context_switch (execution_control_state
*ecs
)
4425 if (ecs
->ptid
!= inferior_ptid
4426 && (inferior_ptid
== null_ptid
4427 || ecs
->event_thread
!= inferior_thread ()))
4429 infrun_debug_printf ("Switching context from %s to %s",
4430 inferior_ptid
.to_string ().c_str (),
4431 ecs
->ptid
.to_string ().c_str ());
4434 switch_to_thread (ecs
->event_thread
);
4437 /* If the target can't tell whether we've hit breakpoints
4438 (target_supports_stopped_by_sw_breakpoint), and we got a SIGTRAP,
4439 check whether that could have been caused by a breakpoint. If so,
4440 adjust the PC, per gdbarch_decr_pc_after_break. */
4443 adjust_pc_after_break (struct thread_info
*thread
,
4444 const target_waitstatus
&ws
)
4446 struct regcache
*regcache
;
4447 struct gdbarch
*gdbarch
;
4448 CORE_ADDR breakpoint_pc
, decr_pc
;
4450 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
4451 we aren't, just return.
4453 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
4454 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
4455 implemented by software breakpoints should be handled through the normal
4458 NOTE drow/2004-01-31: On some targets, breakpoints may generate
4459 different signals (SIGILL or SIGEMT for instance), but it is less
4460 clear where the PC is pointing afterwards. It may not match
4461 gdbarch_decr_pc_after_break. I don't know any specific target that
4462 generates these signals at breakpoints (the code has been in GDB since at
4463 least 1992) so I can not guess how to handle them here.
4465 In earlier versions of GDB, a target with
4466 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
4467 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
4468 target with both of these set in GDB history, and it seems unlikely to be
4469 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
4471 if (ws
.kind () != TARGET_WAITKIND_STOPPED
)
4474 if (ws
.sig () != GDB_SIGNAL_TRAP
)
4477 /* In reverse execution, when a breakpoint is hit, the instruction
4478 under it has already been de-executed. The reported PC always
4479 points at the breakpoint address, so adjusting it further would
4480 be wrong. E.g., consider this case on a decr_pc_after_break == 1
4483 B1 0x08000000 : INSN1
4484 B2 0x08000001 : INSN2
4486 PC -> 0x08000003 : INSN4
4488 Say you're stopped at 0x08000003 as above. Reverse continuing
4489 from that point should hit B2 as below. Reading the PC when the
4490 SIGTRAP is reported should read 0x08000001 and INSN2 should have
4491 been de-executed already.
4493 B1 0x08000000 : INSN1
4494 B2 PC -> 0x08000001 : INSN2
4498 We can't apply the same logic as for forward execution, because
4499 we would wrongly adjust the PC to 0x08000000, since there's a
4500 breakpoint at PC - 1. We'd then report a hit on B1, although
4501 INSN1 hadn't been de-executed yet. Doing nothing is the correct
4503 if (execution_direction
== EXEC_REVERSE
)
4506 /* If the target can tell whether the thread hit a SW breakpoint,
4507 trust it. Targets that can tell also adjust the PC
4509 if (target_supports_stopped_by_sw_breakpoint ())
4512 /* Note that relying on whether a breakpoint is planted in memory to
4513 determine this can fail. E.g,. the breakpoint could have been
4514 removed since. Or the thread could have been told to step an
4515 instruction the size of a breakpoint instruction, and only
4516 _after_ was a breakpoint inserted at its address. */
4518 /* If this target does not decrement the PC after breakpoints, then
4519 we have nothing to do. */
4520 regcache
= get_thread_regcache (thread
);
4521 gdbarch
= regcache
->arch ();
4523 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4527 const address_space
*aspace
= regcache
->aspace ();
4529 /* Find the location where (if we've hit a breakpoint) the
4530 breakpoint would be. */
4531 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
4533 /* If the target can't tell whether a software breakpoint triggered,
4534 fallback to figuring it out based on breakpoints we think were
4535 inserted in the target, and on whether the thread was stepped or
4538 /* Check whether there actually is a software breakpoint inserted at
4541 If in non-stop mode, a race condition is possible where we've
4542 removed a breakpoint, but stop events for that breakpoint were
4543 already queued and arrive later. To suppress those spurious
4544 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
4545 and retire them after a number of stop events are reported. Note
4546 this is an heuristic and can thus get confused. The real fix is
4547 to get the "stopped by SW BP and needs adjustment" info out of
4548 the target/kernel (and thus never reach here; see above). */
4549 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
4550 || (target_is_non_stop_p ()
4551 && moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
4553 gdb::optional
<scoped_restore_tmpl
<int>> restore_operation_disable
;
4555 if (record_full_is_used ())
4556 restore_operation_disable
.emplace
4557 (record_full_gdb_operation_disable_set ());
4559 /* When using hardware single-step, a SIGTRAP is reported for both
4560 a completed single-step and a software breakpoint. Need to
4561 differentiate between the two, as the latter needs adjusting
4562 but the former does not.
4564 The SIGTRAP can be due to a completed hardware single-step only if
4565 - we didn't insert software single-step breakpoints
4566 - this thread is currently being stepped
4568 If any of these events did not occur, we must have stopped due
4569 to hitting a software breakpoint, and have to back up to the
4572 As a special case, we could have hardware single-stepped a
4573 software breakpoint. In this case (prev_pc == breakpoint_pc),
4574 we also need to back up to the breakpoint address. */
4576 if (thread_has_single_step_breakpoints_set (thread
)
4577 || !currently_stepping (thread
)
4578 || (thread
->stepped_breakpoint
4579 && thread
->prev_pc
== breakpoint_pc
))
4580 regcache_write_pc (regcache
, breakpoint_pc
);
4585 stepped_in_from (frame_info_ptr frame
, struct frame_id step_frame_id
)
4587 for (frame
= get_prev_frame (frame
);
4589 frame
= get_prev_frame (frame
))
4591 if (get_frame_id (frame
) == step_frame_id
)
4594 if (get_frame_type (frame
) != INLINE_FRAME
)
4601 /* Look for an inline frame that is marked for skip.
4602 If PREV_FRAME is TRUE start at the previous frame,
4603 otherwise start at the current frame. Stop at the
4604 first non-inline frame, or at the frame where the
4608 inline_frame_is_marked_for_skip (bool prev_frame
, struct thread_info
*tp
)
4610 frame_info_ptr frame
= get_current_frame ();
4613 frame
= get_prev_frame (frame
);
4615 for (; frame
!= nullptr; frame
= get_prev_frame (frame
))
4617 const char *fn
= nullptr;
4618 symtab_and_line sal
;
4621 if (get_frame_id (frame
) == tp
->control
.step_frame_id
)
4623 if (get_frame_type (frame
) != INLINE_FRAME
)
4626 sal
= find_frame_sal (frame
);
4627 sym
= get_frame_function (frame
);
4630 fn
= sym
->print_name ();
4633 && function_name_is_marked_for_skip (fn
, sal
))
4640 /* If the event thread has the stop requested flag set, pretend it
4641 stopped for a GDB_SIGNAL_0 (i.e., as if it stopped due to
4645 handle_stop_requested (struct execution_control_state
*ecs
)
4647 if (ecs
->event_thread
->stop_requested
)
4649 ecs
->ws
.set_stopped (GDB_SIGNAL_0
);
4650 handle_signal_stop (ecs
);
4656 /* Auxiliary function that handles syscall entry/return events.
4657 It returns true if the inferior should keep going (and GDB
4658 should ignore the event), or false if the event deserves to be
4662 handle_syscall_event (struct execution_control_state
*ecs
)
4664 struct regcache
*regcache
;
4667 context_switch (ecs
);
4669 regcache
= get_thread_regcache (ecs
->event_thread
);
4670 syscall_number
= ecs
->ws
.syscall_number ();
4671 ecs
->event_thread
->set_stop_pc (regcache_read_pc (regcache
));
4673 if (catch_syscall_enabled () > 0
4674 && catching_syscall_number (syscall_number
))
4676 infrun_debug_printf ("syscall number=%d", syscall_number
);
4678 ecs
->event_thread
->control
.stop_bpstat
4679 = bpstat_stop_status_nowatch (regcache
->aspace (),
4680 ecs
->event_thread
->stop_pc (),
4681 ecs
->event_thread
, ecs
->ws
);
4683 if (handle_stop_requested (ecs
))
4686 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4688 /* Catchpoint hit. */
4693 if (handle_stop_requested (ecs
))
4696 /* If no catchpoint triggered for this, then keep going. */
4702 /* Lazily fill in the execution_control_state's stop_func_* fields. */
4705 fill_in_stop_func (struct gdbarch
*gdbarch
,
4706 struct execution_control_state
*ecs
)
4708 if (!ecs
->stop_func_filled_in
)
4711 const general_symbol_info
*gsi
;
4713 /* Don't care about return value; stop_func_start and stop_func_name
4714 will both be 0 if it doesn't work. */
4715 find_pc_partial_function_sym (ecs
->event_thread
->stop_pc (),
4717 &ecs
->stop_func_start
,
4718 &ecs
->stop_func_end
,
4720 ecs
->stop_func_name
= gsi
== nullptr ? nullptr : gsi
->print_name ();
4722 /* The call to find_pc_partial_function, above, will set
4723 stop_func_start and stop_func_end to the start and end
4724 of the range containing the stop pc. If this range
4725 contains the entry pc for the block (which is always the
4726 case for contiguous blocks), advance stop_func_start past
4727 the function's start offset and entrypoint. Note that
4728 stop_func_start is NOT advanced when in a range of a
4729 non-contiguous block that does not contain the entry pc. */
4730 if (block
!= nullptr
4731 && ecs
->stop_func_start
<= block
->entry_pc ()
4732 && block
->entry_pc () < ecs
->stop_func_end
)
4734 ecs
->stop_func_start
4735 += gdbarch_deprecated_function_start_offset (gdbarch
);
4737 if (gdbarch_skip_entrypoint_p (gdbarch
))
4738 ecs
->stop_func_start
4739 = gdbarch_skip_entrypoint (gdbarch
, ecs
->stop_func_start
);
4742 ecs
->stop_func_filled_in
= 1;
4747 /* Return the STOP_SOON field of the inferior pointed at by ECS. */
4749 static enum stop_kind
4750 get_inferior_stop_soon (execution_control_state
*ecs
)
4752 struct inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
4754 gdb_assert (inf
!= nullptr);
4755 return inf
->control
.stop_soon
;
4758 /* Poll for one event out of the current target. Store the resulting
4759 waitstatus in WS, and return the event ptid. Does not block. */
4762 poll_one_curr_target (struct target_waitstatus
*ws
)
4766 overlay_cache_invalid
= 1;
4768 /* Flush target cache before starting to handle each event.
4769 Target was running and cache could be stale. This is just a
4770 heuristic. Running threads may modify target memory, but we
4771 don't get any event. */
4772 target_dcache_invalidate ();
4774 event_ptid
= target_wait (minus_one_ptid
, ws
, TARGET_WNOHANG
);
4777 print_target_wait_results (minus_one_ptid
, event_ptid
, *ws
);
4782 /* Wait for one event out of any target. */
4784 static wait_one_event
4789 for (inferior
*inf
: all_inferiors ())
4791 process_stratum_target
*target
= inf
->process_target ();
4792 if (target
== nullptr
4793 || !target
->is_async_p ()
4794 || !target
->threads_executing
)
4797 switch_to_inferior_no_thread (inf
);
4799 wait_one_event event
;
4800 event
.target
= target
;
4801 event
.ptid
= poll_one_curr_target (&event
.ws
);
4803 if (event
.ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
4805 /* If nothing is resumed, remove the target from the
4807 target_async (false);
4809 else if (event
.ws
.kind () != TARGET_WAITKIND_IGNORE
)
4813 /* Block waiting for some event. */
4820 for (inferior
*inf
: all_inferiors ())
4822 process_stratum_target
*target
= inf
->process_target ();
4823 if (target
== nullptr
4824 || !target
->is_async_p ()
4825 || !target
->threads_executing
)
4828 int fd
= target
->async_wait_fd ();
4829 FD_SET (fd
, &readfds
);
4836 /* No waitable targets left. All must be stopped. */
4837 target_waitstatus ws
;
4838 ws
.set_no_resumed ();
4839 return {nullptr, minus_one_ptid
, std::move (ws
)};
4844 int numfds
= interruptible_select (nfds
, &readfds
, 0, nullptr, 0);
4850 perror_with_name ("interruptible_select");
4855 /* Save the thread's event and stop reason to process it later. */
4858 save_waitstatus (struct thread_info
*tp
, const target_waitstatus
&ws
)
4860 infrun_debug_printf ("saving status %s for %s",
4861 ws
.to_string ().c_str (),
4862 tp
->ptid
.to_string ().c_str ());
4864 /* Record for later. */
4865 tp
->set_pending_waitstatus (ws
);
4867 if (ws
.kind () == TARGET_WAITKIND_STOPPED
4868 && ws
.sig () == GDB_SIGNAL_TRAP
)
4870 struct regcache
*regcache
= get_thread_regcache (tp
);
4871 const address_space
*aspace
= regcache
->aspace ();
4872 CORE_ADDR pc
= regcache_read_pc (regcache
);
4874 adjust_pc_after_break (tp
, tp
->pending_waitstatus ());
4876 scoped_restore_current_thread restore_thread
;
4877 switch_to_thread (tp
);
4879 if (target_stopped_by_watchpoint ())
4880 tp
->set_stop_reason (TARGET_STOPPED_BY_WATCHPOINT
);
4881 else if (target_supports_stopped_by_sw_breakpoint ()
4882 && target_stopped_by_sw_breakpoint ())
4883 tp
->set_stop_reason (TARGET_STOPPED_BY_SW_BREAKPOINT
);
4884 else if (target_supports_stopped_by_hw_breakpoint ()
4885 && target_stopped_by_hw_breakpoint ())
4886 tp
->set_stop_reason (TARGET_STOPPED_BY_HW_BREAKPOINT
);
4887 else if (!target_supports_stopped_by_hw_breakpoint ()
4888 && hardware_breakpoint_inserted_here_p (aspace
, pc
))
4889 tp
->set_stop_reason (TARGET_STOPPED_BY_HW_BREAKPOINT
);
4890 else if (!target_supports_stopped_by_sw_breakpoint ()
4891 && software_breakpoint_inserted_here_p (aspace
, pc
))
4892 tp
->set_stop_reason (TARGET_STOPPED_BY_SW_BREAKPOINT
);
4893 else if (!thread_has_single_step_breakpoints_set (tp
)
4894 && currently_stepping (tp
))
4895 tp
->set_stop_reason (TARGET_STOPPED_BY_SINGLE_STEP
);
4899 /* Mark the non-executing threads accordingly. In all-stop, all
4900 threads of all processes are stopped when we get any event
4901 reported. In non-stop mode, only the event thread stops. */
4904 mark_non_executing_threads (process_stratum_target
*target
,
4906 const target_waitstatus
&ws
)
4910 if (!target_is_non_stop_p ())
4911 mark_ptid
= minus_one_ptid
;
4912 else if (ws
.kind () == TARGET_WAITKIND_SIGNALLED
4913 || ws
.kind () == TARGET_WAITKIND_EXITED
)
4915 /* If we're handling a process exit in non-stop mode, even
4916 though threads haven't been deleted yet, one would think
4917 that there is nothing to do, as threads of the dead process
4918 will be soon deleted, and threads of any other process were
4919 left running. However, on some targets, threads survive a
4920 process exit event. E.g., for the "checkpoint" command,
4921 when the current checkpoint/fork exits, linux-fork.c
4922 automatically switches to another fork from within
4923 target_mourn_inferior, by associating the same
4924 inferior/thread to another fork. We haven't mourned yet at
4925 this point, but we must mark any threads left in the
4926 process as not-executing so that finish_thread_state marks
4927 them stopped (in the user's perspective) if/when we present
4928 the stop to the user. */
4929 mark_ptid
= ptid_t (event_ptid
.pid ());
4932 mark_ptid
= event_ptid
;
4934 set_executing (target
, mark_ptid
, false);
4936 /* Likewise the resumed flag. */
4937 set_resumed (target
, mark_ptid
, false);
4940 /* Handle one event after stopping threads. If the eventing thread
4941 reports back any interesting event, we leave it pending. If the
4942 eventing thread was in the middle of a displaced step, we
4943 cancel/finish it, and unless the thread's inferior is being
4944 detached, put the thread back in the step-over chain. Returns true
4945 if there are no resumed threads left in the target (thus there's no
4946 point in waiting further), false otherwise. */
4949 handle_one (const wait_one_event
&event
)
4952 ("%s %s", event
.ws
.to_string ().c_str (),
4953 event
.ptid
.to_string ().c_str ());
4955 if (event
.ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
4957 /* All resumed threads exited. */
4960 else if (event
.ws
.kind () == TARGET_WAITKIND_THREAD_EXITED
4961 || event
.ws
.kind () == TARGET_WAITKIND_EXITED
4962 || event
.ws
.kind () == TARGET_WAITKIND_SIGNALLED
)
4964 /* One thread/process exited/signalled. */
4966 thread_info
*t
= nullptr;
4968 /* The target may have reported just a pid. If so, try
4969 the first non-exited thread. */
4970 if (event
.ptid
.is_pid ())
4972 int pid
= event
.ptid
.pid ();
4973 inferior
*inf
= find_inferior_pid (event
.target
, pid
);
4974 for (thread_info
*tp
: inf
->non_exited_threads ())
4980 /* If there is no available thread, the event would
4981 have to be appended to a per-inferior event list,
4982 which does not exist (and if it did, we'd have
4983 to adjust run control command to be able to
4984 resume such an inferior). We assert here instead
4985 of going into an infinite loop. */
4986 gdb_assert (t
!= nullptr);
4989 ("using %s", t
->ptid
.to_string ().c_str ());
4993 t
= find_thread_ptid (event
.target
, event
.ptid
);
4994 /* Check if this is the first time we see this thread.
4995 Don't bother adding if it individually exited. */
4997 && event
.ws
.kind () != TARGET_WAITKIND_THREAD_EXITED
)
4998 t
= add_thread (event
.target
, event
.ptid
);
5003 /* Set the threads as non-executing to avoid
5004 another stop attempt on them. */
5005 switch_to_thread_no_regs (t
);
5006 mark_non_executing_threads (event
.target
, event
.ptid
,
5008 save_waitstatus (t
, event
.ws
);
5009 t
->stop_requested
= false;
5014 thread_info
*t
= find_thread_ptid (event
.target
, event
.ptid
);
5016 t
= add_thread (event
.target
, event
.ptid
);
5018 t
->stop_requested
= 0;
5019 t
->set_executing (false);
5020 t
->set_resumed (false);
5021 t
->control
.may_range_step
= 0;
5023 /* This may be the first time we see the inferior report
5025 if (t
->inf
->needs_setup
)
5027 switch_to_thread_no_regs (t
);
5031 if (event
.ws
.kind () == TARGET_WAITKIND_STOPPED
5032 && event
.ws
.sig () == GDB_SIGNAL_0
)
5034 /* We caught the event that we intended to catch, so
5035 there's no event to save as pending. */
5037 if (displaced_step_finish (t
, GDB_SIGNAL_0
)
5038 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5040 /* Add it back to the step-over queue. */
5042 ("displaced-step of %s canceled",
5043 t
->ptid
.to_string ().c_str ());
5045 t
->control
.trap_expected
= 0;
5046 if (!t
->inf
->detaching
)
5047 global_thread_step_over_chain_enqueue (t
);
5052 enum gdb_signal sig
;
5053 struct regcache
*regcache
;
5056 ("target_wait %s, saving status for %s",
5057 event
.ws
.to_string ().c_str (),
5058 t
->ptid
.to_string ().c_str ());
5060 /* Record for later. */
5061 save_waitstatus (t
, event
.ws
);
5063 sig
= (event
.ws
.kind () == TARGET_WAITKIND_STOPPED
5064 ? event
.ws
.sig () : GDB_SIGNAL_0
);
5066 if (displaced_step_finish (t
, sig
)
5067 == DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED
)
5069 /* Add it back to the step-over queue. */
5070 t
->control
.trap_expected
= 0;
5071 if (!t
->inf
->detaching
)
5072 global_thread_step_over_chain_enqueue (t
);
5075 regcache
= get_thread_regcache (t
);
5076 t
->set_stop_pc (regcache_read_pc (regcache
));
5078 infrun_debug_printf ("saved stop_pc=%s for %s "
5079 "(currently_stepping=%d)",
5080 paddress (target_gdbarch (), t
->stop_pc ()),
5081 t
->ptid
.to_string ().c_str (),
5082 currently_stepping (t
));
5092 stop_all_threads (const char *reason
, inferior
*inf
)
5094 /* We may need multiple passes to discover all threads. */
5098 gdb_assert (exists_non_stop_target ());
5100 INFRUN_SCOPED_DEBUG_START_END ("reason=%s, inf=%d", reason
,
5101 inf
!= nullptr ? inf
->num
: -1);
5103 infrun_debug_show_threads ("non-exited threads",
5104 all_non_exited_threads ());
5106 scoped_restore_current_thread restore_thread
;
5108 /* Enable thread events on relevant targets. */
5109 for (auto *target
: all_non_exited_process_targets ())
5111 if (inf
!= nullptr && inf
->process_target () != target
)
5114 switch_to_target_no_thread (target
);
5115 target_thread_events (true);
5120 /* Disable thread events on relevant targets. */
5121 for (auto *target
: all_non_exited_process_targets ())
5123 if (inf
!= nullptr && inf
->process_target () != target
)
5126 switch_to_target_no_thread (target
);
5127 target_thread_events (false);
5130 /* Use debug_prefixed_printf directly to get a meaningful function
5133 debug_prefixed_printf ("infrun", "stop_all_threads", "done");
5136 /* Request threads to stop, and then wait for the stops. Because
5137 threads we already know about can spawn more threads while we're
5138 trying to stop them, and we only learn about new threads when we
5139 update the thread list, do this in a loop, and keep iterating
5140 until two passes find no threads that need to be stopped. */
5141 for (pass
= 0; pass
< 2; pass
++, iterations
++)
5143 infrun_debug_printf ("pass=%d, iterations=%d", pass
, iterations
);
5146 int waits_needed
= 0;
5148 for (auto *target
: all_non_exited_process_targets ())
5150 if (inf
!= nullptr && inf
->process_target () != target
)
5153 switch_to_target_no_thread (target
);
5154 update_thread_list ();
5157 /* Go through all threads looking for threads that we need
5158 to tell the target to stop. */
5159 for (thread_info
*t
: all_non_exited_threads ())
5161 if (inf
!= nullptr && t
->inf
!= inf
)
5164 /* For a single-target setting with an all-stop target,
5165 we would not even arrive here. For a multi-target
5166 setting, until GDB is able to handle a mixture of
5167 all-stop and non-stop targets, simply skip all-stop
5168 targets' threads. This should be fine due to the
5169 protection of 'check_multi_target_resumption'. */
5171 switch_to_thread_no_regs (t
);
5172 if (!target_is_non_stop_p ())
5175 if (t
->executing ())
5177 /* If already stopping, don't request a stop again.
5178 We just haven't seen the notification yet. */
5179 if (!t
->stop_requested
)
5181 infrun_debug_printf (" %s executing, need stop",
5182 t
->ptid
.to_string ().c_str ());
5183 target_stop (t
->ptid
);
5184 t
->stop_requested
= 1;
5188 infrun_debug_printf (" %s executing, already stopping",
5189 t
->ptid
.to_string ().c_str ());
5192 if (t
->stop_requested
)
5197 infrun_debug_printf (" %s not executing",
5198 t
->ptid
.to_string ().c_str ());
5200 /* The thread may be not executing, but still be
5201 resumed with a pending status to process. */
5202 t
->set_resumed (false);
5206 if (waits_needed
== 0)
5209 /* If we find new threads on the second iteration, restart
5210 over. We want to see two iterations in a row with all
5215 for (int i
= 0; i
< waits_needed
; i
++)
5217 wait_one_event event
= wait_one ();
5218 if (handle_one (event
))
5225 /* Handle a TARGET_WAITKIND_NO_RESUMED event. */
5228 handle_no_resumed (struct execution_control_state
*ecs
)
5230 if (target_can_async_p ())
5232 bool any_sync
= false;
5234 for (ui
*ui
: all_uis ())
5236 if (ui
->prompt_state
== PROMPT_BLOCKED
)
5244 /* There were no unwaited-for children left in the target, but,
5245 we're not synchronously waiting for events either. Just
5248 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED (ignoring: bg)");
5249 prepare_to_wait (ecs
);
5254 /* Otherwise, if we were running a synchronous execution command, we
5255 may need to cancel it and give the user back the terminal.
5257 In non-stop mode, the target can't tell whether we've already
5258 consumed previous stop events, so it can end up sending us a
5259 no-resumed event like so:
5261 #0 - thread 1 is left stopped
5263 #1 - thread 2 is resumed and hits breakpoint
5264 -> TARGET_WAITKIND_STOPPED
5266 #2 - thread 3 is resumed and exits
5267 this is the last resumed thread, so
5268 -> TARGET_WAITKIND_NO_RESUMED
5270 #3 - gdb processes stop for thread 2 and decides to re-resume
5273 #4 - gdb processes the TARGET_WAITKIND_NO_RESUMED event.
5274 thread 2 is now resumed, so the event should be ignored.
5276 IOW, if the stop for thread 2 doesn't end a foreground command,
5277 then we need to ignore the following TARGET_WAITKIND_NO_RESUMED
5278 event. But it could be that the event meant that thread 2 itself
5279 (or whatever other thread was the last resumed thread) exited.
5281 To address this we refresh the thread list and check whether we
5282 have resumed threads _now_. In the example above, this removes
5283 thread 3 from the thread list. If thread 2 was re-resumed, we
5284 ignore this event. If we find no thread resumed, then we cancel
5285 the synchronous command and show "no unwaited-for " to the
5288 inferior
*curr_inf
= current_inferior ();
5290 scoped_restore_current_thread restore_thread
;
5291 update_thread_list ();
5295 - the current target has no thread executing, and
5296 - the current inferior is native, and
5297 - the current inferior is the one which has the terminal, and
5300 then a Ctrl-C from this point on would remain stuck in the
5301 kernel, until a thread resumes and dequeues it. That would
5302 result in the GDB CLI not reacting to Ctrl-C, not able to
5303 interrupt the program. To address this, if the current inferior
5304 no longer has any thread executing, we give the terminal to some
5305 other inferior that has at least one thread executing. */
5306 bool swap_terminal
= true;
5308 /* Whether to ignore this TARGET_WAITKIND_NO_RESUMED event, or
5309 whether to report it to the user. */
5310 bool ignore_event
= false;
5312 for (thread_info
*thread
: all_non_exited_threads ())
5314 if (swap_terminal
&& thread
->executing ())
5316 if (thread
->inf
!= curr_inf
)
5318 target_terminal::ours ();
5320 switch_to_thread (thread
);
5321 target_terminal::inferior ();
5323 swap_terminal
= false;
5326 if (!ignore_event
&& thread
->resumed ())
5328 /* Either there were no unwaited-for children left in the
5329 target at some point, but there are now, or some target
5330 other than the eventing one has unwaited-for children
5331 left. Just ignore. */
5332 infrun_debug_printf ("TARGET_WAITKIND_NO_RESUMED "
5333 "(ignoring: found resumed)");
5335 ignore_event
= true;
5338 if (ignore_event
&& !swap_terminal
)
5344 switch_to_inferior_no_thread (curr_inf
);
5345 prepare_to_wait (ecs
);
5349 /* Go ahead and report the event. */
5353 /* Given an execution control state that has been freshly filled in by
5354 an event from the inferior, figure out what it means and take
5357 The alternatives are:
5359 1) stop_waiting and return; to really stop and return to the
5362 2) keep_going and return; to wait for the next event (set
5363 ecs->event_thread->stepping_over_breakpoint to 1 to single step
5367 handle_inferior_event (struct execution_control_state
*ecs
)
5369 /* Make sure that all temporary struct value objects that were
5370 created during the handling of the event get deleted at the
5372 scoped_value_mark free_values
;
5374 infrun_debug_printf ("%s", ecs
->ws
.to_string ().c_str ());
5376 if (ecs
->ws
.kind () == TARGET_WAITKIND_IGNORE
)
5378 /* We had an event in the inferior, but we are not interested in
5379 handling it at this level. The lower layers have already
5380 done what needs to be done, if anything.
5382 One of the possible circumstances for this is when the
5383 inferior produces output for the console. The inferior has
5384 not stopped, and we are ignoring the event. Another possible
5385 circumstance is any event which the lower level knows will be
5386 reported multiple times without an intervening resume. */
5387 prepare_to_wait (ecs
);
5391 if (ecs
->ws
.kind () == TARGET_WAITKIND_THREAD_EXITED
)
5393 prepare_to_wait (ecs
);
5397 if (ecs
->ws
.kind () == TARGET_WAITKIND_NO_RESUMED
5398 && handle_no_resumed (ecs
))
5401 /* Cache the last target/ptid/waitstatus. */
5402 set_last_target_status (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5404 /* Always clear state belonging to the previous time we stopped. */
5405 stop_stack_dummy
= STOP_NONE
;
5407 if (ecs
->ws
.kind () == TARGET_WAITKIND_NO_RESUMED
)
5409 /* No unwaited-for children left. IOW, all resumed children
5411 stop_print_frame
= false;
5416 if (ecs
->ws
.kind () != TARGET_WAITKIND_EXITED
5417 && ecs
->ws
.kind () != TARGET_WAITKIND_SIGNALLED
)
5419 ecs
->event_thread
= find_thread_ptid (ecs
->target
, ecs
->ptid
);
5420 /* If it's a new thread, add it to the thread database. */
5421 if (ecs
->event_thread
== nullptr)
5422 ecs
->event_thread
= add_thread (ecs
->target
, ecs
->ptid
);
5424 /* Disable range stepping. If the next step request could use a
5425 range, this will be end up re-enabled then. */
5426 ecs
->event_thread
->control
.may_range_step
= 0;
5429 /* Dependent on valid ECS->EVENT_THREAD. */
5430 adjust_pc_after_break (ecs
->event_thread
, ecs
->ws
);
5432 /* Dependent on the current PC value modified by adjust_pc_after_break. */
5433 reinit_frame_cache ();
5435 breakpoint_retire_moribund ();
5437 /* First, distinguish signals caused by the debugger from signals
5438 that have to do with the program's own actions. Note that
5439 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
5440 on the operating system version. Here we detect when a SIGILL or
5441 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
5442 something similar for SIGSEGV, since a SIGSEGV will be generated
5443 when we're trying to execute a breakpoint instruction on a
5444 non-executable stack. This happens for call dummy breakpoints
5445 for architectures like SPARC that place call dummies on the
5447 if (ecs
->ws
.kind () == TARGET_WAITKIND_STOPPED
5448 && (ecs
->ws
.sig () == GDB_SIGNAL_ILL
5449 || ecs
->ws
.sig () == GDB_SIGNAL_SEGV
5450 || ecs
->ws
.sig () == GDB_SIGNAL_EMT
))
5452 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5454 if (breakpoint_inserted_here_p (regcache
->aspace (),
5455 regcache_read_pc (regcache
)))
5457 infrun_debug_printf ("Treating signal as SIGTRAP");
5458 ecs
->ws
.set_stopped (GDB_SIGNAL_TRAP
);
5462 mark_non_executing_threads (ecs
->target
, ecs
->ptid
, ecs
->ws
);
5464 switch (ecs
->ws
.kind ())
5466 case TARGET_WAITKIND_LOADED
:
5468 context_switch (ecs
);
5469 /* Ignore gracefully during startup of the inferior, as it might
5470 be the shell which has just loaded some objects, otherwise
5471 add the symbols for the newly loaded objects. Also ignore at
5472 the beginning of an attach or remote session; we will query
5473 the full list of libraries once the connection is
5476 stop_kind stop_soon
= get_inferior_stop_soon (ecs
);
5477 if (stop_soon
== NO_STOP_QUIETLY
)
5479 struct regcache
*regcache
;
5481 regcache
= get_thread_regcache (ecs
->event_thread
);
5483 handle_solib_event ();
5485 ecs
->event_thread
->set_stop_pc (regcache_read_pc (regcache
));
5486 ecs
->event_thread
->control
.stop_bpstat
5487 = bpstat_stop_status_nowatch (regcache
->aspace (),
5488 ecs
->event_thread
->stop_pc (),
5489 ecs
->event_thread
, ecs
->ws
);
5491 if (handle_stop_requested (ecs
))
5494 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5496 /* A catchpoint triggered. */
5497 process_event_stop_test (ecs
);
5501 /* If requested, stop when the dynamic linker notifies
5502 gdb of events. This allows the user to get control
5503 and place breakpoints in initializer routines for
5504 dynamically loaded objects (among other things). */
5505 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5506 if (stop_on_solib_events
)
5508 /* Make sure we print "Stopped due to solib-event" in
5510 stop_print_frame
= true;
5517 /* If we are skipping through a shell, or through shared library
5518 loading that we aren't interested in, resume the program. If
5519 we're running the program normally, also resume. */
5520 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
5522 /* Loading of shared libraries might have changed breakpoint
5523 addresses. Make sure new breakpoints are inserted. */
5524 if (stop_soon
== NO_STOP_QUIETLY
)
5525 insert_breakpoints ();
5526 resume (GDB_SIGNAL_0
);
5527 prepare_to_wait (ecs
);
5531 /* But stop if we're attaching or setting up a remote
5533 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
5534 || stop_soon
== STOP_QUIETLY_REMOTE
)
5536 infrun_debug_printf ("quietly stopped");
5541 internal_error (_("unhandled stop_soon: %d"), (int) stop_soon
);
5544 case TARGET_WAITKIND_SPURIOUS
:
5545 if (handle_stop_requested (ecs
))
5547 context_switch (ecs
);
5548 resume (GDB_SIGNAL_0
);
5549 prepare_to_wait (ecs
);
5552 case TARGET_WAITKIND_THREAD_CREATED
:
5553 if (handle_stop_requested (ecs
))
5555 context_switch (ecs
);
5556 if (!switch_back_to_stepped_thread (ecs
))
5560 case TARGET_WAITKIND_EXITED
:
5561 case TARGET_WAITKIND_SIGNALLED
:
5563 /* Depending on the system, ecs->ptid may point to a thread or
5564 to a process. On some targets, target_mourn_inferior may
5565 need to have access to the just-exited thread. That is the
5566 case of GNU/Linux's "checkpoint" support, for example.
5567 Call the switch_to_xxx routine as appropriate. */
5568 thread_info
*thr
= find_thread_ptid (ecs
->target
, ecs
->ptid
);
5570 switch_to_thread (thr
);
5573 inferior
*inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5574 switch_to_inferior_no_thread (inf
);
5577 handle_vfork_child_exec_or_exit (0);
5578 target_terminal::ours (); /* Must do this before mourn anyway. */
5580 /* Clearing any previous state of convenience variables. */
5581 clear_exit_convenience_vars ();
5583 if (ecs
->ws
.kind () == TARGET_WAITKIND_EXITED
)
5585 /* Record the exit code in the convenience variable $_exitcode, so
5586 that the user can inspect this again later. */
5587 set_internalvar_integer (lookup_internalvar ("_exitcode"),
5588 (LONGEST
) ecs
->ws
.exit_status ());
5590 /* Also record this in the inferior itself. */
5591 current_inferior ()->has_exit_code
= true;
5592 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.exit_status ();
5594 /* Support the --return-child-result option. */
5595 return_child_result_value
= ecs
->ws
.exit_status ();
5597 gdb::observers::exited
.notify (ecs
->ws
.exit_status ());
5601 struct gdbarch
*gdbarch
= current_inferior ()->gdbarch
;
5603 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
5605 /* Set the value of the internal variable $_exitsignal,
5606 which holds the signal uncaught by the inferior. */
5607 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
5608 gdbarch_gdb_signal_to_target (gdbarch
,
5613 /* We don't have access to the target's method used for
5614 converting between signal numbers (GDB's internal
5615 representation <-> target's representation).
5616 Therefore, we cannot do a good job at displaying this
5617 information to the user. It's better to just warn
5618 her about it (if infrun debugging is enabled), and
5620 infrun_debug_printf ("Cannot fill $_exitsignal with the correct "
5624 gdb::observers::signal_exited
.notify (ecs
->ws
.sig ());
5627 gdb_flush (gdb_stdout
);
5628 target_mourn_inferior (inferior_ptid
);
5629 stop_print_frame
= false;
5633 case TARGET_WAITKIND_FORKED
:
5634 case TARGET_WAITKIND_VFORKED
:
5635 /* Check whether the inferior is displaced stepping. */
5637 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
5638 struct gdbarch
*gdbarch
= regcache
->arch ();
5639 inferior
*parent_inf
= find_inferior_ptid (ecs
->target
, ecs
->ptid
);
5641 /* If this is a fork (child gets its own address space copy)
5642 and some displaced step buffers were in use at the time of
5643 the fork, restore the displaced step buffer bytes in the
5646 Architectures which support displaced stepping and fork
5647 events must supply an implementation of
5648 gdbarch_displaced_step_restore_all_in_ptid. This is not
5649 enforced during gdbarch validation to support architectures
5650 which support displaced stepping but not forks. */
5651 if (ecs
->ws
.kind () == TARGET_WAITKIND_FORKED
5652 && gdbarch_supports_displaced_stepping (gdbarch
))
5653 gdbarch_displaced_step_restore_all_in_ptid
5654 (gdbarch
, parent_inf
, ecs
->ws
.child_ptid ());
5656 /* If displaced stepping is supported, and thread ecs->ptid is
5657 displaced stepping. */
5658 if (displaced_step_in_progress_thread (ecs
->event_thread
))
5660 struct regcache
*child_regcache
;
5661 CORE_ADDR parent_pc
;
5663 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
5664 indicating that the displaced stepping of syscall instruction
5665 has been done. Perform cleanup for parent process here. Note
5666 that this operation also cleans up the child process for vfork,
5667 because their pages are shared. */
5668 displaced_step_finish (ecs
->event_thread
, GDB_SIGNAL_TRAP
);
5669 /* Start a new step-over in another thread if there's one
5673 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
5674 the child's PC is also within the scratchpad. Set the child's PC
5675 to the parent's PC value, which has already been fixed up.
5676 FIXME: we use the parent's aspace here, although we're touching
5677 the child, because the child hasn't been added to the inferior
5678 list yet at this point. */
5681 = get_thread_arch_aspace_regcache (parent_inf
->process_target (),
5682 ecs
->ws
.child_ptid (),
5684 parent_inf
->aspace
);
5685 /* Read PC value of parent process. */
5686 parent_pc
= regcache_read_pc (regcache
);
5688 displaced_debug_printf ("write child pc from %s to %s",
5690 regcache_read_pc (child_regcache
)),
5691 paddress (gdbarch
, parent_pc
));
5693 regcache_write_pc (child_regcache
, parent_pc
);
5697 context_switch (ecs
);
5699 /* Immediately detach breakpoints from the child before there's
5700 any chance of letting the user delete breakpoints from the
5701 breakpoint lists. If we don't do this early, it's easy to
5702 leave left over traps in the child, vis: "break foo; catch
5703 fork; c; <fork>; del; c; <child calls foo>". We only follow
5704 the fork on the last `continue', and by that time the
5705 breakpoint at "foo" is long gone from the breakpoint table.
5706 If we vforked, then we don't need to unpatch here, since both
5707 parent and child are sharing the same memory pages; we'll
5708 need to unpatch at follow/detach time instead to be certain
5709 that new breakpoints added between catchpoint hit time and
5710 vfork follow are detached. */
5711 if (ecs
->ws
.kind () != TARGET_WAITKIND_VFORKED
)
5713 /* This won't actually modify the breakpoint list, but will
5714 physically remove the breakpoints from the child. */
5715 detach_breakpoints (ecs
->ws
.child_ptid ());
5718 delete_just_stopped_threads_single_step_breakpoints ();
5720 /* In case the event is caught by a catchpoint, remember that
5721 the event is to be followed at the next resume of the thread,
5722 and not immediately. */
5723 ecs
->event_thread
->pending_follow
= ecs
->ws
;
5725 ecs
->event_thread
->set_stop_pc
5726 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
5728 ecs
->event_thread
->control
.stop_bpstat
5729 = bpstat_stop_status_nowatch (get_current_regcache ()->aspace (),
5730 ecs
->event_thread
->stop_pc (),
5731 ecs
->event_thread
, ecs
->ws
);
5733 if (handle_stop_requested (ecs
))
5736 /* If no catchpoint triggered for this, then keep going. Note
5737 that we're interested in knowing the bpstat actually causes a
5738 stop, not just if it may explain the signal. Software
5739 watchpoints, for example, always appear in the bpstat. */
5740 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5743 = (follow_fork_mode_string
== follow_fork_mode_child
);
5745 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5747 process_stratum_target
*targ
5748 = ecs
->event_thread
->inf
->process_target ();
5750 bool should_resume
= follow_fork ();
5752 /* Note that one of these may be an invalid pointer,
5753 depending on detach_fork. */
5754 thread_info
*parent
= ecs
->event_thread
;
5755 thread_info
*child
= find_thread_ptid (targ
, ecs
->ws
.child_ptid ());
5757 /* At this point, the parent is marked running, and the
5758 child is marked stopped. */
5760 /* If not resuming the parent, mark it stopped. */
5761 if (follow_child
&& !detach_fork
&& !non_stop
&& !sched_multi
)
5762 parent
->set_running (false);
5764 /* If resuming the child, mark it running. */
5765 if (follow_child
|| (!detach_fork
&& (non_stop
|| sched_multi
)))
5766 child
->set_running (true);
5768 /* In non-stop mode, also resume the other branch. */
5769 if (!detach_fork
&& (non_stop
5770 || (sched_multi
&& target_is_non_stop_p ())))
5773 switch_to_thread (parent
);
5775 switch_to_thread (child
);
5777 ecs
->event_thread
= inferior_thread ();
5778 ecs
->ptid
= inferior_ptid
;
5783 switch_to_thread (child
);
5785 switch_to_thread (parent
);
5787 ecs
->event_thread
= inferior_thread ();
5788 ecs
->ptid
= inferior_ptid
;
5792 /* Never call switch_back_to_stepped_thread if we are waiting for
5793 vfork-done (waiting for an external vfork child to exec or
5794 exit). We will resume only the vforking thread for the purpose
5795 of collecting the vfork-done event, and we will restart any
5796 step once the critical shared address space window is done. */
5799 && parent
->inf
->thread_waiting_for_vfork_done
!= nullptr)
5800 || !switch_back_to_stepped_thread (ecs
))
5807 process_event_stop_test (ecs
);
5810 case TARGET_WAITKIND_VFORK_DONE
:
5811 /* Done with the shared memory region. Re-insert breakpoints in
5812 the parent, and keep going. */
5814 context_switch (ecs
);
5816 handle_vfork_done (ecs
->event_thread
);
5817 gdb_assert (inferior_thread () == ecs
->event_thread
);
5819 if (handle_stop_requested (ecs
))
5822 if (!switch_back_to_stepped_thread (ecs
))
5824 gdb_assert (inferior_thread () == ecs
->event_thread
);
5825 /* This also takes care of reinserting breakpoints in the
5826 previously locked inferior. */
5831 case TARGET_WAITKIND_EXECD
:
5833 /* Note we can't read registers yet (the stop_pc), because we
5834 don't yet know the inferior's post-exec architecture.
5835 'stop_pc' is explicitly read below instead. */
5836 switch_to_thread_no_regs (ecs
->event_thread
);
5838 /* Do whatever is necessary to the parent branch of the vfork. */
5839 handle_vfork_child_exec_or_exit (1);
5841 /* This causes the eventpoints and symbol table to be reset.
5842 Must do this now, before trying to determine whether to
5844 follow_exec (inferior_ptid
, ecs
->ws
.execd_pathname ());
5846 /* In follow_exec we may have deleted the original thread and
5847 created a new one. Make sure that the event thread is the
5848 execd thread for that case (this is a nop otherwise). */
5849 ecs
->event_thread
= inferior_thread ();
5851 ecs
->event_thread
->set_stop_pc
5852 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
5854 ecs
->event_thread
->control
.stop_bpstat
5855 = bpstat_stop_status_nowatch (get_current_regcache ()->aspace (),
5856 ecs
->event_thread
->stop_pc (),
5857 ecs
->event_thread
, ecs
->ws
);
5859 if (handle_stop_requested (ecs
))
5862 /* If no catchpoint triggered for this, then keep going. */
5863 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
5865 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
5869 process_event_stop_test (ecs
);
5872 /* Be careful not to try to gather much state about a thread
5873 that's in a syscall. It's frequently a losing proposition. */
5874 case TARGET_WAITKIND_SYSCALL_ENTRY
:
5875 /* Getting the current syscall number. */
5876 if (handle_syscall_event (ecs
) == 0)
5877 process_event_stop_test (ecs
);
5880 /* Before examining the threads further, step this thread to
5881 get it entirely out of the syscall. (We get notice of the
5882 event when the thread is just on the verge of exiting a
5883 syscall. Stepping one instruction seems to get it back
5885 case TARGET_WAITKIND_SYSCALL_RETURN
:
5886 if (handle_syscall_event (ecs
) == 0)
5887 process_event_stop_test (ecs
);
5890 case TARGET_WAITKIND_STOPPED
:
5891 handle_signal_stop (ecs
);
5894 case TARGET_WAITKIND_NO_HISTORY
:
5895 /* Reverse execution: target ran out of history info. */
5897 /* Switch to the stopped thread. */
5898 context_switch (ecs
);
5899 infrun_debug_printf ("stopped");
5901 delete_just_stopped_threads_single_step_breakpoints ();
5902 ecs
->event_thread
->set_stop_pc
5903 (regcache_read_pc (get_thread_regcache (inferior_thread ())));
5905 if (handle_stop_requested (ecs
))
5908 gdb::observers::no_history
.notify ();
5914 /* Restart threads back to what they were trying to do back when we
5915 paused them (because of an in-line step-over or vfork, for example).
5916 The EVENT_THREAD thread is ignored (not restarted).
5918 If INF is non-nullptr, only resume threads from INF. */
5921 restart_threads (struct thread_info
*event_thread
, inferior
*inf
)
5923 INFRUN_SCOPED_DEBUG_START_END ("event_thread=%s, inf=%d",
5924 event_thread
->ptid
.to_string ().c_str (),
5925 inf
!= nullptr ? inf
->num
: -1);
5927 gdb_assert (!step_over_info_valid_p ());
5929 /* In case the instruction just stepped spawned a new thread. */
5930 update_thread_list ();
5932 for (thread_info
*tp
: all_non_exited_threads ())
5934 if (inf
!= nullptr && tp
->inf
!= inf
)
5937 if (tp
->inf
->detaching
)
5939 infrun_debug_printf ("restart threads: [%s] inferior detaching",
5940 tp
->ptid
.to_string ().c_str ());
5944 switch_to_thread_no_regs (tp
);
5946 if (tp
== event_thread
)
5948 infrun_debug_printf ("restart threads: [%s] is event thread",
5949 tp
->ptid
.to_string ().c_str ());
5953 if (!(tp
->state
== THREAD_RUNNING
|| tp
->control
.in_infcall
))
5955 infrun_debug_printf ("restart threads: [%s] not meant to be running",
5956 tp
->ptid
.to_string ().c_str ());
5962 infrun_debug_printf ("restart threads: [%s] resumed",
5963 tp
->ptid
.to_string ().c_str ());
5964 gdb_assert (tp
->executing () || tp
->has_pending_waitstatus ());
5968 if (thread_is_in_step_over_chain (tp
))
5970 infrun_debug_printf ("restart threads: [%s] needs step-over",
5971 tp
->ptid
.to_string ().c_str ());
5972 gdb_assert (!tp
->resumed ());
5977 if (tp
->has_pending_waitstatus ())
5979 infrun_debug_printf ("restart threads: [%s] has pending status",
5980 tp
->ptid
.to_string ().c_str ());
5981 tp
->set_resumed (true);
5985 gdb_assert (!tp
->stop_requested
);
5987 /* If some thread needs to start a step-over at this point, it
5988 should still be in the step-over queue, and thus skipped
5990 if (thread_still_needs_step_over (tp
))
5992 internal_error ("thread [%s] needs a step-over, but not in "
5993 "step-over queue\n",
5994 tp
->ptid
.to_string ().c_str ());
5997 if (currently_stepping (tp
))
5999 infrun_debug_printf ("restart threads: [%s] was stepping",
6000 tp
->ptid
.to_string ().c_str ());
6001 keep_going_stepped_thread (tp
);
6005 infrun_debug_printf ("restart threads: [%s] continuing",
6006 tp
->ptid
.to_string ().c_str ());
6007 execution_control_state
ecs (tp
);
6008 switch_to_thread (tp
);
6009 keep_going_pass_signal (&ecs
);
6014 /* Callback for iterate_over_threads. Find a resumed thread that has
6015 a pending waitstatus. */
6018 resumed_thread_with_pending_status (struct thread_info
*tp
,
6021 return tp
->resumed () && tp
->has_pending_waitstatus ();
6024 /* Called when we get an event that may finish an in-line or
6025 out-of-line (displaced stepping) step-over started previously.
6026 Return true if the event is processed and we should go back to the
6027 event loop; false if the caller should continue processing the
6031 finish_step_over (struct execution_control_state
*ecs
)
6033 displaced_step_finish (ecs
->event_thread
, ecs
->event_thread
->stop_signal ());
6035 bool had_step_over_info
= step_over_info_valid_p ();
6037 if (had_step_over_info
)
6039 /* If we're stepping over a breakpoint with all threads locked,
6040 then only the thread that was stepped should be reporting
6042 gdb_assert (ecs
->event_thread
->control
.trap_expected
);
6044 clear_step_over_info ();
6047 if (!target_is_non_stop_p ())
6050 /* Start a new step-over in another thread if there's one that
6054 /* If we were stepping over a breakpoint before, and haven't started
6055 a new in-line step-over sequence, then restart all other threads
6056 (except the event thread). We can't do this in all-stop, as then
6057 e.g., we wouldn't be able to issue any other remote packet until
6058 these other threads stop. */
6059 if (had_step_over_info
&& !step_over_info_valid_p ())
6061 struct thread_info
*pending
;
6063 /* If we only have threads with pending statuses, the restart
6064 below won't restart any thread and so nothing re-inserts the
6065 breakpoint we just stepped over. But we need it inserted
6066 when we later process the pending events, otherwise if
6067 another thread has a pending event for this breakpoint too,
6068 we'd discard its event (because the breakpoint that
6069 originally caused the event was no longer inserted). */
6070 context_switch (ecs
);
6071 insert_breakpoints ();
6073 restart_threads (ecs
->event_thread
);
6075 /* If we have events pending, go through handle_inferior_event
6076 again, picking up a pending event at random. This avoids
6077 thread starvation. */
6079 /* But not if we just stepped over a watchpoint in order to let
6080 the instruction execute so we can evaluate its expression.
6081 The set of watchpoints that triggered is recorded in the
6082 breakpoint objects themselves (see bp->watchpoint_triggered).
6083 If we processed another event first, that other event could
6084 clobber this info. */
6085 if (ecs
->event_thread
->stepping_over_watchpoint
)
6088 pending
= iterate_over_threads (resumed_thread_with_pending_status
,
6090 if (pending
!= nullptr)
6092 struct thread_info
*tp
= ecs
->event_thread
;
6093 struct regcache
*regcache
;
6095 infrun_debug_printf ("found resumed threads with "
6096 "pending events, saving status");
6098 gdb_assert (pending
!= tp
);
6100 /* Record the event thread's event for later. */
6101 save_waitstatus (tp
, ecs
->ws
);
6102 /* This was cleared early, by handle_inferior_event. Set it
6103 so this pending event is considered by
6105 tp
->set_resumed (true);
6107 gdb_assert (!tp
->executing ());
6109 regcache
= get_thread_regcache (tp
);
6110 tp
->set_stop_pc (regcache_read_pc (regcache
));
6112 infrun_debug_printf ("saved stop_pc=%s for %s "
6113 "(currently_stepping=%d)",
6114 paddress (target_gdbarch (), tp
->stop_pc ()),
6115 tp
->ptid
.to_string ().c_str (),
6116 currently_stepping (tp
));
6118 /* This in-line step-over finished; clear this so we won't
6119 start a new one. This is what handle_signal_stop would
6120 do, if we returned false. */
6121 tp
->stepping_over_breakpoint
= 0;
6123 /* Wake up the event loop again. */
6124 mark_async_event_handler (infrun_async_inferior_event_token
);
6126 prepare_to_wait (ecs
);
6134 /* Come here when the program has stopped with a signal. */
6137 handle_signal_stop (struct execution_control_state
*ecs
)
6139 frame_info_ptr frame
;
6140 struct gdbarch
*gdbarch
;
6141 int stopped_by_watchpoint
;
6142 enum stop_kind stop_soon
;
6145 gdb_assert (ecs
->ws
.kind () == TARGET_WAITKIND_STOPPED
);
6147 ecs
->event_thread
->set_stop_signal (ecs
->ws
.sig ());
6149 /* Do we need to clean up the state of a thread that has
6150 completed a displaced single-step? (Doing so usually affects
6151 the PC, so do it here, before we set stop_pc.) */
6152 if (finish_step_over (ecs
))
6155 /* If we either finished a single-step or hit a breakpoint, but
6156 the user wanted this thread to be stopped, pretend we got a
6157 SIG0 (generic unsignaled stop). */
6158 if (ecs
->event_thread
->stop_requested
6159 && ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
6160 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6162 ecs
->event_thread
->set_stop_pc
6163 (regcache_read_pc (get_thread_regcache (ecs
->event_thread
)));
6165 context_switch (ecs
);
6167 if (deprecated_context_hook
)
6168 deprecated_context_hook (ecs
->event_thread
->global_num
);
6172 struct regcache
*regcache
= get_thread_regcache (ecs
->event_thread
);
6173 struct gdbarch
*reg_gdbarch
= regcache
->arch ();
6176 ("stop_pc=%s", paddress (reg_gdbarch
, ecs
->event_thread
->stop_pc ()));
6177 if (target_stopped_by_watchpoint ())
6181 infrun_debug_printf ("stopped by watchpoint");
6183 if (target_stopped_data_address (current_inferior ()->top_target (),
6185 infrun_debug_printf ("stopped data address=%s",
6186 paddress (reg_gdbarch
, addr
));
6188 infrun_debug_printf ("(no data address available)");
6192 /* This is originated from start_remote(), start_inferior() and
6193 shared libraries hook functions. */
6194 stop_soon
= get_inferior_stop_soon (ecs
);
6195 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
6197 infrun_debug_printf ("quietly stopped");
6198 stop_print_frame
= true;
6203 /* This originates from attach_command(). We need to overwrite
6204 the stop_signal here, because some kernels don't ignore a
6205 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
6206 See more comments in inferior.h. On the other hand, if we
6207 get a non-SIGSTOP, report it to the user - assume the backend
6208 will handle the SIGSTOP if it should show up later.
6210 Also consider that the attach is complete when we see a
6211 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
6212 target extended-remote report it instead of a SIGSTOP
6213 (e.g. gdbserver). We already rely on SIGTRAP being our
6214 signal, so this is no exception.
6216 Also consider that the attach is complete when we see a
6217 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
6218 the target to stop all threads of the inferior, in case the
6219 low level attach operation doesn't stop them implicitly. If
6220 they weren't stopped implicitly, then the stub will report a
6221 GDB_SIGNAL_0, meaning: stopped for no particular reason
6222 other than GDB's request. */
6223 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
6224 && (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_STOP
6225 || ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6226 || ecs
->event_thread
->stop_signal () == GDB_SIGNAL_0
))
6228 stop_print_frame
= true;
6230 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6234 /* At this point, get hold of the now-current thread's frame. */
6235 frame
= get_current_frame ();
6236 gdbarch
= get_frame_arch (frame
);
6238 /* Pull the single step breakpoints out of the target. */
6239 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
6241 struct regcache
*regcache
;
6244 regcache
= get_thread_regcache (ecs
->event_thread
);
6245 const address_space
*aspace
= regcache
->aspace ();
6247 pc
= regcache_read_pc (regcache
);
6249 /* However, before doing so, if this single-step breakpoint was
6250 actually for another thread, set this thread up for moving
6252 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
6255 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
6257 infrun_debug_printf ("[%s] hit another thread's single-step "
6259 ecs
->ptid
.to_string ().c_str ());
6260 ecs
->hit_singlestep_breakpoint
= 1;
6265 infrun_debug_printf ("[%s] hit its single-step breakpoint",
6266 ecs
->ptid
.to_string ().c_str ());
6269 delete_just_stopped_threads_single_step_breakpoints ();
6271 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6272 && ecs
->event_thread
->control
.trap_expected
6273 && ecs
->event_thread
->stepping_over_watchpoint
)
6274 stopped_by_watchpoint
= 0;
6276 stopped_by_watchpoint
= watchpoints_triggered (ecs
->ws
);
6278 /* If necessary, step over this watchpoint. We'll be back to display
6280 if (stopped_by_watchpoint
6281 && (target_have_steppable_watchpoint ()
6282 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
6284 /* At this point, we are stopped at an instruction which has
6285 attempted to write to a piece of memory under control of
6286 a watchpoint. The instruction hasn't actually executed
6287 yet. If we were to evaluate the watchpoint expression
6288 now, we would get the old value, and therefore no change
6289 would seem to have occurred.
6291 In order to make watchpoints work `right', we really need
6292 to complete the memory write, and then evaluate the
6293 watchpoint expression. We do this by single-stepping the
6296 It may not be necessary to disable the watchpoint to step over
6297 it. For example, the PA can (with some kernel cooperation)
6298 single step over a watchpoint without disabling the watchpoint.
6300 It is far more common to need to disable a watchpoint to step
6301 the inferior over it. If we have non-steppable watchpoints,
6302 we must disable the current watchpoint; it's simplest to
6303 disable all watchpoints.
6305 Any breakpoint at PC must also be stepped over -- if there's
6306 one, it will have already triggered before the watchpoint
6307 triggered, and we either already reported it to the user, or
6308 it didn't cause a stop and we called keep_going. In either
6309 case, if there was a breakpoint at PC, we must be trying to
6311 ecs
->event_thread
->stepping_over_watchpoint
= 1;
6316 ecs
->event_thread
->stepping_over_breakpoint
= 0;
6317 ecs
->event_thread
->stepping_over_watchpoint
= 0;
6318 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
6319 ecs
->event_thread
->control
.stop_step
= 0;
6320 stop_print_frame
= true;
6321 stopped_by_random_signal
= 0;
6322 bpstat
*stop_chain
= nullptr;
6324 /* Hide inlined functions starting here, unless we just performed stepi or
6325 nexti. After stepi and nexti, always show the innermost frame (not any
6326 inline function call sites). */
6327 if (ecs
->event_thread
->control
.step_range_end
!= 1)
6329 const address_space
*aspace
6330 = get_thread_regcache (ecs
->event_thread
)->aspace ();
6332 /* skip_inline_frames is expensive, so we avoid it if we can
6333 determine that the address is one where functions cannot have
6334 been inlined. This improves performance with inferiors that
6335 load a lot of shared libraries, because the solib event
6336 breakpoint is defined as the address of a function (i.e. not
6337 inline). Note that we have to check the previous PC as well
6338 as the current one to catch cases when we have just
6339 single-stepped off a breakpoint prior to reinstating it.
6340 Note that we're assuming that the code we single-step to is
6341 not inline, but that's not definitive: there's nothing
6342 preventing the event breakpoint function from containing
6343 inlined code, and the single-step ending up there. If the
6344 user had set a breakpoint on that inlined code, the missing
6345 skip_inline_frames call would break things. Fortunately
6346 that's an extremely unlikely scenario. */
6347 if (!pc_at_non_inline_function (aspace
,
6348 ecs
->event_thread
->stop_pc (),
6350 && !(ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6351 && ecs
->event_thread
->control
.trap_expected
6352 && pc_at_non_inline_function (aspace
,
6353 ecs
->event_thread
->prev_pc
,
6356 stop_chain
= build_bpstat_chain (aspace
,
6357 ecs
->event_thread
->stop_pc (),
6359 skip_inline_frames (ecs
->event_thread
, stop_chain
);
6361 /* Re-fetch current thread's frame in case that invalidated
6363 frame
= get_current_frame ();
6364 gdbarch
= get_frame_arch (frame
);
6368 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6369 && ecs
->event_thread
->control
.trap_expected
6370 && gdbarch_single_step_through_delay_p (gdbarch
)
6371 && currently_stepping (ecs
->event_thread
))
6373 /* We're trying to step off a breakpoint. Turns out that we're
6374 also on an instruction that needs to be stepped multiple
6375 times before it's been fully executing. E.g., architectures
6376 with a delay slot. It needs to be stepped twice, once for
6377 the instruction and once for the delay slot. */
6378 int step_through_delay
6379 = gdbarch_single_step_through_delay (gdbarch
, frame
);
6381 if (step_through_delay
)
6382 infrun_debug_printf ("step through delay");
6384 if (ecs
->event_thread
->control
.step_range_end
== 0
6385 && step_through_delay
)
6387 /* The user issued a continue when stopped at a breakpoint.
6388 Set up for another trap and get out of here. */
6389 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6393 else if (step_through_delay
)
6395 /* The user issued a step when stopped at a breakpoint.
6396 Maybe we should stop, maybe we should not - the delay
6397 slot *might* correspond to a line of source. In any
6398 case, don't decide that here, just set
6399 ecs->stepping_over_breakpoint, making sure we
6400 single-step again before breakpoints are re-inserted. */
6401 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6405 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
6406 handles this event. */
6407 ecs
->event_thread
->control
.stop_bpstat
6408 = bpstat_stop_status (get_current_regcache ()->aspace (),
6409 ecs
->event_thread
->stop_pc (),
6410 ecs
->event_thread
, ecs
->ws
, stop_chain
);
6412 /* Following in case break condition called a
6414 stop_print_frame
= true;
6416 /* This is where we handle "moribund" watchpoints. Unlike
6417 software breakpoints traps, hardware watchpoint traps are
6418 always distinguishable from random traps. If no high-level
6419 watchpoint is associated with the reported stop data address
6420 anymore, then the bpstat does not explain the signal ---
6421 simply make sure to ignore it if `stopped_by_watchpoint' is
6424 if (ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6425 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6427 && stopped_by_watchpoint
)
6429 infrun_debug_printf ("no user watchpoint explains watchpoint SIGTRAP, "
6433 /* NOTE: cagney/2003-03-29: These checks for a random signal
6434 at one stage in the past included checks for an inferior
6435 function call's call dummy's return breakpoint. The original
6436 comment, that went with the test, read:
6438 ``End of a stack dummy. Some systems (e.g. Sony news) give
6439 another signal besides SIGTRAP, so check here as well as
6442 If someone ever tries to get call dummys on a
6443 non-executable stack to work (where the target would stop
6444 with something like a SIGSEGV), then those tests might need
6445 to be re-instated. Given, however, that the tests were only
6446 enabled when momentary breakpoints were not being used, I
6447 suspect that it won't be the case.
6449 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
6450 be necessary for call dummies on a non-executable stack on
6453 /* See if the breakpoints module can explain the signal. */
6455 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
6456 ecs
->event_thread
->stop_signal ());
6458 /* Maybe this was a trap for a software breakpoint that has since
6460 if (random_signal
&& target_stopped_by_sw_breakpoint ())
6462 if (gdbarch_program_breakpoint_here_p (gdbarch
,
6463 ecs
->event_thread
->stop_pc ()))
6465 struct regcache
*regcache
;
6468 /* Re-adjust PC to what the program would see if GDB was not
6470 regcache
= get_thread_regcache (ecs
->event_thread
);
6471 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
6474 gdb::optional
<scoped_restore_tmpl
<int>>
6475 restore_operation_disable
;
6477 if (record_full_is_used ())
6478 restore_operation_disable
.emplace
6479 (record_full_gdb_operation_disable_set ());
6481 regcache_write_pc (regcache
,
6482 ecs
->event_thread
->stop_pc () + decr_pc
);
6487 /* A delayed software breakpoint event. Ignore the trap. */
6488 infrun_debug_printf ("delayed software breakpoint trap, ignoring");
6493 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
6494 has since been removed. */
6495 if (random_signal
&& target_stopped_by_hw_breakpoint ())
6497 /* A delayed hardware breakpoint event. Ignore the trap. */
6498 infrun_debug_printf ("delayed hardware breakpoint/watchpoint "
6503 /* If not, perhaps stepping/nexting can. */
6505 random_signal
= !(ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
6506 && currently_stepping (ecs
->event_thread
));
6508 /* Perhaps the thread hit a single-step breakpoint of _another_
6509 thread. Single-step breakpoints are transparent to the
6510 breakpoints module. */
6512 random_signal
= !ecs
->hit_singlestep_breakpoint
;
6514 /* No? Perhaps we got a moribund watchpoint. */
6516 random_signal
= !stopped_by_watchpoint
;
6518 /* Always stop if the user explicitly requested this thread to
6520 if (ecs
->event_thread
->stop_requested
)
6523 infrun_debug_printf ("user-requested stop");
6526 /* For the program's own signals, act according to
6527 the signal handling tables. */
6531 /* Signal not for debugging purposes. */
6532 enum gdb_signal stop_signal
= ecs
->event_thread
->stop_signal ();
6534 infrun_debug_printf ("random signal (%s)",
6535 gdb_signal_to_symbol_string (stop_signal
));
6537 stopped_by_random_signal
= 1;
6539 /* Always stop on signals if we're either just gaining control
6540 of the program, or the user explicitly requested this thread
6541 to remain stopped. */
6542 if (stop_soon
!= NO_STOP_QUIETLY
6543 || ecs
->event_thread
->stop_requested
6544 || signal_stop_state (ecs
->event_thread
->stop_signal ()))
6550 /* Notify observers the signal has "handle print" set. Note we
6551 returned early above if stopping; normal_stop handles the
6552 printing in that case. */
6553 if (signal_print
[ecs
->event_thread
->stop_signal ()])
6555 /* The signal table tells us to print about this signal. */
6556 target_terminal::ours_for_output ();
6557 gdb::observers::signal_received
.notify (ecs
->event_thread
->stop_signal ());
6558 target_terminal::inferior ();
6561 /* Clear the signal if it should not be passed. */
6562 if (signal_program
[ecs
->event_thread
->stop_signal ()] == 0)
6563 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
6565 if (ecs
->event_thread
->prev_pc
== ecs
->event_thread
->stop_pc ()
6566 && ecs
->event_thread
->control
.trap_expected
6567 && ecs
->event_thread
->control
.step_resume_breakpoint
== nullptr)
6569 /* We were just starting a new sequence, attempting to
6570 single-step off of a breakpoint and expecting a SIGTRAP.
6571 Instead this signal arrives. This signal will take us out
6572 of the stepping range so GDB needs to remember to, when
6573 the signal handler returns, resume stepping off that
6575 /* To simplify things, "continue" is forced to use the same
6576 code paths as single-step - set a breakpoint at the
6577 signal return address and then, once hit, step off that
6579 infrun_debug_printf ("signal arrived while stepping over breakpoint");
6581 insert_hp_step_resume_breakpoint_at_frame (frame
);
6582 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6583 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6584 ecs
->event_thread
->control
.trap_expected
= 0;
6586 /* If we were nexting/stepping some other thread, switch to
6587 it, so that we don't continue it, losing control. */
6588 if (!switch_back_to_stepped_thread (ecs
))
6593 if (ecs
->event_thread
->stop_signal () != GDB_SIGNAL_0
6594 && (pc_in_thread_step_range (ecs
->event_thread
->stop_pc (),
6596 || ecs
->event_thread
->control
.step_range_end
== 1)
6597 && (get_stack_frame_id (frame
)
6598 == ecs
->event_thread
->control
.step_stack_frame_id
)
6599 && ecs
->event_thread
->control
.step_resume_breakpoint
== nullptr)
6601 /* The inferior is about to take a signal that will take it
6602 out of the single step range. Set a breakpoint at the
6603 current PC (which is presumably where the signal handler
6604 will eventually return) and then allow the inferior to
6607 Note that this is only needed for a signal delivered
6608 while in the single-step range. Nested signals aren't a
6609 problem as they eventually all return. */
6610 infrun_debug_printf ("signal may take us out of single-step range");
6612 clear_step_over_info ();
6613 insert_hp_step_resume_breakpoint_at_frame (frame
);
6614 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
6615 /* Reset trap_expected to ensure breakpoints are re-inserted. */
6616 ecs
->event_thread
->control
.trap_expected
= 0;
6621 /* Note: step_resume_breakpoint may be non-NULL. This occurs
6622 when either there's a nested signal, or when there's a
6623 pending signal enabled just as the signal handler returns
6624 (leaving the inferior at the step-resume-breakpoint without
6625 actually executing it). Either way continue until the
6626 breakpoint is really hit. */
6628 if (!switch_back_to_stepped_thread (ecs
))
6630 infrun_debug_printf ("random signal, keep going");
6637 process_event_stop_test (ecs
);
6640 /* Come here when we've got some debug event / signal we can explain
6641 (IOW, not a random signal), and test whether it should cause a
6642 stop, or whether we should resume the inferior (transparently).
6643 E.g., could be a breakpoint whose condition evaluates false; we
6644 could be still stepping within the line; etc. */
6647 process_event_stop_test (struct execution_control_state
*ecs
)
6649 struct symtab_and_line stop_pc_sal
;
6650 frame_info_ptr frame
;
6651 struct gdbarch
*gdbarch
;
6652 CORE_ADDR jmp_buf_pc
;
6653 struct bpstat_what what
;
6655 /* Handle cases caused by hitting a breakpoint. */
6657 frame
= get_current_frame ();
6658 gdbarch
= get_frame_arch (frame
);
6660 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
6662 if (what
.call_dummy
)
6664 stop_stack_dummy
= what
.call_dummy
;
6667 /* A few breakpoint types have callbacks associated (e.g.,
6668 bp_jit_event). Run them now. */
6669 bpstat_run_callbacks (ecs
->event_thread
->control
.stop_bpstat
);
6671 /* If we hit an internal event that triggers symbol changes, the
6672 current frame will be invalidated within bpstat_what (e.g., if we
6673 hit an internal solib event). Re-fetch it. */
6674 frame
= get_current_frame ();
6675 gdbarch
= get_frame_arch (frame
);
6677 switch (what
.main_action
)
6679 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
6680 /* If we hit the breakpoint at longjmp while stepping, we
6681 install a momentary breakpoint at the target of the
6684 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME");
6686 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6688 if (what
.is_longjmp
)
6690 struct value
*arg_value
;
6692 /* If we set the longjmp breakpoint via a SystemTap probe,
6693 then use it to extract the arguments. The destination PC
6694 is the third argument to the probe. */
6695 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
6698 jmp_buf_pc
= value_as_address (arg_value
);
6699 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
6701 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
6702 || !gdbarch_get_longjmp_target (gdbarch
,
6703 frame
, &jmp_buf_pc
))
6705 infrun_debug_printf ("BPSTAT_WHAT_SET_LONGJMP_RESUME "
6706 "(!gdbarch_get_longjmp_target)");
6711 /* Insert a breakpoint at resume address. */
6712 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
6715 check_exception_resume (ecs
, frame
);
6719 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
6721 frame_info_ptr init_frame
;
6723 /* There are several cases to consider.
6725 1. The initiating frame no longer exists. In this case we
6726 must stop, because the exception or longjmp has gone too
6729 2. The initiating frame exists, and is the same as the
6730 current frame. We stop, because the exception or longjmp
6733 3. The initiating frame exists and is different from the
6734 current frame. This means the exception or longjmp has
6735 been caught beneath the initiating frame, so keep going.
6737 4. longjmp breakpoint has been placed just to protect
6738 against stale dummy frames and user is not interested in
6739 stopping around longjmps. */
6741 infrun_debug_printf ("BPSTAT_WHAT_CLEAR_LONGJMP_RESUME");
6743 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
6745 delete_exception_resume_breakpoint (ecs
->event_thread
);
6747 if (what
.is_longjmp
)
6749 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
6751 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
6759 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
6763 struct frame_id current_id
6764 = get_frame_id (get_current_frame ());
6765 if (current_id
== ecs
->event_thread
->initiating_frame
)
6767 /* Case 2. Fall through. */
6777 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
6779 delete_step_resume_breakpoint (ecs
->event_thread
);
6781 end_stepping_range (ecs
);
6785 case BPSTAT_WHAT_SINGLE
:
6786 infrun_debug_printf ("BPSTAT_WHAT_SINGLE");
6787 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6788 /* Still need to check other stuff, at least the case where we
6789 are stepping and step out of the right range. */
6792 case BPSTAT_WHAT_STEP_RESUME
:
6793 infrun_debug_printf ("BPSTAT_WHAT_STEP_RESUME");
6795 delete_step_resume_breakpoint (ecs
->event_thread
);
6796 if (ecs
->event_thread
->control
.proceed_to_finish
6797 && execution_direction
== EXEC_REVERSE
)
6799 struct thread_info
*tp
= ecs
->event_thread
;
6801 /* We are finishing a function in reverse, and just hit the
6802 step-resume breakpoint at the start address of the
6803 function, and we're almost there -- just need to back up
6804 by one more single-step, which should take us back to the
6806 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
6810 fill_in_stop_func (gdbarch
, ecs
);
6811 if (ecs
->event_thread
->stop_pc () == ecs
->stop_func_start
6812 && execution_direction
== EXEC_REVERSE
)
6814 /* We are stepping over a function call in reverse, and just
6815 hit the step-resume breakpoint at the start address of
6816 the function. Go back to single-stepping, which should
6817 take us back to the function call. */
6818 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6824 case BPSTAT_WHAT_STOP_NOISY
:
6825 infrun_debug_printf ("BPSTAT_WHAT_STOP_NOISY");
6826 stop_print_frame
= true;
6828 /* Assume the thread stopped for a breakpoint. We'll still check
6829 whether a/the breakpoint is there when the thread is next
6831 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6836 case BPSTAT_WHAT_STOP_SILENT
:
6837 infrun_debug_printf ("BPSTAT_WHAT_STOP_SILENT");
6838 stop_print_frame
= false;
6840 /* Assume the thread stopped for a breakpoint. We'll still check
6841 whether a/the breakpoint is there when the thread is next
6843 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6847 case BPSTAT_WHAT_HP_STEP_RESUME
:
6848 infrun_debug_printf ("BPSTAT_WHAT_HP_STEP_RESUME");
6850 delete_step_resume_breakpoint (ecs
->event_thread
);
6851 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
6853 /* Back when the step-resume breakpoint was inserted, we
6854 were trying to single-step off a breakpoint. Go back to
6856 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6857 ecs
->event_thread
->stepping_over_breakpoint
= 1;
6863 case BPSTAT_WHAT_KEEP_CHECKING
:
6867 /* If we stepped a permanent breakpoint and we had a high priority
6868 step-resume breakpoint for the address we stepped, but we didn't
6869 hit it, then we must have stepped into the signal handler. The
6870 step-resume was only necessary to catch the case of _not_
6871 stepping into the handler, so delete it, and fall through to
6872 checking whether the step finished. */
6873 if (ecs
->event_thread
->stepped_breakpoint
)
6875 struct breakpoint
*sr_bp
6876 = ecs
->event_thread
->control
.step_resume_breakpoint
;
6878 if (sr_bp
!= nullptr
6879 && sr_bp
->loc
->permanent
6880 && sr_bp
->type
== bp_hp_step_resume
6881 && sr_bp
->loc
->address
== ecs
->event_thread
->prev_pc
)
6883 infrun_debug_printf ("stepped permanent breakpoint, stopped in handler");
6884 delete_step_resume_breakpoint (ecs
->event_thread
);
6885 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
6889 /* We come here if we hit a breakpoint but should not stop for it.
6890 Possibly we also were stepping and should stop for that. So fall
6891 through and test for stepping. But, if not stepping, do not
6894 /* In all-stop mode, if we're currently stepping but have stopped in
6895 some other thread, we need to switch back to the stepped thread. */
6896 if (switch_back_to_stepped_thread (ecs
))
6899 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
6901 infrun_debug_printf ("step-resume breakpoint is inserted");
6903 /* Having a step-resume breakpoint overrides anything
6904 else having to do with stepping commands until
6905 that breakpoint is reached. */
6910 if (ecs
->event_thread
->control
.step_range_end
== 0)
6912 infrun_debug_printf ("no stepping, continue");
6913 /* Likewise if we aren't even stepping. */
6918 /* Re-fetch current thread's frame in case the code above caused
6919 the frame cache to be re-initialized, making our FRAME variable
6920 a dangling pointer. */
6921 frame
= get_current_frame ();
6922 gdbarch
= get_frame_arch (frame
);
6923 fill_in_stop_func (gdbarch
, ecs
);
6925 /* If stepping through a line, keep going if still within it.
6927 Note that step_range_end is the address of the first instruction
6928 beyond the step range, and NOT the address of the last instruction
6931 Note also that during reverse execution, we may be stepping
6932 through a function epilogue and therefore must detect when
6933 the current-frame changes in the middle of a line. */
6935 if (pc_in_thread_step_range (ecs
->event_thread
->stop_pc (),
6937 && (execution_direction
!= EXEC_REVERSE
6938 || get_frame_id (frame
) == ecs
->event_thread
->control
.step_frame_id
))
6941 ("stepping inside range [%s-%s]",
6942 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
6943 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
6945 /* Tentatively re-enable range stepping; `resume' disables it if
6946 necessary (e.g., if we're stepping over a breakpoint or we
6947 have software watchpoints). */
6948 ecs
->event_thread
->control
.may_range_step
= 1;
6950 /* When stepping backward, stop at beginning of line range
6951 (unless it's the function entry point, in which case
6952 keep going back to the call point). */
6953 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
6954 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
6955 && stop_pc
!= ecs
->stop_func_start
6956 && execution_direction
== EXEC_REVERSE
)
6957 end_stepping_range (ecs
);
6964 /* We stepped out of the stepping range. */
6966 /* If we are stepping at the source level and entered the runtime
6967 loader dynamic symbol resolution code...
6969 EXEC_FORWARD: we keep on single stepping until we exit the run
6970 time loader code and reach the callee's address.
6972 EXEC_REVERSE: we've already executed the callee (backward), and
6973 the runtime loader code is handled just like any other
6974 undebuggable function call. Now we need only keep stepping
6975 backward through the trampoline code, and that's handled further
6976 down, so there is nothing for us to do here. */
6978 if (execution_direction
!= EXEC_REVERSE
6979 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
6980 && in_solib_dynsym_resolve_code (ecs
->event_thread
->stop_pc ())
6981 && (ecs
->event_thread
->control
.step_start_function
== nullptr
6982 || !in_solib_dynsym_resolve_code (
6983 ecs
->event_thread
->control
.step_start_function
->value_block ()
6986 CORE_ADDR pc_after_resolver
=
6987 gdbarch_skip_solib_resolver (gdbarch
, ecs
->event_thread
->stop_pc ());
6989 infrun_debug_printf ("stepped into dynsym resolve code");
6991 if (pc_after_resolver
)
6993 /* Set up a step-resume breakpoint at the address
6994 indicated by SKIP_SOLIB_RESOLVER. */
6995 symtab_and_line sr_sal
;
6996 sr_sal
.pc
= pc_after_resolver
;
6997 sr_sal
.pspace
= get_frame_program_space (frame
);
6999 insert_step_resume_breakpoint_at_sal (gdbarch
,
7000 sr_sal
, null_frame_id
);
7007 /* Step through an indirect branch thunk. */
7008 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7009 && gdbarch_in_indirect_branch_thunk (gdbarch
,
7010 ecs
->event_thread
->stop_pc ()))
7012 infrun_debug_printf ("stepped into indirect branch thunk");
7017 if (ecs
->event_thread
->control
.step_range_end
!= 1
7018 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7019 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7020 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
7022 infrun_debug_printf ("stepped into signal trampoline");
7023 /* The inferior, while doing a "step" or "next", has ended up in
7024 a signal trampoline (either by a signal being delivered or by
7025 the signal handler returning). Just single-step until the
7026 inferior leaves the trampoline (either by calling the handler
7032 /* If we're in the return path from a shared library trampoline,
7033 we want to proceed through the trampoline when stepping. */
7034 /* macro/2012-04-25: This needs to come before the subroutine
7035 call check below as on some targets return trampolines look
7036 like subroutine calls (MIPS16 return thunks). */
7037 if (gdbarch_in_solib_return_trampoline (gdbarch
,
7038 ecs
->event_thread
->stop_pc (),
7039 ecs
->stop_func_name
)
7040 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7042 /* Determine where this trampoline returns. */
7043 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7044 CORE_ADDR real_stop_pc
7045 = gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7047 infrun_debug_printf ("stepped into solib return tramp");
7049 /* Only proceed through if we know where it's going. */
7052 /* And put the step-breakpoint there and go until there. */
7053 symtab_and_line sr_sal
;
7054 sr_sal
.pc
= real_stop_pc
;
7055 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7056 sr_sal
.pspace
= get_frame_program_space (frame
);
7058 /* Do not specify what the fp should be when we stop since
7059 on some machines the prologue is where the new fp value
7061 insert_step_resume_breakpoint_at_sal (gdbarch
,
7062 sr_sal
, null_frame_id
);
7064 /* Restart without fiddling with the step ranges or
7071 /* Check for subroutine calls. The check for the current frame
7072 equalling the step ID is not necessary - the check of the
7073 previous frame's ID is sufficient - but it is a common case and
7074 cheaper than checking the previous frame's ID.
7076 NOTE: frame_id::operator== will never report two invalid frame IDs as
7077 being equal, so to get into this block, both the current and
7078 previous frame must have valid frame IDs. */
7079 /* The outer_frame_id check is a heuristic to detect stepping
7080 through startup code. If we step over an instruction which
7081 sets the stack pointer from an invalid value to a valid value,
7082 we may detect that as a subroutine call from the mythical
7083 "outermost" function. This could be fixed by marking
7084 outermost frames as !stack_p,code_p,special_p. Then the
7085 initial outermost frame, before sp was valid, would
7086 have code_addr == &_start. See the comment in frame_id::operator==
7088 if ((get_stack_frame_id (frame
)
7089 != ecs
->event_thread
->control
.step_stack_frame_id
)
7090 && ((frame_unwind_caller_id (get_current_frame ())
7091 == ecs
->event_thread
->control
.step_stack_frame_id
)
7092 && ((ecs
->event_thread
->control
.step_stack_frame_id
7094 || (ecs
->event_thread
->control
.step_start_function
7095 != find_pc_function (ecs
->event_thread
->stop_pc ())))))
7097 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7098 CORE_ADDR real_stop_pc
;
7100 infrun_debug_printf ("stepped into subroutine");
7102 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
7104 /* I presume that step_over_calls is only 0 when we're
7105 supposed to be stepping at the assembly language level
7106 ("stepi"). Just stop. */
7107 /* And this works the same backward as frontward. MVS */
7108 end_stepping_range (ecs
);
7112 /* Reverse stepping through solib trampolines. */
7114 if (execution_direction
== EXEC_REVERSE
7115 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
7116 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7117 || (ecs
->stop_func_start
== 0
7118 && in_solib_dynsym_resolve_code (stop_pc
))))
7120 /* Any solib trampoline code can be handled in reverse
7121 by simply continuing to single-step. We have already
7122 executed the solib function (backwards), and a few
7123 steps will take us back through the trampoline to the
7129 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
7131 /* We're doing a "next".
7133 Normal (forward) execution: set a breakpoint at the
7134 callee's return address (the address at which the caller
7137 Reverse (backward) execution. set the step-resume
7138 breakpoint at the start of the function that we just
7139 stepped into (backwards), and continue to there. When we
7140 get there, we'll need to single-step back to the caller. */
7142 if (execution_direction
== EXEC_REVERSE
)
7144 /* If we're already at the start of the function, we've either
7145 just stepped backward into a single instruction function,
7146 or stepped back out of a signal handler to the first instruction
7147 of the function. Just keep going, which will single-step back
7149 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
7151 /* Normal function call return (static or dynamic). */
7152 symtab_and_line sr_sal
;
7153 sr_sal
.pc
= ecs
->stop_func_start
;
7154 sr_sal
.pspace
= get_frame_program_space (frame
);
7155 insert_step_resume_breakpoint_at_sal (gdbarch
,
7156 sr_sal
, get_stack_frame_id (frame
));
7160 insert_step_resume_breakpoint_at_caller (frame
);
7166 /* If we are in a function call trampoline (a stub between the
7167 calling routine and the real function), locate the real
7168 function. That's what tells us (a) whether we want to step
7169 into it at all, and (b) what prologue we want to run to the
7170 end of, if we do step into it. */
7171 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
7172 if (real_stop_pc
== 0)
7173 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
7174 if (real_stop_pc
!= 0)
7175 ecs
->stop_func_start
= real_stop_pc
;
7177 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
7179 symtab_and_line sr_sal
;
7180 sr_sal
.pc
= ecs
->stop_func_start
;
7181 sr_sal
.pspace
= get_frame_program_space (frame
);
7183 insert_step_resume_breakpoint_at_sal (gdbarch
,
7184 sr_sal
, null_frame_id
);
7189 /* If we have line number information for the function we are
7190 thinking of stepping into and the function isn't on the skip
7193 If there are several symtabs at that PC (e.g. with include
7194 files), just want to know whether *any* of them have line
7195 numbers. find_pc_line handles this. */
7197 struct symtab_and_line tmp_sal
;
7199 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7200 if (tmp_sal
.line
!= 0
7201 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
7203 && !inline_frame_is_marked_for_skip (true, ecs
->event_thread
))
7205 if (execution_direction
== EXEC_REVERSE
)
7206 handle_step_into_function_backward (gdbarch
, ecs
);
7208 handle_step_into_function (gdbarch
, ecs
);
7213 /* If we have no line number and the step-stop-if-no-debug is
7214 set, we stop the step so that the user has a chance to switch
7215 in assembly mode. */
7216 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7217 && step_stop_if_no_debug
)
7219 end_stepping_range (ecs
);
7223 if (execution_direction
== EXEC_REVERSE
)
7225 /* If we're already at the start of the function, we've either just
7226 stepped backward into a single instruction function without line
7227 number info, or stepped back out of a signal handler to the first
7228 instruction of the function without line number info. Just keep
7229 going, which will single-step back to the caller. */
7230 if (ecs
->stop_func_start
!= stop_pc
)
7232 /* Set a breakpoint at callee's start address.
7233 From there we can step once and be back in the caller. */
7234 symtab_and_line sr_sal
;
7235 sr_sal
.pc
= ecs
->stop_func_start
;
7236 sr_sal
.pspace
= get_frame_program_space (frame
);
7237 insert_step_resume_breakpoint_at_sal (gdbarch
,
7238 sr_sal
, null_frame_id
);
7242 /* Set a breakpoint at callee's return address (the address
7243 at which the caller will resume). */
7244 insert_step_resume_breakpoint_at_caller (frame
);
7250 /* Reverse stepping through solib trampolines. */
7252 if (execution_direction
== EXEC_REVERSE
7253 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
7255 CORE_ADDR stop_pc
= ecs
->event_thread
->stop_pc ();
7257 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
7258 || (ecs
->stop_func_start
== 0
7259 && in_solib_dynsym_resolve_code (stop_pc
)))
7261 /* Any solib trampoline code can be handled in reverse
7262 by simply continuing to single-step. We have already
7263 executed the solib function (backwards), and a few
7264 steps will take us back through the trampoline to the
7269 else if (in_solib_dynsym_resolve_code (stop_pc
))
7271 /* Stepped backward into the solib dynsym resolver.
7272 Set a breakpoint at its start and continue, then
7273 one more step will take us out. */
7274 symtab_and_line sr_sal
;
7275 sr_sal
.pc
= ecs
->stop_func_start
;
7276 sr_sal
.pspace
= get_frame_program_space (frame
);
7277 insert_step_resume_breakpoint_at_sal (gdbarch
,
7278 sr_sal
, null_frame_id
);
7284 /* This always returns the sal for the inner-most frame when we are in a
7285 stack of inlined frames, even if GDB actually believes that it is in a
7286 more outer frame. This is checked for below by calls to
7287 inline_skipped_frames. */
7288 stop_pc_sal
= find_pc_line (ecs
->event_thread
->stop_pc (), 0);
7290 /* NOTE: tausq/2004-05-24: This if block used to be done before all
7291 the trampoline processing logic, however, there are some trampolines
7292 that have no names, so we should do trampoline handling first. */
7293 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
7294 && ecs
->stop_func_name
== nullptr
7295 && stop_pc_sal
.line
== 0)
7297 infrun_debug_printf ("stepped into undebuggable function");
7299 /* The inferior just stepped into, or returned to, an
7300 undebuggable function (where there is no debugging information
7301 and no line number corresponding to the address where the
7302 inferior stopped). Since we want to skip this kind of code,
7303 we keep going until the inferior returns from this
7304 function - unless the user has asked us not to (via
7305 set step-mode) or we no longer know how to get back
7306 to the call site. */
7307 if (step_stop_if_no_debug
7308 || !frame_id_p (frame_unwind_caller_id (frame
)))
7310 /* If we have no line number and the step-stop-if-no-debug
7311 is set, we stop the step so that the user has a chance to
7312 switch in assembly mode. */
7313 end_stepping_range (ecs
);
7318 /* Set a breakpoint at callee's return address (the address
7319 at which the caller will resume). */
7320 insert_step_resume_breakpoint_at_caller (frame
);
7326 if (ecs
->event_thread
->control
.step_range_end
== 1)
7328 /* It is stepi or nexti. We always want to stop stepping after
7330 infrun_debug_printf ("stepi/nexti");
7331 end_stepping_range (ecs
);
7335 if (stop_pc_sal
.line
== 0)
7337 /* We have no line number information. That means to stop
7338 stepping (does this always happen right after one instruction,
7339 when we do "s" in a function with no line numbers,
7340 or can this happen as a result of a return or longjmp?). */
7341 infrun_debug_printf ("line number info");
7342 end_stepping_range (ecs
);
7346 /* Look for "calls" to inlined functions, part one. If the inline
7347 frame machinery detected some skipped call sites, we have entered
7348 a new inline function. */
7350 if ((get_frame_id (get_current_frame ())
7351 == ecs
->event_thread
->control
.step_frame_id
)
7352 && inline_skipped_frames (ecs
->event_thread
))
7354 infrun_debug_printf ("stepped into inlined function");
7356 symtab_and_line call_sal
= find_frame_sal (get_current_frame ());
7358 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
7360 /* For "step", we're going to stop. But if the call site
7361 for this inlined function is on the same source line as
7362 we were previously stepping, go down into the function
7363 first. Otherwise stop at the call site. */
7365 if (call_sal
.line
== ecs
->event_thread
->current_line
7366 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7368 step_into_inline_frame (ecs
->event_thread
);
7369 if (inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7376 end_stepping_range (ecs
);
7381 /* For "next", we should stop at the call site if it is on a
7382 different source line. Otherwise continue through the
7383 inlined function. */
7384 if (call_sal
.line
== ecs
->event_thread
->current_line
7385 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
7388 end_stepping_range (ecs
);
7393 /* Look for "calls" to inlined functions, part two. If we are still
7394 in the same real function we were stepping through, but we have
7395 to go further up to find the exact frame ID, we are stepping
7396 through a more inlined call beyond its call site. */
7398 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
7399 && (get_frame_id (get_current_frame ())
7400 != ecs
->event_thread
->control
.step_frame_id
)
7401 && stepped_in_from (get_current_frame (),
7402 ecs
->event_thread
->control
.step_frame_id
))
7404 infrun_debug_printf ("stepping through inlined function");
7406 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
7407 || inline_frame_is_marked_for_skip (false, ecs
->event_thread
))
7410 end_stepping_range (ecs
);
7414 bool refresh_step_info
= true;
7415 if ((ecs
->event_thread
->stop_pc () == stop_pc_sal
.pc
)
7416 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
7417 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
7419 /* We are at a different line. */
7421 if (stop_pc_sal
.is_stmt
)
7423 /* We are at the start of a statement.
7425 So stop. Note that we don't stop if we step into the middle of a
7426 statement. That is said to make things like for (;;) statements
7428 infrun_debug_printf ("stepped to a different line");
7429 end_stepping_range (ecs
);
7432 else if (get_frame_id (get_current_frame ())
7433 == ecs
->event_thread
->control
.step_frame_id
)
7435 /* We are not at the start of a statement, and we have not changed
7438 We ignore this line table entry, and continue stepping forward,
7439 looking for a better place to stop. */
7440 refresh_step_info
= false;
7441 infrun_debug_printf ("stepped to a different line, but "
7442 "it's not the start of a statement");
7446 /* We are not the start of a statement, and we have changed frame.
7448 We ignore this line table entry, and continue stepping forward,
7449 looking for a better place to stop. Keep refresh_step_info at
7450 true to note that the frame has changed, but ignore the line
7451 number to make sure we don't ignore a subsequent entry with the
7452 same line number. */
7453 stop_pc_sal
.line
= 0;
7454 infrun_debug_printf ("stepped to a different frame, but "
7455 "it's not the start of a statement");
7459 /* We aren't done stepping.
7461 Optimize by setting the stepping range to the line.
7462 (We might not be in the original line, but if we entered a
7463 new line in mid-statement, we continue stepping. This makes
7464 things like for(;;) statements work better.)
7466 If we entered a SAL that indicates a non-statement line table entry,
7467 then we update the stepping range, but we don't update the step info,
7468 which includes things like the line number we are stepping away from.
7469 This means we will stop when we find a line table entry that is marked
7470 as is-statement, even if it matches the non-statement one we just
7473 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
7474 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
7475 ecs
->event_thread
->control
.may_range_step
= 1;
7477 ("updated step range, start = %s, end = %s, may_range_step = %d",
7478 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
7479 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
),
7480 ecs
->event_thread
->control
.may_range_step
);
7481 if (refresh_step_info
)
7482 set_step_info (ecs
->event_thread
, frame
, stop_pc_sal
);
7484 infrun_debug_printf ("keep going");
7488 static bool restart_stepped_thread (process_stratum_target
*resume_target
,
7489 ptid_t resume_ptid
);
7491 /* In all-stop mode, if we're currently stepping but have stopped in
7492 some other thread, we may need to switch back to the stepped
7493 thread. Returns true we set the inferior running, false if we left
7494 it stopped (and the event needs further processing). */
7497 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
7499 if (!target_is_non_stop_p ())
7501 /* If any thread is blocked on some internal breakpoint, and we
7502 simply need to step over that breakpoint to get it going
7503 again, do that first. */
7505 /* However, if we see an event for the stepping thread, then we
7506 know all other threads have been moved past their breakpoints
7507 already. Let the caller check whether the step is finished,
7508 etc., before deciding to move it past a breakpoint. */
7509 if (ecs
->event_thread
->control
.step_range_end
!= 0)
7512 /* Check if the current thread is blocked on an incomplete
7513 step-over, interrupted by a random signal. */
7514 if (ecs
->event_thread
->control
.trap_expected
7515 && ecs
->event_thread
->stop_signal () != GDB_SIGNAL_TRAP
)
7518 ("need to finish step-over of [%s]",
7519 ecs
->event_thread
->ptid
.to_string ().c_str ());
7524 /* Check if the current thread is blocked by a single-step
7525 breakpoint of another thread. */
7526 if (ecs
->hit_singlestep_breakpoint
)
7528 infrun_debug_printf ("need to step [%s] over single-step breakpoint",
7529 ecs
->ptid
.to_string ().c_str ());
7534 /* If this thread needs yet another step-over (e.g., stepping
7535 through a delay slot), do it first before moving on to
7537 if (thread_still_needs_step_over (ecs
->event_thread
))
7540 ("thread [%s] still needs step-over",
7541 ecs
->event_thread
->ptid
.to_string ().c_str ());
7546 /* If scheduler locking applies even if not stepping, there's no
7547 need to walk over threads. Above we've checked whether the
7548 current thread is stepping. If some other thread not the
7549 event thread is stepping, then it must be that scheduler
7550 locking is not in effect. */
7551 if (schedlock_applies (ecs
->event_thread
))
7554 /* Otherwise, we no longer expect a trap in the current thread.
7555 Clear the trap_expected flag before switching back -- this is
7556 what keep_going does as well, if we call it. */
7557 ecs
->event_thread
->control
.trap_expected
= 0;
7559 /* Likewise, clear the signal if it should not be passed. */
7560 if (!signal_program
[ecs
->event_thread
->stop_signal ()])
7561 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
7563 if (restart_stepped_thread (ecs
->target
, ecs
->ptid
))
7565 prepare_to_wait (ecs
);
7569 switch_to_thread (ecs
->event_thread
);
7575 /* Look for the thread that was stepping, and resume it.
7576 RESUME_TARGET / RESUME_PTID indicate the set of threads the caller
7577 is resuming. Return true if a thread was started, false
7581 restart_stepped_thread (process_stratum_target
*resume_target
,
7584 /* Do all pending step-overs before actually proceeding with
7586 if (start_step_over ())
7589 for (thread_info
*tp
: all_threads_safe ())
7591 if (tp
->state
== THREAD_EXITED
)
7594 if (tp
->has_pending_waitstatus ())
7597 /* Ignore threads of processes the caller is not
7600 && (tp
->inf
->process_target () != resume_target
7601 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7604 if (tp
->control
.trap_expected
)
7606 infrun_debug_printf ("switching back to stepped thread (step-over)");
7608 if (keep_going_stepped_thread (tp
))
7613 for (thread_info
*tp
: all_threads_safe ())
7615 if (tp
->state
== THREAD_EXITED
)
7618 if (tp
->has_pending_waitstatus ())
7621 /* Ignore threads of processes the caller is not
7624 && (tp
->inf
->process_target () != resume_target
7625 || tp
->inf
->pid
!= resume_ptid
.pid ()))
7628 /* Did we find the stepping thread? */
7629 if (tp
->control
.step_range_end
)
7631 infrun_debug_printf ("switching back to stepped thread (stepping)");
7633 if (keep_going_stepped_thread (tp
))
7644 restart_after_all_stop_detach (process_stratum_target
*proc_target
)
7646 /* Note we don't check target_is_non_stop_p() here, because the
7647 current inferior may no longer have a process_stratum target
7648 pushed, as we just detached. */
7650 /* See if we have a THREAD_RUNNING thread that need to be
7651 re-resumed. If we have any thread that is already executing,
7652 then we don't need to resume the target -- it is already been
7653 resumed. With the remote target (in all-stop), it's even
7654 impossible to issue another resumption if the target is already
7655 resumed, until the target reports a stop. */
7656 for (thread_info
*thr
: all_threads (proc_target
))
7658 if (thr
->state
!= THREAD_RUNNING
)
7661 /* If we have any thread that is already executing, then we
7662 don't need to resume the target -- it is already been
7664 if (thr
->executing ())
7667 /* If we have a pending event to process, skip resuming the
7668 target and go straight to processing it. */
7669 if (thr
->resumed () && thr
->has_pending_waitstatus ())
7673 /* Alright, we need to re-resume the target. If a thread was
7674 stepping, we need to restart it stepping. */
7675 if (restart_stepped_thread (proc_target
, minus_one_ptid
))
7678 /* Otherwise, find the first THREAD_RUNNING thread and resume
7680 for (thread_info
*thr
: all_threads (proc_target
))
7682 if (thr
->state
!= THREAD_RUNNING
)
7685 execution_control_state
ecs (thr
);
7686 switch_to_thread (thr
);
7692 /* Set a previously stepped thread back to stepping. Returns true on
7693 success, false if the resume is not possible (e.g., the thread
7697 keep_going_stepped_thread (struct thread_info
*tp
)
7699 frame_info_ptr frame
;
7701 /* If the stepping thread exited, then don't try to switch back and
7702 resume it, which could fail in several different ways depending
7703 on the target. Instead, just keep going.
7705 We can find a stepping dead thread in the thread list in two
7708 - The target supports thread exit events, and when the target
7709 tries to delete the thread from the thread list, inferior_ptid
7710 pointed at the exiting thread. In such case, calling
7711 delete_thread does not really remove the thread from the list;
7712 instead, the thread is left listed, with 'exited' state.
7714 - The target's debug interface does not support thread exit
7715 events, and so we have no idea whatsoever if the previously
7716 stepping thread is still alive. For that reason, we need to
7717 synchronously query the target now. */
7719 if (tp
->state
== THREAD_EXITED
|| !target_thread_alive (tp
->ptid
))
7721 infrun_debug_printf ("not resuming previously stepped thread, it has "
7728 infrun_debug_printf ("resuming previously stepped thread");
7730 execution_control_state
ecs (tp
);
7731 switch_to_thread (tp
);
7733 tp
->set_stop_pc (regcache_read_pc (get_thread_regcache (tp
)));
7734 frame
= get_current_frame ();
7736 /* If the PC of the thread we were trying to single-step has
7737 changed, then that thread has trapped or been signaled, but the
7738 event has not been reported to GDB yet. Re-poll the target
7739 looking for this particular thread's event (i.e. temporarily
7740 enable schedlock) by:
7742 - setting a break at the current PC
7743 - resuming that particular thread, only (by setting trap
7746 This prevents us continuously moving the single-step breakpoint
7747 forward, one instruction at a time, overstepping. */
7749 if (tp
->stop_pc () != tp
->prev_pc
)
7753 infrun_debug_printf ("expected thread advanced also (%s -> %s)",
7754 paddress (target_gdbarch (), tp
->prev_pc
),
7755 paddress (target_gdbarch (), tp
->stop_pc ()));
7757 /* Clear the info of the previous step-over, as it's no longer
7758 valid (if the thread was trying to step over a breakpoint, it
7759 has already succeeded). It's what keep_going would do too,
7760 if we called it. Do this before trying to insert the sss
7761 breakpoint, otherwise if we were previously trying to step
7762 over this exact address in another thread, the breakpoint is
7764 clear_step_over_info ();
7765 tp
->control
.trap_expected
= 0;
7767 insert_single_step_breakpoint (get_frame_arch (frame
),
7768 get_frame_address_space (frame
),
7771 tp
->set_resumed (true);
7772 resume_ptid
= internal_resume_ptid (tp
->control
.stepping_command
);
7773 do_target_resume (resume_ptid
, false, GDB_SIGNAL_0
);
7777 infrun_debug_printf ("expected thread still hasn't advanced");
7779 keep_going_pass_signal (&ecs
);
7785 /* Is thread TP in the middle of (software or hardware)
7786 single-stepping? (Note the result of this function must never be
7787 passed directly as target_resume's STEP parameter.) */
7790 currently_stepping (struct thread_info
*tp
)
7792 return ((tp
->control
.step_range_end
7793 && tp
->control
.step_resume_breakpoint
== nullptr)
7794 || tp
->control
.trap_expected
7795 || tp
->stepped_breakpoint
7796 || bpstat_should_step ());
7799 /* Inferior has stepped into a subroutine call with source code that
7800 we should not step over. Do step to the first line of code in
7804 handle_step_into_function (struct gdbarch
*gdbarch
,
7805 struct execution_control_state
*ecs
)
7807 fill_in_stop_func (gdbarch
, ecs
);
7809 compunit_symtab
*cust
7810 = find_pc_compunit_symtab (ecs
->event_thread
->stop_pc ());
7811 if (cust
!= nullptr && cust
->language () != language_asm
)
7812 ecs
->stop_func_start
7813 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7815 symtab_and_line stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
7816 /* Use the step_resume_break to step until the end of the prologue,
7817 even if that involves jumps (as it seems to on the vax under
7819 /* If the prologue ends in the middle of a source line, continue to
7820 the end of that source line (if it is still within the function).
7821 Otherwise, just go to end of prologue. */
7822 if (stop_func_sal
.end
7823 && stop_func_sal
.pc
!= ecs
->stop_func_start
7824 && stop_func_sal
.end
< ecs
->stop_func_end
)
7825 ecs
->stop_func_start
= stop_func_sal
.end
;
7827 /* Architectures which require breakpoint adjustment might not be able
7828 to place a breakpoint at the computed address. If so, the test
7829 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
7830 ecs->stop_func_start to an address at which a breakpoint may be
7831 legitimately placed.
7833 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
7834 made, GDB will enter an infinite loop when stepping through
7835 optimized code consisting of VLIW instructions which contain
7836 subinstructions corresponding to different source lines. On
7837 FR-V, it's not permitted to place a breakpoint on any but the
7838 first subinstruction of a VLIW instruction. When a breakpoint is
7839 set, GDB will adjust the breakpoint address to the beginning of
7840 the VLIW instruction. Thus, we need to make the corresponding
7841 adjustment here when computing the stop address. */
7843 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7845 ecs
->stop_func_start
7846 = gdbarch_adjust_breakpoint_address (gdbarch
,
7847 ecs
->stop_func_start
);
7850 if (ecs
->stop_func_start
== ecs
->event_thread
->stop_pc ())
7852 /* We are already there: stop now. */
7853 end_stepping_range (ecs
);
7858 /* Put the step-breakpoint there and go until there. */
7859 symtab_and_line sr_sal
;
7860 sr_sal
.pc
= ecs
->stop_func_start
;
7861 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
7862 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
7864 /* Do not specify what the fp should be when we stop since on
7865 some machines the prologue is where the new fp value is
7867 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
7869 /* And make sure stepping stops right away then. */
7870 ecs
->event_thread
->control
.step_range_end
7871 = ecs
->event_thread
->control
.step_range_start
;
7876 /* Inferior has stepped backward into a subroutine call with source
7877 code that we should not step over. Do step to the beginning of the
7878 last line of code in it. */
7881 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
7882 struct execution_control_state
*ecs
)
7884 struct compunit_symtab
*cust
;
7885 struct symtab_and_line stop_func_sal
;
7887 fill_in_stop_func (gdbarch
, ecs
);
7889 cust
= find_pc_compunit_symtab (ecs
->event_thread
->stop_pc ());
7890 if (cust
!= nullptr && cust
->language () != language_asm
)
7891 ecs
->stop_func_start
7892 = gdbarch_skip_prologue_noexcept (gdbarch
, ecs
->stop_func_start
);
7894 stop_func_sal
= find_pc_line (ecs
->event_thread
->stop_pc (), 0);
7896 /* OK, we're just going to keep stepping here. */
7897 if (stop_func_sal
.pc
== ecs
->event_thread
->stop_pc ())
7899 /* We're there already. Just stop stepping now. */
7900 end_stepping_range (ecs
);
7904 /* Else just reset the step range and keep going.
7905 No step-resume breakpoint, they don't work for
7906 epilogues, which can have multiple entry paths. */
7907 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
7908 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
7914 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
7915 This is used to both functions and to skip over code. */
7918 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
7919 struct symtab_and_line sr_sal
,
7920 struct frame_id sr_id
,
7921 enum bptype sr_type
)
7923 /* There should never be more than one step-resume or longjmp-resume
7924 breakpoint per thread, so we should never be setting a new
7925 step_resume_breakpoint when one is already active. */
7926 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== nullptr);
7927 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
7929 infrun_debug_printf ("inserting step-resume breakpoint at %s",
7930 paddress (gdbarch
, sr_sal
.pc
));
7932 inferior_thread ()->control
.step_resume_breakpoint
7933 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
).release ();
7937 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
7938 struct symtab_and_line sr_sal
,
7939 struct frame_id sr_id
)
7941 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
7946 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
7947 This is used to skip a potential signal handler.
7949 This is called with the interrupted function's frame. The signal
7950 handler, when it returns, will resume the interrupted function at
7954 insert_hp_step_resume_breakpoint_at_frame (frame_info_ptr return_frame
)
7956 gdb_assert (return_frame
!= nullptr);
7958 struct gdbarch
*gdbarch
= get_frame_arch (return_frame
);
7960 symtab_and_line sr_sal
;
7961 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
7962 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7963 sr_sal
.pspace
= get_frame_program_space (return_frame
);
7965 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
7966 get_stack_frame_id (return_frame
),
7970 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
7971 is used to skip a function after stepping into it (for "next" or if
7972 the called function has no debugging information).
7974 The current function has almost always been reached by single
7975 stepping a call or return instruction. NEXT_FRAME belongs to the
7976 current function, and the breakpoint will be set at the caller's
7979 This is a separate function rather than reusing
7980 insert_hp_step_resume_breakpoint_at_frame in order to avoid
7981 get_prev_frame, which may stop prematurely (see the implementation
7982 of frame_unwind_caller_id for an example). */
7985 insert_step_resume_breakpoint_at_caller (frame_info_ptr next_frame
)
7987 /* We shouldn't have gotten here if we don't know where the call site
7989 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
7991 struct gdbarch
*gdbarch
= frame_unwind_caller_arch (next_frame
);
7993 symtab_and_line sr_sal
;
7994 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
7995 frame_unwind_caller_pc (next_frame
));
7996 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
7997 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
7999 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
8000 frame_unwind_caller_id (next_frame
));
8003 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
8004 new breakpoint at the target of a jmp_buf. The handling of
8005 longjmp-resume uses the same mechanisms used for handling
8006 "step-resume" breakpoints. */
8009 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8011 /* There should never be more than one longjmp-resume breakpoint per
8012 thread, so we should never be setting a new
8013 longjmp_resume_breakpoint when one is already active. */
8014 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== nullptr);
8016 infrun_debug_printf ("inserting longjmp-resume breakpoint at %s",
8017 paddress (gdbarch
, pc
));
8019 inferior_thread ()->control
.exception_resume_breakpoint
=
8020 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
).release ();
8023 /* Insert an exception resume breakpoint. TP is the thread throwing
8024 the exception. The block B is the block of the unwinder debug hook
8025 function. FRAME is the frame corresponding to the call to this
8026 function. SYM is the symbol of the function argument holding the
8027 target PC of the exception. */
8030 insert_exception_resume_breakpoint (struct thread_info
*tp
,
8031 const struct block
*b
,
8032 frame_info_ptr frame
,
8037 struct block_symbol vsym
;
8038 struct value
*value
;
8040 struct breakpoint
*bp
;
8042 vsym
= lookup_symbol_search_name (sym
->search_name (),
8044 value
= read_var_value (vsym
.symbol
, vsym
.block
, frame
);
8045 /* If the value was optimized out, revert to the old behavior. */
8046 if (! value
->optimized_out ())
8048 handler
= value_as_address (value
);
8050 infrun_debug_printf ("exception resume at %lx",
8051 (unsigned long) handler
);
8053 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8055 bp_exception_resume
).release ();
8057 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
8060 bp
->thread
= tp
->global_num
;
8061 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
8064 catch (const gdb_exception_error
&e
)
8066 /* We want to ignore errors here. */
8070 /* A helper for check_exception_resume that sets an
8071 exception-breakpoint based on a SystemTap probe. */
8074 insert_exception_resume_from_probe (struct thread_info
*tp
,
8075 const struct bound_probe
*probe
,
8076 frame_info_ptr frame
)
8078 struct value
*arg_value
;
8080 struct breakpoint
*bp
;
8082 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
8086 handler
= value_as_address (arg_value
);
8088 infrun_debug_printf ("exception resume at %s",
8089 paddress (probe
->objfile
->arch (), handler
));
8091 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
8092 handler
, bp_exception_resume
).release ();
8093 bp
->thread
= tp
->global_num
;
8094 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
8097 /* This is called when an exception has been intercepted. Check to
8098 see whether the exception's destination is of interest, and if so,
8099 set an exception resume breakpoint there. */
8102 check_exception_resume (struct execution_control_state
*ecs
,
8103 frame_info_ptr frame
)
8105 struct bound_probe probe
;
8106 struct symbol
*func
;
8108 /* First see if this exception unwinding breakpoint was set via a
8109 SystemTap probe point. If so, the probe has two arguments: the
8110 CFA and the HANDLER. We ignore the CFA, extract the handler, and
8111 set a breakpoint there. */
8112 probe
= find_probe_by_pc (get_frame_pc (frame
));
8115 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
8119 func
= get_frame_function (frame
);
8125 const struct block
*b
;
8128 /* The exception breakpoint is a thread-specific breakpoint on
8129 the unwinder's debug hook, declared as:
8131 void _Unwind_DebugHook (void *cfa, void *handler);
8133 The CFA argument indicates the frame to which control is
8134 about to be transferred. HANDLER is the destination PC.
8136 We ignore the CFA and set a temporary breakpoint at HANDLER.
8137 This is not extremely efficient but it avoids issues in gdb
8138 with computing the DWARF CFA, and it also works even in weird
8139 cases such as throwing an exception from inside a signal
8142 b
= func
->value_block ();
8143 for (struct symbol
*sym
: block_iterator_range (b
))
8145 if (!sym
->is_argument ())
8152 insert_exception_resume_breakpoint (ecs
->event_thread
,
8158 catch (const gdb_exception_error
&e
)
8164 stop_waiting (struct execution_control_state
*ecs
)
8166 infrun_debug_printf ("stop_waiting");
8168 /* Let callers know we don't want to wait for the inferior anymore. */
8169 ecs
->wait_some_more
= 0;
8172 /* Like keep_going, but passes the signal to the inferior, even if the
8173 signal is set to nopass. */
8176 keep_going_pass_signal (struct execution_control_state
*ecs
)
8178 gdb_assert (ecs
->event_thread
->ptid
== inferior_ptid
);
8179 gdb_assert (!ecs
->event_thread
->resumed ());
8181 /* Save the pc before execution, to compare with pc after stop. */
8182 ecs
->event_thread
->prev_pc
8183 = regcache_read_pc_protected (get_thread_regcache (ecs
->event_thread
));
8185 if (ecs
->event_thread
->control
.trap_expected
)
8187 struct thread_info
*tp
= ecs
->event_thread
;
8189 infrun_debug_printf ("%s has trap_expected set, "
8190 "resuming to collect trap",
8191 tp
->ptid
.to_string ().c_str ());
8193 /* We haven't yet gotten our trap, and either: intercepted a
8194 non-signal event (e.g., a fork); or took a signal which we
8195 are supposed to pass through to the inferior. Simply
8197 resume (ecs
->event_thread
->stop_signal ());
8199 else if (step_over_info_valid_p ())
8201 /* Another thread is stepping over a breakpoint in-line. If
8202 this thread needs a step-over too, queue the request. In
8203 either case, this resume must be deferred for later. */
8204 struct thread_info
*tp
= ecs
->event_thread
;
8206 if (ecs
->hit_singlestep_breakpoint
8207 || thread_still_needs_step_over (tp
))
8209 infrun_debug_printf ("step-over already in progress: "
8210 "step-over for %s deferred",
8211 tp
->ptid
.to_string ().c_str ());
8212 global_thread_step_over_chain_enqueue (tp
);
8215 infrun_debug_printf ("step-over in progress: resume of %s deferred",
8216 tp
->ptid
.to_string ().c_str ());
8220 struct regcache
*regcache
= get_current_regcache ();
8223 step_over_what step_what
;
8225 /* Either the trap was not expected, but we are continuing
8226 anyway (if we got a signal, the user asked it be passed to
8229 We got our expected trap, but decided we should resume from
8232 We're going to run this baby now!
8234 Note that insert_breakpoints won't try to re-insert
8235 already inserted breakpoints. Therefore, we don't
8236 care if breakpoints were already inserted, or not. */
8238 /* If we need to step over a breakpoint, and we're not using
8239 displaced stepping to do so, insert all breakpoints
8240 (watchpoints, etc.) but the one we're stepping over, step one
8241 instruction, and then re-insert the breakpoint when that step
8244 step_what
= thread_still_needs_step_over (ecs
->event_thread
);
8246 remove_bp
= (ecs
->hit_singlestep_breakpoint
8247 || (step_what
& STEP_OVER_BREAKPOINT
));
8248 remove_wps
= (step_what
& STEP_OVER_WATCHPOINT
);
8250 /* We can't use displaced stepping if we need to step past a
8251 watchpoint. The instruction copied to the scratch pad would
8252 still trigger the watchpoint. */
8254 && (remove_wps
|| !use_displaced_stepping (ecs
->event_thread
)))
8256 set_step_over_info (regcache
->aspace (),
8257 regcache_read_pc (regcache
), remove_wps
,
8258 ecs
->event_thread
->global_num
);
8260 else if (remove_wps
)
8261 set_step_over_info (nullptr, 0, remove_wps
, -1);
8263 /* If we now need to do an in-line step-over, we need to stop
8264 all other threads. Note this must be done before
8265 insert_breakpoints below, because that removes the breakpoint
8266 we're about to step over, otherwise other threads could miss
8268 if (step_over_info_valid_p () && target_is_non_stop_p ())
8269 stop_all_threads ("starting in-line step-over");
8271 /* Stop stepping if inserting breakpoints fails. */
8274 insert_breakpoints ();
8276 catch (const gdb_exception_error
&e
)
8278 exception_print (gdb_stderr
, e
);
8280 clear_step_over_info ();
8284 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
8286 resume (ecs
->event_thread
->stop_signal ());
8289 prepare_to_wait (ecs
);
8292 /* Called when we should continue running the inferior, because the
8293 current event doesn't cause a user visible stop. This does the
8294 resuming part; waiting for the next event is done elsewhere. */
8297 keep_going (struct execution_control_state
*ecs
)
8299 if (ecs
->event_thread
->control
.trap_expected
8300 && ecs
->event_thread
->stop_signal () == GDB_SIGNAL_TRAP
)
8301 ecs
->event_thread
->control
.trap_expected
= 0;
8303 if (!signal_program
[ecs
->event_thread
->stop_signal ()])
8304 ecs
->event_thread
->set_stop_signal (GDB_SIGNAL_0
);
8305 keep_going_pass_signal (ecs
);
8308 /* This function normally comes after a resume, before
8309 handle_inferior_event exits. It takes care of any last bits of
8310 housekeeping, and sets the all-important wait_some_more flag. */
8313 prepare_to_wait (struct execution_control_state
*ecs
)
8315 infrun_debug_printf ("prepare_to_wait");
8317 ecs
->wait_some_more
= 1;
8319 /* If the target can't async, emulate it by marking the infrun event
8320 handler such that as soon as we get back to the event-loop, we
8321 immediately end up in fetch_inferior_event again calling
8323 if (!target_can_async_p ())
8324 mark_infrun_async_event_handler ();
8327 /* We are done with the step range of a step/next/si/ni command.
8328 Called once for each n of a "step n" operation. */
8331 end_stepping_range (struct execution_control_state
*ecs
)
8333 ecs
->event_thread
->control
.stop_step
= 1;
8337 /* Several print_*_reason functions to print why the inferior has stopped.
8338 We always print something when the inferior exits, or receives a signal.
8339 The rest of the cases are dealt with later on in normal_stop and
8340 print_it_typical. Ideally there should be a call to one of these
8341 print_*_reason functions functions from handle_inferior_event each time
8342 stop_waiting is called.
8344 Note that we don't call these directly, instead we delegate that to
8345 the interpreters, through observers. Interpreters then call these
8346 with whatever uiout is right. */
8349 print_end_stepping_range_reason (struct ui_out
*uiout
)
8351 /* For CLI-like interpreters, print nothing. */
8353 if (uiout
->is_mi_like_p ())
8355 uiout
->field_string ("reason",
8356 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
8361 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8363 annotate_signalled ();
8364 if (uiout
->is_mi_like_p ())
8366 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
8367 uiout
->text ("\nProgram terminated with signal ");
8368 annotate_signal_name ();
8369 uiout
->field_string ("signal-name",
8370 gdb_signal_to_name (siggnal
));
8371 annotate_signal_name_end ();
8373 annotate_signal_string ();
8374 uiout
->field_string ("signal-meaning",
8375 gdb_signal_to_string (siggnal
));
8376 annotate_signal_string_end ();
8377 uiout
->text (".\n");
8378 uiout
->text ("The program no longer exists.\n");
8382 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
8384 struct inferior
*inf
= current_inferior ();
8385 std::string pidstr
= target_pid_to_str (ptid_t (inf
->pid
));
8387 annotate_exited (exitstatus
);
8390 if (uiout
->is_mi_like_p ())
8391 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXITED
));
8392 std::string exit_code_str
8393 = string_printf ("0%o", (unsigned int) exitstatus
);
8394 uiout
->message ("[Inferior %s (%s) exited with code %pF]\n",
8395 plongest (inf
->num
), pidstr
.c_str (),
8396 string_field ("exit-code", exit_code_str
.c_str ()));
8400 if (uiout
->is_mi_like_p ())
8402 ("reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
8403 uiout
->message ("[Inferior %s (%s) exited normally]\n",
8404 plongest (inf
->num
), pidstr
.c_str ());
8409 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
8411 struct thread_info
*thr
= inferior_thread ();
8413 infrun_debug_printf ("signal = %s", gdb_signal_to_string (siggnal
));
8417 if (uiout
->is_mi_like_p ())
8419 else if (show_thread_that_caused_stop ())
8421 uiout
->text ("\nThread ");
8422 uiout
->field_string ("thread-id", print_thread_id (thr
));
8424 const char *name
= thread_name (thr
);
8425 if (name
!= nullptr)
8427 uiout
->text (" \"");
8428 uiout
->field_string ("name", name
);
8433 uiout
->text ("\nProgram");
8435 if (siggnal
== GDB_SIGNAL_0
&& !uiout
->is_mi_like_p ())
8436 uiout
->text (" stopped");
8439 uiout
->text (" received signal ");
8440 annotate_signal_name ();
8441 if (uiout
->is_mi_like_p ())
8443 ("reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
8444 uiout
->field_string ("signal-name", gdb_signal_to_name (siggnal
));
8445 annotate_signal_name_end ();
8447 annotate_signal_string ();
8448 uiout
->field_string ("signal-meaning", gdb_signal_to_string (siggnal
));
8450 struct regcache
*regcache
= get_current_regcache ();
8451 struct gdbarch
*gdbarch
= regcache
->arch ();
8452 if (gdbarch_report_signal_info_p (gdbarch
))
8453 gdbarch_report_signal_info (gdbarch
, uiout
, siggnal
);
8455 annotate_signal_string_end ();
8457 uiout
->text (".\n");
8461 print_no_history_reason (struct ui_out
*uiout
)
8463 if (uiout
->is_mi_like_p ())
8464 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_NO_HISTORY
));
8466 uiout
->text ("\nNo more reverse-execution history.\n");
8469 /* Print current location without a level number, if we have changed
8470 functions or hit a breakpoint. Print source line if we have one.
8471 bpstat_print contains the logic deciding in detail what to print,
8472 based on the event(s) that just occurred. */
8475 print_stop_location (const target_waitstatus
&ws
)
8478 enum print_what source_flag
;
8479 int do_frame_printing
= 1;
8480 struct thread_info
*tp
= inferior_thread ();
8482 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
.kind ());
8486 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
8487 should) carry around the function and does (or should) use
8488 that when doing a frame comparison. */
8489 if (tp
->control
.stop_step
8490 && (tp
->control
.step_frame_id
8491 == get_frame_id (get_current_frame ()))
8492 && (tp
->control
.step_start_function
8493 == find_pc_function (tp
->stop_pc ())))
8495 /* Finished step, just print source line. */
8496 source_flag
= SRC_LINE
;
8500 /* Print location and source line. */
8501 source_flag
= SRC_AND_LOC
;
8504 case PRINT_SRC_AND_LOC
:
8505 /* Print location and source line. */
8506 source_flag
= SRC_AND_LOC
;
8508 case PRINT_SRC_ONLY
:
8509 source_flag
= SRC_LINE
;
8512 /* Something bogus. */
8513 source_flag
= SRC_LINE
;
8514 do_frame_printing
= 0;
8517 internal_error (_("Unknown value."));
8520 /* The behavior of this routine with respect to the source
8522 SRC_LINE: Print only source line
8523 LOCATION: Print only location
8524 SRC_AND_LOC: Print location and source line. */
8525 if (do_frame_printing
)
8526 print_stack_frame (get_selected_frame (nullptr), 0, source_flag
, 1);
8532 print_stop_event (struct ui_out
*uiout
, bool displays
)
8534 struct target_waitstatus last
;
8535 struct thread_info
*tp
;
8537 get_last_target_status (nullptr, nullptr, &last
);
8540 scoped_restore save_uiout
= make_scoped_restore (¤t_uiout
, uiout
);
8542 print_stop_location (last
);
8544 /* Display the auto-display expressions. */
8549 tp
= inferior_thread ();
8550 if (tp
->thread_fsm () != nullptr
8551 && tp
->thread_fsm ()->finished_p ())
8553 struct return_value_info
*rv
;
8555 rv
= tp
->thread_fsm ()->return_value ();
8557 print_return_value (uiout
, rv
);
8564 maybe_remove_breakpoints (void)
8566 if (!breakpoints_should_be_inserted_now () && target_has_execution ())
8568 if (remove_breakpoints ())
8570 target_terminal::ours_for_output ();
8571 gdb_printf (_("Cannot remove breakpoints because "
8572 "program is no longer writable.\nFurther "
8573 "execution is probably impossible.\n"));
8578 /* The execution context that just caused a normal stop. */
8584 DISABLE_COPY_AND_ASSIGN (stop_context
);
8586 bool changed () const;
8591 /* The event PTID. */
8595 /* If stopp for a thread event, this is the thread that caused the
8597 thread_info_ref thread
;
8599 /* The inferior that caused the stop. */
8603 /* Initializes a new stop context. If stopped for a thread event, this
8604 takes a strong reference to the thread. */
8606 stop_context::stop_context ()
8608 stop_id
= get_stop_id ();
8609 ptid
= inferior_ptid
;
8610 inf_num
= current_inferior ()->num
;
8612 if (inferior_ptid
!= null_ptid
)
8614 /* Take a strong reference so that the thread can't be deleted
8616 thread
= thread_info_ref::new_reference (inferior_thread ());
8620 /* Return true if the current context no longer matches the saved stop
8624 stop_context::changed () const
8626 if (ptid
!= inferior_ptid
)
8628 if (inf_num
!= current_inferior ()->num
)
8630 if (thread
!= nullptr && thread
->state
!= THREAD_STOPPED
)
8632 if (get_stop_id () != stop_id
)
8642 struct target_waitstatus last
;
8644 get_last_target_status (nullptr, nullptr, &last
);
8648 /* If an exception is thrown from this point on, make sure to
8649 propagate GDB's knowledge of the executing state to the
8650 frontend/user running state. A QUIT is an easy exception to see
8651 here, so do this before any filtered output. */
8653 ptid_t finish_ptid
= null_ptid
;
8656 finish_ptid
= minus_one_ptid
;
8657 else if (last
.kind () == TARGET_WAITKIND_SIGNALLED
8658 || last
.kind () == TARGET_WAITKIND_EXITED
)
8660 /* On some targets, we may still have live threads in the
8661 inferior when we get a process exit event. E.g., for
8662 "checkpoint", when the current checkpoint/fork exits,
8663 linux-fork.c automatically switches to another fork from
8664 within target_mourn_inferior. */
8665 if (inferior_ptid
!= null_ptid
)
8666 finish_ptid
= ptid_t (inferior_ptid
.pid ());
8668 else if (last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
8669 finish_ptid
= inferior_ptid
;
8671 gdb::optional
<scoped_finish_thread_state
> maybe_finish_thread_state
;
8672 if (finish_ptid
!= null_ptid
)
8674 maybe_finish_thread_state
.emplace
8675 (user_visible_resume_target (finish_ptid
), finish_ptid
);
8678 /* As we're presenting a stop, and potentially removing breakpoints,
8679 update the thread list so we can tell whether there are threads
8680 running on the target. With target remote, for example, we can
8681 only learn about new threads when we explicitly update the thread
8682 list. Do this before notifying the interpreters about signal
8683 stops, end of stepping ranges, etc., so that the "new thread"
8684 output is emitted before e.g., "Program received signal FOO",
8685 instead of after. */
8686 update_thread_list ();
8688 if (last
.kind () == TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
8689 gdb::observers::signal_received
.notify (inferior_thread ()->stop_signal ());
8691 /* As with the notification of thread events, we want to delay
8692 notifying the user that we've switched thread context until
8693 the inferior actually stops.
8695 There's no point in saying anything if the inferior has exited.
8696 Note that SIGNALLED here means "exited with a signal", not
8697 "received a signal".
8699 Also skip saying anything in non-stop mode. In that mode, as we
8700 don't want GDB to switch threads behind the user's back, to avoid
8701 races where the user is typing a command to apply to thread x,
8702 but GDB switches to thread y before the user finishes entering
8703 the command, fetch_inferior_event installs a cleanup to restore
8704 the current thread back to the thread the user had selected right
8705 after this event is handled, so we're not really switching, only
8706 informing of a stop. */
8708 && previous_inferior_ptid
!= inferior_ptid
8709 && target_has_execution ()
8710 && last
.kind () != TARGET_WAITKIND_SIGNALLED
8711 && last
.kind () != TARGET_WAITKIND_EXITED
8712 && last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
8714 SWITCH_THRU_ALL_UIS ()
8716 target_terminal::ours_for_output ();
8717 gdb_printf (_("[Switching to %s]\n"),
8718 target_pid_to_str (inferior_ptid
).c_str ());
8719 annotate_thread_changed ();
8721 previous_inferior_ptid
= inferior_ptid
;
8724 if (last
.kind () == TARGET_WAITKIND_NO_RESUMED
)
8726 SWITCH_THRU_ALL_UIS ()
8727 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
8729 target_terminal::ours_for_output ();
8730 gdb_printf (_("No unwaited-for children left.\n"));
8734 /* Note: this depends on the update_thread_list call above. */
8735 maybe_remove_breakpoints ();
8737 /* If an auto-display called a function and that got a signal,
8738 delete that auto-display to avoid an infinite recursion. */
8740 if (stopped_by_random_signal
)
8741 disable_current_display ();
8743 SWITCH_THRU_ALL_UIS ()
8745 async_enable_stdin ();
8748 /* Let the user/frontend see the threads as stopped. */
8749 maybe_finish_thread_state
.reset ();
8751 /* Select innermost stack frame - i.e., current frame is frame 0,
8752 and current location is based on that. Handle the case where the
8753 dummy call is returning after being stopped. E.g. the dummy call
8754 previously hit a breakpoint. (If the dummy call returns
8755 normally, we won't reach here.) Do this before the stop hook is
8756 run, so that it doesn't get to see the temporary dummy frame,
8757 which is not where we'll present the stop. */
8758 if (has_stack_frames ())
8760 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
8762 /* Pop the empty frame that contains the stack dummy. This
8763 also restores inferior state prior to the call (struct
8764 infcall_suspend_state). */
8765 frame_info_ptr frame
= get_current_frame ();
8767 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
8769 /* frame_pop calls reinit_frame_cache as the last thing it
8770 does which means there's now no selected frame. */
8773 select_frame (get_current_frame ());
8775 /* Set the current source location. */
8776 set_current_sal_from_frame (get_current_frame ());
8779 /* Look up the hook_stop and run it (CLI internally handles problem
8780 of stop_command's pre-hook not existing). */
8781 stop_context saved_context
;
8785 execute_cmd_pre_hook (stop_command
);
8787 catch (const gdb_exception
&ex
)
8789 exception_fprintf (gdb_stderr
, ex
,
8790 "Error while running hook_stop:\n");
8793 /* If the stop hook resumes the target, then there's no point in
8794 trying to notify about the previous stop; its context is
8795 gone. Likewise if the command switches thread or inferior --
8796 the observers would print a stop for the wrong
8798 if (saved_context
.changed ())
8801 /* Notify observers about the stop. This is where the interpreters
8802 print the stop event. */
8803 if (inferior_ptid
!= null_ptid
)
8804 gdb::observers::normal_stop
.notify (inferior_thread ()->control
.stop_bpstat
,
8807 gdb::observers::normal_stop
.notify (nullptr, stop_print_frame
);
8809 annotate_stopped ();
8811 if (target_has_execution ())
8813 if (last
.kind () != TARGET_WAITKIND_SIGNALLED
8814 && last
.kind () != TARGET_WAITKIND_EXITED
8815 && last
.kind () != TARGET_WAITKIND_NO_RESUMED
)
8816 /* Delete the breakpoint we stopped at, if it wants to be deleted.
8817 Delete any breakpoint that is to be deleted at the next stop. */
8818 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
8825 signal_stop_state (int signo
)
8827 return signal_stop
[signo
];
8831 signal_print_state (int signo
)
8833 return signal_print
[signo
];
8837 signal_pass_state (int signo
)
8839 return signal_program
[signo
];
8843 signal_cache_update (int signo
)
8847 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
8848 signal_cache_update (signo
);
8853 signal_pass
[signo
] = (signal_stop
[signo
] == 0
8854 && signal_print
[signo
] == 0
8855 && signal_program
[signo
] == 1
8856 && signal_catch
[signo
] == 0);
8860 signal_stop_update (int signo
, int state
)
8862 int ret
= signal_stop
[signo
];
8864 signal_stop
[signo
] = state
;
8865 signal_cache_update (signo
);
8870 signal_print_update (int signo
, int state
)
8872 int ret
= signal_print
[signo
];
8874 signal_print
[signo
] = state
;
8875 signal_cache_update (signo
);
8880 signal_pass_update (int signo
, int state
)
8882 int ret
= signal_program
[signo
];
8884 signal_program
[signo
] = state
;
8885 signal_cache_update (signo
);
8889 /* Update the global 'signal_catch' from INFO and notify the
8893 signal_catch_update (const unsigned int *info
)
8897 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
8898 signal_catch
[i
] = info
[i
] > 0;
8899 signal_cache_update (-1);
8900 target_pass_signals (signal_pass
);
8904 sig_print_header (void)
8906 gdb_printf (_("Signal Stop\tPrint\tPass "
8907 "to program\tDescription\n"));
8911 sig_print_info (enum gdb_signal oursig
)
8913 const char *name
= gdb_signal_to_name (oursig
);
8914 int name_padding
= 13 - strlen (name
);
8916 if (name_padding
<= 0)
8919 gdb_printf ("%s", name
);
8920 gdb_printf ("%*.*s ", name_padding
, name_padding
, " ");
8921 gdb_printf ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
8922 gdb_printf ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
8923 gdb_printf ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
8924 gdb_printf ("%s\n", gdb_signal_to_string (oursig
));
8927 /* Specify how various signals in the inferior should be handled. */
8930 handle_command (const char *args
, int from_tty
)
8932 int digits
, wordlen
;
8933 int sigfirst
, siglast
;
8934 enum gdb_signal oursig
;
8937 if (args
== nullptr)
8939 error_no_arg (_("signal to handle"));
8942 /* Allocate and zero an array of flags for which signals to handle. */
8944 const size_t nsigs
= GDB_SIGNAL_LAST
;
8945 unsigned char sigs
[nsigs
] {};
8947 /* Break the command line up into args. */
8949 gdb_argv
built_argv (args
);
8951 /* Walk through the args, looking for signal oursigs, signal names, and
8952 actions. Signal numbers and signal names may be interspersed with
8953 actions, with the actions being performed for all signals cumulatively
8954 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
8956 for (char *arg
: built_argv
)
8958 wordlen
= strlen (arg
);
8959 for (digits
= 0; isdigit (arg
[digits
]); digits
++)
8963 sigfirst
= siglast
= -1;
8965 if (wordlen
>= 1 && !strncmp (arg
, "all", wordlen
))
8967 /* Apply action to all signals except those used by the
8968 debugger. Silently skip those. */
8971 siglast
= nsigs
- 1;
8973 else if (wordlen
>= 1 && !strncmp (arg
, "stop", wordlen
))
8975 SET_SIGS (nsigs
, sigs
, signal_stop
);
8976 SET_SIGS (nsigs
, sigs
, signal_print
);
8978 else if (wordlen
>= 1 && !strncmp (arg
, "ignore", wordlen
))
8980 UNSET_SIGS (nsigs
, sigs
, signal_program
);
8982 else if (wordlen
>= 2 && !strncmp (arg
, "print", wordlen
))
8984 SET_SIGS (nsigs
, sigs
, signal_print
);
8986 else if (wordlen
>= 2 && !strncmp (arg
, "pass", wordlen
))
8988 SET_SIGS (nsigs
, sigs
, signal_program
);
8990 else if (wordlen
>= 3 && !strncmp (arg
, "nostop", wordlen
))
8992 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
8994 else if (wordlen
>= 3 && !strncmp (arg
, "noignore", wordlen
))
8996 SET_SIGS (nsigs
, sigs
, signal_program
);
8998 else if (wordlen
>= 4 && !strncmp (arg
, "noprint", wordlen
))
9000 UNSET_SIGS (nsigs
, sigs
, signal_print
);
9001 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
9003 else if (wordlen
>= 4 && !strncmp (arg
, "nopass", wordlen
))
9005 UNSET_SIGS (nsigs
, sigs
, signal_program
);
9007 else if (digits
> 0)
9009 /* It is numeric. The numeric signal refers to our own
9010 internal signal numbering from target.h, not to host/target
9011 signal number. This is a feature; users really should be
9012 using symbolic names anyway, and the common ones like
9013 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
9015 sigfirst
= siglast
= (int)
9016 gdb_signal_from_command (atoi (arg
));
9017 if (arg
[digits
] == '-')
9020 gdb_signal_from_command (atoi (arg
+ digits
+ 1));
9022 if (sigfirst
> siglast
)
9024 /* Bet he didn't figure we'd think of this case... */
9025 std::swap (sigfirst
, siglast
);
9030 oursig
= gdb_signal_from_name (arg
);
9031 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
9033 sigfirst
= siglast
= (int) oursig
;
9037 /* Not a number and not a recognized flag word => complain. */
9038 error (_("Unrecognized or ambiguous flag word: \"%s\"."), arg
);
9042 /* If any signal numbers or symbol names were found, set flags for
9043 which signals to apply actions to. */
9045 for (int signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
9047 switch ((enum gdb_signal
) signum
)
9049 case GDB_SIGNAL_TRAP
:
9050 case GDB_SIGNAL_INT
:
9051 if (!allsigs
&& !sigs
[signum
])
9053 if (query (_("%s is used by the debugger.\n\
9054 Are you sure you want to change it? "),
9055 gdb_signal_to_name ((enum gdb_signal
) signum
)))
9060 gdb_printf (_("Not confirmed, unchanged.\n"));
9064 case GDB_SIGNAL_DEFAULT
:
9065 case GDB_SIGNAL_UNKNOWN
:
9066 /* Make sure that "all" doesn't print these. */
9075 for (int signum
= 0; signum
< nsigs
; signum
++)
9078 signal_cache_update (-1);
9079 target_pass_signals (signal_pass
);
9080 target_program_signals (signal_program
);
9084 /* Show the results. */
9085 sig_print_header ();
9086 for (; signum
< nsigs
; signum
++)
9088 sig_print_info ((enum gdb_signal
) signum
);
9095 /* Complete the "handle" command. */
9098 handle_completer (struct cmd_list_element
*ignore
,
9099 completion_tracker
&tracker
,
9100 const char *text
, const char *word
)
9102 static const char * const keywords
[] =
9116 signal_completer (ignore
, tracker
, text
, word
);
9117 complete_on_enum (tracker
, keywords
, word
, word
);
9121 gdb_signal_from_command (int num
)
9123 if (num
>= 1 && num
<= 15)
9124 return (enum gdb_signal
) num
;
9125 error (_("Only signals 1-15 are valid as numeric signals.\n\
9126 Use \"info signals\" for a list of symbolic signals."));
9129 /* Print current contents of the tables set by the handle command.
9130 It is possible we should just be printing signals actually used
9131 by the current target (but for things to work right when switching
9132 targets, all signals should be in the signal tables). */
9135 info_signals_command (const char *signum_exp
, int from_tty
)
9137 enum gdb_signal oursig
;
9139 sig_print_header ();
9143 /* First see if this is a symbol name. */
9144 oursig
= gdb_signal_from_name (signum_exp
);
9145 if (oursig
== GDB_SIGNAL_UNKNOWN
)
9147 /* No, try numeric. */
9149 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
9151 sig_print_info (oursig
);
9156 /* These ugly casts brought to you by the native VAX compiler. */
9157 for (oursig
= GDB_SIGNAL_FIRST
;
9158 (int) oursig
< (int) GDB_SIGNAL_LAST
;
9159 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
9163 if (oursig
!= GDB_SIGNAL_UNKNOWN
9164 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
9165 sig_print_info (oursig
);
9168 gdb_printf (_("\nUse the \"handle\" command "
9169 "to change these tables.\n"));
9172 /* The $_siginfo convenience variable is a bit special. We don't know
9173 for sure the type of the value until we actually have a chance to
9174 fetch the data. The type can change depending on gdbarch, so it is
9175 also dependent on which thread you have selected.
9177 1. making $_siginfo be an internalvar that creates a new value on
9180 2. making the value of $_siginfo be an lval_computed value. */
9182 /* This function implements the lval_computed support for reading a
9186 siginfo_value_read (struct value
*v
)
9188 LONGEST transferred
;
9190 /* If we can access registers, so can we access $_siginfo. Likewise
9192 validate_registers_access ();
9195 target_read (current_inferior ()->top_target (),
9196 TARGET_OBJECT_SIGNAL_INFO
,
9198 v
->contents_all_raw ().data (),
9200 v
->type ()->length ());
9202 if (transferred
!= v
->type ()->length ())
9203 error (_("Unable to read siginfo"));
9206 /* This function implements the lval_computed support for writing a
9210 siginfo_value_write (struct value
*v
, struct value
*fromval
)
9212 LONGEST transferred
;
9214 /* If we can access registers, so can we access $_siginfo. Likewise
9216 validate_registers_access ();
9218 transferred
= target_write (current_inferior ()->top_target (),
9219 TARGET_OBJECT_SIGNAL_INFO
,
9221 fromval
->contents_all_raw ().data (),
9223 fromval
->type ()->length ());
9225 if (transferred
!= fromval
->type ()->length ())
9226 error (_("Unable to write siginfo"));
9229 static const struct lval_funcs siginfo_value_funcs
=
9235 /* Return a new value with the correct type for the siginfo object of
9236 the current thread using architecture GDBARCH. Return a void value
9237 if there's no object available. */
9239 static struct value
*
9240 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
9243 if (target_has_stack ()
9244 && inferior_ptid
!= null_ptid
9245 && gdbarch_get_siginfo_type_p (gdbarch
))
9247 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9249 return value::allocate_computed (type
, &siginfo_value_funcs
, nullptr);
9252 return value::allocate (builtin_type (gdbarch
)->builtin_void
);
9256 /* infcall_suspend_state contains state about the program itself like its
9257 registers and any signal it received when it last stopped.
9258 This state must be restored regardless of how the inferior function call
9259 ends (either successfully, or after it hits a breakpoint or signal)
9260 if the program is to properly continue where it left off. */
9262 class infcall_suspend_state
9265 /* Capture state from GDBARCH, TP, and REGCACHE that must be restored
9266 once the inferior function call has finished. */
9267 infcall_suspend_state (struct gdbarch
*gdbarch
,
9268 const struct thread_info
*tp
,
9269 struct regcache
*regcache
)
9270 : m_registers (new readonly_detached_regcache (*regcache
))
9272 tp
->save_suspend_to (m_thread_suspend
);
9274 gdb::unique_xmalloc_ptr
<gdb_byte
> siginfo_data
;
9276 if (gdbarch_get_siginfo_type_p (gdbarch
))
9278 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9279 size_t len
= type
->length ();
9281 siginfo_data
.reset ((gdb_byte
*) xmalloc (len
));
9283 if (target_read (current_inferior ()->top_target (),
9284 TARGET_OBJECT_SIGNAL_INFO
, nullptr,
9285 siginfo_data
.get (), 0, len
) != len
)
9287 /* Errors ignored. */
9288 siginfo_data
.reset (nullptr);
9294 m_siginfo_gdbarch
= gdbarch
;
9295 m_siginfo_data
= std::move (siginfo_data
);
9299 /* Return a pointer to the stored register state. */
9301 readonly_detached_regcache
*registers () const
9303 return m_registers
.get ();
9306 /* Restores the stored state into GDBARCH, TP, and REGCACHE. */
9308 void restore (struct gdbarch
*gdbarch
,
9309 struct thread_info
*tp
,
9310 struct regcache
*regcache
) const
9312 tp
->restore_suspend_from (m_thread_suspend
);
9314 if (m_siginfo_gdbarch
== gdbarch
)
9316 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
9318 /* Errors ignored. */
9319 target_write (current_inferior ()->top_target (),
9320 TARGET_OBJECT_SIGNAL_INFO
, nullptr,
9321 m_siginfo_data
.get (), 0, type
->length ());
9324 /* The inferior can be gone if the user types "print exit(0)"
9325 (and perhaps other times). */
9326 if (target_has_execution ())
9327 /* NB: The register write goes through to the target. */
9328 regcache
->restore (registers ());
9332 /* How the current thread stopped before the inferior function call was
9334 struct thread_suspend_state m_thread_suspend
;
9336 /* The registers before the inferior function call was executed. */
9337 std::unique_ptr
<readonly_detached_regcache
> m_registers
;
9339 /* Format of SIGINFO_DATA or NULL if it is not present. */
9340 struct gdbarch
*m_siginfo_gdbarch
= nullptr;
9342 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
9343 gdbarch_get_siginfo_type ()->length (). For different gdbarch the
9344 content would be invalid. */
9345 gdb::unique_xmalloc_ptr
<gdb_byte
> m_siginfo_data
;
9348 infcall_suspend_state_up
9349 save_infcall_suspend_state ()
9351 struct thread_info
*tp
= inferior_thread ();
9352 struct regcache
*regcache
= get_current_regcache ();
9353 struct gdbarch
*gdbarch
= regcache
->arch ();
9355 infcall_suspend_state_up inf_state
9356 (new struct infcall_suspend_state (gdbarch
, tp
, regcache
));
9358 /* Having saved the current state, adjust the thread state, discarding
9359 any stop signal information. The stop signal is not useful when
9360 starting an inferior function call, and run_inferior_call will not use
9361 the signal due to its `proceed' call with GDB_SIGNAL_0. */
9362 tp
->set_stop_signal (GDB_SIGNAL_0
);
9367 /* Restore inferior session state to INF_STATE. */
9370 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9372 struct thread_info
*tp
= inferior_thread ();
9373 struct regcache
*regcache
= get_current_regcache ();
9374 struct gdbarch
*gdbarch
= regcache
->arch ();
9376 inf_state
->restore (gdbarch
, tp
, regcache
);
9377 discard_infcall_suspend_state (inf_state
);
9381 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
9386 readonly_detached_regcache
*
9387 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
9389 return inf_state
->registers ();
9392 /* infcall_control_state contains state regarding gdb's control of the
9393 inferior itself like stepping control. It also contains session state like
9394 the user's currently selected frame. */
9396 struct infcall_control_state
9398 struct thread_control_state thread_control
;
9399 struct inferior_control_state inferior_control
;
9402 enum stop_stack_kind stop_stack_dummy
= STOP_NONE
;
9403 int stopped_by_random_signal
= 0;
9405 /* ID and level of the selected frame when the inferior function
9407 struct frame_id selected_frame_id
{};
9408 int selected_frame_level
= -1;
9411 /* Save all of the information associated with the inferior<==>gdb
9414 infcall_control_state_up
9415 save_infcall_control_state ()
9417 infcall_control_state_up
inf_status (new struct infcall_control_state
);
9418 struct thread_info
*tp
= inferior_thread ();
9419 struct inferior
*inf
= current_inferior ();
9421 inf_status
->thread_control
= tp
->control
;
9422 inf_status
->inferior_control
= inf
->control
;
9424 tp
->control
.step_resume_breakpoint
= nullptr;
9425 tp
->control
.exception_resume_breakpoint
= nullptr;
9427 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
9428 chain. If caller's caller is walking the chain, they'll be happier if we
9429 hand them back the original chain when restore_infcall_control_state is
9431 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
9434 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
9435 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
9437 save_selected_frame (&inf_status
->selected_frame_id
,
9438 &inf_status
->selected_frame_level
);
9443 /* Restore inferior session state to INF_STATUS. */
9446 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
9448 struct thread_info
*tp
= inferior_thread ();
9449 struct inferior
*inf
= current_inferior ();
9451 if (tp
->control
.step_resume_breakpoint
)
9452 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
9454 if (tp
->control
.exception_resume_breakpoint
)
9455 tp
->control
.exception_resume_breakpoint
->disposition
9456 = disp_del_at_next_stop
;
9458 /* Handle the bpstat_copy of the chain. */
9459 bpstat_clear (&tp
->control
.stop_bpstat
);
9461 tp
->control
= inf_status
->thread_control
;
9462 inf
->control
= inf_status
->inferior_control
;
9465 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
9466 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
9468 if (target_has_stack ())
9470 restore_selected_frame (inf_status
->selected_frame_id
,
9471 inf_status
->selected_frame_level
);
9478 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
9480 if (inf_status
->thread_control
.step_resume_breakpoint
)
9481 inf_status
->thread_control
.step_resume_breakpoint
->disposition
9482 = disp_del_at_next_stop
;
9484 if (inf_status
->thread_control
.exception_resume_breakpoint
)
9485 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
9486 = disp_del_at_next_stop
;
9488 /* See save_infcall_control_state for info on stop_bpstat. */
9489 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
9497 clear_exit_convenience_vars (void)
9499 clear_internalvar (lookup_internalvar ("_exitsignal"));
9500 clear_internalvar (lookup_internalvar ("_exitcode"));
9504 /* User interface for reverse debugging:
9505 Set exec-direction / show exec-direction commands
9506 (returns error unless target implements to_set_exec_direction method). */
9508 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
9509 static const char exec_forward
[] = "forward";
9510 static const char exec_reverse
[] = "reverse";
9511 static const char *exec_direction
= exec_forward
;
9512 static const char *const exec_direction_names
[] = {
9519 set_exec_direction_func (const char *args
, int from_tty
,
9520 struct cmd_list_element
*cmd
)
9522 if (target_can_execute_reverse ())
9524 if (!strcmp (exec_direction
, exec_forward
))
9525 execution_direction
= EXEC_FORWARD
;
9526 else if (!strcmp (exec_direction
, exec_reverse
))
9527 execution_direction
= EXEC_REVERSE
;
9531 exec_direction
= exec_forward
;
9532 error (_("Target does not support this operation."));
9537 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
9538 struct cmd_list_element
*cmd
, const char *value
)
9540 switch (execution_direction
) {
9542 gdb_printf (out
, _("Forward.\n"));
9545 gdb_printf (out
, _("Reverse.\n"));
9548 internal_error (_("bogus execution_direction value: %d"),
9549 (int) execution_direction
);
9554 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
9555 struct cmd_list_element
*c
, const char *value
)
9557 gdb_printf (file
, _("Resuming the execution of threads "
9558 "of all processes is %s.\n"), value
);
9561 /* Implementation of `siginfo' variable. */
9563 static const struct internalvar_funcs siginfo_funcs
=
9569 /* Callback for infrun's target events source. This is marked when a
9570 thread has a pending status to process. */
9573 infrun_async_inferior_event_handler (gdb_client_data data
)
9575 clear_async_event_handler (infrun_async_inferior_event_token
);
9576 inferior_event_handler (INF_REG_EVENT
);
9583 /* Verify that when two threads with the same ptid exist (from two different
9584 targets) and one of them changes ptid, we only update inferior_ptid if
9585 it is appropriate. */
9588 infrun_thread_ptid_changed ()
9590 gdbarch
*arch
= current_inferior ()->gdbarch
;
9592 /* The thread which inferior_ptid represents changes ptid. */
9594 scoped_restore_current_pspace_and_thread restore
;
9596 scoped_mock_context
<test_target_ops
> target1 (arch
);
9597 scoped_mock_context
<test_target_ops
> target2 (arch
);
9599 ptid_t
old_ptid (111, 222);
9600 ptid_t
new_ptid (111, 333);
9602 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9603 target1
.mock_thread
.ptid
= old_ptid
;
9604 target1
.mock_inferior
.ptid_thread_map
.clear ();
9605 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
9607 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9608 target2
.mock_thread
.ptid
= old_ptid
;
9609 target2
.mock_inferior
.ptid_thread_map
.clear ();
9610 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
9612 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9613 set_current_inferior (&target1
.mock_inferior
);
9615 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9617 gdb_assert (inferior_ptid
== new_ptid
);
9620 /* A thread with the same ptid as inferior_ptid, but from another target,
9623 scoped_restore_current_pspace_and_thread restore
;
9625 scoped_mock_context
<test_target_ops
> target1 (arch
);
9626 scoped_mock_context
<test_target_ops
> target2 (arch
);
9628 ptid_t
old_ptid (111, 222);
9629 ptid_t
new_ptid (111, 333);
9631 target1
.mock_inferior
.pid
= old_ptid
.pid ();
9632 target1
.mock_thread
.ptid
= old_ptid
;
9633 target1
.mock_inferior
.ptid_thread_map
.clear ();
9634 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
9636 target2
.mock_inferior
.pid
= old_ptid
.pid ();
9637 target2
.mock_thread
.ptid
= old_ptid
;
9638 target2
.mock_inferior
.ptid_thread_map
.clear ();
9639 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
9641 auto restore_inferior_ptid
= make_scoped_restore (&inferior_ptid
, old_ptid
);
9642 set_current_inferior (&target2
.mock_inferior
);
9644 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
9646 gdb_assert (inferior_ptid
== old_ptid
);
9650 } /* namespace selftests */
9652 #endif /* GDB_SELF_TEST */
9654 void _initialize_infrun ();
9656 _initialize_infrun ()
9658 struct cmd_list_element
*c
;
9660 /* Register extra event sources in the event loop. */
9661 infrun_async_inferior_event_token
9662 = create_async_event_handler (infrun_async_inferior_event_handler
, nullptr,
9665 cmd_list_element
*info_signals_cmd
9666 = add_info ("signals", info_signals_command
, _("\
9667 What debugger does when program gets various signals.\n\
9668 Specify a signal as argument to print info on that signal only."));
9669 add_info_alias ("handle", info_signals_cmd
, 0);
9671 c
= add_com ("handle", class_run
, handle_command
, _("\
9672 Specify how to handle signals.\n\
9673 Usage: handle SIGNAL [ACTIONS]\n\
9674 Args are signals and actions to apply to those signals.\n\
9675 If no actions are specified, the current settings for the specified signals\n\
9676 will be displayed instead.\n\
9678 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
9679 from 1-15 are allowed for compatibility with old versions of GDB.\n\
9680 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
9681 The special arg \"all\" is recognized to mean all signals except those\n\
9682 used by the debugger, typically SIGTRAP and SIGINT.\n\
9684 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
9685 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
9686 Stop means reenter debugger if this signal happens (implies print).\n\
9687 Print means print a message if this signal happens.\n\
9688 Pass means let program see this signal; otherwise program doesn't know.\n\
9689 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
9690 Pass and Stop may be combined.\n\
9692 Multiple signals may be specified. Signal numbers and signal names\n\
9693 may be interspersed with actions, with the actions being performed for\n\
9694 all signals cumulatively specified."));
9695 set_cmd_completer (c
, handle_completer
);
9697 stop_command
= add_cmd ("stop", class_obscure
,
9698 not_just_help_class_command
, _("\
9699 There is no `stop' command, but you can set a hook on `stop'.\n\
9700 This allows you to set a list of commands to be run each time execution\n\
9701 of the program stops."), &cmdlist
);
9703 add_setshow_boolean_cmd
9704 ("infrun", class_maintenance
, &debug_infrun
,
9705 _("Set inferior debugging."),
9706 _("Show inferior debugging."),
9707 _("When non-zero, inferior specific debugging is enabled."),
9708 nullptr, show_debug_infrun
, &setdebuglist
, &showdebuglist
);
9710 add_setshow_boolean_cmd ("non-stop", no_class
,
9712 Set whether gdb controls the inferior in non-stop mode."), _("\
9713 Show whether gdb controls the inferior in non-stop mode."), _("\
9714 When debugging a multi-threaded program and this setting is\n\
9715 off (the default, also called all-stop mode), when one thread stops\n\
9716 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
9717 all other threads in the program while you interact with the thread of\n\
9718 interest. When you continue or step a thread, you can allow the other\n\
9719 threads to run, or have them remain stopped, but while you inspect any\n\
9720 thread's state, all threads stop.\n\
9722 In non-stop mode, when one thread stops, other threads can continue\n\
9723 to run freely. You'll be able to step each thread independently,\n\
9724 leave it stopped or free to run as needed."),
9730 for (size_t i
= 0; i
< GDB_SIGNAL_LAST
; i
++)
9733 signal_print
[i
] = 1;
9734 signal_program
[i
] = 1;
9735 signal_catch
[i
] = 0;
9738 /* Signals caused by debugger's own actions should not be given to
9739 the program afterwards.
9741 Do not deliver GDB_SIGNAL_TRAP by default, except when the user
9742 explicitly specifies that it should be delivered to the target
9743 program. Typically, that would occur when a user is debugging a
9744 target monitor on a simulator: the target monitor sets a
9745 breakpoint; the simulator encounters this breakpoint and halts
9746 the simulation handing control to GDB; GDB, noting that the stop
9747 address doesn't map to any known breakpoint, returns control back
9748 to the simulator; the simulator then delivers the hardware
9749 equivalent of a GDB_SIGNAL_TRAP to the program being
9751 signal_program
[GDB_SIGNAL_TRAP
] = 0;
9752 signal_program
[GDB_SIGNAL_INT
] = 0;
9754 /* Signals that are not errors should not normally enter the debugger. */
9755 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
9756 signal_print
[GDB_SIGNAL_ALRM
] = 0;
9757 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
9758 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
9759 signal_stop
[GDB_SIGNAL_PROF
] = 0;
9760 signal_print
[GDB_SIGNAL_PROF
] = 0;
9761 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
9762 signal_print
[GDB_SIGNAL_CHLD
] = 0;
9763 signal_stop
[GDB_SIGNAL_IO
] = 0;
9764 signal_print
[GDB_SIGNAL_IO
] = 0;
9765 signal_stop
[GDB_SIGNAL_POLL
] = 0;
9766 signal_print
[GDB_SIGNAL_POLL
] = 0;
9767 signal_stop
[GDB_SIGNAL_URG
] = 0;
9768 signal_print
[GDB_SIGNAL_URG
] = 0;
9769 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
9770 signal_print
[GDB_SIGNAL_WINCH
] = 0;
9771 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
9772 signal_print
[GDB_SIGNAL_PRIO
] = 0;
9774 /* These signals are used internally by user-level thread
9775 implementations. (See signal(5) on Solaris.) Like the above
9776 signals, a healthy program receives and handles them as part of
9777 its normal operation. */
9778 signal_stop
[GDB_SIGNAL_LWP
] = 0;
9779 signal_print
[GDB_SIGNAL_LWP
] = 0;
9780 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
9781 signal_print
[GDB_SIGNAL_WAITING
] = 0;
9782 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
9783 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
9784 signal_stop
[GDB_SIGNAL_LIBRT
] = 0;
9785 signal_print
[GDB_SIGNAL_LIBRT
] = 0;
9787 /* Update cached state. */
9788 signal_cache_update (-1);
9790 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
9791 &stop_on_solib_events
, _("\
9792 Set stopping for shared library events."), _("\
9793 Show stopping for shared library events."), _("\
9794 If nonzero, gdb will give control to the user when the dynamic linker\n\
9795 notifies gdb of shared library events. The most common event of interest\n\
9796 to the user would be loading/unloading of a new library."),
9797 set_stop_on_solib_events
,
9798 show_stop_on_solib_events
,
9799 &setlist
, &showlist
);
9801 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
9802 follow_fork_mode_kind_names
,
9803 &follow_fork_mode_string
, _("\
9804 Set debugger response to a program call of fork or vfork."), _("\
9805 Show debugger response to a program call of fork or vfork."), _("\
9806 A fork or vfork creates a new process. follow-fork-mode can be:\n\
9807 parent - the original process is debugged after a fork\n\
9808 child - the new process is debugged after a fork\n\
9809 The unfollowed process will continue to run.\n\
9810 By default, the debugger will follow the parent process."),
9812 show_follow_fork_mode_string
,
9813 &setlist
, &showlist
);
9815 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
9816 follow_exec_mode_names
,
9817 &follow_exec_mode_string
, _("\
9818 Set debugger response to a program call of exec."), _("\
9819 Show debugger response to a program call of exec."), _("\
9820 An exec call replaces the program image of a process.\n\
9822 follow-exec-mode can be:\n\
9824 new - the debugger creates a new inferior and rebinds the process\n\
9825 to this new inferior. The program the process was running before\n\
9826 the exec call can be restarted afterwards by restarting the original\n\
9829 same - the debugger keeps the process bound to the same inferior.\n\
9830 The new executable image replaces the previous executable loaded in\n\
9831 the inferior. Restarting the inferior after the exec call restarts\n\
9832 the executable the process was running after the exec call.\n\
9834 By default, the debugger will use the same inferior."),
9836 show_follow_exec_mode_string
,
9837 &setlist
, &showlist
);
9839 add_setshow_enum_cmd ("scheduler-locking", class_run
,
9840 scheduler_enums
, &scheduler_mode
, _("\
9841 Set mode for locking scheduler during execution."), _("\
9842 Show mode for locking scheduler during execution."), _("\
9843 off == no locking (threads may preempt at any time)\n\
9844 on == full locking (no thread except the current thread may run)\n\
9845 This applies to both normal execution and replay mode.\n\
9846 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
9847 In this mode, other threads may run during other commands.\n\
9848 This applies to both normal execution and replay mode.\n\
9849 replay == scheduler locked in replay mode and unlocked during normal execution."),
9850 set_schedlock_func
, /* traps on target vector */
9851 show_scheduler_mode
,
9852 &setlist
, &showlist
);
9854 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
9855 Set mode for resuming threads of all processes."), _("\
9856 Show mode for resuming threads of all processes."), _("\
9857 When on, execution commands (such as 'continue' or 'next') resume all\n\
9858 threads of all processes. When off (which is the default), execution\n\
9859 commands only resume the threads of the current process. The set of\n\
9860 threads that are resumed is further refined by the scheduler-locking\n\
9861 mode (see help set scheduler-locking)."),
9863 show_schedule_multiple
,
9864 &setlist
, &showlist
);
9866 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
9867 Set mode of the step operation."), _("\
9868 Show mode of the step operation."), _("\
9869 When set, doing a step over a function without debug line information\n\
9870 will stop at the first instruction of that function. Otherwise, the\n\
9871 function is skipped and the step command stops at a different source line."),
9873 show_step_stop_if_no_debug
,
9874 &setlist
, &showlist
);
9876 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
9877 &can_use_displaced_stepping
, _("\
9878 Set debugger's willingness to use displaced stepping."), _("\
9879 Show debugger's willingness to use displaced stepping."), _("\
9880 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
9881 supported by the target architecture. If off, gdb will not use displaced\n\
9882 stepping to step over breakpoints, even if such is supported by the target\n\
9883 architecture. If auto (which is the default), gdb will use displaced stepping\n\
9884 if the target architecture supports it and non-stop mode is active, but will not\n\
9885 use it in all-stop mode (see help set non-stop)."),
9887 show_can_use_displaced_stepping
,
9888 &setlist
, &showlist
);
9890 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
9891 &exec_direction
, _("Set direction of execution.\n\
9892 Options are 'forward' or 'reverse'."),
9893 _("Show direction of execution (forward/reverse)."),
9894 _("Tells gdb whether to execute forward or backward."),
9895 set_exec_direction_func
, show_exec_direction_func
,
9896 &setlist
, &showlist
);
9898 /* Set/show detach-on-fork: user-settable mode. */
9900 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
9901 Set whether gdb will detach the child of a fork."), _("\
9902 Show whether gdb will detach the child of a fork."), _("\
9903 Tells gdb whether to detach the child of a fork."),
9904 nullptr, nullptr, &setlist
, &showlist
);
9906 /* Set/show disable address space randomization mode. */
9908 add_setshow_boolean_cmd ("disable-randomization", class_support
,
9909 &disable_randomization
, _("\
9910 Set disabling of debuggee's virtual address space randomization."), _("\
9911 Show disabling of debuggee's virtual address space randomization."), _("\
9912 When this mode is on (which is the default), randomization of the virtual\n\
9913 address space is disabled. Standalone programs run with the randomization\n\
9914 enabled by default on some platforms."),
9915 &set_disable_randomization
,
9916 &show_disable_randomization
,
9917 &setlist
, &showlist
);
9919 /* ptid initializations */
9920 inferior_ptid
= null_ptid
;
9921 target_last_wait_ptid
= minus_one_ptid
;
9923 gdb::observers::thread_ptid_changed
.attach (infrun_thread_ptid_changed
,
9925 gdb::observers::thread_stop_requested
.attach (infrun_thread_stop_requested
,
9927 gdb::observers::thread_exit
.attach (infrun_thread_thread_exit
, "infrun");
9928 gdb::observers::inferior_exit
.attach (infrun_inferior_exit
, "infrun");
9929 gdb::observers::inferior_execd
.attach (infrun_inferior_execd
, "infrun");
9931 /* Explicitly create without lookup, since that tries to create a
9932 value with a void typed value, and when we get here, gdbarch
9933 isn't initialized yet. At this point, we're quite sure there
9934 isn't another convenience variable of the same name. */
9935 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, nullptr);
9937 add_setshow_boolean_cmd ("observer", no_class
,
9938 &observer_mode_1
, _("\
9939 Set whether gdb controls the inferior in observer mode."), _("\
9940 Show whether gdb controls the inferior in observer mode."), _("\
9941 In observer mode, GDB can get data from the inferior, but not\n\
9942 affect its execution. Registers and memory may not be changed,\n\
9943 breakpoints may not be set, and the program cannot be interrupted\n\
9951 selftests::register_test ("infrun_thread_ptid_changed",
9952 selftests::infrun_thread_ptid_changed
);